[Chromium] Let the embedder override the max page scale factor set by the page
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2012 01:59:57 +0000 (01:59 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2012 01:59:57 +0000 (01:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=89406

Reviewed by James Robinson.

Chrome on Android has an option to force the web site to allow page
scaling (for accessibility). This patch adds
WebView::setIgnoreViewportTagMaximumScale, which instructs the WebView
to ignore the maximum scale factor supplied by by the page in the
viewport meta tag.

This patch is a bit different from how this is implemented on the
chromium-android branch, but I'll clean up the branch once this patch
lands.

* public/WebView.h:
(WebView):
* src/ChromeClientImpl.cpp:
(WebKit::ChromeClientImpl::dispatchViewportPropertiesDidChange):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::WebViewImpl):
(WebKit::WebViewImpl::setIgnoreViewportTagMaximumScale):
(WebKit):
* src/WebViewImpl.h:
(WebViewImpl):
(WebKit::WebViewImpl::ignoreViewportTagMaximumScale):
* tests/WebFrameTest.cpp:
(WebKit::TEST_F):
(WebKit):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121213 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebView.h
Source/WebKit/chromium/src/ChromeClientImpl.cpp
Source/WebKit/chromium/src/WebViewImpl.cpp
Source/WebKit/chromium/src/WebViewImpl.h
Source/WebKit/chromium/tests/WebFrameTest.cpp
Source/WebKit/chromium/tests/data/no_scale_for_you.html [new file with mode: 0644]

index 9a5d18f..65e8cf6 100644 (file)
@@ -1,3 +1,35 @@
+2012-06-25  Adam Barth  <abarth@webkit.org>
+
+        [Chromium] Let the embedder override the max page scale factor set by the page
+        https://bugs.webkit.org/show_bug.cgi?id=89406
+
+        Reviewed by James Robinson.
+
+        Chrome on Android has an option to force the web site to allow page
+        scaling (for accessibility). This patch adds
+        WebView::setIgnoreViewportTagMaximumScale, which instructs the WebView
+        to ignore the maximum scale factor supplied by by the page in the
+        viewport meta tag.
+
+        This patch is a bit different from how this is implemented on the
+        chromium-android branch, but I'll clean up the branch once this patch
+        lands.
+
+        * public/WebView.h:
+        (WebView):
+        * src/ChromeClientImpl.cpp:
+        (WebKit::ChromeClientImpl::dispatchViewportPropertiesDidChange):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::WebViewImpl):
+        (WebKit::WebViewImpl::setIgnoreViewportTagMaximumScale):
+        (WebKit):
+        * src/WebViewImpl.h:
+        (WebViewImpl):
+        (WebKit::WebViewImpl::ignoreViewportTagMaximumScale):
+        * tests/WebFrameTest.cpp:
+        (WebKit::TEST_F):
+        (WebKit):
+
 2012-06-25  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r121176.
index c152982..4a2804f 100644 (file)
@@ -249,6 +249,11 @@ public:
     virtual float minimumPageScaleFactor() const = 0;
     virtual float maximumPageScaleFactor() const = 0;
 
+    // Prevent the web page from setting a maximum scale via the viewport meta
+    // tag. This is an accessibility feature that lets folks zoom in to web
+    // pages even if the web page tries to block scaling.
+    virtual void setIgnoreViewportTagMaximumScale(bool) = 0;
+
     // The ratio of the current device's screen DPI to the target device's screen DPI.
     virtual float deviceScaleFactor() const = 0;
 
index dd1e210..50c5609 100644 (file)
@@ -657,6 +657,11 @@ void ChromeClientImpl::dispatchViewportPropertiesDidChange(const ViewportArgumen
         args, settings->layoutFallbackWidth(), deviceRect.width, deviceRect.height,
         dpi, IntSize(deviceRect.width, deviceRect.height));
 
+    if (m_webView->ignoreViewportTagMaximumScale()) {
+        computed.maximumScale = max(computed.maximumScale, m_webView->maxPageScaleFactor);
+        computed.userScalable = true;
+    }
+
     int layoutWidth = computed.layoutSize.width();
     int layoutHeight = computed.layoutSize.height();
     m_webView->setFixedLayoutSize(IntSize(layoutWidth, layoutHeight));
index d2393c3..02db63e 100644 (file)
@@ -386,6 +386,7 @@ WebViewImpl::WebViewImpl(WebViewClient* client)
     , m_pageDefinedMaximumPageScaleFactor(-1)
     , m_minimumPageScaleFactor(minPageScaleFactor)
     , m_maximumPageScaleFactor(maxPageScaleFactor)
+    , m_ignoreViewportTagMaximumScale(false)
     , m_pageScaleFactorIsSet(false)
     , m_contextMenuAllowed(false)
     , m_doingDragAndDrop(false)
@@ -2607,6 +2608,16 @@ void WebViewImpl::setPageScaleFactorLimits(float minPageScale, float maxPageScal
     computePageScaleFactorLimits();
 }
 
+void WebViewImpl::setIgnoreViewportTagMaximumScale(bool flag)
+{
+    m_ignoreViewportTagMaximumScale = flag;
+
+    if (!page() || !page()->mainFrame())
+        return;
+
+    m_page->chrome()->client()->dispatchViewportPropertiesDidChange(page()->mainFrame()->document()->viewportArguments());
+}
+
 bool WebViewImpl::computePageScaleFactorLimits()
 {
     if (m_pageDefinedMinimumPageScaleFactor == -1 || m_pageDefinedMaximumPageScaleFactor == -1)
index d4527da..a0ddedb 100644 (file)
@@ -207,6 +207,7 @@ public:
     virtual void setPageScaleFactorLimits(float minPageScale, float maxPageScale);
     virtual float minimumPageScaleFactor() const;
     virtual float maximumPageScaleFactor() const;
+    virtual void setIgnoreViewportTagMaximumScale(bool);
 
     virtual float deviceScaleFactor() const;
     virtual void setDeviceScaleFactor(float);
@@ -451,6 +452,8 @@ public:
         return m_emulatedTextZoomFactor;
     }
 
+    bool ignoreViewportTagMaximumScale() const { return m_ignoreViewportTagMaximumScale; }
+
     // Determines whether a page should e.g. be opened in a background tab.
     // Returns false if it has no opinion, in which case it doesn't set *policy.
     static bool navigationPolicyFromMouseEvent(
@@ -709,6 +712,8 @@ private:
     float m_minimumPageScaleFactor;
     float m_maximumPageScaleFactor;
 
+    bool m_ignoreViewportTagMaximumScale;
+
     bool m_pageScaleFactorIsSet;
 
     bool m_contextMenuAllowed;
index b884733..3c8d334 100644 (file)
@@ -284,6 +284,28 @@ TEST_F(WebFrameTest, FixedLayoutInitializeAtMinimumPageScale)
 }
 #endif
 
+TEST_F(WebFrameTest, CanOverrideMaximumScaleFactor)
+{
+    registerMockedHttpURLLoad("no_scale_for_you.html");
+
+    FixedLayoutTestWebViewClient client;
+    client.m_screenInfo.horizontalDPI = 160;
+    int viewportWidth = 640;
+    int viewportHeight = 480;
+    client.m_windowRect = WebRect(0, 0, viewportWidth, viewportHeight);
+
+    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_scale_for_you.html", true, 0, &client));
+    webViewImpl->enableFixedLayoutMode(true);
+    webViewImpl->settings()->setViewportEnabled(true);
+    webViewImpl->resize(WebSize(viewportWidth, viewportHeight));
+
+    EXPECT_EQ(1.0f, webViewImpl->maximumPageScaleFactor());
+
+    webViewImpl->setIgnoreViewportTagMaximumScale(true);
+
+    EXPECT_EQ(4.0f, webViewImpl->maximumPageScaleFactor());
+}
+
 #if ENABLE(GESTURE_EVENTS)
 TEST_F(WebFrameTest, DivAutoZoomParamsTest)
 {
diff --git a/Source/WebKit/chromium/tests/data/no_scale_for_you.html b/Source/WebKit/chromium/tests/data/no_scale_for_you.html
new file mode 100644 (file)
index 0000000..86bac2c
--- /dev/null
@@ -0,0 +1 @@
+<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" >