Dark mode#21617
Closed
adrianoracano wants to merge 2 commits into
Closed
Conversation
Contributor
|
I'm taking this out of the l10n queue for now, as there is no issue or bug attached justifying this work. |
Collaborator
|
Sorry, but features such as this requires feedback and a design specification from Firefox UX/UI before any work can start. (Also, given that AI was used to write #21617 (comment) there'd also be the question if that applies to all of the code as well.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Smart Page Dark Mode for PDF Viewer
This PR adds a smart dark mode feature for PDF page content in the viewer, with two distinct modes that preserve images and graphics rather than applying a naive full inversion.
Motivation
Reading PDFs with bright white backgrounds causes eye strain in low-light environments. The existing
viewerCssThemeoption controls the UI chrome theme (toolbar, sidebar, dialogs) but does not affect the rendered page content. This PR fills that gap with a content-aware dark mode that only affects the page canvas and thumbnails, leaving UI components to follow the system theme independently.Dark Mode Modes
A new
pageDarkModeoption (persisted as a viewer preference) supports three states:0none1brightness(0.85) contrast(0.95)2invert(0.88) hue-rotate(180deg)Both modes are "smart" — they use CSS filters that handle images and graphics gracefully, unlike a crude
invert(1)which would turn photos into photographic negatives.Scope
The dark mode filter is applied only to:
.canvasWrapper canvas— the rendered PDF page canvases.thumbnailsView .thumbnailImageContainer img— the thumbnail images in the sidebarThe toolbar, sidebar, menus, dialogs, and all other UI chrome are not affected and continue to follow the OS-level
color-schemepreference (or the explicitviewerCssThemesetting).UX
A new "Page Dark Mode" button (moon icon) has been added to the secondary toolbar (the tools dropdown). Each click cycles through Off → Soft → Full → Off. The button label updates to indicate the active mode (e.g. "Page Dark Mode: Soft").
Files Changed
web/app_options.jspageDarkModeoption (0/1/2, persisted as a preference)web/app.js_togglePageDarkMode()and_applyPageDarkMode()methods; wired up event listeners and initial preference applicationweb/pdf_viewer.css--page-dark-mode-filterCSS custom property; applied it as afilterto canvas elements and thumbnail imagesweb/viewer.css--secondaryToolbarButton-pageDarkMode-iconvariable and button icon mask ruleweb/viewer.htmlweb/viewer.jspageDarkModeButtoningetViewerConfiguration()web/secondary_toolbar.jstogglepagedarkmode)l10n/en-US/viewer.ftlweb/images/secondaryToolbarButton-pageDarkMode.svgHow It Works
secondary_toolbar.jsdispatches atogglepagedarkmodeeventapp.jshandler cycles thepageDarkModeAppOption (0→1→2→0)AppOptions.set()triggers apagedarkmodeevent viaEVENT_DISPATCH_applyPageDarkMode()sets the--page-dark-mode-filterCSS variable on the viewer and thumbnail containers