Diff
Modified: trunk/Source/WebCore/ChangeLog (101706 => 101707)
--- trunk/Source/WebCore/ChangeLog 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/ChangeLog 2011-12-01 22:22:41 UTC (rev 101707)
@@ -1,3 +1,60 @@
+2011-12-01 Andreas Kling <[email protected]>
+
+ StyledElement: Clean up inline style accessors.
+ <http://webkit.org/b/73568>
+
+ Reviewed by Antti Koivisto.
+
+ Renamed StyledElement's getInlineStyleDecl() to ensureInlineStyleDecl() to
+ make it clear that it will always return non-null as opposed to inlineStyleDecl().
+
+ Also updated call sites to store the return value in a CSSInlineStyleDeclaration*
+ rather than a CSSMutableStyleDeclaration*, and reduced scoping of temporaries
+ in some cases.
+
+ * dom/StyledElement.cpp:
+ (WebCore::StyledElement::createInlineStyleDecl):
+ (WebCore::StyledElement::destroyInlineStyleDecl):
+ (WebCore::StyledElement::parseMappedAttribute):
+ (WebCore::StyledElement::ensureInlineStyleDecl):
+ (WebCore::StyledElement::style):
+ (WebCore::StyledElement::copyNonAttributeProperties):
+ (WebCore::StyledElement::addSubresourceAttributeURLs):
+ * dom/StyledElement.h:
+ (WebCore::StyledElement::inlineStyleDecl):
+ * editing/ApplyStyleCommand.cpp:
+ (WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
+ (WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock):
+ (WebCore::ApplyStyleCommand::applyInlineStyleToNodeRange):
+ (WebCore::ApplyStyleCommand::addBlockStyle):
+ (WebCore::ApplyStyleCommand::addInlineStyleIfNeeded):
+ * editing/DeleteButtonController.cpp:
+ (WebCore::DeleteButtonController::createDeletionUI):
+ (WebCore::DeleteButtonController::show):
+ (WebCore::DeleteButtonController::hide):
+ * editing/ReplaceSelectionCommand.cpp:
+ (WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):
+ (WebCore::ReplaceSelectionCommand::handleStyleSpans):
+ * html/HTMLTextFormControlElement.cpp:
+ (WebCore::HTMLTextFormControlElement::updatePlaceholderVisibility):
+ * html/ValidationMessage.cpp:
+ (WebCore::adjustBubblePosition):
+ * html/shadow/MediaControlElements.cpp:
+ (WebCore::MediaControlElement::show):
+ (WebCore::MediaControlElement::hide):
+ (WebCore::MediaControlPanelElement::setPosition):
+ (WebCore::MediaControlPanelElement::resetPosition):
+ (WebCore::MediaControlPanelElement::makeOpaque):
+ (WebCore::MediaControlPanelElement::makeTransparent):
+ (WebCore::MediaControlInputElement::show):
+ (WebCore::MediaControlInputElement::hide):
+ * html/shadow/MeterShadowElement.cpp:
+ (WebCore::MeterValueElement::setWidthPercentage):
+ * html/shadow/ProgressShadowElement.cpp:
+ (WebCore::ProgressValueElement::setWidthPercentage):
+ * html/shadow/SliderThumbElement.cpp:
+ (WebCore::TrackLimiterElement::create):
+
2011-12-01 Kelly Norton <[email protected]>
More void functions eager to return values in RenderObject & WebFrameImpl
Modified: trunk/Source/WebCore/dom/StyledElement.cpp (101706 => 101707)
--- trunk/Source/WebCore/dom/StyledElement.cpp 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/dom/StyledElement.cpp 2011-12-01 22:22:41 UTC (rev 101707)
@@ -129,6 +129,7 @@
void StyledElement::createInlineStyleDecl()
{
+ ASSERT(!m_inlineStyleDecl);
m_inlineStyleDecl = CSSInlineStyleDeclaration::create();
m_inlineStyleDecl->setElement(this);
m_inlineStyleDecl->setStrictParsing(isHTMLElement() && !document()->inQuirksMode());
@@ -136,10 +137,10 @@
void StyledElement::destroyInlineStyleDecl()
{
- if (m_inlineStyleDecl) {
- m_inlineStyleDecl->setElement(0);
- m_inlineStyleDecl = 0;
- }
+ if (!m_inlineStyleDecl)
+ return;
+ m_inlineStyleDecl->setElement(0);
+ m_inlineStyleDecl = 0;
}
void StyledElement::attributeChanged(Attribute* attr, bool preserveDecls)
@@ -240,13 +241,13 @@
if (attr->isNull())
destroyInlineStyleDecl();
else if (document()->contentSecurityPolicy()->allowInlineStyle())
- getInlineStyleDecl()->parseDeclaration(attr->value());
+ ensureInlineStyleDecl()->parseDeclaration(attr->value());
setIsStyleAttributeValid();
setNeedsStyleRecalc();
}
}
-CSSInlineStyleDeclaration* StyledElement::getInlineStyleDecl()
+CSSInlineStyleDeclaration* StyledElement::ensureInlineStyleDecl()
{
if (!m_inlineStyleDecl)
createInlineStyleDecl();
@@ -255,7 +256,7 @@
CSSStyleDeclaration* StyledElement::style()
{
- return getInlineStyleDecl();
+ return ensureInlineStyleDecl();
}
void StyledElement::addCSSProperty(Attribute* attribute, int id, const String &value)
@@ -436,7 +437,7 @@
if (!source->inlineStyleDecl())
return;
- CSSInlineStyleDeclaration* inlineStyle = getInlineStyleDecl();
+ CSSInlineStyleDeclaration* inlineStyle = ensureInlineStyleDecl();
inlineStyle->copyPropertiesFrom(*source->inlineStyleDecl());
inlineStyle->setStrictParsing(source->inlineStyleDecl()->useStrictParsing());
@@ -448,8 +449,9 @@
void StyledElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
{
- if (CSSInlineStyleDeclaration* style = inlineStyleDecl())
- style->addSubresourceStyleURLs(urls);
+ if (!m_inlineStyleDecl)
+ return;
+ m_inlineStyleDecl->addSubresourceStyleURLs(urls);
}
}
Modified: trunk/Source/WebCore/dom/StyledElement.h (101706 => 101707)
--- trunk/Source/WebCore/dom/StyledElement.h 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/dom/StyledElement.h 2011-12-01 22:22:41 UTC (rev 101707)
@@ -54,13 +54,14 @@
static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, Attribute*);
static void setMappedAttributeDecl(MappedAttributeEntry, Attribute*, CSSMappedAttributeDeclaration*);
- CSSInlineStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
virtual bool canHaveAdditionalAttributeStyleDecls() const { return false; }
virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) { }
- CSSInlineStyleDeclaration* getInlineStyleDecl();
- CSSStyleDeclaration* style();
void invalidateStyleAttribute();
+ CSSInlineStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
+ CSSInlineStyleDeclaration* ensureInlineStyleDecl();
+ virtual CSSStyleDeclaration* style() OVERRIDE;
+
const SpaceSplitString& classNames() const;
virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
Modified: trunk/Source/WebCore/editing/ApplyStyleCommand.cpp (101706 => 101707)
--- trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2011-12-01 22:22:41 UTC (rev 101707)
@@ -385,7 +385,7 @@
}
lastStyledNode = node;
- CSSMutableStyleDeclaration* inlineStyleDecl = element->getInlineStyleDecl();
+ CSSInlineStyleDeclaration* inlineStyleDecl = element->ensureInlineStyleDecl();
float currentFontSize = computedFontSize(node);
float desiredFontSize = max(MinimumFontSize, startingFontSizes.get(node) + style->fontSizeDelta());
RefPtr<CSSValue> value = inlineStyleDecl->getPropertyCSSValue(CSSPropertyFontSize);
@@ -512,7 +512,7 @@
// other attributes, like we (should) do with B and I elements.
removeNodeAttribute(element, dirAttr);
} else {
- RefPtr<CSSMutableStyleDeclaration> inlineStyle = element->getInlineStyleDecl()->copy();
+ RefPtr<CSSMutableStyleDeclaration> inlineStyle = element->ensureInlineStyleDecl()->copy();
inlineStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
inlineStyle->removeProperty(CSSPropertyDirection);
setNodeAttribute(element, styleAttr, inlineStyle->cssText());
@@ -726,7 +726,7 @@
break;
// Add to this element's inline style and skip over its contents.
HTMLElement* element = toHTMLElement(node);
- RefPtr<CSSMutableStyleDeclaration> inlineStyle = element->getInlineStyleDecl()->copy();
+ RefPtr<CSSMutableStyleDeclaration> inlineStyle = element->ensureInlineStyleDecl()->copy();
inlineStyle->merge(style->style());
setNodeAttribute(element, styleAttr, inlineStyle->cssText());
next = node->traverseNextSibling();
@@ -1313,8 +1313,7 @@
return;
String cssText = styleChange.cssStyle();
- CSSMutableStyleDeclaration* decl = block->inlineStyleDecl();
- if (decl)
+ if (CSSMutableStyleDeclaration* decl = block->inlineStyleDecl())
cssText += decl->cssText();
setNodeAttribute(block, styleAttr, cssText);
}
@@ -1379,8 +1378,7 @@
if (styleChange.cssStyle().length()) {
if (styleContainer) {
- CSSMutableStyleDeclaration* existingStyle = styleContainer->inlineStyleDecl();
- if (existingStyle)
+ if (CSSInlineStyleDeclaration* existingStyle = styleContainer->inlineStyleDecl())
setNodeAttribute(styleContainer, styleAttr, existingStyle->cssText() + styleChange.cssStyle());
else
setNodeAttribute(styleContainer, styleAttr, styleChange.cssStyle());
Modified: trunk/Source/WebCore/editing/DeleteButtonController.cpp (101706 => 101707)
--- trunk/Source/WebCore/editing/DeleteButtonController.cpp 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/editing/DeleteButtonController.cpp 2011-12-01 22:22:41 UTC (rev 101707)
@@ -204,7 +204,7 @@
RefPtr<HTMLDivElement> container = HTMLDivElement::create(m_target->document());
container->setIdAttribute(containerElementIdentifier);
- CSSMutableStyleDeclaration* style = container->getInlineStyleDecl();
+ CSSInlineStyleDeclaration* style = container->ensureInlineStyleDecl();
style->setProperty(CSSPropertyWebkitUserDrag, CSSValueNone);
style->setProperty(CSSPropertyWebkitUserSelect, CSSValueNone);
style->setProperty(CSSPropertyWebkitUserModify, CSSValueReadOnly);
@@ -222,7 +222,7 @@
const int borderWidth = 4;
const int borderRadius = 6;
- style = outline->getInlineStyleDecl();
+ style = outline->ensureInlineStyleDecl();
style->setProperty(CSSPropertyPosition, CSSValueAbsolute);
style->setProperty(CSSPropertyZIndex, String::number(-1000000));
style->setProperty(CSSPropertyTop, String::number(-borderWidth - m_target->renderBox()->borderTop()) + "px");
@@ -246,7 +246,7 @@
const int buttonHeight = 30;
const int buttonBottomShadowOffset = 2;
- style = button->getInlineStyleDecl();
+ style = button->ensureInlineStyleDecl();
style->setProperty(CSSPropertyPosition, CSSValueAbsolute);
style->setProperty(CSSPropertyZIndex, String::number(1000000));
style->setProperty(CSSPropertyTop, String::number((-buttonHeight / 2) - m_target->renderBox()->borderTop() - (borderWidth / 2) + buttonBottomShadowOffset) + "px");
@@ -309,12 +309,12 @@
}
if (m_target->renderer()->style()->position() == StaticPosition) {
- m_target->getInlineStyleDecl()->setProperty(CSSPropertyPosition, CSSValueRelative);
+ m_target->ensureInlineStyleDecl()->setProperty(CSSPropertyPosition, CSSValueRelative);
m_wasStaticPositioned = true;
}
if (m_target->renderer()->style()->hasAutoZIndex()) {
- m_target->getInlineStyleDecl()->setProperty(CSSPropertyZIndex, "0");
+ m_target->ensureInlineStyleDecl()->setProperty(CSSPropertyZIndex, "0");
m_wasAutoZIndex = true;
}
}
@@ -330,9 +330,9 @@
if (m_target) {
if (m_wasStaticPositioned)
- m_target->getInlineStyleDecl()->setProperty(CSSPropertyPosition, CSSValueStatic);
+ m_target->ensureInlineStyleDecl()->setProperty(CSSPropertyPosition, CSSValueStatic);
if (m_wasAutoZIndex)
- m_target->getInlineStyleDecl()->setProperty(CSSPropertyZIndex, CSSValueAuto);
+ m_target->ensureInlineStyleDecl()->setProperty(CSSPropertyZIndex, CSSValueAuto);
}
m_wasStaticPositioned = false;
Modified: trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp (101706 => 101707)
--- trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp 2011-12-01 22:22:41 UTC (rev 101707)
@@ -529,9 +529,9 @@
// results. We already know one issue because td elements ignore their display property
// in quirks mode (which Mail.app is always in). We should look for an alternative.
if (isBlock(element))
- element->getInlineStyleDecl()->setProperty(CSSPropertyDisplay, CSSValueInline);
+ element->ensureInlineStyleDecl()->setProperty(CSSPropertyDisplay, CSSValueInline);
if (element->renderer() && element->renderer()->style()->isFloating())
- element->getInlineStyleDecl()->setProperty(CSSPropertyFloat, CSSValueNone);
+ element->ensureInlineStyleDecl()->setProperty(CSSPropertyFloat, CSSValueNone);
}
}
}
@@ -646,7 +646,7 @@
if (!wrappingStyleSpan)
return;
- RefPtr<EditingStyle> style = EditingStyle::create(wrappingStyleSpan->getInlineStyleDecl());
+ RefPtr<EditingStyle> style = EditingStyle::create(wrappingStyleSpan->ensureInlineStyleDecl());
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/HTMLTextFormControlElement.cpp (101706 => 101707)
--- trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp 2011-12-01 22:22:41 UTC (rev 101707)
@@ -153,7 +153,7 @@
if (!placeholder)
return;
ExceptionCode ec = 0;
- placeholder->getInlineStyleDecl()->setProperty(CSSPropertyVisibility, placeholderShouldBeVisible() ? "visible" : "hidden", ec);
+ placeholder->ensureInlineStyleDecl()->setProperty(CSSPropertyVisibility, placeholderShouldBeVisible() ? "visible" : "hidden", ec);
ASSERT(!ec);
}
Modified: trunk/Source/WebCore/html/ValidationMessage.cpp (101706 => 101707)
--- trunk/Source/WebCore/html/ValidationMessage.cpp 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/html/ValidationMessage.cpp 2011-12-01 22:22:41 UTC (rev 101707)
@@ -118,13 +118,15 @@
hostX -= containerLocation.x() + container->borderLeft();
hostY -= containerLocation.y() + container->borderTop();
}
- bubble->getInlineStyleDecl()->setProperty(CSSPropertyTop, hostY + hostRect.height(), CSSPrimitiveValue::CSS_PX);
+
+ CSSInlineStyleDeclaration* style = bubble->ensureInlineStyleDecl();
+ style->setProperty(CSSPropertyTop, hostY + hostRect.height(), CSSPrimitiveValue::CSS_PX);
// The 'left' value of ::-webkit-validation-bubble-arrow.
const int bubbleArrowTopOffset = 32;
double bubbleX = hostX;
if (hostRect.width() / 2 < bubbleArrowTopOffset)
bubbleX = max(hostX + hostRect.width() / 2 - bubbleArrowTopOffset, 0.0);
- bubble->getInlineStyleDecl()->setProperty(CSSPropertyLeft, bubbleX, CSSPrimitiveValue::CSS_PX);
+ style->setProperty(CSSPropertyLeft, bubbleX, CSSPrimitiveValue::CSS_PX);
}
void ValidationMessage::buildBubbleTree(Timer<ValidationMessage>*)
@@ -135,7 +137,7 @@
m_bubble->setShadowPseudoId("-webkit-validation-bubble");
// Need to force position:absolute because RenderMenuList doesn't assume it
// contains non-absolute or non-fixed renderers as children.
- m_bubble->getInlineStyleDecl()->setProperty(CSSPropertyPosition, CSSValueAbsolute);
+ m_bubble->ensureInlineStyleDecl()->setProperty(CSSPropertyPosition, CSSValueAbsolute);
ExceptionCode ec = 0;
host->ensureShadowRoot()->appendChild(m_bubble.get(), ec);
ASSERT(!ec);
Modified: trunk/Source/WebCore/html/shadow/MediaControlElements.cpp (101706 => 101707)
--- trunk/Source/WebCore/html/shadow/MediaControlElements.cpp 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/html/shadow/MediaControlElements.cpp 2011-12-01 22:22:41 UTC (rev 101707)
@@ -88,12 +88,12 @@
void MediaControlElement::show()
{
- getInlineStyleDecl()->removeProperty(CSSPropertyDisplay);
+ ensureInlineStyleDecl()->removeProperty(CSSPropertyDisplay);
}
void MediaControlElement::hide()
{
- getInlineStyleDecl()->setProperty(CSSPropertyDisplay, CSSValueNone);
+ ensureInlineStyleDecl()->setProperty(CSSPropertyDisplay, CSSValueNone);
}
// ----------------------------
@@ -171,7 +171,7 @@
void MediaControlPanelElement::setPosition(const LayoutPoint& position)
{
- CSSMutableStyleDeclaration* style = getInlineStyleDecl();
+ CSSInlineStyleDeclaration* style = ensureInlineStyleDecl();
double left = position.x();
double top = position.y();
@@ -186,7 +186,7 @@
void MediaControlPanelElement::resetPosition()
{
- CSSMutableStyleDeclaration* style = getInlineStyleDecl();
+ CSSInlineStyleDeclaration* style = ensureInlineStyleDecl();
style->removeProperty(CSSPropertyLeft);
style->removeProperty(CSSPropertyTop);
@@ -199,7 +199,7 @@
if (m_opaque)
return;
- CSSMutableStyleDeclaration* style = getInlineStyleDecl();
+ CSSInlineStyleDeclaration* style = ensureInlineStyleDecl();
style->setProperty(CSSPropertyWebkitTransitionProperty, CSSPropertyOpacity);
style->setProperty(CSSPropertyWebkitTransitionDuration, document()->page()->theme()->mediaControlsFadeInDuration(), CSSPrimitiveValue::CSS_S);
style->setProperty(CSSPropertyOpacity, 1.0, CSSPrimitiveValue::CSS_NUMBER);
@@ -212,7 +212,7 @@
if (!m_opaque)
return;
- CSSMutableStyleDeclaration* style = getInlineStyleDecl();
+ CSSInlineStyleDeclaration* style = ensureInlineStyleDecl();
style->setProperty(CSSPropertyWebkitTransitionProperty, CSSPropertyOpacity);
style->setProperty(CSSPropertyWebkitTransitionDuration, document()->page()->theme()->mediaControlsFadeOutDuration(), CSSPrimitiveValue::CSS_S);
style->setProperty(CSSPropertyOpacity, 0.0, CSSPrimitiveValue::CSS_NUMBER);
@@ -422,12 +422,12 @@
void MediaControlInputElement::show()
{
- getInlineStyleDecl()->removeProperty(CSSPropertyDisplay);
+ ensureInlineStyleDecl()->removeProperty(CSSPropertyDisplay);
}
void MediaControlInputElement::hide()
{
- getInlineStyleDecl()->setProperty(CSSPropertyDisplay, CSSValueNone);
+ ensureInlineStyleDecl()->setProperty(CSSPropertyDisplay, CSSValueNone);
}
Modified: trunk/Source/WebCore/html/shadow/MeterShadowElement.cpp (101706 => 101707)
--- trunk/Source/WebCore/html/shadow/MeterShadowElement.cpp 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/html/shadow/MeterShadowElement.cpp 2011-12-01 22:22:41 UTC (rev 101707)
@@ -93,7 +93,7 @@
void MeterValueElement::setWidthPercentage(double width)
{
- getInlineStyleDecl()->setProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
+ ensureInlineStyleDecl()->setProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
}
Modified: trunk/Source/WebCore/html/shadow/ProgressShadowElement.cpp (101706 => 101707)
--- trunk/Source/WebCore/html/shadow/ProgressShadowElement.cpp 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/html/shadow/ProgressShadowElement.cpp 2011-12-01 22:22:41 UTC (rev 101707)
@@ -73,7 +73,7 @@
void ProgressValueElement::setWidthPercentage(double width)
{
- getInlineStyleDecl()->setProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
+ ensureInlineStyleDecl()->setProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
}
}
Modified: trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp (101706 => 101707)
--- trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp 2011-12-01 22:16:10 UTC (rev 101706)
+++ trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp 2011-12-01 22:22:41 UTC (rev 101707)
@@ -333,8 +333,11 @@
PassRefPtr<TrackLimiterElement> TrackLimiterElement::create(Document* document)
{
RefPtr<TrackLimiterElement> element = adoptRef(new TrackLimiterElement(document));
- element->getInlineStyleDecl()->setProperty(CSSPropertyVisibility, CSSValueHidden);
- element->getInlineStyleDecl()->setProperty(CSSPropertyPosition, CSSValueStatic);
+
+ CSSInlineStyleDeclaration* style = element->ensureInlineStyleDecl();
+ style->setProperty(CSSPropertyVisibility, CSSValueHidden);
+ style->setProperty(CSSPropertyPosition, CSSValueStatic);
+
return element.release();
}