Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/Element.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/Element.cpp b/third_party/WebKit/Source/core/dom/Element.cpp |
| index 939513be530ab3f38d2d9839257f98d8bec967ae..29918cfcbf45e06072d78d83ab1921b3fb57208d 100644 |
| --- a/third_party/WebKit/Source/core/dom/Element.cpp |
| +++ b/third_party/WebKit/Source/core/dom/Element.cpp |
| @@ -1998,9 +1998,13 @@ StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) { |
| // https://codereview.chromium.org/30453002/ |
| layoutObject->setStyleInternal(newStyle.get()); |
| } |
| - } else if (localChange != NoChange && |
| - shouldStoreNonLayoutObjectComputedStyle(*newStyle)) { |
| - storeNonLayoutObjectComputedStyle(newStyle); |
| + } else { |
| + if (localChange != NoChange) { |
| + if (shouldStoreNonLayoutObjectComputedStyle(*newStyle)) |
| + storeNonLayoutObjectComputedStyle(newStyle); |
| + else if (hasRareData()) |
| + elementRareData()->clearComputedStyle(); |
| + } |
| } |
| if (getStyleChangeType() >= SubtreeStyleChange) |
| @@ -3170,18 +3174,24 @@ const ComputedStyle* Element::ensureComputedStyle( |
| if (!pseudoElementSpecifier) |
| return elementStyle; |
| - if (ComputedStyle* pseudoElementStyle = |
| + if (ComputedStyle* cached = |
| elementStyle->getCachedPseudoStyle(pseudoElementSpecifier)) |
| - return pseudoElementStyle; |
| + return cached; |
| + |
| + const ComputedStyle* layoutParentStyle = elementStyle; |
| + if (hasDisplayContentsStyle()) { |
| + LayoutObject* parentLayoutObject = |
| + LayoutTreeBuilderTraversal::parentLayoutObject(*this); |
| + if (parentLayoutObject) |
| + layoutParentStyle = parentLayoutObject->style(); |
| + } |
| - // TODO(ecobos): Passing two times elementStyle may be wrong, though we don't |
| - // support display: contents elements' pseudo-elements yet, so this is not a |
| - // problem for now. |
| RefPtr<ComputedStyle> result = |
| document().ensureStyleResolver().pseudoStyleForElement( |
| - this, PseudoStyleRequest(pseudoElementSpecifier, |
| - PseudoStyleRequest::ForComputedStyle), |
| - elementStyle, elementStyle); |
| + this, |
| + PseudoStyleRequest(pseudoElementSpecifier, |
| + PseudoStyleRequest::ForComputedStyle), |
| + elementStyle, layoutParentStyle); |
| DCHECK(result); |
| return elementStyle->addCachedPseudoStyle(result.release()); |
| } |
| @@ -3277,8 +3287,9 @@ void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) { |
| // continuously create and destroy PseudoElements when |
| // LayoutObject::isChildAllowed on our parent returns false for the |
| // PseudoElement's layoutObject for each style recalc. |
| - if (!layoutObject() || !pseudoElementLayoutObjectIsNeeded( |
| - pseudoStyle(PseudoStyleRequest(pseudoId)))) |
| + if (!canHaveGeneratedPseudo(pseudoId) || |
| + !pseudoElementLayoutObjectIsNeeded( |
| + pseudoStyle(PseudoStyleRequest(pseudoId)))) |
| elementRareData()->setPseudoElement(pseudoId, nullptr); |
| } else if (pseudoId == PseudoIdFirstLetter && element && |
| change >= UpdatePseudoElements && |
| @@ -3405,6 +3416,15 @@ PassRefPtr<ComputedStyle> Element::getUncachedPseudoStyle( |
| this, request, parentStyle, parentStyle); |
| } |
| +// For display: contents elements, we still need to generate ::before and |
| +// ::after, but the rest of the pseudo-elements should only be used for elements |
| +// with an actual layout object. |
| +bool Element::canHaveGeneratedPseudo(PseudoId pseudoId) const { |
|
rune
2017/04/04 14:23:41
canHavePseudoElement() or canGeneratePseudoElement
emilio
2017/04/04 15:09:18
Acknowledged.
|
| + if (hasDisplayContentsStyle()) |
| + return pseudoId == PseudoIdBefore || pseudoId == PseudoIdAfter; |
| + return !!layoutObject(); |
| +} |
| + |
| bool Element::matches(const AtomicString& selectors, |
| ExceptionState& exceptionState) { |
| SelectorQuery* selectorQuery = document().selectorQueryCache().add( |