Changeset 250863 in webkit


Ignore:
Timestamp:
Oct 8, 2019 2:56:28 PM (5 years ago)
Author:
timothy@apple.com
Message:

Copying white text from dark mode WebKit apps and pasting in a light mode app results in white (invisible) text.
https://bugs.webkit.org/show_bug.cgi?id=202662
rdar://problem/48677354

Reviewed by Megan Gardner.

Source/WebCore:

Covered by new API tests.

HTMLConverter needs to strip white text colors when the document is in dark mode, like it does for black in light mode.

  • editing/cocoa/HTMLConverter.mm:

(normalizedColor): Handle dark mode and ignore white.
(HTMLConverterCaches::colorPropertyValueForNode): Pass element to normalizedColor.

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/CopyRTF.mm: Added.

(readRTFDataFromPasteboard):
(copyAttributedStringFromHTML):
(checkColor):
(TEST):

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r250861 r250863  
     12019-10-08  Timothy Hatcher  <timothy@apple.com>
     2
     3        Copying white text from dark mode WebKit apps and pasting in a light mode app results in white (invisible) text.
     4        https://bugs.webkit.org/show_bug.cgi?id=202662
     5        rdar://problem/48677354
     6
     7        Reviewed by Megan Gardner.
     8
     9        Covered by new API tests.
     10
     11        HTMLConverter needs to strip white text colors when the document is in dark mode, like it does for black in light mode.
     12
     13        * editing/cocoa/HTMLConverter.mm:
     14        (normalizedColor): Handle dark mode and ignore white.
     15        (HTMLConverterCaches::colorPropertyValueForNode): Pass element to normalizedColor.
     16
    1172019-10-08  Antti Koivisto  <antti@apple.com>
    218
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r248846 r250863  
    856856}
    857857
    858 static Color normalizedColor(Color color, bool ignoreBlack)
    859 {
    860     const double ColorEpsilon = 1 / (2 * (double)255.0);
    861    
    862     double red, green, blue, alpha;
    863     color.getRGBA(red, green, blue, alpha);
    864     if (red < ColorEpsilon && green < ColorEpsilon && blue < ColorEpsilon && (ignoreBlack || alpha < ColorEpsilon))
     858static Color normalizedColor(Color color, bool ignoreDefaultColor, Element& element)
     859{
     860    if (!ignoreDefaultColor)
     861        return color;
     862
     863    bool useDarkAppearance = element.document().useDarkAppearance(element.existingComputedStyle());
     864    if (useDarkAppearance && Color::isWhiteColor(color))
    865865        return Color();
    866    
     866
     867    if (!useDarkAppearance && Color::isBlackColor(color))
     868        return Color();
     869
    867870    return color;
    868871}
     
    876879    }
    877880
     881    bool ignoreDefaultColor = propertyId == CSSPropertyColor;
     882
    878883    Element& element = downcast<Element>(node);
    879884    if (RefPtr<CSSValue> value = computedStylePropertyForElement(element, propertyId)) {
    880885        if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isRGBColor())
    881             return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).color().rgb()), propertyId == CSSPropertyColor);
     886            return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).color().rgb()), ignoreDefaultColor, element);
    882887    }
    883888
     
    885890    if (RefPtr<CSSValue> value = inlineStylePropertyForElement(element, propertyId)) {
    886891        if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isRGBColor())
    887             return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).color().rgb()), propertyId == CSSPropertyColor);
     892            return normalizedColor(Color(downcast<CSSPrimitiveValue>(*value).color().rgb()), ignoreDefaultColor, element);
    888893        if (value->isInheritedValue())
    889894            inherit = true;
  • trunk/Tools/ChangeLog

    r250852 r250863  
     12019-10-08  Timothy Hatcher  <timothy@apple.com>
     2
     3        Copying white text from dark mode WebKit apps and pasting in a light mode app results in white (invisible) text.
     4        https://bugs.webkit.org/show_bug.cgi?id=202662
     5        rdar://problem/48677354
     6
     7        Reviewed by Megan Gardner.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKitCocoa/CopyRTF.mm: Added.
     11        (readRTFDataFromPasteboard):
     12        (copyAttributedStringFromHTML):
     13        (checkColor):
     14        (TEST):
     15
    1162019-10-08  Brady Eidson  <beidson@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r250774 r250863  
    104104                1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81851C89252300A5529F /* Ahem.ttf */; };
    105105                1C734B5320788C4800F430EA /* SystemColors.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C734B5220788C4800F430EA /* SystemColors.mm */; };
     106                1C79201C234BDD9B001EAF23 /* CopyRTF.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C79201B234BDD9B001EAF23 /* CopyRTF.mm */; };
    106107                1C7FEB20207C0F2E00D23278 /* BackgroundColor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */; };
    107108                1C90420C2326E03C00BEF91E /* SelectionByWord.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C90420B2326E03C00BEF91E /* SelectionByWord.mm */; };
     
    15361537                1C2B81851C89252300A5529F /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
    15371538                1C734B5220788C4800F430EA /* SystemColors.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemColors.mm; sourceTree = "<group>"; };
     1539                1C79201B234BDD9B001EAF23 /* CopyRTF.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CopyRTF.mm; sourceTree = "<group>"; };
    15381540                1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BackgroundColor.mm; sourceTree = "<group>"; };
    15391541                1C90420B2326E03C00BEF91E /* SelectionByWord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SelectionByWord.mm; sourceTree = "<group>"; };
     
    27802782                                9B1056411F9045C700D5583F /* CopyHTML.mm */,
    27812783                                9999108A1F393C8B008AD455 /* Copying.mm */,
     2784                                1C79201B234BDD9B001EAF23 /* CopyRTF.mm */,
    27822785                                9B7A37C21F8AEBA5004AA228 /* CopyURL.mm */,
    27832786                                46A911582108E66B0078D40D /* CustomUserAgent.mm */,
     
    44644467                                9B1F6F781F90558400B55744 /* CopyHTML.mm in Sources */,
    44654468                                9999108B1F393C96008AD455 /* Copying.mm in Sources */,
     4469                                1C79201C234BDD9B001EAF23 /* CopyRTF.mm in Sources */,
    44664470                                9B7A37C41F8AEBA5004AA228 /* CopyURL.mm in Sources */,
    44674471                                7CCE7EAC1A411A3400447C4C /* Counters.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.