Commit dec0cbf2 authored by hyatt@apple.com's avatar hyatt@apple.com

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):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@37637 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2c7cec41
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.
......
......@@ -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); }
......
This diff is collapsed.
......@@ -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;
......
......@@ -30,7 +30,7 @@
namespace WebCore {
CSSVariableDependentValue::CSSVariableDependentValue(const PassRefPtr<CSSValueList>& list)
CSSVariableDependentValue::CSSVariableDependentValue(PassRefPtr<CSSValueList> list)
: m_list(list)
{
}
......
......@@ -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;
};
......
......@@ -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())
......
......@@ -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()
......
......@@ -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);
......
......@@ -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();
}
}
......
......@@ -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);
......
......@@ -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();
......
......@@ -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();
......
......@@ -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
......
......@@ -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();