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")
import("//rlz/buildflags/buildflags.gni")
import("//third_party/protobuf/proto_library.gni")
import("//ui/base/ui_features.gni")
import("//ui/ozone/ozone.gni")
import("//ui/views/features.gni")
# Reset sources_assignment_filter for the BUILD.gn file to prevent
......@@ -3067,12 +3068,19 @@ static_library("ui") {
]
}
if (use_x11) {
if (use_dbus && (use_x11 || ozone_platform_x11)) {
sources += [
"views/frame/global_menu_bar_registrar_x11.cc",
"views/frame/global_menu_bar_registrar_x11.h",
"views/frame/global_menu_bar_x11.cc",
"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/javascript_app_modal_dialog_views_x11.cc",
"views/javascript_app_modal_dialog_views_x11.h",
......@@ -3080,7 +3088,6 @@ static_library("ui") {
"views/javascript_app_modal_event_blocker_x11.h",
]
deps += [
"//components/dbus/menu",
"//ui/events/devices",
"//ui/events/devices/x11",
"//ui/events/platform/x11",
......
......@@ -14,8 +14,23 @@
#include "chrome/browser/ui/views/frame/desktop_browser_frame_aura_linux.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "ui/base/ui_base_features.h"
#include "ui/ozone/public/ozone_platform.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:
......@@ -76,17 +91,19 @@ void BrowserDesktopWindowTreeHostLinux::Init(
const views::Widget::InitParams& params) {
DesktopWindowTreeHostLinuxImpl::Init(std::move(params));
#if defined(USE_X11)
// We have now created our backing X11 window. We now need to (possibly)
// alert Unity that there's a menu bar attached to it.
if (!features::IsUsingOzonePlatform())
global_menu_bar_x11_ =
std::make_unique<GlobalMenuBarX11>(browser_view_, this);
#if defined(USE_DBUS_MENU)
// We have now created our backing X11 window. We now need to (possibly)
// alert the desktop environment that there's a menu bar attached to it.
if (CreateGlobalMenuBar()) {
global_menu_bar_x11_ = std::make_unique<GlobalMenuBarX11>(
browser_view_, GetAcceleratedWidget());
}
#endif
}
void BrowserDesktopWindowTreeHostLinux::CloseNow() {
#if defined(USE_X11)
#if defined(USE_DBUS_MENU)
global_menu_bar_x11_.reset();
#endif
DesktopWindowTreeHostLinuxImpl::CloseNow();
......
......@@ -8,8 +8,11 @@
#include "base/macros.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
#endif
#if defined(USE_X11)
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" // nogncheck
#else
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h" // nogncheck
......@@ -63,7 +66,7 @@ class BrowserDesktopWindowTreeHostLinux
BrowserView* browser_view_ = 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
// level dbus protocol associates a xid to a menu bar; we can't map multiple
// xids to the same menu bar.
......
......@@ -45,7 +45,7 @@ void GlobalMenuBarRegistrarX11::OnMenuBarDestroyed(GlobalMenuBarX11* menu) {
dbus::MethodCall method_call(kAppMenuRegistrarInterface,
"UnregisterWindow");
dbus::MessageWriter writer(&method_call);
writer.AppendUint32(static_cast<uint32_t>(menu->window()));
writer.AppendUint32(menu->browser_frame_xid());
registrar_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
......@@ -90,7 +90,7 @@ void GlobalMenuBarRegistrarX11::RegisterMenu(GlobalMenuBarX11* menu) {
menus_[menu] = kRegistered;
dbus::MethodCall method_call(kAppMenuRegistrarInterface, "RegisterWindow");
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()));
registrar_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, base::DoNothing());
......
......@@ -206,11 +206,11 @@ struct GlobalMenuBarX11::HistoryItem {
};
GlobalMenuBarX11::GlobalMenuBarX11(BrowserView* browser_view,
aura::WindowTreeHost* host)
uint32_t browser_frame_xid)
: browser_(browser_view->browser()),
profile_(browser_->profile()),
browser_view_(browser_view),
window_(static_cast<x11::Window>(host->GetAcceleratedWidget())),
browser_frame_xid_(browser_frame_xid),
tab_restore_service_(nullptr),
last_command_id_(kFirstUnreservedCommandId - 1) {
GlobalMenuBarRegistrarX11::GetInstance()->OnMenuBarCreated(this);
......@@ -285,8 +285,7 @@ void GlobalMenuBarX11::Initialize(DbusMenu::InitializedCallback callback) {
}
std::string GlobalMenuBarX11::GetPath() const {
return base::StringPrintf("/com/canonical/menu/%X",
static_cast<uint32_t>(window_));
return base::StringPrintf("/com/canonical/menu/%X", browser_frame_xid_);
}
ui::SimpleMenuModel* GlobalMenuBarX11::BuildStaticMenu(
......
......@@ -26,8 +26,6 @@
#include "components/sessions/core/tab_restore_service_observer.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_types.h"
namespace ui {
class Accelerator;
......@@ -38,10 +36,12 @@ class BrowserView;
struct GlobalMenuBarCommand;
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
// depending on the active window.
// Unity had a MacOS-like menu bar at the top of the screen that changed
// 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,
public BrowserListObserver,
public CommandObserver,
......@@ -49,7 +49,7 @@ class GlobalMenuBarX11 : public AvatarMenuObserver,
public sessions::TabRestoreServiceObserver,
public ui::SimpleMenuModel::Delegate {
public:
GlobalMenuBarX11(BrowserView* browser_view, aura::WindowTreeHost* host);
GlobalMenuBarX11(BrowserView* browser_view, uint32_t browser_frame_xid);
~GlobalMenuBarX11() override;
void Initialize(DbusMenu::InitializedCallback callback);
......@@ -57,7 +57,7 @@ class GlobalMenuBarX11 : public AvatarMenuObserver,
// Creates the object path for DbusemenuServer which is attached to |window|.
std::string GetPath() const;
x11::Window window() const { return window_; }
uint32_t browser_frame_xid() const { return browser_frame_xid_; }
private:
struct HistoryItem;
......@@ -130,7 +130,12 @@ class GlobalMenuBarX11 : public AvatarMenuObserver,
Browser* const browser_;
Profile* profile_;
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?
bool initialized_ = false;
......
......@@ -71,7 +71,8 @@ constexpr OzonePlatform::PlatformProperties kX11PlatformProperties{
// events. See GLSurfaceGLX and https://crbug.com/326995.
.message_pump_type_for_gpu = base::MessagePumpType::UI,
.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.
class OzonePlatformX11 : public OzonePlatform,
......
......@@ -96,6 +96,10 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform {
// If true, the platform shows and updates the drag image.
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.
......
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