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

Unified Diff: third_party/WebKit/Source/core/layout/LayoutObject.cpp

Issue 2727253004: Call getUncachedPseudoStyle on correct node for ::selection. (Closed)
Patch Set: Documentation fixes. Created 3 years, 10 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/layout/LayoutObject.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/layout/LayoutObject.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutObject.cpp b/third_party/WebKit/Source/core/layout/LayoutObject.cpp
index 24d0131ae325d01d5b7145bbc8bd1cbb5600983c..394c12af172a30d2ca68d8813de0324c0913ebc8 100644
--- a/third_party/WebKit/Source/core/layout/LayoutObject.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutObject.cpp
@@ -1384,8 +1384,7 @@ Color LayoutObject::selectionBackgroundColor() const {
if (!isSelectable())
return Color::transparent;
- if (RefPtr<ComputedStyle> pseudoStyle =
- getUncachedPseudoStyleFromParentOrShadowHost())
+ if (RefPtr<ComputedStyle> pseudoStyle = getUncachedSelectionStyle())
return resolveColor(*pseudoStyle, CSSPropertyBackgroundColor)
.blendWithWhite();
return frame()->selection().isFocusedAndActive()
@@ -1401,8 +1400,7 @@ Color LayoutObject::selectionColor(
if (!isSelectable() || (globalPaintFlags & GlobalPaintSelectionOnly))
return resolveColor(colorProperty);
- if (RefPtr<ComputedStyle> pseudoStyle =
- getUncachedPseudoStyleFromParentOrShadowHost())
+ if (RefPtr<ComputedStyle> pseudoStyle = getUncachedSelectionStyle())
return resolveColor(*pseudoStyle, colorProperty);
if (!LayoutTheme::theme().supportsSelectionForegroundColors())
return resolveColor(colorProperty);
@@ -3067,11 +3065,15 @@ PassRefPtr<ComputedStyle> LayoutObject::getUncachedPseudoStyle(
element, pseudoStyleRequest, parentStyle, parentStyle);
}
-PassRefPtr<ComputedStyle>
-LayoutObject::getUncachedPseudoStyleFromParentOrShadowHost() const {
+PassRefPtr<ComputedStyle> LayoutObject::getUncachedSelectionStyle() const {
if (!node())
return nullptr;
+ // In Blink, ::selection only applies to direct children of the element on
+ // which ::selection is matched. In order to be able to style ::selection
+ // inside elements implemented with a UA shadow tree, like input::selection,
+ // we calculate ::selection style on the shadow host for elements inside the
+ // UA shadow.
if (ShadowRoot* root = node()->containingShadowRoot()) {
if (root->type() == ShadowRootType::UserAgent) {
if (Element* shadowHost = node()->ownerShadowHost()) {
@@ -3081,7 +3083,20 @@ LayoutObject::getUncachedPseudoStyleFromParentOrShadowHost() const {
}
}
- return getUncachedPseudoStyle(PseudoStyleRequest(PseudoIdSelection));
+ // If we request ::selection style for LayoutText, query ::selection style on
+ // the parent element instead, as that is the node for which ::selection
+ // matches.
+ const LayoutObject* selectionLayoutObject = this;
+ Element* element = Traversal<Element>::firstAncestorOrSelf(*node());
+ if (!element)
+ return nullptr;
+ if (element != node()) {
+ selectionLayoutObject = element->layoutObject();
+ if (!selectionLayoutObject)
+ return nullptr;
+ }
+ return selectionLayoutObject->getUncachedPseudoStyle(
+ PseudoStyleRequest(PseudoIdSelection));
}
void LayoutObject::addAnnotatedRegions(Vector<AnnotatedRegionValue>& regions) {
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutObject.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698