Changeset 236519 in webkit


Ignore:
Timestamp:
Sep 26, 2018 1:02:57 PM (6 years ago)
Author:
rniwa@webkit.org
Message:

Selection should work across shadow boundary when initiated by a mouse drag
https://bugs.webkit.org/show_bug.cgi?id=151380
<rdar://problem/24363872>

Source/WebCore:

Reviewed by Antti Koivisto and Wenson Hsieh.

This patch adds the basic support for selecting content across shadow DOM boundaries to VisibleSelection,
which is enough to allow users to select content across shadow DOM boundaries via a mouse drag.

This is the first step in allowing users to select, copy and paste content across shadow DOM boundaries,
which is a serious user experience regression right now. The new behavior is disabled by default under
an interal debug feature flag: selectionAcrossShadowBoundariesEnabled.

Like Chrome, we are not going to support selecting editable content across shadow DOM boundaries since
we'd have to generalize every editing commands to make that work, and there aren't any HTML editors that
use shadow DOM boundaries within an editable region yet. For simplicity, we also don't support extending
a selection out of a shadow root which resides inside an editing region.

The keyboard based navigation & manipulation of selection as well as allowing copy & paste of content
across shadow DOM boundaries will be implemented by separate patches. DOMSelection will not expose this new
behavior either. This is tracked in the spec as https://github.com/w3c/webcomponents/issues/79

Tests: editing/selection/selection-across-shadow-boundaries-mixed-editability-1.html

editing/selection/selection-across-shadow-boundaries-mixed-editability-2.html
editing/selection/selection-across-shadow-boundaries-mixed-editability-3.html
editing/selection/selection-across-shadow-boundaries-mixed-editability-4.html
editing/selection/selection-across-shadow-boundaries-mixed-editability-5.html
editing/selection/selection-across-shadow-boundaries-readonly-1.html
editing/selection/selection-across-shadow-boundaries-readonly-2.html
editing/selection/selection-across-shadow-boundaries-readonly-3.html
editing/selection/selection-across-shadow-boundaries-user-select-all-1.html

  • editing/VisibleSelection.cpp:

(WebCore::isInUserAgentShadowRootOrHasEditableShadowAncestor): Added.
(WebCore::VisibleSelection::adjustSelectionToAvoidCrossingShadowBoundaries): When the feature is enabled,
allow crossing shadow DOM boundaries except when either end is inside an user agent shadow root, or one of
its shadow includign ancestor is inside an editable region. The latter check is needed to disallow
an extension of a selection starting in a shadow tree inside a non-editable region inside an editable region
to outside the editable region. The rest of the editing code is not ready to deal with selection like that.

  • page/Settings.yaml: Added an internal debug feature to enable this new behavior.

Source/WebKit:

Reviewed by Antti Koivisto.

Added SelectionAcrossShadowBoundariesEnabled as an internal debug feature,
and moved CSSCustomPropertiesAndValuesEnabled to where other experimental features are located.

  • Shared/WebPreferences.yaml:

Source/WebKitLegacy/mac:

Reviewed by Wenson Hsieh.

Added selectionAcrossShadowBoundariesEnabled as a preference to be used in DumpRenderTree.

  • WebView/WebPreferenceKeysPrivate.h:
  • WebView/WebPreferences.mm:

(+[WebPreferences initialize]):
(-[WebPreferences selectionAcrossShadowBoundariesEnabled]):
(-[WebPreferences setSelectionAcrossShadowBoundariesEnabled:]):

  • WebView/WebPreferencesPrivate.h:
  • WebView/WebView.mm:

(-[WebView _preferencesChanged:]):

Tools:

Reviewed by Wenson Hsieh.

Added the support for internal:selectionAcrossShadowBoundariesEnabled test option.

  • DumpRenderTree/TestOptions.cpp:

(TestOptions::TestOptions):

  • DumpRenderTree/TestOptions.h:
  • DumpRenderTree/mac/DumpRenderTree.mm:

(resetWebPreferencesToConsistentValues):
(setWebPreferencesForTestOptions):

LayoutTests:

Reviewed by Antti Koivisto and Wenson Hsieh.

Added regression tests using ref tests since getSelection() doesn't expose any node inside a shadow tree.

  • editing/selection/selection-across-shadow-boundaries-mixed-editability-1-expected.html: Added.
  • editing/selection/selection-across-shadow-boundaries-mixed-editability-1.html: Added.
  • editing/selection/selection-across-shadow-boundaries-mixed-editability-2-expected.html: Added.
  • editing/selection/selection-across-shadow-boundaries-mixed-editability-2.html: Added.
  • editing/selection/selection-across-shadow-boundaries-mixed-editability-3-expected.html: Added.
  • editing/selection/selection-across-shadow-boundaries-mixed-editability-3.html: Added.
  • editing/selection/selection-across-shadow-boundaries-mixed-editability-4-expected.html: Added.
  • editing/selection/selection-across-shadow-boundaries-mixed-editability-4.html: Added.
  • editing/selection/selection-across-shadow-boundaries-mixed-editability-5-expected.html: Added.
  • editing/selection/selection-across-shadow-boundaries-mixed-editability-5.html: Added.
  • editing/selection/selection-across-shadow-boundaries-readonly-1-expected.html: Added.
  • editing/selection/selection-across-shadow-boundaries-readonly-1.html: Added.
  • editing/selection/selection-across-shadow-boundaries-readonly-2-expected.html: Added.
  • editing/selection/selection-across-shadow-boundaries-readonly-2.html: Added.
  • editing/selection/selection-across-shadow-boundaries-readonly-3-expected.html: Added.
  • editing/selection/selection-across-shadow-boundaries-readonly-3.html: Added.
  • editing/selection/selection-across-shadow-boundaries-user-select-all-1-expected.html: Added.
  • editing/selection/selection-across-shadow-boundaries-user-select-all-1.html: Added.
Location:
trunk
Files:
18 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r236515 r236519  
     12018-09-26  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Selection should work across shadow boundary when initiated by a mouse drag
     4        https://bugs.webkit.org/show_bug.cgi?id=151380
     5        <rdar://problem/24363872>
     6
     7        Reviewed by Antti Koivisto and Wenson Hsieh.
     8
     9        Added regression tests using ref tests since getSelection() doesn't expose any node inside a shadow tree.
     10
     11        * editing/selection/selection-across-shadow-boundaries-mixed-editability-1-expected.html: Added.
     12        * editing/selection/selection-across-shadow-boundaries-mixed-editability-1.html: Added.
     13        * editing/selection/selection-across-shadow-boundaries-mixed-editability-2-expected.html: Added.
     14        * editing/selection/selection-across-shadow-boundaries-mixed-editability-2.html: Added.
     15        * editing/selection/selection-across-shadow-boundaries-mixed-editability-3-expected.html: Added.
     16        * editing/selection/selection-across-shadow-boundaries-mixed-editability-3.html: Added.
     17        * editing/selection/selection-across-shadow-boundaries-mixed-editability-4-expected.html: Added.
     18        * editing/selection/selection-across-shadow-boundaries-mixed-editability-4.html: Added.
     19        * editing/selection/selection-across-shadow-boundaries-mixed-editability-5-expected.html: Added.
     20        * editing/selection/selection-across-shadow-boundaries-mixed-editability-5.html: Added.
     21        * editing/selection/selection-across-shadow-boundaries-readonly-1-expected.html: Added.
     22        * editing/selection/selection-across-shadow-boundaries-readonly-1.html: Added.
     23        * editing/selection/selection-across-shadow-boundaries-readonly-2-expected.html: Added.
     24        * editing/selection/selection-across-shadow-boundaries-readonly-2.html: Added.
     25        * editing/selection/selection-across-shadow-boundaries-readonly-3-expected.html: Added.
     26        * editing/selection/selection-across-shadow-boundaries-readonly-3.html: Added.
     27        * editing/selection/selection-across-shadow-boundaries-user-select-all-1-expected.html: Added.
     28        * editing/selection/selection-across-shadow-boundaries-user-select-all-1.html: Added.
     29
    1302018-09-26  Alicia Boya García  <aboya@igalia.com>
    231
  • trunk/LayoutTests/platform/win/TestExpectations

    r236487 r236519  
    102102webkit.org/b/173281 editing/style/set-backColor-with-color-filter.html [ Skip ]
    103103webkit.org/b/173281 editing/style/inverse-color-filter.html [ Skip ]
     104webkit.org/b/173281 editing/selection/selection-across-shadow-boundaries-mixed-editability-1.html [ Skip ]
     105webkit.org/b/173281 editing/selection/selection-across-shadow-boundaries-mixed-editability-2.html [ Skip ]
     106webkit.org/b/173281 editing/selection/selection-across-shadow-boundaries-mixed-editability-3.html [ Skip ]
     107webkit.org/b/173281 editing/selection/selection-across-shadow-boundaries-mixed-editability-4.html [ Skip ]
     108webkit.org/b/173281 editing/selection/selection-across-shadow-boundaries-mixed-editability-5.html [ Skip ]
     109webkit.org/b/173281 editing/selection/selection-across-shadow-boundaries-readonly-1.html [ Skip ]
     110webkit.org/b/173281 editing/selection/selection-across-shadow-boundaries-readonly-2.html [ Skip ]
     111webkit.org/b/173281 editing/selection/selection-across-shadow-boundaries-readonly-3.html [ Skip ]
     112webkit.org/b/173281 editing/selection/selection-across-shadow-boundaries-user-select-all-1.html [ Skip ]
    104113
    105114# TODO HW filters not yet supported on Windows
  • trunk/Source/WebCore/ChangeLog

    r236517 r236519  
     12018-09-26  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Selection should work across shadow boundary when initiated by a mouse drag
     4        https://bugs.webkit.org/show_bug.cgi?id=151380
     5        <rdar://problem/24363872>
     6
     7        Reviewed by Antti Koivisto and Wenson Hsieh.
     8
     9        This patch adds the basic support for selecting content across shadow DOM boundaries to VisibleSelection,
     10        which is enough to allow users to select content across shadow DOM boundaries via a mouse drag.
     11
     12        This is the first step in allowing users to select, copy and paste content across shadow DOM boundaries,
     13        which is a serious user experience regression right now. The new behavior is disabled by default under
     14        an interal debug feature flag: selectionAcrossShadowBoundariesEnabled.
     15
     16        Like Chrome, we are not going to support selecting editable content across shadow DOM boundaries since
     17        we'd have to generalize every editing commands to make that work, and there aren't any HTML editors that
     18        use shadow DOM boundaries within an editable region yet. For simplicity, we also don't support extending
     19        a selection out of a shadow root which resides inside an editing region.
     20
     21        The keyboard based navigation & manipulation of selection as well as allowing copy & paste of content
     22        across shadow DOM boundaries will be implemented by separate patches. DOMSelection will not expose this new
     23        behavior either. This is tracked in the spec as https://github.com/w3c/webcomponents/issues/79
     24
     25        Tests: editing/selection/selection-across-shadow-boundaries-mixed-editability-1.html
     26               editing/selection/selection-across-shadow-boundaries-mixed-editability-2.html
     27               editing/selection/selection-across-shadow-boundaries-mixed-editability-3.html
     28               editing/selection/selection-across-shadow-boundaries-mixed-editability-4.html
     29               editing/selection/selection-across-shadow-boundaries-mixed-editability-5.html
     30               editing/selection/selection-across-shadow-boundaries-readonly-1.html
     31               editing/selection/selection-across-shadow-boundaries-readonly-2.html
     32               editing/selection/selection-across-shadow-boundaries-readonly-3.html
     33               editing/selection/selection-across-shadow-boundaries-user-select-all-1.html
     34
     35        * editing/VisibleSelection.cpp:
     36        (WebCore::isInUserAgentShadowRootOrHasEditableShadowAncestor): Added.
     37        (WebCore::VisibleSelection::adjustSelectionToAvoidCrossingShadowBoundaries): When the feature is enabled,
     38        allow crossing shadow DOM boundaries except when either end is inside an user agent shadow root, or one of
     39        its shadow includign ancestor is inside an editable region. The latter check is needed to disallow
     40        an extension of a selection starting in a shadow tree inside a non-editable region inside an editable region
     41        to outside the editable region. The rest of the editing code is not ready to deal with selection like that.
     42        * page/Settings.yaml: Added an internal debug feature to enable this new behavior.
     43
    1442018-09-26  Chris Dumez  <cdumez@apple.com>
    245
  • trunk/Source/WebCore/editing/VisibleSelection.cpp

    r233778 r236519  
    3131#include "Element.h"
    3232#include "HTMLInputElement.h"
     33#include "Settings.h"
    3334#include "TextIterator.h"
    3435#include "VisibleUnits.h"
     
    505506}
    506507
     508static bool isInUserAgentShadowRootOrHasEditableShadowAncestor(Node& node)
     509{
     510    auto* shadowRoot = node.containingShadowRoot();
     511    if (!shadowRoot)
     512        return false;
     513
     514    if (shadowRoot->mode() == ShadowRootMode::UserAgent)
     515        return true;
     516
     517    for (RefPtr<Node> currentNode = &node; currentNode; currentNode = currentNode->parentOrShadowHostNode()) {
     518        if (currentNode->hasEditableStyle())
     519            return true;
     520    }
     521    return false;
     522}
     523
    507524void VisibleSelection::adjustSelectionToAvoidCrossingShadowBoundaries()
    508525{
     
    510527        return;
    511528
    512     if (&m_start.anchorNode()->treeScope() == &m_end.anchorNode()->treeScope())
     529    auto startNode = makeRef(*m_start.anchorNode());
     530    auto endNode = makeRef(*m_end.anchorNode());
     531    if (&startNode->treeScope() == &endNode->treeScope())
    513532        return;
    514533
     534    if (startNode->document().settings().selectionAcrossShadowBoundariesEnabled()) {
     535        if (!isInUserAgentShadowRootOrHasEditableShadowAncestor(startNode)
     536            && !isInUserAgentShadowRootOrHasEditableShadowAncestor(endNode))
     537            return;
     538    }
     539
    515540    if (m_baseIsFirst) {
    516         m_extent = adjustPositionForEnd(m_end, m_start.containerNode());
     541        m_extent = adjustPositionForEnd(m_end, startNode.ptr());
    517542        m_end = m_extent;
    518543    } else {
    519         m_extent = adjustPositionForStart(m_start, m_end.containerNode());
     544        m_extent = adjustPositionForStart(m_start, endNode.ptr());
    520545        m_start = m_extent;
    521546    }
    522 
    523     ASSERT(&m_start.anchorNode()->treeScope() == &m_end.anchorNode()->treeScope());
    524547}
    525548
  • trunk/Source/WebCore/page/Settings.yaml

    r236424 r236519  
    390390selectTrailingWhitespaceEnabled:
    391391  initial: defaultSelectTrailingWhitespaceEnabled
     392selectionAcrossShadowBoundariesEnabled:
     393  initial: false
    392394
    393395useLegacyBackgroundSizeShorthandBehavior:
  • trunk/Source/WebKit/ChangeLog

    r236513 r236519  
     12018-09-26  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Selection should work across shadow boundary when initiated by a mouse drag
     4        https://bugs.webkit.org/show_bug.cgi?id=151380
     5        <rdar://problem/24363872>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Added SelectionAcrossShadowBoundariesEnabled as an internal debug feature,
     10        and moved CSSCustomPropertiesAndValuesEnabled to where other experimental features are located.
     11
     12        * Shared/WebPreferences.yaml:
     13
    1142018-09-26  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/Source/WebKit/Shared/WebPreferences.yaml

    r236497 r236519  
    12581258  webcoreName: serverTimingEnabled
    12591259
     1260CSSCustomPropertiesAndValuesEnabled:
     1261  type: bool
     1262  defaultValue: false
     1263  humanReadableName: "CSS Custom Properties and Values API"
     1264  humanReadableDescription: "Enable CSS Custom Properties and Values API"
     1265  webcoreBinding: RuntimeEnabledFeatures
     1266  category: experimental
     1267
    12601268# For internal features:
    12611269# The type should be boolean.
     
    13421350AriaReflectionEnabled:
    13431351  type: bool
    1344   defaultValue: true
     1352  defaultValue: false
    13451353  humanReadableName: "ARIA Reflection"
    13461354  humanReadableDescription: "ARIA Reflection support"
     
    13561364  category: internal
    13571365
    1358 CSSCustomPropertiesAndValuesEnabled:
    1359   type: bool
    1360   defaultValue: false
    1361   humanReadableName: "CSS Custom Properties and Values API"
    1362   humanReadableDescription: "Enable CSS Custom Properties and Values API"
    1363   webcoreBinding: RuntimeEnabledFeatures
    1364   category: experimental
     1366SelectionAcrossShadowBoundariesEnabled:
     1367  type: bool
     1368  defaultValue: true
     1369  humanReadableName: "Selection across shadow DOM"
     1370  humanReadableDescription: "Allow user-initiated selection across shadow DOM boundaries"
     1371  category: internal
     1372  webcoreName: selectionAcrossShadowBoundariesEnabled
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r236445 r236519  
     12018-09-26  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Selection should work across shadow boundary when initiated by a mouse drag
     4        https://bugs.webkit.org/show_bug.cgi?id=151380
     5        <rdar://problem/24363872>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Added selectionAcrossShadowBoundariesEnabled as a preference to be used in DumpRenderTree.
     10
     11        * WebView/WebPreferenceKeysPrivate.h:
     12        * WebView/WebPreferences.mm:
     13        (+[WebPreferences initialize]):
     14        (-[WebPreferences selectionAcrossShadowBoundariesEnabled]):
     15        (-[WebPreferences setSelectionAcrossShadowBoundariesEnabled:]):
     16        * WebView/WebPreferencesPrivate.h:
     17        * WebView/WebView.mm:
     18        (-[WebView _preferencesChanged:]):
     19
    1202018-09-24  Wenson Hsieh  <wenson_hsieh@apple.com>
    221
  • trunk/Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h

    r235539 r236519  
    263263#define WebKitMediaCapabilitiesEnabledPreferenceKey @"WebKitMediaCapabilitiesEnabled"
    264264#define WebKitServerTimingEnabledPreferenceKey @"WebKitServerTimingEnabled"
     265#define WebKitSelectionAcrossShadowBoundariesEnabledPreferenceKey @"WebKitSelectionAcrossShadowBoundariesEnabled"
  • trunk/Source/WebKitLegacy/mac/WebView/WebPreferences.mm

    r236010 r236519  
    665665        [NSNumber numberWithBool:YES], WebKitPeerConnectionEnabledPreferenceKey,
    666666#endif
     667        [NSNumber numberWithBool:NO], WebKitSelectionAcrossShadowBoundariesEnabledPreferenceKey,
    667668#if ENABLE(INTERSECTION_OBSERVER)
    668669        @NO, WebKitIntersectionObserverEnabledPreferenceKey,
     
    33663367}
    33673368
     3369- (BOOL)selectionAcrossShadowBoundariesEnabled
     3370{
     3371    return [self _boolValueForKey:WebKitSelectionAcrossShadowBoundariesEnabledPreferenceKey];
     3372}
     3373
     3374- (void)setSelectionAcrossShadowBoundariesEnabled:(BOOL)flag
     3375{
     3376    [self _setBoolValue:flag forKey:WebKitSelectionAcrossShadowBoundariesEnabledPreferenceKey];
     3377}
     3378
    33683379@end
    33693380
  • trunk/Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h

    r235539 r236519  
    582582- (void)setServerTimingEnabled:(BOOL)flag;
    583583- (BOOL)serverTimingEnabled;
     584
     585- (void)setSelectionAcrossShadowBoundariesEnabled:(BOOL)flag;
     586- (BOOL)selectionAcrossShadowBoundariesEnabled;
    584587
    585588@property (nonatomic) BOOL visualViewportEnabled;
  • trunk/Source/WebKitLegacy/mac/WebView/WebView.mm

    r236445 r236519  
    31713171
    31723172    RuntimeEnabledFeatures::sharedFeatures().setServerTimingEnabled([preferences serverTimingEnabled]);
     3173
     3174    settings.setSelectionAcrossShadowBoundariesEnabled(preferences.selectionAcrossShadowBoundariesEnabled);
    31733175}
    31743176
  • trunk/Tools/ChangeLog

    r236518 r236519  
     12018-09-26  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Selection should work across shadow boundary when initiated by a mouse drag
     4        https://bugs.webkit.org/show_bug.cgi?id=151380
     5        <rdar://problem/24363872>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Added the support for internal:selectionAcrossShadowBoundariesEnabled test option.
     10
     11        * DumpRenderTree/TestOptions.cpp:
     12        (TestOptions::TestOptions):
     13        * DumpRenderTree/TestOptions.h:
     14        * DumpRenderTree/mac/DumpRenderTree.mm:
     15        (resetWebPreferencesToConsistentValues):
     16        (setWebPreferencesForTestOptions):
     17
    1182018-09-26  Ryosuke Niwa  <rniwa@webkit.org>
    219
  • trunk/Tools/DumpRenderTree/TestOptions.cpp

    r235948 r236519  
    102102        else if (key == "experimental:WebAnimationsCSSIntegrationEnabled")
    103103            enableWebAnimationsCSSIntegration = parseBooleanTestHeaderValue(value);
     104        else if (key == "internal:selectionAcrossShadowBoundariesEnabled")
     105            enableSelectionAcrossShadowBoundaries = parseBooleanTestHeaderValue(value);
    104106        else if (key == "enableColorFilter")
    105107            enableColorFilter = parseBooleanTestHeaderValue(value);
  • trunk/Tools/DumpRenderTree/TestOptions.h

    r232733 r236519  
    4444    bool allowCrossOriginSubresourcesToAskForCredentials { false };
    4545    bool enableColorFilter { false };
     46    bool enableSelectionAcrossShadowBoundaries { false };
    4647    std::string jscOptions;
    4748
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r235806 r236519  
    991991    preferences.mediaCapabilitiesEnabled = YES;
    992992
     993    preferences.selectionAcrossShadowBoundariesEnabled = NO;
     994
    993995    [WebPreferences _clearNetworkLoaderSession];
    994996    [WebPreferences _setCurrentNetworkLoaderSessionCookieAcceptPolicy:NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain];
     
    10091011    preferences.webAnimationsCSSIntegrationEnabled = options.enableWebAnimationsCSSIntegration;
    10101012    preferences.colorFilterEnabled = options.enableColorFilter;
     1013    preferences.selectionAcrossShadowBoundariesEnabled = options.enableSelectionAcrossShadowBoundaries;
    10111014}
    10121015
Note: See TracChangeset for help on using the changeset viewer.