| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/BrowserControls.h" |
| 5 #include "core/frame/FrameHost.h" | 6 #include "core/frame/FrameHost.h" |
| 6 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 7 #include "core/frame/RootFrameViewport.h" | 8 #include "core/frame/RootFrameViewport.h" |
| 8 #include "core/frame/TopControls.h" | |
| 9 #include "core/html/HTMLFrameOwnerElement.h" | 9 #include "core/html/HTMLFrameOwnerElement.h" |
| 10 #include "core/layout/LayoutBox.h" | 10 #include "core/layout/LayoutBox.h" |
| 11 #include "core/layout/api/LayoutViewItem.h" | 11 #include "core/layout/api/LayoutViewItem.h" |
| 12 #include "core/layout/compositing/PaintLayerCompositor.h" | 12 #include "core/layout/compositing/PaintLayerCompositor.h" |
| 13 #include "core/page/Page.h" | 13 #include "core/page/Page.h" |
| 14 #include "core/page/scrolling/RootScrollerController.h" | 14 #include "core/page/scrolling/RootScrollerController.h" |
| 15 #include "core/page/scrolling/TopDocumentRootScrollerController.h" | 15 #include "core/page/scrolling/TopDocumentRootScrollerController.h" |
| 16 #include "core/paint/PaintLayerScrollableArea.h" | 16 #include "core/paint/PaintLayerScrollableArea.h" |
| 17 #include "platform/testing/URLTestHelpers.h" | 17 #include "platform/testing/URLTestHelpers.h" |
| 18 #include "platform/testing/UnitTestHelpers.h" | 18 #include "platform/testing/UnitTestHelpers.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 WebCache::clear(); | 51 WebCache::clear(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 WebViewImpl* initialize(const std::string& pageName, | 54 WebViewImpl* initialize(const std::string& pageName, |
| 55 FrameTestHelpers::TestWebViewClient* client) { | 55 FrameTestHelpers::TestWebViewClient* client) { |
| 56 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); | 56 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); |
| 57 | 57 |
| 58 m_helper.initializeAndLoad(m_baseURL + pageName, true, nullptr, client, | 58 m_helper.initializeAndLoad(m_baseURL + pageName, true, nullptr, client, |
| 59 nullptr, &configureSettings); | 59 nullptr, &configureSettings); |
| 60 | 60 |
| 61 // Initialize top controls to be shown. | 61 // Initialize browser controls to be shown. |
| 62 webViewImpl()->resizeWithTopControls(IntSize(400, 400), 50, true); | 62 webViewImpl()->resizeWithBrowserControls(IntSize(400, 400), 50, true); |
| 63 webViewImpl()->topControls().setShownRatio(1); | 63 webViewImpl()->browserControls().setShownRatio(1); |
| 64 | 64 |
| 65 mainFrameView()->updateAllLifecyclePhases(); | 65 mainFrameView()->updateAllLifecyclePhases(); |
| 66 | 66 |
| 67 return webViewImpl(); | 67 return webViewImpl(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 WebViewImpl* initialize(const std::string& pageName) { | 70 WebViewImpl* initialize(const std::string& pageName) { |
| 71 return initialize(pageName, &m_client); | 71 return initialize(pageName, &m_client); |
| 72 } | 72 } |
| 73 | 73 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 WebLocalFrame* mainWebFrame() const { return webViewImpl()->mainFrameImpl(); } | 107 WebLocalFrame* mainWebFrame() const { return webViewImpl()->mainFrameImpl(); } |
| 108 | 108 |
| 109 FrameView* mainFrameView() const { | 109 FrameView* mainFrameView() const { |
| 110 return webViewImpl()->mainFrameImpl()->frame()->view(); | 110 return webViewImpl()->mainFrameImpl()->frame()->view(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 VisualViewport& visualViewport() const { | 113 VisualViewport& visualViewport() const { |
| 114 return frameHost().visualViewport(); | 114 return frameHost().visualViewport(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 TopControls& topControls() const { return frameHost().topControls(); } | 117 BrowserControls& browserControls() const { |
| 118 return frameHost().browserControls(); |
| 119 } |
| 118 | 120 |
| 119 Element* effectiveRootScroller(Document* doc) const { | 121 Element* effectiveRootScroller(Document* doc) const { |
| 120 return doc->rootScrollerController()->effectiveRootScroller(); | 122 return doc->rootScrollerController()->effectiveRootScroller(); |
| 121 } | 123 } |
| 122 | 124 |
| 123 WebGestureEvent generateTouchGestureEvent(WebInputEvent::Type type, | 125 WebGestureEvent generateTouchGestureEvent(WebInputEvent::Type type, |
| 124 int deltaX = 0, | 126 int deltaX = 0, |
| 125 int deltaY = 0) { | 127 int deltaY = 0) { |
| 126 return generateGestureEvent(type, WebGestureDeviceTouchscreen, deltaX, | 128 return generateGestureEvent(type, WebGestureDeviceTouchscreen, deltaX, |
| 127 deltaY); | 129 deltaY); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 mainFrame()->document()->setRootScroller(container, exceptionState); | 190 mainFrame()->document()->setRootScroller(container, exceptionState); |
| 189 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); | 191 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); |
| 190 | 192 |
| 191 // Content is 1000x1000, WebView size is 400x400 so max scroll is 600px. | 193 // Content is 1000x1000, WebView size is 400x400 so max scroll is 600px. |
| 192 double maximumScroll = 600; | 194 double maximumScroll = 600; |
| 193 | 195 |
| 194 webViewImpl()->handleInputEvent( | 196 webViewImpl()->handleInputEvent( |
| 195 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin)); | 197 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin)); |
| 196 | 198 |
| 197 { | 199 { |
| 198 // Scrolling over the #container DIV should cause the top controls to | 200 // Scrolling over the #container DIV should cause the browser controls to |
| 199 // hide. | 201 // hide. |
| 200 EXPECT_FLOAT_EQ(1, topControls().shownRatio()); | 202 EXPECT_FLOAT_EQ(1, browserControls().shownRatio()); |
| 201 webViewImpl()->handleInputEvent(generateTouchGestureEvent( | 203 webViewImpl()->handleInputEvent(generateTouchGestureEvent( |
| 202 WebInputEvent::GestureScrollUpdate, 0, -topControls().height())); | 204 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height())); |
| 203 EXPECT_FLOAT_EQ(0, topControls().shownRatio()); | 205 EXPECT_FLOAT_EQ(0, browserControls().shownRatio()); |
| 204 } | 206 } |
| 205 | 207 |
| 206 { | 208 { |
| 207 // Make sure we're actually scrolling the DIV and not the FrameView. | 209 // Make sure we're actually scrolling the DIV and not the FrameView. |
| 208 webViewImpl()->handleInputEvent( | 210 webViewImpl()->handleInputEvent( |
| 209 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, -100)); | 211 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, -100)); |
| 210 EXPECT_FLOAT_EQ(100, container->scrollTop()); | 212 EXPECT_FLOAT_EQ(100, container->scrollTop()); |
| 211 EXPECT_FLOAT_EQ(0, mainFrameView()->scrollOffset().height()); | 213 EXPECT_FLOAT_EQ(0, mainFrameView()->scrollOffset().height()); |
| 212 } | 214 } |
| 213 | 215 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, -30)); | 251 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, -30)); |
| 250 EXPECT_FLOAT_EQ(maximumScroll, container->scrollTop()); | 252 EXPECT_FLOAT_EQ(maximumScroll, container->scrollTop()); |
| 251 EXPECT_FLOAT_EQ(0, mainFrameView()->scrollOffset().height()); | 253 EXPECT_FLOAT_EQ(0, mainFrameView()->scrollOffset().height()); |
| 252 Mock::VerifyAndClearExpectations(&client); | 254 Mock::VerifyAndClearExpectations(&client); |
| 253 | 255 |
| 254 webViewImpl()->handleInputEvent( | 256 webViewImpl()->handleInputEvent( |
| 255 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd)); | 257 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd)); |
| 256 } | 258 } |
| 257 | 259 |
| 258 { | 260 { |
| 259 // Scrolling up should show the top controls. | 261 // Scrolling up should show the browser controls. |
| 260 webViewImpl()->handleInputEvent( | 262 webViewImpl()->handleInputEvent( |
| 261 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin)); | 263 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin)); |
| 262 | 264 |
| 263 EXPECT_FLOAT_EQ(0, topControls().shownRatio()); | 265 EXPECT_FLOAT_EQ(0, browserControls().shownRatio()); |
| 264 webViewImpl()->handleInputEvent( | 266 webViewImpl()->handleInputEvent( |
| 265 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, 30)); | 267 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, 30)); |
| 266 EXPECT_FLOAT_EQ(0.6, topControls().shownRatio()); | 268 EXPECT_FLOAT_EQ(0.6, browserControls().shownRatio()); |
| 267 | 269 |
| 268 webViewImpl()->handleInputEvent( | 270 webViewImpl()->handleInputEvent( |
| 269 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd)); | 271 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd)); |
| 270 } | 272 } |
| 271 | 273 |
| 272 // Reset manually to avoid lifetime issues with custom WebViewClient. | 274 // Reset manually to avoid lifetime issues with custom WebViewClient. |
| 273 m_helper.reset(); | 275 m_helper.reset(); |
| 274 } | 276 } |
| 275 | 277 |
| 276 // Tests that removing the element that is the root scroller from the DOM tree | 278 // Tests that removing the element that is the root scroller from the DOM tree |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 EXPECT_EQ(mainFrame()->document()->documentElement(), | 927 EXPECT_EQ(mainFrame()->document()->documentElement(), |
| 926 globalController.globalRootScroller()); | 928 globalController.globalRootScroller()); |
| 927 EXPECT_EQ( | 929 EXPECT_EQ( |
| 928 mainFrameView()->layoutViewportScrollableArea()->layerForScrolling(), | 930 mainFrameView()->layoutViewportScrollableArea()->layerForScrolling(), |
| 929 globalController.rootScrollerLayer()); | 931 globalController.rootScrollerLayer()); |
| 930 } | 932 } |
| 931 | 933 |
| 932 } // namespace | 934 } // namespace |
| 933 | 935 |
| 934 } // namespace blink | 936 } // namespace blink |
| OLD | NEW |