Bug 15999

Summary: Use differenceSquared() to detect similar fg/bg text selection colours
Product: WebKit Reporter: Alp Toker <alp>
Component: TextAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Minor CC: ahmad.saleem792, mcatanzaro, mmaxfield
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   

Description Alp Toker 2007-11-15 03:34:07 PST
It would be nice to use correctedTextColor() or a similar differenceSquared() algorithm to identify and avoid situations where the text selection foreground colour is similar to the selection background colour.

This situation is more likely to arise in the GTK+ port when users are using a high contrast/inverted video accessibility colour scheme. It is also more likely to arise if text selection opacity is disabled in a port for whatever reason, say due to limited graphics capabilities.

This feature could be implemented in InlineTextBox and SVGInlineTextBox, or possibly directly in RenderObject. (It seems right now there's code that could be shared between InlineTextBox and SVGInlineTextBox to avoid implementing this in two places.)

correctedTextColor() is already used in InlineTextBox to ensure that text is legible when printed, so the necessary clever bits have already been written.


There is actually already simple support for inverting the text selection background colour:

    Color textColor = style->color();
    Color c = object()->selectionBackgroundColor();
    if (!c.isValid() || c.alpha() == 0)
        return;

    if (textColor == c)
        c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());


I'm a bit suspicious that this code is not doing the right thing.

I wonder also if it should be:

    -Color textColor = style->color();
    +Color textColor = object()->selectionForegroundColor();

Is there a text selection/text legibility test suite? I'm not too familiar with the tests yet.
Comment 1 Ahmad Saleem 2023-09-16 15:18:42 PDT
Is this applicable in today's GTK port or in general to WebKit?