Bug 136763

Summary: Simplify DOM tree traversal in FrameSelection::setSelectionFromNone()
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: HTML EditingAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, rniwa
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Chris Dumez 2014-09-11 15:39:11 PDT
Simplify DOM Tree traversal in FrameSelection::setSelectionFromNone(). We only need to traverse the direct children of the Document element to find the body. The previous code was potentially traversing descendants.
The new code is consistent with Document::body() except that we only look for an HTMLBodyElement (and ignore HTMLFrameSetElement).
Comment 1 Chris Dumez 2014-09-11 15:51:47 PDT
Created attachment 237992 [details]
Patch
Comment 2 Ryosuke Niwa 2014-09-11 16:58:34 PDT
Comment on attachment 237992 [details]
Patch

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

> Source/WebCore/editing/FrameSelection.cpp:2117
> +    Element* documentElement = document->documentElement();
> +    if (!documentElement)
> +        return;

If I were you, I'd declare documentElement inside the if condition and nest the if's.
Comment 3 WebKit Commit Bot 2014-09-11 17:40:20 PDT
Comment on attachment 237992 [details]
Patch

Clearing flags on attachment: 237992

Committed r173549: <http://trac.webkit.org/changeset/173549>
Comment 4 WebKit Commit Bot 2014-09-11 17:40:23 PDT
All reviewed patches have been landed.  Closing bug.
Comment 5 Darin Adler 2014-09-11 18:46:21 PDT
Comment on attachment 237992 [details]
Patch

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

> Source/WebCore/editing/FrameSelection.cpp:2115
> +    Element* documentElement = document->documentElement();

In a case like this I prefer to use auto*. Later we might make the documentElement() function return a more specific type and it would be nice not to have to visit this call site.
Comment 6 Chris Dumez 2014-09-12 07:51:40 PDT
Comment on attachment 237992 [details]
Patch

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

>> Source/WebCore/editing/FrameSelection.cpp:2115
>> +    Element* documentElement = document->documentElement();
> 
> In a case like this I prefer to use auto*. Later we might make the documentElement() function return a more specific type and it would be nice not to have to visit this call site.

Ok, it makes sense. Would you like me to land another patch for the nit fix or is this for future reference?