From af31ce0135367fa698c94ec5bed2717c99b84d50 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 15 May 2025 19:38:44 -0500 Subject: [PATCH] refactor: decouple NativeWindowViews and GlobalMenuBarX11 (#47117) The GlobalMenuBar used to hold a raw_ptr reference to its NativeWindow; but since it doesn't use it & only wants the gfx::AcceleratedWidget info, let's remove the NativeWindowViews reference. AFAICT, GlobalMenuBarX11::window_ has never been used Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/browser/native_window_views.cc | 3 ++- shell/browser/ui/views/global_menu_bar_x11.cc | 7 ++----- shell/browser/ui/views/global_menu_bar_x11.h | 5 +---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 1b44c5207e92..6981cf96b4af 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1397,7 +1397,8 @@ void NativeWindowViews::SetMenu(ElectronMenuModel* menu_model) { .supports_global_application_menus; if (can_use_global_menus && ShouldUseGlobalMenuBar()) { if (!global_menu_bar_) - global_menu_bar_ = std::make_unique(this); + global_menu_bar_ = + std::make_unique(GetAcceleratedWidget()); if (global_menu_bar_->IsServerStarted()) { root_view_.RegisterAcceleratorsWithFocusManager(menu_model); global_menu_bar_->SetMenu(menu_model); diff --git a/shell/browser/ui/views/global_menu_bar_x11.cc b/shell/browser/ui/views/global_menu_bar_x11.cc index 021c7c46afcb..e28b86e25e15 100644 --- a/shell/browser/ui/views/global_menu_bar_x11.cc +++ b/shell/browser/ui/views/global_menu_bar_x11.cc @@ -9,7 +9,6 @@ #include "base/functional/bind.h" #include "base/strings/utf_string_conversions.h" -#include "shell/browser/native_window_views.h" #include "shell/browser/ui/electron_menu_model.h" #include "shell/browser/ui/views/global_menu_bar_registrar_x11.h" #include "third_party/abseil-cpp/absl/strings/str_format.h" @@ -173,10 +172,8 @@ std::string GetMenuModelStatus(ElectronMenuModel* model) { } // namespace -GlobalMenuBarX11::GlobalMenuBarX11(NativeWindowViews* window) - : window_(window), - xwindow_(static_cast( - window_->GetNativeWindow()->GetHost()->GetAcceleratedWidget())) { +GlobalMenuBarX11::GlobalMenuBarX11(gfx::AcceleratedWidget accelerated_widget) + : xwindow_(static_cast(accelerated_widget)) { EnsureMethodsLoaded(); if (server_new) InitServer(xwindow_); diff --git a/shell/browser/ui/views/global_menu_bar_x11.h b/shell/browser/ui/views/global_menu_bar_x11.h index 893f2cf6a040..0851822fc3f1 100644 --- a/shell/browser/ui/views/global_menu_bar_x11.h +++ b/shell/browser/ui/views/global_menu_bar_x11.h @@ -22,8 +22,6 @@ class Accelerator; namespace electron { -class NativeWindowViews; - // Controls the Mac style menu bar on Unity. // // Unity has an Apple-like menu bar at the top of the screen that changes @@ -37,7 +35,7 @@ class NativeWindowViews; // from menu models instead, and it is also per-window specific. class GlobalMenuBarX11 { public: - explicit GlobalMenuBarX11(NativeWindowViews* window); + explicit GlobalMenuBarX11(gfx::AcceleratedWidget accelerated_widget); virtual ~GlobalMenuBarX11(); // disable copy @@ -68,7 +66,6 @@ class GlobalMenuBarX11 { void OnItemActivated(DbusmenuMenuitem* item, unsigned int timestamp); void OnSubMenuShow(DbusmenuMenuitem* item); - raw_ptr window_; x11::Window xwindow_; raw_ptr server_ = nullptr;