OLD | NEW |
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 25 matching lines...) Expand all Loading... |
36 #include "core/events/KeyboardEvent.h" | 36 #include "core/events/KeyboardEvent.h" |
37 #include "core/events/MouseEvent.h" | 37 #include "core/events/MouseEvent.h" |
38 #include "core/events/TouchEvent.h" | 38 #include "core/events/TouchEvent.h" |
39 #include "core/events/WheelEvent.h" | 39 #include "core/events/WheelEvent.h" |
40 #include "core/frame/FrameHost.h" | 40 #include "core/frame/FrameHost.h" |
41 #include "core/frame/FrameView.h" | 41 #include "core/frame/FrameView.h" |
42 #include "core/frame/VisualViewport.h" | 42 #include "core/frame/VisualViewport.h" |
43 #include "core/layout/api/LayoutItem.h" | 43 #include "core/layout/api/LayoutItem.h" |
44 #include "core/page/ChromeClient.h" | 44 #include "core/page/ChromeClient.h" |
45 #include "core/page/Page.h" | 45 #include "core/page/Page.h" |
| 46 #include "platform/FrameViewBase.h" |
46 #include "platform/KeyboardCodes.h" | 47 #include "platform/KeyboardCodes.h" |
47 #include "platform/Widget.h" | |
48 #include "public/platform/Platform.h" | 48 #include "public/platform/Platform.h" |
49 | 49 |
50 namespace blink { | 50 namespace blink { |
51 | 51 |
52 namespace { | 52 namespace { |
53 float frameScale(const Widget* widget) { | 53 float frameScale(const FrameViewBase* frameViewBase) { |
54 float scale = 1; | 54 float scale = 1; |
55 if (widget) { | 55 if (frameViewBase) { |
56 FrameView* rootView = toFrameView(widget->root()); | 56 FrameView* rootView = toFrameView(frameViewBase->root()); |
57 if (rootView) | 57 if (rootView) |
58 scale = rootView->inputEventsScaleFactor(); | 58 scale = rootView->inputEventsScaleFactor(); |
59 } | 59 } |
60 return scale; | 60 return scale; |
61 } | 61 } |
62 | 62 |
63 FloatPoint frameTranslation(const Widget* widget) { | 63 FloatPoint frameTranslation(const FrameViewBase* frameViewBase) { |
64 float scale = 1; | 64 float scale = 1; |
65 FloatSize offset; | 65 FloatSize offset; |
66 IntPoint visualViewport; | 66 IntPoint visualViewport; |
67 FloatSize overscrollOffset; | 67 FloatSize overscrollOffset; |
68 if (widget) { | 68 if (frameViewBase) { |
69 FrameView* rootView = toFrameView(widget->root()); | 69 FrameView* rootView = toFrameView(frameViewBase->root()); |
70 if (rootView) { | 70 if (rootView) { |
71 scale = rootView->inputEventsScaleFactor(); | 71 scale = rootView->inputEventsScaleFactor(); |
72 offset = FloatSize(rootView->inputEventsOffsetForEmulation()); | 72 offset = FloatSize(rootView->inputEventsOffsetForEmulation()); |
73 visualViewport = flooredIntPoint(rootView->page() | 73 visualViewport = flooredIntPoint(rootView->page() |
74 ->frameHost() | 74 ->frameHost() |
75 .visualViewport() | 75 .visualViewport() |
76 .visibleRect() | 76 .visibleRect() |
77 .location()); | 77 .location()); |
78 overscrollOffset = rootView->page()->chromeClient().elasticOverscroll(); | 78 overscrollOffset = rootView->page()->chromeClient().elasticOverscroll(); |
79 } | 79 } |
(...skipping 10 matching lines...) Expand all Loading... |
90 return layoutItem.absoluteToLocal(FloatPoint(location), UseTransforms); | 90 return layoutItem.absoluteToLocal(FloatPoint(location), UseTransforms); |
91 } | 91 } |
92 | 92 |
93 IntPoint convertAbsoluteLocationForLayoutObjectInt( | 93 IntPoint convertAbsoluteLocationForLayoutObjectInt( |
94 const DoublePoint& location, | 94 const DoublePoint& location, |
95 const LayoutItem layoutItem) { | 95 const LayoutItem layoutItem) { |
96 return roundedIntPoint( | 96 return roundedIntPoint( |
97 convertAbsoluteLocationForLayoutObjectFloat(location, layoutItem)); | 97 convertAbsoluteLocationForLayoutObjectFloat(location, layoutItem)); |
98 } | 98 } |
99 | 99 |
100 // FIXME: Change |widget| to const Widget& after RemoteFrames get | 100 // FIXME: Change |FrameViewBase| to const FrameViewBase& after RemoteFrames get |
101 // RemoteFrameViews. | 101 // RemoteFrameViews. |
102 void updateWebMouseEventFromCoreMouseEvent(const MouseEvent& event, | 102 void updateWebMouseEventFromCoreMouseEvent(const MouseEvent& event, |
103 const Widget* widget, | 103 const FrameViewBase* frameViewBase, |
104 const LayoutItem layoutItem, | 104 const LayoutItem layoutItem, |
105 WebMouseEvent& webEvent) { | 105 WebMouseEvent& webEvent) { |
106 webEvent.setTimeStampSeconds(event.platformTimeStamp().InSeconds()); | 106 webEvent.setTimeStampSeconds(event.platformTimeStamp().InSeconds()); |
107 webEvent.setModifiers(event.modifiers()); | 107 webEvent.setModifiers(event.modifiers()); |
108 | 108 |
109 FrameView* view = widget ? toFrameView(widget->parent()) : 0; | 109 FrameView* view = frameViewBase ? toFrameView(frameViewBase->parent()) : 0; |
110 // TODO(bokan): If view == nullptr, pointInRootFrame will really be | 110 // TODO(bokan): If view == nullptr, pointInRootFrame will really be |
111 // pointInRootContent. | 111 // pointInRootContent. |
112 IntPoint pointInRootFrame(event.absoluteLocation().x(), | 112 IntPoint pointInRootFrame(event.absoluteLocation().x(), |
113 event.absoluteLocation().y()); | 113 event.absoluteLocation().y()); |
114 if (view) | 114 if (view) |
115 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); | 115 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); |
116 webEvent.globalX = event.screenX(); | 116 webEvent.globalX = event.screenX(); |
117 webEvent.globalY = event.screenY(); | 117 webEvent.globalY = event.screenY(); |
118 webEvent.windowX = pointInRootFrame.x(); | 118 webEvent.windowX = pointInRootFrame.x(); |
119 webEvent.windowY = pointInRootFrame.y(); | 119 webEvent.windowY = pointInRootFrame.y(); |
120 IntPoint localPoint = convertAbsoluteLocationForLayoutObjectInt( | 120 IntPoint localPoint = convertAbsoluteLocationForLayoutObjectInt( |
121 event.absoluteLocation(), layoutItem); | 121 event.absoluteLocation(), layoutItem); |
122 webEvent.x = localPoint.x(); | 122 webEvent.x = localPoint.x(); |
123 webEvent.y = localPoint.y(); | 123 webEvent.y = localPoint.y(); |
124 } | 124 } |
125 | 125 |
126 unsigned toWebInputEventModifierFrom(WebMouseEvent::Button button) { | 126 unsigned toWebInputEventModifierFrom(WebMouseEvent::Button button) { |
127 if (button == WebMouseEvent::Button::NoButton) | 127 if (button == WebMouseEvent::Button::NoButton) |
128 return 0; | 128 return 0; |
129 | 129 |
130 unsigned webMouseButtonToPlatformModifier[] = { | 130 unsigned webMouseButtonToPlatformModifier[] = { |
131 WebInputEvent::LeftButtonDown, WebInputEvent::MiddleButtonDown, | 131 WebInputEvent::LeftButtonDown, WebInputEvent::MiddleButtonDown, |
132 WebInputEvent::RightButtonDown}; | 132 WebInputEvent::RightButtonDown}; |
133 | 133 |
134 return webMouseButtonToPlatformModifier[static_cast<int>(button)]; | 134 return webMouseButtonToPlatformModifier[static_cast<int>(button)]; |
135 } | 135 } |
136 | 136 |
137 } // namespace | 137 } // namespace |
138 | 138 |
139 WebMouseEvent TransformWebMouseEvent(Widget* widget, | 139 WebMouseEvent TransformWebMouseEvent(FrameViewBase* frameViewBase, |
140 const WebMouseEvent& event) { | 140 const WebMouseEvent& event) { |
141 WebMouseEvent result = event; | 141 WebMouseEvent result = event; |
142 | 142 |
143 // TODO(dtapuska): Remove this translation. In the past blink has | 143 // TODO(dtapuska): Remove this translation. In the past blink has |
144 // converted leaves into moves and not known about leaves. It should | 144 // converted leaves into moves and not known about leaves. It should |
145 // be educated about them. crbug.com/686196 | 145 // be educated about them. crbug.com/686196 |
146 if (event.type() == WebInputEvent::MouseEnter || | 146 if (event.type() == WebInputEvent::MouseEnter || |
147 event.type() == WebInputEvent::MouseLeave) { | 147 event.type() == WebInputEvent::MouseLeave) { |
148 result.setType(WebInputEvent::MouseMove); | 148 result.setType(WebInputEvent::MouseMove); |
149 } | 149 } |
150 | 150 |
151 // TODO(dtapuska): Perhaps the event should be constructed correctly? | 151 // TODO(dtapuska): Perhaps the event should be constructed correctly? |
152 // crbug.com/686200 | 152 // crbug.com/686200 |
153 if (event.type() == WebInputEvent::MouseUp) { | 153 if (event.type() == WebInputEvent::MouseUp) { |
154 result.setModifiers(event.modifiers() & | 154 result.setModifiers(event.modifiers() & |
155 ~toWebInputEventModifierFrom(event.button)); | 155 ~toWebInputEventModifierFrom(event.button)); |
156 } | 156 } |
157 result.setFrameScale(frameScale(widget)); | 157 result.setFrameScale(frameScale(frameViewBase)); |
158 result.setFrameTranslate(frameTranslation(widget)); | 158 result.setFrameTranslate(frameTranslation(frameViewBase)); |
159 return result; | 159 return result; |
160 } | 160 } |
161 | 161 |
162 WebMouseWheelEvent TransformWebMouseWheelEvent( | 162 WebMouseWheelEvent TransformWebMouseWheelEvent( |
163 Widget* widget, | 163 FrameViewBase* frameViewBase, |
164 const WebMouseWheelEvent& event) { | 164 const WebMouseWheelEvent& event) { |
165 WebMouseWheelEvent result = event; | 165 WebMouseWheelEvent result = event; |
166 result.setFrameScale(frameScale(widget)); | 166 result.setFrameScale(frameScale(frameViewBase)); |
167 result.setFrameTranslate(frameTranslation(widget)); | 167 result.setFrameTranslate(frameTranslation(frameViewBase)); |
168 return result; | 168 return result; |
169 } | 169 } |
170 | 170 |
171 WebGestureEvent TransformWebGestureEvent(Widget* widget, | 171 WebGestureEvent TransformWebGestureEvent(FrameViewBase* frameViewBase, |
172 const WebGestureEvent& event) { | 172 const WebGestureEvent& event) { |
173 WebGestureEvent result = event; | 173 WebGestureEvent result = event; |
174 result.setFrameScale(frameScale(widget)); | 174 result.setFrameScale(frameScale(frameViewBase)); |
175 result.setFrameTranslate(frameTranslation(widget)); | 175 result.setFrameTranslate(frameTranslation(frameViewBase)); |
176 return result; | 176 return result; |
177 } | 177 } |
178 | 178 |
179 WebTouchEvent TransformWebTouchEvent(float frameScale, | 179 WebTouchEvent TransformWebTouchEvent(float frameScale, |
180 FloatPoint frameTranslate, | 180 FloatPoint frameTranslate, |
181 const WebTouchEvent& event) { | 181 const WebTouchEvent& event) { |
182 // frameScale is default initialized in debug builds to be 0. | 182 // frameScale is default initialized in debug builds to be 0. |
183 DCHECK_EQ(0, event.frameScale()); | 183 DCHECK_EQ(0, event.frameScale()); |
184 DCHECK_EQ(0, event.frameTranslate().x); | 184 DCHECK_EQ(0, event.frameTranslate().x); |
185 DCHECK_EQ(0, event.frameTranslate().y); | 185 DCHECK_EQ(0, event.frameTranslate().y); |
186 WebTouchEvent result = event; | 186 WebTouchEvent result = event; |
187 result.setFrameScale(frameScale); | 187 result.setFrameScale(frameScale); |
188 result.setFrameTranslate(frameTranslate); | 188 result.setFrameTranslate(frameTranslate); |
189 return result; | 189 return result; |
190 } | 190 } |
191 | 191 |
192 WebTouchEvent TransformWebTouchEvent(Widget* widget, | 192 WebTouchEvent TransformWebTouchEvent(FrameViewBase* frameViewBase, |
193 const WebTouchEvent& event) { | 193 const WebTouchEvent& event) { |
194 return TransformWebTouchEvent(frameScale(widget), frameTranslation(widget), | 194 return TransformWebTouchEvent(frameScale(frameViewBase), |
195 event); | 195 frameTranslation(frameViewBase), event); |
196 } | 196 } |
197 | 197 |
198 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, | 198 WebMouseEventBuilder::WebMouseEventBuilder(const FrameViewBase* frameViewBase, |
199 const LayoutItem layoutItem, | 199 const LayoutItem layoutItem, |
200 const MouseEvent& event) { | 200 const MouseEvent& event) { |
201 if (event.nativeEvent()) { | 201 if (event.nativeEvent()) { |
202 *static_cast<WebMouseEvent*>(this) = | 202 *static_cast<WebMouseEvent*>(this) = |
203 event.nativeEvent()->flattenTransform(); | 203 event.nativeEvent()->flattenTransform(); |
204 WebFloatPoint absoluteRootFrameLocation = positionInRootFrame(); | 204 WebFloatPoint absoluteRootFrameLocation = positionInRootFrame(); |
205 IntPoint localPoint = roundedIntPoint( | 205 IntPoint localPoint = roundedIntPoint( |
206 layoutItem.absoluteToLocal(absoluteRootFrameLocation, UseTransforms)); | 206 layoutItem.absoluteToLocal(absoluteRootFrameLocation, UseTransforms)); |
207 x = localPoint.x(); | 207 x = localPoint.x(); |
208 y = localPoint.y(); | 208 y = localPoint.y(); |
(...skipping 14 matching lines...) Expand all Loading... |
223 m_type = WebInputEvent::MouseDown; | 223 m_type = WebInputEvent::MouseDown; |
224 else if (event.type() == EventTypeNames::mouseup) | 224 else if (event.type() == EventTypeNames::mouseup) |
225 m_type = WebInputEvent::MouseUp; | 225 m_type = WebInputEvent::MouseUp; |
226 else if (event.type() == EventTypeNames::contextmenu) | 226 else if (event.type() == EventTypeNames::contextmenu) |
227 m_type = WebInputEvent::ContextMenu; | 227 m_type = WebInputEvent::ContextMenu; |
228 else | 228 else |
229 return; // Skip all other mouse events. | 229 return; // Skip all other mouse events. |
230 | 230 |
231 m_timeStampSeconds = event.platformTimeStamp().InSeconds(); | 231 m_timeStampSeconds = event.platformTimeStamp().InSeconds(); |
232 m_modifiers = event.modifiers(); | 232 m_modifiers = event.modifiers(); |
233 updateWebMouseEventFromCoreMouseEvent(event, widget, layoutItem, *this); | 233 updateWebMouseEventFromCoreMouseEvent(event, frameViewBase, layoutItem, |
| 234 *this); |
234 | 235 |
235 switch (event.button()) { | 236 switch (event.button()) { |
236 case short(WebPointerProperties::Button::Left): | 237 case short(WebPointerProperties::Button::Left): |
237 button = WebMouseEvent::Button::Left; | 238 button = WebMouseEvent::Button::Left; |
238 break; | 239 break; |
239 case short(WebPointerProperties::Button::Middle): | 240 case short(WebPointerProperties::Button::Middle): |
240 button = WebMouseEvent::Button::Middle; | 241 button = WebMouseEvent::Button::Middle; |
241 break; | 242 break; |
242 case short(WebPointerProperties::Button::Right): | 243 case short(WebPointerProperties::Button::Right): |
243 button = WebMouseEvent::Button::Right; | 244 button = WebMouseEvent::Button::Right; |
(...skipping 16 matching lines...) Expand all Loading... |
260 } | 261 } |
261 movementX = event.movementX(); | 262 movementX = event.movementX(); |
262 movementY = event.movementY(); | 263 movementY = event.movementY(); |
263 clickCount = event.detail(); | 264 clickCount = event.detail(); |
264 | 265 |
265 pointerType = WebPointerProperties::PointerType::Mouse; | 266 pointerType = WebPointerProperties::PointerType::Mouse; |
266 } | 267 } |
267 | 268 |
268 // Generate a synthetic WebMouseEvent given a TouchEvent (eg. for emulating a | 269 // Generate a synthetic WebMouseEvent given a TouchEvent (eg. for emulating a |
269 // mouse with touch input for plugins that don't support touch input). | 270 // mouse with touch input for plugins that don't support touch input). |
270 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, | 271 WebMouseEventBuilder::WebMouseEventBuilder(const FrameViewBase* frameViewBase, |
271 const LayoutItem layoutItem, | 272 const LayoutItem layoutItem, |
272 const TouchEvent& event) { | 273 const TouchEvent& event) { |
273 if (!event.touches()) | 274 if (!event.touches()) |
274 return; | 275 return; |
275 if (event.touches()->length() != 1) { | 276 if (event.touches()->length() != 1) { |
276 if (event.touches()->length() || event.type() != EventTypeNames::touchend || | 277 if (event.touches()->length() || event.type() != EventTypeNames::touchend || |
277 !event.changedTouches() || event.changedTouches()->length() != 1) | 278 !event.changedTouches() || event.changedTouches()->length() != 1) |
278 return; | 279 return; |
279 } | 280 } |
280 | 281 |
(...skipping 12 matching lines...) Expand all Loading... |
293 else | 294 else |
294 return; | 295 return; |
295 | 296 |
296 m_timeStampSeconds = event.platformTimeStamp().InSeconds(); | 297 m_timeStampSeconds = event.platformTimeStamp().InSeconds(); |
297 m_modifiers = event.modifiers(); | 298 m_modifiers = event.modifiers(); |
298 m_frameScale = 1; | 299 m_frameScale = 1; |
299 m_frameTranslate = WebFloatPoint(); | 300 m_frameTranslate = WebFloatPoint(); |
300 | 301 |
301 // The mouse event co-ordinates should be generated from the co-ordinates of | 302 // The mouse event co-ordinates should be generated from the co-ordinates of |
302 // the touch point. | 303 // the touch point. |
303 FrameView* view = toFrameView(widget->parent()); | 304 FrameView* view = toFrameView(frameViewBase->parent()); |
304 // FIXME: if view == nullptr, pointInRootFrame will really be | 305 // FIXME: if view == nullptr, pointInRootFrame will really be |
305 // pointInRootContent. | 306 // pointInRootContent. |
306 IntPoint pointInRootFrame = roundedIntPoint(touch->absoluteLocation()); | 307 IntPoint pointInRootFrame = roundedIntPoint(touch->absoluteLocation()); |
307 if (view) | 308 if (view) |
308 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); | 309 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); |
309 IntPoint screenPoint = roundedIntPoint(touch->screenLocation()); | 310 IntPoint screenPoint = roundedIntPoint(touch->screenLocation()); |
310 globalX = screenPoint.x(); | 311 globalX = screenPoint.x(); |
311 globalY = screenPoint.y(); | 312 globalY = screenPoint.y(); |
312 windowX = pointInRootFrame.x(); | 313 windowX = pointInRootFrame.x(); |
313 windowY = pointInRootFrame.y(); | 314 windowY = pointInRootFrame.y(); |
(...skipping 29 matching lines...) Expand all Loading... |
343 m_type = WebInputEvent::Char; | 344 m_type = WebInputEvent::Char; |
344 else | 345 else |
345 return; // Skip all other keyboard events. | 346 return; // Skip all other keyboard events. |
346 | 347 |
347 m_modifiers = event.modifiers(); | 348 m_modifiers = event.modifiers(); |
348 m_timeStampSeconds = event.platformTimeStamp().InSeconds(); | 349 m_timeStampSeconds = event.platformTimeStamp().InSeconds(); |
349 windowsKeyCode = event.keyCode(); | 350 windowsKeyCode = event.keyCode(); |
350 } | 351 } |
351 | 352 |
352 Vector<WebMouseEvent> TransformWebMouseEventVector( | 353 Vector<WebMouseEvent> TransformWebMouseEventVector( |
353 Widget* widget, | 354 FrameViewBase* frameViewBase, |
354 const std::vector<const WebInputEvent*>& coalescedEvents) { | 355 const std::vector<const WebInputEvent*>& coalescedEvents) { |
355 Vector<WebMouseEvent> result; | 356 Vector<WebMouseEvent> result; |
356 for (const auto& event : coalescedEvents) { | 357 for (const auto& event : coalescedEvents) { |
357 DCHECK(WebInputEvent::isMouseEventType(event->type())); | 358 DCHECK(WebInputEvent::isMouseEventType(event->type())); |
358 result.push_back(TransformWebMouseEvent( | 359 result.push_back(TransformWebMouseEvent( |
359 widget, static_cast<const WebMouseEvent&>(*event))); | 360 frameViewBase, static_cast<const WebMouseEvent&>(*event))); |
360 } | 361 } |
361 return result; | 362 return result; |
362 } | 363 } |
363 | 364 |
364 Vector<WebTouchEvent> TransformWebTouchEventVector( | 365 Vector<WebTouchEvent> TransformWebTouchEventVector( |
365 Widget* widget, | 366 FrameViewBase* frameViewBase, |
366 const std::vector<const WebInputEvent*>& coalescedEvents) { | 367 const std::vector<const WebInputEvent*>& coalescedEvents) { |
367 float scale = frameScale(widget); | 368 float scale = frameScale(frameViewBase); |
368 FloatPoint translation = frameTranslation(widget); | 369 FloatPoint translation = frameTranslation(frameViewBase); |
369 Vector<WebTouchEvent> result; | 370 Vector<WebTouchEvent> result; |
370 for (const auto& event : coalescedEvents) { | 371 for (const auto& event : coalescedEvents) { |
371 DCHECK(WebInputEvent::isTouchEventType(event->type())); | 372 DCHECK(WebInputEvent::isTouchEventType(event->type())); |
372 result.push_back(TransformWebTouchEvent( | 373 result.push_back(TransformWebTouchEvent( |
373 scale, translation, static_cast<const WebTouchEvent&>(*event))); | 374 scale, translation, static_cast<const WebTouchEvent&>(*event))); |
374 } | 375 } |
375 return result; | 376 return result; |
376 } | 377 } |
377 | 378 |
378 } // namespace blink | 379 } // namespace blink |
OLD | NEW |