OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "webkit/tools/pepper_test_plugin/event_handler.h" | 26 #include "webkit/tools/pepper_test_plugin/event_handler.h" |
27 | 27 |
28 #include <stdio.h> | 28 #include <stdio.h> |
29 #include <string> | 29 #include <sstream> |
30 | 30 |
31 #include "base/basictypes.h" | |
32 #include "base/logging.h" | |
33 #include "base/string_util.h" | |
34 #include "webkit/tools/pepper_test_plugin/plugin_object.h" | 31 #include "webkit/tools/pepper_test_plugin/plugin_object.h" |
35 | 32 |
36 EventHandler* event_handler = NULL; | 33 EventHandler* event_handler = NULL; |
37 | 34 |
38 // EventHandler ---------------------------------------------------------------- | 35 // EventHandler ---------------------------------------------------------------- |
39 | 36 |
40 EventHandler::EventHandler(NPP npp) | 37 EventHandler::EventHandler(NPP npp) |
41 : npp_(npp), | 38 : npp_(npp), |
42 text_box_(NULL) { | 39 text_box_(NULL) { |
43 } | 40 } |
44 | 41 |
45 EventHandler::~EventHandler() { | 42 EventHandler::~EventHandler() { |
46 } | 43 } |
47 | 44 |
48 void EventHandler::addText(const char* cstr) { | 45 void EventHandler::addText(const char* cstr) { |
49 NPVariant variant; | 46 NPVariant variant; |
50 // Create a a string variant to be set for the innerText. | 47 // Create a a string variant to be set for the innerText. |
51 MakeNPVariant(cstr, &variant); | 48 MakeNPVariant(cstr, &variant); |
52 // Report the string to the div. | 49 // Report the string to the div. |
53 NPVariant result; | 50 NPVariant result; |
54 browser->invokeDefault(npp_, text_box_, &variant, 1, &result); | 51 browser->invokeDefault(npp_, text_box_, &variant, 1, &result); |
55 // Release the variant. | 52 // Release the variant. |
56 browser->releasevariantvalue(&variant); | 53 browser->releasevariantvalue(&variant); |
57 browser->releasevariantvalue(&result); | 54 browser->releasevariantvalue(&result); |
58 } | 55 } |
59 | 56 |
60 std::string EventHandler::EventName(double timestamp, int32 type) { | 57 std::string EventHandler::EventName(double timestamp, int32 type) { |
61 std::string str = DoubleToString(timestamp) + ": "; | 58 std::stringstream strstr; |
| 59 strstr.setf(std::ios::fixed, std::ios::floatfield); |
| 60 strstr << timestamp << ": "; |
| 61 std::string str(strstr.str()); |
62 switch (type) { | 62 switch (type) { |
63 case NPEventType_MouseDown: | 63 case NPEventType_MouseDown: |
64 return str + "MouseDown"; | 64 return str + "MouseDown"; |
65 case NPEventType_MouseUp: | 65 case NPEventType_MouseUp: |
66 return str + "MouseUp"; | 66 return str + "MouseUp"; |
67 case NPEventType_MouseMove: | 67 case NPEventType_MouseMove: |
68 return str + "MouseMove"; | 68 return str + "MouseMove"; |
69 case NPEventType_MouseEnter: | 69 case NPEventType_MouseEnter: |
70 return str + "MouseEnter"; | 70 return str + "MouseEnter"; |
71 case NPEventType_MouseLeave: | 71 case NPEventType_MouseLeave: |
(...skipping 15 matching lines...) Expand all Loading... |
87 case NPEventType_Device: | 87 case NPEventType_Device: |
88 return str + "Device"; | 88 return str + "Device"; |
89 case NPEventType_Undefined: | 89 case NPEventType_Undefined: |
90 default: | 90 default: |
91 return str + "Undefined"; | 91 return str + "Undefined"; |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 int EventHandler::handle(void* event) { | 95 int EventHandler::handle(void* event) { |
96 NPPepperEvent* npevent = reinterpret_cast<NPPepperEvent*>(event); | 96 NPPepperEvent* npevent = reinterpret_cast<NPPepperEvent*>(event); |
97 std::string str = EventName(npevent->timeStampSeconds, npevent->type); | 97 std::stringstream str; |
| 98 str << EventName(npevent->timeStampSeconds, npevent->type); |
98 switch (npevent->type) { | 99 switch (npevent->type) { |
99 case NPEventType_MouseDown: | 100 case NPEventType_MouseDown: |
100 case NPEventType_MouseUp: | 101 case NPEventType_MouseUp: |
101 case NPEventType_MouseMove: | 102 case NPEventType_MouseMove: |
102 case NPEventType_MouseEnter: | 103 case NPEventType_MouseEnter: |
103 case NPEventType_MouseLeave: | 104 case NPEventType_MouseLeave: |
104 str += StringPrintf(": mod %x, but: %x, x: %d, y: %d, click: %d", | 105 str << ": mod " << npevent->u.mouse.modifier |
105 npevent->u.mouse.modifier, | 106 << ", but: " << npevent->u.mouse.button |
106 npevent->u.mouse.button, | 107 << ", x: " << npevent->u.mouse.x |
107 npevent->u.mouse.x, | 108 << ", y: " << npevent->u.mouse.y |
108 npevent->u.mouse.y, | 109 << ", click: " << npevent->u.mouse.clickCount; |
109 npevent->u.mouse.clickCount); | |
110 break; | 110 break; |
111 case NPEventType_MouseWheel: | 111 case NPEventType_MouseWheel: |
112 str += StringPrintf(": mod %x, dx: %f, dy: %f, wtx: %f, wty: %d: sbp %d", | 112 str << ": mod " << npevent->u.wheel.modifier |
113 npevent->u.wheel.modifier, | 113 << ", dx: " << npevent->u.wheel.deltaX |
114 npevent->u.wheel.deltaX, | 114 << ", dy: " << npevent->u.wheel.deltaY |
115 npevent->u.wheel.deltaY, | 115 << ", wtx: " << npevent->u.wheel.wheelTicksX |
116 npevent->u.wheel.wheelTicksX, | 116 << ", wty: " << npevent->u.wheel.wheelTicksY |
117 npevent->u.wheel.wheelTicksY, | 117 << ", sbp:" << npevent->u.wheel.scrollByPage; |
118 npevent->u.wheel.scrollByPage); | |
119 break; | 118 break; |
120 case NPEventType_RawKeyDown: | 119 case NPEventType_RawKeyDown: |
121 case NPEventType_KeyDown: | 120 case NPEventType_KeyDown: |
122 case NPEventType_KeyUp: | 121 case NPEventType_KeyUp: |
123 str += StringPrintf(": mod %x, key: %x", | 122 str << ": mod " << npevent->u.key.modifier |
124 npevent->u.key.modifier, | 123 << ", key: " << npevent->u.key.normalizedKeyCode; |
125 npevent->u.key.normalizedKeyCode); | |
126 break; | 124 break; |
127 case NPEventType_Char: | 125 case NPEventType_Char: |
128 str += StringPrintf(": mod %x, text: ", | 126 str << ": mod " << npevent->u.character.modifier << ", text: "; |
129 npevent->u.character.modifier); | |
130 size_t i; | 127 size_t i; |
131 for (i = 0; i < arraysize(npevent->u.character.text); ++i) { | 128 for (i = 0; i < arraysize(npevent->u.character.text); ++i) { |
132 str += StringPrintf("%x ", npevent->u.character.text[i]); | 129 str << npevent->u.character.text[i] << ' '; |
133 } | 130 } |
134 str += ", unmod: "; | 131 str << ", unmod: "; |
135 for (i = 0; i < arraysize(npevent->u.character.unmodifiedText); ++i) { | 132 for (i = 0; i < arraysize(npevent->u.character.unmodifiedText); ++i) { |
136 str += StringPrintf("%x ", npevent->u.character.unmodifiedText[i]); | 133 str << npevent->u.character.unmodifiedText[i] << ' '; |
137 } | 134 } |
138 break; | 135 break; |
139 case NPEventType_Minimize: | 136 case NPEventType_Minimize: |
140 case NPEventType_Focus: | 137 case NPEventType_Focus: |
141 case NPEventType_Device: | 138 case NPEventType_Device: |
142 break; | 139 break; |
143 case NPEventType_Undefined: | 140 case NPEventType_Undefined: |
144 default: | 141 default: |
145 break; | 142 break; |
146 } | 143 } |
147 addText(str.c_str()); | 144 addText(str.str().c_str()); |
148 return 0; | 145 return 0; |
149 } | 146 } |
150 | 147 |
151 bool EventHandler::set_text_box(NPObject* text_box_object) { | 148 bool EventHandler::set_text_box(NPObject* text_box_object) { |
152 text_box_ = text_box_object; | 149 text_box_ = text_box_object; |
153 // Keep a reference to the text box update object. | 150 // Keep a reference to the text box update object. |
154 browser->retainobject(text_box_object); | 151 browser->retainobject(text_box_object); |
155 // Announce that we are alive. | 152 // Announce that we are alive. |
156 addText("Set the callback for text\n"); | 153 addText("Set the callback for text\n"); |
157 return true; | 154 return true; |
(...skipping 16 matching lines...) Expand all Loading... |
174 return; | 171 return; |
175 } | 172 } |
176 size_t len; | 173 size_t len; |
177 char* name = string_duplicate(cstr, &len); | 174 char* name = string_duplicate(cstr, &len); |
178 if (NULL == name) { | 175 if (NULL == name) { |
179 STRINGN_TO_NPVARIANT(NULL, 0, *var); | 176 STRINGN_TO_NPVARIANT(NULL, 0, *var); |
180 return; | 177 return; |
181 } | 178 } |
182 STRINGN_TO_NPVARIANT(name, len, *var); | 179 STRINGN_TO_NPVARIANT(name, len, *var); |
183 } | 180 } |
OLD | NEW |