Diff
Modified: branches/safari-608.1-branch/LayoutTests/ChangeLog (248346 => 248347)
--- branches/safari-608.1-branch/LayoutTests/ChangeLog 2019-08-07 06:52:22 UTC (rev 248346)
+++ branches/safari-608.1-branch/LayoutTests/ChangeLog 2019-08-07 06:52:25 UTC (rev 248347)
@@ -1,5 +1,68 @@
2019-08-06 Kocsen Chung <[email protected]>
+ Cherry-pick r247792. rdar://problem/54017900
+
+ Daring Fireball long press highlights are unnecessarily inflated due to false illegibility
+ https://bugs.webkit.org/show_bug.cgi?id=200064
+
+ Reviewed by Geoff Garen.
+
+ Source/WebCore:
+
+ If we consider text illegible on the given estimated background color,
+ we bail from doing a tightly fitted selection-only TextIndicator and
+ instead just paint the page without modification into the indicator,
+ causing ugly overlap and an excessively inflated indicator.
+
+ Change the mechanism we use to determine illegibility to be based on
+ a standard, instead of a constant chosen by hand 13 years ago.
+
+ Test: fast/text-indicator/text-indicator-with-low-contrast-text.html
+
+ * platform/graphics/ColorUtilities.cpp:
+ (WebCore::luminance):
+ Fix a typo.
+
+ (WebCore::contrastRatio):
+ Add a function that computes the contrast ratio given two colors using
+ the formula from WCAG.
+
+ * platform/graphics/ColorUtilities.h:
+ * rendering/TextPaintStyle.cpp:
+ (WebCore::textColorIsLegibleAgainstBackgroundColor):
+ Make use of WCAG's minimum legible contrast ratio instead of an
+ arbitrary color difference cutoff for determining whether we consider
+ text legible. It seems sensible and also considers the text on DF readable
+ (which it seems to be to me!).
+
+ * testing/Internals.cpp:
+ (WebCore::Internals::TextIndicatorInfo::TextIndicatorInfo):
+ * testing/Internals.h:
+ * testing/Internals.idl:
+ Expose all of the text rects to Internals, not just the bounding rect.
+ Expose some more TextIndicator options to Internals so that we can
+ turn on the legibility mechanism.
+
+ LayoutTests:
+
+ * fast/text-indicator/text-indicator-with-low-contrast-text-expected.txt: Added.
+ * fast/text-indicator/text-indicator-with-low-contrast-text.html: Added.
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247792 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-07-24 Tim Horton <[email protected]>
+
+ Daring Fireball long press highlights are unnecessarily inflated due to false illegibility
+ https://bugs.webkit.org/show_bug.cgi?id=200064
+
+ Reviewed by Geoff Garen.
+
+ * fast/text-indicator/text-indicator-with-low-contrast-text-expected.txt: Added.
+ * fast/text-indicator/text-indicator-with-low-contrast-text.html: Added.
+
+2019-08-06 Kocsen Chung <[email protected]>
+
Cherry-pick r247730. rdar://problem/54017873
Long press hint of AirPods buy buttons are tall and narrow during animation
Added: branches/safari-608.1-branch/LayoutTests/fast/text-indicator/text-indicator-with-low-contrast-text-expected.txt (0 => 248347)
--- branches/safari-608.1-branch/LayoutTests/fast/text-indicator/text-indicator-with-low-contrast-text-expected.txt (rev 0)
+++ branches/safari-608.1-branch/LayoutTests/fast/text-indicator/text-indicator-with-low-contrast-text-expected.txt 2019-08-07 06:52:25 UTC (rev 248347)
@@ -0,0 +1,40 @@
+whiteTextWhiteBackground: NOT legible
+ 0 0 68 66
+whiteTextGrayBackground: NOT legible
+ 0 0 68 66
+whiteTextBlackBackground: legible
+ 0 0 68 18
+ 0 48 36 18
+grayTextWhiteBackground: NOT legible
+ 0 0 68 66
+grayTextGrayBackground: NOT legible
+ 0 0 68 66
+grayTextBlackBackground: legible
+ 0 0 68 18
+ 0 48 36 18
+lightGrayTextWhiteBackground: NOT legible
+ 0 0 68 66
+lightGrayTextGrayBackground: NOT legible
+ 0 0 68 66
+lightGrayTextBlackBackground: legible
+ 0 0 68 18
+ 0 48 36 18
+darkGrayTextWhiteBackground: legible
+ 0 0 68 18
+ 0 48 36 18
+darkGrayTextGrayBackground: NOT legible
+ 0 0 68 66
+darkGrayTextBlackBackground: NOT legible
+ 0 0 68 66
+blackTextWhiteBackground: legible
+ 0 0 68 18
+ 0 48 36 18
+blackTextGrayBackground: legible
+ 0 0 68 18
+ 0 48 36 18
+blackTextBlackBackground: NOT legible
+ 0 0 68 66
+dfTextDfBackground: legible
+ 0 0 68 18
+ 0 48 36 18
+
Added: branches/safari-608.1-branch/LayoutTests/fast/text-indicator/text-indicator-with-low-contrast-text.html (0 => 248347)
--- branches/safari-608.1-branch/LayoutTests/fast/text-indicator/text-indicator-with-low-contrast-text.html (rev 0)
+++ branches/safari-608.1-branch/LayoutTests/fast/text-indicator/text-indicator-with-low-contrast-text.html 2019-08-07 06:52:25 UTC (rev 248347)
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+* { box-sizing: border-box; font-family: ahem; }
+body { margin: 0; }
+div { position: absolute; top: 0; left: 0; }
+
+.whiteText { color: white; }
+.grayText { color: gray; }
+.lightGrayText { color: lightgray; }
+.darkGrayText { color: dimgray; }
+.blackText { color: black; }
+.dfGrayText { color: #ddd; }
+
+.whiteBackground { background-color: white; }
+.grayBackground { background-color: gray; }
+.blackBackground { background-color: black; }
+.dfGrayBackground { background-color: #4a525a; }
+</style>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+function output(s)
+{
+ window.log.innerText += s + "\n";
+}
+
+function runTest()
+{
+ if (!window.internals) {
+ output("This test cannot be run outside of WebKitTestRunner.");
+ return;
+ }
+
+ function dumpIndicatorBoundsForElement(el)
+ {
+ var indicatorOptions = {
+ "useBoundingRectAndPaintAllContentForComplexRanges": true,
+ "computeEstimatedBackgroundColor": true,
+ "respectTextColor": true,
+ };
+ var range = internals.rangeFromLocationAndLength(el, 0, 9);
+ var indicator = window.internals.textIndicatorForRange(range, indicatorOptions);
+ var rects = indicator.textRectsInBoundingRectCoordinates;
+
+ output(`${el.id}: ` + (rects.length == 1 ? "NOT legible" : "legible"));
+ for (var rect of rects)
+ output(` ${rect.x} ${rect.y} ${rect.width} ${rect.height}`);
+ }
+
+ dumpIndicatorBoundsForElement(document.getElementById("whiteTextWhiteBackground"));
+ dumpIndicatorBoundsForElement(document.getElementById("whiteTextGrayBackground"));
+ dumpIndicatorBoundsForElement(document.getElementById("whiteTextBlackBackground"));
+
+ dumpIndicatorBoundsForElement(document.getElementById("grayTextWhiteBackground"));
+ dumpIndicatorBoundsForElement(document.getElementById("grayTextGrayBackground"));
+ dumpIndicatorBoundsForElement(document.getElementById("grayTextBlackBackground"));
+
+ dumpIndicatorBoundsForElement(document.getElementById("lightGrayTextWhiteBackground"));
+ dumpIndicatorBoundsForElement(document.getElementById("lightGrayTextGrayBackground"));
+ dumpIndicatorBoundsForElement(document.getElementById("lightGrayTextBlackBackground"));
+
+ dumpIndicatorBoundsForElement(document.getElementById("darkGrayTextWhiteBackground"));
+ dumpIndicatorBoundsForElement(document.getElementById("darkGrayTextGrayBackground"));
+ dumpIndicatorBoundsForElement(document.getElementById("darkGrayTextBlackBackground"));
+
+ dumpIndicatorBoundsForElement(document.getElementById("blackTextWhiteBackground"));
+ dumpIndicatorBoundsForElement(document.getElementById("blackTextGrayBackground"));
+ dumpIndicatorBoundsForElement(document.getElementById("blackTextBlackBackground"));
+
+ dumpIndicatorBoundsForElement(document.getElementById("dfTextDfBackground"));
+
+ // Remove the test cases so they don't show up in the dump.
+ document.getElementById("testCases").innerText = "";
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<div id="testCases">
+ <div class="whiteText whiteBackground" id="whiteTextWhiteBackground">test<br><br><br>test</div>
+ <div class="whiteText grayBackground" id="whiteTextGrayBackground">test<br><br><br>test</div>
+ <div class="whiteText blackBackground" id="whiteTextBlackBackground">test<br><br><br>test</div>
+
+ <div class="grayText whiteBackground" id="grayTextWhiteBackground">test<br><br><br>test</div>
+ <div class="grayText grayBackground" id="grayTextGrayBackground">test<br><br><br>test</div>
+ <div class="grayText blackBackground" id="grayTextBlackBackground">test<br><br><br>test</div>
+
+ <div class="lightGrayText whiteBackground" id="lightGrayTextWhiteBackground">test<br><br><br>test</div>
+ <div class="lightGrayText grayBackground" id="lightGrayTextGrayBackground">test<br><br><br>test</div>
+ <div class="lightGrayText blackBackground" id="lightGrayTextBlackBackground">test<br><br><br>test</div>
+
+ <div class="darkGrayText whiteBackground" id="darkGrayTextWhiteBackground">test<br><br><br>test</div>
+ <div class="darkGrayText grayBackground" id="darkGrayTextGrayBackground">test<br><br><br>test</div>
+ <div class="darkGrayText blackBackground" id="darkGrayTextBlackBackground">test<br><br><br>test</div>
+
+ <div class="blackText whiteBackground" id="blackTextWhiteBackground">test<br><br><br>test</div>
+ <div class="blackText grayBackground" id="blackTextGrayBackground">test<br><br><br>test</div>
+ <div class="blackText blackBackground" id="blackTextBlackBackground">test<br><br><br>test</div>
+
+ <div class="dfGrayText dfGrayBackground" id="dfTextDfBackground">test<br><br><br>test</div>
+</div>
+<pre id="log"></pre>
+</body>
+</html>
\ No newline at end of file
Modified: branches/safari-608.1-branch/Source/WebCore/ChangeLog (248346 => 248347)
--- branches/safari-608.1-branch/Source/WebCore/ChangeLog 2019-08-07 06:52:22 UTC (rev 248346)
+++ branches/safari-608.1-branch/Source/WebCore/ChangeLog 2019-08-07 06:52:25 UTC (rev 248347)
@@ -1,5 +1,99 @@
2019-08-06 Kocsen Chung <[email protected]>
+ Cherry-pick r247792. rdar://problem/54017900
+
+ Daring Fireball long press highlights are unnecessarily inflated due to false illegibility
+ https://bugs.webkit.org/show_bug.cgi?id=200064
+
+ Reviewed by Geoff Garen.
+
+ Source/WebCore:
+
+ If we consider text illegible on the given estimated background color,
+ we bail from doing a tightly fitted selection-only TextIndicator and
+ instead just paint the page without modification into the indicator,
+ causing ugly overlap and an excessively inflated indicator.
+
+ Change the mechanism we use to determine illegibility to be based on
+ a standard, instead of a constant chosen by hand 13 years ago.
+
+ Test: fast/text-indicator/text-indicator-with-low-contrast-text.html
+
+ * platform/graphics/ColorUtilities.cpp:
+ (WebCore::luminance):
+ Fix a typo.
+
+ (WebCore::contrastRatio):
+ Add a function that computes the contrast ratio given two colors using
+ the formula from WCAG.
+
+ * platform/graphics/ColorUtilities.h:
+ * rendering/TextPaintStyle.cpp:
+ (WebCore::textColorIsLegibleAgainstBackgroundColor):
+ Make use of WCAG's minimum legible contrast ratio instead of an
+ arbitrary color difference cutoff for determining whether we consider
+ text legible. It seems sensible and also considers the text on DF readable
+ (which it seems to be to me!).
+
+ * testing/Internals.cpp:
+ (WebCore::Internals::TextIndicatorInfo::TextIndicatorInfo):
+ * testing/Internals.h:
+ * testing/Internals.idl:
+ Expose all of the text rects to Internals, not just the bounding rect.
+ Expose some more TextIndicator options to Internals so that we can
+ turn on the legibility mechanism.
+
+ LayoutTests:
+
+ * fast/text-indicator/text-indicator-with-low-contrast-text-expected.txt: Added.
+ * fast/text-indicator/text-indicator-with-low-contrast-text.html: Added.
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247792 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-07-24 Tim Horton <[email protected]>
+
+ Daring Fireball long press highlights are unnecessarily inflated due to false illegibility
+ https://bugs.webkit.org/show_bug.cgi?id=200064
+
+ Reviewed by Geoff Garen.
+
+ If we consider text illegible on the given estimated background color,
+ we bail from doing a tightly fitted selection-only TextIndicator and
+ instead just paint the page without modification into the indicator,
+ causing ugly overlap and an excessively inflated indicator.
+
+ Change the mechanism we use to determine illegibility to be based on
+ a standard, instead of a constant chosen by hand 13 years ago.
+
+ Test: fast/text-indicator/text-indicator-with-low-contrast-text.html
+
+ * platform/graphics/ColorUtilities.cpp:
+ (WebCore::luminance):
+ Fix a typo.
+
+ (WebCore::contrastRatio):
+ Add a function that computes the contrast ratio given two colors using
+ the formula from WCAG.
+
+ * platform/graphics/ColorUtilities.h:
+ * rendering/TextPaintStyle.cpp:
+ (WebCore::textColorIsLegibleAgainstBackgroundColor):
+ Make use of WCAG's minimum legible contrast ratio instead of an
+ arbitrary color difference cutoff for determining whether we consider
+ text legible. It seems sensible and also considers the text on DF readable
+ (which it seems to be to me!).
+
+ * testing/Internals.cpp:
+ (WebCore::Internals::TextIndicatorInfo::TextIndicatorInfo):
+ * testing/Internals.h:
+ * testing/Internals.idl:
+ Expose all of the text rects to Internals, not just the bounding rect.
+ Expose some more TextIndicator options to Internals so that we can
+ turn on the legibility mechanism.
+
+2019-08-06 Kocsen Chung <[email protected]>
+
Cherry-pick r247756. rdar://problem/54017897
Long press hint has half blue shape in Feedly.com
Modified: branches/safari-608.1-branch/Source/WebCore/platform/graphics/ColorUtilities.cpp (248346 => 248347)
--- branches/safari-608.1-branch/Source/WebCore/platform/graphics/ColorUtilities.cpp 2019-08-07 06:52:22 UTC (rev 248346)
+++ branches/safari-608.1-branch/Source/WebCore/platform/graphics/ColorUtilities.cpp 2019-08-07 06:52:25 UTC (rev 248347)
@@ -104,14 +104,27 @@
return clampTo<float>(std::pow((c + 0.055f) / 1.055f, 2.4f), 0, 1);
}
-float luminance(const FloatComponents& sRGBCompontents)
+float luminance(const FloatComponents& sRGBComponents)
{
// Values from https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
- return 0.2126f * sRGBToLinearColorComponentForLuminance(sRGBCompontents.components[0])
- + 0.7152f * sRGBToLinearColorComponentForLuminance(sRGBCompontents.components[1])
- + 0.0722f * sRGBToLinearColorComponentForLuminance(sRGBCompontents.components[2]);
+ return 0.2126f * sRGBToLinearColorComponentForLuminance(sRGBComponents.components[0])
+ + 0.7152f * sRGBToLinearColorComponentForLuminance(sRGBComponents.components[1])
+ + 0.0722f * sRGBToLinearColorComponentForLuminance(sRGBComponents.components[2]);
}
+float contrastRatio(const FloatComponents& componentsA, const FloatComponents& componentsB)
+{
+ // Uses the WCAG 2.0 definition of contrast ratio.
+ // https://www.w3.org/TR/WCAG20/#contrast-ratiodef
+ float lighterLuminance = luminance(componentsA);
+ float darkerLuminance = luminance(componentsB);
+
+ if (lighterLuminance < darkerLuminance)
+ std::swap(lighterLuminance, darkerLuminance);
+
+ return (lighterLuminance + 0.05) / (darkerLuminance + 0.05);
+}
+
FloatComponents sRGBToHSL(const FloatComponents& sRGBColor)
{
// http://en.wikipedia.org/wiki/HSL_color_space.
Modified: branches/safari-608.1-branch/Source/WebCore/platform/graphics/ColorUtilities.h (248346 => 248347)
--- branches/safari-608.1-branch/Source/WebCore/platform/graphics/ColorUtilities.h 2019-08-07 06:52:22 UTC (rev 248346)
+++ branches/safari-608.1-branch/Source/WebCore/platform/graphics/ColorUtilities.h 2019-08-07 06:52:25 UTC (rev 248347)
@@ -162,6 +162,7 @@
FloatComponents HSLToSRGB(const FloatComponents&);
float luminance(const FloatComponents& sRGBCompontents);
+float contrastRatio(const FloatComponents&, const FloatComponents&);
class ColorMatrix {
public:
Modified: branches/safari-608.1-branch/Source/WebCore/rendering/TextPaintStyle.cpp (248346 => 248347)
--- branches/safari-608.1-branch/Source/WebCore/rendering/TextPaintStyle.cpp 2019-08-07 06:52:22 UTC (rev 248346)
+++ branches/safari-608.1-branch/Source/WebCore/rendering/TextPaintStyle.cpp 2019-08-07 06:52:25 UTC (rev 248347)
@@ -26,6 +26,7 @@
#include "config.h"
#include "TextPaintStyle.h"
+#include "ColorUtilities.h"
#include "FocusController.h"
#include "Frame.h"
#include "GraphicsContext.h"
@@ -60,8 +61,9 @@
bool textColorIsLegibleAgainstBackgroundColor(const Color& textColor, const Color& backgroundColor)
{
- // Semi-arbitrarily chose 65025 (255^2) value here after a few tests.
- return differenceSquared(textColor, backgroundColor) > 65025;
+ // Uses the WCAG 2.0 definition of legibility: a contrast ratio of 4.5:1 or greater.
+ // https://www.w3.org/TR/WCAG20/#visual-audio-contrast-contrast
+ return contrastRatio(textColor, backgroundColor) > 4.5;
}
static Color adjustColorForVisibilityOnBackground(const Color& textColor, const Color& backgroundColor)
Modified: branches/safari-608.1-branch/Source/WebCore/testing/Internals.cpp (248346 => 248347)
--- branches/safari-608.1-branch/Source/WebCore/testing/Internals.cpp 2019-08-07 06:52:22 UTC (rev 248346)
+++ branches/safari-608.1-branch/Source/WebCore/testing/Internals.cpp 2019-08-07 06:52:25 UTC (rev 248347)
@@ -5109,6 +5109,7 @@
Internals::TextIndicatorInfo::TextIndicatorInfo(const WebCore::TextIndicatorData& data)
: textBoundingRectInRootViewCoordinates(DOMRect::create(data.textBoundingRectInRootViewCoordinates))
+ , textRectsInBoundingRectCoordinates(DOMRectList::create(data.textRectsInBoundingRectCoordinates))
{
}
Modified: branches/safari-608.1-branch/Source/WebCore/testing/Internals.h (248346 => 248347)
--- branches/safari-608.1-branch/Source/WebCore/testing/Internals.h 2019-08-07 06:52:22 UTC (rev 248346)
+++ branches/safari-608.1-branch/Source/WebCore/testing/Internals.h 2019-08-07 06:52:25 UTC (rev 248347)
@@ -835,6 +835,7 @@
struct TextIndicatorInfo {
RefPtr<DOMRectReadOnly> textBoundingRectInRootViewCoordinates;
+ RefPtr<DOMRectList> textRectsInBoundingRectCoordinates;
TextIndicatorInfo();
TextIndicatorInfo(const WebCore::TextIndicatorData&);
@@ -843,6 +844,8 @@
struct TextIndicatorOptions {
bool useBoundingRectAndPaintAllContentForComplexRanges { false };
+ bool computeEstimatedBackgroundColor { false };
+ bool respectTextColor { false };
WebCore::TextIndicatorOptions core()
{
@@ -849,6 +852,10 @@
WebCore::TextIndicatorOptions options = 0;
if (useBoundingRectAndPaintAllContentForComplexRanges)
options = options | TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges;
+ if (computeEstimatedBackgroundColor)
+ options = options | TextIndicatorOptionComputeEstimatedBackgroundColor;
+ if (respectTextColor)
+ options = options | TextIndicatorOptionRespectTextColor;
return options;
}
};
Modified: branches/safari-608.1-branch/Source/WebCore/testing/Internals.idl (248346 => 248347)
--- branches/safari-608.1-branch/Source/WebCore/testing/Internals.idl 2019-08-07 06:52:22 UTC (rev 248346)
+++ branches/safari-608.1-branch/Source/WebCore/testing/Internals.idl 2019-08-07 06:52:25 UTC (rev 248347)
@@ -164,6 +164,7 @@
JSGenerateToJSObject,
] dictionary TextIndicatorInfo {
DOMRectReadOnly textBoundingRectInRootViewCoordinates;
+ DOMRectList textRectsInBoundingRectCoordinates;
};
[
@@ -171,6 +172,8 @@
JSGenerateToJSObject,
] dictionary TextIndicatorOptions {
boolean useBoundingRectAndPaintAllContentForComplexRanges = false;
+ boolean computeEstimatedBackgroundColor = false;
+ boolean respectTextColor = false;
};
[