Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Unified Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 2789283003: [css-display] Support pseudo-elements on display: contents elements. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 585beca84fb915bb397971818812de64b35f9488..56eede0205aa29a9d07182d06914186997cdd3ec 100644
--- a/third_party/WebKit/Source/core/dom/Element.cpp
+++ b/third_party/WebKit/Source/core/dom/Element.cpp
@@ -2016,9 +2016,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();
rune 2017/04/04 20:32:40 I think I've commented on this before ... Was the
+ }
}
if (getStyleChangeType() >= SubtreeStyleChange)
@@ -3192,14 +3196,20 @@ const ComputedStyle* Element::ensureComputedStyle(
elementStyle->getCachedPseudoStyle(pseudoElementSpecifier))
return pseudoElementStyle;
- // 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.
+ const ComputedStyle* layoutParentStyle = elementStyle;
+ if (hasDisplayContentsStyle()) {
+ LayoutObject* parentLayoutObject =
+ LayoutTreeBuilderTraversal::parentLayoutObject(*this);
+ if (parentLayoutObject)
+ layoutParentStyle = parentLayoutObject->style();
+ }
+
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());
}
@@ -3295,8 +3305,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 (!canGeneratePseudoElement(pseudoId) ||
+ !pseudoElementLayoutObjectIsNeeded(
+ pseudoStyle(PseudoStyleRequest(pseudoId))))
elementRareData()->setPseudoElement(pseudoId, nullptr);
} else if (pseudoId == PseudoIdFirstLetter && element &&
change >= UpdatePseudoElements &&
@@ -3422,6 +3433,14 @@ PassRefPtr<ComputedStyle> Element::getUncachedPseudoStyle(
return document().ensureStyleResolver().pseudoStyleForElement(
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::canGeneratePseudoElement(PseudoId pseudoId) const {
+ if (hasDisplayContentsStyle())
+ return pseudoId == PseudoIdBefore || pseudoId == PseudoIdAfter;
+ return !!layoutObject();
+}
bool Element::matches(const AtomicString& selectors,
ExceptionState& exceptionState) {
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698