Title: [130249] trunk/Source/WebCore
Revision
130249
Author
morr...@google.com
Date
2012-10-02 22:26:07 -0700 (Tue, 02 Oct 2012)

Log Message

https://bugs.webkit.org/show_bug.cgi?id=98134
[Refactoring] StyleResolver::matchScopedAuthorRules() could be simpler.

Reviewed by Dimitri Glazkov.

matchScopedAuthorRules() did have some optimization which only
makes sense for heavily nested shadow tree. However, we don't see
such type of usage of Shadow DOM and this looks premature
optimization. This change unified its triple for loop into one,
which makes the code much simpler.

No new tests. Covered by existing tests.

* css/StyleResolver.cpp:
(WebCore::StyleResolver::matchScopedAuthorRules):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (130248 => 130249)


--- trunk/Source/WebCore/ChangeLog	2012-10-03 05:12:10 UTC (rev 130248)
+++ trunk/Source/WebCore/ChangeLog	2012-10-03 05:26:07 UTC (rev 130249)
@@ -1,3 +1,21 @@
+2012-10-02  MORITA Hajime  <morr...@google.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=98134
+        [Refactoring] StyleResolver::matchScopedAuthorRules() could be simpler.
+
+        Reviewed by Dimitri Glazkov.
+
+        matchScopedAuthorRules() did have some optimization which only
+        makes sense for heavily nested shadow tree. However, we don't see
+        such type of usage of Shadow DOM and this looks premature
+        optimization. This change unified its triple for loop into one,
+        which makes the code much simpler.
+
+        No new tests. Covered by existing tests.
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::matchScopedAuthorRules):
+
 2012-10-02  Kent Tamura  <tk...@chromium.org>
 
         Introduce Localizer::dateTimeFormatWithSecond and dateTimeFormatWithoutSecond

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (130248 => 130249)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2012-10-03 05:12:10 UTC (rev 130248)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2012-10-03 05:26:07 UTC (rev 130249)
@@ -962,41 +962,31 @@
     if (m_scopedAuthorStyles.isEmpty())
         return;
 
-    MatchOptions options(includeEmptyRules);
-
     // Match scoped author rules by traversing the scoped element stack (rebuild it if it got inconsistent).
     if (!scopeStackIsConsistent(m_element))
         setupScopeStack(m_element);
-
-    unsigned int firstShadowScopeIndex = 0;
-    if (m_element->treeScope()->applyAuthorStyles()) {
-        unsigned i;
-        for (i = 0; i < m_scopeStack.size() && !m_scopeStack[i].m_scope->isInShadowTree(); ++i) {
-            const ScopeStackFrame& frame = m_scopeStack[i];
-            options.scope = frame.m_scope;
-            collectMatchingRules(frame.m_ruleSet, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
-            collectMatchingRulesForRegion(frame.m_ruleSet, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
-        }
-        firstShadowScopeIndex = i;
-    }
-
-    if (!m_element->isInShadowTree() || m_scopeStack.isEmpty())
+    if (m_scopeStack.isEmpty())
         return;
 
-    unsigned scopedIndex = m_scopeStack.size();
-    int authorStyleBoundsIndex = m_scopeStackParentBoundsIndex;
-    for ( ; scopedIndex > firstShadowScopeIndex; --scopedIndex) {
-        if (authorStyleBoundsIndex != m_scopeStack[scopedIndex - 1].m_authorStyleBoundsIndex)
-            break;
-    }
-
-    // Ruleset for ancestor nodes should be applied first.
-    for (unsigned i = scopedIndex; i < m_scopeStack.size(); ++i) {
+    bool applyAuthorStyles = m_element->treeScope()->applyAuthorStyles();
+    bool documentScope = true;
+    unsigned scopeSize = m_scopeStack.size();
+    for (unsigned i = 0; i < scopeSize; ++i) {
         const ScopeStackFrame& frame = m_scopeStack[i];
-        options.scope = frame.m_scope;
+        documentScope = documentScope && !frame.m_scope->isInShadowTree();
+        if (documentScope) {
+            if (!applyAuthorStyles)
+                continue;
+        } else {
+            if (frame.m_authorStyleBoundsIndex != m_scopeStackParentBoundsIndex)
+                continue;
+        }
+           
+        MatchOptions options(includeEmptyRules, frame.m_scope);
         collectMatchingRules(frame.m_ruleSet, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
         collectMatchingRulesForRegion(frame.m_ruleSet, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
     }
+
 #else
     UNUSED_PARAM(result);
     UNUSED_PARAM(includeEmptyRules);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to