fix: revert 6ecf729 to fix Linux titlebar dark mode (#25055)

Fixes #24741
This commit is contained in:
Charles Kerr 2020-08-20 15:53:06 -05:00 committed by GitHub
parent 2d502b8ac6
commit d9a1c453ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 33 deletions

View file

@ -207,7 +207,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
* `opacity` Number (optional) - Set the initial opacity of the window, between 0.0 (fully * `opacity` Number (optional) - Set the initial opacity of the window, between 0.0 (fully
transparent) and 1.0 (fully opaque). This is only implemented on Windows and macOS. transparent) and 1.0 (fully opaque). This is only implemented on Windows and macOS.
* `darkTheme` Boolean (optional) - Forces using dark theme for the window, only works on * `darkTheme` Boolean (optional) - Forces using dark theme for the window, only works on
some GTK desktop environments. Default is [`nativeTheme.shouldUseDarkColors`](native-theme.md). some GTK+3 desktop environments. Default is `false`.
* `transparent` Boolean (optional) - Makes the window [transparent](frameless-window.md#transparent-window). * `transparent` Boolean (optional) - Makes the window [transparent](frameless-window.md#transparent-window).
Default is `false`. On Windows, does not work unless the window is frameless. Default is `false`. On Windows, does not work unless the window is frameless.
* `type` String (optional) - The type of window, default is normal window. See more about * `type` String (optional) - The type of window, default is normal window. See more about

View file

@ -914,6 +914,10 @@ void BaseWindow::CloseFilePreview() {
window_->CloseFilePreview(); window_->CloseFilePreview();
} }
void BaseWindow::SetGTKDarkThemeEnabled(bool use_dark_theme) {
window_->SetGTKDarkThemeEnabled(use_dark_theme);
}
v8::Local<v8::Value> BaseWindow::GetContentView() const { v8::Local<v8::Value> BaseWindow::GetContentView() const {
if (content_view_.IsEmpty()) if (content_view_.IsEmpty())
return v8::Null(isolate()); return v8::Null(isolate());

View file

@ -206,6 +206,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
void SetAspectRatio(double aspect_ratio, gin_helper::Arguments* args); void SetAspectRatio(double aspect_ratio, gin_helper::Arguments* args);
void PreviewFile(const std::string& path, gin_helper::Arguments* args); void PreviewFile(const std::string& path, gin_helper::Arguments* args);
void CloseFilePreview(); void CloseFilePreview();
void SetGTKDarkThemeEnabled(bool use_dark_theme);
// Public getters of NativeWindow. // Public getters of NativeWindow.
v8::Local<v8::Value> GetContentView() const; v8::Local<v8::Value> GetContentView() const;

View file

@ -10,8 +10,6 @@
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "gin/handle.h" #include "gin/handle.h"
#include "shell/browser/native_window_views.h"
#include "shell/browser/window_list.h"
#include "shell/common/gin_converters/std_converter.h" #include "shell/common/gin_converters/std_converter.h"
#include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/gin_helper/object_template_builder.h"
@ -53,13 +51,8 @@ void NativeTheme::SetThemeSource(ui::NativeTheme::ThemeSource override) {
// Update the macOS appearance setting for this new override value // Update the macOS appearance setting for this new override value
UpdateMacOSAppearanceForOverrideValue(override); UpdateMacOSAppearanceForOverrideValue(override);
#endif #endif
#if defined(USE_X11) // TODO(MarshallOfSound): Update all existing browsers windows to use GTK dark
const bool dark_enabled = ShouldUseDarkColors(); // theme
for (auto* window : WindowList::GetWindows()) {
static_cast<NativeWindowViews*>(window)->SetGTKDarkThemeEnabled(
dark_enabled);
}
#endif
} }
ui::NativeTheme::ThemeSource NativeTheme::GetThemeSource() const { ui::NativeTheme::ThemeSource NativeTheme::GetThemeSource() const {

View file

@ -234,6 +234,8 @@ class NativeWindow : public base::SupportsUserData,
const std::string& display_name); const std::string& display_name);
virtual void CloseFilePreview(); virtual void CloseFilePreview();
virtual void SetGTKDarkThemeEnabled(bool use_dark_theme) = 0;
// Converts between content bounds and window bounds. // Converts between content bounds and window bounds.
virtual gfx::Rect ContentBoundsToWindowBounds( virtual gfx::Rect ContentBoundsToWindowBounds(
const gfx::Rect& bounds) const = 0; const gfx::Rect& bounds) const = 0;

View file

@ -138,6 +138,7 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
std::vector<gin_helper::PersistentDictionary> items) override; std::vector<gin_helper::PersistentDictionary> items) override;
void RefreshTouchBarItem(const std::string& item_id) override; void RefreshTouchBarItem(const std::string& item_id) override;
void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item) override; void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item) override;
void SetGTKDarkThemeEnabled(bool use_dark_theme) override {}
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override; gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override; gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;

View file

@ -34,7 +34,6 @@
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
@ -215,10 +214,10 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
window_state_watcher_ = std::make_unique<WindowStateWatcher>(this); window_state_watcher_ = std::make_unique<WindowStateWatcher>(this);
// Set _GTK_THEME_VARIANT to dark if we have "dark-theme" option set. // Set _GTK_THEME_VARIANT to dark if we have "dark-theme" option set.
bool use_dark_theme = bool use_dark_theme = false;
ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors(); if (options.Get(options::kDarkTheme, &use_dark_theme) && use_dark_theme) {
options.Get(options::kDarkTheme, &use_dark_theme); SetGTKDarkThemeEnabled(use_dark_theme);
SetGTKDarkThemeEnabled(use_dark_theme); }
// Before the window is mapped the SetWMSpecState can not work, so we have // Before the window is mapped the SetWMSpecState can not work, so we have
// to manually set the _NET_WM_STATE. // to manually set the _NET_WM_STATE.
@ -329,6 +328,20 @@ NativeWindowViews::~NativeWindowViews() {
#endif #endif
} }
void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
#if defined(USE_X11)
if (use_dark_theme) {
ui::SetStringProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
gfx::GetAtom("_GTK_THEME_VARIANT"),
gfx::GetAtom("UTF8_STRING"), "dark");
} else {
ui::SetStringProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
gfx::GetAtom("_GTK_THEME_VARIANT"),
gfx::GetAtom("UTF8_STRING"), "light");
}
#endif
}
void NativeWindowViews::SetContentView(views::View* view) { void NativeWindowViews::SetContentView(views::View* view) {
if (content_view()) { if (content_view()) {
root_view_->RemoveChildView(content_view()); root_view_->RemoveChildView(content_view());
@ -1291,20 +1304,6 @@ void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) {
} }
#endif #endif
#if defined(USE_X11)
void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
if (use_dark_theme) {
ui::SetStringProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
gfx::GetAtom("_GTK_THEME_VARIANT"),
gfx::GetAtom("UTF8_STRING"), "dark");
} else {
ui::SetStringProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
gfx::GetAtom("_GTK_THEME_VARIANT"),
gfx::GetAtom("UTF8_STRING"), "light");
}
}
#endif
void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget, void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget,
bool active) { bool active) {
if (changed_widget != widget()) if (changed_widget != widget())

View file

@ -128,6 +128,8 @@ class NativeWindowViews : public NativeWindow,
bool IsVisibleOnAllWorkspaces() override; bool IsVisibleOnAllWorkspaces() override;
void SetGTKDarkThemeEnabled(bool use_dark_theme) override;
content::DesktopMediaID GetDesktopMediaID() const override; content::DesktopMediaID GetDesktopMediaID() const override;
gfx::AcceleratedWidget GetAcceleratedWidget() const override; gfx::AcceleratedWidget GetAcceleratedWidget() const override;
NativeWindowHandle GetNativeWindowHandle() const override; NativeWindowHandle GetNativeWindowHandle() const override;
@ -156,10 +158,6 @@ class NativeWindowViews : public NativeWindow,
void SetIcon(const gfx::ImageSkia& icon); void SetIcon(const gfx::ImageSkia& icon);
#endif #endif
#if defined(USE_X11)
void SetGTKDarkThemeEnabled(bool use_dark_theme);
#endif
SkRegion* draggable_region() const { return draggable_region_.get(); } SkRegion* draggable_region() const { return draggable_region_.get(); }
#if defined(OS_WIN) #if defined(OS_WIN)