commit 1e3ab6dfd5d367e843163ec27ac7188fc3a635d0 parent e538d5c362b488d35a27ead7e7230b32aec4c6f1 Author: iulian moraru <imoraru@mozilla.com> Date: Thu, 9 Oct 2025 12:45:08 +0300 Revert "Bug 1974121: apply code formatting via Lando" for causing reftest failures on target-text-black.html. This reverts commit 5d0bdc0d2a6ebc1a3ca7ada59640ef7e4b88b711. Revert "Bug 1974121, part 2 - Text Fragments: Add adaptive default colors for ::target-text based on the background. r=layout-reviewers,emilio" This reverts commit 00ab578441397e1065c7a679d4c3fc05d94c9b61. Revert "Bug 1974121, part 1 - Text Fragments: Change HCM colors to `SelectedItem`. r=ayeddi,layout-reviewers,emilio,accessibility-frontend-reviewers,win-reviewers,gstoll" This reverts commit ee21c1ff64ffac09e49ba4cd5491da0ddaf820f6. Diffstat:
19 files changed, 57 insertions(+), 151 deletions(-)
diff --git a/layout/generic/nsTextPaintStyle.cpp b/layout/generic/nsTextPaintStyle.cpp @@ -7,7 +7,6 @@ #include "nsTextPaintStyle.h" #include "mozilla/LookAndFeel.h" -#include "mozilla/RelativeLuminanceUtils.h" #include "nsCSSColorUtils.h" #include "nsCSSRendering.h" #include "nsFrameSelection.h" @@ -218,7 +217,6 @@ void nsTextPaintStyle::GetTargetTextColors(nscolor* aForeColor, nscolor* aBackColor) { NS_ASSERTION(aForeColor, "aForeColor is null"); NS_ASSERTION(aBackColor, "aBackColor is null"); - InitCommonColors(); const RefPtr<const ComputedStyle> targetTextStyle = mFrame->ComputeTargetTextStyle(); if (targetTextStyle) { @@ -228,28 +226,15 @@ void nsTextPaintStyle::GetTargetTextColors(nscolor* aForeColor, &nsStyleBackground::mBackgroundColor); return; } - - const auto darkSchemeBackground = LookAndFeel::Color( - LookAndFeel::ColorID::TargetTextBackground, - LookAndFeel::ColorScheme::Dark, LookAndFeel::UseStandins::No); - const auto lightSchemeBackground = LookAndFeel::Color( - LookAndFeel::ColorID::TargetTextBackground, - LookAndFeel::ColorScheme::Light, LookAndFeel::UseStandins::No); - const auto lightSchemeForeground = LookAndFeel::Color( - LookAndFeel::ColorID::TargetTextForeground, - LookAndFeel::ColorScheme::Light, LookAndFeel::UseStandins::No); - const auto darkSchemeForeground = LookAndFeel::Color( - LookAndFeel::ColorID::TargetTextForeground, - LookAndFeel::ColorScheme::Dark, LookAndFeel::UseStandins::No); - const float ratioLightScheme = RelativeLuminanceUtils::ContrastRatio( - lightSchemeBackground, mFrameBackgroundColor); - const float ratioDarkScheme = RelativeLuminanceUtils::ContrastRatio( - darkSchemeBackground, mFrameBackgroundColor); - - *aBackColor = ratioLightScheme > ratioDarkScheme ? lightSchemeBackground - : darkSchemeBackground; - *aForeColor = ratioLightScheme > ratioDarkScheme ? lightSchemeForeground - : darkSchemeForeground; + if (PresContext()->ForcingColors()) { + *aBackColor = LookAndFeel::Color(LookAndFeel::ColorID::Mark, mFrame); + *aForeColor = LookAndFeel::Color(LookAndFeel::ColorID::Marktext, mFrame); + } else { + *aBackColor = + LookAndFeel::Color(LookAndFeel::ColorID::TargetTextBackground, mFrame); + *aForeColor = + LookAndFeel::Color(LookAndFeel::ColorID::TargetTextForeground, mFrame); + } } bool nsTextPaintStyle::GetCustomHighlightTextColor(nsAtom* aHighlightName, diff --git a/layout/reftests/high-contrast/reftest.list b/layout/reftests/high-contrast/reftest.list @@ -34,7 +34,8 @@ test-pref(browser.display.suppress_canvas_background_image_on_forced_colors,fals needs-focus == selection-001.html selection-001-ref.html pref(browser.display.document_color_use,0) needs-focus != selection-001.html selection-001-ref.html -pref(dom.text_fragments.enabled,true) == target-text.html target-text-ref.html +pref(dom.text_fragments.enabled,true) == target-text-001.html target-text-001-ref.html +pref(dom.text_fragments.enabled,true) == target-text-002.html target-text-001-ref.html == color-transparent-001.html about:blank != color-transparent-002.html about:blank diff --git a/layout/reftests/high-contrast/target-text-001-ref.html b/layout/reftests/high-contrast/target-text-001-ref.html @@ -0,0 +1,12 @@ +<!doctype html> +<html> +<style> +span { + background-color: mark; + color: marktext; +} +</style> +<body> +<span>Some selected text</span> +</body> +</html> diff --git a/layout/reftests/high-contrast/target-text-001.html b/layout/reftests/high-contrast/target-text-001.html @@ -0,0 +1,10 @@ +<!doctype html> +<html> +<title>::target-text without custom colors should be replaced with mark/marktext</title> +<script> +location.hash = ':~:text=Some selected text'; +</script> +<body> +<span>Some selected text</span> +</body> +</html> diff --git a/layout/reftests/high-contrast/target-text-002.html b/layout/reftests/high-contrast/target-text-002.html @@ -0,0 +1,16 @@ +<!doctype html> +<html> +<title>::target-text with custom colors should be replaced with mark/marktext</title> +<style> +::target-text { + background: #FF0000; + color: #0000FF; +} +</style> +<script> +location.hash = ':~:text=Some selected text'; +</script> +<body> +<span>Some selected text</span> +</body> +</html> diff --git a/layout/reftests/high-contrast/target-text-ref.html b/layout/reftests/high-contrast/target-text-ref.html @@ -1,9 +0,0 @@ -<!doctype html> -<html> -<body> -<span>Some selected text</span> -<script> -location.hash = ':~:text=Some selected text'; -</script> -</body> -</html> diff --git a/layout/reftests/high-contrast/target-text.html b/layout/reftests/high-contrast/target-text.html @@ -1,16 +0,0 @@ -<!doctype html> -<html> -<title>custom colors for ::target-text should be replaced with forced-colors colors</title> -<style> -::target-text { - background: #FF0000; - color: #0000FF; -} -</style> -<script> -location.hash = ':~:text=Some selected text'; -</script> -<body> -<span>Some selected text</span> -</body> -</html> diff --git a/layout/reftests/reftest.list b/layout/reftests/reftest.list @@ -340,9 +340,6 @@ include table-width/reftest.list include ../tables/reftests/reftest.list -# target-text/ -include target-text/reftest.list - # text/ include text/reftest.list diff --git a/layout/reftests/target-text/reftest.list b/layout/reftests/target-text/reftest.list @@ -1,4 +0,0 @@ -== target-text-light.html target-text-light-ref.html -== target-text-black.html target-text-black-ref.html -== target-text-bg-is-same-as-light.html target-text-bg-is-same-as-light-ref.html -== target-text-bg-is-same-as-dark.html target-text-bg-is-same-as-dark-ref.html diff --git a/layout/reftests/target-text/target-text-bg-is-same-as-dark-ref.html b/layout/reftests/target-text/target-text-bg-is-same-as-dark-ref.html @@ -1,10 +0,0 @@ -<!doctype html> -<meta charset="utf-8"> -<title>Reference: Background color is yellow-20, therefore the highlight must be yellow-00</title> -<style> - body { background:#f5cc58; } - - .hl { background:#fff4d0; color:#000; } -</style> - -<p><span class="hl">HighlightThis</span> is a keyword to test ::target-text highlight colour.</p> diff --git a/layout/reftests/target-text/target-text-bg-is-same-as-dark.html b/layout/reftests/target-text/target-text-bg-is-same-as-dark.html @@ -1,11 +0,0 @@ -<!doctype html> -<meta charset="utf-8"> -<title>Background color is yellow-20, therefore the highlight must be yellow-00</title> -<script> - location.hash = '#:~:text=HighlightThis'; -</script> -<style> - body { background:#f5cc58; } -</style> - -<p>HighlightThis is a keyword to test ::target-text highlight colour.</p> diff --git a/layout/reftests/target-text/target-text-bg-is-same-as-light-ref.html b/layout/reftests/target-text/target-text-bg-is-same-as-light-ref.html @@ -1,10 +0,0 @@ -<!doctype html> -<meta charset="utf-8"> -<title>Reference: Background color is yellow-00, therefore the highlight must be yellow-20</title> -<style> - body { background:#fff4d0; } - - .hl { background:#f5cc58; color:#000; } -</style> - -<p><span class="hl">HighlightThis</span> is a keyword to test ::target-text highlight colour.</p> diff --git a/layout/reftests/target-text/target-text-bg-is-same-as-light.html b/layout/reftests/target-text/target-text-bg-is-same-as-light.html @@ -1,11 +0,0 @@ -<!doctype html> -<meta charset="utf-8"> -<title>Background color is yellow-05, therefore the highlight must be yellow-20</title> -<script> - location.hash = '#:~:text=HighlightThis'; -</script> -<style> - body { background:#fff4d0; } -</style> - -<p>HighlightThis is a keyword to test ::target-text highlight colour.</p> diff --git a/layout/reftests/target-text/target-text-black-ref.html b/layout/reftests/target-text/target-text-black-ref.html @@ -1,9 +0,0 @@ -<!doctype html> -<meta charset="utf-8"> -<title>Reference: Dark background should use yellow-00 for highlight</title> -<style> - body { background:#000; color:#fff; } - .hl { background:#fff4d0; color:#000; } -</style> - -<p><span class="hl">HighlightThis</span> is a keyword to test ::target-text highlight colour.</p> diff --git a/layout/reftests/target-text/target-text-black.html b/layout/reftests/target-text/target-text-black.html @@ -1,11 +0,0 @@ -<!doctype html> -<meta charset="utf-8"> -<title>Dark background should use yellow-05 for highlight</title> -<script> - location.hash = '#:~:text=HighlightThis'; -</script> -<style> - body { background:#000; color: #fff; } -</style> - -<p>HighlightThis is a keyword to test ::target-text highlight colour.</p> diff --git a/layout/reftests/target-text/target-text-light-ref.html b/layout/reftests/target-text/target-text-light-ref.html @@ -1,8 +0,0 @@ -<!doctype html> -<meta charset="utf-8"> -<title>Reference: Light background should use yellow-20 for highlight</title> -<style> - .hl { background:#f5cc58; color:#000; } -</style> - -<p><span class="hl">HighlightThis</span> is a keyword to test ::target-text highlight colour.</p> diff --git a/layout/reftests/target-text/target-text-light.html b/layout/reftests/target-text/target-text-light.html @@ -1,8 +0,0 @@ -<!doctype html> -<meta charset="utf-8"> -<title>Light background should use yellow-20 for highlight</title> -<script> - location.hash = '#:~:text=HighlightThis'; -</script> - -<p>HighlightThis is a keyword to test ::target-text highlight colour.</p> diff --git a/widget/nsXPLookAndFeel.cpp b/widget/nsXPLookAndFeel.cpp @@ -713,7 +713,7 @@ nscolor nsXPLookAndFeel::GetStandinForNativeColor(ColorID aID, COLOR(Activetext, 0xee, 0x00, 0x00) COLOR(Visitedtext, 0x55, 0x1A, 0x8B) COLOR(MozAutofillBackground, 0xff, 0xfc, 0xc8) - COLOR(TargetTextBackground, 0xf5, 0xcc, 0x58) // --yellow-20 + COLOR(TargetTextBackground, 0xff, 0xeb, 0xcd) COLOR(TargetTextForeground, 0x00, 0x00, 0x00) default: break; @@ -872,12 +872,6 @@ Maybe<nscolor> nsXPLookAndFeel::GenericDarkColor(ColorID aID) { // contrast with our white-ish FieldText. color = NS_RGB(0x72, 0x6c, 0x00); break; - case ColorID::TargetTextBackground: - color = NS_RGB(0xff, 0xf4, 0xd0); // --yellow-0 - break; - case ColorID::TargetTextForeground: - color = NS_RGB(0x00, 0x00, 0x00); - break; default: return Nothing(); } diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp @@ -264,6 +264,13 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme, break; } + if (aScheme == ColorScheme::Dark) { + if (auto color = GenericDarkColor(aID)) { + aColor = *color; + return NS_OK; + } + } + if (mHighContrastOn) { switch (aID) { case ColorID::MozButtonhoverborder: @@ -271,14 +278,12 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme, case ColorID::MozColheaderhover: case ColorID::MozButtonactivetext: case ColorID::MozColheaderactivetext: - case ColorID::TargetTextBackground: aColor = GetColorForSysColorIndex(COLOR_HIGHLIGHT); return NS_OK; case ColorID::MozButtonhovertext: case ColorID::MozColheaderhovertext: case ColorID::MozButtonactiveface: case ColorID::MozColheaderactive: - case ColorID::TargetTextForeground: aColor = GetColorForSysColorIndex(COLOR_HIGHLIGHTTEXT); return NS_OK; case ColorID::MozButtondisabledborder: @@ -315,13 +320,6 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aScheme, } } - if (aScheme == ColorScheme::Dark) { - if (auto color = GenericDarkColor(aID)) { - aColor = *color; - return NS_OK; - } - } - static constexpr auto kNonNativeMenuText = NS_RGB(0x15, 0x14, 0x1a); nsresult res = NS_OK; int idx;