Title: [150686] trunk/Source/WebCore
Revision
150686
Author
akl...@apple.com
Date
2013-05-25 03:27:37 -0700 (Sat, 25 May 2013)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (150685 => 150686)


--- trunk/Source/WebCore/ChangeLog	2013-05-25 09:51:25 UTC (rev 150685)
+++ trunk/Source/WebCore/ChangeLog	2013-05-25 10:27:37 UTC (rev 150686)
@@ -1,3 +1,33 @@
+2013-05-25  Andreas Kling  <akl...@apple.com>
+
+        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.
+
 2013-05-25  Noam Rosenthal  <noam.rosent...@nokia.com>
 
         Direct pattern compositing breaks when no-repeat is set on a large layer

Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (150685 => 150686)


--- trunk/Source/WebCore/dom/ContainerNode.cpp	2013-05-25 09:51:25 UTC (rev 150685)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp	2013-05-25 10:27:37 UTC (rev 150686)
@@ -968,17 +968,6 @@
     return enclosingLayoutRect(FloatRect(upperLeft, lowerRight.expandedTo(upperLeft) - upperLeft));
 }
 
-void ContainerNode::setFocus(bool received)
-{
-    if (focused() == received)
-        return;
-
-    Node::setFocus(received);
-
-    // note that we need to recalc the style
-    setNeedsStyleRecalc();
-}
-
 void ContainerNode::setActive(bool down, bool pause)
 {
     if (down == active()) return;

Modified: trunk/Source/WebCore/dom/ContainerNode.h (150685 => 150686)


--- trunk/Source/WebCore/dom/ContainerNode.h	2013-05-25 09:51:25 UTC (rev 150685)
+++ trunk/Source/WebCore/dom/ContainerNode.h	2013-05-25 10:27:37 UTC (rev 150686)
@@ -109,7 +109,6 @@
     virtual void attach() OVERRIDE;
     virtual void detach() OVERRIDE;
     virtual LayoutRect boundingBox() const OVERRIDE;
-    virtual void setFocus(bool) OVERRIDE;
     virtual void setActive(bool active = true, bool pause = false) OVERRIDE;
     virtual void scheduleSetNeedsStyleRecalc(StyleChangeType = FullStyleChange) OVERRIDE FINAL;
 

Modified: trunk/Source/WebCore/dom/Document.cpp (150685 => 150686)


--- trunk/Source/WebCore/dom/Document.cpp	2013-05-25 09:51:25 UTC (rev 150685)
+++ trunk/Source/WebCore/dom/Document.cpp	2013-05-25 10:27:37 UTC (rev 150686)
@@ -3341,7 +3341,8 @@
         if (oldFocusedNode->active())
             oldFocusedNode->setActive(false);
 
-        oldFocusedNode->setFocus(false);
+        if (oldFocusedNode->isElementNode())
+            toElement(oldFocusedNode.get())->setFocus(false);
 
         // Dispatch a change event for text fields or textareas that have been edited
         if (oldFocusedNode->isElementNode()) {
@@ -3419,8 +3420,10 @@
             focusChangeBlocked = true;
             goto SetFocusedNodeDone;
         }
-        m_focusedNode->setFocus(true);
 
+        if (m_focusedNode->isElementNode())
+            toElement(m_focusedNode.get())->setFocus(true);
+
         if (m_focusedNode->isRootEditableElement())
             frame()->editor().didBeginEditing();
 

Modified: trunk/Source/WebCore/dom/Element.cpp (150685 => 150686)


--- trunk/Source/WebCore/dom/Element.cpp	2013-05-25 09:51:25 UTC (rev 150685)
+++ trunk/Source/WebCore/dom/Element.cpp	2013-05-25 10:27:37 UTC (rev 150686)
@@ -402,12 +402,29 @@
     return nullAtom;
 }
 
+bool Element::isUserActionElementFocused() const
+{
+    ASSERT(isUserActionElement());
+    return document()->userActionElements().isFocused(this);
+}
+
 bool Element::isUserActionElementHovered() const
 {
     ASSERT(isUserActionElement());
     return document()->userActionElements().isHovered(this);
 }
 
+void Element::setFocus(bool flag)
+{
+    if (flag == focused())
+        return;
+
+    if (Document* document = this->document())
+        document->userActionElements().setFocused(this, flag);
+
+    setNeedsStyleRecalc();
+}
+
 void Element::setHovered(bool flag)
 {
     if (flag == hovered())

Modified: trunk/Source/WebCore/dom/Element.h (150685 => 150686)


--- trunk/Source/WebCore/dom/Element.h	2013-05-25 09:51:25 UTC (rev 150685)
+++ trunk/Source/WebCore/dom/Element.h	2013-05-25 10:27:37 UTC (rev 150686)
@@ -427,7 +427,10 @@
     virtual const AtomicString& shadowPseudoId() const;
 
     bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); }
+    bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
+
     virtual void setHovered(bool flag = true);
+    virtual void setFocus(bool flag);
 
     RenderStyle* computedStyle(PseudoId = NOPSEUDO);
 
@@ -657,6 +660,7 @@
     void classAttributeChanged(const AtomicString& newClassString);
 
 private:
+    bool isUserActionElementFocused() const;
     bool isUserActionElementHovered() const;
 
     void updatePseudoElement(PseudoId, StyleChange = NoChange);

Modified: trunk/Source/WebCore/dom/Node.cpp (150685 => 150686)


--- trunk/Source/WebCore/dom/Node.cpp	2013-05-25 09:51:25 UTC (rev 150685)
+++ trunk/Source/WebCore/dom/Node.cpp	2013-05-25 10:27:37 UTC (rev 150686)
@@ -2737,12 +2737,6 @@
     return count;
 }
 
-void Node::setFocus(bool flag)
-{
-    if (Document* document = this->document())
-        document->userActionElements().setFocused(this, flag);
-}
-
 void Node::setActive(bool flag, bool)
 {
     if (Document* document = this->document())
@@ -2761,12 +2755,6 @@
     return document()->userActionElements().isInActiveChain(this);
 }
 
-bool Node::isUserActionElementFocused() const
-{
-    ASSERT(isUserActionElement());
-    return document()->userActionElements().isFocused(this);
-}
-
 } // namespace WebCore
 
 #ifndef NDEBUG

Modified: trunk/Source/WebCore/dom/Node.h (150685 => 150686)


--- trunk/Source/WebCore/dom/Node.h	2013-05-25 09:51:25 UTC (rev 150685)
+++ trunk/Source/WebCore/dom/Node.h	2013-05-25 10:27:37 UTC (rev 150686)
@@ -360,7 +360,6 @@
 
     bool active() const { return isUserActionElement() && isUserActionElementActive(); }
     bool inActiveChain() const { return isUserActionElement() && isUserActionElementInActiveChain(); }
-    bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
 
     bool attached() const { return getFlag(IsAttachedFlag); }
     void setAttached() { setFlag(IsAttachedFlag); }
@@ -398,7 +397,6 @@
     void lazyAttach(ShouldSetAttached = SetAttached);
     void lazyReattach(ShouldSetAttached = SetAttached);
 
-    virtual void setFocus(bool flag);
     virtual void setActive(bool flag = true, bool pause = false);
 
     virtual short tabIndex() const;

Modified: trunk/Source/WebCore/dom/UserActionElementSet.h (150685 => 150686)


--- trunk/Source/WebCore/dom/UserActionElementSet.h	2013-05-25 09:51:25 UTC (rev 150685)
+++ trunk/Source/WebCore/dom/UserActionElementSet.h	2013-05-25 10:27:37 UTC (rev 150686)
@@ -42,11 +42,11 @@
 public:
     static PassOwnPtr<UserActionElementSet> create() { return adoptPtr(new UserActionElementSet()); }
 
-    bool isFocused(const Node* node) { return hasFlags(node, IsFocusedFlag); }
+    bool isFocused(const Element* element) { return hasFlags(element, IsFocusedFlag); }
     bool isActive(const Node* node) { return hasFlags(node, IsActiveFlag); }
     bool isInActiveChain(const Node* node) { return hasFlags(node, InActiveChainFlag); }
-    bool isHovered(const Node* node) { return hasFlags(node, IsHoveredFlag); }
-    void setFocused(Node* node, bool enable) { setFlags(node, enable, IsFocusedFlag); }
+    bool isHovered(const Element* element) { return hasFlags(element, IsHoveredFlag); }
+    void setFocused(Element* element, bool enable) { setFlags(element, enable, IsFocusedFlag); }
     void setActive(Node* node, bool enable) { setFlags(node, enable, IsActiveFlag); }
     void setInActiveChain(Node* node, bool enable) { setFlags(node, enable, InActiveChainFlag); }
     void setHovered(Element* element, bool enable) { setFlags(element, enable, IsHoveredFlag); }

Modified: trunk/Source/WebCore/page/EventHandler.cpp (150685 => 150686)


--- trunk/Source/WebCore/page/EventHandler.cpp	2013-05-25 09:51:25 UTC (rev 150685)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2013-05-25 10:27:37 UTC (rev 150686)
@@ -2360,7 +2360,7 @@
             if (node && node->isMouseFocusable()) {
                 if (!page->focusController()->setFocusedNode(node, m_frame))
                     swallowEvent = true;
-            } else if (!node || !node->focused()) {
+            } else if (!node || !node->isElementNode() || !toElement(node)->focused()) {
                 if (!page->focusController()->setFocusedNode(0, m_frame))
                     swallowEvent = true;
             }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to