⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 276236 in webkit


Ignore:
Timestamp:
Apr 18, 2021, 11:32:12 PM (5 years ago)
Author:
Wenson Hsieh
Message:

Selected image overlay text should never be visible
https://bugs.webkit.org/show_bug.cgi?id=224734
<rdar://problem/76806399>

Reviewed by Darin Adler.

Source/WebCore:

Make a slight adjustment to the UA stylesheet to ensure that image overlay text is never visible. See below for
more details.

Test: fast/images/image-extraction/image-overlay-with-selection-styles.html

  • html/shadow/imageOverlay.css:

(div.image-overlay-text::selection):

Enforce selected text styles for image overlay text.

  • rendering/RenderElement.cpp:

(WebCore::RenderElement::selectionPseudoStyle const):

Make an additional adjustment when computing selection pseudo styles for UA shadow root content. Currently, for
elements inside a UA shadow root, we always immediately ascend to the shadow host; this means that ::selection
pseudo selectors currently don't work in UA stylesheets, since they're skipped when resolving styles, upon
painting selected text.

To fix this, we can let the element's own pseudo styles take precedence over the shadow host's renderer in the
case where we have a selection pseudo style. While we're here, also replace a few raw pointers with RefPtr.

LayoutTests:

Add a new layout test.

  • fast/images/image-extraction/image-overlay-with-selection-styles-expected.html: Added.
  • fast/images/image-extraction/image-overlay-with-selection-styles.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r276235 r276236  
     12021-04-18  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Selected image overlay text should never be visible
     4        https://bugs.webkit.org/show_bug.cgi?id=224734
     5        <rdar://problem/76806399>
     6
     7        Reviewed by Darin Adler.
     8
     9        Add a new layout test.
     10
     11        * fast/images/image-extraction/image-overlay-with-selection-styles-expected.html: Added.
     12        * fast/images/image-extraction/image-overlay-with-selection-styles.html: Added.
     13
    1142021-04-18  Rob Buis  <rbuis@igalia.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r276235 r276236  
     12021-04-18  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Selected image overlay text should never be visible
     4        https://bugs.webkit.org/show_bug.cgi?id=224734
     5        <rdar://problem/76806399>
     6
     7        Reviewed by Darin Adler.
     8
     9        Make a slight adjustment to the UA stylesheet to ensure that image overlay text is never visible. See below for
     10        more details.
     11
     12        Test: fast/images/image-extraction/image-overlay-with-selection-styles.html
     13
     14        * html/shadow/imageOverlay.css:
     15        (div.image-overlay-text::selection):
     16
     17        Enforce selected text styles for image overlay text.
     18
     19        * rendering/RenderElement.cpp:
     20        (WebCore::RenderElement::selectionPseudoStyle const):
     21
     22        Make an additional adjustment when computing selection pseudo styles for UA shadow root content. Currently, for
     23        elements inside a UA shadow root, we always immediately ascend to the shadow host; this means that `::selection`
     24        pseudo selectors currently don't work in UA stylesheets, since they're skipped when resolving styles, upon
     25        painting selected text.
     26
     27        To fix this, we can let the element's own pseudo styles take precedence over the shadow host's renderer in the
     28        case where we have a selection pseudo style. While we're here, also replace a few raw pointers with `RefPtr`.
     29
    1302021-04-18  Rob Buis  <rbuis@igalia.com>
    231
  • trunk/Source/WebCore/html/shadow/imageOverlay.css

    r276026 r276236  
    3939    overflow: hidden;
    4040}
     41
     42div.image-overlay-text::selection {
     43    color: transparent;
     44    background-color: highlight;
     45}
  • trunk/Source/WebCore/rendering/RenderElement.cpp

    r275478 r276236  
    15301530        return nullptr;
    15311531
    1532     if (ShadowRoot* root = element()->containingShadowRoot()) {
     1532    if (auto selectionStyle = getUncachedPseudoStyle({ PseudoId::Selection })) {
     1533        // We intentionally return the pseudo selection style here if it exists before ascending to
     1534        // the shadow host element. This allows us to apply selection pseudo styles in user agent
     1535        // shadow roots, instead of always deferring to the shadow host's selection pseudo style.
     1536        return selectionStyle;
     1537    }
     1538
     1539    if (auto root = makeRefPtr(element()->containingShadowRoot())) {
    15331540        if (root->mode() == ShadowRootMode::UserAgent) {
    1534             auto* currentElement = element()->shadowHost();
     1541            auto currentElement = makeRefPtr(element()->shadowHost());
    15351542            // When an element has display: contents, this element doesn't have a renderer
    15361543            // and its children will render as children of the parent element.
     
    15421549    }
    15431550
    1544     return getUncachedPseudoStyle({ PseudoId::Selection });
     1551    return nullptr;
    15451552}
    15461553
Note: See TracChangeset for help on using the changeset viewer.