| 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) { | 
|  |