Diff
Modified: trunk/Source/WebCore/ChangeLog (105738 => 105739)
--- trunk/Source/WebCore/ChangeLog 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/ChangeLog 2012-01-24 16:09:05 UTC (rev 105739)
@@ -1,3 +1,48 @@
+2012-01-24 Antti Koivisto <[email protected]>
+
+ Reduce internal use of CSSStyleDeclaration base class
+ https://bugs.webkit.org/show_bug.cgi?id=76904
+
+ Reviewed by Andreas Kling.
+
+ Internally WebCore should use the more specific CSSMutableStyleDeclaration and CSSComputedStyleDeclaration types.
+ The CSSStyleDeclaration base should be used in the DOM API functions only. This will make it easier to separate
+ internal style sheet implementation from the DOM in the future.
+
+ - Switch CSSStyleDeclaration -> CSSMutableStyleDeclaration where feasible
+ - Use StyledElement::ensureInlineStyleDecl() instead of Element::style() (which is a DOM API function)
+ - Remove Attribute::style() which looks like a DOM API function but is not exposed.
+
+ * css/CSSMutableStyleDeclaration.h:
+ (WebCore::CSSMutableStyleDeclaration::getPropertyCSSValue):
+ * dom/Attr.h:
+ (WebCore::Attr::style):
+ * dom/Attribute.h:
+ * editing/EditingStyle.cpp:
+ (WebCore::HTMLElementEquivalent::propertyExistsInStyle):
+ (WebCore::HTMLElementEquivalent::valueIsPresentInStyle):
+ (WebCore::HTMLTextDecorationEquivalent::propertyExistsInStyle):
+ (WebCore::HTMLTextDecorationEquivalent::valueIsPresentInStyle):
+ (WebCore::HTMLAttributeEquivalent::valueIsPresentInStyle):
+ * editing/Editor.cpp:
+ (WebCore::Editor::applyEditingStyleToElement):
+ * editing/markup.cpp:
+ (WebCore::StyledMarkupAccumulator::wrapWithStyleNode):
+ (WebCore::StyledMarkupAccumulator::appendStyleNodeOpenTag):
+ (WebCore::propertyMissingOrEqualToNone):
+ * inspector/InspectorCSSAgent.cpp:
+ (WebCore::InspectorCSSAgent::buildArrayForAttributeStyles):
+ * page/DragController.cpp:
+ (WebCore::DragController::concludeEditDrag):
+ * page/PageSerializer.cpp:
+ (WebCore::PageSerializer::serializeFrame):
+ (WebCore::PageSerializer::retrieveResourcesForCSSDeclaration):
+ * page/PageSerializer.h:
+ * rendering/RenderLayer.cpp:
+ (WebCore::RenderLayer::resize):
+ * svg/SVGStyledElement.cpp:
+ (WebCore::SVGStyledElement::getPresentationAttribute):
+
2012-01-23 Andreas Kling <[email protected]>
Make elements that don't have attributes smaller.
Modified: trunk/Source/WebCore/css/CSSMutableStyleDeclaration.h (105738 => 105739)
--- trunk/Source/WebCore/css/CSSMutableStyleDeclaration.h 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/css/CSSMutableStyleDeclaration.h 2012-01-24 16:09:05 UTC (rev 105739)
@@ -111,6 +111,8 @@
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); }
Modified: trunk/Source/WebCore/dom/Attr.h (105738 => 105739)
--- trunk/Source/WebCore/dom/Attr.h 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/dom/Attr.h 2012-01-24 16:09:05 UTC (rev 105739)
@@ -56,7 +56,7 @@
bool isId() const;
// An extension to get presentational information for attributes.
- CSSStyleDeclaration* style() { return m_attribute->style(); }
+ CSSStyleDeclaration* style() { return m_attribute->decl(); }
void setSpecified(bool specified) { m_specified = specified; }
Modified: trunk/Source/WebCore/dom/Attribute.h (105738 => 105739)
--- trunk/Source/WebCore/dom/Attribute.h 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/dom/Attribute.h 2012-01-24 16:09:05 UTC (rev 105739)
@@ -69,8 +69,6 @@
PassRefPtr<Attribute> clone() const;
- // An extension to get the style information for presentational attributes.
- CSSStyleDeclaration* style() const { return m_styleDecl.get(); }
CSSMappedAttributeDeclaration* decl() const { return m_styleDecl.get(); }
void setDecl(PassRefPtr<CSSMappedAttributeDeclaration> decl) { m_styleDecl = decl; }
Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (105738 => 105739)
--- trunk/Source/WebCore/editing/EditingStyle.cpp 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp 2012-01-24 16:09:05 UTC (rev 105739)
@@ -121,8 +121,8 @@
virtual ~HTMLElementEquivalent() { }
virtual bool matches(const Element* element) const { return !m_tagName || element->hasTagName(*m_tagName); }
virtual bool hasAttribute() const { return false; }
- virtual bool propertyExistsInStyle(CSSStyleDeclaration* style) const { return style && style->getPropertyCSSValue(m_propertyID); }
- virtual bool valueIsPresentInStyle(Element*, CSSStyleDeclaration*) const;
+ virtual bool propertyExistsInStyle(CSSMutableStyleDeclaration* style) const { return style && style->getPropertyCSSValue(m_propertyID); }
+ virtual bool valueIsPresentInStyle(Element*, CSSMutableStyleDeclaration*) const;
virtual void addToStyle(Element*, EditingStyle*) const;
protected:
@@ -154,7 +154,7 @@
ASSERT(primitiveValue != CSSValueInvalid);
}
-bool HTMLElementEquivalent::valueIsPresentInStyle(Element* element, CSSStyleDeclaration* style) const
+bool HTMLElementEquivalent::valueIsPresentInStyle(Element* element, CSSMutableStyleDeclaration* style) const
{
RefPtr<CSSValue> value = style->getPropertyCSSValue(m_propertyID);
return matches(element) && value && value->isPrimitiveValue() && static_cast<CSSPrimitiveValue*>(value.get())->getIdent() == m_primitiveValue->getIdent();
@@ -171,8 +171,8 @@
{
return adoptPtr(new HTMLTextDecorationEquivalent(primitiveValue, tagName));
}
- virtual bool propertyExistsInStyle(CSSStyleDeclaration*) const;
- virtual bool valueIsPresentInStyle(Element*, CSSStyleDeclaration*) const;
+ virtual bool propertyExistsInStyle(CSSMutableStyleDeclaration*) const;
+ virtual bool valueIsPresentInStyle(Element*, CSSMutableStyleDeclaration*) const;
private:
HTMLTextDecorationEquivalent(int primitiveValue, const QualifiedName& tagName);
@@ -184,12 +184,12 @@
{
}
-bool HTMLTextDecorationEquivalent::propertyExistsInStyle(CSSStyleDeclaration* style) const
+bool HTMLTextDecorationEquivalent::propertyExistsInStyle(CSSMutableStyleDeclaration* style) const
{
return style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect) || style->getPropertyCSSValue(CSSPropertyTextDecoration);
}
-bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(Element* element, CSSStyleDeclaration* style) const
+bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(Element* element, CSSMutableStyleDeclaration* style) const
{
RefPtr<CSSValue> styleValue = style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);
if (!styleValue)
@@ -210,7 +210,7 @@
bool matches(const Element* elem) const { return HTMLElementEquivalent::matches(elem) && elem->hasAttribute(m_attrName); }
virtual bool hasAttribute() const { return true; }
- virtual bool valueIsPresentInStyle(Element*, CSSStyleDeclaration*) const;
+ virtual bool valueIsPresentInStyle(Element*, CSSMutableStyleDeclaration*) const;
virtual void addToStyle(Element*, EditingStyle*) const;
virtual PassRefPtr<CSSValue> attributeValueAsCSSValue(Element*) const;
inline const QualifiedName& attributeName() const { return m_attrName; }
@@ -233,7 +233,7 @@
{
}
-bool HTMLAttributeEquivalent::valueIsPresentInStyle(Element* element, CSSStyleDeclaration* style) const
+bool HTMLAttributeEquivalent::valueIsPresentInStyle(Element* element, CSSMutableStyleDeclaration* style) const
{
RefPtr<CSSValue> value = attributeValueAsCSSValue(element);
RefPtr<CSSValue> styleValue = style->getPropertyCSSValue(m_propertyID);
Modified: trunk/Source/WebCore/editing/Editor.cpp (105738 => 105739)
--- trunk/Source/WebCore/editing/Editor.cpp 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/editing/Editor.cpp 2012-01-24 16:09:05 UTC (rev 105739)
@@ -2747,12 +2747,10 @@
{
if (!element)
return;
-
- CSSStyleDeclaration* style = element->style();
- ASSERT(style);
- if (!style)
+ ASSERT(element->isStyledElement());
+ if (!element->isStyledElement())
return;
-
+ CSSMutableStyleDeclaration* style = static_cast<StyledElement*>(element)->ensureInlineStyleDecl();
ExceptionCode ec = 0;
style->setProperty(CSSPropertyWordWrap, "break-word", false, ec);
ASSERT(!ec);
Modified: trunk/Source/WebCore/editing/markup.cpp (105738 => 105739)
--- trunk/Source/WebCore/editing/markup.cpp 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/editing/markup.cpp 2012-01-24 16:09:05 UTC (rev 105739)
@@ -69,7 +69,7 @@
using namespace HTMLNames;
-static bool propertyMissingOrEqualToNone(CSSStyleDeclaration*, int propertyID);
+static bool propertyMissingOrEqualToNone(CSSMutableStyleDeclaration*, int propertyID);
class AttributeChange {
public:
@@ -127,11 +127,11 @@
Node* serializeNodes(Node* startNode, Node* pastEnd);
virtual void appendString(const String& s) { return MarkupAccumulator::appendString(s); }
void wrapWithNode(Node*, bool convertBlocksToInlines = false, RangeFullySelectsNode = DoesFullySelectNode);
- void wrapWithStyleNode(CSSStyleDeclaration*, Document*, bool isBlock = false);
+ void wrapWithStyleNode(CSSMutableStyleDeclaration*, Document*, bool isBlock = false);
String takeResults();
private:
- void appendStyleNodeOpenTag(StringBuilder&, CSSStyleDeclaration*, Document*, bool isBlock = false);
+ void appendStyleNodeOpenTag(StringBuilder&, CSSMutableStyleDeclaration*, Document*, bool isBlock = false);
const String styleNodeCloseTag(bool isBlock = false);
virtual void appendText(StringBuilder& out, Text*);
String renderedText(const Node*, const Range*);
@@ -176,7 +176,7 @@
m_nodes->append(node);
}
-void StyledMarkupAccumulator::wrapWithStyleNode(CSSStyleDeclaration* style, Document* document, bool isBlock)
+void StyledMarkupAccumulator::wrapWithStyleNode(CSSMutableStyleDeclaration* style, Document* document, bool isBlock)
{
StringBuilder openTag;
appendStyleNodeOpenTag(openTag, style, document, isBlock);
@@ -184,7 +184,7 @@
appendString(styleNodeCloseTag(isBlock));
}
-void StyledMarkupAccumulator::appendStyleNodeOpenTag(StringBuilder& out, CSSStyleDeclaration* style, Document* document, bool isBlock)
+void StyledMarkupAccumulator::appendStyleNodeOpenTag(StringBuilder& out, CSSMutableStyleDeclaration* style, Document* document, bool isBlock)
{
// wrappingStyleForSerialization should have removed -webkit-text-decorations-in-effect
ASSERT(propertyMissingOrEqualToNone(style, CSSPropertyWebkitTextDecorationsInEffect));
@@ -465,7 +465,7 @@
return ancestorToRetainStructureAndAppearanceForBlock(commonAncestorBlock);
}
-static bool propertyMissingOrEqualToNone(CSSStyleDeclaration* style, int propertyID)
+static bool propertyMissingOrEqualToNone(CSSMutableStyleDeclaration* style, int propertyID)
{
if (!style)
return false;
Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (105738 => 105739)
--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp 2012-01-24 16:09:05 UTC (rev 105739)
@@ -720,14 +720,14 @@
NamedNodeMap* attributes = element->attributes();
for (unsigned i = 0; attributes && i < attributes->length(); ++i) {
Attribute* attribute = attributes->attributeItem(i);
- if (attribute->style()) {
- RefPtr<InspectorObject> attrStyleObject = InspectorObject::create();
- String attributeName = attribute->localName();
- RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), attribute->style(), 0);
- attrStyleObject->setString("name", attributeName.utf8().data());
- attrStyleObject->setObject("style", inspectorStyle->buildObjectForStyle());
- attrStyles->pushObject(attrStyleObject.release());
- }
+ if (!attribute->decl())
+ continue;
+ RefPtr<InspectorObject> attrStyleObject = InspectorObject::create();
+ String attributeName = attribute->localName();
+ RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), attribute->decl(), 0);
+ attrStyleObject->setString("name", attributeName.utf8().data());
+ attrStyleObject->setObject("style", inspectorStyle->buildObjectForStyle());
+ attrStyles->pushObject(attrStyleObject.release());
}
return attrStyles.release();
Modified: trunk/Source/WebCore/page/DragController.cpp (105738 => 105739)
--- trunk/Source/WebCore/page/DragController.cpp 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/page/DragController.cpp 2012-01-24 16:09:05 UTC (rev 105739)
@@ -27,7 +27,7 @@
#include "DragController.h"
#if ENABLE(DRAG_SUPPORT)
-#include "CSSStyleDeclaration.h"
+#include "CSSMutableStyleDeclaration.h"
#include "Clipboard.h"
#include "ClipboardAccessPolicy.h"
#include "CachedResourceLoader.h"
@@ -445,7 +445,7 @@
if (!color.isValid())
return false;
RefPtr<Range> innerRange = innerFrame->selection()->toNormalizedRange();
- RefPtr<CSSStyleDeclaration> style = m_documentUnderMouse->createCSSStyleDeclaration();
+ RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
ExceptionCode ec;
style->setProperty(CSSPropertyColor, color.serialized(), false, ec);
if (!innerFrame->editor()->shouldApplyStyle(style.get(), innerRange.get()))
Modified: trunk/Source/WebCore/page/PageSerializer.cpp (105738 => 105739)
--- trunk/Source/WebCore/page/PageSerializer.cpp 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/page/PageSerializer.cpp 2012-01-24 16:09:05 UTC (rev 105739)
@@ -225,7 +225,8 @@
Element* element = toElement(node);
// We have to process in-line style as it might contain some resources (typically background images).
- retrieveResourcesForCSSDeclaration(element->style());
+ if (element->isStyledElement())
+ retrieveResourcesForCSSDeclaration(static_cast<StyledElement*>(element)->inlineStyleDecl());
if (element->hasTagName(HTMLNames::imgTag)) {
HTMLImageElement* imageElement = static_cast<HTMLImageElement*>(element);
@@ -305,7 +306,7 @@
retrieveResourcesForCSSDeclaration(rule->style());
}
-void PageSerializer::retrieveResourcesForCSSDeclaration(CSSStyleDeclaration* styleDeclaration)
+void PageSerializer::retrieveResourcesForCSSDeclaration(CSSMutableStyleDeclaration* styleDeclaration)
{
if (!styleDeclaration)
return;
Modified: trunk/Source/WebCore/page/PageSerializer.h (105738 => 105739)
--- trunk/Source/WebCore/page/PageSerializer.h 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/page/PageSerializer.h 2012-01-24 16:09:05 UTC (rev 105739)
@@ -41,7 +41,7 @@
namespace WebCore {
class CachedImage;
-class CSSStyleDeclaration;
+class CSSMutableStyleDeclaration;
class CSSStyleRule;
class CSSStyleSheet;
class Frame;
@@ -77,7 +77,7 @@
void serializeCSSStyleSheet(CSSStyleSheet*, const KURL&);
void addImageToResources(CachedImage*, RenderObject*, const KURL&);
- void retrieveResourcesForCSSDeclaration(CSSStyleDeclaration*);
+ void retrieveResourcesForCSSDeclaration(CSSMutableStyleDeclaration*);
void retrieveResourcesForCSSRule(CSSStyleRule*);
Vector<Resource>* m_resources;
Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (105738 => 105739)
--- trunk/Source/WebCore/rendering/RenderLayer.cpp 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp 2012-01-24 16:09:05 UTC (rev 105739)
@@ -45,8 +45,8 @@
#include "RenderLayer.h"
#include "ColumnInfo.h"
+#include "CSSMutableStyleDeclaration.h"
#include "CSSPropertyNames.h"
-#include "CSSStyleDeclaration.h"
#include "CSSStyleSelector.h"
#include "Chrome.h"
#include "Document.h"
@@ -1705,7 +1705,8 @@
LayoutSize difference = (currentSize + newOffset - adjustedOldOffset).expandedTo(minimumSize) - currentSize;
- CSSStyleDeclaration* style = element->style();
+ ASSERT(element->isStyledElement());
+ CSSMutableStyleDeclaration* styleDeclaration = static_cast<StyledElement*>(element)->ensureInlineStyleDecl();
bool isBoxSizingBorder = renderer->style()->boxSizing() == BORDER_BOX;
ExceptionCode ec;
@@ -1713,23 +1714,23 @@
if (resize != RESIZE_VERTICAL && difference.width()) {
if (element->isFormControlElement()) {
// Make implicit margins from the theme explicit (see <http://bugs.webkit.org/show_bug.cgi?id=9547>).
- style->setProperty(CSSPropertyMarginLeft, String::number(renderer->marginLeft() / zoomFactor) + "px", false, ec);
- style->setProperty(CSSPropertyMarginRight, String::number(renderer->marginRight() / zoomFactor) + "px", false, ec);
+ styleDeclaration->setProperty(CSSPropertyMarginLeft, String::number(renderer->marginLeft() / zoomFactor) + "px", false, ec);
+ styleDeclaration->setProperty(CSSPropertyMarginRight, String::number(renderer->marginRight() / zoomFactor) + "px", false, ec);
}
LayoutUnit baseWidth = renderer->width() - (isBoxSizingBorder ? 0 : renderer->borderAndPaddingWidth());
baseWidth = baseWidth / zoomFactor;
- style->setProperty(CSSPropertyWidth, String::number(baseWidth + difference.width()) + "px", false, ec);
+ styleDeclaration->setProperty(CSSPropertyWidth, String::number(baseWidth + difference.width()) + "px", false, ec);
}
if (resize != RESIZE_HORIZONTAL && difference.height()) {
if (element->isFormControlElement()) {
// Make implicit margins from the theme explicit (see <http://bugs.webkit.org/show_bug.cgi?id=9547>).
- style->setProperty(CSSPropertyMarginTop, String::number(renderer->marginTop() / zoomFactor) + "px", false, ec);
- style->setProperty(CSSPropertyMarginBottom, String::number(renderer->marginBottom() / zoomFactor) + "px", false, ec);
+ styleDeclaration->setProperty(CSSPropertyMarginTop, String::number(renderer->marginTop() / zoomFactor) + "px", false, ec);
+ styleDeclaration->setProperty(CSSPropertyMarginBottom, String::number(renderer->marginBottom() / zoomFactor) + "px", false, ec);
}
LayoutUnit baseHeight = renderer->height() - (isBoxSizingBorder ? 0 : renderer->borderAndPaddingHeight());
baseHeight = baseHeight / zoomFactor;
- style->setProperty(CSSPropertyHeight, String::number(baseHeight + difference.height()) + "px", false, ec);
+ styleDeclaration->setProperty(CSSPropertyHeight, String::number(baseHeight + difference.height()) + "px", false, ec);
}
document->updateLayout();
Modified: trunk/Source/WebCore/svg/SVGStyledElement.cpp (105738 => 105739)
--- trunk/Source/WebCore/svg/SVGStyledElement.cpp 2012-01-24 15:42:07 UTC (rev 105738)
+++ trunk/Source/WebCore/svg/SVGStyledElement.cpp 2012-01-24 16:09:05 UTC (rev 105739)
@@ -422,7 +422,7 @@
QualifiedName attributeName(nullAtom, name, nullAtom);
Attribute* attr = attributeMap()->getAttributeItem(attributeName);
- if (!attr || !attr->isMappedAttribute() || !attr->style())
+ if (!attr || !attr->isMappedAttribute() || !attr->decl())
return 0;
Attribute* cssSVGAttr = attr;
@@ -437,7 +437,7 @@
int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(cssSVGAttr->name());
addCSSProperty(cssSVGAttr, propId, cssSVGAttr->value());
}
- return cssSVGAttr->style()->getPropertyCSSValue(name);
+ return cssSVGAttr->decl()->getPropertyCSSValue(name);
}
bool SVGStyledElement::instanceUpdatesBlocked() const