Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: webkit/plugins/ppapi/event_conversion.cc

Issue 7237044: Make PP_TimeTicks actually be a tick counter rather than be the same as the (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/plugins/ppapi/event_conversion.h" 5 #include "webkit/plugins/ppapi/event_conversion.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/i18n/char_iterator.h" 8 #include "base/i18n/char_iterator.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/utf_string_conversion_utils.h" 13 #include "base/utf_string_conversion_utils.h"
14 #include "ppapi/c/pp_input_event.h" 14 #include "ppapi/c/pp_input_event.h"
15 #include "ppapi/shared_impl/input_event_impl.h" 15 #include "ppapi/shared_impl/input_event_impl.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
17 #include "webkit/plugins/ppapi/common.h" 17 #include "webkit/plugins/ppapi/common.h"
18 #include "webkit/plugins/ppapi/time_conversion.h"
18 19
19 using ppapi::InputEventData; 20 using ppapi::InputEventData;
20 using WebKit::WebInputEvent; 21 using WebKit::WebInputEvent;
21 using WebKit::WebKeyboardEvent; 22 using WebKit::WebKeyboardEvent;
22 using WebKit::WebMouseEvent; 23 using WebKit::WebMouseEvent;
23 using WebKit::WebMouseWheelEvent; 24 using WebKit::WebMouseWheelEvent;
24 25
25 namespace webkit { 26 namespace webkit {
26 namespace ppapi { 27 namespace ppapi {
27 28
(...skipping 28 matching lines...) Expand all
56 return PP_INPUTEVENT_TYPE_UNDEFINED; 57 return PP_INPUTEVENT_TYPE_UNDEFINED;
57 } 58 }
58 } 59 }
59 60
60 // Generates a PP_InputEvent with the fields common to all events, as well as 61 // Generates a PP_InputEvent with the fields common to all events, as well as
61 // the event type from the given web event. Event-specific fields will be zero 62 // the event type from the given web event. Event-specific fields will be zero
62 // initialized. 63 // initialized.
63 InputEventData GetEventWithCommonFieldsAndType(const WebInputEvent& web_event) { 64 InputEventData GetEventWithCommonFieldsAndType(const WebInputEvent& web_event) {
64 InputEventData result; 65 InputEventData result;
65 result.event_type = ConvertEventTypes(web_event.type); 66 result.event_type = ConvertEventTypes(web_event.type);
66 // TODO(brettw) http://code.google.com/p/chromium/issues/detail?id=57448 67 result.event_time_stamp = EventTimeToPPTimeTicks(web_event.timeStampSeconds);
67 // This should use a tick count rather than the wall clock time that WebKit
68 // uses.
69 result.event_time_stamp = web_event.timeStampSeconds;
70 return result; 68 return result;
71 } 69 }
72 70
73 void AppendKeyEvent(const WebInputEvent& event, 71 void AppendKeyEvent(const WebInputEvent& event,
74 std::vector<InputEventData>* result_events) { 72 std::vector<InputEventData>* result_events) {
75 const WebKeyboardEvent& key_event = 73 const WebKeyboardEvent& key_event =
76 static_cast<const WebKeyboardEvent&>(event); 74 static_cast<const WebKeyboardEvent&>(event);
77 InputEventData result = GetEventWithCommonFieldsAndType(event); 75 InputEventData result = GetEventWithCommonFieldsAndType(event);
78 result.event_modifiers = key_event.modifiers; 76 result.event_modifiers = key_event.modifiers;
79 result.key_code = key_event.windowsKeyCode; 77 result.key_code = key_event.windowsKeyCode;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 break; 158 break;
161 case PP_INPUTEVENT_TYPE_KEYDOWN: 159 case PP_INPUTEVENT_TYPE_KEYDOWN:
162 key_event->type = WebInputEvent::KeyDown; 160 key_event->type = WebInputEvent::KeyDown;
163 break; 161 break;
164 case PP_INPUTEVENT_TYPE_KEYUP: 162 case PP_INPUTEVENT_TYPE_KEYUP:
165 key_event->type = WebInputEvent::KeyUp; 163 key_event->type = WebInputEvent::KeyUp;
166 break; 164 break;
167 default: 165 default:
168 NOTREACHED(); 166 NOTREACHED();
169 } 167 }
170 key_event->timeStampSeconds = event.time_stamp; 168 key_event->timeStampSeconds = PPTimeTicksToEventTime(event.time_stamp);
171 key_event->modifiers = event.u.key.modifier; 169 key_event->modifiers = event.u.key.modifier;
172 key_event->windowsKeyCode = event.u.key.key_code; 170 key_event->windowsKeyCode = event.u.key.key_code;
173 return key_event; 171 return key_event;
174 } 172 }
175 173
176 WebKeyboardEvent* BuildCharEvent(const PP_InputEvent& event) { 174 WebKeyboardEvent* BuildCharEvent(const PP_InputEvent& event) {
177 WebKeyboardEvent* key_event = new WebKeyboardEvent(); 175 WebKeyboardEvent* key_event = new WebKeyboardEvent();
178 key_event->type = WebInputEvent::Char; 176 key_event->type = WebInputEvent::Char;
179 key_event->timeStampSeconds = event.time_stamp; 177 key_event->timeStampSeconds = PPTimeTicksToEventTime(event.time_stamp);
180 key_event->modifiers = event.u.character.modifier; 178 key_event->modifiers = event.u.character.modifier;
181 179
182 // Make sure to not read beyond the buffer in case some bad code doesn't 180 // Make sure to not read beyond the buffer in case some bad code doesn't
183 // NULL-terminate it (this is called from plugins). 181 // NULL-terminate it (this is called from plugins).
184 size_t text_length_cap = WebKeyboardEvent::textLengthCap; 182 size_t text_length_cap = WebKeyboardEvent::textLengthCap;
185 size_t text_len = 0; 183 size_t text_len = 0;
186 while (text_len < text_length_cap && event.u.character.text[text_len]) 184 while (text_len < text_length_cap && event.u.character.text[text_len])
187 text_len++; 185 text_len++;
188 string16 text16 = UTF8ToUTF16(std::string(event.u.character.text, text_len)); 186 string16 text16 = UTF8ToUTF16(std::string(event.u.character.text, text_len));
189 187
(...skipping 23 matching lines...) Expand all
213 break; 211 break;
214 case PP_INPUTEVENT_TYPE_MOUSELEAVE: 212 case PP_INPUTEVENT_TYPE_MOUSELEAVE:
215 mouse_event->type = WebInputEvent::MouseLeave; 213 mouse_event->type = WebInputEvent::MouseLeave;
216 break; 214 break;
217 case PP_INPUTEVENT_TYPE_CONTEXTMENU: 215 case PP_INPUTEVENT_TYPE_CONTEXTMENU:
218 mouse_event->type = WebInputEvent::ContextMenu; 216 mouse_event->type = WebInputEvent::ContextMenu;
219 break; 217 break;
220 default: 218 default:
221 NOTREACHED(); 219 NOTREACHED();
222 } 220 }
223 mouse_event->timeStampSeconds = event.time_stamp; 221 mouse_event->timeStampSeconds = PPTimeTicksToEventTime(event.time_stamp);
224 mouse_event->modifiers = event.u.mouse.modifier; 222 mouse_event->modifiers = event.u.mouse.modifier;
225 mouse_event->button = 223 mouse_event->button =
226 static_cast<WebMouseEvent::Button>(event.u.mouse.button); 224 static_cast<WebMouseEvent::Button>(event.u.mouse.button);
227 mouse_event->x = static_cast<int>(event.u.mouse.x); 225 mouse_event->x = static_cast<int>(event.u.mouse.x);
228 mouse_event->y = static_cast<int>(event.u.mouse.y); 226 mouse_event->y = static_cast<int>(event.u.mouse.y);
229 mouse_event->clickCount = event.u.mouse.click_count; 227 mouse_event->clickCount = event.u.mouse.click_count;
230 return mouse_event; 228 return mouse_event;
231 } 229 }
232 230
233 WebMouseWheelEvent* BuildMouseWheelEvent(const PP_InputEvent& event) { 231 WebMouseWheelEvent* BuildMouseWheelEvent(const PP_InputEvent& event) {
234 WebMouseWheelEvent* mouse_wheel_event = new WebMouseWheelEvent(); 232 WebMouseWheelEvent* mouse_wheel_event = new WebMouseWheelEvent();
235 mouse_wheel_event->type = WebInputEvent::MouseWheel; 233 mouse_wheel_event->type = WebInputEvent::MouseWheel;
236 mouse_wheel_event->timeStampSeconds = event.time_stamp; 234 mouse_wheel_event->timeStampSeconds =
235 PPTimeTicksToEventTime(event.time_stamp);
237 mouse_wheel_event->modifiers = event.u.wheel.modifier; 236 mouse_wheel_event->modifiers = event.u.wheel.modifier;
238 mouse_wheel_event->deltaX = event.u.wheel.delta_x; 237 mouse_wheel_event->deltaX = event.u.wheel.delta_x;
239 mouse_wheel_event->deltaY = event.u.wheel.delta_y; 238 mouse_wheel_event->deltaY = event.u.wheel.delta_y;
240 mouse_wheel_event->wheelTicksX = event.u.wheel.wheel_ticks_x; 239 mouse_wheel_event->wheelTicksX = event.u.wheel.wheel_ticks_x;
241 mouse_wheel_event->wheelTicksY = event.u.wheel.wheel_ticks_y; 240 mouse_wheel_event->wheelTicksY = event.u.wheel.wheel_ticks_y;
242 mouse_wheel_event->scrollByPage = event.u.wheel.scroll_by_page; 241 mouse_wheel_event->scrollByPage = event.u.wheel.scroll_by_page;
243 return mouse_wheel_event; 242 return mouse_wheel_event;
244 } 243 }
245 244
246 void InputEventDataToPPInputEvent(const InputEventData& data, 245 void InputEventDataToPPInputEvent(const InputEventData& data,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 return PP_INPUTEVENT_CLASS_KEYBOARD; 373 return PP_INPUTEVENT_CLASS_KEYBOARD;
375 case WebInputEvent::Undefined: 374 case WebInputEvent::Undefined:
376 default: 375 default:
377 NOTREACHED(); 376 NOTREACHED();
378 return PP_InputEvent_Class(0); 377 return PP_InputEvent_Class(0);
379 } 378 }
380 } 379 }
381 380
382 } // namespace ppapi 381 } // namespace ppapi
383 } // namespace webkit 382 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698