Bug 15999 - Use differenceSquared() to detect similar fg/bg text selection colours
Summary: Use differenceSquared() to detect similar fg/bg text selection colours
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Text (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Minor
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-15 03:34 PST by Alp Toker
Modified: 2023-09-16 15:18 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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?