Skip to content

Commit

Permalink
Cherry-pick ee38052. rdar://117909679
Browse files Browse the repository at this point in the history
    macOS: Text cursor in HTML note is black, regardless of set Accent Color
    https://bugs.webkit.org/show_bug.cgi?id=264189
    rdar://117909679

    Reviewed by Aditya Keerthi and Tim Horton.

    266070@main changed the behavior of the caret color to more closely follow the spec, and improve
    web compat. However, this behavior change also affected HTML Notes, which sets `color` on
    an ancestor of the editable div. As a result, the caret color is black. However, it should match
    the accent color of the app it is in, if it sets a custom accent color.

    To fix, implement the same solution as 269314@main effectively, but on macOS.

    * Source/WebCore/editing/FrameSelection.cpp:
    (WebCore::FrameSelection::paintCaret):
    (WebCore::CaretBase::computeCaretColor):
    (WebCore::CaretBase::paintCaret const):
    (WebCore::DragCaretController::paintDragCaret const):
    * Source/WebCore/editing/FrameSelection.h:
    * Source/WebCore/page/Page.cpp:
    (WebCore::Page::setAppUsesCustomAccentColor):
    (WebCore::Page::appUsesCustomAccentColor const):
    * Source/WebCore/page/Page.h:
    * Source/WebCore/rendering/RenderThemeIOS.mm:
    (WebCore::RenderThemeIOS::autocorrectionReplacementMarkerColor const):
    * Source/WebCore/rendering/style/RenderStyle.h:
    * Source/WebKit/Shared/WebPageCreationParameters.h:
    * Source/WebKit/Shared/WebPageCreationParameters.serialization.in:
    * Source/WebKit/UIProcess/PageClient.h:
    * Source/WebKit/UIProcess/WebPageProxy.cpp:
    (WebKit::WebPageProxy::creationParameters):
    * Source/WebKit/UIProcess/mac/PageClientImplMac.h:
    * Source/WebKit/UIProcess/mac/PageClientImplMac.mm:
    (WebKit::cachedAppUsesCustomAccentColor):
    (WebKit::PageClientImpl::appUsesCustomAccentColor):
    * Source/WebKit/WebProcess/WebPage/WebPage.cpp:
    (WebKit::m_historyItemClient):
    (WebKit::WebPage::reinitializeWebPage):
    * Source/WebKit/WebProcess/WebPage/WebPage.h:
    * Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
    (WebKit::WebPage::getPlatformEditorState const):
    * Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm:
    (WebKit::WebPage::setAppUsesCustomAccentColor):

    Canonical link: https://commits.webkit.org/270325@main

Identifier: 267815.553@safari-7617-branch
  • Loading branch information
Dan Robson committed Nov 9, 2023
1 parent bbdd510 commit dae531d
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Source/WebCore/editing/FrameSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,13 @@ Color CaretBase::computeCaretColor(const RenderStyle& elementStyle, const Node*
return { };
return elementStyle.colorResolvingCurrentColor(elementStyle.caretColor());
#elif HAVE(REDESIGNED_TEXT_CURSOR)
if (elementStyle.hasAutoCaretColor() && !elementStyle.hasExplicitlySetColor()) {
#if HAVE(APP_ACCENT_COLORS) && PLATFORM(MAC)
auto appUsesCustomAccentColor = node && node->document().page() && node->document().page()->appUsesCustomAccentColor();
#else
auto appUsesCustomAccentColor = false;
#endif

if (elementStyle.hasAutoCaretColor() && (!elementStyle.hasExplicitlySetColor() || appUsesCustomAccentColor)) {
#if PLATFORM(MAC)
auto cssColorValue = CSSValueAppleSystemControlAccent;
#else
Expand Down
12 changes: 12 additions & 0 deletions Source/WebCore/page/Page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3087,6 +3087,18 @@ Color Page::sampledPageTopColor() const
return valueOrDefault(m_sampledPageTopColor);
}

#if HAVE(APP_ACCENT_COLORS) && PLATFORM(MAC)
void Page::setAppUsesCustomAccentColor(bool appUsesCustomAccentColor)
{
m_appUsesCustomAccentColor = appUsesCustomAccentColor;
}

bool Page::appUsesCustomAccentColor() const
{
return m_appUsesCustomAccentColor;
}
#endif

void Page::setUnderPageBackgroundColorOverride(Color&& underPageBackgroundColorOverride)
{
if (underPageBackgroundColorOverride == m_underPageBackgroundColorOverride)
Expand Down
9 changes: 9 additions & 0 deletions Source/WebCore/page/Page.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ class Page : public Supplementable<Page>, public CanMakeWeakPtr<Page> {
WEBCORE_EXPORT Color pageExtendedBackgroundColor() const;
WEBCORE_EXPORT Color sampledPageTopColor() const;

#if HAVE(APP_ACCENT_COLORS) && PLATFORM(MAC)
WEBCORE_EXPORT void setAppUsesCustomAccentColor(bool);
WEBCORE_EXPORT bool appUsesCustomAccentColor() const;
#endif

Color underPageBackgroundColorOverride() const { return m_underPageBackgroundColorOverride; }
WEBCORE_EXPORT void setUnderPageBackgroundColorOverride(Color&&);

Expand Down Expand Up @@ -1436,6 +1441,10 @@ class Page : public Supplementable<Page>, public CanMakeWeakPtr<Page> {
Ref<BadgeClient> m_badgeClient;

HashMap<RegistrableDomain, uint64_t> m_noiseInjectionHashSalts;

#if HAVE(APP_ACCENT_COLORS) && PLATFORM(MAC)
bool m_appUsesCustomAccentColor { false };
#endif
};

inline PageGroup& Page::group()
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/Shared/WebPageCreationParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ struct WebPageCreationParameters {
#endif
#if HAVE(APP_ACCENT_COLORS)
WebCore::Color accentColor;
#if PLATFORM(MAC)
bool appUsesCustomAccentColor;
#endif
#endif
#if USE(WPE_RENDERER)
UnixFileDescriptor hostFileDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ struct WebKit::WebPageCreationParameters {
#if HAVE(APP_ACCENT_COLORS)
WebCore::Color accentColor;
#endif
#if HAVE(APP_ACCENT_COLORS) && PLATFORM(MAC)
bool appUsesCustomAccentColor;
#endif
#if USE(WPE_RENDERER)
UnixFileDescriptor hostFileDescriptor;
#endif
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/UIProcess/PageClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ class PageClient : public CanMakeWeakPtr<PageClient> {

#if HAVE(APP_ACCENT_COLORS)
virtual WebCore::Color accentColor() = 0;
#if PLATFORM(MAC)
virtual bool appUsesCustomAccentColor() = 0;
#endif
#endif

virtual bool effectiveAppearanceIsDark() const { return false; }
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9448,6 +9448,9 @@ WebPageCreationParameters WebPageProxy::creationParameters(WebProcessProxy& proc
#endif
#if HAVE(APP_ACCENT_COLORS)
parameters.accentColor = pageClient().accentColor();
#if PLATFORM(MAC)
parameters.appUsesCustomAccentColor = pageClient().appUsesCustomAccentColor();
#endif
#endif
parameters.shouldScaleViewToFitDocument = m_shouldScaleViewToFitDocument;
parameters.userInterfaceLayoutDirection = pageClient().userInterfaceLayoutDirection();
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/UIProcess/mac/PageClientImplMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ class PageClientImpl final : public PageClientImplCocoa

#if HAVE(APP_ACCENT_COLORS)
WebCore::Color accentColor() override;
#if PLATFORM(MAC)
bool appUsesCustomAccentColor() override;
#endif
#endif

#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
Expand Down
18 changes: 18 additions & 0 deletions Source/WebKit/UIProcess/mac/PageClientImplMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,24 @@ static inline NSCorrectionResponse toCorrectionResponse(AutocorrectionResponse r
{
return WebCore::colorFromCocoaColor([NSApp _effectiveAccentColor]);
}

bool PageClientImpl::appUsesCustomAccentColor()
{
static dispatch_once_t once;
static BOOL usesCustomAppAccentColor = NO;
dispatch_once(&once, ^{
NSBundle *bundleForAccentColor = [NSBundle mainBundle];
NSDictionary *info = [bundleForAccentColor infoDictionary];
NSString *accentColorName = info[@"NSAccentColorName"];
if ([accentColorName length])
usesCustomAppAccentColor = !!adoptNS([NSColor colorNamed:accentColorName bundle:bundleForAccentColor]).get();

if (!usesCustomAppAccentColor && [(accentColorName = info[@"NSAppAccentColorName"]) length])
usesCustomAppAccentColor = !!adoptNS([NSColor colorNamed:accentColorName bundle:bundleForAccentColor]).get();
});

return usesCustomAppAccentColor;
}
#endif

#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
Expand Down
6 changes: 6 additions & 0 deletions Source/WebKit/WebProcess/WebPage/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,9 @@ WebPage::WebPage(PageIdentifier pageID, WebPageCreationParameters&& parameters)

#if HAVE(APP_ACCENT_COLORS)
setAccentColor(parameters.accentColor);
#if PLATFORM(MAC)
setAppUsesCustomAccentColor(parameters.appUsesCustomAccentColor);
#endif
#endif

m_needsFontAttributes = parameters.needsFontAttributes;
Expand Down Expand Up @@ -1211,6 +1214,9 @@ void WebPage::reinitializeWebPage(WebPageCreationParameters&& parameters)

#if HAVE(APP_ACCENT_COLORS)
setAccentColor(parameters.accentColor);
#if PLATFORM(MAC)
setAppUsesCustomAccentColor(parameters.appUsesCustomAccentColor);
#endif
#endif

effectiveAppearanceDidChange(parameters.useDarkAppearance, parameters.useElevatedUserInterfaceLevel);
Expand Down
8 changes: 8 additions & 0 deletions Source/WebKit/WebProcess/WebPage/WebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,10 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP

#if HAVE(APP_ACCENT_COLORS)
void setAccentColor(WebCore::Color);
#if PLATFORM(MAC)
void setAppUsesCustomAccentColor(bool);
bool appUsesCustomAccentColor();
#endif
#endif

void setMainFrameIsScrollable(bool);
Expand Down Expand Up @@ -2572,6 +2576,10 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP
bool m_useSceneKitForModel { false };
#endif

#if HAVE(APP_ACCENT_COLORS)
bool m_appUsesCustomAccentColor { false };
#endif

bool m_textManipulationIncludesSubframes { false };
std::optional<Vector<WebCore::TextManipulationController::ExclusionRule>> m_textManipulationExclusionRules;

Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,13 @@ static void drawPDFPage(PDFDocument *pdfDocument, CFIndex pageIndex, CGContextRe
[NSApp _setAccentColor:cocoaColorOrNil(color).get()];
}

#if PLATFORM(MAC)
void WebPage::setAppUsesCustomAccentColor(bool appUsesCustomAccentColor)
{
corePage()->setAppUsesCustomAccentColor(appUsesCustomAccentColor);
}
#endif

#endif // HAVE(APP_ACCENT_COLORS)

void WebPage::zoomPDFIn(PDFPluginIdentifier identifier)
Expand Down

0 comments on commit dae531d

Please sign in to comment.