Title: [102429] trunk/Source
Revision
102429
Author
fsam...@chromium.org
Date
2011-12-08 21:15:18 -0800 (Thu, 08 Dec 2011)

Log Message

[Chromium] Enable viewport metatag
https://bugs.webkit.org/show_bug.cgi?id=73495

Reviewed by Darin Fisher.

Source/_javascript_Core:

* wtf/Platform.h: Added ENABLE(VIEWPORT) tag.

Source/WebCore:

Recompute viewpot parameters on frame rect resize.

* page/FrameView.cpp:
(WebCore::FrameView::setFrameRect):

Source/WebKit/chromium:

Compute the appropriate fixed layout size, page, and device scale factors,
based on the viewport meta tag parameters.

See http://developer.android.com/guide/webapps/targeting.html for more information.

* features.gypi:
* public/WebView.h:
* src/ChromeClientImpl.cpp:
(WebKit::ChromeClientImpl::layoutUpdated):
(WebKit::ChromeClientImpl::dispatchViewportPropertiesDidChange):
* src/ChromeClientImpl.h:
* src/WebFrameImpl.cpp:
(WebKit::WebFrameImpl::createFrameView):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::WebViewImpl):
(WebKit::WebViewImpl::isPageScaleFactorSet):
(WebKit::WebViewImpl::setPageScaleFactor):
(WebKit::WebViewImpl::observeNewNavigation):
* src/WebViewImpl.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (102428 => 102429)


--- trunk/Source/_javascript_Core/ChangeLog	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-12-09 05:15:18 UTC (rev 102429)
@@ -1,3 +1,12 @@
+2011-12-08  Fady Samuel  <fsam...@chromium.org>
+
+        [Chromium] Enable viewport metatag
+        https://bugs.webkit.org/show_bug.cgi?id=73495
+
+        Reviewed by Darin Fisher.
+
+        * wtf/Platform.h: Added ENABLE(VIEWPORT) tag.
+
 2011-12-08  Adam Klein  <ad...@chromium.org>
 
         Use HashMap<Node*, OwnPtr<...>> in ChildListMutationScope

Modified: trunk/Source/_javascript_Core/wtf/Platform.h (102428 => 102429)


--- trunk/Source/_javascript_Core/wtf/Platform.h	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/_javascript_Core/wtf/Platform.h	2011-12-09 05:15:18 UTC (rev 102429)
@@ -857,6 +857,10 @@
 #define ENABLE_GESTURE_RECOGNIZER 0
 #endif
 
+#if !defined(ENABLE_VIEWPORT)
+#define ENABLE_VIEWPORT 0
+#endif
+
 #if !defined(ENABLE_NOTIFICATIONS)
 #define ENABLE_NOTIFICATIONS 0
 #endif

Modified: trunk/Source/WebCore/ChangeLog (102428 => 102429)


--- trunk/Source/WebCore/ChangeLog	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/WebCore/ChangeLog	2011-12-09 05:15:18 UTC (rev 102429)
@@ -1,3 +1,15 @@
+2011-12-08  Fady Samuel  <fsam...@chromium.org>
+
+        [Chromium] Enable viewport metatag
+        https://bugs.webkit.org/show_bug.cgi?id=73495
+
+        Reviewed by Darin Fisher.
+
+        Recompute viewpot parameters on frame rect resize.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::setFrameRect):
+
 2011-12-08  Kent Tamura  <tk...@chromium.org>
 
         Build fix for r102419.

Modified: trunk/Source/WebCore/page/FrameView.cpp (102428 => 102429)


--- trunk/Source/WebCore/page/FrameView.cpp	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/WebCore/page/FrameView.cpp	2011-12-09 05:15:18 UTC (rev 102429)
@@ -405,6 +405,16 @@
     if (newRect == oldRect)
         return;
 
+#if ENABLE(VIEWPORT)
+    if (useFixedLayout()) {
+        Document* document = m_frame->document();
+        ViewportArguments viewport = document->viewportArguments();
+        Page* page = frame() ? frame()->page() : 0;
+        if (page)
+            page->chrome()->client()->dispatchViewportPropertiesDidChange(viewport);
+    }
+#endif
+
     ScrollView::setFrameRect(newRect);
 
 #if USE(ACCELERATED_COMPOSITING)

Modified: trunk/Source/WebKit/chromium/ChangeLog (102428 => 102429)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-12-09 05:15:18 UTC (rev 102429)
@@ -1,3 +1,31 @@
+2011-12-08  Fady Samuel  <fsam...@chromium.org>
+
+        [Chromium] Enable viewport metatag
+        https://bugs.webkit.org/show_bug.cgi?id=73495
+
+        Reviewed by Darin Fisher.
+
+        Compute the appropriate fixed layout size, page, and device scale factors,
+        based on the viewport meta tag parameters.
+
+        See http://developer.android.com/guide/webapps/targeting.html for more information.
+
+
+        * features.gypi:
+        * public/WebView.h:
+        * src/ChromeClientImpl.cpp:
+        (WebKit::ChromeClientImpl::layoutUpdated):
+        (WebKit::ChromeClientImpl::dispatchViewportPropertiesDidChange):
+        * src/ChromeClientImpl.h:
+        * src/WebFrameImpl.cpp:
+        (WebKit::WebFrameImpl::createFrameView):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::WebViewImpl):
+        (WebKit::WebViewImpl::isPageScaleFactorSet):
+        (WebKit::WebViewImpl::setPageScaleFactor):
+        (WebKit::WebViewImpl::observeNewNavigation):
+        * src/WebViewImpl.h:
+
 2011-12-08  Pierre Rossi  <pierre.ro...@gmail.com>
 
         Drop ENABLE_NO_LISTBOX_RENDERING, and make it a runtime decision.

Modified: trunk/Source/WebKit/chromium/features.gypi (102428 => 102429)


--- trunk/Source/WebKit/chromium/features.gypi	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/WebKit/chromium/features.gypi	2011-12-09 05:15:18 UTC (rev 102429)
@@ -90,6 +90,7 @@
       'ENABLE_V8_SCRIPT_DEBUG_SERVER=1',
       'ENABLE_VIDEO=1',
       'ENABLE_VIDEO_TRACK=1',
+      'ENABLE_VIEWPORT=<(enable_viewport)',
       'ENABLE_WEBGL=1',
       'ENABLE_WEB_SOCKETS=1',
       'ENABLE_WEB_TIMING=1',
@@ -112,6 +113,7 @@
       'use_accelerated_compositing%': 1,
       'enable_skia_text%': 0,
       'enable_svg%': 1,
+      'enable_viewport%': 0,
       'enable_touch_events%': 1,
       'use_skia%': 0,
       'enable_touch_icon_loading%' : 0,

Modified: trunk/Source/WebKit/chromium/public/WebView.h (102428 => 102429)


--- trunk/Source/WebKit/chromium/public/WebView.h	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/WebKit/chromium/public/WebView.h	2011-12-09 05:15:18 UTC (rev 102429)
@@ -214,6 +214,10 @@
     // is scaled up, < 1.0 is scaled down.
     virtual float pageScaleFactor() const = 0;
 
+    // Indicates wehther the page scale factor has been set since navigating
+    // to a new page.
+    virtual bool isPageScaleFactorSet() const = 0;
+
     // Scales the page and the scroll offset by a given factor, while ensuring
     // that the new scroll position does not go beyond the edge of the page.
     virtual void setPageScaleFactorPreservingScrollOffset(float) = 0;

Modified: trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp (102428 => 102429)


--- trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp	2011-12-09 05:15:18 UTC (rev 102429)
@@ -55,6 +55,7 @@
 #include "NavigationAction.h"
 #include "Node.h"
 #include "Page.h"
+#include "PlatformScreen.h"
 #include "PlatformSupport.h"
 #include "PopupContainer.h"
 #include "PopupMenuChromium.h"
@@ -559,6 +560,15 @@
 
 void ChromeClientImpl::layoutUpdated(Frame* frame) const
 {
+#if ENABLE(VIEWPORT)
+    if (!m_webView->isPageScaleFactorSet() && frame == frame->page()->mainFrame()) {
+        // If the page does not have a viewport tag, then compute a scale
+        // factor to make the page width fit the device width based on the
+        // default viewport parameters.
+        ViewportArguments viewport = frame->document()->viewportArguments();
+        dispatchViewportPropertiesDidChange(viewport);
+    }
+#endif
     m_webView->layoutUpdated(WebFrameImpl::fromFrame(frame));
 }
 
@@ -603,6 +613,47 @@
         tooltipText, textDirection);
 }
 
+void ChromeClientImpl::dispatchViewportPropertiesDidChange(const ViewportArguments& arguments) const
+{
+#if ENABLE(VIEWPORT)
+    if (!m_webView->isFixedLayoutModeEnabled() || !m_webView->client() || !m_webView->page())
+        return;
+
+    ViewportArguments args;
+    if (arguments == args)
+        // Default viewport arguments passed in. This is a signal to reset the viewport.
+        args.width = ViewportArguments::ValueDesktopWidth;
+    else
+        args = arguments;
+
+    FrameView* frameView = m_webView->mainFrameImpl()->frameView();
+    int dpi = screenHorizontalDPI(frameView);
+    ASSERT(dpi > 0);
+
+    WebViewClient* client = m_webView->client();
+    WebRect deviceRect = client->windowRect();
+    // If the window size has not been set yet don't attempt to set the viewport
+    if (!deviceRect.width || !deviceRect.height)
+        return;
+
+    Settings* settings = m_webView->page()->settings();
+    // Call the common viewport computing logic in ViewportArguments.cpp.
+    ViewportAttributes computed = computeViewportAttributes(
+        args, settings->layoutFallbackWidth(), deviceRect.width, deviceRect.height,
+        dpi, IntSize(deviceRect.width, deviceRect.height));
+
+    int layoutWidth = computed.layoutSize.width();
+    int layoutHeight = computed.layoutSize.height();
+    m_webView->setFixedLayoutSize(IntSize(layoutWidth, layoutHeight));
+
+    // FIXME: Investigate the impact this has on layout/rendering if any.
+    // This exposes the correct device scale to _javascript_ and media queries.
+    m_webView->setDeviceScaleFactor(computed.devicePixelRatio);
+    m_webView->setPageScaleFactorLimits(computed.minimumScale, computed.maximumScale);
+    m_webView->setPageScaleFactorPreservingScrollOffset(computed.initialScale * computed.devicePixelRatio);
+#endif
+}
+
 void ChromeClientImpl::print(Frame* frame)
 {
     if (m_webView->client())

Modified: trunk/Source/WebKit/chromium/src/ChromeClientImpl.h (102428 => 102429)


--- trunk/Source/WebKit/chromium/src/ChromeClientImpl.h	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/WebKit/chromium/src/ChromeClientImpl.h	2011-12-09 05:15:18 UTC (rev 102429)
@@ -125,6 +125,7 @@
     virtual void mouseDidMoveOverElement(
         const WebCore::HitTestResult& result, unsigned modifierFlags);
     virtual void setToolTip(const WTF::String& tooltipText, WebCore::TextDirection);
+    virtual void dispatchViewportPropertiesDidChange(const WebCore::ViewportArguments&) const;
     virtual void print(WebCore::Frame*);
     virtual void exceededDatabaseQuota(
         WebCore::Frame*, const WTF::String& databaseName);

Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp (102428 => 102429)


--- trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2011-12-09 05:15:18 UTC (rev 102429)
@@ -2088,7 +2088,8 @@
     ASSERT(m_frame); // If m_frame doesn't exist, we probably didn't init properly.
 
     WebViewImpl* webView = viewImpl();
-    m_frame->createView(webView->size(), Color::white, webView->isTransparent(),  webView->fixedLayoutSize(), webView->isFixedLayoutModeEnabled());
+    bool isMainFrame = webView->mainFrameImpl()->frame() == m_frame;
+    m_frame->createView(webView->size(), Color::white, webView->isTransparent(),  webView->fixedLayoutSize(), isMainFrame ? webView->isFixedLayoutModeEnabled() : 0);
     if (webView->shouldAutoResize())
         m_frame->view()->enableAutoSizeMode(true, webView->minAutoSize(), webView->maxAutoSize());
 

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (102428 => 102429)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2011-12-09 05:15:18 UTC (rev 102429)
@@ -347,6 +347,7 @@
     , m_pageDefinedMaximumPageScaleFactor(-1)
     , m_minimumPageScaleFactor(minPageScaleFactor)
     , m_maximumPageScaleFactor(maxPageScaleFactor)
+    , m_pageScaleFactorIsSet(false)
     , m_contextMenuAllowed(false)
     , m_doingDragAndDrop(false)
     , m_ignoreInputEvents(false)
@@ -1955,6 +1956,11 @@
     return page()->pageScaleFactor();
 }
 
+bool WebViewImpl::isPageScaleFactorSet() const
+{
+    return m_pageScaleFactorIsSet;
+}
+
 float WebViewImpl::clampPageScaleFactorToLimits(float scaleFactor)
 {
     return min(max(scaleFactor, m_minimumPageScaleFactor), m_maximumPageScaleFactor);
@@ -2003,6 +2009,7 @@
     scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
     WebPoint clampedOrigin = clampOffsetAtScale(origin, scaleFactor);
     page()->setPageScaleFactor(scaleFactor, clampedOrigin);
+    m_pageScaleFactorIsSet = true;
 }
 
 float WebViewImpl::deviceScaleFactor() const
@@ -2675,6 +2682,9 @@
 void WebViewImpl::observeNewNavigation()
 {
     m_observedNewNavigation = true;
+    // FIXME: We need to make sure that m_pageScaleFactorIsSet is not reset
+    // on same page navigations.
+    m_pageScaleFactorIsSet = false;
 #ifndef NDEBUG
     m_newNavigationLoader = m_page->mainFrame()->loader()->documentLoader();
 #endif

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (102428 => 102429)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.h	2011-12-09 05:00:25 UTC (rev 102428)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h	2011-12-09 05:15:18 UTC (rev 102429)
@@ -164,6 +164,7 @@
     virtual void zoomLimitsChanged(double minimumZoomLevel,
                                    double maximumZoomLevel);
     virtual float pageScaleFactor() const;
+    virtual bool isPageScaleFactorSet() const;
     virtual void setPageScaleFactorPreservingScrollOffset(float);
     virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin);
     virtual void setPageScaleFactorLimits(float minPageScale, float maxPageScale);
@@ -576,6 +577,8 @@
     float m_minimumPageScaleFactor;
     float m_maximumPageScaleFactor;
 
+    bool m_pageScaleFactorIsSet;
+
     bool m_contextMenuAllowed;
 
     bool m_doingDragAndDrop;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to