| 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 <sstream> | 29 #include <string> |
| 30 | 30 |
| 31 #include "base/basictypes.h" |
| 32 #include "base/logging.h" |
| 33 #include "base/string_util.h" |
| 31 #include "webkit/tools/pepper_test_plugin/plugin_object.h" | 34 #include "webkit/tools/pepper_test_plugin/plugin_object.h" |
| 32 | 35 |
| 33 EventHandler* event_handler = NULL; | 36 EventHandler* event_handler = NULL; |
| 34 | 37 |
| 35 // EventHandler ---------------------------------------------------------------- | 38 // EventHandler ---------------------------------------------------------------- |
| 36 | 39 |
| 37 EventHandler::EventHandler(NPP npp) | 40 EventHandler::EventHandler(NPP npp) |
| 38 : npp_(npp), | 41 : npp_(npp), |
| 39 text_box_(NULL) { | 42 text_box_(NULL) { |
| 40 } | 43 } |
| 41 | 44 |
| 42 EventHandler::~EventHandler() { | 45 EventHandler::~EventHandler() { |
| 43 } | 46 } |
| 44 | 47 |
| 45 void EventHandler::addText(const char* cstr) { | 48 void EventHandler::addText(const char* cstr) { |
| 46 NPVariant variant; | 49 NPVariant variant; |
| 47 // Create a a string variant to be set for the innerText. | 50 // Create a a string variant to be set for the innerText. |
| 48 MakeNPVariant(cstr, &variant); | 51 MakeNPVariant(cstr, &variant); |
| 49 // Report the string to the div. | 52 // Report the string to the div. |
| 50 NPVariant result; | 53 NPVariant result; |
| 51 browser->invokeDefault(npp_, text_box_, &variant, 1, &result); | 54 browser->invokeDefault(npp_, text_box_, &variant, 1, &result); |
| 52 // Release the variant. | 55 // Release the variant. |
| 53 browser->releasevariantvalue(&variant); | 56 browser->releasevariantvalue(&variant); |
| 54 browser->releasevariantvalue(&result); | 57 browser->releasevariantvalue(&result); |
| 55 } | 58 } |
| 56 | 59 |
| 57 std::string EventHandler::EventName(double timestamp, int32 type) { | 60 std::string EventHandler::EventName(double timestamp, int32 type) { |
| 58 std::stringstream strstr; | 61 std::string str = DoubleToString(timestamp) + ": "; |
| 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::stringstream str; | 97 std::string str = EventName(npevent->timeStampSeconds, npevent->type); |
| 98 str << EventName(npevent->timeStampSeconds, npevent->type); | |
| 99 switch (npevent->type) { | 98 switch (npevent->type) { |
| 100 case NPEventType_MouseDown: | 99 case NPEventType_MouseDown: |
| 101 case NPEventType_MouseUp: | 100 case NPEventType_MouseUp: |
| 102 case NPEventType_MouseMove: | 101 case NPEventType_MouseMove: |
| 103 case NPEventType_MouseEnter: | 102 case NPEventType_MouseEnter: |
| 104 case NPEventType_MouseLeave: | 103 case NPEventType_MouseLeave: |
| 105 str << ": mod " << npevent->u.mouse.modifier | 104 str += StringPrintf(": mod %x, but: %x, x: %d, y: %d, click: %d", |
| 106 << ", but: " << npevent->u.mouse.button | 105 npevent->u.mouse.modifier, |
| 107 << ", x: " << npevent->u.mouse.x | 106 npevent->u.mouse.button, |
| 108 << ", y: " << npevent->u.mouse.y | 107 npevent->u.mouse.x, |
| 109 << ", click: " << npevent->u.mouse.clickCount; | 108 npevent->u.mouse.y, |
| 109 npevent->u.mouse.clickCount); |
| 110 break; | 110 break; |
| 111 case NPEventType_MouseWheel: | 111 case NPEventType_MouseWheel: |
| 112 str << ": mod " << npevent->u.wheel.modifier | 112 str += StringPrintf(": mod %x, dx: %f, dy: %f, wtx: %f, wty: %d: sbp %d", |
| 113 << ", dx: " << npevent->u.wheel.deltaX | 113 npevent->u.wheel.modifier, |
| 114 << ", dy: " << npevent->u.wheel.deltaY | 114 npevent->u.wheel.deltaX, |
| 115 << ", wtx: " << npevent->u.wheel.wheelTicksX | 115 npevent->u.wheel.deltaY, |
| 116 << ", wty: " << npevent->u.wheel.wheelTicksY | 116 npevent->u.wheel.wheelTicksX, |
| 117 << ", sbp:" << npevent->u.wheel.scrollByPage; | 117 npevent->u.wheel.wheelTicksY, |
| 118 npevent->u.wheel.scrollByPage); |
| 118 break; | 119 break; |
| 119 case NPEventType_RawKeyDown: | 120 case NPEventType_RawKeyDown: |
| 120 case NPEventType_KeyDown: | 121 case NPEventType_KeyDown: |
| 121 case NPEventType_KeyUp: | 122 case NPEventType_KeyUp: |
| 122 str << ": mod " << npevent->u.key.modifier | 123 str += StringPrintf(": mod %x, key: %x", |
| 123 << ", key: " << npevent->u.key.normalizedKeyCode; | 124 npevent->u.key.modifier, |
| 125 npevent->u.key.normalizedKeyCode); |
| 124 break; | 126 break; |
| 125 case NPEventType_Char: | 127 case NPEventType_Char: |
| 126 str << ": mod " << npevent->u.character.modifier << ", text: "; | 128 str += StringPrintf(": mod %x, text: ", |
| 129 npevent->u.character.modifier); |
| 127 size_t i; | 130 size_t i; |
| 128 for (i = 0; i < arraysize(npevent->u.character.text); ++i) { | 131 for (i = 0; i < arraysize(npevent->u.character.text); ++i) { |
| 129 str << npevent->u.character.text[i] << ' '; | 132 str += StringPrintf("%x ", npevent->u.character.text[i]); |
| 130 } | 133 } |
| 131 str << ", unmod: "; | 134 str += ", unmod: "; |
| 132 for (i = 0; i < arraysize(npevent->u.character.unmodifiedText); ++i) { | 135 for (i = 0; i < arraysize(npevent->u.character.unmodifiedText); ++i) { |
| 133 str << npevent->u.character.unmodifiedText[i] << ' '; | 136 str += StringPrintf("%x ", npevent->u.character.unmodifiedText[i]); |
| 134 } | 137 } |
| 135 break; | 138 break; |
| 136 case NPEventType_Minimize: | 139 case NPEventType_Minimize: |
| 137 case NPEventType_Focus: | 140 case NPEventType_Focus: |
| 138 case NPEventType_Device: | 141 case NPEventType_Device: |
| 139 break; | 142 break; |
| 140 case NPEventType_Undefined: | 143 case NPEventType_Undefined: |
| 141 default: | 144 default: |
| 142 break; | 145 break; |
| 143 } | 146 } |
| 144 addText(str.str().c_str()); | 147 addText(str.c_str()); |
| 145 return 0; | 148 return 0; |
| 146 } | 149 } |
| 147 | 150 |
| 148 bool EventHandler::set_text_box(NPObject* text_box_object) { | 151 bool EventHandler::set_text_box(NPObject* text_box_object) { |
| 149 text_box_ = text_box_object; | 152 text_box_ = text_box_object; |
| 150 // Keep a reference to the text box update object. | 153 // Keep a reference to the text box update object. |
| 151 browser->retainobject(text_box_object); | 154 browser->retainobject(text_box_object); |
| 152 // Announce that we are alive. | 155 // Announce that we are alive. |
| 153 addText("Set the callback for text\n"); | 156 addText("Set the callback for text\n"); |
| 154 return true; | 157 return true; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 171 return; | 174 return; |
| 172 } | 175 } |
| 173 size_t len; | 176 size_t len; |
| 174 char* name = string_duplicate(cstr, &len); | 177 char* name = string_duplicate(cstr, &len); |
| 175 if (NULL == name) { | 178 if (NULL == name) { |
| 176 STRINGN_TO_NPVARIANT(NULL, 0, *var); | 179 STRINGN_TO_NPVARIANT(NULL, 0, *var); |
| 177 return; | 180 return; |
| 178 } | 181 } |
| 179 STRINGN_TO_NPVARIANT(name, len, *var); | 182 STRINGN_TO_NPVARIANT(name, len, *var); |
| 180 } | 183 } |
| OLD | NEW |