⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 247792 in webkit


Ignore:
Timestamp:
Jul 24, 2019, 3:36:13 PM (7 years ago)
Author:
timothy_horton@apple.com
Message:

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.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r247790 r247792  
     12019-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
    1112019-07-24  Devin Rousso  <drousso@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r247790 r247792  
     12019-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
    1422019-07-24  Devin Rousso  <drousso@apple.com>
    243
  • trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp

    r233877 r247792  
    105105}
    106106
    107 float luminance(const FloatComponents& sRGBCompontents)
     107float luminance(const FloatComponents& sRGBComponents)
    108108{
    109109    // 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
     115float 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);
    113126}
    114127
  • trunk/Source/WebCore/platform/graphics/ColorUtilities.h

    r233877 r247792  
    163163
    164164float luminance(const FloatComponents& sRGBCompontents);
     165float contrastRatio(const FloatComponents&, const FloatComponents&);
    165166
    166167class ColorMatrix {
  • trunk/Source/WebCore/rendering/TextPaintStyle.cpp

    r245752 r247792  
    2727#include "TextPaintStyle.h"
    2828
     29#include "ColorUtilities.h"
    2930#include "FocusController.h"
    3031#include "Frame.h"
     
    6162bool textColorIsLegibleAgainstBackgroundColor(const Color& textColor, const Color& backgroundColor)
    6263{
    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;
    6567}
    6668
  • trunk/Source/WebCore/testing/Internals.cpp

    r247698 r247792  
    51265126Internals::TextIndicatorInfo::TextIndicatorInfo(const WebCore::TextIndicatorData& data)
    51275127    : textBoundingRectInRootViewCoordinates(DOMRect::create(data.textBoundingRectInRootViewCoordinates))
     5128    , textRectsInBoundingRectCoordinates(DOMRectList::create(data.textRectsInBoundingRectCoordinates))
    51285129{
    51295130}
  • trunk/Source/WebCore/testing/Internals.h

    r247698 r247792  
    838838    struct TextIndicatorInfo {
    839839        RefPtr<DOMRectReadOnly> textBoundingRectInRootViewCoordinates;
     840        RefPtr<DOMRectList> textRectsInBoundingRectCoordinates;
    840841       
    841842        TextIndicatorInfo();
     
    846847    struct TextIndicatorOptions {
    847848        bool useBoundingRectAndPaintAllContentForComplexRanges { false };
     849        bool computeEstimatedBackgroundColor { false };
     850        bool respectTextColor { false };
    848851       
    849852        WebCore::TextIndicatorOptions core()
     
    852855            if (useBoundingRectAndPaintAllContentForComplexRanges)
    853856                options = options | TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges;
     857            if (computeEstimatedBackgroundColor)
     858                options = options | TextIndicatorOptionComputeEstimatedBackgroundColor;
     859            if (respectTextColor)
     860                options = options | TextIndicatorOptionRespectTextColor;
    854861            return options;
    855862        }
  • trunk/Source/WebCore/testing/Internals.idl

    r247698 r247792  
    165165] dictionary TextIndicatorInfo {
    166166    DOMRectReadOnly textBoundingRectInRootViewCoordinates;
     167    DOMRectList textRectsInBoundingRectCoordinates;
    167168};
    168169
     
    172173] dictionary TextIndicatorOptions {
    173174    boolean useBoundingRectAndPaintAllContentForComplexRanges = false;
     175    boolean computeEstimatedBackgroundColor = false;
     176    boolean respectTextColor = false;
    174177};
    175178
Note: See TracChangeset for help on using the changeset viewer.