Commit f9ae0524 authored by antti@apple.com's avatar antti@apple.com

Reduce non-CSSOM API of CSSStyleDeclaration

https://bugs.webkit.org/show_bug.cgi?id=77299

Reviewed by Andreas Kling.

../WebCore: 

CSSStyleDeclaration should expose the CSSOM API only. Subclasses should expose the internal API only. 
This will move us closer to being able to split the CSSOM API from the internal implementation.
        
- Make CSSStyleDeclaration CSSOM functions virtual, internal functions non-virtual.
- Move implementations to subclasses (CSSComputedStyleDeclaration, CSSMutableStyleDeclaration).
- Make CSSOM functions in the subclasses private (making it harder to invoke them internally).
- Switch a bunch of places to use internal API instead of CSSOM.

* bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp:
(WebCore::V8CSSStyleDeclaration::namedPropertyGetter):
(WebCore::V8CSSStyleDeclaration::namedPropertySetter):
        
    Switch to *Internal versions of the CSSOM functions.
        
* css/CSSComputedStyleDeclaration.cpp:
(WebCore):
(WebCore::CSSComputedStyleDeclaration::length):
(WebCore::CSSComputedStyleDeclaration::cssPropertyMatches):
(WebCore::CSSComputedStyleDeclaration::copyPropertiesInSet):
        
    Move copyPropertiesInSet to subclasses, devirtualize.
            
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
(WebCore::CSSComputedStyleDeclaration::getPropertyValue):
(WebCore::CSSComputedStyleDeclaration::getPropertyPriority):
(WebCore::CSSComputedStyleDeclaration::getPropertyShorthand):
(WebCore::CSSComputedStyleDeclaration::isPropertyImplicit):
(WebCore::CSSComputedStyleDeclaration::setProperty):
(WebCore::CSSComputedStyleDeclaration::removeProperty):
* css/CSSComputedStyleDeclaration.h:
(CSSComputedStyleDeclaration):
* css/CSSFontFaceRule.cpp:
(WebCore::CSSFontFaceRule::cssText):
* css/CSSMutableStyleDeclaration.cpp:
(WebCore::CSSMutableStyleDeclaration::length):
(WebCore::CSSMutableStyleDeclaration::asText):
(WebCore::CSSMutableStyleDeclaration::cssText):
(WebCore):
(WebCore::CSSMutableStyleDeclaration::getPropertyCSSValue):
(WebCore::CSSMutableStyleDeclaration::getPropertyValue):
(WebCore::CSSMutableStyleDeclaration::getPropertyPriority):
(WebCore::CSSMutableStyleDeclaration::getPropertyShorthand):
(WebCore::CSSMutableStyleDeclaration::isPropertyImplicit):
(WebCore::CSSMutableStyleDeclaration::setProperty):
(WebCore::CSSMutableStyleDeclaration::removeProperty):
(WebCore::CSSMutableStyleDeclaration::copyPropertiesInSet):
        
    Move copyPropertiesInSet to subclasses, devirtualize.
        
(WebCore::CSSMutableStyleDeclaration::cssPropertyMatches):
(WebCore::CSSMutableStyleDeclaration::removeEquivalentProperties):
        
    Move diff() to CSSMutableStyleDeclaration, rename to removeEquivalentProperties, switch to mutate
    this object instead of the argument object.
    
* css/CSSMutableStyleDeclaration.h:
(CSSMutableStyleDeclaration):
(WebCore::CSSMutableStyleDeclaration::propertyCount):
(WebCore::CSSMutableStyleDeclaration::isEmpty):
(WebCore::CSSMutableStyleDeclaration::propertyAt):
        
    Expose properties and property count internally (iterator should be removed in favor of these).
        
* css/CSSStyleDeclaration.cpp:
(WebCore):
* css/CSSStyleDeclaration.h:
(CSSStyleDeclaration):
(WebCore::CSSStyleDeclaration::getPropertyCSSValueInternal):
(WebCore::CSSStyleDeclaration::getPropertyValueInternal):
(WebCore::CSSStyleDeclaration::setPropertyInternal):
        
    Add *Internal versions of some CSSOM APIs to support some editing and bindings uses.
    These take propertyIDs instead of strings names.

* css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::cssText):
* css/CSSStyleSelector.cpp:
(WebCore::leftToRightDeclaration):
(WebCore::rightToLeftDeclaration):
(WebCore::CSSStyleSelector::collectMatchingRulesForList):
(WebCore::CSSStyleSelector::matchPageRulesForList):
* css/WebKitCSSKeyframeRule.cpp:
(WebCore::WebKitCSSKeyframeRule::cssText):
* dom/StyledElement.cpp:
(WebCore::StyledElement::updateStyleAttribute):
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
(WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock):
(WebCore::ApplyStyleCommand::applyInlineStyleToNodeRange):
(WebCore::ApplyStyleCommand::applyInlineStyleToPushDown):
(WebCore::ApplyStyleCommand::addBlockStyle):
(WebCore::ApplyStyleCommand::addInlineStyleIfNeeded):
* editing/EditingStyle.cpp:
():
(WebCore::copyEditingProperties):
(WebCore):
(WebCore::propertyCSSValue):
(WebCore::getRGBAFontColor):
(WebCore::EditingStyle::overrideWithStyle):
(WebCore::EditingStyle::removeStyleAddedByNode):
(WebCore::EditingStyle::removeStyleConflictingWithStyleOfNode):
(WebCore::EditingStyle::triStateOfStyle):
(WebCore::EditingStyle::styleIsPresentInComputedStyleOfNode):
(WebCore::EditingStyle::prepareToApplyAt):
(WebCore::removePropertiesInStyle):
(WebCore::EditingStyle::removeStyleFromRulesAndContext):
(WebCore::EditingStyle::removePropertiesInElementDefaultStyle):
(WebCore::StyleChange::StyleChange):
(WebCore::fontWeightIsBold):
(WebCore::getPropertiesNotIn):
(WebCore::getIdentifierValue):
(WebCore::hasTransparentBackgroundColor):
* editing/EditingStyle.h:
        
    Adapt to changes.
    
(WebCore):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):
(WebCore::handleStyleSpansBeforeInsertion):
(WebCore::ReplaceSelectionCommand::handleStyleSpans):
* editing/mac/EditorMac.mm:
(WebCore::styleForSelectionStart):
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::appendStyleNodeOpenTag):
(WebCore::StyledMarkupAccumulator::appendElement):
* html/ImageDocument.cpp:
(WebCore::ImageDocument::resizeImageToFit):
(WebCore::ImageDocument::restoreImageSize):
(WebCore::ImageDocument::windowSizeChanged):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::setFont):
* html/canvas/CanvasStyle.cpp:
(WebCore::currentColor):
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyleSheet::revalidateStyle):
* page/PageSerializer.cpp:
(WebCore::PageSerializer::retrieveResourcesForCSSDeclaration):
* rendering/RenderTreeAsText.cpp:
(WebCore::isEmptyOrUnstyledAppleStyleSpan):
* svg/SVGStyledElement.cpp:
(WebCore::SVGStyledElement::getPresentationAttribute):

../WebKit/qt: 

* Api/qwebelement.cpp:
(QWebElement::styleProperty):
(QWebElement::setStyleProperty):
* WebCoreSupport/DumpRenderTreeSupportQt.cpp:
(DumpRenderTreeSupportQt::computedStyleIncludingVisitedInfo):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106247 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ae4b5a5d
2012-01-29 Antti Koivisto <antti@apple.com>
Reduce non-CSSOM API of CSSStyleDeclaration
https://bugs.webkit.org/show_bug.cgi?id=77299
Reviewed by Andreas Kling.
CSSStyleDeclaration should expose the CSSOM API only. Subclasses should expose the internal API only.
This will move us closer to being able to split the CSSOM API from the internal implementation.
- Make CSSStyleDeclaration CSSOM functions virtual, internal functions non-virtual.
- Move implementations to subclasses (CSSComputedStyleDeclaration, CSSMutableStyleDeclaration).
- Make CSSOM functions in the subclasses private (making it harder to invoke them internally).
- Switch a bunch of places to use internal API instead of CSSOM.
* bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp:
(WebCore::V8CSSStyleDeclaration::namedPropertyGetter):
(WebCore::V8CSSStyleDeclaration::namedPropertySetter):
Switch to *Internal versions of the CSSOM functions.
* css/CSSComputedStyleDeclaration.cpp:
(WebCore):
(WebCore::CSSComputedStyleDeclaration::length):
(WebCore::CSSComputedStyleDeclaration::cssPropertyMatches):
(WebCore::CSSComputedStyleDeclaration::copyPropertiesInSet):
Move copyPropertiesInSet to subclasses, devirtualize.
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
(WebCore::CSSComputedStyleDeclaration::getPropertyValue):
(WebCore::CSSComputedStyleDeclaration::getPropertyPriority):
(WebCore::CSSComputedStyleDeclaration::getPropertyShorthand):
(WebCore::CSSComputedStyleDeclaration::isPropertyImplicit):
(WebCore::CSSComputedStyleDeclaration::setProperty):
(WebCore::CSSComputedStyleDeclaration::removeProperty):
* css/CSSComputedStyleDeclaration.h:
(CSSComputedStyleDeclaration):
* css/CSSFontFaceRule.cpp:
(WebCore::CSSFontFaceRule::cssText):
* css/CSSMutableStyleDeclaration.cpp:
(WebCore::CSSMutableStyleDeclaration::length):
(WebCore::CSSMutableStyleDeclaration::asText):
(WebCore::CSSMutableStyleDeclaration::cssText):
(WebCore):
(WebCore::CSSMutableStyleDeclaration::getPropertyCSSValue):
(WebCore::CSSMutableStyleDeclaration::getPropertyValue):
(WebCore::CSSMutableStyleDeclaration::getPropertyPriority):
(WebCore::CSSMutableStyleDeclaration::getPropertyShorthand):
(WebCore::CSSMutableStyleDeclaration::isPropertyImplicit):
(WebCore::CSSMutableStyleDeclaration::setProperty):
(WebCore::CSSMutableStyleDeclaration::removeProperty):
(WebCore::CSSMutableStyleDeclaration::copyPropertiesInSet):
Move copyPropertiesInSet to subclasses, devirtualize.
(WebCore::CSSMutableStyleDeclaration::cssPropertyMatches):
(WebCore::CSSMutableStyleDeclaration::removeEquivalentProperties):
Move diff() to CSSMutableStyleDeclaration, rename to removeEquivalentProperties, switch to mutate
this object instead of the argument object.
* css/CSSMutableStyleDeclaration.h:
(CSSMutableStyleDeclaration):
(WebCore::CSSMutableStyleDeclaration::propertyCount):
(WebCore::CSSMutableStyleDeclaration::isEmpty):
(WebCore::CSSMutableStyleDeclaration::propertyAt):
Expose properties and property count internally (iterator should be removed in favor of these).
* css/CSSStyleDeclaration.cpp:
(WebCore):
* css/CSSStyleDeclaration.h:
(CSSStyleDeclaration):
(WebCore::CSSStyleDeclaration::getPropertyCSSValueInternal):
(WebCore::CSSStyleDeclaration::getPropertyValueInternal):
(WebCore::CSSStyleDeclaration::setPropertyInternal):
Add *Internal versions of some CSSOM APIs to support some editing and bindings uses.
These take propertyIDs instead of strings names.
* css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::cssText):
* css/CSSStyleSelector.cpp:
(WebCore::leftToRightDeclaration):
(WebCore::rightToLeftDeclaration):
(WebCore::CSSStyleSelector::collectMatchingRulesForList):
(WebCore::CSSStyleSelector::matchPageRulesForList):
* css/WebKitCSSKeyframeRule.cpp:
(WebCore::WebKitCSSKeyframeRule::cssText):
* dom/StyledElement.cpp:
(WebCore::StyledElement::updateStyleAttribute):
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
(WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock):
(WebCore::ApplyStyleCommand::applyInlineStyleToNodeRange):
(WebCore::ApplyStyleCommand::applyInlineStyleToPushDown):
(WebCore::ApplyStyleCommand::addBlockStyle):
(WebCore::ApplyStyleCommand::addInlineStyleIfNeeded):
* editing/EditingStyle.cpp:
():
(WebCore::copyEditingProperties):
(WebCore):
(WebCore::propertyCSSValue):
(WebCore::getRGBAFontColor):
(WebCore::EditingStyle::overrideWithStyle):
(WebCore::EditingStyle::removeStyleAddedByNode):
(WebCore::EditingStyle::removeStyleConflictingWithStyleOfNode):
(WebCore::EditingStyle::triStateOfStyle):
(WebCore::EditingStyle::styleIsPresentInComputedStyleOfNode):
(WebCore::EditingStyle::prepareToApplyAt):
(WebCore::removePropertiesInStyle):
(WebCore::EditingStyle::removeStyleFromRulesAndContext):
(WebCore::EditingStyle::removePropertiesInElementDefaultStyle):
(WebCore::StyleChange::StyleChange):
(WebCore::fontWeightIsBold):
(WebCore::getPropertiesNotIn):
(WebCore::getIdentifierValue):
(WebCore::hasTransparentBackgroundColor):
* editing/EditingStyle.h:
Adapt to changes.
(WebCore):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):
(WebCore::handleStyleSpansBeforeInsertion):
(WebCore::ReplaceSelectionCommand::handleStyleSpans):
* editing/mac/EditorMac.mm:
(WebCore::styleForSelectionStart):
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::appendStyleNodeOpenTag):
(WebCore::StyledMarkupAccumulator::appendElement):
* html/ImageDocument.cpp:
(WebCore::ImageDocument::resizeImageToFit):
(WebCore::ImageDocument::restoreImageSize):
(WebCore::ImageDocument::windowSizeChanged):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::setFont):
* html/canvas/CanvasStyle.cpp:
(WebCore::currentColor):
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyleSheet::revalidateStyle):
* page/PageSerializer.cpp:
(WebCore::PageSerializer::retrieveResourcesForCSSDeclaration):
* rendering/RenderTreeAsText.cpp:
(WebCore::isEmptyOrUnstyledAppleStyleSpan):
* svg/SVGStyledElement.cpp:
(WebCore::SVGStyledElement::getPresentationAttribute):
2012-01-30 Pavel Feldman <pfeldman@google.com>
Web Inspector: protocol validator should fail if one of response fields turns optional
......@@ -202,7 +202,7 @@ v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertyGetter(v8::Local<v8::S
return notHandledByInterceptor();
CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder());
RefPtr<CSSValue> cssValue = imp->getPropertyCSSValue(propInfo->propID);
RefPtr<CSSValue> cssValue = imp->getPropertyCSSValueInternal(static_cast<CSSPropertyID>(propInfo->propID));
if (cssValue) {
if (propInfo->hadPixelOrPosPrefix &&
cssValue->isPrimitiveValue()) {
......@@ -212,7 +212,7 @@ v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertyGetter(v8::Local<v8::S
return v8StringOrNull(cssValue->cssText());
}
String result = imp->getPropertyValue(propInfo->propID);
String result = imp->getPropertyValueInternal(static_cast<CSSPropertyID>(propInfo->propID));
if (result.isNull())
result = ""; // convert null to empty string.
......@@ -232,7 +232,7 @@ v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertySetter(v8::Local<v8::S
propertyValue.append("px");
ExceptionCode ec = 0;
imp->setProperty(propInfo->propID, propertyValue, false, ec);
imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), propertyValue, false, ec);
if (ec)
throwError(ec);
......
......@@ -29,6 +29,7 @@
#include "CSSBorderImage.h"
#include "CSSLineBoxContainValue.h"
#include "CSSMutableStyleDeclaration.h"
#include "CSSParser.h"
#include "CSSPrimitiveValue.h"
#include "CSSPrimitiveValueMappings.h"
#include "CSSProperty.h"
......@@ -2475,24 +2476,8 @@ String CSSComputedStyleDeclaration::getPropertyValue(int propertyID) const
return "";
}
bool CSSComputedStyleDeclaration::getPropertyPriority(int /*propertyID*/) const
{
// All computed styles have a priority of false (not "important").
return false;
}
String CSSComputedStyleDeclaration::removeProperty(int /*propertyID*/, ExceptionCode& ec)
{
ec = NO_MODIFICATION_ALLOWED_ERR;
return String();
}
void CSSComputedStyleDeclaration::setProperty(int /*propertyID*/, const String& /*value*/, bool /*important*/, ExceptionCode& ec)
{
ec = NO_MODIFICATION_ALLOWED_ERR;
}
unsigned CSSComputedStyleDeclaration::virtualLength() const
unsigned CSSComputedStyleDeclaration::length() const
{
Node* node = m_node.get();
if (!node)
......@@ -2525,8 +2510,8 @@ bool CSSComputedStyleDeclaration::cssPropertyMatches(const CSSProperty* property
return true;
}
}
return CSSStyleDeclaration::cssPropertyMatches(property);
RefPtr<CSSValue> value = getPropertyCSSValue(property->id());
return value && value->cssText() == property->value()->cssText();
}
PassRefPtr<CSSMutableStyleDeclaration> CSSComputedStyleDeclaration::copy() const
......@@ -2577,4 +2562,74 @@ PassRefPtr<CSSValueList> CSSComputedStyleDeclaration::getCSSPropertyValuesForSid
return list.release();
}
PassRefPtr<CSSMutableStyleDeclaration> CSSComputedStyleDeclaration::copyPropertiesInSet(const int* set, unsigned length) const
{
Vector<CSSProperty> list;
list.reserveInitialCapacity(length);
for (unsigned i = 0; i < length; ++i) {
RefPtr<CSSValue> value = getPropertyCSSValue(set[i]);
if (value)
list.append(CSSProperty(set[i], value.release(), false));
}
return CSSMutableStyleDeclaration::create(list);
}
PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(const String& propertyName)
{
int propertyID = cssPropertyID(propertyName);
if (!propertyID)
return 0;
return getPropertyCSSValue(propertyID);
}
String CSSComputedStyleDeclaration::getPropertyValue(const String &propertyName)
{
int propertyID = cssPropertyID(propertyName);
if (!propertyID)
return String();
return getPropertyValue(propertyID);
}
String CSSComputedStyleDeclaration::getPropertyPriority(const String&)
{
// All computed styles have a priority of not "important".
return "";
}
String CSSComputedStyleDeclaration::getPropertyShorthand(const String&)
{
return "";
}
bool CSSComputedStyleDeclaration::isPropertyImplicit(const String&)
{
return false;
}
void CSSComputedStyleDeclaration::setProperty(const String&, const String&, const String&, ExceptionCode& ec)
{
ec = NO_MODIFICATION_ALLOWED_ERR;
}
String CSSComputedStyleDeclaration::removeProperty(const String&, ExceptionCode& ec)
{
ec = NO_MODIFICATION_ALLOWED_ERR;
return String();
}
PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
{
return getPropertyCSSValue(propertyID);
}
String CSSComputedStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID)
{
return getPropertyValue(propertyID);
}
void CSSComputedStyleDeclaration::setPropertyInternal(CSSPropertyID, const String&, bool, ExceptionCode& ec)
{
ec = NO_MODIFICATION_ALLOWED_ERR;
}
} // namespace WebCore
......@@ -50,16 +50,9 @@ public:
friend PassRefPtr<CSSComputedStyleDeclaration> computedStyle(PassRefPtr<Node>, bool allowVisitedStyle, const String& pseudoElementName);
virtual ~CSSComputedStyleDeclaration();
virtual String cssText() const;
virtual unsigned virtualLength() const;
virtual String item(unsigned index) const;
virtual PassRefPtr<CSSValue> getPropertyCSSValue(int propertyID) const;
virtual String getPropertyValue(int propertyID) const;
virtual bool getPropertyPriority(int propertyID) const;
virtual int getPropertyShorthand(int /*propertyID*/) const { return -1; }
virtual bool isPropertyImplicit(int /*propertyID*/) const { return false; }
PassRefPtr<CSSValue> getPropertyCSSValue(int propertyID) const;
String getPropertyValue(int propertyID) const;
bool getPropertyPriority(int propertyID) const;
virtual PassRefPtr<CSSMutableStyleDeclaration> copy() const;
virtual PassRefPtr<CSSMutableStyleDeclaration> makeMutable();
......@@ -71,16 +64,28 @@ public:
PassRefPtr<CSSValue> getSVGPropertyCSSValue(int propertyID, EUpdateLayout) const;
#endif
protected:
virtual bool cssPropertyMatches(const CSSProperty*) const;
PassRefPtr<CSSMutableStyleDeclaration> copyPropertiesInSet(const int* set, unsigned length) const;
private:
CSSComputedStyleDeclaration(PassRefPtr<Node>, bool allowVisitedStyle, const String&);
// CSSOM functions. Don't make these public.
virtual unsigned length() const;
virtual String item(unsigned index) const;
virtual PassRefPtr<CSSValue> getPropertyCSSValue(const String& propertyName);
virtual String getPropertyValue(const String& propertyName);
virtual String getPropertyPriority(const String& propertyName);
virtual String getPropertyShorthand(const String& propertyName);
virtual bool isPropertyImplicit(const String& propertyName);
virtual void setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode&);
virtual String removeProperty(const String& propertyName, ExceptionCode&);
virtual String cssText() const;
virtual void setCssText(const String&, ExceptionCode&);
virtual PassRefPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID);
virtual String getPropertyValueInternal(CSSPropertyID);
virtual void setPropertyInternal(CSSPropertyID, const String& value, bool important, ExceptionCode&);
virtual String removeProperty(int propertyID, ExceptionCode&);
virtual void setProperty(int propertyId, const String& value, bool important, ExceptionCode&);
virtual bool cssPropertyMatches(const CSSProperty*) const;
PassRefPtr<CSSValue> valueForShadow(const ShadowData*, int, RenderStyle*) const;
PassRefPtr<CSSPrimitiveValue> currentColorOrValidColor(RenderStyle*, const Color&) const;
......
......@@ -42,7 +42,7 @@ String CSSFontFaceRule::cssText() const
{
String result("@font-face");
result += " { ";
result += m_style->cssText();
result += m_style->asText();
result += "}";
return result;
}
......
......@@ -682,18 +682,6 @@ bool CSSMutableStyleDeclaration::isPropertyImplicit(int propertyID) const
return property ? property->isImplicit() : false;
}
void CSSMutableStyleDeclaration::setProperty(int propertyID, const String& value, bool important, ExceptionCode& ec)
{
ec = 0;
setProperty(propertyID, value, important, true);
}
String CSSMutableStyleDeclaration::removeProperty(int propertyID, ExceptionCode& ec)
{
ec = 0;
return removeProperty(propertyID, true, true);
}
bool CSSMutableStyleDeclaration::setProperty(int propertyID, const String& value, bool important, bool notifyChanged)
{
ASSERT(!m_iteratorCount);
......@@ -826,9 +814,9 @@ void CSSMutableStyleDeclaration::addParsedProperty(const CSSProperty& property)
#endif
}
unsigned CSSMutableStyleDeclaration::virtualLength() const
unsigned CSSMutableStyleDeclaration::length() const
{
return length();
return propertyCount();
}
String CSSMutableStyleDeclaration::item(unsigned i) const
......@@ -838,7 +826,7 @@ String CSSMutableStyleDeclaration::item(unsigned i) const
return getPropertyName(static_cast<CSSPropertyID>(m_properties[i].id()));
}
String CSSMutableStyleDeclaration::cssText() const
String CSSMutableStyleDeclaration::asText() const
{
String result = "";
......@@ -1052,4 +1040,119 @@ CSSProperty* CSSMutableStyleDeclaration::findPropertyWithId(int propertyID)
return 0;
}
String CSSMutableStyleDeclaration::cssText() const
{
return asText();
}
PassRefPtr<CSSValue> CSSMutableStyleDeclaration::getPropertyCSSValue(const String& propertyName)
{
int propertyID = cssPropertyID(propertyName);
if (!propertyID)
return 0;
return getPropertyCSSValue(propertyID);
}
String CSSMutableStyleDeclaration::getPropertyValue(const String &propertyName)
{
int propertyID = cssPropertyID(propertyName);
if (!propertyID)
return String();
return getPropertyValue(propertyID);
}
String CSSMutableStyleDeclaration::getPropertyPriority(const String& propertyName)
{
int propertyID = cssPropertyID(propertyName);
if (!propertyID)
return String();
return getPropertyPriority(propertyID) ? "important" : "";
}
String CSSMutableStyleDeclaration::getPropertyShorthand(const String& propertyName)
{
int propertyID = cssPropertyID(propertyName);
if (!propertyID)
return String();
int shorthandID = getPropertyShorthand(propertyID);
if (!shorthandID)
return String();
return getPropertyName(static_cast<CSSPropertyID>(shorthandID));
}
bool CSSMutableStyleDeclaration::isPropertyImplicit(const String& propertyName)
{
int propertyID = cssPropertyID(propertyName);
if (!propertyID)
return false;
return isPropertyImplicit(propertyID);
}
void CSSMutableStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode& ec)
{
int propertyID = cssPropertyID(propertyName);
if (!propertyID)
return;
bool important = priority.find("important", 0, false) != notFound;
ec = 0;
setProperty(propertyID, value, important, true);
}
String CSSMutableStyleDeclaration::removeProperty(const String& propertyName, ExceptionCode& ec)
{
int propertyID = cssPropertyID(propertyName);
if (!propertyID)
return String();
ec = 0;
return removeProperty(propertyID, true, true);
}
PassRefPtr<CSSValue> CSSMutableStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
{
return getPropertyCSSValue(propertyID);
}
String CSSMutableStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID)
{
return getPropertyValue(propertyID);
}
void CSSMutableStyleDeclaration::setPropertyInternal(CSSPropertyID propertyID, const String& value, bool important, ExceptionCode& ec)
{
ec = 0;
setProperty(propertyID, value, important, true);
}
PassRefPtr<CSSMutableStyleDeclaration> CSSMutableStyleDeclaration::copyPropertiesInSet(const int* set, unsigned length) const
{
Vector<CSSProperty> list;
list.reserveInitialCapacity(length);
for (unsigned i = 0; i < length; ++i) {
RefPtr<CSSValue> value = getPropertyCSSValue(set[i]);
if (value)
list.append(CSSProperty(set[i], value.release(), false));
}
return CSSMutableStyleDeclaration::create(list);
}
bool CSSMutableStyleDeclaration::cssPropertyMatches(const CSSProperty* property) const
{
RefPtr<CSSValue> value = getPropertyCSSValue(property->id());
return value && value->cssText() == property->value()->cssText();
}
void CSSMutableStyleDeclaration::removeEquivalentProperties(const CSSStyleDeclaration* style)
{
Vector<int> propertiesToRemove;
size_t size = m_properties.size();
for (size_t i = 0; i < size; ++i) {
const CSSProperty& property = m_properties[i];
if (style->cssPropertyMatches(&property))
propertiesToRemove.append(property.id());
}
// FIXME: This should use mass removal.
for (unsigned i = 0; i < propertiesToRemove.size(); ++i)
removeProperty(propertiesToRemove[i]);
}
} // namespace WebCore
......@@ -83,6 +83,8 @@ public:
{
return adoptRef(new CSSMutableStyleDeclaration(element, false));
}
static bool isPropertyName(const String&);
// Used by StyledElement::copyNonAttributeProperties().
void copyPropertiesFrom(const CSSMutableStyleDeclaration&);
......@@ -92,27 +94,18 @@ public:
const_iterator begin() { return const_iterator(this, m_properties.begin()); }
const_iterator end() { return const_iterator(this, m_properties.end()); }
virtual String cssText() const;
virtual void setCssText(const String&, ExceptionCode&);
unsigned propertyCount() const { return m_properties.size(); }
bool isEmpty() const { return m_properties.isEmpty(); }
const CSSProperty& propertyAt(unsigned index) const { return m_properties[index]; }
virtual unsigned virtualLength() const;
unsigned length() const { return m_properties.size(); }
virtual String item(unsigned index) const;
virtual PassRefPtr<CSSValue> getPropertyCSSValue(int propertyID) const;
virtual String getPropertyValue(int propertyID) const;
virtual bool getPropertyPriority(int propertyID) const;
virtual int getPropertyShorthand(int propertyID) const;
virtual bool isPropertyImplicit(int propertyID) const;
virtual void setProperty(int propertyId, const String& value, bool important, ExceptionCode&);
virtual String removeProperty(int propertyID, ExceptionCode&);
PassRefPtr<CSSValue> getPropertyCSSValue(int propertyID) const;
String getPropertyValue(int propertyID) const;
bool getPropertyPriority(int propertyID) const;
int getPropertyShorthand(int propertyID) const;
bool isPropertyImplicit(int propertyID) const;
virtual PassRefPtr<CSSMutableStyleDeclaration> copy() const;
using CSSStyleDeclaration::getPropertyCSSValue;
bool setProperty(int propertyID, int value, bool important = false) { return setProperty(propertyID, value, important, true); }
bool setProperty(int propertyId, double value, CSSPrimitiveValue::UnitTypes unit, bool important = false) { return setProperty(propertyId, value, unit, important, true); }
bool setProperty(int propertyID, const String& value, bool important = false) { return setProperty(propertyID, value, important, true); }
......@@ -138,6 +131,12 @@ public:
bool useStrictParsing() const { return m_strictParsing; }
void addSubresourceStyleURLs(ListHashSet<KURL>&);
void removeEquivalentProperties(const CSSStyleDeclaration*);
PassRefPtr<CSSMutableStyleDeclaration> copyPropertiesInSet(const int* set, unsigned length) const;
String asText() const;
protected:
CSSMutableStyleDeclaration();
......@@ -153,6 +152,22 @@ private:
virtual PassRefPtr<CSSMutableStyleDeclaration> makeMutable();
// CSSOM functions. Don't make these public.
virtual unsigned length() const;
virtual String item(unsigned index) const;
virtual PassRefPtr<CSSValue> getPropertyCSSValue(const String& propertyName);
virtual String getPropertyValue(const String& propertyName);
virtual String getPropertyPriority(const String& propertyName);
virtual String getPropertyShorthand(const String& propertyName);
virtual bool isPropertyImplicit(const String& propertyName);
virtual void setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode&);
virtual String removeProperty(const String& propertyName, ExceptionCode&);
virtual String cssText() const;
virtual void setCssText(const String&, ExceptionCode&);
virtual PassRefPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID);
virtual String getPropertyValueInternal(CSSPropertyID);
virtual void setPropertyInternal(CSSPropertyID, const String& value, bool important, ExceptionCode&);
void setNeedsStyleRecalc();
String getShorthandValue(const int* properties, size_t) const;
......@@ -173,6 +188,8 @@ private:
bool removeShorthandProperty(int propertyID, bool notifyChanged);
bool removePropertiesInSet(const int* set, unsigned length, bool notifyChanged);
virtual bool cssPropertyMatches(const CSSProperty*) const;
Vector<CSSProperty>::const_iterator findPropertyWithId(int propertyId) const;
Vector<CSSProperty>::iterator findPropertyWithId(int propertyId);
......
......@@ -77,109 +77,11 @@ CSSStyleSheet* CSSStyleDeclaration::parentStyleSheet() const
return m_parent.rule->parentStyleSheet();
}
PassRefPtr<CSSValue> CSSStyleDeclaration::getPropertyCSSValue(const String& propertyName)
{
int propID = cssPropertyID(propertyName);
if (!propID)
return 0;
return getPropertyCSSValue(propID);
}
String CSSStyleDeclaration::getPropertyValue(const String &propertyName)
{
int propID = cssPropertyID(propertyName);
if (!propID)
return String();
return getPropertyValue(propID);
}
String CSSStyleDeclaration::getPropertyPriority(const String& propertyName)
{
int propID = cssPropertyID(propertyName);
if (!propID)
return String();
return getPropertyPriority(propID) ? "important" : "";
}
String CSSStyleDeclaration::getPropertyShorthand(const String& propertyName)
{
int propID = cssPropertyID(propertyName);
if (!propID)
return String();
int shorthandID = getPropertyShorthand(propID);
if (!shorthandID)
return String();
return getPropertyName(static_cast<CSSPropertyID>(shorthandID));