Title: [149532] trunk/Source
Revision
149532
Author
[email protected]
Date
2013-05-03 13:43:27 -0700 (Fri, 03 May 2013)

Log Message

StyleResolver: Have "list of matched rules" API vend internal types instead of CSSOM wrappers.
<http://webkit.org/b/115563>

Reviewed by Antti Koivisto.

Source/WebCore:

Change styleRulesForElement() and pseudoStyleRulesForElement() to return Vectors of StyleRuleBase
instead of CSSRuleLists. This defers instantiating CSSOM wrappers until they're actually needed
for exposure to web API.

* page/DOMWindow.cpp:
(WebCore::DOMWindow::getMatchedCSSRules):

    Create a StaticCSSRuleList and populate it with CSSOM wrappers for the matched rules.
    This is the one place where we expose this functionality to the web.

* css/ElementRuleCollector.h:
* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::matchedRuleList):
(WebCore::ElementRuleCollector::sortAndTransferMatchedRules):

    Collect internal StyleRuleBase pointers here instead of creating wrappers.

* css/StyleResolver.h:
* css/StyleResolver.cpp:
(WebCore::StyleResolver::styleRulesForElement):
(WebCore::StyleResolver::pseudoStyleRulesForElement):

    Vend said pointers.

* editing/EditingStyle.cpp:
(WebCore::styleFromMatchedRulesForElement):

    Dodge CSSOM wrapper instantiation (Woop woop!)

* inspector/InspectorCSSAgent.h:
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::buildObjectForRule):

    Split buildObjectForRule() into two versions, one for CSSStyleRule and one for StyleRule.
    The CSSStyleRule one doesn't need a special path for parent-less rules, since those always
    come in through the StyleRule interface instead. This factoring can be improved further
    after this change.

(WebCore::InspectorCSSAgent::getMatchedStylesForNode):
(WebCore::InspectorCSSAgent::buildArrayForRuleList):
(WebCore::InspectorCSSAgent::buildArrayForMatchedRuleList):

    Tweaked for changes in StyleResolver API.

Source/WebKit/qt:

* Api/qwebelement.cpp:
(QWebElement::styleProperty):

    Tweaked for changes in StyleResolver API.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149531 => 149532)


--- trunk/Source/WebCore/ChangeLog	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebCore/ChangeLog	2013-05-03 20:43:27 UTC (rev 149532)
@@ -1,3 +1,54 @@
+2013-05-03  Andreas Kling  <[email protected]>
+
+        StyleResolver: Have "list of matched rules" API vend internal types instead of CSSOM wrappers.
+        <http://webkit.org/b/115563>
+
+        Reviewed by Antti Koivisto.
+
+        Change styleRulesForElement() and pseudoStyleRulesForElement() to return Vectors of StyleRuleBase
+        instead of CSSRuleLists. This defers instantiating CSSOM wrappers until they're actually needed
+        for exposure to web API.
+
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::getMatchedCSSRules):
+
+            Create a StaticCSSRuleList and populate it with CSSOM wrappers for the matched rules.
+            This is the one place where we expose this functionality to the web.
+
+        * css/ElementRuleCollector.h:
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::matchedRuleList):
+        (WebCore::ElementRuleCollector::sortAndTransferMatchedRules):
+
+            Collect internal StyleRuleBase pointers here instead of creating wrappers.
+
+        * css/StyleResolver.h:
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::styleRulesForElement):
+        (WebCore::StyleResolver::pseudoStyleRulesForElement):
+
+            Vend said pointers.
+
+        * editing/EditingStyle.cpp:
+        (WebCore::styleFromMatchedRulesForElement):
+
+            Dodge CSSOM wrapper instantiation (Woop woop!)
+
+        * inspector/InspectorCSSAgent.h:
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::buildObjectForRule):
+
+            Split buildObjectForRule() into two versions, one for CSSStyleRule and one for StyleRule.
+            The CSSStyleRule one doesn't need a special path for parent-less rules, since those always
+            come in through the StyleRule interface instead. This factoring can be improved further
+            after this change.
+
+        (WebCore::InspectorCSSAgent::getMatchedStylesForNode):
+        (WebCore::InspectorCSSAgent::buildArrayForRuleList):
+        (WebCore::InspectorCSSAgent::buildArrayForMatchedRuleList):
+
+            Tweaked for changes in StyleResolver API.
+
 2013-05-03  Alexey Proskuryakov  <[email protected]>
 
         REGRESSION (r145042): Downloading a file sometimes results in could not create

Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (149531 => 149532)


--- trunk/Source/WebCore/css/ElementRuleCollector.cpp	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp	2013-05-03 20:43:27 UTC (rev 149532)
@@ -68,10 +68,10 @@
     return m_result;
 }
 
-PassRefPtr<CSSRuleList> ElementRuleCollector::matchedRuleList()
+const Vector<RefPtr<StyleRuleBase> >& ElementRuleCollector::matchedRuleList() const
 {
     ASSERT(m_mode == SelectorChecker::CollectingRules);
-    return m_ruleList.release();
+    return m_matchedRuleList;
 }
 
 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule)
@@ -88,13 +88,6 @@
     m_matchedRules->clear();
 }
 
-inline StaticCSSRuleList* ElementRuleCollector::ensureRuleList()
-{
-    if (!m_ruleList)
-        m_ruleList = StaticCSSRuleList::create();
-    return m_ruleList.get();
-}
-
 inline void ElementRuleCollector::addElementStyleProperties(const StylePropertySet* propertySet, bool isCacheable)
 {
     if (!propertySet)
@@ -210,7 +203,7 @@
     Vector<const RuleData*, 32>& matchedRules = *m_matchedRules;
     if (m_mode == SelectorChecker::CollectingRules) {
         for (unsigned i = 0; i < matchedRules.size(); ++i)
-            ensureRuleList()->rules().append(matchedRules[i]->rule()->createCSSOMWrapper());
+            m_matchedRuleList.append(matchedRules[i]->rule());
         return;
     }
 

Modified: trunk/Source/WebCore/css/ElementRuleCollector.h (149531 => 149532)


--- trunk/Source/WebCore/css/ElementRuleCollector.h	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebCore/css/ElementRuleCollector.h	2013-05-03 20:43:27 UTC (rev 149532)
@@ -30,14 +30,12 @@
 
 namespace WebCore {
 
-class CSSRuleList;
 class DocumentRuleSets;
 class RenderRegion;
 class RuleData;
 class RuleSet;
 class SelectorFilter;
 class StyleScopeResolver;
-class StaticCSSRuleList;
 
 class ElementRuleCollector {
 public:
@@ -69,7 +67,7 @@
     bool hasAnyMatchingRules(RuleSet*);
 
     StyleResolver::MatchResult& matchedResult();
-    PassRefPtr<CSSRuleList> matchedRuleList();
+    const Vector<RefPtr<StyleRuleBase> >& matchedRuleList() const;
 
 private:
     Document* document() { return m_state.document(); }
@@ -92,8 +90,6 @@
 
     void addMatchedRule(const RuleData*);
     void clearMatchedRules();
-
-    StaticCSSRuleList* ensureRuleList();
         
 private:
     const StyleResolver::State& m_state;
@@ -113,7 +109,7 @@
     OwnPtr<Vector<const RuleData*, 32> > m_matchedRules;
 
     // Output.
-    RefPtr<StaticCSSRuleList> m_ruleList;
+    Vector<RefPtr<StyleRuleBase> > m_matchedRuleList;
     StyleResolver::MatchResult m_result;
 };
 

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (149531 => 149532)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2013-05-03 20:43:27 UTC (rev 149532)
@@ -1630,15 +1630,15 @@
     m_state.setFontDirty(false);
 }
 
-PassRefPtr<CSSRuleList> StyleResolver::styleRulesForElement(Element* e, unsigned rulesToInclude)
+Vector<RefPtr<StyleRuleBase> > StyleResolver::styleRulesForElement(Element* e, unsigned rulesToInclude)
 {
     return pseudoStyleRulesForElement(e, NOPSEUDO, rulesToInclude);
 }
 
-PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, PseudoId pseudoId, unsigned rulesToInclude)
+Vector<RefPtr<StyleRuleBase> > StyleResolver::pseudoStyleRulesForElement(Element* e, PseudoId pseudoId, unsigned rulesToInclude)
 {
     if (!e || !e->document()->haveStylesheetsLoaded())
-        return 0;
+        return Vector<RefPtr<StyleRuleBase> >();
 
     initElement(e);
     m_state.initForStyleResolve(document(), e, 0);

Modified: trunk/Source/WebCore/css/StyleResolver.h (149531 => 149532)


--- trunk/Source/WebCore/css/StyleResolver.h	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebCore/css/StyleResolver.h	2013-05-03 20:43:27 UTC (rev 149532)
@@ -22,7 +22,6 @@
 #ifndef StyleResolver_h
 #define StyleResolver_h
 
-#include "CSSRuleList.h"
 #include "CSSToStyleMap.h"
 #include "CSSValueList.h"
 #include "DocumentRuleSets.h"
@@ -66,7 +65,6 @@
 class CSSPageRule;
 class CSSPrimitiveValue;
 class CSSProperty;
-class CSSRuleList;
 class CSSSelector;
 class CSSStyleSheet;
 class CSSValue;
@@ -91,7 +89,6 @@
 class RuleData;
 class RuleSet;
 class Settings;
-class StaticCSSRuleList;
 class StyleCustomFilterProgramCache;
 class StyleScopeResolver;
 class StyleImage;
@@ -251,8 +248,8 @@
         AllButEmptyCSSRules = UAAndUserCSSRules | AuthorCSSRules | CrossOriginCSSRules,
         AllCSSRules         = AllButEmptyCSSRules | EmptyCSSRules,
     };
-    PassRefPtr<CSSRuleList> styleRulesForElement(Element*, unsigned rulesToInclude = AllButEmptyCSSRules);
-    PassRefPtr<CSSRuleList> pseudoStyleRulesForElement(Element*, PseudoId, unsigned rulesToInclude = AllButEmptyCSSRules);
+    Vector<RefPtr<StyleRuleBase> > styleRulesForElement(Element*, unsigned rulesToInclude = AllButEmptyCSSRules);
+    Vector<RefPtr<StyleRuleBase> > pseudoStyleRulesForElement(Element*, PseudoId, unsigned rulesToInclude = AllButEmptyCSSRules);
 
     // Given a CSS keyword in the range (xx-small to -webkit-xxx-large), this function will return
     // the correct font size scaled relative to the user's default (medium).

Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (149531 => 149532)


--- trunk/Source/WebCore/editing/EditingStyle.cpp	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp	2013-05-03 20:43:27 UTC (rev 149532)
@@ -1076,12 +1076,10 @@
 static PassRefPtr<MutableStylePropertySet> styleFromMatchedRulesForElement(Element* element, unsigned rulesToInclude)
 {
     RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
-    RefPtr<CSSRuleList> matchedRules = element->document()->ensureStyleResolver()->styleRulesForElement(element, rulesToInclude);
-    if (matchedRules) {
-        for (unsigned i = 0; i < matchedRules->length(); i++) {
-            if (matchedRules->item(i)->type() == CSSRule::STYLE_RULE)
-                style->mergeAndOverrideOnConflict(static_cast<CSSStyleRule*>(matchedRules->item(i))->styleRule()->properties());
-        }
+    Vector<RefPtr<StyleRuleBase> > matchedRules = element->document()->ensureStyleResolver()->styleRulesForElement(element, rulesToInclude);
+    for (unsigned i = 0; i < matchedRules.size(); ++i) {
+        if (matchedRules[i]->isStyleRule())
+            style->mergeAndOverrideOnConflict(static_pointer_cast<StyleRule>(matchedRules[i])->properties());
     }
     
     return style.release();

Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (149531 => 149532)


--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp	2013-05-03 20:43:27 UTC (rev 149532)
@@ -735,18 +735,18 @@
 
     // Matched rules.
     StyleResolver* styleResolver = element->ownerDocument()->ensureStyleResolver();
-    RefPtr<CSSRuleList> matchedRules = styleResolver->styleRulesForElement(element, StyleResolver::AllCSSRules);
-    matchedCSSRules = buildArrayForMatchedRuleList(matchedRules.get(), styleResolver, element);
+    Vector<RefPtr<StyleRuleBase> > matchedRules = styleResolver->styleRulesForElement(element, StyleResolver::AllCSSRules);
+    matchedCSSRules = buildArrayForMatchedRuleList(matchedRules, styleResolver, element);
 
     // Pseudo elements.
     if (!includePseudo || *includePseudo) {
         RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches> > pseudoElements = TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches>::create();
         for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < AFTER_LAST_INTERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) {
-            RefPtr<CSSRuleList> matchedRules = styleResolver->pseudoStyleRulesForElement(element, pseudoId, StyleResolver::AllCSSRules);
-            if (matchedRules && matchedRules->length()) {
+            Vector<RefPtr<StyleRuleBase> > matchedRules = styleResolver->pseudoStyleRulesForElement(element, pseudoId, StyleResolver::AllCSSRules);
+            if (!matchedRules.isEmpty()) {
                 RefPtr<TypeBuilder::CSS::PseudoIdMatches> matches = TypeBuilder::CSS::PseudoIdMatches::create()
                     .setPseudoId(static_cast<int>(pseudoId))
-                    .setMatches(buildArrayForMatchedRuleList(matchedRules.get(), styleResolver, element));
+                    .setMatches(buildArrayForMatchedRuleList(matchedRules, styleResolver, element));
                 pseudoElements->addItem(matches.release());
             }
         }
@@ -760,9 +760,9 @@
         Element* parentElement = element->parentElement();
         while (parentElement) {
             StyleResolver* parentStyleResolver = parentElement->ownerDocument()->ensureStyleResolver();
-            RefPtr<CSSRuleList> parentMatchedRules = parentStyleResolver->styleRulesForElement(parentElement, StyleResolver::AllCSSRules);
+            Vector<RefPtr<StyleRuleBase> > parentMatchedRules = parentStyleResolver->styleRulesForElement(parentElement, StyleResolver::AllCSSRules);
             RefPtr<TypeBuilder::CSS::InheritedStyleEntry> entry = TypeBuilder::CSS::InheritedStyleEntry::create()
-                .setMatchedCSSRules(buildArrayForMatchedRuleList(parentMatchedRules.get(), styleResolver, parentElement));
+                .setMatchedCSSRules(buildArrayForMatchedRuleList(parentMatchedRules, styleResolver, parentElement));
             if (parentElement->style() && parentElement->style()->length()) {
                 InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(parentElement);
                 if (styleSheet)
@@ -1192,24 +1192,31 @@
     return origin;
 }
 
-PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorCSSAgent::buildObjectForRule(CSSStyleRule* rule, StyleResolver* styleResolver)
+PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorCSSAgent::buildObjectForRule(StyleRule* styleRule, StyleResolver* styleResolver)
 {
+    if (!styleRule)
+        return 0;
+
+    // StyleRules returned by StyleResolver::styleRulesForElement lack parent pointers since that infomation is not cheaply available.
+    // Since the inspector wants to walk the parent chain, we construct the full wrappers here.
+    CSSStyleRule* cssomWrapper = styleResolver->inspectorCSSOMWrappers().getWrapperForRuleInSheets(styleRule, styleResolver->document()->styleSheetCollection());
+    if (!cssomWrapper)
+        return 0;
+    InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(cssomWrapper->parentStyleSheet());
+    return inspectorStyleSheet ? inspectorStyleSheet->buildObjectForRule(cssomWrapper) : 0;
+}
+
+PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorCSSAgent::buildObjectForRule(CSSStyleRule* rule)
+{
     if (!rule)
         return 0;
 
-    // CSSRules returned by StyleResolver::styleRulesForElement lack parent pointers since that infomation is not cheaply available.
-    // Since the inspector wants to walk the parent chain, we construct the full wrappers here.
-    // FIXME: This could be factored better. StyleResolver::styleRulesForElement should return a StyleRule vector, not a CSSRuleList.
-    if (!rule->parentStyleSheet()) {
-        rule = styleResolver->inspectorCSSOMWrappers().getWrapperForRuleInSheets(rule->styleRule(), styleResolver->document()->styleSheetCollection());
-        if (!rule)
-            return 0;
-    }
+    ASSERT(rule->parentStyleSheet());
     InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(rule->parentStyleSheet());
     return inspectorStyleSheet ? inspectorStyleSheet->buildObjectForRule(rule) : 0;
 }
 
-PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > InspectorCSSAgent::buildArrayForRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver)
+PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > InspectorCSSAgent::buildArrayForRuleList(CSSRuleList* ruleList)
 {
     RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > result = TypeBuilder::Array<TypeBuilder::CSS::CSSRule>::create();
     if (!ruleList)
@@ -1217,7 +1224,7 @@
 
     for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
         CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i));
-        RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule, styleResolver);
+        RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule);
         if (!ruleObject)
             continue;
         result->addItem(ruleObject);
@@ -1225,19 +1232,19 @@
     return result.release();
 }
 
-PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent::buildArrayForMatchedRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver, Element* element)
+PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent::buildArrayForMatchedRuleList(const Vector<RefPtr<StyleRuleBase> >& matchedRules, StyleResolver* styleResolver, Element* element)
 {
     RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilder::Array<TypeBuilder::CSS::RuleMatch>::create();
-    if (!ruleList)
-        return result.release();
 
-    for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
-        CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i));
-        RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule, styleResolver);
+    for (unsigned i = 0; i < matchedRules.size(); ++i) {
+        if (!matchedRules[i]->isStyleRule())
+            continue;
+        StyleRule* matchedStyleRule = static_cast<StyleRule*>(matchedRules[i].get());
+        RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(matchedStyleRule, styleResolver);
         if (!ruleObject)
             continue;
         RefPtr<TypeBuilder::Array<int> > matchingSelectors = TypeBuilder::Array<int>::create();
-        const CSSSelectorList& selectorList = rule->styleRule()->selectorList();
+        const CSSSelectorList& selectorList = matchedStyleRule->selectorList();
         long index = 0;
         for (const CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(selector)) {
             bool matched = element->webkitMatchesSelector(selector->selectorText(), IGNORE_EXCEPTION);
@@ -1251,7 +1258,7 @@
         result->addItem(match);
     }
 
-    return result;
+    return result.release();
 }
 
 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorCSSAgent::buildObjectForAttributesStyle(Element* element)

Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.h (149531 => 149532)


--- trunk/Source/WebCore/inspector/InspectorCSSAgent.h	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.h	2013-05-03 20:43:27 UTC (rev 149532)
@@ -161,9 +161,10 @@
     InspectorStyleSheet* assertStyleSheetForId(ErrorString*, const String&);
     TypeBuilder::CSS::StyleSheetOrigin::Enum detectOrigin(CSSStyleSheet* pageStyleSheet, Document* ownerDocument);
 
-    PassRefPtr<TypeBuilder::CSS::CSSRule> buildObjectForRule(CSSStyleRule*, StyleResolver*);
-    PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > buildArrayForRuleList(CSSRuleList*, StyleResolver*);
-    PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > buildArrayForMatchedRuleList(CSSRuleList*, StyleResolver*, Element*);
+    PassRefPtr<TypeBuilder::CSS::CSSRule> buildObjectForRule(StyleRule*, StyleResolver*);
+    PassRefPtr<TypeBuilder::CSS::CSSRule> buildObjectForRule(CSSStyleRule*);
+    PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > buildArrayForRuleList(CSSRuleList*);
+    PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > buildArrayForMatchedRuleList(const Vector<RefPtr<StyleRuleBase> >&, StyleResolver*, Element*);
     PassRefPtr<TypeBuilder::CSS::CSSStyle> buildObjectForAttributesStyle(Element*);
     PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::Region> > buildArrayForRegions(ErrorString*, PassRefPtr<NodeList>, int documentNodeId);
     PassRefPtr<TypeBuilder::CSS::NamedFlow> buildObjectForNamedFlow(ErrorString*, WebKitNamedFlow*, int documentNodeId);

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (149531 => 149532)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2013-05-03 20:43:27 UTC (rev 149532)
@@ -31,6 +31,7 @@
 #include "BarInfo.h"
 #include "BeforeUnloadEvent.h"
 #include "CSSComputedStyleDeclaration.h"
+#include "CSSRule.h"
 #include "CSSRuleList.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
@@ -1382,7 +1383,15 @@
 
     PseudoId pseudoId = CSSSelector::pseudoId(pseudoType);
 
-    return m_frame->document()->ensureStyleResolver()->pseudoStyleRulesForElement(element, pseudoId, rulesToInclude);
+    Vector<RefPtr<StyleRuleBase> > matchedRules = m_frame->document()->ensureStyleResolver()->pseudoStyleRulesForElement(element, pseudoId, rulesToInclude);
+    if (matchedRules.isEmpty())
+        return 0;
+
+    RefPtr<StaticCSSRuleList> ruleList = StaticCSSRuleList::create();
+    for (unsigned i = 0; i < matchedRules.size(); ++i)
+        ruleList->rules().append(matchedRules[i]->createCSSOMWrapper());
+
+    return ruleList.release();
 }
 
 PassRefPtr<WebKitPoint> DOMWindow::webkitConvertPointFromNodeToPage(Node* node, const WebKitPoint* p) const

Modified: trunk/Source/WebKit/qt/Api/qwebelement.cpp (149531 => 149532)


--- trunk/Source/WebKit/qt/Api/qwebelement.cpp	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebKit/qt/Api/qwebelement.cpp	2013-05-03 20:43:27 UTC (rev 149532)
@@ -829,16 +829,17 @@
         // declarations, as well as embedded and inline style declarations.
 
         Document* doc = m_element->document();
-        if (RefPtr<CSSRuleList> rules = doc->ensureStyleResolver()->styleRulesForElement(m_element, StyleResolver::AuthorCSSRules | StyleResolver::CrossOriginCSSRules)) {
-            for (int i = rules->length(); i > 0; --i) {
-                CSSStyleRule* rule = static_cast<CSSStyleRule*>(rules->item(i - 1));
+        Vector<RefPtr<StyleRuleBase> > rules = doc->ensureStyleResolver()->styleRulesForElement(m_element, StyleResolver::AuthorCSSRules | StyleResolver::CrossOriginCSSRules);
+        for (int i = rules.size(); i > 0; --i) {
+            if (!rules[i]->isStyleRule())
+                continue;
+            StyleRule* styleRule = static_cast<StyleRule*>(rules[i - 1].get());
 
-                if (rule->styleRule()->properties()->propertyIsImportant(propID))
-                    return rule->styleRule()->properties()->getPropertyValue(propID);
+            if (styleRule->properties()->propertyIsImportant(propID))
+                return styleRule->properties()->getPropertyValue(propID);
 
-                if (!style || style->getPropertyValue(propID).isEmpty())
-                    style = rule->styleRule()->properties();
-            }
+            if (!style || style->getPropertyValue(propID).isEmpty())
+                style = styleRule->properties();
         }
 
         if (!style)

Modified: trunk/Source/WebKit/qt/ChangeLog (149531 => 149532)


--- trunk/Source/WebKit/qt/ChangeLog	2013-05-03 20:29:53 UTC (rev 149531)
+++ trunk/Source/WebKit/qt/ChangeLog	2013-05-03 20:43:27 UTC (rev 149532)
@@ -1,3 +1,15 @@
+2013-05-03  Andreas Kling  <[email protected]>
+
+        StyleResolver: Have "list of matched rules" API vend internal types instead of CSSOM wrappers.
+        <http://webkit.org/b/115563>
+
+        Reviewed by Antti Koivisto.
+
+        * Api/qwebelement.cpp:
+        (QWebElement::styleProperty):
+
+            Tweaked for changes in StyleResolver API.
+
 2013-04-30  Andreas Kling  <[email protected]>
 
         Don't create StyleResolvers just to invalidate them.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to