2008-10-16 David Hyatt <hyatt@apple.com>
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Oct 2008 00:25:33 +0000 (00:25 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Oct 2008 00:25:33 +0000 (00:25 +0000)
        https://bugs.webkit.org/attachment.cgi?bugid=21647

        Make RenderStyle inherit from RefCounted so that it works with RefPtr.  RenderStyle was being malloced
        out of the RenderArena.  Years and years ago (before TCMalloc), the plan was to make RenderStyles and
        all their associated sub-structs use the arena.  However only the RenderStyle itself was ever changed
        to use the arena.

        At a later point style sharing was implemented, which made using the arena for styles pretty pointless,
        as the bulk of the styles on a given page are actually shared.  Not ever making the sub-structs use the
        arena also limited the usefulness.

        Now that we have RefPtr/PassRefPtr to eliminate manual ref/deref and now that we use TCMalloc for fast
        mallocs, there is no reason to keep RenderStyles in the arena.  The benefits of being able to eliminate
        manual ref/deref far outweigh keeping them in the arena.

        Reviewed by Adam Roben

        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::CSSStyleSelector):
        (WebCore::CSSStyleSelector::~CSSStyleSelector):
        (WebCore::CSSStyleSelector::styleForElement):
        (WebCore::CSSStyleSelector::keyframeStylesForAnimation):
        (WebCore::CSSStyleSelector::pseudoStyleForElement):
        These methods now return a PassRefPtr.  They will null out the m_style variable as they hand it back
        so that it isn't left pointing to the previous style resolve RenderStyle (which is what the old code did).

        (WebCore::CSSStyleSelector::updateFont):
        (WebCore::CSSStyleSelector::checkSelector):
        (WebCore::CSSStyleSelector::applyProperty):
        (WebCore::CSSStyleSelector::mapFillSize):
        (WebCore::CSSStyleSelector::mapFillXPosition):
        (WebCore::CSSStyleSelector::mapFillYPosition):
        * css/CSSStyleSelector.h:
        (WebCore::CSSStyleSelector::style):
        * dom/Document.cpp:
        (WebCore::Document::recalcStyle):
        * dom/Element.cpp:
        (WebCore::Element::styleForRenderer):
        (WebCore::Element::recalcStyle):
        (WebCore::Element::computedStyle):
        * dom/Element.h:
        * dom/ElementRareData.h:
        (WebCore::ElementRareData::ElementRareData):
        (WebCore::ElementRareData::resetComputedStyle):
        * dom/Node.cpp:
        (WebCore::Node::diff):
        (WebCore::Node::createRendererIfNeeded):
        (WebCore::Node::styleForRenderer):
        (WebCore::Node::setRenderStyle):
        * dom/Node.h:
        * html/CanvasRenderingContext2D.cpp:
        (WebCore::CanvasRenderingContext2D::setFont):
        * html/HTMLOptGroupElement.cpp:
        (WebCore::HTMLOptGroupElement::attach):
        (WebCore::HTMLOptGroupElement::detach):
        (WebCore::HTMLOptGroupElement::setRenderStyle):
        (WebCore::HTMLOptGroupElement::nonRendererRenderStyle):
        * html/HTMLOptGroupElement.h:
        * html/HTMLOptionElement.cpp:
        (WebCore::HTMLOptionElement::attach):
        (WebCore::HTMLOptionElement::detach):
        (WebCore::HTMLOptionElement::setRenderStyle):
        (WebCore::HTMLOptionElement::nonRendererRenderStyle):
        * html/HTMLOptionElement.h:
        * page/animation/AnimationBase.h:
        (WebCore::AnimationBase::animate):
        * page/animation/AnimationController.cpp:
        (WebCore::AnimationController::updateAnimations):
        * page/animation/AnimationController.h:
        * page/animation/CompositeAnimation.cpp:
        (WebCore::CompositeAnimationPrivate::updateTransitions):
        (WebCore::CompositeAnimationPrivate::updateKeyframeAnimations):
        (WebCore::CompositeAnimationPrivate::animate):
        (WebCore::CompositeAnimation::animate):
        * page/animation/CompositeAnimation.h:
        * page/animation/ImplicitAnimation.cpp:
        (WebCore::ImplicitAnimation::ImplicitAnimation):
        (WebCore::ImplicitAnimation::~ImplicitAnimation):
        (WebCore::ImplicitAnimation::animate):
        (WebCore::ImplicitAnimation::reset):
        (WebCore::ImplicitAnimation::isTargetPropertyEqual):
        (WebCore::ImplicitAnimation::blendPropertyValueInStyle):
        * page/animation/ImplicitAnimation.h:
        (WebCore::ImplicitAnimation::create):
        * page/animation/KeyframeAnimation.cpp:
        (WebCore::KeyframeAnimation::KeyframeAnimation):
        (WebCore::KeyframeAnimation::~KeyframeAnimation):
        (WebCore::KeyframeAnimation::animate):
        (WebCore::KeyframeAnimation::validateTransformFunctionList):
        * page/animation/KeyframeAnimation.h:
        (WebCore::KeyframeAnimation::create):
        (WebCore::KeyframeAnimation::unanimatedStyle):
        * rendering/InlineTextBox.cpp:
        (WebCore::InlineTextBox::paint):
        * rendering/MediaControlElements.cpp:
        (WebCore::MediaControlShadowRootElement::MediaControlShadowRootElement):
        (WebCore::MediaControlInputElement::MediaControlInputElement):
        * rendering/RenderBlock.cpp:
        (WebCore::RenderBlock::styleDidChange):
        (WebCore::RenderBlock::updateFirstLetter):
        * rendering/RenderContainer.cpp:
        (WebCore::RenderContainer::addChild):
        (WebCore::RenderContainer::updateBeforeAfterContentForContainer):
        * rendering/RenderFileUploadControl.cpp:
        (WebCore::RenderFileUploadControl::updateFromElement):
        (WebCore::RenderFileUploadControl::createButtonStyle):
        * rendering/RenderFileUploadControl.h:
        * rendering/RenderFlow.cpp:
        (WebCore::RenderFlow::createAnonymousFlow):
        * rendering/RenderFlow.h:
        * rendering/RenderInline.cpp:
        (WebCore::RenderInline::addChildToFlow):
        * rendering/RenderLayer.cpp:
        (WebCore::RenderLayer::updateScrollCornerStyle):
        (WebCore::RenderLayer::updateResizerStyle):
        (WebCore::RenderLayer::updateReflectionStyle):
        * rendering/RenderListItem.cpp:
        (WebCore::RenderListItem::styleDidChange):
        * rendering/RenderMedia.cpp:
        (WebCore::RenderMedia::createPanel):
        (WebCore::RenderMedia::createTimeDisplay):
        (WebCore::RenderMedia::changeOpacity):
        * rendering/RenderObject.cpp:
        (WebCore::RenderObject::selectionBackgroundColor):
        (WebCore::RenderObject::selectionForegroundColor):
        (WebCore::RenderObject::createAnonymousBlock):
        (WebCore::RenderObject::setAnimatableStyle):
        (WebCore::RenderObject::setStyle):
        (WebCore::RenderObject::setStyleInternal):
        (WebCore::RenderObject::arenaDelete):
        (WebCore::RenderObject::firstLineStyle):
        (WebCore::RenderObject::getPseudoStyle):
        * rendering/RenderObject.h:
        (WebCore::RenderObject::style):
        * rendering/RenderSVGBlock.cpp:
        (WebCore::RenderSVGBlock::setStyle):
        * rendering/RenderSVGBlock.h:
        * rendering/RenderScrollbar.cpp:
        (WebCore::RenderScrollbar::getScrollbarPseudoStyle):
        (WebCore::RenderScrollbar::updateScrollbarPart):
        * rendering/RenderScrollbar.h:
        * rendering/RenderSlider.cpp:
        (WebCore::RenderSlider::styleDidChange):
        (WebCore::RenderSlider::createThumbStyle):
        (WebCore::RenderSlider::updateFromElement):
        * rendering/RenderSlider.h:
        * rendering/RenderTable.cpp:
        (WebCore::RenderTable::addChild):
        * rendering/RenderTableRow.cpp:
        (WebCore::RenderTableRow::addChild):
        * rendering/RenderTableSection.cpp:
        (WebCore::RenderTableSection::addChild):
        * rendering/RenderTextControl.cpp:
        (WebCore::RenderTextControl::styleDidChange):
        (WebCore::RenderTextControl::createInnerBlockStyle):
        (WebCore::RenderTextControl::createInnerTextStyle):
        (WebCore::RenderTextControl::createResultsButtonStyle):
        (WebCore::RenderTextControl::createCancelButtonStyle):
        (WebCore::RenderTextControl::createSubtreeIfNeeded):
        (WebCore::RenderTextControl::updatePlaceholderVisibility):
        * rendering/RenderTextControl.h:
        * rendering/TextControlInnerElements.cpp:
        (WebCore::TextControlInnerElement::attachInnerElement):
        * rendering/TextControlInnerElements.h:
        * rendering/style/KeyframeList.cpp:
        (WebCore::KeyframeList::clear):
        (WebCore::KeyframeList::operator==):
        (WebCore::KeyframeList::insert):
        * rendering/style/KeyframeList.h:
        (WebCore::KeyframeValue::KeyframeValue):
        (WebCore::KeyframeValue::~KeyframeValue):
        (WebCore::KeyframeValue::key):
        (WebCore::KeyframeValue::style):
        * rendering/style/RenderStyle.cpp:
        (WebCore::defaultStyle):
        (WebCore::RenderStyle::create):
        (WebCore::RenderStyle::createDefaultStyle):
        (WebCore::RenderStyle::clone):
        (WebCore::RenderStyle::RenderStyle):
        (WebCore::RenderStyle::getCachedPseudoStyle):
        (WebCore::RenderStyle::addCachedPseudoStyle):
        * rendering/style/RenderStyle.h:
        (WebCore::):
        (WebCore::InheritedFlags::operator!=):
        * svg/SVGClipPathElement.cpp:
        (WebCore::SVGClipPathElement::canvasResource):
        * svg/SVGGradientElement.cpp:
        (WebCore::SVGGradientElement::buildStops):
        * svg/SVGStyledElement.cpp:
        (WebCore::SVGStyledElement::resolveStyle):
        * svg/SVGStyledElement.h:
        * svg/SVGUseElement.cpp:
        (WebCore::SVGUseElement::recalcStyle):
        (WebCore::SVGUseElement::attachShadowTree):

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

62 files changed:
WebCore/ChangeLog
WebCore/css/CSSGradientValue.h
WebCore/css/CSSStyleSelector.cpp
WebCore/css/CSSStyleSelector.h
WebCore/css/CSSVariableDependentValue.cpp
WebCore/css/CSSVariableDependentValue.h
WebCore/dom/Document.cpp
WebCore/dom/Element.cpp
WebCore/dom/Element.h
WebCore/dom/ElementRareData.h
WebCore/dom/Node.cpp
WebCore/dom/Node.h
WebCore/html/CanvasRenderingContext2D.cpp
WebCore/html/HTMLOptGroupElement.cpp
WebCore/html/HTMLOptGroupElement.h
WebCore/html/HTMLOptionElement.cpp
WebCore/html/HTMLOptionElement.h
WebCore/page/animation/AnimationBase.h
WebCore/page/animation/AnimationController.cpp
WebCore/page/animation/AnimationController.h
WebCore/page/animation/CompositeAnimation.cpp
WebCore/page/animation/CompositeAnimation.h
WebCore/page/animation/ImplicitAnimation.cpp
WebCore/page/animation/ImplicitAnimation.h
WebCore/page/animation/KeyframeAnimation.cpp
WebCore/page/animation/KeyframeAnimation.h
WebCore/rendering/InlineTextBox.cpp
WebCore/rendering/MediaControlElements.cpp
WebCore/rendering/RenderBlock.cpp
WebCore/rendering/RenderContainer.cpp
WebCore/rendering/RenderFileUploadControl.cpp
WebCore/rendering/RenderFileUploadControl.h
WebCore/rendering/RenderFlow.cpp
WebCore/rendering/RenderFlow.h
WebCore/rendering/RenderInline.cpp
WebCore/rendering/RenderLayer.cpp
WebCore/rendering/RenderListItem.cpp
WebCore/rendering/RenderMedia.cpp
WebCore/rendering/RenderObject.cpp
WebCore/rendering/RenderObject.h
WebCore/rendering/RenderSVGBlock.cpp
WebCore/rendering/RenderSVGBlock.h
WebCore/rendering/RenderScrollbar.cpp
WebCore/rendering/RenderScrollbar.h
WebCore/rendering/RenderSlider.cpp
WebCore/rendering/RenderSlider.h
WebCore/rendering/RenderTable.cpp
WebCore/rendering/RenderTableRow.cpp
WebCore/rendering/RenderTableSection.cpp
WebCore/rendering/RenderTextControl.cpp
WebCore/rendering/RenderTextControl.h
WebCore/rendering/TextControlInnerElements.cpp
WebCore/rendering/TextControlInnerElements.h
WebCore/rendering/style/KeyframeList.cpp
WebCore/rendering/style/KeyframeList.h
WebCore/rendering/style/RenderStyle.cpp
WebCore/rendering/style/RenderStyle.h
WebCore/svg/SVGClipPathElement.cpp
WebCore/svg/SVGGradientElement.cpp
WebCore/svg/SVGStyledElement.cpp
WebCore/svg/SVGStyledElement.h
WebCore/svg/SVGUseElement.cpp

index 2a3a8ce..4bd61ea 100644 (file)
@@ -1,3 +1,200 @@
+2008-10-16  David Hyatt  <hyatt@apple.com>
+
+        https://bugs.webkit.org/attachment.cgi?bugid=21647
+
+        Make RenderStyle inherit from RefCounted so that it works with RefPtr.  RenderStyle was being malloced
+        out of the RenderArena.  Years and years ago (before TCMalloc), the plan was to make RenderStyles and
+        all their associated sub-structs use the arena.  However only the RenderStyle itself was ever changed
+        to use the arena.
+
+        At a later point style sharing was implemented, which made using the arena for styles pretty pointless,
+        as the bulk of the styles on a given page are actually shared.  Not ever making the sub-structs use the
+        arena also limited the usefulness.
+
+        Now that we have RefPtr/PassRefPtr to eliminate manual ref/deref and now that we use TCMalloc for fast
+        mallocs, there is no reason to keep RenderStyles in the arena.  The benefits of being able to eliminate
+        manual ref/deref far outweigh keeping them in the arena.
+
+        Reviewed by Adam Roben
+
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::CSSStyleSelector):
+        (WebCore::CSSStyleSelector::~CSSStyleSelector):
+        (WebCore::CSSStyleSelector::styleForElement):
+        (WebCore::CSSStyleSelector::keyframeStylesForAnimation):
+        (WebCore::CSSStyleSelector::pseudoStyleForElement):
+        These methods now return a PassRefPtr.  They will null out the m_style variable as they hand it back
+        so that it isn't left pointing to the previous style resolve RenderStyle (which is what the old code did).
+
+        (WebCore::CSSStyleSelector::updateFont):
+        (WebCore::CSSStyleSelector::checkSelector):
+        (WebCore::CSSStyleSelector::applyProperty):
+        (WebCore::CSSStyleSelector::mapFillSize):
+        (WebCore::CSSStyleSelector::mapFillXPosition):
+        (WebCore::CSSStyleSelector::mapFillYPosition):
+        * css/CSSStyleSelector.h:
+        (WebCore::CSSStyleSelector::style):
+        * dom/Document.cpp:
+        (WebCore::Document::recalcStyle):
+        * dom/Element.cpp:
+        (WebCore::Element::styleForRenderer):
+        (WebCore::Element::recalcStyle):
+        (WebCore::Element::computedStyle):
+        * dom/Element.h:
+        * dom/ElementRareData.h:
+        (WebCore::ElementRareData::ElementRareData):
+        (WebCore::ElementRareData::resetComputedStyle):
+        * dom/Node.cpp:
+        (WebCore::Node::diff):
+        (WebCore::Node::createRendererIfNeeded):
+        (WebCore::Node::styleForRenderer):
+        (WebCore::Node::setRenderStyle):
+        * dom/Node.h:
+        * html/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::setFont):
+        * html/HTMLOptGroupElement.cpp:
+        (WebCore::HTMLOptGroupElement::attach):
+        (WebCore::HTMLOptGroupElement::detach):
+        (WebCore::HTMLOptGroupElement::setRenderStyle):
+        (WebCore::HTMLOptGroupElement::nonRendererRenderStyle):
+        * html/HTMLOptGroupElement.h:
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::attach):
+        (WebCore::HTMLOptionElement::detach):
+        (WebCore::HTMLOptionElement::setRenderStyle):
+        (WebCore::HTMLOptionElement::nonRendererRenderStyle):
+        * html/HTMLOptionElement.h:
+        * page/animation/AnimationBase.h:
+        (WebCore::AnimationBase::animate):
+        * page/animation/AnimationController.cpp:
+        (WebCore::AnimationController::updateAnimations):
+        * page/animation/AnimationController.h:
+        * page/animation/CompositeAnimation.cpp:
+        (WebCore::CompositeAnimationPrivate::updateTransitions):
+        (WebCore::CompositeAnimationPrivate::updateKeyframeAnimations):
+        (WebCore::CompositeAnimationPrivate::animate):
+        (WebCore::CompositeAnimation::animate):
+        * page/animation/CompositeAnimation.h:
+        * page/animation/ImplicitAnimation.cpp:
+        (WebCore::ImplicitAnimation::ImplicitAnimation):
+        (WebCore::ImplicitAnimation::~ImplicitAnimation):
+        (WebCore::ImplicitAnimation::animate):
+        (WebCore::ImplicitAnimation::reset):
+        (WebCore::ImplicitAnimation::isTargetPropertyEqual):
+        (WebCore::ImplicitAnimation::blendPropertyValueInStyle):
+        * page/animation/ImplicitAnimation.h:
+        (WebCore::ImplicitAnimation::create):
+        * page/animation/KeyframeAnimation.cpp:
+        (WebCore::KeyframeAnimation::KeyframeAnimation):
+        (WebCore::KeyframeAnimation::~KeyframeAnimation):
+        (WebCore::KeyframeAnimation::animate):
+        (WebCore::KeyframeAnimation::validateTransformFunctionList):
+        * page/animation/KeyframeAnimation.h:
+        (WebCore::KeyframeAnimation::create):
+        (WebCore::KeyframeAnimation::unanimatedStyle):
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::paint):
+        * rendering/MediaControlElements.cpp:
+        (WebCore::MediaControlShadowRootElement::MediaControlShadowRootElement):
+        (WebCore::MediaControlInputElement::MediaControlInputElement):
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::styleDidChange):
+        (WebCore::RenderBlock::updateFirstLetter):
+        * rendering/RenderContainer.cpp:
+        (WebCore::RenderContainer::addChild):
+        (WebCore::RenderContainer::updateBeforeAfterContentForContainer):
+        * rendering/RenderFileUploadControl.cpp:
+        (WebCore::RenderFileUploadControl::updateFromElement):
+        (WebCore::RenderFileUploadControl::createButtonStyle):
+        * rendering/RenderFileUploadControl.h:
+        * rendering/RenderFlow.cpp:
+        (WebCore::RenderFlow::createAnonymousFlow):
+        * rendering/RenderFlow.h:
+        * rendering/RenderInline.cpp:
+        (WebCore::RenderInline::addChildToFlow):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::updateScrollCornerStyle):
+        (WebCore::RenderLayer::updateResizerStyle):
+        (WebCore::RenderLayer::updateReflectionStyle):
+        * rendering/RenderListItem.cpp:
+        (WebCore::RenderListItem::styleDidChange):
+        * rendering/RenderMedia.cpp:
+        (WebCore::RenderMedia::createPanel):
+        (WebCore::RenderMedia::createTimeDisplay):
+        (WebCore::RenderMedia::changeOpacity):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::selectionBackgroundColor):
+        (WebCore::RenderObject::selectionForegroundColor):
+        (WebCore::RenderObject::createAnonymousBlock):
+        (WebCore::RenderObject::setAnimatableStyle):
+        (WebCore::RenderObject::setStyle):
+        (WebCore::RenderObject::setStyleInternal):
+        (WebCore::RenderObject::arenaDelete):
+        (WebCore::RenderObject::firstLineStyle):
+        (WebCore::RenderObject::getPseudoStyle):
+        * rendering/RenderObject.h:
+        (WebCore::RenderObject::style):
+        * rendering/RenderSVGBlock.cpp:
+        (WebCore::RenderSVGBlock::setStyle):
+        * rendering/RenderSVGBlock.h:
+        * rendering/RenderScrollbar.cpp:
+        (WebCore::RenderScrollbar::getScrollbarPseudoStyle):
+        (WebCore::RenderScrollbar::updateScrollbarPart):
+        * rendering/RenderScrollbar.h:
+        * rendering/RenderSlider.cpp:
+        (WebCore::RenderSlider::styleDidChange):
+        (WebCore::RenderSlider::createThumbStyle):
+        (WebCore::RenderSlider::updateFromElement):
+        * rendering/RenderSlider.h:
+        * rendering/RenderTable.cpp:
+        (WebCore::RenderTable::addChild):
+        * rendering/RenderTableRow.cpp:
+        (WebCore::RenderTableRow::addChild):
+        * rendering/RenderTableSection.cpp:
+        (WebCore::RenderTableSection::addChild):
+        * rendering/RenderTextControl.cpp:
+        (WebCore::RenderTextControl::styleDidChange):
+        (WebCore::RenderTextControl::createInnerBlockStyle):
+        (WebCore::RenderTextControl::createInnerTextStyle):
+        (WebCore::RenderTextControl::createResultsButtonStyle):
+        (WebCore::RenderTextControl::createCancelButtonStyle):
+        (WebCore::RenderTextControl::createSubtreeIfNeeded):
+        (WebCore::RenderTextControl::updatePlaceholderVisibility):
+        * rendering/RenderTextControl.h:
+        * rendering/TextControlInnerElements.cpp:
+        (WebCore::TextControlInnerElement::attachInnerElement):
+        * rendering/TextControlInnerElements.h:
+        * rendering/style/KeyframeList.cpp:
+        (WebCore::KeyframeList::clear):
+        (WebCore::KeyframeList::operator==):
+        (WebCore::KeyframeList::insert):
+        * rendering/style/KeyframeList.h:
+        (WebCore::KeyframeValue::KeyframeValue):
+        (WebCore::KeyframeValue::~KeyframeValue):
+        (WebCore::KeyframeValue::key):
+        (WebCore::KeyframeValue::style):
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::defaultStyle):
+        (WebCore::RenderStyle::create):
+        (WebCore::RenderStyle::createDefaultStyle):
+        (WebCore::RenderStyle::clone):
+        (WebCore::RenderStyle::RenderStyle):
+        (WebCore::RenderStyle::getCachedPseudoStyle):
+        (WebCore::RenderStyle::addCachedPseudoStyle):
+        * rendering/style/RenderStyle.h:
+        (WebCore::):
+        (WebCore::InheritedFlags::operator!=):
+        * svg/SVGClipPathElement.cpp:
+        (WebCore::SVGClipPathElement::canvasResource):
+        * svg/SVGGradientElement.cpp:
+        (WebCore::SVGGradientElement::buildStops):
+        * svg/SVGStyledElement.cpp:
+        (WebCore::SVGStyledElement::resolveStyle):
+        * svg/SVGStyledElement.h:
+        * svg/SVGUseElement.cpp:
+        (WebCore::SVGUseElement::recalcStyle):
+        (WebCore::SVGUseElement::attachShadowTree):
+
 2008-10-16  Kenneth Russell  <kenneth.russell@sun.com>
 
         Reviewed and landed by Anders Carlsson.
index 4c90be2..83c1815 100644 (file)
@@ -62,13 +62,13 @@ public:
     CSSGradientType type() const { return m_type; }
     void setType(CSSGradientType type) { m_type = type; }
     
-    void setFirstX(const PassRefPtr<CSSPrimitiveValue>& val) { m_firstX = val; }
-    void setFirstY(const PassRefPtr<CSSPrimitiveValue>& val) { m_firstY = val; }
-    void setSecondX(const PassRefPtr<CSSPrimitiveValue>& val) { m_secondX = val; }
-    void setSecondY(const PassRefPtr<CSSPrimitiveValue>& val) { m_secondY = val; }
+    void setFirstX(PassRefPtr<CSSPrimitiveValue> val) { m_firstX = val; }
+    void setFirstY(PassRefPtr<CSSPrimitiveValue> val) { m_firstY = val; }
+    void setSecondX(PassRefPtr<CSSPrimitiveValue> val) { m_secondX = val; }
+    void setSecondY(PassRefPtr<CSSPrimitiveValue> val) { m_secondY = val; }
     
-    void setFirstRadius(const PassRefPtr<CSSPrimitiveValue>& val) { m_firstRadius = val; }
-    void setSecondRadius(const PassRefPtr<CSSPrimitiveValue>& val) { m_secondRadius = val; }
+    void setFirstRadius(PassRefPtr<CSSPrimitiveValue> val) { m_firstRadius = val; }
+    void setSecondRadius(PassRefPtr<CSSPrimitiveValue> val) { m_secondRadius = val; }
 
     void addStop(const CSSGradientColorStop& stop) { m_stops.append(stop); }
 
index 6497bff..ef811cb 100644 (file)
@@ -419,7 +419,7 @@ CSSStyleSelector::CSSStyleSelector(Document* doc, const String& userStyleSheet,
 
     if (m_rootDefaultStyle && view) {
         delete m_medium;
-        m_medium = new MediaQueryEvaluator(view->mediaType(), view->frame(), m_rootDefaultStyle);
+        m_medium = new MediaQueryEvaluator(view->mediaType(), view->frame(), m_rootDefaultStyle.get());
     }
 
     // FIXME: This sucks! The user sheet is reparsed every time!
@@ -466,7 +466,6 @@ CSSStyleSelector::~CSSStyleSelector()
 {
     m_fontSelector->clearDocument();
     delete m_medium;
-    ::delete m_rootDefaultStyle;
     delete m_authorStyle;
     delete m_userStyle;
     deleteAllValues(m_viewportDependentMediaQueryResults);
@@ -1006,7 +1005,7 @@ void CSSStyleSelector::matchUARules(int& firstUARule, int& lastUARule)
 // If resolveForRootDefault is true, style based on user agent style sheet only. This is used in media queries, where
 // relative units are interpreted according to document root element style, styled only with UA stylesheet
 
-RenderStyle* CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultParent, bool allowSharing, bool resolveForRootDefault)
+PassRefPtr<RenderStyle> CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultParent, bool allowSharing, bool resolveForRootDefault)
 {
     // Once an element has a renderer, we don't try to destroy it, since otherwise the renderer
     // will vanish if a style recalc happens during loading.
@@ -1024,30 +1023,18 @@ RenderStyle* CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultP
 
     initElementAndPseudoState(e);
     if (allowSharing) {
-        m_style = locateSharedStyle();
-#ifdef STYLE_SHARING_STATS
-        fraction += m_style != 0;
-        total++;
-        printf("Sharing %d out of %d\n", fraction, total);
-#endif
-        if (m_style) {
-            m_style->ref();
-            return m_style;
-        }
+        RenderStyle* sharedStyle = locateSharedStyle();
+        if (sharedStyle)
+            return sharedStyle;
     }
     initForStyleResolve(e, defaultParent);
 
-    if (resolveForRootDefault) {
-        m_style = ::new RenderStyle();
-        // don't ref, because we want to delete this, but we cannot unref it
-    } else {
-        m_style = new (e->document()->renderArena()) RenderStyle();
-        m_style->ref();
-    }
+    m_style = RenderStyle::create();
+
     if (m_parentStyle)
         m_style->inheritFrom(m_parentStyle);
     else
-        m_parentStyle = m_style;
+        m_parentStyle = style();
 
     if (simpleDefaultStyleSheet && !elementCanUseSimpleDefaultStyle(e))
         loadFullDefaultStyle();
@@ -1167,7 +1154,7 @@ RenderStyle* CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultP
         updateFont();
     
     // Clean up our style object's display and text decorations (among other fixups).
-    adjustRenderStyle(m_style, e);
+    adjustRenderStyle(style(), e);
 
     // If we are a link, cache the determined pseudo-state.
     if (e->isLink())
@@ -1178,7 +1165,7 @@ RenderStyle* CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultP
         m_style->setUnique();
 
     // Now return the style.
-    return m_style;
+    return m_style.release();
 }
 
 void CSSStyleSelector::keyframeStylesForAnimation(Element* e, const RenderStyle* elementStyle, KeyframeList& list)
@@ -1206,8 +1193,7 @@ void CSSStyleSelector::keyframeStylesForAnimation(Element* e, const RenderStyle*
         ASSERT(!m_style);
 
         // Create the style
-        m_style = new (e->document()->renderArena()) RenderStyle(*elementStyle);
-        m_style->ref();
+        m_style = RenderStyle::clone(elementStyle);
         
         m_lineHeightValue = 0;
         
@@ -1243,18 +1229,17 @@ void CSSStyleSelector::keyframeStylesForAnimation(Element* e, const RenderStyle*
             float key = keys[keyIndex];
             list.insert(key, m_style);
         }
-        m_style->deref(e->document()->renderArena());
         m_style = 0;
     }
     
     // Make sure there is a 0% and a 100% keyframe
-    float first = list.beginKeyframes()->key;
-    float last = (list.endKeyframes()-1)->key;
+    float first = list.beginKeyframes()->key();
+    float last = (list.endKeyframes()-1)->key();
     if (first != 0 || last != 1)
         list.clear();
 }
 
-RenderStyle* CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseudo, Element* e, RenderStyle* parentStyle)
+PassRefPtr<RenderStyle> CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseudo, Element* e, RenderStyle* parentStyle)
 {
     if (!e)
         return 0;
@@ -1278,8 +1263,7 @@ RenderStyle* CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseud
     if (m_matchedDecls.isEmpty())
         return 0;
     
-    m_style = new (e->document()->renderArena()) RenderStyle();
-    m_style->ref();
+    m_style = RenderStyle::create();
     if (parentStyle)
         m_style->inheritFrom(parentStyle);
 
@@ -1316,10 +1300,10 @@ RenderStyle* CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseud
     if (m_fontDirty)
         updateFont();
     // Clean up our style object's display and text decorations (among other fixups).
-    adjustRenderStyle(m_style, 0);
+    adjustRenderStyle(style(), 0);
 
     // Now return the style.
-    return m_style;
+    return m_style.release();
 }
 
 static void addIntrinsicMargins(RenderStyle* style)
@@ -1517,8 +1501,8 @@ void CSSStyleSelector::adjustRenderStyle(RenderStyle* style, Element *e)
 void CSSStyleSelector::updateFont()
 {
     checkForTextSizeAdjust();
-    checkForGenericFamilyChange(m_style, m_parentStyle);
-    checkForZoomChange(m_style, m_parentStyle);
+    checkForGenericFamilyChange(style(), m_parentStyle);
+    checkForZoomChange(style(), m_parentStyle);
     m_style->font().update(m_fontSelector);
     m_fontDirty = false;
 }
@@ -1577,7 +1561,7 @@ bool CSSStyleSelector::checkSelector(CSSSelector* sel)
     m_dynamicPseudo = RenderStyle::NOPSEUDO;
 
     // Check the selector
-    SelectorMatch match = m_checker.checkSelector(sel, m_element, &m_selectorAttrs, m_dynamicPseudo, true, false, m_style, m_parentStyle);
+    SelectorMatch match = m_checker.checkSelector(sel, m_element, &m_selectorAttrs, m_dynamicPseudo, true, false, style(), m_parentStyle);
     if (match != SelectorMatches)
         return false;
 
@@ -3122,7 +3106,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
         HANDLE_INHERIT_AND_INITIAL(horizontalBorderSpacing, HorizontalBorderSpacing)
         if (!primitiveValue)
             return;
-        short spacing =  primitiveValue->computeLengthShort(m_style, zoomFactor);
+        short spacing =  primitiveValue->computeLengthShort(style(), zoomFactor);
         m_style->setHorizontalBorderSpacing(spacing);
         return;
     }
@@ -3130,7 +3114,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
         HANDLE_INHERIT_AND_INITIAL(verticalBorderSpacing, VerticalBorderSpacing)
         if (!primitiveValue)
             return;
-        short spacing =  primitiveValue->computeLengthShort(m_style, zoomFactor);
+        short spacing =  primitiveValue->computeLengthShort(style(), zoomFactor);
         m_style->setVerticalBorderSpacing(spacing);
         return;
     }
@@ -3305,7 +3289,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             width = 5;
             break;
         case CSSValueInvalid:
-            width = primitiveValue->computeLengthShort(m_style, zoomFactor);
+            width = primitiveValue->computeLengthShort(style(), zoomFactor);
             break;
         default:
             return;
@@ -3358,7 +3342,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
         } else {
             if (!primitiveValue)
                 return;
-            width = primitiveValue->computeLengthInt(m_style, zoomFactor);
+            width = primitiveValue->computeLengthInt(style(), zoomFactor);
         }
         switch (id) {
         case CSSPropertyLetterSpacing:
@@ -3502,7 +3486,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             int type = primitiveValue->primitiveType();
             if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
                 // Handle our quirky margin units if we have them.
-                l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed, 
+                l = Length(primitiveValue->computeLengthIntForLength(style(), zoomFactor), Fixed, 
                            primitiveValue->isQuirkValue());
             else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
                 l = Length(primitiveValue->getDoubleValue(), Percent);
@@ -3602,7 +3586,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
         if (primitiveValue && !apply) {
             unsigned short type = primitiveValue->primitiveType();
             if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
-                l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
+                l = Length(primitiveValue->computeLengthIntForLength(style(), zoomFactor), Fixed);
             else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
                 l = Length(primitiveValue->getDoubleValue(), Percent);
             else
@@ -3658,7 +3642,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
           int type = primitiveValue->primitiveType();
           Length l;
           if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
-            l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
+            l = Length(primitiveValue->computeLengthIntForLength(style(), zoomFactor), Fixed);
           else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
             l = Length(primitiveValue->getDoubleValue(), Percent);
 
@@ -3788,7 +3772,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             double multiplier = m_style->effectiveZoom();
             if (m_style->textSizeAdjust() && m_checker.m_document->frame() && m_checker.m_document->frame()->shouldApplyTextZoom())
                 multiplier *= m_checker.m_document->frame()->textZoomFactor();
-            lineHeight = Length(primitiveValue->computeLengthIntForLength(m_style, multiplier), Fixed);
+            lineHeight = Length(primitiveValue->computeLengthIntForLength(style(), multiplier), Fixed);
         } else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
             lineHeight = Length((m_style->fontSize() * primitiveValue->getIntValue()) / 100, Fixed);
         else if (type == CSSPrimitiveValue::CSS_NUMBER)
@@ -3843,10 +3827,10 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             Rect* rect = primitiveValue->getRectValue();
             if (!rect)
                 return;
-            top = convertToLength(rect->top(), m_style);
-            right = convertToLength(rect->right(), m_style);
-            bottom = convertToLength(rect->bottom(), m_style);
-            left = convertToLength(rect->left(), m_style);
+            top = convertToLength(rect->top(), style());
+            right = convertToLength(rect->right(), style());
+            bottom = convertToLength(rect->bottom(), style());
+            left = convertToLength(rect->left(), style());
 
         } else if (primitiveValue->getIdent() != CSSValueAuto) {
             return;
@@ -3927,10 +3911,10 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
     }
 
     case CSSPropertyCounterIncrement:
-        applyCounterList(m_style, value->isValueList() ? static_cast<CSSValueList*>(value) : 0, false);
+        applyCounterList(style(), value->isValueList() ? static_cast<CSSValueList*>(value) : 0, false);
         return;
     case CSSPropertyCounterReset:
-        applyCounterList(m_style, value->isValueList() ? static_cast<CSSValueList*>(value) : 0, true);
+        applyCounterList(style(), value->isValueList() ? static_cast<CSSValueList*>(value) : 0, true);
         return;
 
     case CSSPropertyFontFamily: {
@@ -4398,8 +4382,8 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
         if (!pair)
             return;
 
-        int width = pair->first()->computeLengthInt(m_style, zoomFactor);
-        int height = pair->second()->computeLengthInt(m_style, zoomFactor);
+        int width = pair->first()->computeLengthInt(style(), zoomFactor);
+        int height = pair->second()->computeLengthInt(style(), zoomFactor);
         if (width < 0 || height < 0)
             return;
 
@@ -4431,7 +4415,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
 
     case CSSPropertyOutlineOffset:
         HANDLE_INHERIT_AND_INITIAL(outlineOffset, OutlineOffset)
-        m_style->setOutlineOffset(primitiveValue->computeLengthInt(m_style, zoomFactor));
+        m_style->setOutlineOffset(primitiveValue->computeLengthInt(style(), zoomFactor));
         return;
 
     case CSSPropertyTextShadow:
@@ -4451,9 +4435,9 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
         int len = list->length();
         for (int i = 0; i < len; i++) {
             ShadowValue* item = static_cast<ShadowValue*>(list->itemWithoutBoundsCheck(i));
-            int x = item->x->computeLengthInt(m_style, zoomFactor);
-            int y = item->y->computeLengthInt(m_style, zoomFactor);
-            int blur = item->blur ? item->blur->computeLengthInt(m_style, zoomFactor) : 0;
+            int x = item->x->computeLengthInt(style(), zoomFactor);
+            int y = item->y->computeLengthInt(style(), zoomFactor);
+            int blur = item->blur ? item->blur->computeLengthInt(style(), zoomFactor) : 0;
             Color color;
             if (item->color)
                 color = getColorFromPrimitiveValue(item->color.get());
@@ -4479,7 +4463,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
                 reflection->setOffset(Length(reflectValue->offset()->getDoubleValue(), Percent));
             else
-                reflection->setOffset(Length(reflectValue->offset()->computeLengthIntForLength(m_style, zoomFactor), Fixed));
+                reflection->setOffset(Length(reflectValue->offset()->computeLengthIntForLength(style(), zoomFactor), Fixed));
         }
         NinePieceImage mask;
         mapNinePieceImage(reflectValue->mask(), mask);
@@ -4586,7 +4570,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             m_style->setHasNormalColumnGap();
             return;
         }
-        m_style->setColumnGap(primitiveValue->computeLengthFloat(m_style, zoomFactor));
+        m_style->setColumnGap(primitiveValue->computeLengthFloat(style(), zoomFactor));
         return;
     }
     case CSSPropertyWebkitColumnWidth: {
@@ -4600,7 +4584,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             m_style->setHasAutoColumnWidth();
             return;
         }
-        m_style->setColumnWidth(primitiveValue->computeLengthFloat(m_style, zoomFactor));
+        m_style->setColumnWidth(primitiveValue->computeLengthFloat(style(), zoomFactor));
         return;
     }
     case CSSPropertyWebkitColumnRuleStyle:
@@ -4707,7 +4691,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
         }
         else {
             bool ok = true;
-            Length l = convertToLength(primitiveValue, m_style, &ok);
+            Length l = convertToLength(primitiveValue, style(), &ok);
             if (ok)
                 m_style->setMarqueeIncrement(l);
         }
@@ -4830,10 +4814,10 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             
         DashboardRegion *first = region;
         while (region) {
-            Length top = convertToLength (region->top(), m_style);
-            Length right = convertToLength (region->right(), m_style);
-            Length bottom = convertToLength (region->bottom(), m_style);
-            Length left = convertToLength (region->left(), m_style);
+            Length top = convertToLength(region->top(), style());
+            Length right = convertToLength(region->right(), style());
+            Length bottom = convertToLength(region->bottom(), style());
+            Length left = convertToLength(region->left(), style());
             if (region->m_isCircle)
                 m_style->setDashboardRegion(StyleDashboardRegion::Circle, region->m_label, top, right, bottom, left, region == first ? false : true);
             else if (region->m_isRectangle)
@@ -4864,11 +4848,11 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
                     result *= 3;
                 else if (primitiveValue->getIdent() == CSSValueThick)
                     result *= 5;
-                width = CSSPrimitiveValue::create(result, CSSPrimitiveValue::CSS_EMS)->computeLengthFloat(m_style, zoomFactor);
+                width = CSSPrimitiveValue::create(result, CSSPrimitiveValue::CSS_EMS)->computeLengthFloat(style(), zoomFactor);
                 break;
             }
             default:
-                width = primitiveValue->computeLengthFloat(m_style, zoomFactor);
+                width = primitiveValue->computeLengthFloat(style(), zoomFactor);
                 break;
         }
         m_style->setTextStrokeWidth(width);
@@ -4877,7 +4861,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
     case CSSPropertyWebkitTransform: {
         HANDLE_INHERIT_AND_INITIAL(transform, Transform);
         TransformOperations operations;
-        createTransformOperations(value, m_style, operations);
+        createTransformOperations(value, style(), operations);
         m_style->setTransform(operations);
         return;
     }
@@ -4891,7 +4875,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
         Length l;
         int type = primitiveValue->primitiveType();
         if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
-            l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
+            l = Length(primitiveValue->computeLengthIntForLength(style(), zoomFactor), Fixed);
         else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
             l = Length(primitiveValue->getDoubleValue(), Percent);
         else
@@ -4905,7 +4889,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
         Length l;
         int type = primitiveValue->primitiveType();
         if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
-            l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
+            l = Length(primitiveValue->computeLengthIntForLength(style(), zoomFactor), Fixed);
         else if(type == CSSPrimitiveValue::CSS_PERCENTAGE)
             l = Length(primitiveValue->getDoubleValue(), Percent);
         else
@@ -5130,7 +5114,7 @@ void CSSStyleSelector::mapFillSize(FillLayer* layer, CSSValue* value)
     if (firstType == CSSPrimitiveValue::CSS_UNKNOWN)
         firstLength = Length(Auto);
     else if (firstType > CSSPrimitiveValue::CSS_PERCENTAGE && firstType < CSSPrimitiveValue::CSS_DEG)
-        firstLength = Length(first->computeLengthIntForLength(m_style, zoomFactor), Fixed);
+        firstLength = Length(first->computeLengthIntForLength(style(), zoomFactor), Fixed);
     else if (firstType == CSSPrimitiveValue::CSS_PERCENTAGE)
         firstLength = Length(first->getDoubleValue(), Percent);
     else
@@ -5139,7 +5123,7 @@ void CSSStyleSelector::mapFillSize(FillLayer* layer, CSSValue* value)
     if (secondType == CSSPrimitiveValue::CSS_UNKNOWN)
         secondLength = Length(Auto);
     else if (secondType > CSSPrimitiveValue::CSS_PERCENTAGE && secondType < CSSPrimitiveValue::CSS_DEG)
-        secondLength = Length(second->computeLengthIntForLength(m_style, zoomFactor), Fixed);
+        secondLength = Length(second->computeLengthIntForLength(style(), zoomFactor), Fixed);
     else if (secondType == CSSPrimitiveValue::CSS_PERCENTAGE)
         secondLength = Length(second->getDoubleValue(), Percent);
     else
@@ -5166,7 +5150,7 @@ void CSSStyleSelector::mapFillXPosition(FillLayer* layer, CSSValue* value)
     Length l;
     int type = primitiveValue->primitiveType();
     if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
-        l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
+        l = Length(primitiveValue->computeLengthIntForLength(style(), zoomFactor), Fixed);
     else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
         l = Length(primitiveValue->getDoubleValue(), Percent);
     else
@@ -5190,7 +5174,7 @@ void CSSStyleSelector::mapFillYPosition(FillLayer* layer, CSSValue* value)
     Length l;
     int type = primitiveValue->primitiveType();
     if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
-        l = Length(primitiveValue->computeLengthIntForLength(m_style, zoomFactor), Fixed);
+        l = Length(primitiveValue->computeLengthIntForLength(style(), zoomFactor), Fixed);
     else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
         l = Length(primitiveValue->getDoubleValue(), Percent);
     else
index 05bc264..388dc9f 100644 (file)
@@ -83,16 +83,18 @@ public:
 
         void initElementAndPseudoState(Element*);
         void initForStyleResolve(Element*, RenderStyle* parentStyle = 0, RenderStyle::PseudoId = RenderStyle::NOPSEUDO);
-        RenderStyle* styleForElement(Element*, RenderStyle* parentStyle = 0, bool allowSharing = true, bool resolveForRootDefault = false);
+        PassRefPtr<RenderStyle> styleForElement(Element*, RenderStyle* parentStyle = 0, bool allowSharing = true, bool resolveForRootDefault = false);
         void keyframeStylesForAnimation(Element*, const RenderStyle*, KeyframeList& list);
 
-        RenderStyle* pseudoStyleForElement(RenderStyle::PseudoId, Element*, RenderStyle* parentStyle = 0);
+        PassRefPtr<RenderStyle> pseudoStyleForElement(RenderStyle::PseudoId, Element*, RenderStyle* parentStyle = 0);
 
     private:
         RenderStyle* locateSharedStyle();
         Node* locateCousinList(Element* parent, unsigned depth = 1);
         bool canShareStyleWithElement(Node*);
 
+        RenderStyle* style() const { return m_style.get(); }
+
     public:
         // These methods will give back the set of rules that matched for a given element (or a pseudo-element).
         PassRefPtr<CSSRuleList> styleRulesForElement(Element*, bool authorOnly);
@@ -111,7 +113,7 @@ public:
         float smallerFontSize(float size, bool quirksMode) const;
 
     public:
-        void setStyle(RenderStyle* s) { m_style = s; } // Used by the document when setting up its root style.
+        void setStyle(PassRefPtr<RenderStyle> s) { m_style = s; } // Used by the document when setting up its root style.
         void setFontSize(FontDescription&, float size);
 
         void applyPropertyToStyle(int id, CSSValue*, RenderStyle*);
@@ -249,13 +251,13 @@ public:
         RefPtr<CSSRuleList> m_ruleList;
 
         MediaQueryEvaluator* m_medium;
-        RenderStyle* m_rootDefaultStyle;
+        RefPtr<RenderStyle> m_rootDefaultStyle;
 
         RenderStyle::PseudoId m_dynamicPseudo;
 
         SelectorChecker m_checker;
 
-        RenderStyle* m_style;
+        RefPtr<RenderStyle> m_style;
         RenderStyle* m_parentStyle;
         Element* m_element;
         StyledElement* m_styledElement;
index 42d6022..2eadc1c 100644 (file)
@@ -30,7 +30,7 @@
 
 namespace WebCore {
 
-CSSVariableDependentValue::CSSVariableDependentValue(const PassRefPtr<CSSValueList>& list)
+CSSVariableDependentValue::CSSVariableDependentValue(PassRefPtr<CSSValueList> list)
 : m_list(list)
 {
 }
index c095f8c..e8dce2e 100644 (file)
@@ -34,7 +34,7 @@ class CSSValueList;
 
 class CSSVariableDependentValue : public CSSValue {
 public:
-    static PassRefPtr<CSSVariableDependentValue> create(const PassRefPtr<CSSValueList>& valueList)
+    static PassRefPtr<CSSVariableDependentValue> create(PassRefPtr<CSSValueList> valueList)
     {
         return adoptRef(new CSSVariableDependentValue(valueList));
     }
@@ -47,7 +47,7 @@ public:
     CSSValueList* valueList() const { return m_list.get(); }
 
 private:
-    CSSVariableDependentValue(const PassRefPtr<CSSValueList>&);
+    CSSVariableDependentValue(PassRefPtr<CSSValueList>);
     
     RefPtr<CSSValueList> m_list;
 };
index 054e2ce..0420204 100644 (file)
@@ -1129,22 +1129,18 @@ void Document::recalcStyle(StyleChange change)
         // style selector may set this again during recalc
         m_hasNodesWithPlaceholderStyle = false;
         
-        RenderStyle* oldStyle = renderer()->style();
-        if (oldStyle)
-            oldStyle->ref();
-        RenderStyle* _style = new (m_renderArena) RenderStyle();
-        _style->ref();
-        _style->setDisplay(BLOCK);
-        _style->setVisuallyOrdered(visuallyOrdered);
-        _style->setZoom(frame()->pageZoomFactor());
-        m_styleSelector->setStyle(_style);
+        RefPtr<RenderStyle> documentStyle = RenderStyle::create();
+        documentStyle->setDisplay(BLOCK);
+        documentStyle->setVisuallyOrdered(visuallyOrdered);
+        documentStyle->setZoom(frame()->pageZoomFactor());
+        m_styleSelector->setStyle(documentStyle);
     
         FontDescription fontDescription;
         fontDescription.setUsePrinterFont(printing());
         if (Settings* settings = this->settings()) {
             fontDescription.setRenderingMode(settings->fontRenderingMode());
             if (printing() && !settings->shouldPrintBackgrounds())
-                _style->setForceBackgroundsToWhite(true);
+                documentStyle->setForceBackgroundsToWhite(true);
             const AtomicString& stdfont = settings->standardFontFamily();
             if (!stdfont.isEmpty()) {
                 fontDescription.firstFamily().setFamily(stdfont);
@@ -1154,20 +1150,16 @@ void Document::recalcStyle(StyleChange change)
             m_styleSelector->setFontSize(fontDescription, m_styleSelector->fontSizeForKeyword(CSSValueMedium, inCompatMode(), false));
         }
 
-        _style->setFontDescription(fontDescription);
-        _style->font().update(m_styleSelector->fontSelector());
+        documentStyle->setFontDescription(fontDescription);
+        documentStyle->font().update(m_styleSelector->fontSelector());
         if (inCompatMode())
-            _style->setHtmlHacks(true); // enable html specific rendering tricks
+            documentStyle->setHtmlHacks(true); // enable html specific rendering tricks
 
-        StyleChange ch = diff(_style, oldStyle);
+        StyleChange ch = diff(documentStyle.get(), renderer()->style());
         if (renderer() && ch != NoChange)
-            renderer()->setStyle(_style);
+            renderer()->setStyle(documentStyle.release());
         if (change != Force)
             change = ch;
-
-        _style->deref(m_renderArena);
-        if (oldStyle)
-            oldStyle->deref(m_renderArena);
     }
 
     for (Node* n = firstChild(); n; n = n->nextSibling())
index 98657a9..76435ce 100644 (file)
@@ -609,7 +609,7 @@ const QualifiedName& Element::imageSourceAttributeName() const
     return srcAttr;
 }
 
-RenderStyle* Element::styleForRenderer(RenderObject* parentRenderer)
+PassRefPtr<RenderStyle> Element::styleForRenderer(RenderObject* parentRenderer)
 {
     return document()->styleSelector()->styleForElement(this);
 }
@@ -694,17 +694,15 @@ void Element::recalcStyle(StyleChange change)
             rareData()->resetComputedStyle(this);
     }
     if (hasParentStyle && (change >= Inherit || changed())) {
-        RenderStyle *newStyle = document()->styleSelector()->styleForElement(this);
-        StyleChange ch = diff(currentStyle, newStyle);
+        RefPtr<RenderStyle> newStyle = document()->styleSelector()->styleForElement(this);
+        StyleChange ch = diff(currentStyle, newStyle.get());
         if (ch == Detach || !currentStyle) {
             if (attached())
                 detach();
-            // ### Suboptimal. Style gets calculated again.
-            attach();
+            attach(); // FIXME: The style gets computed twice by calling attach. We could do better if we passed the style along.
             // attach recalulates the style for all children. No need to do it twice.
             setChanged(NoStyleChange);
             setHasChangedChild(false);
-            newStyle->deref(document()->renderArena());
             return;
         }
 
@@ -737,14 +735,12 @@ void Element::recalcStyle(StyleChange change)
             // sibling/descendant rules, since otherwise it isn't possible for ancestor styles to affect sharing of
             // descendants.
             if (renderer())
-                renderer()->setStyleInternal(newStyle);
+                renderer()->setStyleInternal(newStyle.get());
             else
                 setRenderStyle(newStyle);
         } else if (styleChangeType() == AnimationStyleChange)
              setRenderStyle(newStyle);
 
-        newStyle->deref(document()->renderArena());
-
         if (change != Force) {
             if ((document()->usesDescendantRules() || hasPositionalRules) && styleChangeType() >= FullStyleChange)
                 change = Force;
@@ -1188,7 +1184,7 @@ RenderStyle* Element::computedStyle()
     ElementRareData* data = ensureRareData();
     if (!data->m_computedStyle)
         data->m_computedStyle = document()->styleSelector()->styleForElement(this, parent() ? parent()->computedStyle() : 0);
-    return data->m_computedStyle;
+    return data->m_computedStyle.get();
 }
 
 void Element::cancelFocusAppearanceUpdate()
index dd646c9..dc8eac6 100644 (file)
@@ -140,7 +140,7 @@ public:
 
     virtual void attach();
     virtual void detach();
-    RenderStyle* styleForRenderer(RenderObject* parent);
+    PassRefPtr<RenderStyle> styleForRenderer(RenderObject* parent);
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
     virtual void recalcStyle(StyleChange = NoChange);
 
index fdc0070..8250757 100644 (file)
@@ -34,7 +34,7 @@ public:
     void resetComputedStyle(Element*);
 
     IntSize m_minimumSizeForResizing;
-    RenderStyle* m_computedStyle;
+    RefPtr<RenderStyle> m_computedStyle;
 };
 
 inline IntSize defaultMinimumSizeForResizing()
@@ -44,16 +44,12 @@ inline IntSize defaultMinimumSizeForResizing()
 
 inline ElementRareData::ElementRareData(Element* e)
     : m_minimumSizeForResizing(defaultMinimumSizeForResizing())
-    , m_computedStyle(0)
 {
 }
 
 inline void ElementRareData::resetComputedStyle(Element* element)
 {
-    if (!m_computedStyle)
-        return;
-    m_computedStyle->deref(element->document()->renderArena());
-    m_computedStyle = 0;
+    m_computedStyle.clear();
 }
 
 }
index fca4863..391fadf 100644 (file)
@@ -114,20 +114,20 @@ Node::StyleChange Node::diff( RenderStyle *s1, RenderStyle *s2 )
     // If the pseudoStyles have changed, we want any StyleChange that is not NoChange
     // because setStyle will do the right thing with anything else.
     if (ch == NoChange && s1->hasPseudoStyle(RenderStyle::BEFORE)) {
-        RenderStyle* ps2 = s2->getPseudoStyle(RenderStyle::BEFORE);
+        RenderStyle* ps2 = s2->getCachedPseudoStyle(RenderStyle::BEFORE);
         if (!ps2)
             ch = NoInherit;
         else {
-            RenderStyle* ps1 = s1->getPseudoStyle(RenderStyle::BEFORE);
+            RenderStyle* ps1 = s1->getCachedPseudoStyle(RenderStyle::BEFORE);
             ch = ps1 && *ps1 == *ps2 ? NoChange : NoInherit;
         }
     }
     if (ch == NoChange && s1->hasPseudoStyle(RenderStyle::AFTER)) {
-        RenderStyle* ps2 = s2->getPseudoStyle(RenderStyle::AFTER);
+        RenderStyle* ps2 = s2->getCachedPseudoStyle(RenderStyle::AFTER);
         if (!ps2)
             ch = NoInherit;
         else {
-            RenderStyle* ps1 = s1->getPseudoStyle(RenderStyle::AFTER);
+            RenderStyle* ps1 = s1->getCachedPseudoStyle(RenderStyle::AFTER);
             ch = ps2 && *ps1 == *ps2 ? NoChange : NoInherit;
         }
     }
@@ -1027,10 +1027,10 @@ void Node::createRendererIfNeeded()
         && parent->childShouldCreateRenderer(this)
 #endif
         ) {
-        RenderStyle* style = styleForRenderer(parentRenderer);
-        if (rendererIsNeeded(style)) {
-            if (RenderObject* r = createRenderer(document()->renderArena(), style)) {
-                if (!parentRenderer->isChildAllowed(r, style))
+        RefPtr<RenderStyle> style = styleForRenderer(parentRenderer);
+        if (rendererIsNeeded(style.get())) {
+            if (RenderObject* r = createRenderer(document()->renderArena(), style.get())) {
+                if (!parentRenderer->isChildAllowed(r, style.get()))
                     r->destroy();
                 else {
                     setRenderer(r);
@@ -1039,17 +1039,14 @@ void Node::createRendererIfNeeded()
                 }
             }
         }
-        style->deref(document()->renderArena());
     }
 }
 
-RenderStyle* Node::styleForRenderer(RenderObject* parent)
+PassRefPtr<RenderStyle> Node::styleForRenderer(RenderObject* parent)
 {
     if (isElementNode())
         return document()->styleSelector()->styleForElement(static_cast<Element*>(this));
-    RenderStyle* style = parent->style();
-    style->ref();
-    return style;
+    return parent->style();
 }
 
 bool Node::rendererIsNeeded(RenderStyle *style)
@@ -1068,7 +1065,7 @@ RenderStyle* Node::nonRendererRenderStyle() const
     return 0; 
 }   
 
-void Node::setRenderStyle(RenderStyle* s)
+void Node::setRenderStyle(PassRefPtr<RenderStyle> s)
 {
     if (m_renderer)
         m_renderer->setAnimatableStyle(s); 
index 23ca9ef..a1edb8e 100644 (file)
@@ -408,7 +408,7 @@ public:
 
     virtual void willRemove();
     void createRendererIfNeeded();
-    RenderStyle* styleForRenderer(RenderObject* parent);
+    PassRefPtr<RenderStyle> styleForRenderer(RenderObject* parent);
     virtual bool rendererIsNeeded(RenderStyle*);
 #if ENABLE(SVG)
     virtual bool childShouldCreateRenderer(Node*) const { return true; }
@@ -417,7 +417,7 @@ public:
     
     // Wrapper for nodes that don't have a renderer, but still cache the style (like HTMLOptionElement).
     RenderStyle* renderStyle() const;
-    virtual void setRenderStyle(RenderStyle*);
+    virtual void setRenderStyle(PassRefPtr<RenderStyle>);
 
     virtual RenderStyle* computedStyle();
 
index 4f1e669..43fc7e0 100644 (file)
@@ -1181,21 +1181,17 @@ void CanvasRenderingContext2D::setFont(const String& newFont)
     
     // Map the <canvas> font into the text style. If the font uses keywords like larger/smaller, these will work
     // relative to the canvas.
-    RenderArena* arena = m_canvas->document()->renderArena();
-    RenderStyle* newStyle = new (arena) RenderStyle();
-    newStyle->ref();
+    RefPtr<RenderStyle> newStyle = RenderStyle::create();
     if (m_canvas->computedStyle())
         newStyle->setFontDescription(m_canvas->computedStyle()->fontDescription());
 
     // Now map the font property into the style.
     CSSStyleSelector* styleSelector = m_canvas->document()->styleSelector();
-    styleSelector->applyPropertyToStyle(CSSPropertyFont, tempDecl->getPropertyCSSValue(CSSPropertyFont).get(), newStyle);
+    styleSelector->applyPropertyToStyle(CSSPropertyFont, tempDecl->getPropertyCSSValue(CSSPropertyFont).get(), newStyle.get());
     
     state().m_font = newStyle->font();
     state().m_font.update(styleSelector->fontSelector());
     state().m_realizedFont = true;
-
-    newStyle->deref(arena);
     
     // Set the font in the graphics context.
     GraphicsContext* c = drawingContext();
index d6e4c02..f270a31 100644 (file)
@@ -132,36 +132,25 @@ bool HTMLOptGroupElement::checkDTD(const Node* newChild)
 
 void HTMLOptGroupElement::attach()
 {
-    if (parentNode()->renderStyle()) {
-        RenderStyle* style = styleForRenderer(0);
-        setRenderStyle(style);
-        style->deref(document()->renderArena());
-    }
+    if (parentNode()->renderStyle())
+        setRenderStyle(styleForRenderer(0));
     HTMLFormControlElement::attach();
 }
 
 void HTMLOptGroupElement::detach()
 {
-    if (m_style) {
-        m_style->deref(document()->renderArena());
-        m_style = 0;
-    }
+    m_style.clear();
     HTMLFormControlElement::detach();
 }
 
-void HTMLOptGroupElement::setRenderStyle(RenderStyle* newStyle)
+void HTMLOptGroupElement::setRenderStyle(PassRefPtr<RenderStyle> newStyle)
 {
-    RenderStyle* oldStyle = m_style;
     m_style = newStyle;
-    if (newStyle)
-        newStyle->ref();
-    if (oldStyle)
-        oldStyle->deref(document()->renderArena());
 }
     
 RenderStyle* HTMLOptGroupElement::nonRendererRenderStyle() const 
 { 
-    return m_style; 
+    return m_style.get()
 }
 
 String HTMLOptGroupElement::groupLabelText() const
index 3e46e4a..85e789b 100644 (file)
@@ -41,7 +41,7 @@ public:
     virtual bool rendererIsNeeded(RenderStyle*) { return false; }
     virtual void attach();
     virtual void detach();
-    virtual void setRenderStyle(RenderStyle*);
+    virtual void setRenderStyle(PassRefPtr<RenderStyle>);
 
     virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false);
     virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false);
@@ -62,7 +62,7 @@ private:
     
     void recalcSelectOptions();
 
-    RenderStyle* m_style;
+    RefPtr<RenderStyle> m_style;
 };
 
 } //namespace
index 93a9bd7..ccbb6b2 100644 (file)
@@ -57,20 +57,14 @@ bool HTMLOptionElement::checkDTD(const Node* newChild)
 
 void HTMLOptionElement::attach()
 {
-    if (parentNode()->renderStyle()) {
-        RenderStyle* style = styleForRenderer(0);
-        setRenderStyle(style);
-        style->deref(document()->renderArena());
-    }
+    if (parentNode()->renderStyle())
+        setRenderStyle(styleForRenderer(0));
     HTMLFormControlElement::attach();
 }
 
 void HTMLOptionElement::detach()
 {
-    if (m_style) {
-        m_style->deref(document()->renderArena());
-        m_style = 0;
-    }
+    m_style.clear();
     HTMLFormControlElement::detach();
 }
 
@@ -235,19 +229,14 @@ void HTMLOptionElement::setLabel(const String& value)
     setAttribute(labelAttr, value);
 }
 
-void HTMLOptionElement::setRenderStyle(RenderStyle* newStyle)
+void HTMLOptionElement::setRenderStyle(PassRefPtr<RenderStyle> newStyle)
 {
-    RenderStyle* oldStyle = m_style;
     m_style = newStyle;
-    if (newStyle)
-        newStyle->ref();
-    if (oldStyle)
-        oldStyle->deref(document()->renderArena());
 }
 
 RenderStyle* HTMLOptionElement::nonRendererRenderStyle() const 
 { 
-    return m_style; 
+    return m_style.get()
 }
 
 String HTMLOptionElement::optionText()
index c9e93ca..58426eb 100644 (file)
@@ -47,7 +47,7 @@ public:
     virtual bool rendererIsNeeded(RenderStyle*) { return false; }
     virtual void attach();
     virtual void detach();
-    virtual void setRenderStyle(RenderStyle*);
+    virtual void setRenderStyle(PassRefPtr<RenderStyle>);
     
     virtual const AtomicString& type() const;
 
@@ -86,7 +86,7 @@ private:
     
     String m_value;
     bool m_selected;
-    RenderStyle* m_style;
+    RefPtr<RenderStyle> m_style;
 };
 
 } //namespace
index 0a22218..925c0d5 100644 (file)
@@ -181,7 +181,7 @@ public:
     double progress(double scale, double offset, const TimingFunction*) const;
 
     virtual void animate(CompositeAnimation*, RenderObject*, const RenderStyle* currentStyle, 
-                         const RenderStyle* targetStyle, RenderStyle*& animatedStyle) { }
+                         const RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle) { }
 
     virtual bool shouldFireEvents() const { return false; }
 
index ddb0449..d449afe 100644 (file)
@@ -223,7 +223,7 @@ void AnimationController::cancelAnimations(RenderObject* renderer)
     }
 }
 
-RenderStyle* AnimationController::updateAnimations(RenderObject* renderer, RenderStyle* newStyle)
+PassRefPtr<RenderStyle> AnimationController::updateAnimations(RenderObject* renderer, RenderStyle* newStyle)
 {    
     // Don't do anything if we're in the cache
     if (!renderer->document() || renderer->document()->inPageCache())
@@ -234,8 +234,6 @@ RenderStyle* AnimationController::updateAnimations(RenderObject* renderer, Rende
     if ((!oldStyle || (!oldStyle->animations() && !oldStyle->transitions())) && (!newStyle->animations() && !newStyle->transitions()))
         return newStyle;
 
-    RenderStyle* blendedStyle = newStyle;
-    
     // Fetch our current set of implicit animations from a hashtable.  We then compare them
     // against the animations in the style and make sure we're in sync.  If destination values
     // have changed, we reset the animation.  We then do a blend to get new values and we return
@@ -243,7 +241,7 @@ RenderStyle* AnimationController::updateAnimations(RenderObject* renderer, Rende
     ASSERT(renderer->element()); // FIXME: We do not animate generated content yet.
 
     CompositeAnimation* rendererAnimations = m_data->accessCompositeAnimation(renderer);
-    blendedStyle = rendererAnimations->animate(renderer, oldStyle, newStyle);
+    RefPtr<RenderStyle> blendedStyle = rendererAnimations->animate(renderer, oldStyle, newStyle);
 
     m_data->updateAnimationTimer();
 
@@ -254,7 +252,7 @@ RenderStyle* AnimationController::updateAnimations(RenderObject* renderer, Rende
         if (blendedStyle->hasAutoZIndex() && (blendedStyle->opacity() < 1.0f || blendedStyle->hasTransform()))
             blendedStyle->setZIndex(0);
     }
-    return blendedStyle;
+    return blendedStyle.release();
 }
 
 void AnimationController::setAnimationStartTime(RenderObject* renderer, double t)
index 8ea19dc..bc13a2a 100644 (file)
@@ -29,6 +29,8 @@
 #ifndef AnimationController_h
 #define AnimationController_h
 
+#include <wtf/Forward.h>
+
 namespace WebCore {
 
 class AnimationControllerPrivate;
@@ -43,7 +45,7 @@ public:
     ~AnimationController();
 
     void cancelAnimations(RenderObject*);
-    RenderStyle* updateAnimations(RenderObject*, RenderStyle* newStyle);
+    PassRefPtr<RenderStyle> updateAnimations(RenderObject*, RenderStyle* newStyle);
 
     void setAnimationStartTime(RenderObject*, double t);
     void setTransitionStartTime(RenderObject*, int property, double t);
index 216b1bc..2ae68d9 100644 (file)
@@ -50,7 +50,7 @@ public:
     
     ~CompositeAnimationPrivate();
 
-    RenderStyle* animate(RenderObject*, const RenderStyle* currentStyle, RenderStyle* targetStyle);
+    PassRefPtr<RenderStyle> animate(RenderObject*, RenderStyle* currentStyle, RenderStyle* targetStyle);
 
     void setAnimating(bool);
     bool isAnimating() const;
@@ -79,8 +79,8 @@ public:
     void setWaitingForStyleAvailable(bool);
 
 protected:
-    void updateTransitions(RenderObject*, const RenderStyle* currentStyle, RenderStyle* targetStyle);
-    void updateKeyframeAnimations(RenderObject*, const RenderStyle* currentStyle, RenderStyle* targetStyle);
+    void updateTransitions(RenderObject*, RenderStyle* currentStyle, RenderStyle* targetStyle);
+    void updateKeyframeAnimations(RenderObject*, RenderStyle* currentStyle, RenderStyle* targetStyle);
 
 private:
     typedef HashMap<int, RefPtr<ImplicitAnimation> > CSSPropertyTransitionsMap;
@@ -100,7 +100,7 @@ CompositeAnimationPrivate::~CompositeAnimationPrivate()
     m_keyframeAnimations.clear();
 }
     
-void CompositeAnimationPrivate::updateTransitions(RenderObject* renderer, const RenderStyle* currentStyle, RenderStyle* targetStyle)
+void CompositeAnimationPrivate::updateTransitions(RenderObject* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle)
 {
     // If currentStyle is null, we don't do transitions
     if (!currentStyle || !targetStyle->transitions())
@@ -133,7 +133,7 @@ void CompositeAnimationPrivate::updateTransitions(RenderObject* renderer, const
             // and we have to use the unanimatedStyle from the animation. We do the test
             // against the unanimated style here, but we "override" the transition later.
             const KeyframeAnimation* keyframeAnim = getAnimationForProperty(prop);
-            const RenderStyle* fromStyle = keyframeAnim ? keyframeAnim->unanimatedStyle() : currentStyle;
+            RenderStyle* fromStyle = keyframeAnim ? keyframeAnim->unanimatedStyle() : currentStyle;
 
             // See if there is a current transition for this prop
             ImplicitAnimation* implAnim = m_transitions.get(prop).get();
@@ -168,7 +168,7 @@ void CompositeAnimationPrivate::updateTransitions(RenderObject* renderer, const
     }
 }
 
-void CompositeAnimationPrivate::updateKeyframeAnimations(RenderObject* renderer, const RenderStyle* currentStyle, RenderStyle* targetStyle)
+void CompositeAnimationPrivate::updateKeyframeAnimations(RenderObject* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle)
 {
     // Nothing to do if we don't have any animations, and didn't have any before
     if (m_keyframeAnimations.isEmpty() && !targetStyle->hasAnimations())
@@ -226,9 +226,9 @@ void CompositeAnimationPrivate::updateKeyframeAnimations(RenderObject* renderer,
         m_keyframeAnimations.remove(animsToBeRemoved[j]);
 }
 
-RenderStyle* CompositeAnimationPrivate::animate(RenderObject* renderer, const RenderStyle* currentStyle, RenderStyle* targetStyle)
+PassRefPtr<RenderStyle> CompositeAnimationPrivate::animate(RenderObject* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle)
 {
-    RenderStyle* resultStyle = 0;
+    RefPtr<RenderStyle> resultStyle;
 
     // Update animations first so we can see if any transitions are overridden
     updateKeyframeAnimations(renderer, currentStyle, targetStyle);
@@ -263,7 +263,7 @@ RenderStyle* CompositeAnimationPrivate::animate(RenderObject* renderer, const Re
 
     cleanupFinishedAnimations(renderer);
 
-    return resultStyle ? resultStyle : targetStyle;
+    return resultStyle ? resultStyle.release() : targetStyle;
 }
 
 // "animating" means that something is running that requires the timer to keep firing
@@ -521,7 +521,7 @@ CompositeAnimation::~CompositeAnimation()
     delete m_data;
 }
 
-RenderStyle* CompositeAnimation::animate(RenderObject* renderer, const RenderStyle* currentStyle, RenderStyle* targetStyle)
+PassRefPtr<RenderStyle> CompositeAnimation::animate(RenderObject* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle)
 {
     return m_data->animate(renderer, currentStyle, targetStyle);
 }
index 0dc4c28..13f1179 100644 (file)
@@ -48,7 +48,7 @@ public:
     CompositeAnimation(AnimationController* animationController);
     ~CompositeAnimation();
 
-    RenderStyle* animate(RenderObject*, const RenderStyle* currentStyle, RenderStyle* targetStyle);
+    PassRefPtr<RenderStyle> animate(RenderObject*, RenderStyle* currentStyle, RenderStyle* targetStyle);
     bool isAnimating() const;
 
     void setWaitingForStyleAvailable(bool);
index 797c02f..3024ce4 100644 (file)
 
 namespace WebCore {
 
-ImplicitAnimation::ImplicitAnimation(const Animation* transition, int animatingProperty, RenderObject* renderer, CompositeAnimation* compAnim, const RenderStyle* fromStyle)
+ImplicitAnimation::ImplicitAnimation(const Animation* transition, int animatingProperty, RenderObject* renderer, CompositeAnimation* compAnim, RenderStyle* fromStyle)
     : AnimationBase(transition, renderer, compAnim)
     , m_transitionProperty(transition->property())
     , m_animatingProperty(animatingProperty)
     , m_overridden(false)
-    , m_fromStyle(0)
-    , m_toStyle(0)
+    , m_fromStyle(fromStyle)
 {
     ASSERT(animatingProperty != cAnimateAll);
-    if (fromStyle) {
-        m_fromStyle = fromStyle;
-        const_cast<RenderStyle*>(m_fromStyle)->ref();
-    }
 }
 
 ImplicitAnimation::~ImplicitAnimation()
 {
-    // Get rid of style refs
-    if (m_fromStyle)
-        const_cast<RenderStyle*>(m_fromStyle)->deref(renderer()->renderArena());
-    if (m_toStyle)
-        const_cast<RenderStyle*>(m_toStyle)->deref(renderer()->renderArena());
-
     // Do the cleanup here instead of in the base class so the specialized methods get called
     if (!postActive())
         updateStateMachine(AnimationStateInputEndAnimation, -1);
@@ -67,8 +56,8 @@ bool ImplicitAnimation::shouldSendEventForListener(Document::ListenerType inList
     return m_object->document()->hasListenerType(inListenerType);
 }
 
-void ImplicitAnimation::animate(CompositeAnimation* animation, RenderObject* renderer, const RenderStyle* currentStyle,
-                                const RenderStyle* targetStyle, RenderStyle*& animatedStyle)
+void ImplicitAnimation::animate(CompositeAnimation* animation, RenderObject* renderer, RenderStyle* currentStyle,
+                                RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle)
 {
     if (paused())
         return;
@@ -85,9 +74,9 @@ void ImplicitAnimation::animate(CompositeAnimation* animation, RenderObject* ren
     // Run a cycle of animation.
     // We know we will need a new render style, so make one if needed
     if (!animatedStyle)
-        animatedStyle = new (renderer->renderArena()) RenderStyle(*targetStyle);
+        animatedStyle = RenderStyle::clone(targetStyle);
 
-    if (blendProperties(this, m_animatingProperty, animatedStyle, m_fromStyle, m_toStyle, progress(1, 0, 0)))
+    if (blendProperties(this, m_animatingProperty, animatedStyle.get(), m_fromStyle.get(), m_toStyle.get(), progress(1, 0, 0)))
         setAnimating();
 }
 
@@ -135,17 +124,13 @@ bool ImplicitAnimation::sendTransitionEvent(const AtomicString& eventType, doubl
     return false; // Didn't dispatch an event
 }
 
-void ImplicitAnimation::reset(const RenderStyle* to)
+void ImplicitAnimation::reset(RenderStyle* to)
 {
     ASSERT(to);
     ASSERT(m_fromStyle);
     
-    if (m_toStyle)
-        const_cast<RenderStyle*>(m_toStyle)->deref(renderer()->renderArena());
 
-    m_toStyle = to;       // It is read-only, other than the ref
-    if (m_toStyle)
-        const_cast<RenderStyle*>(m_toStyle)->ref();
+    m_toStyle = to;
 
     // Restart the transition
     if (m_fromStyle && m_toStyle)
@@ -171,12 +156,12 @@ bool ImplicitAnimation::affectsProperty(int property) const
 
 bool ImplicitAnimation::isTargetPropertyEqual(int prop, const RenderStyle* targetStyle)
 {
-    return propertiesEqual(prop, m_toStyle, targetStyle);
+    return propertiesEqual(prop, m_toStyle.get(), targetStyle);
 }
 
 void ImplicitAnimation::blendPropertyValueInStyle(int prop, RenderStyle* currentStyle)
 {
-    blendProperties(this, prop, currentStyle, m_fromStyle, m_toStyle, progress(1, 0, 0));
+    blendProperties(this, prop, currentStyle, m_fromStyle.get(), m_toStyle.get(), progress(1, 0, 0));
 }
 
 void ImplicitAnimation::validateTransformFunctionList()
index ef4bdaa..7c9d50f 100644 (file)
@@ -38,7 +38,7 @@ namespace WebCore {
 // for a single RenderObject.
 class ImplicitAnimation : public AnimationBase {
 public:
-    static PassRefPtr<ImplicitAnimation> create(const Animation* animation, int animatingProperty, RenderObject* renderer, CompositeAnimation* compositeAnimation, const RenderStyle* fromStyle)
+    static PassRefPtr<ImplicitAnimation> create(const Animation* animation, int animatingProperty, RenderObject* renderer, CompositeAnimation* compositeAnimation, RenderStyle* fromStyle)
     {
         return adoptRef(new ImplicitAnimation(animation, animatingProperty, renderer, compositeAnimation, fromStyle));
     };
@@ -48,8 +48,8 @@ public:
 
     virtual void onAnimationEnd(double elapsedTime);
 
-    virtual void animate(CompositeAnimation*, RenderObject*, const RenderStyle* currentStyle, const RenderStyle* targetStyle, RenderStyle*& animatedStyle);
-    virtual void reset(const RenderStyle* to);
+    virtual void animate(CompositeAnimation*, RenderObject*, RenderStyle* currentStyle, RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle);
+    virtual void reset(RenderStyle* to);
 
     void setOverridden(bool);
     virtual bool overridden() const { return m_overridden; }
@@ -71,7 +71,7 @@ protected:
     void validateTransformFunctionList();
 
 private:
-    ImplicitAnimation(const Animation*, int animatingProperty, RenderObject*, CompositeAnimation*, const RenderStyle* fromStyle);    
+    ImplicitAnimation(const Animation*, int animatingProperty, RenderObject*, CompositeAnimation*, RenderStyle* fromStyle);    
     virtual ~ImplicitAnimation();
 
     int m_transitionProperty;   // Transition property as specified in the RenderStyle. May be cAnimateAll
@@ -79,8 +79,8 @@ private:
     bool m_overridden;          // true when there is a keyframe animation that overrides the transitioning property
 
     // The two styles that we are blending.
-    const RenderStyle* m_fromStyle;
-    const RenderStyle* m_toStyle;
+    RefPtr<RenderStyle> m_fromStyle;
+    RefPtr<RenderStyle> m_toStyle;
 };
 
 } // namespace WebCore
index 9793b48..b7e6966 100644 (file)
 
 namespace WebCore {
 
-KeyframeAnimation::KeyframeAnimation(const Animation* animation, RenderObject* renderer, int index, CompositeAnimation* compAnim, const RenderStyle* unanimatedStyle)
+KeyframeAnimation::KeyframeAnimation(const Animation* animation, RenderObject* renderer, int index, CompositeAnimation* compAnim, RenderStyle* unanimatedStyle)
     : AnimationBase(animation, renderer, compAnim)
     , m_keyframes(renderer, animation->name())
     , m_index(index)
-    , m_unanimatedStyle(0)
+    , m_unanimatedStyle(unanimatedStyle)
 {
-    if (unanimatedStyle) {
-        const_cast<RenderStyle*>(unanimatedStyle)->ref();
-        m_unanimatedStyle = unanimatedStyle;
-    }
-    
     // Get the keyframe RenderStyles
     if (m_object && m_object->element() && m_object->element()->isElementNode())
         m_object->document()->styleSelector()->keyframeStylesForAnimation(static_cast<Element*>(m_object->element()), unanimatedStyle, m_keyframes);
@@ -62,13 +57,10 @@ KeyframeAnimation::~KeyframeAnimation()
     // Do the cleanup here instead of in the base class so the specialized methods get called
     if (!postActive())
         updateStateMachine(AnimationStateInputEndAnimation, -1);
-
-    if (m_unanimatedStyle)
-        const_cast<RenderStyle*>(m_unanimatedStyle)->deref(renderer()->renderArena());
 }
 
 void KeyframeAnimation::animate(CompositeAnimation* animation, RenderObject* renderer, const RenderStyle* currentStyle, 
-                                    const RenderStyle* targetStyle, RenderStyle*& animatedStyle)
+                                    const RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle)
 {
     // If we have not yet started, we will not have a valid start time, so just start the animation if needed.
     if (isNew() && m_animation->playState() == AnimPlayStatePlaying)
@@ -102,23 +94,23 @@ void KeyframeAnimation::animate(CompositeAnimation* animation, RenderObject* ren
     if (m_animation->direction() && (i & 1))
         t = 1 - t;
 
-    RenderStyle* fromStyle = 0;
-    RenderStyle* toStyle = 0;
+    const RenderStyle* fromStyle = 0;
+    const RenderStyle* toStyle = 0;
     double scale = 1;
     double offset = 0;
     Vector<KeyframeValue>::const_iterator endKeyframes = m_keyframes.endKeyframes();
     for (Vector<KeyframeValue>::const_iterator it = m_keyframes.beginKeyframes(); it != endKeyframes; ++it) {
-        if (t < it->key) {
+        if (t < it->key()) {
             // The first key should always be 0, so we should never succeed on the first key
             if (!fromStyle)
                 break;
-            scale = 1.0 / (it->key - offset);
-            toStyle = it->style;
+            scale = 1.0 / (it->key() - offset);
+            toStyle = it->style();
             break;
         }
 
-        offset = it->key;
-        fromStyle = it->style;
+        offset = it->key();
+        fromStyle = it->style();
     }
 
     // If either style is 0 we have an invalid case, just stop the animation.
@@ -130,7 +122,7 @@ void KeyframeAnimation::animate(CompositeAnimation* animation, RenderObject* ren
     // Run a cycle of animation.
     // We know we will need a new render style, so make one if needed.
     if (!animatedStyle)
-        animatedStyle = new (renderer->renderArena()) RenderStyle(*targetStyle);
+        animatedStyle = RenderStyle::clone(targetStyle);
 
     const TimingFunction* timingFunction = 0;
     if (fromStyle->animations() && fromStyle->animations()->size() > 0)
@@ -140,7 +132,7 @@ void KeyframeAnimation::animate(CompositeAnimation* animation, RenderObject* ren
 
     HashSet<int>::const_iterator endProperties = m_keyframes.endProperties();
     for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != endProperties; ++it) {
-        if (blendProperties(this, *it, animatedStyle, fromStyle, toStyle, prog))
+        if (blendProperties(this, *it, animatedStyle.get(), fromStyle, toStyle, prog))
             setAnimating();
     }
 }
@@ -264,7 +256,7 @@ void KeyframeAnimation::validateTransformFunctionList()
     Vector<KeyframeValue>::const_iterator firstIt = end;
     
     for (Vector<KeyframeValue>::const_iterator it = m_keyframes.beginKeyframes(); it != end; ++it, ++firstIndex) {
-        if (it->style->transform().operations().size() > 0) {
+        if (it->style()->transform().operations().size() > 0) {
             firstIt = it;
             break;
         }
@@ -273,11 +265,11 @@ void KeyframeAnimation::validateTransformFunctionList()
     if (firstIt == end)
         return;
         
-    const TransformOperations* firstVal = &firstIt->style->transform();
+    const TransformOperations* firstVal = &firstIt->style()->transform();
     
     // See if the keyframes are valid
     for (Vector<KeyframeValue>::const_iterator it = firstIt+1; it != end; ++it) {
-        const TransformOperations* val = &it->style->transform();
+        const TransformOperations* val = &it->style()->transform();
         
         // A null transform matches anything
         if (val->operations().isEmpty())
index 1212731..55b429a 100644 (file)
@@ -40,12 +40,12 @@ namespace WebCore {
 // for a single RenderObject.
 class KeyframeAnimation : public AnimationBase {
 public:
-    static PassRefPtr<KeyframeAnimation> create(const Animation* animation, RenderObject* renderer, int index, CompositeAnimation* compositeAnimation, const RenderStyle* unanimatedStyle)
+    static PassRefPtr<KeyframeAnimation> create(const Animation* animation, RenderObject* renderer, int index, CompositeAnimation* compositeAnimation, RenderStyle* unanimatedStyle)
     {
         return adoptRef(new KeyframeAnimation(animation, renderer, index, compositeAnimation, unanimatedStyle));
     };
     
-    virtual void animate(CompositeAnimation*, RenderObject*, const RenderStyle* currentStyle, const RenderStyle* targetStyle, RenderStyle*& animatedStyle);
+    virtual void animate(CompositeAnimation*, RenderObject*, const RenderStyle* currentStyle, const RenderStyle* targetStyle, RefPtr<RenderStyle>& animatedStyle);
 
     const AtomicString& name() const { return m_keyframes.animationName(); }
     int index() const { return m_index; }
@@ -55,7 +55,7 @@ public:
     
     bool hasAnimationForProperty(int property) const;
     
-    const RenderStyle* unanimatedStyle() const { return m_unanimatedStyle; }
+    RenderStyle* unanimatedStyle() const { return m_unanimatedStyle.get(); }
 
 protected:
     virtual void onAnimationStart(double elapsedTime);
@@ -74,7 +74,7 @@ protected:
     void validateTransformFunctionList();
 
 private:
-    KeyframeAnimation(const Animation* animation, RenderObject*, int index, CompositeAnimation*, const RenderStyle* unanimatedStyle);
+    KeyframeAnimation(const Animation* animation, RenderObject*, int index, CompositeAnimation*, RenderStyle* unanimatedStyle);
     virtual ~KeyframeAnimation();
     
     // The keyframes that we are blending.
@@ -84,7 +84,7 @@ private:
     int m_index;
 
     // The style just before we started animation
-    const RenderStyle* m_unanimatedStyle;
+    RefPtr<RenderStyle> m_unanimatedStyle;
 };
 
 } // namespace WebCore
index 6743227..0d15839 100644 (file)
@@ -376,7 +376,7 @@ void InlineTextBox::paint(RenderObject::PaintInfo& paintInfo, int tx, int ty)
             selectionFillColor = foreground;
         }
 
-        if (RenderStyle* pseudoStyle = object()->getPseudoStyle(RenderStyle::SELECTION)) {
+        if (RenderStyle* pseudoStyle = object()->getCachedPseudoStyle(RenderStyle::SELECTION)) {
             ShadowData* shadow = paintInfo.forceBlackText ? 0 : pseudoStyle->textShadow();
             if (shadow != selectionShadow) {
                 if (!paintSelectedTextOnly)
index efaf668..95a1aeb 100644 (file)
@@ -54,13 +54,13 @@ MediaControlShadowRootElement::MediaControlShadowRootElement(Document* doc, HTML
     : HTMLDivElement(doc)
     , m_mediaElement(mediaElement) 
 {
-    RenderStyle* rootStyle = new (mediaElement->renderer()->renderArena()) RenderStyle();
+    RefPtr<RenderStyle> rootStyle = RenderStyle::create();
     rootStyle->inheritFrom(mediaElement->renderer()->style());
     rootStyle->setDisplay(BLOCK);
     rootStyle->setPosition(RelativePosition);
     RenderMediaControlShadowRoot* renderer = new (mediaElement->renderer()->renderArena()) RenderMediaControlShadowRoot(this);
     renderer->setParent(mediaElement->renderer());
-    renderer->setStyle(rootStyle);
+    renderer->setStyle(rootStyle.release());
     setRenderer(renderer);
     setAttached();
     setInDocument(true);
@@ -73,7 +73,7 @@ MediaControlInputElement::MediaControlInputElement(Document* doc, RenderStyle::P
     , m_mediaElement(mediaElement)
 {
     setInputType(type);
-    RenderStyle* style = m_mediaElement->renderer()->getPseudoStyle(pseudo);
+    RenderStyle* style = m_mediaElement->renderer()->getCachedPseudoStyle(pseudo);
     RenderObject* renderer = createRenderer(m_mediaElement->renderer()->renderArena(), style);
     if (renderer) {
         setRenderer(renderer);
index 38df22f..a608a3a 100644 (file)
@@ -159,10 +159,10 @@ void RenderBlock::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldS
     // FIXME: We could save this call when the change only affected non-inherited properties
     for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
         if (child->isAnonymousBlock()) {
-            RenderStyle* newStyle = new (renderArena()) RenderStyle();
+            RefPtr<RenderStyle> newStyle = RenderStyle::create();
             newStyle->inheritFrom(style());
             newStyle->setDisplay(BLOCK);
-            child->setStyle(newStyle);
+            child->setStyle(newStyle.release());
         }
     }
 
@@ -4368,8 +4368,8 @@ void RenderBlock::updateFirstLetter()
     // If the child already has style, then it has already been created, so we just want
     // to update it.
     if (currChild->style()->styleType() == RenderStyle::FIRST_LETTER) {
-        RenderStyle* pseudo = firstLetterBlock->getPseudoStyle(RenderStyle::FIRST_LETTER,
-                                                               firstLetterContainer->firstLineStyle());
+        RenderStyle* pseudo = firstLetterBlock->getCachedPseudoStyle(RenderStyle::FIRST_LETTER,
+                                                                     firstLetterContainer->firstLineStyle());
         currChild->setStyle(pseudo);
         for (RenderObject* genChild = currChild->firstChild(); genChild; genChild = genChild->nextSibling()) {
             if (genChild->isText()) 
@@ -4387,8 +4387,8 @@ void RenderBlock::updateFirstLetter()
         RenderText* textObj = static_cast<RenderText*>(currChild);
         
         // Create our pseudo style now that we have our firstLetterContainer determined.
-        RenderStyle* pseudoStyle = firstLetterBlock->getPseudoStyle(RenderStyle::FIRST_LETTER,
-                                                                    firstLetterContainer->firstLineStyle());
+        RenderStyle* pseudoStyle = firstLetterBlock->getCachedPseudoStyle(RenderStyle::FIRST_LETTER,
+                                                                          firstLetterContainer->firstLineStyle());
         
         // Force inline display (except for floating first-letters)
         pseudoStyle->setDisplay( pseudoStyle->isFloating() ? BLOCK : INLINE);
@@ -4429,9 +4429,9 @@ void RenderBlock::updateFirstLetter()
             // construct text fragment for the first letter
             RenderTextFragment* letter = 
                 new (renderArena()) RenderTextFragment(remainingText->node(), oldText.get(), 0, length);
-            RenderStyle* newStyle = new (renderArena()) RenderStyle();
+            RefPtr<RenderStyle> newStyle = RenderStyle::create();
             newStyle->inheritFrom(pseudoStyle);
-            letter->setStyle(newStyle);
+            letter->setStyle(newStyle.release());
             firstLetter->addChild(letter);
 
             textObj->destroy();
index f0b3bca..528c173 100644 (file)
@@ -113,10 +113,10 @@ void RenderContainer::addChild(RenderObject* newChild, RenderObject* beforeChild
             table = static_cast<RenderTable*>(afterChild);
         else {
             table = new (renderArena()) RenderTable(document() /* is anonymous */);
-            RenderStyle *newStyle = new (renderArena()) RenderStyle;
+            RefPtr<RenderStyle> newStyle = RenderStyle::create();
             newStyle->inheritFrom(style());
             newStyle->setDisplay(TABLE);
-            table->setStyle(newStyle);
+            table->setStyle(newStyle.release());
             addChild(table, beforeChild);
         }
         table->addChild(newChild);
@@ -261,7 +261,7 @@ void RenderContainer::updateBeforeAfterContentForContainer(RenderStyle::PseudoId
     if (style()->styleType() == RenderStyle::BEFORE || style()->styleType() == RenderStyle::AFTER)
         return;
     
-    RenderStyle* pseudoElementStyle = styledObject->getPseudoStyle(type);
+    RenderStyle* pseudoElementStyle = styledObject->getCachedPseudoStyle(type);
     RenderObject* child = beforeAfterContainer(type);
 
     // Whether or not we currently have generated content attached.
@@ -324,9 +324,9 @@ void RenderContainer::updateBeforeAfterContentForContainer(RenderStyle::PseudoId
                     genChild->setStyle(pseudoElementStyle);
                 else if (genChild->isImage()) {
                     // Images get an empty style that inherits from the pseudo.
-                    RenderStyle* style = new (renderArena()) RenderStyle;
+                    RefPtr<RenderStyle> style = RenderStyle::create();
                     style->inheritFrom(pseudoElementStyle);
-                    genChild->setStyle(style);
+                    genChild->setStyle(style.release());
                 } else
                     // Must be a first-letter container. updateFirstLetter() will take care of it.
                     ASSERT(genChild->style()->styleType() == RenderStyle::FIRST_LETTER);
@@ -353,9 +353,9 @@ void RenderContainer::updateBeforeAfterContentForContainer(RenderStyle::PseudoId
                 break;
             case CONTENT_OBJECT: {
                 RenderImageGeneratedContent* image = new (renderArena()) RenderImageGeneratedContent(document()); // anonymous object
-                RenderStyle* style = new (renderArena()) RenderStyle;
+                RefPtr<RenderStyle> style = RenderStyle::create();
                 style->inheritFrom(pseudoElementStyle);
-                image->setStyle(style);
+                image->setStyle(style.release());
                 if (StyleImage* styleImage = content->m_content.m_image)
                     image->setStyleImage(styleImage);
                 renderer = image;
index 050691e..40d8372 100644 (file)
@@ -107,10 +107,10 @@ void RenderFileUploadControl::updateFromElement()
         m_button = new HTMLFileUploadInnerButtonElement(document(), inputElement);
         m_button->setInputType("button");
         m_button->setValue(fileButtonChooseFileLabel());
-        RenderStyle* buttonStyle = createButtonStyle(style());
-        RenderObject* renderer = m_button->createRenderer(renderArena(), buttonStyle);
+        RefPtr<RenderStyle> buttonStyle = createButtonStyle(style());
+        RenderObject* renderer = m_button->createRenderer(renderArena(), buttonStyle.get());
         m_button->setRenderer(renderer);
-        renderer->setStyle(buttonStyle);
+        renderer->setStyle(buttonStyle.release());
         renderer->updateFromElement();
         m_button->setAttached();
         m_button->setInDocument(true);
@@ -134,11 +134,11 @@ int RenderFileUploadControl::maxFilenameWidth() const
         - (m_fileChooser->icon() ? iconWidth + iconFilenameSpacing : 0));
 }
 
-RenderStyle* RenderFileUploadControl::createButtonStyle(const RenderStyle* parentStyle) const
+PassRefPtr<RenderStyle> RenderFileUploadControl::createButtonStyle(const RenderStyle* parentStyle) const
 {
-    RenderStyle* style = getPseudoStyle(RenderStyle::FILE_UPLOAD_BUTTON);
+    RefPtr<RenderStyle> style = getCachedPseudoStyle(RenderStyle::FILE_UPLOAD_BUTTON);
     if (!style) {
-        style = new (renderArena()) RenderStyle;
+        style = RenderStyle::create();
         if (parentStyle)
             style->inheritFrom(parentStyle);
     }
@@ -147,7 +147,7 @@ RenderStyle* RenderFileUploadControl::createButtonStyle(const RenderStyle* paren
     // without this setWhiteSpace.
     style->setWhiteSpace(NOWRAP);
 
-    return style;
+    return style.release();
 }
 
 void RenderFileUploadControl::paintObject(PaintInfo& paintInfo, int tx, int ty)
index 340cbc9..d909b6e 100644 (file)
@@ -57,7 +57,7 @@ protected:
 
 private:
     int maxFilenameWidth() const;
-    RenderStyle* createButtonStyle(const RenderStyle* parentStyle) const;
+    PassRefPtr<RenderStyle> createButtonStyle(const RenderStyle* parentStyle) const;
 
     RefPtr<HTMLInputElement> m_button;
     RefPtr<FileChooser> m_fileChooser;
index 035cfe1..eb689cf 100644 (file)
@@ -47,7 +47,7 @@ RenderFlow::~RenderFlow()
 
 #endif
 
-RenderFlow* RenderFlow::createAnonymousFlow(Document* doc, RenderStyle* style)
+RenderFlow* RenderFlow::createAnonymousFlow(Document* doc, PassRefPtr<RenderStyle> style)
 {
     RenderFlow* result;
     if (style->display() == INLINE)
index ec85ce5..c284ed8 100644 (file)
@@ -66,7 +66,7 @@ public:
     virtual void addChildToFlow(RenderObject* newChild, RenderObject* beforeChild) = 0;
     virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
 
-    static RenderFlow* createAnonymousFlow(Document*, RenderStyle*);
+    static RenderFlow* createAnonymousFlow(Document*, PassRefPtr<RenderStyle>);
 
     void extractLineBox(InlineFlowBox*);
     void attachLineBox(InlineFlowBox*);
index e9f56a9..79d914f 100644 (file)
@@ -102,12 +102,12 @@ void RenderInline::addChildToFlow(RenderObject* newChild, RenderObject* beforeCh
         // inline into continuations.  This involves creating an anonymous block box to hold
         // |newChild|.  We then make that block box a continuation of this inline.  We take all of
         // the children after |beforeChild| and put them in a clone of this object.
-        RenderStyle* newStyle = new (renderArena()) RenderStyle();
+        RefPtr<RenderStyle> newStyle = RenderStyle::create();
         newStyle->inheritFrom(style());
         newStyle->setDisplay(BLOCK);
 
         RenderBlock* newBox = new (renderArena()) RenderBlock(document() /* anonymous box */);
-        newBox->setStyle(newStyle);
+        newBox->setStyle(newStyle.release());
         RenderFlow* oldContinuation = continuation();
         setContinuation(newBox);
 
index 2adb3de..2785b40 100644 (file)
@@ -2481,13 +2481,13 @@ void RenderLayer::styleChanged(RenderStyle::Diff, const RenderStyle* oldStyle)
 void RenderLayer::updateScrollCornerStyle()
 {
     RenderObject* actualRenderer = m_object->node()->isElementNode() ? m_object->node()->shadowAncestorNode()->renderer() : m_object;
-    RenderStyle* corner = m_object->hasOverflowClip() ? actualRenderer->getPseudoStyle(RenderStyle::SCROLLBAR_CORNER, actualRenderer->style(), false) : 0;
+    RefPtr<RenderStyle> corner = m_object->hasOverflowClip() ? actualRenderer->getUncachedPseudoStyle(RenderStyle::SCROLLBAR_CORNER, actualRenderer->style()) : 0;
     if (corner) {
         if (!m_scrollCorner) {
             m_scrollCorner = new (m_object->renderArena()) RenderScrollbarPart(m_object->document());
             m_scrollCorner->setParent(m_object);
         }
-        m_scrollCorner->setStyle(corner);
+        m_scrollCorner->setStyle(corner.release());
     } else if (m_scrollCorner) {
         m_scrollCorner->destroy();
         m_scrollCorner = 0;
@@ -2497,13 +2497,13 @@ void RenderLayer::updateScrollCornerStyle()
 void RenderLayer::updateResizerStyle()
 {
     RenderObject* actualRenderer = m_object->node()->isElementNode() ? m_object->node()->shadowAncestorNode()->renderer() : m_object;
-    RenderStyle* resizer = m_object->hasOverflowClip() ? actualRenderer->getPseudoStyle(RenderStyle::RESIZER, actualRenderer->style(), false) : 0;
+    RefPtr<RenderStyle> resizer = m_object->hasOverflowClip() ? actualRenderer->getUncachedPseudoStyle(RenderStyle::RESIZER, actualRenderer->style()) : 0;
     if (resizer) {
         if (!m_resizer) {
             m_resizer = new (m_object->renderArena()) RenderScrollbarPart(m_object->document());
             m_resizer->setParent(m_object);
         }
-        m_resizer->setStyle(resizer);
+        m_resizer->setStyle(resizer.release());
     } else if (m_resizer) {
         m_resizer->destroy();
         m_resizer = 0;
@@ -2524,7 +2524,7 @@ void RenderLayer::createReflection()
 
 void RenderLayer::updateReflectionStyle()
 {
-    RenderStyle* newStyle = new (renderer()->renderArena()) RenderStyle();
+    RefPtr<RenderStyle> newStyle = RenderStyle::create();
     newStyle->inheritFrom(renderer()->style());
     
     // Map in our transform.
@@ -2556,7 +2556,7 @@ void RenderLayer::updateReflectionStyle()
     // Map in our mask.
     newStyle->setMaskBoxImage(renderer()->style()->boxReflect()->mask());
     
-    m_reflection->setStyle(newStyle);
+    m_reflection->setStyle(newStyle.release());
 }
 
 void RenderLayer::suspendMarquees()
index fb95685..b69612e 100644 (file)
@@ -54,15 +54,13 @@ void RenderListItem::styleDidChange(RenderStyle::Diff diff, const RenderStyle* o
 
     if (style()->listStyleType() != LNONE ||
         (style()->listStyleImage() && !style()->listStyleImage()->errorOccurred())) {
-        RenderStyle* newStyle = new (renderArena()) RenderStyle;
-        newStyle->ref();
+        RefPtr<RenderStyle> newStyle = RenderStyle::create();
         // The marker always inherits from the list item, regardless of where it might end
         // up (e.g., in some deeply nested line box). See CSS3 spec.
         newStyle->inheritFrom(style()); 
         if (!m_marker)
             m_marker = new (renderArena()) RenderListMarker(this);
-        m_marker->setStyle(newStyle);
-        newStyle->deref(renderArena());
+        m_marker->setStyle(newStyle.release());
     } else if (m_marker) {
         m_marker->destroy();
         m_marker = 0;
index c92bc6d..e1d7bcc 100644 (file)
@@ -146,7 +146,7 @@ void RenderMedia::createControlsShadowRoot()
 void RenderMedia::createPanel()
 {
     ASSERT(!m_panel);
-    RenderStyle* style = getPseudoStyle(RenderStyle::MEDIA_CONTROLS_PANEL);
+    RenderStyle* style = getCachedPseudoStyle(RenderStyle::MEDIA_CONTROLS_PANEL);
     m_panel = new HTMLDivElement(document());
     RenderObject* renderer = m_panel->createRenderer(renderArena(), style);
     if (renderer) {
@@ -197,7 +197,7 @@ void RenderMedia::createTimeline()
 void RenderMedia::createTimeDisplay()
 {
     ASSERT(!m_timeDisplay);
-    RenderStyle* style = getPseudoStyle(RenderStyle::MEDIA_CONTROLS_TIME_DISPLAY);
+    RenderStyle* style = getCachedPseudoStyle(RenderStyle::MEDIA_CONTROLS_TIME_DISPLAY);
     m_timeDisplay = new HTMLDivElement(document());
     RenderObject* renderer = m_timeDisplay->createRenderer(renderArena(), style);
     if (renderer) {
@@ -340,11 +340,11 @@ void RenderMedia::changeOpacity(HTMLElement* e, float opacity)
 {
     if (!e || !e->renderer() || !e->renderer()->style())
         return;
-    RenderStyle* s = new (renderArena()) RenderStyle(*e->renderer()->style());
+    RefPtr<RenderStyle> s = RenderStyle::clone(e->renderer()->style());
     s->setOpacity(opacity);
     // z-index can't be auto if opacity is used
     s->setZIndex(0);
-    e->renderer()->setStyle(s);
+    e->renderer()->setStyle(s.release());
 }
     
 void RenderMedia::opacityAnimationTimerFired(Timer<RenderMedia>*)
index f4c8a78..b2d3b3e 100644 (file)
@@ -2038,7 +2038,7 @@ Color RenderObject::selectionBackgroundColor() const
 {
     Color color;
     if (style()->userSelect() != SELECT_NONE) {
-        RenderStyle* pseudoStyle = getPseudoStyle(RenderStyle::SELECTION);
+        RenderStyle* pseudoStyle = getCachedPseudoStyle(RenderStyle::SELECTION);
         if (pseudoStyle && pseudoStyle->backgroundColor().isValid())
             color = pseudoStyle->backgroundColor().blendWithWhite();
         else
@@ -2056,7 +2056,7 @@ Color RenderObject::selectionForegroundColor() const
     if (style()->userSelect() == SELECT_NONE)
         return color;
 
-    if (RenderStyle* pseudoStyle = getPseudoStyle(RenderStyle::SELECTION)) {
+    if (RenderStyle* pseudoStyle = getCachedPseudoStyle(RenderStyle::SELECTION)) {
         color = pseudoStyle->textFillColor();
         if (!color.isValid())
             color = pseudoStyle->color();
@@ -2110,12 +2110,12 @@ void RenderObject::selectionStartEnd(int& spos, int& epos) const
 
 RenderBlock* RenderObject::createAnonymousBlock()
 {
-    RenderStyle* newStyle = new (renderArena()) RenderStyle();
-    newStyle->inheritFrom(m_style);
+    RefPtr<RenderStyle> newStyle = RenderStyle::create();
+    newStyle->inheritFrom(m_style.get());
     newStyle->setDisplay(BLOCK);
 
     RenderBlock* newBox = new (renderArena()) RenderBlock(document() /* anonymous box */);
-    newBox->setStyle(newStyle);
+    newBox->setStyle(newStyle.release());
     return newBox;
 }
 
@@ -2154,33 +2154,31 @@ void RenderObject::handleDynamicFloatPositionChange()
     }
 }
 
-void RenderObject::setAnimatableStyle(RenderStyle* style)
+void RenderObject::setAnimatableStyle(PassRefPtr<RenderStyle> style)
 {
     if (!isText() && style)
-        style = animation()->updateAnimations(this, style);
-
-    setStyle(style);
+        setStyle(animation()->updateAnimations(this, style.get()));
+    else
+        setStyle(style);
 }
 
-void RenderObject::setStyle(const RenderStyle* style)
+void RenderObject::setStyle(PassRefPtr<RenderStyle> style)
 {
     if (m_style == style)
         return;
 
     RenderStyle::Diff diff = RenderStyle::Equal;
     if (m_style)
-        diff = m_style->diff(style);
+        diff = m_style->diff(style.get());
 
     // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint.
     if (diff == RenderStyle::RepaintLayer && !hasLayer())
         diff = RenderStyle::Repaint;
 
-    styleWillChange(diff, style);
+    styleWillChange(diff, style.get());
     
-    RenderStyle* oldStyle = m_style;
-    m_style = const_cast<RenderStyle*>(style);
-    if (m_style)
-        m_style->ref();
+    RefPtr<RenderStyle> oldStyle = m_style.release();
+    m_style = style;
 
     updateFillImages(oldStyle ? oldStyle->backgroundLayers() : 0, m_style ? m_style->backgroundLayers() : 0);
     updateFillImages(oldStyle ? oldStyle->maskLayers() : 0, m_style ? m_style->maskLayers() : 0);
@@ -2188,22 +2186,12 @@ void RenderObject::setStyle(const RenderStyle* style)
     updateImage(oldStyle ? oldStyle->borderImage().image() : 0, m_style ? m_style->borderImage().image() : 0);
     updateImage(oldStyle ? oldStyle->maskBoxImage().image() : 0, m_style ? m_style->maskBoxImage().image() : 0);
 
-    styleDidChange(diff, oldStyle);
-
-    if (oldStyle) {
-        oldStyle->deref(renderArena());
-    }
+    styleDidChange(diff, oldStyle.get());
 }
 
-void RenderObject::setStyleInternal(RenderStyle* style)
+void RenderObject::setStyleInternal(PassRefPtr<RenderStyle> style)
 {
-    if (m_style == style)
-        return;
-    if (m_style)
-        m_style->deref(renderArena());
     m_style = style;
-    if (m_style)
-        m_style->ref();
 }
 
 void RenderObject::styleWillChange(RenderStyle::Diff diff, const RenderStyle* newStyle)
@@ -2581,8 +2569,6 @@ void RenderObject::arenaDelete(RenderArena* arena, void* base)
 
         if (StyleImage* maskBoxImage = m_style->maskBoxImage().image())
             maskBoxImage->removeClient(this);
-
-        m_style->deref(arena);
     }
 
 #ifndef NDEBUG
@@ -2802,54 +2788,62 @@ void RenderObject::deleteLineBoxWrapper()
 RenderStyle* RenderObject::firstLineStyle() const
 {
     if (!document()->usesFirstLineRules())
-        return m_style;
+        return m_style.get();
 
-    RenderStyle* s = m_style;
+    RenderStyle* s = m_style.get();
     const RenderObject* obj = isText() ? parent() : this;
     if (obj->isBlockFlow()) {
         RenderBlock* firstLineBlock = obj->firstLineBlock();
         if (firstLineBlock)
-            s = firstLineBlock->getPseudoStyle(RenderStyle::FIRST_LINE, style());
+            s = firstLineBlock->getCachedPseudoStyle(RenderStyle::FIRST_LINE, style());
     } else if (!obj->isAnonymous() && obj->isInlineFlow()) {
         RenderStyle* parentStyle = obj->parent()->firstLineStyle();
         if (parentStyle != obj->parent()->style()) {
             // A first-line style is in effect. We need to cache a first-line style
             // for ourselves.
             style()->setHasPseudoStyle(RenderStyle::FIRST_LINE_INHERITED);
-            s = obj->getPseudoStyle(RenderStyle::FIRST_LINE_INHERITED, parentStyle);
+            s = obj->getCachedPseudoStyle(RenderStyle::FIRST_LINE_INHERITED, parentStyle);
         }
     }
     return s;
 }
 
-RenderStyle* RenderObject::getPseudoStyle(RenderStyle::PseudoId pseudo, RenderStyle* parentStyle, bool useCachedStyle) const
+RenderStyle* RenderObject::getCachedPseudoStyle(RenderStyle::PseudoId pseudo, RenderStyle* parentStyle) const
 {
     if (pseudo < RenderStyle::FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo))
         return 0;
 
+    RenderStyle* cachedStyle = style()->getCachedPseudoStyle(pseudo);
+    if (cachedStyle)
+        return cachedStyle;
+    
+    RefPtr<RenderStyle> result = getUncachedPseudoStyle(pseudo, parentStyle);
+    if (result)
+        return style()->addCachedPseudoStyle(result.release());
+    return 0;
+}
+
+PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(RenderStyle::PseudoId pseudo, RenderStyle* parentStyle) const
+{
+    if (pseudo < RenderStyle::FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo))
+        return 0;
+    
     if (!parentStyle)
         parentStyle = style();
 
-    RenderStyle* result = useCachedStyle ? style()->getPseudoStyle(pseudo) : 0;
-    if (result)
-        return result;
-
     Node* node = element();
     while (node && !node->isElementNode())
         node = node->parentNode();
     if (!node)
         return 0;
 
+    RefPtr<RenderStyle> result;
     if (pseudo == RenderStyle::FIRST_LINE_INHERITED) {
         result = document()->styleSelector()->styleForElement(static_cast<Element*>(node), parentStyle, false);
         result->setStyleType(RenderStyle::FIRST_LINE_INHERITED);
     } else
         result = document()->styleSelector()->pseudoStyleForElement(pseudo, static_cast<Element*>(node), parentStyle);
-    if (result && useCachedStyle) {
-        style()->addPseudoStyle(result);
-        result->deref(document()->renderArena());
-    }
-    return result;
+    return result.release();
 }
 
 static Color decorationColor(RenderStyle* style)
index e3ed46b..df56d96 100644 (file)
@@ -376,8 +376,11 @@ private:
     bool includeHorizontalScrollbarSize() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || style()->overflowX() == OAUTO); }
 
 public:
-    RenderStyle* getPseudoStyle(RenderStyle::PseudoId, RenderStyle* parentStyle = 0, bool useCachedStyle = true) const;
-
+    // The pseudo element style can be cached or uncached.  Use the cached method if the pseudo element doesn't respect
+    // any pseudo classes (and therefore has no concept of changing state).
+    RenderStyle* getCachedPseudoStyle(RenderStyle::PseudoId, RenderStyle* parentStyle = 0) const;
+    PassRefPtr<RenderStyle> getUncachedPseudoStyle(RenderStyle::PseudoId, RenderStyle* parentStyle = 0) const;
+    
     void updateDragState(bool dragOn);
 
     RenderView* view() const;
@@ -539,14 +542,14 @@ public:
     // Called to update a style that is allowed to trigger animations.
     // FIXME: Right now this will typically be called only when updating happens from the DOM on explicit elements.
     // We don't yet handle generated content animation such as first-letter or before/after (we'll worry about this later).
-    void setAnimatableStyle(RenderStyle*);
+    void setAnimatableStyle(PassRefPtr<RenderStyle>);
 
     // Set the style of the object and update the state of the object accordingly.
-    virtual void setStyle(const RenderStyle*);
+    virtual void setStyle(PassRefPtr<RenderStyle>);
 
     // Updates only the local style ptr of the object.  Does not update the state of the object,
     // and so only should be called when the style is known not to have changed (or from setStyle).
-    void setStyleInternal(RenderStyle*);
+    void setStyleInternal(PassRefPtr<RenderStyle>);
 
     // returns the containing block level element for this element.
     RenderBlock* containingBlock() const;
@@ -695,7 +698,7 @@ public:
     virtual int minPrefWidth() const { return 0; }
     virtual int maxPrefWidth() const { return 0; }
 
-    RenderStyle* style() const { return m_style; }
+    RenderStyle* style() const { return m_style.get(); }
     RenderStyle* firstLineStyle() const;
     RenderStyle* style(bool firstLine) const { return firstLine ? firstLineStyle() : style(); }
 
@@ -911,7 +914,7 @@ protected:
     void arenaDelete(RenderArena*, void* objectBase);
 
 private:
-    RenderStyle* m_style;
+    RefPtr<RenderStyle> m_style;
 
     Node* m_node;
 
index fc8c361..f065c44 100644 (file)
@@ -35,21 +35,21 @@ RenderSVGBlock::RenderSVGBlock(SVGElement* node)
 {
 }
 
-void RenderSVGBlock::setStyle(const RenderStyle* style) 
+void RenderSVGBlock::setStyle(PassRefPtr<RenderStyle> style) 
 {
-    const RenderStyle* useStyle = style;
+    RefPtr<RenderStyle> useStyle = style;
 
     // SVG text layout code expects us to be a block-level style element.   
     if (useStyle->display() == NONE)
         setChildrenInline(false);
     else if (useStyle->isDisplayInlineType()) {
-        RenderStyle* newStyle = new (renderArena()) RenderStyle();
-        newStyle->inheritFrom(style);
+        RefPtr<RenderStyle> newStyle = RenderStyle::create();
+        newStyle->inheritFrom(useStyle.get());
         newStyle->setDisplay(BLOCK);
-        useStyle = newStyle;
+        useStyle = newStyle.release();
     }
 
-    RenderBlock::setStyle(useStyle);
+    RenderBlock::setStyle(useStyle.release());
     setReplaced(false);
 
     //FIXME: Once overflow rules are supported by SVG we should
index 3d8a99b..d545fd0 100644 (file)
@@ -33,7 +33,7 @@ class SVGElement;
 class RenderSVGBlock : public RenderBlock {
 public:
     RenderSVGBlock(SVGElement*);
-    virtual void setStyle(const RenderStyle*);
+    virtual void setStyle(PassRefPtr<RenderStyle>);
 };
 
 }
index dc2ff78..b7045d6 100644 (file)
@@ -117,13 +117,11 @@ ScrollbarPart RenderScrollbar::partForStyleResolve()
     return s_styleResolvePart;
 }
 
-RenderStyle* RenderScrollbar::getScrollbarPseudoStyle(ScrollbarPart partType, RenderStyle::PseudoId pseudoId)
+PassRefPtr<RenderStyle> RenderScrollbar::getScrollbarPseudoStyle(ScrollbarPart partType, RenderStyle::PseudoId pseudoId)
 {
     s_styleResolvePart = partType;
     s_styleResolveScrollbar = this;
-    RenderStyle* result = m_owner->getPseudoStyle(pseudoId, m_owner->style(), false);
-    if (result)
-        result->ref();
+    RefPtr<RenderStyle> result = m_owner->getUncachedPseudoStyle(pseudoId, m_owner->style());
     s_styleResolvePart = NoPart;
     s_styleResolveScrollbar = 0;
     return result;
@@ -185,7 +183,7 @@ void RenderScrollbar::updateScrollbarPart(ScrollbarPart partType, bool destroy)
     if (partType == NoPart)
         return;
 
-    RenderStyle* partStyle = !destroy ? getScrollbarPseudoStyle(partType,  pseudoForScrollbarPart(partType)) : 0;
+    RefPtr<RenderStyle> partStyle = !destroy ? getScrollbarPseudoStyle(partType,  pseudoForScrollbarPart(partType)) : 0;
     
     bool needRenderer = !destroy && partStyle && partStyle->display() != NONE && partStyle->visibility() == VISIBLE;
     
@@ -223,10 +221,7 @@ void RenderScrollbar::updateScrollbarPart(ScrollbarPart partType, bool destroy)
     }
     
     if (partRenderer)
-        partRenderer->setStyle(partStyle);
-        
-    if (partStyle)
-        partStyle->deref(m_owner->renderArena());
+        partRenderer->setStyle(partStyle.release());
 }
 
 void RenderScrollbar::paintPart(GraphicsContext* graphicsContext, ScrollbarPart partType, const IntRect& rect)
index 0261c63..ad97001 100644 (file)
@@ -71,7 +71,7 @@ public:
     int minimumThumbLength();
 
 private:
-    RenderStyle* getScrollbarPseudoStyle(ScrollbarPart, RenderStyle::PseudoId);
+    PassRefPtr<RenderStyle> getScrollbarPseudoStyle(ScrollbarPart, RenderStyle::PseudoId);
     void updateScrollbarPart(ScrollbarPart, bool destroy = false);
 
     RenderObject* m_owner;
index a3d0c1f..9c8a390 100644 (file)
@@ -168,24 +168,21 @@ void RenderSlider::styleDidChange(RenderStyle::Diff diff, const RenderStyle* old
 {
     RenderBlock::styleDidChange(diff, oldStyle);
     
-    if (m_thumb) {
-        RenderStyle* thumbStyle = createThumbStyle(style(), m_thumb->renderer()->style());
-        m_thumb->renderer()->setStyle(thumbStyle);
-    }
+    if (m_thumb)
+        m_thumb->renderer()->setStyle(createThumbStyle(style(), m_thumb->renderer()->style()));
         
     setReplaced(isInline());
 }
 
-RenderStyle* RenderSlider::createThumbStyle(const RenderStyle* parentStyle, const RenderStyle* oldStyle)
+PassRefPtr<RenderStyle> RenderSlider::createThumbStyle(const RenderStyle* parentStyle, const RenderStyle* oldStyle)
 {
-    RenderStyle* style;
-
-    RenderStyle* pseudoStyle = getPseudoStyle(RenderStyle::SLIDER_THUMB);
+    RefPtr<RenderStyle> style;
+    RenderStyle* pseudoStyle = getCachedPseudoStyle(RenderStyle::SLIDER_THUMB);
     if (pseudoStyle)
         // We may be sharing style with another slider, but we must not share the thumb style.
-        style = new (renderArena()) RenderStyle(*pseudoStyle);
+        style = RenderStyle::clone(pseudoStyle);
     else
-        style = new (renderArena()) RenderStyle();
+        style = RenderStyle::create();
 
     if (parentStyle)
         style->inheritFrom(parentStyle);
@@ -204,7 +201,7 @@ RenderStyle* RenderSlider::createThumbStyle(const RenderStyle* parentStyle, cons
     else if (parentStyle->appearance() == MediaSliderAppearance)
         style->setAppearance(MediaSliderThumbAppearance);
 
-    return style;
+    return style.release();
 }
 
 void RenderSlider::layout()
@@ -244,9 +241,9 @@ void RenderSlider::updateFromElement()
 {
     if (!m_thumb) {
         m_thumb = new HTMLSliderThumbElement(document(), node());
-        RenderStyle* thumbStyle = createThumbStyle(style());
-        m_thumb->setRenderer(m_thumb->createRenderer(renderArena(), thumbStyle));
-        m_thumb->renderer()->setStyle(thumbStyle);
+        RefPtr<RenderStyle> thumbStyle = createThumbStyle(style());
+        m_thumb->setRenderer(m_thumb->createRenderer(renderArena(), thumbStyle.get()));
+        m_thumb->renderer()->setStyle(thumbStyle.release());
         m_thumb->setAttached();
         m_thumb->setInDocument(true);
         addChild(m_thumb->renderer());
index de6a89f..2667672 100644 (file)
@@ -62,7 +62,7 @@ namespace WebCore {
         virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
     
     private:
-        RenderStyle* createThumbStyle(const RenderStyle* parentStyle, const RenderStyle* oldStyle = 0);
+        PassRefPtr<RenderStyle> createThumbStyle(const RenderStyle* parentStyle, const RenderStyle* oldStyle = 0);
         int trackSize();
 
         RefPtr<HTMLSliderThumbElement> m_thumb;
index 1b58db7..01e420e 100644 (file)
@@ -200,10 +200,10 @@ void RenderTable::addChild(RenderObject* child, RenderObject* beforeChild)
     if (beforeChild && !beforeChild->isTableSection() && beforeChild->style()->display() != TABLE_CAPTION && beforeChild->style()->display() != TABLE_COLUMN_GROUP)
         beforeChild = 0;
     RenderTableSection* section = new (renderArena()) RenderTableSection(document() /* anonymous */);
-    RenderStyle* newStyle = new (renderArena()) RenderStyle();
+    RefPtr<RenderStyle> newStyle = RenderStyle::create();
     newStyle->inheritFrom(style());
     newStyle->setDisplay(TABLE_ROW_GROUP);
-    section->setStyle(newStyle);
+    section->setStyle(newStyle.release());
     addChild(section, beforeChild);
     section->addChild(child);
 }
index db3836d..4e9323d 100644 (file)
@@ -93,10 +93,10 @@ void RenderTableRow::addChild(RenderObject* child, RenderObject* beforeChild)
         }
 
         RenderTableCell* cell = new (renderArena()) RenderTableCell(document() /* anonymous object */);
-        RenderStyle* newStyle = new (renderArena()) RenderStyle();
+        RefPtr<RenderStyle> newStyle = RenderStyle::create();
         newStyle->inheritFrom(style());
         newStyle->setDisplay(TABLE_CELL);
-        cell->setStyle(newStyle);
+        cell->setStyle(newStyle.release());
         addChild(cell, beforeChild);
         cell->addChild(child);
         return;
index 10f8297..eae5713 100644 (file)
@@ -112,10 +112,10 @@ void RenderTableSection::addChild(RenderObject* child, RenderObject* beforeChild
         }
 
         RenderObject* row = new (renderArena()) RenderTableRow(document() /* anonymous table */);
-        RenderStyle* newStyle = new (renderArena()) RenderStyle();
+        RefPtr<RenderStyle> newStyle = RenderStyle::create();
         newStyle->inheritFrom(style());
         newStyle->setDisplay(TABLE_ROW);
-        row->setStyle(newStyle);
+        row->setStyle(newStyle.release());
         addChild(row, beforeChild);
         row->addChild(child);
         return;
index 63e03fa..2d7bd78 100644 (file)
@@ -122,7 +122,7 @@ void RenderTextControl::styleDidChange(RenderStyle::Diff diff, const RenderStyle
 
     if (m_innerText) {
         RenderBlock* textBlockRenderer = static_cast<RenderBlock*>(m_innerText->renderer());
-        RenderStyle* textBlockStyle = createInnerTextStyle(style());
+        RefPtr<RenderStyle> textBlockStyle = createInnerTextStyle(style());
         // We may have set the width and the height in the old style in layout(). Reset them now to avoid
         // getting a spurious layout hint.
         textBlockRenderer->style()->setHeight(Length());
@@ -143,9 +143,9 @@ void RenderTextControl::styleDidChange(RenderStyle::Diff diff, const RenderStyle
     setReplaced(isInline());
 }
 
-RenderStyle* RenderTextControl::createInnerBlockStyle(const RenderStyle* startStyle)
+PassRefPtr<RenderStyle> RenderTextControl::createInnerBlockStyle(const RenderStyle* startStyle)
 {
-    RenderStyle* innerBlockStyle = new (renderArena()) RenderStyle();
+    RefPtr<RenderStyle> innerBlockStyle = RenderStyle::create();
 
     innerBlockStyle->inheritFrom(startStyle);
     innerBlockStyle->setDisplay(BLOCK);
@@ -153,20 +153,20 @@ RenderStyle* RenderTextControl::createInnerBlockStyle(const RenderStyle* startSt
     // We don't want the shadow dom to be editable, so we set this block to read-only in case the input itself is editable.
     innerBlockStyle->setUserModify(READ_ONLY);
 
-    return innerBlockStyle;
+    return innerBlockStyle.release();
 }
 
-RenderStyle* RenderTextControl::createInnerTextStyle(const RenderStyle* startStyle)
+PassRefPtr<RenderStyle> RenderTextControl::createInnerTextStyle(const RenderStyle* startStyle)
 {
     HTMLFormControlElement* element = static_cast<HTMLFormControlElement*>(node());
     bool placeholderShouldBeVisible = !m_multiLine && static_cast<HTMLInputElement*>(element)->placeholderShouldBeVisible();
 
-    RenderStyle* textBlockStyle = 0;
+    RefPtr<RenderStyle> textBlockStyle;
     if (placeholderShouldBeVisible) {
-        RenderStyle* pseudoStyle = getPseudoStyle(RenderStyle::INPUT_PLACEHOLDER);
-        textBlockStyle = new (renderArena()) RenderStyle(*pseudoStyle);
+        RenderStyle* pseudoStyle = getCachedPseudoStyle(RenderStyle::INPUT_PLACEHOLDER);
+        textBlockStyle = RenderStyle::clone(pseudoStyle);
     } else {
-        textBlockStyle = new (renderArena()) RenderStyle();    
+        textBlockStyle = RenderStyle::create();   
         textBlockStyle->inheritFrom(startStyle);
     }
     
@@ -223,46 +223,46 @@ RenderStyle* RenderTextControl::createInnerTextStyle(const RenderStyle* startSty
     if (!element->isEnabled())
         textBlockStyle->setColor(disabledTextColor(textBlockStyle->color(), startStyle->backgroundColor()));
 
-    return textBlockStyle;
+    return textBlockStyle.release();
 }
 
-RenderStyle* RenderTextControl::createResultsButtonStyle(const RenderStyle* startStyle)
+PassRefPtr<RenderStyle> RenderTextControl::createResultsButtonStyle(const RenderStyle* startStyle)
 {
     ASSERT(!m_multiLine);
     HTMLInputElement* input = static_cast<HTMLInputElement*>(node());
-    RenderStyle* resultsBlockStyle;
+    RefPtr<RenderStyle> resultsBlockStyle;
     if (input->maxResults() < 0)
-        resultsBlockStyle = getPseudoStyle(RenderStyle::SEARCH_DECORATION);
+        resultsBlockStyle = getCachedPseudoStyle(RenderStyle::SEARCH_DECORATION);
     else if (!input->maxResults())
-        resultsBlockStyle = getPseudoStyle(RenderStyle::SEARCH_RESULTS_DECORATION);
+        resultsBlockStyle = getCachedPseudoStyle(RenderStyle::SEARCH_RESULTS_DECORATION);
     else
-        resultsBlockStyle = getPseudoStyle(RenderStyle::SEARCH_RESULTS_BUTTON);
+        resultsBlockStyle = getCachedPseudoStyle(RenderStyle::SEARCH_RESULTS_BUTTON);
 
     if (!resultsBlockStyle)
-        resultsBlockStyle = new (renderArena()) RenderStyle();
+        resultsBlockStyle = RenderStyle::create();
 
     if (startStyle)
         resultsBlockStyle->inheritFrom(startStyle);
 
-    return resultsBlockStyle;
+    return resultsBlockStyle.release();
 }
 
-RenderStyle* RenderTextControl::createCancelButtonStyle(const RenderStyle* startStyle)
+PassRefPtr<RenderStyle> RenderTextControl::createCancelButtonStyle(const RenderStyle* startStyle)
 {
-    RenderStyle* cancelBlockStyle;
+    RefPtr<RenderStyle> cancelBlockStyle;
     
-    if (RenderStyle* pseudoStyle = getPseudoStyle(RenderStyle::SEARCH_CANCEL_BUTTON))
+    if (RefPtr<RenderStyle> pseudoStyle = getCachedPseudoStyle(RenderStyle::SEARCH_CANCEL_BUTTON))
         // We may be sharing style with another search field, but we must not share the cancel button style.
-        cancelBlockStyle = new (renderArena()) RenderStyle(*pseudoStyle);
+        cancelBlockStyle = RenderStyle::clone(pseudoStyle.get());
     else
-        cancelBlockStyle = new (renderArena()) RenderStyle();
+        cancelBlockStyle = RenderStyle::create();
 
     if (startStyle)
         cancelBlockStyle->inheritFrom(startStyle);
 
-    updateCancelButtonVisibility(cancelBlockStyle);
+    updateCancelButtonVisibility(cancelBlockStyle.get());
 
-    return cancelBlockStyle;
+    return cancelBlockStyle.release();
 }
 
 void RenderTextControl::createSubtreeIfNeeded()
@@ -271,18 +271,12 @@ void RenderTextControl::createSubtreeIfNeeded()
     if (isSearchField && !m_innerBlock) {
         // Create the inner block element
         m_innerBlock = new TextControlInnerElement(document(), node());
-        RenderStyle* innerBlockStyle = createInnerBlockStyle(style());
-        innerBlockStyle->ref();
-        m_innerBlock->attachInnerElement(node(), innerBlockStyle, renderArena());
-        innerBlockStyle->deref(renderArena());
+        m_innerBlock->attachInnerElement(node(), createInnerBlockStyle(style()), renderArena());
     }
     if (isSearchField && !m_resultsButton) {
         // Create the search results button element
         m_resultsButton = new SearchFieldResultsButtonElement(document());
-        RenderStyle* resultsButtonStyle = createResultsButtonStyle(m_innerBlock->renderer()->style());
-        resultsButtonStyle->ref();
-        m_resultsButton->attachInnerElement(m_innerBlock.get(), resultsButtonStyle, renderArena());
-        resultsButtonStyle->deref(renderArena());
+        m_resultsButton->attachInnerElement(m_innerBlock.get(), createResultsButtonStyle(m_innerBlock->renderer()->style()), renderArena());
     }
     if (!m_innerText) {
         // Create the text block element
@@ -292,19 +286,13 @@ void RenderTextControl::createSubtreeIfNeeded()
         RenderStyle* parentStyle = style();
         if (m_innerBlock)
             parentStyle = m_innerBlock->renderer()->style();
-        RenderStyle* textBlockStyle = createInnerTextStyle(parentStyle);
-        textBlockStyle->ref();
         m_innerText = new TextControlInnerTextElement(document(), m_innerBlock ? 0 : node());
-        m_innerText->attachInnerElement(m_innerBlock ? m_innerBlock.get() : node(), textBlockStyle, renderArena());
-        textBlockStyle->deref(renderArena());
+        m_innerText->attachInnerElement(m_innerBlock ? m_innerBlock.get() : node(), createInnerTextStyle(parentStyle), renderArena());
     }
     if (isSearchField && !m_cancelButton) {
         // Create the cancel button element
         m_cancelButton = new SearchFieldCancelButtonElement(document());
-        RenderStyle* cancelButtonStyle = createCancelButtonStyle(m_innerBlock->renderer()->style());
-        cancelButtonStyle->ref();
-        m_cancelButton->attachInnerElement(m_innerBlock.get(), cancelButtonStyle, renderArena());
-        cancelButtonStyle->deref(renderArena());
+        m_cancelButton->attachInnerElement(m_innerBlock.get(), createCancelButtonStyle(m_innerBlock->renderer()->style()), renderArena());
     }
 }
 
@@ -1190,14 +1178,12 @@ FontSelector* RenderTextControl::fontSelector() const
 void RenderTextControl::updatePlaceholderVisibility()
 {
     RenderStyle* parentStyle = m_innerBlock ? m_innerBlock->renderer()->style() : style();
-    RenderStyle* textBlockStyle = createInnerTextStyle(parentStyle);
-    textBlockStyle->ref();
+    RefPtr<RenderStyle> textBlockStyle = createInnerTextStyle(parentStyle);
     m_innerText->renderer()->setStyle(textBlockStyle);
     for (Node* n = m_innerText->firstChild(); n; n = n->traverseNextNode(m_innerText.get())) {
         if (n->renderer())
             n->renderer()->setStyle(textBlockStyle);
     }
-    textBlockStyle->deref(renderArena());
     updateFromElement();
 }
 
index 04163b2..74fdd26 100644 (file)
@@ -132,10 +132,10 @@ private:
     virtual HostWindow* hostWindow() const;
     virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize);
 
-    RenderStyle* createInnerBlockStyle(const RenderStyle* startStyle);
-    RenderStyle* createInnerTextStyle(const RenderStyle* startStyle);
-    RenderStyle* createCancelButtonStyle(const RenderStyle* startStyle);
-    RenderStyle* createResultsButtonStyle(const RenderStyle* startStyle);
+    PassRefPtr<RenderStyle> createInnerBlockStyle(const RenderStyle* startStyle);
+    PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle);
+    PassRefPtr<RenderStyle> createCancelButtonStyle(const RenderStyle* startStyle);
+    PassRefPtr<RenderStyle> createResultsButtonStyle(const RenderStyle* startStyle);
 
     void createSubtreeIfNeeded();
     void updateCancelButtonVisibility(RenderStyle*);
index 55969c6..26571b8 100644 (file)
@@ -59,13 +59,13 @@ TextControlInnerElement::TextControlInnerElement(Document* doc, Node* shadowPare
 {
 }
 
-void TextControlInnerElement::attachInnerElement(Node* parent, RenderStyle* style, RenderArena* arena)
+void TextControlInnerElement::attachInnerElement(Node* parent, PassRefPtr<RenderStyle> style, RenderArena* arena)
 {
     // When adding these elements, create the renderer & style first before adding to the DOM.
     // Otherwise, the render tree will create some anonymous blocks that will mess up our layout.
 
     // Create the renderer with the specified style
-    RenderObject* renderer = createRenderer(arena, style);
+    RenderObject* renderer = createRenderer(arena, style.get());
     if (renderer) {
         setRenderer(renderer);
         renderer->setStyle(style);
index df5757a..9e81ada 100644 (file)
@@ -41,7 +41,7 @@ public:
     virtual bool isShadowNode() const { return m_shadowParent; }
     virtual Node* shadowParentNode() { return m_shadowParent; }
     void setShadowParentNode(Node* node) { m_shadowParent = node; }
-    void attachInnerElement(Node*, RenderStyle*, RenderArena*);
+    void attachInnerElement(Node*, PassRefPtr<RenderStyle>, RenderArena*);
     
 private:
     Node* m_shadowParent;
index e1f8b47..41fbbe2 100644 (file)
@@ -32,10 +32,6 @@ KeyframeList::~KeyframeList()
 
 void KeyframeList::clear()
 {
-    for (Vector<KeyframeValue>::const_iterator it = m_keyframes.begin(); it != m_keyframes.end(); ++it)
-        if (it->style)
-            it->style->deref(m_renderer->renderArena());
-
     m_keyframes.clear();
     m_properties.clear();
 }
@@ -47,11 +43,11 @@ bool KeyframeList::operator==(const KeyframeList& o) const
 
     Vector<KeyframeValue>::const_iterator it2 = o.m_keyframes.begin();
     for (Vector<KeyframeValue>::const_iterator it1 = m_keyframes.begin(); it1 != m_keyframes.end(); ++it1) {
-        if (it1->key != it2->key)
+        if (it1->m_key != it2->m_key)
             return false;
-        const RenderStyle& style1 = it1->style;
-        const RenderStyle& style2 = it2->style;
-        if (!(style1 == style2))
+        const RenderStyle& style1 = *it1->m_style;
+        const RenderStyle& style2 = *it2->m_style;
+        if (style1 != style2)
             return false;
         ++it2;
     }
@@ -59,7 +55,7 @@ bool KeyframeList::operator==(const KeyframeList& o) const
     return true;
 }
 
-void KeyframeList::insert(float key, RenderStyle* style)
+void KeyframeList::insert(float key, PassRefPtr<RenderStyle> style)
 {
     if (key < 0 || key > 1)
         return;
@@ -67,11 +63,11 @@ void KeyframeList::insert(float key, RenderStyle* style)
     int index = -1;
     
     for (size_t i = 0; i < m_keyframes.size(); ++i) {
-        if (m_keyframes[i].key == key) {
+        if (m_keyframes[i].m_key == key) {
             index = (int) i;
             break;
         }
-        if (m_keyframes[i].key > key) {
+        if (m_keyframes[i].m_key > key) {
             // insert before
             m_keyframes.insert(i, KeyframeValue());
             index = (int) i;
@@ -85,12 +81,8 @@ void KeyframeList::insert(float key, RenderStyle* style)
         m_keyframes.append(KeyframeValue());
     }
     
-    if (style)
-        style->ref();
-    if (m_keyframes[index].style)
-        m_keyframes[index].style->deref(m_renderer->renderArena());
-    m_keyframes[index].key = key;
-    m_keyframes[index].style = style;
+    m_keyframes[index].m_key = key;
+    m_keyframes[index].m_style = style;
 }
 
 } // namespace WebCore
index 11c0250..b1009d2 100644 (file)
@@ -28,6 +28,7 @@
 #include "AtomicString.h"
 #include <wtf/Vector.h>
 #include <wtf/HashSet.h>
+#include <wtf/RefPtr.h>
 
 namespace WebCore {
 
@@ -37,13 +38,15 @@ class RenderStyle;
 class KeyframeValue {
 public:
     KeyframeValue()
-        : key(-1)
-        , style(0)
+        : m_key(-1)
     {
     }
 
-    float key;
-    RenderStyle* style;
+    float key() const { return m_key; }
+    const RenderStyle* style() const { return m_style.get(); }
+
+    float m_key;
+    RefPtr<RenderStyle> m_style;
 };
 
 class KeyframeList {
@@ -62,7 +65,7 @@ public:
     
     const AtomicString& animationName() const { return m_animationName; }
     
-    void insert(float key, RenderStyle* style);
+    void insert(float key, PassRefPtr<RenderStyle> style);
     
     void addProperty(int prop) { m_properties.add(prop); }
     bool containsProperty(int prop) const { return m_properties.contains(prop); }
index b55d744..6e8b7b9 100644 (file)
 
 namespace WebCore {
 
-static RenderStyle* defaultStyle;
-
-void* RenderStyle::operator new(size_t sz, RenderArena* renderArena) throw()
+inline RenderStyle* defaultStyle()
 {
-    return renderArena->allocate(sz);
+    static RenderStyle* s_defaultStyle = RenderStyle::createDefaultStyle().releaseRef();
+    return s_defaultStyle;
 }
 
-void RenderStyle::operator delete(void* ptr, size_t sz)
+PassRefPtr<RenderStyle> RenderStyle::create()
 {
-    // Stash size where destroy can find it.
-    *(size_t *)ptr = sz;
+    return adoptRef(new RenderStyle());
 }
 
-void RenderStyle::arenaDelete(RenderArena *arena)
+PassRefPtr<RenderStyle> RenderStyle::createDefaultStyle()
 {
-    RenderStyle* ps = pseudoStyle;
-    RenderStyle* prev = 0;
-
-    while (ps) {
-        prev = ps;
-        ps = ps->pseudoStyle;
-        // to prevent a double deletion.
-        // this works only because the styles below aren't really shared
-        // Dirk said we need another construct as soon as these are shared
-        prev->pseudoStyle = 0;
-        prev->deref(arena);
-    }
-    delete this;
-
-    // Recover the size left there for us by operator delete and free the memory.
-    arena->free(*(size_t *)this, this);
+    return adoptRef(new RenderStyle(true));
 }
 
-inline RenderStyle* initDefaultStyle()
+PassRefPtr<RenderStyle> RenderStyle::clone(const RenderStyle* other)
 {
-    if (!defaultStyle)
-        defaultStyle = ::new RenderStyle(true);
-    return defaultStyle;
+    return adoptRef(new RenderStyle(*other));
 }
 
 RenderStyle::RenderStyle()
-    : box(initDefaultStyle()->box)
-    , visual(defaultStyle->visual)
-    , background(defaultStyle->background)
-    , surround(defaultStyle->surround)
-    , rareNonInheritedData(defaultStyle->rareNonInheritedData)
-    , rareInheritedData(defaultStyle->rareInheritedData)
-    , inherited(defaultStyle->inherited)
-    , pseudoStyle(0)
+    : box(defaultStyle()->box)
+    , visual(defaultStyle()->visual)
+    , background(defaultStyle()->background)
+    , surround(defaultStyle()->surround)
+    , rareNonInheritedData(defaultStyle()->rareNonInheritedData)
+    , rareInheritedData(defaultStyle()->rareInheritedData)
+    , inherited(defaultStyle()->inherited)
     , m_pseudoState(PseudoUnknown)
     , m_affectedByAttributeSelectors(false)
     , m_unique(false)
@@ -95,17 +75,15 @@ RenderStyle::RenderStyle()
     , m_firstChildState(false)
     , m_lastChildState(false)
     , m_childIndex(0)
-    , m_ref(0)
 #if ENABLE(SVG)
-    , m_svgStyle(defaultStyle->m_svgStyle)
+    , m_svgStyle(defaultStyle()->m_svgStyle)
 #endif
 {
     setBitDefaults(); // Would it be faster to copy this from the default style?
 }
 
 RenderStyle::RenderStyle(bool)
-    : pseudoStyle(0)
-    , m_pseudoState(PseudoUnknown)
+    : m_pseudoState(PseudoUnknown)
     , m_affectedByAttributeSelectors(false)
     , m_unique(false)
     , m_affectedByEmpty(false)
@@ -118,7 +96,6 @@ RenderStyle::RenderStyle(bool)
     , m_firstChildState(false)
     , m_lastChildState(false)
     , m_childIndex(0)
-    , m_ref(1)
 {
     setBitDefaults();
 
@@ -140,7 +117,8 @@ RenderStyle::RenderStyle(bool)
 }
 
 RenderStyle::RenderStyle(const RenderStyle& o)
-    : inherited_flags(o.inherited_flags)
+    : RefCounted<RenderStyle>()
+    , inherited_flags(o.inherited_flags)
     , noninherited_flags(o.noninherited_flags)
     , box(o.box)
     , visual(o.visual)
@@ -149,7 +127,6 @@ RenderStyle::RenderStyle(const RenderStyle& o)
     , rareNonInheritedData(o.rareNonInheritedData)
     , rareInheritedData(o.rareInheritedData)
     , inherited(o.inherited)
-    , pseudoStyle(0)
     , m_pseudoState(o.m_pseudoState)
     , m_affectedByAttributeSelectors(false)
     , m_unique(false)
@@ -163,7 +140,6 @@ RenderStyle::RenderStyle(const RenderStyle& o)
     , m_firstChildState(false)
     , m_lastChildState(false)
     , m_childIndex(0)
-    , m_ref(0)
 #if ENABLE(SVG)
     , m_svgStyle(o.m_svgStyle)
 #endif
@@ -227,23 +203,23 @@ void RenderStyle::setHasPseudoStyle(PseudoId pseudo)
     noninherited_flags._pseudoBits |= pseudoBit(pseudo);
 }
 
-RenderStyle* RenderStyle::getPseudoStyle(PseudoId pid)
+RenderStyle* RenderStyle::getCachedPseudoStyle(PseudoId pid)
 {
-    if (!pseudoStyle || styleType() != NOPSEUDO)
+    if (!m_cachedPseudoStyle || styleType() != NOPSEUDO)
         return 0;
-    RenderStyle* ps = pseudoStyle;
+    RenderStyle* ps = m_cachedPseudoStyle.get();
     while (ps && ps->styleType() != pid)
-        ps = ps->pseudoStyle;
+        ps = ps->m_cachedPseudoStyle.get();
     return ps;
 }
 
-void RenderStyle::addPseudoStyle(RenderStyle* pseudo)
+RenderStyle* RenderStyle::addCachedPseudoStyle(PassRefPtr<RenderStyle> pseudo)
 {
     if (!pseudo)
-        return;
-    pseudo->ref();
-    pseudo->pseudoStyle = pseudoStyle;
-    pseudoStyle = pseudo;
+        return 0;
+    pseudo->m_cachedPseudoStyle = m_cachedPseudoStyle;
+    m_cachedPseudoStyle = pseudo;
+    return m_cachedPseudoStyle.get();
 }
 
 bool RenderStyle::inheritedNotEqual(RenderStyle* other) const
index 67d0bf8..3d1711b 100644 (file)
@@ -97,11 +97,10 @@ class CSSStyleSelector;
 class CSSValueList;
 class CachedImage;
 class Pair;
-class RenderArena;
 class StringImpl;
 class StyleImage;
 
-class RenderStyle {
+class RenderStyle: public RefCounted<RenderStyle> {
     friend class CSSStyleSelector;
 
 public:
@@ -113,27 +112,6 @@ public:
                     SCROLLBAR_THUMB, SCROLLBAR_BUTTON, SCROLLBAR_TRACK, SCROLLBAR_TRACK_PIECE, SCROLLBAR_CORNER, RESIZER };
     static const int FIRST_INTERNAL_PSEUDOID = FILE_UPLOAD_BUTTON;
 
-    void ref() { m_ref++; }
-    void deref(RenderArena* arena)
-    {
-        if (m_ref)
-            m_ref--;
-        if (!m_ref)
-            arenaDelete(arena);
-    }
-    bool hasOneRef() { return m_ref == 1; }
-    int refCount() const { return m_ref; }
-
-    // Overloaded new operator.  Derived classes must override operator new
-    // in order to allocate out of the RenderArena.
-    void* operator new(size_t sz, RenderArena* renderArena) throw();
-
-    // Overridden to prevent the normal delete from being called.
-    void operator delete(void* ptr, size_t sz);
-
-private:
-    void arenaDelete(RenderArena*);
-
 protected:
 
 // !START SYNC!: Keep this in sync with the copy constructor in RenderStyle.cpp
@@ -241,7 +219,7 @@ protected:
     DataRef<StyleInheritedData> inherited;
 
     // list of associated pseudo styles
-    RenderStyle* pseudoStyle;
+    RefPtr<RenderStyle> m_cachedPseudoStyle;
 
     unsigned m_pseudoState : 3; // PseudoState
     bool m_affectedByAttributeSelectors : 1;
@@ -262,8 +240,6 @@ protected:
     bool m_lastChildState : 1;
     unsigned m_childIndex : 18; // Plenty of bits to cache an index.
 
-    int m_ref;
-
 #if ENABLE(SVG)
     DataRef<SVGRenderStyle> m_svgStyle;
 #endif
@@ -308,12 +284,17 @@ protected:
         noninherited_flags._unicodeBidi = initialUnicodeBidi();
     }
 
-public:
+protected:
     RenderStyle();
     // used to create the default style.
     RenderStyle(bool);
     RenderStyle(const RenderStyle&);
 
+public:
+    static PassRefPtr<RenderStyle> create();
+    static PassRefPtr<RenderStyle> createDefaultStyle();
+    static PassRefPtr<RenderStyle> clone(const RenderStyle*);
+
     ~RenderStyle();
 
     void inheritFrom(const RenderStyle* inheritParent);
@@ -321,8 +302,8 @@ public:
     PseudoId styleType() { return static_cast<PseudoId>(noninherited_flags._styleType); }
     void setStyleType(PseudoId styleType) { noninherited_flags._styleType = styleType; }
 
-    RenderStyle* getPseudoStyle(PseudoId pi);
-    void addPseudoStyle(RenderStyle* pseudo);
+    RenderStyle* getCachedPseudoStyle(PseudoId);
+    RenderStyle* addCachedPseudoStyle(PassRefPtr<RenderStyle>);
 
     bool affectedByHoverRules() const { return noninherited_flags._affectedByHover; }
     bool affectedByActiveRules() const { return noninherited_flags._affectedByActive; }
@@ -333,6 +314,7 @@ public:
     void setAffectedByDragRules(bool b) { noninherited_flags._affectedByDrag = b; }
 
     bool operator==(const RenderStyle& other) const;
+    bool operator!=(const RenderStyle& other) const { return !(*this == other); }
     bool isFloating() const { return !(noninherited_flags._floating == FNONE); }
     bool hasMargin() const { return surround->margin.nonZero(); }
     bool hasBorder() const { return surround->border.hasBorder(); }
@@ -892,7 +874,7 @@ public:
     void setBoxOrient(EBoxOrient o) { SET_VAR(rareNonInheritedData.access()->flexibleBox, orient, o); }
     void setBoxPack(EBoxAlignment p) { SET_VAR(rareNonInheritedData.access()->flexibleBox, pack, p); }
     void setBoxShadow(ShadowData* val, bool add=false);
-    void setBoxReflect(const PassRefPtr<StyleReflection>& reflect) { if (rareNonInheritedData->m_boxReflect != reflect) rareNonInheritedData.access()->m_boxReflect = reflect; }
+    void setBoxReflect(PassRefPtr<StyleReflection> reflect) { if (rareNonInheritedData->m_boxReflect != reflect) rareNonInheritedData.access()->m_boxReflect = reflect; }
     void setBoxSizing(EBoxSizing s) { SET_VAR(box, boxSizing, s); }
     void setMarqueeIncrement(const Length& f) { SET_VAR(rareNonInheritedData.access()->marquee, increment, f); }
     void setMarqueeSpeed(int f) { SET_VAR(rareNonInheritedData.access()->marquee, speed, f); }
index 268cf9c..ec76c4e 100644 (file)
@@ -98,17 +98,16 @@ SVGResource* SVGClipPathElement::canvasResource()
 
     bool bbox = clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
 
-    RenderStyle* clipPathStyle = styleForRenderer(parent()->renderer()); // FIXME: Manual style resolution is a hack
+    RefPtr<RenderStyle> clipPathStyle = styleForRenderer(parent()->renderer()); // FIXME: Manual style resolution is a hack
     for (Node* n = firstChild(); n; n = n->nextSibling()) {
         if (n->isSVGElement() && static_cast<SVGElement*>(n)->isStyledTransformable()) {
             SVGStyledTransformableElement* styled = static_cast<SVGStyledTransformableElement*>(n);
-            RenderStyle* pathStyle = document()->styleSelector()->styleForElement(styled, clipPathStyle);
+            RefPtr<RenderStyle> pathStyle = document()->styleSelector()->styleForElement(styled, clipPathStyle.get());
             if (pathStyle->display() != NONE) {
                 Path pathData = styled->toClipPath();
                 if (!pathData.isEmpty())
                     m_clipper->addClipData(pathData, pathStyle->svgStyle()->clipRule(), bbox);
             }
-            pathStyle->deref(document()->renderArena());
         }
     }
     if (m_clipper->clipData().isEmpty()) {
@@ -116,7 +115,6 @@ SVGResource* SVGClipPathElement::canvasResource()
         pathData.addRect(FloatRect());
         m_clipper->addClipData(pathData, RULE_EVENODD, bbox);
     }
-    clipPathStyle->deref(document()->renderArena());
     return m_clipper.get();
 }
 
index 042aab8..36e49ea 100644 (file)
@@ -128,7 +128,7 @@ SVGResource* SVGGradientElement::canvasResource()
 Vector<SVGGradientStop> SVGGradientElement::buildStops() const
 {
     Vector<SVGGradientStop> stops;
-    RenderStyle* gradientStyle = 0;
+    RefPtr<RenderStyle> gradientStyle;
 
     for (Node* n = firstChild(); n; n = n->nextSibling()) {
         SVGElement* element = n->isSVGElement() ? static_cast<SVGElement*>(n) : 0;
@@ -151,21 +151,16 @@ Vector<SVGGradientStop> SVGGradientElement::buildStops() const
                 if (!gradientStyle)
                     gradientStyle = const_cast<SVGGradientElement*>(this)->styleForRenderer(parent()->renderer());
 
-                RenderStyle* stopStyle = stop->resolveStyle(gradientStyle);
+                RefPtr<RenderStyle> stopStyle = stop->resolveStyle(gradientStyle.get());
 
                 color = stopStyle->svgStyle()->stopColor();
                 opacity = stopStyle->svgStyle()->stopOpacity();
-
-                stopStyle->deref(document()->renderArena());
             }
 
             stops.append(makeGradientStop(stopOffset, makeRGBA(color.red(), color.green(), color.blue(), int(opacity * 255.))));
         }
     }
 
-    if (gradientStyle)
-        gradientStyle->deref(document()->renderArena());
-
     return stops;
 }
 
index 63fa428..466ce3c 100644 (file)
@@ -231,14 +231,10 @@ void SVGStyledElement::childrenChanged(bool changedByParser, Node* beforeChange,
     SVGElementInstance::invalidateAllInstancesOfElement(this);
 }
 
-RenderStyle* SVGStyledElement::resolveStyle(RenderStyle* parentStyle)
+PassRefPtr<RenderStyle> SVGStyledElement::resolveStyle(RenderStyle* parentStyle)
 {
-    if (renderer()) {
-        RenderStyle* renderStyle = renderer()->style();
-        renderStyle->ref();
-        return renderStyle;
-    }
-
+    if (renderer())
+        return renderer()->style();
     return document()->styleSelector()->styleForElement(this, parentStyle);
 }
 
index 1ed6d33..e21db97 100644 (file)
@@ -58,7 +58,7 @@ namespace WebCore {
         virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
 
         // Centralized place to force a manual style resolution. Hacky but needed for now.
-        RenderStyle* resolveStyle(RenderStyle* parentStyle);
+        PassRefPtr<RenderStyle> resolveStyle(RenderStyle* parentStyle);
 
         void invalidateResourcesInAncestorChain() const;        
         virtual void detach();
index d715fb6..f27793d 100644 (file)
@@ -187,8 +187,8 @@ void SVGUseElement::recalcStyle(StyleChange change)
     // shadow tree root element, but call attachShadowTree() here. Calling attach() will crash
     // as the shadow tree root element has no (direct) parent node. Yes, shadow trees are tricky.
     if (change >= Inherit || m_shadowTreeRootElement->changed()) {
-        RenderStyle* newStyle = document()->styleSelector()->styleForElement(m_shadowTreeRootElement.get());
-        StyleChange ch = Node::diff(m_shadowTreeRootElement->renderStyle(), newStyle);
+        RefPtr<RenderStyle> newStyle = document()->styleSelector()->styleForElement(m_shadowTreeRootElement.get());
+        StyleChange ch = Node::diff(m_shadowTreeRootElement->renderStyle(), newStyle.get());
         if (ch == Detach) {
             ASSERT(m_shadowTreeRootElement->attached());
             m_shadowTreeRootElement->detach();
@@ -197,11 +197,8 @@ void SVGUseElement::recalcStyle(StyleChange change)
             // attach recalulates the style for all children. No need to do it twice.
             m_shadowTreeRootElement->setChanged(NoStyleChange);
             m_shadowTreeRootElement->setHasChangedChild(false);
-            newStyle->deref(document()->renderArena());
             return;
         }
-
-        newStyle->deref(document()->renderArena());
     }
 
     // Only change==Detach needs special treatment, for anything else recalcStyle() works.
@@ -744,19 +741,17 @@ void SVGUseElement::attachShadowTree()
 
     // Inspired by RenderTextControl::createSubtreeIfNeeded(). 
     if (renderer()->canHaveChildren() && childShouldCreateRenderer(m_shadowTreeRootElement.get())) {
-        RenderStyle* style = m_shadowTreeRootElement->styleForRenderer(renderer());
+        RefPtr<RenderStyle> style = m_shadowTreeRootElement->styleForRenderer(renderer());
 
-        if (m_shadowTreeRootElement->rendererIsNeeded(style)) {
-            m_shadowTreeRootElement->setRenderer(m_shadowTreeRootElement->createRenderer(document()->renderArena(), style));
+        if (m_shadowTreeRootElement->rendererIsNeeded(style.get())) {
+            m_shadowTreeRootElement->setRenderer(m_shadowTreeRootElement->createRenderer(document()->renderArena(), style.get()));
             if (RenderObject* shadowRenderer = m_shadowTreeRootElement->renderer()) {
-                shadowRenderer->setStyle(style);
+                shadowRenderer->setStyle(style.release());
                 renderer()->addChild(shadowRenderer, m_shadowTreeRootElement->nextRenderer());
                 m_shadowTreeRootElement->setAttached();
             }
         }
 
-        style->deref(document()->renderArena());
-
         // This will take care of attaching all shadow tree child nodes.
         for (Node* child = m_shadowTreeRootElement->firstChild(); child; child = child->nextSibling())
             child->attach();