- Revision
- 256921
- Author
- megan_gard...@apple.com
- Date
- 2020-02-19 08:57:15 -0800 (Wed, 19 Feb 2020)
Log Message
Ensure that contenteditable carets on macCatalyst are the right color, especially in Dark Mode
https://bugs.webkit.org/show_bug.cgi?id=207789
<rdar://problem/59429715>
Reviewed by Tim Horton.
Source/WebCore:
Factor out caret color calculation to be used in WebPageIOS.
Fixes EditorStateTests.CaretColorInContentEditable.
* editing/FrameSelection.cpp:
(WebCore::CaretBase::computeCaretColor):
(WebCore::CaretBase::paintCaret const):
* editing/FrameSelection.h:
Source/WebKit:
Because UIKit only uses label color for the caret in macCatalyst,
we need skip text input traits and send the correctly calculated color
to UIKit.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView insertionPointColor]):
(-[WKContentView getInteractionTintColor]):
(-[WKContentView _updateInteractionTintColor]):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformEditorState const):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (256920 => 256921)
--- trunk/Source/WebCore/ChangeLog 2020-02-19 16:37:35 UTC (rev 256920)
+++ trunk/Source/WebCore/ChangeLog 2020-02-19 16:57:15 UTC (rev 256921)
@@ -1,3 +1,20 @@
+2020-02-19 Megan Gardner <megan_gard...@apple.com>
+
+ Ensure that contenteditable carets on macCatalyst are the right color, especially in Dark Mode
+ https://bugs.webkit.org/show_bug.cgi?id=207789
+ <rdar://problem/59429715>
+
+ Reviewed by Tim Horton.
+
+ Factor out caret color calculation to be used in WebPageIOS.
+
+ Fixes EditorStateTests.CaretColorInContentEditable.
+
+ * editing/FrameSelection.cpp:
+ (WebCore::CaretBase::computeCaretColor):
+ (WebCore::CaretBase::paintCaret const):
+ * editing/FrameSelection.h:
+
2020-02-19 Chris Dumez <cdu...@apple.com>
Unreviewed, fix assertions in storage access API layout tests after r256882.
Modified: trunk/Source/WebCore/editing/FrameSelection.cpp (256920 => 256921)
--- trunk/Source/WebCore/editing/FrameSelection.cpp 2020-02-19 16:37:35 UTC (rev 256920)
+++ trunk/Source/WebCore/editing/FrameSelection.cpp 2020-02-19 16:57:15 UTC (rev 256921)
@@ -1768,6 +1768,27 @@
CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, paintOffset, clipRect);
}
+Color CaretBase::computeCaretColor(const RenderStyle& elementStyle, Node* node)
+{
+ // On iOS, we want to fall back to the tintColor, and only override if CSS has explicitly specified a custom color.
+#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
+ UNUSED_PARAM(node);
+ return elementStyle.caretColor();
+#else
+ auto* rootEditableElement = node ? node->rootEditableElement() : nullptr;
+ auto* rootEditableStyle = rootEditableElement && rootEditableElement->renderer() ? &rootEditableElement->renderer()->style() : nullptr;
+ // CSS value "auto" is treated as an invalid color.
+ if (!elementStyle.caretColor().isValid() && rootEditableStyle) {
+ auto rootEditableBackgroundColor = rootEditableStyle->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
+ auto elementBackgroundColor = elementStyle.visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
+ auto disappearsIntoBackground = rootEditableBackgroundColor.blend(elementBackgroundColor) == rootEditableBackgroundColor;
+ if (disappearsIntoBackground)
+ return rootEditableStyle->visitedDependentColorWithColorFilter(CSSPropertyCaretColor);
+ }
+ return elementStyle.visitedDependentColorWithColorFilter(CSSPropertyCaretColor);
+#endif
+}
+
void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const
{
#if ENABLE(TEXT_CARET)
@@ -1784,22 +1805,8 @@
Color caretColor = Color::black;
Element* element = is<Element>(*node) ? downcast<Element>(node) : node->parentElement();
- if (element && element->renderer()) {
- auto computeCaretColor = [] (const RenderStyle& elementStyle, const RenderStyle* rootEditableStyle) {
- // CSS value "auto" is treated as an invalid color.
- if (!elementStyle.caretColor().isValid() && rootEditableStyle) {
- auto rootEditableBackgroundColor = rootEditableStyle->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
- auto elementBackgroundColor = elementStyle.visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
- auto disappearsIntoBackground = rootEditableBackgroundColor.blend(elementBackgroundColor) == rootEditableBackgroundColor;
- if (disappearsIntoBackground)
- return rootEditableStyle->visitedDependentColorWithColorFilter(CSSPropertyCaretColor);
- }
- return elementStyle.visitedDependentColorWithColorFilter(CSSPropertyCaretColor);
- };
- auto* rootEditableElement = node->rootEditableElement();
- auto* rootEditableStyle = rootEditableElement && rootEditableElement->renderer() ? &rootEditableElement->renderer()->style() : nullptr;
- caretColor = computeCaretColor(element->renderer()->style(), rootEditableStyle);
- }
+ if (element && element->renderer())
+ caretColor = CaretBase::computeCaretColor(element->renderer()->style(), node);
context.fillRect(caret, caretColor);
#else
Modified: trunk/Source/WebCore/editing/FrameSelection.h (256920 => 256921)
--- trunk/Source/WebCore/editing/FrameSelection.h 2020-02-19 16:37:35 UTC (rev 256920)
+++ trunk/Source/WebCore/editing/FrameSelection.h 2020-02-19 16:57:15 UTC (rev 256921)
@@ -62,6 +62,8 @@
class CaretBase {
WTF_MAKE_NONCOPYABLE(CaretBase);
WTF_MAKE_FAST_ALLOCATED;
+public:
+ WEBCORE_EXPORT static Color computeCaretColor(const RenderStyle& elementStyle, Node*);
protected:
enum CaretVisibility { Visible, Hidden };
explicit CaretBase(CaretVisibility = Hidden);
Modified: trunk/Source/WebKit/ChangeLog (256920 => 256921)
--- trunk/Source/WebKit/ChangeLog 2020-02-19 16:37:35 UTC (rev 256920)
+++ trunk/Source/WebKit/ChangeLog 2020-02-19 16:57:15 UTC (rev 256921)
@@ -1,3 +1,22 @@
+2020-02-19 Megan Gardner <megan_gard...@apple.com>
+
+ Ensure that contenteditable carets on macCatalyst are the right color, especially in Dark Mode
+ https://bugs.webkit.org/show_bug.cgi?id=207789
+ <rdar://problem/59429715>
+
+ Reviewed by Tim Horton.
+
+ Because UIKit only uses label color for the caret in macCatalyst,
+ we need skip text input traits and send the correctly calculated color
+ to UIKit.
+
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView insertionPointColor]):
+ (-[WKContentView getInteractionTintColor]):
+ (-[WKContentView _updateInteractionTintColor]):
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::platformEditorState const):
+
2020-02-19 Cathie Chen <cathiec...@igalia.com>
Enable AspectRatioOfImgFromWidthAndHeightEnabled by default
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (256920 => 256921)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2020-02-19 16:37:35 UTC (rev 256920)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2020-02-19 16:57:15 UTC (rev 256921)
@@ -3223,7 +3223,12 @@
- (UIColor *)insertionPointColor
{
+ // On macCatalyst we need to explicitly return the color we have calculated, rather than rely on textTraits, as on macCatalyst, UIKit ignores text traits.
+#if PLATFORM(MACCATALYST)
+ return [self _cascadeInteractionTintColor];
+#else
return [self.textInputTraits insertionPointColor];
+#endif
}
- (UIColor *)selectionBarColor
@@ -3236,22 +3241,22 @@
return [self.textInputTraits selectionHighlightColor];
}
-- (void)_updateInteractionTintColor
+- (UIColor *)_cascadeInteractionTintColor
{
- UIColor *tintColor = ^{
- if (!self.webView.configuration._textInteractionGesturesEnabled)
- return [UIColor clearColor];
+ if (!self.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];
- }();
+ 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)_updateInteractionTintColor
+{
+ [_traits _setColorsToMatchTintColor:[self _cascadeInteractionTintColor]];
}
- (void)tintColorDidChange
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (256920 => 256921)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2020-02-19 16:37:35 UTC (rev 256920)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2020-02-19 16:57:15 UTC (rev 256921)
@@ -280,7 +280,7 @@
if (m_focusedElement && m_focusedElement->renderer()) {
auto& renderer = *m_focusedElement->renderer();
postLayoutData.focusedElementRect = rootViewInteractionBoundsForElement(*m_focusedElement);
- postLayoutData.caretColor = renderer.style().caretColor();
+ postLayoutData.caretColor = CaretBase::computeCaretColor(renderer.style(), renderer.element());
}
if (result.isContentEditable) {
if (auto editableRootOrFormControl = makeRefPtr(selection.rootEditableElement())) {