diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 1b764296d5dc..fb2f037b7808 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -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; diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index 1c9bbdd9ead4..29c597fd744d 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -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; diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 104167015e94..1625063c7671 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -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. diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index a9b4ba0f2103..801d8f5fc00e 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -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 {}