Commit 9fb5db59 authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

[ozone/x11] Enabled the global menu bar for Ozone/X11.

The global menu bar (aka DbusMenu) was originally available only on
non-Ozone, but we can enable it on Ozone/X11 as well.

This CL does some code cleanup and enables the menu for Ozone/X11.

Bug: 990756
Change-Id: I2cd4a504474d31d7e3ced350a8afeeff62e4a778
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2289772
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791140}
parent d0effefb
...@@ -24,6 +24,7 @@ import("//printing/buildflags/buildflags.gni") ...@@ -24,6 +24,7 @@ import("//printing/buildflags/buildflags.gni")
import("//rlz/buildflags/buildflags.gni") import("//rlz/buildflags/buildflags.gni")
import("//third_party/protobuf/proto_library.gni") import("//third_party/protobuf/proto_library.gni")
import("//ui/base/ui_features.gni") import("//ui/base/ui_features.gni")
import("//ui/ozone/ozone.gni")
import("//ui/views/features.gni") import("//ui/views/features.gni")
# Reset sources_assignment_filter for the BUILD.gn file to prevent # Reset sources_assignment_filter for the BUILD.gn file to prevent
...@@ -3067,12 +3068,19 @@ static_library("ui") { ...@@ -3067,12 +3068,19 @@ static_library("ui") {
] ]
} }
if (use_x11) { if (use_dbus && (use_x11 || ozone_platform_x11)) {
sources += [ sources += [
"views/frame/global_menu_bar_registrar_x11.cc", "views/frame/global_menu_bar_registrar_x11.cc",
"views/frame/global_menu_bar_registrar_x11.h", "views/frame/global_menu_bar_registrar_x11.h",
"views/frame/global_menu_bar_x11.cc", "views/frame/global_menu_bar_x11.cc",
"views/frame/global_menu_bar_x11.h", "views/frame/global_menu_bar_x11.h",
]
defines += [ "USE_DBUS_MENU" ]
deps += [ "//ui/gfx/x" ]
}
if (use_x11) {
sources += [
"views/frame/native_browser_frame_factory_aurax11.cc", "views/frame/native_browser_frame_factory_aurax11.cc",
"views/javascript_app_modal_dialog_views_x11.cc", "views/javascript_app_modal_dialog_views_x11.cc",
"views/javascript_app_modal_dialog_views_x11.h", "views/javascript_app_modal_dialog_views_x11.h",
...@@ -3080,7 +3088,6 @@ static_library("ui") { ...@@ -3080,7 +3088,6 @@ static_library("ui") {
"views/javascript_app_modal_event_blocker_x11.h", "views/javascript_app_modal_event_blocker_x11.h",
] ]
deps += [ deps += [
"//components/dbus/menu",
"//ui/events/devices", "//ui/events/devices",
"//ui/events/devices/x11", "//ui/events/devices/x11",
"//ui/events/platform/x11", "//ui/events/platform/x11",
......
...@@ -14,8 +14,23 @@ ...@@ -14,8 +14,23 @@
#include "chrome/browser/ui/views/frame/desktop_browser_frame_aura_linux.h" #include "chrome/browser/ui/views/frame/desktop_browser_frame_aura_linux.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h" #include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/platform_window/extensions/x11_extension.h" #include "ui/platform_window/extensions/x11_extension.h"
namespace {
bool CreateGlobalMenuBar() {
#if defined(USE_OZONE)
return ui::OzonePlatform::GetInstance()
->GetPlatformProperties()
.supports_global_application_menus;
#else
return true;
#endif
}
} // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// BrowserDesktopWindowTreeHostLinux, public: // BrowserDesktopWindowTreeHostLinux, public:
...@@ -76,17 +91,19 @@ void BrowserDesktopWindowTreeHostLinux::Init( ...@@ -76,17 +91,19 @@ void BrowserDesktopWindowTreeHostLinux::Init(
const views::Widget::InitParams& params) { const views::Widget::InitParams& params) {
DesktopWindowTreeHostLinuxImpl::Init(std::move(params)); DesktopWindowTreeHostLinuxImpl::Init(std::move(params));
#if defined(USE_X11) #if defined(USE_DBUS_MENU)
// We have now created our backing X11 window. We now need to (possibly) // We have now created our backing X11 window. We now need to (possibly)
// alert Unity that there's a menu bar attached to it. // alert the desktop environment that there's a menu bar attached to it.
if (!features::IsUsingOzonePlatform())
global_menu_bar_x11_ = if (CreateGlobalMenuBar()) {
std::make_unique<GlobalMenuBarX11>(browser_view_, this); global_menu_bar_x11_ = std::make_unique<GlobalMenuBarX11>(
browser_view_, GetAcceleratedWidget());
}
#endif #endif
} }
void BrowserDesktopWindowTreeHostLinux::CloseNow() { void BrowserDesktopWindowTreeHostLinux::CloseNow() {
#if defined(USE_X11) #if defined(USE_DBUS_MENU)
global_menu_bar_x11_.reset(); global_menu_bar_x11_.reset();
#endif #endif
DesktopWindowTreeHostLinuxImpl::CloseNow(); DesktopWindowTreeHostLinuxImpl::CloseNow();
......
...@@ -8,8 +8,11 @@ ...@@ -8,8 +8,11 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host.h" #include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host.h"
#if defined(USE_X11) #if defined(USE_DBUS_MENU)
#include "chrome/browser/ui/views/frame/global_menu_bar_x11.h" // nogncheck #include "chrome/browser/ui/views/frame/global_menu_bar_x11.h" // nogncheck
#endif
#if defined(USE_X11)
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" // nogncheck #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" // nogncheck
#else #else
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h" // nogncheck #include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h" // nogncheck
...@@ -63,7 +66,7 @@ class BrowserDesktopWindowTreeHostLinux ...@@ -63,7 +66,7 @@ class BrowserDesktopWindowTreeHostLinux
BrowserView* browser_view_ = nullptr; BrowserView* browser_view_ = nullptr;
BrowserFrame* browser_frame_ = nullptr; BrowserFrame* browser_frame_ = nullptr;
#if defined(USE_X11) #if defined(USE_DBUS_MENU)
// Each browser frame maintains its own menu bar object because the lower // Each browser frame maintains its own menu bar object because the lower
// level dbus protocol associates a xid to a menu bar; we can't map multiple // level dbus protocol associates a xid to a menu bar; we can't map multiple
// xids to the same menu bar. // xids to the same menu bar.
......
...@@ -45,7 +45,7 @@ void GlobalMenuBarRegistrarX11::OnMenuBarDestroyed(GlobalMenuBarX11* menu) { ...@@ -45,7 +45,7 @@ void GlobalMenuBarRegistrarX11::OnMenuBarDestroyed(GlobalMenuBarX11* menu) {
dbus::MethodCall method_call(kAppMenuRegistrarInterface, dbus::MethodCall method_call(kAppMenuRegistrarInterface,
"UnregisterWindow"); "UnregisterWindow");
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendUint32(static_cast<uint32_t>(menu->window())); writer.AppendUint32(menu->browser_frame_xid());
registrar_proxy_->CallMethod(&method_call, registrar_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing()); base::DoNothing());
...@@ -90,7 +90,7 @@ void GlobalMenuBarRegistrarX11::RegisterMenu(GlobalMenuBarX11* menu) { ...@@ -90,7 +90,7 @@ void GlobalMenuBarRegistrarX11::RegisterMenu(GlobalMenuBarX11* menu) {
menus_[menu] = kRegistered; menus_[menu] = kRegistered;
dbus::MethodCall method_call(kAppMenuRegistrarInterface, "RegisterWindow"); dbus::MethodCall method_call(kAppMenuRegistrarInterface, "RegisterWindow");
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
writer.AppendUint32(static_cast<uint32_t>(menu->window())); writer.AppendUint32(menu->browser_frame_xid());
writer.AppendObjectPath(dbus::ObjectPath(menu->GetPath())); writer.AppendObjectPath(dbus::ObjectPath(menu->GetPath()));
registrar_proxy_->CallMethod( registrar_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, base::DoNothing()); &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, base::DoNothing());
......
...@@ -206,11 +206,11 @@ struct GlobalMenuBarX11::HistoryItem { ...@@ -206,11 +206,11 @@ struct GlobalMenuBarX11::HistoryItem {
}; };
GlobalMenuBarX11::GlobalMenuBarX11(BrowserView* browser_view, GlobalMenuBarX11::GlobalMenuBarX11(BrowserView* browser_view,
aura::WindowTreeHost* host) uint32_t browser_frame_xid)
: browser_(browser_view->browser()), : browser_(browser_view->browser()),
profile_(browser_->profile()), profile_(browser_->profile()),
browser_view_(browser_view), browser_view_(browser_view),
window_(static_cast<x11::Window>(host->GetAcceleratedWidget())), browser_frame_xid_(browser_frame_xid),
tab_restore_service_(nullptr), tab_restore_service_(nullptr),
last_command_id_(kFirstUnreservedCommandId - 1) { last_command_id_(kFirstUnreservedCommandId - 1) {
GlobalMenuBarRegistrarX11::GetInstance()->OnMenuBarCreated(this); GlobalMenuBarRegistrarX11::GetInstance()->OnMenuBarCreated(this);
...@@ -285,8 +285,7 @@ void GlobalMenuBarX11::Initialize(DbusMenu::InitializedCallback callback) { ...@@ -285,8 +285,7 @@ void GlobalMenuBarX11::Initialize(DbusMenu::InitializedCallback callback) {
} }
std::string GlobalMenuBarX11::GetPath() const { std::string GlobalMenuBarX11::GetPath() const {
return base::StringPrintf("/com/canonical/menu/%X", return base::StringPrintf("/com/canonical/menu/%X", browser_frame_xid_);
static_cast<uint32_t>(window_));
} }
ui::SimpleMenuModel* GlobalMenuBarX11::BuildStaticMenu( ui::SimpleMenuModel* GlobalMenuBarX11::BuildStaticMenu(
......
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
#include "components/sessions/core/tab_restore_service_observer.h" #include "components/sessions/core/tab_restore_service_observer.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_types.h"
namespace ui { namespace ui {
class Accelerator; class Accelerator;
...@@ -38,10 +36,12 @@ class BrowserView; ...@@ -38,10 +36,12 @@ class BrowserView;
struct GlobalMenuBarCommand; struct GlobalMenuBarCommand;
class Profile; class Profile;
// Controls the Mac style menu bar on Unity. // Controls the Mac style menu bar on Linux desktop environments.
// //
// Unity has an Apple-like menu bar at the top of the screen that changes // Unity had a MacOS-like menu bar at the top of the screen that changed
// depending on the active window. // depending on the active window. Unity has been discontinued but the menu
// survived and is usually referred to as DBus AppMenu. There is support for it
// in KDE Plasma in form of a widget that can be inserted into a panel.
class GlobalMenuBarX11 : public AvatarMenuObserver, class GlobalMenuBarX11 : public AvatarMenuObserver,
public BrowserListObserver, public BrowserListObserver,
public CommandObserver, public CommandObserver,
...@@ -49,7 +49,7 @@ class GlobalMenuBarX11 : public AvatarMenuObserver, ...@@ -49,7 +49,7 @@ class GlobalMenuBarX11 : public AvatarMenuObserver,
public sessions::TabRestoreServiceObserver, public sessions::TabRestoreServiceObserver,
public ui::SimpleMenuModel::Delegate { public ui::SimpleMenuModel::Delegate {
public: public:
GlobalMenuBarX11(BrowserView* browser_view, aura::WindowTreeHost* host); GlobalMenuBarX11(BrowserView* browser_view, uint32_t browser_frame_xid);
~GlobalMenuBarX11() override; ~GlobalMenuBarX11() override;
void Initialize(DbusMenu::InitializedCallback callback); void Initialize(DbusMenu::InitializedCallback callback);
...@@ -57,7 +57,7 @@ class GlobalMenuBarX11 : public AvatarMenuObserver, ...@@ -57,7 +57,7 @@ class GlobalMenuBarX11 : public AvatarMenuObserver,
// Creates the object path for DbusemenuServer which is attached to |window|. // Creates the object path for DbusemenuServer which is attached to |window|.
std::string GetPath() const; std::string GetPath() const;
x11::Window window() const { return window_; } uint32_t browser_frame_xid() const { return browser_frame_xid_; }
private: private:
struct HistoryItem; struct HistoryItem;
...@@ -130,7 +130,12 @@ class GlobalMenuBarX11 : public AvatarMenuObserver, ...@@ -130,7 +130,12 @@ class GlobalMenuBarX11 : public AvatarMenuObserver,
Browser* const browser_; Browser* const browser_;
Profile* profile_; Profile* profile_;
BrowserView* browser_view_; BrowserView* browser_view_;
x11::Window window_; // XID of the browser's frame window that owns this menu. Deliberately stored
// as plain int (and not as x11::Window) because it is never used for any
// calls to the X server, but it is always used for building string paths and
// messages, for which it is converted to int (see GetPath() and calls to our
// browser_frame_xid() in GlobalMenuBarRegistrarX11).
const uint32_t browser_frame_xid_;
// Has Initialize() been called? // Has Initialize() been called?
bool initialized_ = false; bool initialized_ = false;
......
...@@ -71,7 +71,8 @@ constexpr OzonePlatform::PlatformProperties kX11PlatformProperties{ ...@@ -71,7 +71,8 @@ constexpr OzonePlatform::PlatformProperties kX11PlatformProperties{
// events. See GLSurfaceGLX and https://crbug.com/326995. // events. See GLSurfaceGLX and https://crbug.com/326995.
.message_pump_type_for_gpu = base::MessagePumpType::UI, .message_pump_type_for_gpu = base::MessagePumpType::UI,
.supports_vulkan_swap_chain = true, .supports_vulkan_swap_chain = true,
.platform_shows_drag_image = false}; .platform_shows_drag_image = false,
.supports_global_application_menus = true};
// Singleton OzonePlatform implementation for X11 platform. // Singleton OzonePlatform implementation for X11 platform.
class OzonePlatformX11 : public OzonePlatform, class OzonePlatformX11 : public OzonePlatform,
......
...@@ -96,6 +96,10 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform { ...@@ -96,6 +96,10 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform {
// If true, the platform shows and updates the drag image. // If true, the platform shows and updates the drag image.
bool platform_shows_drag_image = true; bool platform_shows_drag_image = true;
// Linux only, but see a TODO in BrowserDesktopWindowTreeHostLinux.
// Determines whether the platform supports the global application menu.
bool supports_global_application_menus = false;
}; };
// Properties available in the host process after initialization. // Properties available in the host process after initialization.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment