Changeset 81220 in webkit


Ignore:
Timestamp:
Mar 15, 2011 11:21:39 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2011-03-15 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Darin Adler.

Devirtualize isContentEditable and isRichlyContentEditable
https://bugs.webkit.org/show_bug.cgi?id=56421

Rewrote Node::isContentEditable as a non-recursive non-virtual function.

  • dom/Document.cpp: Removed isContentEditable and isContentRichlyEditable.
  • dom/Document.h: Ditto.
  • dom/Node.cpp: (WebCore::Node::isContentEditable): Rewritten.
  • dom/Node.h: (WebCore::Node::isContentEditable): Calls isContentEditable(Editable). (WebCore::Node::isContentRichlyEditable): Calls isContentEditable(RichlyEditable).
  • html/HTMLElement.cpp: Removed isContentEditable and isContentRichlyEditable.
  • html/HTMLElement.h: Ditto.
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r81218 r81220  
     12011-03-15  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Devirtualize isContentEditable and isRichlyContentEditable
     6        https://bugs.webkit.org/show_bug.cgi?id=56421
     7
     8        Rewrote Node::isContentEditable as a non-recursive non-virtual function.
     9
     10        * dom/Document.cpp: Removed isContentEditable and isContentRichlyEditable.
     11        * dom/Document.h: Ditto.
     12        * dom/Node.cpp:
     13        (WebCore::Node::isContentEditable): Rewritten.
     14        * dom/Node.h:
     15        (WebCore::Node::isContentEditable): Calls isContentEditable(Editable).
     16        (WebCore::Node::isContentRichlyEditable): Calls isContentEditable(RichlyEditable).
     17        * html/HTMLElement.cpp: Removed isContentEditable and isContentRichlyEditable.
     18        * html/HTMLElement.h: Ditto.
     19
    1202011-03-15  Adam Barth  <abarth@webkit.org>
    221
  • trunk/Source/WebCore/dom/Document.cpp

    r81198 r81220  
    41184118}
    41194119
    4120 bool Document::isContentEditable() const
    4121 {
    4122     if (inDesignMode())
    4123         return true;
    4124 
    4125     return renderer() && (renderer()->style()->userModify() == READ_WRITE || renderer()->style()->userModify() == READ_WRITE_PLAINTEXT_ONLY);
    4126 }
    4127 
    4128 bool Document::isContentRichlyEditable() const
    4129 {
    4130     if (inDesignMode())
    4131         return true;
    4132 
    4133     return renderer() && renderer()->style()->userModify() == READ_WRITE;
    4134 }
    4135 
    41364120Document* Document::parentDocument() const
    41374121{
  • trunk/Source/WebCore/dom/Document.h

    r81198 r81220  
    895895    InheritedBool getDesignMode() const;
    896896    bool inDesignMode() const;
    897     virtual bool isContentEditable() const;
    898     virtual bool isContentRichlyEditable() const;
    899897
    900898    Document* parentDocument() const;
  • trunk/Source/WebCore/dom/Node.cpp

    r80811 r81220  
    712712}
    713713
    714 bool Node::isContentEditable() const
    715 {
    716     return parentOrHostNode() && parentOrHostNode()->isContentEditable();
    717 }
    718 
    719 bool Node::isContentRichlyEditable() const
    720 {
    721     return parentOrHostNode() && parentOrHostNode()->isContentRichlyEditable();
     714bool Node::isContentEditable(EditableLevel editableLevel) const
     715{
     716    if (document()->inDesignMode())
     717        return true;
     718
     719    // Ideally we'd call ASSERT(!needsStyleRecalc()) here, but
     720    // ContainerNode::setFocus() calls setNeedsStyleRecalc(), so the assertion
     721    // would fire in the middle of Document::setFocusedNode().
     722
     723    for (const Node* node = this; node; ) {
     724        if (node->isHTMLElement() || node->isDocumentNode()) {
     725            if (node->renderer()) {
     726                if (editableLevel == RichlyEditable)
     727                    return node->renderer()->style()->userModify() == READ_WRITE;
     728
     729                EUserModify userModify = node->renderer()->style()->userModify();
     730                return userModify == READ_WRITE || userModify == READ_WRITE_PLAINTEXT_ONLY;
     731            }
     732            node = node->parentNode();
     733        } else {
     734            // FIXME: Should this be parentNode() instead?
     735            node = node->parentOrHostNode();
     736        }
     737    }
     738
     739    return false;
    722740}
    723741
  • trunk/Source/WebCore/dom/Node.h

    r80811 r81220  
    328328    virtual bool isMouseFocusable() const;
    329329
    330     virtual bool isContentEditable() const;
    331     virtual bool isContentRichlyEditable() const;
     330    bool isContentEditable() const { return isContentEditable(Editable); }
     331    bool isContentRichlyEditable() const { return isContentEditable(RichlyEditable); }
    332332    virtual bool shouldUseInputMethod() const;
    333333    virtual IntRect getRect() const;
     
    660660#endif
    661661
     662    enum EditableLevel { Editable, RichlyEditable };
     663    bool isContentEditable(EditableLevel) const;
     664
    662665    void setStyleChange(StyleChangeType);
    663666
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r79953 r81220  
    658658}
    659659
    660 bool HTMLElement::isContentEditable() const
    661 {
    662     if (document()->inDesignMode())
    663         return true;
    664 
    665     // Ideally we'd call ASSERT!needsStyleRecalc()) here, but
    666     // ContainerNode::setFocus() calls setNeedsStyleRecalc(), so the assertion
    667     // would fire in the middle of Document::setFocusedNode().
    668 
    669     if (!renderer()) {
    670         if (parentNode())
    671             return parentNode()->isContentEditable();
    672         else
    673             return false;
    674     }
    675    
    676     return renderer()->style()->userModify() == READ_WRITE || renderer()->style()->userModify() == READ_WRITE_PLAINTEXT_ONLY;
    677 }
    678 
    679 bool HTMLElement::isContentRichlyEditable() const
    680 {
    681     if (document()->inDesignMode())
    682         return true;
    683 
    684     if (!renderer()) {
    685         if (parentNode())
    686             return parentNode()->isContentEditable();
    687         else
    688             return false;
    689     }
    690    
    691     return renderer()->style()->userModify() == READ_WRITE;
    692 }
    693 
    694660String HTMLElement::contentEditable() const
    695661{
  • trunk/Source/WebCore/html/HTMLElement.h

    r79024 r81220  
    5757
    5858    virtual bool supportsFocus() const;
    59    
    60     virtual bool isContentEditable() const;
    61     virtual bool isContentRichlyEditable() const;
    6259
    6360    String contentEditable() const;
Note: See TracChangeset for help on using the changeset viewer.