Source/WebKit:
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Oct 2017 00:09:48 +0000 (00:09 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Oct 2017 00:09:48 +0000 (00:09 +0000)
[iOS] Respect the "caret-color" CSS property when editing
https://bugs.webkit.org/show_bug.cgi?id=177489
<rdar://problem/34600419>

Patch by Aishwarya Nirmal <anirmal@apple.com> on 2017-10-06
Reviewed by Tim Horton.

This change adds support for the caret-color property on iOS.

* Shared/EditorState.cpp:
(WebKit::EditorState::PostLayoutData::encode const):
(WebKit::EditorState::PostLayoutData::decode):
* Shared/EditorState.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView insertionPointColor]):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformEditorState const):

Tools:
[iOS] Respect the "caret-color" CSS property when editing
https://bugs.webkit.org/show_bug.cgi?id=177489
<rdar://problem/34600419>

Patch by Aishwarya Nirmal <anirmal@apple.com> on 2017-10-06
Reviewed by Tim Horton.

Adds test for iOS caret color support.

* TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/ios/UIKitSPI.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223012 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/Shared/EditorState.cpp
Source/WebKit/Shared/EditorState.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm
Tools/TestWebKitAPI/ios/UIKitSPI.h

index c121113..17336ea 100644 (file)
@@ -1,3 +1,22 @@
+2017-10-06  Aishwarya Nirmal  <anirmal@apple.com>
+
+        [iOS] Respect the "caret-color" CSS property when editing 
+        https://bugs.webkit.org/show_bug.cgi?id=177489
+        <rdar://problem/34600419>
+
+        Reviewed by Tim Horton.
+
+        This change adds support for the caret-color property on iOS.
+
+        * Shared/EditorState.cpp:
+        (WebKit::EditorState::PostLayoutData::encode const):
+        (WebKit::EditorState::PostLayoutData::decode):
+        * Shared/EditorState.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView insertionPointColor]):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::platformEditorState const):
+
 2017-10-06  Brian Burg  <bburg@apple.com>
 
         Web Inspector: clicking in Inspector webview clears the selection in the inspected page
index 5afac59..d4d0950 100644 (file)
@@ -128,6 +128,7 @@ void EditorState::PostLayoutData::encode(IPC::Encoder& encoder) const
     encoder << isStableStateUpdate;
     encoder << insideFixedPosition;
     encoder << hasPlainText;
+    encoder << caretColor;
 #endif
 #if PLATFORM(MAC)
     encoder << candidateRequestStartPosition;
@@ -179,6 +180,8 @@ bool EditorState::PostLayoutData::decode(IPC::Decoder& decoder, PostLayoutData&
         return false;
     if (!decoder.decode(result.hasPlainText))
         return false;
+    if (!decoder.decode(result.caretColor))
+        return false;
 #endif
 #if PLATFORM(MAC)
     if (!decoder.decode(result.candidateRequestStartPosition))
index b705a6e..f769720 100644 (file)
@@ -102,6 +102,7 @@ struct EditorState {
         bool isStableStateUpdate { false };
         bool insideFixedPosition { false };
         bool hasPlainText { false };
+        WebCore::Color caretColor;
 #endif
 #if PLATFORM(MAC)
         uint64_t candidateRequestStartPosition { 0 };
index 0ba3088..542f667 100644 (file)
@@ -2025,6 +2025,11 @@ FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKWEBVIEW)
 
 - (UIColor *)insertionPointColor
 {
+    if (!_page->editorState().isMissingPostLayoutData) {
+        WebCore::Color caretColor = _page->editorState().postLayoutData().caretColor;
+        if (caretColor.isValid())
+            return [UIColor colorWithCGColor:cachedCGColor(caretColor)];
+    }
     return [UIColor insertionPointColor];
 }
 
index 7064a12..6c5cd41 100644 (file)
@@ -228,8 +228,10 @@ void WebPage::platformEditorState(Frame& frame, EditorState& result, IncludePost
     }
     postLayoutData.insideFixedPosition = startNodeIsInsideFixedPosition || endNodeIsInsideFixedPosition;
     if (!selection.isNone()) {
-        if (m_assistedNode && m_assistedNode->renderer())
+        if (m_assistedNode && m_assistedNode->renderer()) {
             postLayoutData.selectionClipRect = view->contentsToRootView(m_assistedNode->renderer()->absoluteBoundingBoxRect());
+            postLayoutData.caretColor = m_assistedNode->renderer()->style().caretColor();
+        }
         computeEditableRootHasContentAndPlainText(selection, postLayoutData);
     }
 }
index db8d757..568ac19 100644 (file)
@@ -1,3 +1,17 @@
+2017-10-06  Aishwarya Nirmal  <anirmal@apple.com>
+
+        [iOS] Respect the "caret-color" CSS property when editing
+        https://bugs.webkit.org/show_bug.cgi?id=177489
+        <rdar://problem/34600419>
+
+        Reviewed by Tim Horton.
+
+        Adds test for iOS caret color support.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2017-10-06  Alex Christensen  <achristensen@webkit.org>
 
         Add more infrastructure to apply custom header fields to same-origin requests
index 8efbb90..d336ec0 100644 (file)
@@ -33,6 +33,7 @@
 #import <WebKit/WKWebViewPrivate.h>
 
 #if PLATFORM(IOS)
+#import "UIKitSPI.h"
 #import <UIKit/UIKit.h>
 #endif
 
@@ -298,6 +299,19 @@ TEST(EditorStateTests, ContentViewHasTextInTextarea)
     checkContentViewHasTextWithFailureDescription(webView.get(), NO, @"after losing focus");
 }
 
+TEST(EditorStateTests, CaretColorInContentEditable)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView synchronouslyLoadHTMLString:@"<body style=\"caret-color: red;\" contenteditable=\"true\"></body>"];
+    [webView stringByEvaluatingJavaScript:@"document.body.focus()"];
+    UIView<UITextInputTraits_Private> *textInput = (UIView<UITextInputTraits_Private> *) [webView textInputContentView];
+    UIColor *insertionPointColor = textInput.insertionPointColor;
+    UIColor *redColor = [UIColor redColor];
+    auto colorSpace = adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
+    auto cgInsertionPointColor = adoptCF(CGColorCreateCopyByMatchingToColorSpace(colorSpace.get(), kCGRenderingIntentDefault, insertionPointColor.CGColor, NULL));
+    auto cgRedColor = adoptCF(CGColorCreateCopyByMatchingToColorSpace(colorSpace.get(), kCGRenderingIntentDefault, redColor.CGColor, NULL));
+    EXPECT_TRUE(CGColorEqualToColor(cgInsertionPointColor.get(), cgRedColor.get()));
+}
 #endif
 
 } // namespace TestWebKitAPI
index c333ba8..81e5674 100644 (file)
@@ -56,6 +56,7 @@ WTF_EXTERN_C_END
 @end
 
 @protocol UITextInputTraits_Private <NSObject, UITextInputTraits>
+@property (nonatomic, readonly) UIColor *insertionPointColor;
 @end
 
 @protocol UITextInputPrivate <UITextInput, UITextInputTraits_Private>