Have CSS classes' methods return more references
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Sep 2014 01:45:40 +0000 (01:45 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Sep 2014 01:45:40 +0000 (01:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137036

Reviewed by Ryosuke Niwa.

Have CSS classes' methods return more references instead of pointers
when possible.

No new tests, no behavior change.

* css/CSSFontFaceRule.cpp:
(WebCore::CSSFontFaceRule::style):
* css/CSSFontFaceRule.h:
* css/CSSGroupingRule.cpp:
(WebCore::CSSGroupingRule::cssRules):
* css/CSSGroupingRule.h:
* css/CSSImportRule.cpp:
(WebCore::CSSImportRule::media):
* css/CSSImportRule.h:
* css/CSSPageRule.cpp:
(WebCore::CSSPageRule::style):
* css/CSSPageRule.h:
* css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::style):
* css/CSSStyleRule.h:
* css/WebKitCSSKeyframeRule.cpp:
(WebCore::WebKitCSSKeyframeRule::style):
* css/WebKitCSSKeyframeRule.h:
* css/WebKitCSSKeyframesRule.cpp:
(WebCore::WebKitCSSKeyframesRule::cssRules):
* css/WebKitCSSKeyframesRule.h:
* css/WebKitCSSViewportRule.cpp:
(WebCore::WebKitCSSViewportRule::style):
* css/WebKitCSSViewportRule.h:
* inspector/InspectorStyleSheet.cpp:
(WebCore::asCSSRuleList):
(WebCore::fillMediaListChain):
(WebCore::InspectorStyleSheet::setRuleSelector):
(WebCore::InspectorStyleSheet::deleteRule):
(WebCore::InspectorStyleSheet::buildObjectForSelectorList):
(WebCore::InspectorStyleSheet::buildObjectForRule):
(WebCore::InspectorStyleSheet::styleForId):
(WebCore::InspectorStyleSheet::ruleIndexByStyle):
(WebCore::InspectorStyleSheet::ruleId):
(WebCore::InspectorStyleSheet::revalidateStyle):

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

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontFaceRule.cpp
Source/WebCore/css/CSSFontFaceRule.h
Source/WebCore/css/CSSGroupingRule.cpp
Source/WebCore/css/CSSGroupingRule.h
Source/WebCore/css/CSSImportRule.cpp
Source/WebCore/css/CSSImportRule.h
Source/WebCore/css/CSSPageRule.cpp
Source/WebCore/css/CSSPageRule.h
Source/WebCore/css/CSSStyleRule.cpp
Source/WebCore/css/CSSStyleRule.h
Source/WebCore/css/WebKitCSSKeyframeRule.cpp
Source/WebCore/css/WebKitCSSKeyframeRule.h
Source/WebCore/css/WebKitCSSKeyframesRule.cpp
Source/WebCore/css/WebKitCSSKeyframesRule.h
Source/WebCore/css/WebKitCSSViewportRule.cpp
Source/WebCore/css/WebKitCSSViewportRule.h
Source/WebCore/inspector/InspectorStyleSheet.cpp

index 3465021..6def853 100644 (file)
@@ -1,3 +1,51 @@
+2014-09-23  Chris Dumez  <cdumez@apple.com>
+
+        Have CSS classes' methods return more references
+        https://bugs.webkit.org/show_bug.cgi?id=137036
+
+        Reviewed by Ryosuke Niwa.
+
+        Have CSS classes' methods return more references instead of pointers
+        when possible.
+
+        No new tests, no behavior change.
+
+        * css/CSSFontFaceRule.cpp:
+        (WebCore::CSSFontFaceRule::style):
+        * css/CSSFontFaceRule.h:
+        * css/CSSGroupingRule.cpp:
+        (WebCore::CSSGroupingRule::cssRules):
+        * css/CSSGroupingRule.h:
+        * css/CSSImportRule.cpp:
+        (WebCore::CSSImportRule::media):
+        * css/CSSImportRule.h:
+        * css/CSSPageRule.cpp:
+        (WebCore::CSSPageRule::style):
+        * css/CSSPageRule.h:
+        * css/CSSStyleRule.cpp:
+        (WebCore::CSSStyleRule::style):
+        * css/CSSStyleRule.h:
+        * css/WebKitCSSKeyframeRule.cpp:
+        (WebCore::WebKitCSSKeyframeRule::style):
+        * css/WebKitCSSKeyframeRule.h:
+        * css/WebKitCSSKeyframesRule.cpp:
+        (WebCore::WebKitCSSKeyframesRule::cssRules):
+        * css/WebKitCSSKeyframesRule.h:
+        * css/WebKitCSSViewportRule.cpp:
+        (WebCore::WebKitCSSViewportRule::style):
+        * css/WebKitCSSViewportRule.h:
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::asCSSRuleList):
+        (WebCore::fillMediaListChain):
+        (WebCore::InspectorStyleSheet::setRuleSelector):
+        (WebCore::InspectorStyleSheet::deleteRule):
+        (WebCore::InspectorStyleSheet::buildObjectForSelectorList):
+        (WebCore::InspectorStyleSheet::buildObjectForRule):
+        (WebCore::InspectorStyleSheet::styleForId):
+        (WebCore::InspectorStyleSheet::ruleIndexByStyle):
+        (WebCore::InspectorStyleSheet::ruleId):
+        (WebCore::InspectorStyleSheet::revalidateStyle):
+
 2014-09-23  Roger Fong  <roger_fong@apple.com>
 
         [Windows] Enable CSS Supports Rule on Windows.
index e5c2a55..2bb945a 100644 (file)
@@ -41,11 +41,11 @@ CSSFontFaceRule::~CSSFontFaceRule()
         m_propertiesCSSOMWrapper->clearParentRule();
 }
 
-CSSStyleDeclaration* CSSFontFaceRule::style()
+CSSStyleDeclaration& CSSFontFaceRule::style()
 {
     if (!m_propertiesCSSOMWrapper)
         m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_fontFaceRule->mutableProperties(), *this);
-    return m_propertiesCSSOMWrapper.get();
+    return *m_propertiesCSSOMWrapper;
 }
 
 String CSSFontFaceRule::cssText() const
index f961645..3631be7 100644 (file)
@@ -40,7 +40,7 @@ public:
     virtual String cssText() const override;
     virtual void reattach(StyleRuleBase*) override;
 
-    CSSStyleDeclaration* style();
+    CSSStyleDeclaration& style();
 
 private:
     CSSFontFaceRule(StyleRuleFontFace*, CSSStyleSheet* parent);
index 664c9b9..648fc22 100644 (file)
@@ -141,11 +141,11 @@ CSSRule* CSSGroupingRule::item(unsigned index) const
     return rule.get();
 }
 
-CSSRuleList* CSSGroupingRule::cssRules() const
+CSSRuleList& CSSGroupingRule::cssRules() const
 {
     if (!m_ruleListCSSOMWrapper)
         m_ruleListCSSOMWrapper = std::make_unique<LiveCSSRuleList<CSSGroupingRule>>(const_cast<CSSGroupingRule*>(this));
-    return m_ruleListCSSOMWrapper.get();
+    return *m_ruleListCSSOMWrapper;
 }
 
 void CSSGroupingRule::reattach(StyleRuleBase* rule)
index f14ee2c..30f3042 100644 (file)
@@ -38,7 +38,7 @@ public:
 
     virtual void reattach(StyleRuleBase*) override;
 
-    CSSRuleList* cssRules() const;
+    CSSRuleList& cssRules() const;
 
     unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
     void deleteRule(unsigned index, ExceptionCode&);
index 5e68cc7..5175756 100644 (file)
@@ -53,11 +53,11 @@ String CSSImportRule::href() const
     return m_importRule->href();
 }
 
-MediaList* CSSImportRule::media() const
+MediaList& CSSImportRule::media() const
 {
     if (!m_mediaCSSOMWrapper)
         m_mediaCSSOMWrapper = MediaList::create(m_importRule->mediaQueries(), const_cast<CSSImportRule*>(this));
-    return m_mediaCSSOMWrapper.get();
+    return *m_mediaCSSOMWrapper;
 }
 
 String CSSImportRule::cssText() const
index fbf261a..18bedac 100644 (file)
@@ -42,7 +42,7 @@ public:
     virtual void reattach(StyleRuleBase*) override;
 
     String href() const;
-    MediaList* media() const;
+    MediaList& media() const;
     CSSStyleSheet* styleSheet() const;
 
 private:
index 4895e8b..3e4836b 100644 (file)
@@ -46,11 +46,11 @@ CSSPageRule::~CSSPageRule()
         m_propertiesCSSOMWrapper->clearParentRule();
 }
 
-CSSStyleDeclaration* CSSPageRule::style()
+CSSStyleDeclaration& CSSPageRule::style()
 {
     if (!m_propertiesCSSOMWrapper)
         m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_pageRule->mutableProperties(), *this);
-    return m_propertiesCSSOMWrapper.get();
+    return *m_propertiesCSSOMWrapper;
 }
 
 String CSSPageRule::selectorText() const
index a4439b6..82e91aa 100644 (file)
@@ -41,7 +41,7 @@ public:
     virtual String cssText() const override;
     virtual void reattach(StyleRuleBase*) override;
 
-    CSSStyleDeclaration* style();
+    CSSStyleDeclaration& style();
 
     String selectorText() const;
     void setSelectorText(const String&);
index 800c63b..85639b5 100644 (file)
@@ -59,12 +59,11 @@ CSSStyleRule::~CSSStyleRule()
     }
 }
 
-CSSStyleDeclaration* CSSStyleRule::style()
+CSSStyleDeclaration& CSSStyleRule::style()
 {
-    if (!m_propertiesCSSOMWrapper) {
+    if (!m_propertiesCSSOMWrapper)
         m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_styleRule->mutableProperties(), *this);
-    }
-    return m_propertiesCSSOMWrapper.get();
+    return *m_propertiesCSSOMWrapper;
 }
 
 String CSSStyleRule::generateSelectorText() const
index 649bb06..52c9546 100644 (file)
@@ -43,7 +43,7 @@ public:
     String selectorText() const;
     void setSelectorText(const String&);
 
-    CSSStyleDeclaration* style();
+    CSSStyleDeclaration& style();
 
     // FIXME: Not CSSOM. Remove.
     StyleRule* styleRule() const { return m_styleRule.get(); }
index 087107f..3e56398 100644 (file)
@@ -105,11 +105,11 @@ WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule()
         m_propertiesCSSOMWrapper->clearParentRule();
 }
 
-CSSStyleDeclaration* WebKitCSSKeyframeRule::style()
+CSSStyleDeclaration& WebKitCSSKeyframeRule::style()
 {
     if (!m_propertiesCSSOMWrapper)
         m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_keyframe->mutableProperties(), *this);
-    return m_propertiesCSSOMWrapper.get();
+    return *m_propertiesCSSOMWrapper;
 }
 
 void WebKitCSSKeyframeRule::reattach(StyleRuleBase*)
index 30469f5..7aa5a2c 100644 (file)
@@ -76,7 +76,7 @@ public:
     String keyText() const { return m_keyframe->keyText(); }
     void setKeyText(const String& s) { m_keyframe->setKeyText(s); }
 
-    CSSStyleDeclaration* style();
+    CSSStyleDeclaration& style();
 
 private:
     WebKitCSSKeyframeRule(StyleKeyframe*, WebKitCSSKeyframesRule* parent);
index a92ccd5..e532bce 100644 (file)
@@ -185,11 +185,11 @@ WebKitCSSKeyframeRule* WebKitCSSKeyframesRule::item(unsigned index) const
     return rule.get(); 
 }
 
-CSSRuleList* WebKitCSSKeyframesRule::cssRules()
+CSSRuleList& WebKitCSSKeyframesRule::cssRules()
 {
     if (!m_ruleListCSSOMWrapper)
         m_ruleListCSSOMWrapper = std::make_unique<LiveCSSRuleList<WebKitCSSKeyframesRule>>(this);
-    return m_ruleListCSSOMWrapper.get();
+    return *m_ruleListCSSOMWrapper;
 }
 
 void WebKitCSSKeyframesRule::reattach(StyleRuleBase* rule)
index f259db4..0a6734f 100644 (file)
@@ -78,7 +78,7 @@ public:
     String name() const { return m_keyframesRule->name(); }
     void setName(const String&);
 
-    CSSRuleList* cssRules();
+    CSSRuleList& cssRules();
 
     void insertRule(const String& rule);
     void deleteRule(const String& key);
index b1de93c..c05960b 100644 (file)
@@ -52,12 +52,12 @@ WebKitCSSViewportRule::~WebKitCSSViewportRule()
         m_propertiesCSSOMWrapper->clearParentRule();
 }
 
-CSSStyleDeclaration* WebKitCSSViewportRule::style()
+CSSStyleDeclaration& WebKitCSSViewportRule::style()
 {
     if (!m_propertiesCSSOMWrapper)
         m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_viewportRule->mutableProperties(), *this);
 
-    return m_propertiesCSSOMWrapper.get();
+    return *m_propertiesCSSOMWrapper;
 }
 
 String WebKitCSSViewportRule::cssText() const
index 6614c80..b1c924f 100644 (file)
@@ -53,7 +53,7 @@ public:
     virtual String cssText() const override;
     virtual void reattach(StyleRuleBase*) override;
 
-    CSSStyleDeclaration* style();
+    CSSStyleDeclaration& style();
 
 private:
     WebKitCSSViewportRule(StyleRuleViewport*, CSSStyleSheet*);
index 012c538..a35f1e6 100644 (file)
@@ -215,14 +215,14 @@ static PassRefPtr<CSSRuleList> asCSSRuleList(CSSRule* rule)
         return nullptr;
 
     if (rule->type() == CSSRule::MEDIA_RULE)
-        return toCSSMediaRule(rule)->cssRules();
+        return &toCSSMediaRule(rule)->cssRules();
 
     if (rule->type() == CSSRule::WEBKIT_KEYFRAMES_RULE)
-        return static_cast<WebKitCSSKeyframesRule*>(rule)->cssRules();
+        return &static_cast<WebKitCSSKeyframesRule*>(rule)->cssRules();
 
 #if ENABLE(CSS3_CONDITIONAL_RULES)
     if (rule->type() == CSSRule::SUPPORTS_RULE)
-        return toCSSSupportsRule(rule)->cssRules();
+        return &toCSSSupportsRule(rule)->cssRules();
 #endif
 
     return nullptr;
@@ -242,7 +242,7 @@ static void fillMediaListChain(CSSRule* rule, Array<Inspector::Protocol::CSS::CS
             parentStyleSheet = mediaRule->parentStyleSheet();
         } else if (parentRule->type() == CSSRule::IMPORT_RULE) {
             CSSImportRule* importRule = toCSSImportRule(parentRule);
-            mediaList = importRule->media();
+            mediaList = &importRule->media();
             parentStyleSheet = importRule->parentStyleSheet();
             isMediaRule = false;
         } else
@@ -846,7 +846,7 @@ bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String
     }
 
     rule->setSelectorText(selector);
-    RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->style());
+    RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(&rule->style());
     if (!sourceData) {
         ec = NOT_FOUND_ERR;
         return false;
@@ -929,7 +929,7 @@ bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, ExceptionCode& ec
         return false;
     }
 
-    RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->style());
+    RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(&rule->style());
     if (!sourceData) {
         ec = NOT_FOUND_ERR;
         return false;
@@ -1018,7 +1018,7 @@ PassRefPtr<Inspector::Protocol::CSS::SelectorList> InspectorStyleSheet::buildObj
 {
     RefPtr<CSSRuleSourceData> sourceData;
     if (ensureParsedDataReady())
-        sourceData = ruleSourceDataFor(rule->style());
+        sourceData = ruleSourceDataFor(&rule->style());
     RefPtr<Inspector::Protocol::Array<String>> selectors;
 
     // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{').
@@ -1051,7 +1051,7 @@ PassRefPtr<Inspector::Protocol::CSS::CSSRule> InspectorStyleSheet::buildObjectFo
         .setSelectorList(buildObjectForSelectorList(rule))
         .setSourceLine(rule->styleRule()->sourceLine())
         .setOrigin(m_origin)
-        .setStyle(buildObjectForStyle(rule->style()));
+        .setStyle(buildObjectForStyle(&rule->style()));
 
     // "sourceURL" is present only for regular rules, otherwise "origin" should be used in the frontend.
     if (m_origin == Inspector::Protocol::CSS::StyleSheetOrigin::Regular)
@@ -1165,7 +1165,7 @@ CSSStyleDeclaration* InspectorStyleSheet::styleForId(const InspectorCSSId& id) c
     if (!rule)
         return nullptr;
 
-    return rule->style();
+    return &rule->style();
 }
 
 void InspectorStyleSheet::fireStyleSheetChanged()
@@ -1228,7 +1228,7 @@ unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) c
     ensureFlatRules();
     unsigned index = 0;
     for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) {
-        if (m_flatRules.at(i)->style() == pageStyle)
+        if (&m_flatRules.at(i)->style() == pageStyle)
             return index;
 
         ++index;
@@ -1334,7 +1334,7 @@ bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st
 
 InspectorCSSId InspectorStyleSheet::ruleId(CSSStyleRule* rule) const
 {
-    return ruleOrStyleId(rule->style());
+    return ruleOrStyleId(&rule->style());
 }
 
 void InspectorStyleSheet::revalidateStyle(CSSStyleDeclaration* pageStyle)
@@ -1346,7 +1346,7 @@ void InspectorStyleSheet::revalidateStyle(CSSStyleDeclaration* pageStyle)
     ensureFlatRules();
     for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) {
         CSSStyleRule* parsedRule = m_flatRules.at(i).get();
-        if (parsedRule->style() == pageStyle) {
+        if (&parsedRule->style() == pageStyle) {
             if (parsedRule->styleRule()->properties().asText() != pageStyle->cssText()) {
                 // Clear the disabled properties for the invalid style here.
                 m_inspectorStyles.remove(pageStyle);