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

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

Issue 572043002: Support getComputedStyle for non-rendered pseudo elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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
Index: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index aec2f6ac9612dc5eb0a2dcbb793d62c909ed005e..76765cc6a397a56c849e2e4d58503308dd99dd12 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -2398,26 +2398,32 @@ RenderStyle* Element::computedStyle(PseudoId pseudoElementSpecifier)
if (PseudoElement* element = pseudoElement(pseudoElementSpecifier))
return element->computedStyle();
+ if (!inActiveDocument()) {
+ // FIXME: Try to do better than this. Ensure that styleForElement() works for elements that are not in the
+ // document tree and figure out when to destroy the computed style for such elements.
+ return 0;
+ }
+
// FIXME: Find and use the renderer from the pseudo element instead of the actual element so that the 'length'
// properties, which are only known by the renderer because it did the layout, will be correct and so that the
// values returned for the ":selection" pseudo-element will be correct.
- if (RenderStyle* usedStyle = renderStyle()) {
- if (pseudoElementSpecifier) {
- RenderStyle* cachedPseudoStyle = usedStyle->getCachedPseudoStyle(pseudoElementSpecifier);
- return cachedPseudoStyle ? cachedPseudoStyle : usedStyle;
- } else
- return usedStyle;
+ RenderStyle* elementStyle = renderStyle();
+ if (!elementStyle) {
+ ElementRareData& rareData = ensureElementRareData();
+ if (!rareData.computedStyle())
+ rareData.setComputedStyle(document().styleForElementIgnoringPendingStylesheets(this));
+ elementStyle = rareData.computedStyle();
}
- if (!inActiveDocument())
- // FIXME: Try to do better than this. Ensure that styleForElement() works for elements that are not in the
- // document tree and figure out when to destroy the computed style for such elements.
- return 0;
+ if (!pseudoElementSpecifier)
+ return elementStyle;
- ElementRareData& rareData = ensureElementRareData();
- if (!rareData.computedStyle())
- rareData.setComputedStyle(document().styleForElementIgnoringPendingStylesheets(this));
- return pseudoElementSpecifier ? rareData.computedStyle()->getCachedPseudoStyle(pseudoElementSpecifier) : rareData.computedStyle();
+ if (RenderStyle* pseudoElementStyle = elementStyle->getCachedPseudoStyle(pseudoElementSpecifier))
+ return pseudoElementStyle;
+
+ RefPtr<RenderStyle> result = document().ensureStyleResolver().pseudoStyleForElement(this, PseudoStyleRequest(pseudoElementSpecifier, PseudoStyleRequest::ForComputedStyle), elementStyle);
+ ASSERT(result);
+ return elementStyle->addCachedPseudoStyle(result.release());
}
AtomicString Element::computeInheritedLanguage() const
« Source/core/css/resolver/StyleResolver.cpp ('K') | « Source/core/css/resolver/StyleResolver.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698