Title: [165076] trunk/Source/WebCore
Revision
165076
Author
[email protected]
Date
2014-03-04 14:23:13 -0800 (Tue, 04 Mar 2014)

Log Message

Add a Document::updateStyleIfNeededForNode(Node&).
<https://webkit.org/b/129689>

Generalize the mechanism that computed style uses to avoid doing full
style updates when the node we're interested in isn't actually dirty.

Reviewed by Antti Koivisto.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::propertyValue):
* dom/Document.cpp:
(WebCore::nodeOrItsAncestorNeedsStyleRecalc):
(WebCore::Document::updateStyleIfNeededForNode):
* dom/Document.h:
* editing/htmlediting.cpp:
(WebCore::isEditablePosition):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::defaultEventHandler):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (165075 => 165076)


--- trunk/Source/WebCore/ChangeLog	2014-03-04 22:15:16 UTC (rev 165075)
+++ trunk/Source/WebCore/ChangeLog	2014-03-04 22:23:13 UTC (rev 165076)
@@ -1,3 +1,24 @@
+2014-03-04  Andreas Kling  <[email protected]>
+
+        Add a Document::updateStyleIfNeededForNode(Node&).
+        <https://webkit.org/b/129689>
+
+        Generalize the mechanism that computed style uses to avoid doing full
+        style updates when the node we're interested in isn't actually dirty.
+
+        Reviewed by Antti Koivisto.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::propertyValue):
+        * dom/Document.cpp:
+        (WebCore::nodeOrItsAncestorNeedsStyleRecalc):
+        (WebCore::Document::updateStyleIfNeededForNode):
+        * dom/Document.h:
+        * editing/htmlediting.cpp:
+        (WebCore::isEditablePosition):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::defaultEventHandler):
+
 2014-03-04  Mark Hahnenberg  <[email protected]>
 
         Merge API shims and JSLock

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (165075 => 165076)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2014-03-04 22:15:16 UTC (rev 165075)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2014-03-04 22:23:13 UTC (rev 165076)
@@ -1609,17 +1609,6 @@
     return ComputedStyleExtractor(m_node, m_allowVisitedStyle, m_pseudoElementSpecifier).copyProperties();
 }
 
-static inline bool nodeOrItsAncestorNeedsStyleRecalc(Node* styledNode)
-{
-    if (styledNode->document().hasPendingForcedStyleRecalc())
-        return true;
-    for (Node* n = styledNode; n; n = n->parentNode()) {// FIXME: Call parentOrShadowHostNode() instead
-        if (n->needsStyleRecalc())
-            return true;
-    }
-    return false;
-}
-
 static inline PassRefPtr<RenderStyle> computeRenderStyleForProperty(Node* styledNode, PseudoId pseudoElementSpecifier, CSSPropertyID propertyID)
 {
     RenderObject* renderer = styledNode->renderer();
@@ -1674,8 +1663,7 @@
     if (updateLayout) {
         Document& document = styledNode->document();
 
-        if (nodeOrItsAncestorNeedsStyleRecalc(styledNode)) {
-            document.updateStyleIfNeeded();
+        if (document.updateStyleIfNeededForNode(*styledNode)) {
             // The style recalc could have caused the styled node to be discarded or replaced
             // if it was a PseudoElement so we need to update it.
             styledNode = this->styledNode();

Modified: trunk/Source/WebCore/dom/Document.cpp (165075 => 165076)


--- trunk/Source/WebCore/dom/Document.cpp	2014-03-04 22:15:16 UTC (rev 165075)
+++ trunk/Source/WebCore/dom/Document.cpp	2014-03-04 22:23:13 UTC (rev 165076)
@@ -6049,4 +6049,21 @@
 }
 #endif // ENABLE(SUBTLE_CRYPTO)
 
+static inline bool nodeOrItsAncestorNeedsStyleRecalc(const Node& node)
+{
+    for (const Node* n = &node; n; n = n->parentOrShadowHostElement()) {
+        if (n->needsStyleRecalc())
+            return true;
+    }
+    return false;
+}
+
+bool Document::updateStyleIfNeededForNode(const Node& node)
+{
+    if (!hasPendingForcedStyleRecalc() && !nodeOrItsAncestorNeedsStyleRecalc(node))
+        return false;
+    updateStyleIfNeeded();
+    return true;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/Document.h (165075 => 165076)


--- trunk/Source/WebCore/dom/Document.h	2014-03-04 22:15:16 UTC (rev 165075)
+++ trunk/Source/WebCore/dom/Document.h	2014-03-04 22:23:13 UTC (rev 165076)
@@ -589,6 +589,7 @@
 
     void recalcStyle(Style::Change = Style::NoChange);
     void updateStyleIfNeeded();
+    bool updateStyleIfNeededForNode(const Node&);
     void updateLayout();
     void updateLayoutIgnorePendingStylesheets();
     PassRef<RenderStyle> styleForElementIgnoringPendingStylesheets(Element*);

Modified: trunk/Source/WebCore/editing/htmlediting.cpp (165075 => 165076)


--- trunk/Source/WebCore/editing/htmlediting.cpp	2014-03-04 22:15:16 UTC (rev 165075)
+++ trunk/Source/WebCore/editing/htmlediting.cpp	2014-03-04 22:23:13 UTC (rev 165076)
@@ -146,7 +146,7 @@
     if (!node)
         return false;
     if (updateStyle == UpdateStyle)
-        node->document().updateStyleIfNeeded();
+        node->document().updateStyleIfNeededForNode(*node);
     else
         ASSERT(updateStyle == DoNotUpdateStyle);
 

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (165075 => 165076)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2014-03-04 22:15:16 UTC (rev 165075)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2014-03-04 22:23:13 UTC (rev 165076)
@@ -1176,7 +1176,7 @@
             return;
     }
 
-    document().updateStyleIfNeeded();
+    document().updateStyleIfNeededForNode(*this);
     m_inputType->forwardEvent(evt);
 
     if (!callBaseClassEarly && !evt->defaultHandled())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to