Skip to content

Commit

Permalink
Notify NativeTheme changed when theme changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed Oct 10, 2018
1 parent a76b249 commit 2209f6c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
20 changes: 19 additions & 1 deletion browser/ui/views/frame/brave_browser_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

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;
}
1 change: 1 addition & 0 deletions browser/ui/views/frame/brave_browser_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions patches/ui-views-widget-widget.h.patch
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 2209f6c

Please sign in to comment.