Skip to content

Commit

Permalink
Selection and search forced colors
Browse files Browse the repository at this point in the history
This change updates the selection and search text/background colors
in forced colors mode to HighlightText and Highlight.

Bug: 970285
Change-Id: I170fdce8be02e31c26273e4eab5390427e672065
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1735471
Reviewed-by: Stephen Chenney <schenney@chromium.org>
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Reviewed-by: Kevin Babbitt <kbabbitt@microsoft.com>
Commit-Queue: Alison Maher <almaher@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#687276}
  • Loading branch information
alisonmaher authored and Commit Bot committed Aug 15, 2019
1 parent a67cadf commit 12bb018
Show file tree
Hide file tree
Showing 21 changed files with 259 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2303,8 +2303,7 @@ void StyleResolver::Trace(blink::Visitor* visitor) {
}

bool StyleResolver::IsForcedColorsModeEnabled() const {
return RuntimeEnabledFeatures::ForcedColorsEnabled() &&
GetDocument().GetSettings()->GetForcedColors() != ForcedColors::kNone;
return GetDocument().InForcedColorsMode();
}

} // namespace blink
5 changes: 5 additions & 0 deletions third_party/blink/renderer/core/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8407,6 +8407,11 @@ void Document::ColorSchemeChanged() {
MediaQueryAffectingValueChanged();
}

bool Document::InForcedColorsMode() const {
return RuntimeEnabledFeatures::ForcedColorsEnabled() &&
GetSettings()->GetForcedColors() != ForcedColors::kNone;
}

void Document::CountUse(mojom::WebFeature feature) const {
if (DocumentLoader* loader = Loader()) {
loader->CountUse(feature);
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/renderer/core/dom/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,8 @@ class CORE_EXPORT Document : public ContainerNode,
// applied to this document.
void BindContentSecurityPolicy();

bool InForcedColorsMode() const;

// Capture the toggle event during parsing either by HTML parser or XML
// parser.
void SetToggleDuringParsing(bool toggle_during_parsing) {
Expand Down
14 changes: 11 additions & 3 deletions third_party/blink/renderer/core/layout/layout_theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -791,13 +791,21 @@ Color LayoutTheme::SystemColor(CSSValueID css_value_id) const {
return Color();
}

Color LayoutTheme::PlatformTextSearchHighlightColor(bool active_match) const {
if (active_match)
Color LayoutTheme::PlatformTextSearchHighlightColor(
bool active_match,
bool in_forced_colors_mode) const {
if (active_match) {
if (in_forced_colors_mode)
return GetTheme().SystemColor(CSSValueID::kHighlight);
return Color(255, 150, 50); // Orange.
}
return Color(255, 255, 0); // Yellow.
}

Color LayoutTheme::PlatformTextSearchColor(bool active_match) const {
Color LayoutTheme::PlatformTextSearchColor(bool active_match,
bool in_forced_colors_mode) const {
if (in_forced_colors_mode && active_match)
return GetTheme().SystemColor(CSSValueID::kHighlighttext);
return Color::kBlack;
}

Expand Down
6 changes: 4 additions & 2 deletions third_party/blink/renderer/core/layout/layout_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ class CORE_EXPORT LayoutTheme : public RefCounted<LayoutTheme> {
Color PlatformActiveSpellingMarkerHighlightColor() const;

// Highlight and text colors for TextMatches.
Color PlatformTextSearchHighlightColor(bool active_match) const;
Color PlatformTextSearchColor(bool active_match) const;
Color PlatformTextSearchHighlightColor(bool active_match,
bool in_forced_colors_mode) const;
Color PlatformTextSearchColor(bool active_match,
bool in_forced_colors_mode) const;

virtual bool IsFocusRingOutset() const;
Color FocusRingColor() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ void DocumentMarkerPainter::PaintDocumentMarker(

TextPaintStyle DocumentMarkerPainter::ComputeTextPaintStyleFrom(
const ComputedStyle& style,
const TextMatchMarker& marker) {
const Color text_color =
LayoutTheme::GetTheme().PlatformTextSearchColor(marker.IsActiveMatch());
const TextMatchMarker& marker,
bool in_forced_colors_mode) {
const Color text_color = LayoutTheme::GetTheme().PlatformTextSearchColor(
marker.IsActiveMatch(), in_forced_colors_mode);
if (style.VisitedDependentColor(GetCSSPropertyColor()) == text_color)
return {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class DocumentMarkerPainter {
const ComputedStyle& style,
DocumentMarker::MarkerType marker_type,
const PhysicalRect& local_rect);
static TextPaintStyle ComputeTextPaintStyleFrom(
const ComputedStyle& style,
const TextMatchMarker& marker);
static TextPaintStyle ComputeTextPaintStyleFrom(const ComputedStyle& style,
const TextMatchMarker& marker,
bool in_forced_colors_mode);
};

} // namespace blink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,11 @@ void InlineTextBoxPainter::PaintTextMatchMarkerForeground(
return;

const TextPaintStyle text_style =
DocumentMarkerPainter::ComputeTextPaintStyleFrom(style, marker);
DocumentMarkerPainter::ComputeTextPaintStyleFrom(
style, marker,
inline_text_box_.GetLineLayoutItem()
.GetDocument()
.InForcedColorsMode());
if (text_style.current_color == Color::kTransparent)
return;

Expand Down Expand Up @@ -879,7 +883,8 @@ void InlineTextBoxPainter::PaintTextMatchMarkerBackground(
TextRun run = inline_text_box_.ConstructTextRun(style);

Color color = LayoutTheme::GetTheme().PlatformTextSearchHighlightColor(
marker.IsActiveMatch());
marker.IsActiveMatch(),
inline_text_box_.GetLineLayoutItem().GetDocument().InForcedColorsMode());
GraphicsContext& context = paint_info.context;
GraphicsContextStateSaver state_saver(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ void PaintDocumentMarkers(GraphicsContext& context,
if (marker_paint_phase == DocumentMarkerPaintPhase::kBackground) {
const Color color =
LayoutTheme::GetTheme().PlatformTextSearchHighlightColor(
text_match_marker.IsActiveMatch());
text_match_marker.IsActiveMatch(),
text_fragment.GetNode()->GetDocument().InForcedColorsMode());
PaintRect(
context, PhysicalOffset(box_origin),
text_fragment.LocalRect(paint_start_offset, paint_end_offset),
Expand All @@ -186,8 +187,9 @@ void PaintDocumentMarkers(GraphicsContext& context,
}

const TextPaintStyle text_style =
DocumentMarkerPainter::ComputeTextPaintStyleFrom(style,
text_match_marker);
DocumentMarkerPainter::ComputeTextPaintStyleFrom(
style, text_match_marker,
text_fragment.GetNode()->GetDocument().InForcedColorsMode());
if (text_style.current_color == Color::kTransparent)
break;
text_painter->Paint(paint_start_offset, paint_end_offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@ Color SelectionColor(const Document& document,
return style.VisitedDependentColor(color_property);

if (scoped_refptr<ComputedStyle> pseudo_style =
GetUncachedSelectionStyle(node))
GetUncachedSelectionStyle(node)) {
if (document.InForcedColorsMode() &&
pseudo_style->ForcedColorAdjust() != EForcedColorAdjust::kNone)
return LayoutTheme::GetTheme().SystemColor(CSSValueID::kHighlighttext);
return pseudo_style->VisitedDependentColor(color_property);
}

if (document.InForcedColorsMode())
return LayoutTheme::GetTheme().SystemColor(CSSValueID::kHighlighttext);

if (!LayoutTheme::GetTheme().SupportsSelectionForegroundColors())
return style.VisitedDependentColor(color_property);
return document.GetFrame()->Selection().FrameIsFocusedAndActive()
Expand Down Expand Up @@ -106,10 +114,16 @@ Color SelectionPaintingUtils::SelectionBackgroundColor(

if (scoped_refptr<ComputedStyle> pseudo_style =
GetUncachedSelectionStyle(node)) {
if (document.InForcedColorsMode() &&
pseudo_style->ForcedColorAdjust() != EForcedColorAdjust::kNone)
return LayoutTheme::GetTheme().SystemColor(CSSValueID::kHighlight);
return pseudo_style->VisitedDependentColor(GetCSSPropertyBackgroundColor())
.BlendWithWhite();
}

if (document.InForcedColorsMode())
return LayoutTheme::GetTheme().SystemColor(CSSValueID::kHighlight);

return document.GetFrame()->Selection().FrameIsFocusedAndActive()
? LayoutTheme::GetTheme().ActiveSelectionBackgroundColor()
: LayoutTheme::GetTheme().InactiveSelectionBackgroundColor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,10 @@ void SVGInlineTextBoxPainter::PaintTextMatchMarkerForeground(
if (text_match_info_list.IsEmpty())
return;

Color text_color =
LayoutTheme::GetTheme().PlatformTextSearchColor(marker.IsActiveMatch());
Color text_color = LayoutTheme::GetTheme().PlatformTextSearchColor(
marker.IsActiveMatch(), svg_inline_text_box_.GetLineLayoutItem()
.GetDocument()
.InForcedColorsMode());

PaintFlags fill_flags;
fill_flags.setColor(text_color.Rgb());
Expand Down Expand Up @@ -642,7 +644,9 @@ void SVGInlineTextBoxPainter::PaintTextMatchMarkerBackground(
return;

Color color = LayoutTheme::GetTheme().PlatformTextSearchHighlightColor(
marker.IsActiveMatch());
marker.IsActiveMatch(), svg_inline_text_box_.GetLineLayoutItem()
.GetDocument()
.InForcedColorsMode());
for (const SVGTextFragmentWithRange& text_match_info : text_match_info_list) {
const SVGTextFragment& fragment = text_match_info.fragment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ crbug.com/591099 external/wpt/quirks/line-height-trailing-collapsable-whitespace
### fast/css/
crbug.com/591099 fast/css/absolute-inline-alignment-2.html [ Failure ]

# Newline painting difference with LayoutNG disabled.
crbug.com/591099 fast/css/forced-colors-mode/forced-colors-mode-14.html [ Failure ]
crbug.com/591099 fast/css/forced-colors-mode/forced-colors-mode-15.html [ Failure ]
crbug.com/591099 virtual/forced-colors/fast/css/forced-colors-mode/forced-colors-mode-14.html [ Failure ]
crbug.com/591099 virtual/forced-colors/fast/css/forced-colors-mode/forced-colors-mode-15.html [ Failure ]

### http/tests/credentialmanager/
crbug.com/874695 http/tests/credentialmanager/credentialscontainer-create-with-virtual-authenticator.html [ Failure ]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<style>
span {
background-color: rgba(255, 0, 0, 0.99);
color: blue;
display: inline-block;
forced-color-adjust: none;
}
</style>
<body>
<span class="select">AAA</span>
<br>
<span class="select" id="adjust-none">AAA</span>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<title>
Forced colors mode - active selection.
</title>
<style>
br::selection {
background-color: transparent;
forced-color-adjust: none;
}
span {
/* inline-block to ensure the selection bounding rectangle matches that of the
span. This allows us to test selection using a reference test. */
display: inline-block;
}
.select::selection {
background-color: rgba(255, 0, 0, 0.99); /* alpha < 1 so that we don't blend the background color with white. */
color: blue;
}
#adjust-none::selection {
forced-color-adjust: none;
}
</style>
<body>
<span class="select">AAA</span>
<br>
<span class="select" id="adjust-none">AAA</span>
</body>

<script>
var node1 = document.getElementsByClassName('select')[0].firstChild;
var node2 = document.getElementsByClassName('select')[1].firstChild;
var range = document.createRange();
range.setStart(node1, 0);
range.setEnd(node2, node2.length);
window.getSelection().addRange(range);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<style>
span {
background-color: rgba(255, 0, 0, 0.99);
color: blue;
display: inline-block;
forced-color-adjust: none;
}
</style>
<body>
<span class="select">AAA</span>
<br>
<span class="select" id="adjust-none">AAA</span>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<title>
Forced colors mode - inactive selection.
</title>
<style>
br::selection:window-inactive {
background-color: transparent;
forced-color-adjust: none;
}
span {
/* inline-block to ensure the selection bounding rectangle matches that of the
span. This allows us to test selection using a reference test. */
display: inline-block;
}
.select::selection:window-inactive {
background-color: rgba(255, 0, 0, 0.99); /* alpha < 1 so that we don't blend the background color with white. */
color: blue;
}
#adjust-none::selection:window-inactive {
forced-color-adjust: none;
}
</style>
<body>
<span class="select">AAA</span>
<br>
<span class="select" id="adjust-none">AAA</span>
</body>

<script>
var node1 = document.getElementsByClassName('select')[0].firstChild;
var node2 = document.getElementsByClassName('select')[1].firstChild;
var range = document.createRange();
range.setStart(node1, 0);
range.setEnd(node2, node2.length);
window.getSelection().addRange(range);

// Make the window inactive.
if (window.testRunner)
testRunner.setWindowIsKey(false);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<div>
<br><span style="background-color: rgb(255, 255, 0)">AAA</span>
</div>

<div>
<br><span style="background-color: rgb(255, 150, 50)">AAA</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<title>
Forced colors mode - search.
</title>
<link rel=match href=forced-colors-mode-16-expected.html>
<div>
<br id='b1'>AAA
</div>
<div>
<br id='b2'>AAA
</div>

<script>
function highlightRange(element, start, end, active) {
var range = document.createRange();
range.setStart(element, start);
range.setEnd(element, end);
internals.addTextMatchMarker(range, active);
}

if (window.internals) {
onload = function() {
highlightRange(document.getElementById('b1').nextSibling, 0, 3, 'kInactive');
highlightRange(document.getElementById('b2').nextSibling, 0, 3, 'kActive');
internals.setMarkedTextMatchesAreHighlighted(document, true);
};
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<style>
span {
background-color: Highlight;
color: HighlightText;
display: inline-block;
forced-color-adjust: none;
}
#adjust-none {
background-color: rgba(255, 0, 0, 0.99);
color: blue;
}
</style>
<body>
<span class="select">AAA</span>
<br>
<span class="select" id="adjust-none">AAA</span>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<style>
span {
background-color: Highlight;
color: HighlightText;
display: inline-block;
forced-color-adjust: none;
}
#adjust-none {
background-color: rgba(255, 0, 0, 0.99);
color: blue;
}
</style>
<body>
<span class="select">AAA</span>
<br>
<span class="select" id="adjust-none">AAA</span>
</body>

0 comments on commit 12bb018

Please sign in to comment.