Closed Bug 249982 Opened 20 years ago Closed 18 years ago

percentage margins relative to float width not CB width if width:auto

Categories

(Core :: Layout: Floats, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: ian, Assigned: bzbarsky)

References

()

Details

(Whiteboard: [reflow-refactor])

Attachments

(3 files, 1 obsolete file)

If you have a width:auto float, then percentage margins are relative to the
actual width of the float, not its containing block width.
This happens for any shrink-wrapping block, actually.  It looks to me like the
code at the end of nsBlockReflowContext::ReflowBlock that does:

  // If the block is shrink wrapping its width, then see if we have percentage
  // based margins. If so, we can calculate them now that we know the shrink
  // wrap width
  if (NS_SHRINKWRAPWIDTH == aFrameRS.mComputedWidth) {
    ComputeShrinkwrapMargins(aFrameRS.mStyleMargin, mMetrics.width, mMargin, mX);
  }

is completely bogus (and has been since troy checked it in sometime in 2000). 
If the block being reflown is shrink-wrapping, its _kids_ need to use
ComputeShrinkWrapMargins; it itself does not need to.
In this testcase, the black square should be half the width of the red
rectangle.
Attached patch Proposed patch (obsolete) — Splinter Review
With this patch, the "testcase to not regress" is not regressed, and this bug
is fixed.  Now that we're not changing mX anymore (that part was pretty bogus
too, in my opinion), we no longer need the last arg of
ComputeShrinkwrapMargins.
Comment on attachment 153269 [details] [diff] [review]
Proposed patch

David, what do you think?
Attachment #153269 - Flags: superreview?(dbaron)
Attachment #153269 - Flags: review?(dbaron)
I'm suspicious of this change.  mComputeMaximumWidth isn't the normal way of
computing maximum width, so I think there has to be a third caller somewhere
(until reflow refactoring), for maximum width computation using
NS_UNCONSTRAINEDSIZE, under some condition.  Did you run the regression tests?

I haven't yet; I need to clear up a gig of disk space first.... But I'll try to
do that today.
OK, I finished running the regression tests.  There weren't any failures (other
than the false positives).

If you'd prefer to hold off on this till after reflow refactoring, I guess I'm
OK with that.
Comment on attachment 153269 [details] [diff] [review]
Proposed patch

As long as you don't make http://dbaron.org/css/test/intrinsic/perc-marg-max
and http://dbaron.org/css/test/intrinsic/perc-marg-min any worse (the're not so
great already), r+sr=dbaron.
Attachment #153269 - Flags: superreview?(dbaron)
Attachment #153269 - Flags: superreview+
Attachment #153269 - Flags: review?(dbaron)
Attachment #153269 - Flags: review+
Comment on attachment 153269 [details] [diff] [review]
Proposed patch

Ah, there we go.  That patch does make the testcase at
http://dbaron.org/css/test/intrinsic/perc-marg-max worse (the margins compute
to 0, looks like).  The testcase at
http://dbaron.org/css/test/intrinsic/perc-marg-min is not affected (and is
really bad, yes).

So it looks like this is no good as things stand -- 
we can't easily tell whether the width is shrink-wrap because it really is or
because the parent is shrink-wrapping... :(
Attachment #153269 - Attachment is obsolete: true
Attachment #153269 - Flags: superreview-
Attachment #153269 - Flags: superreview+
Attachment #153269 - Flags: review-
Attachment #153269 - Flags: review+
This computes the shrinkwrap margins only if our _parent_ is shrinkwrapping,
instead of if we're shrinkwrapping.
Comment on attachment 153739 [details] [diff] [review]
As discussed on IRC

Where by "parent" I mean "containing block", since that's what the percent
margins should be using to size.
Attachment #153739 - Flags: superreview?(dbaron)
Attachment #153739 - Flags: review?(dbaron)
Unfortunately you need to do the equivalent for the other two callers (and I'm
not really sure how one would do that right now) -- particularly the max-width
one, since this will cause {inc} bugs without such a change.

That said, maybe the best solution is to move this code where it belongs, and
add the margins at the parent, just like all other margins are added (right?).
Comment on attachment 153739 [details] [diff] [review]
As discussed on IRC

Hmm.. Yeah, margins are generally added at the parent (though most just add
whatever the reflow state computed margin is).

You're right that this has {inc} issues..
Attachment #153739 - Flags: superreview?(dbaron)
Attachment #153739 - Flags: superreview-
Attachment #153739 - Flags: review?(dbaron)
Attachment #153739 - Flags: review-
*** Bug 332551 has been marked as a duplicate of this bug. ***
Whiteboard: [reflow-refactor]
Blocks: 332551
Based on the test case:
fails with the 20061207 build
works with the 20061298 build

Bug 300030 fixed this, I think.
Yeah, it would have.
Status: NEW → RESOLVED
Closed: 18 years ago
Depends on: reflow-refactor
Resolution: --- → FIXED
Attached patch ReftestsSplinter Review
Attachment #257619 - Flags: review?(dbaron)
Comment on attachment 257619 [details] [diff] [review]
Reftests

Checked in after testing in pre- and post-reflow-branch builds.
Attachment #257619 - Flags: review?(dbaron) → review+
Status: RESOLVED → VERIFIED
Flags: in-testsuite+
Assignee: nobody → bzbarsky
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: