Document::elementSheet() should return a reference
authorpsolanki@apple.com <psolanki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Aug 2013 19:24:50 +0000 (19:24 +0000)
committerpsolanki@apple.com <psolanki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Aug 2013 19:24:50 +0000 (19:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=120433

Reviewed by Andreas Kling.

Since elementSheet() always retruns a valid pointer, we can simply return a reference
instead. Also rename m_elemSheet to m_elementSheet.

* css/CSSParser.cpp:
(WebCore::CSSParser::parseInlineStyleDeclaration):
* css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::InlineCSSStyleDeclaration::parentStyleSheet):
* dom/Document.cpp:
(WebCore::Document::~Document):
(WebCore::Document::recalcStyle):
(WebCore::Document::updateBaseURL):
(WebCore::Document::elementSheet):
* dom/Document.h:
* dom/StyledElement.cpp:
(WebCore::StyledElement::setInlineStyleFromString):
(WebCore::StyledElement::setInlineStyleProperty):
(WebCore::StyledElement::addSubresourceAttributeURLs):
(WebCore::StyledElement::addPropertyToPresentationAttributeStyle):
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges):

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

Source/WebCore/ChangeLog
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/StyledElement.cpp
Source/WebCore/inspector/InspectorStyleSheet.cpp

index 9d16e8dfcd9d6a440f46207a23bf4deb69d6ed72..f3be9c75fadbbef9108f0180870121e431f1308a 100644 (file)
@@ -1,3 +1,31 @@
+2013-08-28  Pratik Solanki  <psolanki@apple.com>
+
+        Document::elementSheet() should return a reference
+        https://bugs.webkit.org/show_bug.cgi?id=120433
+
+        Reviewed by Andreas Kling.
+
+        Since elementSheet() always retruns a valid pointer, we can simply return a reference
+        instead. Also rename m_elemSheet to m_elementSheet.
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseInlineStyleDeclaration):
+        * css/PropertySetCSSStyleDeclaration.cpp:
+        (WebCore::InlineCSSStyleDeclaration::parentStyleSheet):
+        * dom/Document.cpp:
+        (WebCore::Document::~Document):
+        (WebCore::Document::recalcStyle):
+        (WebCore::Document::updateBaseURL):
+        (WebCore::Document::elementSheet):
+        * dom/Document.h:
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::setInlineStyleFromString):
+        (WebCore::StyledElement::setInlineStyleProperty):
+        (WebCore::StyledElement::addSubresourceAttributeURLs):
+        (WebCore::StyledElement::addPropertyToPresentationAttributeStyle):
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges):
+
 2013-08-28  Ryosuke Niwa  <rniwa@webkit.org>
 
         REGRESSION(r154586): Past names map should only be used when named item is empty
index 10a0450a644b8264cb98601a52e484d259aa495a..7eba00f0926d31e6269235033506eeb9045342ef 100644 (file)
@@ -1423,9 +1423,9 @@ void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorLis
 
 PassRefPtr<ImmutableStylePropertySet> CSSParser::parseInlineStyleDeclaration(const String& string, Element* element)
 {
-    CSSParserContext context = element->document()->elementSheet()->contents()->parserContext();
+    CSSParserContext context = element->document()->elementSheet().contents()->parserContext();
     context.mode = strictToCSSParserMode(element->isHTMLElement() && !element->document()->inQuirksMode());
-    return CSSParser(context).parseDeclaration(string, element->document()->elementSheet()->contents());
+    return CSSParser(context).parseDeclaration(string, element->document()->elementSheet().contents());
 }
 
 PassRefPtr<ImmutableStylePropertySet> CSSParser::parseDeclaration(const String& string, StyleSheetContents* contextStyleSheet)
index eaa24b21f14dfebc72578ea0d3b4f0b95a434d39..5b86ac3f98b19de869c3e96ac96048fe3d1ed26f 100644 (file)
@@ -366,7 +366,7 @@ void InlineCSSStyleDeclaration::didMutate(MutationType type)
 
 CSSStyleSheet* InlineCSSStyleDeclaration::parentStyleSheet() const
 {
-    return m_parentElement ? m_parentElement->document()->elementSheet() : 0;
+    return m_parentElement ? &m_parentElement->document()->elementSheet() : 0;
 }
 
 } // namespace WebCore
index 31807dbe3da72bf0c4e0671967781dda7779c81c..2b9681e047e0aa5d6c299d1df2d30a492729472e 100644 (file)
@@ -593,8 +593,8 @@ Document::~Document()
 
     m_styleSheetCollection.clear();
 
-    if (m_elemSheet)
-        m_elemSheet->clearOwnerNode();
+    if (m_elementSheet)
+        m_elementSheet->clearOwnerNode();
 
     clearStyleResolver(); // We need to destroy CSSFontSelector before destroying m_cachedResourceLoader.
 
@@ -1753,7 +1753,7 @@ void Document::recalcStyle(Style::Change change)
 
     InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRecalculateStyle(this);
 
-    if (m_elemSheet && m_elemSheet->contents()->usesRemUnits())
+    if (m_elementSheet && m_elementSheet->contents()->usesRemUnits())
         m_styleSheetCollection->setUsesRemUnit(true);
 
     m_inStyleRecalc = true;
@@ -2647,13 +2647,13 @@ void Document::updateBaseURL()
     if (!m_baseURL.isValid())
         m_baseURL = KURL();
 
-    if (m_elemSheet) {
+    if (m_elementSheet) {
         // Element sheet is silly. It never contains anything.
-        ASSERT(!m_elemSheet->contents()->ruleCount());
-        bool usesRemUnits = m_elemSheet->contents()->usesRemUnits();
-        m_elemSheet = CSSStyleSheet::createInline(this, m_baseURL);
+        ASSERT(!m_elementSheet->contents()->ruleCount());
+        bool usesRemUnits = m_elementSheet->contents()->usesRemUnits();
+        m_elementSheet = CSSStyleSheet::createInline(this, m_baseURL);
         // FIXME: So we are not really the parser. The right fix is to eliminate the element sheet completely.
-        m_elemSheet->contents()->parserSetUsesRemUnits(usesRemUnits);
+        m_elementSheet->contents()->parserSetUsesRemUnits(usesRemUnits);
     }
 
     if (!equalIgnoringFragmentIdentifier(oldBaseURL, m_baseURL)) {
@@ -2814,11 +2814,11 @@ void Document::didRemoveAllPendingStylesheet()
         view()->scrollToFragment(m_url);
 }
 
-CSSStyleSheet* Document::elementSheet()
+CSSStyleSheet& Document::elementSheet()
 {
-    if (!m_elemSheet)
-        m_elemSheet = CSSStyleSheet::createInline(this, m_baseURL);
-    return m_elemSheet.get();
+    if (!m_elementSheet)
+        m_elementSheet = CSSStyleSheet::createInline(this, m_baseURL);
+    return *m_elementSheet;
 }
 
 void Document::processHttpEquiv(const String& equiv, const String& content)
index 5ac0385d2b07e6ba44009b55eff2183cbb42710d..da6baa064a460c11d1ec849823987fd0844e8df4 100644 (file)
@@ -597,7 +597,7 @@ public:
     bool canNavigate(Frame* targetFrame);
     Frame* findUnsafeParentScrollPropagationBoundary();
 
-    CSSStyleSheet* elementSheet();
+    CSSStyleSheet& elementSheet();
     
     virtual PassRefPtr<DocumentParser> createParser();
     DocumentParser* parser() const { return m_parser.get(); }
@@ -1316,7 +1316,7 @@ private:
     RefPtr<DocumentType> m_docType;
     OwnPtr<DOMImplementation> m_implementation;
 
-    RefPtr<CSSStyleSheet> m_elemSheet;
+    RefPtr<CSSStyleSheet> m_elementSheet;
 
     bool m_printing;
     bool m_paginatedForScreen;
index 3003dd5b04574c638371445bd09f77701aa844b1..85906e5d9a0afddc18ba1c53a136b88aca2959cd 100644 (file)
@@ -195,7 +195,7 @@ inline void StyledElement::setInlineStyleFromString(const AtomicString& newStyle
         inlineStyle = CSSParser::parseInlineStyleDeclaration(newStyleString, this);
     else {
         ASSERT(inlineStyle->isMutable());
-        static_pointer_cast<MutableStylePropertySet>(inlineStyle)->parseDeclaration(newStyleString, document()->elementSheet()->contents());
+        static_pointer_cast<MutableStylePropertySet>(inlineStyle)->parseDeclaration(newStyleString, document()->elementSheet().contents());
     }
 }
 
@@ -249,7 +249,7 @@ bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, double valu
 
 bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, const String& value, bool important)
 {
-    bool changes = ensureMutableInlineStyle().setProperty(propertyID, value, important, document()->elementSheet()->contents());
+    bool changes = ensureMutableInlineStyle().setProperty(propertyID, value, important, document()->elementSheet().contents());
     if (changes)
         inlineStyleChanged();
     return changes;
@@ -276,7 +276,7 @@ void StyledElement::removeAllInlineStyleProperties()
 void StyledElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
 {
     if (const StylePropertySet* inlineStyle = elementData() ? elementData()->inlineStyle() : 0)
-        inlineStyle->addSubresourceStyleURLs(urls, document()->elementSheet()->contents());
+        inlineStyle->addSubresourceStyleURLs(urls, document()->elementSheet().contents());
 }
 
 static inline bool attributeNameSort(const pair<AtomicStringImpl*, AtomicString>& p1, const pair<AtomicStringImpl*, AtomicString>& p2)
@@ -384,7 +384,7 @@ void StyledElement::addPropertyToPresentationAttributeStyle(MutableStyleProperty
     
 void StyledElement::addPropertyToPresentationAttributeStyle(MutableStylePropertySet* style, CSSPropertyID propertyID, const String& value)
 {
-    style->setProperty(propertyID, value, false, document()->elementSheet()->contents());
+    style->setProperty(propertyID, value, false, document()->elementSheet().contents());
 }
 
 }
index 2c9888686bc2f4b68f0dcc2338b4ae7732df398a..0759199d4470b4205ab4e25a4ff28507dbe5e47e 100644 (file)
@@ -1548,7 +1548,7 @@ bool InspectorStyleSheetForInlineStyle::getStyleAttributeRanges(CSSRuleSourceDat
     }
 
     RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::create();
-    createCSSParser(m_element->document())->parseDeclaration(tempDeclaration.get(), m_styleText, result, m_element->document()->elementSheet()->contents());
+    createCSSParser(m_element->document())->parseDeclaration(tempDeclaration.get(), m_styleText, result, m_element->document()->elementSheet().contents());
     return true;
 }