Specialize InsertionPoint attach/detach.

This is another step towards making attach non-virtual. InsertionPoints are
core to the engine, so it seems fine to bake them directly into recalcStyle.

I did this already to willRecalcStyle.

R=ojan@chromium.org

Review URL: https://codereview.chromium.org/765523002
This commit is contained in:
Elliott Sprehn 2014-11-26 14:40:38 -05:00
parent 9e43ce3605
commit 63533b3091
4 changed files with 13 additions and 10 deletions

View File

@ -801,6 +801,9 @@ void Element::attach(const AttachContext& context)
{
ASSERT(document().inStyleRecalc());
if (isInsertionPoint())
toInsertionPoint(this)->attachDistribution(context);
// We've already been through detach when doing an attach, but we might
// need to clear any state that's been added since then.
if (hasRareData() && styleChangeType() == NeedsReattachStyleChange) {
@ -826,6 +829,9 @@ void Element::attach(const AttachContext& context)
void Element::detach(const AttachContext& context)
{
if (isInsertionPoint())
toInsertionPoint(this)->detachDistribution(context);
if (hasRareData()) {
ElementRareData* data = elementRareData();

View File

@ -196,8 +196,9 @@ public:
bool hasEquivalentAttributes(const Element* other) const;
virtual void attach(const AttachContext& = AttachContext()) override;
virtual void detach(const AttachContext& = AttachContext()) override;
void attach(const AttachContext& = AttachContext()) final;
void detach(const AttachContext& = AttachContext()) final;
virtual RenderObject* createRenderer(RenderStyle*);
void recalcStyle(StyleRecalcChange, Text* nextTextSibling = 0);
void setAnimationStyleChange(bool);

View File

@ -92,7 +92,7 @@ void InsertionPoint::setDistribution(ContentDistribution& distribution)
m_distribution.shrinkToFit();
}
void InsertionPoint::attach(const AttachContext& context)
void InsertionPoint::attachDistribution(const AttachContext& context)
{
// We need to attach the distribution here so that they're inserted in the right order
// otherwise the n^2 protection inside RenderTreeBuilder will cause them to be
@ -102,16 +102,12 @@ void InsertionPoint::attach(const AttachContext& context)
if (m_distribution.at(i)->needsAttach())
m_distribution.at(i)->attach(context);
}
HTMLElement::attach(context);
}
void InsertionPoint::detach(const AttachContext& context)
void InsertionPoint::detachDistribution(const AttachContext& context)
{
for (size_t i = 0; i < m_distribution.size(); ++i)
m_distribution.at(i)->lazyReattachIfAttached();
HTMLElement::detach(context);
}
void InsertionPoint::willRecalcStyle(StyleRecalcChange change)

View File

@ -54,8 +54,8 @@ public:
virtual bool canAffectSelector() const { return false; }
virtual void attach(const AttachContext& = AttachContext()) override;
virtual void detach(const AttachContext& = AttachContext()) override;
void attachDistribution(const AttachContext&);
void detachDistribution(const AttachContext&);
bool shouldUseFallbackElements() const;