fix: window accentColor
should adhere to native window behavior (#48012)
* fix: window accentColor should adhere to native window behavior Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * fix: address review feedback Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * chore: remove duplicate UpdateWindowAccentColor call in ctor Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * refactor: add NativeWindow::IsActive() (#47148) this was already present on macOS; use in NativeWindowViews too --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
9b058a45bc
commit
b6dbb2bab7
5 changed files with 18 additions and 13 deletions
|
@ -2014,13 +2014,8 @@ void WebContents::ReadyToCommitNavigation(
|
||||||
// Don't focus content in an inactive window.
|
// Don't focus content in an inactive window.
|
||||||
if (!owner_window())
|
if (!owner_window())
|
||||||
return;
|
return;
|
||||||
#if BUILDFLAG(IS_MAC)
|
|
||||||
if (!owner_window()->IsActive())
|
if (!owner_window()->IsActive())
|
||||||
return;
|
return;
|
||||||
#else
|
|
||||||
if (!owner_window()->widget()->IsActive())
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
// Don't focus content after subframe navigations.
|
// Don't focus content after subframe navigations.
|
||||||
if (!navigation_handle->IsInMainFrame())
|
if (!navigation_handle->IsInMainFrame())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -157,10 +157,10 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
virtual void Invalidate() = 0;
|
virtual void Invalidate() = 0;
|
||||||
virtual void SetTitle(const std::string& title) = 0;
|
virtual void SetTitle(const std::string& title) = 0;
|
||||||
virtual std::string GetTitle() const = 0;
|
virtual std::string GetTitle() const = 0;
|
||||||
|
[[nodiscard]] virtual bool IsActive() const = 0;
|
||||||
#if BUILDFLAG(IS_MAC)
|
#if BUILDFLAG(IS_MAC)
|
||||||
virtual std::string GetAlwaysOnTopLevel() const = 0;
|
virtual std::string GetAlwaysOnTopLevel() const = 0;
|
||||||
virtual void SetActive(bool is_key) = 0;
|
virtual void SetActive(bool is_key) = 0;
|
||||||
virtual bool IsActive() const = 0;
|
|
||||||
virtual void RemoveChildFromParentWindow() = 0;
|
virtual void RemoveChildFromParentWindow() = 0;
|
||||||
virtual void RemoveChildWindow(NativeWindow* child) = 0;
|
virtual void RemoveChildWindow(NativeWindow* child) = 0;
|
||||||
virtual void AttachChildren() = 0;
|
virtual void AttachChildren() = 0;
|
||||||
|
|
|
@ -423,8 +423,6 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
|
||||||
last_window_state_ = ui::mojom::WindowShowState::kFullscreen;
|
last_window_state_ = ui::mojom::WindowShowState::kFullscreen;
|
||||||
else
|
else
|
||||||
last_window_state_ = ui::mojom::WindowShowState::kNormal;
|
last_window_state_ = ui::mojom::WindowShowState::kNormal;
|
||||||
|
|
||||||
UpdateWindowAccentColor();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Listen to mouse events.
|
// Listen to mouse events.
|
||||||
|
@ -1153,6 +1151,11 @@ std::string NativeWindowViews::GetTitle() const {
|
||||||
return title_;
|
return title_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NativeWindowViews::IsActive() const {
|
||||||
|
views::Widget* const widget = this->widget();
|
||||||
|
return widget && widget->IsActive();
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowViews::FlashFrame(bool flash) {
|
void NativeWindowViews::FlashFrame(bool flash) {
|
||||||
#if BUILDFLAG(IS_WIN)
|
#if BUILDFLAG(IS_WIN)
|
||||||
// The Chromium's implementation has a bug stopping flash.
|
// The Chromium's implementation has a bug stopping flash.
|
||||||
|
@ -1737,6 +1740,12 @@ void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget,
|
||||||
NativeWindow::NotifyWindowBlur();
|
NativeWindow::NotifyWindowBlur();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BUILDFLAG(IS_WIN)
|
||||||
|
// Update accent color based on activation state when no explicit color is
|
||||||
|
// set.
|
||||||
|
UpdateWindowAccentColor(active);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Hide menu bar when window is blurred.
|
// Hide menu bar when window is blurred.
|
||||||
if (!active && IsMenuBarAutoHide() && IsMenuBarVisible())
|
if (!active && IsMenuBarAutoHide() && IsMenuBarVisible())
|
||||||
SetMenuBarVisibility(false);
|
SetMenuBarVisibility(false);
|
||||||
|
|
|
@ -100,6 +100,7 @@ class NativeWindowViews : public NativeWindow,
|
||||||
void Invalidate() override;
|
void Invalidate() override;
|
||||||
void SetTitle(const std::string& title) override;
|
void SetTitle(const std::string& title) override;
|
||||||
std::string GetTitle() const override;
|
std::string GetTitle() const override;
|
||||||
|
[[nodiscard]] bool IsActive() const override;
|
||||||
void FlashFrame(bool flash) override;
|
void FlashFrame(bool flash) override;
|
||||||
void SetSkipTaskbar(bool skip) override;
|
void SetSkipTaskbar(bool skip) override;
|
||||||
void SetExcludedFromShownWindowsMenu(bool excluded) override {}
|
void SetExcludedFromShownWindowsMenu(bool excluded) override {}
|
||||||
|
@ -209,7 +210,7 @@ class NativeWindowViews : public NativeWindow,
|
||||||
void ResetWindowControls();
|
void ResetWindowControls();
|
||||||
void SetRoundedCorners(bool rounded);
|
void SetRoundedCorners(bool rounded);
|
||||||
void SetForwardMouseMessages(bool forward);
|
void SetForwardMouseMessages(bool forward);
|
||||||
void UpdateWindowAccentColor();
|
void UpdateWindowAccentColor(bool active);
|
||||||
static LRESULT CALLBACK SubclassProc(HWND hwnd,
|
static LRESULT CALLBACK SubclassProc(HWND hwnd,
|
||||||
UINT msg,
|
UINT msg,
|
||||||
WPARAM w_param,
|
WPARAM w_param,
|
||||||
|
|
|
@ -497,7 +497,7 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case WM_DWMCOLORIZATIONCOLORCHANGED: {
|
case WM_DWMCOLORIZATIONCOLORCHANGED: {
|
||||||
UpdateWindowAccentColor();
|
UpdateWindowAccentColor(IsActive());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case WM_SETTINGCHANGE: {
|
case WM_SETTINGCHANGE: {
|
||||||
|
@ -505,7 +505,7 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
|
||||||
const wchar_t* setting_name = reinterpret_cast<const wchar_t*>(l_param);
|
const wchar_t* setting_name = reinterpret_cast<const wchar_t*>(l_param);
|
||||||
std::wstring setting_str(setting_name);
|
std::wstring setting_str(setting_name);
|
||||||
if (setting_str == L"ImmersiveColorSet")
|
if (setting_str == L"ImmersiveColorSet")
|
||||||
UpdateWindowAccentColor();
|
UpdateWindowAccentColor(IsActive());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -568,7 +568,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::UpdateWindowAccentColor() {
|
void NativeWindowViews::UpdateWindowAccentColor(bool active) {
|
||||||
if (base::win::GetVersion() < base::win::Version::WIN11)
|
if (base::win::GetVersion() < base::win::Version::WIN11)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -587,7 +587,7 @@ void NativeWindowViews::UpdateWindowAccentColor() {
|
||||||
should_apply_accent = std::get<bool>(accent_color_);
|
should_apply_accent = std::get<bool>(accent_color_);
|
||||||
} else if (std::holds_alternative<std::monostate>(accent_color_)) {
|
} else if (std::holds_alternative<std::monostate>(accent_color_)) {
|
||||||
// If no explicit color was set, default to the system accent color.
|
// If no explicit color was set, default to the system accent color.
|
||||||
should_apply_accent = IsAccentColorOnTitleBarsEnabled();
|
should_apply_accent = IsAccentColorOnTitleBarsEnabled() && active;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use system accent color as fallback if no explicit color was set.
|
// Use system accent color as fallback if no explicit color was set.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue