Add a Document::updateStyleIfNeededForNode(Node&).
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Mar 2014 22:23:13 +0000 (22:23 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Mar 2014 22:23:13 +0000 (22:23 +0000)
<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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@165076 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/editing/htmlediting.cpp
Source/WebCore/html/HTMLInputElement.cpp

index a44856de84da97545bf20cb55624673e19600f6d..21b81a4065ed2c3fc578f531b3ca13f47470316d 100644 (file)
@@ -1,3 +1,24 @@
+2014-03-04  Andreas Kling  <akling@apple.com>
+
+        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  <mhahnenberg@apple.com>
 
         Merge API shims and JSLock
index 867f9210a68fd9d8e5f58e26c32e51068930b6d0..e9eb505a42b0eba36c7b3325c7891068f0fc67d0 100644 (file)
@@ -1609,17 +1609,6 @@ PassRef<MutableStyleProperties> CSSComputedStyleDeclaration::copyProperties() co
     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 @@ PassRefPtr<CSSValue> ComputedStyleExtractor::propertyValue(CSSPropertyID propert
     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();
index 0bf9137b22348401a9b6d50acda40d4dceca1742..0c72ba488d8822898a7eac3ad798d1c05badff0f 100644 (file)
@@ -6049,4 +6049,21 @@ bool Document::unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t
 }
 #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
index 41e821572a39c15606307e5cfc781c2bb27e850d..14da1b2a10331e9b7290c641c0660a3ea5fbb682 100644 (file)
@@ -589,6 +589,7 @@ public:
 
     void recalcStyle(Style::Change = Style::NoChange);
     void updateStyleIfNeeded();
+    bool updateStyleIfNeededForNode(const Node&);
     void updateLayout();
     void updateLayoutIgnorePendingStylesheets();
     PassRef<RenderStyle> styleForElementIgnoringPendingStylesheets(Element*);
index 050583dc9932a4bb34ce9e65b2c5f5d695e640db..4cbd6ff3fc1f024242280893cee02dec92f96f01 100644 (file)
@@ -146,7 +146,7 @@ bool isEditablePosition(const Position& p, EditableType editableType, EUpdateSty
     if (!node)
         return false;
     if (updateStyle == UpdateStyle)
-        node->document().updateStyleIfNeeded();
+        node->document().updateStyleIfNeededForNode(*node);
     else
         ASSERT(updateStyle == DoNotUpdateStyle);
 
index 18d04f9df30416baa3edb7dd902ee2324adf480c..f8c9777199e7688d4813bc5ab5888f2fb6667d8e 100644 (file)
@@ -1176,7 +1176,7 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
             return;
     }
 
-    document().updateStyleIfNeeded();
+    document().updateStyleIfNeededForNode(*this);
     m_inputType->forwardEvent(evt);
 
     if (!callBaseClassEarly && !evt->defaultHandled())