Closed
Bug 173354
Opened 22 years ago
Closed 22 years ago
[FIX]margins are not computed correctly when they are set to % values
Categories
(Core :: DOM: CSS Object Model, defect)
Core
DOM: CSS Object Model
Tracking
()
VERIFIED
FIXED
People
(Reporter: vladimire, Assigned: bzbarsky)
References
Details
(Keywords: testcase)
Attachments
(5 files)
962 bytes,
text/html
|
Details | |
961 bytes,
text/html
|
Details | |
985 bytes,
text/html
|
Details | |
2.04 KB,
patch
|
caillon
:
review+
|
Details | Diff | Splinter Review |
8.00 KB,
patch
|
caillon
:
review+
hjtoi-bugzilla
:
superreview+
asa
:
approval+
|
Details | Diff | Splinter Review |
if you set margins to % values (margin-right: 38%) when computed using
getComputedStyle the value is not correct, even though it is layed out correctly.
See testcase.
Reporter | ||
Comment 1•22 years ago
|
||
Reporter | ||
Comment 2•22 years ago
|
||
first one did not label properties properly.
![]() |
Assignee | |
Comment 3•22 years ago
|
||
Hmmm... we just use CalcMarginWidthFor() here...
Could that be broken?
Comment 4•22 years ago
|
||
You get different results after the page is fully loaded.
Comment 5•22 years ago
|
||
Actually, I think that this bug is partially invalid. We are taking a
percentage of an auto margin. That auto margin will not be computed until later
on. Certainly not until we have finished loading the body (which Mats has shown).
That said, we should certainly not be returning negative values...
Reporter | ||
Comment 6•22 years ago
|
||
The values are 0 if the border of the outside DIV are removed.
![]() |
Assignee | |
Comment 7•22 years ago
|
||
You mean we're taking a percentage of a _width_ right? Look at the definition
of %-values for margins...
Perhaps all we need to do is flush before computing margins (in
nsComputedDOMStyle::GetMarginWidthFor). We don't do that now...
I'll try that and see what happens, unless caillon beats me to it.
Mats, thanks for the testcase!
Comment 8•22 years ago
|
||
You're welcome. In return, maybe you can explain why 38% of 100px = 37.9375px ?
Keywords: testcase
![]() |
Assignee | |
Comment 9•22 years ago
|
||
It's 37.9286 for me. Basically, the problem is that layout does all its
calculations in twips, using integer arithmetic. There are 20 twips per point.
So at 72 dpi, there are 20 twips per pixel. I'm at 100dpi. I think we force
it up to a So there are 72/100*20 = 14.4 twips per pixel.
Now 100px == 1440 twips (on my machine). 38% of that is 547.2 twips, so layout
will have a value of 547 twips for that length (integers, remember). Now we
convert back. 547/14.4 != 38, since we rounded off that 0.2 twip...
Comment 10•22 years ago
|
||
Err, I got confused. Too much "spec-ulating" today about undefined behaviors
has gotten me out of whack.
![]() |
Assignee | |
Comment 11•22 years ago
|
||
The first hunk just fixes some debug-me-or-caillon bustage. The other two are
actually relevant to this bug.
Updated•22 years ago
|
Attachment #102304 -
Flags: review+
Comment 12•22 years ago
|
||
Comment on attachment 102304 [details] [diff] [review]
flushing helps make things haaaaapppppy
I swear, the first part really compiles for me! :-)
r=caillon for the patch, though we should probably consider adding a private
void FlushPendingNotifications() to our class, since we do this exact same
thing in several places.
![]() |
Assignee | |
Comment 13•22 years ago
|
||
Comment 14•22 years ago
|
||
Comment on attachment 102305 [details] [diff] [review]
To inline or not, that is the question. I say not.
Right, we shouldn't inline in this case. r=caillon, thanks for doing the extra
work.
Attachment #102305 -
Flags: review+
Comment on attachment 102305 [details] [diff] [review]
To inline or not, that is the question. I say not.
sr=heikki
Attachment #102305 -
Flags: superreview+
![]() |
Assignee | |
Updated•22 years ago
|
Summary: margins are not computed correctly when they are set to % values → [FIX]margins are not computed correctly when they are set to % values
Comment 16•22 years ago
|
||
Comment on attachment 102305 [details] [diff] [review]
To inline or not, that is the question. I say not.
a=asa for checkin to 1.2beta or final (on behalf of drivers)
Attachment #102305 -
Flags: approval+
![]() |
Assignee | |
Comment 17•22 years ago
|
||
fixed.
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Comment 18•22 years ago
|
||
const nsStyleText *text = nsnull;
GetStyleData(eStyleStruct_Text, (const nsStyleStruct*&)text, aFrame);
- // Flush all pending notifications so that our frames are up to date
- nsCOMPtr<nsIDocument> document;
- mContent->GetDocument(*getter_AddRefs(document));
- if (document) {
- document->FlushPendingNotifications();
- }
+ FlushPendingReflows();
[paranoia] Might have been safer/consistent to flush before GetStyleData()
everywhere.
Reporter | ||
Comment 19•22 years ago
|
||
Looks fixed. Verifying. (build 2002-10-18-08-trunk)
Status: RESOLVED → VERIFIED
![]() |
Assignee | |
Comment 20•22 years ago
|
||
rbs, are there really times when flushing will affect what GetStyleData returns?
I can see frame construction forcing it, I guess; I see, to recall that table
code does something funky... is that what you meant?
Comment 21•22 years ago
|
||
Yep that's what I meant. If the flush didn't affect the styledata, you wouldn't
have got this bug in the first place.
Since what you found was that the flush was required to guarantee up-to-date
style data, it may happen that the flush may then hit hard on the style data --
possibly moving from a shared styledata slot to a brand new styledata slot.
Since it trivial to swap the order of the calls, I thought worthwhile to mention
it to avoid unforeseen inaccuracies -- albeit it is paranoia.
![]() |
Assignee | |
Comment 22•22 years ago
|
||
> If the flush didn't affect the styledata, you wouldn't have got this bug in the
> first place.
Sure we would have. We're not actually looking at styledata here, but at frame
rects. And flushes most certainly affect those....
I agree with the paranoia; the next time I touch this code I'll reorder the calls.
You need to log in
before you can comment on or make changes to this bug.
Description
•