2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
32 #include "web/WebInputEventConversion.h"
34 #include "core/dom/Touch.h"
35 #include "core/dom/TouchList.h"
36 #include "core/events/GestureEvent.h"
37 #include "core/events/KeyboardEvent.h"
38 #include "core/events/MouseEvent.h"
39 #include "core/events/TouchEvent.h"
40 #include "core/events/WheelEvent.h"
41 #include "core/frame/FrameHost.h"
42 #include "core/frame/FrameView.h"
43 #include "core/frame/LocalFrame.h"
44 #include "core/layout/LayoutView.h"
45 #include "core/page/Page.h"
46 #include "platform/testing/URLTestHelpers.h"
47 #include "public/web/WebFrame.h"
48 #include "public/web/WebSettings.h"
49 #include "web/WebViewImpl.h"
50 #include "web/tests/FrameTestHelpers.h"
51 #include <gtest/gtest.h>
55 PassRefPtrWillBeRawPtr
<KeyboardEvent
> createKeyboardEventWithLocation(KeyboardEvent::KeyLocationCode location
)
57 return KeyboardEvent::create("keydown", true, true, 0, "", "", "", location
, false, false, false, false);
60 int getModifiersForKeyLocationCode(KeyboardEvent::KeyLocationCode location
)
62 RefPtrWillBeRawPtr
<KeyboardEvent
> event
= createKeyboardEventWithLocation(location
);
63 WebKeyboardEventBuilder
convertedEvent(*event
);
64 return convertedEvent
.modifiers
;
67 TEST(WebInputEventConversionTest
, WebKeyboardEventBuilder
)
69 // Test key location conversion.
70 int modifiers
= getModifiersForKeyLocationCode(KeyboardEvent::DOM_KEY_LOCATION_STANDARD
);
71 EXPECT_FALSE(modifiers
& WebInputEvent::IsKeyPad
|| modifiers
& WebInputEvent::IsLeft
|| modifiers
& WebInputEvent::IsRight
);
73 modifiers
= getModifiersForKeyLocationCode(KeyboardEvent::DOM_KEY_LOCATION_LEFT
);
74 EXPECT_TRUE(modifiers
& WebInputEvent::IsLeft
);
75 EXPECT_FALSE(modifiers
& WebInputEvent::IsKeyPad
|| modifiers
& WebInputEvent::IsRight
);
77 modifiers
= getModifiersForKeyLocationCode(KeyboardEvent::DOM_KEY_LOCATION_RIGHT
);
78 EXPECT_TRUE(modifiers
& WebInputEvent::IsRight
);
79 EXPECT_FALSE(modifiers
& WebInputEvent::IsKeyPad
|| modifiers
& WebInputEvent::IsLeft
);
81 modifiers
= getModifiersForKeyLocationCode(KeyboardEvent::DOM_KEY_LOCATION_NUMPAD
);
82 EXPECT_TRUE(modifiers
& WebInputEvent::IsKeyPad
);
83 EXPECT_FALSE(modifiers
& WebInputEvent::IsLeft
|| modifiers
& WebInputEvent::IsRight
);
86 TEST(WebInputEventConversionTest
, WebMouseEventBuilder
)
88 RefPtrWillBeRawPtr
<TouchEvent
> event
= TouchEvent::create();
89 WebMouseEventBuilder
mouse(0, 0, *event
);
90 EXPECT_EQ(WebInputEvent::Undefined
, mouse
.type
);
93 TEST(WebInputEventConversionTest
, WebTouchEventBuilder
)
95 const std::string
baseURL("http://www.test0.com/");
96 const std::string
fileName("fixed_layout.html");
98 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL
.c_str()), WebString::fromUTF8("fixed_layout.html"));
99 FrameTestHelpers::WebViewHelper webViewHelper
;
100 WebViewImpl
* webViewImpl
= webViewHelper
.initializeAndLoad(baseURL
+ fileName
, true);
102 int pageHeight
= 480;
103 webViewImpl
->resize(WebSize(pageWidth
, pageHeight
));
104 webViewImpl
->layout();
106 RefPtrWillBeRawPtr
<Document
> document
= toLocalFrame(webViewImpl
->page()->mainFrame())->document();
107 LocalDOMWindow
* domWindow
= document
->domWindow();
108 LayoutView
* documentLayoutView
= document
->layoutView();
110 WebTouchPoint p0
, p1
;
113 p0
.screenPosition
= WebFloatPoint(100.f
, 50.f
);
114 p1
.screenPosition
= WebFloatPoint(150.f
, 25.f
);
115 p0
.position
= WebFloatPoint(10.f
, 10.f
);
116 p1
.position
= WebFloatPoint(5.f
, 5.f
);
117 p0
.radiusX
= p1
.radiusY
= 10.f
;
118 p0
.radiusY
= p1
.radiusX
= 5.f
;
119 p0
.rotationAngle
= p1
.rotationAngle
= 1.f
;
120 p0
.force
= p1
.force
= 25.f
;
122 RefPtrWillBeRawPtr
<Touch
> touch0
= Touch::create(toLocalFrame(webViewImpl
->page()->mainFrame()), document
.get(), p0
.id
, p0
.screenPosition
, p0
.position
, FloatSize(p0
.radiusX
, p0
.radiusY
), p0
.rotationAngle
, p0
.force
);
123 RefPtrWillBeRawPtr
<Touch
> touch1
= Touch::create(toLocalFrame(webViewImpl
->page()->mainFrame()), document
.get(), p1
.id
, p1
.screenPosition
, p1
.position
, FloatSize(p1
.radiusX
, p1
.radiusY
), p1
.rotationAngle
, p1
.force
);
127 RefPtrWillBeRawPtr
<TouchList
> touchList
= TouchList::create();
128 touchList
->append(touch0
);
129 RefPtrWillBeRawPtr
<TouchEvent
> touchEvent
= TouchEvent::create(touchList
.get(), touchList
.get(), touchList
.get(), EventTypeNames::touchstart
, domWindow
, false, false, false, false, false, false);
131 WebTouchEventBuilder
webTouchBuilder(documentLayoutView
, *touchEvent
);
132 ASSERT_EQ(1u, webTouchBuilder
.touchesLength
);
133 EXPECT_EQ(WebInputEvent::TouchStart
, webTouchBuilder
.type
);
134 EXPECT_EQ(WebTouchPoint::StatePressed
, webTouchBuilder
.touches
[0].state
);
135 EXPECT_FLOAT_EQ(p0
.screenPosition
.x
, webTouchBuilder
.touches
[0].screenPosition
.x
);
136 EXPECT_FLOAT_EQ(p0
.screenPosition
.y
, webTouchBuilder
.touches
[0].screenPosition
.y
);
137 EXPECT_FLOAT_EQ(p0
.position
.x
, webTouchBuilder
.touches
[0].position
.x
);
138 EXPECT_FLOAT_EQ(p0
.position
.y
, webTouchBuilder
.touches
[0].position
.y
);
139 EXPECT_FLOAT_EQ(p0
.radiusX
, webTouchBuilder
.touches
[0].radiusX
);
140 EXPECT_FLOAT_EQ(p0
.radiusY
, webTouchBuilder
.touches
[0].radiusY
);
141 EXPECT_FLOAT_EQ(p0
.rotationAngle
, webTouchBuilder
.touches
[0].rotationAngle
);
142 EXPECT_FLOAT_EQ(p0
.force
, webTouchBuilder
.touches
[0].force
);
147 RefPtrWillBeRawPtr
<TouchList
> activeTouchList
= TouchList::create();
148 RefPtrWillBeRawPtr
<TouchList
> movedTouchList
= TouchList::create();
149 activeTouchList
->append(touch0
);
150 activeTouchList
->append(touch1
);
151 movedTouchList
->append(touch0
);
152 RefPtrWillBeRawPtr
<TouchEvent
> touchEvent
= TouchEvent::create(activeTouchList
.get(), activeTouchList
.get(), movedTouchList
.get(), EventTypeNames::touchmove
, domWindow
, false, false, false, false, false, false);
154 WebTouchEventBuilder
webTouchBuilder(documentLayoutView
, *touchEvent
);
155 ASSERT_EQ(2u, webTouchBuilder
.touchesLength
);
156 EXPECT_EQ(WebInputEvent::TouchMove
, webTouchBuilder
.type
);
157 EXPECT_EQ(WebTouchPoint::StateMoved
, webTouchBuilder
.touches
[0].state
);
158 EXPECT_EQ(WebTouchPoint::StateStationary
, webTouchBuilder
.touches
[1].state
);
159 EXPECT_EQ(p0
.id
, webTouchBuilder
.touches
[0].id
);
160 EXPECT_EQ(p1
.id
, webTouchBuilder
.touches
[1].id
);
163 // Test touchmove, different point yields same ordering.
165 RefPtrWillBeRawPtr
<TouchList
> activeTouchList
= TouchList::create();
166 RefPtrWillBeRawPtr
<TouchList
> movedTouchList
= TouchList::create();
167 activeTouchList
->append(touch0
);
168 activeTouchList
->append(touch1
);
169 movedTouchList
->append(touch1
);
170 RefPtrWillBeRawPtr
<TouchEvent
> touchEvent
= TouchEvent::create(activeTouchList
.get(), activeTouchList
.get(), movedTouchList
.get(), EventTypeNames::touchmove
, domWindow
, false, false, false, false, false, false);
172 WebTouchEventBuilder
webTouchBuilder(documentLayoutView
, *touchEvent
);
173 ASSERT_EQ(2u, webTouchBuilder
.touchesLength
);
174 EXPECT_EQ(WebInputEvent::TouchMove
, webTouchBuilder
.type
);
175 EXPECT_EQ(WebTouchPoint::StateStationary
, webTouchBuilder
.touches
[0].state
);
176 EXPECT_EQ(WebTouchPoint::StateMoved
, webTouchBuilder
.touches
[1].state
);
177 EXPECT_EQ(p0
.id
, webTouchBuilder
.touches
[0].id
);
178 EXPECT_EQ(p1
.id
, webTouchBuilder
.touches
[1].id
);
183 RefPtrWillBeRawPtr
<TouchList
> activeTouchList
= TouchList::create();
184 RefPtrWillBeRawPtr
<TouchList
> releasedTouchList
= TouchList::create();
185 activeTouchList
->append(touch0
);
186 releasedTouchList
->append(touch1
);
187 RefPtrWillBeRawPtr
<TouchEvent
> touchEvent
= TouchEvent::create(activeTouchList
.get(), activeTouchList
.get(), releasedTouchList
.get(), EventTypeNames::touchend
, domWindow
, false, false, false, false, false, false);
189 WebTouchEventBuilder
webTouchBuilder(documentLayoutView
, *touchEvent
);
190 ASSERT_EQ(2u, webTouchBuilder
.touchesLength
);
191 EXPECT_EQ(WebInputEvent::TouchEnd
, webTouchBuilder
.type
);
192 EXPECT_EQ(WebTouchPoint::StateStationary
, webTouchBuilder
.touches
[0].state
);
193 EXPECT_EQ(WebTouchPoint::StateReleased
, webTouchBuilder
.touches
[1].state
);
194 EXPECT_EQ(p0
.id
, webTouchBuilder
.touches
[0].id
);
195 EXPECT_EQ(p1
.id
, webTouchBuilder
.touches
[1].id
);
200 RefPtrWillBeRawPtr
<TouchList
> activeTouchList
= TouchList::create();
201 RefPtrWillBeRawPtr
<TouchList
> cancelledTouchList
= TouchList::create();
202 cancelledTouchList
->append(touch0
);
203 cancelledTouchList
->append(touch1
);
204 RefPtrWillBeRawPtr
<TouchEvent
> touchEvent
= TouchEvent::create(activeTouchList
.get(), activeTouchList
.get(), cancelledTouchList
.get(), EventTypeNames::touchcancel
, domWindow
, false, false, false, false, false, false);
206 WebTouchEventBuilder
webTouchBuilder(documentLayoutView
, *touchEvent
);
207 ASSERT_EQ(2u, webTouchBuilder
.touchesLength
);
208 EXPECT_EQ(WebInputEvent::TouchCancel
, webTouchBuilder
.type
);
209 EXPECT_EQ(WebTouchPoint::StateCancelled
, webTouchBuilder
.touches
[0].state
);
210 EXPECT_EQ(WebTouchPoint::StateCancelled
, webTouchBuilder
.touches
[1].state
);
211 EXPECT_EQ(p0
.id
, webTouchBuilder
.touches
[0].id
);
212 EXPECT_EQ(p1
.id
, webTouchBuilder
.touches
[1].id
);
215 // Test max point limit.
217 RefPtrWillBeRawPtr
<TouchList
> touchList
= TouchList::create();
218 RefPtrWillBeRawPtr
<TouchList
> changedTouchList
= TouchList::create();
219 for (int i
= 0; i
<= static_cast<int>(WebTouchEvent::touchesLengthCap
) * 2; ++i
) {
220 RefPtrWillBeRawPtr
<Touch
> touch
= Touch::create(toLocalFrame(webViewImpl
->page()->mainFrame()), document
.get(), i
, p0
.screenPosition
, p0
.position
, FloatSize(p0
.radiusX
, p0
.radiusY
), p0
.rotationAngle
, p0
.force
);
221 touchList
->append(touch
);
222 changedTouchList
->append(touch
);
224 RefPtrWillBeRawPtr
<TouchEvent
> touchEvent
= TouchEvent::create(touchList
.get(), touchList
.get(), touchList
.get(), EventTypeNames::touchstart
, domWindow
, false, false, false, false, false, false);
226 WebTouchEventBuilder
webTouchBuilder(documentLayoutView
, *touchEvent
);
227 ASSERT_EQ(static_cast<unsigned>(WebTouchEvent::touchesLengthCap
), webTouchBuilder
.touchesLength
);
231 TEST(WebInputEventConversionTest
, InputEventsScaling
)
233 const std::string
baseURL("http://www.test1.com/");
234 const std::string
fileName("fixed_layout.html");
236 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL
.c_str()), WebString::fromUTF8("fixed_layout.html"));
237 FrameTestHelpers::WebViewHelper webViewHelper
;
238 WebViewImpl
* webViewImpl
= webViewHelper
.initializeAndLoad(baseURL
+ fileName
, true);
239 webViewImpl
->settings()->setViewportEnabled(true);
241 int pageHeight
= 480;
242 webViewImpl
->resize(WebSize(pageWidth
, pageHeight
));
243 webViewImpl
->layout();
245 webViewImpl
->setPageScaleFactor(2);
247 FrameView
* view
= toLocalFrame(webViewImpl
->page()->mainFrame())->view();
248 RefPtrWillBeRawPtr
<Document
> document
= toLocalFrame(webViewImpl
->page()->mainFrame())->document();
249 LocalDOMWindow
* domWindow
= document
->domWindow();
250 LayoutView
* documentLayoutView
= document
->layoutView();
253 WebMouseEvent webMouseEvent
;
254 webMouseEvent
.type
= WebInputEvent::MouseMove
;
255 webMouseEvent
.x
= 10;
256 webMouseEvent
.y
= 10;
257 webMouseEvent
.windowX
= 10;
258 webMouseEvent
.windowY
= 10;
259 webMouseEvent
.globalX
= 10;
260 webMouseEvent
.globalY
= 10;
261 webMouseEvent
.movementX
= 10;
262 webMouseEvent
.movementY
= 10;
264 PlatformMouseEventBuilder
platformMouseBuilder(view
, webMouseEvent
);
265 EXPECT_EQ(5, platformMouseBuilder
.position().x());
266 EXPECT_EQ(5, platformMouseBuilder
.position().y());
267 EXPECT_EQ(10, platformMouseBuilder
.globalPosition().x());
268 EXPECT_EQ(10, platformMouseBuilder
.globalPosition().y());
269 EXPECT_EQ(5, platformMouseBuilder
.movementDelta().x());
270 EXPECT_EQ(5, platformMouseBuilder
.movementDelta().y());
274 WebGestureEvent webGestureEvent
;
275 webGestureEvent
.type
= WebInputEvent::GestureScrollUpdate
;
276 webGestureEvent
.x
= 10;
277 webGestureEvent
.y
= 12;
278 webGestureEvent
.globalX
= 20;
279 webGestureEvent
.globalY
= 22;
280 webGestureEvent
.data
.scrollUpdate
.deltaX
= 30;
281 webGestureEvent
.data
.scrollUpdate
.deltaY
= 32;
282 webGestureEvent
.data
.scrollUpdate
.velocityX
= 40;
283 webGestureEvent
.data
.scrollUpdate
.velocityY
= 42;
284 webGestureEvent
.data
.scrollUpdate
.inertial
= true;
285 webGestureEvent
.data
.scrollUpdate
.preventPropagation
= true;
287 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
288 EXPECT_EQ(5, platformGestureBuilder
.position().x());
289 EXPECT_EQ(6, platformGestureBuilder
.position().y());
290 EXPECT_EQ(20, platformGestureBuilder
.globalPosition().x());
291 EXPECT_EQ(22, platformGestureBuilder
.globalPosition().y());
292 EXPECT_EQ(15, platformGestureBuilder
.deltaX());
293 EXPECT_EQ(16, platformGestureBuilder
.deltaY());
294 // TODO: The velocity values may need to be scaled to page scale in
295 // order to remain consist with delta values.
296 EXPECT_EQ(40, platformGestureBuilder
.velocityX());
297 EXPECT_EQ(42, platformGestureBuilder
.velocityY());
298 EXPECT_TRUE(platformGestureBuilder
.inertial());
299 EXPECT_TRUE(platformGestureBuilder
.preventPropagation());
303 WebGestureEvent webGestureEvent
;
304 webGestureEvent
.type
= WebInputEvent::GestureScrollEnd
;
305 webGestureEvent
.x
= 10;
306 webGestureEvent
.y
= 12;
307 webGestureEvent
.globalX
= 20;
308 webGestureEvent
.globalY
= 22;
310 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
311 EXPECT_EQ(5, platformGestureBuilder
.position().x());
312 EXPECT_EQ(6, platformGestureBuilder
.position().y());
313 EXPECT_EQ(20, platformGestureBuilder
.globalPosition().x());
314 EXPECT_EQ(22, platformGestureBuilder
.globalPosition().y());
315 EXPECT_FALSE(platformGestureBuilder
.inertial());
319 WebGestureEvent webGestureEvent
;
320 webGestureEvent
.type
= WebInputEvent::GestureTap
;
321 webGestureEvent
.data
.tap
.width
= 10;
322 webGestureEvent
.data
.tap
.height
= 10;
324 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
325 EXPECT_EQ(5, platformGestureBuilder
.area().width());
326 EXPECT_EQ(5, platformGestureBuilder
.area().height());
330 WebGestureEvent webGestureEvent
;
331 webGestureEvent
.type
= WebInputEvent::GestureTapUnconfirmed
;
332 webGestureEvent
.data
.tap
.width
= 10;
333 webGestureEvent
.data
.tap
.height
= 10;
335 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
336 EXPECT_EQ(5, platformGestureBuilder
.area().width());
337 EXPECT_EQ(5, platformGestureBuilder
.area().height());
341 WebGestureEvent webGestureEvent
;
342 webGestureEvent
.type
= WebInputEvent::GestureTapDown
;
343 webGestureEvent
.data
.tapDown
.width
= 10;
344 webGestureEvent
.data
.tapDown
.height
= 10;
346 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
347 EXPECT_EQ(5, platformGestureBuilder
.area().width());
348 EXPECT_EQ(5, platformGestureBuilder
.area().height());
352 WebGestureEvent webGestureEvent
;
353 webGestureEvent
.type
= WebInputEvent::GestureShowPress
;
354 webGestureEvent
.data
.showPress
.width
= 10;
355 webGestureEvent
.data
.showPress
.height
= 10;
357 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
358 EXPECT_EQ(5, platformGestureBuilder
.area().width());
359 EXPECT_EQ(5, platformGestureBuilder
.area().height());
363 WebGestureEvent webGestureEvent
;
364 webGestureEvent
.type
= WebInputEvent::GestureLongPress
;
365 webGestureEvent
.data
.longPress
.width
= 10;
366 webGestureEvent
.data
.longPress
.height
= 10;
368 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
369 EXPECT_EQ(5, platformGestureBuilder
.area().width());
370 EXPECT_EQ(5, platformGestureBuilder
.area().height());
374 WebGestureEvent webGestureEvent
;
375 webGestureEvent
.type
= WebInputEvent::GestureTwoFingerTap
;
376 webGestureEvent
.data
.twoFingerTap
.firstFingerWidth
= 10;
377 webGestureEvent
.data
.twoFingerTap
.firstFingerHeight
= 10;
379 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
380 EXPECT_EQ(5, platformGestureBuilder
.area().width());
381 EXPECT_EQ(5, platformGestureBuilder
.area().height());
385 WebTouchEvent webTouchEvent
;
386 webTouchEvent
.type
= WebInputEvent::TouchMove
;
387 webTouchEvent
.touchesLength
= 1;
388 webTouchEvent
.touches
[0].state
= WebTouchPoint::StateMoved
;
389 webTouchEvent
.touches
[0].screenPosition
.x
= 10.6f
;
390 webTouchEvent
.touches
[0].screenPosition
.y
= 10.4f
;
391 webTouchEvent
.touches
[0].position
.x
= 10.6f
;
392 webTouchEvent
.touches
[0].position
.y
= 10.4f
;
393 webTouchEvent
.touches
[0].radiusX
= 10.6f
;
394 webTouchEvent
.touches
[0].radiusY
= 10.4f
;
396 EXPECT_FLOAT_EQ(10.6f
, webTouchEvent
.touches
[0].screenPosition
.x
);
397 EXPECT_FLOAT_EQ(10.4f
, webTouchEvent
.touches
[0].screenPosition
.y
);
398 EXPECT_FLOAT_EQ(10.6f
, webTouchEvent
.touches
[0].position
.x
);
399 EXPECT_FLOAT_EQ(10.4f
, webTouchEvent
.touches
[0].position
.y
);
400 EXPECT_FLOAT_EQ(10.6f
, webTouchEvent
.touches
[0].radiusX
);
401 EXPECT_FLOAT_EQ(10.4f
, webTouchEvent
.touches
[0].radiusY
);
403 PlatformTouchEventBuilder
platformTouchBuilder(view
, webTouchEvent
);
404 EXPECT_FLOAT_EQ(10.6f
, platformTouchBuilder
.touchPoints()[0].screenPos().x());
405 EXPECT_FLOAT_EQ(10.4f
, platformTouchBuilder
.touchPoints()[0].screenPos().y());
406 EXPECT_FLOAT_EQ(5.3f
, platformTouchBuilder
.touchPoints()[0].pos().x());
407 EXPECT_FLOAT_EQ(5.2f
, platformTouchBuilder
.touchPoints()[0].pos().y());
408 EXPECT_FLOAT_EQ(5.3f
, platformTouchBuilder
.touchPoints()[0].radius().width());
409 EXPECT_FLOAT_EQ(5.2f
, platformTouchBuilder
.touchPoints()[0].radius().height());
412 // Reverse builders should *not* go back to physical pixels, as they are used for plugins
413 // which expect CSS pixel coordinates.
415 PlatformMouseEvent
platformMouseEvent(IntPoint(10, 10), IntPoint(10, 10), LeftButton
, PlatformEvent::MouseMoved
, 1, false, false, false, false, PlatformMouseEvent::RealOrIndistinguishable
, 0);
416 RefPtrWillBeRawPtr
<MouseEvent
> mouseEvent
= MouseEvent::create(EventTypeNames::mousemove
, domWindow
, platformMouseEvent
, 0, document
);
417 WebMouseEventBuilder
webMouseBuilder(view
, documentLayoutView
, *mouseEvent
);
419 EXPECT_EQ(10, webMouseBuilder
.x
);
420 EXPECT_EQ(10, webMouseBuilder
.y
);
421 EXPECT_EQ(10, webMouseBuilder
.globalX
);
422 EXPECT_EQ(10, webMouseBuilder
.globalY
);
423 EXPECT_EQ(10, webMouseBuilder
.windowX
);
424 EXPECT_EQ(10, webMouseBuilder
.windowY
);
428 PlatformMouseEvent
platformMouseEvent(IntPoint(10, 10), IntPoint(10, 10), NoButton
, PlatformEvent::MouseMoved
, 1, false, false, false, false, PlatformMouseEvent::RealOrIndistinguishable
, 0);
429 RefPtrWillBeRawPtr
<MouseEvent
> mouseEvent
= MouseEvent::create(EventTypeNames::mousemove
, domWindow
, platformMouseEvent
, 0, document
);
430 WebMouseEventBuilder
webMouseBuilder(view
, documentLayoutView
, *mouseEvent
);
431 EXPECT_EQ(WebMouseEvent::ButtonNone
, webMouseBuilder
.button
);
435 PlatformGestureEvent
platformGestureEvent(PlatformEvent::GestureScrollUpdate
, IntPoint(10, 12), IntPoint(20, 22), IntSize(25, 27), 0,
436 false, false, false, false);
437 platformGestureEvent
.setScrollGestureData(30, 32, 40, 42, true, true, -1 /* null plugin id */);
438 // FIXME: GestureEvent does not preserve velocityX, velocityY,
439 // or preventPropagation. It also fails to scale
440 // coordinates (x, y, deltaX, deltaY) to the page scale. This
441 // may lead to unexpected bugs if a PlatformGestureEvent is
442 // transformed into WebGestureEvent and back.
443 RefPtrWillBeRawPtr
<GestureEvent
> gestureEvent
= GestureEvent::create(domWindow
, platformGestureEvent
);
444 WebGestureEventBuilder
webGestureBuilder(documentLayoutView
, *gestureEvent
);
446 EXPECT_EQ(10, webGestureBuilder
.x
);
447 EXPECT_EQ(12, webGestureBuilder
.y
);
448 EXPECT_EQ(20, webGestureBuilder
.globalX
);
449 EXPECT_EQ(22, webGestureBuilder
.globalY
);
450 EXPECT_EQ(30, webGestureBuilder
.data
.scrollUpdate
.deltaX
);
451 EXPECT_EQ(32, webGestureBuilder
.data
.scrollUpdate
.deltaY
);
452 EXPECT_EQ(0, webGestureBuilder
.data
.scrollUpdate
.velocityX
);
453 EXPECT_EQ(0, webGestureBuilder
.data
.scrollUpdate
.velocityY
);
454 EXPECT_TRUE(webGestureBuilder
.data
.scrollUpdate
.inertial
);
455 EXPECT_FALSE(webGestureBuilder
.data
.scrollUpdate
.preventPropagation
);
459 RefPtrWillBeRawPtr
<Touch
> touch
= Touch::create(toLocalFrame(webViewImpl
->page()->mainFrame()), document
.get(), 0, FloatPoint(10, 9.5), FloatPoint(3.5, 2), FloatSize(4, 4.5), 0, 0);
460 RefPtrWillBeRawPtr
<TouchList
> touchList
= TouchList::create();
461 touchList
->append(touch
);
462 RefPtrWillBeRawPtr
<TouchEvent
> touchEvent
= TouchEvent::create(touchList
.get(), touchList
.get(), touchList
.get(), EventTypeNames::touchmove
, domWindow
, false, false, false, false, false, false);
464 WebTouchEventBuilder
webTouchBuilder(documentLayoutView
, *touchEvent
);
465 ASSERT_EQ(1u, webTouchBuilder
.touchesLength
);
466 EXPECT_EQ(10, webTouchBuilder
.touches
[0].screenPosition
.x
);
467 EXPECT_FLOAT_EQ(9.5, webTouchBuilder
.touches
[0].screenPosition
.y
);
468 EXPECT_FLOAT_EQ(3.5, webTouchBuilder
.touches
[0].position
.x
);
469 EXPECT_FLOAT_EQ(2, webTouchBuilder
.touches
[0].position
.y
);
470 EXPECT_FLOAT_EQ(4, webTouchBuilder
.touches
[0].radiusX
);
471 EXPECT_FLOAT_EQ(4.5, webTouchBuilder
.touches
[0].radiusY
);
472 EXPECT_FALSE(webTouchBuilder
.cancelable
);
476 TEST(WebInputEventConversionTest
, InputEventsTransform
)
478 const std::string
baseURL("http://www.test2.com/");
479 const std::string
fileName("fixed_layout.html");
481 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL
.c_str()), WebString::fromUTF8("fixed_layout.html"));
482 FrameTestHelpers::WebViewHelper webViewHelper
;
483 WebViewImpl
* webViewImpl
= webViewHelper
.initializeAndLoad(baseURL
+ fileName
, true);
484 webViewImpl
->settings()->setViewportEnabled(true);
486 int pageHeight
= 480;
487 webViewImpl
->resize(WebSize(pageWidth
, pageHeight
));
488 webViewImpl
->layout();
490 webViewImpl
->setPageScaleFactor(2);
491 webViewImpl
->setRootLayerTransform(WebSize(10, 20), 1.5);
493 FrameView
* view
= toLocalFrame(webViewImpl
->page()->mainFrame())->view();
496 WebMouseEvent webMouseEvent
;
497 webMouseEvent
.type
= WebInputEvent::MouseMove
;
498 webMouseEvent
.x
= 100;
499 webMouseEvent
.y
= 110;
500 webMouseEvent
.windowX
= 100;
501 webMouseEvent
.windowY
= 110;
502 webMouseEvent
.globalX
= 100;
503 webMouseEvent
.globalY
= 110;
504 webMouseEvent
.movementX
= 60;
505 webMouseEvent
.movementY
= 60;
507 PlatformMouseEventBuilder
platformMouseBuilder(view
, webMouseEvent
);
508 EXPECT_EQ(30, platformMouseBuilder
.position().x());
509 EXPECT_EQ(30, platformMouseBuilder
.position().y());
510 EXPECT_EQ(100, platformMouseBuilder
.globalPosition().x());
511 EXPECT_EQ(110, platformMouseBuilder
.globalPosition().y());
512 EXPECT_EQ(20, platformMouseBuilder
.movementDelta().x());
513 EXPECT_EQ(20, platformMouseBuilder
.movementDelta().y());
517 WebGestureEvent webGestureEvent
;
518 webGestureEvent
.type
= WebInputEvent::GestureScrollUpdate
;
519 webGestureEvent
.x
= 100;
520 webGestureEvent
.y
= 110;
521 webGestureEvent
.globalX
= 100;
522 webGestureEvent
.globalY
= 110;
523 webGestureEvent
.data
.scrollUpdate
.deltaX
= 60;
524 webGestureEvent
.data
.scrollUpdate
.deltaY
= 60;
526 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
527 EXPECT_EQ(30, platformGestureBuilder
.position().x());
528 EXPECT_EQ(30, platformGestureBuilder
.position().y());
529 EXPECT_EQ(100, platformGestureBuilder
.globalPosition().x());
530 EXPECT_EQ(110, platformGestureBuilder
.globalPosition().y());
531 EXPECT_EQ(20, platformGestureBuilder
.deltaX());
532 EXPECT_EQ(20, platformGestureBuilder
.deltaY());
536 WebGestureEvent webGestureEvent
;
537 webGestureEvent
.type
= WebInputEvent::GestureTap
;
538 webGestureEvent
.data
.tap
.width
= 30;
539 webGestureEvent
.data
.tap
.height
= 30;
541 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
542 EXPECT_EQ(10, platformGestureBuilder
.area().width());
543 EXPECT_EQ(10, platformGestureBuilder
.area().height());
547 WebGestureEvent webGestureEvent
;
548 webGestureEvent
.type
= WebInputEvent::GestureTapUnconfirmed
;
549 webGestureEvent
.data
.tap
.width
= 30;
550 webGestureEvent
.data
.tap
.height
= 30;
552 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
553 EXPECT_EQ(10, platformGestureBuilder
.area().width());
554 EXPECT_EQ(10, platformGestureBuilder
.area().height());
558 WebGestureEvent webGestureEvent
;
559 webGestureEvent
.type
= WebInputEvent::GestureTapDown
;
560 webGestureEvent
.data
.tapDown
.width
= 30;
561 webGestureEvent
.data
.tapDown
.height
= 30;
563 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
564 EXPECT_EQ(10, platformGestureBuilder
.area().width());
565 EXPECT_EQ(10, platformGestureBuilder
.area().height());
569 WebGestureEvent webGestureEvent
;
570 webGestureEvent
.type
= WebInputEvent::GestureShowPress
;
571 webGestureEvent
.data
.showPress
.width
= 30;
572 webGestureEvent
.data
.showPress
.height
= 30;
574 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
575 EXPECT_EQ(10, platformGestureBuilder
.area().width());
576 EXPECT_EQ(10, platformGestureBuilder
.area().height());
580 WebGestureEvent webGestureEvent
;
581 webGestureEvent
.type
= WebInputEvent::GestureLongPress
;
582 webGestureEvent
.data
.longPress
.width
= 30;
583 webGestureEvent
.data
.longPress
.height
= 30;
585 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
586 EXPECT_EQ(10, platformGestureBuilder
.area().width());
587 EXPECT_EQ(10, platformGestureBuilder
.area().height());
591 WebGestureEvent webGestureEvent
;
592 webGestureEvent
.type
= WebInputEvent::GestureTwoFingerTap
;
593 webGestureEvent
.data
.twoFingerTap
.firstFingerWidth
= 30;
594 webGestureEvent
.data
.twoFingerTap
.firstFingerHeight
= 30;
596 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
597 EXPECT_EQ(10, platformGestureBuilder
.area().width());
598 EXPECT_EQ(10, platformGestureBuilder
.area().height());
602 WebTouchEvent webTouchEvent
;
603 webTouchEvent
.type
= WebInputEvent::TouchMove
;
604 webTouchEvent
.touchesLength
= 1;
605 webTouchEvent
.touches
[0].state
= WebTouchPoint::StateMoved
;
606 webTouchEvent
.touches
[0].screenPosition
.x
= 100;
607 webTouchEvent
.touches
[0].screenPosition
.y
= 110;
608 webTouchEvent
.touches
[0].position
.x
= 100;
609 webTouchEvent
.touches
[0].position
.y
= 110;
610 webTouchEvent
.touches
[0].radiusX
= 30;
611 webTouchEvent
.touches
[0].radiusY
= 30;
613 PlatformTouchEventBuilder
platformTouchBuilder(view
, webTouchEvent
);
614 EXPECT_FLOAT_EQ(100, platformTouchBuilder
.touchPoints()[0].screenPos().x());
615 EXPECT_FLOAT_EQ(110, platformTouchBuilder
.touchPoints()[0].screenPos().y());
616 EXPECT_FLOAT_EQ(30, platformTouchBuilder
.touchPoints()[0].pos().x());
617 EXPECT_FLOAT_EQ(30, platformTouchBuilder
.touchPoints()[0].pos().y());
618 EXPECT_FLOAT_EQ(10, platformTouchBuilder
.touchPoints()[0].radius().width());
619 EXPECT_FLOAT_EQ(10, platformTouchBuilder
.touchPoints()[0].radius().height());
623 TEST(WebInputEventConversionTest
, InputEventsConversions
)
625 const std::string
baseURL("http://www.test3.com/");
626 const std::string
fileName("fixed_layout.html");
628 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL
.c_str()), WebString::fromUTF8("fixed_layout.html"));
629 FrameTestHelpers::WebViewHelper webViewHelper
;
630 WebViewImpl
* webViewImpl
= webViewHelper
.initializeAndLoad(baseURL
+ fileName
, true);
632 int pageHeight
= 480;
633 webViewImpl
->resize(WebSize(pageWidth
, pageHeight
));
634 webViewImpl
->layout();
636 FrameView
* view
= toLocalFrame(webViewImpl
->page()->mainFrame())->view();
637 RefPtrWillBeRawPtr
<Document
> document
= toLocalFrame(webViewImpl
->page()->mainFrame())->document();
638 LocalDOMWindow
* domWindow
= document
->domWindow();
639 LayoutView
* documentLayoutView
= document
->layoutView();
642 WebGestureEvent webGestureEvent
;
643 webGestureEvent
.type
= WebInputEvent::GestureTap
;
644 webGestureEvent
.x
= 10;
645 webGestureEvent
.y
= 10;
646 webGestureEvent
.globalX
= 10;
647 webGestureEvent
.globalY
= 10;
648 webGestureEvent
.data
.tap
.tapCount
= 1;
649 webGestureEvent
.data
.tap
.width
= 10;
650 webGestureEvent
.data
.tap
.height
= 10;
652 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
653 EXPECT_EQ(10.f
, platformGestureBuilder
.position().x());
654 EXPECT_EQ(10.f
, platformGestureBuilder
.position().y());
655 EXPECT_EQ(10.f
, platformGestureBuilder
.globalPosition().x());
656 EXPECT_EQ(10.f
, platformGestureBuilder
.globalPosition().y());
657 EXPECT_EQ(1, platformGestureBuilder
.tapCount());
659 RefPtrWillBeRawPtr
<GestureEvent
> coreGestureEvent
= GestureEvent::create(domWindow
, platformGestureBuilder
);
660 WebGestureEventBuilder
recreatedWebGestureEvent(documentLayoutView
, *coreGestureEvent
);
661 EXPECT_EQ(webGestureEvent
.type
, recreatedWebGestureEvent
.type
);
662 EXPECT_EQ(webGestureEvent
.x
, recreatedWebGestureEvent
.x
);
663 EXPECT_EQ(webGestureEvent
.y
, recreatedWebGestureEvent
.y
);
664 EXPECT_EQ(webGestureEvent
.globalX
, recreatedWebGestureEvent
.globalX
);
665 EXPECT_EQ(webGestureEvent
.globalY
, recreatedWebGestureEvent
.globalY
);
666 EXPECT_EQ(webGestureEvent
.data
.tap
.tapCount
, recreatedWebGestureEvent
.data
.tap
.tapCount
);
670 TEST(WebInputEventConversionTest
, VisualViewportOffset
)
672 const std::string
baseURL("http://www.test4.com/");
673 const std::string
fileName("fixed_layout.html");
675 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL
.c_str()), WebString::fromUTF8("fixed_layout.html"));
676 FrameTestHelpers::WebViewHelper webViewHelper
;
677 WebViewImpl
* webViewImpl
= webViewHelper
.initializeAndLoad(baseURL
+ fileName
, true);
679 int pageHeight
= 480;
680 webViewImpl
->resize(WebSize(pageWidth
, pageHeight
));
681 webViewImpl
->layout();
683 webViewImpl
->setPageScaleFactor(2);
685 IntPoint
visualOffset(35, 60);
686 webViewImpl
->page()->frameHost().visualViewport().setLocation(visualOffset
);
688 FrameView
* view
= toLocalFrame(webViewImpl
->page()->mainFrame())->view();
691 WebMouseEvent webMouseEvent
;
692 webMouseEvent
.type
= WebInputEvent::MouseMove
;
693 webMouseEvent
.x
= 10;
694 webMouseEvent
.y
= 10;
695 webMouseEvent
.windowX
= 10;
696 webMouseEvent
.windowY
= 10;
697 webMouseEvent
.globalX
= 10;
698 webMouseEvent
.globalY
= 10;
700 PlatformMouseEventBuilder
platformMouseBuilder(view
, webMouseEvent
);
701 EXPECT_EQ(5 + visualOffset
.x(), platformMouseBuilder
.position().x());
702 EXPECT_EQ(5 + visualOffset
.y(), platformMouseBuilder
.position().y());
703 EXPECT_EQ(10, platformMouseBuilder
.globalPosition().x());
704 EXPECT_EQ(10, platformMouseBuilder
.globalPosition().y());
708 WebMouseWheelEvent webMouseWheelEvent
;
709 webMouseWheelEvent
.type
= WebInputEvent::MouseWheel
;
710 webMouseWheelEvent
.x
= 10;
711 webMouseWheelEvent
.y
= 10;
712 webMouseWheelEvent
.windowX
= 10;
713 webMouseWheelEvent
.windowY
= 10;
714 webMouseWheelEvent
.globalX
= 10;
715 webMouseWheelEvent
.globalY
= 10;
717 PlatformWheelEventBuilder
platformWheelBuilder(view
, webMouseWheelEvent
);
718 EXPECT_EQ(5 + visualOffset
.x(), platformWheelBuilder
.position().x());
719 EXPECT_EQ(5 + visualOffset
.y(), platformWheelBuilder
.position().y());
720 EXPECT_EQ(10, platformWheelBuilder
.globalPosition().x());
721 EXPECT_EQ(10, platformWheelBuilder
.globalPosition().y());
725 WebGestureEvent webGestureEvent
;
726 webGestureEvent
.type
= WebInputEvent::GestureScrollUpdate
;
727 webGestureEvent
.x
= 10;
728 webGestureEvent
.y
= 10;
729 webGestureEvent
.globalX
= 10;
730 webGestureEvent
.globalY
= 10;
732 PlatformGestureEventBuilder
platformGestureBuilder(view
, webGestureEvent
);
733 EXPECT_EQ(5 + visualOffset
.x(), platformGestureBuilder
.position().x());
734 EXPECT_EQ(5 + visualOffset
.y(), platformGestureBuilder
.position().y());
735 EXPECT_EQ(10, platformGestureBuilder
.globalPosition().x());
736 EXPECT_EQ(10, platformGestureBuilder
.globalPosition().y());
740 WebTouchEvent webTouchEvent
;
741 webTouchEvent
.type
= WebInputEvent::TouchMove
;
742 webTouchEvent
.touchesLength
= 1;
743 webTouchEvent
.touches
[0].state
= WebTouchPoint::StateMoved
;
744 webTouchEvent
.touches
[0].screenPosition
.x
= 10.6f
;
745 webTouchEvent
.touches
[0].screenPosition
.y
= 10.4f
;
746 webTouchEvent
.touches
[0].position
.x
= 10.6f
;
747 webTouchEvent
.touches
[0].position
.y
= 10.4f
;
749 EXPECT_FLOAT_EQ(10.6f
, webTouchEvent
.touches
[0].screenPosition
.x
);
750 EXPECT_FLOAT_EQ(10.4f
, webTouchEvent
.touches
[0].screenPosition
.y
);
751 EXPECT_FLOAT_EQ(10.6f
, webTouchEvent
.touches
[0].position
.x
);
752 EXPECT_FLOAT_EQ(10.4f
, webTouchEvent
.touches
[0].position
.y
);
754 PlatformTouchEventBuilder
platformTouchBuilder(view
, webTouchEvent
);
755 EXPECT_FLOAT_EQ(10.6f
, platformTouchBuilder
.touchPoints()[0].screenPos().x());
756 EXPECT_FLOAT_EQ(10.4f
, platformTouchBuilder
.touchPoints()[0].screenPos().y());
757 EXPECT_FLOAT_EQ(5.3f
+ visualOffset
.x(), platformTouchBuilder
.touchPoints()[0].pos().x());
758 EXPECT_FLOAT_EQ(5.2f
+ visualOffset
.y(), platformTouchBuilder
.touchPoints()[0].pos().y());
762 TEST(WebInputEventConversionTest
, ElasticOverscroll
)
764 const std::string
baseURL("http://www.test5.com/");
765 const std::string
fileName("fixed_layout.html");
767 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL
.c_str()), WebString::fromUTF8("fixed_layout.html"));
768 FrameTestHelpers::WebViewHelper webViewHelper
;
769 WebViewImpl
* webViewImpl
= webViewHelper
.initializeAndLoad(baseURL
+ fileName
, true);
771 int pageHeight
= 480;
772 webViewImpl
->resize(WebSize(pageWidth
, pageHeight
));
773 webViewImpl
->layout();
775 FrameView
* view
= toLocalFrame(webViewImpl
->page()->mainFrame())->view();
777 FloatSize
elasticOverscroll(10, -20);
778 webViewImpl
->applyViewportDeltas(WebFloatSize(), WebFloatSize(), elasticOverscroll
, 1.0f
, 0.0f
);
780 // Just elastic overscroll.
782 WebMouseEvent webMouseEvent
;
783 webMouseEvent
.type
= WebInputEvent::MouseMove
;
784 webMouseEvent
.x
= 10;
785 webMouseEvent
.y
= 50;
786 webMouseEvent
.windowX
= 10;
787 webMouseEvent
.windowY
= 50;
788 webMouseEvent
.globalX
= 10;
789 webMouseEvent
.globalY
= 50;
791 PlatformMouseEventBuilder
platformMouseBuilder(view
, webMouseEvent
);
792 EXPECT_EQ(webMouseEvent
.x
+ elasticOverscroll
.width(), platformMouseBuilder
.position().x());
793 EXPECT_EQ(webMouseEvent
.y
+ elasticOverscroll
.height(), platformMouseBuilder
.position().y());
794 EXPECT_EQ(webMouseEvent
.globalX
, platformMouseBuilder
.globalPosition().x());
795 EXPECT_EQ(webMouseEvent
.globalY
, platformMouseBuilder
.globalPosition().y());
798 // Elastic overscroll and pinch-zoom (this doesn't actually ever happen,
799 // but ensure that if it were to, the overscroll would be applied after the
802 webViewImpl
->setPageScaleFactor(pageScale
);
803 IntPoint
visualOffset(35, 60);
804 webViewImpl
->page()->frameHost().visualViewport().setLocation(visualOffset
);
806 WebMouseEvent webMouseEvent
;
807 webMouseEvent
.type
= WebInputEvent::MouseMove
;
808 webMouseEvent
.x
= 10;
809 webMouseEvent
.y
= 10;
810 webMouseEvent
.windowX
= 10;
811 webMouseEvent
.windowY
= 10;
812 webMouseEvent
.globalX
= 10;
813 webMouseEvent
.globalY
= 10;
815 PlatformMouseEventBuilder
platformMouseBuilder(view
, webMouseEvent
);
816 EXPECT_EQ(webMouseEvent
.x
/ pageScale
+ visualOffset
.x() + elasticOverscroll
.width(), platformMouseBuilder
.position().x());
817 EXPECT_EQ(webMouseEvent
.y
/ pageScale
+ visualOffset
.y() + elasticOverscroll
.height(), platformMouseBuilder
.position().y());
818 EXPECT_EQ(webMouseEvent
.globalX
, platformMouseBuilder
.globalPosition().x());
819 EXPECT_EQ(webMouseEvent
.globalY
, platformMouseBuilder
.globalPosition().y());
823 // Page reload/navigation should not reset elastic overscroll.
824 TEST(WebInputEventConversionTest
, ElasticOverscrollWithPageReload
)
826 const std::string
baseURL("http://www.test6.com/");
827 const std::string
fileName("fixed_layout.html");
829 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL
.c_str()), WebString::fromUTF8("fixed_layout.html"));
830 FrameTestHelpers::WebViewHelper webViewHelper
;
831 WebViewImpl
* webViewImpl
= webViewHelper
.initializeAndLoad(baseURL
+ fileName
, true);
833 int pageHeight
= 480;
834 webViewImpl
->resize(WebSize(pageWidth
, pageHeight
));
835 webViewImpl
->layout();
837 FloatSize
elasticOverscroll(10, -20);
838 webViewImpl
->applyViewportDeltas(WebFloatSize(), WebFloatSize(), elasticOverscroll
, 1.0f
, 0.0f
);
839 FrameTestHelpers::reloadFrame(webViewHelper
.webView()->mainFrame());
840 FrameView
* view
= toLocalFrame(webViewImpl
->page()->mainFrame())->view();
842 // Just elastic overscroll.
844 WebMouseEvent webMouseEvent
;
845 webMouseEvent
.type
= WebInputEvent::MouseMove
;
846 webMouseEvent
.x
= 10;
847 webMouseEvent
.y
= 50;
848 webMouseEvent
.windowX
= 10;
849 webMouseEvent
.windowY
= 50;
850 webMouseEvent
.globalX
= 10;
851 webMouseEvent
.globalY
= 50;
853 PlatformMouseEventBuilder
platformMouseBuilder(view
, webMouseEvent
);
854 EXPECT_EQ(webMouseEvent
.x
+ elasticOverscroll
.width(), platformMouseBuilder
.position().x());
855 EXPECT_EQ(webMouseEvent
.y
+ elasticOverscroll
.height(), platformMouseBuilder
.position().y());
856 EXPECT_EQ(webMouseEvent
.globalX
, platformMouseBuilder
.globalPosition().x());
857 EXPECT_EQ(webMouseEvent
.globalY
, platformMouseBuilder
.globalPosition().y());
861 TEST(WebInputEventConversionTest
, WebMouseWheelEventBuilder
)
863 const std::string
baseURL("http://www.test7.com/");
864 const std::string
fileName("fixed_layout.html");
866 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL
.c_str()), WebString::fromUTF8("fixed_layout.html"));
867 FrameTestHelpers::WebViewHelper webViewHelper
;
868 WebViewImpl
* webViewImpl
= webViewHelper
.initializeAndLoad(baseURL
+ fileName
, true);
870 int pageHeight
= 480;
871 webViewImpl
->resize(WebSize(pageWidth
, pageHeight
));
872 webViewImpl
->layout();
874 RefPtrWillBeRawPtr
<Document
> document
= toLocalFrame(webViewImpl
->page()->mainFrame())->document();
875 RefPtrWillBeRawPtr
<WheelEvent
> event
= WheelEvent::create(FloatPoint(1, 3), FloatPoint(5, 10),
876 WheelEvent::DOM_DELTA_PAGE
, document
.get()->domWindow(), IntPoint(2, 6), IntPoint(10, 30),
877 true, false, false, false, 0, true, -1 /* null plugin id */, true, Event::RailsModeHorizontal
);
878 WebMouseWheelEventBuilder
webMouseWheel(toLocalFrame(webViewImpl
->page()->mainFrame())->view(), document
.get()->layoutView(), *event
);
879 EXPECT_EQ(1, webMouseWheel
.wheelTicksX
);
880 EXPECT_EQ(3, webMouseWheel
.wheelTicksY
);
881 EXPECT_EQ(5, webMouseWheel
.deltaX
);
882 EXPECT_EQ(10, webMouseWheel
.deltaY
);
883 EXPECT_EQ(2, webMouseWheel
.globalX
);
884 EXPECT_EQ(6, webMouseWheel
.globalY
);
885 EXPECT_EQ(10, webMouseWheel
.windowX
);
886 EXPECT_EQ(30, webMouseWheel
.windowY
);
887 EXPECT_TRUE(webMouseWheel
.scrollByPage
);
888 EXPECT_EQ(WebInputEvent::ControlKey
, webMouseWheel
.modifiers
);
889 EXPECT_TRUE(webMouseWheel
.canScroll
);
890 EXPECT_EQ(WebInputEvent::RailsModeHorizontal
, webMouseWheel
.railsMode
);
893 TEST(WebInputEventConversionTest
, PlatformWheelEventBuilder
)
895 const std::string
baseURL("http://www.test8.com/");
896 const std::string
fileName("fixed_layout.html");
898 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL
.c_str()), WebString::fromUTF8("fixed_layout.html"));
899 FrameTestHelpers::WebViewHelper webViewHelper
;
900 WebViewImpl
* webViewImpl
= webViewHelper
.initializeAndLoad(baseURL
+ fileName
, true);
902 int pageHeight
= 480;
903 webViewImpl
->resize(WebSize(pageWidth
, pageHeight
));
904 webViewImpl
->layout();
906 FrameView
* view
= toLocalFrame(webViewImpl
->page()->mainFrame())->view();
909 WebMouseWheelEvent webMouseWheelEvent
;
910 webMouseWheelEvent
.type
= WebInputEvent::MouseWheel
;
911 webMouseWheelEvent
.x
= 0;
912 webMouseWheelEvent
.y
= 5;
913 webMouseWheelEvent
.deltaX
= 10;
914 webMouseWheelEvent
.deltaY
= 15;
915 webMouseWheelEvent
.modifiers
= WebInputEvent::ControlKey
;
916 webMouseWheelEvent
.hasPreciseScrollingDeltas
= true;
917 webMouseWheelEvent
.canScroll
= true;
918 webMouseWheelEvent
.railsMode
= WebInputEvent::RailsModeHorizontal
;
920 PlatformWheelEventBuilder
platformWheelBuilder(view
, webMouseWheelEvent
);
921 EXPECT_EQ(0, platformWheelBuilder
.position().x());
922 EXPECT_EQ(5, platformWheelBuilder
.position().y());
923 EXPECT_EQ(10, platformWheelBuilder
.deltaX());
924 EXPECT_EQ(15, platformWheelBuilder
.deltaY());
925 EXPECT_EQ(PlatformEvent::CtrlKey
, platformWheelBuilder
.modifiers());
926 EXPECT_TRUE(platformWheelBuilder
.hasPreciseScrollingDeltas());
927 EXPECT_TRUE(platformWheelBuilder
.canScroll());
928 EXPECT_EQ(platformWheelBuilder
.railsMode(), PlatformEvent::RailsModeHorizontal
);
932 WebMouseWheelEvent webMouseWheelEvent
;
933 webMouseWheelEvent
.type
= WebInputEvent::MouseWheel
;
934 webMouseWheelEvent
.x
= 5;
935 webMouseWheelEvent
.y
= 0;
936 webMouseWheelEvent
.deltaX
= 15;
937 webMouseWheelEvent
.deltaY
= 10;
938 webMouseWheelEvent
.modifiers
= WebInputEvent::ShiftKey
;
939 webMouseWheelEvent
.hasPreciseScrollingDeltas
= false;
940 webMouseWheelEvent
.canScroll
= false;
941 webMouseWheelEvent
.railsMode
= WebInputEvent::RailsModeFree
;
943 PlatformWheelEventBuilder
platformWheelBuilder(view
, webMouseWheelEvent
);
944 EXPECT_EQ(5, platformWheelBuilder
.position().x());
945 EXPECT_EQ(0, platformWheelBuilder
.position().y());
946 EXPECT_EQ(15, platformWheelBuilder
.deltaX());
947 EXPECT_EQ(10, platformWheelBuilder
.deltaY());
948 EXPECT_EQ(PlatformEvent::ShiftKey
, platformWheelBuilder
.modifiers());
949 EXPECT_FALSE(platformWheelBuilder
.hasPreciseScrollingDeltas());
950 EXPECT_FALSE(platformWheelBuilder
.canScroll());
951 EXPECT_EQ(platformWheelBuilder
.railsMode(), PlatformEvent::RailsModeFree
);
955 WebMouseWheelEvent webMouseWheelEvent
;
956 webMouseWheelEvent
.type
= WebInputEvent::MouseWheel
;
957 webMouseWheelEvent
.x
= 5;
958 webMouseWheelEvent
.y
= 0;
959 webMouseWheelEvent
.deltaX
= 15;
960 webMouseWheelEvent
.deltaY
= 10;
961 webMouseWheelEvent
.modifiers
= WebInputEvent::AltKey
;
962 webMouseWheelEvent
.hasPreciseScrollingDeltas
= true;
963 webMouseWheelEvent
.canScroll
= false;
964 webMouseWheelEvent
.railsMode
= WebInputEvent::RailsModeVertical
;
966 PlatformWheelEventBuilder
platformWheelBuilder(view
, webMouseWheelEvent
);
967 EXPECT_EQ(5, platformWheelBuilder
.position().x());
968 EXPECT_EQ(0, platformWheelBuilder
.position().y());
969 EXPECT_EQ(15, platformWheelBuilder
.deltaX());
970 EXPECT_EQ(10, platformWheelBuilder
.deltaY());
971 EXPECT_EQ(PlatformEvent::AltKey
, platformWheelBuilder
.modifiers());
972 EXPECT_TRUE(platformWheelBuilder
.hasPreciseScrollingDeltas());
973 EXPECT_FALSE(platformWheelBuilder
.canScroll());
974 EXPECT_EQ(platformWheelBuilder
.railsMode(), PlatformEvent::RailsModeVertical
);