Refactor GTK build target and dependencies
This CL removes the ozone->gtk dependency to fix bug 1198747, which opens up several other cleanups: * ui/gtk/x and ui/gtk/wayland can be moved into ui/gtk * //ui/gtk:gtk_compat used to be linked into multiple components, but now is linked into just libgtk.so * Dependencies on //ui/gtk/x and //ui/gtk/wayland can be removed * gtk_unittests no longer needs to be a friend target This CL also includes trivial renaming, iwyu, etc. BUG=1192861,1198747 R=sky CC=lambroslambrou,nickdiego Change-Id: I26a9e2fa4fbf035f78c0b66afe9391fc70c49195 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2836669 Reviewed-by: danakj <danakj@chromium.org> Reviewed-by: Nick Yamane <nickdiego@igalia.com> Reviewed-by: Lambros Lambrou <lambroslambrou@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Commit-Queue: Thomas Anderson <thomasanderson@chromium.org> Auto-Submit: Thomas Anderson <thomasanderson@chromium.org> Cr-Commit-Position: refs/heads/master@{#874401}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
5f4035faaa
commit
bf89dc63f3
build/config/linux/gtk
chrome/browser/ui
BUILD.gn
views
content/shell
remoting/host
ui
base
gtk
BUILD.gngtk_key_bindings_handler.ccgtk_key_bindings_handler.hgtk_types.hgtk_ui.ccgtk_ui.hgtk_ui_delegate.ccgtk_ui_factory.ccgtk_ui_factory.hgtk_ui_platform.hgtk_util.ccgtk_util.hinput_method_context_impl_gtk.ccnative_theme_gtk.ccnative_theme_gtk.hnative_theme_gtk_unittest.ccnav_button_provider_gtk.ccnav_button_provider_gtk.h
printing
select_file_dialog_impl_gtk.ccwayland
x
ozone
BUILD.gn
platform
views
linux_ui
@ -7,7 +7,11 @@ import("//build/config/linux/pkg_config.gni")
|
||||
|
||||
assert(is_linux, "This file should only be referenced on Linux")
|
||||
|
||||
assert(gtk_version == 3 || gtk_version == 4)
|
||||
declare_args() {
|
||||
# The (major) version of GTK to build against. A different version may be
|
||||
# loaded at runtime.
|
||||
gtk_version = 3
|
||||
}
|
||||
|
||||
# GN doesn't check visibility for configs so we give this an obviously internal
|
||||
# name to discourage random targets from accidentally depending on this and
|
||||
@ -22,18 +26,18 @@ pkg_config("gtk_internal_config") {
|
||||
if (gtk_version == 3) {
|
||||
packages += [ "gtk+-3.0" ]
|
||||
} else {
|
||||
assert(gtk_version == 4)
|
||||
packages += [ "gtk4" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("gtk") {
|
||||
visibility = [
|
||||
# These are the only directories that should depend on GTK.
|
||||
"//ui/gtk:*",
|
||||
"//ui/gtk/wayland",
|
||||
"//ui/gtk/x",
|
||||
# This is the only target that can depend on GTK. Do not add more targets
|
||||
# to this list.
|
||||
"//ui/gtk:gtk_stubs",
|
||||
|
||||
# These are all for WebRTC.
|
||||
# These are allow-listed for WebRTC builds.
|
||||
"//examples:peerconnection_client",
|
||||
"//remoting/host:common",
|
||||
"//remoting/host:remoting_me2me_host_static",
|
||||
@ -53,6 +57,7 @@ pkg_config("gtkprint_internal_config") {
|
||||
if (gtk_version == 3) {
|
||||
packages = [ "gtk+-unix-print-3.0" ]
|
||||
} else {
|
||||
assert(gtk_version == 4)
|
||||
packages = [ "gtk4-unix-print" ]
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,4 @@ import("//build/config/ui.gni")
|
||||
declare_args() {
|
||||
# Whether or not we should use libgtk.
|
||||
use_gtk = is_linux && !is_chromecast
|
||||
|
||||
# The (major) version of GTK to build against.
|
||||
gtk_version = 3
|
||||
}
|
||||
|
||||
assert(gtk_version >= 3 && gtk_version <= 4)
|
||||
|
@ -4470,12 +4470,6 @@ static_library("ui") {
|
||||
]
|
||||
if (use_gtk) {
|
||||
deps += [ "//ui/gtk" ]
|
||||
if (use_x11) {
|
||||
deps += [
|
||||
"//ui/gfx/x",
|
||||
"//ui/gtk/x",
|
||||
]
|
||||
}
|
||||
if (use_ozone) {
|
||||
deps += [ "//ui/ozone" ]
|
||||
}
|
||||
|
@ -7,14 +7,14 @@
|
||||
#include "chrome/browser/themes/theme_service_aura_linux.h"
|
||||
#include "chrome/browser/ui/browser_list.h"
|
||||
#include "chrome/browser/ui/views/theme_profile_key.h"
|
||||
#include "ui/base/buildflags.h"
|
||||
#include "ui/base/cursor/cursor_factory.h"
|
||||
#include "ui/base/ime/linux/fake_input_method_context_factory.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/views/linux_ui/linux_ui.h"
|
||||
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
#include "ui/gtk/gtk_ui.h"
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
#include "ui/gtk/gtk_ui_factory.h"
|
||||
#endif
|
||||
|
||||
#if defined(USE_OZONE)
|
||||
@ -23,24 +23,14 @@
|
||||
#include "ui/ozone/public/ozone_platform.h"
|
||||
#endif
|
||||
|
||||
#if defined(USE_X11)
|
||||
#include "ui/gfx/x/connection.h" // nogncheck
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
#include "ui/base/ui_base_features.h"
|
||||
#include "ui/gtk/x/gtk_ui_delegate_x11.h" // nogncheck
|
||||
#endif // BUILDFLAG(USE_GTK)
|
||||
#endif // defined(USE_X11)
|
||||
|
||||
namespace {
|
||||
|
||||
views::LinuxUI* BuildLinuxUI() {
|
||||
views::LinuxUI* linux_ui = nullptr;
|
||||
std::unique_ptr<views::LinuxUI> BuildLinuxUI() {
|
||||
// GtkUi is the only LinuxUI implementation for now.
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
if (ui::GtkUiDelegate::instance())
|
||||
linux_ui = BuildGtkUi(ui::GtkUiDelegate::instance());
|
||||
return BuildGtkUi();
|
||||
#endif
|
||||
return linux_ui;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -57,21 +47,9 @@ ChromeBrowserMainExtraPartsViewsLinux::
|
||||
}
|
||||
|
||||
void ChromeBrowserMainExtraPartsViewsLinux::ToolkitInitialized() {
|
||||
#if defined(USE_X11) && BUILDFLAG(USE_GTK)
|
||||
if (!features::IsUsingOzonePlatform()) {
|
||||
// In Aura/X11, Gtk-based LinuxUI implementation is used, so we instantiate
|
||||
// and inject the GtkUiDelegate before
|
||||
// ChromeBrowserMainExtraPartsViewsLinux, so it can properly initialize
|
||||
// GtkUi on its |ToolkitInitialized| override.
|
||||
gtk_ui_delegate_ =
|
||||
std::make_unique<ui::GtkUiDelegateX11>(x11::Connection::Get());
|
||||
ui::GtkUiDelegate::SetInstance(gtk_ui_delegate_.get());
|
||||
}
|
||||
#endif
|
||||
|
||||
ChromeBrowserMainExtraPartsViews::ToolkitInitialized();
|
||||
|
||||
views::LinuxUI* linux_ui = BuildLinuxUI();
|
||||
auto linux_ui = BuildLinuxUI();
|
||||
if (!linux_ui) {
|
||||
// In case if GTK is not used, input method factory won't be set for X11 and
|
||||
// Ozone/X11. Set a fake one instead to avoid crashing browser later.
|
||||
@ -100,12 +78,8 @@ void ChromeBrowserMainExtraPartsViewsLinux::ToolkitInitialized() {
|
||||
GetThemeProfileForWindow(window));
|
||||
}));
|
||||
|
||||
// Update the device scale factor before initializing views
|
||||
// because its display::Screen instance depends on it.
|
||||
linux_ui->UpdateDeviceScaleFactor();
|
||||
|
||||
views::LinuxUI::SetInstance(linux_ui);
|
||||
linux_ui->Initialize();
|
||||
views::LinuxUI::SetInstance(std::move(linux_ui));
|
||||
|
||||
// Cursor theme changes are tracked by LinuxUI (via a CursorThemeManager
|
||||
// implementation). Start observing them once it's initialized.
|
||||
|
@ -11,15 +11,8 @@
|
||||
#include "base/macros.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
|
||||
#include "ui/base/buildflags.h"
|
||||
#include "ui/display/display_observer.h"
|
||||
|
||||
#if defined(USE_X11) && BUILDFLAG(USE_GTK)
|
||||
namespace ui {
|
||||
class GtkUiDelegate;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Extra parts, which are used by both Ozone/X11/Wayland and inherited by the
|
||||
// non-ozone X11 extra parts.
|
||||
class ChromeBrowserMainExtraPartsViewsLinux
|
||||
@ -37,10 +30,6 @@ class ChromeBrowserMainExtraPartsViewsLinux
|
||||
// display::DisplayObserver:
|
||||
void OnCurrentWorkspaceChanged(const std::string& new_workspace) override;
|
||||
|
||||
#if defined(USE_X11) && BUILDFLAG(USE_GTK)
|
||||
std::unique_ptr<ui::GtkUiDelegate> gtk_ui_delegate_;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsViewsLinux);
|
||||
};
|
||||
|
||||
|
@ -296,12 +296,6 @@ static_library("content_shell_lib") {
|
||||
|
||||
if (use_gtk) {
|
||||
deps += [ "//ui/gtk" ]
|
||||
if (use_x11 || ozone_platform_x11) {
|
||||
deps += [
|
||||
"//ui/gfx/x",
|
||||
"//ui/gtk/x",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (use_x11) {
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "net/base/filename_util.h"
|
||||
#include "net/base/net_module.h"
|
||||
#include "net/grit/net_resources.h"
|
||||
#include "ui/base/buildflags.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
@ -67,11 +68,8 @@
|
||||
#endif // #elif (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
|
||||
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
#include "ui/gtk/gtk_ui.h"
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
#if defined(USE_X11)
|
||||
#include "ui/gtk/x/gtk_ui_delegate_x11.h" // nogncheck
|
||||
#endif
|
||||
#include "ui/gtk/gtk_ui_factory.h"
|
||||
#include "ui/views/linux_ui/linux_ui.h" // nogncheck
|
||||
#endif
|
||||
|
||||
namespace content {
|
||||
@ -116,12 +114,9 @@ scoped_refptr<base::RefCountedMemory> PlatformResourceProvider(int key) {
|
||||
|
||||
ShellBrowserMainParts::ShellBrowserMainParts(
|
||||
const MainFunctionParams& parameters)
|
||||
: parameters_(parameters),
|
||||
run_message_loop_(true) {
|
||||
}
|
||||
: parameters_(parameters), run_message_loop_(true) {}
|
||||
|
||||
ShellBrowserMainParts::~ShellBrowserMainParts() {
|
||||
}
|
||||
ShellBrowserMainParts::~ShellBrowserMainParts() = default;
|
||||
|
||||
#if !defined(OS_MAC)
|
||||
void ShellBrowserMainParts::PreMainMessageLoopStart() {
|
||||
@ -165,24 +160,13 @@ void ShellBrowserMainParts::InitializeMessageLoopContext() {
|
||||
// Copied from ChromeBrowserMainExtraPartsViewsLinux::ToolkitInitialized().
|
||||
// See that function for details.
|
||||
void ShellBrowserMainParts::ToolkitInitialized() {
|
||||
#if BUILDFLAG(USE_GTK) && defined(USE_X11)
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
if (switches::IsRunWebTestsSwitchPresent())
|
||||
return;
|
||||
#if defined(USE_OZONE)
|
||||
if (!features::IsUsingOzonePlatform()) {
|
||||
// Ozone platform initialises the instance of GtkUiDelegate in its
|
||||
// InitializeUI() method and owns it.
|
||||
gtk_ui_delegate_ =
|
||||
std::make_unique<ui::GtkUiDelegateX11>(x11::Connection::Get());
|
||||
ui::GtkUiDelegate::SetInstance(gtk_ui_delegate_.get());
|
||||
}
|
||||
#endif
|
||||
if (ui::GtkUiDelegate::instance()) {
|
||||
views::LinuxUI* linux_ui = BuildGtkUi(ui::GtkUiDelegate::instance());
|
||||
linux_ui->UpdateDeviceScaleFactor();
|
||||
views::LinuxUI::SetInstance(linux_ui);
|
||||
linux_ui->Initialize();
|
||||
}
|
||||
|
||||
auto linux_ui = BuildGtkUi();
|
||||
linux_ui->Initialize();
|
||||
views::LinuxUI::SetInstance(std::move(linux_ui));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -255,4 +239,4 @@ ShellBrowserMainParts::CreateShellPlatformDelegate() {
|
||||
return std::make_unique<ShellPlatformDelegate>();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace content
|
||||
|
@ -13,18 +13,11 @@
|
||||
#include "content/public/browser/browser_main_parts.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "content/shell/browser/shell_browser_context.h"
|
||||
#include "ui/base/buildflags.h"
|
||||
|
||||
namespace performance_manager {
|
||||
class PerformanceManagerLifetime;
|
||||
} // namespace performance_manager
|
||||
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
namespace ui {
|
||||
class GtkUiDelegate;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace content {
|
||||
class ShellPlatformDelegate;
|
||||
|
||||
@ -66,7 +59,6 @@ class ShellBrowserMainParts : public BrowserMainParts {
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::unique_ptr<ShellBrowserContext> browser_context_;
|
||||
std::unique_ptr<ShellBrowserContext> off_the_record_browser_context_;
|
||||
|
||||
@ -74,10 +66,6 @@ class ShellBrowserMainParts : public BrowserMainParts {
|
||||
const MainFunctionParams parameters_;
|
||||
bool run_message_loop_;
|
||||
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
std::unique_ptr<ui::GtkUiDelegate> gtk_ui_delegate_;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<performance_manager::PerformanceManagerLifetime>
|
||||
performance_manager_lifetime_;
|
||||
|
||||
|
@ -942,7 +942,7 @@ if (enable_me2me_host) {
|
||||
deps = [ "//remoting/host/mac:remoting_me2me_host" ]
|
||||
}
|
||||
} else {
|
||||
target("executable", "remoting_me2me_host") {
|
||||
executable("remoting_me2me_host") {
|
||||
configs += [ "//remoting/build/config:version" ]
|
||||
|
||||
sources = [
|
||||
@ -961,6 +961,9 @@ if (enable_me2me_host) {
|
||||
"//remoting/host/setup:common",
|
||||
"//remoting/resources",
|
||||
]
|
||||
|
||||
# https://crbug.com/1198747
|
||||
assert_no_deps = [ "//ui/gtk" ]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -358,6 +358,8 @@ component("base") {
|
||||
"accelerators/menu_label_accelerator_util_linux.h",
|
||||
"linux/linux_desktop.cc",
|
||||
"linux/linux_desktop.h",
|
||||
"linux/linux_ui_delegate.cc",
|
||||
"linux/linux_ui_delegate.h",
|
||||
]
|
||||
}
|
||||
|
||||
|
46
ui/base/linux/linux_ui_delegate.cc
Normal file
46
ui/base/linux/linux_ui_delegate.cc
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ui/base/linux/linux_ui_delegate.h"
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/notreached.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
// static
|
||||
LinuxUiDelegate* LinuxUiDelegate::instance_ = nullptr;
|
||||
|
||||
// static
|
||||
LinuxUiDelegate* LinuxUiDelegate::GetInstance() {
|
||||
return instance_;
|
||||
}
|
||||
|
||||
LinuxUiDelegate::LinuxUiDelegate() {
|
||||
DCHECK(!instance_);
|
||||
instance_ = this;
|
||||
}
|
||||
|
||||
LinuxUiDelegate::~LinuxUiDelegate() {
|
||||
DCHECK_EQ(instance_, this);
|
||||
instance_ = nullptr;
|
||||
}
|
||||
|
||||
bool LinuxUiDelegate::SetWidgetTransientFor(
|
||||
uint32_t parent_widget,
|
||||
base::OnceCallback<void(const std::string&)> callback) {
|
||||
// This function should not be called when using a platform that doesn't
|
||||
// implement it.
|
||||
NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
int LinuxUiDelegate::GetKeyState() {
|
||||
// This function should not be called when using a platform that doesn't
|
||||
// implement it.
|
||||
NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace ui
|
44
ui/base/linux/linux_ui_delegate.h
Normal file
44
ui/base/linux/linux_ui_delegate.h
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef UI_BASE_LINUX_LINUX_UI_DELEGATE_H_
|
||||
#define UI_BASE_LINUX_LINUX_UI_DELEGATE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "base/callback_forward.h"
|
||||
#include "base/component_export.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
enum class LinuxUiBackend {
|
||||
kX11,
|
||||
kWayland,
|
||||
};
|
||||
|
||||
class COMPONENT_EXPORT(UI_BASE) LinuxUiDelegate {
|
||||
public:
|
||||
static LinuxUiDelegate* GetInstance();
|
||||
|
||||
LinuxUiDelegate();
|
||||
virtual ~LinuxUiDelegate();
|
||||
|
||||
virtual LinuxUiBackend GetBackend() const = 0;
|
||||
|
||||
// Only implemented on Wayland.
|
||||
virtual bool SetWidgetTransientFor(
|
||||
uint32_t parent_widget,
|
||||
base::OnceCallback<void(const std::string&)> callback);
|
||||
|
||||
// Only implemented on Wayland.
|
||||
virtual int GetKeyState();
|
||||
|
||||
private:
|
||||
static LinuxUiDelegate* instance_;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif // UI_BASE_LINUX_LINUX_UI_DELEGATE_H_
|
@ -4,7 +4,6 @@
|
||||
|
||||
import("//build/config/chromeos/ui_mode.gni")
|
||||
import("//build/config/features.gni")
|
||||
import("//build/config/linux/gtk/gtk.gni")
|
||||
import("//build/config/ozone.gni")
|
||||
import("//build/config/ui.gni")
|
||||
import("//printing/buildflags/buildflags.gni")
|
||||
@ -15,10 +14,12 @@ assert(is_linux || is_chromeos_lacros || is_chromeos,
|
||||
"This file should only be referenced on Linux")
|
||||
|
||||
source_set("gtk_types") {
|
||||
sources = [ "gtk_types.h" ]
|
||||
visibility = [ ":gtk_stubs" ]
|
||||
public = [ "gtk_types.h" ]
|
||||
}
|
||||
|
||||
generate_stubs("gtk_stubs") {
|
||||
visibility = [ ":gtk" ]
|
||||
sigs = [
|
||||
"gdk_pixbuf.sigs",
|
||||
"gdk.sigs",
|
||||
@ -28,7 +29,7 @@ generate_stubs("gtk_stubs") {
|
||||
]
|
||||
extra_header = "gtk.fragment"
|
||||
output_name = "gtk_stubs"
|
||||
deps = [
|
||||
public_deps = [
|
||||
":gtk_types",
|
||||
"//build/config/linux/gtk",
|
||||
"//build/config/linux/gtk:gtkprint",
|
||||
@ -37,45 +38,20 @@ generate_stubs("gtk_stubs") {
|
||||
logging_include = "ui/gtk/log_noop.h"
|
||||
}
|
||||
|
||||
source_set("gtk_compat") {
|
||||
sources = [
|
||||
"gtk_compat.cc",
|
||||
"gtk_compat.h",
|
||||
]
|
||||
deps = [
|
||||
":gtk_stubs",
|
||||
":gtk_types",
|
||||
"//base",
|
||||
"//ui/base",
|
||||
"//ui/gfx",
|
||||
]
|
||||
public_deps = [
|
||||
"//build/config/linux/gtk",
|
||||
"//build/config/linux/gtk:gtkprint",
|
||||
]
|
||||
}
|
||||
|
||||
component("gtk_ui_delegate") {
|
||||
public = [ "gtk_ui_delegate.h" ]
|
||||
sources = [ "gtk_ui_delegate.cc" ]
|
||||
deps = [
|
||||
"//base",
|
||||
"//ui/gfx",
|
||||
]
|
||||
defines = [ "IS_GTK_IMPL" ]
|
||||
}
|
||||
|
||||
component("gtk") {
|
||||
public = [ "gtk_ui.h" ]
|
||||
|
||||
friend = [ ":gtk_unittests" ]
|
||||
public = [ "gtk_ui_factory.h" ]
|
||||
|
||||
sources = [
|
||||
"gtk_color_mixers.cc",
|
||||
"gtk_color_mixers.h",
|
||||
"gtk_compat.cc",
|
||||
"gtk_compat.h",
|
||||
"gtk_key_bindings_handler.cc",
|
||||
"gtk_key_bindings_handler.h",
|
||||
"gtk_ui.cc",
|
||||
"gtk_ui.h",
|
||||
"gtk_ui_factory.cc",
|
||||
"gtk_ui_platform.h",
|
||||
"gtk_util.cc",
|
||||
"gtk_util.h",
|
||||
"input_method_context_impl_gtk.cc",
|
||||
@ -112,10 +88,8 @@ component("gtk") {
|
||||
}
|
||||
|
||||
deps = [
|
||||
":gtk_compat",
|
||||
":gtk_stubs",
|
||||
"//base",
|
||||
"//build/config/linux/gtk",
|
||||
"//build/config/linux/gtk:gtkprint",
|
||||
"//printing",
|
||||
"//skia",
|
||||
|
||||
@ -148,7 +122,26 @@ component("gtk") {
|
||||
deps += [ "//printing/mojom" ]
|
||||
}
|
||||
|
||||
public_deps = [ ":gtk_ui_delegate" ]
|
||||
if (use_x11 || ozone_platform_x11) {
|
||||
sources += [
|
||||
"x/gtk_event_loop_x11.cc",
|
||||
"x/gtk_event_loop_x11.h",
|
||||
"x/gtk_ui_platform_x11.cc",
|
||||
"x/gtk_ui_platform_x11.h",
|
||||
]
|
||||
deps += [
|
||||
"//ui/events/platform/x11",
|
||||
"//ui/gfx/x",
|
||||
"//ui/platform_window/x11",
|
||||
]
|
||||
}
|
||||
|
||||
if (ozone_platform_wayland) {
|
||||
sources += [
|
||||
"wayland/gtk_ui_platform_wayland.cc",
|
||||
"wayland/gtk_ui_platform_wayland.h",
|
||||
]
|
||||
}
|
||||
|
||||
# TODO: This should be removed.
|
||||
if (use_ozone) {
|
||||
@ -163,15 +156,10 @@ test("gtk_unittests") {
|
||||
":gtk",
|
||||
"//base/test:run_all_unittests",
|
||||
"//base/test:test_support",
|
||||
|
||||
# Required so that including gtk_util.h can resolve <gtk/gtk.h>.
|
||||
"//build/config/linux/gtk",
|
||||
|
||||
# Required so that including gtk_util.h can resolve <gtk/gtkunixprint.h>.
|
||||
"//build/config/linux/gtk:gtkprint",
|
||||
"//testing/gtest",
|
||||
"//ui/base:features",
|
||||
"//ui/native_theme",
|
||||
"//ui/native_theme:test_support",
|
||||
"//ui/views",
|
||||
]
|
||||
}
|
||||
|
@ -4,9 +4,7 @@
|
||||
|
||||
#include "ui/gtk/gtk_key_bindings_handler.h"
|
||||
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
#include "base/logging.h"
|
||||
|
@ -5,8 +5,6 @@
|
||||
#ifndef UI_GTK_GTK_KEY_BINDINGS_HANDLER_H_
|
||||
#define UI_GTK_GTK_KEY_BINDINGS_HANDLER_H_
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -54,7 +54,7 @@ using GdkSurface = struct _GdkSurface;
|
||||
using GdkToplevel = struct _GdkToplevel;
|
||||
|
||||
constexpr GdkMemoryFormat GDK_MEMORY_B8G8R8A8 = static_cast<GdkMemoryFormat>(3);
|
||||
#else
|
||||
#elif GTK_MAJOR_VERSION == 4
|
||||
enum GtkWidgetHelpType : int;
|
||||
enum GtkWindowType : int;
|
||||
|
||||
@ -97,6 +97,8 @@ constexpr int GTK_ICON_LOOKUP_FORCE_SIZE = 1 << 4;
|
||||
constexpr const char GTK_STYLE_PROPERTY_BACKGROUND_IMAGE[] = "background-image";
|
||||
|
||||
constexpr auto GTK_WINDOW_TOPLEVEL = static_cast<GtkWindowType>(0);
|
||||
#else
|
||||
#error "Unsupported GTK version"
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,6 @@
|
||||
#include "ui/gtk/gtk_ui.h"
|
||||
|
||||
#include <cairo.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
#include <cmath>
|
||||
@ -35,6 +33,7 @@
|
||||
#include "ui/base/ime/linux/fake_input_method_context.h"
|
||||
#include "ui/base/ime/linux/linux_input_method_context.h"
|
||||
#include "ui/base/ime/linux/linux_input_method_context_factory.h"
|
||||
#include "ui/base/linux/linux_ui_delegate.h"
|
||||
#include "ui/display/display.h"
|
||||
#include "ui/events/keycodes/dom/dom_code.h"
|
||||
#include "ui/events/keycodes/dom/dom_keyboard_layout_manager.h"
|
||||
@ -49,7 +48,7 @@
|
||||
#include "ui/gfx/skia_util.h"
|
||||
#include "ui/gtk/gtk_compat.h"
|
||||
#include "ui/gtk/gtk_key_bindings_handler.h"
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
#include "ui/gtk/gtk_ui_platform.h"
|
||||
#include "ui/gtk/gtk_util.h"
|
||||
#include "ui/gtk/input_method_context_impl_gtk.h"
|
||||
#include "ui/gtk/native_theme_gtk.h"
|
||||
@ -74,13 +73,28 @@
|
||||
#if defined(USE_OZONE)
|
||||
#include "ui/base/ime/input_method.h"
|
||||
#include "ui/base/ui_base_features.h"
|
||||
#include "ui/ozone/buildflags.h"
|
||||
#include "ui/ozone/public/ozone_platform.h"
|
||||
#if BUILDFLAG(OZONE_PLATFORM_WAYLAND)
|
||||
#define USE_WAYLAND
|
||||
#endif
|
||||
#if BUILDFLAG(OZONE_PLATFORM_X11) && !defined(USE_X11)
|
||||
#define USE_X11
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
#include "printing/printing_context_linux.h"
|
||||
#endif
|
||||
|
||||
#if defined(USE_WAYLAND)
|
||||
#include "ui/gtk/wayland/gtk_ui_platform_wayland.h"
|
||||
#endif
|
||||
|
||||
#if defined(USE_X11)
|
||||
#include "ui/gtk/x/gtk_ui_platform_x11.h"
|
||||
#endif
|
||||
|
||||
namespace gtk {
|
||||
|
||||
namespace {
|
||||
@ -284,9 +298,25 @@ views::LinuxUI::WindowFrameAction GetDefaultMiddleClickAction() {
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<GtkUiPlatform> CreateGtkUiPlatform(ui::LinuxUiBackend backend) {
|
||||
switch (backend) {
|
||||
#if defined(USE_X11)
|
||||
case ui::LinuxUiBackend::kX11:
|
||||
return std::make_unique<GtkUiPlatformX11>();
|
||||
#endif
|
||||
#if defined(USE_WAYLAND)
|
||||
case ui::LinuxUiBackend::kWayland:
|
||||
return std::make_unique<GtkUiPlatformWayland>();
|
||||
#endif
|
||||
default:
|
||||
NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
GtkUi::GtkUi(ui::GtkUiDelegate* delegate) : delegate_(delegate) {
|
||||
GtkUi::GtkUi() {
|
||||
using Action = views::LinuxUI::WindowFrameAction;
|
||||
using ActionSource = views::LinuxUI::WindowFrameActionSource;
|
||||
|
||||
@ -295,10 +325,11 @@ GtkUi::GtkUi(ui::GtkUiDelegate* delegate) : delegate_(delegate) {
|
||||
|
||||
CHECK(LoadGtk());
|
||||
|
||||
window_frame_actions_ = {
|
||||
{ActionSource::kDoubleClick, Action::kToggleMaximize},
|
||||
{ActionSource::kMiddleClick, GetDefaultMiddleClickAction()},
|
||||
{ActionSource::kRightClick, Action::kMenu}};
|
||||
auto* delegate = ui::LinuxUiDelegate::GetInstance();
|
||||
// TODO(thomasanderson): This should be replaced with DCHECK(delegate) once
|
||||
// fully migrated to ozone.
|
||||
auto backend = delegate ? delegate->GetBackend() : ui::LinuxUiBackend::kX11;
|
||||
platform_ = CreateGtkUiPlatform(backend);
|
||||
|
||||
// Avoid GTK initializing atk-bridge, and let AuraLinux implementation
|
||||
// do it once it is ready.
|
||||
@ -306,15 +337,22 @@ GtkUi::GtkUi(ui::GtkUiDelegate* delegate) : delegate_(delegate) {
|
||||
env->SetVar("NO_AT_BRIDGE", "1");
|
||||
GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess());
|
||||
native_theme_ = NativeThemeGtk::instance();
|
||||
|
||||
window_frame_actions_ = {
|
||||
{ActionSource::kDoubleClick, Action::kToggleMaximize},
|
||||
{ActionSource::kMiddleClick, GetDefaultMiddleClickAction()},
|
||||
{ActionSource::kRightClick, Action::kMenu}};
|
||||
}
|
||||
|
||||
GtkUi::~GtkUi() {
|
||||
DCHECK_EQ(g_gtk_ui, this);
|
||||
g_gtk_ui = nullptr;
|
||||
}
|
||||
|
||||
ui::GtkUiDelegate* GtkUi::GetDelegate() {
|
||||
// static
|
||||
GtkUiPlatform* GtkUi::GetPlatform() {
|
||||
DCHECK(g_gtk_ui) << "GtkUi instance is not set.";
|
||||
return g_gtk_ui->delegate_;
|
||||
return g_gtk_ui->platform_.get();
|
||||
}
|
||||
|
||||
void GtkUi::Initialize() {
|
||||
@ -366,7 +404,7 @@ void GtkUi::Initialize() {
|
||||
|
||||
indicators_count = 0;
|
||||
|
||||
GetDelegate()->OnInitialized(GetDummyWindow());
|
||||
platform_->OnInitialized(GetDummyWindow());
|
||||
}
|
||||
|
||||
bool GtkUi::GetTint(int id, color_utils::HSL* tint) const {
|
||||
@ -774,7 +812,7 @@ bool GtkUi::MatchEvent(const ui::Event& event,
|
||||
// determine if GtkUi's key binding handling implementation is used or not.
|
||||
// Ozone/Wayland was unintentionally using GtkUi for keybinding handling, so
|
||||
// early out here, for now, until a proper solution for ozone is implemented.
|
||||
if (!GetDelegate()->GetGdkKeymap())
|
||||
if (!platform_->GetGdkKeymap())
|
||||
return false;
|
||||
|
||||
// Ensure that we have a keyboard handler.
|
||||
@ -1058,7 +1096,3 @@ float GtkUi::GetDeviceScaleFactor() const {
|
||||
}
|
||||
|
||||
} // namespace gtk
|
||||
|
||||
views::LinuxUI* BuildGtkUi(ui::GtkUiDelegate* delegate) {
|
||||
return new gtk::GtkUi(delegate);
|
||||
}
|
||||
|
@ -10,12 +10,11 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/component_export.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "ui/base/glib/glib_signal.h"
|
||||
#include "ui/gfx/color_utils.h"
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
#include "ui/gtk/gtk_ui_platform.h"
|
||||
#include "ui/views/linux_ui/linux_ui.h"
|
||||
#include "ui/views/window/frame_buttons.h"
|
||||
|
||||
@ -35,12 +34,12 @@ class SettingsProvider;
|
||||
// Interface to GTK desktop features.
|
||||
class GtkUi : public views::LinuxUI {
|
||||
public:
|
||||
explicit GtkUi(ui::GtkUiDelegate* delegate);
|
||||
GtkUi();
|
||||
~GtkUi() override;
|
||||
|
||||
// Static delegate getter, used by different objects (created by GtkUi), e.g:
|
||||
// Dialogs, IME Context, when platform-specific functionality is required.
|
||||
static ui::GtkUiDelegate* GetDelegate();
|
||||
static GtkUiPlatform* GetPlatform();
|
||||
|
||||
// Setters used by SettingsProvider:
|
||||
void SetWindowButtonOrdering(
|
||||
@ -146,8 +145,7 @@ class GtkUi : public views::LinuxUI {
|
||||
|
||||
float GetRawDeviceScaleFactor();
|
||||
|
||||
// Not owned by GtkUi.
|
||||
ui::GtkUiDelegate* const delegate_;
|
||||
std::unique_ptr<GtkUiPlatform> platform_;
|
||||
|
||||
NativeThemeGtk* native_theme_;
|
||||
|
||||
@ -214,8 +212,4 @@ class GtkUi : public views::LinuxUI {
|
||||
|
||||
} // namespace gtk
|
||||
|
||||
// Access point to the GTK desktop system.
|
||||
COMPONENT_EXPORT(GTK)
|
||||
views::LinuxUI* BuildGtkUi(ui::GtkUiDelegate* delegate);
|
||||
|
||||
#endif // UI_GTK_GTK_UI_H_
|
||||
|
@ -1,23 +0,0 @@
|
||||
// Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
namespace {
|
||||
|
||||
GtkUiDelegate* g_gtk_ui_delegate = nullptr;
|
||||
|
||||
} // namespace
|
||||
|
||||
void GtkUiDelegate::SetInstance(GtkUiDelegate* instance) {
|
||||
g_gtk_ui_delegate = instance;
|
||||
}
|
||||
|
||||
GtkUiDelegate* GtkUiDelegate::instance() {
|
||||
return g_gtk_ui_delegate;
|
||||
}
|
||||
|
||||
} // namespace ui
|
11
ui/gtk/gtk_ui_factory.cc
Normal file
11
ui/gtk/gtk_ui_factory.cc
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ui/gtk/gtk_ui_factory.h"
|
||||
|
||||
#include "ui/gtk/gtk_ui.h"
|
||||
|
||||
std::unique_ptr<views::LinuxUI> BuildGtkUi() {
|
||||
return std::make_unique<gtk::GtkUi>();
|
||||
}
|
21
ui/gtk/gtk_ui_factory.h
Normal file
21
ui/gtk/gtk_ui_factory.h
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef UI_GTK_GTK_UI_FACTORY_H_
|
||||
#define UI_GTK_GTK_UI_FACTORY_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/component_export.h"
|
||||
|
||||
namespace views {
|
||||
class LinuxUI;
|
||||
}
|
||||
|
||||
// Access point to the GTK desktop system. This should be the only symbol
|
||||
// exported from this component.
|
||||
COMPONENT_EXPORT(GTK)
|
||||
std::unique_ptr<views::LinuxUI> BuildGtkUi();
|
||||
|
||||
#endif // UI_GTK_GTK_UI_FACTORY_H_
|
@ -2,10 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef UI_GTK_GTK_UI_DELEGATE_H_
|
||||
#define UI_GTK_GTK_UI_DELEGATE_H_
|
||||
#ifndef UI_GTK_GTK_UI_PLATFORM_H_
|
||||
#define UI_GTK_GTK_UI_PLATFORM_H_
|
||||
|
||||
#include "base/component_export.h"
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
|
||||
using GdkKeymap = struct _GdkKeymap;
|
||||
@ -13,27 +12,13 @@ using GtkWindow = struct _GtkWindow;
|
||||
using GtkWidget = struct _GtkWidget;
|
||||
using GdkWindow = struct _GdkWindow;
|
||||
|
||||
namespace ui {
|
||||
namespace gtk {
|
||||
|
||||
// GtkUiDelegate encapsulates platform-specific functionalities required by
|
||||
// a Gtk-based LinuxUI implementation. The main goal of this interface is to
|
||||
// make GtkUi platform agnostic, moving the platform specifics to lower level
|
||||
// layers (e.g: ozone). Linux backends (e.g: ozone/x11, aura/x11, ozone/wayland)
|
||||
// must provide a GtkUiDelegate implementation and inject its singleton instance
|
||||
// of it via |SetInstance| in order to be able to use GtkUi.
|
||||
class COMPONENT_EXPORT(GTK) GtkUiDelegate {
|
||||
// GtkUiPlatform encapsulates platform-specific functionalities required by
|
||||
// a Gtk-based LinuxUI implementation.
|
||||
class GtkUiPlatform {
|
||||
public:
|
||||
virtual ~GtkUiDelegate() = default;
|
||||
|
||||
// Sets the singleton delegate instance to be used by GtkUi. This makes it
|
||||
// possible for ozone-based backends, for example, to inject the GtkUiDelegate
|
||||
// object without polluting Ozone API, since just a small subset of ozone
|
||||
// backends make use of GtkUi. This pointer is not owned, and if this method
|
||||
// is called a second time, the first instance is not deleted.
|
||||
static void SetInstance(GtkUiDelegate* instance);
|
||||
|
||||
// Returns the current active instance.
|
||||
static GtkUiDelegate* instance();
|
||||
virtual ~GtkUiPlatform() = default;
|
||||
|
||||
// Called when the GtkUi instance initialization process finished. |widget| is
|
||||
// a dummy window passed in for context.
|
||||
@ -62,6 +47,6 @@ class COMPONENT_EXPORT(GTK) GtkUiDelegate {
|
||||
virtual int GetGdkKeyState() = 0;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace gtk
|
||||
|
||||
#endif // UI_GTK_GTK_UI_DELEGATE_H_
|
||||
#endif // UI_GTK_GTK_UI_PLATFORM_H_
|
@ -4,8 +4,6 @@
|
||||
|
||||
#include "ui/gtk/gtk_util.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <locale.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@ -29,7 +27,7 @@
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
#include "ui/gtk/gtk_compat.h"
|
||||
#include "ui/gtk/gtk_ui.h"
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
#include "ui/gtk/gtk_ui_platform.h"
|
||||
#include "ui/native_theme/common_theme.h"
|
||||
#include "ui/ozone/public/ozone_platform.h"
|
||||
#include "ui/views/linux_ui/linux_ui.h"
|
||||
@ -183,7 +181,7 @@ void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent) {
|
||||
|
||||
gtk_widget_realize(dialog);
|
||||
gfx::AcceleratedWidget parent_id = parent->GetHost()->GetAcceleratedWidget();
|
||||
GtkUi::GetDelegate()->SetGtkWidgetTransientFor(dialog, parent_id);
|
||||
GtkUi::GetPlatform()->SetGtkWidgetTransientFor(dialog, parent_id);
|
||||
|
||||
// We also set the |parent| as a property of |dialog|, so that we can unlink
|
||||
// the two later.
|
||||
@ -197,7 +195,7 @@ aura::Window* GetAuraTransientParent(GtkWidget* dialog) {
|
||||
|
||||
void ClearAuraTransientParent(GtkWidget* dialog, aura::Window* parent) {
|
||||
g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, nullptr);
|
||||
GtkUi::GetDelegate()->ClearTransientFor(
|
||||
GtkUi::GetPlatform()->ClearTransientFor(
|
||||
parent->GetHost()->GetAcceleratedWidget());
|
||||
}
|
||||
|
||||
@ -625,7 +623,7 @@ GdkModifierType GetGdkKeyEventState(const ui::KeyEvent& key_event) {
|
||||
// In such a case there is no event being dispatching in the display
|
||||
// backend.
|
||||
state = static_cast<GdkModifierType>(
|
||||
state | ui::GtkUiDelegate::instance()->GetGdkKeyState());
|
||||
state | GtkUi::GetPlatform()->GetGdkKeyState());
|
||||
}
|
||||
|
||||
return state;
|
||||
@ -640,7 +638,7 @@ GdkEvent* GdkEventFromKeyEvent(const ui::KeyEvent& key_event) {
|
||||
int group = GetKeyEventProperty(key_event, ui::kPropertyKeyboardGroup);
|
||||
|
||||
// Get GdkKeymap
|
||||
GdkKeymap* keymap = GtkUi::GetDelegate()->GetGdkKeymap();
|
||||
GdkKeymap* keymap = GtkUi::GetPlatform()->GetGdkKeymap();
|
||||
|
||||
// Get keyval and state
|
||||
GdkModifierType state = GetGdkKeyEventState(key_event);
|
||||
|
@ -5,9 +5,6 @@
|
||||
#ifndef UI_GTK_GTK_UTIL_H_
|
||||
#define UI_GTK_GTK_UTIL_H_
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -4,10 +4,7 @@
|
||||
|
||||
#include "ui/gtk/input_method_context_impl_gtk.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "ui/aura/window_tree_host.h"
|
||||
@ -21,7 +18,7 @@
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
#include "ui/gtk/gtk_compat.h"
|
||||
#include "ui/gtk/gtk_ui.h"
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
#include "ui/gtk/gtk_ui_platform.h"
|
||||
#include "ui/gtk/gtk_util.h"
|
||||
#include "ui/views/linux_ui/linux_ui.h"
|
||||
|
||||
@ -46,7 +43,7 @@ GdkWindow* GetTargetWindow(const ui::KeyEvent& key_event) {
|
||||
DCHECK(window) << "KeyEvent target window not set.";
|
||||
|
||||
auto window_id = window->GetHost()->GetAcceleratedWidget();
|
||||
return GtkUi::GetDelegate()->GetGdkWindow(window_id);
|
||||
return GtkUi::GetPlatform()->GetGdkWindow(window_id);
|
||||
}
|
||||
|
||||
// Translate IME ui::KeyEvent to a GdkEventKey.
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
#include "ui/gtk/native_theme_gtk.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "base/strings/strcat.h"
|
||||
#include "ui/color/color_provider_manager.h"
|
||||
#include "ui/gfx/color_palette.h"
|
||||
|
@ -6,7 +6,6 @@
|
||||
#define UI_GTK_NATIVE_THEME_GTK_H_
|
||||
|
||||
#include "base/callback_list.h"
|
||||
#include "base/component_export.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "base/optional.h"
|
||||
@ -23,7 +22,7 @@ namespace gtk {
|
||||
using ScopedCssProvider = ScopedGObject<GtkCssProvider>;
|
||||
|
||||
// A version of NativeTheme that uses GTK-rendered widgets.
|
||||
class COMPONENT_EXPORT(GTK) NativeThemeGtk : public ui::NativeThemeBase {
|
||||
class NativeThemeGtk : public ui::NativeThemeBase {
|
||||
public:
|
||||
static NativeThemeGtk* instance();
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ui/gtk/native_theme_gtk.h"
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
@ -13,10 +11,10 @@
|
||||
#include "base/test/scoped_feature_list.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "ui/base/ui_base_features.h"
|
||||
#include "ui/gtk/gtk_ui.h"
|
||||
#include "ui/gtk/gtk_util.h"
|
||||
#include "ui/gtk/gtk_ui_factory.h"
|
||||
#include "ui/native_theme/native_theme_color_id.h"
|
||||
#include "ui/native_theme/test/color_utils.h"
|
||||
#include "ui/views/linux_ui/linux_ui.h"
|
||||
|
||||
namespace gtk {
|
||||
|
||||
@ -26,9 +24,7 @@ class NativeThemeGtkRedirectedEquivalenceTest
|
||||
: public testing::TestWithParam<
|
||||
std::tuple<ui::NativeTheme::ColorScheme, ui::NativeTheme::ColorId>> {
|
||||
public:
|
||||
NativeThemeGtkRedirectedEquivalenceTest() {
|
||||
gtk_ui_ = base::WrapUnique(BuildGtkUi(nullptr));
|
||||
}
|
||||
NativeThemeGtkRedirectedEquivalenceTest() { gtk_ui_ = BuildGtkUi(); }
|
||||
|
||||
static std::string ParamInfoToString(
|
||||
::testing::TestParamInfo<
|
||||
@ -42,6 +38,9 @@ class NativeThemeGtkRedirectedEquivalenceTest
|
||||
std::get<ui::NativeTheme::ColorId>(param_tuple));
|
||||
}
|
||||
|
||||
protected:
|
||||
views::LinuxUI* gtk_ui() { return gtk_ui_.get(); }
|
||||
|
||||
private:
|
||||
static std::string ColorSchemeToString(ui::NativeTheme::ColorScheme scheme) {
|
||||
switch (scheme) {
|
||||
@ -69,7 +68,7 @@ TEST_P(NativeThemeGtkRedirectedEquivalenceTest, GetSystemColor) {
|
||||
auto color_id = std::get<ui::NativeTheme::ColorId>(param_tuple);
|
||||
|
||||
// Verifies that colors with and without the Color Provider are the same.
|
||||
auto* native_theme_gtk = NativeThemeGtk::instance();
|
||||
auto* native_theme_gtk = gtk_ui()->GetNativeTheme(nullptr);
|
||||
|
||||
ui::test::PrintableSkColor original{
|
||||
native_theme_gtk->GetSystemColor(color_id, color_scheme)};
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
#include "ui/gtk/nav_button_provider_gtk.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "base/notreached.h"
|
||||
#include "ui/base/glib/glib_cast.h"
|
||||
#include "ui/base/glib/scoped_gobject.h"
|
||||
|
@ -7,15 +7,13 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "base/component_export.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/linux_ui/nav_button_provider.h"
|
||||
|
||||
namespace gtk {
|
||||
|
||||
class COMPONENT_EXPORT(GTK) NavButtonProviderGtk
|
||||
: public views::NavButtonProvider {
|
||||
class NavButtonProviderGtk : public views::NavButtonProvider {
|
||||
public:
|
||||
NavButtonProviderGtk();
|
||||
~NavButtonProviderGtk() override;
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
#include "ui/gtk/printing/print_dialog_gtk.h"
|
||||
|
||||
#include <gtk/gtkunixprint.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
@ -30,7 +28,7 @@
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/gtk/gtk_compat.h"
|
||||
#include "ui/gtk/gtk_ui.h"
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
#include "ui/gtk/gtk_ui_platform.h"
|
||||
#include "ui/gtk/gtk_util.h"
|
||||
#include "ui/gtk/printing/printing_gtk_util.h"
|
||||
|
||||
@ -409,7 +407,7 @@ void PrintDialogGtk::ShowDialog(
|
||||
g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this);
|
||||
gtk_widget_show(dialog_);
|
||||
|
||||
gtk::GtkUi::GetDelegate()->ShowGtkWindow(GTK_WINDOW(dialog_));
|
||||
gtk::GtkUi::GetPlatform()->ShowGtkWindow(GTK_WINDOW(dialog_));
|
||||
}
|
||||
|
||||
void PrintDialogGtk::PrintDocument(const printing::MetafilePlayer& metafile,
|
||||
|
@ -5,8 +5,6 @@
|
||||
#ifndef UI_GTK_PRINTING_PRINT_DIALOG_GTK_H_
|
||||
#define UI_GTK_PRINTING_PRINT_DIALOG_GTK_H_
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gtk/gtkunixprint.h>
|
||||
#include <memory>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
@ -17,6 +15,7 @@
|
||||
#include "printing/printing_context_linux.h"
|
||||
#include "ui/aura/window_observer.h"
|
||||
#include "ui/base/glib/glib_signal.h"
|
||||
#include "ui/gtk/gtk_compat.h"
|
||||
|
||||
namespace printing {
|
||||
class MetafilePlayer;
|
||||
|
@ -4,9 +4,6 @@
|
||||
|
||||
#include "ui/gtk/printing/printing_gtk_util.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gtk/gtkunixprint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
@ -15,6 +12,7 @@
|
||||
#include "printing/units.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/geometry/size_f.h"
|
||||
#include "ui/gtk/gtk_compat.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -5,12 +5,11 @@
|
||||
#include "ui/gtk/select_file_dialog_impl_gtk.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
@ -30,7 +29,7 @@
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/gtk/gtk_compat.h"
|
||||
#include "ui/gtk/gtk_ui.h"
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
#include "ui/gtk/gtk_ui_platform.h"
|
||||
#include "ui/gtk/gtk_util.h"
|
||||
#include "ui/gtk/select_file_dialog_impl.h"
|
||||
#include "ui/shell_dialogs/select_file_dialog.h"
|
||||
@ -299,7 +298,7 @@ void SelectFileDialogImplGTK::SelectFileImpl(
|
||||
|
||||
if (!GtkCheckVersion(4))
|
||||
gtk_widget_show_all(dialog);
|
||||
gtk::GtkUi::GetDelegate()->ShowGtkWindow(GTK_WINDOW(dialog));
|
||||
gtk::GtkUi::GetPlatform()->ShowGtkWindow(GTK_WINDOW(dialog));
|
||||
}
|
||||
|
||||
void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) {
|
||||
|
@ -1,23 +0,0 @@
|
||||
# Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//build/config/ozone.gni")
|
||||
|
||||
assert(ozone_platform_wayland)
|
||||
|
||||
component("wayland") {
|
||||
output_name = "ui_gtk_wayland"
|
||||
sources = [
|
||||
"gtk_ui_delegate_wayland_base.cc",
|
||||
"gtk_ui_delegate_wayland_base.h",
|
||||
]
|
||||
deps = [
|
||||
"//base",
|
||||
"//build/config/linux/gtk",
|
||||
"//ui/base",
|
||||
"//ui/gtk:gtk_compat",
|
||||
]
|
||||
public_deps = [ "//ui/gtk:gtk_ui_delegate" ]
|
||||
defines = [ "IS_GTK_WAYLAND_IMPL" ]
|
||||
}
|
@ -2,46 +2,43 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ui/gtk/wayland/gtk_ui_delegate_wayland_base.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "ui/gtk/wayland/gtk_ui_platform_wayland.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/logging.h"
|
||||
#include "ui/base/glib/glib_cast.h"
|
||||
#include "ui/base/linux/linux_ui_delegate.h"
|
||||
#include "ui/gtk/gtk_compat.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
GtkUiDelegateWaylandBase::GtkUiDelegateWaylandBase() {
|
||||
CHECK(gtk::LoadGtk());
|
||||
namespace gtk {
|
||||
|
||||
GtkUiPlatformWayland::GtkUiPlatformWayland() {
|
||||
gdk_set_allowed_backends("wayland");
|
||||
// GDK_BACKEND takes precedence over gdk_set_allowed_backends(), so override
|
||||
// it to ensure we get the wayland backend.
|
||||
base::Environment::Create()->SetVar("GDK_BACKEND", "wayland");
|
||||
}
|
||||
|
||||
GtkUiDelegateWaylandBase::~GtkUiDelegateWaylandBase() = default;
|
||||
GtkUiPlatformWayland::~GtkUiPlatformWayland() = default;
|
||||
|
||||
void GtkUiDelegateWaylandBase::OnInitialized(GtkWidget* widget) {
|
||||
void GtkUiPlatformWayland::OnInitialized(GtkWidget* widget) {
|
||||
// Nothing to do upon initialization for Wayland.
|
||||
}
|
||||
|
||||
GdkKeymap* GtkUiDelegateWaylandBase::GetGdkKeymap() {
|
||||
GdkKeymap* GtkUiPlatformWayland::GetGdkKeymap() {
|
||||
NOTIMPLEMENTED_LOG_ONCE();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GdkWindow* GtkUiDelegateWaylandBase::GetGdkWindow(
|
||||
GdkWindow* GtkUiPlatformWayland::GetGdkWindow(
|
||||
gfx::AcceleratedWidget window_id) {
|
||||
NOTIMPLEMENTED_LOG_ONCE();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool GtkUiDelegateWaylandBase::SetGtkWidgetTransientFor(
|
||||
bool GtkUiPlatformWayland::SetGtkWidgetTransientFor(
|
||||
GtkWidget* widget,
|
||||
gfx::AcceleratedWidget parent) {
|
||||
if (!gtk::GtkCheckVersion(3, 22)) {
|
||||
@ -51,24 +48,23 @@ bool GtkUiDelegateWaylandBase::SetGtkWidgetTransientFor(
|
||||
return false;
|
||||
}
|
||||
|
||||
return SetGtkWidgetTransientForImpl(
|
||||
parent, base::BindOnce(&GtkUiDelegateWaylandBase::OnHandle,
|
||||
return ui::LinuxUiDelegate::GetInstance()->SetWidgetTransientFor(
|
||||
parent, base::BindOnce(&GtkUiPlatformWayland::OnHandle,
|
||||
weak_factory_.GetWeakPtr(), widget));
|
||||
}
|
||||
|
||||
void GtkUiDelegateWaylandBase::ClearTransientFor(
|
||||
gfx::AcceleratedWidget parent) {
|
||||
void GtkUiPlatformWayland::ClearTransientFor(gfx::AcceleratedWidget parent) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
void GtkUiDelegateWaylandBase::ShowGtkWindow(GtkWindow* window) {
|
||||
void GtkUiPlatformWayland::ShowGtkWindow(GtkWindow* window) {
|
||||
// TODO(crbug.com/1008755): Check if gtk_window_present_with_time is needed
|
||||
// here as well, similarly to what is done in X11 impl.
|
||||
gtk_window_present(window);
|
||||
}
|
||||
|
||||
void GtkUiDelegateWaylandBase::OnHandle(GtkWidget* widget,
|
||||
const std::string& handle) {
|
||||
void GtkUiPlatformWayland::OnHandle(GtkWidget* widget,
|
||||
const std::string& handle) {
|
||||
char* parent = const_cast<char*>(handle.c_str());
|
||||
if (gtk::GtkCheckVersion(4)) {
|
||||
auto* toplevel = GlibCast<GdkToplevel>(
|
||||
@ -81,4 +77,8 @@ void GtkUiDelegateWaylandBase::OnHandle(GtkWidget* widget,
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
int GtkUiPlatformWayland::GetGdkKeyState() {
|
||||
return ui::LinuxUiDelegate::GetInstance()->GetKeyState();
|
||||
}
|
||||
|
||||
} // namespace gtk
|
@ -2,27 +2,25 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef UI_GTK_WAYLAND_GTK_UI_DELEGATE_WAYLAND_BASE_H_
|
||||
#define UI_GTK_WAYLAND_GTK_UI_DELEGATE_WAYLAND_BASE_H_
|
||||
#ifndef UI_GTK_WAYLAND_GTK_UI_PLATFORM_WAYLAND_H_
|
||||
#define UI_GTK_WAYLAND_GTK_UI_PLATFORM_WAYLAND_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/callback_forward.h"
|
||||
#include "base/component_export.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
#include "ui/gtk/gtk_ui_platform.h"
|
||||
|
||||
namespace ui {
|
||||
namespace gtk {
|
||||
|
||||
class COMPONENT_EXPORT(GTK_WAYLAND) GtkUiDelegateWaylandBase
|
||||
: public GtkUiDelegate {
|
||||
class GtkUiPlatformWayland : public GtkUiPlatform {
|
||||
public:
|
||||
GtkUiDelegateWaylandBase();
|
||||
GtkUiDelegateWaylandBase(const GtkUiDelegateWaylandBase&) = delete;
|
||||
GtkUiDelegateWaylandBase& operator=(const GtkUiDelegateWaylandBase&) = delete;
|
||||
~GtkUiDelegateWaylandBase() override;
|
||||
GtkUiPlatformWayland();
|
||||
GtkUiPlatformWayland(const GtkUiPlatformWayland&) = delete;
|
||||
GtkUiPlatformWayland& operator=(const GtkUiPlatformWayland&) = delete;
|
||||
~GtkUiPlatformWayland() override;
|
||||
|
||||
// GtkUiDelegate:
|
||||
// GtkUiPlatform:
|
||||
void OnInitialized(GtkWidget* widget) override;
|
||||
GdkKeymap* GetGdkKeymap() override;
|
||||
GdkWindow* GetGdkWindow(gfx::AcceleratedWidget window_id) override;
|
||||
@ -30,20 +28,16 @@ class COMPONENT_EXPORT(GTK_WAYLAND) GtkUiDelegateWaylandBase
|
||||
gfx::AcceleratedWidget parent) override;
|
||||
void ClearTransientFor(gfx::AcceleratedWidget parent) override;
|
||||
void ShowGtkWindow(GtkWindow* window) override;
|
||||
|
||||
protected:
|
||||
virtual bool SetGtkWidgetTransientForImpl(
|
||||
gfx::AcceleratedWidget parent,
|
||||
base::OnceCallback<void(const std::string&)> callback) = 0;
|
||||
int GetGdkKeyState() override;
|
||||
|
||||
private:
|
||||
// Called when xdg-foreign exports a parent window passed in
|
||||
// SetGtkWidgetTransientFor.
|
||||
void OnHandle(GtkWidget* widget, const std::string& handle);
|
||||
|
||||
base::WeakPtrFactory<GtkUiDelegateWaylandBase> weak_factory_{this};
|
||||
base::WeakPtrFactory<GtkUiPlatformWayland> weak_factory_{this};
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace gtk
|
||||
|
||||
#endif // UI_GTK_WAYLAND_GTK_UI_DELEGATE_WAYLAND_BASE_H_
|
||||
#endif // UI_GTK_WAYLAND_GTK_UI_PLATFORM_WAYLAND_H_
|
@ -1,29 +0,0 @@
|
||||
# Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//build/config/ozone.gni")
|
||||
import("//build/config/ui.gni")
|
||||
|
||||
assert(use_x11 || ozone_platform_x11)
|
||||
|
||||
component("x") {
|
||||
output_name = "ui_gtk_x"
|
||||
sources = [
|
||||
"gtk_event_loop_x11.cc",
|
||||
"gtk_event_loop_x11.h",
|
||||
"gtk_ui_delegate_x11.cc",
|
||||
"gtk_ui_delegate_x11.h",
|
||||
]
|
||||
deps = [
|
||||
"//base",
|
||||
"//build/config/linux/gtk",
|
||||
"//ui/base",
|
||||
"//ui/events/platform/x11",
|
||||
"//ui/gfx/x",
|
||||
"//ui/gtk:gtk_compat",
|
||||
"//ui/platform_window/x11",
|
||||
]
|
||||
public_deps = [ "//ui/gtk:gtk_ui_delegate" ]
|
||||
defines = [ "IS_UI_GTK_X_IMPL" ]
|
||||
}
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "ui/gtk/x/gtk_event_loop_x11.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xproto.h>
|
||||
|
||||
@ -12,7 +11,7 @@
|
||||
#include "ui/gfx/x/event.h"
|
||||
#include "ui/gtk/gtk_compat.h"
|
||||
|
||||
namespace ui {
|
||||
namespace gtk {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -138,4 +137,4 @@ void GtkEventLoopX11::DispatchGdkEvent(GdkEvent* gdk_event, gpointer) {
|
||||
gtk_main_do_event(gdk_event);
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace gtk
|
||||
|
@ -5,14 +5,11 @@
|
||||
#ifndef UI_GTK_X_GTK_EVENT_LOOP_X11_H_
|
||||
#define UI_GTK_X_GTK_EVENT_LOOP_X11_H_
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "ui/base/glib/glib_integers.h"
|
||||
#include "ui/base/glib/glib_signal.h"
|
||||
#include "ui/gtk/gtk_compat.h"
|
||||
|
||||
namespace ui {
|
||||
namespace gtk {
|
||||
|
||||
class GtkEventLoopX11 {
|
||||
public:
|
||||
@ -34,6 +31,6 @@ class GtkEventLoopX11 {
|
||||
CHROMEG_CALLBACK_0(GtkEventLoopX11, gboolean, OnEvent, GdkEvent*);
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace gtk
|
||||
|
||||
#endif // UI_GTK_X_GTK_EVENT_LOOP_X11_H_
|
||||
|
@ -2,9 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ui/gtk/x/gtk_ui_delegate_x11.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "ui/gtk/x/gtk_ui_platform_x11.h"
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/environment.h"
|
||||
@ -20,13 +18,9 @@
|
||||
#include "ui/platform_window/x11/x11_window.h"
|
||||
#include "ui/platform_window/x11/x11_window_manager.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
GtkUiDelegateX11::GtkUiDelegateX11(x11::Connection* connection)
|
||||
: connection_(connection) {
|
||||
DCHECK(connection_);
|
||||
CHECK(gtk::LoadGtk());
|
||||
namespace gtk {
|
||||
|
||||
GtkUiPlatformX11::GtkUiPlatformX11() : connection_(x11::Connection::Get()) {
|
||||
gdk_set_allowed_backends("x11");
|
||||
// GDK_BACKEND takes precedence over gdk_set_allowed_backends(), so override
|
||||
// it to ensure we get the x11 backend.
|
||||
@ -34,9 +28,9 @@ GtkUiDelegateX11::GtkUiDelegateX11(x11::Connection* connection)
|
||||
x11::InitXlib();
|
||||
}
|
||||
|
||||
GtkUiDelegateX11::~GtkUiDelegateX11() = default;
|
||||
GtkUiPlatformX11::~GtkUiPlatformX11() = default;
|
||||
|
||||
void GtkUiDelegateX11::OnInitialized(GtkWidget* widget) {
|
||||
void GtkUiPlatformX11::OnInitialized(GtkWidget* widget) {
|
||||
// Ensure the singleton instance of GtkEventLoopX11 is created and started.
|
||||
if (!event_loop_)
|
||||
event_loop_ = std::make_unique<GtkEventLoopX11>(widget);
|
||||
@ -47,12 +41,12 @@ void GtkUiDelegateX11::OnInitialized(GtkWidget* widget) {
|
||||
x11::SetXlibErrorHandler();
|
||||
}
|
||||
|
||||
GdkKeymap* GtkUiDelegateX11::GetGdkKeymap() {
|
||||
GdkKeymap* GtkUiPlatformX11::GetGdkKeymap() {
|
||||
DCHECK(!gtk::GtkCheckVersion(4));
|
||||
return gdk_keymap_get_for_display(GetGdkDisplay());
|
||||
}
|
||||
|
||||
GdkWindow* GtkUiDelegateX11::GetGdkWindow(gfx::AcceleratedWidget window_id) {
|
||||
GdkWindow* GtkUiPlatformX11::GetGdkWindow(gfx::AcceleratedWidget window_id) {
|
||||
DCHECK(!gtk::GtkCheckVersion(4));
|
||||
GdkDisplay* display = GetGdkDisplay();
|
||||
GdkWindow* gdk_window = gdk_x11_window_lookup_for_display(
|
||||
@ -65,7 +59,7 @@ GdkWindow* GtkUiDelegateX11::GetGdkWindow(gfx::AcceleratedWidget window_id) {
|
||||
return gdk_window;
|
||||
}
|
||||
|
||||
bool GtkUiDelegateX11::SetGtkWidgetTransientFor(GtkWidget* widget,
|
||||
bool GtkUiPlatformX11::SetGtkWidgetTransientFor(GtkWidget* widget,
|
||||
gfx::AcceleratedWidget parent) {
|
||||
auto x11_window = static_cast<x11::Window>(
|
||||
gtk::GtkCheckVersion(4)
|
||||
@ -84,7 +78,7 @@ bool GtkUiDelegateX11::SetGtkWidgetTransientFor(GtkWidget* widget,
|
||||
return true;
|
||||
}
|
||||
|
||||
void GtkUiDelegateX11::ClearTransientFor(gfx::AcceleratedWidget parent) {
|
||||
void GtkUiPlatformX11::ClearTransientFor(gfx::AcceleratedWidget parent) {
|
||||
ui::X11Window* parent_window =
|
||||
ui::X11WindowManager::GetInstance()->GetWindow(parent);
|
||||
// parent_window might be dead if there was a top-down window close
|
||||
@ -92,24 +86,24 @@ void GtkUiDelegateX11::ClearTransientFor(gfx::AcceleratedWidget parent) {
|
||||
parent_window->SetTransientWindow(x11::Window::None);
|
||||
}
|
||||
|
||||
GdkDisplay* GtkUiDelegateX11::GetGdkDisplay() {
|
||||
GdkDisplay* GtkUiPlatformX11::GetGdkDisplay() {
|
||||
if (!display_)
|
||||
display_ = gdk_display_get_default();
|
||||
return display_;
|
||||
}
|
||||
|
||||
void GtkUiDelegateX11::ShowGtkWindow(GtkWindow* window) {
|
||||
void GtkUiPlatformX11::ShowGtkWindow(GtkWindow* window) {
|
||||
// We need to call gtk_window_present after making the widgets visible to make
|
||||
// sure window gets correctly raised and gets focus.
|
||||
DCHECK(X11EventSource::HasInstance());
|
||||
DCHECK(ui::X11EventSource::HasInstance());
|
||||
gtk_window_present_with_time(
|
||||
window,
|
||||
static_cast<uint32_t>(X11EventSource::GetInstance()->GetTimestamp()));
|
||||
static_cast<uint32_t>(ui::X11EventSource::GetInstance()->GetTimestamp()));
|
||||
}
|
||||
|
||||
int GtkUiDelegateX11::GetGdkKeyState() {
|
||||
int GtkUiPlatformX11::GetGdkKeyState() {
|
||||
auto* xevent =
|
||||
X11EventSource::GetInstance()->connection()->dispatching_event();
|
||||
ui::X11EventSource::GetInstance()->connection()->dispatching_event();
|
||||
|
||||
if (!xevent)
|
||||
return ui::EF_NONE;
|
||||
@ -119,4 +113,4 @@ int GtkUiDelegateX11::GetGdkKeyState() {
|
||||
return static_cast<int>(key_xevent->state);
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace gtk
|
@ -2,33 +2,28 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef UI_GTK_X_GTK_UI_DELEGATE_X11_H_
|
||||
#define UI_GTK_X_GTK_UI_DELEGATE_X11_H_
|
||||
#ifndef UI_GTK_X_GTK_UI_PLATFORM_X11_H_
|
||||
#define UI_GTK_X_GTK_UI_PLATFORM_X11_H_
|
||||
|
||||
#include "base/component_export.h"
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
#include "ui/gfx/x/connection.h"
|
||||
#include "ui/gtk/gtk_ui_delegate.h"
|
||||
#include "ui/gtk/gtk_ui_platform.h"
|
||||
|
||||
using GdkDisplay = struct _GdkDisplay;
|
||||
|
||||
namespace ui {
|
||||
namespace gtk {
|
||||
|
||||
class GtkEventLoopX11;
|
||||
|
||||
// GtkUiDelegate implementation for desktop Linux X11 backends.
|
||||
//
|
||||
// TODO(crbug.com/1002674): For now, this is used by both Aura (legacy) and
|
||||
// Ozone X11. Move this into X11 Ozone backend once Linux Chrome migration to
|
||||
// Ozone is completed.
|
||||
class COMPONENT_EXPORT(UI_GTK_X) GtkUiDelegateX11 : public GtkUiDelegate {
|
||||
// GtkUiPlatform implementation for desktop Linux X11 backends.
|
||||
class GtkUiPlatformX11 : public GtkUiPlatform {
|
||||
public:
|
||||
explicit GtkUiDelegateX11(x11::Connection* connection);
|
||||
GtkUiDelegateX11(const GtkUiDelegateX11&) = delete;
|
||||
GtkUiDelegateX11& operator=(const GtkUiDelegateX11&) = delete;
|
||||
~GtkUiDelegateX11() override;
|
||||
GtkUiPlatformX11();
|
||||
GtkUiPlatformX11(const GtkUiPlatformX11&) = delete;
|
||||
GtkUiPlatformX11& operator=(const GtkUiPlatformX11&) = delete;
|
||||
~GtkUiPlatformX11() override;
|
||||
|
||||
// GtkUiDelegate:
|
||||
// GtkUiPlatform:
|
||||
void OnInitialized(GtkWidget* widget) override;
|
||||
GdkKeymap* GetGdkKeymap() override;
|
||||
GdkWindow* GetGdkWindow(gfx::AcceleratedWidget window_id) override;
|
||||
@ -46,6 +41,6 @@ class COMPONENT_EXPORT(UI_GTK_X) GtkUiDelegateX11 : public GtkUiDelegate {
|
||||
std::unique_ptr<GtkEventLoopX11> event_loop_;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace gtk
|
||||
|
||||
#endif // UI_GTK_X_GTK_UI_DELEGATE_X11_H_
|
||||
#endif // UI_GTK_X_GTK_UI_PLATFORM_X11_H_
|
@ -381,7 +381,10 @@ if (ozone_platform_x11) {
|
||||
|
||||
buildflag_header("buildflags") {
|
||||
header = "buildflags.h"
|
||||
flags = [ "OZONE_PLATFORM_X11=$ozone_platform_x11" ]
|
||||
flags = [
|
||||
"OZONE_PLATFORM_WAYLAND=$ozone_platform_wayland",
|
||||
"OZONE_PLATFORM_X11=$ozone_platform_x11",
|
||||
]
|
||||
visibility += [ "*" ]
|
||||
}
|
||||
|
||||
|
@ -221,12 +221,8 @@ source_set("wayland") {
|
||||
|
||||
if (use_gtk) {
|
||||
sources += [
|
||||
"host/gtk_ui_delegate_wayland.cc",
|
||||
"host/gtk_ui_delegate_wayland.h",
|
||||
]
|
||||
deps += [
|
||||
"//ui/gtk:gtk_ui_delegate",
|
||||
"//ui/gtk/wayland",
|
||||
"host/linux_ui_delegate_wayland.cc",
|
||||
"host/linux_ui_delegate_wayland.h",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,6 @@ include_rules = [
|
||||
"+ui/base/buildflags.h", # Doesn't bring in all of ui/base.
|
||||
"+ui/base/hit_test.h", # UI hit test doesn't bring in all of ui/base.
|
||||
"+ui/base/ui_base_features.h",
|
||||
"+ui/gtk/gtk_ui_delegate.h",
|
||||
"+ui/gtk/wayland/gtk_ui_delegate_wayland_base.h",
|
||||
"+mojo/public",
|
||||
"+third_party/wayland",
|
||||
"+ui/base/clipboard/clipboard_constants.h",
|
||||
|
@ -5,5 +5,5 @@ include_rules = [
|
||||
"+chromeos/lacros/lacros_chrome_service_impl.h",
|
||||
"+chromeos/ui/base",
|
||||
# Common includes.
|
||||
"+ui/base/linux/linux_desktop.h",
|
||||
"+ui/base/linux",
|
||||
]
|
||||
|
@ -1,33 +0,0 @@
|
||||
// Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_GTK_UI_DELEGATE_WAYLAND_H_
|
||||
#define UI_OZONE_PLATFORM_WAYLAND_HOST_GTK_UI_DELEGATE_WAYLAND_H_
|
||||
|
||||
#include "ui/gtk/wayland/gtk_ui_delegate_wayland_base.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class WaylandConnection;
|
||||
|
||||
class GtkUiDelegateWayland : public GtkUiDelegateWaylandBase {
|
||||
public:
|
||||
explicit GtkUiDelegateWayland(WaylandConnection* connection);
|
||||
~GtkUiDelegateWayland() override;
|
||||
|
||||
// GtkUiDelegateWaylandBase:
|
||||
bool SetGtkWidgetTransientForImpl(
|
||||
gfx::AcceleratedWidget parent,
|
||||
base::OnceCallback<void(const std::string&)> callback) override;
|
||||
|
||||
// GtkUiDelegate:
|
||||
int GetGdkKeyState() override;
|
||||
|
||||
private:
|
||||
WaylandConnection* const connection_;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif // UI_OZONE_PLATFORM_WAYLAND_HOST_GTK_UI_DELEGATE_WAYLAND_H_
|
@ -2,11 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ui/ozone/platform/wayland/host/gtk_ui_delegate_wayland.h"
|
||||
#include "ui/ozone/platform/wayland/host/linux_ui_delegate_wayland.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "ui/base/linux/linux_ui_delegate.h"
|
||||
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
|
||||
#include "ui/ozone/platform/wayland/host/wayland_event_source.h"
|
||||
#include "ui/ozone/platform/wayland/host/wayland_surface.h"
|
||||
@ -17,14 +18,18 @@
|
||||
|
||||
namespace ui {
|
||||
|
||||
GtkUiDelegateWayland::GtkUiDelegateWayland(WaylandConnection* connection)
|
||||
LinuxUiDelegateWayland::LinuxUiDelegateWayland(WaylandConnection* connection)
|
||||
: connection_(connection) {
|
||||
DCHECK(connection_);
|
||||
}
|
||||
|
||||
GtkUiDelegateWayland::~GtkUiDelegateWayland() = default;
|
||||
LinuxUiDelegateWayland::~LinuxUiDelegateWayland() = default;
|
||||
|
||||
bool GtkUiDelegateWayland::SetGtkWidgetTransientForImpl(
|
||||
LinuxUiBackend LinuxUiDelegateWayland::GetBackend() const {
|
||||
return LinuxUiBackend::kWayland;
|
||||
}
|
||||
|
||||
bool LinuxUiDelegateWayland::SetWidgetTransientFor(
|
||||
gfx::AcceleratedWidget parent,
|
||||
base::OnceCallback<void(const std::string&)> callback) {
|
||||
auto* parent_window =
|
||||
@ -39,7 +44,7 @@ bool GtkUiDelegateWayland::SetGtkWidgetTransientForImpl(
|
||||
return true;
|
||||
}
|
||||
|
||||
int GtkUiDelegateWayland::GetGdkKeyState() {
|
||||
int LinuxUiDelegateWayland::GetKeyState() {
|
||||
// TODO(crbug/1159460): Test fcitx unikey IME on ozone/wayland.
|
||||
return connection_->event_source()->keyboard_modifiers();
|
||||
}
|
33
ui/ozone/platform/wayland/host/linux_ui_delegate_wayland.h
Normal file
33
ui/ozone/platform/wayland/host/linux_ui_delegate_wayland.h
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_LINUX_UI_DELEGATE_WAYLAND_H_
|
||||
#define UI_OZONE_PLATFORM_WAYLAND_HOST_LINUX_UI_DELEGATE_WAYLAND_H_
|
||||
|
||||
#include "ui/base/linux/linux_ui_delegate.h"
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class WaylandConnection;
|
||||
|
||||
class LinuxUiDelegateWayland : public LinuxUiDelegate {
|
||||
public:
|
||||
explicit LinuxUiDelegateWayland(WaylandConnection* connection);
|
||||
~LinuxUiDelegateWayland() override;
|
||||
|
||||
// LinuxUiDelegate:
|
||||
LinuxUiBackend GetBackend() const override;
|
||||
bool SetWidgetTransientFor(
|
||||
gfx::AcceleratedWidget parent,
|
||||
base::OnceCallback<void(const std::string&)> callback) override;
|
||||
int GetKeyState() override;
|
||||
|
||||
private:
|
||||
WaylandConnection* const connection_;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif // UI_OZONE_PLATFORM_WAYLAND_HOST_LINUX_UI_DELEGATE_WAYLAND_H_
|
@ -59,8 +59,7 @@
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
#include "ui/gtk/gtk_ui_delegate.h" // nogncheck
|
||||
#include "ui/ozone/platform/wayland/host/gtk_ui_delegate_wayland.h" //nogncheck
|
||||
#include "ui/ozone/platform/wayland/host/linux_ui_delegate_wayland.h" // nogncheck
|
||||
#endif
|
||||
|
||||
namespace ui {
|
||||
@ -185,10 +184,8 @@ class OzonePlatformWayland : public OzonePlatform {
|
||||
supported_buffer_formats_ =
|
||||
connection_->buffer_manager_host()->GetSupportedBufferFormats();
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
DCHECK(!GtkUiDelegate::instance());
|
||||
gtk_ui_delegate_ =
|
||||
std::make_unique<GtkUiDelegateWayland>(connection_.get());
|
||||
GtkUiDelegate::SetInstance(gtk_ui_delegate_.get());
|
||||
gtk_ui_platform_ =
|
||||
std::make_unique<LinuxUiDelegateWayland>(connection_.get());
|
||||
#endif
|
||||
|
||||
menu_utils_ = std::make_unique<WaylandMenuUtils>(connection_.get());
|
||||
@ -322,7 +319,7 @@ class OzonePlatformWayland : public OzonePlatform {
|
||||
DrmRenderNodePathFinder path_finder_;
|
||||
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
std::unique_ptr<GtkUiDelegateWayland> gtk_ui_delegate_;
|
||||
std::unique_ptr<LinuxUiDelegateWayland> gtk_ui_platform_;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(OzonePlatformWayland);
|
||||
|
@ -3,7 +3,6 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//build/config/chromeos/ui_mode.gni")
|
||||
import("//build/config/linux/gtk/gtk.gni")
|
||||
import("//gpu/vulkan/features.gni")
|
||||
import("//ui/base/ui_features.gni")
|
||||
|
||||
@ -92,10 +91,6 @@ source_set("x11") {
|
||||
deps += [ "//gpu/vulkan/x" ]
|
||||
}
|
||||
|
||||
if (use_gtk) {
|
||||
deps += [ "//ui/gtk/x" ]
|
||||
}
|
||||
|
||||
if (use_xkbcommon) {
|
||||
configs += [ "//ui/events/ozone/layout:xkbcommon" ]
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
include_rules = [
|
||||
"+ui/base/x",
|
||||
"+ui/base",
|
||||
"+ui/gtk/gtk_ui_delegate.h",
|
||||
"+ui/gtk/x/gtk_ui_delegate_x11.h",
|
||||
]
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "ui/base/dragdrop/os_exchange_data_provider_factory.h"
|
||||
#include "ui/base/dragdrop/os_exchange_data_provider_factory_ozone.h"
|
||||
#include "ui/base/ime/linux/linux_input_method_context_factory.h"
|
||||
#include "ui/base/linux/linux_ui_delegate.h"
|
||||
#include "ui/base/x/x11_cursor_factory.h"
|
||||
#include "ui/base/x/x11_util.h"
|
||||
#include "ui/display/fake/fake_display_delegate.h"
|
||||
@ -58,15 +59,18 @@
|
||||
#include "ui/ozone/platform/x11/x11_os_exchange_data_provider_ozone.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
#include "ui/gtk/gtk_ui_delegate.h" // nogncheck
|
||||
#include "ui/gtk/x/gtk_ui_delegate_x11.h" // nogncheck
|
||||
#endif
|
||||
|
||||
namespace ui {
|
||||
|
||||
namespace {
|
||||
|
||||
class LinuxUiDelegateX11 : public LinuxUiDelegate {
|
||||
public:
|
||||
~LinuxUiDelegateX11() override = default;
|
||||
|
||||
// LinuxUiDelegate:
|
||||
LinuxUiBackend GetBackend() const override { return LinuxUiBackend::kX11; }
|
||||
};
|
||||
|
||||
// Singleton OzonePlatform implementation for X11 platform.
|
||||
class OzonePlatformX11 : public OzonePlatform,
|
||||
public ui::OSExchangeDataProviderFactoryOzone {
|
||||
@ -241,10 +245,7 @@ class OzonePlatformX11 : public OzonePlatform,
|
||||
TouchFactory::SetTouchDeviceListFromCommandLine();
|
||||
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
DCHECK(!GtkUiDelegate::instance());
|
||||
gtk_ui_delegate_ =
|
||||
std::make_unique<GtkUiDelegateX11>(x11::Connection::Get());
|
||||
GtkUiDelegate::SetInstance(gtk_ui_delegate_.get());
|
||||
linux_ui_delegate_ = std::make_unique<LinuxUiDelegateX11>();
|
||||
#endif
|
||||
|
||||
menu_utils_ = std::make_unique<X11MenuUtils>();
|
||||
@ -328,7 +329,7 @@ class OzonePlatformX11 : public OzonePlatform,
|
||||
std::unique_ptr<X11EventSource> event_source_;
|
||||
|
||||
#if BUILDFLAG(USE_GTK)
|
||||
std::unique_ptr<GtkUiDelegate> gtk_ui_delegate_;
|
||||
std::unique_ptr<LinuxUiDelegate> linux_ui_delegate_;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(OzonePlatformX11);
|
||||
|
@ -17,17 +17,17 @@ views::LinuxUI* g_linux_ui = nullptr;
|
||||
|
||||
namespace views {
|
||||
|
||||
void LinuxUI::SetInstance(LinuxUI* instance) {
|
||||
void LinuxUI::SetInstance(std::unique_ptr<LinuxUI> instance) {
|
||||
delete g_linux_ui;
|
||||
g_linux_ui = instance;
|
||||
g_linux_ui = instance.release();
|
||||
// Do not set IME instance for ozone as we delegate creating the input method
|
||||
// to OzonePlatforms instead. If this is set, OzonePlatform never sets a
|
||||
// context factory.
|
||||
if (!features::IsUsingOzonePlatform())
|
||||
LinuxInputMethodContextFactory::SetInstance(instance);
|
||||
SkiaFontDelegate::SetInstance(instance);
|
||||
ShellDialogLinux::SetInstance(instance);
|
||||
ui::SetTextEditKeyBindingsDelegate(instance);
|
||||
LinuxInputMethodContextFactory::SetInstance(g_linux_ui);
|
||||
SkiaFontDelegate::SetInstance(g_linux_ui);
|
||||
ShellDialogLinux::SetInstance(g_linux_ui);
|
||||
ui::SetTextEditKeyBindingsDelegate(g_linux_ui);
|
||||
}
|
||||
|
||||
LinuxUI* LinuxUI::instance() {
|
||||
|
@ -82,7 +82,7 @@ class VIEWS_EXPORT LinuxUI : public ui::LinuxInputMethodContextFactory,
|
||||
~LinuxUI() override;
|
||||
|
||||
// Sets the dynamically loaded singleton that draws the desktop native UI.
|
||||
static void SetInstance(LinuxUI* instance);
|
||||
static void SetInstance(std::unique_ptr<LinuxUI> instance);
|
||||
|
||||
// Returns a LinuxUI instance for the toolkit used in the user's desktop
|
||||
// environment.
|
||||
|
Reference in New Issue
Block a user