Skip to content

Commit

Permalink
Followup to 270854@main: remove some hard-coded default colors in `WK…
Browse files Browse the repository at this point in the history
…ExtendedTextInputTraits`

https://bugs.webkit.org/show_bug.cgi?id=264977
rdar://118526529

Reviewed by Richard Robinson.

The following three properties:

```
-insertionPointColor
-selectionBarColor
-selectionHighlightColor
```

...are actually nullable on `UIExtendedTextInputTraits`, and setting them to `nil` allows UIKit to
fall back to default colors. As such, we can avoid hard-coding default values here and just set
these properties to `nil`.

* Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.mm:
(-[WKExtendedTextInputTraits setSelectionColorsToMatchTintColor:]):
(WebKit::defaultInsertionPointColor): Deleted.
(WebKit::defaultSelectionGrabberColor): Deleted.
(WebKit::defaultSelectionHighlightColor): Deleted.

Canonical link: https://commits.webkit.org/271257@main
  • Loading branch information
whsieh committed Nov 29, 2023
1 parent 9ebaa6b commit 9265f75
Showing 1 changed file with 4 additions and 31 deletions.
35 changes: 4 additions & 31 deletions Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,6 @@

#import <wtf/RetainPtr.h>

namespace WebKit {

static constexpr auto selectionHighlightAlphaComponent = 0.2;

static UIColor *defaultInsertionPointColor()
{
#if PLATFORM(MACCATALYST)
return UIColor.systemBlueColor;
#else
static NeverDestroyed<RetainPtr<UIColor>> color = [UIColor colorWithRed:0.26 green:0.42 blue:0.95 alpha:1];
return color->get();
#endif
}

static UIColor *defaultSelectionGrabberColor()
{
static NeverDestroyed<RetainPtr<UIColor>> color = [UIColor colorWithRed:0.078 green:0.435 blue:0.882 alpha:1];
return color->get();
}

static UIColor *defaultSelectionHighlightColor()
{
static NeverDestroyed<RetainPtr<UIColor>> color = [UIColor colorWithRed:0.33 green:0.65 blue:0.2 alpha:1];
return color->get();
}

} // namespace WebKit

@implementation WKExtendedTextInputTraits {
RetainPtr<UITextContentType> _textContentType;
RetainPtr<UIColor> _insertionPointColor;
Expand Down Expand Up @@ -107,10 +79,11 @@ - (UIColor *)selectionHighlightColor

- (void)setSelectionColorsToMatchTintColor:(UIColor *)tintColor
{
static constexpr auto selectionHighlightAlphaComponent = 0.2;
BOOL shouldUseTintColor = tintColor && tintColor != UIColor.systemBlueColor;
self.insertionPointColor = shouldUseTintColor ? tintColor : WebKit::defaultInsertionPointColor();
self.selectionBarColor = shouldUseTintColor ? tintColor : WebKit::defaultSelectionGrabberColor();
self.selectionHighlightColor = shouldUseTintColor ? [tintColor colorWithAlphaComponent:WebKit::selectionHighlightAlphaComponent] : WebKit::defaultSelectionHighlightColor();
self.insertionPointColor = shouldUseTintColor ? tintColor : nil;
self.selectionBarColor = shouldUseTintColor ? tintColor : nil;
self.selectionHighlightColor = shouldUseTintColor ? [tintColor colorWithAlphaComponent:selectionHighlightAlphaComponent] : nil;
}

@end
Expand Down

0 comments on commit 9265f75

Please sign in to comment.