Text caret changes to color of text in Mail and Notes
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Sep 2014 00:55:07 +0000 (00:55 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Sep 2014 00:55:07 +0000 (00:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135904

Patch by Myles C. Maxfield <mmaxfield@apple.com> on 2014-09-03
Reviewed by Simon Fraser.

Source/WebCore:

Consult with the background color of spans inside editable divs to determine what color
the caret should be.

Test: editing/caret/color-span-inside-editable.html

* editing/FrameSelection.cpp:
(WebCore::CaretBase::paintCaret):

LayoutTests:

Make sure the caret is the correct color.

* editing/caret/color-span-inside-editable-expected.html: Added.
* editing/caret/color-span-inside-editable.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/editing/caret/color-span-inside-editable-expected.html [new file with mode: 0644]
LayoutTests/editing/caret/color-span-inside-editable.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/FrameSelection.cpp

index 5438830824b4f4ed8414ca332e1617df9cdd3a59..c67248676bb062697d4907450d55a4126f8938d4 100644 (file)
@@ -1,3 +1,15 @@
+2014-09-03  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Text caret changes to color of text in Mail and Notes
+        https://bugs.webkit.org/show_bug.cgi?id=135904
+
+        Reviewed by Simon Fraser.
+
+        Make sure the caret is the correct color.
+
+        * editing/caret/color-span-inside-editable-expected.html: Added.
+        * editing/caret/color-span-inside-editable.html: Added.
+
 2014-09-03  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] Mark a number of passing tests.
diff --git a/LayoutTests/editing/caret/color-span-inside-editable-expected.html b/LayoutTests/editing/caret/color-span-inside-editable-expected.html
new file mode 100644 (file)
index 0000000..326f1fb
--- /dev/null
@@ -0,0 +1,4 @@
+This test makes sure that carets in content editable divs remain black even if there is a span inside them with a foreground color specified.
+<div style="width: 505px; height: 505px; overflow: hidden;">
+<div style="width: 50px; height: 500px; background-color: black"></div>
+</div>
diff --git a/LayoutTests/editing/caret/color-span-inside-editable.html b/LayoutTests/editing/caret/color-span-inside-editable.html
new file mode 100644 (file)
index 0000000..185abaf
--- /dev/null
@@ -0,0 +1,8 @@
+This test makes sure that carets in content editable divs remain black even if there is a span inside them with a foreground color specified.
+<div style="width: 505px; height: 505px; overflow: hidden;">
+<div id="edit" contenteditable="true" style="-webkit-transform-origin: left top; -webkit-transform: scale(50, 50); outline: none; font-family: Ahem; font-size: 10px;"><span id="spn" style="color: red;">&nbsp;&nbsp;</span></div>
+</div>
+<script>
+var edit = document.getElementById("edit");
+edit.focus();
+</script>
index e1c520fa287c8fe5133e9f586e5370e5d21b75f3..c10b0e2c398a86fc3ee368326cd58ffc3a76d1df 100644 (file)
@@ -1,3 +1,18 @@
+2014-09-03  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Text caret changes to color of text in Mail and Notes
+        https://bugs.webkit.org/show_bug.cgi?id=135904
+
+        Reviewed by Simon Fraser.
+
+        Consult with the background color of spans inside editable divs to determine what color
+        the caret should be.
+
+        Test: editing/caret/color-span-inside-editable.html
+
+        * editing/FrameSelection.cpp:
+        (WebCore::CaretBase::paintCaret):
+
 2014-09-03  Tim Horton  <timothy_horton@apple.com>
 
         Fix the iOS build after r173230
index 7ddc4e9c0286c218c70d6fb2a27b4aa2919f6646..8d3ae29dbbe434a16169d88c545f7a57904c5b9e 100644 (file)
@@ -1493,10 +1493,23 @@ void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
     Color caretColor = Color::black;
     ColorSpace colorSpace = ColorSpaceDeviceRGB;
     Element* element = node->isElementNode() ? toElement(node) : node->parentElement();
+    Element* rootEditableElement = node->rootEditableElement();
 
     if (element && element->renderer()) {
-        caretColor = element->renderer()->style().visitedDependentColor(CSSPropertyColor);
-        colorSpace = element->renderer()->style().colorSpace();
+        bool setToRootEditableElement = false;
+        if (rootEditableElement && rootEditableElement->renderer()) {
+            const auto& rootEditableStyle = rootEditableElement->renderer()->style();
+            const auto& elementStyle = element->renderer()->style();
+            if (rootEditableStyle.visitedDependentColor(CSSPropertyBackgroundColor) == elementStyle.visitedDependentColor(CSSPropertyBackgroundColor)) {
+                caretColor = rootEditableElement->renderer()->style().visitedDependentColor(CSSPropertyColor);
+                colorSpace = rootEditableElement->renderer()->style().colorSpace();
+                setToRootEditableElement = true;
+            }
+        }
+        if (!setToRootEditableElement) {
+            caretColor = element->renderer()->style().visitedDependentColor(CSSPropertyColor);
+            colorSpace = element->renderer()->style().colorSpace();
+        }
     }
 
     context->fillRect(caret, caretColor, colorSpace);