<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>152588</bug_id>
          
          <creation_ts>2015-12-29 12:02:33 -0800</creation_ts>
          <short_desc>Webkit not recalculating width when changing height of absolute-positioned div with image</short_desc>
          <delta_ts>2021-10-16 23:30:32 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Layout and Rendering</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Mingwei Samuel">lugnuts25</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dbates</cc>
    
    <cc>hyatt</cc>
    
    <cc>rbuis</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1151556</commentid>
    <comment_count>0</comment_count>
      <attachid>267987</attachid>
    <who name="Mingwei Samuel">lugnuts25</who>
    <bug_when>2015-12-29 12:02:33 -0800</bug_when>
    <thetext>Created attachment 267987
Page that demonstrates bug

StackOverflow issue, has an example you can run:
http://stackoverflow.com/questions/34506314/webkit-bug-rendering-image-in-centered-absolute-div

Basically I have a relatively position div, with a absolutely positioned div child.  Inside the absolutely positioned div is a (square) image:
&lt;div relative&gt;
 &lt;div absolute&gt;
  &lt;img /&gt;
 &lt;/div&gt;
&lt;/div&gt;

Both absolute and img have height: 100%, so when relative changes height, so should both children. The image should then recalculate it&apos;s width to preserve it&apos;s aspect ratio, which in turn will change its parent (absolute) to change width. However, when relative&apos;s height is changed (via javascript or the debugger) the widths are not properly updated. If relative&apos;s height is decreased, no widths are recalculated and the image becomes squished vertically. if relative&apos;s height is increased, the image&apos;s width is increased to maintain the aspect ratio, but its parent (absolute) does not increase width, causing the image to overflow and be displaced to the right (in the example, it should stay centered).

Attached is an example page that shows this bug (also included in the stackoverflow).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1151770</commentid>
    <comment_count>1</comment_count>
      <attachid>268055</attachid>
    <who name="alan">zalan</who>
    <bug_when>2015-12-31 14:02:05 -0800</bug_when>
    <thetext>Created attachment 268055
Test reduction</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1151818</commentid>
    <comment_count>2</comment_count>
    <who name="alan">zalan</who>
    <bug_when>2015-12-31 18:05:21 -0800</bug_when>
    <thetext>(In reply to comment #0)
&gt; Created attachment 267987 [details]
&gt; Page that demonstrates bug
&gt; 
&gt; StackOverflow issue, has an example you can run:
&gt; http://stackoverflow.com/questions/34506314/webkit-bug-rendering-image-in-
&gt; centered-absolute-div
&gt; 
&gt; Basically I have a relatively position div, with a absolutely positioned div
&gt; child.  Inside the absolutely positioned div is a (square) image:
&gt; &lt;div relative&gt;
&gt;  &lt;div absolute&gt;
&gt;   &lt;img /&gt;
&gt;  &lt;/div&gt;
&gt; &lt;/div&gt;
&gt; 
&gt; Both absolute and img have height: 100%, so when relative changes height, so
&gt; should both children. The image should then recalculate it&apos;s width to
&gt; preserve it&apos;s aspect ratio, which in turn will change its parent (absolute)
&gt; to change width. However, when relative&apos;s height is changed (via javascript
&gt; or the debugger) the widths are not properly updated. If relative&apos;s height
&gt; is decreased, no widths are recalculated and the image becomes squished
&gt; vertically. if relative&apos;s height is increased, the image&apos;s width is
&gt; increased to maintain the aspect ratio, but its parent (absolute) does not
&gt; increase width, causing the image to overflow and be displaced to the right
&gt; (in the example, it should stay centered).
&gt; 
&gt; Attached is an example page that shows this bug (also included in the
&gt; stackoverflow).
You could add &quot;-webkit-aspect-ratio: from-intrinsic;&quot; to your img element to preserve ratio.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1151821</commentid>
    <comment_count>3</comment_count>
    <who name="alan">zalan</who>
    <bug_when>2015-12-31 18:21:27 -0800</bug_when>
    <thetext>It looks like we don&apos;t dirty the preferred min width on the image renderer, so we always end up with the original width.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1151901</commentid>
    <comment_count>4</comment_count>
    <who name="alan">zalan</who>
    <bug_when>2016-01-01 21:26:45 -0800</bug_when>
    <thetext>diff --git a/Source/WebCore/rendering/RenderBlockFlow.cpp b/Source/WebCore/rendering/RenderBlockFlow.cpp
index 286649c..96ed8c2 100644
--- a/Source/WebCore/rendering/RenderBlockFlow.cpp
+++ b/Source/WebCore/rendering/RenderBlockFlow.cpp
@@ -479,6 +479,7 @@ void RenderBlockFlow::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalH
     LayoutUnit maxFloatLogicalBottom = 0;
     if (!firstChild() &amp;&amp; !isAnonymousBlock())
         setChildrenInline(true);
+    dirtyForLayoutFromPercentageHeightDescendants();
     if (childrenInline())
         layoutInlineChildren(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);
     else
@@ -584,8 +585,6 @@ void RenderBlockFlow::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalH
 
 void RenderBlockFlow::layoutBlockChildren(bool relayoutChildren, LayoutUnit&amp; maxFloatLogicalBottom)
 {
-    dirtyForLayoutFromPercentageHeightDescendants();
-
     LayoutUnit beforeEdge = borderAndPaddingBefore();
     LayoutUnit afterEdge = borderAndPaddingAfter() + scrollbarLogicalHeight();
 
^^It fixes the issue of not dirtying the replaced renderer&apos;s preferred width when the (non-direct)ancestor height changes.
 
The failing test case has 
(A)RenderBlock with fixed height.
  (B)RenderBlock with percentage height
    (C)RenderImage with percentage height

When (A)&apos;s height is changed, we recalculate (C)&apos;s height but we keep the original width (so we might lose the original aspect ratio)

In this case, gPercentHeightDescendantsMap has the (B)-&gt;(C) pair -since (A) has non-auto, non-percentage height. By changing (A)&apos;s height, all the renderers (A)(B) and (C) are correctly marked dirty. However the preferred width bit does not get dirty (C) because the RenderBlock only calls dirtyForLayoutFromPercentageHeightDescendants() on its block children only -while here, (B) only has an inline child (C) 
Dave, do you know why it was originally added only to the block children path?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1154548</commentid>
    <comment_count>5</comment_count>
    <who name="alan">zalan</who>
    <bug_when>2016-01-11 16:53:13 -0800</bug_when>
    <thetext>(B)lock/(I)nline/I(N)line-block, (R)elative/A(B)solute/Fi(X)ed/Stick(Y) positioned, (O)verflow clipping, (A)nonymous, (G)enerated, (F)loating, has(L)ayer, (C)omposited, (D)irty layout, Dirty (S)tyle
B--AG-L- --* RenderView  (0.00, 0.00) (1323.00, 455.00) renderer-&gt;(0x11596c580)
B-----L- --    HTML RenderBlock  (0.00, 0.00) (1323.00, 455.00) renderer-&gt;(0x1159ee678) node-&gt;(0x1159f1680)
B------- --      BODY RenderBody  (8.00, 8.00) (1307.00, 439.00) renderer-&gt;(0x1159ee730) node-&gt;(0x1159f1750)
B------- --        DIV RenderBlock  (0.00, 0.00) (1307.00, 100.00) renderer-&gt;(0x1159ee7e8) node-&gt;(0x1159f17b8)
B------- --          DIV RenderBlock  (0.00, 0.00) (1307.00, 100.00) renderer-&gt;(0x1159ee8a0) node-&gt;(0x1159f1888)
-------- --            RootInlineBox  (0.00, 86.00) (200.00, 18.00) (0x11a7dc888) renderer-&gt;(0x1159ee8a0)
-------- --              InlineBox  (0.00, 0.00) (200.00, 100.00) (0x11a7e62d0) renderer-&gt;(0x1159da420)
I------- --            IMG RenderImage  (0.00, 0.00) (200.00, 100.00) renderer-&gt;(0x1159da420) node-&gt;(0x11595e160)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1208326</commentid>
    <comment_count>6</comment_count>
    <who name="Mingwei Samuel">lugnuts25</who>
    <bug_when>2016-07-06 12:20:24 -0700</bug_when>
    <thetext>I noticed that in AppleWebKit/537.36 (I do not know if that is the same vendor as this site) the image width now correctly updates to stay proportional, however the parent absolute still does not update it&apos;s width, causing the image to be left-ish-aligned instead of center-aligned</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1803661</commentid>
    <comment_count>7</comment_count>
    <who name="Rob Buis">rbuis</who>
    <bug_when>2021-10-13 00:21:17 -0700</bug_when>
    <thetext>I am not sure this can be reproduced these days?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1805362</commentid>
    <comment_count>8</comment_count>
    <who name="Mingwei Samuel">lugnuts25</who>
    <bug_when>2021-10-16 23:30:32 -0700</bug_when>
    <thetext>Seems that this issue is fixed. I can no longer produce any unexpected behavior.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>267987</attachid>
            <date>2015-12-29 12:02:33 -0800</date>
            <delta_ts>2015-12-29 12:02:33 -0800</delta_ts>
            <desc>Page that demonstrates bug</desc>
            <filename>webkit-bug.html</filename>
            <type>text/html</type>
            <size>2079</size>
            <attacher name="Mingwei Samuel">lugnuts25</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgogIDxoZWFkPjx0aXRsZT5XZWJraXQgYnVnPC90aXRsZT48
L2hlYWQ+CiAgPHN0eWxlPgogICAgI2NoYW5nZXNIZWlnaHQgewogICAgICBwb3NpdGlvbjogcmVs
YXRpdmU7CiAgICB9CiAgICAKICAgICNjaGlsZCB7CiAgICAgIHBvc2l0aW9uOiBhYnNvbHV0ZTsK
ICAgICAgbGVmdDogNTAlOwogICAgICBoZWlnaHQ6IDEwMCU7CiAgICAgIHRyYW5zZm9ybTogdHJh
bnNsYXRlWCgtNTAlKTsKICAgIH0KICA8L3N0eWxlPgogIDxib2R5PgogICAgPGR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ogMDsgbGVmdDogMCIgdHlwZT0ibnVtYmVyIiB2YWx1ZT0iMjAwIj4KICAgIDxzY3JpcHQ+
CiAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRzQnlUYWdOYW1lKCdpbnB1dCcpWzBdLm9uY2hhbmdl
ID0gZnVuY3Rpb24oYSkgewogICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdjaGFuZ2Vz
SGVpZ2h0Jykuc3R5bGUuaGVpZ2h0ID0gdGhpcy52YWx1ZSArICdweCc7CiAgICAgIH07CiAgICA8
L3NjcmlwdD4KICA8L2JvZHk+CjwvaHRtbD4K
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>268055</attachid>
            <date>2015-12-31 14:02:05 -0800</date>
            <delta_ts>2015-12-31 14:02:05 -0800</delta_ts>
            <desc>Test reduction</desc>
            <filename>bug-152588.html</filename>
            <type>text/html</type>
            <size>411</size>
            <attacher name="alan">zalan</attacher>
            
              <data encoding="base64">PHN0eWxlPgogICNjaGlsZCB7CiAgICBoZWlnaHQ6IDEwMCU7CiAgICBib3JkZXI6IDFweCBzb2xp
ZCBncmVlbjsKICB9Cjwvc3R5bGU+CmltZyBzaG91bGQgcHJlc2VydmUgYXNwZWN0IHJhdGlvIGFm
dGVyIGNvbnRhaW5lciByZXNpemUuCjxkaXYgaWQ9ImNoYW5nZXNIZWlnaHQiIHN0eWxlPSJoZWln
aHQ6IDIwMHB4OyI+CiAgPGRpdiBpZD0iY2hpbGQiPjxpbWcgc3R5bGU9ImJvcmRlcjogMXB4IHNv
bGlkIHJlZDsgaGVpZ2h0OiAxMDAlIiBzcmM9Im5vdGZvdW5kLmpwZyI+PC9kaXY+CjwvZGl2Pgo8
c2NyaXB0PgogIHNldFRpbWVvdXQoZnVuY3Rpb24oKSB7CiAgICBkb2N1bWVudC5nZXRFbGVtZW50
QnlJZCgnY2hhbmdlc0hlaWdodCcpLnN0eWxlLmhlaWdodCA9ICIxMDBweCI7CiAgICB9LCAxMDAp
Owo8L3NjcmlwdD4K
</data>

          </attachment>
      

    </bug>

</bugzilla>