diff options
| author | bokan@chromium.org <bokan@chromium.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2013-11-05 21:21:20 +0000 |
|---|---|---|
| committer | bokan@chromium.org <bokan@chromium.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2013-11-05 21:21:20 +0000 |
| commit | f6aa30c5efd8eb36e070a38364a29d0b6dbc95b6 (patch) | |
| tree | c73d005d0c3180081213b4affbad8183747751f9 | |
| parent | 98b2255bbd2d0fba7a62c9eef6b7cadaaa258067 (diff) | |
| download | chromium_src-f6aa30c5efd8eb36e070a38364a29d0b6dbc95b6.zip chromium_src-f6aa30c5efd8eb36e070a38364a29d0b6dbc95b6.tar.gz chromium_src-f6aa30c5efd8eb36e070a38364a29d0b6dbc95b6.tar.bz2 | |
Experimental viewport meta tag support for desktop, Blink-side.
Added flag to allow desktop builds to experimentally turn
on support for the viewport meta tag. The --enable-viewport
flag now turns on only support for @viewport.
--enable-viewport-meta turns on viewport meta and @viewport
support.
On Android, the viewport gets rescaled when the view is
resized, i.e. phone is rotated between landscape and
portrait. On desktop, enabling the viewport causes the page
to zoom out when the window is shrunk, rather than adding
scrollbars. To support viewport on both devices, I've added
a --scale-viewport-on-resize flag that should be set on
Android and not desktop. This prevents the viewport scaling
code in WebViewImpl::resize().
Enabling viewport on desktop means the page scale can
change. This causes a known issue with scrollbars where
mouse events are scaled with the page, making mouse
interaction with scrollbars broken.
This is the Blink side of a 2-side patch.
BUG=232102
Review URL: https://codereview.chromium.org/40423003
git-svn-id: svn://svn.chromium.org/blink/trunk@161378 bbb929c8-8fbe-4397-9dbb-9b2b20218538
20 files changed, 259 insertions, 38 deletions
diff --git a/third_party/WebKit/LayoutTests/css3/device-adapt/viewport-user-agent-style.html b/third_party/WebKit/LayoutTests/css3/device-adapt/viewport-user-agent-style.html index 9b71239..a6ca8f0 100644 --- a/third_party/WebKit/LayoutTests/css3/device-adapt/viewport-user-agent-style.html +++ b/third_party/WebKit/LayoutTests/css3/device-adapt/viewport-user-agent-style.html @@ -6,6 +6,9 @@ <script src="../../resources/testharnessreport.js"></script> <script> if (window.testRunner) { + // FIXME: Emulate the android viewport UA stylesheet. We should test this + // based on the platform we're building for + testRunner.addUserStyleSheet("@viewport {min-width: 980px}", true); internals.settings.setViewportEnabled(true); } </script> diff --git a/third_party/WebKit/Source/core/core.gyp b/third_party/WebKit/Source/core/core.gyp index 2d4a319..ab9140d 100644 --- a/third_party/WebKit/Source/core/core.gyp +++ b/third_party/WebKit/Source/core/core.gyp @@ -969,6 +969,7 @@ ], }], ['OS=="android"', { + 'sources/': [['exclude', 'ViewportStyle\\.cpp$']], 'cflags': [ # WebCore does not work with strict aliasing enabled. # https://bugs.webkit.org/show_bug.cgi?id=25864 diff --git a/third_party/WebKit/Source/core/core.gypi b/third_party/WebKit/Source/core/core.gypi index 412166d..31a583a 100644 --- a/third_party/WebKit/Source/core/core.gypi +++ b/third_party/WebKit/Source/core/core.gypi @@ -804,6 +804,9 @@ 'css/StyleSheetContents.h', 'css/StyleSheetList.cpp', 'css/StyleSheetList.h', + 'css/ViewportStyle.cpp', + 'css/ViewportStyleAndroid.cpp', + 'css/ViewportStyle.h', 'css/resolver/AnimatedStyleBuilder.cpp', 'css/resolver/AnimatedStyleBuilder.h', 'css/resolver/ElementResolveContext.cpp', diff --git a/third_party/WebKit/Source/core/core_derived_sources.gyp b/third_party/WebKit/Source/core/core_derived_sources.gyp index 5332082..fa910cf 100644 --- a/third_party/WebKit/Source/core/core_derived_sources.gyp +++ b/third_party/WebKit/Source/core/core_derived_sources.gyp @@ -435,6 +435,7 @@ 'css/mediaControlsAndroid.css', 'css/fullscreen.css', 'css/xhtmlmp.css', + 'css/viewportAndroid.css', ], }, 'inputs': [ diff --git a/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp b/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp index 2799cff..53d79c1 100644 --- a/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp +++ b/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp @@ -33,6 +33,7 @@ #include "core/css/MediaQueryEvaluator.h" #include "core/css/RuleSet.h" #include "core/css/StyleSheetContents.h" +#include "core/css/ViewportStyle.h" #include "core/dom/FullscreenElementStack.h" #include "core/html/HTMLAnchorElement.h" #include "core/html/HTMLHtmlElement.h" @@ -57,7 +58,7 @@ StyleSheetContents* CSSDefaultStyleSheets::mediaControlsStyleSheet; StyleSheetContents* CSSDefaultStyleSheets::fullscreenStyleSheet; // FIXME: It would be nice to use some mechanism that guarantees this is in sync with the real UA stylesheet. -static const char simpleUserAgentStyleSheet[] = "html,body,div{display:block}head{display:none}body{margin:8px}div:focus,span:focus,a:focus{outline:auto 5px -webkit-focus-ring-color}a:-webkit-any-link{color:-webkit-link;text-decoration:underline}a:-webkit-any-link:active{color:-webkit-activelink}body:-webkit-seamless-document{margin:0}body:-webkit-full-page-media{background-color:black}@viewport{min-width:980px}@page{size:auto;margin:auto;padding:0;border-width:0}"; +static const char simpleUserAgentStyleSheet[] = "html,body,div{display:block}head{display:none}body{margin:8px}div:focus,span:focus,a:focus{outline:auto 5px -webkit-focus-ring-color}a:-webkit-any-link{color:-webkit-link;text-decoration:underline}a:-webkit-any-link:active{color:-webkit-activelink}body:-webkit-seamless-document{margin:0}body:-webkit-full-page-media{background-color:black}@page{size:auto;margin:auto;padding:0;border-width:0}"; static inline bool elementCanUseSimpleDefaultStyle(Element* e) { @@ -119,6 +120,7 @@ void CSSDefaultStyleSheets::loadFullDefaultStyle() String defaultRules = String(htmlUserAgentStyleSheet, sizeof(htmlUserAgentStyleSheet)) + RenderTheme::theme().extraDefaultStyleSheet(); defaultStyleSheet = parseUASheet(defaultRules); defaultStyle->addRulesFromSheet(defaultStyleSheet, screenEval()); + defaultStyle->addRulesFromSheet(parseUASheet(ViewportStyle::viewportStyleSheet()), screenEval()); defaultPrintStyle->addRulesFromSheet(defaultStyleSheet, printEval()); // Quirks-mode rules. @@ -139,6 +141,7 @@ void CSSDefaultStyleSheets::loadSimpleDefaultStyle() simpleDefaultStyleSheet = parseUASheet(simpleUserAgentStyleSheet, strlen(simpleUserAgentStyleSheet)); defaultStyle->addRulesFromSheet(simpleDefaultStyleSheet, screenEval()); + defaultStyle->addRulesFromSheet(parseUASheet(ViewportStyle::viewportStyleSheet()), screenEval()); // No need to initialize quirks sheet yet as there are no quirk rules for elements allowed in simple default style. } diff --git a/third_party/WebKit/Source/core/css/ViewportStyle.cpp b/third_party/WebKit/Source/core/css/ViewportStyle.cpp new file mode 100644 index 0000000..a031542 --- /dev/null +++ b/third_party/WebKit/Source/core/css/ViewportStyle.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2013 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ViewportStyle.h" + +namespace WebCore { + +String ViewportStyle::viewportStyleSheet() +{ + return String(); +} + +} // namespace WebCore diff --git a/third_party/WebKit/Source/core/css/ViewportStyle.h b/third_party/WebKit/Source/core/css/ViewportStyle.h new file mode 100644 index 0000000..903ad0f --- /dev/null +++ b/third_party/WebKit/Source/core/css/ViewportStyle.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ViewportStyle_h +#define ViewportStyle_h + +#include "wtf/text/WTFString.h" + +namespace WebCore { + +class ViewportStyle { +public: + static String viewportStyleSheet(); +}; + +} // namespace WebCore + +#endif // ViewportStyle_h diff --git a/third_party/WebKit/Source/core/css/ViewportStyleAndroid.cpp b/third_party/WebKit/Source/core/css/ViewportStyleAndroid.cpp new file mode 100644 index 0000000..c5e1932 --- /dev/null +++ b/third_party/WebKit/Source/core/css/ViewportStyleAndroid.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2013 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ViewportStyle.h" + +#include "UserAgentStyleSheets.h" + +namespace WebCore { + +String ViewportStyle::viewportStyleSheet() +{ + return String(viewportAndroidUserAgentStyleSheet, sizeof(viewportAndroidUserAgentStyleSheet)); +} + +} // namespace WebCore diff --git a/third_party/WebKit/Source/core/css/html.css b/third_party/WebKit/Source/core/css/html.css index 9f306fa..bd8fdf3 100644 --- a/third_party/WebKit/Source/core/css/html.css +++ b/third_party/WebKit/Source/core/css/html.css @@ -1128,11 +1128,5 @@ textarea[dir=auto] { border-width: 0px; } -/* viewport */ - -@viewport { - min-width: 980px; -} - /* noscript is handled internally, as it depends on settings. */ diff --git a/third_party/WebKit/Source/core/css/viewportAndroid.css b/third_party/WebKit/Source/core/css/viewportAndroid.css new file mode 100644 index 0000000..f406505 --- /dev/null +++ b/third_party/WebKit/Source/core/css/viewportAndroid.css @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2013 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* These styles override other user-agent styles for Chromium on Android. */ + +@viewport { + min-width: 980px; +} diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp index 113f4ce..74b6992 100644 --- a/third_party/WebKit/Source/core/dom/Document.cpp +++ b/third_party/WebKit/Source/core/dom/Document.cpp @@ -2928,6 +2928,9 @@ bool Document::shouldMergeWithLegacyDescription(ViewportDescription::Type origin void Document::setViewportDescription(const ViewportDescription& viewportDescription) { if (viewportDescription.isLegacyViewportType()) { + if (settings() && !settings()->viewportMetaEnabled()) + return; + m_legacyViewportDescription = viewportDescription; // When no author style for @viewport is present, and a meta tag for defining diff --git a/third_party/WebKit/Source/core/page/Settings.cpp b/third_party/WebKit/Source/core/page/Settings.cpp index 53aae2d..0746f652 100644 --- a/third_party/WebKit/Source/core/page/Settings.cpp +++ b/third_party/WebKit/Source/core/page/Settings.cpp @@ -133,6 +133,7 @@ Settings::Settings(Page* page) , m_touchEventEmulationEnabled(false) , m_openGLMultisamplingEnabled(false) , m_viewportEnabled(false) + , m_viewportMetaEnabled(false) , m_compositorDrivenAcceleratedScrollingEnabled(false) , m_setImageLoadingSettingsTimer(this, &Settings::imageLoadingSettingsTimerFired) { @@ -403,9 +404,17 @@ void Settings::setViewportEnabled(bool enabled) if (m_viewportEnabled == enabled) return; + // FIXME: Remove once Chromium-side lands. + setViewportMetaEnabled(enabled); + m_viewportEnabled = enabled; if (m_page->mainFrame()) m_page->mainFrame()->document()->updateViewportDescription(); } +void Settings::setViewportMetaEnabled(bool enabled) +{ + m_viewportMetaEnabled = enabled; +} + } // namespace WebCore diff --git a/third_party/WebKit/Source/core/page/Settings.h b/third_party/WebKit/Source/core/page/Settings.h index 86bfa9f..66edf55 100644 --- a/third_party/WebKit/Source/core/page/Settings.h +++ b/third_party/WebKit/Source/core/page/Settings.h @@ -154,6 +154,14 @@ public: void setViewportEnabled(bool); bool viewportEnabled() const { return m_viewportEnabled; } + void setViewportMetaEnabled(bool); + bool viewportMetaEnabled() const + { + // FIXME: Remove and uncomment once chromium side changes land. + return true; + // return m_viewportMetaEnabled; + } + // FIXME: This is a temporary flag and should be removed once accelerated // overflow scroll is ready (crbug.com/254111). void setCompositorDrivenAcceleratedScrollingEnabled(bool enabled) { m_compositorDrivenAcceleratedScrollingEnabled = enabled; } @@ -192,6 +200,7 @@ private: bool m_touchEventEmulationEnabled : 1; bool m_openGLMultisamplingEnabled : 1; bool m_viewportEnabled : 1; + bool m_viewportMetaEnabled : 1; // FIXME: This is a temporary flag and should be removed once accelerated // overflow scroll is ready (crbug.com/254111). diff --git a/third_party/WebKit/Source/web/WebSettingsImpl.cpp b/third_party/WebKit/Source/web/WebSettingsImpl.cpp index a19f75c..0a9963d1 100644 --- a/third_party/WebKit/Source/web/WebSettingsImpl.cpp +++ b/third_party/WebKit/Source/web/WebSettingsImpl.cpp @@ -59,6 +59,7 @@ WebSettingsImpl::WebSettingsImpl(Settings* settings) , m_viewportMetaLayoutSizeQuirk(false) , m_clobberUserAgentInitialScaleQuirk(false) , m_pinchOverlayScrollbarThickness(0) + , m_mainFrameResizesAreOrientationChanges(false) { ASSERT(settings); } @@ -652,6 +653,16 @@ bool WebSettingsImpl::viewportEnabled() const return m_settings->viewportEnabled(); } +bool WebSettingsImpl::viewportMetaEnabled() const +{ + return m_settings->viewportMetaEnabled(); +} + +bool WebSettingsImpl::mainFrameResizesAreOrientationChanges() const +{ + return m_mainFrameResizesAreOrientationChanges; +} + void WebSettingsImpl::setShouldDisplaySubtitles(bool enabled) { m_settings->setShouldDisplaySubtitles(enabled); @@ -689,9 +700,17 @@ void WebSettingsImpl::setFixedPositionCreatesStackingContext(bool creates) void WebSettingsImpl::setViewportEnabled(bool enabled) { + // FIXME: Remove once Chromium side changes land. + setMainFrameResizesAreOrientationChanges(enabled); + m_settings->setViewportEnabled(enabled); } +void WebSettingsImpl::setViewportMetaEnabled(bool enabled) +{ + m_settings->setViewportMetaEnabled(enabled); +} + void WebSettingsImpl::setSyncXHRInDocumentsEnabled(bool enabled) { m_settings->setSyncXHRInDocumentsEnabled(enabled); @@ -752,4 +771,9 @@ void WebSettingsImpl::setUseSolidColorScrollbars(bool enabled) m_settings->setUseSolidColorScrollbars(enabled); } +void WebSettingsImpl::setMainFrameResizesAreOrientationChanges(bool enabled) +{ + m_mainFrameResizesAreOrientationChanges = enabled; +} + } // namespace WebKit diff --git a/third_party/WebKit/Source/web/WebSettingsImpl.h b/third_party/WebKit/Source/web/WebSettingsImpl.h index 4d61935..7d8e2a0 100644 --- a/third_party/WebKit/Source/web/WebSettingsImpl.h +++ b/third_party/WebKit/Source/web/WebSettingsImpl.h @@ -44,10 +44,12 @@ public: explicit WebSettingsImpl(WebCore::Settings*); virtual ~WebSettingsImpl() { } + virtual bool mainFrameResizesAreOrientationChanges() const; virtual bool deviceSupportsTouch(); virtual bool scrollAnimatorEnabled() const; virtual bool touchEditingEnabled() const; virtual bool viewportEnabled() const; + virtual bool viewportMetaEnabled() const; virtual void setAccelerated2dCanvasEnabled(bool); virtual void setAccelerated2dCanvasMSAASampleCount(int); virtual void setAcceleratedCompositingEnabled(bool); @@ -118,6 +120,7 @@ public: virtual void setLoadWithOverviewMode(bool); virtual void setLocalStorageEnabled(bool); virtual void setMainFrameClipsContent(bool); + virtual void setMainFrameResizesAreOrientationChanges(bool); virtual void setMaxTouchPoints(int); virtual void setMediaPlaybackRequiresUserGesture(bool); virtual void setMediaFullscreenRequiresUserGesture(bool); @@ -172,6 +175,7 @@ public: virtual void setUseWideViewport(bool); virtual void setValidationMessageTimerMagnification(int); virtual void setViewportEnabled(bool); + virtual void setViewportMetaEnabled(bool); virtual void setViewportMetaLayoutSizeQuirk(bool); virtual void setViewportMetaMergeContentQuirk(bool); virtual void setViewportMetaZeroValuesQuirk(bool); @@ -216,6 +220,7 @@ private: // can be removed any time after 2015. See http://crbug.com/313754. bool m_clobberUserAgentInitialScaleQuirk; int m_pinchOverlayScrollbarThickness; + bool m_mainFrameResizesAreOrientationChanges; }; } // namespace WebKit diff --git a/third_party/WebKit/Source/web/WebViewImpl.cpp b/third_party/WebKit/Source/web/WebViewImpl.cpp index 09ae305e..6bc02fb 100644 --- a/third_party/WebKit/Source/web/WebViewImpl.cpp +++ b/third_party/WebKit/Source/web/WebViewImpl.cpp @@ -1697,7 +1697,9 @@ void WebViewImpl::resize(const WebSize& newSize) m_size = newSize; - bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSize.width && oldContentsWidth && newSize.width != oldSize.width; + bool shouldAnchorAndRescaleViewport = settings()->mainFrameResizesAreOrientationChanges() + && oldSize.width && oldContentsWidth && newSize.width != oldSize.width; + ViewportAnchor viewportAnchor(&mainFrameImpl()->frame()->eventHandler()); if (shouldAnchorAndRescaleViewport) { viewportAnchor.setAnchor(view->visibleContentRect(), diff --git a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp index d49540e..3face60 100644 --- a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp +++ b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp @@ -1028,6 +1028,14 @@ TEST_F(WebFrameTest, SetLoadWithOverviewModeToFalseAndNoWideViewport) EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor()); } +// Viewport settings need to be set before the page gets loaded +static void enableViewportSettings(WebSettings* settings) +{ + settings->setViewportMetaEnabled(true); + settings->setViewportEnabled(true); + settings->setMainFrameResizesAreOrientationChanges(true); +} + TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidth) { UseMockScrollbarSettings mockScrollbarSettings; @@ -1061,8 +1069,7 @@ TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidthButAccountsScale) int viewportHeight = 480; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); webViewHelper.webView()->settings()->setUseWideViewport(false); webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); @@ -1146,8 +1153,7 @@ TEST_F(WebFrameTest, PageViewportInitialScaleOverridesLoadWithOverviewMode) int viewportHeight = 480; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setLoadWithOverviewMode(false); webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); @@ -1199,8 +1205,7 @@ TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesLoadWithOverviewMod float enforcedPageScalePactor = 0.5f; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setLoadWithOverviewMode(false); webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScalePactor); webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); @@ -1220,8 +1225,7 @@ TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesPageViewportInitial float enforcedPageScaleFactor = 0.5f; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScaleFactor); webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); @@ -1309,8 +1313,7 @@ TEST_F(WebFrameTest, WideViewportInitialScaleDoesNotExpandFixedLayoutWidth) int viewportHeight = 480; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "viewport-device-0.5x-initial-scale.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "viewport-device-0.5x-initial-scale.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); webViewHelper.webView()->settings()->setUseWideViewport(true); webViewHelper.webView()->settings()->setViewportMetaLayoutSizeQuirk(true); @@ -1336,8 +1339,7 @@ TEST_F(WebFrameTest, WideViewportAndWideContentWithInitialScale) int viewportHeight = 800; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad("about:blank", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad("about:blank", true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); webViewHelper.webView()->settings()->setUseWideViewport(true); webViewHelper.webView()->settings()->setViewportMetaLayoutSizeQuirk(true); @@ -1364,8 +1366,7 @@ TEST_F(WebFrameTest, ZeroValuesQuirk) int viewportHeight = 480; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initialize(true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initialize(true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setViewportMetaZeroValuesQuirk(true); webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "viewport-zero-values.html"); @@ -1432,8 +1433,7 @@ TEST_F(WebFrameTest, NonZeroValuesNoQuirk) float expectedPageScaleFactor = 0.5f; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initialize(true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initialize(true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setViewportMetaZeroValuesQuirk(true); webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "viewport-nonzero-values.html"); @@ -1610,8 +1610,7 @@ TEST_F(WebFrameTest, targetDensityDpiHigh) client.m_screenInfo.deviceScaleFactor = deviceScaleFactor; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-high.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-high.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true); webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); @@ -1640,8 +1639,7 @@ TEST_F(WebFrameTest, targetDensityDpiDevice) client.m_screenInfo.deviceScaleFactor = deviceScaleFactors[i]; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-device.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-device.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true); webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); @@ -1667,8 +1665,7 @@ TEST_F(WebFrameTest, targetDensityDpiDeviceAndFixedWidth) client.m_screenInfo.deviceScaleFactor = deviceScaleFactors[i]; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-device-and-fixed-width.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-device-and-fixed-width.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true); webViewHelper.webView()->settings()->setUseWideViewport(true); @@ -1691,8 +1688,7 @@ TEST_F(WebFrameTest, NoWideViewportAndScaleLessThanOne) int viewportHeight = 480; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "viewport-initial-scale-less-than-1.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "viewport-initial-scale-less-than-1.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true); webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); webViewHelper.webView()->settings()->setUseWideViewport(false); @@ -1715,8 +1711,7 @@ TEST_F(WebFrameTest, NoWideViewportAndScaleLessThanOneWithDeviceWidth) int viewportHeight = 480; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "viewport-initial-scale-less-than-1-device-width.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "viewport-initial-scale-less-than-1-device-width.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true); webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); webViewHelper.webView()->settings()->setUseWideViewport(false); @@ -1750,8 +1745,7 @@ protected: const float aspectRatio = static_cast<float>(viewportSize.width) / viewportSize.height; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + url, true); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + url, true, 0, 0, enableViewportSettings); // Origin scrollOffsets preserved under resize. { @@ -1926,8 +1920,7 @@ TEST_F(WebFrameTest, CanOverrideScaleLimits) int viewportHeight = 480; FrameTestHelpers::WebViewHelper webViewHelper; - webViewHelper.initializeAndLoad(m_baseURL + "no_scale_for_you.html", true, 0, &client); - webViewHelper.webView()->settings()->setViewportEnabled(true); + webViewHelper.initializeAndLoad(m_baseURL + "no_scale_for_you.html", true, 0, &client, enableViewportSettings); webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); EXPECT_EQ(2.0f, webViewHelper.webView()->minimumPageScaleFactor()); diff --git a/third_party/WebKit/Source/web/tests/data/fixed_layout.html b/third_party/WebKit/Source/web/tests/data/fixed_layout.html index a89ceca..a3576b4 100644 --- a/third_party/WebKit/Source/web/tests/data/fixed_layout.html +++ b/third_party/WebKit/Source/web/tests/data/fixed_layout.html @@ -1 +1,10 @@ +<head> + <style> + /* Since tests are built with desktop viewport settings set the viewport + to behave like Android */ + @viewport { + min-width: 980px; + } + </style> +</head> <body>Ordinary non-mobile page</body> diff --git a/third_party/WebKit/Source/web/tests/data/no_viewport_tag.html b/third_party/WebKit/Source/web/tests/data/no_viewport_tag.html index 9ba9815..897b8d8 100644 --- a/third_party/WebKit/Source/web/tests/data/no_viewport_tag.html +++ b/third_party/WebKit/Source/web/tests/data/no_viewport_tag.html @@ -1,4 +1,13 @@ <html> + <head> + <style> + /* Since tests are built with desktop viewport settings set the viewport + to behave like Android */ + @viewport { + min-width: 980px; + } + </style> + </head> <body> <p> Test </p> </body> diff --git a/third_party/WebKit/public/web/WebSettings.h b/third_party/WebKit/public/web/WebSettings.h index 7da8649..006ff51 100644 --- a/third_party/WebKit/public/web/WebSettings.h +++ b/third_party/WebKit/public/web/WebSettings.h @@ -52,9 +52,11 @@ public: EditingBehaviorAndroid }; + virtual bool mainFrameResizesAreOrientationChanges() const = 0; virtual bool scrollAnimatorEnabled() const = 0; virtual bool touchEditingEnabled() const = 0; virtual bool viewportEnabled() const = 0; + virtual bool viewportMetaEnabled() const = 0; virtual void setAccelerated2dCanvasEnabled(bool) = 0; virtual void setAccelerated2dCanvasMSAASampleCount(int) = 0; virtual void setAcceleratedCompositingEnabled(bool) = 0; @@ -125,6 +127,7 @@ public: virtual void setLoadWithOverviewMode(bool) = 0; virtual void setLocalStorageEnabled(bool) = 0; virtual void setMainFrameClipsContent(bool) = 0; + virtual void setMainFrameResizesAreOrientationChanges(bool) = 0; virtual void setMaxTouchPoints(int) = 0; virtual void setMediaPlaybackRequiresUserGesture(bool) = 0; virtual void setMediaFullscreenRequiresUserGesture(bool) = 0; @@ -183,6 +186,7 @@ public: virtual void setUseWideViewport(bool) = 0; virtual void setValidationMessageTimerMagnification(int) = 0; virtual void setViewportEnabled(bool) = 0; + virtual void setViewportMetaEnabled(bool) = 0; virtual void setViewportMetaLayoutSizeQuirk(bool) = 0; virtual void setViewportMetaMergeContentQuirk(bool) = 0; virtual void setViewportMetaZeroValuesQuirk(bool) = 0; |
