Bug 86390 - Expose FrameSelection::absoluteCaretBounds() via window.internals
Summary: Expose FrameSelection::absoluteCaretBounds() via window.internals
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Shezan Baig
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-14 12:11 PDT by Shezan Baig
Modified: 2012-05-18 11:41 PDT (History)
9 users (show)

See Also:


Attachments
Patch (11.88 KB, patch)
2012-05-15 15:17 PDT, Shezan Baig
no flags Details | Formatted Diff | Diff
Patch (with exported symbols for windows) (16.39 KB, patch)
2012-05-16 06:58 PDT, Shezan Baig
no flags Details | Formatted Diff | Diff
Patch (with change from comment 8) (16.43 KB, patch)
2012-05-16 10:51 PDT, Shezan Baig
no flags Details | Formatted Diff | Diff
Patch (with change from comment 12) (9.43 KB, patch)
2012-05-18 07:03 PDT, Shezan Baig
no flags Details | Formatted Diff | Diff
Patch (with exported symbols for windows) (11.54 KB, patch)
2012-05-18 09:04 PDT, Shezan Baig
no flags Details | Formatted Diff | Diff
Patch (removed unneccessary include statement) (11.33 KB, patch)
2012-05-18 09:58 PDT, Shezan Baig
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Shezan Baig 2012-05-14 12:11:56 PDT
A number of bugs (bug 85385, bug 85793, among others) involve caret positions for empty cells.  Right now, the only way to test fixes for these bugs is by pixel tests.  If we expose FrameSelection::localCaretRect to the Internals object, then we can use a simple dumpAsText test.
Comment 1 Darin Adler 2012-05-14 12:28:12 PDT
I would expose the caret rectangle in a document-relative fashion, not “local”.
Comment 2 Shezan Baig 2012-05-14 12:56:32 PDT
(In reply to comment #1)
> I would expose the caret rectangle in a document-relative fashion, not “local”.

My only concern with this is that it will make testing harder because the document-relative position of our test divs may be different depending on the platform (for example if we have some explanatory text at the top of the document), which means our test values are going to be platform-dependent.
Comment 3 Ryosuke Niwa 2012-05-14 13:31:17 PDT
(In reply to comment #2)
> (In reply to comment #1)
> > I would expose the caret rectangle in a document-relative fashion, not “local”.
> 
> My only concern with this is that it will make testing harder because the document-relative position of our test divs may be different depending on the platform (for example if we have some explanatory text at the top of the document), which means our test values are going to be platform-dependent.

But you can compute the diff between element's offsetTop/offsetLeft, right?
Comment 4 Shezan Baig 2012-05-15 06:39:14 PDT
(In reply to comment #3)
> But you can compute the diff between element's offsetTop/offsetLeft, right?

Yeah, we could do that.  I've updated the bug title for document-relative caret rect, thanks.
Comment 5 Shezan Baig 2012-05-15 15:17:22 PDT
Created attachment 142076 [details]
Patch

Initial patch to pass to the build bots, I suspect there will be some missing exported symbols from other platforms that I'm not building on.
Comment 6 Build Bot 2012-05-15 15:50:42 PDT
Comment on attachment 142076 [details]
Patch

Attachment 142076 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/12701609
Comment 7 Shezan Baig 2012-05-16 06:58:58 PDT
Created attachment 142246 [details]
Patch (with exported symbols for windows)
Comment 8 Ryosuke Niwa 2012-05-16 09:37:38 PDT
Comment on attachment 142246 [details]
Patch (with exported symbols for windows)

View in context: https://bugs.webkit.org/attachment.cgi?id=142246&action=review

> Source/WebCore/testing/Internals.cpp:409
> +        || !document->frame()->selection()->caretRenderer()
> +        || !document->frame()->selection()->caretRenderer()->isBoxModelObject()) {
> +        ec = INVALID_ACCESS_ERR;
> +        return ClientRect::create();

It's kind of odd to throw when there are no renderers.

> LayoutTests/editing/selection/internal-caret-rect.html:41
> +    getSelection().collapse(textNode, 0);  // before a
> +    verifyCaretRect(8, 140, 1, 20);
> +    getSelection().collapse(textNode, 1);  // after a
> +    verifyCaretRect(28, 140, 1, 20);
> +    getSelection().collapse(textNode, 2);  // after b
> +    verifyCaretRect(48, 140, 1, 20);
> +    getSelection().collapse(textNode, 3);  // after c
> +    verifyCaretRect(68, 140, 1, 20);
> +    getSelection().collapse(textNode, 4);  // after d
> +    verifyCaretRect(88, 140, 1, 20);

Are you sure these values work on all platforms?
Comment 9 Shezan Baig 2012-05-16 09:48:01 PDT
(In reply to comment #8)
> (From update of attachment 142246 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=142246&action=review
> 
> > Source/WebCore/testing/Internals.cpp:409
> > +        || !document->frame()->selection()->caretRenderer()
> > +        || !document->frame()->selection()->caretRenderer()->isBoxModelObject()) {
> > +        ec = INVALID_ACCESS_ERR;
> > +        return ClientRect::create();
> 
> It's kind of odd to throw when there are no renderers.


Agreed -- will fix this in a new patch to just return an empty rect.


> 
> > LayoutTests/editing/selection/internal-caret-rect.html:41
> > +    getSelection().collapse(textNode, 0);  // before a
> > +    verifyCaretRect(8, 140, 1, 20);
> > +    getSelection().collapse(textNode, 1);  // after a
> > +    verifyCaretRect(28, 140, 1, 20);
> > +    getSelection().collapse(textNode, 2);  // after b
> > +    verifyCaretRect(48, 140, 1, 20);
> > +    getSelection().collapse(textNode, 3);  // after c
> > +    verifyCaretRect(68, 140, 1, 20);
> > +    getSelection().collapse(textNode, 4);  // after d
> > +    verifyCaretRect(88, 140, 1, 20);
> 
> Are you sure these values work on all platforms?


It works on chromium-win and gtk-linux.  I don't have a mac to test this on, but I'm hoping the Ahem font at 20px (applied to the body element) will guarantee these numbers on all platforms.  Unfortunately the mac ews doesn't run the layout tests, so I'm not sure how to verify this.
Comment 10 Shezan Baig 2012-05-16 10:51:18 PDT
Created attachment 142297 [details]
Patch (with change from comment 8)
Comment 11 Ryosuke Niwa 2012-05-17 17:38:48 PDT
Comment on attachment 142297 [details]
Patch (with change from comment 8)

View in context: https://bugs.webkit.org/attachment.cgi?id=142297&action=review

> Source/WebCore/testing/Internals.cpp:421
> +    while (renderer->offsetParent()) {
> +        caretRect.move(renderer->offsetLeft(), renderer->offsetTop());
> +        renderer = renderer->offsetParent();
> +    }

Can't we just use localToAbsolute or its friends here?
Comment 12 Simon Fraser (smfr) 2012-05-17 17:45:35 PDT
Comment on attachment 142297 [details]
Patch (with change from comment 8)

View in context: https://bugs.webkit.org/attachment.cgi?id=142297&action=review

>> Source/WebCore/testing/Internals.cpp:421
>> +    }
> 
> Can't we just use localToAbsolute or its friends here?

Yes we totally should. We also have FrameSelection::absoluteCaretBounds() which does this already.
Comment 13 Shezan Baig 2012-05-18 05:47:34 PDT
(In reply to comment #12)
> (From update of attachment 142297 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=142297&action=review
> 
> >> Source/WebCore/testing/Internals.cpp:421
> >> +    }
> > 
> > Can't we just use localToAbsolute or its friends here?
> 
> Yes we totally should. We also have FrameSelection::absoluteCaretBounds() which does this already.

Sweet!  I'll use this.  Will also rename the method to window.internals.absoluteCaretBounds
Comment 14 Shezan Baig 2012-05-18 07:03:03 PDT
Created attachment 142711 [details]
Patch (with change from comment 12)
Comment 15 Build Bot 2012-05-18 08:45:35 PDT
Comment on attachment 142711 [details]
Patch (with change from comment 12)

Attachment 142711 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/12722834
Comment 16 Shezan Baig 2012-05-18 09:04:24 PDT
Created attachment 142726 [details]
Patch (with exported symbols for windows)
Comment 17 Shezan Baig 2012-05-18 09:53:02 PDT
Comment on attachment 142726 [details]
Patch (with exported symbols for windows)

View in context: https://bugs.webkit.org/attachment.cgi?id=142726&action=review

> Source/WebCore/testing/Internals.cpp:57
> +#include "RenderBoxModelObject.h"

I just noticed this, sorry I didn't see it earlier when I was cleaning up the previous implementation.  I'll upload a new patch since this include isn't necessary.
Comment 18 Shezan Baig 2012-05-18 09:58:38 PDT
Created attachment 142730 [details]
Patch (removed unneccessary include statement)
Comment 19 WebKit Review Bot 2012-05-18 11:41:25 PDT
Comment on attachment 142730 [details]
Patch (removed unneccessary include statement)

Clearing flags on attachment: 142730

Committed r117610: <http://trac.webkit.org/changeset/117610>
Comment 20 WebKit Review Bot 2012-05-18 11:41:32 PDT
All reviewed patches have been landed.  Closing bug.