Don't create StyleResolvers just to invalidate them.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Apr 2013 19:42:45 +0000 (19:42 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Apr 2013 19:42:45 +0000 (19:42 +0000)
<http://webkit.org/b/115436>

Reviewed by Geoffrey Garen.

Source/WebCore:

Renamed Document::styleResolver() to ensureStyleResolver() so it's clear that it never returns null.
Removed a bunch of unnecessary null-checks I spotted while doing this.

Also fixed Element::willModifyAttribute() and FrameView::setFrameRect() to not create a StyleResolver
and immediately invalidate it in some cases.

* css/FontLoader.cpp:
(WebCore::FontLoader::loadFont):
(WebCore::FontLoader::checkFont):
(WebCore::FontLoader::resolveFontStyle):
* css/MediaQueryMatcher.cpp:
(WebCore::MediaQueryMatcher::prepareEvaluator):
* css/StyleMedia.cpp:
(WebCore::StyleMedia::matchMedium):
* dom/Document.cpp:
(WebCore::Document::styleForElementIgnoringPendingStylesheets):
(WebCore::Document::styleForPage):
* dom/Document.h:
(WebCore::Document::ensureStyleResolver):
* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::combineCSSFeatureFlags):
(WebCore::DocumentStyleSheetCollection::resetCSSFeatureFlags):
(WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
* dom/Element.cpp:
(WebCore::StyleResolverParentPusher::push):
(WebCore::StyleResolverParentPusher::~StyleResolverParentPusher):
(WebCore::Element::styleForRenderer):
(WebCore::Element::recalcStyle):
(WebCore::Element::willModifyAttribute):
* dom/NodeRenderingContext.cpp:
(WebCore::NodeRenderingContext::createRendererForTextIfNeeded):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::recalcStyle):
(WebCore::ShadowRoot::attach):
* dom/Text.cpp:
(WebCore::Text::recalcTextStyle):
* editing/EditingStyle.cpp:
(WebCore::styleFromMatchedRulesForElement):
* html/HTMLCanvasElement.cpp:
* html/HTMLCanvasElement.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::customStyleForRenderer):
* html/HTMLOptGroupElement.cpp:
(WebCore::HTMLOptGroupElement::updateNonRenderStyle):
* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::updateNonRenderStyle):
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::customStyleForRenderer):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::setFont):
* html/shadow/DateTimeEditElement.cpp:
(WebCore::DateTimeEditElement::customStyleForRenderer):
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::getMatchedStylesForNode):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::getMatchedCSSRules):
* page/FrameView.cpp:
(WebCore::FrameView::setFrameRect):
* page/animation/KeyframeAnimation.cpp:
(WebCore::KeyframeAnimation::KeyframeAnimation):
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::updateFromElement):
(WebCore::RenderListBox::paintItemForeground):
* rendering/RenderMenuList.cpp:
(WebCore::RenderMenuList::fontSelector):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::getUncachedPseudoStyle):
* rendering/RenderRegion.cpp:
(WebCore::RenderRegion::checkRegionStyle):
(WebCore::RenderRegion::computeStyleInRegion):
* rendering/RenderSearchField.cpp:
(WebCore::RenderSearchField::fontSelector):
* rendering/svg/RenderSVGInlineText.cpp:
(WebCore::RenderSVGInlineText::computeNewScaledFontForStyle):
* svg/SVGElement.cpp:
(WebCore::SVGElement::customStyleForRenderer):
* svg/SVGElementRareData.h:
(WebCore::SVGElementRareData::overrideComputedStyle):

Source/WebKit/qt:

* Api/qwebelement.cpp:
(QWebElement::styleProperty):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@149392 268f45cc-cd09-0410-ab3c-d52691b4dbfc

34 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/FontLoader.cpp
Source/WebCore/css/MediaQueryMatcher.cpp
Source/WebCore/css/StyleMedia.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/DocumentStyleSheetCollection.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/NodeRenderingContext.cpp
Source/WebCore/dom/ShadowRoot.cpp
Source/WebCore/dom/Text.cpp
Source/WebCore/editing/EditingStyle.cpp
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/html/HTMLCanvasElement.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLOptGroupElement.cpp
Source/WebCore/html/HTMLOptionElement.cpp
Source/WebCore/html/HTMLPlugInImageElement.cpp
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/html/shadow/DateTimeEditElement.cpp
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/animation/KeyframeAnimation.cpp
Source/WebCore/rendering/RenderListBox.cpp
Source/WebCore/rendering/RenderMenuList.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderRegion.cpp
Source/WebCore/rendering/RenderSearchField.cpp
Source/WebCore/rendering/svg/RenderSVGInlineText.cpp
Source/WebCore/svg/SVGElement.cpp
Source/WebCore/svg/SVGElementRareData.h
Source/WebKit/qt/Api/qwebelement.cpp
Source/WebKit/qt/ChangeLog

index f89381d..7a22561 100644 (file)
@@ -1,3 +1,89 @@
+2013-04-30  Andreas Kling  <akling@apple.com>
+
+        Don't create StyleResolvers just to invalidate them.
+        <http://webkit.org/b/115436>
+
+        Reviewed by Geoffrey Garen.
+
+        Renamed Document::styleResolver() to ensureStyleResolver() so it's clear that it never returns null.
+        Removed a bunch of unnecessary null-checks I spotted while doing this.
+
+        Also fixed Element::willModifyAttribute() and FrameView::setFrameRect() to not create a StyleResolver
+        and immediately invalidate it in some cases.
+
+        * css/FontLoader.cpp:
+        (WebCore::FontLoader::loadFont):
+        (WebCore::FontLoader::checkFont):
+        (WebCore::FontLoader::resolveFontStyle):
+        * css/MediaQueryMatcher.cpp:
+        (WebCore::MediaQueryMatcher::prepareEvaluator):
+        * css/StyleMedia.cpp:
+        (WebCore::StyleMedia::matchMedium):
+        * dom/Document.cpp:
+        (WebCore::Document::styleForElementIgnoringPendingStylesheets):
+        (WebCore::Document::styleForPage):
+        * dom/Document.h:
+        (WebCore::Document::ensureStyleResolver):
+        * dom/DocumentStyleSheetCollection.cpp:
+        (WebCore::DocumentStyleSheetCollection::combineCSSFeatureFlags):
+        (WebCore::DocumentStyleSheetCollection::resetCSSFeatureFlags):
+        (WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
+        * dom/Element.cpp:
+        (WebCore::StyleResolverParentPusher::push):
+        (WebCore::StyleResolverParentPusher::~StyleResolverParentPusher):
+        (WebCore::Element::styleForRenderer):
+        (WebCore::Element::recalcStyle):
+        (WebCore::Element::willModifyAttribute):
+        * dom/NodeRenderingContext.cpp:
+        (WebCore::NodeRenderingContext::createRendererForTextIfNeeded):
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::recalcStyle):
+        (WebCore::ShadowRoot::attach):
+        * dom/Text.cpp:
+        (WebCore::Text::recalcTextStyle):
+        * editing/EditingStyle.cpp:
+        (WebCore::styleFromMatchedRulesForElement):
+        * html/HTMLCanvasElement.cpp:
+        * html/HTMLCanvasElement.h:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::customStyleForRenderer):
+        * html/HTMLOptGroupElement.cpp:
+        (WebCore::HTMLOptGroupElement::updateNonRenderStyle):
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::updateNonRenderStyle):
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::HTMLPlugInImageElement::customStyleForRenderer):
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::setFont):
+        * html/shadow/DateTimeEditElement.cpp:
+        (WebCore::DateTimeEditElement::customStyleForRenderer):
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::getMatchedStylesForNode):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::getMatchedCSSRules):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::setFrameRect):
+        * page/animation/KeyframeAnimation.cpp:
+        (WebCore::KeyframeAnimation::KeyframeAnimation):
+        * rendering/RenderListBox.cpp:
+        (WebCore::RenderListBox::updateFromElement):
+        (WebCore::RenderListBox::paintItemForeground):
+        * rendering/RenderMenuList.cpp:
+        (WebCore::RenderMenuList::fontSelector):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::getUncachedPseudoStyle):
+        * rendering/RenderRegion.cpp:
+        (WebCore::RenderRegion::checkRegionStyle):
+        (WebCore::RenderRegion::computeStyleInRegion):
+        * rendering/RenderSearchField.cpp:
+        (WebCore::RenderSearchField::fontSelector):
+        * rendering/svg/RenderSVGInlineText.cpp:
+        (WebCore::RenderSVGInlineText::computeNewScaledFontForStyle):
+        * svg/SVGElement.cpp:
+        (WebCore::SVGElement::customStyleForRenderer):
+        * svg/SVGElementRareData.h:
+        (WebCore::SVGElementRareData::overrideComputedStyle):
+
 2013-04-30  Simon Fraser  <simon.fraser@apple.com>
 
         Cap max CALayer tree depth to avoid crashes
index e9153d9..8e1f948 100644 (file)
@@ -237,7 +237,7 @@ void FontLoader::loadFont(const Dictionary& params)
     RefPtr<LoadFontCallback> callback = LoadFontCallback::createFromParams(params, font.family());
     
     for (const FontFamily* f = &font.family(); f; f = f->next()) {
-        CSSSegmentedFontFace* face = m_document->styleResolver()->fontSelector()->getFontFace(font.fontDescription(), f->family());
+        CSSSegmentedFontFace* face = m_document->ensureStyleResolver()->fontSelector()->getFontFace(font.fontDescription(), f->family());
         if (!face) {
             if (callback)
                 callback->notifyError();
@@ -254,7 +254,7 @@ bool FontLoader::checkFont(const String& fontString, const String&)
     if (!resolveFontStyle(fontString, font))
         return false;
     for (const FontFamily* f = &font.family(); f; f = f->next()) {
-        CSSSegmentedFontFace* face = m_document->styleResolver()->fontSelector()->getFontFace(font.fontDescription(), f->family());
+        CSSSegmentedFontFace* face = m_document->ensureStyleResolver()->fontSelector()->getFontFace(font.fontDescription(), f->family());
         if (!face || !face->checkFont())
             return false;
     }
@@ -293,7 +293,7 @@ bool FontLoader::resolveFontStyle(const String& fontString, Font& font)
     style->font().update(style->font().fontSelector());
 
     // Now map the font property longhands into the style.
-    StyleResolver* styleResolver = m_document->styleResolver();
+    StyleResolver* styleResolver = m_document->ensureStyleResolver();
     styleResolver->applyPropertyToStyle(CSSPropertyFontFamily, parsedStyle->getPropertyCSSValue(CSSPropertyFontFamily).get(), style.get());
     applyPropertyToCurrentStyle(styleResolver, CSSPropertyFontStyle, parsedStyle);
     applyPropertyToCurrentStyle(styleResolver, CSSPropertyFontVariant, parsedStyle);
index 689f658..a568a9d 100644 (file)
@@ -84,9 +84,7 @@ PassOwnPtr<MediaQueryEvaluator> MediaQueryMatcher::prepareEvaluator() const
     if (!documentElement)
         return nullptr;
 
-    StyleResolver* styleResolver = m_document->styleResolver();
-    if (!styleResolver)
-        return nullptr;
+    StyleResolver* styleResolver = m_document->ensureStyleResolver();
 
     RefPtr<RenderStyle> rootStyle = styleResolver->styleForElement(documentElement, 0 /*defaultParent*/, DisallowStyleSharing, MatchOnlyUserAgentRules);
 
index c78c00a..a167418 100644 (file)
@@ -60,9 +60,7 @@ bool StyleMedia::matchMedium(const String& query) const
     if (!documentElement)
         return false;
 
-    StyleResolver* styleResolver = document->styleResolver();
-    if (!styleResolver)
-        return false;
+    StyleResolver* styleResolver = document->ensureStyleResolver();
 
     RefPtr<RenderStyle> rootStyle = styleResolver->styleForElement(documentElement, 0 /*defaultParent*/, DisallowStyleSharing, MatchOnlyUserAgentRules);
 
index d9f20d3..a457a82 100644 (file)
@@ -1934,14 +1934,14 @@ PassRefPtr<RenderStyle> Document::styleForElementIgnoringPendingStylesheets(Elem
 
     bool oldIgnore = m_ignorePendingStylesheets;
     m_ignorePendingStylesheets = true;
-    RefPtr<RenderStyle> style = styleResolver()->styleForElement(element, element->parentNode() ? element->parentNode()->computedStyle() : 0);
+    RefPtr<RenderStyle> style = ensureStyleResolver()->styleForElement(element, element->parentNode() ? element->parentNode()->computedStyle() : 0);
     m_ignorePendingStylesheets = oldIgnore;
     return style.release();
 }
 
 PassRefPtr<RenderStyle> Document::styleForPage(int pageIndex)
 {
-    RefPtr<RenderStyle> style = styleResolver()->styleForPage(pageIndex);
+    RefPtr<RenderStyle> style = ensureStyleResolver()->styleForPage(pageIndex);
     return style.release();
 }
 
index 0a2a3ad..3d63351 100644 (file)
@@ -449,7 +449,7 @@ public:
 
     bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; }
 
-    StyleResolver* styleResolver()
+    StyleResolver* ensureStyleResolver()
     { 
         if (!m_styleResolver)
             createStyleResolver();
index 16d22cf..dbef0c9 100644 (file)
@@ -86,7 +86,7 @@ DocumentStyleSheetCollection::~DocumentStyleSheetCollection()
 void DocumentStyleSheetCollection::combineCSSFeatureFlags()
 {
     // Delay resetting the flags until after next style recalc since unapplying the style may not work without these set (this is true at least with before/after).
-    StyleResolver* styleResolver = m_document->styleResolver();
+    StyleResolver* styleResolver = m_document->ensureStyleResolver();
     m_usesSiblingRules = m_usesSiblingRules || styleResolver->usesSiblingRules();
     m_usesFirstLineRules = m_usesFirstLineRules || styleResolver->usesFirstLineRules();
     m_usesBeforeAfterRules = m_usesBeforeAfterRules || styleResolver->usesBeforeAfterRules();
@@ -94,7 +94,7 @@ void DocumentStyleSheetCollection::combineCSSFeatureFlags()
 
 void DocumentStyleSheetCollection::resetCSSFeatureFlags()
 {
-    StyleResolver* styleResolver = m_document->styleResolver();
+    StyleResolver* styleResolver = m_document->ensureStyleResolver();
     m_usesSiblingRules = styleResolver->usesSiblingRules();
     m_usesFirstLineRules = styleResolver->usesFirstLineRules();
     m_usesBeforeAfterRules = styleResolver->usesBeforeAfterRules();
@@ -474,7 +474,7 @@ bool DocumentStyleSheetCollection::updateActiveStyleSheets(UpdateFlag updateFlag
     if (styleResolverUpdateType == Reconstruct)
         m_document->clearStyleResolver();
     else {
-        StyleResolver* styleResolver = m_document->styleResolver();
+        StyleResolver* styleResolver = m_document->ensureStyleResolver();
         if (styleResolverUpdateType == Reset) {
             styleResolver->ruleSets().resetAuthorStyle();
             styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets);
index 7eb186d..e336482 100644 (file)
@@ -112,7 +112,7 @@ public:
     {
         if (m_pushedStyleResolver)
             return;
-        m_pushedStyleResolver = m_parent->document()->styleResolver();
+        m_pushedStyleResolver = m_parent->document()->ensureStyleResolver();
         m_pushedStyleResolver->pushParentElement(m_parent);
     }
     ~StyleResolverParentPusher()
@@ -123,8 +123,8 @@ public:
 
         // This tells us that our pushed style selector is in a bad state,
         // so we should just bail out in that scenario.
-        ASSERT(m_pushedStyleResolver == m_parent->document()->styleResolver());
-        if (m_pushedStyleResolver != m_parent->document()->styleResolver())
+        ASSERT(m_pushedStyleResolver == m_parent->document()->ensureStyleResolver());
+        if (m_pushedStyleResolver != m_parent->document()->ensureStyleResolver())
             return;
 
         m_pushedStyleResolver->popParentElement(m_parent);
@@ -1387,7 +1387,7 @@ PassRefPtr<RenderStyle> Element::styleForRenderer()
             return style.release();
     }
 
-    return document()->styleResolver()->styleForElement(this);
+    return document()->ensureStyleResolver()->styleForElement(this);
 }
 
 void Element::recalcStyle(StyleChange change)
@@ -1440,7 +1440,8 @@ void Element::recalcStyle(StyleChange change)
         // all the way down the tree. This is simpler than having to maintain a cache of objects (and such font size changes should be rare anyway).
         if (document()->styleSheetCollection()->usesRemUnits() && document()->documentElement() == this && localChange != NoChange && currentStyle && newStyle && currentStyle->fontSize() != newStyle->fontSize()) {
             // Cached RenderStyles may depend on the re units.
-            document()->styleResolver()->invalidateMatchedPropertiesCache();
+            if (StyleResolver* styleResolver = document()->styleResolverIfExists())
+                styleResolver->invalidateMatchedPropertiesCache();
             change = Force;
         }
 
@@ -2721,7 +2722,7 @@ void Element::willModifyAttribute(const QualifiedName& name, const AtomicString&
     }
 
     if (oldValue != newValue) {
-        if (attached() && document()->styleResolver() && document()->styleResolver()->hasSelectorForAttribute(name.localName()))
+        if (attached() && document()->styleResolverIfExists() && document()->styleResolverIfExists()->hasSelectorForAttribute(name.localName()))
             setNeedsStyleRecalc();
     }
 
index 9f08ed3..998b931 100644 (file)
@@ -297,7 +297,7 @@ void NodeRenderingContext::createRendererForTextIfNeeded()
     Document* document = textNode->document();
 
     if (resetStyleInheritance())
-        m_style = document->styleResolver()->defaultStyleForElement();
+        m_style = document->ensureStyleResolver()->defaultStyleForElement();
     else
         m_style = parentRenderer->style();
 
index 16d477c..2aaccc5 100644 (file)
@@ -134,7 +134,7 @@ void ShadowRoot::recalcStyle(StyleChange change)
     // ShadowRoot doesn't support custom callbacks.
     ASSERT(!hasCustomStyleCallbacks());
 
-    StyleResolver* styleResolver = document()->styleResolver();
+    StyleResolver* styleResolver = document()->ensureStyleResolver();
     styleResolver->pushParentShadowRoot(this);
 
     for (Node* child = firstChild(); child; child = child->nextSibling()) {
@@ -174,7 +174,7 @@ void ShadowRoot::setResetStyleInheritance(bool value)
 
 void ShadowRoot::attach()
 {
-    StyleResolver* styleResolver = document()->styleResolver();
+    StyleResolver* styleResolver = document()->ensureStyleResolver();
     styleResolver->pushParentShadowRoot(this);
     DocumentFragment::attach();
     styleResolver->popParentShadowRoot(this);
index 283b8d5..602cb59 100644 (file)
@@ -286,7 +286,7 @@ void Text::recalcTextStyle(StyleChange change)
     RenderText* renderer = toRenderText(this->renderer());
 
     if (change != NoChange && renderer)
-        renderer->setStyle(document()->styleResolver()->styleForText(this));
+        renderer->setStyle(document()->ensureStyleResolver()->styleForText(this));
 
     if (needsStyleRecalc()) {
         if (renderer)
index 745f2bb..b063075 100644 (file)
@@ -1076,7 +1076,7 @@ void EditingStyle::mergeStyle(const StylePropertySet* style, CSSPropertyOverride
 static PassRefPtr<MutableStylePropertySet> styleFromMatchedRulesForElement(Element* element, unsigned rulesToInclude)
 {
     RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
-    RefPtr<CSSRuleList> matchedRules = element->document()->styleResolver()->styleRulesForElement(element, rulesToInclude);
+    RefPtr<CSSRuleList> matchedRules = element->document()->ensureStyleResolver()->styleRulesForElement(element, rulesToInclude);
     if (matchedRules) {
         for (unsigned i = 0; i < matchedRules->length(); i++) {
             if (matchedRules->item(i)->type() == CSSRule::STYLE_RULE)
index a8ffa9f..e317e0a 100644 (file)
@@ -478,11 +478,6 @@ SecurityOrigin* HTMLCanvasElement::securityOrigin() const
     return document()->securityOrigin();
 }
 
-StyleResolver* HTMLCanvasElement::styleResolver()
-{
-    return document()->styleResolver();
-}
-
 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const
 {
 #if USE(IOSURFACE_CANVAS_BACKING_STORE)
index 11b1b10..4087194 100644 (file)
@@ -124,8 +124,6 @@ public:
     void setOriginTainted() { m_originClean = false; }
     bool originClean() const { return m_originClean; }
 
-    StyleResolver* styleResolver();
-
     AffineTransform baseTransform() const;
 
 #if ENABLE(WEBGL)    
index 4985129..3b30344 100644 (file)
@@ -1972,7 +1972,7 @@ bool HTMLInputElement::setupDateTimeChooserParameters(DateTimeChooserParameters&
 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
 PassRefPtr<RenderStyle> HTMLInputElement::customStyleForRenderer()
 {
-    return m_inputType->customStyleForRenderer(document()->styleResolver()->styleForElement(this));
+    return m_inputType->customStyleForRenderer(document()->ensureStyleResolver()->styleForElement(this));
 }
 #endif
 
index a90799c..660172a 100644 (file)
@@ -114,7 +114,7 @@ void HTMLOptGroupElement::detach()
 
 void HTMLOptGroupElement::updateNonRenderStyle()
 {
-    m_style = document()->styleResolver()->styleForElement(this);
+    m_style = document()->ensureStyleResolver()->styleForElement(this);
 }
 
 RenderStyle* HTMLOptGroupElement::nonRendererStyle() const
index 761248a..0ed80e7 100644 (file)
@@ -312,7 +312,7 @@ void HTMLOptionElement::setLabel(const String& label)
 
 void HTMLOptionElement::updateNonRenderStyle()
 {
-    m_style = document()->styleResolver()->styleForElement(this);
+    m_style = document()->ensureStyleResolver()->styleForElement(this);
 }
 
 RenderStyle* HTMLOptionElement::nonRendererStyle() const
index 2c6971c..30e46bf 100644 (file)
@@ -293,7 +293,7 @@ void HTMLPlugInImageElement::documentDidResumeFromPageCache()
 PassRefPtr<RenderStyle> HTMLPlugInImageElement::customStyleForRenderer()
 {
     if (!m_customStyleForPageCache)
-        return document()->styleResolver()->styleForElement(this);
+        return document()->ensureStyleResolver()->styleForElement(this);
     return m_customStyleForPageCache;
 }
 
index 47197d9..19bc950 100644 (file)
@@ -2063,7 +2063,7 @@ void CanvasRenderingContext2D::setFont(const String& newFont)
     newStyle->font().update(newStyle->font().fontSelector());
 
     // Now map the font property longhands into the style.
-    StyleResolver* styleResolver = canvas()->styleResolver();
+    StyleResolver* styleResolver = canvas()->document()->ensureStyleResolver();
     styleResolver->applyPropertyToStyle(CSSPropertyFontFamily, parsedStyle->getPropertyCSSValue(CSSPropertyFontFamily).get(), newStyle.get());
     styleResolver->applyPropertyToCurrentStyle(CSSPropertyFontStyle, parsedStyle->getPropertyCSSValue(CSSPropertyFontStyle).get());
     styleResolver->applyPropertyToCurrentStyle(CSSPropertyFontVariant, parsedStyle->getPropertyCSSValue(CSSPropertyFontVariant).get());
index 90a9ddc..2be6ea1 100644 (file)
@@ -498,7 +498,7 @@ PassRefPtr<RenderStyle> DateTimeEditElement::customStyleForRenderer()
 {
     // FIXME: This is a kind of layout. We might want to introduce new renderer.
     FontCachePurgePreventer fontCachePurgePreventer;
-    RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForElement(this);
+    RefPtr<RenderStyle> originalStyle = document()->ensureStyleResolver()->styleForElement(this);
     RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
     float width = 0;
     for (Node* child = fieldsWrapperElement()->firstChild(); child; child = child->nextSibling()) {
index 21d6991..2a3e66a 100644 (file)
@@ -734,7 +734,7 @@ void InspectorCSSAgent::getMatchedStylesForNode(ErrorString* errorString, int no
         return;
 
     // Matched rules.
-    StyleResolver* styleResolver = element->ownerDocument()->styleResolver();
+    StyleResolver* styleResolver = element->ownerDocument()->ensureStyleResolver();
     RefPtr<CSSRuleList> matchedRules = styleResolver->styleRulesForElement(element, StyleResolver::AllCSSRules);
     matchedCSSRules = buildArrayForMatchedRuleList(matchedRules.get(), styleResolver, element);
 
@@ -759,7 +759,7 @@ void InspectorCSSAgent::getMatchedStylesForNode(ErrorString* errorString, int no
         RefPtr<TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry> > entries = TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry>::create();
         Element* parentElement = element->parentElement();
         while (parentElement) {
-            StyleResolver* parentStyleResolver = parentElement->ownerDocument()->styleResolver();
+            StyleResolver* parentStyleResolver = parentElement->ownerDocument()->ensureStyleResolver();
             RefPtr<CSSRuleList> parentMatchedRules = parentStyleResolver->styleRulesForElement(parentElement, StyleResolver::AllCSSRules);
             RefPtr<TypeBuilder::CSS::InheritedStyleEntry> entry = TypeBuilder::CSS::InheritedStyleEntry::create()
                 .setMatchedCSSRules(buildArrayForMatchedRuleList(parentMatchedRules.get(), styleResolver, parentElement));
index 7b864fc..c1c19c8 100644 (file)
@@ -1382,7 +1382,7 @@ PassRefPtr<CSSRuleList> DOMWindow::getMatchedCSSRules(Element* element, const St
 
     PseudoId pseudoId = CSSSelector::pseudoId(pseudoType);
 
-    return m_frame->document()->styleResolver()->pseudoStyleRulesForElement(element, pseudoId, rulesToInclude);
+    return m_frame->document()->ensureStyleResolver()->pseudoStyleRulesForElement(element, pseudoId, rulesToInclude);
 }
 
 PassRefPtr<WebKitPoint> DOMWindow::webkitConvertPointFromNodeToPage(Node* node, const WebKitPoint* p) const
index 2bbc218..e0d1bfd 100644 (file)
@@ -481,7 +481,7 @@ void FrameView::setFrameRect(const IntRect& newRect)
     Document* document = m_frame ? m_frame->document() : 0;
 
     // Viewport-dependent media queries may cause us to need completely different style information.
-    if (document && document->styleResolver() && document->styleResolver()->affectedByViewportChange()) {
+    if (document && document->styleResolverIfExists() && document->styleResolverIfExists()->affectedByViewportChange()) {
         document->styleResolverChanged(DeferRecalcStyle);
         InspectorInstrumentation::mediaQueryResultChanged(document);
     }
index 538ef04..6cb827e 100644 (file)
@@ -52,7 +52,7 @@ KeyframeAnimation::KeyframeAnimation(const Animation* animation, RenderObject* r
 {
     // Get the keyframe RenderStyles
     if (m_object && m_object->node() && m_object->node()->isElementNode())
-        m_object->document()->styleResolver()->keyframeStylesForAnimation(toElement(m_object->node()), unanimatedStyle, m_keyframes);
+        m_object->document()->ensureStyleResolver()->keyframeStylesForAnimation(toElement(m_object->node()), unanimatedStyle, m_keyframes);
 
     // Update the m_transformFunctionListValid flag based on whether the function lists in the keyframes match.
     validateTransformFunctionList();
index a75eb86..238c165 100644 (file)
@@ -131,7 +131,7 @@ void RenderListBox::updateFromElement()
                 FontDescription d = itemFont.fontDescription();
                 d.setWeight(d.bolderWeight());
                 itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing());
-                itemFont.update(document()->styleResolver()->fontSelector());
+                itemFont.update(document()->ensureStyleResolver()->fontSelector());
             }
 
             if (!text.isEmpty()) {
@@ -431,7 +431,7 @@ void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const LayoutPoint&
         FontDescription d = itemFont.fontDescription();
         d.setWeight(d.bolderWeight());
         itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing());
-        itemFont.update(document()->styleResolver()->fontSelector());
+        itemFont.update(document()->ensureStyleResolver()->fontSelector());
     }
 
     // Draw the item text
index 5a4e36a..7f6d298 100644 (file)
@@ -615,7 +615,7 @@ void RenderMenuList::setTextFromItem(unsigned listIndex)
 
 FontSelector* RenderMenuList::fontSelector() const
 {
-    return document()->styleResolver()->fontSelector();
+    return document()->ensureStyleResolver()->fontSelector();
 }
 
 }
index 00935e1..17a1bd9 100644 (file)
@@ -2768,12 +2768,12 @@ PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(const PseudoStyleRe
     Element* element = toElement(n);
 
     if (pseudoStyleRequest.pseudoId == FIRST_LINE_INHERITED) {
-        RefPtr<RenderStyle> result = document()->styleResolver()->styleForElement(element, parentStyle, DisallowStyleSharing);
+        RefPtr<RenderStyle> result = document()->ensureStyleResolver()->styleForElement(element, parentStyle, DisallowStyleSharing);
         result->setStyleType(FIRST_LINE_INHERITED);
         return result.release();
     }
 
-    return document()->styleResolver()->pseudoStyleForElement(element, pseudoStyleRequest, parentStyle);
+    return document()->ensureStyleResolver()->pseudoStyleForElement(element, pseudoStyleRequest, parentStyle);
 }
 
 static Color decorationColor(RenderStyle* style)
index 5e13e3d..9d7355e 100644 (file)
@@ -195,7 +195,7 @@ void RenderRegion::checkRegionStyle()
     // FIXME: Region styling doesn't work for pseudo elements.
     if (node()) {
         Element* regionElement = toElement(node());
-        customRegionStyle = view()->document()->styleResolver()->checkRegionStyle(regionElement);
+        customRegionStyle = view()->document()->ensureStyleResolver()->checkRegionStyle(regionElement);
     }
     setHasCustomRegionStyle(customRegionStyle);
     m_flowThread->checkRegionsWithStyling();
@@ -526,7 +526,7 @@ PassRefPtr<RenderStyle> RenderRegion::computeStyleInRegion(const RenderObject* o
 
     // FIXME: Region styling fails for pseudo-elements because the renderers don't have a node.
     Element* element = toElement(object->node());
-    RefPtr<RenderStyle> renderObjectRegionStyle = object->view()->document()->styleResolver()->styleForElement(element, 0, DisallowStyleSharing, MatchAllRules, this);
+    RefPtr<RenderStyle> renderObjectRegionStyle = object->view()->document()->ensureStyleResolver()->styleForElement(element, 0, DisallowStyleSharing, MatchAllRules, this);
 
     return renderObjectRegionStyle.release();
 }
index ca0228c..c36e834 100644 (file)
@@ -344,7 +344,7 @@ void RenderSearchField::setTextFromItem(unsigned listIndex)
 
 FontSelector* RenderSearchField::fontSelector() const
 {
-    return document()->styleResolver()->fontSelector();
+    return document()->ensureStyleResolver()->fontSelector();
 }
 
 HostWindow* RenderSearchField::hostWindow() const
index 2371d1a..f1ed27b 100644 (file)
@@ -228,8 +228,7 @@ void RenderSVGInlineText::computeNewScaledFontForStyle(RenderObject* renderer, c
     Document* document = renderer->document();
     ASSERT(document);
     
-    StyleResolver* styleResolver = document->styleResolver();
-    ASSERT(styleResolver);
+    StyleResolver* styleResolver = document->ensureStyleResolver();
 
     // Alter font-size to the right on-screen value to avoid scaling the glyphs themselves, except when GeometricPrecision is specified
     scalingFactor = SVGRenderingContext::calculateScreenFontSizeScalingFactor(renderer);
index 51c4c1f..afdfaf4 100644 (file)
@@ -596,7 +596,7 @@ void SVGElement::synchronizeSystemLanguage(SVGElement* contextElement)
 PassRefPtr<RenderStyle> SVGElement::customStyleForRenderer()
 {
     if (!correspondingElement())
-        return document()->styleResolver()->styleForElement(this);
+        return document()->ensureStyleResolver()->styleForElement(this);
 
     RenderStyle* style = 0;
     if (Element* parent = parentOrShadowHostElement()) {
@@ -604,7 +604,7 @@ PassRefPtr<RenderStyle> SVGElement::customStyleForRenderer()
             style = renderer->style();
     }
 
-    return document()->styleResolver()->styleForElement(correspondingElement(), style, DisallowStyleSharing);
+    return document()->ensureStyleResolver()->styleForElement(correspondingElement(), style, DisallowStyleSharing);
 }
 
 MutableStylePropertySet* SVGElement::animatedSMILStyleProperties() const
index d53f473..ba706bd 100644 (file)
@@ -95,7 +95,7 @@ public:
             return 0;
         if (!m_overrideComputedStyle || m_needsOverrideComputedStyleUpdate) {
             // The style computed here contains no CSS Animations/Transitions or SMIL induced rules - this is needed to compute the "base value" for the SMIL animation sandwhich model.
-            m_overrideComputedStyle = element->document()->styleResolver()->styleForElement(element, parentStyle, DisallowStyleSharing, MatchAllRulesExcludingSMIL);
+            m_overrideComputedStyle = element->document()->ensureStyleResolver()->styleForElement(element, parentStyle, DisallowStyleSharing, MatchAllRulesExcludingSMIL);
             m_needsOverrideComputedStyleUpdate = false;
         }
         ASSERT(m_overrideComputedStyle);
index 1974d4c..ca9c204 100644 (file)
@@ -829,7 +829,7 @@ QString QWebElement::styleProperty(const QString &name, StyleResolveStrategy str
         // declarations, as well as embedded and inline style declarations.
 
         Document* doc = m_element->document();
-        if (RefPtr<CSSRuleList> rules = doc->styleResolver()->styleRulesForElement(m_element, StyleResolver::AuthorCSSRules | StyleResolver::CrossOriginCSSRules)) {
+        if (RefPtr<CSSRuleList> rules = doc->ensureStyleResolver()->styleRulesForElement(m_element, StyleResolver::AuthorCSSRules | StyleResolver::CrossOriginCSSRules)) {
             for (int i = rules->length(); i > 0; --i) {
                 CSSStyleRule* rule = static_cast<CSSStyleRule*>(rules->item(i - 1));
 
index c32bd0c..1cd7e3a 100644 (file)
@@ -1,3 +1,13 @@
+2013-04-30  Andreas Kling  <akling@apple.com>
+
+        Don't create StyleResolvers just to invalidate them.
+        <http://webkit.org/b/115436>
+
+        Reviewed by Geoffrey Garen.
+
+        * Api/qwebelement.cpp:
+        (QWebElement::styleProperty):
+
 2013-04-25  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: ConsoleMessage should include line and column number where possible