Title: [239026] trunk
Revision
239026
Author
[email protected]
Date
2018-12-10 01:05:01 -0800 (Mon, 10 Dec 2018)

Log Message

WKWebView should support custom tintColor
https://bugs.webkit.org/show_bug.cgi?id=192518
<rdar://problem/37243261>

Reviewed by Wenson Hsieh.

Source/WebKit:

* Platform/spi/ios/UIKitSPI.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView insertionPointColor]):
(-[WKContentView selectionBarColor]):
(-[WKContentView selectionHighlightColor]):
Grab insertion point and selection colors from UITextInputTraits.

(-[WKContentView _updateInteractionTintColor]):
Determine our effective tint color:
    - transparent if interaction is disabled
    - a CSS-derived color if caret-color style is applied
    - the _inheritedInteractionTintColor, which climbs up to the tintColor API
Apply it to our UITextInputTraits.

(-[WKContentView tintColorDidChange]):
(-[WKContentView textInputTraits]):
Call _updateInteractionTintColor whenever we create a new UITextInputTraits
or when the tint color changes.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/SystemColors.mm:
(TestWebKitAPI::TEST):
Add a test that tintColor affects UITextInputTraits' interaction colors.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (239025 => 239026)


--- trunk/Source/WebKit/ChangeLog	2018-12-10 07:54:16 UTC (rev 239025)
+++ trunk/Source/WebKit/ChangeLog	2018-12-10 09:05:01 UTC (rev 239026)
@@ -1,3 +1,30 @@
+2018-12-10  Tim Horton  <[email protected]>
+
+        WKWebView should support custom tintColor
+        https://bugs.webkit.org/show_bug.cgi?id=192518
+        <rdar://problem/37243261>
+
+        Reviewed by Wenson Hsieh.
+
+        * Platform/spi/ios/UIKitSPI.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView insertionPointColor]):
+        (-[WKContentView selectionBarColor]):
+        (-[WKContentView selectionHighlightColor]):
+        Grab insertion point and selection colors from UITextInputTraits.
+
+        (-[WKContentView _updateInteractionTintColor]):
+        Determine our effective tint color:
+            - transparent if interaction is disabled
+            - a CSS-derived color if caret-color style is applied
+            - the _inheritedInteractionTintColor, which climbs up to the tintColor API
+        Apply it to our UITextInputTraits.
+
+        (-[WKContentView tintColorDidChange]):
+        (-[WKContentView textInputTraits]):
+        Call _updateInteractionTintColor whenever we create a new UITextInputTraits
+        or when the tint color changes.
+
 2018-12-09  Youenn Fablet  <[email protected]>
 
         Move capture manager from RealtimeMediaSourceCenter to capture factory

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (239025 => 239026)


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2018-12-10 07:54:16 UTC (rev 239025)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2018-12-10 09:05:01 UTC (rev 239026)
@@ -374,6 +374,9 @@
 - (void)takeTraitsFrom:(id <UITextInputTraits>)traits;
 @optional
 @property (nonatomic) UITextShortcutConversionType shortcutConversionType;
+@property (nonatomic, retain) UIColor *insertionPointColor;
+@property (nonatomic, retain) UIColor *selectionBarColor;
+@property (nonatomic, retain) UIColor *selectionHighlightColor;
 @end
 
 @class UITextInputArrowKeyHistory;
@@ -397,6 +400,7 @@
 @end
 
 @interface UITextInputTraits : NSObject <UITextInputTraits, UITextInputTraits_Private, NSCopying>
+- (void)_setColorsToMatchTintColor:(UIColor *)tintColor;
 @end
 
 @interface UITextInteractionAssistant : NSObject
@@ -502,6 +506,7 @@
 - (void)viewWillMoveToSuperview:(UIView *)newSuperview;
 - (CGSize)convertSize:(CGSize)size toView:(UIView *)view;
 - (void)_removeAllAnimations:(BOOL)includeSubviews;
+- (UIColor *)_inheritedInteractionTintColor;
 @end
 
 @interface UIWebSelectionView : UIView

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (239025 => 239026)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-12-10 07:54:16 UTC (rev 239025)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-12-10 09:05:01 UTC (rev 239026)
@@ -2489,17 +2489,43 @@
 
 - (UIColor *)insertionPointColor
 {
-    if (!_webView.configuration._textInteractionGesturesEnabled)
-        return [UIColor clearColor];
+    return [self.textInputTraits insertionPointColor];
+}
 
-    if (!_page->editorState().isMissingPostLayoutData) {
-        WebCore::Color caretColor = _page->editorState().postLayoutData().caretColor;
-        if (caretColor.isValid())
-            return [UIColor colorWithCGColor:cachedCGColor(caretColor)];
-    }
-    return [UIColor insertionPointColor];
+- (UIColor *)selectionBarColor
+{
+    return [self.textInputTraits selectionBarColor];
 }
 
+- (UIColor *)selectionHighlightColor
+{
+    return [self.textInputTraits selectionHighlightColor];
+}
+
+- (void)_updateInteractionTintColor
+{
+    UIColor *tintColor = ^{
+        if (!_webView.configuration._textInteractionGesturesEnabled)
+            return [UIColor clearColor];
+
+        if (!_page->editorState().isMissingPostLayoutData) {
+            WebCore::Color caretColor = _page->editorState().postLayoutData().caretColor;
+            if (caretColor.isValid())
+                return [UIColor colorWithCGColor:cachedCGColor(caretColor)];
+        }
+        
+        return [self _inheritedInteractionTintColor];    
+    }();
+
+    [_traits _setColorsToMatchTintColor:tintColor];
+}
+
+- (void)tintColorDidChange
+{
+    [super tintColorDidChange];
+    [self _updateInteractionTintColor];
+}
+
 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
 {
     return [_webView canPerformAction:action withSender:sender];
@@ -3846,6 +3872,8 @@
 
     [_traits setTextContentType:contentTypeFromFieldName(_assistedNodeInformation.autofillFieldName)];
 
+    [self _updateInteractionTintColor];
+
     return _traits.get();
 }
 

Modified: trunk/Tools/ChangeLog (239025 => 239026)


--- trunk/Tools/ChangeLog	2018-12-10 07:54:16 UTC (rev 239025)
+++ trunk/Tools/ChangeLog	2018-12-10 09:05:01 UTC (rev 239026)
@@ -1,3 +1,15 @@
+2018-12-10  Tim Horton  <[email protected]>
+
+        WKWebView should support custom tintColor
+        https://bugs.webkit.org/show_bug.cgi?id=192518
+        <rdar://problem/37243261>
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/SystemColors.mm:
+        (TestWebKitAPI::TEST):
+        Add a test that tintColor affects UITextInputTraits' interaction colors.
+
 2018-12-09  Wenson Hsieh  <[email protected]>
 
         [iOS] DragAndDropTests.RespectsExternalSourceFidelityRankings is flaky

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemColors.mm (239025 => 239026)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemColors.mm	2018-12-10 07:54:16 UTC (rev 239025)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemColors.mm	2018-12-10 09:05:01 UTC (rev 239026)
@@ -36,6 +36,11 @@
 #import <pal/spi/cocoa/NSColorSPI.h>
 #endif
 
+#if PLATFORM(IOS_FAMILY)
+#import "UIKitSPI.h"
+#import <UIKit/UIKit.h>
+#endif
+
 namespace TestWebKitAPI {
 
 TEST(WebKit, LinkColor)
@@ -69,6 +74,19 @@
 }
 #endif
 
+#if PLATFORM(IOS_FAMILY)
+TEST(WebKit, TintColorAffectsInteractionColor)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView setTintColor:[UIColor greenColor]];
+    [webView synchronouslyLoadHTMLString:@"<body contenteditable></body>"];
+    [webView stringByEvaluatingJavaScript:@"document.body.focus()"];
+    UIView<UITextInputTraits_Private> *textInput = (UIView<UITextInputTraits_Private> *) [webView textInputContentView];
+    EXPECT_TRUE([textInput.insertionPointColor isEqual:[UIColor greenColor]]);
+    EXPECT_TRUE([textInput.selectionBarColor isEqual:[UIColor greenColor]]);
+}
+#endif
+
 } // namespace TestWebKitAPI
 
 #endif

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (239025 => 239026)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2018-12-10 07:54:16 UTC (rev 239025)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2018-12-10 09:05:01 UTC (rev 239026)
@@ -68,6 +68,7 @@
 
 @protocol UITextInputTraits_Private <NSObject, UITextInputTraits>
 @property (nonatomic, readonly) UIColor *insertionPointColor;
+@property (nonatomic, readonly) UIColor *selectionBarColor;
 @end
 
 @class WebEvent;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to