Diff
Modified: trunk/Source/WebCore/ChangeLog (94658 => 94659)
--- trunk/Source/WebCore/ChangeLog 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/ChangeLog 2011-09-07 10:16:26 UTC (rev 94659)
@@ -1,3 +1,64 @@
+2011-09-07 Antti Koivisto <[email protected]>
+
+ https://bugs.webkit.org/show_bug.cgi?id=67634
+ De-virtualize styleForRenderer()
+
+ Reviewed by Sam Weinig.
+
+ This has performance and code clarity benefits.
+
+ - move styleForRenderer from Node to Element
+ - get rid of the now unnecessary NodeRenderingContext parameter
+ - de-virtualize, add virtual customStyleForRenderer()
+
+ * dom/Element.cpp:
+ (WebCore::Element::customStyleForRenderer):
+ (WebCore::Element::styleForRenderer):
+ (WebCore::Element::recalcStyle):
+ * dom/Element.h:
+ * dom/Node.cpp:
+ * dom/Node.h:
+ (WebCore::Node::hasCustomWillOrDidRecalcStyle):
+ (WebCore::Node::setHasCustomWillOrDidRecalcStyle):
+ (WebCore::Node::hasCustomStyleForRenderer):
+ (WebCore::Node::setHasCustomStyleForRenderer):
+
+ Move styleForRenderer, add customStyleForRenderer, add a bit.
+
+ * dom/NodeRenderingContext.cpp:
+ (WebCore::NodeRendererFactory::createRendererAndStyle):
+
+ Handle non-element case separately since styleForRenderer was moved from Node to Element.
+
+ * html/HTMLNoScriptElement.cpp:
+ (WebCore::HTMLNoScriptElement::HTMLNoScriptElement):
+ (WebCore::HTMLNoScriptElement::customStyleForRenderer):
+ * html/HTMLNoScriptElement.h:
+
+ Move a strange XHTMLMP special case to where it belongs.
+
+ * html/HTMLOptGroupElement.cpp:
+ (WebCore::HTMLOptGroupElement::attach):
+ * html/HTMLOptionElement.cpp:
+ (WebCore::HTMLOptionElement::attach):
+ * html/HTMLTitleElement.cpp:
+ (WebCore::HTMLTitleElement::textWithDirection):
+ * html/shadow/TextControlInnerElements.cpp:
+ (WebCore::TextControlInnerElement::TextControlInnerElement):
+ (WebCore::TextControlInnerElement::customStyleForRenderer):
+ (WebCore::TextControlInnerTextElement::TextControlInnerTextElement):
+ (WebCore::TextControlInnerTextElement::customStyleForRenderer):
+ * html/shadow/TextControlInnerElements.h:
+ * rendering/svg/SVGShadowTreeElements.cpp:
+ (WebCore::SVGShadowTreeContainerElement::customStyleForRenderer):
+ * rendering/svg/SVGShadowTreeElements.h:
+ * svg/SVGElement.cpp:
+ (WebCore::SVGElement::SVGElement):
+ (WebCore::SVGElement::customStyleForRenderer):
+ * svg/SVGElement.h:
+
+ Adopt customStyleForRenderer().
+
2011-09-07 Ryosuke Niwa <[email protected]>
Change event is not fired for input[type=number] when the user reverts a change made by script
@@ -47,7 +108,7 @@
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::determineLinkStateSlowCase):
-2011-09-06 Antti Koivisto <[email protected]>
+2011-09-07 Antti Koivisto <[email protected]>
Move SelectorChecker out from CSSStyleSelector scope
https://bugs.webkit.org/show_bug.cgi?id=67648
Modified: trunk/Source/WebCore/dom/Element.cpp (94658 => 94659)
--- trunk/Source/WebCore/dom/Element.cpp 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/dom/Element.cpp 2011-09-07 10:16:26 UTC (rev 94659)
@@ -1046,6 +1046,19 @@
return false;
}
+PassRefPtr<RenderStyle> Element::customStyleForRenderer()
+{
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
+PassRefPtr<RenderStyle> Element::styleForRenderer()
+{
+ if (hasCustomStyleForRenderer())
+ return customStyleForRenderer();
+ return document()->styleSelector()->styleForElement(static_cast<Element*>(this), 0, true/*allowSharing*/);
+}
+
void Element::recalcStyle(StyleChange change)
{
if (hasCustomWillOrDidRecalcStyle()) {
@@ -1067,7 +1080,7 @@
}
}
if (hasParentStyle && (change >= Inherit || needsStyleRecalc())) {
- RefPtr<RenderStyle> newStyle = styleForRenderer(NodeRenderingContext(this, 0));
+ RefPtr<RenderStyle> newStyle = styleForRenderer();
StyleChange ch = diff(currentStyle.get(), newStyle.get());
if (ch == Detach || !currentStyle) {
// FIXME: The style gets computed twice by calling attach. We could do better if we passed the style along.
Modified: trunk/Source/WebCore/dom/Element.h (94658 => 94659)
--- trunk/Source/WebCore/dom/Element.h 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/dom/Element.h 2011-09-07 10:16:26 UTC (rev 94659)
@@ -359,6 +359,8 @@
virtual bool isSpellCheckingEnabled() const;
PassRefPtr<WebKitAnimationList> webkitGetAnimations() const;
+
+ PassRefPtr<RenderStyle> styleForRenderer();
protected:
Element(const QualifiedName& tagName, Document* document, ConstructionType type)
@@ -375,6 +377,7 @@
virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
virtual bool willRecalcStyle(StyleChange) { return true; }
virtual void didRecalcStyle(StyleChange) { }
+ virtual PassRefPtr<RenderStyle> customStyleForRenderer();
// The implementation of Element::attributeChanged() calls the following two functions.
// They are separated to allow a different flow of control in StyledElement::attributeChanged().
Modified: trunk/Source/WebCore/dom/Node.cpp (94658 => 94659)
--- trunk/Source/WebCore/dom/Node.cpp 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/dom/Node.cpp 2011-09-07 10:16:26 UTC (rev 94659)
@@ -1464,21 +1464,6 @@
NodeRendererFactory(this).createRendererIfNeeded();
}
-PassRefPtr<RenderStyle> Node::styleForRenderer(const NodeRenderingContext& context)
-{
- if (isElementNode()) {
- bool allowSharing = true;
-#if ENABLE(XHTMLMP)
- // noscript needs the display property protected - it's a special case
- allowSharing = localName() != HTMLNames::noscriptTag.localName();
-#endif
- return document()->styleSelector()->styleForElement(static_cast<Element*>(this), 0, allowSharing);
- }
- if (RenderObject* renderer = context.parentRenderer())
- return renderer->style();
- return 0;
-}
-
bool Node::rendererIsNeeded(const NodeRenderingContext& context)
{
return (document()->documentElement() == this) || (context.style()->display() != NONE);
Modified: trunk/Source/WebCore/dom/Node.h (94658 => 94659)
--- trunk/Source/WebCore/dom/Node.h 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/dom/Node.h 2011-09-07 10:16:26 UTC (rev 94659)
@@ -455,7 +455,6 @@
virtual void willRemove();
void createRendererIfNeeded();
- virtual PassRefPtr<RenderStyle> styleForRenderer(const NodeRenderingContext&);
virtual bool rendererIsNeeded(const NodeRenderingContext&);
virtual bool childShouldCreateRenderer(Node*) const { return true; }
virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
@@ -615,7 +614,8 @@
StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1),
SelfOrAncestorHasDirAutoFlag = 1 << 27,
- HasCustomWillOrDidRecalcStyle = 1 << 28,
+ HasCustomWillOrDidRecalcStyleFlag = 1 << 28,
+ HasCustomStyleForRendererFlag = 1 << 29,
#if ENABLE(SVG)
DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag | AreSVGAttributesValidFlag
@@ -624,7 +624,7 @@
#endif
};
- // 3 bits remaining
+ // 2 bits remaining
bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); }
@@ -657,8 +657,11 @@
NodeRareData* ensureRareData();
void clearRareData();
- bool hasCustomWillOrDidRecalcStyle() const { return getFlag(HasCustomWillOrDidRecalcStyle); }
- void setHasCustomWillOrDidRecalcStyle() { setFlag(true, HasCustomWillOrDidRecalcStyle); }
+ bool hasCustomWillOrDidRecalcStyle() const { return getFlag(HasCustomWillOrDidRecalcStyleFlag); }
+ void setHasCustomWillOrDidRecalcStyle() { setFlag(true, HasCustomWillOrDidRecalcStyleFlag); }
+
+ bool hasCustomStyleForRenderer() const { return getFlag(HasCustomStyleForRendererFlag); }
+ void setHasCustomStyleForRenderer() { setFlag(true, HasCustomStyleForRendererFlag); }
private:
// Do not use this method to change the document of a node until after the node has been
Modified: trunk/Source/WebCore/dom/NodeRenderingContext.cpp (94658 => 94659)
--- trunk/Source/WebCore/dom/NodeRenderingContext.cpp 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/dom/NodeRenderingContext.cpp 2011-09-07 10:16:26 UTC (rev 94659)
@@ -296,13 +296,15 @@
if (!m_context.shouldCreateRenderer())
return 0;
- m_context.setStyle(node->styleForRenderer(m_context));
+ Element* element = node->isElementNode() ? toElement(node) : 0;
+ if (element)
+ m_context.setStyle(element->styleForRenderer());
+ else if (RenderObject* parentRenderer = m_context.parentRenderer())
+ m_context.setStyle(parentRenderer->style());
+
if (!node->rendererIsNeeded(m_context)) {
- if (node->isElementNode()) {
- Element* element = toElement(node);
- if (m_context.style()->affectedByEmpty())
- element->setStyleAffectedByEmpty();
- }
+ if (element && m_context.style()->affectedByEmpty())
+ element->setStyleAffectedByEmpty();
return 0;
}
Modified: trunk/Source/WebCore/html/HTMLNoScriptElement.cpp (94658 => 94659)
--- trunk/Source/WebCore/html/HTMLNoScriptElement.cpp 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/html/HTMLNoScriptElement.cpp 2011-09-07 10:16:26 UTC (rev 94659)
@@ -37,6 +37,9 @@
ASSERT(hasTagName(noscriptTag));
setHasCustomWillOrDidRecalcStyle();
+#if ENABLE(XHTMLMP)
+ setHasCustomStyleForRenderer();
+#endif
}
PassRefPtr<HTMLNoScriptElement> HTMLNoScriptElement::create(const QualifiedName& tagName, Document* document)
@@ -75,6 +78,15 @@
}
return false;
}
+
+#if ENABLE(XHTMLMP)
+PassRefPtr<RenderStyle> HTMLNoScriptElement::customStyleForRenderer()
+{
+ // noscript needs the display property protected - it's a special case
+ // FIXME: Why?
+ return document()->styleSelector()->styleForElement(static_cast<Element*>(this), 0, false/*allowSharing*/);
+}
+#endif
bool HTMLNoScriptElement::childShouldCreateRenderer(Node*) const
{
Modified: trunk/Source/WebCore/html/HTMLNoScriptElement.h (94658 => 94659)
--- trunk/Source/WebCore/html/HTMLNoScriptElement.h 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/html/HTMLNoScriptElement.h 2011-09-07 10:16:26 UTC (rev 94659)
@@ -38,6 +38,9 @@
virtual bool willRecalcStyle(StyleChange);
virtual bool childShouldCreateRenderer(Node*) const;
virtual bool rendererIsNeeded(const NodeRenderingContext&) { return true; }
+#if ENABLE(XHTMLMP)
+ virtual PassRefPtr<RenderStyle> customStyleForRenderer();
+#endif
};
} //namespace
Modified: trunk/Source/WebCore/html/HTMLOptGroupElement.cpp (94658 => 94659)
--- trunk/Source/WebCore/html/HTMLOptGroupElement.cpp 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/html/HTMLOptGroupElement.cpp 2011-09-07 10:16:26 UTC (rev 94659)
@@ -90,7 +90,7 @@
void HTMLOptGroupElement::attach()
{
if (parentNode()->renderStyle())
- setRenderStyle(styleForRenderer(NodeRenderingContext(this, 0)));
+ setRenderStyle(styleForRenderer());
HTMLFormControlElement::attach();
}
Modified: trunk/Source/WebCore/html/HTMLOptionElement.cpp (94658 => 94659)
--- trunk/Source/WebCore/html/HTMLOptionElement.cpp 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/html/HTMLOptionElement.cpp 2011-09-07 10:16:26 UTC (rev 94659)
@@ -82,7 +82,7 @@
void HTMLOptionElement::attach()
{
if (parentNode()->renderStyle())
- setRenderStyle(styleForRenderer(NodeRenderingContext(this, 0)));
+ setRenderStyle(styleForRenderer());
HTMLFormControlElement::attach();
}
Modified: trunk/Source/WebCore/html/HTMLTitleElement.cpp (94658 => 94659)
--- trunk/Source/WebCore/html/HTMLTitleElement.cpp 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/html/HTMLTitleElement.cpp 2011-09-07 10:16:26 UTC (rev 94659)
@@ -81,7 +81,7 @@
TextDirection direction = LTR;
if (RenderStyle* style = computedStyle())
direction = style->direction();
- else if (RefPtr<RenderStyle> style = styleForRenderer(NodeRenderingContext(this, 0)))
+ else if (RefPtr<RenderStyle> style = styleForRenderer())
direction = style->direction();
return StringWithDirection(text(), direction);
}
Modified: trunk/Source/WebCore/html/shadow/TextControlInnerElements.cpp (94658 => 94659)
--- trunk/Source/WebCore/html/shadow/TextControlInnerElements.cpp 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/html/shadow/TextControlInnerElements.cpp 2011-09-07 10:16:26 UTC (rev 94659)
@@ -51,6 +51,7 @@
TextControlInnerElement::TextControlInnerElement(Document* document)
: HTMLDivElement(divTag, document)
{
+ setHasCustomStyleForRenderer();
}
PassRefPtr<TextControlInnerElement> TextControlInnerElement::create(Document* document)
@@ -58,7 +59,7 @@
return adoptRef(new TextControlInnerElement(document));
}
-PassRefPtr<RenderStyle> TextControlInnerElement::styleForRenderer(const NodeRenderingContext&)
+PassRefPtr<RenderStyle> TextControlInnerElement::customStyleForRenderer()
{
RenderTextControlSingleLine* parentRenderer = toRenderTextControlSingleLine(shadowAncestorNode()->renderer());
return parentRenderer->createInnerBlockStyle(parentRenderer->style());
@@ -69,6 +70,7 @@
inline TextControlInnerTextElement::TextControlInnerTextElement(Document* document)
: HTMLDivElement(divTag, document)
{
+ setHasCustomStyleForRenderer();
}
PassRefPtr<TextControlInnerTextElement> TextControlInnerTextElement::create(Document* document)
@@ -104,7 +106,7 @@
return new (arena) RenderTextControlInnerBlock(this, multiLine);
}
-PassRefPtr<RenderStyle> TextControlInnerTextElement::styleForRenderer(const NodeRenderingContext&)
+PassRefPtr<RenderStyle> TextControlInnerTextElement::customStyleForRenderer()
{
RenderTextControl* parentRenderer = toRenderTextControl(shadowAncestorNode()->renderer());
return parentRenderer->createInnerTextStyle(parentRenderer->style());
Modified: trunk/Source/WebCore/html/shadow/TextControlInnerElements.h (94658 => 94659)
--- trunk/Source/WebCore/html/shadow/TextControlInnerElements.h 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/html/shadow/TextControlInnerElements.h 2011-09-07 10:16:26 UTC (rev 94659)
@@ -42,7 +42,7 @@
protected:
TextControlInnerElement(Document*);
- virtual PassRefPtr<RenderStyle> styleForRenderer(const NodeRenderingContext&);
+ virtual PassRefPtr<RenderStyle> customStyleForRenderer();
private:
virtual bool isMouseFocusable() const { return false; }
@@ -57,7 +57,7 @@
private:
TextControlInnerTextElement(Document*);
virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
- virtual PassRefPtr<RenderStyle> styleForRenderer(const NodeRenderingContext&);
+ virtual PassRefPtr<RenderStyle> customStyleForRenderer();
virtual bool isMouseFocusable() const { return false; }
};
Modified: trunk/Source/WebCore/rendering/svg/SVGShadowTreeElements.cpp (94658 => 94659)
--- trunk/Source/WebCore/rendering/svg/SVGShadowTreeElements.cpp 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/rendering/svg/SVGShadowTreeElements.cpp 2011-09-07 10:16:26 UTC (rev 94659)
@@ -98,7 +98,7 @@
setParent(0);
}
-PassRefPtr<RenderStyle> SVGShadowTreeContainerElement::styleForRenderer(const NodeRenderingContext&)
+PassRefPtr<RenderStyle> SVGShadowTreeContainerElement::customStyleForRenderer()
{
return document()->styleSelector()->styleForElement(this, 0, true/*allowSharing*/);
}
Modified: trunk/Source/WebCore/rendering/svg/SVGShadowTreeElements.h (94658 => 94659)
--- trunk/Source/WebCore/rendering/svg/SVGShadowTreeElements.h 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/rendering/svg/SVGShadowTreeElements.h 2011-09-07 10:16:26 UTC (rev 94659)
@@ -39,7 +39,7 @@
bool containerOffsetChanged() const { return m_containerOffsetChanged; }
void setContainerOffsetChanged(bool containerOffsetChanged) { m_containerOffsetChanged = containerOffsetChanged; }
- virtual PassRefPtr<RenderStyle> styleForRenderer(const NodeRenderingContext&);
+ virtual PassRefPtr<RenderStyle> customStyleForRenderer();
protected:
SVGShadowTreeContainerElement(Document*);
Modified: trunk/Source/WebCore/svg/SVGElement.cpp (94658 => 94659)
--- trunk/Source/WebCore/svg/SVGElement.cpp 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/svg/SVGElement.cpp 2011-09-07 10:16:26 UTC (rev 94659)
@@ -58,6 +58,7 @@
SVGElement::SVGElement(const QualifiedName& tagName, Document* document)
: StyledElement(tagName, document, CreateSVGElement)
{
+ setHasCustomStyleForRenderer();
}
PassRefPtr<SVGElement> SVGElement::create(const QualifiedName& tagName, Document* document)
@@ -426,12 +427,12 @@
static_cast<SVGElement*>(contextElement)->synchronizeSystemLanguage();
}
-PassRefPtr<RenderStyle> SVGElement::styleForRenderer(const NodeRenderingContext& context)
+PassRefPtr<RenderStyle> SVGElement::customStyleForRenderer()
{
if (correspondingElement())
return document()->styleSelector()->styleForElement(correspondingElement(), parentNode() ? parentNode()->renderer()->style() : 0, false/*allowSharing*/);
- return StyledElement::styleForRenderer(context);
+ return document()->styleSelector()->styleForElement(static_cast<Element*>(this), 0, true);
}
}
Modified: trunk/Source/WebCore/svg/SVGElement.h (94658 => 94659)
--- trunk/Source/WebCore/svg/SVGElement.h 2011-09-07 10:07:10 UTC (rev 94658)
+++ trunk/Source/WebCore/svg/SVGElement.h 2011-09-07 10:16:26 UTC (rev 94659)
@@ -89,7 +89,7 @@
virtual void updateAnimatedSVGAttribute(const QualifiedName&) const;
- virtual PassRefPtr<RenderStyle> styleForRenderer(const NodeRenderingContext&);
+ virtual PassRefPtr<RenderStyle> customStyleForRenderer();
static void synchronizeRequiredFeatures(void* contextElement);
static void synchronizeRequiredExtensions(void* contextElement);