Bug 76839 - Range.getClientRects() should not include rects for partially selected elements
Summary: Range.getClientRects() should not include rects for partially selected elements
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Andy Estes
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2012-01-23 10:29 PST by JuanCar Gallego
Modified: 2013-04-22 11:22 PDT (History)
6 users (show)

See Also:


Attachments
Patch (9.46 KB, patch)
2013-04-22 03:38 PDT, Andy Estes
sam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description JuanCar Gallego 2012-01-23 10:29:43 PST
Range.getclientrects returns too much rects, some of them incorrect (out of the range), at least when:
 - the end point of the range (endOffset) doesn't match the last position of the endContainer element
 - AND the beguinning of the endContainer is included in the range, but it's not the startOffset
In addition of the range rects, it's returning the rects of the whole endContainer element.

Tested in Chrome and Safari, working right in FireFox.

Described with an example here:
http://stackoverflow.com/questions/7232723/semantics-of-clientrect-from-getclientrects-in-webkit-browsers
Comment 1 theTestTube 2012-01-26 04:30:40 PST
Subscribe this.

I'm afraid we're also suffering it with Chrome and Safari.-
Comment 2 JuanCar Gallego 2012-01-27 05:25:49 PST
More information.

It seems like two close problems:

1. Range.getClientRects return rects for the partially selected text nodes in the startContaniner and endContainer. Correct. But for the not border elements it returns both rects for the whole elements, and rects for any text "fragment" inside them. It's redundant and confusing, and I think uncompliant with http://www.w3.org/TR/cssom-view/#extensions-to-the-range-interface

2. Correcting my first description of the problem: When endContainer is partially selected, and endContainer doesn't match startContainer, Range.getClientRects returns rect for the topmost ancestor of the endContainer whose parent contains the whole range (the child of range.commonAncestorContainer containing or being endContainer). This is clearly an error, because part of that rect (remember endContainer is partially selected) is outside the range.
Comment 3 Andy Estes 2013-04-18 20:31:01 PDT
<rdar://problem/13387823>
Comment 4 JuanCar Gallego 2013-04-22 03:34:08 PDT
(In reply to comment #3)
> <rdar://problem/13387823>

Hi, Andy.
I'm not sure to understand why you changed the subject of the bug.
IMHO not returning any rects for partially selected elements is worst than returning partial and total rects. With actual behaviour, at least I'm able to detect and discard wrong rects.
Comment 5 Andy Estes 2013-04-22 03:38:57 PDT
Created attachment 199012 [details]
Patch
Comment 6 Andy Estes 2013-04-22 03:44:45 PDT
(In reply to comment #4)
> (In reply to comment #3)
> > <rdar://problem/13387823>
> 
> Hi, Andy.
> I'm not sure to understand why you changed the subject of the bug.
> IMHO not returning any rects for partially selected elements is worst than returning partial and total rects. With actual behaviour, at least I'm able to detect and discard wrong rects.

You will still get rects for the selected children of the partially selected element.
Comment 7 JuanCar Gallego 2013-04-22 03:51:41 PDT
(In reply to comment #6)
> (In reply to comment #4)
> > (In reply to comment #3)
> > > <rdar://problem/13387823>
> > 
> > Hi, Andy.
> > I'm not sure to understand why you changed the subject of the bug.
> > IMHO not returning any rects for partially selected elements is worst than returning partial and total rects. With actual behaviour, at least I'm able to detect and discard wrong rects.
> 
> You will still get rects for the selected children of the partially selected element.

If it includes portions of partially selected text elements, as it does now, that's fine. Thank you.
Comment 8 Andy Estes 2013-04-22 11:22:49 PDT
Committed r148898: <http://trac.webkit.org/changeset/148898>