refactor: add NativeWindow::IsActive() (#47148)

this was already present on macOS; use in NativeWindowViews too
This commit is contained in:
Charles Kerr 2025-05-20 15:08:44 +00:00 committed by GitHub
parent 296e39456a
commit 211faed848
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 6 deletions

View file

@ -2007,13 +2007,8 @@ void WebContents::ReadyToCommitNavigation(
// Don't focus content in an inactive window.
if (!owner_window())
return;
#if BUILDFLAG(IS_MAC)
if (!owner_window()->IsActive())
return;
#else
if (!owner_window()->widget()->IsActive())
return;
#endif
// Don't focus content after subframe navigations.
if (!navigation_handle->IsInMainFrame())
return;

View file

@ -157,10 +157,10 @@ class NativeWindow : public base::SupportsUserData,
virtual ui::ZOrderLevel GetZOrderLevel() const = 0;
virtual void Center() = 0;
virtual void Invalidate() = 0;
[[nodiscard]] virtual bool IsActive() const = 0;
#if BUILDFLAG(IS_MAC)
virtual std::string GetAlwaysOnTopLevel() const = 0;
virtual void SetActive(bool is_key) = 0;
virtual bool IsActive() const = 0;
virtual void RemoveChildFromParentWindow() = 0;
virtual void RemoveChildWindow(NativeWindow* child) = 0;
virtual void AttachChildren() = 0;

View file

@ -1202,6 +1202,11 @@ void NativeWindowViews::Invalidate() {
widget()->SchedulePaintInRect(gfx::Rect(GetBounds().size()));
}
bool NativeWindowViews::IsActive() const {
views::Widget* const widget = this->widget();
return widget && widget->IsActive();
}
void NativeWindowViews::FlashFrame(bool flash) {
#if BUILDFLAG(IS_WIN)
// The Chromium's implementation has a bug stopping flash.

View file

@ -103,6 +103,7 @@ class NativeWindowViews : public NativeWindow,
ui::ZOrderLevel GetZOrderLevel() const override;
void Center() override;
void Invalidate() override;
[[nodiscard]] bool IsActive() const override;
void FlashFrame(bool flash) override;
void SetSkipTaskbar(bool skip) override;
void SetExcludedFromShownWindowsMenu(bool excluded) override {}