Title: [156338] trunk/Source/WebCore
Revision
156338
Author
[email protected]
Date
2013-09-24 10:51:16 -0700 (Tue, 24 Sep 2013)

Log Message

Make hoverAncestor() a RenderElement concept.
<https://webkit.org/b/121845>

Reviewed by Antti Koivisto.

The hover ancestor renderer is always a RenderElement, we only ever
ask RenderElements for their hover ancestors.

Updated Document::updateHoverActiveState() to take advantage of the
tighter typing, removing a few isElementNode() checks.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (156337 => 156338)


--- trunk/Source/WebCore/ChangeLog	2013-09-24 17:12:37 UTC (rev 156337)
+++ trunk/Source/WebCore/ChangeLog	2013-09-24 17:51:16 UTC (rev 156338)
@@ -1,3 +1,16 @@
+2013-09-24  Andreas Kling  <[email protected]>
+
+        Make hoverAncestor() a RenderElement concept.
+        <https://webkit.org/b/121845>
+
+        Reviewed by Antti Koivisto.
+
+        The hover ancestor renderer is always a RenderElement, we only ever
+        ask RenderElements for their hover ancestors.
+
+        Updated Document::updateHoverActiveState() to take advantage of the
+        tighter typing, removing a few isElementNode() checks.
+
 2013-09-24  Daniel Bates  <[email protected]>
 
         [iOS] Initialize settings mediaPlayback{AllowsInline, RequiresUserGesture} and

Modified: trunk/Source/WebCore/dom/Document.cpp (156337 => 156338)


--- trunk/Source/WebCore/dom/Document.cpp	2013-09-24 17:12:37 UTC (rev 156337)
+++ trunk/Source/WebCore/dom/Document.cpp	2013-09-24 17:51:16 UTC (rev 156338)
@@ -5803,13 +5803,13 @@
     frame()->loader().checkLoadComplete();
 }
 
-static RenderObject* nearestCommonHoverAncestor(RenderObject* obj1, RenderObject* obj2)
+static RenderElement* nearestCommonHoverAncestor(RenderElement* obj1, RenderElement* obj2)
 {
     if (!obj1 || !obj2)
         return 0;
 
-    for (RenderObject* currObj1 = obj1; currObj1; currObj1 = currObj1->hoverAncestor()) {
-        for (RenderObject* currObj2 = obj2; currObj2; currObj2 = currObj2->hoverAncestor()) {
+    for (RenderElement* currObj1 = obj1; currObj1; currObj1 = currObj1->hoverAncestor()) {
+        for (RenderElement* currObj2 = obj2; currObj2; currObj2 = currObj2->hoverAncestor()) {
             if (currObj1 == currObj2)
                 return currObj1;
         }
@@ -5831,10 +5831,10 @@
     Element* oldActiveElement = m_activeElement.get();
     if (oldActiveElement && !request.active()) {
         // We are clearing the :active chain because the mouse has been released.
-        for (RenderObject* curr = oldActiveElement->renderer(); curr; curr = curr->parent()) {
-            if (!curr->node() || !curr->node()->isElementNode())
+        for (RenderElement* curr = oldActiveElement->renderer(); curr; curr = curr->parent()) {
+            Element* element = curr->element();
+            if (!element)
                 continue;
-            Element* element = toElement(curr->node());
             element->setActive(false);
             m_userActionElements.setInActiveChain(element, false);
         }
@@ -5844,10 +5844,11 @@
         if (!oldActiveElement && newActiveElement && request.active() && !request.touchMove()) {
             // We are setting the :active chain and freezing it. If future moves happen, they
             // will need to reference this chain.
-            for (RenderObject* curr = newActiveElement->renderer(); curr; curr = curr->parent()) {
-                if (!curr->node() || !curr->node()->isElementNode() || curr->isTextOrLineBreak())
+            for (RenderElement* curr = newActiveElement->renderer(); curr; curr = curr->parent()) {
+                Element* element = curr->element();
+                if (!element || curr->isTextOrLineBreak())
                     continue;
-                m_userActionElements.setInActiveChain(toElement(curr->node()), true);
+                m_userActionElements.setInActiveChain(element, true);
             }
 
             m_activeElement = newActiveElement;
@@ -5864,10 +5865,10 @@
 
     RefPtr<Element> oldHoveredElement = m_hoveredElement.release();
 
-    // A touch release does not set a new hover target; setting the element we're working with to 0
+    // A touch release does not set a new hover target; clearing the element we're working with
     // will clear the chain of hovered elements all the way to the top of the tree.
     if (request.touchRelease())
-        innerElementInDocument = 0;
+        innerElementInDocument = nullptr;
 
     // Check to see if the hovered Element has changed.
     // If it hasn't, we do not need to do anything.
@@ -5878,11 +5879,11 @@
     m_hoveredElement = newHoveredElement;
 
     // We have two different objects. Fetch their renderers.
-    RenderObject* oldHoverObj = oldHoveredElement ? oldHoveredElement->renderer() : 0;
-    RenderObject* newHoverObj = newHoveredElement ? newHoveredElement->renderer() : 0;
+    RenderElement* oldHoverObj = oldHoveredElement ? oldHoveredElement->renderer() : nullptr;
+    RenderElement* newHoverObj = newHoveredElement ? newHoveredElement->renderer() : nullptr;
 
     // Locate the common ancestor render object for the two renderers.
-    RenderObject* ancestor = nearestCommonHoverAncestor(oldHoverObj, newHoverObj);
+    RenderElement* ancestor = nearestCommonHoverAncestor(oldHoverObj, newHoverObj);
 
     Vector<RefPtr<Element>, 32> elementsToRemoveFromChain;
     Vector<RefPtr<Element>, 32> elementsToAddToChain;
@@ -5893,13 +5894,13 @@
     bool hasCapturingMouseEnterListener = false;
     bool hasCapturingMouseLeaveListener = false;
     if (event && newHoveredElement != oldHoveredElement.get()) {
-        for (Node* curr = newHoveredElement; curr; curr = curr->parentOrShadowHostNode()) {
+        for (ContainerNode* curr = newHoveredElement; curr; curr = curr->parentOrShadowHostNode()) {
             if (curr->hasCapturingEventListeners(eventNames().mouseenterEvent)) {
                 hasCapturingMouseEnterListener = true;
                 break;
             }
         }
-        for (Node* curr = oldHoveredElement.get(); curr; curr = curr->parentOrShadowHostNode()) {
+        for (ContainerNode* curr = oldHoveredElement.get(); curr; curr = curr->parentOrShadowHostNode()) {
             if (curr->hasCapturingEventListeners(eventNames().mouseleaveEvent)) {
                 hasCapturingMouseLeaveListener = true;
                 break;
@@ -5912,32 +5913,32 @@
         // (for instance by setting display:none in the :hover pseudo-class). In this case, the old hovered element (and its ancestors)
         // must be updated, to ensure it's normal style is re-applied.
         if (oldHoveredElement && !oldHoverObj) {
-            for (Element* element= oldHoveredElement.get(); element; element = element->parentElement()) {
+            for (Element* element = oldHoveredElement.get(); element; element = element->parentElement()) {
                 if (!mustBeInActiveChain || element->inActiveChain())
                     elementsToRemoveFromChain.append(element);
             }
         }
 
         // The old hover path only needs to be cleared up to (and not including) the common ancestor;
-        for (RenderObject* curr = oldHoverObj; curr && curr != ancestor; curr = curr->hoverAncestor()) {
-            if (!curr->node() || !curr->node()->isElementNode())
+        for (RenderElement* curr = oldHoverObj; curr && curr != ancestor; curr = curr->hoverAncestor()) {
+            Element* element = curr->element();
+            if (!element)
                 continue;
-            Element* element = toElement(curr->node());
             if (!mustBeInActiveChain || element->inActiveChain())
                 elementsToRemoveFromChain.append(element);
         }
         // Unset hovered nodes in sub frame documents if the old hovered node was a frame owner.
         if (oldHoveredElement && oldHoveredElement->isFrameOwnerElement()) {
             if (Document* contentDocument = toFrameOwnerElement(oldHoveredElement.get())->contentDocument())
-                contentDocument->updateHoverActiveState(request, 0, event);
+                contentDocument->updateHoverActiveState(request, nullptr, event);
         }
     }
 
     // Now set the hover state for our new object up to the root.
-    for (RenderObject* curr = newHoverObj; curr; curr = curr->hoverAncestor()) {
-        if (!curr->node() || !curr->node()->isElementNode())
+    for (RenderElement* curr = newHoverObj; curr; curr = curr->hoverAncestor()) {
+        Element* element = curr->element();
+        if (!element)
             continue;
-        Element* element = toElement(curr->node());
         if (!mustBeInActiveChain || element->inActiveChain())
             elementsToAddToChain.append(element);
     }
@@ -5953,7 +5954,7 @@
     for (size_t i = 0, size = elementsToAddToChain.size(); i < size; ++i) {
         if (allowActiveChanges)
             elementsToAddToChain[i]->setActive(true);
-        if (ancestor && elementsToAddToChain[i] == ancestor->node())
+        if (ancestor && elementsToAddToChain[i] == ancestor->element())
             sawCommonAncestor = true;
         if (!sawCommonAncestor) {
             // Elements after the common hover ancestor does not change hover state, but are iterated over because they may change active state.

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (156337 => 156338)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2013-09-24 17:12:37 UTC (rev 156337)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2013-09-24 17:51:16 UTC (rev 156338)
@@ -6227,7 +6227,7 @@
     return r;
 }
 
-RenderObject* RenderBlock::hoverAncestor() const
+RenderElement* RenderBlock::hoverAncestor() const
 {
     return isAnonymousBlockContinuation() ? continuation() : RenderBox::hoverAncestor();
 }

Modified: trunk/Source/WebCore/rendering/RenderBlock.h (156337 => 156338)


--- trunk/Source/WebCore/rendering/RenderBlock.h	2013-09-24 17:12:37 UTC (rev 156337)
+++ trunk/Source/WebCore/rendering/RenderBlock.h	2013-09-24 17:51:16 UTC (rev 156338)
@@ -706,7 +706,7 @@
     virtual LayoutRect rectWithOutlineForRepaint(const RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const OVERRIDE FINAL;
     virtual RenderStyle* outlineStyleForRepaint() const OVERRIDE FINAL;
     
-    virtual RenderObject* hoverAncestor() const OVERRIDE FINAL;
+    virtual RenderElement* hoverAncestor() const OVERRIDE FINAL;
     virtual void updateDragState(bool dragOn) OVERRIDE FINAL;
     virtual void childBecameNonInline(RenderObject* child) OVERRIDE FINAL;
 

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (156337 => 156338)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2013-09-24 17:12:37 UTC (rev 156337)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2013-09-24 17:51:16 UTC (rev 156338)
@@ -929,4 +929,30 @@
     return this;
 }
 
+RenderElement* RenderElement::hoverAncestor() const
+{
+    // When searching for the hover ancestor and encountering a named flow thread,
+    // the search will continue with the DOM ancestor of the top-most element
+    // in the named flow thread.
+    // See https://bugs.webkit.org/show_bug.cgi?id=111749
+    RenderElement* hoverAncestor = parent();
+
+    // Skip anonymous blocks directly flowed into flow threads as it would
+    // prevent us from continuing the search on the DOM tree when reaching the named flow thread.
+    if (hoverAncestor && hoverAncestor->isAnonymousBlock() && hoverAncestor->parent() && hoverAncestor->parent()->isRenderNamedFlowThread())
+        hoverAncestor = hoverAncestor->parent();
+
+    if (hoverAncestor && hoverAncestor->isRenderNamedFlowThread()) {
+        hoverAncestor = nullptr;
+
+        if (Element* element = this->element()) {
+            ContainerNode* domAncestorNode = element->parentNode();
+            if (domAncestorNode)
+                hoverAncestor = toRenderElement(domAncestorNode->renderer());
+        }
+    }
+
+    return hoverAncestor;
 }
+
+}

Modified: trunk/Source/WebCore/rendering/RenderElement.h (156337 => 156338)


--- trunk/Source/WebCore/rendering/RenderElement.h	2013-09-24 17:12:37 UTC (rev 156337)
+++ trunk/Source/WebCore/rendering/RenderElement.h	2013-09-24 17:51:16 UTC (rev 156338)
@@ -60,6 +60,8 @@
     void insertChildInternal(RenderObject*, RenderObject* beforeChild, NotifyChildrenType);
     void removeChildInternal(RenderObject*, NotifyChildrenType);
 
+    virtual RenderElement* hoverAncestor() const;
+
     // Return the renderer whose background style is used to paint the root background. Should only be called on the renderer for which isRoot() is true.
     RenderElement* rendererForRootBackground();
 

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (156337 => 156338)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2013-09-24 17:12:37 UTC (rev 156337)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2013-09-24 17:51:16 UTC (rev 156338)
@@ -2549,34 +2549,7 @@
 {
     imageChanged(static_cast<WrappedImagePtr>(image), rect);
 }
-    
-RenderObject* RenderObject::hoverAncestor() const
-{
-    // When searching for the hover ancestor and encountering a named flow thread,
-    // the search will continue with the DOM ancestor of the top-most element
-    // in the named flow thread.
-    // See https://bugs.webkit.org/show_bug.cgi?id=111749
-    RenderObject* hoverAncestor = parent();
-    
-    // Skip anonymous blocks directly flowed into flow threads as it would
-    // prevent us from continuing the search on the DOM tree when reaching the named flow thread.
-    if (hoverAncestor && hoverAncestor->isAnonymousBlock() && hoverAncestor->parent() && hoverAncestor->parent()->isRenderNamedFlowThread())
-        hoverAncestor = hoverAncestor->parent();
 
-    if (hoverAncestor && hoverAncestor->isRenderNamedFlowThread()) {
-        hoverAncestor = 0;
-        
-        Node* node = this->node();
-        if (node) {
-            Node* domAncestorNode = node->parentNode();
-            if (domAncestorNode)
-                hoverAncestor = domAncestorNode->renderer();
-        }
-    }
-    
-    return hoverAncestor;
-}
-
 RenderBoxModelObject* RenderObject::offsetParent() const
 {
     // If any of the following holds true return null and stop this algorithm:

Modified: trunk/Source/WebCore/rendering/RenderObject.h (156337 => 156338)


--- trunk/Source/WebCore/rendering/RenderObject.h	2013-09-24 17:12:37 UTC (rev 156337)
+++ trunk/Source/WebCore/rendering/RenderObject.h	2013-09-24 17:51:16 UTC (rev 156338)
@@ -632,8 +632,6 @@
     // is true if the renderer returned is an ancestor of repaintContainer.
     RenderElement* container(const RenderLayerModelObject* repaintContainer = 0, bool* repaintContainerSkipped = 0) const;
 
-    virtual RenderObject* hoverAncestor() const;
-
     RenderBoxModelObject* offsetParent() const;
 
     void markContainingBlocksForLayout(bool scheduleRelayout = true, RenderObject* newRoot = 0);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to