Changeset 150686 in webkit


Ignore:
Timestamp:
May 25, 2013 3:27:37 AM (11 years ago)
Author:
akling@apple.com
Message:

Begin moving "focus" state logic from Node to Element.
<http://webkit.org/b/116760>

Reviewed by Antti Koivisto.

Only Elements can be focused, so merge the "focus" state logic from Node and ContainerNode
and move it into Element. There's a lot more iceberg under this tip, but we'll be starting
with setFocus(bool) and focused().

  • dom/Node.h:
  • dom/ContainerNode.cpp:
  • dom/ContainerNode.h:
  • dom/Element.cpp:

(WebCore::Element::isUserActionElementFocused):
(WebCore::Element::setFocus):

  • dom/Element.h:

(WebCore::Element::focused):

  • dom/Node.cpp:

Move focused() and setFocus(bool) from Node/ContainerNode to Element.

  • dom/Document.cpp:

(WebCore::Document::setFocusedNode):

  • page/EventHandler.cpp:

(WebCore::EventHandler::dispatchMouseEvent):

Check if the inspected Node is an Element before asking if it's focused.

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r150685 r150686  
     12013-05-25  Andreas Kling  <akling@apple.com>
     2
     3        Begin moving "focus" state logic from Node to Element.
     4        <http://webkit.org/b/116760>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Only Elements can be focused, so merge the "focus" state logic from Node and ContainerNode
     9        and move it into Element. There's a lot more iceberg under this tip, but we'll be starting
     10        with setFocus(bool) and focused().
     11
     12        * dom/Node.h:
     13        * dom/ContainerNode.cpp:
     14        * dom/ContainerNode.h:
     15        * dom/Element.cpp:
     16        (WebCore::Element::isUserActionElementFocused):
     17        (WebCore::Element::setFocus):
     18        * dom/Element.h:
     19        (WebCore::Element::focused):
     20        * dom/Node.cpp:
     21
     22            Move focused() and setFocus(bool) from Node/ContainerNode to Element.
     23
     24        * dom/Document.cpp:
     25        (WebCore::Document::setFocusedNode):
     26        * page/EventHandler.cpp:
     27        (WebCore::EventHandler::dispatchMouseEvent):
     28
     29            Check if the inspected Node is an Element before asking if it's focused.
     30
    1312013-05-25  Noam Rosenthal  <noam.rosenthal@nokia.com>
    232
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r150684 r150686  
    969969}
    970970
    971 void ContainerNode::setFocus(bool received)
    972 {
    973     if (focused() == received)
    974         return;
    975 
    976     Node::setFocus(received);
    977 
    978     // note that we need to recalc the style
    979     setNeedsStyleRecalc();
    980 }
    981 
    982971void ContainerNode::setActive(bool down, bool pause)
    983972{
  • trunk/Source/WebCore/dom/ContainerNode.h

    r150684 r150686  
    110110    virtual void detach() OVERRIDE;
    111111    virtual LayoutRect boundingBox() const OVERRIDE;
    112     virtual void setFocus(bool) OVERRIDE;
    113112    virtual void setActive(bool active = true, bool pause = false) OVERRIDE;
    114113    virtual void scheduleSetNeedsStyleRecalc(StyleChangeType = FullStyleChange) OVERRIDE FINAL;
  • trunk/Source/WebCore/dom/Document.cpp

    r150684 r150686  
    33423342            oldFocusedNode->setActive(false);
    33433343
    3344         oldFocusedNode->setFocus(false);
     3344        if (oldFocusedNode->isElementNode())
     3345            toElement(oldFocusedNode.get())->setFocus(false);
    33453346
    33463347        // Dispatch a change event for text fields or textareas that have been edited
     
    34203421            goto SetFocusedNodeDone;
    34213422        }
    3422         m_focusedNode->setFocus(true);
     3423
     3424        if (m_focusedNode->isElementNode())
     3425            toElement(m_focusedNode.get())->setFocus(true);
    34233426
    34243427        if (m_focusedNode->isRootEditableElement())
  • trunk/Source/WebCore/dom/Element.cpp

    r150684 r150686  
    403403}
    404404
     405bool Element::isUserActionElementFocused() const
     406{
     407    ASSERT(isUserActionElement());
     408    return document()->userActionElements().isFocused(this);
     409}
     410
    405411bool Element::isUserActionElementHovered() const
    406412{
    407413    ASSERT(isUserActionElement());
    408414    return document()->userActionElements().isHovered(this);
     415}
     416
     417void Element::setFocus(bool flag)
     418{
     419    if (flag == focused())
     420        return;
     421
     422    if (Document* document = this->document())
     423        document->userActionElements().setFocused(this, flag);
     424
     425    setNeedsStyleRecalc();
    409426}
    410427
  • trunk/Source/WebCore/dom/Element.h

    r150684 r150686  
    428428
    429429    bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); }
     430    bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
     431
    430432    virtual void setHovered(bool flag = true);
     433    virtual void setFocus(bool flag);
    431434
    432435    RenderStyle* computedStyle(PseudoId = NOPSEUDO);
     
    658661
    659662private:
     663    bool isUserActionElementFocused() const;
    660664    bool isUserActionElementHovered() const;
    661665
  • trunk/Source/WebCore/dom/Node.cpp

    r150684 r150686  
    27382738}
    27392739
    2740 void Node::setFocus(bool flag)
    2741 {
    2742     if (Document* document = this->document())
    2743         document->userActionElements().setFocused(this, flag);
    2744 }
    2745 
    27462740void Node::setActive(bool flag, bool)
    27472741{
     
    27622756}
    27632757
    2764 bool Node::isUserActionElementFocused() const
    2765 {
    2766     ASSERT(isUserActionElement());
    2767     return document()->userActionElements().isFocused(this);
    2768 }
    2769 
    27702758} // namespace WebCore
    27712759
  • trunk/Source/WebCore/dom/Node.h

    r150684 r150686  
    361361    bool active() const { return isUserActionElement() && isUserActionElementActive(); }
    362362    bool inActiveChain() const { return isUserActionElement() && isUserActionElementInActiveChain(); }
    363     bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
    364363
    365364    bool attached() const { return getFlag(IsAttachedFlag); }
     
    399398    void lazyReattach(ShouldSetAttached = SetAttached);
    400399
    401     virtual void setFocus(bool flag);
    402400    virtual void setActive(bool flag = true, bool pause = false);
    403401
  • trunk/Source/WebCore/dom/UserActionElementSet.h

    r150684 r150686  
    4343    static PassOwnPtr<UserActionElementSet> create() { return adoptPtr(new UserActionElementSet()); }
    4444
    45     bool isFocused(const Node* node) { return hasFlags(node, IsFocusedFlag); }
     45    bool isFocused(const Element* element) { return hasFlags(element, IsFocusedFlag); }
    4646    bool isActive(const Node* node) { return hasFlags(node, IsActiveFlag); }
    4747    bool isInActiveChain(const Node* node) { return hasFlags(node, InActiveChainFlag); }
    48     bool isHovered(const Node* node) { return hasFlags(node, IsHoveredFlag); }
    49     void setFocused(Node* node, bool enable) { setFlags(node, enable, IsFocusedFlag); }
     48    bool isHovered(const Element* element) { return hasFlags(element, IsHoveredFlag); }
     49    void setFocused(Element* element, bool enable) { setFlags(element, enable, IsFocusedFlag); }
    5050    void setActive(Node* node, bool enable) { setFlags(node, enable, IsActiveFlag); }
    5151    void setInActiveChain(Node* node, bool enable) { setFlags(node, enable, InActiveChainFlag); }
  • trunk/Source/WebCore/page/EventHandler.cpp

    r150354 r150686  
    23612361                if (!page->focusController()->setFocusedNode(node, m_frame))
    23622362                    swallowEvent = true;
    2363             } else if (!node || !node->focused()) {
     2363            } else if (!node || !node->isElementNode() || !toElement(node)->focused()) {
    23642364                if (!page->focusController()->setFocusedNode(0, m_frame))
    23652365                    swallowEvent = true;
Note: See TracChangeset for help on using the changeset viewer.