-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[cssom-view] Let offsetWidth / offsetHeight report actual size? #4541
Comments
So the issue here is that the (And then, separately, the I'm not sure how Firefox/etc got the idea that the |
The CSS Working Group just discussed The full IRC log of that discussion<dael> Topic: [cssom-view] Let offsetWidth / offsetHeight report actual size?<dael> github: https://github.com//issues/4541 <dael> TabAtkins: I'm confused on this issue. Thanks for digging up issues fantasai . According to the eample script and I verified Chrome. FF it repots offset of A is 40x40 but that's the div child. Chrome doesn't. It has 2 boxes surrounding hte div and b/c whitespace is collapsed the boxes are 0x0. <dael> TabAtkins: Haven't done spec diving to see if it allows A to report div as size. I think Chrome and Wk is correct here and we close no change <dael> AmeliaBR: Do you have link to spec that says block inside inline isn't counted as part of inline dimensions <dael> TabAtkins: Yu return size of first layout box. A element starts with inline that has whtiespace only <dael> AmeliaBR: Entire A includes div but there's a 0 width <dael> TabAtkins: Not quite. In box tree div is not child of A. A produces 2 siblings but they're children of A parent. <astearns> spec link: https://drafts.csswg.org/cssom-view-1/#extensions-to-the-htmlelement-interface <dael> dbaron: I think there are multi explinations for difference and worth checking which. Possible it's due to FF treating block as inside the inline. Another poss if difference if there's a box generated for that little piece or not <dael> TabAtkins: Yeah, and couldn't tell that without diving more <dael> dbaron: Could check if there's a difference if you put the letter in there <dael> TabAtkins: Yeah. <dael> TabAtkins: Letter in there still considers div part of A but the height is a little higher <dael> TabAtkins: FF makes height a littler higher. In Chrome it's still 0x0. Appears consistent. Chrome generates the empty box, FF considers it a part <dael> dbaron: Not sure how it's higher b/c not sure what box it's dealing with <dael> astearns: Seems like nice to be consistent here <dael> dbaron: Nevermind. <TabAtkins> With <a>foo<div></div></a>, you get a "foo" with the box below it, so the height grows in Firefox. <dael> dbaron: Code for getOffsetRect does go through all fragments <dael> TabAtkins: Rather then get first? <dael> dbaron: Yeah. At least Geck code goes through all <dael> TabAtkins: Sounds like Chrome doesn't <dael> dbaron: Maybe diff is do you go through all fragments <dael> AmeliaBR: Ran quick test using issue example + character before div and that way we can tell if it's about collapsing whitespace and in that case if there's a character FF gives width of div when giving offset of A element. It's not the first inline, but entire thing. Chrome gives size of first inline <dael> dbaron: Another test is letter before and after div <TabAtkins> before and after: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/7825 Chrome still reports the height of just one line, so it's not iterating all the fragments <dael> florian: Another thing confusing is Chrome behavior which is simple about first. For FF with most all frag are next to in this case. But it's not clear all fragments will be next to each other. If it's multi-col they're not adjacent. <dael> dbaron: I think ti's smallest rect that encloses all <dael> florian: So multi-col you get unrelated stuff, but when printing? <dael> dbaron: API doesn't work in printing. DOn't have access <dael> iank_: I think we had this convo with client height in multi-col. Two things you can do, union of all clients or stack them all. Impl stack. CSS Regions make it funky. Need to be consistent. <dael> emilio: Chrome does take height in getBoundingClientRect <dael> TabAtkins: It should b/c div height influences boundary. But this is just client rect <dael> florian: Not working in printing, saying when we print there is no script so it's not there? B/c that's not true. THing that renders to PDF runs scripts so you can ask this question in an engine that's fragmenting to multiple pieces not next ot each other. Easy for Chrome example, not sure what it does if try and stick together <dael> astearns: Top of hour. I think way forward is write test cases and then come to agreement what success for those cases should be and get that into spec <florian> s/THing/UAs/ <dael> astearns: Sound okay to everyone? <dael> florian: I would suggest including something like Prince in test cases to get an engine that prints and runs scripts <TabAtkins> As far as I can tell, the test cases are all consistently showing that Chrome returns the dimensions of the first fragment, and Firefox gives a bounding rect of all the fragments (including the blocks splitting the inline). <dael> astearns: Fair enough. |
@dbaron suggested several additional tests to make sure of exactly what behavior was being shown.
Results:
So yeah, this consistently shows that Chrome is returning the size of the first layout box (always something preceding the I haven't tested across multicols, but I think interop is spotty there anyway, so I'm not sure how useful such a test would be, considering we already see the break in these tests. |
There was some additional relevant IRC conversation at https://log.csswg.org/irc.w3.org/css/2020-03-18/#e1297586
|
Actually it should, in #1477 (comment) we resolved
|
oh dang, well then, that changes things |
Here's how I view it: If we go with chrome's behavior, how this behaves in multicol or paged scenario is not interesting, because it is sufficiently well defined: as you go with the first piece of element, and it's not terribly interesting to know what happens to the other ones, since they're not considered. If we are inclined to go with the firefox behavior, it becomes essential: as soon as you say you have to take into account all the pieces, you have to say what that means, and it is not trivial in all cases. Testing gives part of the answer here, as browsers that have this behavior must already have some answer to that question, but that does not necessarily mean it's the right answer. Maybe I'm missing something, but I see 3 different kinds of situation where this question is interesting, and may lead to different answers:
Some answers to "how do you account for multiple pieces" work in all of these situations, some don't. Some are more useful than others. a. measure the first one only (Chrome behavior): b. use the maximum inline size, and the sum of the block sizes: c. measure the size of the bounding box of all fragments: d. measure the size of the bounding box of all the pieces that fit in the first thing-that-establishes-a-coordinate-space (i.e. the first page), ignore the rest: e. ??? My inclination would be to go for a (and to use the same logic for getBoundingClientRect() and any other similar API), and to introduce additional fragment/box aware APIs, for two reasons: (b) and (d) also satisfy the first criteria, but because they appear to work in more situations (inline-broken-by-a-block for b and d, as well as multicol / regions for d) but not all situations, they trick authors into thinking they got the right tool for the job, while giving broken results in less commonly tested situations, which I think signals a bad and fragile API. Interestingly, prince, which supports javascript and pagination, does not support offsetWidth/offsetHeight/getBoundingClientRect(), but does have an API that lets you iterate through boxes/fragments/pieces (called (note: I'm using the word "piece" here, to walk around the fact that it is poorly defined whether we're talking about boxes or fragments here, as mentioned in #4541 (comment)) |
Does it? Boxes don't have a size, fragments do, so it shifts the problem one definition further, but doesn't really make a difference to the end result, does it? |
Firefox, Edge 42, IE 11: 40x40
Chrome, Safari: 0x0
According to current spec [1], I guess Chrome is correct. However, from a developer perspective, returning the actual size, as Firefox does, is way more useful and intuitive.
[1] Return the size of "the first CSS layout box associated with the element".
Is Firefox's behavior spec-able?
The text was updated successfully, but these errors were encountered: