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 c1211131685853cfd1932dedd9fe8b06975c36cf..17336ea2b2b00edb1d3920a11531db7435f83191 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 5afac59abedbaad0173146f7c202137a4faae318..d4d0950f3c9a46a77ca1d0a67dbdbd0de02091da 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 b705a6e98f835f3b0f205ad04ed31b3328013685..f7697206985e1578520520e04833f7c352310e20 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 0ba3088a847eee6f24bab294927fc12ab12adb19..542f667f636212050405c82c521fd5eeb88e9780 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 7064a12b2b2300b83d43f575b85b30ffd736b86b..6c5cd41bf75de0408d406b022a776c0b55a825c0 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 db8d757cdbda9de39a7fd85a28a90f29a85f62fd..568ac1973fa83dc11dbb8f40f491d0d55222f52d 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 8efbb90e82a2565877497700767af4daa6667292..d336ec0bda7a435267bf5a1bd59349ccfdc5a969 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 c333ba80f56324cf4945323fbfc667bd934a6196..81e5674b40981eb7d9891ff80d40bd8b68d6cb2f 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>