Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.mm (246041 => 246042)
--- trunk/Source/WebCore/editing/cocoa/DataDetection.mm 2019-06-03 18:42:34 UTC (rev 246041)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.mm 2019-06-03 19:14:42 UTC (rev 246042)
@@ -580,12 +580,14 @@
auto* parentNode = range->startContainer().parentNode();
if (!parentNode)
continue;
+
if (!is<Text>(range->startContainer()))
continue;
+
auto& currentTextNode = downcast<Text>(range->startContainer());
Document& document = currentTextNode.document();
String textNodeData;
-
+
if (lastTextNodeToUpdate != ¤tTextNode) {
if (lastTextNodeToUpdate)
lastTextNodeToUpdate->setData(lastNodeContent);
@@ -594,12 +596,12 @@
textNodeData = currentTextNode.data().substring(0, range->startOffset());
} else
textNodeData = currentTextNode.data().substring(contentOffset, range->startOffset() - contentOffset);
-
+
if (!textNodeData.isEmpty()) {
parentNode->insertBefore(Text::create(document, textNodeData), ¤tTextNode);
contentOffset = range->startOffset();
}
-
+
// Create the actual anchor node and insert it before the current node.
textNodeData = currentTextNode.data().substring(range->startOffset(), range->endOffset() - range->startOffset());
Ref<Text> newTextNode = Text::create(document, textNodeData);
@@ -608,35 +610,31 @@
Ref<HTMLAnchorElement> anchorElement = HTMLAnchorElement::create(document);
anchorElement->setHref(correspondingURL);
anchorElement->setDir("ltr");
+ anchorElement->setInlineStyleProperty(CSSPropertyColor, CSSValueCurrentcolor);
+
if (shouldUseLightLinks) {
document.updateStyleIfNeeded();
+
auto* renderStyle = parentNode->computedStyle();
if (renderStyle) {
auto textColor = renderStyle->visitedDependentColor(CSSPropertyColor);
if (textColor.isValid()) {
- double h = 0;
- double s = 0;
- double v = 0;
- textColor.getHSV(h, s, v);
+ double hue, saturation, lightness;
+ textColor.getHSL(hue, saturation, lightness);
- // Set the alpha of the underline to 46% if the text color is white-ish (defined
- // as having a saturation of less than 2% and a value/brightness or greater than
- // 98%). Otherwise, set the alpha of the underline to 26%.
- double overrideAlpha = (s < 0.02 && v > 0.98) ? 0.46 : 0.26;
- auto underlineColor = Color(colorWithOverrideAlpha(textColor.rgb(), overrideAlpha));
+ // Force the lightness of the underline color to the middle, and multiply the alpha by 38%,
+ // so the color will appear on light and dark backgrounds, since only one color can be specified.
+ double overrideLightness = 0.5;
+ double overrideAlphaMultiplier = 0.38;
+ auto underlineColor = Color(makeRGBAFromHSLA(hue, saturation, overrideLightness, overrideAlphaMultiplier * textColor.alphaAsFloat()));
- anchorElement->setInlineStyleProperty(CSSPropertyColor, textColor.cssText());
anchorElement->setInlineStyleProperty(CSSPropertyTextDecorationColor, underlineColor.cssText());
}
}
- } else if (is<StyledElement>(*parentNode)) {
- if (auto* style = downcast<StyledElement>(*parentNode).presentationAttributeStyle()) {
- String color = style->getPropertyValue(CSSPropertyColor);
- if (!color.isEmpty())
- anchorElement->setInlineStyleProperty(CSSPropertyColor, color);
- }
}
+
anchorElement->appendChild(WTFMove(newTextNode));
+
// Add a special attribute to mark this URLification as the result of data detectors.
anchorElement->setAttributeWithoutSynchronization(x_apple_data_detectorsAttr, AtomicString("true", AtomicString::ConstructFromLiteral));
anchorElement->setAttributeWithoutSynchronization(x_apple_data_detectors_typeAttr, dataDetectorTypeForCategory(softLink_DataDetectorsCore_DDResultGetCategory(coreResult)));
@@ -645,11 +643,12 @@
parentNode->insertBefore(WTFMove(anchorElement), ¤tTextNode);
contentOffset = range->endOffset();
-
+
lastNodeContent = currentTextNode.data().substring(range->endOffset(), currentTextNode.length() - range->endOffset());
lastTextNodeToUpdate = ¤tTextNode;
}
}
+
if (lastTextNodeToUpdate)
lastTextNodeToUpdate->setData(lastNodeContent);
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/Color.cpp (246041 => 246042)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/Color.cpp 2019-06-03 18:42:34 UTC (rev 246041)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/Color.cpp 2019-06-03 19:14:42 UTC (rev 246042)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2012, 2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -144,6 +144,102 @@
EXPECT_DOUBLE_EQ(0.75294117647058822, v);
}
+TEST(Color, RGBToHSL_White)
+{
+ Color color = Color::white;
+
+ double hue, saturation, lightness;
+ color.getHSL(hue, saturation, lightness);
+
+ EXPECT_DOUBLE_EQ(0, hue);
+ EXPECT_DOUBLE_EQ(0, saturation);
+ EXPECT_DOUBLE_EQ(1, lightness);
+}
+
+TEST(Color, RGBToHSL_Black)
+{
+ Color color = Color::black;
+
+ double hue, saturation, lightness;
+ color.getHSL(hue, saturation, lightness);
+
+ EXPECT_DOUBLE_EQ(0, hue);
+ EXPECT_DOUBLE_EQ(0, saturation);
+ EXPECT_DOUBLE_EQ(0, lightness);
+}
+
+TEST(Color, RGBToHSL_Red)
+{
+ Color color(255, 0, 0);
+
+ double hue, saturation, lightness;
+ color.getHSL(hue, saturation, lightness);
+
+ EXPECT_DOUBLE_EQ(0, hue);
+ EXPECT_DOUBLE_EQ(1, saturation);
+ EXPECT_DOUBLE_EQ(0.5, lightness);
+}
+
+TEST(Color, RGBToHSL_Green)
+{
+ Color color(0, 255, 0);
+
+ double hue, saturation, lightness;
+ color.getHSL(hue, saturation, lightness);
+
+ EXPECT_DOUBLE_EQ(2, hue);
+ EXPECT_DOUBLE_EQ(1, saturation);
+ EXPECT_DOUBLE_EQ(0.5, lightness);
+}
+
+TEST(Color, RGBToHSL_Blue)
+{
+ Color color(0, 0, 255);
+
+ double hue, saturation, lightness;
+ color.getHSL(hue, saturation, lightness);
+
+ EXPECT_DOUBLE_EQ(4, hue);
+ EXPECT_DOUBLE_EQ(1, saturation);
+ EXPECT_DOUBLE_EQ(0.5, lightness);
+}
+
+TEST(Color, RGBToHSL_DarkGray)
+{
+ Color color = Color::darkGray;
+
+ double hue, saturation, lightness;
+ color.getHSL(hue, saturation, lightness);
+
+ EXPECT_DOUBLE_EQ(0, hue);
+ EXPECT_DOUBLE_EQ(0, saturation);
+ EXPECT_DOUBLE_EQ(0.50196078431372548, lightness);
+}
+
+TEST(Color, RGBToHSL_Gray)
+{
+ Color color = Color::gray;
+
+ double hue, saturation, lightness;
+ color.getHSL(hue, saturation, lightness);
+
+ EXPECT_DOUBLE_EQ(0, hue);
+ EXPECT_DOUBLE_EQ(0, saturation);
+ EXPECT_DOUBLE_EQ(0.62745098039215685, lightness);
+}
+
+TEST(Color, RGBToHSL_LightGray)
+{
+ Color color = Color::lightGray;
+
+ double hue, saturation, lightness;
+ color.getHSL(hue, saturation, lightness);
+
+ EXPECT_DOUBLE_EQ(0, hue);
+ EXPECT_DOUBLE_EQ(0, saturation);
+ EXPECT_DOUBLE_EQ(0.75294117647058822, lightness);
+}
+
TEST(Color, Validity)
{
Color invalidColor;