Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mac Catalyst] Adjust autocorrection underline color based on caret color #13588

Merged
merged 1 commit into from
May 9, 2023

Conversation

pxlcoder
Copy link
Member

@pxlcoder pxlcoder commented May 8, 2023

b199f7d

[Mac Catalyst] Adjust autocorrection underline color based on caret color
https://bugs.webkit.org/show_bug.cgi?id=256475
rdar://108355409

Reviewed by Wenson Hsieh.

The autocorrection underline color should be a variant of the current caret
color. In order to facilitate this, the insertion point color is plumbed from
the UI Process into the Web Process.

* Source/WebCore/rendering/RenderTheme.cpp:
(WebCore::RenderTheme::autocorrectionReplacementMarkerColor const):
(WebCore::RenderTheme::documentMarkerLineColor const):
* Source/WebCore/rendering/RenderTheme.h:

Add a `RenderText` parameter to `documentMarkerLineColor`, since it is
necessary to determine the caret color.

* Source/WebCore/rendering/RenderThemeCocoa.h:
* Source/WebCore/rendering/RenderThemeCocoa.mm:
(WebCore::RenderThemeCocoa::platformAutocorrectionReplacementMarkerColor const): Deleted.

Remove override, as the color is too dynamic to be cached. `caret-color` can
differ per-element, so the autocorrection underline color can no longer be cached.

* Source/WebCore/rendering/RenderThemeIOS.h:

Add a static method to set the insertion point color to avoid unnecessary
initialization of the singleton.

* Source/WebCore/rendering/RenderThemeIOS.mm:
(WebCore::cachedInsertionPointColor):
(WebCore::RenderThemeIOS::insertionPointColor):
(WebCore::RenderThemeIOS::autocorrectionReplacementMarkerColor const):

Adjust the autocorrection underline color based on the current caret color. If
`caret-color` is `auto`, use the default color from the UI process. The
adjustment is performed using the HSL colorspace, matching UIKit.

(WebCore::RenderThemeIOS::setInsertionPointColor):
* Source/WebCore/rendering/TextBoxPainter.cpp:
(WebCore::TextBoxPainter<TextBoxPath>::paintPlatformDocumentMarker):
* Source/WebKit/Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Source/WebKit/Shared/WebPageCreationParameters.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _insertionPointColor]):

Get the insertion point color from the text input traits if it exists. Otherwise,
use the default color specified in UIKit.

* Source/WebKit/UIProcess/PageClient.h:

Add a `PageClient` hook to get the insertion point color.

* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::insertionPointColor):
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView tintColorDidChange]):

Ensure the insertion point color is up-to-date, following changes to the view's
tint color.

* Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::insertionPointColorDidChange):
* Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::platformInitialize):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::setInsertionPointColor):

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

c346ce9

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ›  gtk
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios ❌ πŸ§ͺ mac-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  tv-sim
βœ… πŸ›  watch
βœ… πŸ›  πŸ§ͺ unsafe-merge βœ… πŸ›  watch-sim

@pxlcoder pxlcoder requested a review from cdumez as a code owner May 8, 2023 18:10
@pxlcoder pxlcoder self-assigned this May 8, 2023
@pxlcoder pxlcoder added the Platform Portability improvements and other general platform improvements not driven directly by site bugs. label May 8, 2023
Comment on lines 652 to 655
if (auto *insertionPointColor = [[self _textInputTraits] insertionPointColor])
return insertionPointColor;

return UIColor.insertionPointColor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - possibly a bit more concise as return self._textInputTraits.insertionPointColor ?: UIColor.insertionPointColor;.

@@ -1078,6 +1078,11 @@ static UIInterfaceOrientationMask toUIInterfaceOrientationMask(WebCore::ScreenOr
return color;
}

WebCore::Color PageClientImpl::insertionPointColor()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - you can omit the WebCore:: here and below, since this file already uses namespace WebCore;.


Color RenderThemeIOS::autocorrectionReplacementMarkerColor(const RenderText& renderer, OptionSet<StyleColorOptions>) const
{
Color caretColor = CaretBase::computeCaretColor(renderer.style(), renderer.textNode());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Color caretColor = CaretBase::computeCaretColor(renderer.style(), renderer.textNode());
auto caretColor = CaretBase::computeCaretColor(renderer.style(), renderer.textNode());

return *cachedInsertionPointColor();
}

Color RenderThemeIOS::autocorrectionReplacementMarkerColor(const RenderText& renderer, OptionSet<StyleColorOptions>) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - would it be cleaner to just pass in a renderer here, and use renderer.styleColorOptions() to grab the color options from it? (So that the function never takes a set of StyleColorOptions that doesn't match the renderer).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was already using renderer.styleColorOptions() in the method body – removed the parameter.

@@ -2041,7 +2041,7 @@ Color RenderTheme::platformDictationAlternativesMarkerColor(OptionSet<StyleColor
return Color::green;
}

Color RenderTheme::autocorrectionReplacementMarkerColor(OptionSet<StyleColorOptions> options) const
Color RenderTheme::autocorrectionReplacementMarkerColor(const RenderText&, OptionSet<StyleColorOptions> options) const
Copy link
Member

@aprotyas aprotyas May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Since options == RenderText::styleColorOptions(), do we need the options argument?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

@pxlcoder
Copy link
Member Author

pxlcoder commented May 8, 2023

Thanks for the reviews!

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 8, 2023
@pxlcoder pxlcoder added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merging-blocked Applied to prevent a change from being merged labels May 9, 2023
…olor

https://bugs.webkit.org/show_bug.cgi?id=256475
rdar://108355409

Reviewed by Wenson Hsieh.

The autocorrection underline color should be a variant of the current caret
color. In order to facilitate this, the insertion point color is plumbed from
the UI Process into the Web Process.

* Source/WebCore/rendering/RenderTheme.cpp:
(WebCore::RenderTheme::autocorrectionReplacementMarkerColor const):
(WebCore::RenderTheme::documentMarkerLineColor const):
* Source/WebCore/rendering/RenderTheme.h:

Add a `RenderText` parameter to `documentMarkerLineColor`, since it is
necessary to determine the caret color.

* Source/WebCore/rendering/RenderThemeCocoa.h:
* Source/WebCore/rendering/RenderThemeCocoa.mm:
(WebCore::RenderThemeCocoa::platformAutocorrectionReplacementMarkerColor const): Deleted.

Remove override, as the color is too dynamic to be cached. `caret-color` can
differ per-element, so the autocorrection underline color can no longer be cached.

* Source/WebCore/rendering/RenderThemeIOS.h:

Add a static method to set the insertion point color to avoid unnecessary
initialization of the singleton.

* Source/WebCore/rendering/RenderThemeIOS.mm:
(WebCore::cachedInsertionPointColor):
(WebCore::RenderThemeIOS::insertionPointColor):
(WebCore::RenderThemeIOS::autocorrectionReplacementMarkerColor const):

Adjust the autocorrection underline color based on the current caret color. If
`caret-color` is `auto`, use the default color from the UI process. The
adjustment is performed using the HSL colorspace, matching UIKit.

(WebCore::RenderThemeIOS::setInsertionPointColor):
* Source/WebCore/rendering/TextBoxPainter.cpp:
(WebCore::TextBoxPainter<TextBoxPath>::paintPlatformDocumentMarker):
* Source/WebKit/Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Source/WebKit/Shared/WebPageCreationParameters.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h:
* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _insertionPointColor]):

Get the insertion point color from the text input traits if it exists. Otherwise,
use the default color specified in UIKit.

* Source/WebKit/UIProcess/PageClient.h:

Add a `PageClient` hook to get the insertion point color.

* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::insertionPointColor):
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView tintColorDidChange]):

Ensure the insertion point color is up-to-date, following changes to the view's
tint color.

* Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::insertionPointColorDidChange):
* Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::platformInitialize):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::setInsertionPointColor):

Canonical link: https://commits.webkit.org/263879@main
@webkit-commit-queue
Copy link
Collaborator

Committed 263879@main (b199f7d): https://commits.webkit.org/263879@main

Reviewed commits have been landed. Closing PR #13588 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit b199f7d into WebKit:main May 9, 2023
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform Portability improvements and other general platform improvements not driven directly by site bugs.
Projects
None yet
6 participants