Commit 6637ddc6 authored by esprehn@chromium.org's avatar esprehn@chromium.org

Share recalcChildStyle between Element and ShadowRoot.

Instead of needing to update both loops any time we change anything we
should just put the Element specific things in Element::recalcStyle and
then put the shared method into ContainerNode. I also removed an old
comment about ShadowRoot::recalcStyle not supporting adjacent selectors
properly (I fixed that bug a long time ago).

There should be no change in behavior, I just moved the code around.

BUG=399816

Review URL: https://codereview.chromium.org/548693002

git-svn-id: svn://svn.chromium.org/blink/trunk@181500 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 09a7faa1
......@@ -1205,6 +1205,37 @@ void ContainerNode::setRestyleFlag(DynamicRestyleFlags mask)
ensureRareData().setRestyleFlag(mask);
}
void ContainerNode::recalcChildStyle(StyleRecalcChange change)
{
ASSERT(document().inStyleRecalc());
ASSERT(change >= UpdatePseudoElements || childNeedsStyleRecalc());
ASSERT(!needsStyleRecalc());
if (change < Force && hasRareData() && childNeedsStyleRecalc())
checkForChildrenAdjacentRuleChanges();
// This loop is deliberately backwards because we use insertBefore in the rendering tree, and want to avoid
// a potentially n^2 loop to find the insertion point while resolving style. Having us start from the last
// child and work our way back means in the common case, we'll find the insertion point in O(1) time.
// See crbug.com/288225
StyleResolver& styleResolver = document().ensureStyleResolver();
Text* lastTextNode = 0;
for (Node* child = lastChild(); child; child = child->previousSibling()) {
if (child->isTextNode()) {
toText(child)->recalcTextStyle(change, lastTextNode);
lastTextNode = toText(child);
} else if (child->isElementNode()) {
Element* element = toElement(child);
if (element->shouldCallRecalcStyle(change))
element->recalcStyle(change, lastTextNode);
else if (element->supportsStyleSharing())
styleResolver.addToStyleSharingList(*element);
if (element->renderer())
lastTextNode = 0;
}
}
}
void ContainerNode::checkForChildrenAdjacentRuleChanges()
{
bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules();
......
......@@ -148,6 +148,7 @@ public:
void checkForChildrenAdjacentRuleChanges();
enum SiblingCheckType { FinishedParsingChildren, SiblingElementInserted, SiblingElementRemoved };
void checkForSiblingStyleChanges(SiblingCheckType, Node* nodeBeforeChange, Node* nodeAfterChange);
void recalcChildStyle(StyleRecalcChange);
bool childrenSupportStyleSharing() const { return !hasRestyleFlags(); }
......
......@@ -1497,7 +1497,21 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling)
// If we reattached we don't need to recalc the style of our descendants anymore.
if ((change >= UpdatePseudoElements && change < Reattach) || childNeedsStyleRecalc()) {
recalcChildStyle(change);
StyleResolverParentScope parentScope(*this);
updatePseudoElement(BEFORE, change);
if (change > UpdatePseudoElements || childNeedsStyleRecalc()) {
for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot()) {
if (root->shouldCallRecalcStyle(change))
root->recalcStyle(change);
}
recalcChildStyle(change);
}
updatePseudoElement(AFTER, change);
updatePseudoElement(BACKDROP, change);
clearChildNeedsStyleRecalc();
}
......@@ -1560,53 +1574,6 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change)
return localChange;
}
void Element::recalcChildStyle(StyleRecalcChange change)
{
ASSERT(document().inStyleRecalc());
ASSERT(change >= UpdatePseudoElements || childNeedsStyleRecalc());
ASSERT(!needsStyleRecalc());
StyleResolverParentScope parentScope(*this);
updatePseudoElement(BEFORE, change);
if (change > UpdatePseudoElements || childNeedsStyleRecalc()) {
for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot()) {
if (root->shouldCallRecalcStyle(change))
root->recalcStyle(change);
}
}
if (change < Force && hasRareData() && childNeedsStyleRecalc())
checkForChildrenAdjacentRuleChanges();
if (change > UpdatePseudoElements || childNeedsStyleRecalc()) {
// This loop is deliberately backwards because we use insertBefore in the rendering tree, and want to avoid
// a potentially n^2 loop to find the insertion point while resolving style. Having us start from the last
// child and work our way back means in the common case, we'll find the insertion point in O(1) time.
// See crbug.com/288225
StyleResolver& styleResolver = document().ensureStyleResolver();
Text* lastTextNode = 0;
for (Node* child = lastChild(); child; child = child->previousSibling()) {
if (child->isTextNode()) {
toText(child)->recalcTextStyle(change, lastTextNode);
lastTextNode = toText(child);
} else if (child->isElementNode()) {
Element* element = toElement(child);
if (element->shouldCallRecalcStyle(change))
element->recalcStyle(change, lastTextNode);
else if (element->supportsStyleSharing())
styleResolver.addToStyleSharingList(*element);
if (element->renderer())
lastTextNode = 0;
}
}
}
updatePseudoElement(AFTER, change);
updatePseudoElement(BACKDROP, change);
}
void Element::updateCallbackSelectors(RenderStyle* oldStyle, RenderStyle* newStyle)
{
Vector<String> emptyVector;
......
......@@ -566,7 +566,6 @@ private:
void setInlineStyleFromString(const AtomicString&);
StyleRecalcChange recalcOwnStyle(StyleRecalcChange);
void recalcChildStyle(StyleRecalcChange);
inline void checkForEmptyStyleChange();
......
......@@ -140,26 +140,10 @@ void ShadowRoot::recalcStyle(StyleRecalcChange change)
if (styleChangeType() >= SubtreeStyleChange)
change = Force;
if (change < Force && hasRareData() && childNeedsStyleRecalc())
checkForChildrenAdjacentRuleChanges();
// There's no style to update so just calling recalcStyle means we're updated.
clearNeedsStyleRecalc();
// FIXME: This doesn't handle :hover + div properly like Element::recalcStyle does.
Text* lastTextNode = 0;
for (Node* child = lastChild(); child; child = child->previousSibling()) {
if (child->isTextNode()) {
toText(child)->recalcTextStyle(change, lastTextNode);
lastTextNode = toText(child);
} else if (child->isElementNode()) {
if (child->shouldCallRecalcStyle(change))
toElement(child)->recalcStyle(change, lastTextNode);
if (child->renderer())
lastTextNode = 0;
}
}
recalcChildStyle(change);
clearChildNeedsStyleRecalc();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment