development
修订版 | 8efcfb5dd06e89215a9e119a81a8a05be6c8af7a (tree) |
---|---|
时间 | 2011-01-30 01:00:48 |
作者 | Jean-Baptiste Queru <jbq@goog...> |
Commiter | Android Git Automerger |
am c8fd87e4: Delete browserplugin sample. do not merge
* commit 'c8fd87e47685146e2c9b32b4f0bdfa3bb724081b':
@@ -1,38 +0,0 @@ | ||
1 | -# Copyright (C) 2009 The Android Open Source Project | |
2 | -# | |
3 | -# Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | -# you may not use this file except in compliance with the License. | |
5 | -# You may obtain a copy of the License at | |
6 | -# | |
7 | -# http://www.apache.org/licenses/LICENSE-2.0 | |
8 | -# | |
9 | -# Unless required by applicable law or agreed to in writing, software | |
10 | -# distributed under the License is distributed on an "AS IS" BASIS, | |
11 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | -# See the License for the specific language governing permissions and | |
13 | -# limitations under the License. | |
14 | -# | |
15 | - | |
16 | -TOP_LOCAL_PATH:= $(call my-dir) | |
17 | - | |
18 | -# Build application | |
19 | - | |
20 | -LOCAL_PATH:= $(call my-dir) | |
21 | -include $(CLEAR_VARS) | |
22 | - | |
23 | -LOCAL_MODULE_TAGS := tests | |
24 | - | |
25 | -LOCAL_SRC_FILES := $(call all-subdir-java-files) | |
26 | - | |
27 | -LOCAL_PROGUARD_ENABLED := disabled | |
28 | - | |
29 | -LOCAL_PACKAGE_NAME := SampleBrowserPlugin | |
30 | - | |
31 | -LOCAL_JNI_SHARED_LIBRARIES := libsampleplugin | |
32 | - | |
33 | -include $(BUILD_PACKAGE) | |
34 | - | |
35 | -# ============================================================ | |
36 | - | |
37 | -# Also build all of the sub-targets under this one: the shared library. | |
38 | -include $(call all-makefiles-under,$(LOCAL_PATH)) |
@@ -1,36 +0,0 @@ | ||
1 | -<?xml version="1.0" encoding="utf-8"?> | |
2 | -<!-- Copyright (C) 2009 The Android Open Source Project | |
3 | - | |
4 | - Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - you may not use this file except in compliance with the License. | |
6 | - You may obtain a copy of the License at | |
7 | - | |
8 | - http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - | |
10 | - Unless required by applicable law or agreed to in writing, software | |
11 | - distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - See the License for the specific language governing permissions and | |
14 | - limitations under the License. | |
15 | ---> | |
16 | - | |
17 | -<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
18 | - package="com.android.sampleplugin" | |
19 | - android:versionCode="1" | |
20 | - android:versionName="1.0"> | |
21 | - | |
22 | - <uses-permission android:name="android.webkit.permission.PLUGIN"/> | |
23 | - | |
24 | - <uses-sdk android:minSdkVersion="3" /> | |
25 | - | |
26 | - <application android:icon="@drawable/sample_browser_plugin" | |
27 | - android:label="@string/sample_browser_plugin"> | |
28 | - <service android:name=".SamplePlugin"> | |
29 | - <intent-filter> | |
30 | - <action android:name="android.webkit.PLUGIN" /> | |
31 | - </intent-filter> | |
32 | - <meta-data android:name="type" android:value="native" /> | |
33 | - </service> | |
34 | - </application> | |
35 | - | |
36 | -</manifest> |
@@ -1,190 +0,0 @@ | ||
1 | - | |
2 | - Copyright (c) 2005-2008, The Android Open Source Project | |
3 | - | |
4 | - Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - you may not use this file except in compliance with the License. | |
6 | - | |
7 | - Unless required by applicable law or agreed to in writing, software | |
8 | - distributed under the License is distributed on an "AS IS" BASIS, | |
9 | - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
10 | - See the License for the specific language governing permissions and | |
11 | - limitations under the License. | |
12 | - | |
13 | - | |
14 | - Apache License | |
15 | - Version 2.0, January 2004 | |
16 | - http://www.apache.org/licenses/ | |
17 | - | |
18 | - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | |
19 | - | |
20 | - 1. Definitions. | |
21 | - | |
22 | - "License" shall mean the terms and conditions for use, reproduction, | |
23 | - and distribution as defined by Sections 1 through 9 of this document. | |
24 | - | |
25 | - "Licensor" shall mean the copyright owner or entity authorized by | |
26 | - the copyright owner that is granting the License. | |
27 | - | |
28 | - "Legal Entity" shall mean the union of the acting entity and all | |
29 | - other entities that control, are controlled by, or are under common | |
30 | - control with that entity. For the purposes of this definition, | |
31 | - "control" means (i) the power, direct or indirect, to cause the | |
32 | - direction or management of such entity, whether by contract or | |
33 | - otherwise, or (ii) ownership of fifty percent (50%) or more of the | |
34 | - outstanding shares, or (iii) beneficial ownership of such entity. | |
35 | - | |
36 | - "You" (or "Your") shall mean an individual or Legal Entity | |
37 | - exercising permissions granted by this License. | |
38 | - | |
39 | - "Source" form shall mean the preferred form for making modifications, | |
40 | - including but not limited to software source code, documentation | |
41 | - source, and configuration files. | |
42 | - | |
43 | - "Object" form shall mean any form resulting from mechanical | |
44 | - transformation or translation of a Source form, including but | |
45 | - not limited to compiled object code, generated documentation, | |
46 | - and conversions to other media types. | |
47 | - | |
48 | - "Work" shall mean the work of authorship, whether in Source or | |
49 | - Object form, made available under the License, as indicated by a | |
50 | - copyright notice that is included in or attached to the work | |
51 | - (an example is provided in the Appendix below). | |
52 | - | |
53 | - "Derivative Works" shall mean any work, whether in Source or Object | |
54 | - form, that is based on (or derived from) the Work and for which the | |
55 | - editorial revisions, annotations, elaborations, or other modifications | |
56 | - represent, as a whole, an original work of authorship. For the purposes | |
57 | - of this License, Derivative Works shall not include works that remain | |
58 | - separable from, or merely link (or bind by name) to the interfaces of, | |
59 | - the Work and Derivative Works thereof. | |
60 | - | |
61 | - "Contribution" shall mean any work of authorship, including | |
62 | - the original version of the Work and any modifications or additions | |
63 | - to that Work or Derivative Works thereof, that is intentionally | |
64 | - submitted to Licensor for inclusion in the Work by the copyright owner | |
65 | - or by an individual or Legal Entity authorized to submit on behalf of | |
66 | - the copyright owner. For the purposes of this definition, "submitted" | |
67 | - means any form of electronic, verbal, or written communication sent | |
68 | - to the Licensor or its representatives, including but not limited to | |
69 | - communication on electronic mailing lists, source code control systems, | |
70 | - and issue tracking systems that are managed by, or on behalf of, the | |
71 | - Licensor for the purpose of discussing and improving the Work, but | |
72 | - excluding communication that is conspicuously marked or otherwise | |
73 | - designated in writing by the copyright owner as "Not a Contribution." | |
74 | - | |
75 | - "Contributor" shall mean Licensor and any individual or Legal Entity | |
76 | - on behalf of whom a Contribution has been received by Licensor and | |
77 | - subsequently incorporated within the Work. | |
78 | - | |
79 | - 2. Grant of Copyright License. Subject to the terms and conditions of | |
80 | - this License, each Contributor hereby grants to You a perpetual, | |
81 | - worldwide, non-exclusive, no-charge, royalty-free, irrevocable | |
82 | - copyright license to reproduce, prepare Derivative Works of, | |
83 | - publicly display, publicly perform, sublicense, and distribute the | |
84 | - Work and such Derivative Works in Source or Object form. | |
85 | - | |
86 | - 3. Grant of Patent License. Subject to the terms and conditions of | |
87 | - this License, each Contributor hereby grants to You a perpetual, | |
88 | - worldwide, non-exclusive, no-charge, royalty-free, irrevocable | |
89 | - (except as stated in this section) patent license to make, have made, | |
90 | - use, offer to sell, sell, import, and otherwise transfer the Work, | |
91 | - where such license applies only to those patent claims licensable | |
92 | - by such Contributor that are necessarily infringed by their | |
93 | - Contribution(s) alone or by combination of their Contribution(s) | |
94 | - with the Work to which such Contribution(s) was submitted. If You | |
95 | - institute patent litigation against any entity (including a | |
96 | - cross-claim or counterclaim in a lawsuit) alleging that the Work | |
97 | - or a Contribution incorporated within the Work constitutes direct | |
98 | - or contributory patent infringement, then any patent licenses | |
99 | - granted to You under this License for that Work shall terminate | |
100 | - as of the date such litigation is filed. | |
101 | - | |
102 | - 4. Redistribution. You may reproduce and distribute copies of the | |
103 | - Work or Derivative Works thereof in any medium, with or without | |
104 | - modifications, and in Source or Object form, provided that You | |
105 | - meet the following conditions: | |
106 | - | |
107 | - (a) You must give any other recipients of the Work or | |
108 | - Derivative Works a copy of this License; and | |
109 | - | |
110 | - (b) You must cause any modified files to carry prominent notices | |
111 | - stating that You changed the files; and | |
112 | - | |
113 | - (c) You must retain, in the Source form of any Derivative Works | |
114 | - that You distribute, all copyright, patent, trademark, and | |
115 | - attribution notices from the Source form of the Work, | |
116 | - excluding those notices that do not pertain to any part of | |
117 | - the Derivative Works; and | |
118 | - | |
119 | - (d) If the Work includes a "NOTICE" text file as part of its | |
120 | - distribution, then any Derivative Works that You distribute must | |
121 | - include a readable copy of the attribution notices contained | |
122 | - within such NOTICE file, excluding those notices that do not | |
123 | - pertain to any part of the Derivative Works, in at least one | |
124 | - of the following places: within a NOTICE text file distributed | |
125 | - as part of the Derivative Works; within the Source form or | |
126 | - documentation, if provided along with the Derivative Works; or, | |
127 | - within a display generated by the Derivative Works, if and | |
128 | - wherever such third-party notices normally appear. The contents | |
129 | - of the NOTICE file are for informational purposes only and | |
130 | - do not modify the License. You may add Your own attribution | |
131 | - notices within Derivative Works that You distribute, alongside | |
132 | - or as an addendum to the NOTICE text from the Work, provided | |
133 | - that such additional attribution notices cannot be construed | |
134 | - as modifying the License. | |
135 | - | |
136 | - You may add Your own copyright statement to Your modifications and | |
137 | - may provide additional or different license terms and conditions | |
138 | - for use, reproduction, or distribution of Your modifications, or | |
139 | - for any such Derivative Works as a whole, provided Your use, | |
140 | - reproduction, and distribution of the Work otherwise complies with | |
141 | - the conditions stated in this License. | |
142 | - | |
143 | - 5. Submission of Contributions. Unless You explicitly state otherwise, | |
144 | - any Contribution intentionally submitted for inclusion in the Work | |
145 | - by You to the Licensor shall be under the terms and conditions of | |
146 | - this License, without any additional terms or conditions. | |
147 | - Notwithstanding the above, nothing herein shall supersede or modify | |
148 | - the terms of any separate license agreement you may have executed | |
149 | - with Licensor regarding such Contributions. | |
150 | - | |
151 | - 6. Trademarks. This License does not grant permission to use the trade | |
152 | - names, trademarks, service marks, or product names of the Licensor, | |
153 | - except as required for reasonable and customary use in describing the | |
154 | - origin of the Work and reproducing the content of the NOTICE file. | |
155 | - | |
156 | - 7. Disclaimer of Warranty. Unless required by applicable law or | |
157 | - agreed to in writing, Licensor provides the Work (and each | |
158 | - Contributor provides its Contributions) on an "AS IS" BASIS, | |
159 | - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | |
160 | - implied, including, without limitation, any warranties or conditions | |
161 | - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | |
162 | - PARTICULAR PURPOSE. You are solely responsible for determining the | |
163 | - appropriateness of using or redistributing the Work and assume any | |
164 | - risks associated with Your exercise of permissions under this License. | |
165 | - | |
166 | - 8. Limitation of Liability. In no event and under no legal theory, | |
167 | - whether in tort (including negligence), contract, or otherwise, | |
168 | - unless required by applicable law (such as deliberate and grossly | |
169 | - negligent acts) or agreed to in writing, shall any Contributor be | |
170 | - liable to You for damages, including any direct, indirect, special, | |
171 | - incidental, or consequential damages of any character arising as a | |
172 | - result of this License or out of the use or inability to use the | |
173 | - Work (including but not limited to damages for loss of goodwill, | |
174 | - work stoppage, computer failure or malfunction, or any and all | |
175 | - other commercial damages or losses), even if such Contributor | |
176 | - has been advised of the possibility of such damages. | |
177 | - | |
178 | - 9. Accepting Warranty or Additional Liability. While redistributing | |
179 | - the Work or Derivative Works thereof, You may choose to offer, | |
180 | - and charge a fee for, acceptance of support, warranty, indemnity, | |
181 | - or other liability obligations and/or rights consistent with this | |
182 | - License. However, in accepting such obligations, You may act only | |
183 | - on Your own behalf and on Your sole responsibility, not on behalf | |
184 | - of any other Contributor, and only if You agree to indemnify, | |
185 | - defend, and hold each Contributor harmless for any liability | |
186 | - incurred by, or claims asserted against, such Contributor by reason | |
187 | - of your accepting any such warranty or additional liability. | |
188 | - | |
189 | - END OF TERMS AND CONDITIONS | |
190 | - |
@@ -1,177 +0,0 @@ | ||
1 | -# Copyright (C) 2009 The Android Open Source Project | |
2 | -# | |
3 | -# Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | -# you may not use this file except in compliance with the License. | |
5 | -# You may obtain a copy of the License at | |
6 | -# | |
7 | -# http://www.apache.org/licenses/LICENSE-2.0 | |
8 | -# | |
9 | -# Unless required by applicable law or agreed to in writing, software | |
10 | -# distributed under the License is distributed on an "AS IS" BASIS, | |
11 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | -# See the License for the specific language governing permissions and | |
13 | -# limitations under the License. | |
14 | -# | |
15 | - | |
16 | -############################## | |
17 | -######### CONTENTS ########### | |
18 | -A. INTRODUCTION | |
19 | -B. PLUGIN STRUCTURE | |
20 | -C. HOW TO DEPLOY | |
21 | -D. SUB-PLUGINS | |
22 | - 1. ANIMATION | |
23 | - 2. AUDIO | |
24 | - 3. BACKGROUND | |
25 | - 4. FORM | |
26 | - 5. PAINT | |
27 | - | |
28 | - | |
29 | -############################## | |
30 | -## (A) INTRODUCTION ########## | |
31 | - | |
32 | -The sample plugin is intended to give plugin developers a point of reference to | |
33 | -see how an android browser plugin is created and how to use the available APIs. | |
34 | -A plugin is packaged like a standard apk and can be installed either via the | |
35 | -market or adb. The sample plugin attempts to exercise as many of the APIs as | |
36 | -possible but unfortunately not all are covered. | |
37 | - | |
38 | -Trying to have a single plugin demonstrate all possible API interactions on one | |
39 | -screen was not practical. On the other hand we also didn't want a separate | |
40 | -plugin for each interction, as that would result in many separate apk's that | |
41 | -would need to be maintained. To solve this problem we developed the idea to use | |
42 | -"sub-plugins". With a sub-plugin only one specific feature of the plugin would | |
43 | -be active at a time, but they would all share as much common code as possible. | |
44 | -A detailed description of each sub-plugin and its function can be found in the | |
45 | -sub-plugins section. | |
46 | - | |
47 | -############################## | |
48 | -## (B) PLUGIN STRUCTURE ###### | |
49 | - | |
50 | -The sample plugin is packaged as one plugin but contains many unique sub-plugins | |
51 | -(e.g. audio and paint). The package consists of two pieces: (1) Java code | |
52 | -containing the config; (2) C++ shared library containing the brower/plugin | |
53 | -bindings and the sub-plugin classes. | |
54 | - | |
55 | -~~~~ (1) JAVA ~~~~~ | |
56 | -Android.mk: specifies the name of the APK (SampleBrowserPlugin) as well as which | |
57 | - shared libraries to include. | |
58 | - | |
59 | -AndroidManifest.xml: similar to a standard android manifest file, except that it | |
60 | - must contain the "uses-permission" and "service" | |
61 | - elements that are plugin specific. The "service" element | |
62 | - contains sub-elements that describe the java component of | |
63 | - the service. | |
64 | - | |
65 | -src/*: location of the java source files. This contains the SamplePlugin.class | |
66 | - which is the java component of our plugin. The component must exist and | |
67 | - implement the required interfaces, though simply returning null is valid. | |
68 | - | |
69 | -res/*: location of the static resources (e.g. an icon for the plugin) | |
70 | - | |
71 | -~~~~ (2) C++ ~~~~~ | |
72 | -jni/Android.mk: specifies the build parameters for the shared library that is to | |
73 | - be included with the apk. The library contains all the bindings | |
74 | - between the plugin and the browser. | |
75 | - | |
76 | -jni/main.*: this code is the binding point between the plugin and the browser. | |
77 | - It supports all of the functions required for a standard netscape | |
78 | - style plugin as well as all the android specific APIs. The initial | |
79 | - starting point for the plugin is the NP_Initialize function. The | |
80 | - NPP_New function is responsible for reading the input args and | |
81 | - selecting the appropriate sub-plugin to instantiate. Most other | |
82 | - functions either return fixed values or pass their inputs to the | |
83 | - sub-plugin for processing. | |
84 | - | |
85 | -jni/PluginObject.*: The pluginObject provides a convenient container in which to | |
86 | - store variables (the plugin's state). This objects two main | |
87 | - responsibilities are (1) to construct and store the NPClass | |
88 | - object (done using code provided by Apple) and (2) provide | |
89 | - the abstract class for the sub-plugin objects and a place to | |
90 | - store the sub-plugin after it is instantiated. | |
91 | - | |
92 | -jni/*/*: Each of the sub-plugins has a folder that contains its class definition | |
93 | - and logic. The sub-plugin receives events from the browser and it can | |
94 | - also communicate with the browser using the netscape plugin functions | |
95 | - as well as the specialized android interfaces. | |
96 | - | |
97 | - | |
98 | -############################## | |
99 | -## (C) HOW TO DEPLOY ######### | |
100 | - | |
101 | -To compile and install a plugin on a device/emulator simply... | |
102 | - | |
103 | -1. run "make SampleBrowserPlugin" (compiles libsampleplugin.so and builds the apk) | |
104 | -2. the previous command produces an apk file so record its location | |
105 | -3. run "adb install [apk_file]" to install it on a device/emulator | |
106 | -4. the browser will auto recognize the plugin is available | |
107 | - | |
108 | -Now that the plugin is installed you can manage it just like you would any other | |
109 | -application via Settings -> Applications -> Manage applications. To execute the | |
110 | -plugin you need to include an html snippet (similar to the one found below) in | |
111 | -a document that is accessible by the browser. The mime-type cannot change but | |
112 | -you can change the width, height, and parameters. The parameters are used to | |
113 | -notify the plugin which sub-plugin to execute and which drawing model to use. | |
114 | - | |
115 | -<object type="application/x-testbrowserplugin" height=50 width=250> | |
116 | - <param name="DrawingModel" value="Surface" /> | |
117 | - <param name="PluginType" value="Background" /> | |
118 | -</object> | |
119 | - | |
120 | - | |
121 | -############################## | |
122 | -## (D) SUB-PLUGINS ########### | |
123 | - | |
124 | -Each sub-plugin corresponds to exactly one plugin type and can support one or | |
125 | -more drawing models. In the subsections below there are descriptions of each of | |
126 | -the sub-plugins as well as the information required to create the html snippets. | |
127 | - | |
128 | -####################### | |
129 | -## (D1) ANIMATION ##### | |
130 | - | |
131 | -PLUGIN TYPE: Animation | |
132 | -DRAWING MODEL: Bitmap | |
133 | - | |
134 | -This plugin draws a ball bouncing around the screen. If the plugin is not entirely | |
135 | -on the screen and it it touched, then it will attempt to center itself on screen. | |
136 | - | |
137 | -####################### | |
138 | -## (D2) AUDIO ######### | |
139 | - | |
140 | -PLUGIN TYPE: Audio | |
141 | -DRAWING MODEL: Bitmap | |
142 | - | |
143 | -This plugin plays a raw audio file located at /sdcard/sample.raw (need to supply | |
144 | -your own). It uses touch to trigger the play, pause, and stop buttons. | |
145 | - | |
146 | -####################### | |
147 | -## (D3) BACKGROUND #### | |
148 | - | |
149 | -PLUGIN TYPE: Background | |
150 | -DRAWING MODEL: Surface | |
151 | - | |
152 | -This plugin has minimal visual components but mainly runs API tests in the | |
153 | -background. The plugin handles scaling its own bitmap on zoom which in this | |
154 | -case is a simple string of text. The output of this plugin is found in the logs | |
155 | -as it prints errors if it detects any API failures. Some of the API's tested are | |
156 | -timers, javascript access, and bitmap formatting. | |
157 | - | |
158 | -####################### | |
159 | -## (D4) FORM ########## | |
160 | - | |
161 | -PLUGIN TYPE: Form | |
162 | -DRAWING MODEL: Bitmap | |
163 | - | |
164 | -This plugin mimics a simple username/password form. You can select a textbox by | |
165 | -either touching it or using the navigation keys. Once selected the box will | |
166 | -highlight and the keyboard will appear. If the textbox selected is not fully | |
167 | -in view then the plugin will ensure it is centered on the screen. | |
168 | - | |
169 | -####################### | |
170 | -## (D5) PAINT ######### | |
171 | - | |
172 | -PLUGIN TYPE: Paint | |
173 | -DRAWING MODEL: Surface | |
174 | - | |
175 | -This plugin provides a surface that the user can "paint" on. The inputs method | |
176 | -can be toggled between mouse (dots) and touch (lines). This plugin has a fixed | |
177 | -surface and allows the browser to scale the surface when zooming. |
@@ -1,68 +0,0 @@ | ||
1 | -## | |
2 | -## | |
3 | -## Copyright 2008, The Android Open Source Project | |
4 | -## | |
5 | -## Redistribution and use in source and binary forms, with or without | |
6 | -## modification, are permitted provided that the following conditions | |
7 | -## are met: | |
8 | -## * Redistributions of source code must retain the above copyright | |
9 | -## notice, this list of conditions and the following disclaimer. | |
10 | -## * Redistributions in binary form must reproduce the above copyright | |
11 | -## notice, this list of conditions and the following disclaimer in the | |
12 | -## documentation and/or other materials provided with the distribution. | |
13 | -## | |
14 | -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
15 | -## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
16 | -## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
17 | -## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
18 | -## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
19 | -## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
20 | -## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
21 | -## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
22 | -## OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 | -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
24 | -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 | -## | |
26 | - | |
27 | -LOCAL_PATH:= $(call my-dir) | |
28 | -include $(CLEAR_VARS) | |
29 | - | |
30 | -LOCAL_SRC_FILES := \ | |
31 | - main.cpp \ | |
32 | - PluginObject.cpp \ | |
33 | - animation/AnimationPlugin.cpp \ | |
34 | - audio/AudioPlugin.cpp \ | |
35 | - background/BackgroundPlugin.cpp \ | |
36 | - form/FormPlugin.cpp \ | |
37 | - navigation/NavigationPlugin.cpp \ | |
38 | - paint/PaintPlugin.cpp \ | |
39 | - video/VideoPlugin.cpp \ | |
40 | - jni-bridge.cpp \ | |
41 | - | |
42 | -LOCAL_C_INCLUDES += \ | |
43 | - $(JNI_H_INCLUDE) \ | |
44 | - $(LOCAL_PATH) \ | |
45 | - $(LOCAL_PATH)/animation \ | |
46 | - $(LOCAL_PATH)/audio \ | |
47 | - $(LOCAL_PATH)/background \ | |
48 | - $(LOCAL_PATH)/form \ | |
49 | - $(LOCAL_PATH)/navigation \ | |
50 | - $(LOCAL_PATH)/paint \ | |
51 | - $(LOCAL_PATH)/video \ | |
52 | - external/webkit/WebCore/bridge \ | |
53 | - external/webkit/WebCore/plugins \ | |
54 | - external/webkit/WebCore/platform/android/JavaVM \ | |
55 | - external/webkit/WebKit/android/plugins | |
56 | - | |
57 | -LOCAL_SHARED_LIBRARIES := \ | |
58 | - libnativehelper | |
59 | - | |
60 | -LOCAL_CFLAGS += -fvisibility=hidden | |
61 | -LOCAL_PRELINK_MODULE:=false | |
62 | - | |
63 | -LOCAL_MODULE:= libsampleplugin | |
64 | - | |
65 | -LOCAL_MODULE_TAGS := optional | |
66 | - | |
67 | -include $(BUILD_SHARED_LIBRARY) | |
68 | - |
@@ -1,211 +0,0 @@ | ||
1 | -/* | |
2 | - IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in | |
3 | - consideration of your agreement to the following terms, and your use, installation, | |
4 | - modification or redistribution of this Apple software constitutes acceptance of these | |
5 | - terms. If you do not agree with these terms, please do not use, install, modify or | |
6 | - redistribute this Apple software. | |
7 | - | |
8 | - In consideration of your agreement to abide by the following terms, and subject to these | |
9 | - terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in | |
10 | - this original Apple software (the "Apple Software"), to use, reproduce, modify and | |
11 | - redistribute the Apple Software, with or without modifications, in source and/or binary | |
12 | - forms; provided that if you redistribute the Apple Software in its entirety and without | |
13 | - modifications, you must retain this notice and the following text and disclaimers in all | |
14 | - such redistributions of the Apple Software. Neither the name, trademarks, service marks | |
15 | - or logos of Apple Computer, Inc. may be used to endorse or promote products derived from | |
16 | - the Apple Software without specific prior written permission from Apple. Except as expressly | |
17 | - stated in this notice, no other rights or licenses, express or implied, are granted by Apple | |
18 | - herein, including but not limited to any patent rights that may be infringed by your | |
19 | - derivative works or by other works in which the Apple Software may be incorporated. | |
20 | - | |
21 | - The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, | |
22 | - EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, | |
23 | - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS | |
24 | - USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. | |
25 | - | |
26 | - IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL | |
27 | - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | |
28 | - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, | |
29 | - REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND | |
30 | - WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR | |
31 | - OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
32 | - */ | |
33 | - | |
34 | -#include <stdlib.h> | |
35 | -#include "main.h" | |
36 | -#include "PluginObject.h" | |
37 | - | |
38 | -int SubPlugin::getPluginWidth() { | |
39 | - PluginObject *obj = (PluginObject*) inst()->pdata; | |
40 | - return obj->window->width; | |
41 | -} | |
42 | - | |
43 | -int SubPlugin::getPluginHeight() { | |
44 | - PluginObject *obj = (PluginObject*) inst()->pdata; | |
45 | - return obj->window->height; | |
46 | -} | |
47 | - | |
48 | -bool SurfaceSubPlugin::supportsDrawingModel(ANPDrawingModel model) { | |
49 | - return (model == kSurface_ANPDrawingModel); | |
50 | -} | |
51 | - | |
52 | -void SurfaceSubPlugin::setContext(jobject context) { | |
53 | - JNIEnv* env = NULL; | |
54 | - if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) == JNI_OK) { | |
55 | - | |
56 | - // if one exists then free its global reference | |
57 | - if (m_context) { | |
58 | - env->DeleteGlobalRef(m_context); | |
59 | - m_context = NULL; | |
60 | - } | |
61 | - | |
62 | - // create a new global ref | |
63 | - if (context) { | |
64 | - context = env->NewGlobalRef(context); | |
65 | - } | |
66 | - | |
67 | - // set the value | |
68 | - m_context = context; | |
69 | - } | |
70 | -} | |
71 | - | |
72 | -static void pluginInvalidate(NPObject *obj); | |
73 | -static bool pluginHasProperty(NPObject *obj, NPIdentifier name); | |
74 | -static bool pluginHasMethod(NPObject *obj, NPIdentifier name); | |
75 | -static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant); | |
76 | -static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant); | |
77 | -static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result); | |
78 | -static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result); | |
79 | -static NPObject *pluginAllocate(NPP npp, NPClass *theClass); | |
80 | -static void pluginDeallocate(NPObject *obj); | |
81 | -static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name); | |
82 | -static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count); | |
83 | - | |
84 | - | |
85 | - | |
86 | -static NPClass pluginClass = { | |
87 | - NP_CLASS_STRUCT_VERSION, | |
88 | - pluginAllocate, | |
89 | - pluginDeallocate, | |
90 | - pluginInvalidate, | |
91 | - pluginHasMethod, | |
92 | - pluginInvoke, | |
93 | - pluginInvokeDefault, | |
94 | - pluginHasProperty, | |
95 | - pluginGetProperty, | |
96 | - pluginSetProperty, | |
97 | - pluginRemoveProperty, | |
98 | - pluginEnumerate | |
99 | -}; | |
100 | - | |
101 | -NPClass *getPluginClass(void) | |
102 | -{ | |
103 | - return &pluginClass; | |
104 | -} | |
105 | - | |
106 | -static bool identifiersInitialized = false; | |
107 | - | |
108 | -#define ID_TESTFILE_PROPERTY 0 | |
109 | -#define NUM_PROPERTY_IDENTIFIERS 1 | |
110 | - | |
111 | -static NPIdentifier pluginPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS]; | |
112 | -static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = { | |
113 | - "testfile" | |
114 | -}; | |
115 | - | |
116 | -#define ID_GETTESTFILE_METHOD 0 | |
117 | -#define NUM_METHOD_IDENTIFIERS 1 | |
118 | - | |
119 | -static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS]; | |
120 | -static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = { | |
121 | - "getTestFile" | |
122 | -}; | |
123 | - | |
124 | -static void initializeIdentifiers(void) | |
125 | -{ | |
126 | - browser->getstringidentifiers(pluginPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, pluginPropertyIdentifiers); | |
127 | - browser->getstringidentifiers(pluginMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, pluginMethodIdentifiers); | |
128 | -} | |
129 | - | |
130 | -static bool pluginHasProperty(NPObject *obj, NPIdentifier name) | |
131 | -{ | |
132 | - int i; | |
133 | - for (i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++) | |
134 | - if (name == pluginPropertyIdentifiers[i]) | |
135 | - return true; | |
136 | - return false; | |
137 | -} | |
138 | - | |
139 | -static bool pluginHasMethod(NPObject *obj, NPIdentifier name) | |
140 | -{ | |
141 | - int i; | |
142 | - for (i = 0; i < NUM_METHOD_IDENTIFIERS; i++) | |
143 | - if (name == pluginMethodIdentifiers[i]) | |
144 | - return true; | |
145 | - return false; | |
146 | -} | |
147 | - | |
148 | -static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant) | |
149 | -{ | |
150 | - PluginObject *plugin = (PluginObject *)obj; | |
151 | - if (name == pluginPropertyIdentifiers[ID_TESTFILE_PROPERTY]) { | |
152 | - BOOLEAN_TO_NPVARIANT(true, *variant); | |
153 | - return true; | |
154 | - } | |
155 | - return false; | |
156 | -} | |
157 | - | |
158 | -static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant) | |
159 | -{ | |
160 | - return false; | |
161 | -} | |
162 | - | |
163 | -static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) | |
164 | -{ | |
165 | - PluginObject *plugin = (PluginObject *)obj; | |
166 | - if (name == pluginMethodIdentifiers[ID_GETTESTFILE_METHOD]) { | |
167 | - return true; | |
168 | - } | |
169 | - return false; | |
170 | -} | |
171 | - | |
172 | -static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result) | |
173 | -{ | |
174 | - return false; | |
175 | -} | |
176 | - | |
177 | -static void pluginInvalidate(NPObject *obj) | |
178 | -{ | |
179 | - // Release any remaining references to JavaScript objects. | |
180 | -} | |
181 | - | |
182 | -static NPObject *pluginAllocate(NPP npp, NPClass *theClass) | |
183 | -{ | |
184 | - PluginObject *newInstance = (PluginObject*) malloc(sizeof(PluginObject)); | |
185 | - newInstance->header._class = theClass; | |
186 | - newInstance->header.referenceCount = 1; | |
187 | - | |
188 | - if (!identifiersInitialized) { | |
189 | - identifiersInitialized = true; | |
190 | - initializeIdentifiers(); | |
191 | - } | |
192 | - | |
193 | - newInstance->npp = npp; | |
194 | - | |
195 | - return &newInstance->header; | |
196 | -} | |
197 | - | |
198 | -static void pluginDeallocate(NPObject *obj) | |
199 | -{ | |
200 | - free(obj); | |
201 | -} | |
202 | - | |
203 | -static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name) | |
204 | -{ | |
205 | - return false; | |
206 | -} | |
207 | - | |
208 | -static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count) | |
209 | -{ | |
210 | - return false; | |
211 | -} |
@@ -1,99 +0,0 @@ | ||
1 | -/* | |
2 | - IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in | |
3 | - consideration of your agreement to the following terms, and your use, installation, | |
4 | - modification or redistribution of this Apple software constitutes acceptance of these | |
5 | - terms. If you do not agree with these terms, please do not use, install, modify or | |
6 | - redistribute this Apple software. | |
7 | - | |
8 | - In consideration of your agreement to abide by the following terms, and subject to these | |
9 | - terms, Apple grants you a personal, non-exclusive license, under Apple�s copyrights in | |
10 | - this original Apple software (the "Apple Software"), to use, reproduce, modify and | |
11 | - redistribute the Apple Software, with or without modifications, in source and/or binary | |
12 | - forms; provided that if you redistribute the Apple Software in its entirety and without | |
13 | - modifications, you must retain this notice and the following text and disclaimers in all | |
14 | - such redistributions of the Apple Software. Neither the name, trademarks, service marks | |
15 | - or logos of Apple Computer, Inc. may be used to endorse or promote products derived from | |
16 | - the Apple Software without specific prior written permission from Apple. Except as expressly | |
17 | - stated in this notice, no other rights or licenses, express or implied, are granted by Apple | |
18 | - herein, including but not limited to any patent rights that may be infringed by your | |
19 | - derivative works or by other works in which the Apple Software may be incorporated. | |
20 | - | |
21 | - The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, | |
22 | - EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, | |
23 | - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS | |
24 | - USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. | |
25 | - | |
26 | - IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL | |
27 | - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | |
28 | - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, | |
29 | - REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND | |
30 | - WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR | |
31 | - OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
32 | - */ | |
33 | - | |
34 | -#ifndef PluginObject__DEFINED | |
35 | -#define PluginObject__DEFINED | |
36 | - | |
37 | -#include "main.h" | |
38 | -#include <jni.h> | |
39 | - | |
40 | -enum CustomEventTypes { | |
41 | - kSurfaceCreated_CustomEvent = 0, | |
42 | - kSurfaceChanged_CustomEvent = 1, | |
43 | - kSurfaceDestroyed_CustomEvent = 2, | |
44 | -}; | |
45 | -typedef int32_t CustomEventType; | |
46 | - | |
47 | -class SubPlugin { | |
48 | -public: | |
49 | - SubPlugin(NPP inst) : m_inst(inst) {} | |
50 | - virtual ~SubPlugin() {} | |
51 | - virtual int16 handleEvent(const ANPEvent* evt) = 0; | |
52 | - virtual bool supportsDrawingModel(ANPDrawingModel) = 0; | |
53 | - | |
54 | - int getPluginWidth(); | |
55 | - int getPluginHeight(); | |
56 | - | |
57 | - NPP inst() const { return m_inst; } | |
58 | - | |
59 | -private: | |
60 | - NPP m_inst; | |
61 | -}; | |
62 | - | |
63 | -class SurfaceSubPlugin : public SubPlugin { | |
64 | -public: | |
65 | - SurfaceSubPlugin(NPP inst) : SubPlugin(inst) { m_context = NULL; } | |
66 | - virtual ~SurfaceSubPlugin() {} | |
67 | - virtual jobject getSurface() = 0; | |
68 | - virtual bool supportsDrawingModel(ANPDrawingModel); | |
69 | - | |
70 | - void setContext(jobject context); | |
71 | - | |
72 | - jobject m_context; | |
73 | -}; | |
74 | - | |
75 | -enum PluginTypes { | |
76 | - kAnimation_PluginType = 1, | |
77 | - kAudio_PluginType = 2, | |
78 | - kBackground_PluginType = 3, | |
79 | - kForm_PluginType = 4, | |
80 | - kText_PluginType = 5, | |
81 | - kPaint_PluginType = 6, | |
82 | - kVideo_PluginType = 7, | |
83 | - kNavigation_PluginType = 8, | |
84 | -}; | |
85 | -typedef uint32_t PluginType; | |
86 | - | |
87 | -typedef struct PluginObject { | |
88 | - NPObject header; | |
89 | - NPP npp; | |
90 | - NPWindow* window; | |
91 | - | |
92 | - PluginType pluginType; | |
93 | - SubPlugin* activePlugin; | |
94 | - | |
95 | -} PluginObject; | |
96 | - | |
97 | -NPClass *getPluginClass(void); | |
98 | - | |
99 | -#endif // PluginObject__DEFINED |
@@ -1,197 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2008, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "AnimationPlugin.h" | |
27 | - | |
28 | -#include <math.h> | |
29 | -#include <string.h> | |
30 | - | |
31 | -extern NPNetscapeFuncs* browser; | |
32 | -extern ANPLogInterfaceV0 gLogI; | |
33 | -extern ANPCanvasInterfaceV0 gCanvasI; | |
34 | -extern ANPPaintInterfaceV0 gPaintI; | |
35 | -extern ANPPathInterfaceV0 gPathI; | |
36 | -extern ANPWindowInterfaceV0 gWindowI; | |
37 | - | |
38 | -static uint16 rnd16(float x, int inset) { | |
39 | - int ix = (int)roundf(x) + inset; | |
40 | - if (ix < 0) { | |
41 | - ix = 0; | |
42 | - } | |
43 | - return static_cast<uint16>(ix); | |
44 | -} | |
45 | - | |
46 | -static void inval(NPP instance, const ANPRectF& r, bool doAA) { | |
47 | - const int inset = doAA ? -1 : 0; | |
48 | - | |
49 | - NPRect inval; | |
50 | - inval.left = rnd16(r.left, inset); | |
51 | - inval.top = rnd16(r.top, inset); | |
52 | - inval.right = rnd16(r.right, -inset); | |
53 | - inval.bottom = rnd16(r.bottom, -inset); | |
54 | - browser->invalidaterect(instance, &inval); | |
55 | -} | |
56 | - | |
57 | -static void bounce(float* x, float* dx, const float max) { | |
58 | - *x += *dx; | |
59 | - if (*x < 0) { | |
60 | - *x = 0; | |
61 | - if (*dx < 0) { | |
62 | - *dx = -*dx; | |
63 | - } | |
64 | - } else if (*x > max) { | |
65 | - *x = max; | |
66 | - if (*dx > 0) { | |
67 | - *dx = -*dx; | |
68 | - } | |
69 | - } | |
70 | -} | |
71 | -/////////////////////////////////////////////////////////////////////////////// | |
72 | - | |
73 | -BallAnimation::BallAnimation(NPP inst) : SubPlugin(inst) { | |
74 | - m_x = m_y = 0; | |
75 | - m_dx = 7 * SCALE; | |
76 | - m_dy = 5 * SCALE; | |
77 | - | |
78 | - memset(&m_oval, 0, sizeof(m_oval)); | |
79 | - | |
80 | - m_paint = gPaintI.newPaint(); | |
81 | - gPaintI.setFlags(m_paint, gPaintI.getFlags(m_paint) | kAntiAlias_ANPPaintFlag); | |
82 | - gPaintI.setColor(m_paint, 0xFFFF0000); | |
83 | - | |
84 | - //register for touch events | |
85 | - ANPEventFlags flags = kTouch_ANPEventFlag; | |
86 | - NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); | |
87 | - if (err != NPERR_NO_ERROR) { | |
88 | - gLogI.log(kError_ANPLogType, "Error selecting input events."); | |
89 | - } | |
90 | -} | |
91 | - | |
92 | -BallAnimation::~BallAnimation() { | |
93 | - gPaintI.deletePaint(m_paint); | |
94 | -} | |
95 | - | |
96 | -bool BallAnimation::supportsDrawingModel(ANPDrawingModel model) { | |
97 | - return (model == kBitmap_ANPDrawingModel); | |
98 | -} | |
99 | - | |
100 | -void BallAnimation::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) { | |
101 | - | |
102 | - // create a canvas | |
103 | - ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap); | |
104 | - | |
105 | - // clip the canvas | |
106 | - ANPRectF clipR; | |
107 | - clipR.left = clip.left; | |
108 | - clipR.top = clip.top; | |
109 | - clipR.right = clip.right; | |
110 | - clipR.bottom = clip.bottom; | |
111 | - gCanvasI.clipRect(canvas, &clipR); | |
112 | - | |
113 | - // setup variables | |
114 | - PluginObject *obj = (PluginObject*) inst()->pdata; | |
115 | - const float OW = 20; | |
116 | - const float OH = 20; | |
117 | - const int W = obj->window->width; | |
118 | - const int H = obj->window->height; | |
119 | - | |
120 | - // paint the canvas (using the path API) | |
121 | - gCanvasI.drawColor(canvas, 0xFFFFFFFF); | |
122 | - { | |
123 | - ANPPath* path = gPathI.newPath(); | |
124 | - | |
125 | - float cx = W * 0.5f; | |
126 | - float cy = H * 0.5f; | |
127 | - gPathI.moveTo(path, 0, 0); | |
128 | - gPathI.quadTo(path, cx, cy, W, 0); | |
129 | - gPathI.quadTo(path, cx, cy, W, H); | |
130 | - gPathI.quadTo(path, cx, cy, 0, H); | |
131 | - gPathI.quadTo(path, cx, cy, 0, 0); | |
132 | - | |
133 | - gPaintI.setColor(m_paint, 0xFF0000FF); | |
134 | - gCanvasI.drawPath(canvas, path, m_paint); | |
135 | - | |
136 | - ANPRectF bounds; | |
137 | - memset(&bounds, 0, sizeof(bounds)); | |
138 | - gPathI.getBounds(path, &bounds); | |
139 | - gPathI.deletePath(path); | |
140 | - } | |
141 | - | |
142 | - // draw the oval | |
143 | - inval(inst(), m_oval, true); // inval the old | |
144 | - m_oval.left = m_x; | |
145 | - m_oval.top = m_y; | |
146 | - m_oval.right = m_x + OW; | |
147 | - m_oval.bottom = m_y + OH; | |
148 | - inval(inst(), m_oval, true); // inval the new | |
149 | - gPaintI.setColor(m_paint, 0xFFFF0000); | |
150 | - gCanvasI.drawOval(canvas, &m_oval, m_paint); | |
151 | - | |
152 | - // update the coordinates of the oval | |
153 | - bounce(&m_x, &m_dx, obj->window->width - OW); | |
154 | - bounce(&m_y, &m_dy, obj->window->height - OH); | |
155 | - | |
156 | - // delete the canvas | |
157 | - gCanvasI.deleteCanvas(canvas); | |
158 | -} | |
159 | - | |
160 | -void BallAnimation::showEntirePluginOnScreen() { | |
161 | - NPP instance = this->inst(); | |
162 | - PluginObject *obj = (PluginObject*) instance->pdata; | |
163 | - NPWindow *window = obj->window; | |
164 | - | |
165 | - ANPRectI visibleRects[1]; | |
166 | - | |
167 | - visibleRects[0].left = 0; | |
168 | - visibleRects[0].top = 0; | |
169 | - visibleRects[0].right = window->width; | |
170 | - visibleRects[0].bottom = window->height; | |
171 | - | |
172 | - gWindowI.setVisibleRects(instance, visibleRects, 1); | |
173 | - gWindowI.clearVisibleRects(instance); | |
174 | -} | |
175 | - | |
176 | -int16 BallAnimation::handleEvent(const ANPEvent* evt) { | |
177 | - NPP instance = this->inst(); | |
178 | - | |
179 | - switch (evt->eventType) { | |
180 | - case kDraw_ANPEventType: | |
181 | - switch (evt->data.draw.model) { | |
182 | - case kBitmap_ANPDrawingModel: | |
183 | - drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip); | |
184 | - return 1; | |
185 | - default: | |
186 | - break; // unknown drawing model | |
187 | - } | |
188 | - case kTouch_ANPEventType: | |
189 | - if (kDown_ANPTouchAction == evt->data.touch.action) { | |
190 | - showEntirePluginOnScreen(); | |
191 | - } | |
192 | - return 1; | |
193 | - default: | |
194 | - break; | |
195 | - } | |
196 | - return 0; // unknown or unhandled event | |
197 | -} |
@@ -1,52 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2008, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "PluginObject.h" | |
27 | - | |
28 | -#ifndef pluginGraphics__DEFINED | |
29 | -#define pluginGraphics__DEFINED | |
30 | - | |
31 | -class BallAnimation : public SubPlugin { | |
32 | -public: | |
33 | - BallAnimation(NPP inst); | |
34 | - virtual ~BallAnimation(); | |
35 | - virtual bool supportsDrawingModel(ANPDrawingModel); | |
36 | - virtual int16 handleEvent(const ANPEvent* evt); | |
37 | -private: | |
38 | - void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip); | |
39 | - void showEntirePluginOnScreen(); | |
40 | - | |
41 | - float m_x; | |
42 | - float m_y; | |
43 | - float m_dx; | |
44 | - float m_dy; | |
45 | - | |
46 | - ANPRectF m_oval; | |
47 | - ANPPaint* m_paint; | |
48 | - | |
49 | - static const float SCALE = 0.1; | |
50 | -}; | |
51 | - | |
52 | -#endif // pluginGraphics__DEFINED |
@@ -1,382 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2008, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "AudioPlugin.h" | |
27 | - | |
28 | -#include <fcntl.h> | |
29 | -#include <sys/stat.h> | |
30 | -#include <sys/time.h> | |
31 | -#include <time.h> | |
32 | -#include <math.h> | |
33 | -#include <string.h> | |
34 | - | |
35 | -extern NPNetscapeFuncs* browser; | |
36 | -extern ANPLogInterfaceV0 gLogI; | |
37 | -extern ANPCanvasInterfaceV0 gCanvasI; | |
38 | -extern ANPPaintInterfaceV0 gPaintI; | |
39 | -extern ANPAudioTrackInterfaceV0 gSoundI; | |
40 | -extern ANPTypefaceInterfaceV0 gTypefaceI; | |
41 | - | |
42 | - | |
43 | -static void inval(NPP instance) { | |
44 | - browser->invalidaterect(instance, NULL); | |
45 | -} | |
46 | - | |
47 | -static uint16 rnd16(float x, int inset) { | |
48 | - int ix = (int)roundf(x) + inset; | |
49 | - if (ix < 0) { | |
50 | - ix = 0; | |
51 | - } | |
52 | - return static_cast<uint16>(ix); | |
53 | -} | |
54 | - | |
55 | -static void inval(NPP instance, const ANPRectF& r, bool doAA) { | |
56 | - const int inset = doAA ? -1 : 0; | |
57 | - | |
58 | - PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata); | |
59 | - NPRect inval; | |
60 | - inval.left = rnd16(r.left, inset); | |
61 | - inval.top = rnd16(r.top, inset); | |
62 | - inval.right = rnd16(r.right, -inset); | |
63 | - inval.bottom = rnd16(r.bottom, -inset); | |
64 | - browser->invalidaterect(instance, &inval); | |
65 | -} | |
66 | - | |
67 | -static void audioCallback(ANPAudioEvent evt, void* user, ANPAudioBuffer* buffer) { | |
68 | - switch (evt) { | |
69 | - case kMoreData_ANPAudioEvent: { | |
70 | - SoundPlay* play = reinterpret_cast<SoundPlay*>(user); | |
71 | - size_t amount = fread(buffer->bufferData, 1, buffer->size, play->file); | |
72 | - buffer->size = amount; | |
73 | - if (amount == 0) { | |
74 | - gSoundI.stop(play->track); | |
75 | - fclose(play->file); | |
76 | - play->file = NULL; | |
77 | - // TODO need to notify our main thread to delete the track now | |
78 | - } | |
79 | - | |
80 | - if (play->fileSize > 0) { | |
81 | - // TODO we need to properly update the progress value | |
82 | - play->progress = 1; | |
83 | - inval(play->instance); | |
84 | - } | |
85 | - | |
86 | - | |
87 | - break; | |
88 | - } | |
89 | - default: | |
90 | - break; | |
91 | - } | |
92 | -} | |
93 | - | |
94 | -/////////////////////////////////////////////////////////////////////////////// | |
95 | - | |
96 | -AudioPlugin::AudioPlugin(NPP inst) : SubPlugin(inst) { | |
97 | - | |
98 | - const char path[] = "/sdcard/sample.raw"; | |
99 | - | |
100 | - // open a file stream | |
101 | - FILE* f = fopen(path, "r"); | |
102 | - gLogI.log(kDebug_ANPLogType, "--- path %s FILE %p", path, f); | |
103 | - | |
104 | - // setup our private audio struct's default values | |
105 | - m_soundPlay = new SoundPlay; | |
106 | - m_soundPlay->instance = inst; | |
107 | - m_soundPlay->progress = 0; | |
108 | - m_soundPlay->fileSize = 0; | |
109 | - m_soundPlay->file = f; | |
110 | - m_soundPlay->track = NULL; | |
111 | - | |
112 | - // create the audio track | |
113 | - if (f) { | |
114 | - m_soundPlay->track = gSoundI.newTrack(44100, kPCM16Bit_ANPSampleFormat, 2, audioCallback, m_soundPlay); | |
115 | - if (!m_soundPlay->track) { | |
116 | - fclose(f); | |
117 | - m_soundPlay->file = NULL; | |
118 | - } | |
119 | - } | |
120 | - | |
121 | - // get the audio file's size | |
122 | - int fileDescriptor = open(path, O_RDONLY); | |
123 | - struct stat fileStatus; | |
124 | - | |
125 | - if(fileDescriptor <= 0) { | |
126 | - gLogI.log(kError_ANPLogType, "fopen error"); | |
127 | - } | |
128 | - else if (fstat(fileDescriptor, &fileStatus) != 0) { | |
129 | - gLogI.log(kDebug_ANPLogType, "File Size: %d", fileStatus.st_size); | |
130 | - m_soundPlay->fileSize = fileStatus.st_size; | |
131 | - } else { | |
132 | - gLogI.log(kError_ANPLogType, "fstat error"); | |
133 | - } | |
134 | - | |
135 | - // configure the UI elements | |
136 | - m_activeTouch = false; | |
137 | - | |
138 | - memset(&m_trackRect, 0, sizeof(m_trackRect)); | |
139 | - memset(&m_playRect, 0, sizeof(m_playRect)); | |
140 | - memset(&m_pauseRect, 0, sizeof(m_pauseRect)); | |
141 | - memset(&m_stopRect, 0, sizeof(m_stopRect)); | |
142 | - | |
143 | - m_paintTrack = gPaintI.newPaint(); | |
144 | - gPaintI.setFlags(m_paintTrack, gPaintI.getFlags(m_paintTrack) | kAntiAlias_ANPPaintFlag); | |
145 | - gPaintI.setColor(m_paintTrack, 0xFFC0C0C0); | |
146 | - | |
147 | - m_paintRect = gPaintI.newPaint(); | |
148 | - gPaintI.setFlags(m_paintRect, gPaintI.getFlags(m_paintRect) | kAntiAlias_ANPPaintFlag); | |
149 | - gPaintI.setColor(m_paintRect, 0xFFA8A8A8); | |
150 | - | |
151 | - m_paintText = gPaintI.newPaint(); | |
152 | - gPaintI.setFlags(m_paintText, gPaintI.getFlags(m_paintText) | kAntiAlias_ANPPaintFlag); | |
153 | - gPaintI.setColor(m_paintText, 0xFF2F4F4F); | |
154 | - gPaintI.setTextSize(m_paintText, 18); | |
155 | - | |
156 | - m_paintTrackProgress = gPaintI.newPaint(); | |
157 | - gPaintI.setFlags(m_paintTrackProgress, gPaintI.getFlags(m_paintTrackProgress) | kAntiAlias_ANPPaintFlag); | |
158 | - gPaintI.setColor(m_paintTrackProgress, 0xFF545454); | |
159 | - | |
160 | - m_paintActiveRect = gPaintI.newPaint(); | |
161 | - gPaintI.setFlags(m_paintActiveRect, gPaintI.getFlags(m_paintActiveRect) | kAntiAlias_ANPPaintFlag); | |
162 | - gPaintI.setColor(m_paintActiveRect, 0xFF545454); | |
163 | - | |
164 | - ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); | |
165 | - gPaintI.setTypeface(m_paintText, tf); | |
166 | - gTypefaceI.unref(tf); | |
167 | - | |
168 | - //register for touch events | |
169 | - ANPEventFlags flags = kTouch_ANPEventFlag; | |
170 | - NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); | |
171 | - if (err != NPERR_NO_ERROR) { | |
172 | - gLogI.log(kError_ANPLogType, "Error selecting input events."); | |
173 | - } | |
174 | -} | |
175 | - | |
176 | -AudioPlugin::~AudioPlugin() { | |
177 | - gPaintI.deletePaint(m_paintTrack); | |
178 | - gPaintI.deletePaint(m_paintRect); | |
179 | - gPaintI.deletePaint(m_paintText); | |
180 | - gPaintI.deletePaint(m_paintTrackProgress); | |
181 | - gPaintI.deletePaint(m_paintActiveRect); | |
182 | - if(m_soundPlay->track) | |
183 | - gSoundI.deleteTrack(m_soundPlay->track); | |
184 | - delete m_soundPlay; | |
185 | -} | |
186 | - | |
187 | -bool AudioPlugin::supportsDrawingModel(ANPDrawingModel model) { | |
188 | - return (model == kBitmap_ANPDrawingModel); | |
189 | -} | |
190 | - | |
191 | -void AudioPlugin::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) { | |
192 | - ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap); | |
193 | - | |
194 | - ANPRectF clipR; | |
195 | - clipR.left = clip.left; | |
196 | - clipR.top = clip.top; | |
197 | - clipR.right = clip.right; | |
198 | - clipR.bottom = clip.bottom; | |
199 | - gCanvasI.clipRect(canvas, &clipR); | |
200 | - | |
201 | - draw(canvas); | |
202 | - gCanvasI.deleteCanvas(canvas); | |
203 | -} | |
204 | - | |
205 | -void AudioPlugin::draw(ANPCanvas* canvas) { | |
206 | - | |
207 | - PluginObject *obj = (PluginObject*) this->inst()->pdata; | |
208 | - | |
209 | - gLogI.log(kError_ANPLogType, "Drawing"); | |
210 | - | |
211 | - const float trackHeight = 30; | |
212 | - const float buttonWidth = 60; | |
213 | - const float buttonHeight = 30; | |
214 | - const int W = obj->window->width; | |
215 | - const int H = obj->window->height; | |
216 | - | |
217 | - // color the plugin canvas | |
218 | - gCanvasI.drawColor(canvas, 0xFFCDCDCD); | |
219 | - | |
220 | - // get font metrics | |
221 | - ANPFontMetrics fontMetrics; | |
222 | - gPaintI.getFontMetrics(m_paintText, &fontMetrics); | |
223 | - | |
224 | - // draw the track box (1 px from the edge) | |
225 | - m_trackRect.left = 1; | |
226 | - m_trackRect.top = 1; | |
227 | - m_trackRect.right = W - 2; | |
228 | - m_trackRect.bottom = 1 + trackHeight; | |
229 | - gCanvasI.drawRect(canvas, &m_trackRect, m_paintTrack); | |
230 | - | |
231 | - // draw the progress bar | |
232 | - if (m_soundPlay->progress > 0) { | |
233 | - // TODO need to draw progress bar to cover the proper percentage of the track bar | |
234 | - gCanvasI.drawRect(canvas, &m_trackRect, m_paintTrackProgress); | |
235 | - } | |
236 | - | |
237 | - // draw the play box (under track box) | |
238 | - m_playRect.left = m_trackRect.left + 5; | |
239 | - m_playRect.top = m_trackRect.bottom + 10; | |
240 | - m_playRect.right = m_playRect.left + buttonWidth; | |
241 | - m_playRect.bottom = m_playRect.top + buttonHeight; | |
242 | - gCanvasI.drawRect(canvas, &m_playRect, getPaint(&m_playRect)); | |
243 | - // draw the play box (under track box) | |
244 | - const char playText[] = "Play"; | |
245 | - gCanvasI.drawText(canvas, playText, sizeof(playText)-1, m_playRect.left + 5, | |
246 | - m_playRect.top - fontMetrics.fTop, m_paintText); | |
247 | - | |
248 | - // draw the pause box (under track box) | |
249 | - m_pauseRect.left = m_playRect.right + 20; | |
250 | - m_pauseRect.top = m_trackRect.bottom + 10; | |
251 | - m_pauseRect.right = m_pauseRect.left + buttonWidth; | |
252 | - m_pauseRect.bottom = m_pauseRect.top + buttonHeight; | |
253 | - gCanvasI.drawRect(canvas, &m_pauseRect, getPaint(&m_pauseRect)); | |
254 | - // draw the text in the pause box | |
255 | - const char pauseText[] = "Pause"; | |
256 | - gCanvasI.drawText(canvas, pauseText, sizeof(pauseText)-1, m_pauseRect.left + 5, | |
257 | - m_pauseRect.top - fontMetrics.fTop, m_paintText); | |
258 | - | |
259 | - // draw the stop box (under track box) | |
260 | - m_stopRect.left = m_pauseRect.right + 20; | |
261 | - m_stopRect.top = m_trackRect.bottom + 10; | |
262 | - m_stopRect.right = m_stopRect.left + buttonWidth; | |
263 | - m_stopRect.bottom = m_stopRect.top + buttonHeight; | |
264 | - gCanvasI.drawRect(canvas, &m_stopRect, getPaint(&m_stopRect)); | |
265 | - // draw the text in the pause box | |
266 | - const char stopText[] = "Stop"; | |
267 | - gCanvasI.drawText(canvas, stopText, sizeof(stopText)-1, m_stopRect.left + 5, | |
268 | - m_stopRect.top - fontMetrics.fTop, m_paintText); | |
269 | -} | |
270 | - | |
271 | -ANPPaint* AudioPlugin::getPaint(ANPRectF* input) { | |
272 | - return (input == m_activeRect) ? m_paintActiveRect : m_paintRect; | |
273 | -} | |
274 | - | |
275 | -int16 AudioPlugin::handleEvent(const ANPEvent* evt) { | |
276 | - NPP instance = this->inst(); | |
277 | - | |
278 | - switch (evt->eventType) { | |
279 | - case kDraw_ANPEventType: | |
280 | - switch (evt->data.draw.model) { | |
281 | - case kBitmap_ANPDrawingModel: | |
282 | - drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip); | |
283 | - return 1; | |
284 | - default: | |
285 | - break; // unknown drawing model | |
286 | - } | |
287 | - | |
288 | - case kTouch_ANPEventType: { | |
289 | - int x = evt->data.touch.x; | |
290 | - int y = evt->data.touch.y; | |
291 | - if (kDown_ANPTouchAction == evt->data.touch.action) { | |
292 | - | |
293 | - m_activeTouchRect = validTouch(x,y); | |
294 | - if(m_activeTouchRect) { | |
295 | - m_activeTouch = true; | |
296 | - return 1; | |
297 | - } | |
298 | - | |
299 | - } else if (kUp_ANPTouchAction == evt->data.touch.action && m_activeTouch) { | |
300 | - handleTouch(x, y); | |
301 | - m_activeTouch = false; | |
302 | - return 1; | |
303 | - } else if (kCancel_ANPTouchAction == evt->data.touch.action) { | |
304 | - m_activeTouch = false; | |
305 | - } | |
306 | - break; | |
307 | - } | |
308 | - default: | |
309 | - break; | |
310 | - } | |
311 | - return 0; // unknown or unhandled event | |
312 | -} | |
313 | - | |
314 | -void AudioPlugin::invalActiveRect() { | |
315 | - | |
316 | -} | |
317 | - | |
318 | -ANPRectF* AudioPlugin::validTouch(int x, int y) { | |
319 | - | |
320 | - if (m_playRect.left && x < m_playRect.right && y > m_playRect.top && y < m_playRect.bottom) | |
321 | - return &m_playRect; | |
322 | - else if (m_pauseRect.left && x < m_pauseRect.right && y > m_pauseRect.top && y < m_pauseRect.bottom) | |
323 | - return &m_pauseRect; | |
324 | - else if (x > m_stopRect.left && x < m_stopRect.right && y > m_stopRect.top && y < m_stopRect.bottom) | |
325 | - return &m_stopRect; | |
326 | - else | |
327 | - return NULL; | |
328 | -} | |
329 | - | |
330 | -void AudioPlugin::handleTouch(int x, int y) { | |
331 | - NPP instance = this->inst(); | |
332 | - | |
333 | - // if the track is null then return | |
334 | - if (NULL == m_soundPlay->track) { | |
335 | - gLogI.log(kError_ANPLogType, "---- %p unable to create track", | |
336 | - instance); | |
337 | - return; | |
338 | - } | |
339 | - | |
340 | - // check to make sure the currentRect matches the activeRect | |
341 | - ANPRectF* currentRect = validTouch(x,y); | |
342 | - if (m_activeTouchRect != currentRect) | |
343 | - return; | |
344 | - | |
345 | - if (currentRect == &m_playRect) { | |
346 | - | |
347 | - gLogI.log(kDebug_ANPLogType, "---- %p starting track (%d)", | |
348 | - m_soundPlay->track, gSoundI.isStopped(m_soundPlay->track)); | |
349 | - | |
350 | - if (gSoundI.isStopped(m_soundPlay->track)) { | |
351 | - gSoundI.start(m_soundPlay->track); | |
352 | - } | |
353 | - } | |
354 | - else if (currentRect == &m_pauseRect) { | |
355 | - | |
356 | - gLogI.log(kDebug_ANPLogType, "---- %p pausing track (%d)", | |
357 | - m_soundPlay->track, gSoundI.isStopped(m_soundPlay->track)); | |
358 | - | |
359 | - if (!gSoundI.isStopped(m_soundPlay->track)) { | |
360 | - gSoundI.pause(m_soundPlay->track); | |
361 | - } | |
362 | - } | |
363 | - else if (currentRect == &m_stopRect) { | |
364 | - | |
365 | - gLogI.log(kDebug_ANPLogType, "---- %p stopping track (%d)", | |
366 | - m_soundPlay->track, gSoundI.isStopped(m_soundPlay->track)); | |
367 | - | |
368 | - if (!gSoundI.isStopped(m_soundPlay->track)) { | |
369 | - gSoundI.stop(m_soundPlay->track); | |
370 | - } | |
371 | - if (m_soundPlay->file) { | |
372 | - fseek(m_soundPlay->file, 0, SEEK_SET); | |
373 | - } | |
374 | - } | |
375 | - else { | |
376 | - return; | |
377 | - } | |
378 | - | |
379 | - // set the currentRect to be the activeRect | |
380 | - m_activeRect = currentRect; | |
381 | - inval(instance); | |
382 | -} |
@@ -1,74 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2008, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "PluginObject.h" | |
27 | -#include <stdio.h> | |
28 | - | |
29 | -#ifndef audioPlugin__DEFINED | |
30 | -#define audioPlugin__DEFINED | |
31 | - | |
32 | -struct SoundPlay { | |
33 | - NPP instance; | |
34 | - ANPAudioTrack* track; | |
35 | - FILE* file; | |
36 | - int fileSize; | |
37 | - int progress; // value between 0 and 100 | |
38 | -}; | |
39 | - | |
40 | -class AudioPlugin : public SubPlugin { | |
41 | -public: | |
42 | - AudioPlugin(NPP inst); | |
43 | - virtual ~AudioPlugin(); | |
44 | - virtual bool supportsDrawingModel(ANPDrawingModel); | |
45 | - virtual int16 handleEvent(const ANPEvent* evt); | |
46 | -private: | |
47 | - void draw(ANPCanvas*); | |
48 | - void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip); | |
49 | - | |
50 | - void handleTouch(int x, int y); | |
51 | - void invalActiveRect(); | |
52 | - ANPPaint* getPaint(ANPRectF*); | |
53 | - ANPRectF* validTouch(int x, int y); | |
54 | - | |
55 | - ANPRectF m_trackRect; | |
56 | - ANPRectF m_playRect; | |
57 | - ANPRectF m_pauseRect; | |
58 | - ANPRectF m_stopRect; | |
59 | - | |
60 | - ANPPaint* m_paintTrack; | |
61 | - ANPPaint* m_paintRect; | |
62 | - ANPPaint* m_paintText; | |
63 | - | |
64 | - ANPPaint* m_paintTrackProgress; | |
65 | - ANPPaint* m_paintActiveRect; | |
66 | - | |
67 | - SoundPlay* m_soundPlay; | |
68 | - | |
69 | - bool m_activeTouch; | |
70 | - ANPRectF* m_activeTouchRect; | |
71 | - ANPRectF* m_activeRect; | |
72 | -}; | |
73 | - | |
74 | -#endif // audioPlugin__DEFINED |
@@ -1,499 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2008, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "BackgroundPlugin.h" | |
27 | -#include "android_npapi.h" | |
28 | - | |
29 | -#include <stdio.h> | |
30 | -#include <sys/time.h> | |
31 | -#include <time.h> | |
32 | -#include <math.h> | |
33 | -#include <string.h> | |
34 | - | |
35 | -extern NPNetscapeFuncs* browser; | |
36 | -extern ANPBitmapInterfaceV0 gBitmapI; | |
37 | -extern ANPCanvasInterfaceV0 gCanvasI; | |
38 | -extern ANPLogInterfaceV0 gLogI; | |
39 | -extern ANPPaintInterfaceV0 gPaintI; | |
40 | -extern ANPSurfaceInterfaceV0 gSurfaceI; | |
41 | -extern ANPSystemInterfaceV0 gSystemI; | |
42 | -extern ANPTypefaceInterfaceV0 gTypefaceI; | |
43 | -extern ANPWindowInterfaceV0 gWindowI; | |
44 | - | |
45 | -#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) | |
46 | - | |
47 | -static uint32_t getMSecs() { | |
48 | - struct timeval tv; | |
49 | - gettimeofday(&tv, NULL); | |
50 | - return (uint32_t) (tv.tv_sec * 1000 + tv.tv_usec / 1000 ); // microseconds to milliseconds | |
51 | -} | |
52 | - | |
53 | -/////////////////////////////////////////////////////////////////////////////// | |
54 | - | |
55 | -BackgroundPlugin::BackgroundPlugin(NPP inst) : SurfaceSubPlugin(inst) { | |
56 | - | |
57 | - // initialize the drawing surface | |
58 | - m_surface = NULL; | |
59 | - | |
60 | - //initialize bitmap transparency variables | |
61 | - mFinishedStageOne = false; | |
62 | - mFinishedStageTwo = false; | |
63 | - mFinishedStageThree = false; | |
64 | - | |
65 | - // test basic plugin functionality | |
66 | - test_logging(); // android logging | |
67 | - test_timers(); // plugin timers | |
68 | - test_bitmaps(); // android bitmaps | |
69 | - test_domAccess(); | |
70 | - test_javascript(); | |
71 | - test_loadJavaClass(); | |
72 | - | |
73 | - //register for touch events | |
74 | - ANPEventFlags flags = kTouch_ANPEventFlag; | |
75 | - NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); | |
76 | - if (err != NPERR_NO_ERROR) { | |
77 | - gLogI.log(kError_ANPLogType, "Error selecting input events."); | |
78 | - } | |
79 | -} | |
80 | - | |
81 | -BackgroundPlugin::~BackgroundPlugin() { | |
82 | - setContext(NULL); | |
83 | - destroySurface(); | |
84 | -} | |
85 | - | |
86 | -jobject BackgroundPlugin::getSurface() { | |
87 | - | |
88 | - if (m_surface) { | |
89 | - return m_surface; | |
90 | - } | |
91 | - | |
92 | - // load the appropriate java class and instantiate it | |
93 | - JNIEnv* env = NULL; | |
94 | - if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { | |
95 | - gLogI.log(kError_ANPLogType, " ---- getSurface: failed to get env"); | |
96 | - return NULL; | |
97 | - } | |
98 | - | |
99 | - const char* className = "com.android.sampleplugin.BackgroundSurface"; | |
100 | - jclass backgroundClass = gSystemI.loadJavaClass(inst(), className); | |
101 | - | |
102 | - if(!backgroundClass) { | |
103 | - gLogI.log(kError_ANPLogType, " ---- getSurface: failed to load class"); | |
104 | - return NULL; | |
105 | - } | |
106 | - | |
107 | - jmethodID constructor = env->GetMethodID(backgroundClass, "<init>", "(Landroid/content/Context;)V"); | |
108 | - jobject backgroundSurface = env->NewObject(backgroundClass, constructor, m_context); | |
109 | - | |
110 | - if(!backgroundSurface) { | |
111 | - gLogI.log(kError_ANPLogType, " ---- getSurface: failed to construct object"); | |
112 | - return NULL; | |
113 | - } | |
114 | - | |
115 | - m_surface = env->NewGlobalRef(backgroundSurface); | |
116 | - return m_surface; | |
117 | -} | |
118 | - | |
119 | -void BackgroundPlugin::destroySurface() { | |
120 | - JNIEnv* env = NULL; | |
121 | - if (m_surface && gVM->GetEnv((void**) &env, JNI_VERSION_1_4) == JNI_OK) { | |
122 | - env->DeleteGlobalRef(m_surface); | |
123 | - m_surface = NULL; | |
124 | - } | |
125 | -} | |
126 | - | |
127 | -void BackgroundPlugin::drawPlugin(int surfaceWidth, int surfaceHeight) { | |
128 | - | |
129 | - // get the plugin's dimensions according to the DOM | |
130 | - PluginObject *obj = (PluginObject*) inst()->pdata; | |
131 | - const int W = obj->window->width; | |
132 | - const int H = obj->window->height; | |
133 | - | |
134 | - // compute the current zoom level | |
135 | - const float zoomFactorW = static_cast<float>(surfaceWidth) / W; | |
136 | - const float zoomFactorH = static_cast<float>(surfaceHeight) / H; | |
137 | - | |
138 | - // check to make sure the zoom level is uniform | |
139 | - if (zoomFactorW + .01 < zoomFactorH && zoomFactorW - .01 > zoomFactorH) | |
140 | - gLogI.log(kError_ANPLogType, " ------ %p zoom is out of sync (%f,%f)", | |
141 | - inst(), zoomFactorW, zoomFactorH); | |
142 | - | |
143 | - // scale the variables based on the zoom level | |
144 | - const int fontSize = (int)(zoomFactorW * 16); | |
145 | - const int leftMargin = (int)(zoomFactorW * 10); | |
146 | - | |
147 | - // lock the surface | |
148 | - ANPBitmap bitmap; | |
149 | - JNIEnv* env = NULL; | |
150 | - if (!m_surface || gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK || | |
151 | - !gSurfaceI.lock(env, m_surface, &bitmap, NULL)) { | |
152 | - gLogI.log(kError_ANPLogType, " ------ %p unable to lock the plugin", inst()); | |
153 | - return; | |
154 | - } | |
155 | - | |
156 | - // create a canvas | |
157 | - ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap); | |
158 | - gCanvasI.drawColor(canvas, 0xFFFFFFFF); | |
159 | - | |
160 | - ANPPaint* paint = gPaintI.newPaint(); | |
161 | - gPaintI.setFlags(paint, gPaintI.getFlags(paint) | kAntiAlias_ANPPaintFlag); | |
162 | - gPaintI.setColor(paint, 0xFFFF0000); | |
163 | - gPaintI.setTextSize(paint, fontSize); | |
164 | - | |
165 | - ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); | |
166 | - gPaintI.setTypeface(paint, tf); | |
167 | - gTypefaceI.unref(tf); | |
168 | - | |
169 | - ANPFontMetrics fm; | |
170 | - gPaintI.getFontMetrics(paint, &fm); | |
171 | - | |
172 | - gPaintI.setColor(paint, 0xFF0000FF); | |
173 | - const char c[] = "This is a background plugin."; | |
174 | - gCanvasI.drawText(canvas, c, sizeof(c)-1, leftMargin, -fm.fTop, paint); | |
175 | - | |
176 | - // clean up variables and unlock the surface | |
177 | - gPaintI.deletePaint(paint); | |
178 | - gCanvasI.deleteCanvas(canvas); | |
179 | - gSurfaceI.unlock(env, m_surface); | |
180 | -} | |
181 | - | |
182 | -int16 BackgroundPlugin::handleEvent(const ANPEvent* evt) { | |
183 | - switch (evt->eventType) { | |
184 | - case kDraw_ANPEventType: | |
185 | - gLogI.log(kError_ANPLogType, " ------ %p the plugin did not request draw events", inst()); | |
186 | - break; | |
187 | - case kLifecycle_ANPEventType: | |
188 | - switch (evt->data.lifecycle.action) { | |
189 | - case kOnLoad_ANPLifecycleAction: | |
190 | - gLogI.log(kDebug_ANPLogType, " ------ %p onLoad", inst()); | |
191 | - return 1; | |
192 | - case kOnScreen_ANPLifecycleAction: | |
193 | - gLogI.log(kDebug_ANPLogType, " ------ %p onScreen", inst()); | |
194 | - return 1; | |
195 | - case kOffScreen_ANPLifecycleAction: | |
196 | - gLogI.log(kDebug_ANPLogType, " ------ %p offScreen", inst()); | |
197 | - return 1; | |
198 | - } | |
199 | - break; // end kLifecycle_ANPEventType | |
200 | - case kTouch_ANPEventType: | |
201 | - if (kLongPress_ANPTouchAction == evt->data.touch.action) { | |
202 | - browser->geturl(inst(), "javascript:alert('Detected long press event.')", 0); | |
203 | - gWindowI.requestFullScreen(inst()); | |
204 | - } | |
205 | - else if (kDoubleTap_ANPTouchAction == evt->data.touch.action) | |
206 | - browser->geturl(inst(), "javascript:alert('Detected double tap event.')", 0); | |
207 | - break; | |
208 | - case kKey_ANPEventType: | |
209 | - gLogI.log(kError_ANPLogType, " ------ %p the plugin did not request key events", inst()); | |
210 | - break; | |
211 | - default: | |
212 | - break; | |
213 | - } | |
214 | - return 0; // unknown or unhandled event | |
215 | -} | |
216 | - | |
217 | -/////////////////////////////////////////////////////////////////////////////// | |
218 | -// LOGGING TESTS | |
219 | -/////////////////////////////////////////////////////////////////////////////// | |
220 | - | |
221 | - | |
222 | -void BackgroundPlugin::test_logging() { | |
223 | - NPP instance = this->inst(); | |
224 | - | |
225 | - //LOG_ERROR(instance, " ------ %p Testing Log Error", instance); | |
226 | - gLogI.log(kError_ANPLogType, " ------ %p Testing Log Error", instance); | |
227 | - gLogI.log(kWarning_ANPLogType, " ------ %p Testing Log Warning", instance); | |
228 | - gLogI.log(kDebug_ANPLogType, " ------ %p Testing Log Debug", instance); | |
229 | -} | |
230 | - | |
231 | -/////////////////////////////////////////////////////////////////////////////// | |
232 | -// TIMER TESTS | |
233 | -/////////////////////////////////////////////////////////////////////////////// | |
234 | - | |
235 | -#define TIMER_INTERVAL 50 | |
236 | -static void timer_oneshot(NPP instance, uint32 timerID); | |
237 | -static void timer_repeat(NPP instance, uint32 timerID); | |
238 | -static void timer_neverfires(NPP instance, uint32 timerID); | |
239 | -static void timer_latency(NPP instance, uint32 timerID); | |
240 | - | |
241 | -void BackgroundPlugin::test_timers() { | |
242 | - NPP instance = this->inst(); | |
243 | - | |
244 | - //Setup the testing counters | |
245 | - mTimerRepeatCount = 5; | |
246 | - mTimerLatencyCount = 5; | |
247 | - | |
248 | - // test for bogus timerID | |
249 | - browser->unscheduletimer(instance, 999999); | |
250 | - // test one-shot | |
251 | - browser->scheduletimer(instance, 100, false, timer_oneshot); | |
252 | - // test repeat | |
253 | - browser->scheduletimer(instance, 50, true, timer_repeat); | |
254 | - // test timer latency | |
255 | - browser->scheduletimer(instance, TIMER_INTERVAL, true, timer_latency); | |
256 | - mStartTime = mPrevTime = getMSecs(); | |
257 | - // test unschedule immediately | |
258 | - uint32 id = browser->scheduletimer(instance, 100, false, timer_neverfires); | |
259 | - browser->unscheduletimer(instance, id); | |
260 | - // test double unschedule (should be no-op) | |
261 | - browser->unscheduletimer(instance, id); | |
262 | - | |
263 | -} | |
264 | - | |
265 | -static void timer_oneshot(NPP instance, uint32 timerID) { | |
266 | - gLogI.log(kDebug_ANPLogType, "-------- oneshot timer\n"); | |
267 | -} | |
268 | - | |
269 | -static void timer_repeat(NPP instance, uint32 timerID) { | |
270 | - BackgroundPlugin *obj = ((BackgroundPlugin*) ((PluginObject*) instance->pdata)->activePlugin); | |
271 | - | |
272 | - gLogI.log(kDebug_ANPLogType, "-------- repeat timer %d\n", | |
273 | - obj->mTimerRepeatCount); | |
274 | - if (--obj->mTimerRepeatCount == 0) { | |
275 | - browser->unscheduletimer(instance, timerID); | |
276 | - } | |
277 | -} | |
278 | - | |
279 | -static void timer_neverfires(NPP instance, uint32 timerID) { | |
280 | - gLogI.log(kError_ANPLogType, "-------- timer_neverfires!!!\n"); | |
281 | -} | |
282 | - | |
283 | -static void timer_latency(NPP instance, uint32 timerID) { | |
284 | - BackgroundPlugin *obj = ((BackgroundPlugin*) ((PluginObject*) instance->pdata)->activePlugin); | |
285 | - | |
286 | - obj->mTimerLatencyCurrentCount += 1; | |
287 | - | |
288 | - uint32_t now = getMSecs(); | |
289 | - uint32_t interval = now - obj->mPrevTime; | |
290 | - uint32_t dur = now - obj->mStartTime; | |
291 | - uint32_t expectedDur = obj->mTimerLatencyCurrentCount * TIMER_INTERVAL; | |
292 | - int32_t drift = dur - expectedDur; | |
293 | - int32_t avgDrift = drift / obj->mTimerLatencyCurrentCount; | |
294 | - | |
295 | - obj->mPrevTime = now; | |
296 | - | |
297 | - gLogI.log(kDebug_ANPLogType, | |
298 | - "-------- latency test: [%3d] interval %d expected %d, total %d expected %d, drift %d avg %d\n", | |
299 | - obj->mTimerLatencyCurrentCount, interval, TIMER_INTERVAL, dur, | |
300 | - expectedDur, drift, avgDrift); | |
301 | - | |
302 | - if (--obj->mTimerLatencyCount == 0) { | |
303 | - browser->unscheduletimer(instance, timerID); | |
304 | - } | |
305 | -} | |
306 | - | |
307 | -/////////////////////////////////////////////////////////////////////////////// | |
308 | -// BITMAP TESTS | |
309 | -/////////////////////////////////////////////////////////////////////////////// | |
310 | - | |
311 | -static void test_formats(NPP instance); | |
312 | - | |
313 | -void BackgroundPlugin::test_bitmaps() { | |
314 | - test_formats(this->inst()); | |
315 | -} | |
316 | - | |
317 | -static void test_formats(NPP instance) { | |
318 | - | |
319 | - // TODO pull names from enum in npapi instead of hardcoding them | |
320 | - static const struct { | |
321 | - ANPBitmapFormat fFormat; | |
322 | - const char* fName; | |
323 | - } gRecs[] = { | |
324 | - { kUnknown_ANPBitmapFormat, "unknown" }, | |
325 | - { kRGBA_8888_ANPBitmapFormat, "8888" }, | |
326 | - { kRGB_565_ANPBitmapFormat, "565" }, | |
327 | - }; | |
328 | - | |
329 | - ANPPixelPacking packing; | |
330 | - for (size_t i = 0; i < ARRAY_COUNT(gRecs); i++) { | |
331 | - if (gBitmapI.getPixelPacking(gRecs[i].fFormat, &packing)) { | |
332 | - gLogI.log(kDebug_ANPLogType, | |
333 | - "pixel format [%d] %s has packing ARGB [%d %d] [%d %d] [%d %d] [%d %d]\n", | |
334 | - gRecs[i].fFormat, gRecs[i].fName, | |
335 | - packing.AShift, packing.ABits, | |
336 | - packing.RShift, packing.RBits, | |
337 | - packing.GShift, packing.GBits, | |
338 | - packing.BShift, packing.BBits); | |
339 | - } else { | |
340 | - gLogI.log(kDebug_ANPLogType, | |
341 | - "pixel format [%d] %s has no packing\n", | |
342 | - gRecs[i].fFormat, gRecs[i].fName); | |
343 | - } | |
344 | - } | |
345 | -} | |
346 | - | |
347 | -void BackgroundPlugin::test_bitmap_transparency(const ANPEvent* evt) { | |
348 | - NPP instance = this->inst(); | |
349 | - | |
350 | - // check default & set transparent | |
351 | - if (!mFinishedStageOne) { | |
352 | - | |
353 | - gLogI.log(kDebug_ANPLogType, "BEGIN: testing bitmap transparency"); | |
354 | - | |
355 | - //check to make sure it is not transparent | |
356 | - if (evt->data.draw.data.bitmap.format == kRGBA_8888_ANPBitmapFormat) { | |
357 | - gLogI.log(kError_ANPLogType, "bitmap default format is transparent"); | |
358 | - } | |
359 | - | |
360 | - //make it transparent (any non-null value will set it to true) | |
361 | - bool value = true; | |
362 | - NPError err = browser->setvalue(instance, NPPVpluginTransparentBool, &value); | |
363 | - if (err != NPERR_NO_ERROR) { | |
364 | - gLogI.log(kError_ANPLogType, "Error setting transparency."); | |
365 | - } | |
366 | - | |
367 | - mFinishedStageOne = true; | |
368 | - browser->invalidaterect(instance, NULL); | |
369 | - } | |
370 | - // check transparent & set opaque | |
371 | - else if (!mFinishedStageTwo) { | |
372 | - | |
373 | - //check to make sure it is transparent | |
374 | - if (evt->data.draw.data.bitmap.format != kRGBA_8888_ANPBitmapFormat) { | |
375 | - gLogI.log(kError_ANPLogType, "bitmap did not change to transparent format"); | |
376 | - } | |
377 | - | |
378 | - //make it opaque | |
379 | - NPError err = browser->setvalue(instance, NPPVpluginTransparentBool, NULL); | |
380 | - if (err != NPERR_NO_ERROR) { | |
381 | - gLogI.log(kError_ANPLogType, "Error setting transparency."); | |
382 | - } | |
383 | - | |
384 | - mFinishedStageTwo = true; | |
385 | - } | |
386 | - // check opaque | |
387 | - else if (!mFinishedStageThree) { | |
388 | - | |
389 | - //check to make sure it is not transparent | |
390 | - if (evt->data.draw.data.bitmap.format == kRGBA_8888_ANPBitmapFormat) { | |
391 | - gLogI.log(kError_ANPLogType, "bitmap default format is transparent"); | |
392 | - } | |
393 | - | |
394 | - gLogI.log(kDebug_ANPLogType, "END: testing bitmap transparency"); | |
395 | - | |
396 | - mFinishedStageThree = true; | |
397 | - } | |
398 | -} | |
399 | - | |
400 | -/////////////////////////////////////////////////////////////////////////////// | |
401 | -// DOM TESTS | |
402 | -/////////////////////////////////////////////////////////////////////////////// | |
403 | - | |
404 | -void BackgroundPlugin::test_domAccess() { | |
405 | - NPP instance = this->inst(); | |
406 | - | |
407 | - gLogI.log(kDebug_ANPLogType, " ------ %p Testing DOM Access", instance); | |
408 | - | |
409 | - // Get the plugin's DOM object | |
410 | - NPObject* windowObject = NULL; | |
411 | - browser->getvalue(instance, NPNVWindowNPObject, &windowObject); | |
412 | - | |
413 | - if (!windowObject) | |
414 | - gLogI.log(kError_ANPLogType, " ------ %p Unable to retrieve DOM Window", instance); | |
415 | - | |
416 | - // Retrieve a property from the plugin's DOM object | |
417 | - NPIdentifier topIdentifier = browser->getstringidentifier("top"); | |
418 | - NPVariant topObjectVariant; | |
419 | - browser->getproperty(instance, windowObject, topIdentifier, &topObjectVariant); | |
420 | - | |
421 | - if (topObjectVariant.type != NPVariantType_Object) | |
422 | - gLogI.log(kError_ANPLogType, " ------ %p Invalid Variant type for DOM Property: %d,%d", instance, topObjectVariant.type, NPVariantType_Object); | |
423 | -} | |
424 | - | |
425 | - | |
426 | -/////////////////////////////////////////////////////////////////////////////// | |
427 | -// JAVASCRIPT TESTS | |
428 | -/////////////////////////////////////////////////////////////////////////////// | |
429 | - | |
430 | - | |
431 | -void BackgroundPlugin::test_javascript() { | |
432 | - NPP instance = this->inst(); | |
433 | - | |
434 | - gLogI.log(kDebug_ANPLogType, " ------ %p Testing JavaScript Access", instance); | |
435 | - | |
436 | - // Get the plugin's DOM object | |
437 | - NPObject* windowObject = NULL; | |
438 | - browser->getvalue(instance, NPNVWindowNPObject, &windowObject); | |
439 | - | |
440 | - if (!windowObject) | |
441 | - gLogI.log(kError_ANPLogType, " ------ %p Unable to retrieve DOM Window", instance); | |
442 | - | |
443 | - // create a string (JS code) that is stored in memory allocated by the browser | |
444 | - const char* jsString = "1200 + 34"; | |
445 | - void* stringMem = browser->memalloc(strlen(jsString)); | |
446 | - memcpy(stringMem, jsString, strlen(jsString)); | |
447 | - | |
448 | - // execute the javascript in the plugin's DOM object | |
449 | - NPString script = { (char*)stringMem, strlen(jsString) }; | |
450 | - NPVariant scriptVariant; | |
451 | - if (!browser->evaluate(instance, windowObject, &script, &scriptVariant)) | |
452 | - gLogI.log(kError_ANPLogType, " ------ %p Unable to eval the JS.", instance); | |
453 | - | |
454 | - if (scriptVariant.type == NPVariantType_Int32) { | |
455 | - if (scriptVariant.value.intValue != 1234) | |
456 | - gLogI.log(kError_ANPLogType, " ------ %p Invalid Value for JS Return: %d,1234", instance, scriptVariant.value.intValue); | |
457 | - } else { | |
458 | - gLogI.log(kError_ANPLogType, " ------ %p Invalid Variant type for JS Return: %d,%d", instance, scriptVariant.type, NPVariantType_Int32); | |
459 | - } | |
460 | - | |
461 | - // free the memory allocated within the browser | |
462 | - browser->memfree(stringMem); | |
463 | -} | |
464 | - | |
465 | -/////////////////////////////////////////////////////////////////////////////// | |
466 | -// Load Java Classes Tests | |
467 | -/////////////////////////////////////////////////////////////////////////////// | |
468 | - | |
469 | -void BackgroundPlugin::test_loadJavaClass() { | |
470 | - | |
471 | - JNIEnv* env = NULL; | |
472 | - if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { | |
473 | - gLogI.log(kError_ANPLogType, " ---- LoadJavaTest: failed to get env"); | |
474 | - return; | |
475 | - } | |
476 | - | |
477 | - const char* className = "com.android.sampleplugin.BackgroundTest"; | |
478 | - jclass backgroundClass = gSystemI.loadJavaClass(inst(), className); | |
479 | - | |
480 | - if(!backgroundClass) { | |
481 | - gLogI.log(kError_ANPLogType, " ---- LoadJavaTest: failed to load class"); | |
482 | - return; | |
483 | - } | |
484 | - | |
485 | - jmethodID constructor = env->GetMethodID(backgroundClass, "<init>", "()V"); | |
486 | - jmethodID addMethod = env->GetMethodID(backgroundClass, "addInt", "(II)I"); | |
487 | - jobject backgroundObject = env->NewObject(backgroundClass, constructor); | |
488 | - | |
489 | - if(!backgroundObject) { | |
490 | - gLogI.log(kError_ANPLogType, " ---- LoadJavaTest: failed to construct object"); | |
491 | - return; | |
492 | - } | |
493 | - | |
494 | - jint result = env->CallIntMethod(backgroundObject, addMethod, 2, 2); | |
495 | - | |
496 | - if (result != 4) { | |
497 | - gLogI.log(kError_ANPLogType, " ---- LoadJavaTest: invalid result (%d != 4)", result); | |
498 | - } | |
499 | -} |
@@ -1,66 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2008, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "PluginObject.h" | |
27 | - | |
28 | -#ifndef backgroundPlugin__DEFINED | |
29 | -#define backgroundPlugin__DEFINED | |
30 | - | |
31 | -class BackgroundPlugin : public SurfaceSubPlugin { | |
32 | -public: | |
33 | - BackgroundPlugin(NPP inst); | |
34 | - virtual ~BackgroundPlugin(); | |
35 | - virtual int16 handleEvent(const ANPEvent* evt); | |
36 | - virtual jobject getSurface(); | |
37 | - | |
38 | - // Timer Testing Variables | |
39 | - uint32_t mStartTime; | |
40 | - uint32_t mPrevTime; | |
41 | - int mTimerRepeatCount; | |
42 | - int mTimerLatencyCount; | |
43 | - int mTimerLatencyCurrentCount; | |
44 | - | |
45 | - // Bitmap Transparency Variables | |
46 | - bool mFinishedStageOne; // check default & set transparent | |
47 | - bool mFinishedStageTwo; // check transparent & set opaque | |
48 | - bool mFinishedStageThree; // check opaque | |
49 | - | |
50 | -private: | |
51 | - void drawPlugin(int surfaceWidth, int surfaceHeight); | |
52 | - void destroySurface(); | |
53 | - | |
54 | - jobject m_surface; | |
55 | - | |
56 | - void test_logging(); | |
57 | - void test_timers(); | |
58 | - void test_bitmaps(); | |
59 | - void test_bitmap_transparency(const ANPEvent* evt); | |
60 | - void test_domAccess(); | |
61 | - void test_javascript(); | |
62 | - void test_loadJavaClass(); | |
63 | - | |
64 | -}; | |
65 | - | |
66 | -#endif // backgroundPlugin__DEFINED |
@@ -1,381 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2008, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "FormPlugin.h" | |
27 | - | |
28 | -#include <stdio.h> | |
29 | -#include <sys/time.h> | |
30 | -#include <time.h> | |
31 | -#include <math.h> | |
32 | -#include <string.h> | |
33 | - | |
34 | -extern NPNetscapeFuncs* browser; | |
35 | -extern ANPLogInterfaceV0 gLogI; | |
36 | -extern ANPCanvasInterfaceV0 gCanvasI; | |
37 | -extern ANPPaintInterfaceV0 gPaintI; | |
38 | -extern ANPTypefaceInterfaceV0 gTypefaceI; | |
39 | -extern ANPWindowInterfaceV0 gWindowI; | |
40 | - | |
41 | - | |
42 | -static void inval(NPP instance) { | |
43 | - browser->invalidaterect(instance, NULL); | |
44 | -} | |
45 | - | |
46 | -static uint16 rnd16(float x, int inset) { | |
47 | - int ix = (int)roundf(x) + inset; | |
48 | - if (ix < 0) { | |
49 | - ix = 0; | |
50 | - } | |
51 | - return static_cast<uint16>(ix); | |
52 | -} | |
53 | - | |
54 | -static void inval(NPP instance, const ANPRectF& r, bool doAA) { | |
55 | - const int inset = doAA ? -1 : 0; | |
56 | - | |
57 | - PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata); | |
58 | - NPRect inval; | |
59 | - inval.left = rnd16(r.left, inset); | |
60 | - inval.top = rnd16(r.top, inset); | |
61 | - inval.right = rnd16(r.right, -inset); | |
62 | - inval.bottom = rnd16(r.bottom, -inset); | |
63 | - browser->invalidaterect(instance, &inval); | |
64 | -} | |
65 | - | |
66 | -/////////////////////////////////////////////////////////////////////////////// | |
67 | - | |
68 | -FormPlugin::FormPlugin(NPP inst) : SubPlugin(inst) { | |
69 | - | |
70 | - m_hasFocus = false; | |
71 | - m_activeInput = NULL; | |
72 | - | |
73 | - memset(&m_usernameInput, 0, sizeof(m_usernameInput)); | |
74 | - memset(&m_passwordInput, 0, sizeof(m_passwordInput)); | |
75 | - | |
76 | - m_usernameInput.text[0] = '\0'; | |
77 | - m_usernameInput.charPtr = 0; | |
78 | - | |
79 | - m_passwordInput.text[0] = '\0'; | |
80 | - m_passwordInput.charPtr = 0; | |
81 | - | |
82 | - m_paintInput = gPaintI.newPaint(); | |
83 | - gPaintI.setFlags(m_paintInput, gPaintI.getFlags(m_paintInput) | kAntiAlias_ANPPaintFlag); | |
84 | - gPaintI.setColor(m_paintInput, 0xFFFFFFFF); | |
85 | - | |
86 | - m_paintActive = gPaintI.newPaint(); | |
87 | - gPaintI.setFlags(m_paintActive, gPaintI.getFlags(m_paintActive) | kAntiAlias_ANPPaintFlag); | |
88 | - gPaintI.setColor(m_paintActive, 0xFFFFFF00); | |
89 | - | |
90 | - m_paintText = gPaintI.newPaint(); | |
91 | - gPaintI.setFlags(m_paintText, gPaintI.getFlags(m_paintText) | kAntiAlias_ANPPaintFlag); | |
92 | - gPaintI.setColor(m_paintText, 0xFF000000); | |
93 | - gPaintI.setTextSize(m_paintText, 18); | |
94 | - | |
95 | - ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); | |
96 | - gPaintI.setTypeface(m_paintText, tf); | |
97 | - gTypefaceI.unref(tf); | |
98 | - | |
99 | - //register for key and visibleRect events | |
100 | - ANPEventFlags flags = kKey_ANPEventFlag; | |
101 | - NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); | |
102 | - if (err != NPERR_NO_ERROR) { | |
103 | - gLogI.log(kError_ANPLogType, "Error selecting input events."); | |
104 | - } | |
105 | -} | |
106 | - | |
107 | -FormPlugin::~FormPlugin() { | |
108 | - gPaintI.deletePaint(m_paintInput); | |
109 | - gPaintI.deletePaint(m_paintActive); | |
110 | - gPaintI.deletePaint(m_paintText); | |
111 | -} | |
112 | - | |
113 | -bool FormPlugin::supportsDrawingModel(ANPDrawingModel model) { | |
114 | - return (model == kBitmap_ANPDrawingModel); | |
115 | -} | |
116 | - | |
117 | -void FormPlugin::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) { | |
118 | - ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap); | |
119 | - | |
120 | - ANPRectF clipR; | |
121 | - clipR.left = clip.left; | |
122 | - clipR.top = clip.top; | |
123 | - clipR.right = clip.right; | |
124 | - clipR.bottom = clip.bottom; | |
125 | - gCanvasI.clipRect(canvas, &clipR); | |
126 | - | |
127 | - draw(canvas); | |
128 | - gCanvasI.deleteCanvas(canvas); | |
129 | -} | |
130 | - | |
131 | -void FormPlugin::draw(ANPCanvas* canvas) { | |
132 | - NPP instance = this->inst(); | |
133 | - PluginObject *obj = (PluginObject*) instance->pdata; | |
134 | - | |
135 | - const float inputWidth = 60; | |
136 | - const float inputHeight = 30; | |
137 | - const int W = obj->window->width; | |
138 | - const int H = obj->window->height; | |
139 | - | |
140 | - // color the plugin canvas | |
141 | - gCanvasI.drawColor(canvas, (m_hasFocus) ? 0xFFCDCDCD : 0xFF545454); | |
142 | - | |
143 | - // draw the username box (5 px from the top edge) | |
144 | - m_usernameInput.rect.left = 5; | |
145 | - m_usernameInput.rect.top = 5; | |
146 | - m_usernameInput.rect.right = W - 5; | |
147 | - m_usernameInput.rect.bottom = m_usernameInput.rect.top + inputHeight; | |
148 | - gCanvasI.drawRect(canvas, &m_usernameInput.rect, getPaint(&m_usernameInput)); | |
149 | - drawText(canvas, m_usernameInput); | |
150 | - | |
151 | - // draw the password box (5 px from the bottom edge) | |
152 | - m_passwordInput.rect.left = 5; | |
153 | - m_passwordInput.rect.top = H - (inputHeight + 5); | |
154 | - m_passwordInput.rect.right = W - 5; | |
155 | - m_passwordInput.rect.bottom = m_passwordInput.rect.top + inputHeight; | |
156 | - gCanvasI.drawRect(canvas, &m_passwordInput.rect, getPaint(&m_passwordInput)); | |
157 | - drawPassword(canvas, m_passwordInput); | |
158 | - | |
159 | - //invalidate the canvas | |
160 | - //inval(instance); | |
161 | -} | |
162 | - | |
163 | -ANPPaint* FormPlugin::getPaint(TextInput* input) { | |
164 | - return (input == m_activeInput) ? m_paintActive : m_paintInput; | |
165 | -} | |
166 | - | |
167 | -void FormPlugin::drawText(ANPCanvas* canvas, TextInput textInput) { | |
168 | - | |
169 | - // get font metrics | |
170 | - ANPFontMetrics fontMetrics; | |
171 | - gPaintI.getFontMetrics(m_paintText, &fontMetrics); | |
172 | - | |
173 | - gCanvasI.drawText(canvas, textInput.text, textInput.charPtr, | |
174 | - textInput.rect.left + 5, | |
175 | - textInput.rect.bottom - fontMetrics.fBottom, m_paintText); | |
176 | -} | |
177 | - | |
178 | -void FormPlugin::drawPassword(ANPCanvas* canvas, TextInput passwordInput) { | |
179 | - | |
180 | - // get font metrics | |
181 | - ANPFontMetrics fontMetrics; | |
182 | - gPaintI.getFontMetrics(m_paintText, &fontMetrics); | |
183 | - | |
184 | - // comput the circle dimensions and initial location | |
185 | - float initialX = passwordInput.rect.left + 5; | |
186 | - float ovalBottom = passwordInput.rect.bottom - 2; | |
187 | - float ovalTop = ovalBottom - (fontMetrics.fBottom - fontMetrics.fTop); | |
188 | - float ovalWidth = ovalBottom - ovalTop; | |
189 | - float ovalSpacing = 3; | |
190 | - | |
191 | - // draw circles instead of the actual text | |
192 | - for (uint32_t x = 0; x < passwordInput.charPtr; x++) { | |
193 | - ANPRectF oval; | |
194 | - oval.left = initialX + ((ovalWidth + ovalSpacing) * (float) x); | |
195 | - oval.right = oval.left + ovalWidth; | |
196 | - oval.top = ovalTop; | |
197 | - oval.bottom = ovalBottom; | |
198 | - gCanvasI.drawOval(canvas, &oval, m_paintText); | |
199 | - } | |
200 | -} | |
201 | - | |
202 | -int16 FormPlugin::handleEvent(const ANPEvent* evt) { | |
203 | - NPP instance = this->inst(); | |
204 | - | |
205 | - switch (evt->eventType) { | |
206 | - case kDraw_ANPEventType: | |
207 | - switch (evt->data.draw.model) { | |
208 | - case kBitmap_ANPDrawingModel: | |
209 | - drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip); | |
210 | - return 1; | |
211 | - default: | |
212 | - break; // unknown drawing model | |
213 | - } | |
214 | - break; | |
215 | - | |
216 | - case kLifecycle_ANPEventType: | |
217 | - if (evt->data.lifecycle.action == kLoseFocus_ANPLifecycleAction) { | |
218 | - gLogI.log(kDebug_ANPLogType, "----%p Loosing Focus", instance); | |
219 | - | |
220 | - if (m_activeInput) { | |
221 | - // hide the keyboard | |
222 | - gWindowI.showKeyboard(instance, false); | |
223 | - | |
224 | - //reset the activeInput | |
225 | - m_activeInput = NULL; | |
226 | - } | |
227 | - | |
228 | - m_hasFocus = false; | |
229 | - inval(instance); | |
230 | - return 1; | |
231 | - } | |
232 | - else if (evt->data.lifecycle.action == kGainFocus_ANPLifecycleAction) { | |
233 | - gLogI.log(kDebug_ANPLogType, "----%p Gaining Focus", instance); | |
234 | - m_hasFocus = true; | |
235 | - inval(instance); | |
236 | - return 1; | |
237 | - } | |
238 | - break; | |
239 | - | |
240 | - case kMouse_ANPEventType: { | |
241 | - | |
242 | - int x = evt->data.mouse.x; | |
243 | - int y = evt->data.mouse.y; | |
244 | - if (kDown_ANPMouseAction == evt->data.mouse.action) { | |
245 | - | |
246 | - TextInput* currentInput = validTap(x,y); | |
247 | - | |
248 | - if (currentInput) | |
249 | - gWindowI.showKeyboard(instance, true); | |
250 | - else if (m_activeInput) | |
251 | - gWindowI.showKeyboard(instance, false); | |
252 | - | |
253 | - if (currentInput != m_activeInput) | |
254 | - switchActiveInput(currentInput); | |
255 | - | |
256 | - return 1; | |
257 | - } | |
258 | - break; | |
259 | - } | |
260 | - | |
261 | - case kKey_ANPEventType: | |
262 | - if (evt->data.key.action == kDown_ANPKeyAction) { | |
263 | - | |
264 | - //handle navigation keys | |
265 | - if (evt->data.key.nativeCode >= kDpadUp_ANPKeyCode | |
266 | - && evt->data.key.nativeCode <= kDpadCenter_ANPKeyCode) { | |
267 | - return handleNavigation(evt->data.key.nativeCode) ? 1 : 0; | |
268 | - } | |
269 | - | |
270 | - if (m_activeInput) { | |
271 | - handleTextInput(m_activeInput, evt->data.key.nativeCode, | |
272 | - evt->data.key.unichar); | |
273 | - inval(instance, m_activeInput->rect, true); | |
274 | - } | |
275 | - } | |
276 | - return 1; | |
277 | - | |
278 | - default: | |
279 | - break; | |
280 | - } | |
281 | - return 0; // unknown or unhandled event | |
282 | -} | |
283 | - | |
284 | -void FormPlugin::switchActiveInput(TextInput* newInput) { | |
285 | - NPP instance = this->inst(); | |
286 | - | |
287 | - if (m_activeInput) { | |
288 | - inval(instance, m_activeInput->rect, true); // inval the old | |
289 | - gWindowI.clearVisibleRects(instance); | |
290 | - } | |
291 | - | |
292 | - m_activeInput = newInput; // set the new active input | |
293 | - | |
294 | - if (m_activeInput) { | |
295 | - inval(instance, m_activeInput->rect, true); // inval the new | |
296 | - scrollIntoView(m_activeInput); | |
297 | - } | |
298 | -} | |
299 | - | |
300 | -bool FormPlugin::handleNavigation(ANPKeyCode keyCode) { | |
301 | - NPP instance = this->inst(); | |
302 | - | |
303 | - gLogI.log(kDebug_ANPLogType, "----%p Recvd Nav Key %d", instance, keyCode); | |
304 | - | |
305 | - if (!m_activeInput) { | |
306 | - gWindowI.showKeyboard(instance, true); | |
307 | - switchActiveInput(&m_usernameInput); | |
308 | - } | |
309 | - else if (m_activeInput == &m_usernameInput) { | |
310 | - if (keyCode == kDpadDown_ANPKeyCode) { | |
311 | - switchActiveInput(&m_passwordInput); | |
312 | - } | |
313 | - else if (keyCode == kDpadCenter_ANPKeyCode) | |
314 | - gWindowI.showKeyboard(instance, false); | |
315 | - else if (keyCode == kDpadUp_ANPKeyCode) | |
316 | - return false; | |
317 | - } | |
318 | - else if (m_activeInput == &m_passwordInput) { | |
319 | - if (keyCode == kDpadUp_ANPKeyCode) { | |
320 | - switchActiveInput(&m_usernameInput); | |
321 | - } | |
322 | - else if (keyCode == kDpadCenter_ANPKeyCode) | |
323 | - gWindowI.showKeyboard(instance, false); | |
324 | - else if (keyCode == kDpadDown_ANPKeyCode) | |
325 | - return false; | |
326 | - } | |
327 | - | |
328 | - return true; | |
329 | -} | |
330 | - | |
331 | -void FormPlugin::handleTextInput(TextInput* input, ANPKeyCode keyCode, int32_t unichar) { | |
332 | - NPP instance = this->inst(); | |
333 | - | |
334 | - //make sure the input field is in view | |
335 | - scrollIntoView(input); | |
336 | - | |
337 | - //handle the delete operation | |
338 | - if (keyCode == kDel_ANPKeyCode) { | |
339 | - if (input->charPtr > 0) { | |
340 | - input->charPtr--; | |
341 | - } | |
342 | - return; | |
343 | - } | |
344 | - | |
345 | - //check to see that the input is not full | |
346 | - if (input->charPtr >= (sizeof(input->text) - 1)) | |
347 | - return; | |
348 | - | |
349 | - //add the character | |
350 | - input->text[input->charPtr] = static_cast<char>(unichar); | |
351 | - input->charPtr++; | |
352 | - | |
353 | - gLogI.log(kDebug_ANPLogType, "----%p Text: %c", instance, unichar); | |
354 | -} | |
355 | - | |
356 | -void FormPlugin::scrollIntoView(TextInput* input) { | |
357 | - NPP instance = this->inst(); | |
358 | - PluginObject *obj = (PluginObject*) instance->pdata; | |
359 | - NPWindow *window = obj->window; | |
360 | - | |
361 | - // find the textInput's global rect coordinates | |
362 | - ANPRectI visibleRects[1]; | |
363 | - visibleRects[0].left = input->rect.left; | |
364 | - visibleRects[0].top = input->rect.top; | |
365 | - visibleRects[0].right = input->rect.right; | |
366 | - visibleRects[0].bottom = input->rect.bottom; | |
367 | - | |
368 | - gWindowI.setVisibleRects(instance, visibleRects, 1); | |
369 | -} | |
370 | - | |
371 | -TextInput* FormPlugin::validTap(int x, int y) { | |
372 | - | |
373 | - if (x > m_usernameInput.rect.left && x < m_usernameInput.rect.right && | |
374 | - y > m_usernameInput.rect.top && y < m_usernameInput.rect.bottom) | |
375 | - return &m_usernameInput; | |
376 | - else if (x >m_passwordInput.rect.left && x < m_passwordInput.rect.right && | |
377 | - y > m_passwordInput.rect.top && y < m_passwordInput.rect.bottom) | |
378 | - return &m_passwordInput; | |
379 | - else | |
380 | - return NULL; | |
381 | -} |
@@ -1,72 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2008, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "PluginObject.h" | |
27 | - | |
28 | -#ifndef formPlugin__DEFINED | |
29 | -#define formPlugin__DEFINED | |
30 | - | |
31 | -struct TextInput { | |
32 | - ANPRectF rect; | |
33 | - char text[30]; | |
34 | - uint32_t charPtr; | |
35 | -}; | |
36 | - | |
37 | -class FormPlugin : public SubPlugin { | |
38 | -public: | |
39 | - FormPlugin(NPP inst); | |
40 | - virtual ~FormPlugin(); | |
41 | - virtual bool supportsDrawingModel(ANPDrawingModel); | |
42 | - virtual int16 handleEvent(const ANPEvent* evt); | |
43 | -private: | |
44 | - void draw(ANPCanvas*); | |
45 | - void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip); | |
46 | - | |
47 | - bool m_hasFocus; | |
48 | - | |
49 | - TextInput* m_activeInput; | |
50 | - TextInput m_usernameInput; | |
51 | - TextInput m_passwordInput; | |
52 | - | |
53 | - ANPPaint* m_paintInput; | |
54 | - ANPPaint* m_paintActive; | |
55 | - ANPPaint* m_paintText; | |
56 | - | |
57 | - ANPRectI m_visibleRect; | |
58 | - | |
59 | - void drawText(ANPCanvas*, TextInput); | |
60 | - void drawPassword(ANPCanvas*, TextInput); | |
61 | - | |
62 | - bool handleNavigation(ANPKeyCode keyCode); | |
63 | - void handleTextInput(TextInput* input, ANPKeyCode keyCode, int32_t unichar); | |
64 | - void scrollIntoView(TextInput* input); | |
65 | - void switchActiveInput(TextInput* input); | |
66 | - | |
67 | - ANPPaint* getPaint(TextInput*); | |
68 | - TextInput* validTap(int x, int y); | |
69 | - | |
70 | -}; | |
71 | - | |
72 | -#endif // formPlugin__DEFINED |
@@ -1,82 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright (C) 2009 The Android Open Source Project | |
3 | - * | |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
6 | - * You may obtain a copy of the License at | |
7 | - * | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - * See the License for the specific language governing permissions and | |
14 | - * limitations under the License. | |
15 | - * | |
16 | - */ | |
17 | -#include <string.h> | |
18 | -#include <jni.h> | |
19 | -#include <JNIHelp.h> | |
20 | -#include <utils/Log.h> | |
21 | - | |
22 | -#include "PluginObject.h" | |
23 | - | |
24 | -#define EXPORT __attribute__((visibility("default"))) | |
25 | - | |
26 | -extern ANPEventInterfaceV0 gEventI; | |
27 | - | |
28 | -static void surfaceCreated(JNIEnv* env, jobject thiz, jint npp, jobject surface) { | |
29 | - | |
30 | - // send custom event | |
31 | - ANPEvent event; | |
32 | - event.inSize = sizeof(ANPEvent); | |
33 | - event.eventType = kCustom_ANPEventType; | |
34 | - event.data.other[0] = kSurfaceCreated_CustomEvent; | |
35 | - | |
36 | - gEventI.postEvent((NPP)npp, &event); | |
37 | -} | |
38 | - | |
39 | -static void surfaceChanged(JNIEnv* env, jobject thiz, jint npp, jint format, jint width, jint height) { | |
40 | - // send custom event | |
41 | - ANPEvent event; | |
42 | - event.inSize = sizeof(ANPEvent); | |
43 | - event.eventType = kCustom_ANPEventType; | |
44 | - event.data.other[0] = kSurfaceChanged_CustomEvent; | |
45 | - event.data.other[1] = width; | |
46 | - event.data.other[2] = height; | |
47 | - | |
48 | - gEventI.postEvent((NPP)npp, &event); | |
49 | -} | |
50 | - | |
51 | -static void surfaceDestroyed(JNIEnv* env, jobject thiz, jint npp) { | |
52 | - // send custom event | |
53 | - ANPEvent event; | |
54 | - event.inSize = sizeof(ANPEvent); | |
55 | - event.eventType = kCustom_ANPEventType; | |
56 | - event.data.other[0] = kSurfaceDestroyed_CustomEvent; | |
57 | - | |
58 | - gEventI.postEvent((NPP)npp, &event); | |
59 | -} | |
60 | - | |
61 | -/* | |
62 | - * JNI registration. | |
63 | - */ | |
64 | -static JNINativeMethod gPaintSurfaceMethods[] = { | |
65 | - { "nativeSurfaceCreated", "(I)V", (void*) surfaceCreated }, | |
66 | - { "nativeSurfaceChanged", "(IIII)V", (void*) surfaceChanged }, | |
67 | - { "nativeSurfaceDestroyed", "(I)V", (void*) surfaceDestroyed }, | |
68 | -}; | |
69 | - | |
70 | -EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | |
71 | - | |
72 | - JNIEnv* env = NULL; | |
73 | - | |
74 | - if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { | |
75 | - return -1; | |
76 | - } | |
77 | - | |
78 | - jniRegisterNativeMethods(env, "com/android/sampleplugin/PaintSurface", | |
79 | - gPaintSurfaceMethods, NELEM(gPaintSurfaceMethods)); | |
80 | - | |
81 | - return JNI_VERSION_1_4; | |
82 | -} |
@@ -1,457 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2008, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include <stdlib.h> | |
27 | -#include <string.h> | |
28 | -#include <stdio.h> | |
29 | -#include "main.h" | |
30 | -#include "PluginObject.h" | |
31 | -#include "AnimationPlugin.h" | |
32 | -#include "AudioPlugin.h" | |
33 | -#include "BackgroundPlugin.h" | |
34 | -#include "FormPlugin.h" | |
35 | -#include "NavigationPlugin.h" | |
36 | -#include "PaintPlugin.h" | |
37 | -#include "VideoPlugin.h" | |
38 | - | |
39 | -NPNetscapeFuncs* browser; | |
40 | -JavaVM* gVM; | |
41 | - | |
42 | -#define EXPORT __attribute__((visibility("default"))) | |
43 | - | |
44 | -NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, | |
45 | - char* argn[], char* argv[], NPSavedData* saved); | |
46 | -NPError NPP_Destroy(NPP instance, NPSavedData** save); | |
47 | -NPError NPP_SetWindow(NPP instance, NPWindow* window); | |
48 | -NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, | |
49 | - NPBool seekable, uint16* stype); | |
50 | -NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason); | |
51 | -int32 NPP_WriteReady(NPP instance, NPStream* stream); | |
52 | -int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, | |
53 | - void* buffer); | |
54 | -void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname); | |
55 | -void NPP_Print(NPP instance, NPPrint* platformPrint); | |
56 | -int16 NPP_HandleEvent(NPP instance, void* event); | |
57 | -void NPP_URLNotify(NPP instance, const char* URL, NPReason reason, | |
58 | - void* notifyData); | |
59 | -NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value); | |
60 | -NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value); | |
61 | - | |
62 | -extern "C" { | |
63 | -EXPORT NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env); | |
64 | -EXPORT NPError NP_GetValue(NPP instance, NPPVariable variable, void *value); | |
65 | -EXPORT const char* NP_GetMIMEDescription(void); | |
66 | -EXPORT void NP_Shutdown(void); | |
67 | -}; | |
68 | - | |
69 | -ANPAudioTrackInterfaceV0 gSoundI; | |
70 | -ANPBitmapInterfaceV0 gBitmapI; | |
71 | -ANPCanvasInterfaceV0 gCanvasI; | |
72 | -ANPEventInterfaceV0 gEventI; | |
73 | -ANPLogInterfaceV0 gLogI; | |
74 | -ANPPaintInterfaceV0 gPaintI; | |
75 | -ANPPathInterfaceV0 gPathI; | |
76 | -ANPSurfaceInterfaceV0 gSurfaceI; | |
77 | -ANPSystemInterfaceV0 gSystemI; | |
78 | -ANPTypefaceInterfaceV0 gTypefaceI; | |
79 | -ANPWindowInterfaceV0 gWindowI; | |
80 | - | |
81 | -#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) | |
82 | -#define DEBUG_PLUGIN_EVENTS 0 | |
83 | - | |
84 | -NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env) | |
85 | -{ | |
86 | - // Make sure we have a function table equal or larger than we are built against. | |
87 | - if (browserFuncs->size < sizeof(NPNetscapeFuncs)) { | |
88 | - return NPERR_GENERIC_ERROR; | |
89 | - } | |
90 | - | |
91 | - // Copy the function table (structure) | |
92 | - browser = (NPNetscapeFuncs*) malloc(sizeof(NPNetscapeFuncs)); | |
93 | - memcpy(browser, browserFuncs, sizeof(NPNetscapeFuncs)); | |
94 | - | |
95 | - // Build the plugin function table | |
96 | - pluginFuncs->version = 11; | |
97 | - pluginFuncs->size = sizeof(pluginFuncs); | |
98 | - pluginFuncs->newp = NPP_New; | |
99 | - pluginFuncs->destroy = NPP_Destroy; | |
100 | - pluginFuncs->setwindow = NPP_SetWindow; | |
101 | - pluginFuncs->newstream = NPP_NewStream; | |
102 | - pluginFuncs->destroystream = NPP_DestroyStream; | |
103 | - pluginFuncs->asfile = NPP_StreamAsFile; | |
104 | - pluginFuncs->writeready = NPP_WriteReady; | |
105 | - pluginFuncs->write = (NPP_WriteProcPtr)NPP_Write; | |
106 | - pluginFuncs->print = NPP_Print; | |
107 | - pluginFuncs->event = NPP_HandleEvent; | |
108 | - pluginFuncs->urlnotify = NPP_URLNotify; | |
109 | - pluginFuncs->getvalue = NPP_GetValue; | |
110 | - pluginFuncs->setvalue = NPP_SetValue; | |
111 | - | |
112 | - static const struct { | |
113 | - NPNVariable v; | |
114 | - uint32_t size; | |
115 | - ANPInterface* i; | |
116 | - } gPairs[] = { | |
117 | - { kAudioTrackInterfaceV0_ANPGetValue, sizeof(gSoundI), &gSoundI }, | |
118 | - { kBitmapInterfaceV0_ANPGetValue, sizeof(gBitmapI), &gBitmapI }, | |
119 | - { kCanvasInterfaceV0_ANPGetValue, sizeof(gCanvasI), &gCanvasI }, | |
120 | - { kEventInterfaceV0_ANPGetValue, sizeof(gEventI), &gEventI }, | |
121 | - { kLogInterfaceV0_ANPGetValue, sizeof(gLogI), &gLogI }, | |
122 | - { kPaintInterfaceV0_ANPGetValue, sizeof(gPaintI), &gPaintI }, | |
123 | - { kPathInterfaceV0_ANPGetValue, sizeof(gPathI), &gPathI }, | |
124 | - { kSurfaceInterfaceV0_ANPGetValue, sizeof(gSurfaceI), &gSurfaceI }, | |
125 | - { kSystemInterfaceV0_ANPGetValue, sizeof(gSystemI), &gSystemI }, | |
126 | - { kTypefaceInterfaceV0_ANPGetValue, sizeof(gTypefaceI), &gTypefaceI }, | |
127 | - { kWindowInterfaceV0_ANPGetValue, sizeof(gWindowI), &gWindowI }, | |
128 | - }; | |
129 | - for (size_t i = 0; i < ARRAY_COUNT(gPairs); i++) { | |
130 | - gPairs[i].i->inSize = gPairs[i].size; | |
131 | - NPError err = browser->getvalue(NULL, gPairs[i].v, gPairs[i].i); | |
132 | - if (err) { | |
133 | - return err; | |
134 | - } | |
135 | - } | |
136 | - | |
137 | - // store the JavaVM for the plugin | |
138 | - JNIEnv* env = (JNIEnv*)java_env; | |
139 | - env->GetJavaVM(&gVM); | |
140 | - | |
141 | - return NPERR_NO_ERROR; | |
142 | -} | |
143 | - | |
144 | -void NP_Shutdown(void) | |
145 | -{ | |
146 | - | |
147 | -} | |
148 | - | |
149 | -const char *NP_GetMIMEDescription(void) | |
150 | -{ | |
151 | - return "application/x-testbrowserplugin:tst:Test plugin mimetype is application/x-testbrowserplugin"; | |
152 | -} | |
153 | - | |
154 | -NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, | |
155 | - char* argn[], char* argv[], NPSavedData* saved) | |
156 | -{ | |
157 | - | |
158 | - /* BEGIN: STANDARD PLUGIN FRAMEWORK */ | |
159 | - PluginObject *obj = NULL; | |
160 | - | |
161 | - // Scripting functions appeared in NPAPI version 14 | |
162 | - if (browser->version >= 14) { | |
163 | - instance->pdata = browser->createobject (instance, getPluginClass()); | |
164 | - obj = static_cast<PluginObject*>(instance->pdata); | |
165 | - } | |
166 | - /* END: STANDARD PLUGIN FRAMEWORK */ | |
167 | - | |
168 | - // select the drawing model based on user input | |
169 | - ANPDrawingModel model = kBitmap_ANPDrawingModel; | |
170 | - | |
171 | - for (int i = 0; i < argc; i++) { | |
172 | - if (!strcmp(argn[i], "DrawingModel")) { | |
173 | - if (!strcmp(argv[i], "Bitmap")) { | |
174 | - model = kBitmap_ANPDrawingModel; | |
175 | - } | |
176 | - else if (!strcmp(argv[i], "Surface")) { | |
177 | - model = kSurface_ANPDrawingModel; | |
178 | - } | |
179 | - gLogI.log(kDebug_ANPLogType, "------ %p DrawingModel is %d", instance, model); | |
180 | - break; | |
181 | - } | |
182 | - } | |
183 | - | |
184 | - // notify the plugin API of the drawing model we wish to use. This must be | |
185 | - // done prior to creating certain subPlugin objects (e.g. surfaceViews) | |
186 | - NPError err = browser->setvalue(instance, kRequestDrawingModel_ANPSetValue, | |
187 | - reinterpret_cast<void*>(model)); | |
188 | - if (err) { | |
189 | - gLogI.log(kError_ANPLogType, "request model %d err %d", model, err); | |
190 | - return err; | |
191 | - } | |
192 | - | |
193 | - const char* path = gSystemI.getApplicationDataDirectory(); | |
194 | - if (path) { | |
195 | - gLogI.log(kDebug_ANPLogType, "Application data dir is %s", path); | |
196 | - } else { | |
197 | - gLogI.log(kError_ANPLogType, "Can't find Application data dir"); | |
198 | - } | |
199 | - | |
200 | - // select the pluginType | |
201 | - for (int i = 0; i < argc; i++) { | |
202 | - if (!strcmp(argn[i], "PluginType")) { | |
203 | - if (!strcmp(argv[i], "Animation")) { | |
204 | - obj->pluginType = kAnimation_PluginType; | |
205 | - obj->activePlugin = new BallAnimation(instance); | |
206 | - } | |
207 | - else if (!strcmp(argv[i], "Audio")) { | |
208 | - obj->pluginType = kAudio_PluginType; | |
209 | - obj->activePlugin = new AudioPlugin(instance); | |
210 | - } | |
211 | - else if (!strcmp(argv[i], "Background")) { | |
212 | - obj->pluginType = kBackground_PluginType; | |
213 | - obj->activePlugin = new BackgroundPlugin(instance); | |
214 | - } | |
215 | - else if (!strcmp(argv[i], "Form")) { | |
216 | - obj->pluginType = kForm_PluginType; | |
217 | - obj->activePlugin = new FormPlugin(instance); | |
218 | - } | |
219 | - else if (!strcmp(argv[i], "Navigation")) { | |
220 | - obj->pluginType = kNavigation_PluginType; | |
221 | - obj->activePlugin = new NavigationPlugin(instance); | |
222 | - } | |
223 | - else if (!strcmp(argv[i], "Paint")) { | |
224 | - obj->pluginType = kPaint_PluginType; | |
225 | - obj->activePlugin = new PaintPlugin(instance); | |
226 | - } | |
227 | - else if (!strcmp(argv[i], "Video")) { | |
228 | - obj->pluginType = kVideo_PluginType; | |
229 | - obj->activePlugin = new VideoPlugin(instance); | |
230 | - } | |
231 | - gLogI.log(kDebug_ANPLogType, "------ %p PluginType is %d", instance, obj->pluginType); | |
232 | - break; | |
233 | - } | |
234 | - } | |
235 | - | |
236 | - // if no pluginType is specified then default to Animation | |
237 | - if (!obj->pluginType) { | |
238 | - gLogI.log(kError_ANPLogType, "------ %p No PluginType attribute was found", instance); | |
239 | - obj->pluginType = kAnimation_PluginType; | |
240 | - obj->activePlugin = new BallAnimation(instance); | |
241 | - } | |
242 | - | |
243 | - // check to ensure the pluginType supports the model | |
244 | - if (!obj->activePlugin->supportsDrawingModel(model)) { | |
245 | - gLogI.log(kError_ANPLogType, "------ %p Unsupported DrawingModel (%d)", instance, model); | |
246 | - return NPERR_GENERIC_ERROR; | |
247 | - } | |
248 | - | |
249 | - // if the plugin uses the surface drawing model then set the java context | |
250 | - if (model == kSurface_ANPDrawingModel) { | |
251 | - SurfaceSubPlugin* surfacePlugin = static_cast<SurfaceSubPlugin*>(obj->activePlugin); | |
252 | - | |
253 | - jobject context; | |
254 | - NPError err = browser->getvalue(instance, kJavaContext_ANPGetValue, | |
255 | - static_cast<void*>(&context)); | |
256 | - if (err) { | |
257 | - gLogI.log(kError_ANPLogType, "request context err: %d", err); | |
258 | - return err; | |
259 | - } | |
260 | - | |
261 | - surfacePlugin->setContext(context); | |
262 | - } | |
263 | - | |
264 | - | |
265 | - return NPERR_NO_ERROR; | |
266 | -} | |
267 | - | |
268 | -NPError NPP_Destroy(NPP instance, NPSavedData** save) | |
269 | -{ | |
270 | - PluginObject *obj = (PluginObject*) instance->pdata; | |
271 | - if (obj) { | |
272 | - delete obj->activePlugin; | |
273 | - browser->releaseobject(&obj->header); | |
274 | - } | |
275 | - | |
276 | - return NPERR_NO_ERROR; | |
277 | -} | |
278 | - | |
279 | -NPError NPP_SetWindow(NPP instance, NPWindow* window) | |
280 | -{ | |
281 | - PluginObject *obj = (PluginObject*) instance->pdata; | |
282 | - | |
283 | - // Do nothing if browser didn't support NPN_CreateObject which would have created the PluginObject. | |
284 | - if (obj != NULL) { | |
285 | - obj->window = window; | |
286 | - } | |
287 | - | |
288 | - browser->invalidaterect(instance, NULL); | |
289 | - | |
290 | - return NPERR_NO_ERROR; | |
291 | -} | |
292 | - | |
293 | -NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) | |
294 | -{ | |
295 | - *stype = NP_ASFILEONLY; | |
296 | - return NPERR_NO_ERROR; | |
297 | -} | |
298 | - | |
299 | -NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) | |
300 | -{ | |
301 | - return NPERR_NO_ERROR; | |
302 | -} | |
303 | - | |
304 | -int32 NPP_WriteReady(NPP instance, NPStream* stream) | |
305 | -{ | |
306 | - return 0; | |
307 | -} | |
308 | - | |
309 | -int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer) | |
310 | -{ | |
311 | - return 0; | |
312 | -} | |
313 | - | |
314 | -void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) | |
315 | -{ | |
316 | -} | |
317 | - | |
318 | -void NPP_Print(NPP instance, NPPrint* platformPrint) | |
319 | -{ | |
320 | -} | |
321 | - | |
322 | -int16 NPP_HandleEvent(NPP instance, void* event) | |
323 | -{ | |
324 | - PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata); | |
325 | - const ANPEvent* evt = reinterpret_cast<const ANPEvent*>(event); | |
326 | - | |
327 | -#if DEBUG_PLUGIN_EVENTS | |
328 | - switch (evt->eventType) { | |
329 | - case kDraw_ANPEventType: | |
330 | - | |
331 | - if (evt->data.draw.model == kBitmap_ANPDrawingModel) { | |
332 | - | |
333 | - static ANPBitmapFormat currentFormat = -1; | |
334 | - if (evt->data.draw.data.bitmap.format != currentFormat) { | |
335 | - currentFormat = evt->data.draw.data.bitmap.format; | |
336 | - gLogI.log(kDebug_ANPLogType, "---- %p Draw (bitmap)" | |
337 | - " clip=%d,%d,%d,%d format=%d", instance, | |
338 | - evt->data.draw.clip.left, | |
339 | - evt->data.draw.clip.top, | |
340 | - evt->data.draw.clip.right, | |
341 | - evt->data.draw.clip.bottom, | |
342 | - evt->data.draw.data.bitmap.format); | |
343 | - } | |
344 | - } | |
345 | - break; | |
346 | - | |
347 | - case kKey_ANPEventType: | |
348 | - gLogI.log(kDebug_ANPLogType, "---- %p Key action=%d" | |
349 | - " code=%d vcode=%d unichar=%d repeat=%d mods=%x", instance, | |
350 | - evt->data.key.action, | |
351 | - evt->data.key.nativeCode, | |
352 | - evt->data.key.virtualCode, | |
353 | - evt->data.key.unichar, | |
354 | - evt->data.key.repeatCount, | |
355 | - evt->data.key.modifiers); | |
356 | - break; | |
357 | - | |
358 | - case kLifecycle_ANPEventType: | |
359 | - gLogI.log(kDebug_ANPLogType, "---- %p Lifecycle action=%d", | |
360 | - instance, evt->data.lifecycle.action); | |
361 | - break; | |
362 | - | |
363 | - case kTouch_ANPEventType: | |
364 | - gLogI.log(kDebug_ANPLogType, "---- %p Touch action=%d [%d %d]", | |
365 | - instance, evt->data.touch.action, evt->data.touch.x, | |
366 | - evt->data.touch.y); | |
367 | - break; | |
368 | - | |
369 | - case kMouse_ANPEventType: | |
370 | - gLogI.log(kDebug_ANPLogType, "---- %p Mouse action=%d [%d %d]", | |
371 | - instance, evt->data.mouse.action, evt->data.mouse.x, | |
372 | - evt->data.mouse.y); | |
373 | - break; | |
374 | - | |
375 | - case kVisibleRect_ANPEventType: | |
376 | - gLogI.log(kDebug_ANPLogType, "---- %p VisibleRect [%d %d %d %d]", | |
377 | - instance, evt->data.visibleRect.rect.left, evt->data.visibleRect.rect.top, | |
378 | - evt->data.visibleRect.rect.right, evt->data.visibleRect.rect.bottom); | |
379 | - break; | |
380 | - | |
381 | - default: | |
382 | - gLogI.log(kError_ANPLogType, "---- %p Unknown Event [%d]", | |
383 | - instance, evt->eventType); | |
384 | - break; | |
385 | - } | |
386 | -#endif | |
387 | - | |
388 | - if(!obj->activePlugin) { | |
389 | - gLogI.log(kError_ANPLogType, "the active plugin is null."); | |
390 | - return 0; // unknown or unhandled event | |
391 | - } | |
392 | - else { | |
393 | - return obj->activePlugin->handleEvent(evt); | |
394 | - } | |
395 | -} | |
396 | - | |
397 | -void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) | |
398 | -{ | |
399 | - | |
400 | -} | |
401 | - | |
402 | -EXPORT NPError NP_GetValue(NPP instance, NPPVariable variable, void *value) { | |
403 | - | |
404 | - if (variable == NPPVpluginNameString) { | |
405 | - const char **str = (const char **)value; | |
406 | - *str = "Test Plugin"; | |
407 | - return NPERR_NO_ERROR; | |
408 | - } | |
409 | - | |
410 | - if (variable == NPPVpluginDescriptionString) { | |
411 | - const char **str = (const char **)value; | |
412 | - *str = "Description of Test Plugin"; | |
413 | - return NPERR_NO_ERROR; | |
414 | - } | |
415 | - | |
416 | - return NPERR_GENERIC_ERROR; | |
417 | -} | |
418 | - | |
419 | -NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) | |
420 | -{ | |
421 | - if (variable == NPPVpluginScriptableNPObject) { | |
422 | - void **v = (void **)value; | |
423 | - PluginObject *obj = (PluginObject*) instance->pdata; | |
424 | - | |
425 | - if (obj) | |
426 | - browser->retainobject(&obj->header); | |
427 | - | |
428 | - *v = &(obj->header); | |
429 | - return NPERR_NO_ERROR; | |
430 | - } | |
431 | - | |
432 | - if (variable == kJavaSurface_ANPGetValue) { | |
433 | - //get the surface sub-plugin | |
434 | - PluginObject* obj = static_cast<PluginObject*>(instance->pdata); | |
435 | - if (obj && obj->activePlugin) { | |
436 | - | |
437 | - if(obj->activePlugin->supportsDrawingModel(kSurface_ANPDrawingModel)) { | |
438 | - SurfaceSubPlugin* plugin = static_cast<SurfaceSubPlugin*>(obj->activePlugin); | |
439 | - jobject* surface = static_cast<jobject*>(value); | |
440 | - *surface = plugin->getSurface(); | |
441 | - return NPERR_NO_ERROR; | |
442 | - } else { | |
443 | - gLogI.log(kError_ANPLogType, | |
444 | - "-- %p Tried to retrieve surface for non-surface plugin", | |
445 | - instance); | |
446 | - } | |
447 | - } | |
448 | - } | |
449 | - | |
450 | - return NPERR_GENERIC_ERROR; | |
451 | -} | |
452 | - | |
453 | -NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) | |
454 | -{ | |
455 | - return NPERR_GENERIC_ERROR; | |
456 | -} | |
457 | - |
@@ -1,34 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2008, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include <npapi.h> | |
27 | -#include <npfunctions.h> | |
28 | -#include <npruntime.h> | |
29 | -#include "android_npapi.h" | |
30 | -#include "ANPSurface_npapi.h" | |
31 | -#include "ANPSystem_npapi.h" | |
32 | - | |
33 | -extern NPNetscapeFuncs* browser; | |
34 | -extern JavaVM* gVM; |
@@ -1,242 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2010, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "NavigationPlugin.h" | |
27 | - | |
28 | -#include <stdio.h> | |
29 | -#include <sys/time.h> | |
30 | -#include <time.h> | |
31 | -#include <math.h> | |
32 | -#include <string.h> | |
33 | - | |
34 | -extern NPNetscapeFuncs* browser; | |
35 | -extern ANPLogInterfaceV0 gLogI; | |
36 | -extern ANPCanvasInterfaceV0 gCanvasI; | |
37 | -extern ANPPaintInterfaceV0 gPaintI; | |
38 | -extern ANPTypefaceInterfaceV0 gTypefaceI; | |
39 | -extern ANPWindowInterfaceV0 gWindowI; | |
40 | - | |
41 | - | |
42 | -static void inval(NPP instance) { | |
43 | - browser->invalidaterect(instance, NULL); | |
44 | -} | |
45 | - | |
46 | -static uint16 rnd16(float x, int inset) { | |
47 | - int ix = (int)roundf(x) + inset; | |
48 | - if (ix < 0) { | |
49 | - ix = 0; | |
50 | - } | |
51 | - return static_cast<uint16>(ix); | |
52 | -} | |
53 | - | |
54 | -static void inval(NPP instance, const ANPRectF& r, bool doAA) { | |
55 | - const int inset = doAA ? -1 : 0; | |
56 | - | |
57 | - PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata); | |
58 | - NPRect inval; | |
59 | - inval.left = rnd16(r.left, inset); | |
60 | - inval.top = rnd16(r.top, inset); | |
61 | - inval.right = rnd16(r.right, -inset); | |
62 | - inval.bottom = rnd16(r.bottom, -inset); | |
63 | - browser->invalidaterect(instance, &inval); | |
64 | -} | |
65 | - | |
66 | -/////////////////////////////////////////////////////////////////////////////// | |
67 | - | |
68 | -NavigationPlugin::NavigationPlugin(NPP inst) : SubPlugin(inst) { | |
69 | - | |
70 | - m_hasFocus = false; | |
71 | - m_activeNav = NULL; | |
72 | - | |
73 | - m_paintDisabled = gPaintI.newPaint(); | |
74 | - gPaintI.setFlags(m_paintDisabled, gPaintI.getFlags(m_paintDisabled) | kAntiAlias_ANPPaintFlag); | |
75 | - gPaintI.setColor(m_paintDisabled, 0xFFFFFFFF); | |
76 | - | |
77 | - m_paintActive = gPaintI.newPaint(); | |
78 | - gPaintI.setFlags(m_paintActive, gPaintI.getFlags(m_paintActive) | kAntiAlias_ANPPaintFlag); | |
79 | - gPaintI.setColor(m_paintActive, 0xFFFFFF00); | |
80 | - | |
81 | - //register for key events | |
82 | - ANPEventFlags flags = kKey_ANPEventFlag; | |
83 | - NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); | |
84 | - if (err != NPERR_NO_ERROR) { | |
85 | - gLogI.log(kError_ANPLogType, "Error selecting input events."); | |
86 | - } | |
87 | -} | |
88 | - | |
89 | -NavigationPlugin::~NavigationPlugin() { | |
90 | - gPaintI.deletePaint(m_paintDisabled); | |
91 | - gPaintI.deletePaint(m_paintActive); | |
92 | -} | |
93 | - | |
94 | -bool NavigationPlugin::supportsDrawingModel(ANPDrawingModel model) { | |
95 | - return (model == kBitmap_ANPDrawingModel); | |
96 | -} | |
97 | - | |
98 | -void NavigationPlugin::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) { | |
99 | - ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap); | |
100 | - | |
101 | - ANPRectF clipR; | |
102 | - clipR.left = clip.left; | |
103 | - clipR.top = clip.top; | |
104 | - clipR.right = clip.right; | |
105 | - clipR.bottom = clip.bottom; | |
106 | - gCanvasI.clipRect(canvas, &clipR); | |
107 | - | |
108 | - draw(canvas); | |
109 | - gCanvasI.deleteCanvas(canvas); | |
110 | -} | |
111 | - | |
112 | -void NavigationPlugin::draw(ANPCanvas* canvas) { | |
113 | - NPP instance = this->inst(); | |
114 | - PluginObject *obj = (PluginObject*) instance->pdata; | |
115 | - | |
116 | - const int W = obj->window->width; | |
117 | - const int H = obj->window->height; | |
118 | - const int Wm = W/2; | |
119 | - const int Hm = H/2; | |
120 | - | |
121 | - // color the plugin canvas | |
122 | - gCanvasI.drawColor(canvas, (m_hasFocus) ? 0xFFCDCDCD : 0xFF545454); | |
123 | - | |
124 | - // draw the nav up box (5 px from the top edge) | |
125 | - m_navUp.left = Wm - 15; | |
126 | - m_navUp.top = 5; | |
127 | - m_navUp.right = m_navUp.left + 30; | |
128 | - m_navUp.bottom = m_navUp.top + 30; | |
129 | - gCanvasI.drawRect(canvas, &m_navUp, getPaint(&m_navUp)); | |
130 | - | |
131 | - // draw the nav down box (5 px from the bottom edge) | |
132 | - m_navDown.left = Wm - 15; | |
133 | - m_navDown.top = H - (30 + 5); | |
134 | - m_navDown.right = m_navDown.left + 30; | |
135 | - m_navDown.bottom = m_navDown.top + 30; | |
136 | - gCanvasI.drawRect(canvas, &m_navDown, getPaint(&m_navDown)); | |
137 | - | |
138 | - // draw the nav left box (5 px from the left edge) | |
139 | - m_navLeft.left = 5; | |
140 | - m_navLeft.top = Hm - 15; | |
141 | - m_navLeft.right = m_navLeft.left + 30; | |
142 | - m_navLeft.bottom = m_navLeft.top + 30; | |
143 | - gCanvasI.drawRect(canvas, &m_navLeft, getPaint(&m_navLeft)); | |
144 | - | |
145 | - // draw the nav right box (5 px from the right edge) | |
146 | - m_navRight.left = W - (30 + 5); | |
147 | - m_navRight.top = Hm - 15; | |
148 | - m_navRight.right = m_navRight.left + 30; | |
149 | - m_navRight.bottom = m_navRight.top + 30; | |
150 | - gCanvasI.drawRect(canvas, &m_navRight, getPaint(&m_navRight)); | |
151 | - | |
152 | - // draw the nav center box | |
153 | - m_navCenter.left = Wm - 15; | |
154 | - m_navCenter.top = Hm - 15; | |
155 | - m_navCenter.right = m_navCenter.left + 30; | |
156 | - m_navCenter.bottom = m_navCenter.top + 30; | |
157 | - gCanvasI.drawRect(canvas, &m_navCenter, getPaint(&m_navCenter)); | |
158 | - | |
159 | - gLogI.log(kDebug_ANPLogType, "----%p Drawing Plugin", inst()); | |
160 | -} | |
161 | - | |
162 | -ANPPaint* NavigationPlugin::getPaint(ANPRectF* input) { | |
163 | - return (input == m_activeNav) ? m_paintActive : m_paintDisabled; | |
164 | -} | |
165 | - | |
166 | -int16 NavigationPlugin::handleEvent(const ANPEvent* evt) { | |
167 | - NPP instance = this->inst(); | |
168 | - | |
169 | - switch (evt->eventType) { | |
170 | - case kDraw_ANPEventType: | |
171 | - switch (evt->data.draw.model) { | |
172 | - case kBitmap_ANPDrawingModel: | |
173 | - drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip); | |
174 | - return 1; | |
175 | - default: | |
176 | - break; // unknown drawing model | |
177 | - } | |
178 | - break; | |
179 | - | |
180 | - case kLifecycle_ANPEventType: | |
181 | - if (evt->data.lifecycle.action == kLoseFocus_ANPLifecycleAction) { | |
182 | - gLogI.log(kDebug_ANPLogType, "----%p Loosing Focus", instance); | |
183 | - m_hasFocus = false; | |
184 | - inval(instance); | |
185 | - return 1; | |
186 | - } | |
187 | - else if (evt->data.lifecycle.action == kGainFocus_ANPLifecycleAction) { | |
188 | - gLogI.log(kDebug_ANPLogType, "----%p Gaining Focus", instance); | |
189 | - m_hasFocus = true; | |
190 | - inval(instance); | |
191 | - return 1; | |
192 | - } | |
193 | - break; | |
194 | - | |
195 | - case kMouse_ANPEventType: | |
196 | - return 1; | |
197 | - | |
198 | - case kKey_ANPEventType: | |
199 | - if (evt->data.key.action == kDown_ANPKeyAction) { | |
200 | - bool result = handleNavigation(evt->data.key.nativeCode); | |
201 | - inval(instance); | |
202 | - return result; | |
203 | - } | |
204 | - return 1; | |
205 | - | |
206 | - default: | |
207 | - break; | |
208 | - } | |
209 | - return 0; // unknown or unhandled event | |
210 | -} | |
211 | - | |
212 | -bool NavigationPlugin::handleNavigation(ANPKeyCode keyCode) { | |
213 | - NPP instance = this->inst(); | |
214 | - | |
215 | - gLogI.log(kDebug_ANPLogType, "----%p Received Key %d", instance, keyCode); | |
216 | - | |
217 | - switch (keyCode) { | |
218 | - case kDpadUp_ANPKeyCode: | |
219 | - m_activeNav = &m_navUp; | |
220 | - break; | |
221 | - case kDpadDown_ANPKeyCode: | |
222 | - m_activeNav = &m_navDown; | |
223 | - break; | |
224 | - case kDpadLeft_ANPKeyCode: | |
225 | - m_activeNav = &m_navLeft; | |
226 | - break; | |
227 | - case kDpadRight_ANPKeyCode: | |
228 | - m_activeNav = &m_navRight; | |
229 | - break; | |
230 | - case kDpadCenter_ANPKeyCode: | |
231 | - m_activeNav = &m_navCenter; | |
232 | - break; | |
233 | - case kQ_ANPKeyCode: | |
234 | - case kDel_ANPKeyCode: | |
235 | - m_activeNav = NULL; | |
236 | - return false; | |
237 | - default: | |
238 | - m_activeNav = NULL; | |
239 | - break; | |
240 | - } | |
241 | - return true; | |
242 | -} |
@@ -1,57 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2010, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "PluginObject.h" | |
27 | - | |
28 | -#ifndef navigationPlugin__DEFINED | |
29 | -#define navigationPlugin__DEFINED | |
30 | - | |
31 | -class NavigationPlugin : public SubPlugin { | |
32 | -public: | |
33 | - NavigationPlugin(NPP inst); | |
34 | - virtual ~NavigationPlugin(); | |
35 | - virtual bool supportsDrawingModel(ANPDrawingModel); | |
36 | - virtual int16 handleEvent(const ANPEvent* evt); | |
37 | -private: | |
38 | - void draw(ANPCanvas*); | |
39 | - void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip); | |
40 | - | |
41 | - bool m_hasFocus; | |
42 | - | |
43 | - ANPRectF* m_activeNav; | |
44 | - ANPRectF m_navUp; | |
45 | - ANPRectF m_navDown; | |
46 | - ANPRectF m_navLeft; | |
47 | - ANPRectF m_navRight; | |
48 | - ANPRectF m_navCenter; | |
49 | - | |
50 | - ANPPaint* m_paintDisabled; | |
51 | - ANPPaint* m_paintActive; | |
52 | - | |
53 | - bool handleNavigation(ANPKeyCode keyCode); | |
54 | - ANPPaint* getPaint(ANPRectF*); | |
55 | -}; | |
56 | - | |
57 | -#endif // navigationPlugin__DEFINED |
@@ -1,462 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2009, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "PaintPlugin.h" | |
27 | - | |
28 | -#include <fcntl.h> | |
29 | -#include <math.h> | |
30 | -#include <string.h> | |
31 | - | |
32 | -extern NPNetscapeFuncs* browser; | |
33 | -extern ANPLogInterfaceV0 gLogI; | |
34 | -extern ANPCanvasInterfaceV0 gCanvasI; | |
35 | -extern ANPPaintInterfaceV0 gPaintI; | |
36 | -extern ANPPathInterfaceV0 gPathI; | |
37 | -extern ANPSurfaceInterfaceV0 gSurfaceI; | |
38 | -extern ANPSystemInterfaceV0 gSystemI; | |
39 | -extern ANPTypefaceInterfaceV0 gTypefaceI; | |
40 | -extern ANPWindowInterfaceV0 gWindowI; | |
41 | - | |
42 | -/////////////////////////////////////////////////////////////////////////////// | |
43 | - | |
44 | -PaintPlugin::PaintPlugin(NPP inst) : SurfaceSubPlugin(inst) { | |
45 | - | |
46 | - m_isTouchActive = false; | |
47 | - m_isTouchCurrentInput = true; | |
48 | - m_activePaintColor = s_redColor; | |
49 | - | |
50 | - memset(&m_drawingSurface, 0, sizeof(m_drawingSurface)); | |
51 | - memset(&m_inputToggle, 0, sizeof(m_inputToggle)); | |
52 | - memset(&m_colorToggle, 0, sizeof(m_colorToggle)); | |
53 | - memset(&m_fullScreenToggle, 0, sizeof(m_fullScreenToggle)); | |
54 | - memset(&m_clearSurface, 0, sizeof(m_clearSurface)); | |
55 | - | |
56 | - // initialize the drawing surface | |
57 | - m_surface = NULL; | |
58 | - | |
59 | - // initialize the path | |
60 | - m_touchPath = gPathI.newPath(); | |
61 | - if(!m_touchPath) | |
62 | - gLogI.log(kError_ANPLogType, "----%p Unable to create the touch path", inst); | |
63 | - | |
64 | - // initialize the paint colors | |
65 | - m_paintSurface = gPaintI.newPaint(); | |
66 | - gPaintI.setFlags(m_paintSurface, gPaintI.getFlags(m_paintSurface) | kAntiAlias_ANPPaintFlag); | |
67 | - gPaintI.setColor(m_paintSurface, 0xFFC0C0C0); | |
68 | - gPaintI.setTextSize(m_paintSurface, 18); | |
69 | - | |
70 | - m_paintButton = gPaintI.newPaint(); | |
71 | - gPaintI.setFlags(m_paintButton, gPaintI.getFlags(m_paintButton) | kAntiAlias_ANPPaintFlag); | |
72 | - gPaintI.setColor(m_paintButton, 0xFFA8A8A8); | |
73 | - | |
74 | - // initialize the typeface (set the colors) | |
75 | - ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); | |
76 | - gPaintI.setTypeface(m_paintSurface, tf); | |
77 | - gTypefaceI.unref(tf); | |
78 | - | |
79 | - //register for touch events | |
80 | - ANPEventFlags flags = kTouch_ANPEventFlag; | |
81 | - NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); | |
82 | - if (err != NPERR_NO_ERROR) { | |
83 | - gLogI.log(kError_ANPLogType, "Error selecting input events."); | |
84 | - } | |
85 | -} | |
86 | - | |
87 | -PaintPlugin::~PaintPlugin() { | |
88 | - gPathI.deletePath(m_touchPath); | |
89 | - gPaintI.deletePaint(m_paintSurface); | |
90 | - gPaintI.deletePaint(m_paintButton); | |
91 | - | |
92 | - setContext(NULL); | |
93 | - destroySurface(); | |
94 | -} | |
95 | - | |
96 | -ANPCanvas* PaintPlugin::getCanvas(ANPRectI* dirtyRect) { | |
97 | - | |
98 | - ANPBitmap bitmap; | |
99 | - JNIEnv* env = NULL; | |
100 | - if (!m_surface || gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK || | |
101 | - !gSurfaceI.lock(env, m_surface, &bitmap, dirtyRect)) { | |
102 | - return NULL; | |
103 | - } | |
104 | - | |
105 | - ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap); | |
106 | - | |
107 | - // clip the canvas to the dirty rect b/c the surface is only required to | |
108 | - // copy a minimum of the dirty rect and may copy more. The clipped canvas | |
109 | - // however will never write to pixels outside of the clipped area. | |
110 | - if (dirtyRect) { | |
111 | - ANPRectF clipR; | |
112 | - clipR.left = dirtyRect->left; | |
113 | - clipR.top = dirtyRect->top; | |
114 | - clipR.right = dirtyRect->right; | |
115 | - clipR.bottom = dirtyRect->bottom; | |
116 | - gCanvasI.clipRect(canvas, &clipR); | |
117 | - } | |
118 | - | |
119 | - return canvas; | |
120 | -} | |
121 | - | |
122 | -ANPCanvas* PaintPlugin::getCanvas(ANPRectF* dirtyRect) { | |
123 | - | |
124 | - ANPRectI newRect; | |
125 | - newRect.left = (int) dirtyRect->left; | |
126 | - newRect.top = (int) dirtyRect->top; | |
127 | - newRect.right = (int) dirtyRect->right; | |
128 | - newRect.bottom = (int) dirtyRect->bottom; | |
129 | - | |
130 | - return getCanvas(&newRect); | |
131 | -} | |
132 | - | |
133 | -void PaintPlugin::releaseCanvas(ANPCanvas* canvas) { | |
134 | - JNIEnv* env = NULL; | |
135 | - if (m_surface && gVM->GetEnv((void**) &env, JNI_VERSION_1_4) == JNI_OK) { | |
136 | - gSurfaceI.unlock(env, m_surface); | |
137 | - } | |
138 | - gCanvasI.deleteCanvas(canvas); | |
139 | -} | |
140 | - | |
141 | -void PaintPlugin::drawCleanPlugin(ANPCanvas* canvas) { | |
142 | - NPP instance = this->inst(); | |
143 | - PluginObject *obj = (PluginObject*) instance->pdata; | |
144 | - | |
145 | - // if no canvas get a locked canvas | |
146 | - if (!canvas) | |
147 | - canvas = getCanvas(); | |
148 | - | |
149 | - if (!canvas) | |
150 | - return; | |
151 | - | |
152 | - const float buttonWidth = 60; | |
153 | - const float buttonHeight = 30; | |
154 | - const int W = obj->window->width; | |
155 | - const int H = obj->window->height; | |
156 | - | |
157 | - // color the plugin canvas | |
158 | - gCanvasI.drawColor(canvas, 0xFFCDCDCD); | |
159 | - | |
160 | - // get font metrics | |
161 | - ANPFontMetrics fontMetrics; | |
162 | - gPaintI.getFontMetrics(m_paintSurface, &fontMetrics); | |
163 | - | |
164 | - // draw the input toggle button | |
165 | - m_inputToggle.left = 5; | |
166 | - m_inputToggle.top = H - buttonHeight - 5; | |
167 | - m_inputToggle.right = m_inputToggle.left + buttonWidth; | |
168 | - m_inputToggle.bottom = m_inputToggle.top + buttonHeight; | |
169 | - gCanvasI.drawRect(canvas, &m_inputToggle, m_paintButton); | |
170 | - const char* inputText = m_isTouchCurrentInput ? "Touch" : "Mouse"; | |
171 | - gCanvasI.drawText(canvas, inputText, strlen(inputText), m_inputToggle.left + 5, | |
172 | - m_inputToggle.top - fontMetrics.fTop, m_paintSurface); | |
173 | - | |
174 | - // draw the color selector button | |
175 | - m_colorToggle.left = (W/3) - (buttonWidth/2); | |
176 | - m_colorToggle.top = H - buttonHeight - 5; | |
177 | - m_colorToggle.right = m_colorToggle.left + buttonWidth; | |
178 | - m_colorToggle.bottom = m_colorToggle.top + buttonHeight; | |
179 | - gCanvasI.drawRect(canvas, &m_colorToggle, m_paintButton); | |
180 | - const char* colorText = getColorText(); | |
181 | - gCanvasI.drawText(canvas, colorText, strlen(colorText), m_colorToggle.left + 5, | |
182 | - m_colorToggle.top - fontMetrics.fTop, m_paintSurface); | |
183 | - | |
184 | - // draw the full-screen toggle button | |
185 | - m_fullScreenToggle.left = ((W*2)/3) - (buttonWidth/2); | |
186 | - m_fullScreenToggle.top = H - buttonHeight - 5; | |
187 | - m_fullScreenToggle.right = m_fullScreenToggle.left + buttonWidth; | |
188 | - m_fullScreenToggle.bottom = m_fullScreenToggle.top + buttonHeight; | |
189 | - gCanvasI.drawRect(canvas, &m_fullScreenToggle, m_paintButton); | |
190 | - const char* fullScreenText = "Full"; | |
191 | - gCanvasI.drawText(canvas, fullScreenText, strlen(fullScreenText), | |
192 | - m_fullScreenToggle.left + 5, | |
193 | - m_fullScreenToggle.top - fontMetrics.fTop, m_paintSurface); | |
194 | - | |
195 | - // draw the clear canvas button | |
196 | - m_clearSurface.left = W - buttonWidth - 5; | |
197 | - m_clearSurface.top = H - buttonHeight - 5; | |
198 | - m_clearSurface.right = m_clearSurface.left + buttonWidth; | |
199 | - m_clearSurface.bottom = m_clearSurface.top + buttonHeight; | |
200 | - gCanvasI.drawRect(canvas, &m_clearSurface, m_paintButton); | |
201 | - const char* clearText = "Clear"; | |
202 | - gCanvasI.drawText(canvas, clearText, strlen(clearText), m_clearSurface.left + 5, | |
203 | - m_clearSurface.top - fontMetrics.fTop, m_paintSurface); | |
204 | - | |
205 | - // draw the drawing surface box (5 px from the edge) | |
206 | - m_drawingSurface.left = 5; | |
207 | - m_drawingSurface.top = 5; | |
208 | - m_drawingSurface.right = W - 5; | |
209 | - m_drawingSurface.bottom = m_colorToggle.top - 5; | |
210 | - gCanvasI.drawRect(canvas, &m_drawingSurface, m_paintSurface); | |
211 | - | |
212 | - // release the canvas | |
213 | - releaseCanvas(canvas); | |
214 | -} | |
215 | - | |
216 | -const char* PaintPlugin::getColorText() { | |
217 | - | |
218 | - if (m_activePaintColor == s_blueColor) | |
219 | - return "Blue"; | |
220 | - else if (m_activePaintColor == s_greenColor) | |
221 | - return "Green"; | |
222 | - else | |
223 | - return "Red"; | |
224 | -} | |
225 | - | |
226 | -jobject PaintPlugin::getSurface() { | |
227 | - if (m_surface) { | |
228 | - return m_surface; | |
229 | - } | |
230 | - | |
231 | - // load the appropriate java class and instantiate it | |
232 | - JNIEnv* env = NULL; | |
233 | - if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { | |
234 | - gLogI.log(kError_ANPLogType, " ---- getSurface: failed to get env"); | |
235 | - return NULL; | |
236 | - } | |
237 | - | |
238 | - const char* className = "com.android.sampleplugin.PaintSurface"; | |
239 | - jclass paintClass = gSystemI.loadJavaClass(inst(), className); | |
240 | - | |
241 | - if(!paintClass) { | |
242 | - gLogI.log(kError_ANPLogType, " ---- getSurface: failed to load class"); | |
243 | - return NULL; | |
244 | - } | |
245 | - | |
246 | - PluginObject *obj = (PluginObject*) inst()->pdata; | |
247 | - const int pW = obj->window->width; | |
248 | - const int pH = obj->window->height; | |
249 | - | |
250 | - jmethodID constructor = env->GetMethodID(paintClass, "<init>", "(Landroid/content/Context;III)V"); | |
251 | - jobject paintSurface = env->NewObject(paintClass, constructor, m_context, (int)inst(), pW, pH); | |
252 | - | |
253 | - if(!paintSurface) { | |
254 | - gLogI.log(kError_ANPLogType, " ---- getSurface: failed to construct object"); | |
255 | - return NULL; | |
256 | - } | |
257 | - | |
258 | - m_surface = env->NewGlobalRef(paintSurface); | |
259 | - return m_surface; | |
260 | -} | |
261 | - | |
262 | -void PaintPlugin::destroySurface() { | |
263 | - JNIEnv* env = NULL; | |
264 | - if (m_surface && gVM->GetEnv((void**) &env, JNI_VERSION_1_4) == JNI_OK) { | |
265 | - | |
266 | - // detach the native code from the object | |
267 | - jclass javaClass = env->GetObjectClass(m_surface); | |
268 | - jmethodID invalMethod = env->GetMethodID(javaClass, "invalidateNPP", "()V"); | |
269 | - env->CallVoidMethod(m_surface, invalMethod); | |
270 | - | |
271 | - env->DeleteGlobalRef(m_surface); | |
272 | - m_surface = NULL; | |
273 | - } | |
274 | -} | |
275 | - | |
276 | -int16 PaintPlugin::handleEvent(const ANPEvent* evt) { | |
277 | - switch (evt->eventType) { | |
278 | - case kTouch_ANPEventType: { | |
279 | - float x = (float) evt->data.touch.x; | |
280 | - float y = (float) evt->data.touch.y; | |
281 | - if (kDown_ANPTouchAction == evt->data.touch.action && m_isTouchCurrentInput) { | |
282 | - | |
283 | - ANPRectF* rect = validTouch(evt->data.touch.x, evt->data.touch.y); | |
284 | - if(rect == &m_drawingSurface) { | |
285 | - m_isTouchActive = true; | |
286 | - gPathI.moveTo(m_touchPath, x, y); | |
287 | - paintTouch(); | |
288 | - return 1; | |
289 | - } | |
290 | - | |
291 | - } else if (kMove_ANPTouchAction == evt->data.touch.action && m_isTouchActive) { | |
292 | - gPathI.lineTo(m_touchPath, x, y); | |
293 | - paintTouch(); | |
294 | - return 1; | |
295 | - } else if (kUp_ANPTouchAction == evt->data.touch.action && m_isTouchActive) { | |
296 | - gPathI.lineTo(m_touchPath, x, y); | |
297 | - paintTouch(); | |
298 | - m_isTouchActive = false; | |
299 | - gPathI.reset(m_touchPath); | |
300 | - return 1; | |
301 | - } else if (kCancel_ANPTouchAction == evt->data.touch.action) { | |
302 | - m_isTouchActive = false; | |
303 | - gPathI.reset(m_touchPath); | |
304 | - return 1; | |
305 | - } else if (kDoubleTap_ANPTouchAction == evt->data.touch.action) { | |
306 | - gWindowI.requestCenterFitZoom(inst()); | |
307 | - return 1; | |
308 | - | |
309 | - } | |
310 | - break; | |
311 | - } | |
312 | - case kMouse_ANPEventType: { | |
313 | - | |
314 | - if (m_isTouchActive) | |
315 | - gLogI.log(kError_ANPLogType, "----%p Received unintended mouse event", inst()); | |
316 | - | |
317 | - if (kDown_ANPMouseAction == evt->data.mouse.action) { | |
318 | - ANPRectF* rect = validTouch(evt->data.mouse.x, evt->data.mouse.y); | |
319 | - if (rect == &m_drawingSurface) | |
320 | - paintMouse(evt->data.mouse.x, evt->data.mouse.y); | |
321 | - else if (rect == &m_inputToggle) | |
322 | - toggleInputMethod(); | |
323 | - else if (rect == &m_colorToggle) | |
324 | - togglePaintColor(); | |
325 | - else if (rect == &m_fullScreenToggle) | |
326 | - gWindowI.requestFullScreen(inst()); | |
327 | - else if (rect == &m_clearSurface) | |
328 | - drawCleanPlugin(); | |
329 | - } | |
330 | - return 1; | |
331 | - } | |
332 | - case kCustom_ANPEventType: { | |
333 | - | |
334 | - switch (evt->data.other[0]) { | |
335 | - case kSurfaceCreated_CustomEvent: | |
336 | - gLogI.log(kDebug_ANPLogType, " ---- customEvent: surfaceCreated"); | |
337 | - /* The second draw call is added to cover up a problem in this | |
338 | - plugin and is not a recommended usage pattern. This plugin | |
339 | - does not correctly make partial updates to the double | |
340 | - buffered surface and this second call hides that problem. | |
341 | - */ | |
342 | - drawCleanPlugin(); | |
343 | - drawCleanPlugin(); | |
344 | - break; | |
345 | - case kSurfaceChanged_CustomEvent: { | |
346 | - gLogI.log(kDebug_ANPLogType, " ---- customEvent: surfaceChanged"); | |
347 | - | |
348 | - int width = evt->data.other[1]; | |
349 | - int height = evt->data.other[2]; | |
350 | - | |
351 | - PluginObject *obj = (PluginObject*) inst()->pdata; | |
352 | - const int pW = obj->window->width; | |
353 | - const int pH = obj->window->height; | |
354 | - // compare to the plugin's surface dimensions | |
355 | - if (pW != width || pH != height) | |
356 | - gLogI.log(kError_ANPLogType, | |
357 | - "----%p Invalid Surface Dimensions (%d,%d):(%d,%d)", | |
358 | - inst(), pW, pH, width, height); | |
359 | - break; | |
360 | - } | |
361 | - case kSurfaceDestroyed_CustomEvent: | |
362 | - gLogI.log(kDebug_ANPLogType, " ---- customEvent: surfaceDestroyed"); | |
363 | - break; | |
364 | - } | |
365 | - break; // end KCustom_ANPEventType | |
366 | - } | |
367 | - default: | |
368 | - break; | |
369 | - } | |
370 | - return 0; // unknown or unhandled event | |
371 | -} | |
372 | - | |
373 | -ANPRectF* PaintPlugin::validTouch(int x, int y) { | |
374 | - | |
375 | - //convert to float | |
376 | - float fx = (int) x; | |
377 | - float fy = (int) y; | |
378 | - | |
379 | - if (fx > m_drawingSurface.left && fx < m_drawingSurface.right && fy > m_drawingSurface.top && fy < m_drawingSurface.bottom) | |
380 | - return &m_drawingSurface; | |
381 | - else if (fx > m_inputToggle.left && fx < m_inputToggle.right && fy > m_inputToggle.top && fy < m_inputToggle.bottom) | |
382 | - return &m_inputToggle; | |
383 | - else if (fx > m_colorToggle.left && fx < m_colorToggle.right && fy > m_colorToggle.top && fy < m_colorToggle.bottom) | |
384 | - return &m_colorToggle; | |
385 | - else if (fx > m_fullScreenToggle.left && fx < m_fullScreenToggle.right && fy > m_fullScreenToggle.top && fy < m_fullScreenToggle.bottom) | |
386 | - return &m_fullScreenToggle; | |
387 | - else if (fx > m_clearSurface.left && fx < m_clearSurface.right && fy > m_clearSurface.top && fy < m_clearSurface.bottom) | |
388 | - return &m_clearSurface; | |
389 | - else | |
390 | - return NULL; | |
391 | -} | |
392 | - | |
393 | -void PaintPlugin::toggleInputMethod() { | |
394 | - m_isTouchCurrentInput = !m_isTouchCurrentInput; | |
395 | - | |
396 | - // lock only the input toggle and redraw the canvas | |
397 | - ANPCanvas* lockedCanvas = getCanvas(&m_inputToggle); | |
398 | - drawCleanPlugin(lockedCanvas); | |
399 | -} | |
400 | - | |
401 | -void PaintPlugin::togglePaintColor() { | |
402 | - if (m_activePaintColor == s_blueColor) | |
403 | - m_activePaintColor = s_redColor; | |
404 | - else if (m_activePaintColor == s_greenColor) | |
405 | - m_activePaintColor = s_blueColor; | |
406 | - else | |
407 | - m_activePaintColor = s_greenColor; | |
408 | - | |
409 | - // lock only the color toggle and redraw the canvas | |
410 | - ANPCanvas* lockedCanvas = getCanvas(&m_colorToggle); | |
411 | - drawCleanPlugin(lockedCanvas); | |
412 | -} | |
413 | - | |
414 | -void PaintPlugin::paintMouse(int x, int y) { | |
415 | - //TODO do not paint outside the drawing surface | |
416 | - | |
417 | - //create the paint color | |
418 | - ANPPaint* fillPaint = gPaintI.newPaint(); | |
419 | - gPaintI.setFlags(fillPaint, gPaintI.getFlags(fillPaint) | kAntiAlias_ANPPaintFlag); | |
420 | - gPaintI.setStyle(fillPaint, kFill_ANPPaintStyle); | |
421 | - gPaintI.setColor(fillPaint, m_activePaintColor); | |
422 | - | |
423 | - // handle the simple "mouse" paint (draw a point) | |
424 | - ANPRectF point; | |
425 | - point.left = (float) x-3; | |
426 | - point.top = (float) y-3; | |
427 | - point.right = (float) x+3; | |
428 | - point.bottom = (float) y+3; | |
429 | - | |
430 | - // get a canvas that is only locked around the point and draw it | |
431 | - ANPCanvas* canvas = getCanvas(&point); | |
432 | - gCanvasI.drawOval(canvas, &point, fillPaint); | |
433 | - | |
434 | - // clean up | |
435 | - releaseCanvas(canvas); | |
436 | - gPaintI.deletePaint(fillPaint); | |
437 | -} | |
438 | - | |
439 | -void PaintPlugin::paintTouch() { | |
440 | - //TODO do not paint outside the drawing surface | |
441 | - | |
442 | - //create the paint color | |
443 | - ANPPaint* strokePaint = gPaintI.newPaint(); | |
444 | - gPaintI.setFlags(strokePaint, gPaintI.getFlags(strokePaint) | kAntiAlias_ANPPaintFlag); | |
445 | - gPaintI.setColor(strokePaint, m_activePaintColor); | |
446 | - gPaintI.setStyle(strokePaint, kStroke_ANPPaintStyle); | |
447 | - gPaintI.setStrokeWidth(strokePaint, 6.0); | |
448 | - gPaintI.setStrokeCap(strokePaint, kRound_ANPPaintCap); | |
449 | - gPaintI.setStrokeJoin(strokePaint, kRound_ANPPaintJoin); | |
450 | - | |
451 | - // handle the complex "touch" paint (draw a line) | |
452 | - ANPRectF bounds; | |
453 | - gPathI.getBounds(m_touchPath, &bounds); | |
454 | - | |
455 | - // get a canvas that is only locked around the point and draw the path | |
456 | - ANPCanvas* canvas = getCanvas(&bounds); | |
457 | - gCanvasI.drawPath(canvas, m_touchPath, strokePaint); | |
458 | - | |
459 | - // clean up | |
460 | - releaseCanvas(canvas); | |
461 | - gPaintI.deletePaint(strokePaint); | |
462 | -} |
@@ -1,73 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2009, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "PluginObject.h" | |
27 | -#include <stdio.h> | |
28 | - | |
29 | -#ifndef paintPlugin__DEFINED | |
30 | -#define paintPlugin__DEFINED | |
31 | - | |
32 | -class PaintPlugin : public SurfaceSubPlugin { | |
33 | -public: | |
34 | - PaintPlugin(NPP inst); | |
35 | - virtual ~PaintPlugin(); | |
36 | - virtual int16 handleEvent(const ANPEvent* evt); | |
37 | - virtual jobject getSurface(); | |
38 | - | |
39 | -private: | |
40 | - void drawCleanPlugin(ANPCanvas* canvas = NULL); | |
41 | - ANPCanvas* getCanvas(ANPRectI* dirtyRect = NULL); | |
42 | - ANPCanvas* getCanvas(ANPRectF* dirtyRect); | |
43 | - const char* getColorText(); | |
44 | - void destroySurface(); | |
45 | - void paintMouse(int x, int y); | |
46 | - void paintTouch(); | |
47 | - void releaseCanvas(ANPCanvas*); | |
48 | - void toggleInputMethod(); | |
49 | - void togglePaintColor(); | |
50 | - ANPRectF* validTouch(int x, int y); | |
51 | - | |
52 | - bool m_isTouchActive; | |
53 | - bool m_isTouchCurrentInput; | |
54 | - | |
55 | - jobject m_surface; | |
56 | - ANPPath* m_touchPath; | |
57 | - | |
58 | - ANPRectF m_drawingSurface; | |
59 | - ANPRectF m_inputToggle; | |
60 | - ANPRectF m_colorToggle; | |
61 | - ANPRectF m_fullScreenToggle; | |
62 | - ANPRectF m_clearSurface; | |
63 | - | |
64 | - ANPPaint* m_paintSurface; | |
65 | - ANPPaint* m_paintButton; | |
66 | - | |
67 | - ANPColor m_activePaintColor; | |
68 | - static const ANPColor s_redColor = 0xFFFF0000; | |
69 | - static const ANPColor s_greenColor = 0xFF00FF00; | |
70 | - static const ANPColor s_blueColor = 0xFF0000FF; | |
71 | -}; | |
72 | - | |
73 | -#endif // paintPlugin__DEFINED |
@@ -1,135 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2009, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "VideoPlugin.h" | |
27 | -#include "android_npapi.h" | |
28 | - | |
29 | -#include <stdio.h> | |
30 | -#include <sys/time.h> | |
31 | -#include <time.h> | |
32 | -#include <math.h> | |
33 | -#include <string.h> | |
34 | - | |
35 | -extern NPNetscapeFuncs* browser; | |
36 | -extern ANPBitmapInterfaceV0 gBitmapI; | |
37 | -extern ANPCanvasInterfaceV0 gCanvasI; | |
38 | -extern ANPLogInterfaceV0 gLogI; | |
39 | -extern ANPPaintInterfaceV0 gPaintI; | |
40 | -extern ANPSurfaceInterfaceV0 gSurfaceI; | |
41 | -extern ANPSystemInterfaceV0 gSystemI; | |
42 | -extern ANPTypefaceInterfaceV0 gTypefaceI; | |
43 | -extern ANPWindowInterfaceV0 gWindowI; | |
44 | - | |
45 | -/////////////////////////////////////////////////////////////////////////////// | |
46 | - | |
47 | -VideoPlugin::VideoPlugin(NPP inst) : SurfaceSubPlugin(inst) { | |
48 | - | |
49 | - // initialize the drawing surface | |
50 | - m_surface = NULL; | |
51 | - | |
52 | - //register for touch events | |
53 | - ANPEventFlags flags = kTouch_ANPEventFlag; | |
54 | - NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); | |
55 | - if (err != NPERR_NO_ERROR) { | |
56 | - gLogI.log(kError_ANPLogType, "Error selecting input events."); | |
57 | - } | |
58 | -} | |
59 | - | |
60 | -VideoPlugin::~VideoPlugin() { | |
61 | - setContext(NULL); | |
62 | - destroySurface(); | |
63 | -} | |
64 | - | |
65 | -jobject VideoPlugin::getSurface() { | |
66 | - | |
67 | - if (m_surface) { | |
68 | - return m_surface; | |
69 | - } | |
70 | - | |
71 | - // load the appropriate java class and instantiate it | |
72 | - JNIEnv* env = NULL; | |
73 | - if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { | |
74 | - gLogI.log(kError_ANPLogType, " ---- getSurface: failed to get env"); | |
75 | - return NULL; | |
76 | - } | |
77 | - | |
78 | - const char* className = "com.android.sampleplugin.VideoSurface"; | |
79 | - jclass videoClass = gSystemI.loadJavaClass(inst(), className); | |
80 | - | |
81 | - if(!videoClass) { | |
82 | - gLogI.log(kError_ANPLogType, " ---- getSurface: failed to load class"); | |
83 | - return NULL; | |
84 | - } | |
85 | - | |
86 | - jmethodID constructor = env->GetMethodID(videoClass, "<init>", "(Landroid/content/Context;)V"); | |
87 | - jobject videoSurface = env->NewObject(videoClass, constructor, m_context); | |
88 | - | |
89 | - if(!videoSurface) { | |
90 | - gLogI.log(kError_ANPLogType, " ---- getSurface: failed to construct object"); | |
91 | - return NULL; | |
92 | - } | |
93 | - | |
94 | - m_surface = env->NewGlobalRef(videoSurface); | |
95 | - return m_surface; | |
96 | -} | |
97 | - | |
98 | -void VideoPlugin::destroySurface() { | |
99 | - JNIEnv* env = NULL; | |
100 | - if (m_surface && gVM->GetEnv((void**) &env, JNI_VERSION_1_4) == JNI_OK) { | |
101 | - env->DeleteGlobalRef(m_surface); | |
102 | - m_surface = NULL; | |
103 | - } | |
104 | -} | |
105 | - | |
106 | -int16 VideoPlugin::handleEvent(const ANPEvent* evt) { | |
107 | - switch (evt->eventType) { | |
108 | - case kLifecycle_ANPEventType: { | |
109 | - switch (evt->data.lifecycle.action) { | |
110 | - case kEnterFullScreen_ANPLifecycleAction: | |
111 | - gLogI.log(kDebug_ANPLogType, " ---- %p entering fullscreen", inst()); | |
112 | - break; | |
113 | - case kExitFullScreen_ANPLifecycleAction: | |
114 | - gLogI.log(kDebug_ANPLogType, " ---- %p exiting fullscreen", inst()); | |
115 | - break; | |
116 | - } | |
117 | - break; // end kLifecycle_ANPEventType | |
118 | - } | |
119 | - case kDraw_ANPEventType: | |
120 | - gLogI.log(kError_ANPLogType, " ------ %p the plugin did not request draw events", inst()); | |
121 | - break; | |
122 | - case kTouch_ANPEventType: | |
123 | - if (kDown_ANPTouchAction == evt->data.touch.action) { | |
124 | - gLogI.log(kDebug_ANPLogType, " ------ %p requesting fullscreen mode", inst()); | |
125 | - gWindowI.requestFullScreen(inst()); | |
126 | - } | |
127 | - return 1; | |
128 | - case kKey_ANPEventType: | |
129 | - gLogI.log(kError_ANPLogType, " ------ %p the plugin did not request key events", inst()); | |
130 | - break; | |
131 | - default: | |
132 | - break; | |
133 | - } | |
134 | - return 0; // unknown or unhandled event | |
135 | -} |
@@ -1,44 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2009, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | - | |
26 | -#include "PluginObject.h" | |
27 | - | |
28 | -#ifndef videoPlugin__DEFINED | |
29 | -#define videoPlugin__DEFINED | |
30 | - | |
31 | -class VideoPlugin : public SurfaceSubPlugin { | |
32 | -public: | |
33 | - VideoPlugin(NPP inst); | |
34 | - virtual ~VideoPlugin(); | |
35 | - virtual int16 handleEvent(const ANPEvent* evt); | |
36 | - virtual jobject getSurface(); | |
37 | - | |
38 | -private: | |
39 | - void destroySurface(); | |
40 | - | |
41 | - jobject m_surface; | |
42 | -}; | |
43 | - | |
44 | -#endif // videoPlugin__DEFINED |
@@ -1,19 +0,0 @@ | ||
1 | -<?xml version="1.0" encoding="utf-8"?> | |
2 | -<!-- | |
3 | - * Copyright (C) 2009 The Android Open Source Project | |
4 | - * | |
5 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | - * you may not use this file except in compliance with the License. | |
7 | - * You may obtain a copy of the License at | |
8 | - * | |
9 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | - * | |
11 | - * Unless required by applicable law or agreed to in writing, software | |
12 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | - * See the License for the specific language governing permissions and | |
15 | - * limitations under the License. | |
16 | ---> | |
17 | -<resources> | |
18 | - <string name="sample_browser_plugin">Sample Browser Plugin</string> | |
19 | -</resources> |
@@ -1,19 +0,0 @@ | ||
1 | -package com.android.sampleplugin; | |
2 | - | |
3 | -import android.content.Context; | |
4 | -import android.graphics.Color; | |
5 | -import android.widget.TextView; | |
6 | - | |
7 | -public class BackgroundSurface extends TextView { | |
8 | - | |
9 | - public BackgroundSurface(Context context) { | |
10 | - super(context); | |
11 | - | |
12 | - this.setBackgroundColor(Color.BLACK); | |
13 | - this.setTextColor(Color.WHITE); | |
14 | - this.setText("This is a java background plugin"); | |
15 | - | |
16 | - // ensure that the view system is aware that we will be drawing | |
17 | - this.setWillNotDraw(false); | |
18 | - } | |
19 | -} |
@@ -1,11 +0,0 @@ | ||
1 | -package com.android.sampleplugin; | |
2 | - | |
3 | -public class BackgroundTest { | |
4 | - | |
5 | - public BackgroundTest() {} | |
6 | - | |
7 | - public int addInt(int x, int y) { | |
8 | - return x + y; | |
9 | - } | |
10 | - | |
11 | -} |
@@ -1,95 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2009, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | -package com.android.sampleplugin; | |
26 | - | |
27 | -import android.content.Context; | |
28 | -import android.graphics.PixelFormat; | |
29 | -import android.view.SurfaceHolder; | |
30 | -import android.view.SurfaceView; | |
31 | -import android.view.SurfaceHolder.Callback; | |
32 | - | |
33 | -public class PaintSurface extends SurfaceView { | |
34 | - | |
35 | - static { | |
36 | - //needed for jni calls | |
37 | - System.loadLibrary("sampleplugin"); | |
38 | - } | |
39 | - | |
40 | - private final int npp; | |
41 | - | |
42 | - private boolean validNPP = true; | |
43 | - private Object nppLock = new Object(); | |
44 | - | |
45 | - public PaintSurface(Context context, int NPP, int width, int height) { | |
46 | - super(context); | |
47 | - | |
48 | - this.npp = NPP; | |
49 | - | |
50 | - this.getHolder().setFormat(PixelFormat.RGBA_8888); | |
51 | - this.getHolder().addCallback(new Callback() { | |
52 | - | |
53 | - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { | |
54 | - synchronized (nppLock) { | |
55 | - if (validNPP) { | |
56 | - nativeSurfaceChanged(npp, format, width, height); | |
57 | - } | |
58 | - } | |
59 | - } | |
60 | - | |
61 | - public void surfaceCreated(SurfaceHolder holder) { | |
62 | - synchronized (nppLock) { | |
63 | - if (validNPP) { | |
64 | - nativeSurfaceCreated(npp); | |
65 | - } | |
66 | - } | |
67 | - } | |
68 | - | |
69 | - public void surfaceDestroyed(SurfaceHolder holder) { | |
70 | - synchronized (nppLock) { | |
71 | - if (validNPP) { | |
72 | - nativeSurfaceDestroyed(npp); | |
73 | - } | |
74 | - } | |
75 | - } | |
76 | - }); | |
77 | - | |
78 | - // sets the plugin's surface to a fixed size | |
79 | - this.getHolder().setFixedSize(width, height); | |
80 | - | |
81 | - // ensure that the view system is aware that we will be drawing | |
82 | - this.setWillNotDraw(false); | |
83 | - } | |
84 | - | |
85 | - // called by JNI | |
86 | - private void invalidateNPP() { | |
87 | - synchronized (nppLock) { | |
88 | - validNPP = false; | |
89 | - } | |
90 | - } | |
91 | - | |
92 | - private native void nativeSurfaceCreated(int npp); | |
93 | - private native void nativeSurfaceChanged(int npp, int format, int width, int height); | |
94 | - private native void nativeSurfaceDestroyed(int npp); | |
95 | -} |
@@ -1,38 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2009, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | -package com.android.sampleplugin; | |
26 | - | |
27 | -import android.app.Service; | |
28 | -import android.content.Intent; | |
29 | -import android.os.IBinder; | |
30 | - | |
31 | -public class SamplePlugin extends Service { | |
32 | - | |
33 | - @Override | |
34 | - public IBinder onBind(Intent intent) { | |
35 | - // TODO Auto-generated method stub | |
36 | - return null; | |
37 | - } | |
38 | -} |
@@ -1,67 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2009, The Android Open Source Project | |
3 | - * | |
4 | - * Redistribution and use in source and binary forms, with or without | |
5 | - * modification, are permitted provided that the following conditions | |
6 | - * are met: | |
7 | - * * Redistributions of source code must retain the above copyright | |
8 | - * notice, this list of conditions and the following disclaimer. | |
9 | - * * Redistributions in binary form must reproduce the above copyright | |
10 | - * notice, this list of conditions and the following disclaimer in the | |
11 | - * documentation and/or other materials provided with the distribution. | |
12 | - * | |
13 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
14 | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
17 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | - */ | |
25 | -package com.android.sampleplugin; | |
26 | - | |
27 | -import com.android.sampleplugin.graphics.CubeRenderer; | |
28 | - | |
29 | -import android.content.Context; | |
30 | -import android.opengl.GLSurfaceView; | |
31 | -import android.view.WindowManager; | |
32 | -import android.widget.FrameLayout; | |
33 | -import android.widget.MediaController; | |
34 | -import android.widget.VideoView; | |
35 | - | |
36 | -public class VideoSurface extends FrameLayout { | |
37 | - | |
38 | - public VideoSurface(Context context) { | |
39 | - super(context); | |
40 | - | |
41 | - LayoutParams fp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); | |
42 | - this.setLayoutParams(fp); | |
43 | - | |
44 | -// VideoView video = new VideoView(context); | |
45 | -// LayoutParams vp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); | |
46 | -// vp.setLayoutParams(vp); | |
47 | - | |
48 | - GLSurfaceView gl = new GLSurfaceView(context); | |
49 | - LayoutParams gp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); | |
50 | - gl.setLayoutParams(gp); | |
51 | - | |
52 | - this.addView(gl); | |
53 | -// this.addView(video); | |
54 | - | |
55 | - // Tell the cube renderer that we want to render a translucent version | |
56 | - // of the cube: | |
57 | - gl.setRenderer(new CubeRenderer(false)); | |
58 | - gl.setWindowType(WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY); | |
59 | - | |
60 | -// video.setVideoPath("/sdcard/test_video.3gp"); | |
61 | -// video.setMediaController(new MediaController(context)); | |
62 | -// video.requestFocus(); | |
63 | - | |
64 | - // ensure that the view system is aware that we will be drawing | |
65 | - this.setWillNotDraw(false); | |
66 | - } | |
67 | -} |
@@ -1,100 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright (C) 2009 The Android Open Source Project | |
3 | - * | |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
6 | - * You may obtain a copy of the License at | |
7 | - * | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - * See the License for the specific language governing permissions and | |
14 | - * limitations under the License. | |
15 | - */ | |
16 | - | |
17 | -package com.android.sampleplugin.graphics; | |
18 | - | |
19 | -import java.nio.ByteBuffer; | |
20 | -import java.nio.ByteOrder; | |
21 | -import java.nio.IntBuffer; | |
22 | - | |
23 | -import javax.microedition.khronos.opengles.GL10; | |
24 | - | |
25 | -/** | |
26 | - * A vertex shaded cube. | |
27 | - */ | |
28 | -class Cube | |
29 | -{ | |
30 | - public Cube() | |
31 | - { | |
32 | - int one = 0x10000; | |
33 | - int vertices[] = { | |
34 | - -one, -one, -one, | |
35 | - one, -one, -one, | |
36 | - one, one, -one, | |
37 | - -one, one, -one, | |
38 | - -one, -one, one, | |
39 | - one, -one, one, | |
40 | - one, one, one, | |
41 | - -one, one, one, | |
42 | - }; | |
43 | - | |
44 | - int colors[] = { | |
45 | - 0, 0, 0, one, | |
46 | - one, 0, 0, one, | |
47 | - one, one, 0, one, | |
48 | - 0, one, 0, one, | |
49 | - 0, 0, one, one, | |
50 | - one, 0, one, one, | |
51 | - one, one, one, one, | |
52 | - 0, one, one, one, | |
53 | - }; | |
54 | - | |
55 | - byte indices[] = { | |
56 | - 0, 4, 5, 0, 5, 1, | |
57 | - 1, 5, 6, 1, 6, 2, | |
58 | - 2, 6, 7, 2, 7, 3, | |
59 | - 3, 7, 4, 3, 4, 0, | |
60 | - 4, 7, 6, 4, 6, 5, | |
61 | - 3, 0, 1, 3, 1, 2 | |
62 | - }; | |
63 | - | |
64 | - // Buffers to be passed to gl*Pointer() functions | |
65 | - // must be direct, i.e., they must be placed on the | |
66 | - // native heap where the garbage collector cannot | |
67 | - // move them. | |
68 | - // | |
69 | - // Buffers with multi-byte datatypes (e.g., short, int, float) | |
70 | - // must have their byte order set to native order | |
71 | - | |
72 | - ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4); | |
73 | - vbb.order(ByteOrder.nativeOrder()); | |
74 | - mVertexBuffer = vbb.asIntBuffer(); | |
75 | - mVertexBuffer.put(vertices); | |
76 | - mVertexBuffer.position(0); | |
77 | - | |
78 | - ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4); | |
79 | - cbb.order(ByteOrder.nativeOrder()); | |
80 | - mColorBuffer = cbb.asIntBuffer(); | |
81 | - mColorBuffer.put(colors); | |
82 | - mColorBuffer.position(0); | |
83 | - | |
84 | - mIndexBuffer = ByteBuffer.allocateDirect(indices.length); | |
85 | - mIndexBuffer.put(indices); | |
86 | - mIndexBuffer.position(0); | |
87 | - } | |
88 | - | |
89 | - public void draw(GL10 gl) | |
90 | - { | |
91 | - gl.glFrontFace(gl.GL_CW); | |
92 | - gl.glVertexPointer(3, gl.GL_FIXED, 0, mVertexBuffer); | |
93 | - gl.glColorPointer(4, gl.GL_FIXED, 0, mColorBuffer); | |
94 | - gl.glDrawElements(gl.GL_TRIANGLES, 36, gl.GL_UNSIGNED_BYTE, mIndexBuffer); | |
95 | - } | |
96 | - | |
97 | - private IntBuffer mVertexBuffer; | |
98 | - private IntBuffer mColorBuffer; | |
99 | - private ByteBuffer mIndexBuffer; | |
100 | -} |
@@ -1,109 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright (C) 2009 The Android Open Source Project | |
3 | - * | |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
6 | - * You may obtain a copy of the License at | |
7 | - * | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | - * See the License for the specific language governing permissions and | |
14 | - * limitations under the License. | |
15 | - */ | |
16 | - | |
17 | -package com.android.sampleplugin.graphics; | |
18 | - | |
19 | -import javax.microedition.khronos.egl.EGL10; | |
20 | -import javax.microedition.khronos.egl.EGLConfig; | |
21 | -import javax.microedition.khronos.opengles.GL10; | |
22 | - | |
23 | -import android.opengl.GLSurfaceView; | |
24 | - | |
25 | -/** | |
26 | - * Render a pair of tumbling cubes. | |
27 | - */ | |
28 | - | |
29 | -public class CubeRenderer implements GLSurfaceView.Renderer { | |
30 | - public CubeRenderer(boolean useTranslucentBackground) { | |
31 | - mTranslucentBackground = useTranslucentBackground; | |
32 | - mCube = new Cube(); | |
33 | - } | |
34 | - | |
35 | - public void onDrawFrame(GL10 gl) { | |
36 | - /* | |
37 | - * Usually, the first thing one might want to do is to clear | |
38 | - * the screen. The most efficient way of doing this is to use | |
39 | - * glClear(). | |
40 | - */ | |
41 | - | |
42 | - gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); | |
43 | - | |
44 | - /* | |
45 | - * Now we're ready to draw some 3D objects | |
46 | - */ | |
47 | - | |
48 | - gl.glMatrixMode(GL10.GL_MODELVIEW); | |
49 | - gl.glLoadIdentity(); | |
50 | - gl.glTranslatef(0, 0, -3.0f); | |
51 | - gl.glRotatef(mAngle, 0, 1, 0); | |
52 | - gl.glRotatef(mAngle*0.25f, 1, 0, 0); | |
53 | - | |
54 | - gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); | |
55 | - gl.glEnableClientState(GL10.GL_COLOR_ARRAY); | |
56 | - | |
57 | - mCube.draw(gl); | |
58 | - | |
59 | - gl.glRotatef(mAngle*2.0f, 0, 1, 1); | |
60 | - gl.glTranslatef(0.5f, 0.5f, 0.5f); | |
61 | - | |
62 | - mCube.draw(gl); | |
63 | - | |
64 | - mAngle += 1.2f; | |
65 | - } | |
66 | - | |
67 | - public void onSurfaceChanged(GL10 gl, int width, int height) { | |
68 | - gl.glViewport(0, 0, width, height); | |
69 | - | |
70 | - /* | |
71 | - * Set our projection matrix. This doesn't have to be done | |
72 | - * each time we draw, but usually a new projection needs to | |
73 | - * be set when the viewport is resized. | |
74 | - */ | |
75 | - | |
76 | - float ratio = (float) width / height; | |
77 | - gl.glMatrixMode(GL10.GL_PROJECTION); | |
78 | - gl.glLoadIdentity(); | |
79 | - gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); | |
80 | - } | |
81 | - | |
82 | - public void onSurfaceCreated(GL10 gl, EGLConfig config) { | |
83 | - /* | |
84 | - * By default, OpenGL enables features that improve quality | |
85 | - * but reduce performance. One might want to tweak that | |
86 | - * especially on software renderer. | |
87 | - */ | |
88 | - gl.glDisable(GL10.GL_DITHER); | |
89 | - | |
90 | - /* | |
91 | - * Some one-time OpenGL initialization can be made here | |
92 | - * probably based on features of this particular context | |
93 | - */ | |
94 | - gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, | |
95 | - GL10.GL_FASTEST); | |
96 | - | |
97 | - if (mTranslucentBackground) { | |
98 | - gl.glClearColor(0,0,0,0); | |
99 | - } else { | |
100 | - gl.glClearColor(1,1,1,1); | |
101 | - } | |
102 | - gl.glEnable(GL10.GL_CULL_FACE); | |
103 | - gl.glShadeModel(GL10.GL_SMOOTH); | |
104 | - gl.glEnable(GL10.GL_DEPTH_TEST); | |
105 | - } | |
106 | - private boolean mTranslucentBackground; | |
107 | - private Cube mCube; | |
108 | - private float mAngle; | |
109 | -} |