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

Side by Side Diff: sky/engine/web/WebInputEventConversion.cpp

Issue 874823002: Move GestureEvent to NewEventDispatcher (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Build fixes Created 5 years, 11 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
« no previous file with comments | « sky/engine/web/WebInputEventConversion.h ('k') | sky/engine/web/WebViewImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "sky/engine/config.h" 31 #include "sky/engine/config.h"
32 #include "sky/engine/web/WebInputEventConversion.h" 32 #include "sky/engine/web/WebInputEventConversion.h"
33 33
34 #include "sky/engine/core/events/GestureEvent.h"
35 #include "sky/engine/core/events/KeyboardEvent.h" 34 #include "sky/engine/core/events/KeyboardEvent.h"
36 #include "sky/engine/core/frame/FrameHost.h" 35 #include "sky/engine/core/frame/FrameHost.h"
37 #include "sky/engine/core/frame/FrameView.h" 36 #include "sky/engine/core/frame/FrameView.h"
38 #include "sky/engine/core/page/Page.h" 37 #include "sky/engine/core/page/Page.h"
39 #include "sky/engine/core/rendering/RenderObject.h" 38 #include "sky/engine/core/rendering/RenderObject.h"
40 #include "sky/engine/platform/KeyboardCodes.h" 39 #include "sky/engine/platform/KeyboardCodes.h"
41 #include "sky/engine/platform/Widget.h" 40 #include "sky/engine/platform/Widget.h"
42 41
43 namespace blink { 42 namespace blink {
44 43
45 static const double millisPerSecond = 1000.0; 44 static const double millisPerSecond = 1000.0;
46 45
47 static float widgetInputEventsScaleFactor(const Widget* widget)
48 {
49 if (!widget)
50 return 1;
51
52 FrameView* rootView = toFrameView(widget->root());
53 if (!rootView)
54 return 1;
55
56 return rootView->inputEventsScaleFactor();
57 }
58
59 static IntSize widgetInputEventsOffset(const Widget* widget)
60 {
61 if (!widget)
62 return IntSize();
63 FrameView* rootView = toFrameView(widget->root());
64 if (!rootView)
65 return IntSize();
66
67 return rootView->inputEventsOffsetForEmulation();
68 }
69
70
71 // PlatformGestureEventBuilder ------------------------------------------------- -
72
73 PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W ebGestureEvent& e)
74 {
75 float scale = widgetInputEventsScaleFactor(widget);
76 IntSize offset = widgetInputEventsOffset(widget);
77
78 switch (e.type) {
79 case WebInputEvent::GestureScrollBegin:
80 m_type = PlatformEvent::GestureScrollBegin;
81 break;
82 case WebInputEvent::GestureScrollEnd:
83 m_type = PlatformEvent::GestureScrollEnd;
84 break;
85 case WebInputEvent::GestureFlingStart:
86 m_type = PlatformEvent::GestureFlingStart;
87 break;
88 case WebInputEvent::GestureScrollUpdate:
89 m_type = PlatformEvent::GestureScrollUpdate;
90 m_data.m_scrollUpdate.m_deltaX = e.data.scrollUpdate.deltaX / scale;
91 m_data.m_scrollUpdate.m_deltaY = e.data.scrollUpdate.deltaY / scale;
92 m_data.m_scrollUpdate.m_velocityX = e.data.scrollUpdate.velocityX;
93 m_data.m_scrollUpdate.m_velocityY = e.data.scrollUpdate.velocityY;
94 break;
95 case WebInputEvent::GestureScrollUpdateWithoutPropagation:
96 m_type = PlatformEvent::GestureScrollUpdateWithoutPropagation;
97 m_data.m_scrollUpdate.m_deltaX = e.data.scrollUpdate.deltaX / scale;
98 m_data.m_scrollUpdate.m_deltaY = e.data.scrollUpdate.deltaY / scale;
99 m_data.m_scrollUpdate.m_velocityX = e.data.scrollUpdate.velocityX;
100 m_data.m_scrollUpdate.m_velocityY = e.data.scrollUpdate.velocityY;
101 break;
102 case WebInputEvent::GestureTap:
103 m_type = PlatformEvent::GestureTap;
104 m_area = expandedIntSize(FloatSize(e.data.tap.width / scale, e.data.tap. height / scale));
105 m_data.m_tap.m_tapCount = e.data.tap.tapCount;
106 break;
107 case WebInputEvent::GestureTapUnconfirmed:
108 m_type = PlatformEvent::GestureTapUnconfirmed;
109 m_area = expandedIntSize(FloatSize(e.data.tap.width / scale, e.data.tap. height / scale));
110 break;
111 case WebInputEvent::GestureTapDown:
112 m_type = PlatformEvent::GestureTapDown;
113 m_area = expandedIntSize(FloatSize(e.data.tapDown.width / scale, e.data. tapDown.height / scale));
114 break;
115 case WebInputEvent::GestureShowPress:
116 m_type = PlatformEvent::GestureShowPress;
117 m_area = expandedIntSize(FloatSize(e.data.showPress.width / scale, e.dat a.showPress.height / scale));
118 break;
119 case WebInputEvent::GestureTapCancel:
120 m_type = PlatformEvent::GestureTapDownCancel;
121 break;
122 case WebInputEvent::GestureDoubleTap:
123 // DoubleTap gesture is now handled as PlatformEvent::GestureTap with ta p_count = 2. So no
124 // need to convert to a Platfrom DoubleTap gesture. But in WebViewImpl:: handleGestureEvent
125 // all WebGestureEvent are converted to PlatformGestureEvent, for comple teness and not reach
126 // the ASSERT_NOT_REACHED() at the end, convert the DoubleTap to a NoTyp e.
127 m_type = PlatformEvent::NoType;
128 break;
129 case WebInputEvent::GestureTwoFingerTap:
130 m_type = PlatformEvent::GestureTwoFingerTap;
131 m_area = expandedIntSize(FloatSize(e.data.twoFingerTap.firstFingerWidth / scale, e.data.twoFingerTap.firstFingerHeight / scale));
132 break;
133 case WebInputEvent::GestureLongPress:
134 m_type = PlatformEvent::GestureLongPress;
135 m_area = expandedIntSize(FloatSize(e.data.longPress.width / scale, e.dat a.longPress.height / scale));
136 break;
137 case WebInputEvent::GestureLongTap:
138 m_type = PlatformEvent::GestureLongTap;
139 m_area = expandedIntSize(FloatSize(e.data.longPress.width / scale, e.dat a.longPress.height / scale));
140 break;
141 case WebInputEvent::GesturePinchBegin:
142 m_type = PlatformEvent::GesturePinchBegin;
143 break;
144 case WebInputEvent::GesturePinchEnd:
145 m_type = PlatformEvent::GesturePinchEnd;
146 break;
147 case WebInputEvent::GesturePinchUpdate:
148 m_type = PlatformEvent::GesturePinchUpdate;
149 m_data.m_pinchUpdate.m_scale = e.data.pinchUpdate.scale;
150 break;
151 default:
152 ASSERT_NOT_REACHED();
153 }
154 m_position = widget->convertFromContainingView(
155 IntPoint((e.x - offset.width()) / scale, (e.y - offset.height()) / scale ));
156 m_globalPosition = IntPoint(e.globalX, e.globalY);
157 m_timestamp = e.timeStampSeconds;
158
159 m_modifiers = 0;
160 if (e.modifiers & WebInputEvent::ShiftKey)
161 m_modifiers |= PlatformEvent::ShiftKey;
162 if (e.modifiers & WebInputEvent::ControlKey)
163 m_modifiers |= PlatformEvent::CtrlKey;
164 if (e.modifiers & WebInputEvent::AltKey)
165 m_modifiers |= PlatformEvent::AltKey;
166 if (e.modifiers & WebInputEvent::MetaKey)
167 m_modifiers |= PlatformEvent::MetaKey;
168 }
169
170 // MakePlatformKeyboardEvent -------------------------------------------------- 46 // MakePlatformKeyboardEvent --------------------------------------------------
171 47
172 inline PlatformEvent::Type toPlatformKeyboardEventType(WebInputEvent::Type type) 48 inline PlatformEvent::Type toPlatformKeyboardEventType(WebInputEvent::Type type)
173 { 49 {
174 switch (type) { 50 switch (type) {
175 case WebInputEvent::KeyUp: 51 case WebInputEvent::KeyUp:
176 return PlatformEvent::KeyUp; 52 return PlatformEvent::KeyUp;
177 case WebInputEvent::KeyDown: 53 case WebInputEvent::KeyDown:
178 return PlatformEvent::KeyDown; 54 return PlatformEvent::KeyDown;
179 case WebInputEvent::RawKeyDown: 55 case WebInputEvent::RawKeyDown:
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 modifiers |= WebInputEvent::ControlKey; 144 modifiers |= WebInputEvent::ControlKey;
269 if (event.shiftKey()) 145 if (event.shiftKey())
270 modifiers |= WebInputEvent::ShiftKey; 146 modifiers |= WebInputEvent::ShiftKey;
271 if (event.altKey()) 147 if (event.altKey())
272 modifiers |= WebInputEvent::AltKey; 148 modifiers |= WebInputEvent::AltKey;
273 if (event.metaKey()) 149 if (event.metaKey())
274 modifiers |= WebInputEvent::MetaKey; 150 modifiers |= WebInputEvent::MetaKey;
275 return modifiers; 151 return modifiers;
276 } 152 }
277 153
278 static FloatPoint convertAbsoluteLocationForRenderObjectFloat(const LayoutPoint& location, const RenderObject& renderObject)
279 {
280 return renderObject.absoluteToLocal(location, UseTransforms);
281 }
282
283 static IntPoint convertAbsoluteLocationForRenderObject(const LayoutPoint& locati on, const RenderObject& renderObject)
284 {
285 return roundedIntPoint(convertAbsoluteLocationForRenderObjectFloat(location, renderObject));
286 }
287
288 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event) 154 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event)
289 { 155 {
290 if (event.type() == EventTypeNames::keydown) 156 if (event.type() == EventTypeNames::keydown)
291 type = KeyDown; 157 type = KeyDown;
292 else if (event.type() == EventTypeNames::keyup) 158 else if (event.type() == EventTypeNames::keyup)
293 type = WebInputEvent::KeyUp; 159 type = WebInputEvent::KeyUp;
294 else if (event.type() == EventTypeNames::keypress) 160 else if (event.type() == EventTypeNames::keypress)
295 type = WebInputEvent::Char; 161 type = WebInputEvent::Char;
296 else 162 else
297 return; // Skip all other keyboard events. 163 return; // Skip all other keyboard events.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 nativeKeyCode = event.nativeVirtualKeyCode(); 228 nativeKeyCode = event.nativeVirtualKeyCode();
363 229
364 windowsKeyCode = windowsKeyCodeWithoutLocation(event.windowsVirtualKeyCode() ); 230 windowsKeyCode = windowsKeyCodeWithoutLocation(event.windowsVirtualKeyCode() );
365 modifiers |= locationModifiersFromWindowsKeyCode(event.windowsVirtualKeyCode ()); 231 modifiers |= locationModifiersFromWindowsKeyCode(event.windowsVirtualKeyCode ());
366 232
367 event.text().copyTo(text, 0, textLengthCap); 233 event.text().copyTo(text, 0, textLengthCap);
368 event.unmodifiedText().copyTo(unmodifiedText, 0, textLengthCap); 234 event.unmodifiedText().copyTo(unmodifiedText, 0, textLengthCap);
369 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), std::min(static_ cast<unsigned>(keyIdentifierLengthCap), event.keyIdentifier().length())); 235 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), std::min(static_ cast<unsigned>(keyIdentifierLengthCap), event.keyIdentifier().length()));
370 } 236 }
371 237
372 WebGestureEventBuilder::WebGestureEventBuilder(const Widget* widget, const Rende rObject* renderObject, const GestureEvent& event)
373 {
374 if (event.type() == EventTypeNames::gestureshowpress)
375 type = GestureShowPress;
376 else if (event.type() == EventTypeNames::gesturetapdown)
377 type = GestureTapDown;
378 else if (event.type() == EventTypeNames::gesturescrollstart)
379 type = GestureScrollBegin;
380 else if (event.type() == EventTypeNames::gesturescrollend)
381 type = GestureScrollEnd;
382 else if (event.type() == EventTypeNames::gesturescrollupdate) {
383 type = GestureScrollUpdate;
384 data.scrollUpdate.deltaX = event.deltaX();
385 data.scrollUpdate.deltaY = event.deltaY();
386 } else if (event.type() == EventTypeNames::gesturetap) {
387 type = GestureTap;
388 data.tap.tapCount = 1;
389 }
390
391 timeStampSeconds = event.timeStamp() / millisPerSecond;
392 modifiers = getWebInputModifiers(event);
393
394 globalX = event.screenX();
395 globalY = event.screenY();
396 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL ocation(), *renderObject);
397 x = localPoint.x();
398 y = localPoint.y();
399 }
400
401 } // namespace blink 238 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/web/WebInputEventConversion.h ('k') | sky/engine/web/WebViewImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698