Changeset 230368 in webkit


Ignore:
Timestamp:
Apr 7, 2018 1:35:00 AM (6 years ago)
Author:
timothy@apple.com
Message:

Use the system's link color when system appearance is desired for a WebView.

https://bugs.webkit.org/show_bug.cgi?id=184353
rdar://problem/9420053

Reviewed by Wenson Hsieh.

Source/WebCore:

Have Document consult RenderTheme via StyleColor for the various link colors.
This allows the system to have different colors than the standard hardcoded ones.
This adds StyleColor::Options, to avoid multiple booleans being passed around,
since the "for visited link" state is now needed in RenderTheme.

  • WebCore.xcodeproj/project.pbxproj: Made StyleColor.h private, since RenderTheme.h includes it.
  • css/StyleColor.cpp:

(WebCore::StyleColor::colorFromKeyword): Use options instead of a bool.
(WebCore::StyleColor::isSystemColor): Consider CSSValueWebkitLink the start of system colors.

  • css/StyleColor.h:
  • css/StyleResolver.cpp:

(WebCore::StyleResolver::colorFromPrimitiveValue const): Use StyleColor::Options.

  • css/parser/CSSParser.cpp:

(WebCore::CSSParser::parseSystemColor): Use StyleColor::Options.

  • dom/Document.cpp:

(WebCore::Document::resetLinkColor): Ask StyleColor for the link color instead of hardcoding it.
(WebCore::Document::resetVisitedLinkColor): Ditto.
(WebCore::Document::resetActiveLinkColor): Ditto.
(WebCore::Document::styleColorOptions const): Added. Helper to get the options used.

  • dom/Document.h:
  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::drawFocusIfNeededInternal): Use StyleColor::Options.

  • rendering/RenderTheme.cpp:

(WebCore::RenderTheme::systemColor const): Add default values here, moved from Document.
(WebCore::RenderTheme::focusRingColor): Use StyleColor::Options.

  • rendering/RenderTheme.h:

(WebCore::RenderTheme::platformFocusRingColor const): Use StyleColor::Options.

  • rendering/RenderThemeGtk.cpp:

(WebCore::RenderThemeGtk::systemColor const): Use StyleColor::Options.

  • rendering/RenderThemeGtk.h:
  • rendering/RenderThemeIOS.h:
  • rendering/RenderThemeIOS.mm:

(WebCore::RenderThemeIOS::systemColor const): Use StyleColor::Options.

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

(WebCore::RenderThemeMac::platformFocusRingColor const): Use StyleColor::Options.
(WebCore::RenderThemeMac::platformColorsDidChange): Clear m_systemVisitedLinkColor.
(WebCore::RenderThemeMac::systemColor const): Use StyleColor::Options.
(WebCore::RenderThemeMac::adjustMenuListStyle const): Ditto.

  • rendering/RenderThemeWin.cpp:

(WebCore::RenderThemeWin::systemColor const): Use StyleColor::Options.

  • rendering/RenderThemeWin.h:
  • rendering/TextPaintStyle.cpp:

(WebCore::computeTextPaintStyle): Use StyleColor::Options.

Source/WebCore/PAL:

  • pal/spi/cocoa/NSColorSPI.h: Added linkColor.

Tools:

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

(TestWebKitAPI::WebKit::LinkColor):
(TestWebKitAPI::WebKit::LinkColorWithSystemAppearance):

Location:
trunk
Files:
24 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r230365 r230368  
     12018-04-07  Timothy Hatcher  <timothy@apple.com>
     2
     3        Use the system's link color when system appearance is desired for a WebView.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=184353
     6        rdar://problem/9420053
     7
     8        Reviewed by Wenson Hsieh.
     9
     10        Have Document consult RenderTheme via StyleColor for the various link colors.
     11        This allows the system to have different colors than the standard hardcoded ones.
     12        This adds StyleColor::Options, to avoid multiple booleans being passed around,
     13        since the "for visited link" state is now needed in RenderTheme.
     14
     15        * WebCore.xcodeproj/project.pbxproj: Made StyleColor.h private, since RenderTheme.h includes it.
     16        * css/StyleColor.cpp:
     17        (WebCore::StyleColor::colorFromKeyword): Use options instead of a bool.
     18        (WebCore::StyleColor::isSystemColor): Consider CSSValueWebkitLink the start of system colors.
     19        * css/StyleColor.h:
     20        * css/StyleResolver.cpp:
     21        (WebCore::StyleResolver::colorFromPrimitiveValue const): Use StyleColor::Options.
     22        * css/parser/CSSParser.cpp:
     23        (WebCore::CSSParser::parseSystemColor): Use StyleColor::Options.
     24        * dom/Document.cpp:
     25        (WebCore::Document::resetLinkColor): Ask StyleColor for the link color instead of hardcoding it.
     26        (WebCore::Document::resetVisitedLinkColor): Ditto.
     27        (WebCore::Document::resetActiveLinkColor): Ditto.
     28        (WebCore::Document::styleColorOptions const): Added. Helper to get the options used.
     29        * dom/Document.h:
     30        * html/canvas/CanvasRenderingContext2D.cpp:
     31        (WebCore::CanvasRenderingContext2D::drawFocusIfNeededInternal): Use StyleColor::Options.
     32        * rendering/RenderTheme.cpp:
     33        (WebCore::RenderTheme::systemColor const): Add default values here, moved from Document.
     34        (WebCore::RenderTheme::focusRingColor): Use StyleColor::Options.
     35        * rendering/RenderTheme.h:
     36        (WebCore::RenderTheme::platformFocusRingColor const): Use StyleColor::Options.
     37        * rendering/RenderThemeGtk.cpp:
     38        (WebCore::RenderThemeGtk::systemColor const): Use StyleColor::Options.
     39        * rendering/RenderThemeGtk.h:
     40        * rendering/RenderThemeIOS.h:
     41        * rendering/RenderThemeIOS.mm:
     42        (WebCore::RenderThemeIOS::systemColor const): Use StyleColor::Options.
     43        * rendering/RenderThemeMac.h:
     44        * rendering/RenderThemeMac.mm:
     45        (WebCore::RenderThemeMac::platformFocusRingColor const): Use StyleColor::Options.
     46        (WebCore::RenderThemeMac::platformColorsDidChange): Clear m_systemVisitedLinkColor.
     47        (WebCore::RenderThemeMac::systemColor const): Use StyleColor::Options.
     48        (WebCore::RenderThemeMac::adjustMenuListStyle const): Ditto.
     49        * rendering/RenderThemeWin.cpp:
     50        (WebCore::RenderThemeWin::systemColor const): Use StyleColor::Options.
     51        * rendering/RenderThemeWin.h:
     52        * rendering/TextPaintStyle.cpp:
     53        (WebCore::computeTextPaintStyle): Use StyleColor::Options.
     54
    1552018-04-06  Youenn Fablet  <youenn@apple.com>
    256
  • trunk/Source/WebCore/PAL/ChangeLog

    r230311 r230368  
     12018-04-07  Timothy Hatcher  <timothy@apple.com>
     2
     3        Use the system's link color when system appearance is desired for a WebView.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=184353
     6        rdar://problem/9420053
     7
     8        Reviewed by Wenson Hsieh.
     9
     10        * pal/spi/cocoa/NSColorSPI.h: Added linkColor.
     11
    1122018-04-05  John Wilander  <wilander@apple.com>
    213
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/NSColorSPI.h

    r220506 r230368  
    4242+ (NSColor *)systemPurpleColor;
    4343+ (NSColor *)systemGrayColor;
     44+ (NSColor *)linkColor;
    4445@end
    4546
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r230279 r230368  
    26072607                93F9B7A10BA6032600854064 /* JSCDATASection.h in Headers */ = {isa = PBXBuildFile; fileRef = 93F9B79F0BA6032600854064 /* JSCDATASection.h */; };
    26082608                93FDAFCA0B11307400E2746F /* EditorInsertAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 93FDAFC90B11307400E2746F /* EditorInsertAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
    2609                 9418278B1D8B244000492764 /* StyleColor.h in Headers */ = {isa = PBXBuildFile; fileRef = 941827891D8B242200492764 /* StyleColor.h */; };
     2609                9418278B1D8B244000492764 /* StyleColor.h in Headers */ = {isa = PBXBuildFile; fileRef = 941827891D8B242200492764 /* StyleColor.h */; settings = {ATTRIBUTES = (Private, ); }; };
    26102610                9418278F1D8CAF9200492764 /* CSSPendingSubstitutionValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 9418278D1D8CAE9500492764 /* CSSPendingSubstitutionValue.h */; };
    26112611                9444CBD41D860C8B0073A074 /* SizesCalcParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 9444CBCF1D860C740073A074 /* SizesCalcParser.h */; };
  • trunk/Source/WebCore/css/StyleColor.cpp

    r230056 r230368  
    3838namespace WebCore {
    3939
    40 Color StyleColor::colorFromKeyword(CSSValueID keyword, bool useSystemAppearance)
     40Color StyleColor::colorFromKeyword(CSSValueID keyword, OptionSet<Options> options)
    4141{
    4242    if (const char* valueName = getValueName(keyword)) {
     
    4444            return Color(namedColor->ARGBValue);
    4545    }
    46     return RenderTheme::singleton().systemColor(keyword, useSystemAppearance);
     46
     47    return RenderTheme::singleton().systemColor(keyword, options);
    4748}
    4849
     
    5455bool StyleColor::isSystemColor(CSSValueID id)
    5556{
    56     return (id >= CSSValueActiveborder && id <= CSSValueWebkitFocusRingColor) || id == CSSValueMenu || id == CSSValueText;
     57    return (id >= CSSValueWebkitLink && id <= CSSValueWebkitFocusRingColor) || id == CSSValueMenu || id == CSSValueText;
    5758}
    5859
  • trunk/Source/WebCore/css/StyleColor.h

    r229448 r230368  
    3434#include "CSSValueKeywords.h"
    3535#include "Color.h"
     36#include <wtf/OptionSet.h>
    3637
    3738namespace WebCore {
     
    5152    const Color& resolve(const Color& currentColor) const { return m_currentColor ? currentColor : m_color; }
    5253
    53     static Color colorFromKeyword(CSSValueID, bool useSystemAppearance);
     54    enum class Options : uint8_t {
     55        ForVisitedLink = 1 << 0,
     56        UseSystemAppearance = 1 << 1
     57    };
     58
     59    static Color colorFromKeyword(CSSValueID, OptionSet<Options>);
    5460    static bool isColorKeyword(CSSValueID);
    5561    static bool isSystemColor(CSSValueID);
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r230100 r230368  
    18301830        return document().activeLinkColor();
    18311831    case CSSValueWebkitFocusRingColor:
    1832         return RenderTheme::focusRingColor(document().useSystemAppearance());
     1832        return RenderTheme::focusRingColor(document().styleColorOptions());
    18331833    case CSSValueCurrentcolor:
    18341834        // Color is an inherited property so depending on it effectively makes the property inherited.
     
    18371837        return m_state.style()->color();
    18381838    default:
    1839         return StyleColor::colorFromKeyword(identifier, document().useSystemAppearance());
     1839        return StyleColor::colorFromKeyword(identifier, document().styleColorOptions());
    18401840    }
    18411841}
  • trunk/Source/WebCore/css/parser/CSSParser.cpp

    r229654 r230368  
    182182    if (!StyleColor::isSystemColor(id))
    183183        return Color();
    184     if (context)
    185         return RenderTheme::singleton().systemColor(id, context.value().useSystemAppearance);
    186     return RenderTheme::singleton().systemColor(id, false);
     184
     185    OptionSet<StyleColor::Options> options;
     186    if (context && context.value().useSystemAppearance)
     187        options |= StyleColor::Options::UseSystemAppearance;
     188    return RenderTheme::singleton().systemColor(id, options);
    187189}
    188190
  • trunk/Source/WebCore/dom/Document.cpp

    r230290 r230368  
    190190#include "StorageEvent.h"
    191191#include "StringCallback.h"
     192#include "StyleColor.h"
    192193#include "StyleProperties.h"
    193194#include "StyleResolveForDocument.h"
     
    802803void Document::resetLinkColor()
    803804{
    804     m_linkColor = Color(0, 0, 238);
     805    m_linkColor = StyleColor::colorFromKeyword(CSSValueWebkitLink, styleColorOptions());
    805806}
    806807
    807808void Document::resetVisitedLinkColor()
    808809{
    809     m_visitedLinkColor = Color(85, 26, 139);   
     810    m_visitedLinkColor = StyleColor::colorFromKeyword(CSSValueWebkitLink, styleColorOptions() | StyleColor::Options::ForVisitedLink);
    810811}
    811812
    812813void Document::resetActiveLinkColor()
    813814{
    814     m_activeLinkColor = Color(255, 0, 0);
     815    m_activeLinkColor = StyleColor::colorFromKeyword(CSSValueWebkitActivelink, styleColorOptions());
    815816}
    816817
     
    70287029    return deviceScaleFactor;
    70297030}
    7030    
     7031
    70317032bool Document::useSystemAppearance() const
    70327033{
     
    70367037    return useSystemAppearance;
    70377038}
    7038    
     7039
     7040OptionSet<StyleColor::Options> Document::styleColorOptions() const
     7041{
     7042    OptionSet<StyleColor::Options> options;
     7043    if (useSystemAppearance())
     7044        options |= StyleColor::Options::UseSystemAppearance;
     7045    return options;
     7046}
     7047
    70397048void Document::didAssociateFormControl(Element* element)
    70407049{
  • trunk/Source/WebCore/dom/Document.h

    r230226 r230368  
    4646#include "ScriptExecutionContext.h"
    4747#include "StringWithDirection.h"
     48#include "StyleColor.h"
    4849#include "Supplementable.h"
    4950#include "TextResourceDecoder.h"
     
    544545
    545546    float deviceScaleFactor() const;
    546        
     547
    547548    bool useSystemAppearance() const;
     549    OptionSet<StyleColor::Options> styleColorOptions() const;
    548550
    549551    WEBCORE_EXPORT Ref<Range> createRange();
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r229448 r230368  
    8585    if (!element.focused() || !state().hasInvertibleTransform || path.isEmpty() || !element.isDescendantOf(canvas()) || !context)
    8686        return;
    87     context->drawFocusRing(path, 1, 1, RenderTheme::focusRingColor(element.document().useSystemAppearance()));
     87    context->drawFocusRing(path, 1, 1, RenderTheme::focusRingColor(element.document().styleColorOptions()));
    8888}
    8989
  • trunk/Source/WebCore/rendering/RenderTheme.cpp

    r229448 r230368  
    12091209}
    12101210
    1211 Color RenderTheme::systemColor(CSSValueID cssValueId, bool useSystemAppearance) const
    1212 {
    1213     UNUSED_PARAM(useSystemAppearance);
    1214    
     1211Color RenderTheme::systemColor(CSSValueID cssValueId, OptionSet<StyleColor::Options> options) const
     1212{
    12151213    switch (cssValueId) {
     1214    case CSSValueWebkitLink:
     1215        return options.contains(StyleColor::Options::ForVisitedLink) ? 0xFF551A8B : 0xFF0000EE;
     1216    case CSSValueWebkitActivelink:
     1217        return 0xFFFF0000;
    12161218    case CSSValueActiveborder:
    12171219        return 0xFFFFFFFF;
     
    13281330}
    13291331
    1330 Color RenderTheme::focusRingColor(bool useSystemAppearance)
    1331 {
    1332     return customFocusRingColor().isValid() ? customFocusRingColor() : RenderTheme::singleton().platformFocusRingColor(useSystemAppearance);
     1332Color RenderTheme::focusRingColor(OptionSet<StyleColor::Options> options)
     1333{
     1334    return customFocusRingColor().isValid() ? customFocusRingColor() : RenderTheme::singleton().platformFocusRingColor(options);
    13331335}
    13341336
  • trunk/Source/WebCore/rendering/RenderTheme.h

    r229448 r230368  
    2525#include "PopupMenuStyle.h"
    2626#include "ScrollTypes.h"
     27#include "StyleColor.h"
    2728#include "ThemeTypes.h"
    2829
     
    150151    virtual Color disabledTextColor(const Color& textColor, const Color& backgroundColor) const;
    151152
    152     static Color focusRingColor(bool useSystemAppearance);
    153     virtual Color platformFocusRingColor(bool) const { return Color(0, 0, 0); }
     153    static Color focusRingColor(OptionSet<StyleColor::Options>);
     154    virtual Color platformFocusRingColor(OptionSet<StyleColor::Options>) const { return Color(0, 0, 0); }
    154155    static void setCustomFocusRingColor(const Color&);
    155156    static float platformFocusRingWidth() { return 3; }
     
    165166    // System fonts and colors for CSS.
    166167    void systemFont(CSSValueID, FontCascadeDescription&) const;
    167     virtual Color systemColor(CSSValueID, bool useSystemAppearance) const;
     168    virtual Color systemColor(CSSValueID, OptionSet<StyleColor::Options>) const;
    168169
    169170    virtual int minimumMenuListSize(const RenderStyle&) const { return 0; }
  • trunk/Source/WebCore/rendering/RenderThemeGtk.cpp

    r229448 r230368  
    17571757}
    17581758
    1759 Color RenderThemeGtk::systemColor(CSSValueID cssValueId, bool) const
     1759Color RenderThemeGtk::systemColor(CSSValueID cssValueId, OptionSet<StyleColor::Options> options) const
    17601760{
    17611761    switch (cssValueId) {
     
    17651765        return styleColor(Entry, GTK_STATE_FLAG_ACTIVE, StyleColorForeground);
    17661766    default:
    1767         return RenderTheme::systemColor(cssValueId, false);
     1767        return RenderTheme::systemColor(cssValueId, options);
    17681768    }
    17691769}
  • trunk/Source/WebCore/rendering/RenderThemeGtk.h

    r229448 r230368  
    8787
    8888    // System colors.
    89     Color systemColor(CSSValueID, bool) const override;
     89    Color systemColor(CSSValueID, OptionSet<StyleColor::Options>) const override;
    9090
    9191    bool popsMenuBySpaceOrReturn() const override { return true; }
  • trunk/Source/WebCore/rendering/RenderThemeIOS.h

    r229448 r230368  
    136136    FloatRect addRoundedBorderClip(const RenderObject& box, GraphicsContext&, const IntRect&);
    137137
    138     Color systemColor(CSSValueID, bool) const override;
     138    Color systemColor(CSSValueID, OptionSet<StyleColor::Options>) const override;
    139139
    140140    String m_legacyMediaControlsScript;
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r230039 r230368  
    13981398#endif // ENABLE(VIDEO)
    13991399
    1400 Color RenderThemeIOS::systemColor(CSSValueID cssValueID, bool) const
    1401 {
     1400Color RenderThemeIOS::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::Options> options) const
     1401{
     1402    const bool forVisitedLink = options.contains(StyleColor::Options::ForVisitedLink);
     1403
     1404    // The system color cache below can't handle visited links. The only color value
     1405    // that cares about visited links is CSSValueWebkitLink, so handle it here by
     1406    // calling through to RenderTheme's base implementation.
     1407    if (forVisitedLink && cssValueID == CSSValueWebkitLink)
     1408        return RenderTheme::systemColor(cssValueID, options);
     1409
     1410    ASSERT(!forVisitedLink);
     1411
    14021412    auto addResult = m_systemColorCache.add(cssValueID, Color());
    14031413    if (!addResult.isNewEntry)
     
    14351445
    14361446    if (!color.isValid())
    1437         color = RenderTheme::systemColor(cssValueID, false);
     1447        color = RenderTheme::systemColor(cssValueID, options);
    14381448
    14391449    addResult.iterator->value = color;
  • trunk/Source/WebCore/rendering/RenderThemeMac.h

    r229448 r230368  
    6060    Color platformInactiveListBoxSelectionBackgroundColor(bool) const final;
    6161    Color platformInactiveListBoxSelectionForegroundColor() const final;
    62     Color platformFocusRingColor(bool useSystemAppearance) const final;
     62    Color platformFocusRingColor(OptionSet<StyleColor::Options>) const final;
    6363
    6464    ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) final { return SmallScrollbar; }
     
    170170    String fileListNameForWidth(const FileList*, const FontCascade&, int width, bool multipleFilesAllowed) const final;
    171171
    172     Color systemColor(CSSValueID, bool useSystemAppearance) const final;
     172    Color systemColor(CSSValueID, OptionSet<StyleColor::Options>) const final;
    173173
    174174    void purgeCaches() final;
     
    244244
    245245    mutable HashMap<int, Color> m_systemColorCache;
     246    mutable Color m_systemVisitedLinkColor;
    246247
    247248    RetainPtr<WebCoreRenderThemeNotificationObserver> m_notificationObserver;
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r230064 r230368  
    316316}
    317317
    318 Color RenderThemeMac::platformFocusRingColor(bool useSystemAppearance) const
     318Color RenderThemeMac::platformFocusRingColor(OptionSet<StyleColor::Options> options) const
    319319{
    320320    if (usesTestModeFocusRingColor())
    321321        return oldAquaFocusRingColor();
    322 
    323     return systemColor(CSSValueWebkitFocusRingColor, useSystemAppearance);
     322    return systemColor(CSSValueWebkitFocusRingColor, options);
    324323}
    325324
     
    426425{
    427426    m_systemColorCache.clear();
     427    m_systemVisitedLinkColor = Color();
    428428    RenderTheme::platformColorsDidChange();
    429429}
    430430
    431 Color RenderThemeMac::systemColor(CSSValueID cssValueID, bool useSystemAppearance) const
    432 {
     431Color RenderThemeMac::systemColor(CSSValueID cssValueID, OptionSet<StyleColor::Options> options) const
     432{
     433    const bool useSystemAppearance = options.contains(StyleColor::Options::UseSystemAppearance);
     434    const bool forVisitedLink = options.contains(StyleColor::Options::ForVisitedLink);
     435
    433436    LocalDefaultSystemAppearance localAppearance(useSystemAppearance);
    434     return m_systemColorCache.ensure(cssValueID, [this, cssValueID, useSystemAppearance] () -> Color {
    435         auto selectCocoaColor = [cssValueID] () -> SEL {
     437
     438    // The system color cache below can't handle visited links. The only color value
     439    // that cares about visited links is CSSValueWebkitLink, so handle it here.
     440    if (forVisitedLink && cssValueID == CSSValueWebkitLink) {
     441        // Only use NSColor when the system appearance is desired, otherwise use RenderTheme's default.
     442        if (useSystemAppearance) {
     443            if (!m_systemVisitedLinkColor.isValid())
     444                m_systemVisitedLinkColor = colorFromNSColor([NSColor systemPurpleColor]);
     445            return m_systemVisitedLinkColor;
     446        }
     447
     448        return RenderTheme::systemColor(cssValueID, options);
     449    }
     450
     451    ASSERT(!forVisitedLink);
     452
     453    return m_systemColorCache.ensure(cssValueID, [this, cssValueID, useSystemAppearance, options] () -> Color {
     454        auto selectCocoaColor = [cssValueID, useSystemAppearance] () -> SEL {
    436455            switch (cssValueID) {
     456            case CSSValueWebkitLink:
     457                // Only use NSColor when the system appearance is desired, otherwise use RenderTheme's default.
     458                return useSystemAppearance ? @selector(linkColor) : nullptr;
     459            case CSSValueWebkitActivelink:
     460                // Only use NSColor when the system appearance is desired, otherwise use RenderTheme's default.
     461                // FIXME: Use a semantic system color for this, instead of systemRedColor. <rdar://problem/39256684>
     462                return useSystemAppearance ? @selector(systemRedColor) : nullptr;
    437463            case CSSValueActiveborder:
    438464                return @selector(keyboardFocusIndicatorColor);
     
    525551            }
    526552        };
     553
    527554        if (auto selector = selectCocoaColor()) {
    528555            if (auto color = wtfObjcMsgSend<NSColor *>([NSColor class], selector))
    529556                return colorFromNSColor(color);
    530557        }
     558
    531559        switch (cssValueID) {
    532560        case CSSValueActivebuttontext:
     
    547575            FALLTHROUGH;
    548576        default:
    549             return RenderTheme::systemColor(cssValueID, useSystemAppearance);
     577            return RenderTheme::systemColor(cssValueID, options);
    550578        }
    551579    }).iterator->value;
     
    12981326    Color c = Color::darkGray;
    12991327    if (e) {
    1300         bool useSystemAppearance = e->document().page()->useSystemAppearance();
    1301         c = !e->isDisabledFormControl() ? systemColor(CSSValueButtontext, useSystemAppearance) : systemColor(CSSValueGraytext, useSystemAppearance);
     1328        OptionSet<StyleColor::Options> options = e->document().styleColorOptions();
     1329        c = !e->isDisabledFormControl() ? systemColor(CSSValueButtontext, options) : systemColor(CSSValueGraytext, options);
    13021330    }
    13031331    style.setColor(c);
  • trunk/Source/WebCore/rendering/RenderThemeWin.cpp

    r229448 r230368  
    10131013}
    10141014
    1015 Color RenderThemeWin::systemColor(CSSValueID cssValueId, bool) const
     1015Color RenderThemeWin::systemColor(CSSValueID cssValueId, OptionSet<StyleColor::Options> options) const
    10161016{
    10171017    int sysColorIndex = cssValueIdToSysColorIndex(cssValueId);
    10181018    if (sysColorIndex == -1)
    1019         return RenderTheme::systemColor(cssValueId, false);
     1019        return RenderTheme::systemColor(cssValueId, options);
    10201020
    10211021    COLORREF color = GetSysColor(sysColorIndex);
  • trunk/Source/WebCore/rendering/RenderThemeWin.h

    r229448 r230368  
    6060    Color platformInactiveSelectionForegroundColor() const override;
    6161
    62     Color systemColor(CSSValueID, bool) const override;
     62    Color systemColor(CSSValueID, OptionSet<StyleColor::Options>) const override;
    6363
    6464    bool paintCheckbox(const RenderObject& o, const PaintInfo& i, const IntRect& r) override
  • trunk/Source/WebCore/rendering/TextPaintStyle.cpp

    r229510 r230368  
    9999        Page* page = frame.page();
    100100        if (page && page->focusController().isActive()) {
    101             paintStyle.fillColor = RenderTheme::singleton().systemColor(CSSValueActivebuttontext, page->useSystemAppearance());
     101            OptionSet<StyleColor::Options> options;
     102            if (page->useSystemAppearance())
     103                options |= StyleColor::Options::UseSystemAppearance;
     104            paintStyle.fillColor = RenderTheme::singleton().systemColor(CSSValueActivebuttontext, options);
    102105            return paintStyle;
    103106        }
  • trunk/Tools/ChangeLog

    r230366 r230368  
     12018-04-07  Timothy Hatcher  <timothy@apple.com>
     2
     3        Use the system's link color when system appearance is desired for a WebView.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=184353
     6        rdar://problem/9420053
     7
     8        Reviewed by Wenson Hsieh.
     9
     10        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     11        * TestWebKitAPI/Tests/WebKitCocoa/SystemColors.mm: Added.
     12        (TestWebKitAPI::WebKit::LinkColor):
     13        (TestWebKitAPI::WebKit::LinkColorWithSystemAppearance):
     14
    1152018-04-06  Zalan Bujtas  <zalan@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r230099 r230368  
    6363                1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81841C8924A200A5529F /* webfont.html */; };
    6464                1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81851C89252300A5529F /* Ahem.ttf */; };
     65                1C734B5320788C4800F430EA /* SystemColors.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C734B5220788C4800F430EA /* SystemColors.mm */; };
    6566                1C9EB8411E380DA1005C6442 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */; };
    6667                1CAD1F861E5CE7DA00AF2C2C /* FontCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CAD1F851E5CE7DA00AF2C2C /* FontCache.cpp */; };
     
    11851186                1C2B81841C8924A200A5529F /* webfont.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = webfont.html; sourceTree = "<group>"; };
    11861187                1C2B81851C89252300A5529F /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
     1188                1C734B5220788C4800F430EA /* SystemColors.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemColors.mm; sourceTree = "<group>"; };
    11871189                1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ComplexTextController.cpp; sourceTree = "<group>"; };
    11881190                1CAD1F851E5CE7DA00AF2C2C /* FontCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontCache.cpp; sourceTree = "<group>"; };
     
    22182220                                2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */,
    22192221                                515BE1701D428BD100DD7C68 /* StoreBlobThenDelete.mm */,
     2222                                1C734B5220788C4800F430EA /* SystemColors.mm */,
    22202223                                5CB40B4D1F4B98BE007DC7B9 /* UIDelegate.mm */,
    22212224                                7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
     
    37113714                                7CCE7ED21A411A7E00447C4C /* SubresourceErrorCrash.mm in Sources */,
    37123715                                7CCE7EA81A411A1900447C4C /* SyntheticBackingScaleFactorWindow.m in Sources */,
     3716                                1C734B5320788C4800F430EA /* SystemColors.mm in Sources */,
    37133717                                7CCE7F161A411AE600447C4C /* TerminateTwice.cpp in Sources */,
    37143718                                7CCE7EA91A411A1D00447C4C /* TestBrowsingContextLoadDelegate.mm in Sources */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemColors.mm

    r230367 r230368  
    11/*
    2  * Copyright (C) 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import <AppKit/NSColor.h>
     26#include "config.h"
    2727
    28 #if PLATFORM(MAC) && USE(APPLE_INTERNAL_SDK)
     28#if WK_API_ENABLED
    2929
    30 #import <AppKit/NSColor_Private.h>
     30#import "PlatformUtilities.h"
     31#import "TestWKWebView.h"
     32#import <WebKit/WKWebViewPrivate.h>
     33#import <wtf/RetainPtr.h>
    3134
    32 #else
     35namespace TestWebKitAPI {
    3336
    34 @interface NSColor ()
    35 + (NSColor *)systemRedColor;
    36 + (NSColor *)systemGreenColor;
    37 + (NSColor *)systemBlueColor;
    38 + (NSColor *)systemOrangeColor;
    39 + (NSColor *)systemYellowColor;
    40 + (NSColor *)systemBrownColor;
    41 + (NSColor *)systemPinkColor;
    42 + (NSColor *)systemPurpleColor;
    43 + (NSColor *)systemGrayColor;
    44 @end
     37TEST(WebKit, LinkColor)
     38{
     39    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     40
     41    [webView synchronouslyLoadHTMLString:@"<a href>Test</a>"];
     42
     43    NSString *linkColor = [webView stringByEvaluatingJavaScript:@"getComputedStyle(document.links[0]).color"];
     44    EXPECT_WK_STREQ("rgb(0, 0, 238)", linkColor);
     45}
     46
     47#if PLATFORM(MAC)
     48TEST(WebKit, LinkColorWithSystemAppearance)
     49{
     50    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     51    [webView _setUseSystemAppearance:YES];
     52
     53    [webView synchronouslyLoadHTMLString:@"<a href>Test</a>"];
     54
     55    NSString *linkColor = [webView stringByEvaluatingJavaScript:@"getComputedStyle(document.links[0]).color"];
     56    EXPECT_WK_STREQ("rgb(0, 105, 217)", linkColor);
     57}
     58#endif
     59
     60} // namespace TestWebKitAPI
    4561
    4662#endif
Note: See TracChangeset for help on using the changeset viewer.