- Revision
- 143868
- Author
- [email protected]
- Date
- 2013-02-24 08:45:21 -0800 (Sun, 24 Feb 2013)
Log Message
StyledElement: Don't expose a mutable direct interface to the inline style.
<http://webkit.org/b/110711>
Reviewed by Antti Koivisto.
Source/WebCore:
Remove the ability to grab at a mutable StylePropertySet* for a StyledElement's inline style
from the outside world. It's now private and returns MutableStylePropertySet* for future convenience.
Three paths to changing the inline style remain:
- Setting the "style" attribute
- Via CSSOM (element.style)
- setInlineStyleProperty/removeInlineStyleProperty helpers
* dom/StyledElement.cpp:
(WebCore::StyledElement::ensureMutableInlineStyle):
* dom/StyledElement.h:
(StyledElement):
* editing/ApplyStyleCommand.cpp:
(WebCore::copyStyleOrCreateEmpty):
(WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
(WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock):
(WebCore::ApplyStyleCommand::applyInlineStyleToNodeRange):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::handleStyleSpans):
* html/canvas/CanvasStyle.cpp:
(WebCore::currentColor):
Source/WebKit/qt:
QWebElement::styleProperty() is a read-only method, so rewrite it to use StyledElement::inlineStyle().
* Api/qwebelement.cpp:
(QWebElement::styleProperty):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (143867 => 143868)
--- trunk/Source/WebCore/ChangeLog 2013-02-24 16:42:41 UTC (rev 143867)
+++ trunk/Source/WebCore/ChangeLog 2013-02-24 16:45:21 UTC (rev 143868)
@@ -1,3 +1,33 @@
+2013-02-24 Andreas Kling <[email protected]>
+
+ StyledElement: Don't expose a mutable direct interface to the inline style.
+ <http://webkit.org/b/110711>
+
+ Reviewed by Antti Koivisto.
+
+ Remove the ability to grab at a mutable StylePropertySet* for a StyledElement's inline style
+ from the outside world. It's now private and returns MutableStylePropertySet* for future convenience.
+
+ Three paths to changing the inline style remain:
+
+ - Setting the "style" attribute
+ - Via CSSOM (element.style)
+ - setInlineStyleProperty/removeInlineStyleProperty helpers
+
+ * dom/StyledElement.cpp:
+ (WebCore::StyledElement::ensureMutableInlineStyle):
+ * dom/StyledElement.h:
+ (StyledElement):
+ * editing/ApplyStyleCommand.cpp:
+ (WebCore::copyStyleOrCreateEmpty):
+ (WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
+ (WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock):
+ (WebCore::ApplyStyleCommand::applyInlineStyleToNodeRange):
+ * editing/ReplaceSelectionCommand.cpp:
+ (WebCore::ReplaceSelectionCommand::handleStyleSpans):
+ * html/canvas/CanvasStyle.cpp:
+ (WebCore::currentColor):
+
2013-02-24 Keishi Hattori <[email protected]>
Add methods to date types for new calendar picker
Modified: trunk/Source/WebCore/dom/StyledElement.cpp (143867 => 143868)
--- trunk/Source/WebCore/dom/StyledElement.cpp 2013-02-24 16:42:41 UTC (rev 143867)
+++ trunk/Source/WebCore/dom/StyledElement.cpp 2013-02-24 16:45:21 UTC (rev 143868)
@@ -146,14 +146,15 @@
return ensureMutableInlineStyle()->ensureInlineCSSStyleDeclaration(this);
}
-StylePropertySet* StyledElement::ensureMutableInlineStyle()
+MutableStylePropertySet* StyledElement::ensureMutableInlineStyle()
{
RefPtr<StylePropertySet>& inlineStyle = ensureUniqueElementData()->m_inlineStyle;
if (!inlineStyle)
inlineStyle = StylePropertySet::create(strictToCSSParserMode(isHTMLElement() && !document()->inQuirksMode()));
else if (!inlineStyle->isMutable())
inlineStyle = inlineStyle->copy();
- return inlineStyle.get();
+ ASSERT(inlineStyle->isMutable());
+ return static_cast<MutableStylePropertySet*>(inlineStyle.get());
}
void StyledElement::attributeChanged(const QualifiedName& name, const AtomicString& newValue)
Modified: trunk/Source/WebCore/dom/StyledElement.h (143867 => 143868)
--- trunk/Source/WebCore/dom/StyledElement.h 2013-02-24 16:42:41 UTC (rev 143867)
+++ trunk/Source/WebCore/dom/StyledElement.h 2013-02-24 16:45:21 UTC (rev 143868)
@@ -41,9 +41,7 @@
void invalidateStyleAttribute();
const StylePropertySet* inlineStyle() const { return elementData() ? elementData()->m_inlineStyle.get() : 0; }
- StylePropertySet* ensureMutableInlineStyle();
- // Unlike StylePropertySet setters, these implement invalidation.
bool setInlineStyleProperty(CSSPropertyID, int identifier, bool important = false);
bool setInlineStyleProperty(CSSPropertyID, double value, CSSPrimitiveValue::UnitTypes, bool important = false);
bool setInlineStyleProperty(CSSPropertyID, const String& value, bool important = false);
@@ -79,6 +77,7 @@
void inlineStyleChanged();
PropertySetCSSStyleDeclaration* inlineStyleCSSOMWrapper();
void setInlineStyleFromString(const AtomicString&);
+ MutableStylePropertySet* ensureMutableInlineStyle();
void makePresentationAttributeCacheKey(PresentationAttributeCacheKey&) const;
void rebuildPresentationAttributeStyle();
Modified: trunk/Source/WebCore/editing/ApplyStyleCommand.cpp (143867 => 143868)
--- trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2013-02-24 16:42:41 UTC (rev 143867)
+++ trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2013-02-24 16:45:21 UTC (rev 143868)
@@ -296,6 +296,13 @@
updateStartEnd(startRange->startPosition(), endRange->startPosition());
}
+static PassRefPtr<StylePropertySet> copyStyleOrCreateEmpty(const StylePropertySet* style)
+{
+ if (!style)
+ return StylePropertySet::create();
+ return style->copy();
+}
+
void ApplyStyleCommand::applyRelativeFontStyleChange(EditingStyle* style)
{
static const float MinimumFontSize = 0.1f;
@@ -386,19 +393,19 @@
}
lastStyledNode = node;
- RefPtr<StylePropertySet> inlineStyleDecl = element->ensureMutableInlineStyle()->copy();
+ RefPtr<StylePropertySet> inlineStyle = copyStyleOrCreateEmpty(element->inlineStyle());
float currentFontSize = computedFontSize(node);
float desiredFontSize = max(MinimumFontSize, startingFontSizes.get(node) + style->fontSizeDelta());
- RefPtr<CSSValue> value = inlineStyleDecl->getPropertyCSSValue(CSSPropertyFontSize);
+ RefPtr<CSSValue> value = inlineStyle->getPropertyCSSValue(CSSPropertyFontSize);
if (value) {
element->removeInlineStyleProperty(CSSPropertyFontSize);
currentFontSize = computedFontSize(node);
}
if (currentFontSize != desiredFontSize) {
- inlineStyleDecl->setProperty(CSSPropertyFontSize, cssValuePool().createValue(desiredFontSize, CSSPrimitiveValue::CSS_PX), false);
- setNodeAttribute(element.get(), styleAttr, inlineStyleDecl->asText());
+ inlineStyle->setProperty(CSSPropertyFontSize, cssValuePool().createValue(desiredFontSize, CSSPrimitiveValue::CSS_PX), false);
+ setNodeAttribute(element.get(), styleAttr, inlineStyle->asText());
}
- if (inlineStyleDecl->isEmpty()) {
+ if (inlineStyle->isEmpty()) {
removeNodeAttribute(element.get(), styleAttr);
if (isSpanWithoutAttributesOrUnstyledStyleSpan(element.get()))
unstyledSpans.append(element.release());
@@ -513,7 +520,7 @@
// other attributes, like we (should) do with B and I elements.
removeNodeAttribute(element, dirAttr);
} else {
- RefPtr<StylePropertySet> inlineStyle = element->ensureMutableInlineStyle()->copy();
+ RefPtr<StylePropertySet> inlineStyle = copyStyleOrCreateEmpty(element->inlineStyle());
inlineStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
inlineStyle->removeProperty(CSSPropertyDirection);
setNodeAttribute(element, styleAttr, inlineStyle->asText());
@@ -757,7 +764,7 @@
break;
// Add to this element's inline style and skip over its contents.
HTMLElement* element = toHTMLElement(node.get());
- RefPtr<StylePropertySet> inlineStyle = element->ensureMutableInlineStyle()->copy();
+ RefPtr<StylePropertySet> inlineStyle = copyStyleOrCreateEmpty(element->inlineStyle());
inlineStyle->mergeAndOverrideOnConflict(style->style());
setNodeAttribute(element, styleAttr, inlineStyle->asText());
next = NodeTraversal::nextSkippingChildren(node.get());
Modified: trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp (143867 => 143868)
--- trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp 2013-02-24 16:42:41 UTC (rev 143867)
+++ trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp 2013-02-24 16:45:21 UTC (rev 143868)
@@ -668,7 +668,7 @@
if (!wrappingStyleSpan)
return;
- RefPtr<EditingStyle> style = EditingStyle::create(wrappingStyleSpan->ensureMutableInlineStyle());
+ RefPtr<EditingStyle> style = EditingStyle::create(wrappingStyleSpan->inlineStyle());
ContainerNode* context = wrappingStyleSpan->parentNode();
// If Mail wraps the fragment with a Paste as Quotation blockquote, or if you're pasting into a quoted region,
Modified: trunk/Source/WebCore/html/canvas/CanvasStyle.cpp (143867 => 143868)
--- trunk/Source/WebCore/html/canvas/CanvasStyle.cpp 2013-02-24 16:42:41 UTC (rev 143867)
+++ trunk/Source/WebCore/html/canvas/CanvasStyle.cpp 2013-02-24 16:45:21 UTC (rev 143868)
@@ -66,10 +66,10 @@
RGBA32 currentColor(HTMLCanvasElement* canvas)
{
- if (!canvas || !canvas->inDocument())
+ if (!canvas || !canvas->inDocument() || !canvas->inlineStyle())
return Color::black;
RGBA32 rgba = Color::black;
- CSSParser::parseColor(rgba, canvas->ensureMutableInlineStyle()->getPropertyValue(CSSPropertyColor));
+ CSSParser::parseColor(rgba, canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
return rgba;
}
Modified: trunk/Source/WebKit/qt/Api/qwebelement.cpp (143867 => 143868)
--- trunk/Source/WebKit/qt/Api/qwebelement.cpp 2013-02-24 16:42:41 UTC (rev 143867)
+++ trunk/Source/WebKit/qt/Api/qwebelement.cpp 2013-02-24 16:45:21 UTC (rev 143868)
@@ -807,13 +807,16 @@
if (!propID)
return QString();
- const StylePropertySet* style = static_cast<StyledElement*>(m_element)->ensureMutableInlineStyle();
-
- if (strategy == InlineStyle)
+ if (strategy == InlineStyle) {
+ const StylePropertySet* style = static_cast<StyledElement*>(m_element)->inlineStyle();
+ if (!style)
+ return QString();
return style->getPropertyValue(propID);
+ }
if (strategy == CascadedStyle) {
- if (style->propertyIsImportant(propID))
+ const StylePropertySet* style = static_cast<StyledElement*>(m_element)->inlineStyle();
+ if (style && style->propertyIsImportant(propID))
return style->getPropertyValue(propID);
// We are going to resolve the style property by walking through the
@@ -832,11 +835,13 @@
if (rule->styleRule()->properties()->propertyIsImportant(propID))
return rule->styleRule()->properties()->getPropertyValue(propID);
- if (style->getPropertyValue(propID).isEmpty())
+ if (!style || style->getPropertyValue(propID).isEmpty())
style = rule->styleRule()->properties();
}
}
+ if (!style)
+ return QString();
return style->getPropertyValue(propID);
}
Modified: trunk/Source/WebKit/qt/ChangeLog (143867 => 143868)
--- trunk/Source/WebKit/qt/ChangeLog 2013-02-24 16:42:41 UTC (rev 143867)
+++ trunk/Source/WebKit/qt/ChangeLog 2013-02-24 16:45:21 UTC (rev 143868)
@@ -1,3 +1,15 @@
+2013-02-24 Andreas Kling <[email protected]>
+
+ StyledElement: Don't expose a mutable direct interface to the inline style.
+ <http://webkit.org/b/110711>
+
+ Reviewed by Antti Koivisto.
+
+ QWebElement::styleProperty() is a read-only method, so rewrite it to use StyledElement::inlineStyle().
+
+ * Api/qwebelement.cpp:
+ (QWebElement::styleProperty):
+
2013-02-23 Jason Anderssen <[email protected]>
Move setAutofilled from TestRunner to WebCore