Title: [174313] trunk/Source/WebCore
Revision
174313
Author
cdu...@apple.com
Date
2014-10-04 01:30:15 -0700 (Sat, 04 Oct 2014)

Log Message

Use is<>() / downcast<>() for CSS StyleProperties
https://bugs.webkit.org/show_bug.cgi?id=137398

Reviewed by Benjamin Poulain.

Use is<>() / downcast<>() for CSS StyleProperties subclasses.

No new tests, no behavior change.

* css/StyleProperties.cpp:
(WebCore::StyleProperties::immutableCopyIfNeeded):
(WebCore::MutableStyleProperties::MutableStyleProperties):
(WebCore::StyleProperties::hasCSSOMWrapper):
* css/StyleProperties.h:
(WebCore::StyleProperties::PropertyReference::propertyMetadata):
(WebCore::StyleProperties::PropertyReference::propertyValue):
(WebCore::StyleProperties::propertyCount):
(WebCore::StyleProperties::deref):
(WebCore::StyleProperties::findPropertyIndex):
(isType):
(WebCore::toMutableStyleProperties): Deleted.
(WebCore::toImmutableStyleProperties): Deleted.
* css/StyleRule.cpp:
(WebCore::StyleRule::mutableProperties):
(WebCore::StyleRulePage::mutableProperties):
(WebCore::StyleRuleFontFace::mutableProperties):
* css/WebKitCSSKeyframeRule.cpp:
(WebCore::StyleKeyframe::mutableProperties):
* dom/StyledElement.cpp:
(WebCore::StyledElement::ensureMutableInlineStyle):
(WebCore::StyledElement::setInlineStyleFromString):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174312 => 174313)


--- trunk/Source/WebCore/ChangeLog	2014-10-04 08:05:22 UTC (rev 174312)
+++ trunk/Source/WebCore/ChangeLog	2014-10-04 08:30:15 UTC (rev 174313)
@@ -1,3 +1,37 @@
+2014-10-04  Christophe Dumez  <cdu...@apple.com>
+
+        Use is<>() / downcast<>() for CSS StyleProperties
+        https://bugs.webkit.org/show_bug.cgi?id=137398
+
+        Reviewed by Benjamin Poulain.
+
+        Use is<>() / downcast<>() for CSS StyleProperties subclasses.
+
+        No new tests, no behavior change.
+
+        * css/StyleProperties.cpp:
+        (WebCore::StyleProperties::immutableCopyIfNeeded):
+        (WebCore::MutableStyleProperties::MutableStyleProperties):
+        (WebCore::StyleProperties::hasCSSOMWrapper):
+        * css/StyleProperties.h:
+        (WebCore::StyleProperties::PropertyReference::propertyMetadata):
+        (WebCore::StyleProperties::PropertyReference::propertyValue):
+        (WebCore::StyleProperties::propertyCount):
+        (WebCore::StyleProperties::deref):
+        (WebCore::StyleProperties::findPropertyIndex):
+        (isType):
+        (WebCore::toMutableStyleProperties): Deleted.
+        (WebCore::toImmutableStyleProperties): Deleted.
+        * css/StyleRule.cpp:
+        (WebCore::StyleRule::mutableProperties):
+        (WebCore::StyleRulePage::mutableProperties):
+        (WebCore::StyleRuleFontFace::mutableProperties):
+        * css/WebKitCSSKeyframeRule.cpp:
+        (WebCore::StyleKeyframe::mutableProperties):
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::ensureMutableInlineStyle):
+        (WebCore::StyledElement::setInlineStyleFromString):
+
 2014-10-04  Zan Dobersek  <zdober...@igalia.com>
 
         [TexMap] Clean up GraphicsLayerTextureMapper::prepareBackingStoreIfNeeded()

Modified: trunk/Source/WebCore/css/StyleProperties.cpp (174312 => 174313)


--- trunk/Source/WebCore/css/StyleProperties.cpp	2014-10-04 08:05:22 UTC (rev 174312)
+++ trunk/Source/WebCore/css/StyleProperties.cpp	2014-10-04 08:30:15 UTC (rev 174313)
@@ -61,9 +61,9 @@
 
 PassRef<ImmutableStyleProperties> StyleProperties::immutableCopyIfNeeded() const
 {
-    if (!isMutable())
-        return static_cast<ImmutableStyleProperties&>(const_cast<StyleProperties&>(*this));
-    const MutableStyleProperties& mutableThis = static_cast<const MutableStyleProperties&>(*this);
+    if (is<ImmutableStyleProperties>(*this))
+        return downcast<ImmutableStyleProperties>(const_cast<StyleProperties&>(*this));
+    const MutableStyleProperties& mutableThis = downcast<MutableStyleProperties>(*this);
     return ImmutableStyleProperties::create(mutableThis.m_propertyVector.data(), mutableThis.m_propertyVector.size(), cssParserMode());
 }
 
@@ -106,8 +106,8 @@
 MutableStyleProperties::MutableStyleProperties(const StyleProperties& other)
     : StyleProperties(other.cssParserMode())
 {
-    if (other.isMutable())
-        m_propertyVector = static_cast<const MutableStyleProperties&>(other).m_propertyVector;
+    if (is<MutableStyleProperties>(other))
+        m_propertyVector = downcast<MutableStyleProperties>(other).m_propertyVector;
     else {
         m_propertyVector.reserveInitialCapacity(other.propertyCount());
         for (unsigned i = 0; i < other.propertyCount(); ++i)
@@ -1028,7 +1028,7 @@
 
 bool StyleProperties::hasCSSOMWrapper() const
 {
-    return m_isMutable && static_cast<const MutableStyleProperties*>(this)->m_cssomWrapper;
+    return is<MutableStyleProperties>(*this) && downcast<MutableStyleProperties>(*this).m_cssomWrapper;
 }
 
 void MutableStyleProperties::mergeAndOverrideOnConflict(const StyleProperties& other)

Modified: trunk/Source/WebCore/css/StyleProperties.h (174312 => 174313)


--- trunk/Source/WebCore/css/StyleProperties.h	2014-10-04 08:05:22 UTC (rev 174312)
+++ trunk/Source/WebCore/css/StyleProperties.h	2014-10-04 08:30:15 UTC (rev 174313)
@@ -29,6 +29,7 @@
 #include "CSSValueKeywords.h"
 #include <memory>
 #include <wtf/ListHashSet.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
 
@@ -235,38 +236,24 @@
     friend class StyleProperties;
 };
 
-TYPE_CASTS_BASE(MutableStyleProperties, StyleProperties, set, set->isMutable(), set.isMutable());
-
-inline MutableStyleProperties* toMutableStyleProperties(const RefPtr<StyleProperties>& set)
-{
-    return toMutableStyleProperties(set.get());
-}
-
-TYPE_CASTS_BASE(ImmutableStyleProperties, StyleProperties, set, !set->isMutable(), !set.isMutable());
-
-inline ImmutableStyleProperties* toImmutableStyleProperties(const RefPtr<StyleProperties>& set)
-{
-    return toImmutableStyleProperties(set.get());
-}
-
 inline const StylePropertyMetadata& StyleProperties::PropertyReference::propertyMetadata() const
 {
-    if (m_propertySet.isMutable())
-        return static_cast<const MutableStyleProperties&>(m_propertySet).m_propertyVector.at(m_index).metadata();
-    return static_cast<const ImmutableStyleProperties&>(m_propertySet).metadataArray()[m_index];
+    if (is<MutableStyleProperties>(m_propertySet))
+        return downcast<MutableStyleProperties>(m_propertySet).m_propertyVector.at(m_index).metadata();
+    return downcast<ImmutableStyleProperties>(m_propertySet).metadataArray()[m_index];
 }
 
 inline const CSSValue* StyleProperties::PropertyReference::propertyValue() const
 {
-    if (m_propertySet.isMutable())
-        return static_cast<const MutableStyleProperties&>(m_propertySet).m_propertyVector.at(m_index).value();
-    return static_cast<const ImmutableStyleProperties&>(m_propertySet).valueArray()[m_index];
+    if (is<MutableStyleProperties>(m_propertySet))
+        return downcast<MutableStyleProperties>(m_propertySet).m_propertyVector.at(m_index).value();
+    return downcast<ImmutableStyleProperties>(m_propertySet).valueArray()[m_index];
 }
 
 inline unsigned StyleProperties::propertyCount() const
 {
-    if (m_isMutable)
-        return static_cast<const MutableStyleProperties*>(this)->m_propertyVector.size();
+    if (is<MutableStyleProperties>(*this))
+        return downcast<MutableStyleProperties>(*this).m_propertyVector.size();
     return m_arraySize;
 }
 
@@ -280,19 +267,27 @@
     if (!derefBase())
         return;
 
-    if (m_isMutable)
-        delete static_cast<MutableStyleProperties*>(this);
+    if (is<MutableStyleProperties>(*this))
+        delete downcast<MutableStyleProperties>(this);
     else
-        delete static_cast<ImmutableStyleProperties*>(this);
+        delete downcast<ImmutableStyleProperties>(this);
 }
 
 inline int StyleProperties::findPropertyIndex(CSSPropertyID propertyID) const
 {
-    if (m_isMutable)
-        return toMutableStyleProperties(this)->findPropertyIndex(propertyID);
-    return toImmutableStyleProperties(this)->findPropertyIndex(propertyID);
+    if (is<MutableStyleProperties>(*this))
+        return downcast<MutableStyleProperties>(*this).findPropertyIndex(propertyID);
+    return downcast<ImmutableStyleProperties>(*this).findPropertyIndex(propertyID);
 }
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::MutableStyleProperties)
+    static bool isType(const WebCore::StyleProperties& set) { return set.isMutable(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ImmutableStyleProperties)
+    static bool isType(const WebCore::StyleProperties& set) { return !set.isMutable(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // StyleProperties_h

Modified: trunk/Source/WebCore/css/StyleRule.cpp (174312 => 174313)


--- trunk/Source/WebCore/css/StyleRule.cpp	2014-10-04 08:05:22 UTC (rev 174312)
+++ trunk/Source/WebCore/css/StyleRule.cpp	2014-10-04 08:30:15 UTC (rev 174313)
@@ -220,9 +220,9 @@
 
 MutableStyleProperties& StyleRule::mutableProperties()
 {
-    if (!m_properties->isMutable())
+    if (!is<MutableStyleProperties>(m_properties.get()))
         m_properties = m_properties->mutableCopy();
-    return static_cast<MutableStyleProperties&>(m_properties.get());
+    return downcast<MutableStyleProperties>(m_properties.get());
 }
 
 PassRef<StyleRule> StyleRule::create(int sourceLine, const Vector<const CSSSelector*>& selectors, PassRef<StyleProperties> properties)
@@ -282,9 +282,9 @@
 
 MutableStyleProperties& StyleRulePage::mutableProperties()
 {
-    if (!m_properties->isMutable())
+    if (!is<MutableStyleProperties>(m_properties.get()))
         m_properties = m_properties->mutableCopy();
-    return static_cast<MutableStyleProperties&>(m_properties.get());
+    return downcast<MutableStyleProperties>(m_properties.get());
 }
 
 StyleRuleFontFace::StyleRuleFontFace(PassRef<StyleProperties> properties)
@@ -305,9 +305,9 @@
 
 MutableStyleProperties& StyleRuleFontFace::mutableProperties()
 {
-    if (!m_properties->isMutable())
+    if (!is<MutableStyleProperties>(m_properties.get()))
         m_properties = m_properties->mutableCopy();
-    return static_cast<MutableStyleProperties&>(m_properties.get());
+    return downcast<MutableStyleProperties>(m_properties.get());
 }
 
 StyleRuleGroup::StyleRuleGroup(Type type, Vector<RefPtr<StyleRuleBase>>& adoptRule)

Modified: trunk/Source/WebCore/css/WebKitCSSKeyframeRule.cpp (174312 => 174313)


--- trunk/Source/WebCore/css/WebKitCSSKeyframeRule.cpp	2014-10-04 08:05:22 UTC (rev 174312)
+++ trunk/Source/WebCore/css/WebKitCSSKeyframeRule.cpp	2014-10-04 08:30:15 UTC (rev 174313)
@@ -44,9 +44,9 @@
 
 MutableStyleProperties& StyleKeyframe::mutableProperties()
 {
-    if (!m_properties->isMutable())
+    if (!is<MutableStyleProperties>(m_properties.get()))
         m_properties = m_properties->mutableCopy();
-    return static_cast<MutableStyleProperties&>(m_properties.get());
+    return downcast<MutableStyleProperties>(m_properties.get());
 }
 
 /* static */

Modified: trunk/Source/WebCore/dom/StyledElement.cpp (174312 => 174313)


--- trunk/Source/WebCore/dom/StyledElement.cpp	2014-10-04 08:05:22 UTC (rev 174312)
+++ trunk/Source/WebCore/dom/StyledElement.cpp	2014-10-04 08:30:15 UTC (rev 174313)
@@ -144,10 +144,9 @@
     RefPtr<StyleProperties>& inlineStyle = ensureUniqueElementData().m_inlineStyle;
     if (!inlineStyle)
         inlineStyle = MutableStyleProperties::create(strictToCSSParserMode(isHTMLElement() && !document().inQuirksMode()));
-    else if (!inlineStyle->isMutable())
+    else if (!is<MutableStyleProperties>(*inlineStyle))
         inlineStyle = inlineStyle->mutableCopy();
-    ASSERT_WITH_SECURITY_IMPLICATION(inlineStyle->isMutable());
-    return static_cast<MutableStyleProperties&>(*inlineStyle);
+    return downcast<MutableStyleProperties>(*inlineStyle);
 }
 
 void StyledElement::attributeChanged(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason reason)
@@ -181,15 +180,13 @@
 
     // We reconstruct the property set instead of mutating if there is no CSSOM wrapper.
     // This makes wrapperless property sets immutable and so cacheable.
-    if (inlineStyle && !inlineStyle->isMutable())
+    if (inlineStyle && !is<MutableStyleProperties>(*inlineStyle))
         inlineStyle.clear();
 
     if (!inlineStyle)
         inlineStyle = CSSParser::parseInlineStyleDeclaration(newStyleString, this);
-    else {
-        ASSERT(inlineStyle->isMutable());
-        static_pointer_cast<MutableStyleProperties>(inlineStyle)->parseDeclaration(newStyleString, &document().elementSheet().contents());
-    }
+    else
+        downcast<MutableStyleProperties>(*inlineStyle).parseDeclaration(newStyleString, &document().elementSheet().contents());
 }
 
 void StyledElement::styleAttributeChanged(const AtomicString& newStyleString, AttributeModificationReason reason)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to