From 835268c26a1f84e944b70d69703a54c4cb50bc5b Mon Sep 17 00:00:00 2001 From: ymalik Date: Mon, 22 Feb 2016 08:28:12 -0800 Subject: Reverting changes that made window.scroll properties relative to the layout viewport. Reason for revert: Broke a bunch of sites that relied on visual viewport coordinates (see www.crbug.com/571297). Reverting temporary until a new api that provides visual viewport coordinates is made available to developers. Revert "Make window.scroll properties relative to the layout viewport by default." This reverts commit f75faf53de4a5c59269143b6edbfc6dc40c7fb33. Revert "Remove plumbing for the inert-visual-viewport flag." This reverts commit 58d42ae1d6690a9f625e23f160b346e9cebeab01. TBR=avi@chromium.org,kenrb@chromium.org BUG=571297 Review URL: https://codereview.chromium.org/1712743002 Cr-Commit-Position: refs/heads/master@{#376742} --- chrome/app/generated_resources.grd | 6 + chrome/browser/about_flags.cc | 5 + .../renderer_host/render_process_host_impl.cc | 1 + .../browser/renderer_host/render_view_host_impl.cc | 3 + content/public/common/common_param_traits_macros.h | 1 + content/public/common/content_switches.cc | 3 + content/public/common/content_switches.h | 1 + content/public/common/web_preferences.cc | 1 + content/public/common/web_preferences.h | 1 + content/renderer/render_view_impl.cc | 2 + .../window-scaled-viewport-properties-expected.txt | 68 ++++----- .../Window/window-scaled-viewport-properties.html | 158 ++++++++++++--------- .../dom/window-inner-size-scaling-expected.txt | 11 ++ .../fast/dom/window-inner-size-scaling.html | 16 +++ .../repaint/fixed-right-bottom-in-page-scale.html | 3 +- ...-viewport-scroll-no-onscroll-event-expected.txt | 12 -- .../visual-viewport-scroll-no-onscroll-event.html | 65 --------- third_party/WebKit/Source/core/frame/Settings.in | 2 +- .../WebKit/Source/core/testing/DummyPageHolder.cpp | 4 +- third_party/WebKit/Source/web/WebSettingsImpl.cpp | 5 + third_party/WebKit/Source/web/WebSettingsImpl.h | 1 + .../WebKit/Source/web/tests/VisualViewportTest.cpp | 136 ++++++++++++++++++ third_party/WebKit/public/web/WebSettings.h | 1 + 23 files changed, 314 insertions(+), 192 deletions(-) create mode 100644 third_party/WebKit/LayoutTests/fast/dom/window-inner-size-scaling-expected.txt create mode 100644 third_party/WebKit/LayoutTests/fast/dom/window-inner-size-scaling.html delete mode 100644 third_party/WebKit/LayoutTests/fast/scroll-behavior/visual-viewport-scroll-no-onscroll-event-expected.txt delete mode 100644 third_party/WebKit/LayoutTests/fast/scroll-behavior/visual-viewport-scroll-no-onscroll-event.html diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 6b49956..74f6cb6 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -5330,6 +5330,12 @@ Keep your key file in a safe place. You will need it to create new versions of y Overrides the built-in software rendering list and enables GPU-acceleration on unsupported system configurations. + + Inert visual viewport. + + + Experiment to have all APIs reflect the layout viewport. This will make window.scroll properties relative to the layout viewport. + Threaded compositing diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 8113fcc..2a7e586 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -1307,6 +1307,11 @@ const FeatureEntry kFeatureEntries[] = { IDS_FLAGS_SETTINGS_WINDOW_DESCRIPTION, kOsDesktop, ENABLE_DISABLE_VALUE_TYPE(switches::kEnableSettingsWindow, switches::kDisableSettingsWindow)}, + {"inert-visual-viewport", + IDS_FLAGS_INERT_VISUAL_VIEWPORT_NAME, + IDS_FLAGS_INERT_VISUAL_VIEWPORT_DESCRIPTION, + kOsAll, + SINGLE_VALUE_TYPE(switches::kInertVisualViewport)}, #if defined(OS_MACOSX) {"enable-save-password-bubble", IDS_FLAGS_SAVE_PASSWORD_BUBBLE_NAME, IDS_FLAGS_SAVE_PASSWORD_BUBBLE_DESCRIPTION, kOsMac, diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 2c36b9d..2885ae5 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -1478,6 +1478,7 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( switches::kForceDisplayList2dCanvas, switches::kForceOverlayFullscreenVideo, switches::kFullMemoryCrashReport, + switches::kInertVisualViewport, switches::kIPCConnectionTimeout, switches::kJavaScriptFlags, switches::kLoggingLevel, diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index 5e36080..01dc162 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -441,6 +441,9 @@ WebPreferences RenderViewHostImpl::ComputeWebkitPrefs() { atoi(command_line.GetSwitchValueASCII( switches::kAcceleratedCanvas2dMSAASampleCount).c_str()); + prefs.inert_visual_viewport = + command_line.HasSwitch(switches::kInertVisualViewport); + prefs.pinch_overlay_scrollbar_thickness = 10; prefs.use_solid_color_scrollbars = ui::IsOverlayScrollbarEnabled(); diff --git a/content/public/common/common_param_traits_macros.h b/content/public/common/common_param_traits_macros.h index 25a82c0..e3a1dcf 100644 --- a/content/public/common/common_param_traits_macros.h +++ b/content/public/common/common_param_traits_macros.h @@ -145,6 +145,7 @@ IPC_STRUCT_TRAITS_BEGIN(content::WebPreferences) IPC_STRUCT_TRAITS_MEMBER(webaudio_enabled) IPC_STRUCT_TRAITS_MEMBER(experimental_webgl_enabled) IPC_STRUCT_TRAITS_MEMBER(pepper_3d_enabled) + IPC_STRUCT_TRAITS_MEMBER(inert_visual_viewport) IPC_STRUCT_TRAITS_MEMBER(pinch_overlay_scrollbar_thickness) IPC_STRUCT_TRAITS_MEMBER(use_solid_color_scrollbars) IPC_STRUCT_TRAITS_MEMBER(flash_3d_enabled) diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index bfc08b6..f4749f7 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -594,6 +594,9 @@ const char kIgnoreCertificateErrors[] = "ignore-certificate-errors"; // Ignores GPU blacklist. const char kIgnoreGpuBlacklist[] = "ignore-gpu-blacklist"; +// Makes all APIs reflect the layout viewport. +const char kInertVisualViewport[] = "inert-visual-viewport"; + // Run the GPU process as a thread in the browser process. const char kInProcessGPU[] = "in-process-gpu"; diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index f2cb6fd..e9b4619 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -174,6 +174,7 @@ extern const char kGpuVendorID[]; CONTENT_EXPORT extern const char kHostResolverRules[]; CONTENT_EXPORT extern const char kIgnoreCertificateErrors[]; CONTENT_EXPORT extern const char kIgnoreGpuBlacklist[]; +CONTENT_EXPORT extern const char kInertVisualViewport[]; CONTENT_EXPORT extern const char kInProcessGPU[]; CONTENT_EXPORT extern const char kIPCConnectionTimeout[]; CONTENT_EXPORT extern const char kJavaScriptFlags[]; diff --git a/content/public/common/web_preferences.cc b/content/public/common/web_preferences.cc index 5f6502a..86c522a 100644 --- a/content/public/common/web_preferences.cc +++ b/content/public/common/web_preferences.cc @@ -160,6 +160,7 @@ WebPreferences::WebPreferences() use_solid_color_scrollbars(false), navigate_on_drag_drop(true), v8_cache_options(V8_CACHE_OPTIONS_DEFAULT), + inert_visual_viewport(false), cookie_enabled(true), pepper_accelerated_video_decode_enabled(false), animation_policy(IMAGE_ANIMATION_POLICY_ALLOWED), diff --git a/content/public/common/web_preferences.h b/content/public/common/web_preferences.h index 8b6e0565..fcd58f5 100644 --- a/content/public/common/web_preferences.h +++ b/content/public/common/web_preferences.h @@ -176,6 +176,7 @@ struct CONTENT_EXPORT WebPreferences { bool use_solid_color_scrollbars; bool navigate_on_drag_drop; V8CacheOptions v8_cache_options; + bool inert_visual_viewport; // This flags corresponds to a Page's Settings' setCookieEnabled state. It // only controls whether or not the "document.cookie" field is properly diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index ee8b839..eb0b33d 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -1054,6 +1054,8 @@ void RenderView::ApplyWebPreferences(const WebPreferences& prefs, settings->setSupportsMultipleWindows(prefs.supports_multiple_windows); + settings->setInertVisualViewport(prefs.inert_visual_viewport); + settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled); settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled); diff --git a/third_party/WebKit/LayoutTests/fast/dom/Window/window-scaled-viewport-properties-expected.txt b/third_party/WebKit/LayoutTests/fast/dom/Window/window-scaled-viewport-properties-expected.txt index 33e001e7..6550e91 100644 --- a/third_party/WebKit/LayoutTests/fast/dom/Window/window-scaled-viewport-properties-expected.txt +++ b/third_party/WebKit/LayoutTests/fast/dom/Window/window-scaled-viewport-properties-expected.txt @@ -3,41 +3,25 @@ This test makes sure the window properties related to the viewport remain correc On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". -===Initial Scale=== +===Unscaled=== -PASS window.innerWidth is 1600 -PASS window.innerHeight is 1200 -PASS internals.visualViewportWidth() is 1600 -PASS internals.visualViewportHeight() is 1200 +PASS window.innerWidth is 800 +PASS window.innerHeight is 600 ===Pinch Zoom in to 2X=== -PASS window.innerWidth is 1600 -PASS window.innerHeight is 1200 +PASS window.innerWidth is 400 +PASS window.innerHeight is 300 PASS window.scrollX is 0 PASS window.scrollY is 0 -PASS internals.visualViewportWidth() is 400 -PASS internals.visualViewportHeight() is 300 -===ScrollBy=== -PASS window.scrollX is 100 -PASS window.scrollY is 200 -PASS internals.visualViewportScrollX() is 100 -PASS internals.visualViewportScrollY() is 200 -PASS window.scrollX is 400 -PASS window.scrollY is 300 -PASS internals.visualViewportScrollX() is 400 -PASS internals.visualViewportScrollY() is 300 +PASS window.scrollX is 10 +PASS window.scrollY is 20 +PASS window.scrollX is 1600 +PASS window.scrollY is 1200 PASS window.scrollX is 0 PASS window.scrollY is 0 -===ScrollTo=== -PASS window.scrollX is 100 -PASS window.scrollY is 200 -PASS internals.visualViewportScrollX() is 100 -PASS internals.visualViewportScrollY() is 200 -PASS window.scrollX is 400 -PASS window.scrollY is 300 -PASS internals.visualViewportScrollX() is 400 -PASS internals.visualViewportScrollY() is 300 +PASS window.scrollX is 1600 +PASS window.scrollY is 1200 PASS window.scrollX is 0 PASS window.scrollY is 0 @@ -47,30 +31,28 @@ PASS window.innerWidth is 1600 PASS window.innerHeight is 1200 PASS window.scrollX is 0 PASS window.scrollY is 0 -PASS internals.visualViewportWidth() is 1600 -PASS internals.visualViewportHeight() is 1200 -===ScrollBy=== -PASS window.scrollX is 100 -PASS window.scrollY is 200 -PASS internals.visualViewportScrollX() is 100 -PASS internals.visualViewportScrollY() is 200 +PASS window.scrollX is 10 +PASS window.scrollY is 20 PASS window.scrollX is 400 PASS window.scrollY is 300 -PASS internals.visualViewportScrollX() is 400 -PASS internals.visualViewportScrollY() is 300 PASS window.scrollX is 0 PASS window.scrollY is 0 -===ScrollTo=== -PASS window.scrollX is 100 -PASS window.scrollY is 200 -PASS internals.visualViewportScrollX() is 100 -PASS internals.visualViewportScrollY() is 200 PASS window.scrollX is 400 PASS window.scrollY is 300 -PASS internals.visualViewportScrollX() is 400 -PASS internals.visualViewportScrollY() is 300 PASS window.scrollX is 0 PASS window.scrollY is 0 + +===Test OnScroll=== + +PASS window.innerWidth is 800 +PASS window.innerHeight is 600 +PASS window.scrollX is 0 +PASS window.scrollY is 0 +PASS OnScroll called for scroll #1 +PASS OnScroll called for scroll #2 +PASS OnScroll called for scroll #3 +PASS OnScroll called for scroll #4 + PASS successfullyParsed is true TEST COMPLETE diff --git a/third_party/WebKit/LayoutTests/fast/dom/Window/window-scaled-viewport-properties.html b/third_party/WebKit/LayoutTests/fast/dom/Window/window-scaled-viewport-properties.html index 36b0d5a..790c0bf 100644 --- a/third_party/WebKit/LayoutTests/fast/dom/Window/window-scaled-viewport-properties.html +++ b/third_party/WebKit/LayoutTests/fast/dom/Window/window-scaled-viewport-properties.html @@ -1,12 +1,9 @@ - + + + diff --git a/third_party/WebKit/LayoutTests/fast/repaint/fixed-right-bottom-in-page-scale.html b/third_party/WebKit/LayoutTests/fast/repaint/fixed-right-bottom-in-page-scale.html index 2b1b8d1..42fd11d 100644 --- a/third_party/WebKit/LayoutTests/fast/repaint/fixed-right-bottom-in-page-scale.html +++ b/third_party/WebKit/LayoutTests/fast/repaint/fixed-right-bottom-in-page-scale.html @@ -11,8 +11,7 @@ function scroll() { // Fully scroll to bring the fixed pos rect into view. - eventSender.mouseMoveTo(100, 100); - eventSender.continuousMouseScrollBy(-500, -1700); + window.scrollTo(500, 1700); } function scaleWithEventSender() { diff --git a/third_party/WebKit/LayoutTests/fast/scroll-behavior/visual-viewport-scroll-no-onscroll-event-expected.txt b/third_party/WebKit/LayoutTests/fast/scroll-behavior/visual-viewport-scroll-no-onscroll-event-expected.txt deleted file mode 100644 index a54d795..0000000 --- a/third_party/WebKit/LayoutTests/fast/scroll-behavior/visual-viewport-scroll-no-onscroll-event-expected.txt +++ /dev/null @@ -1,12 +0,0 @@ -This test ensures that scrolling the visual viewport doesn't trigger an onscroll event. - -On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". - - -OnScroll called for scroll #1 -PASS numScrollsReceived is 1 -PASS numScrollsReceived is 1 -PASS successfullyParsed is true - -TEST COMPLETE - diff --git a/third_party/WebKit/LayoutTests/fast/scroll-behavior/visual-viewport-scroll-no-onscroll-event.html b/third_party/WebKit/LayoutTests/fast/scroll-behavior/visual-viewport-scroll-no-onscroll-event.html deleted file mode 100644 index d10ea60..0000000 --- a/third_party/WebKit/LayoutTests/fast/scroll-behavior/visual-viewport-scroll-no-onscroll-event.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - -
diff --git a/third_party/WebKit/Source/core/frame/Settings.in b/third_party/WebKit/Source/core/frame/Settings.in index f622dfa..ca5ce32 100644 --- a/third_party/WebKit/Source/core/frame/Settings.in +++ b/third_party/WebKit/Source/core/frame/Settings.in @@ -235,7 +235,7 @@ pinchOverlayScrollbarThickness type=int, initial=0 # Experiment to have all APIs reflect the layout viewport. # crbug.com/489206 tracks the experiment. -inertVisualViewport initial=true +inertVisualViewport initial=false # The rubber-band overscroll effect is implemented in Blink and is being moved # to the compositor thread. This will be set to true and eventually removed. diff --git a/third_party/WebKit/Source/core/testing/DummyPageHolder.cpp b/third_party/WebKit/Source/core/testing/DummyPageHolder.cpp index 9a6696d..2e9b253 100644 --- a/third_party/WebKit/Source/core/testing/DummyPageHolder.cpp +++ b/third_party/WebKit/Source/core/testing/DummyPageHolder.cpp @@ -30,8 +30,9 @@ #include "core/testing/DummyPageHolder.h" -#include "core/frame/LocalDOMWindow.h" +#include "core/frame/FrameHost.h" #include "core/frame/FrameView.h" +#include "core/frame/LocalDOMWindow.h" #include "core/frame/LocalFrame.h" #include "core/frame/Settings.h" #include "core/loader/EmptyClients.h" @@ -82,6 +83,7 @@ DummyPageHolder::DummyPageHolder( m_frame = LocalFrame::create(m_frameLoaderClient.get(), &m_page->frameHost(), 0); m_frame->setView(FrameView::create(m_frame.get(), initialViewSize)); + m_frame->view()->page()->frameHost().visualViewport().setSize(initialViewSize); m_frame->init(); } diff --git a/third_party/WebKit/Source/web/WebSettingsImpl.cpp b/third_party/WebKit/Source/web/WebSettingsImpl.cpp index a7e348c..2a36fbc 100644 --- a/third_party/WebKit/Source/web/WebSettingsImpl.cpp +++ b/third_party/WebKit/Source/web/WebSettingsImpl.cpp @@ -183,6 +183,11 @@ void WebSettingsImpl::setInlineTextBoxAccessibilityEnabled(bool enabled) m_settings->setInlineTextBoxAccessibilityEnabled(enabled); } +void WebSettingsImpl::setInertVisualViewport(bool enabled) +{ + m_settings->setInertVisualViewport(enabled); +} + void WebSettingsImpl::setDeviceScaleAdjustment(float deviceScaleAdjustment) { m_devToolsEmulator->setDeviceScaleAdjustment(deviceScaleAdjustment); diff --git a/third_party/WebKit/Source/web/WebSettingsImpl.h b/third_party/WebKit/Source/web/WebSettingsImpl.h index 1708e83..3748748 100644 --- a/third_party/WebKit/Source/web/WebSettingsImpl.h +++ b/third_party/WebKit/Source/web/WebSettingsImpl.h @@ -103,6 +103,7 @@ public: void setImageAnimationPolicy(ImageAnimationPolicy) override; void setImagesEnabled(bool) override; void setInlineTextBoxAccessibilityEnabled(bool) override; + void setInertVisualViewport(bool) override; void setJavaScriptCanAccessClipboard(bool) override; void setJavaScriptCanOpenWindowsAutomatically(bool) override; void setJavaScriptEnabled(bool) override; diff --git a/third_party/WebKit/Source/web/tests/VisualViewportTest.cpp b/third_party/WebKit/Source/web/tests/VisualViewportTest.cpp index 2ec4ea5..14fea8c 100644 --- a/third_party/WebKit/Source/web/tests/VisualViewportTest.cpp +++ b/third_party/WebKit/Source/web/tests/VisualViewportTest.cpp @@ -1122,6 +1122,64 @@ MAYBE_TEST_P(TestClientNotifiedOfScrollEvents) webViewImpl()->mainFrameImpl()->setClient(oldClient); } +// Tests that calling scroll into view on a visible element doesn cause +// a scroll due to a fractional offset. Bug crbug.com/463356. +TEST_P(ParameterizedVisualViewportTest, ScrollIntoViewFractionalOffset) +{ + initializeWithAndroidSettings(); + + webViewImpl()->resize(IntSize(1000, 1000)); + + registerMockedHttpURLLoad("scroll-into-view.html"); + navigateTo(m_baseURL + "scroll-into-view.html"); + + FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); + ScrollableArea* layoutViewportScrollableArea = frameView.layoutViewportScrollableArea(); + VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport(); + Element* inputBox = frame()->document()->getElementById("box"); + + webViewImpl()->setPageScaleFactor(2); + + // The element is already in the view so the scrollIntoView shouldn't move + // the viewport at all. + webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.25f, 100.25f)); + layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.75), ProgrammaticScroll); + inputBox->scrollIntoViewIfNeeded(false); + + EXPECT_POINT_EQ(DoublePoint(0, 900.75), layoutViewportScrollableArea->scrollPositionDouble()); + EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location()); + + // Change the fractional part of the frameview to one that would round down. + layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.125), ProgrammaticScroll); + inputBox->scrollIntoViewIfNeeded(false); + + EXPECT_POINT_EQ(DoublePoint(0, 900.125), layoutViewportScrollableArea->scrollPositionDouble()); + EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location()); + + // Repeat both tests above with the visual viewport at a high fractional. + webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.875f, 100.875f)); + layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.75), ProgrammaticScroll); + inputBox->scrollIntoViewIfNeeded(false); + + EXPECT_POINT_EQ(DoublePoint(0, 900.75), layoutViewportScrollableArea->scrollPositionDouble()); + EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location()); + + // Change the fractional part of the frameview to one that would round down. + layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.125), ProgrammaticScroll); + inputBox->scrollIntoViewIfNeeded(false); + + EXPECT_POINT_EQ(DoublePoint(0, 900.125), layoutViewportScrollableArea->scrollPositionDouble()); + EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location()); + + // Both viewports with a 0.5 fraction. + webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.5f, 100.5f)); + layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.5), ProgrammaticScroll); + inputBox->scrollIntoViewIfNeeded(false); + + EXPECT_POINT_EQ(DoublePoint(0, 900.5), layoutViewportScrollableArea->scrollPositionDouble()); + EXPECT_POINT_EQ(FloatPoint(250.5f, 100.5f), visualViewport.location()); +} + // Top controls can make an unscrollable page temporarily scrollable, causing // a scroll clamp when the page is resized. Make sure this bug is fixed. // crbug.com/437620 @@ -1418,6 +1476,84 @@ MAYBE_TEST_P(ElementBoundsInViewportSpaceAccountsForViewport) EXPECT_SIZE_EQ(expectedBounds.size(), boundsInViewport.size()); } +// Test that the various window.scroll and document.body.scroll properties and +// methods work unchanged from the pre-virtual viewport mode. +TEST_P(ParameterizedVisualViewportTest, bodyAndWindowScrollPropertiesAccountForViewport) +{ + initializeWithAndroidSettings(); + + webViewImpl()->resize(IntSize(200, 300)); + + // Load page with no main frame scrolling. + registerMockedHttpURLLoad("200-by-300-viewport.html"); + navigateTo(m_baseURL + "200-by-300-viewport.html"); + + VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport(); + visualViewport.setScale(2); + + // Chrome's quirky behavior regarding viewport scrolling means we treat the + // body element as the viewport and don't apply scrolling to the HTML + // element. + RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(false); + + LocalDOMWindow* window = webViewImpl()->mainFrameImpl()->frame()->localDOMWindow(); + window->scrollTo(100, 150); + EXPECT_EQ(100, window->scrollX()); + EXPECT_EQ(150, window->scrollY()); + EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location()); + + HTMLElement* body = toHTMLBodyElement(window->document()->body()); + body->setScrollLeft(50); + body->setScrollTop(130); + EXPECT_EQ(50, body->scrollLeft()); + EXPECT_EQ(130, body->scrollTop()); + EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 130), visualViewport.location()); + + HTMLElement* documentElement = toHTMLElement(window->document()->documentElement()); + documentElement->setScrollLeft(40); + documentElement->setScrollTop(50); + EXPECT_EQ(0, documentElement->scrollLeft()); + EXPECT_EQ(0, documentElement->scrollTop()); + EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 130), visualViewport.location()); + + visualViewport.setLocation(FloatPoint(10, 20)); + EXPECT_EQ(10, body->scrollLeft()); + EXPECT_EQ(20, body->scrollTop()); + EXPECT_EQ(0, documentElement->scrollLeft()); + EXPECT_EQ(0, documentElement->scrollTop()); + EXPECT_EQ(10, window->scrollX()); + EXPECT_EQ(20, window->scrollY()); + + // Turning on the standards-compliant viewport scrolling impl should make + // the document element the viewport and not body. + RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(true); + + window->scrollTo(100, 150); + EXPECT_EQ(100, window->scrollX()); + EXPECT_EQ(150, window->scrollY()); + EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location()); + + body->setScrollLeft(50); + body->setScrollTop(130); + EXPECT_EQ(0, body->scrollLeft()); + EXPECT_EQ(0, body->scrollTop()); + EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location()); + + documentElement->setScrollLeft(40); + documentElement->setScrollTop(50); + EXPECT_EQ(40, documentElement->scrollLeft()); + EXPECT_EQ(50, documentElement->scrollTop()); + EXPECT_FLOAT_POINT_EQ(FloatPoint(40, 50), visualViewport.location()); + + visualViewport.setLocation(FloatPoint(10, 20)); + EXPECT_EQ(0, body->scrollLeft()); + EXPECT_EQ(0, body->scrollTop()); + EXPECT_EQ(10, documentElement->scrollLeft()); + EXPECT_EQ(20, documentElement->scrollTop()); + EXPECT_EQ(10, window->scrollX()); + EXPECT_EQ(20, window->scrollY()); +} + // Tests that when a new frame is created, it is created with the intended // size (i.e. viewport at minimum scale, 100x200 / 0.5). MAYBE_TEST_P(TestMainFrameInitializationSizing) diff --git a/third_party/WebKit/public/web/WebSettings.h b/third_party/WebKit/public/web/WebSettings.h index 8451a16..64b5a80 100644 --- a/third_party/WebKit/public/web/WebSettings.h +++ b/third_party/WebKit/public/web/WebSettings.h @@ -157,6 +157,7 @@ public: virtual void setImageAnimationPolicy(ImageAnimationPolicy) = 0; virtual void setImagesEnabled(bool) = 0; virtual void setInlineTextBoxAccessibilityEnabled(bool) = 0; + virtual void setInertVisualViewport(bool) = 0; virtual void setJavaScriptCanAccessClipboard(bool) = 0; virtual void setJavaScriptCanOpenWindowsAutomatically(bool) = 0; virtual void setJavaScriptEnabled(bool) = 0; -- cgit v1.1