Changeset 233280 in webkit


Ignore:
Timestamp:
Jun 27, 2018 3:14:53 PM (6 years ago)
Author:
timothy@apple.com
Message:

Find on page selection color isn't adapted for dark mode.
https://bugs.webkit.org/show_bug.cgi?id=187072
rdar://problem/40354841

Reviewed by Tim Horton.

Source/WebCore:

  • page/mac/TextIndicatorWindow.mm:

(-[WebTextIndicatorView initWithFrame:textIndicator:margin:offset:]): Use [NSColor findHighlightColor].

  • platform/mac/LocalDefaultSystemAppearance.h:

(WebCore::LocalDefaultSystemAppearance::usingDarkAppearance const): Added.

  • platform/mac/LocalDefaultSystemAppearance.mm:

(WebCore::LocalDefaultSystemAppearance::LocalDefaultSystemAppearance): Set m_usingDarkAppearance.

  • rendering/InlineTextBox.cpp:

(WebCore::InlineTextBox::paintPlatformDocumentMarkers): Use TextPaintPhase::Decoration since this
matches step three of InlineTextBox::paint ("Paint fancy decorations"). This allows TextMatch to
paint a forground and not end up painting during this "fancy decorations" phase.
(WebCore::InlineTextBox::resolveStyleForMarkedText): Set the fillColor for TextMarker to force a
dark text color which will draw over the yellow highlight.
(WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): Added support for TextPaintPhase::Decoration.
Seperate DocumentMarker::TelephoneNumber and DocumentMarker::TextMatch. Have DocumentMarker::TextMatch
support Forground and Background phases.

  • rendering/RenderTheme.cpp:

(WebCore::RenderTheme::platformColorsDidChange):
(WebCore::RenderTheme::activeTextSearchHighlightColor const): Added. Call the platfrom version.
(WebCore::RenderTheme::inactiveTextSearchHighlightColor const): Added. Ditto.
(WebCore::RenderTheme::platformActiveTextSearchHighlightColor const): Added StyleColor::Options.
(WebCore::RenderTheme::platformInactiveTextSearchHighlightColor const): Ditto.

  • rendering/RenderTheme.h:
  • rendering/RenderThemeMac.h:
  • rendering/RenderThemeMac.mm:

(WebCore::RenderThemeMac::platformActiveTextSearchHighlightColor const): Added.
(WebCore::RenderThemeMac::platformInactiveTextSearchHighlightColor const): Added.
(WebCore::RenderThemeMac::platformColorsDidChange): Clear new color caches.
(WebCore::RenderThemeMac::systemColor const): Cache system colors by light and dark mode.

LayoutTests:

  • fast/css/apple-system-control-colors-expected.txt: Updated.
  • fast/text/mark-matches-broken-line-rendering-expected.html: Ditto.
  • fast/text/mark-matches-rendering-expected.html: Ditto.
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r233269 r233280  
     12018-06-27  Timothy Hatcher  <timothy@apple.com>
     2
     3        Find on page selection color isn't adapted for dark mode.
     4        https://bugs.webkit.org/show_bug.cgi?id=187072
     5        rdar://problem/40354841
     6
     7        Reviewed by Tim Horton.
     8
     9        * fast/css/apple-system-control-colors-expected.txt: Updated.
     10        * fast/text/mark-matches-broken-line-rendering-expected.html: Ditto.
     11        * fast/text/mark-matches-rendering-expected.html: Ditto.
     12
    1132018-06-27  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/LayoutTests/fast/css/apple-system-control-colors-expected.txt

    r232878 r233280  
    1313-apple-system-unemphasized-selected-text-background : rgb(212, 212, 212)
    1414-apple-system-placeholder-text : rgba(0, 0, 0, 0.247059)
    15 -apple-system-find-highlight-background : rgb(255, 255, 0)
     15-apple-system-find-highlight-background : rgb(255, 204, 0)
    1616-apple-system-label : rgba(0, 0, 0, 0.85098)
    1717-apple-system-secondary-label : rgba(0, 0, 0, 0.498039)
  • trunk/LayoutTests/fast/text/mark-matches-broken-line-rendering-expected.html

    r188527 r233280  
    77
    88span {
    9     background-color: yellow;
     9    background-color: rgb(255, 204, 0);
     10    color: -apple-system-label;
    1011}
    1112</style>
  • trunk/LayoutTests/fast/text/mark-matches-rendering-expected.html

    r169199 r233280  
    1 <p style="display:inline-block; background-color:yellow">
     1<p style="display: inline-block; background-color: rgb(255, 204, 0); color: -apple-system-label">
    22Quo usque tandem abutere, Catilina, patientia nostra?
    33</p>
  • trunk/Source/WebCore/ChangeLog

    r233279 r233280  
     12018-06-27  Timothy Hatcher  <timothy@apple.com>
     2
     3        Find on page selection color isn't adapted for dark mode.
     4        https://bugs.webkit.org/show_bug.cgi?id=187072
     5        rdar://problem/40354841
     6
     7        Reviewed by Tim Horton.
     8
     9        * page/mac/TextIndicatorWindow.mm:
     10        (-[WebTextIndicatorView initWithFrame:textIndicator:margin:offset:]): Use [NSColor findHighlightColor].
     11        * platform/mac/LocalDefaultSystemAppearance.h:
     12        (WebCore::LocalDefaultSystemAppearance::usingDarkAppearance const): Added.
     13        * platform/mac/LocalDefaultSystemAppearance.mm:
     14        (WebCore::LocalDefaultSystemAppearance::LocalDefaultSystemAppearance): Set m_usingDarkAppearance.
     15        * rendering/InlineTextBox.cpp:
     16        (WebCore::InlineTextBox::paintPlatformDocumentMarkers): Use TextPaintPhase::Decoration since this
     17        matches step three of InlineTextBox::paint ("Paint fancy decorations"). This allows TextMatch to
     18        paint a forground and not end up painting during this "fancy decorations" phase.
     19        (WebCore::InlineTextBox::resolveStyleForMarkedText): Set the fillColor for TextMarker to force a
     20        dark text color which will draw over the yellow highlight.
     21        (WebCore::InlineTextBox::collectMarkedTextsForDocumentMarkers): Added support for TextPaintPhase::Decoration.
     22        Seperate DocumentMarker::TelephoneNumber and DocumentMarker::TextMatch. Have DocumentMarker::TextMatch
     23        support Forground and Background phases.
     24        * rendering/RenderTheme.cpp:
     25        (WebCore::RenderTheme::platformColorsDidChange):
     26        (WebCore::RenderTheme::activeTextSearchHighlightColor const): Added. Call the platfrom version.
     27        (WebCore::RenderTheme::inactiveTextSearchHighlightColor const): Added. Ditto.
     28        (WebCore::RenderTheme::platformActiveTextSearchHighlightColor const): Added StyleColor::Options.
     29        (WebCore::RenderTheme::platformInactiveTextSearchHighlightColor const): Ditto.
     30        * rendering/RenderTheme.h:
     31        * rendering/RenderThemeMac.h:
     32        * rendering/RenderThemeMac.mm:
     33        (WebCore::RenderThemeMac::platformActiveTextSearchHighlightColor const): Added.
     34        (WebCore::RenderThemeMac::platformInactiveTextSearchHighlightColor const): Added.
     35        (WebCore::RenderThemeMac::platformColorsDidChange): Clear new color caches.
     36        (WebCore::RenderThemeMac::systemColor const): Cache system colors by light and dark mode.
     37
    1382018-06-27  Chris Dumez  <cdumez@apple.com>
    239
  • trunk/Source/WebCore/page/mac/TextIndicatorWindow.mm

    r232501 r233280  
    3535#import "WebActionDisablingCALayerDelegate.h"
    3636#import <pal/spi/cg/CoreGraphicsSPI.h>
     37#import <pal/spi/cocoa/NSColorSPI.h>
    3738#import <pal/spi/cocoa/QuartzCoreSPI.h>
    3839
     
    169170    RetainPtr<NSMutableArray> bounceLayers = adoptNS([[NSMutableArray alloc] init]);
    170171
    171     RetainPtr<CGColorRef> highlightColor = [NSColor colorWithDeviceRed:1 green:1 blue:0 alpha:1].CGColor;
     172#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
     173    RetainPtr<CGColorRef> highlightColor = [NSColor findHighlightColor].CGColor;
     174#else
     175    RetainPtr<CGColorRef> highlightColor = [NSColor colorWithDeviceRed:1 green:0.8 blue:0 alpha:1].CGColor;
     176#endif
    172177    RetainPtr<CGColorRef> rimShadowColor = [NSColor colorWithDeviceWhite:0 alpha:0.35].CGColor;
    173178    RetainPtr<CGColorRef> dropShadowColor = [NSColor colorWithDeviceWhite:0 alpha:0.2].CGColor;
  • trunk/Source/WebCore/platform/mac/LocalDefaultSystemAppearance.h

    r233116 r233280  
    3939class LocalDefaultSystemAppearance {
    4040    WTF_MAKE_NONCOPYABLE(LocalDefaultSystemAppearance);
     41
    4142public:
    4243    WEBCORE_EXPORT LocalDefaultSystemAppearance(bool useSystemAppearance, bool useDefaultAppearance);
    4344    WEBCORE_EXPORT ~LocalDefaultSystemAppearance();
     45
     46    bool usingDarkAppearance() const
     47    {
     48#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
     49        return m_usingDarkAppearance;
     50#else
     51        return false;
     52#endif
     53    }
     54
    4455private:
    4556#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
    4657    RetainPtr<NSAppearance> m_savedSystemAppearance;
     58    bool m_usingDarkAppearance { false };
    4759#endif
    4860};
  • trunk/Source/WebCore/platform/mac/LocalDefaultSystemAppearance.mm

    r233116 r233280  
    4343
    4444    m_savedSystemAppearance = [NSAppearance currentAppearance];
    45     [NSAppearance setCurrentAppearance:[NSAppearance appearanceNamed:(!useSystemAppearance || useDefaultAppearance ? NSAppearanceNameAqua : NSAppearanceNameDarkAqua)]];
     45    m_usingDarkAppearance = useSystemAppearance && !useDefaultAppearance;
     46
     47    [NSAppearance setCurrentAppearance:[NSAppearance appearanceNamed:m_usingDarkAppearance ? NSAppearanceNameDarkAqua : NSAppearanceNameAqua]];
    4648#else
    4749    UNUSED_PARAM(useSystemAppearance);
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r233267 r233280  
    654654void InlineTextBox::paintPlatformDocumentMarkers(GraphicsContext& context, const FloatPoint& boxOrigin)
    655655{
    656     for (auto& markedText : subdivide(collectMarkedTextsForDocumentMarkers(TextPaintPhase::Foreground), OverlapStrategy::Frontmost))
     656    for (auto& markedText : subdivide(collectMarkedTextsForDocumentMarkers(TextPaintPhase::Decoration), OverlapStrategy::Frontmost))
    657657        paintPlatformDocumentMarker(context, boxOrigin, markedText);
    658658}
     
    764764        break;
    765765    }
    766     case MarkedText::TextMatch:
    767         style.backgroundColor = markedText.marker->isActiveMatch() ? renderer().theme().platformActiveTextSearchHighlightColor() : renderer().theme().platformInactiveTextSearchHighlightColor();
     766    case MarkedText::TextMatch: {
     767        // Text matches always use the light system appearance.
     768        OptionSet<StyleColor::Options> styleColorOptions = { StyleColor::Options::UseSystemAppearance, StyleColor::Options::UseDefaultAppearance };
     769#if PLATFORM(MAC)
     770        style.textStyles.fillColor = renderer().theme().systemColor(CSSValueAppleSystemLabel, styleColorOptions);
     771#endif
     772        style.backgroundColor = markedText.marker->isActiveMatch() ? renderer().theme().activeTextSearchHighlightColor(styleColorOptions) : renderer().theme().inactiveTextSearchHighlightColor(styleColorOptions);
    768773        break;
     774    }
    769775    }
    770776    StyledMarkedText styledMarkedText = markedText;
     
    833839Vector<MarkedText> InlineTextBox::collectMarkedTextsForDocumentMarkers(TextPaintPhase phase)
    834840{
    835     ASSERT(phase == TextPaintPhase::Background || phase == TextPaintPhase::Foreground);
     841    ASSERT_ARG(phase, phase == TextPaintPhase::Background || phase == TextPaintPhase::Foreground || phase == TextPaintPhase::Decoration);
     842
    836843    if (!renderer().textNode())
    837844        return { };
     
    877884        case DocumentMarker::DictationPhraseWithAlternatives:
    878885#endif
    879             if (phase == TextPaintPhase::Background)
     886            if (phase != TextPaintPhase::Decoration)
    880887                continue;
    881888            break;
     
    883890            if (!renderer().frame().editor().markedTextMatchesAreHighlighted())
    884891                continue;
    885 #if ENABLE(TELEPHONE_NUMBER_DETECTION)
    886             FALLTHROUGH;
    887         case DocumentMarker::TelephoneNumber:
    888 #endif
    889             if (phase == TextPaintPhase::Foreground)
     892            if (phase == TextPaintPhase::Decoration)
    890893                continue;
    891894            break;
     895#if ENABLE(TELEPHONE_NUMBER_DETECTION)
     896        case DocumentMarker::TelephoneNumber:
     897            if (!renderer().frame().editor().markedTextMatchesAreHighlighted())
     898                continue;
     899            if (phase != TextPaintPhase::Background)
     900                continue;
     901            break;
     902#endif
    892903        default:
    893904            continue;
  • trunk/Source/WebCore/rendering/RenderTheme.cpp

    r232486 r233280  
    11591159    m_inactiveListBoxSelectionForegroundColor = Color();
    11601160
     1161    m_activeTextSearchHighlightColor = Color();
     1162    m_inactiveTextSearchHighlightColor = Color();
     1163
    11611164    Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment();
    11621165}
     
    12841287}
    12851288
    1286 Color RenderTheme::platformActiveTextSearchHighlightColor() const
     1289Color RenderTheme::activeTextSearchHighlightColor(OptionSet<StyleColor::Options> options) const
     1290{
     1291    if (!m_activeTextSearchHighlightColor.isValid())
     1292        m_activeTextSearchHighlightColor = platformActiveTextSearchHighlightColor(options);
     1293    return m_activeTextSearchHighlightColor;
     1294}
     1295
     1296Color RenderTheme::inactiveTextSearchHighlightColor(OptionSet<StyleColor::Options> options) const
     1297{
     1298    if (!m_inactiveTextSearchHighlightColor.isValid())
     1299        m_inactiveTextSearchHighlightColor = platformInactiveTextSearchHighlightColor(options);
     1300    return m_inactiveTextSearchHighlightColor;
     1301}
     1302
     1303Color RenderTheme::platformActiveTextSearchHighlightColor(OptionSet<StyleColor::Options>) const
    12871304{
    12881305    return Color(255, 150, 50); // Orange.
    12891306}
    12901307
    1291 Color RenderTheme::platformInactiveTextSearchHighlightColor() const
     1308Color RenderTheme::platformInactiveTextSearchHighlightColor(OptionSet<StyleColor::Options>) const
    12921309{
    12931310    return Color(255, 255, 0); // Yellow.
  • trunk/Source/WebCore/rendering/RenderTheme.h

    r232486 r233280  
    145145    Color inactiveListBoxSelectionForegroundColor(OptionSet<StyleColor::Options>) const;
    146146
    147     // Highlighting colors for TextMatches.
    148     virtual Color platformActiveTextSearchHighlightColor() const;
    149     virtual Color platformInactiveTextSearchHighlightColor() const;
     147    // Highlighting colors for search matches.
     148    Color activeTextSearchHighlightColor(OptionSet<StyleColor::Options>) const;
     149    Color inactiveTextSearchHighlightColor(OptionSet<StyleColor::Options>) const;
    150150
    151151    virtual Color disabledTextColor(const Color& textColor, const Color& backgroundColor) const;
     
    265265    virtual Color platformActiveListBoxSelectionForegroundColor(OptionSet<StyleColor::Options>) const;
    266266    virtual Color platformInactiveListBoxSelectionForegroundColor(OptionSet<StyleColor::Options>) const;
     267
     268    // The platform highlighting colors for search matches.
     269    virtual Color platformActiveTextSearchHighlightColor(OptionSet<StyleColor::Options>) const;
     270    virtual Color platformInactiveTextSearchHighlightColor(OptionSet<StyleColor::Options>) const;
    267271
    268272    virtual bool supportsSelectionForegroundColors() const { return true; }
     
    405409    mutable Color m_activeListBoxSelectionForegroundColor;
    406410    mutable Color m_inactiveListBoxSelectionForegroundColor;
     411
     412    mutable Color m_activeTextSearchHighlightColor;
     413    mutable Color m_inactiveTextSearchHighlightColor;
    407414};
    408415
  • trunk/Source/WebCore/rendering/RenderThemeMac.h

    r232486 r233280  
    6363    Color platformInactiveListBoxSelectionForegroundColor(OptionSet<StyleColor::Options>) const final;
    6464    Color platformFocusRingColor(OptionSet<StyleColor::Options>) const final;
     65    Color platformActiveTextSearchHighlightColor(OptionSet<StyleColor::Options>) const final;
     66    Color platformInactiveTextSearchHighlightColor(OptionSet<StyleColor::Options>) const final;
    6567
    6668    ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) final { return SmallScrollbar; }
     
    243245    bool m_isSliderThumbVerticalPressed { false };
    244246
    245     mutable HashMap<int, Color> m_systemColorCache;
    246     mutable Color m_systemVisitedLinkColor;
     247    mutable HashMap<int, Color> m_lightSystemColorCache;
     248    mutable HashMap<int, Color> m_darkSystemColorCache;
     249    mutable Color m_lightSystemVisitedLinkColor;
     250    mutable Color m_darkSystemVisitedLinkColor;
    247251
    248252    RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r232892 r233280  
    392392}
    393393
     394Color RenderThemeMac::platformActiveTextSearchHighlightColor(OptionSet<StyleColor::Options> options) const
     395{
     396#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
     397    LocalDefaultSystemAppearance localAppearance(options.contains(StyleColor::Options::UseSystemAppearance), options.contains(StyleColor::Options::UseDefaultAppearance));
     398    return colorFromNSColor([NSColor findHighlightColor]);
     399#else
     400    UNUSED_PARAM(options);
     401    return Color(255, 204, 0); // Yellow.
     402#endif
     403}
     404
     405Color RenderThemeMac::platformInactiveTextSearchHighlightColor(OptionSet<StyleColor::Options> options) const
     406{
     407    // The inactive color is normally used, since no legacy WebKit client marks a text match as active.
     408    // So just return the same color for both states.
     409    return platformActiveTextSearchHighlightColor(options);
     410}
     411
    394412static FontSelectionValue toFontWeight(NSInteger appKitFontWeight)
    395413{
     
    487505void RenderThemeMac::platformColorsDidChange()
    488506{
    489     m_systemColorCache.clear();
    490     m_systemVisitedLinkColor = Color();
     507    m_lightSystemColorCache.clear();
     508    m_darkSystemColorCache.clear();
     509
     510    m_lightSystemVisitedLinkColor = Color();
     511    m_darkSystemVisitedLinkColor = Color();
     512
    491513    RenderTheme::platformColorsDidChange();
    492514}
     
    505527        // Only use NSColor when the system appearance is desired, otherwise use RenderTheme's default.
    506528        if (useSystemAppearance) {
    507             if (!m_systemVisitedLinkColor.isValid())
    508                 m_systemVisitedLinkColor = semanticColorFromNSColor([NSColor systemPurpleColor]);
    509             return m_systemVisitedLinkColor;
     529            if (localAppearance.usingDarkAppearance()) {
     530                if (!m_darkSystemVisitedLinkColor.isValid())
     531                    m_darkSystemVisitedLinkColor = semanticColorFromNSColor([NSColor systemPurpleColor]);
     532                return m_darkSystemVisitedLinkColor;
     533            }
     534
     535            if (!m_lightSystemVisitedLinkColor.isValid())
     536                m_lightSystemVisitedLinkColor = semanticColorFromNSColor([NSColor systemPurpleColor]);
     537            return m_lightSystemVisitedLinkColor;
    510538        }
    511539
     
    515543    ASSERT(!forVisitedLink);
    516544
    517     return m_systemColorCache.ensure(cssValueID, [this, cssValueID, useSystemAppearance, options] () -> Color {
     545    auto& systemColorCache = localAppearance.usingDarkAppearance() ? m_darkSystemColorCache : m_lightSystemColorCache;
     546    return systemColorCache.ensure(cssValueID, [this, cssValueID, useSystemAppearance, options] () -> Color {
    518547        auto selectCocoaColor = [cssValueID, useSystemAppearance] () -> SEL {
    519548            switch (cssValueID) {
     
    623652                return @selector(findHighlightColor);
    624653#else
    625                 return @selector(systemYellowColor);
     654                // Handled below.
     655                return nullptr;
    626656#endif
    627657            case CSSValueAppleSystemLabel:
     
    689719            return menuBackgroundColor();
    690720
     721#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
     722        case CSSValueAppleSystemFindHighlightBackground:
     723            return platformActiveTextSearchHighlightColor(options);
     724#endif
     725
    691726        case CSSValueAppleSystemEvenAlternatingContentBackground: {
    692727#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
Note: See TracChangeset for help on using the changeset viewer.