Title: [201889] trunk
Revision
201889
Author
[email protected]
Date
2016-06-09 15:34:41 -0700 (Thu, 09 Jun 2016)

Log Message

Changing canvas height immediately after page load does not relayout canvas
https://bugs.webkit.org/show_bug.cgi?id=156097

Patch by Antoine Quint <[email protected]> on 2016-06-09
Reviewed by Zalan Bujtas.

Source/WebCore:

Promote the logic use to identify whether we should perform a layout after a change of
intrinsic size from RenderImage to RenderReplaced such that RenderCanvas may use it
in canvasSizeChanged() and correctly update its layout in the case where the width
or height attribute is updated and there are no explicit sizing performed with CSS.
Additionally, this will also account for the object-fix property to only perform
a layout if necessary.

Test: fast/canvas/canvas-css-size-after-height-change-with-display-flex.html

* rendering/RenderHTMLCanvas.cpp:
(WebCore::RenderHTMLCanvas::canvasSizeChanged):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::repaintOrMarkForLayout):
* rendering/RenderReplaced.cpp:
(WebCore::RenderReplaced::setNeedsLayoutIfNeededAfterIntrinsicSizeChange):
* rendering/RenderReplaced.h:

LayoutTests:

* fast/canvas/canvas-css-size-after-height-change-with-display-flex-expected.html: Added.
* fast/canvas/canvas-css-size-after-height-change-with-display-flex.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (201888 => 201889)


--- trunk/LayoutTests/ChangeLog	2016-06-09 22:05:04 UTC (rev 201888)
+++ trunk/LayoutTests/ChangeLog	2016-06-09 22:34:41 UTC (rev 201889)
@@ -1,3 +1,13 @@
+2016-06-09  Antoine Quint  <[email protected]>
+
+        Changing canvas height immediately after page load does not relayout canvas
+        https://bugs.webkit.org/show_bug.cgi?id=156097
+
+        Reviewed by Zalan Bujtas.
+
+        * fast/canvas/canvas-css-size-after-height-change-with-display-flex-expected.html: Added.
+        * fast/canvas/canvas-css-size-after-height-change-with-display-flex.html: Added.
+
 2016-06-09  Myles C. Maxfield  <[email protected]>
 
         Deleting a CSSOM style rule invalidates any previously-added FontFaces

Added: trunk/LayoutTests/fast/canvas/canvas-css-size-after-height-change-with-display-flex-expected.html (0 => 201889)


--- trunk/LayoutTests/fast/canvas/canvas-css-size-after-height-change-with-display-flex-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-css-size-after-height-change-with-display-flex-expected.html	2016-06-09 22:34:41 UTC (rev 201889)
@@ -0,0 +1 @@
+<div style="height: 500px; background-color: blue;"></div>

Added: trunk/LayoutTests/fast/canvas/canvas-css-size-after-height-change-with-display-flex.html (0 => 201889)


--- trunk/LayoutTests/fast/canvas/canvas-css-size-after-height-change-with-display-flex.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-css-size-after-height-change-with-display-flex.html	2016-06-09 22:34:41 UTC (rev 201889)
@@ -0,0 +1,14 @@
+<div style="display: flex; flex-direction: column;">
+    <canvas style="background-color: blue;">
+        <script>
+            if (window.testRunner)
+                testRunner.waitUntilDone();
+
+            window.requestAnimationFrame(function() {
+                document.querySelector("canvas").height = "500";
+                if (window.testRunner)
+                    testRunner.notifyDone();
+            });
+        </script>
+    </canvas>
+</div>

Modified: trunk/Source/WebCore/ChangeLog (201888 => 201889)


--- trunk/Source/WebCore/ChangeLog	2016-06-09 22:05:04 UTC (rev 201888)
+++ trunk/Source/WebCore/ChangeLog	2016-06-09 22:34:41 UTC (rev 201889)
@@ -1,3 +1,27 @@
+2016-06-09  Antoine Quint  <[email protected]>
+
+        Changing canvas height immediately after page load does not relayout canvas
+        https://bugs.webkit.org/show_bug.cgi?id=156097
+
+        Reviewed by Zalan Bujtas.
+
+        Promote the logic use to identify whether we should perform a layout after a change of
+        intrinsic size from RenderImage to RenderReplaced such that RenderCanvas may use it
+        in canvasSizeChanged() and correctly update its layout in the case where the width
+        or height attribute is updated and there are no explicit sizing performed with CSS.
+        Additionally, this will also account for the object-fix property to only perform
+        a layout if necessary.
+
+        Test: fast/canvas/canvas-css-size-after-height-change-with-display-flex.html
+
+        * rendering/RenderHTMLCanvas.cpp:
+        (WebCore::RenderHTMLCanvas::canvasSizeChanged):
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::repaintOrMarkForLayout):
+        * rendering/RenderReplaced.cpp:
+        (WebCore::RenderReplaced::setNeedsLayoutIfNeededAfterIntrinsicSizeChange):
+        * rendering/RenderReplaced.h:
+
 2016-06-09  Myles C. Maxfield  <[email protected]>
 
         Deleting a CSSOM style rule invalidates any previously-added FontFaces

Modified: trunk/Source/WebCore/rendering/RenderHTMLCanvas.cpp (201888 => 201889)


--- trunk/Source/WebCore/rendering/RenderHTMLCanvas.cpp	2016-06-09 22:05:04 UTC (rev 201888)
+++ trunk/Source/WebCore/rendering/RenderHTMLCanvas.cpp	2016-06-09 22:34:41 UTC (rev 201889)
@@ -101,18 +101,7 @@
 
     if (!parent())
         return;
-
-    if (!preferredLogicalWidthsDirty())
-        setPreferredLogicalWidthsDirty(true);
-
-    LayoutSize oldSize = size();
-    updateLogicalWidth();
-    updateLogicalHeight();
-    if (oldSize == size())
-        return;
-
-    if (!selfNeedsLayout())
-        setNeedsLayout();
+    setNeedsLayoutIfNeededAfterIntrinsicSizeChange();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (201888 => 201889)


--- trunk/Source/WebCore/rendering/RenderImage.cpp	2016-06-09 22:05:04 UTC (rev 201888)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp	2016-06-09 22:34:41 UTC (rev 201889)
@@ -295,30 +295,9 @@
 
     bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize || imageSizeChange != ImageSizeChangeNone;
 
-    if (imageSourceHasChangedSize) {
-        setPreferredLogicalWidthsDirty(true);
+    if (imageSourceHasChangedSize && setNeedsLayoutIfNeededAfterIntrinsicSizeChange())
+        return;
 
-        // If the actual area occupied by the image has changed and it is not constrained by style then a layout is required.
-        bool imageSizeIsConstrained = style().logicalWidth().isSpecified() && style().logicalHeight().isSpecified();
-
-        // FIXME: We only need to recompute the containing block's preferred size
-        // if the containing block's size depends on the image's size (i.e., the container uses shrink-to-fit sizing).
-        // There's no easy way to detect that shrink-to-fit is needed, always force a layout.
-        bool containingBlockNeedsToRecomputePreferredSize =
-            style().logicalWidth().isPercentOrCalculated()
-            || style().logicalMaxWidth().isPercentOrCalculated()
-            || style().logicalMinWidth().isPercentOrCalculated();
-
-        bool layoutSizeDependsOnIntrinsicSize = style().aspectRatioType() == AspectRatioFromIntrinsic;
-
-        if (!imageSizeIsConstrained || containingBlockNeedsToRecomputePreferredSize || layoutSizeDependsOnIntrinsicSize) {
-            // FIXME: It's not clear that triggering a layout guarantees a repaint in all cases.
-            // But many callers do depend on this code causing a layout.
-            setNeedsLayout();
-            return;
-        }
-    }
-
     if (everHadLayout() && !selfNeedsLayout()) {
         // The inner content rectangle is calculated during layout, but may need an update now
         // (unless the box has already been scheduled for layout). In order to calculate it, we

Modified: trunk/Source/WebCore/rendering/RenderReplaced.cpp (201888 => 201889)


--- trunk/Source/WebCore/rendering/RenderReplaced.cpp	2016-06-09 22:05:04 UTC (rev 201888)
+++ trunk/Source/WebCore/rendering/RenderReplaced.cpp	2016-06-09 22:34:41 UTC (rev 201889)
@@ -290,6 +290,31 @@
     return false;
 }
 
+bool RenderReplaced::setNeedsLayoutIfNeededAfterIntrinsicSizeChange()
+{
+    setPreferredLogicalWidthsDirty(true);
+    
+    // If the actual area occupied by the image has changed and it is not constrained by style then a layout is required.
+    bool imageSizeIsConstrained = style().logicalWidth().isSpecified() && style().logicalHeight().isSpecified();
+    
+    // FIXME: We only need to recompute the containing block's preferred size
+    // if the containing block's size depends on the image's size (i.e., the container uses shrink-to-fit sizing).
+    // There's no easy way to detect that shrink-to-fit is needed, always force a layout.
+    bool containingBlockNeedsToRecomputePreferredSize =
+        style().logicalWidth().isPercentOrCalculated()
+        || style().logicalMaxWidth().isPercentOrCalculated()
+        || style().logicalMinWidth().isPercentOrCalculated();
+    
+    bool layoutSizeDependsOnIntrinsicSize = style().aspectRatioType() == AspectRatioFromIntrinsic;
+    
+    if (!imageSizeIsConstrained || containingBlockNeedsToRecomputePreferredSize || layoutSizeDependsOnIntrinsicSize) {
+        setNeedsLayout();
+        return true;
+    }
+
+    return false;
+}
+    
 void RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* contentRenderer, FloatSize& constrainedSize, double& intrinsicRatio) const
 {
     FloatSize intrinsicSize;

Modified: trunk/Source/WebCore/rendering/RenderReplaced.h (201888 => 201889)


--- trunk/Source/WebCore/rendering/RenderReplaced.h	2016-06-09 22:05:04 UTC (rev 201888)
+++ trunk/Source/WebCore/rendering/RenderReplaced.h	2016-06-09 22:34:41 UTC (rev 201889)
@@ -37,6 +37,7 @@
 
     bool hasReplacedLogicalWidth() const;
     bool hasReplacedLogicalHeight() const;
+    bool setNeedsLayoutIfNeededAfterIntrinsicSizeChange();
 
 protected:
     RenderReplaced(Element&, RenderStyle&&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to