Changeset 256580 in webkit


Ignore:
Timestamp:
Feb 13, 2020 6:56:32 PM (4 years ago)
Author:
rniwa@webkit.org
Message:

Dark Mode: In Notes, list item becomes invisible in dark mode after outdenting
https://bugs.webkit.org/show_bug.cgi?id=207676

Reviewed by Wenson Hsieh and Timothy Hatcher.

Source/WebCore:

The bug was caused by EditingStyle::inverseTransformColorIfNeeded converting -apple-system-label to
transparent color in ReplaceSelectionCommand when InsertListCommand invokes moveParagraphs.

This patch fixes the bug in EditingStyle::inverseTransformColorIfNeeded by treating any semantic color
name or semantic RGB color value as if the color was not specified.

It also fixes the bug that removeStyleFromRulesAndContext was incapable of removing superflous semantic
color names that appear in the inline since the context's computed style only contain RGB values by
replacing the inline style's color values with that of the computed style. This fix is necessary to
eliminate -apple-system-label in the pasted content, which can cause issues when such a content is
sync'ed to other devices via iCloud, etc...

Tests: PasteHTML.TransformColorsOfDarkContentButNotSemanticColor

PasteHTML.DoesNotTransformColorsOfLightContentDuringOutdent

  • editing/EditingStyle.cpp:

(WebCore::EditingStyle::removeStyleFromRulesAndContext):
(WebCore::EditingStyle::inverseTransformColorIfNeeded):

Tools:

Added regression tests for pasting content with -apple-system-label and outdenting content.

  • TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:

(PasteHTML.TransformColorsOfDarkContentButNotSemanticColor):
(PasteHTML.DoesNotTransformColorsOfLightContentDuringOutdent):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r256571 r256580  
     12020-02-13  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Dark Mode: In Notes, list item becomes invisible in dark mode after outdenting
     4        https://bugs.webkit.org/show_bug.cgi?id=207676
     5
     6        Reviewed by Wenson Hsieh and Timothy Hatcher.
     7
     8        The bug was caused by EditingStyle::inverseTransformColorIfNeeded converting -apple-system-label to
     9        transparent color in ReplaceSelectionCommand when InsertListCommand invokes moveParagraphs.
     10
     11        This patch fixes the bug in EditingStyle::inverseTransformColorIfNeeded by treating any semantic color
     12        name or semantic RGB color value as if the color was not specified.
     13
     14        It also fixes the bug that removeStyleFromRulesAndContext was incapable of removing superflous semantic
     15        color names that appear in the inline since the context's computed style only contain RGB values by
     16        replacing the inline style's color values with that of the computed style. This fix is necessary to
     17        eliminate -apple-system-label in the pasted content, which can cause issues when such a content is
     18        sync'ed to other devices via iCloud, etc...
     19
     20        Tests: PasteHTML.TransformColorsOfDarkContentButNotSemanticColor
     21               PasteHTML.DoesNotTransformColorsOfLightContentDuringOutdent
     22
     23        * editing/EditingStyle.cpp:
     24        (WebCore::EditingStyle::removeStyleFromRulesAndContext):
     25        (WebCore::EditingStyle::inverseTransformColorIfNeeded):
     26
    1272020-02-13  Brent Fulgham  <bfulgham@apple.com>
    228
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r253959 r256580  
    13671367            computedStyle->m_mutableStyle->setProperty(CSSPropertyBackgroundColor, CSSValueTransparent);
    13681368
     1369        RefPtr<EditingStyle> computedStyleOfElement;
     1370        auto replaceSemanticColorWithComputedValue = [&](const CSSPropertyID id) {
     1371            auto color = m_mutableStyle->propertyAsColor(id);
     1372            if (!color || (color->isVisible() && !color->isSemantic()))
     1373                return;
     1374
     1375            if (!computedStyleOfElement)
     1376                computedStyleOfElement = EditingStyle::create(&element, EditingPropertiesInEffect);
     1377
     1378            if (!computedStyleOfElement->m_mutableStyle)
     1379                return;
     1380
     1381            auto computedValue = computedStyleOfElement->m_mutableStyle->getPropertyValue(id);
     1382            if (!computedValue)
     1383                return;
     1384
     1385            m_mutableStyle->setProperty(id, computedValue);
     1386        };
     1387
     1388        // Replace semantic color identifiers like -apple-system-label with RGB values so that comparsions in getPropertiesNotIn below would work.
     1389        replaceSemanticColorWithComputedValue(CSSPropertyColor);
     1390        replaceSemanticColorWithComputedValue(CSSPropertyCaretColor);
     1391        replaceSemanticColorWithComputedValue(CSSPropertyBackgroundColor);
     1392
    13691393        removePropertiesInStyle(computedStyle->m_mutableStyle.get(), styleFromMatchedRules.get());
    13701394        m_mutableStyle = getPropertiesNotIn(*m_mutableStyle, *computedStyle->m_mutableStyle);
     
    15881612        return *this;
    15891613
    1590     bool hasColor = m_mutableStyle->getPropertyCSSValue(CSSPropertyColor);
    1591     bool hasCaretColor = m_mutableStyle->getPropertyCSSValue(CSSPropertyCaretColor);
    1592     bool hasBackgroundColor = m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor);
    1593     if (!hasColor && !hasCaretColor && !hasBackgroundColor)
     1614    auto colorForPropertyIfInvertible = [&](CSSPropertyID id) -> Optional<Color> {
     1615        auto color = m_mutableStyle->propertyAsColor(id);
     1616        if (!color || !color->isVisible() || color->isSemantic())
     1617            return WTF::nullopt;
     1618        return color;
     1619    };
     1620
     1621    auto color = colorForPropertyIfInvertible(CSSPropertyColor);
     1622    auto caretColor = colorForPropertyIfInvertible(CSSPropertyCaretColor);
     1623    auto backgroundColor = colorForPropertyIfInvertible(CSSPropertyBackgroundColor);
     1624    if (!color && !caretColor && !backgroundColor)
    15941625        return *this;
    15951626
     
    16041635    };
    16051636
    1606     if (hasColor)
     1637    if (color)
    16071638        invertedColor(CSSPropertyColor);
    16081639
    1609     if (hasCaretColor)
     1640    if (caretColor)
    16101641        invertedColor(CSSPropertyCaretColor);
    16111642
    1612     if (hasBackgroundColor)
     1643    if (backgroundColor)
    16131644        invertedColor(CSSPropertyBackgroundColor);
    16141645
  • trunk/Tools/ChangeLog

    r256562 r256580  
     12020-02-13  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Dark Mode: In Notes, list item becomes invisible in dark mode after outdenting
     4        https://bugs.webkit.org/show_bug.cgi?id=207676
     5
     6        Reviewed by Wenson Hsieh and Timothy Hatcher.
     7
     8        Added regression tests for pasting content with -apple-system-label and outdenting content.
     9
     10        * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
     11        (PasteHTML.TransformColorsOfDarkContentButNotSemanticColor):
     12        (PasteHTML.DoesNotTransformColorsOfLightContentDuringOutdent):
     13
    1142020-02-13  Alex Christensen  <achristensen@webkit.org>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm

    r249535 r256580  
    421421}
    422422
     423TEST(PasteHTML, TransformColorsOfDarkContentButNotSemanticColor)
     424{
     425    auto webView = createWebViewWithCustomPasteboardDataSetting(true, true);
     426    [webView forceDarkMode];
     427
     428    [webView synchronouslyLoadTestPageNamed:@"rich-color-filtered"];
     429
     430    [webView stringByEvaluatingJavaScript:@"document.body.style.color = '-apple-system-label';"];
     431    writeHTMLToPasteboard(@"<span style='color: -apple-system-label'>hello</span><b style='color: #eee'>world</b>");
     432
     433    [webView stringByEvaluatingJavaScript:@"selectRichText()"];
     434    [webView paste:nil];
     435
     436#if USE(APPKIT)
     437    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.innerHTML"], @"hello<b style=\"color: rgb(21, 21, 21);\">world</b>");
     438#else
     439    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.innerHTML"],
     440        @"<span style=\"-webkit-text-size-adjust: auto;\">hello</span><b style=\"-webkit-text-size-adjust: auto; color: rgb(21, 21, 21);\">world</b>");
     441#endif
     442}
     443
     444TEST(PasteHTML, DoesNotTransformColorsOfLightContentDuringOutdent)
     445{
     446    auto webView = createWebViewWithCustomPasteboardDataSetting(true, true);
     447    [webView forceDarkMode];
     448
     449    [webView synchronouslyLoadTestPageNamed:@"rich-color-filtered"];
     450
     451    [webView stringByEvaluatingJavaScript:@"document.body.style = `color: -apple-system-label; caret-color: -apple-system-secondary-label; background-color: -apple-system-text-background;`;"];
     452    [webView stringByEvaluatingJavaScript:@"rich.innerHTML = `<ul><li>hello</li><ul><li id='target'>world</li></ul></ul>`;"];
     453
     454    [webView stringByEvaluatingJavaScript:@"getSelection().setPosition(target, 0); document.execCommand('outdent');"];
     455
     456    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"rich.innerHTML"], @"<ul><li>hello</li><li>world</li></ul>");
     457}
     458
    423459#endif // ENABLE(DARK_MODE_CSS) && HAVE(OS_DARK_MODE_SUPPORT)
    424460
Note: See TracChangeset for help on using the changeset viewer.