Bug 128478 - HTMLTextFormControlElement::setSelectionRange shouldn't use VisiblePosition
Summary: HTMLTextFormControlElement::setSelectionRange shouldn't use VisiblePosition
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords:
Depends on:
Blocks: 127832
  Show dependency treegraph
 
Reported: 2014-02-08 15:35 PST by Ryosuke Niwa
Modified: 2014-02-11 00:53 PST (History)
5 users (show)

See Also:


Attachments
Cleanup (5.92 KB, patch)
2014-02-08 16:25 PST, Ryosuke Niwa
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2014-02-08 15:35:50 PST
setSelectionRange uses visiblePositionForIndex to obtain start and end positions but we shouldn't need to
since we only have br elements and text nodes inside the shadow DOM of inputs and text area elements.

We should be able to obtain a regular Position by traversing through the DOM,
which is significantly more efficient than creating a VisiblePosition
Comment 1 Ryosuke Niwa 2014-02-08 16:25:19 PST
Created attachment 223594 [details]
Cleanup
Comment 2 Darin Adler 2014-02-09 23:41:45 PST
Comment on attachment 223594 [details]
Cleanup

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

> Source/WebCore/html/HTMLTextFormControlElement.cpp:55
> +static Position positionForIndex(TextControlInnerTextElement*, unsigned);

I suggest taking a reference here rather than a pointer.

> Source/WebCore/html/HTMLTextFormControlElement.cpp:324
>  int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& pos) const

Why not rename pos to position while you are changing this entire function?

> Source/WebCore/html/HTMLTextFormControlElement.cpp:569
> +            Text* text = toText(node);

This should be:

    Text& text = toText(*node);

Because we know node is non-null.
Comment 3 Ryosuke Niwa 2014-02-10 15:00:15 PST
Committed r163825: <http://trac.webkit.org/changeset/163825>
Comment 4 Ryosuke Niwa 2014-02-11 00:53:17 PST
Oops, I somehow missed these review comments.  Fixed them in http://trac.webkit.org/changeset/163846

(In reply to comment #2)
> (From update of attachment 223594 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=223594&action=review
> 
> > Source/WebCore/html/HTMLTextFormControlElement.cpp:55
> > +static Position positionForIndex(TextControlInnerTextElement*, unsigned);
> 
> I suggest taking a reference here rather than a pointer.

Unfortunately the pointer could be null in all 3 call sites :(

> > Source/WebCore/html/HTMLTextFormControlElement.cpp:324
> >  int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& pos) const
> 
> Why not rename pos to position while you are changing this entire function?

Done.

> > Source/WebCore/html/HTMLTextFormControlElement.cpp:569
> > +            Text* text = toText(node);
> 
> This should be:
> 
>     Text& text = toText(*node);
> 
> Because we know node is non-null.

Done.