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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "WebFrame.h" | 32 #include "WebFrame.h" |
33 #include "WebFrameClient.h" | 33 #include "WebFrameClient.h" |
34 #include "WebFrameImpl.h" | 34 #include "WebFrameImpl.h" |
35 #include "WebInputEvent.h" | 35 #include "WebInputEvent.h" |
36 #include "WebInputEventConversion.h" | 36 #include "WebInputEventConversion.h" |
37 #include "WebViewClient.h" | 37 #include "WebViewClient.h" |
38 #include "WebViewImpl.h" | 38 #include "WebViewImpl.h" |
39 #include "bindings/v8/ExceptionStatePlaceholder.h" | 39 #include "bindings/v8/ExceptionStatePlaceholder.h" |
40 #include "core/dom/Node.h" | 40 #include "core/dom/Node.h" |
41 #include "core/page/FrameView.h" | 41 #include "core/page/FrameView.h" |
| 42 #include "core/page/TouchDisambiguation.h" |
42 #include "core/platform/graphics/IntRect.h" | 43 #include "core/platform/graphics/IntRect.h" |
43 #include "public/platform/Platform.h" | 44 #include "public/platform/Platform.h" |
44 #include "public/platform/WebContentLayer.h" | 45 #include "public/platform/WebContentLayer.h" |
45 #include "public/platform/WebFloatPoint.h" | 46 #include "public/platform/WebFloatPoint.h" |
46 #include "public/platform/WebSize.h" | 47 #include "public/platform/WebSize.h" |
47 #include "public/platform/WebUnitTestSupport.h" | 48 #include "public/platform/WebUnitTestSupport.h" |
48 #include "wtf/PassOwnPtr.h" | 49 #include "wtf/PassOwnPtr.h" |
49 | 50 |
50 | 51 |
51 using namespace WebKit; | 52 using namespace WebKit; |
(...skipping 30 matching lines...) Expand all Loading... |
82 { | 83 { |
83 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); | 84 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
84 EXPECT_FALSE(webViewImpl->bestTapNode(platformEvent)); | 85 EXPECT_FALSE(webViewImpl->bestTapNode(platformEvent)); |
85 } | 86 } |
86 | 87 |
87 touchEvent.y = 20; | 88 touchEvent.y = 20; |
88 // Shouldn't crash. | 89 // Shouldn't crash. |
89 | 90 |
90 { | 91 { |
91 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); | 92 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
92 webViewImpl->enableTapHighlight(platformEvent); | 93 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
93 } | 94 } |
94 | 95 |
95 EXPECT_TRUE(webViewImpl->linkHighlight()); | 96 EXPECT_TRUE(webViewImpl->linkHighlight(0)); |
96 EXPECT_TRUE(webViewImpl->linkHighlight()->contentLayer()); | 97 EXPECT_TRUE(webViewImpl->linkHighlight(0)->contentLayer()); |
97 EXPECT_TRUE(webViewImpl->linkHighlight()->clipLayer()); | 98 EXPECT_TRUE(webViewImpl->linkHighlight(0)->clipLayer()); |
98 | 99 |
99 // Find a target inside a scrollable div | 100 // Find a target inside a scrollable div |
100 | 101 |
101 touchEvent.y = 100; | 102 touchEvent.y = 100; |
102 { | 103 { |
103 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); | 104 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
104 webViewImpl->enableTapHighlight(platformEvent); | 105 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
105 } | 106 } |
106 | 107 |
107 ASSERT_TRUE(webViewImpl->linkHighlight()); | 108 ASSERT_TRUE(webViewImpl->linkHighlight(0)); |
108 | 109 |
109 // Don't highlight if no "hand cursor" | 110 // Don't highlight if no "hand cursor" |
110 touchEvent.y = 220; // An A-link with cross-hair cursor. | 111 touchEvent.y = 220; // An A-link with cross-hair cursor. |
111 { | 112 { |
112 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); | 113 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
113 webViewImpl->enableTapHighlight(platformEvent); | 114 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
114 } | 115 } |
115 ASSERT_FALSE(webViewImpl->linkHighlight()); | 116 ASSERT_EQ(0U, webViewImpl->numLinkHighlights()); |
116 | 117 |
117 touchEvent.y = 260; // A text input box. | 118 touchEvent.y = 260; // A text input box. |
118 { | 119 { |
119 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); | 120 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->
frameView(), touchEvent); |
120 webViewImpl->enableTapHighlight(platformEvent); | 121 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
121 } | 122 } |
122 ASSERT_FALSE(webViewImpl->linkHighlight()); | 123 ASSERT_EQ(0U, webViewImpl->numLinkHighlights()); |
123 | 124 |
124 webViewImpl->close(); | 125 webViewImpl->close(); |
125 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 126 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
126 } | 127 } |
127 | 128 |
128 class FakeWebFrameClient : public WebFrameClient { | 129 class FakeWebFrameClient : public WebFrameClient { |
129 // To make the destructor public. | 130 // To make the destructor public. |
130 }; | 131 }; |
131 | 132 |
132 class FakeCompositingWebViewClient : public WebViewClient { | 133 class FakeCompositingWebViewClient : public WebViewClient { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 174 |
174 WebGestureEvent touchEvent; | 175 WebGestureEvent touchEvent; |
175 touchEvent.type = WebInputEvent::GestureTapDown; | 176 touchEvent.type = WebInputEvent::GestureTapDown; |
176 touchEvent.x = 20; | 177 touchEvent.x = 20; |
177 touchEvent.y = 20; | 178 touchEvent.y = 20; |
178 | 179 |
179 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->fram
eView(), touchEvent); | 180 PlatformGestureEventBuilder platformEvent(webViewImpl->mainFrameImpl()->fram
eView(), touchEvent); |
180 Node* touchNode = webViewImpl->bestTapNode(platformEvent); | 181 Node* touchNode = webViewImpl->bestTapNode(platformEvent); |
181 ASSERT_TRUE(touchNode); | 182 ASSERT_TRUE(touchNode); |
182 | 183 |
183 webViewImpl->enableTapHighlight(platformEvent); | 184 webViewImpl->enableTapHighlightAtPoint(platformEvent); |
184 ASSERT_TRUE(webViewImpl->linkHighlight()); | 185 ASSERT_TRUE(webViewImpl->linkHighlight(0)); |
185 | 186 |
186 GraphicsLayer* highlightLayer = webViewImpl->linkHighlight()->currentGraphic
sLayerForTesting(); | 187 GraphicsLayer* highlightLayer = webViewImpl->linkHighlight(0)->currentGraphi
csLayerForTesting(); |
187 ASSERT_TRUE(highlightLayer); | 188 ASSERT_TRUE(highlightLayer); |
188 EXPECT_TRUE(highlightLayer->linkHighlight()); | 189 EXPECT_TRUE(highlightLayer->linkHighlight(0)); |
189 | 190 |
190 touchNode->remove(IGNORE_EXCEPTION); | 191 touchNode->remove(IGNORE_EXCEPTION); |
191 webViewImpl->layout(); | 192 webViewImpl->layout(); |
192 EXPECT_FALSE(highlightLayer->linkHighlight()); | 193 ASSERT_EQ(0U, highlightLayer->numLinkHighlights()); |
193 | 194 |
194 webViewImpl->close(); | 195 webViewImpl->close(); |
195 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 196 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 197 } |
| 198 |
| 199 TEST(LinkHighlightTest, multipleHighlights) |
| 200 { |
| 201 const std::string baseURL("http://www.test.com/"); |
| 202 const std::string fileName("test_touch_link_highlight.html"); |
| 203 |
| 204 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_s
tr()), WebString::fromUTF8("test_touch_link_highlight.html")); |
| 205 WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebViewAndL
oad(baseURL + fileName, true, 0, compositingWebViewClient())); |
| 206 |
| 207 int pageWidth = 640; |
| 208 int pageHeight = 480; |
| 209 webViewImpl->resize(WebSize(pageWidth, pageHeight)); |
| 210 webViewImpl->layout(); |
| 211 |
| 212 WebGestureEvent touchEvent; |
| 213 touchEvent.x = 50; |
| 214 touchEvent.y = 310; |
| 215 touchEvent.data.tap.width = 30; |
| 216 touchEvent.data.tap.height = 30; |
| 217 |
| 218 Vector<IntRect> goodTargets; |
| 219 Vector<Node*> highlightNodes; |
| 220 IntRect boundingBox(touchEvent.x - touchEvent.data.tap.width / 2, touchEvent
.y - touchEvent.data.tap.height / 2, touchEvent.data.tap.width, touchEvent.data.
tap.height); |
| 221 findGoodTouchTargets(boundingBox, webViewImpl->mainFrameImpl()->frame(), goo
dTargets, highlightNodes); |
| 222 |
| 223 webViewImpl->enableTapHighlights(highlightNodes); |
| 224 EXPECT_EQ(2U, webViewImpl->numLinkHighlights()); |
| 225 |
| 226 webViewImpl->close(); |
| 227 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
196 } | 228 } |
197 | 229 |
198 } // namespace | 230 } // namespace |
OLD | NEW |