-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopt UIExtendedTextInputTraits and -[UIAsyncTextInput extendedTraits…
…Delegate] https://bugs.webkit.org/show_bug.cgi?id=264977 rdar://118526529 Reviewed by Tim Horton. Adopt the new `UIExtendedTextInputTraits` protocol (which offers additional properties in addition to the existing API properties on `UITextInputTraits`); this is passed from WebKit to UIKit via a new `UIAsyncTextInput` delegate method, `-extendedTraitsDelegate`. * Source/WebKit/Platform/spi/ios/UIKitSPI.h: * Source/WebKit/SourcesCocoa.txt: * Source/WebKit/UIProcess/ios/WKContentViewInteraction.h: Rename the existing `_traits` object (a concrete `UITextInputTraits` object) to `_legacyTextInputTraits`, and introduce a new `_extendedTextInputTraits` object, which is returned from the new `UIAsyncTextInput` delegate method. * Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm: (-[WKContentView _updateTextInputTraitsForInteractionTintColor]): (-[WKContentView tintColorDidChange]): (-[WKContentView textInputTraits]): (-[WKContentView textInputTraitsForWebView]): (-[WKContentView _updateTextInputTraits:]): (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]): (-[WKContentView extendedTraitsDelegate]): (-[WKContentView _updateInteractionTintColor:]): Deleted. Update this to set colors on either `_extendedTextInputTraits` or `_legacyTextInputTraits`, instead of having the caller pass in the traits object. This is only ever used to update the currently cached traits object, so there's no change in behavior here. * Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.h: Added. * Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.mm: Added. (WebKit::defaultInsertionPointColor): (WebKit::defaultSelectionGrabberColor): (WebKit::defaultSelectionHighlightColor): (-[WKExtendedTextInputTraits setTextContentType:]): (-[WKExtendedTextInputTraits textContentType]): (-[WKExtendedTextInputTraits setInsertionPointColor:]): (-[WKExtendedTextInputTraits insertionPointColor]): (-[WKExtendedTextInputTraits setSelectionBarColor:]): (-[WKExtendedTextInputTraits selectionBarColor]): (-[WKExtendedTextInputTraits setSelectionHighlightColor:]): (-[WKExtendedTextInputTraits selectionHighlightColor]): (-[WKExtendedTextInputTraits setSelectionColorsToMatchTintColor:]): Add a new concrete implementation of `UIExtendedTextInputTraits` that's instantiated in WebKit and returned via `-[UIAsyncTextInput extendedTraitsDelegate]`. This also eliminates use of another SPI method, `-_setColorsToMatchTintColor:`, albeit at the cost of hard-coding some system colors related to text interaction. * Source/WebKit/WebKit.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/270854@main
- Loading branch information
Showing
7 changed files
with
234 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2023 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#if PLATFORM(IOS_FAMILY) | ||
|
||
#import "UIKitSPI.h" | ||
|
||
@interface WKExtendedTextInputTraits : NSObject | ||
#if HAVE(UI_ASYNC_TEXT_INTERACTION) | ||
<UIExtendedTextInputTraits_Staging_117880911> | ||
#endif | ||
|
||
@property (nonatomic) UITextAutocapitalizationType autocapitalizationType; | ||
@property (nonatomic) UITextAutocorrectionType autocorrectionType; | ||
@property (nonatomic) UITextSpellCheckingType spellCheckingType; | ||
@property (nonatomic) UITextSmartQuotesType smartQuotesType; | ||
@property (nonatomic) UITextSmartDashesType smartDashesType; | ||
@property (nonatomic) UITextInlinePredictionType inlinePredictionType; | ||
@property (nonatomic) UIKeyboardType keyboardType; | ||
@property (nonatomic) UIKeyboardAppearance keyboardAppearance; | ||
@property (nonatomic) UIReturnKeyType returnKeyType; | ||
@property (nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry; | ||
@property (nonatomic, getter=isSingleLineDocument) BOOL singleLineDocument; | ||
@property (nonatomic) BOOL typingAdaptationDisabled; | ||
@property (nonatomic, copy) UITextContentType textContentType; | ||
|
||
@property (nonatomic, strong) UIColor *insertionPointColor; | ||
@property (nonatomic, strong) UIColor *selectionBarColor; | ||
@property (nonatomic, strong) UIColor *selectionHighlightColor; | ||
|
||
- (void)setSelectionColorsToMatchTintColor:(UIColor *)tintColor; | ||
|
||
@end | ||
|
||
#endif // PLATFORM(IOS_FAMILY) |
116 changes: 116 additions & 0 deletions
116
Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright (C) 2023 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#import "config.h" | ||
#import "WKExtendedTextInputTraits.h" | ||
|
||
#if PLATFORM(IOS_FAMILY) | ||
|
||
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; | ||
RetainPtr<UIColor> _selectionBarColor; | ||
RetainPtr<UIColor> _selectionHighlightColor; | ||
} | ||
|
||
- (void)setTextContentType:(UITextContentType)type | ||
{ | ||
_textContentType = adoptNS(type.copy); | ||
} | ||
|
||
- (UITextContentType)textContentType | ||
{ | ||
return _textContentType.get(); | ||
} | ||
|
||
- (void)setInsertionPointColor:(UIColor *)color | ||
{ | ||
_insertionPointColor = color; | ||
} | ||
|
||
- (UIColor *)insertionPointColor | ||
{ | ||
return _insertionPointColor.get(); | ||
} | ||
|
||
- (void)setSelectionBarColor:(UIColor *)color | ||
{ | ||
_selectionBarColor = color; | ||
} | ||
|
||
- (UIColor *)selectionBarColor | ||
{ | ||
return _selectionBarColor.get(); | ||
} | ||
|
||
- (void)setSelectionHighlightColor:(UIColor *)color | ||
{ | ||
_selectionHighlightColor = color; | ||
} | ||
|
||
- (UIColor *)selectionHighlightColor | ||
{ | ||
return _selectionHighlightColor.get(); | ||
} | ||
|
||
- (void)setSelectionColorsToMatchTintColor:(UIColor *)tintColor | ||
{ | ||
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(); | ||
} | ||
|
||
@end | ||
|
||
#endif // PLATFORM(IOS_FAMILY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters