Changeset 249517 in webkit


Ignore:
Timestamp:
Sep 4, 2019 7:52:40 PM (5 years ago)
Author:
timothy@apple.com
Message:

Mail appears to be double inverting code copied from Notes, Xcode, or Terminal.
https://bugs.webkit.org/show_bug.cgi?id=201368
rdar://problem/40529867

Reviewed by Ryosuke Niwa.

Source/WebCore:

Dark mode content that is pasted should have the inline styles inverse color
transformed by the color filter to match the color filtered document contents.

Layout Test: editing/pasteboard/paste-dark-mode-color-filtered.html
API Tests: PasteHTML.TransformColorsOfDarkContent, PasteHTML.DoesNotTransformColorsOfLightContent,

PasteRTFD.TransformColorsOfDarkContent, PasteRTFD.DoesNotTransformColorsOfLightContent

  • editing/EditingStyle.cpp:

(WebCore::EditingStyle::inverseTransformColorIfNeeded): Added caret-color to the transformed properties.

  • editing/ReplaceSelectionCommand.cpp:

(WebCore::fragmentNeedsColorTransformed): Added.
(WebCore::ReplaceSelectionCommand::inverseTransformColor): Added.
(WebCore::ReplaceSelectionCommand::doApply): Call fragmentNeedsColorTransformed() and inverseTransformColor().

  • editing/ReplaceSelectionCommand.h:

Tools:

Added Tests: PasteHTML.TransformColorsOfDarkContent, PasteHTML.DoesNotTransformColorsOfLightContent,

PasteRTFD.TransformColorsOfDarkContent, PasteRTFD.DoesNotTransformColorsOfLightContent

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:

(createWebViewWithCustomPasteboardDataSetting): Added argument to enable color filter.

  • TestWebKitAPI/Tests/WebKitCocoa/PasteRTFD.mm:

(createWebViewWithCustomPasteboardDataEnabled): Added argument to enable color filter.

  • TestWebKitAPI/Tests/WebKitCocoa/rich-color-filtered.html: Added.
  • TestWebKitAPI/cocoa/TestWKWebView.h:
  • TestWebKitAPI/cocoa/TestWKWebView.mm:

(-[TestWKWebView forceDarkMode]):

LayoutTests:

  • TestExpectations:
  • editing/pasteboard/paste-dark-mode-color-filtered-expected.txt: Added.
  • editing/pasteboard/paste-dark-mode-color-filtered.html: Added.
  • platform/ios-12/TestExpectations:
  • platform/ios/TestExpectations:
  • platform/mac/TestExpectations:
Location:
trunk
Files:
3 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249511 r249517  
     12019-09-04  Timothy Hatcher  <timothy@apple.com>
     2
     3        Mail appears to be double inverting code copied from Notes, Xcode, or Terminal.
     4        https://bugs.webkit.org/show_bug.cgi?id=201368
     5        rdar://problem/40529867
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        * TestExpectations:
     10        * editing/pasteboard/paste-dark-mode-color-filtered-expected.txt: Added.
     11        * editing/pasteboard/paste-dark-mode-color-filtered.html: Added.
     12        * platform/ios-12/TestExpectations:
     13        * platform/ios/TestExpectations:
     14        * platform/mac/TestExpectations:
     15
    1162019-09-04  Yusuke Suzuki  <ysuzuki@apple.com>
    217
  • trunk/LayoutTests/TestExpectations

    r249360 r249517  
    8888fast/images/eps-as-image.html [ Skip ]
    8989
    90 # Only applicable on macOS
     90# Only applicable on platforms with dark mode support
    9191css-dark-mode [ Skip ]
    9292fast/css/apple-system-control-colors.html [ Skip ]
    9393inspector/css/force-page-appearance.html [ Skip ]
     94editing/pasteboard/paste-dark-mode-color-filtered.html [ Skip ]
    9495
    9596# Only Mac supports force tests.
  • trunk/LayoutTests/platform/ios-12/TestExpectations

    r249157 r249517  
    11css-dark-mode [ Skip ]
    22css-dark-mode/older-systems [ Pass ]
     3editing/pasteboard/paste-dark-mode-color-filtered.html [ Skip ]
    34
    45# <rdar://problem/48781098> HEIF and HEICS images are supported only on iOS 13
  • trunk/LayoutTests/platform/ios/TestExpectations

    r249176 r249517  
    32433243css-dark-mode [ Pass ]
    32443244css-dark-mode/older-systems [ Skip ]
     3245editing/pasteboard/paste-dark-mode-color-filtered.html [ Pass ]
    32453246
    32463247fast/forms/auto-fill-button/caps-lock-indicator-should-be-visible-after-hiding-auto-fill-strong-password-button.html [ Pass ]
  • trunk/LayoutTests/platform/mac/TestExpectations

    r249205 r249517  
    17501750[ Mojave+ ] css-dark-mode/older-systems [ Skip ]
    17511751[ Mojave+ ] inspector/css/force-page-appearance.html [ Pass ]
     1752[ Mojave+ ] editing/pasteboard/paste-dark-mode-color-filtered.html [ Pass ]
    17521753
    17531754# Test Dark Mode CSS support for light mode on older systems.
  • trunk/Source/WebCore/ChangeLog

    r249516 r249517  
     12019-09-04  Timothy Hatcher  <timothy@apple.com>
     2
     3        Mail appears to be double inverting code copied from Notes, Xcode, or Terminal.
     4        https://bugs.webkit.org/show_bug.cgi?id=201368
     5        rdar://problem/40529867
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Dark mode content that is pasted should have the inline styles inverse color
     10        transformed by the color filter to match the color filtered document contents.
     11
     12        Layout Test: editing/pasteboard/paste-dark-mode-color-filtered.html
     13        API Tests: PasteHTML.TransformColorsOfDarkContent, PasteHTML.DoesNotTransformColorsOfLightContent,
     14            PasteRTFD.TransformColorsOfDarkContent, PasteRTFD.DoesNotTransformColorsOfLightContent
     15
     16        * editing/EditingStyle.cpp:
     17        (WebCore::EditingStyle::inverseTransformColorIfNeeded): Added caret-color to the transformed properties.
     18        * editing/ReplaceSelectionCommand.cpp:
     19        (WebCore::fragmentNeedsColorTransformed): Added.
     20        (WebCore::ReplaceSelectionCommand::inverseTransformColor): Added.
     21        (WebCore::ReplaceSelectionCommand::doApply): Call fragmentNeedsColorTransformed() and inverseTransformColor().
     22        * editing/ReplaceSelectionCommand.h:
     23
    1242019-09-04  Chris Dumez  <cdumez@apple.com>
    225
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r247720 r249517  
    15811581
    15821582    bool hasColor = m_mutableStyle->getPropertyCSSValue(CSSPropertyColor);
     1583    bool hasCaretColor = m_mutableStyle->getPropertyCSSValue(CSSPropertyCaretColor);
    15831584    bool hasBackgroundColor = m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor);
    1584     if (!hasColor && !hasBackgroundColor)
     1585    if (!hasColor && !hasCaretColor && !hasBackgroundColor)
    15851586        return *this;
    15861587
     
    15971598    if (hasColor)
    15981599        invertedColor(CSSPropertyColor);
     1600
     1601    if (hasCaretColor)
     1602        invertedColor(CSSPropertyCaretColor);
    15991603
    16001604    if (hasBackgroundColor)
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r249307 r249517  
    5656#include "NodeList.h"
    5757#include "NodeRenderStyle.h"
     58#include "Position.h"
    5859#include "RenderInline.h"
    5960#include "RenderText.h"
     
    519520        // be a no-op and cause infinite recursion.
    520521        && !isBlock(sourceNode) && !isBlock(destinationNode);
     522}
     523
     524static bool fragmentNeedsColorTransformed(ReplacementFragment& fragment, const Position& insertionPos)
     525{
     526    // Dark mode content that is inserted should have the inline styles inverse color
     527    // transformed by the color filter to match the color filtered document contents.
     528    // This applies to Mail and Notes when pasting from Xcode. <rdar://problem/40529867>
     529
     530    RefPtr<Element> editableRoot = insertionPos.rootEditableElement();
     531    ASSERT(editableRoot);
     532    if (!editableRoot)
     533        return false;
     534
     535    auto* editableRootRenderer = editableRoot->renderer();
     536    if (!editableRootRenderer || !editableRootRenderer->style().hasAppleColorFilter())
     537        return false;
     538
     539    const auto& colorFilter = editableRootRenderer->style().appleColorFilter();
     540    for (const auto& colorFilterOperation : colorFilter.operations()) {
     541        if (colorFilterOperation->type() != FilterOperation::APPLE_INVERT_LIGHTNESS)
     542            return false;
     543    }
     544
     545    auto propertyLightness = [&](const StyleProperties& inlineStyle, CSSPropertyID propertyID) -> Optional<double> {
     546        auto color = inlineStyle.propertyAsColor(propertyID);
     547        if (!color || !color.value().isVisible() || color.value().isSemantic())
     548            return { };
     549
     550        double hue, saturation, lightness;
     551        color.value().getHSL(hue, saturation, lightness);
     552        return lightness;
     553    };
     554
     555    const double lightnessDarkEnoughForText = 0.4;
     556    const double lightnessLightEnoughForBackground = 0.6;
     557
     558    for (RefPtr<Node> node = fragment.firstChild(); node; node = NodeTraversal::next(*node)) {
     559        if (!is<StyledElement>(*node))
     560            continue;
     561
     562        auto& element = downcast<StyledElement>(*node);
     563        auto* inlineStyle = element.inlineStyle();
     564        if (!inlineStyle)
     565            continue;
     566
     567        auto textLightness = propertyLightness(*inlineStyle, CSSPropertyColor);
     568        if (textLightness && *textLightness < lightnessDarkEnoughForText)
     569            return false;
     570
     571        auto backgroundLightness = propertyLightness(*inlineStyle, CSSPropertyBackgroundColor);
     572        if (backgroundLightness && *backgroundLightness > lightnessLightEnoughForBackground)
     573            return false;
     574    }
     575
     576    return true;
     577}
     578
     579void ReplaceSelectionCommand::inverseTransformColor(InsertedNodes& insertedNodes)
     580{
     581    RefPtr<Node> pastEndNode = insertedNodes.pastLastLeaf();
     582    for (RefPtr<Node> node = insertedNodes.firstNodeInserted(); node && node != pastEndNode; node = NodeTraversal::next(*node)) {
     583        if (!is<StyledElement>(*node))
     584            continue;
     585
     586        auto& element = downcast<StyledElement>(*node);
     587        auto* inlineStyle = element.inlineStyle();
     588        if (!inlineStyle)
     589            continue;
     590
     591        auto editingStyle = EditingStyle::create(inlineStyle);
     592        auto transformedStyle = editingStyle->inverseTransformColorIfNeeded(element);
     593        if (editingStyle.ptr() == transformedStyle.ptr())
     594            continue;
     595
     596        setNodeAttribute(element, styleAttr, transformedStyle->style()->asText());
     597    }
    521598}
    522599
     
    11161193
    11171194    bool hasBlankLinesBetweenParagraphs = hasBlankLineBetweenParagraphs(insertionPos);
    1118    
    11191195    bool handledStyleSpans = handleStyleSpansBeforeInsertion(fragment, insertionPos);
     1196    bool needsColorTransformed = fragmentNeedsColorTransformed(fragment, insertionPos);
    11201197
    11211198    // We're finished if there is nothing to add.
     
    12281305        }
    12291306    }
    1230    
     1307
    12311308    makeInsertedContentRoundTrippableWithHTMLTreeBuilder(insertedNodes);
    12321309    if (insertedNodes.isEmpty())
    12331310        return;
     1311
     1312    if (needsColorTransformed)
     1313        inverseTransformColor(insertedNodes);
    12341314
    12351315    removeRedundantStylesAndKeepStyleSpanInline(insertedNodes);
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.h

    r243124 r249517  
    100100   
    101101    void removeRedundantStylesAndKeepStyleSpanInline(InsertedNodes&);
     102    void inverseTransformColor(InsertedNodes&);
    102103    void makeInsertedContentRoundTrippableWithHTMLTreeBuilder(InsertedNodes&);
    103104    void moveNodeOutOfAncestor(Node&, Node& ancestor, InsertedNodes&);
  • trunk/Tools/ChangeLog

    r249514 r249517  
     12019-09-04  Timothy Hatcher  <timothy@apple.com>
     2
     3        Mail appears to be double inverting code copied from Notes, Xcode, or Terminal.
     4        https://bugs.webkit.org/show_bug.cgi?id=201368
     5        rdar://problem/40529867
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Added Tests: PasteHTML.TransformColorsOfDarkContent, PasteHTML.DoesNotTransformColorsOfLightContent,
     10            PasteRTFD.TransformColorsOfDarkContent, PasteRTFD.DoesNotTransformColorsOfLightContent
     11
     12        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     13        * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
     14        (createWebViewWithCustomPasteboardDataSetting): Added argument to enable color filter.
     15        * TestWebKitAPI/Tests/WebKitCocoa/PasteRTFD.mm:
     16        (createWebViewWithCustomPasteboardDataEnabled): Added argument to enable color filter.
     17        * TestWebKitAPI/Tests/WebKitCocoa/rich-color-filtered.html: Added.
     18        * TestWebKitAPI/cocoa/TestWKWebView.h:
     19        * TestWebKitAPI/cocoa/TestWKWebView.mm:
     20        (-[TestWKWebView forceDarkMode]):
     21
    1222019-09-04  Wenson Hsieh  <wenson_hsieh@apple.com>
    223
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r249311 r249517  
    107107                1C9EB8411E380DA1005C6442 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */; };
    108108                1CACADA1230620AE0007D54C /* WKWebViewOpaque.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CACADA0230620AD0007D54C /* WKWebViewOpaque.mm */; };
     109                1CE6FAC32320267C00E48F6E /* rich-color-filtered.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1CE6FAC12320264F00E48F6E /* rich-color-filtered.html */; };
    109110                1CF59AE221E68925006E37EC /* ForceLightAppearanceInBundle_Bundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CF59AE021E68925006E37EC /* ForceLightAppearanceInBundle_Bundle.mm */; };
    110111                1CF59AE321E68932006E37EC /* ForceLightAppearanceInBundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CF59ADF21E68925006E37EC /* ForceLightAppearanceInBundle.mm */; };
     
    13731374                                A12DDC001E8373E700CF6CAE /* rendered-image-excluding-overflow.html in Copy Resources */,
    13741375                                F46849C01EEF5EF300B937FE /* rich-and-plain-text.html in Copy Resources */,
     1376                                1CE6FAC32320267C00E48F6E /* rich-color-filtered.html in Copy Resources */,
    13751377                                2E92B8F7216490D4005B64F0 /* rich-text-attributes.html in Copy Resources */,
    13761378                                0F5651F91FCE513500310FBC /* scroll-to-anchor.html in Copy Resources */,
     
    15251527                1CACADA0230620AD0007D54C /* WKWebViewOpaque.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewOpaque.mm; sourceTree = "<group>"; };
    15261528                1CB9BC371A67482300FE5678 /* WeakPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakPtr.cpp; sourceTree = "<group>"; };
     1529                1CE6FAC12320264F00E48F6E /* rich-color-filtered.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "rich-color-filtered.html"; sourceTree = "<group>"; };
    15271530                1CF0D3781BBF2F3D00B4EF54 /* WKRetainPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKRetainPtr.cpp; sourceTree = "<group>"; };
    15281531                1CF59ADF21E68925006E37EC /* ForceLightAppearanceInBundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ForceLightAppearanceInBundle.mm; sourceTree = "<group>"; };
     
    33043307                                A12DDBFF1E8373C100CF6CAE /* rendered-image-excluding-overflow.html */,
    33053308                                F46849BF1EEF5EDC00B937FE /* rich-and-plain-text.html */,
     3309                                1CE6FAC12320264F00E48F6E /* rich-color-filtered.html */,
    33063310                                2E92B8F6216490C3005B64F0 /* rich-text-attributes.html */,
    33073311                                F4E0A295211FC5A300AF7C7F /* selected-text-and-textarea.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm

    r247720 r249517  
    5858#endif
    5959
    60 static RetainPtr<TestWKWebView> createWebViewWithCustomPasteboardDataSetting(bool enabled)
    61 {
    62     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
     60static RetainPtr<TestWKWebView> createWebViewWithCustomPasteboardDataSetting(bool enabled, bool colorFilterEnabled = false)
     61{
     62    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
     63    [webViewConfiguration _setColorFilterEnabled:colorFilterEnabled];
     64
     65    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400) configuration:webViewConfiguration.get()]);
    6366    auto preferences = (__bridge WKPreferencesRef)[[webView configuration] preferences];
    6467    WKPreferencesSetDataTransferItemsEnabled(preferences, true);
     
    358361}
    359362
     363#if ENABLE(DARK_MODE_CSS) && HAVE(OS_DARK_MODE_SUPPORT)
     364
     365TEST(PasteHTML, TransformColorsOfDarkContent)
     366{
     367    auto webView = createWebViewWithCustomPasteboardDataSetting(true, true);
     368    [webView forceDarkMode];
     369
     370    [webView synchronouslyLoadTestPageNamed:@"rich-color-filtered"];
     371
     372    writeHTMLToPasteboard(@"<span style=\"color: rgb(238, 238, 238); background-color: rgb(51, 51, 51)\">Hello</span>");
     373
     374    [webView stringByEvaluatingJavaScript:@"selectRichText()"];
     375    [webView paste:nil];
     376
     377    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('span').style.color"], @"rgb(21, 21, 21)");
     378    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('span').style.backgroundColor"], @"rgb(255, 255, 255)");
     379}
     380
     381TEST(PasteHTML, DoesNotTransformColorsOfLightContent)
     382{
     383    auto webView = createWebViewWithCustomPasteboardDataSetting(true, true);
     384    [webView forceDarkMode];
     385
     386    [webView synchronouslyLoadTestPageNamed:@"rich-color-filtered"];
     387
     388    writeHTMLToPasteboard(@"<span style=\"color: rgb(101, 101, 101)\">Hello</span>");
     389
     390    [webView stringByEvaluatingJavaScript:@"selectRichText()"];
     391    [webView paste:nil];
     392
     393    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('span').style.color"], @"rgb(101, 101, 101)");
     394}
     395
     396#endif // ENABLE(DARK_MODE_CSS) && HAVE(OS_DARK_MODE_SUPPORT)
     397
    360398#endif // PLATFORM(COCOA)
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteRTFD.mm

    r242339 r249517  
    4040#endif
    4141
     42#if USE(APPKIT)
     43using PlatformColor = NSColor;
     44#else
     45using PlatformColor = UIColor;
     46#endif
     47
    4248@interface WKWebView ()
    4349- (void)paste:(id)sender;
     
    7783#endif
    7884
    79 static RetainPtr<TestWKWebView> createWebViewWithCustomPasteboardDataEnabled()
    80 {
    81     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
     85static RetainPtr<TestWKWebView> createWebViewWithCustomPasteboardDataEnabled(bool colorFilterEnabled = false)
     86{
     87    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
     88    [webViewConfiguration _setColorFilterEnabled:colorFilterEnabled];
     89
     90    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400) configuration:webViewConfiguration.get()]);
    8291    auto preferences = (__bridge WKPreferencesRef)[[webView configuration] preferences];
    8392    WKPreferencesSetDataTransferItemsEnabled(preferences, true);
     
    177186}
    178187
    179 #endif // PLATFORM(MAC)
    180 
    181 
    182 
     188#if ENABLE(DARK_MODE_CSS) && HAVE(OS_DARK_MODE_SUPPORT)
     189
     190TEST(PasteRTFD, TransformColorsOfDarkContent)
     191{
     192    auto webView = createWebViewWithCustomPasteboardDataEnabled(true);
     193    [webView forceDarkMode];
     194
     195    [webView synchronouslyLoadTestPageNamed:@"rich-color-filtered"];
     196
     197    PlatformColor *textColor = [PlatformColor lightGrayColor];
     198    PlatformColor *backgroundColor = [PlatformColor darkGrayColor];
     199
     200    auto hello = adoptNS([[NSAttributedString alloc] initWithString:@"Hello" attributes:@{ NSBackgroundColorAttributeName : backgroundColor, NSForegroundColorAttributeName : textColor }]);
     201    auto world = adoptNS([[NSAttributedString alloc] initWithString:@" World" attributes:@{ NSForegroundColorAttributeName : textColor }]);
     202    auto string = adoptNS([[NSMutableAttributedString alloc] init]);
     203    [string appendAttributedString:hello.get()];
     204    [string appendAttributedString:world.get()];
     205
     206    writeRTFToPasteboard([string RTFFromRange:NSMakeRange(0, [string length]) documentAttributes:@{ }]);
     207
     208    [webView stringByEvaluatingJavaScript:@"selectRichText()"];
     209    [webView paste:nil];
     210
     211#if USE(APPKIT)
     212    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('p').style.color"], @"rgb(126, 126, 126)");
     213    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('p > span').style.backgroundColor"], @"rgb(235, 235, 235)");
     214#else
     215    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('p').style.color"], @"rgb(106, 106, 106)");
     216    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('p > span').style.backgroundColor"], @"rgb(213, 213, 213)");
     217#endif
     218}
     219
     220TEST(PasteRTFD, DoesNotTransformColorsOfLightContent)
     221{
     222    auto webView = createWebViewWithCustomPasteboardDataEnabled(true);
     223    [webView forceDarkMode];
     224
     225    [webView synchronouslyLoadTestPageNamed:@"rich-color-filtered"];
     226
     227    PlatformColor *textColor = [PlatformColor darkGrayColor];
     228    PlatformColor *backgroundColor = [PlatformColor lightGrayColor];
     229
     230    auto hello = adoptNS([[NSAttributedString alloc] initWithString:@"Hello" attributes:@{ NSBackgroundColorAttributeName : backgroundColor, NSForegroundColorAttributeName : textColor }]);
     231    auto world = adoptNS([[NSAttributedString alloc] initWithString:@" World" attributes:@{ NSForegroundColorAttributeName : textColor }]);
     232    auto string = adoptNS([[NSMutableAttributedString alloc] init]);
     233    [string appendAttributedString:hello.get()];
     234    [string appendAttributedString:world.get()];
     235
     236    writeRTFToPasteboard([string RTFFromRange:NSMakeRange(0, [string length]) documentAttributes:@{ }]);
     237
     238    [webView stringByEvaluatingJavaScript:@"selectRichText()"];
     239    [webView paste:nil];
     240
     241#if USE(APPKIT)
     242    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('p').style.color"], @"rgb(67, 67, 67)");
     243    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('p > span').style.backgroundColor"], @"rgb(154, 154, 154)");
     244#else
     245    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('p').style.color"], @"rgb(85, 85, 85)");
     246    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.querySelector('p > span').style.backgroundColor"], @"rgb(170, 170, 170)");
     247#endif
     248}
     249
     250#endif // ENABLE(DARK_MODE_CSS) && HAVE(OS_DARK_MODE_SUPPORT)
     251
     252#endif // PLATFORM(COCOA)
  • trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h

    r248820 r249517  
    7676- (void)performAfterLoading:(dispatch_block_t)actions;
    7777- (void)waitForNextPresentationUpdate;
     78- (void)forceDarkMode;
    7879- (NSString *)stylePropertyAtSelectionStart:(NSString *)propertyName;
    7980- (NSString *)stylePropertyAtSelectionEnd:(NSString *)propertyName;
  • trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

    r249327 r249517  
    435435}
    436436
     437- (void)forceDarkMode
     438{
     439#if HAVE(OS_DARK_MODE_SUPPORT)
     440#if USE(APPKIT)
     441    [self setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
     442#else
     443    [self setOverrideUserInterfaceStyle:UIUserInterfaceStyleDark];
     444#endif
     445#endif
     446}
     447
    437448- (NSString *)stylePropertyAtSelectionStart:(NSString *)propertyName
    438449{
Note: See TracChangeset for help on using the changeset viewer.