Text caret changes to color of text in Mail and Notes
[WebKit-https.git] / Source / WebCore / editing / FrameSelection.cpp
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);