OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/frame/VisualViewport.h" | 5 #include "core/frame/VisualViewport.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/frame/BrowserControls.h" | 8 #include "core/frame/BrowserControls.h" |
9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
11 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
12 #include "core/html/HTMLBodyElement.h" | 12 #include "core/html/HTMLBodyElement.h" |
13 #include "core/html/HTMLElement.h" | 13 #include "core/html/HTMLElement.h" |
14 #include "core/input/EventHandler.h" | 14 #include "core/input/EventHandler.h" |
15 #include "core/layout/LayoutObject.h" | 15 #include "core/layout/LayoutObject.h" |
16 #include "core/layout/api/LayoutViewItem.h" | 16 #include "core/layout/api/LayoutViewItem.h" |
17 #include "core/layout/compositing/PaintLayerCompositor.h" | 17 #include "core/layout/compositing/PaintLayerCompositor.h" |
18 #include "core/page/Page.h" | 18 #include "core/page/Page.h" |
19 #include "core/paint/PaintLayer.h" | 19 #include "core/paint/PaintLayer.h" |
20 #include "platform/geometry/DoublePoint.h" | 20 #include "platform/geometry/DoublePoint.h" |
21 #include "platform/geometry/DoubleRect.h" | 21 #include "platform/geometry/DoubleRect.h" |
22 #include "platform/graphics/CompositorElementId.h" | 22 #include "platform/graphics/CompositorElementId.h" |
23 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 23 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
24 #include "platform/testing/URLTestHelpers.h" | 24 #include "platform/testing/URLTestHelpers.h" |
| 25 #include "platform/testing/UnitTestHelpers.h" |
25 #include "public/platform/Platform.h" | 26 #include "public/platform/Platform.h" |
26 #include "public/platform/WebCachePolicy.h" | 27 #include "public/platform/WebCachePolicy.h" |
27 #include "public/platform/WebInputEvent.h" | 28 #include "public/platform/WebInputEvent.h" |
28 #include "public/platform/WebLayerTreeView.h" | 29 #include "public/platform/WebLayerTreeView.h" |
29 #include "public/platform/WebURLLoaderMockFactory.h" | 30 #include "public/platform/WebURLLoaderMockFactory.h" |
30 #include "public/web/WebCache.h" | 31 #include "public/web/WebCache.h" |
31 #include "public/web/WebContextMenuData.h" | 32 #include "public/web/WebContextMenuData.h" |
32 #include "public/web/WebDocument.h" | 33 #include "public/web/WebDocument.h" |
33 #include "public/web/WebFrameClient.h" | 34 #include "public/web/WebFrameClient.h" |
34 #include "public/web/WebScriptSource.h" | 35 #include "public/web/WebScriptSource.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 ::std::ostream& operator<<(::std::ostream& os, const WebContextMenuData& data) { | 97 ::std::ostream& operator<<(::std::ostream& os, const WebContextMenuData& data) { |
97 return os << "Context menu location: [" << data.mousePosition.x << ", " | 98 return os << "Context menu location: [" << data.mousePosition.x << ", " |
98 << data.mousePosition.y << "]"; | 99 << data.mousePosition.y << "]"; |
99 } | 100 } |
100 } | 101 } |
101 | 102 |
102 namespace { | 103 namespace { |
103 | 104 |
104 typedef bool TestParamRootLayerScrolling; | 105 typedef bool TestParamRootLayerScrolling; |
105 class VisualViewportTest | 106 class VisualViewportTest |
106 : public testing::Test, | 107 : public ::testing::Test, |
107 public testing::WithParamInterface<TestParamRootLayerScrolling>, | 108 public ::testing::WithParamInterface<TestParamRootLayerScrolling>, |
108 private ScopedRootLayerScrollingForTest { | 109 private ScopedRootLayerScrollingForTest { |
109 public: | 110 public: |
110 VisualViewportTest() | 111 VisualViewportTest() |
111 : ScopedRootLayerScrollingForTest(GetParam()), | 112 : ScopedRootLayerScrollingForTest(GetParam()), |
112 m_baseURL("http://www.test.com/") {} | 113 m_baseURL("http://www.test.com/") {} |
113 | 114 |
114 void initializeWithDesktopSettings( | 115 void initializeWithDesktopSettings( |
115 void (*overrideSettingsFunc)(WebSettings*) = 0) { | 116 void (*overrideSettingsFunc)(WebSettings*) = 0) { |
116 if (!overrideSettingsFunc) | 117 if (!overrideSettingsFunc) |
117 overrideSettingsFunc = &configureSettings; | 118 overrideSettingsFunc = &configureSettings; |
(...skipping 18 matching lines...) Expand all Loading... |
136 | 137 |
137 void navigateTo(const std::string& url) { | 138 void navigateTo(const std::string& url) { |
138 FrameTestHelpers::loadFrame(webViewImpl()->mainFrame(), url); | 139 FrameTestHelpers::loadFrame(webViewImpl()->mainFrame(), url); |
139 } | 140 } |
140 | 141 |
141 void forceFullCompositingUpdate() { | 142 void forceFullCompositingUpdate() { |
142 webViewImpl()->updateAllLifecyclePhases(); | 143 webViewImpl()->updateAllLifecyclePhases(); |
143 } | 144 } |
144 | 145 |
145 void registerMockedHttpURLLoad(const std::string& fileName) { | 146 void registerMockedHttpURLLoad(const std::string& fileName) { |
146 URLTestHelpers::registerMockedURLFromBaseURL( | 147 URLTestHelpers::registerMockedURLLoadFromBase( |
147 WebString::fromUTF8(m_baseURL.c_str()), | 148 WebString::fromUTF8(m_baseURL), blink::testing::webTestDataPath(), |
148 WebString::fromUTF8(fileName.c_str())); | 149 WebString::fromUTF8(fileName)); |
| 150 } |
| 151 |
| 152 void registerMockedHttpURLLoad(const std::string& url, |
| 153 const std::string& fileName) { |
| 154 URLTestHelpers::registerMockedURLLoad( |
| 155 toKURL(url), |
| 156 blink::testing::webTestDataPath(WebString::fromUTF8(fileName))); |
149 } | 157 } |
150 | 158 |
151 WebLayer* getRootScrollLayer() { | 159 WebLayer* getRootScrollLayer() { |
152 PaintLayerCompositor* compositor = | 160 PaintLayerCompositor* compositor = |
153 frame()->contentLayoutItem().compositor(); | 161 frame()->contentLayoutItem().compositor(); |
154 DCHECK(compositor); | 162 DCHECK(compositor); |
155 DCHECK(compositor->scrollLayer()); | 163 DCHECK(compositor->scrollLayer()); |
156 | 164 |
157 WebLayer* webScrollLayer = compositor->scrollLayer()->platformLayer(); | 165 WebLayer* webScrollLayer = compositor->scrollLayer()->platformLayer(); |
158 return webScrollLayer; | 166 return webScrollLayer; |
(...skipping 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2136 &configureAndroidCompositing); | 2144 &configureAndroidCompositing); |
2137 | 2145 |
2138 int pageWidth = 640; | 2146 int pageWidth = 640; |
2139 int pageHeight = 480; | 2147 int pageHeight = 480; |
2140 float browserControlsHeight = 50.0f; | 2148 float browserControlsHeight = 50.0f; |
2141 int smallestHeight = pageHeight - browserControlsHeight; | 2149 int smallestHeight = pageHeight - browserControlsHeight; |
2142 | 2150 |
2143 webViewImpl->resizeWithBrowserControls(WebSize(pageWidth, pageHeight), | 2151 webViewImpl->resizeWithBrowserControls(WebSize(pageWidth, pageHeight), |
2144 browserControlsHeight, false); | 2152 browserControlsHeight, false); |
2145 | 2153 |
2146 URLTestHelpers::registerMockedURLLoad(toKURL("http://example.com/foo.png"), | 2154 registerMockedHttpURLLoad("http://example.com/foo.png", "white-1x1.png"); |
2147 "white-1x1.png"); | |
2148 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); | 2155 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); |
2149 FrameTestHelpers::loadHTMLString(webViewImpl->mainFrame(), | 2156 FrameTestHelpers::loadHTMLString(webViewImpl->mainFrame(), |
2150 "<!DOCTYPE html>" | 2157 "<!DOCTYPE html>" |
2151 "<style>" | 2158 "<style>" |
2152 " body {" | 2159 " body {" |
2153 " background: url('foo.png');" | 2160 " background: url('foo.png');" |
2154 " background-attachment: fixed;" | 2161 " background-attachment: fixed;" |
2155 " background-size: cover;" | 2162 " background-size: cover;" |
2156 " background-repeat: no-repeat;" | 2163 " background-repeat: no-repeat;" |
2157 " }" | 2164 " }" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2219 true, nullptr, nullptr, nullptr, &configureAndroidNonCompositing); | 2226 true, nullptr, nullptr, nullptr, &configureAndroidNonCompositing); |
2220 | 2227 |
2221 int pageWidth = 640; | 2228 int pageWidth = 640; |
2222 int pageHeight = 480; | 2229 int pageHeight = 480; |
2223 float browserControlsHeight = 50.0f; | 2230 float browserControlsHeight = 50.0f; |
2224 int smallestHeight = pageHeight - browserControlsHeight; | 2231 int smallestHeight = pageHeight - browserControlsHeight; |
2225 | 2232 |
2226 webViewImpl->resizeWithBrowserControls(WebSize(pageWidth, pageHeight), | 2233 webViewImpl->resizeWithBrowserControls(WebSize(pageWidth, pageHeight), |
2227 browserControlsHeight, false); | 2234 browserControlsHeight, false); |
2228 | 2235 |
2229 URLTestHelpers::registerMockedURLLoad(toKURL("http://example.com/foo.png"), | 2236 registerMockedHttpURLLoad("http://example.com/foo.png", "white-1x1.png"); |
2230 "white-1x1.png"); | |
2231 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); | 2237 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); |
2232 FrameTestHelpers::loadHTMLString(webViewImpl->mainFrame(), | 2238 FrameTestHelpers::loadHTMLString(webViewImpl->mainFrame(), |
2233 "<!DOCTYPE html>" | 2239 "<!DOCTYPE html>" |
2234 "<style>" | 2240 "<style>" |
2235 " body {" | 2241 " body {" |
2236 " margin: 0px;" | 2242 " margin: 0px;" |
2237 " background: url('foo.png');" | 2243 " background: url('foo.png');" |
2238 " background-attachment: fixed;" | 2244 " background-attachment: fixed;" |
2239 " background-size: cover;" | 2245 " background-size: cover;" |
2240 " background-repeat: no-repeat;" | 2246 " background-repeat: no-repeat;" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2327 &configureAndroidCompositing); | 2333 &configureAndroidCompositing); |
2328 | 2334 |
2329 int pageWidth = 640; | 2335 int pageWidth = 640; |
2330 int pageHeight = 480; | 2336 int pageHeight = 480; |
2331 float browserControlsHeight = 50.0f; | 2337 float browserControlsHeight = 50.0f; |
2332 int smallestHeight = pageHeight - browserControlsHeight; | 2338 int smallestHeight = pageHeight - browserControlsHeight; |
2333 | 2339 |
2334 webViewImpl->resizeWithBrowserControls(WebSize(pageWidth, pageHeight), | 2340 webViewImpl->resizeWithBrowserControls(WebSize(pageWidth, pageHeight), |
2335 browserControlsHeight, false); | 2341 browserControlsHeight, false); |
2336 | 2342 |
2337 URLTestHelpers::registerMockedURLLoad(toKURL("http://example.com/foo.png"), | 2343 registerMockedHttpURLLoad("http://example.com/foo.png", "white-1x1.png"); |
2338 "white-1x1.png"); | |
2339 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); | 2344 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); |
2340 // This time the background is the default attachment. | 2345 // This time the background is the default attachment. |
2341 FrameTestHelpers::loadHTMLString(webViewImpl->mainFrame(), | 2346 FrameTestHelpers::loadHTMLString(webViewImpl->mainFrame(), |
2342 "<!DOCTYPE html>" | 2347 "<!DOCTYPE html>" |
2343 "<style>" | 2348 "<style>" |
2344 " body {" | 2349 " body {" |
2345 " margin: 0px;" | 2350 " margin: 0px;" |
2346 " background: url('foo.png');" | 2351 " background: url('foo.png');" |
2347 " background-size: cover;" | 2352 " background-size: cover;" |
2348 " background-repeat: no-repeat;" | 2353 " background-repeat: no-repeat;" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2467 " body {" | 2472 " body {" |
2468 " margin: 0px;" | 2473 " margin: 0px;" |
2469 " }" | 2474 " }" |
2470 " div { height:110vh; width: 110vw; }" | 2475 " div { height:110vh; width: 110vw; }" |
2471 "</style>" | 2476 "</style>" |
2472 "<div></div>", | 2477 "<div></div>", |
2473 baseURL); | 2478 baseURL); |
2474 } | 2479 } |
2475 | 2480 |
2476 } // namespace | 2481 } // namespace |
OLD | NEW |