Title: [184797] trunk/Source/WebKit2
Revision
184797
Author
[email protected]
Date
2015-05-22 14:48:53 -0700 (Fri, 22 May 2015)

Log Message

Avoid doing an extra layout in some cases while doing scale-to-fit
https://bugs.webkit.org/show_bug.cgi?id=145321
<rdar://problem/21051165>

Reviewed by Beth Dakin.

* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
(WebKit::TiledCoreAnimationDrawingArea::scaleViewToFitDocumentIfNeeded):
If we make it to scaleViewToFitDocumentIfNeeded with valid layout,
the view width is still less than the last-known minimum document size,
and the document size hasn't changed, update the view scale without
doing an extra layout, keeping the fixed layout size at the previously
computed minimum document size.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (184796 => 184797)


--- trunk/Source/WebKit2/ChangeLog	2015-05-22 21:43:14 UTC (rev 184796)
+++ trunk/Source/WebKit2/ChangeLog	2015-05-22 21:48:53 UTC (rev 184797)
@@ -1,3 +1,20 @@
+2015-05-22  Tim Horton  <[email protected]>
+
+        Avoid doing an extra layout in some cases while doing scale-to-fit
+        https://bugs.webkit.org/show_bug.cgi?id=145321
+        <rdar://problem/21051165>
+
+        Reviewed by Beth Dakin.
+
+        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
+        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
+        (WebKit::TiledCoreAnimationDrawingArea::scaleViewToFitDocumentIfNeeded):
+        If we make it to scaleViewToFitDocumentIfNeeded with valid layout,
+        the view width is still less than the last-known minimum document size,
+        and the document size hasn't changed, update the view scale without
+        doing an extra layout, keeping the fixed layout size at the previously
+        computed minimum document size.
+
 2015-05-22  Beth Dakin  <[email protected]>
 
         Yellow highlight and DD popover don't go away when scrolling an iframe

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h (184796 => 184797)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h	2015-05-22 21:43:14 UTC (rev 184796)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h	2015-05-22 21:48:53 UTC (rev 184797)
@@ -154,7 +154,7 @@
 
     Vector<uint64_t> m_fenceCallbacksForAfterNextFlush;
     bool m_shouldScaleViewToFitDocument { false };
-
+    bool m_isScalingViewToFitDocument { false };
     WebCore::IntSize m_lastViewSizeForScaleToFit;
     WebCore::IntSize m_lastDocumentSizeForScaleToFit;
 };

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm (184796 => 184797)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm	2015-05-22 21:43:14 UTC (rev 184796)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm	2015-05-22 21:48:53 UTC (rev 184797)
@@ -272,17 +272,33 @@
 
 void TiledCoreAnimationDrawingArea::scaleViewToFitDocumentIfNeeded()
 {
-    // FIXME: Defer scrollbar flashing until after the second layout.
-
     const int maximumDocumentWidthForScaling = 1440;
     const float minimumViewScale = 0.1;
 
     if (!m_shouldScaleViewToFitDocument)
         return;
 
-    if (!m_webPage.mainFrame()->view()->needsLayout() && m_lastDocumentSizeForScaleToFit == m_webPage.mainFrameView()->renderView()->unscaledDocumentRect().size() && m_lastViewSizeForScaleToFit == m_webPage.size())
+    int viewWidth = m_webPage.size().width();
+    bool documentWidthChangedOrInvalidated = m_webPage.mainFrame()->view()->needsLayout() || (m_lastDocumentSizeForScaleToFit.width() != m_webPage.mainFrameView()->renderView()->unscaledDocumentRect().width());
+    bool viewWidthChanged = m_lastViewSizeForScaleToFit.width() != viewWidth;
+
+    if (!documentWidthChangedOrInvalidated && !viewWidthChanged)
         return;
 
+    // The view is now bigger than the document, so we'll re-evaluate whether we have to scale.
+    if (m_isScalingViewToFitDocument && viewWidth >= m_lastDocumentSizeForScaleToFit.width())
+        m_isScalingViewToFitDocument = false;
+
+    // Our current understanding of the document width is still up to date, and we're in scaling mode.
+    // Update the viewScale without doing an extra layout to re-determine the document width.
+    if (m_isScalingViewToFitDocument && !documentWidthChangedOrInvalidated) {
+        float viewScale = (float)viewWidth / (float)m_lastDocumentSizeForScaleToFit.width();
+        m_lastViewSizeForScaleToFit = m_webPage.size();
+        viewScale = std::max(viewScale, minimumViewScale);
+        m_webPage.scaleView(viewScale);
+        return;
+    }
+
     // Lay out at the view size.
     m_webPage.setUseFixedLayout(false);
     m_webPage.layoutIfNeeded();
@@ -292,7 +308,6 @@
     m_lastDocumentSizeForScaleToFit = documentSize;
 
     int documentWidth = documentSize.width();
-    int viewWidth = m_webPage.size().width();
 
     float viewScale = 1;
 
@@ -300,6 +315,7 @@
     // sites that want horizontal scrollbars to continue to have them.
     if (documentWidth && documentWidth < maximumDocumentWidthForScaling && viewWidth < documentWidth) {
         // If the document doesn't fit in the view, scale it down but lay out at the view size.
+        m_isScalingViewToFitDocument = true;
         m_webPage.setUseFixedLayout(true);
         viewScale = (float)viewWidth / (float)documentWidth;
         viewScale = std::max(viewScale, minimumViewScale);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to