Skip to content

Bug 2048531 - Improve selection contrast in dark mode - #21553

Merged
calixteman merged 1 commit into
mozilla:masterfrom
nicolo-ribaudo:fix-text-selection-dark-mode
Jul 11, 2026
Merged

calixteman merged 1 commit into
mozilla:masterfrom
nicolo-ribaudo:fix-text-selection-dark-mode

Conversation

@nicolo-ribaudo

@nicolo-ribaudo nicolo-ribaudo commented Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator

On some OSes, the current approach of using Highlight/HighlightText
colors to draw selected text doesn't work when the OS is set to dark
mode, as we revert the color-scheme to light to compute them
(because PDFs are normally in light mode) but that does not affect the
HighlightText color (which depends not on the color-scheme but on
the currentColor).

Other than forcing the color-scheme to light, set the color to
black and use the backgroud-color to compute the HighlightText
color instead.

In OSes where HighlightText is theme-dependent this will result in the
OS-provided text color, while in OSes where it is currentColor-dependent
it will be based on the default color for light themes (i.e. black).

If you want to play around with different colors in light/dark mode: css-highlight-color-scheme.html

@nicolo-ribaudo

Copy link
Copy Markdown
Collaborator Author

/botio preview

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_preview from @nicolo-ribaudo received. Current queue size: 0

Live output at: http://54.241.84.105:8877/5d0a64971f24ce6/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Received

Command cmd_preview from @nicolo-ribaudo received. Current queue size: 0

Live output at: http://54.193.163.58:8877/068eb2277adb255/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/5d0a64971f24ce6/output.txt

Total script time: 1.43 mins

Published

@codecov-commenter

codecov-commenter commented Jul 9, 2026 •

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 89.72%. Comparing base (8bc2fe6) to head (199d738).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21553   +/-   ##
=======================================
  Coverage   89.71%   89.72%           
=======================================
  Files         262      262           
  Lines       66709    66713    +4     
=======================================
+ Hits        59847    59856    +9     
+ Misses       6862     6857    -5     
Flag Coverage Ξ”
browsertest 66.56% <60.00%> (+<0.01%) ⬆️
fonttest 9.05% <ΓΈ> (ΓΈ)
integrationtest 69.25% <100.00%> (+<0.01%) ⬆️
unittest 57.33% <0.00%> (+<0.01%) ⬆️
unittestcli 56.26% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Harness.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/068eb2277adb255/output.txt

Total script time: 5.09 mins

Published

@calixteman

Copy link
Copy Markdown
Contributor

It doesn't wfm on Windows at least: CanvasText is black when the color should be white which is the case with HighlightText.

Comment thread src/display/filter_factory.js Resolved
On some OSes, the current approach of using `Highlight`/`HighlightText`
colors to draw selected text doesn't work when the OS is set to dark
mode, as we revert the `color-scheme` to `light` to compute them
(because PDFs are normally in light mode) but that does not affect the
`HighlightText` color (which depends not on the `color-scheme` but on
the `currentColor`).

Other than forcing the `color-scheme` to `light`, set the `color` to
`black` and use the `backgroud-color` to compute the `HighlightText`
color instead.

In OSes where `HighlightText` is theme-dependent this will result in the
OS-provided text color, while in OSes where it is `currentColor`-dependent
it will be based on the default color for light themes (i.e. black).
@nicolo-ribaudo
nicolo-ribaudo force-pushed the fix-text-selection-dark-mode branch from 337b683 to 199d738 Compare July 10, 2026 16:19

@calixteman calixteman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@calixteman
calixteman merged commit 612fa34 into mozilla:master Jul 11, 2026
20 of 21 checks passed
@nicolo-ribaudo
nicolo-ribaudo deleted the fix-text-selection-dark-mode branch July 13, 2026 07:10

This branch was previously deployed

1 inactive deployment
code-coverage β€” 199d7389 Deployed Jul 10, 2026 by nicolo-ribaudo via ubuntu-latest / chrome #831
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants