2008-10-09 Simon Fraser <simon.fraser@apple.com>

        Reviewed by Dave Hyatt

        https://bugs.webkit.org/show_bug.cgi?id=20947

        Refactor setStyle() methods into styleWillChange()
        and styleDidChange(), so most of the setStyle() overrides can
        be removed.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@37464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b2063c19
2008-10-09 Simon Fraser <simon.fraser@apple.com>
Reviewed by Dave Hyatt
https://bugs.webkit.org/show_bug.cgi?id=20947
Refactor setStyle() methods into styleWillChange()
and styleDidChange(), so most of the setStyle() overrides can
be removed.
* rendering/RenderBR.cpp:
(WebCore::RenderBR::styleDidChange):
* rendering/RenderBR.h:
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::styleWillChange):
(WebCore::RenderBlock::styleDidChange):
* rendering/RenderBlock.h:
* rendering/RenderBox.cpp:
(WebCore::RenderBox::~RenderBox):
(WebCore::RenderBox::destroy):
(WebCore::RenderBox::styleWillChange):
(WebCore::RenderBox::styleDidChange):
* rendering/RenderBox.h:
* rendering/RenderButton.cpp:
(WebCore::RenderButton::styleWillChange):
(WebCore::RenderButton::styleDidChange):
* rendering/RenderButton.h:
* rendering/RenderFieldset.cpp:
(WebCore::RenderFieldset::styleDidChange):
* rendering/RenderFieldset.h:
* rendering/RenderFileUploadControl.cpp:
(WebCore::RenderFileUploadControl::styleDidChange):
* rendering/RenderFileUploadControl.h:
* rendering/RenderInline.cpp:
(WebCore::RenderInline::styleDidChange):
* rendering/RenderInline.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::styleChanged):
* rendering/RenderLayer.h:
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::styleDidChange):
* rendering/RenderListBox.h:
* rendering/RenderListItem.cpp:
(WebCore::RenderListItem::styleDidChange):
* rendering/RenderListItem.h:
* rendering/RenderListMarker.cpp:
(WebCore::RenderListMarker::styleWillChange):
(WebCore::RenderListMarker::styleDidChange):
* rendering/RenderListMarker.h:
* rendering/RenderMenuList.cpp:
(WebCore::RenderMenuList::styleDidChange):
* rendering/RenderMenuList.h:
* rendering/RenderObject.cpp:
(WebCore::RenderObject::setStyle):
(WebCore::RenderObject::setStyleInternal):
(WebCore::RenderObject::styleWillChange):
(WebCore::RenderObject::styleDidChange):
* rendering/RenderObject.h:
* rendering/RenderReplaced.cpp:
(WebCore::RenderReplaced::styleDidChange):
* rendering/RenderReplaced.h:
* rendering/RenderSVGGradientStop.cpp:
(WebCore::RenderSVGGradientStop::styleDidChange):
* rendering/RenderSVGGradientStop.h:
* rendering/RenderScrollbarPart.cpp:
(WebCore::RenderScrollbarPart::styleDidChange):
* rendering/RenderScrollbarPart.h:
* rendering/RenderSlider.cpp:
(WebCore::RenderSlider::styleDidChange):
* rendering/RenderSlider.h:
* rendering/RenderTable.cpp:
(WebCore::RenderTable::styleDidChange):
* rendering/RenderTable.h:
* rendering/RenderTableCell.cpp:
(WebCore::RenderTableCell::styleWillChange):
(WebCore::RenderTableCell::styleDidChange):
* rendering/RenderTableCell.h:
* rendering/RenderTableRow.cpp:
(WebCore::RenderTableRow::styleWillChange):
* rendering/RenderTableRow.h:
* rendering/RenderText.cpp:
(WebCore::RenderText::styleDidChange):
* rendering/RenderText.h:
* rendering/RenderTextControl.cpp:
(WebCore::RenderTextControl::styleDidChange):
* rendering/RenderTextControl.h:
* rendering/RenderWidget.cpp:
(WebCore::RenderWidget::styleDidChange):
* rendering/RenderWidget.h:
2008-10-09 David Hyatt <hyatt@apple.com>
Make sure to destroy a custom scrollbar's RenderObject's before the arena goes away. When our widget
......
......@@ -82,9 +82,9 @@ int RenderBR::lineHeight(bool firstLine, bool isRootLineBox) const
return m_lineHeight;
}
void RenderBR::setStyle(const RenderStyle* newStyle)
void RenderBR::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
{
RenderText::setStyle(newStyle);
RenderText::styleDidChange(diff, oldStyle);
m_lineHeight = -1;
}
......
......@@ -47,7 +47,6 @@ public:
virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const;
virtual int baselinePosition(bool firstLine, bool isRootLineBox = false) const;
virtual void setStyle(const RenderStyle*);
// overrides
virtual InlineBox* createInlineBox(bool, bool, bool isOnlyRun = false);
......@@ -60,6 +59,9 @@ public:
virtual VisiblePosition positionForCoordinates(int x, int y);
protected:
virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
private:
mutable int m_lineHeight;
};
......
......@@ -146,11 +146,15 @@ RenderBlock::~RenderBlock()
}
}
void RenderBlock::setStyle(const RenderStyle* newStyle)
void RenderBlock::styleWillChange(RenderStyle::Diff diff, const RenderStyle* newStyle)
{
setReplaced(newStyle->isDisplayReplacedType());
RenderFlow::styleWillChange(diff, newStyle);
}
RenderFlow::setStyle(newStyle);
void RenderBlock::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
{
RenderFlow::styleDidChange(diff, oldStyle);
// FIXME: We could save this call when the change only affected non-inherited properties
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
......
......@@ -106,8 +106,6 @@ public:
virtual void repaintOverhangingFloats(bool paintAllDescendants);
virtual void setStyle(const RenderStyle*);
virtual void layout();
virtual void layoutBlock(bool relayoutChildren);
void layoutBlockChildren(bool relayoutChildren, int& maxFloatBottom);
......@@ -313,6 +311,9 @@ private:
void markLinesDirtyInVerticalRange(int top, int bottom);
protected:
virtual void styleWillChange(RenderStyle::Diff, const RenderStyle* newStyle);
virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
void newLine(EClear);
virtual bool hasLineIfEmpty() const;
bool layoutOnlyPositionedObjects();
......
......@@ -50,11 +50,14 @@ using namespace std;
namespace WebCore {
using namespace HTMLNames;
// Used by flexible boxes when flexing this element.
typedef WTF::HashMap<const RenderBox*, int> OverrideSizeMap;
static OverrideSizeMap* gOverrideSizeMap = 0;
bool RenderBox::s_wasFloating = false;
bool RenderBox::s_hadOverflowClip = false;
RenderBox::RenderBox(Node* node)
: RenderObject(node)
, m_width(0)
......@@ -72,16 +75,39 @@ RenderBox::RenderBox(Node* node)
{
}
void RenderBox::setStyle(const RenderStyle* newStyle)
RenderBox::~RenderBox()
{
bool wasFloating = isFloating();
bool hadOverflowClip = hasOverflowClip();
}
void RenderBox::destroy()
{
// A lot of the code in this function is just pasted into
// RenderWidget::destroy. If anything in this function changes,
// be sure to fix RenderWidget::destroy() as well.
if (hasOverrideSize())
gOverrideSizeMap->remove(this);
RenderStyle* oldStyle = style();
if (oldStyle)
oldStyle->ref();
// This must be done before we destroy the RenderObject.
if (m_layer)
m_layer->clearClipRect();
RenderObject::setStyle(newStyle);
if (style() && (style()->height().isPercent() || style()->minHeight().isPercent() || style()->maxHeight().isPercent()))
RenderBlock::removePercentHeightDescendant(this);
RenderObject::destroy();
}
void RenderBox::styleWillChange(RenderStyle::Diff diff, const RenderStyle* newStyle)
{
s_wasFloating = isFloating();
s_hadOverflowClip = hasOverflowClip();
RenderObject::styleWillChange(diff, newStyle);
}
void RenderBox::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
{
RenderObject::styleDidChange(diff, oldStyle);
if (needsLayout() && oldStyle && (oldStyle->height().isPercent() || oldStyle->minHeight().isPercent() || oldStyle->maxHeight().isPercent()))
RenderBlock::removePercentHeightDescendant(this);
......@@ -90,9 +116,9 @@ void RenderBox::setStyle(const RenderStyle* newStyle)
if (isRoot() || isRenderView())
setHasBoxDecorations(true);
setInline(newStyle->isDisplayInlineType());
setInline(style()->isDisplayInlineType());
switch (newStyle->position()) {
switch (style()->position()) {
case AbsolutePosition:
case FixedPosition:
setPositioned(true);
......@@ -100,31 +126,32 @@ void RenderBox::setStyle(const RenderStyle* newStyle)
default:
setPositioned(false);
if (newStyle->isFloating())
if (style()->isFloating())
setFloating(true);
if (newStyle->position() == RelativePosition)
if (style()->position() == RelativePosition)
setRelPositioned(true);
break;
}
// We also handle <body> and <html>, whose overflow applies to the viewport.
if (!isRoot() && (!isBody() || !document()->isHTMLDocument()) && (isRenderBlock() || isTableRow() || isTableSection())) {
// Check for overflow clip.
// It's sufficient to just check one direction, since it's illegal to have visible on only one overflow value.
if (newStyle->overflowX() != OVISIBLE) {
if (!hadOverflowClip)
if (style()->overflowX() != OVISIBLE) {
if (!s_hadOverflowClip)
// Erase the overflow
repaint();
setHasOverflowClip();
}
}
setHasTransform(newStyle->hasTransform());
setHasReflection(newStyle->boxReflect());
setHasTransform(style()->hasTransform());
setHasReflection(style()->boxReflect());
if (requiresLayer()) {
if (!m_layer) {
if (wasFloating && isFloating())
if (s_wasFloating && isFloating())
setChildNeedsLayout(true);
m_layer = new (renderArena()) RenderLayer(this);
setHasLayer(true);
......@@ -140,7 +167,7 @@ void RenderBox::setStyle(const RenderStyle* newStyle)
setHasTransform(false); // Either a transform wasn't specified or the object doesn't support transforms, so just null out the bit.
setHasReflection(false);
layer->removeOnlyThisLayer();
if (wasFloating && isFloating())
if (s_wasFloating && isFloating())
setChildNeedsLayout(true);
}
......@@ -160,39 +187,14 @@ void RenderBox::setStyle(const RenderStyle* newStyle)
}
if (m_layer)
m_layer->styleChanged(oldStyle);
m_layer->styleChanged(diff, oldStyle);
// Set the text color if we're the body.
if (isBody())
document()->setTextColor(newStyle->color());
document()->setTextColor(style()->color());
if (style()->outlineWidth() > 0 && style()->outlineSize() > maximalOutlineSize(PaintPhaseOutline))
static_cast<RenderView*>(document()->renderer())->setMaximalOutlineSize(style()->outlineSize());
if (oldStyle)
oldStyle->deref(renderArena());
}
RenderBox::~RenderBox()
{
}
void RenderBox::destroy()
{
// A lot of the code in this function is just pasted into
// RenderWidget::destroy. If anything in this function changes,
// be sure to fix RenderWidget::destroy() as well.
if (hasOverrideSize())
gOverrideSizeMap->remove(this);
// This must be done before we destroy the RenderObject.
if (m_layer)
m_layer->clearClipRect();
if (style() && (style()->height().isPercent() || style()->minHeight().isPercent() || style()->maxHeight().isPercent()))
RenderBlock::removePercentHeightDescendant(this);
RenderObject::destroy();
}
int RenderBox::minPrefWidth() const
......
......@@ -36,7 +36,6 @@ public:
virtual const char* renderName() const { return "RenderBox"; }
virtual void setStyle(const RenderStyle*);
virtual void paint(PaintInfo&, int tx, int ty);
virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
......@@ -173,6 +172,9 @@ public:
virtual IntRect maskClipRect();
protected:
virtual void styleWillChange(RenderStyle::Diff, const RenderStyle* newStyle);
virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, int clipY, int clipHeight, int tx, int ty, int width, int height, CompositeOperator = CompositeSourceOver);
void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, int clipY, int clipHeight, int tx, int ty, int width, int height, CompositeOperator = CompositeSourceOver);
......@@ -238,6 +240,11 @@ protected:
// For inline replaced elements, the inline box that owns us.
InlineBox* m_inlineBoxWrapper;
private:
// Used to store state between styleWillChange and styleDidChange
static bool s_wasFloating;
static bool s_hadOverflowClip;
};
} // namespace WebCore
......
......@@ -64,7 +64,7 @@ void RenderButton::removeChild(RenderObject* oldChild)
m_inner->removeChild(oldChild);
}
void RenderButton::setStyle(const RenderStyle* style)
void RenderButton::styleWillChange(RenderStyle::Diff diff, const RenderStyle* newStyle)
{
if (m_inner) {
// RenderBlock::setStyle is going to apply a new style to the inner block, which
......@@ -73,9 +73,15 @@ void RenderButton::setStyle(const RenderStyle* style)
// because of the difference.
m_inner->style()->setBoxFlex(0);
}
RenderBlock::setStyle(style);
RenderBlock::styleWillChange(diff, newStyle);
}
void RenderButton::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
{
RenderBlock::styleDidChange(diff, oldStyle);
if (m_buttonText)
m_buttonText->setStyle(style);
m_buttonText->setStyle(style());
if (m_inner) // RenderBlock handled updating the anonymous block's style.
m_inner->style()->setBoxFlex(1.0f);
setReplaced(isInline());
......
......@@ -45,7 +45,6 @@ public:
virtual void removeLeftoverAnonymousBlock(RenderBlock*) { }
virtual bool createsAnonymousWrapper() const { return true; }
virtual void setStyle(const RenderStyle*);
virtual void updateFromElement();
virtual void updateBeforeAfterContent(RenderStyle::PseudoId);
......@@ -58,6 +57,9 @@ public:
virtual bool canHaveChildren() const;
protected:
virtual void styleWillChange(RenderStyle::Diff, const RenderStyle* newStyle);
virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
virtual bool hasLineIfEmpty() const { return true; }
void timerFired(Timer<RenderButton>*);
......
......@@ -260,9 +260,9 @@ void RenderFieldset::paintBorderMinusLegend(GraphicsContext* graphicsContext, in
}
}
void RenderFieldset::setStyle(const RenderStyle* newStyle)
void RenderFieldset::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
{
RenderBlock::setStyle(newStyle);
RenderBlock::styleDidChange(diff, oldStyle);
// WinIE renders fieldsets with display:inline like they're inline-blocks. For us,
// an inline-block is just a block element with replaced set to true and inline set
......
......@@ -41,8 +41,6 @@ public:
virtual RenderObject* layoutLegend(bool relayoutChildren);
virtual void setStyle(const RenderStyle*);
virtual void calcPrefWidths();
virtual bool avoidsFloats() const { return true; }
virtual bool expandsToEncloseOverhangingFloats() const { return style()->height().isAuto(); }
......@@ -50,6 +48,9 @@ public:
RenderObject* findLegend() const;
protected:
virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
private:
virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
virtual void paintMask(PaintInfo& paintInfo, int tx, int ty);
......
......@@ -71,11 +71,11 @@ RenderFileUploadControl::~RenderFileUploadControl()
m_fileChooser->disconnectClient();
}
void RenderFileUploadControl::setStyle(const RenderStyle* newStyle)
void RenderFileUploadControl::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
{
RenderBlock::setStyle(newStyle);
RenderBlock::styleDidChange(diff, oldStyle);
if (m_button)
m_button->renderer()->setStyle(createButtonStyle(newStyle));
m_button->renderer()->setStyle(createButtonStyle(style()));
setReplaced(isInline());
}
......
......@@ -39,7 +39,6 @@ public:
virtual const char* renderName() const { return "RenderFileUploadControl"; }
virtual void setStyle(const RenderStyle*);
virtual void updateFromElement();
virtual void calcPrefWidths();
virtual void paintObject(PaintInfo&, int tx, int ty);
......@@ -52,7 +51,10 @@ public:
String buttonValue();
String fileTextValue();
protected:
virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
private:
int maxFilenameWidth() const;
RenderStyle* createButtonStyle(const RenderStyle* parentStyle) const;
......
......@@ -41,9 +41,10 @@ RenderInline::~RenderInline()
{
}
void RenderInline::setStyle(const RenderStyle* newStyle)
void RenderInline::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
{
RenderFlow::setStyle(newStyle);
RenderFlow::styleDidChange(diff, oldStyle);
setInline(true);
setHasReflection(false);
......
......@@ -50,8 +50,6 @@ public:
void splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox,
RenderObject* newChild, RenderFlow* oldCont);
virtual void setStyle(const RenderStyle*);
virtual void layout() { } // Do nothing for layout()
virtual void paint(PaintInfo&, int tx, int ty);
......@@ -74,6 +72,8 @@ public:
virtual VisiblePosition positionForCoordinates(int x, int y);
protected:
virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
static RenderInline* cloneInline(RenderFlow* src);
};
......
......@@ -2357,7 +2357,7 @@ bool RenderLayer::shouldBeOverflowOnly() const
!isTransparent();
}
void RenderLayer::styleChanged(RenderStyle* oldStyle)
void RenderLayer::styleChanged(RenderStyle::Diff, const RenderStyle* oldStyle)
{
bool isOverflowOnly = shouldBeOverflowOnly();
if (isOverflowOnly != m_isOverflowOnly) {
......
......@@ -162,7 +162,7 @@ public:
void repaintIncludingDescendants();
void styleChanged(RenderStyle*);
void styleChanged(RenderStyle::Diff, const RenderStyle*);
RenderMarquee* marquee() const { return m_marquee; }
void suspendMarquees();
......
......@@ -90,9 +90,9 @@ RenderListBox::~RenderListBox()
}
}
void RenderListBox::setStyle(const RenderStyle* style)
void RenderListBox::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
{
RenderBlock::setStyle(style);
RenderBlock::styleDidChange(diff, oldStyle);
setReplaced(isInline());
}
......
......@@ -47,7 +47,6 @@ public:
virtual bool isListBox() const { return true; }
virtual void setStyle(const RenderStyle*);
virtual void updateFromElement();
virtual bool canHaveChildren() const { return false; }
......@@ -94,6 +93,9 @@ public:
virtual void setScrollLeft(int);
virtual void setScrollTop(int);
protected:
virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
private:
// ScrollbarClient interface.
virtual void valueChanged(Scrollbar*);
......
......@@ -48,9 +48,9 @@ RenderListItem::RenderListItem(Node* node)
setInline(false);
}
void RenderListItem::setStyle(const RenderStyle* newStyle)
void RenderListItem::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
{
RenderBlock::setStyle(newStyle);
RenderBlock::styleDidChange(diff, oldStyle);
if (style()->listStyleType() != LNONE ||
(style()->listStyleImage() && !style()->listStyleImage()->errorOccurred())) {
......
......@@ -39,8 +39,6 @@ public:
virtual void destroy();
virtual void setStyle(const RenderStyle*);
int value() const { if (!m_isValueUpToDate) updateValueNow(); return m_value; }
void updateValue();
......@@ -62,6 +60,9 @@ public:
const String& markerText() const;
protected:
virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
private:
void updateMarkerLocation();
inline int calcValue() const;
......
......@@ -485,12 +485,17 @@ RenderListMarker::~RenderListMarker()
m_image->removeClient(this);
}
void RenderListMarker::setStyle(const RenderStyle* s)
void RenderListMarker::styleWillChange(RenderStyle::Diff diff, const RenderStyle* newStyle)
{
if (style() && (s->listStylePosition() != style()->listStylePosition() || s->listStyleType() != style()->listStyleType()))
if (style() && (newStyle->listStylePosition() != style()->listStylePosition() || newStyle->listStyleType() != style()->listStyleType()))
setNeedsLayoutAndPrefWidthsRecalc();
RenderBox::setStyle(s);
RenderBox::styleWillChange(diff, newStyle);
}
void RenderListMarker::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle)
{
RenderBox::styleDidChange(diff, oldStyle);
if (m_image != style()->listStyleImage()) {
if (m_image)
......
......@@ -42,8 +42,6 @@ public:
virtual bool isListMarker() const { return true; }
virtual void setStyle(const RenderStyle*);
virtual void paint(PaintInfo&, int tx, int ty);
virtual void layout();
......@@ -69,6 +67,10 @@ public:
void updateMargins();
protected:
virtual void styleWillChange(RenderStyle::Diff, const RenderStyle* newStyle);