Why <img>'s logicalLeft() is not changed after I've updated its ComputedStyle via setMarginLeft?

12 views
Skip to first unread message

小鱼儿

unread,
Mar 28, 2017, 4:26:19 AM3/28/17
to blink-dev, Chromium-dev
Hi blink & chromium guys,
I've hit a problem which i cannot figure out why.
The problem is, i need to reset <img> element's margin-left to 0 if it's greater than 0.

The method i prefer is:

1, update <img>'s renderer(LayoutImage)'s ComputedSty;e via setMarginLeft
2, set renderer `needsLayout`

However, this doesn't work.
I can update <img>'s layout width(logicalWidth) by using this way.
But why logicalLeft/margin-left doesn't work?

when i add VLOG in LayoutReplaced::layout(), its contentRect's x/y is both 0/0, but logicalLeft() always remains the initial value 100, which is exactly the css style margin-left:100px; I've set in test case html.

BTW, from the code, LayoutReplaced::layout() calls LayoutBox::updateLogicalWidth() which calls LayoutBox::updateLogicalLeft(), which is really puzzling me...

Christian Biesinger

unread,
Mar 28, 2017, 3:02:19 PM3/28/17
to 小鱼儿, blink-dev
bcc chromium-dev

In most cases, logicalLeft is set by the containing block (the main
exception is abspos). So you have to make sure that the parent will
have setNeedsLayout=true as well.

Otherwise this probably works but seems a little weird. You may have
an easier time overriding marginStart() and always returning 0 from
there.

Christian
Reply all
Reply to author
Forward
0 new messages