OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 14 matching lines...) Expand all Loading... |
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 "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "WebInputEventConversion.h" | 33 #include "WebInputEventConversion.h" |
34 | 34 |
| 35 #include "Frame.h" |
| 36 #include "FrameTestHelpers.h" |
| 37 #include "FrameView.h" |
| 38 #include "GestureEvent.h" |
35 #include "KeyboardEvent.h" | 39 #include "KeyboardEvent.h" |
| 40 #include "MouseEvent.h" |
| 41 #include "Touch.h" |
36 #include "TouchEvent.h" | 42 #include "TouchEvent.h" |
| 43 #include "TouchList.h" |
| 44 #include "URLTestHelpers.h" |
| 45 #include "WebFrame.h" |
| 46 #include "WebSettings.h" |
| 47 #include "WebViewImpl.h" |
37 #include <gtest/gtest.h> | 48 #include <gtest/gtest.h> |
38 | 49 |
39 using WebKit::WebInputEvent; | 50 using namespace WebKit; |
40 using WebKit::WebKeyboardEvent; | 51 using namespace WebCore; |
41 using WebKit::WebKeyboardEventBuilder; | |
42 using WebKit::WebMouseEventBuilder; | |
43 | 52 |
44 namespace { | 53 namespace { |
45 | 54 |
46 PassRefPtr<WebCore::KeyboardEvent> createKeyboardEventWithLocation(WebCore::Keyb
oardEvent::KeyLocationCode location) | 55 PassRefPtr<WebCore::KeyboardEvent> createKeyboardEventWithLocation(WebCore::Keyb
oardEvent::KeyLocationCode location) |
47 { | 56 { |
48 return WebCore::KeyboardEvent::create("keydown", true, true, 0, "", location
, false, false, false, false, false); | 57 return WebCore::KeyboardEvent::create("keydown", true, true, 0, "", location
, false, false, false, false, false); |
49 } | 58 } |
50 | 59 |
51 int getModifiersForKeyLocationCode(WebCore::KeyboardEvent::KeyLocationCode locat
ion) | 60 int getModifiersForKeyLocationCode(WebCore::KeyboardEvent::KeyLocationCode locat
ion) |
52 { | 61 { |
(...skipping 21 matching lines...) Expand all Loading... |
74 EXPECT_FALSE(modifiers & WebInputEvent::IsLeft || modifiers & WebInputEvent:
:IsRight); | 83 EXPECT_FALSE(modifiers & WebInputEvent::IsLeft || modifiers & WebInputEvent:
:IsRight); |
75 } | 84 } |
76 | 85 |
77 TEST(WebInputEventConversionTest, WebTouchEventBuilder) | 86 TEST(WebInputEventConversionTest, WebTouchEventBuilder) |
78 { | 87 { |
79 RefPtr<WebCore::TouchEvent> event = WebCore::TouchEvent::create(); | 88 RefPtr<WebCore::TouchEvent> event = WebCore::TouchEvent::create(); |
80 WebMouseEventBuilder mouse(0, 0, *event); | 89 WebMouseEventBuilder mouse(0, 0, *event); |
81 EXPECT_EQ(WebInputEvent::Undefined, mouse.type); | 90 EXPECT_EQ(WebInputEvent::Undefined, mouse.type); |
82 } | 91 } |
83 | 92 |
| 93 TEST(WebInputEventConversionTest, InputEventsScaling) |
| 94 { |
| 95 const std::string baseURL("http://www.test.com/"); |
| 96 const std::string fileName("fixed_layout.html"); |
| 97 |
| 98 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s
tr()), WebString::fromUTF8("fixed_layout.html")); |
| 99 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::creat
eWebViewAndLoad(baseURL + fileName, true)); |
| 100 webViewImpl->settings()->setApplyDeviceScaleFactorInCompositor(true); |
| 101 webViewImpl->settings()->setApplyPageScaleFactorInCompositor(true); |
| 102 webViewImpl->enableFixedLayoutMode(true); |
| 103 webViewImpl->settings()->setViewportEnabled(true); |
| 104 int pageWidth = 640; |
| 105 int pageHeight = 480; |
| 106 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
| 107 webViewImpl->layout(); |
| 108 |
| 109 webViewImpl->setPageScaleFactor(2, WebPoint()); |
| 110 |
| 111 FrameView* view = webViewImpl->page()->mainFrame()->view(); |
| 112 RefPtr<Document> document = webViewImpl->page()->mainFrame()->document(); |
| 113 DOMWindow* domWindow = webViewImpl->page()->mainFrame()->document()->default
View(); |
| 114 RenderObject* docRenderer = webViewImpl->page()->mainFrame()->document()->re
nderer(); |
| 115 |
| 116 { |
| 117 WebMouseEvent webMouseEvent; |
| 118 webMouseEvent.type = WebInputEvent::MouseMove; |
| 119 webMouseEvent.x = 10; |
| 120 webMouseEvent.y = 10; |
| 121 webMouseEvent.windowX = 10; |
| 122 webMouseEvent.windowY = 10; |
| 123 webMouseEvent.globalX = 10; |
| 124 webMouseEvent.globalY = 10; |
| 125 webMouseEvent.movementX = 10; |
| 126 webMouseEvent.movementY = 10; |
| 127 |
| 128 PlatformMouseEventBuilder platformMouseBuilder(view, webMouseEvent); |
| 129 EXPECT_EQ(5, platformMouseBuilder.position().x()); |
| 130 EXPECT_EQ(5, platformMouseBuilder.position().y()); |
| 131 EXPECT_EQ(10, platformMouseBuilder.globalPosition().x()); |
| 132 EXPECT_EQ(10, platformMouseBuilder.globalPosition().y()); |
| 133 EXPECT_EQ(5, platformMouseBuilder.movementDelta().x()); |
| 134 EXPECT_EQ(5, platformMouseBuilder.movementDelta().y()); |
| 135 } |
| 136 |
| 137 { |
| 138 WebGestureEvent webGestureEvent; |
| 139 webGestureEvent.type = WebInputEvent::GestureScrollUpdate; |
| 140 webGestureEvent.x = 10; |
| 141 webGestureEvent.y = 10; |
| 142 webGestureEvent.globalX = 10; |
| 143 webGestureEvent.globalY = 10; |
| 144 webGestureEvent.data.scrollUpdate.deltaX = 10; |
| 145 webGestureEvent.data.scrollUpdate.deltaY = 10; |
| 146 |
| 147 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent
); |
| 148 EXPECT_EQ(5, platformGestureBuilder.position().x()); |
| 149 EXPECT_EQ(5, platformGestureBuilder.position().y()); |
| 150 EXPECT_EQ(10, platformGestureBuilder.globalPosition().x()); |
| 151 EXPECT_EQ(10, platformGestureBuilder.globalPosition().y()); |
| 152 EXPECT_EQ(5, platformGestureBuilder.deltaX()); |
| 153 EXPECT_EQ(5, platformGestureBuilder.deltaY()); |
| 154 } |
| 155 |
| 156 { |
| 157 WebGestureEvent webGestureEvent; |
| 158 webGestureEvent.type = WebInputEvent::GestureTap; |
| 159 webGestureEvent.data.tap.width = 10; |
| 160 webGestureEvent.data.tap.height = 10; |
| 161 |
| 162 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent
); |
| 163 EXPECT_EQ(5, platformGestureBuilder.area().width()); |
| 164 EXPECT_EQ(5, platformGestureBuilder.area().height()); |
| 165 } |
| 166 |
| 167 { |
| 168 WebGestureEvent webGestureEvent; |
| 169 webGestureEvent.type = WebInputEvent::GestureTapDown; |
| 170 webGestureEvent.data.tapDown.width = 10; |
| 171 webGestureEvent.data.tapDown.height = 10; |
| 172 |
| 173 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent
); |
| 174 EXPECT_EQ(5, platformGestureBuilder.area().width()); |
| 175 EXPECT_EQ(5, platformGestureBuilder.area().height()); |
| 176 } |
| 177 |
| 178 { |
| 179 WebGestureEvent webGestureEvent; |
| 180 webGestureEvent.type = WebInputEvent::GestureLongPress; |
| 181 webGestureEvent.data.longPress.width = 10; |
| 182 webGestureEvent.data.longPress.height = 10; |
| 183 |
| 184 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent
); |
| 185 EXPECT_EQ(5, platformGestureBuilder.area().width()); |
| 186 EXPECT_EQ(5, platformGestureBuilder.area().height()); |
| 187 } |
| 188 |
| 189 { |
| 190 WebGestureEvent webGestureEvent; |
| 191 webGestureEvent.type = WebInputEvent::GestureTwoFingerTap; |
| 192 webGestureEvent.data.twoFingerTap.firstFingerWidth = 10; |
| 193 webGestureEvent.data.twoFingerTap.firstFingerHeight = 10; |
| 194 |
| 195 PlatformGestureEventBuilder platformGestureBuilder(view, webGestureEvent
); |
| 196 EXPECT_EQ(5, platformGestureBuilder.area().width()); |
| 197 EXPECT_EQ(5, platformGestureBuilder.area().height()); |
| 198 } |
| 199 |
| 200 { |
| 201 WebTouchEvent webTouchEvent; |
| 202 webTouchEvent.type = WebInputEvent::TouchMove; |
| 203 webTouchEvent.touchesLength = 1; |
| 204 webTouchEvent.touches[0].state = WebTouchPoint::StateMoved; |
| 205 webTouchEvent.touches[0].screenPosition.x = 10; |
| 206 webTouchEvent.touches[0].screenPosition.y = 10; |
| 207 webTouchEvent.touches[0].position.x = 10; |
| 208 webTouchEvent.touches[0].position.y = 10; |
| 209 webTouchEvent.touches[0].radiusX = 10; |
| 210 webTouchEvent.touches[0].radiusY = 10; |
| 211 |
| 212 PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent); |
| 213 EXPECT_EQ(10, platformTouchBuilder.touchPoints()[0].screenPos().x()); |
| 214 EXPECT_EQ(10, platformTouchBuilder.touchPoints()[0].screenPos().y()); |
| 215 EXPECT_EQ(5, platformTouchBuilder.touchPoints()[0].pos().x()); |
| 216 EXPECT_EQ(5, platformTouchBuilder.touchPoints()[0].pos().y()); |
| 217 EXPECT_EQ(5, platformTouchBuilder.touchPoints()[0].radiusX()); |
| 218 EXPECT_EQ(5, platformTouchBuilder.touchPoints()[0].radiusY()); |
| 219 } |
| 220 |
| 221 { |
| 222 PlatformMouseEvent platformMouseEvent(IntPoint(10, 10), IntPoint(10, 10)
, LeftButton, PlatformEvent::MouseMoved, 1, false, false, false, false, 0); |
| 223 RefPtr<MouseEvent> mouseEvent = MouseEvent::create(WebCore::eventNames()
.mousemoveEvent, domWindow, platformMouseEvent, 0, document); |
| 224 WebMouseEventBuilder webMouseBuilder(view, docRenderer, *mouseEvent); |
| 225 |
| 226 EXPECT_EQ(20, webMouseBuilder.x); |
| 227 EXPECT_EQ(20, webMouseBuilder.y); |
| 228 EXPECT_EQ(10, webMouseBuilder.globalX); |
| 229 EXPECT_EQ(10, webMouseBuilder.globalY); |
| 230 EXPECT_EQ(20, webMouseBuilder.windowX); |
| 231 EXPECT_EQ(20, webMouseBuilder.windowY); |
| 232 } |
| 233 |
| 234 { |
| 235 PlatformGestureEvent platformGestureEvent(PlatformEvent::GestureScrollUp
date, IntPoint(10, 10), IntPoint(10, 10), 0, IntSize(10, 10), FloatPoint(10, 10)
, false, false, false, false); |
| 236 RefPtr<GestureEvent> gestureEvent = GestureEvent::create(domWindow, plat
formGestureEvent); |
| 237 WebGestureEventBuilder webGestureBuilder(view, docRenderer, *gestureEven
t); |
| 238 |
| 239 EXPECT_EQ(20, webGestureBuilder.x); |
| 240 EXPECT_EQ(20, webGestureBuilder.y); |
| 241 EXPECT_EQ(10, webGestureBuilder.globalX); |
| 242 EXPECT_EQ(10, webGestureBuilder.globalY); |
| 243 EXPECT_EQ(20, webGestureBuilder.data.scrollUpdate.deltaX); |
| 244 EXPECT_EQ(20, webGestureBuilder.data.scrollUpdate.deltaY); |
| 245 } |
| 246 |
| 247 { |
| 248 RefPtr<Touch> touch = Touch::create(webViewImpl->page()->mainFrame(), do
cument.get(), 0, 10, 10, 10, 10, 10, 10, 0, 0); |
| 249 RefPtr<TouchList> touchList = TouchList::create(); |
| 250 touchList->append(touch); |
| 251 RefPtr<TouchEvent> touchEvent = TouchEvent::create(touchList.get(), touc
hList.get(), touchList.get(), WebCore::eventNames().touchmoveEvent, domWindow, 1
0, 10, 10, 10, false, false, false, false); |
| 252 |
| 253 WebTouchEventBuilder webTouchBuilder(view, docRenderer, *touchEvent); |
| 254 ASSERT_EQ(1u, webTouchBuilder.touchesLength); |
| 255 EXPECT_EQ(10, webTouchBuilder.touches[0].screenPosition.x); |
| 256 EXPECT_EQ(10, webTouchBuilder.touches[0].screenPosition.y); |
| 257 EXPECT_EQ(20, webTouchBuilder.touches[0].position.x); |
| 258 EXPECT_EQ(20, webTouchBuilder.touches[0].position.y); |
| 259 EXPECT_EQ(20, webTouchBuilder.touches[0].radiusX); |
| 260 EXPECT_EQ(20, webTouchBuilder.touches[0].radiusY); |
| 261 } |
| 262 |
| 263 webViewImpl->close(); |
| 264 } |
| 265 |
84 } // anonymous namespace | 266 } // anonymous namespace |
OLD | NEW |