Bug 86217

Summary: Add helper function for node()->rootEditableElement() == node()
Product: WebKit Reporter: Shezan Baig <shezbaig.wk>
Component: HTML EditingAssignee: Shezan Baig <shezbaig.wk>
Status: RESOLVED FIXED    
Severity: Normal CC: cshu, darin, enrica, eric, rniwa, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 85385    
Attachments:
Description Flags
Patch
none
Patch (added isElementNode to the condition) none

Description Shezan Baig 2012-05-11 07:35:47 PDT
Per bug 85385, comment 5, this statement can be optimized as:

node()->rendererIsEditable() && (!node()->parentNode() || !node()->parentNode()->rendererIsEditable() || node()->hasTagName(bodyTag))
Comment 1 Shezan Baig 2012-05-11 09:22:26 PDT
Created attachment 141429 [details]
Patch
Comment 2 Shezan Baig 2012-05-11 09:34:12 PDT
I also see a bunch of places where rootEditableElement() is used to determine whether the element is editable, for example editing/FrameSelection.cpp@1788:

    if (!rootEditableElement())
        return;

Couldn't these statements also be replaced with a simple rendererIsEditable()?
Comment 3 Ryosuke Niwa 2012-05-11 10:03:56 PDT
Comment on attachment 141429 [details]
Patch

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

The change looks reasonable.

> Source/WebCore/dom/Node.cpp:1572
> +    return rendererIsEditable() && (!parentNode() || !parentNode()->rendererIsEditable() || hasTagName(bodyTag));

Actually, you can remove hasTagName(bodyTag) here. I wasn't thinking straight about this.
Comment 4 Shezan Baig 2012-05-11 10:17:42 PDT
Hmm, so presumably the body tag check can also be removed from Node::rootEditableElement?
Comment 5 Ryosuke Niwa 2012-05-11 10:36:52 PDT
(In reply to comment #4)
> Hmm, so presumably the body tag check can also be removed from Node::rootEditableElement?

Oh oops, I didn't see that. Okay, I was right. We do need this bodyTag check.
Comment 6 Shezan Baig 2012-05-11 11:33:00 PDT
Created attachment 141459 [details]
Patch (added isElementNode to the condition)
Comment 7 Ryosuke Niwa 2012-05-11 11:38:52 PDT
Comment on attachment 141459 [details]
Patch (added isElementNode to the condition)

Thank you for the refactoring! I've always wanted to do this :)
Comment 8 Ryosuke Niwa 2012-05-11 11:50:09 PDT
(In reply to comment #2)
> I also see a bunch of places where rootEditableElement() is used to determine whether the element is editable, for example editing/FrameSelection.cpp@1788:
> 
>     if (!rootEditableElement())
>         return;
> 
> Couldn't these statements also be replaced with a simple rendererIsEditable()?

There is a possibility that we're also checking that there is an element somewhere up in the ancestor chain (as supposed to a document) but I bet most of those places can just be calling rendererIsEditable.
Comment 9 WebKit Review Bot 2012-05-11 13:08:27 PDT
Comment on attachment 141459 [details]
Patch (added isElementNode to the condition)

Clearing flags on attachment: 141459

Committed r116798: <http://trac.webkit.org/changeset/116798>
Comment 10 WebKit Review Bot 2012-05-11 13:08:36 PDT
All reviewed patches have been landed.  Closing bug.
Comment 11 Ryosuke Niwa 2012-05-11 15:37:57 PDT
Fixed a regression in http://trac.webkit.org/changeset/116814.