Changeset 247792 in webkit
- Timestamp:
- Jul 24, 2019, 3:36:13 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/text-indicator/text-indicator-with-low-contrast-text-expected.txt (added)
-
LayoutTests/fast/text-indicator/text-indicator-with-low-contrast-text.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/platform/graphics/ColorUtilities.cpp (modified) (1 diff)
-
Source/WebCore/platform/graphics/ColorUtilities.h (modified) (1 diff)
-
Source/WebCore/rendering/TextPaintStyle.cpp (modified) (2 diffs)
-
Source/WebCore/testing/Internals.cpp (modified) (1 diff)
-
Source/WebCore/testing/Internals.h (modified) (3 diffs)
-
Source/WebCore/testing/Internals.idl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r247790 r247792 1 2019-07-24 Tim Horton <timothy_horton@apple.com> 2 3 Daring Fireball long press highlights are unnecessarily inflated due to false illegibility 4 https://bugs.webkit.org/show_bug.cgi?id=200064 5 6 Reviewed by Geoff Garen. 7 8 * fast/text-indicator/text-indicator-with-low-contrast-text-expected.txt: Added. 9 * fast/text-indicator/text-indicator-with-low-contrast-text.html: Added. 10 1 11 2019-07-24 Devin Rousso <drousso@apple.com> 2 12 -
trunk/Source/WebCore/ChangeLog
r247790 r247792 1 2019-07-24 Tim Horton <timothy_horton@apple.com> 2 3 Daring Fireball long press highlights are unnecessarily inflated due to false illegibility 4 https://bugs.webkit.org/show_bug.cgi?id=200064 5 6 Reviewed by Geoff Garen. 7 8 If we consider text illegible on the given estimated background color, 9 we bail from doing a tightly fitted selection-only TextIndicator and 10 instead just paint the page without modification into the indicator, 11 causing ugly overlap and an excessively inflated indicator. 12 13 Change the mechanism we use to determine illegibility to be based on 14 a standard, instead of a constant chosen by hand 13 years ago. 15 16 Test: fast/text-indicator/text-indicator-with-low-contrast-text.html 17 18 * platform/graphics/ColorUtilities.cpp: 19 (WebCore::luminance): 20 Fix a typo. 21 22 (WebCore::contrastRatio): 23 Add a function that computes the contrast ratio given two colors using 24 the formula from WCAG. 25 26 * platform/graphics/ColorUtilities.h: 27 * rendering/TextPaintStyle.cpp: 28 (WebCore::textColorIsLegibleAgainstBackgroundColor): 29 Make use of WCAG's minimum legible contrast ratio instead of an 30 arbitrary color difference cutoff for determining whether we consider 31 text legible. It seems sensible and also considers the text on DF readable 32 (which it seems to be to me!). 33 34 * testing/Internals.cpp: 35 (WebCore::Internals::TextIndicatorInfo::TextIndicatorInfo): 36 * testing/Internals.h: 37 * testing/Internals.idl: 38 Expose all of the text rects to Internals, not just the bounding rect. 39 Expose some more TextIndicator options to Internals so that we can 40 turn on the legibility mechanism. 41 1 42 2019-07-24 Devin Rousso <drousso@apple.com> 2 43 -
trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp
r233877 r247792 105 105 } 106 106 107 float luminance(const FloatComponents& sRGBCompon tents)107 float luminance(const FloatComponents& sRGBComponents) 108 108 { 109 109 // Values from https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef 110 return 0.2126f * sRGBToLinearColorComponentForLuminance(sRGBCompontents.components[0]) 111 + 0.7152f * sRGBToLinearColorComponentForLuminance(sRGBCompontents.components[1]) 112 + 0.0722f * sRGBToLinearColorComponentForLuminance(sRGBCompontents.components[2]); 110 return 0.2126f * sRGBToLinearColorComponentForLuminance(sRGBComponents.components[0]) 111 + 0.7152f * sRGBToLinearColorComponentForLuminance(sRGBComponents.components[1]) 112 + 0.0722f * sRGBToLinearColorComponentForLuminance(sRGBComponents.components[2]); 113 } 114 115 float contrastRatio(const FloatComponents& componentsA, const FloatComponents& componentsB) 116 { 117 // Uses the WCAG 2.0 definition of contrast ratio. 118 // https://www.w3.org/TR/WCAG20/#contrast-ratiodef 119 float lighterLuminance = luminance(componentsA); 120 float darkerLuminance = luminance(componentsB); 121 122 if (lighterLuminance < darkerLuminance) 123 std::swap(lighterLuminance, darkerLuminance); 124 125 return (lighterLuminance + 0.05) / (darkerLuminance + 0.05); 113 126 } 114 127 -
trunk/Source/WebCore/platform/graphics/ColorUtilities.h
r233877 r247792 163 163 164 164 float luminance(const FloatComponents& sRGBCompontents); 165 float contrastRatio(const FloatComponents&, const FloatComponents&); 165 166 166 167 class ColorMatrix { -
trunk/Source/WebCore/rendering/TextPaintStyle.cpp
r245752 r247792 27 27 #include "TextPaintStyle.h" 28 28 29 #include "ColorUtilities.h" 29 30 #include "FocusController.h" 30 31 #include "Frame.h" … … 61 62 bool textColorIsLegibleAgainstBackgroundColor(const Color& textColor, const Color& backgroundColor) 62 63 { 63 // Semi-arbitrarily chose 65025 (255^2) value here after a few tests. 64 return differenceSquared(textColor, backgroundColor) > 65025; 64 // Uses the WCAG 2.0 definition of legibility: a contrast ratio of 4.5:1 or greater. 65 // https://www.w3.org/TR/WCAG20/#visual-audio-contrast-contrast 66 return contrastRatio(textColor, backgroundColor) > 4.5; 65 67 } 66 68 -
trunk/Source/WebCore/testing/Internals.cpp
r247698 r247792 5126 5126 Internals::TextIndicatorInfo::TextIndicatorInfo(const WebCore::TextIndicatorData& data) 5127 5127 : textBoundingRectInRootViewCoordinates(DOMRect::create(data.textBoundingRectInRootViewCoordinates)) 5128 , textRectsInBoundingRectCoordinates(DOMRectList::create(data.textRectsInBoundingRectCoordinates)) 5128 5129 { 5129 5130 } -
trunk/Source/WebCore/testing/Internals.h
r247698 r247792 838 838 struct TextIndicatorInfo { 839 839 RefPtr<DOMRectReadOnly> textBoundingRectInRootViewCoordinates; 840 RefPtr<DOMRectList> textRectsInBoundingRectCoordinates; 840 841 841 842 TextIndicatorInfo(); … … 846 847 struct TextIndicatorOptions { 847 848 bool useBoundingRectAndPaintAllContentForComplexRanges { false }; 849 bool computeEstimatedBackgroundColor { false }; 850 bool respectTextColor { false }; 848 851 849 852 WebCore::TextIndicatorOptions core() … … 852 855 if (useBoundingRectAndPaintAllContentForComplexRanges) 853 856 options = options | TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges; 857 if (computeEstimatedBackgroundColor) 858 options = options | TextIndicatorOptionComputeEstimatedBackgroundColor; 859 if (respectTextColor) 860 options = options | TextIndicatorOptionRespectTextColor; 854 861 return options; 855 862 } -
trunk/Source/WebCore/testing/Internals.idl
r247698 r247792 165 165 ] dictionary TextIndicatorInfo { 166 166 DOMRectReadOnly textBoundingRectInRootViewCoordinates; 167 DOMRectList textRectsInBoundingRectCoordinates; 167 168 }; 168 169 … … 172 173 ] dictionary TextIndicatorOptions { 173 174 boolean useBoundingRectAndPaintAllContentForComplexRanges = false; 175 boolean computeEstimatedBackgroundColor = false; 176 boolean respectTextColor = false; 174 177 }; 175 178
Note:
See TracChangeset
for help on using the changeset viewer.