diff --git a/src/app.rs b/src/app.rs index ff3f245..0744d07 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1360,7 +1360,7 @@ impl App { pub fn style_window(&self, win: &mut BrowserWindow) { let settings = self.shared.settings.borrow(); let dark = theme::is_dark(&settings, *self.shared.system_dark.borrow()); - let site = win.tab().and_then(|t| t.theme_color); + let site = win.tab().and_then(Tab::site_colour); let palette = theme::Palette::new(theme::seed(&settings, site, self.shared.system_accent), dark, &settings.theme.variant, settings.theme.contrast); let ctx = &win.egui.egui_ctx; theme::apply(ctx, &palette, &settings); @@ -1368,6 +1368,7 @@ impl App { ctx.set_zoom_factor(settings.ui.scale.clamp(0.5, 3.0)); } win.ui.palette = Some(palette); + win.ui.site_colour = site; } /// Create the web view for the active tab if it doesn't have one yet (lazy restore, unloaded tab). @@ -1610,6 +1611,13 @@ impl App { // ── drawing ─────────────────────────────────────────────────────── fn draw(&mut self, window: WindowId) { + // An internal page shown in a web tab, or Back to the page behind it, changes the site colour. + if self.windows.get(&window).is_some_and(|w| w.tab().and_then(Tab::site_colour) != w.ui.site_colour) + && let Some(mut win) = self.windows.remove(&window) + { + self.style_window(&mut win); + self.windows.insert(window, win); + } let Some(win) = self.windows.get_mut(&window) else { return }; let started = Instant::now(); win.needs_redraw = false; diff --git a/src/tabs.rs b/src/tabs.rs index 0ecaad3..e5b3845 100644 --- a/src/tabs.rs +++ b/src/tabs.rs @@ -277,6 +277,11 @@ impl Tab { self.page.is_some() } + /// The colour the "Website" colour source follows: none on an internal page, even one shown over a web page. + pub fn site_colour(&self) -> Option { + if self.is_internal() { None } else { self.theme_color } + } + pub fn loading(&self) -> bool { self.page.is_none() && matches!(self.load_status, Some(LoadStatus::Started | LoadStatus::HeadParsed)) } @@ -334,3 +339,19 @@ impl Tab { } } } + +#[cfg(test)] +mod tests { + use super::*; + + // R1-11: a nacre:// page opened in a web tab kept the site's colour, so palette picks didn't show. + #[test] + fn internal_page_has_no_site_colour() { + let mut tab = Tab::new(1); + tab.page = None; + tab.theme_color = Some(egui::Color32::from_rgb(0xDE, 0x58, 0x33)); + assert_eq!(tab.site_colour(), tab.theme_color); + tab.page = Some(Page::Settings(String::new())); + assert_eq!(tab.site_colour(), None); + } +} diff --git a/src/ui/mod.rs b/src/ui/mod.rs index d461f16..12ddcc8 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -70,6 +70,8 @@ pub fn fonts() -> egui::FontDefinitions { #[derive(Default)] pub struct WindowUi { pub palette: Option, + /// The site colour `palette` was built from; the window restyles when the active tab's differs. + pub site_colour: Option, /// Address bar text while the user edits it (None = show the page's URL). pub omnibox_edit: Option, pub focus_omnibox: bool, diff --git a/tests/smoke/colours.txt b/tests/smoke/colours.txt new file mode 100644 index 0000000..a4efe08 --- /dev/null +++ b/tests/smoke/colours.txt @@ -0,0 +1,49 @@ +# R1-11: colours still change after the welcome setup, also when Settings is typed into a web tab whose page has a +# theme-color. Hidden 1280x1100 layout (tap positions): SMOKE_SIZE=1280x1100, fresh outdir. Expect: site-* orange +# chrome (#DE5833 seed); s-website NOT orange (an internal page has no site colour); s-teal teal; back-site orange +# again (Website source, back on the page); s-palette and tab-palette teal; s-custom blue. settings.json afterwards: +# theme.source "custom", theme.fallback "palette", theme.preset "#006A6A". +wait 3 +resize 1280 1060 +key enter +wait 0.6 +key enter +wait 0.6 +key enter +wait 0.6 +key enter +wait 0.6 +key enter +wait 0.6 +key enter +wait 1.5 +shot welcome-done +open @PAGES@/theme-colour.html +waitload +wait 1 +shot site +cmd navigate nacre://settings/appearance +wait 1.5 +shot s-website +tap 614 690 +wait 1 +shot s-teal +status teal +cmd back +wait 1.5 +shot back-site +page nacre://settings/appearance +wait 1.5 +tap 747 491 +wait 1 +shot s-palette +cmd select 0 +wait 1 +shot tab-palette +page nacre://settings/appearance +wait 1 +tap 883 491 +wait 1 +shot s-custom +status done +quit diff --git a/tests/smoke/pages/theme-colour.html b/tests/smoke/pages/theme-colour.html new file mode 100644 index 0000000..0f7a592 --- /dev/null +++ b/tests/smoke/pages/theme-colour.html @@ -0,0 +1,5 @@ + + + +Theme colour +A page with an orange theme-color (colours.txt).