Bug 65324

Summary: REGRESSION: getBoundingClientRect() method of Range incorrectly returns null for collapsed Range
Product: WebKit Reporter: Tim Down <timdown>
Component: DOMAssignee: Sam Weinig <sam>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, bdakin, ctruta, evan, jiapu.mail, rniwa, sam
Priority: P1 Keywords: EasyFix, Regression
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Test case
none
Patch
none
Patch
none
Patch rniwa: review+

Tim Down
Reported 2011-07-28 10:28:35 PDT
Created attachment 102269 [details] Test case This contradicts the CSSOM spec (http://www.w3.org/TR/cssom-view/#extensions-to-the-range-interface) which mandates that: - in all cases a ClientRect must be returned; - the ClientRect returned must include the first ClientRect returned by getClientRects().
Attachments
Test case (504 bytes, text/html)
2011-07-28 10:28 PDT, Tim Down
no flags
Patch (8.69 KB, patch)
2011-07-31 13:17 PDT, Sam Weinig
no flags
Patch (8.27 KB, patch)
2011-07-31 13:18 PDT, Sam Weinig
no flags
Patch (8.27 KB, patch)
2011-07-31 13:23 PDT, Sam Weinig
rniwa: review+
Tim Down
Comment 1 2011-07-28 10:39:48 PDT
This looks like a regression: Safari 5.0.5 didn't have this problem, Safari 5.1 does.
Alexey Proskuryakov
Comment 2 2011-07-29 11:02:04 PDT
Confirmed on Mac OS X as a regression. CC'ing some people who changed getBoundingClientRect in the last year. Do you know if this affects any actual Web sites?
Tim Down
Comment 3 2011-07-29 11:34:06 PDT
Not to my knowledge. I discovered it while answering a question on Stack Overflow asking how to find the coordinates of the start of the selection: http://stackoverflow.com/questions/6846230/javascript-text-selection-page-coordinates
Evan Martin
Comment 4 2011-07-29 13:32:21 PDT
CC += selection master.
Sam Weinig
Comment 5 2011-07-29 15:16:13 PDT
Yeah, this clearly looks wrong, this should be an easy fix for someone.
Sam Weinig
Comment 6 2011-07-29 15:17:52 PDT
This probably regressed in http://trac.webkit.org/changeset/80408.
Sam Weinig
Comment 7 2011-07-31 13:17:30 PDT
Sam Weinig
Comment 8 2011-07-31 13:18:35 PDT
Sam Weinig
Comment 9 2011-07-31 13:19:52 PDT
This patch definitely gets us going in the right direction, the only open question in my mind is if the collapsed range being at an x/y of 0,0 is correct. It seems to match Firefox, but also seems a bit wonky.
Sam Weinig
Comment 10 2011-07-31 13:23:18 PDT
Ryosuke Niwa
Comment 11 2011-07-31 13:27:46 PDT
Comment on attachment 102465 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=102465&action=review The change makes sense to me. > LayoutTests/fast/dom/Range/getBoundingClientRect.html:114 > + /*4*/ { left: 0, top: 0, width: 0, height: 0 }, > + /*5*/ { left: -14.574, top: 1761.947, width: 504.009, height: 535.849 }, > + /*6*/ { left: 0, top: 0, width: 0, height: 0 }, It's not great that this test depends on particular font metrics and is failing on non-Mac ports :( Can we instead wrap each text with a span and compare span's offset* and bounding rect?
Sam Weinig
Comment 12 2011-07-31 14:03:19 PDT
(In reply to comment #11) > (From update of attachment 102465 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=102465&action=review > > The change makes sense to me. > > > LayoutTests/fast/dom/Range/getBoundingClientRect.html:114 > > + /*4*/ { left: 0, top: 0, width: 0, height: 0 }, > > + /*5*/ { left: -14.574, top: 1761.947, width: 504.009, height: 535.849 }, > > + /*6*/ { left: 0, top: 0, width: 0, height: 0 }, > > It's not great that this test depends on particular font metrics and is failing on non-Mac ports :( Can we instead wrap each text with a span and compare span's offset* and bounding rect? I think it would probably make more sense to use Ahem if possible, since part of what we want to test with this kind of test is that it works when the range is just selecting a subset of an element. That said, the two subtests I added do not depend on metrics, only the existing ones do.
Sam Weinig
Comment 13 2011-07-31 14:05:32 PDT
Ryosuke Niwa
Comment 14 2011-07-31 16:19:19 PDT
It seems like you've accidentally added some debugging code to the test when you landed the patch. Removed it in http://trac.webkit.org/changeset/92091.
Note You need to log in before you can comment on or make changes to this bug.