Repository navigation
Conversation
A TextHighlighter with no Background drew no highlight in a TextBlock, and one with no Foreground used a fixed black. Like WinUI, resolve an unset brush to the theme's TextControlHighlighterBackground and TextControlHighlighterForeground, each on its own. Fixes unoplatform#24747
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
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.
GitHub Issue: closes #24747; part of the epic #26728
PR Type:
🐞 Bugfix
What changed? 🚀
On WinUI, a
TextHighlighterwhoseBackgroundorForegroundis left unset is drawn with the theme'sTextControlHighlighterBackgroundandTextControlHighlighterForeground(yellow and black in the light and dark themes). On Skia,TextBlockdrew no background at all for an unsetBackground, and used a hard-coded black for an unsetForeground, so an app that overrides those resources didn't get its colors either.UnicodeText.Drawnow resolves an unset brush throughTextHighlightRenderer.GetDefaultHighlighterBrushes, the helper ported from WinUI'sTextHighlightRenderer.cpp, which looks both keys up in the application's resources. Each brush falls back on its own, likeIterateMergedHighlighters: a highlighter with onlyForegroundset gets the default background, and one with onlyBackgroundset gets the default foreground. The lookup only happens when a highlighter actually has an unset brush, so the selection highlighter (which always sets both) costs nothing extra.Visible change for existing apps. A
TextBlockhighlighter that sets onlyForeground, the usual way to recolor part of a text, now also paints the default yellow background behind that range, as it does on WinUI. To keep the old look, setBackgroundto a transparent brush (new SolidColorBrush(Colors.Transparent)): that draws no fill on WinUI or on Skia, and the text keeps the highlighter'sForeground.What it reaches:
TextBlock: fixed.RichTextBlockandRichTextBlockOverflow: unchanged. They still draw through the legacyParsedTextengine, which already falls back to the default background. They will pick up this path when they move toUnicodeText.TextBox,PasswordBoxandRichEditBox: they draw throughUnicodeTexttoo, but only with their selection highlighter, which sets both brushes, so their output doesn't change.TextBlockhighlighter with an unsetBackgroundnow gets the high-contrast selection colors, like one with an explicitBackground, instead of the plain backplate.Validation
Runtime, Skia Desktop (Win32): new tests in
Given_TextBlock, which find the highlight by color in a screenshot:When_TextHighlighter_Has_No_Brushes: yellow background and black text over the highlighted word only.When_TextHighlighter_Has_No_Brushes_Dark_Theme: the same in the dark application theme.When_TextHighlighter_Has_Only_Foreground: yellow background, the highlighter's text color.When_TextHighlighter_Has_Only_Background: the highlighter's background, with the text in the theme's default foreground. The test overridesTextControlHighlighterForeground, since the old hard-coded black is also the light and dark default.When_TextHighlighter_Default_Brushes_Are_Overridden: with both resources overridden inApplication.Resources, the overrides are used.When_TextHighlighter_Has_Transparent_Background: a transparentBackgroundwith aForegrounddraws no fill, only the recolored text (the way to keep the old look).Plus
Given_RichTextBlock_Highlighters.When_Highlighter_Has_No_Brushes, which pins the yellowRichTextBlockalready draws over the highlighted word and not over the rest of the text. The control is sized to its text, so both checked areas sit over glyphs; highlighting the whole text makes it fail.TextBlocktests fail (no yellow background, or black text instead of the overridden foreground). The transparent-background test and theRichTextBlockone pass both before and after, since they pin behavior that doesn't change.RichTextBlockgroup (Given_RichTextBlock|Given_SkiaTextFormatter|Given_BlockLayoutEngine|Given_HyperlinkAutomation, 208 cases) and theTextBlock/TextBox/RichEditBox/PasswordBoxgroup (1,578 cases): against master, no case went from pass to fail. The only differences are the new cases, all passing. The two failures and one inconclusive in the second group fail on master too.Runtime, native WinUI (WinAppSDK): the seven tests pass. Before writing them, I measured WinUI: an unset
Backgroundgives#FFFFFF00, an unsetForegroundgives black even over a red run, each brush falls back on its own, and an app override of either resource is used. The WinUI app ran in the dark application theme, since WinUI can't switch it at runtime; the light values come from WinUI'sgeneric.xaml, where they are the same.Compile:
Uno.UIand the runtime tests project build with analyzers and code style on, with no warning or error.Not in this PR: a non-
SolidColorBrushhighlighter brush, which WinUI rejects (#24684), is left as is.PR Checklist ✅
Screenshots Compare Test Runresults.Backgroundto opt out.