Bug 128478

Summary: HTMLTextFormControlElement::setSelectionRange shouldn't use VisiblePosition
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: FormsAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, barraclough, darin, enrica, sam
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 127832    
Attachments:
Description Flags
Cleanup darin: review+

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.