diff --git a/browser/ui/views/frame/brave_browser_frame.cc b/browser/ui/views/frame/brave_browser_frame.cc index 0b4e26e6f55e..14f21546b22f 100644 --- a/browser/ui/views/frame/brave_browser_frame.cc +++ b/browser/ui/views/frame/brave_browser_frame.cc @@ -36,4 +36,22 @@ const ui::NativeTheme* BraveBrowserFrame::GetNativeTheme() const { // Each platform will implement ui::NativeTheme::GetInstanceForNativeUi // separately, which Widget::GetNativeTheme calls. return views::Widget::GetNativeTheme(); -} \ No newline at end of file +} + +void BraveBrowserFrame::ThemeChanged() { + BrowserFrame::ThemeChanged(); + // Our native theme values must be changed when our theme is changed + // because of white text on white problem for the URLbar and probably + // other problems too. + // I tried a lot of ways but doing the NotifyObserers here is the only + // way that I found which works. Notify Observers does in turn trigger + // a call to ThemeChanged though, so to avoid infinite recurison we use + // the hack below. + static bool inThemeChanged = false; + if (!inThemeChanged) { + inThemeChanged = true; + ui::NativeThemeDarkAura::instance()->NotifyObservers(); + views::Widget::GetNativeTheme()->NotifyObservers(); + } + inThemeChanged = false; +} diff --git a/browser/ui/views/frame/brave_browser_frame.h b/browser/ui/views/frame/brave_browser_frame.h index 3305432ef747..cc4b36fc9c54 100644 --- a/browser/ui/views/frame/brave_browser_frame.h +++ b/browser/ui/views/frame/brave_browser_frame.h @@ -14,6 +14,7 @@ class BraveBrowserFrame : public BrowserFrame { explicit BraveBrowserFrame(BrowserView* browser_view); ~BraveBrowserFrame() override; const ui::NativeTheme* GetNativeTheme() const override; + void ThemeChanged() override; private: // The BrowserView is our ClientView. This is a pointer to it. diff --git a/patches/ui-views-widget-widget.h.patch b/patches/ui-views-widget-widget.h.patch new file mode 100644 index 000000000000..0e8af26eef66 --- /dev/null +++ b/patches/ui-views-widget-widget.h.patch @@ -0,0 +1,13 @@ +diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h +index 2efbe5c4d899ec9ec683b6f8ecb058cbe903cd94..d43b471c277a95b3daa245a25d74c2e5624211de 100644 +--- a/ui/views/widget/widget.h ++++ b/ui/views/widget/widget.h +@@ -637,7 +637,7 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, + + // Notifies the view hierarchy contained in this widget that theme resources + // changed. +- void ThemeChanged(); ++ virtual void ThemeChanged(); + + // Notifies the view hierarchy contained in this widget that the device scale + // factor changed.