Skip to content

Commit

Permalink
Add fallback Linux UI for when GTK 3.20 isn't available
Browse files Browse the repository at this point in the history
The minimum required version of GTK is 3.20 after [1] since all
supported distros have it available.  However, we still have
some infra without GTK 3.20, so this CL adds a fallback codepath
for when GTK 3.20 isn't available.

This CL incidentally makes GTK an optional dependency in Chrome.
For now, the manual dependency will be kept in the deb/rpm packages.

[1] https://crrev.com/1104801

R=thestig,sky

Change-Id: I6f30b7298a13a75602b98547bdfbf9dbc6bab99b
Bug: b/270232634
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4295455
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1111248}
  • Loading branch information
tanderson-google authored and Chromium LUCI CQ committed Feb 28, 2023
1 parent c8ecb5c commit 38f7473
Show file tree
Hide file tree
Showing 14 changed files with 385 additions and 77 deletions.
18 changes: 9 additions & 9 deletions chrome/browser/renderer_preferences_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ void UpdateFromSystemSettings(blink::RendererPreferences* prefs,
auto* linux_ui_theme = ui::LinuxUiTheme::GetForProfile(profile);
if (linux_ui_theme) {
if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
prefs->focus_ring_color = linux_ui_theme->GetFocusRingColor();
prefs->active_selection_bg_color =
linux_ui_theme->GetActiveSelectionBgColor();
prefs->active_selection_fg_color =
linux_ui_theme->GetActiveSelectionFgColor();
prefs->inactive_selection_bg_color =
linux_ui_theme->GetInactiveSelectionBgColor();
prefs->inactive_selection_fg_color =
linux_ui_theme->GetInactiveSelectionFgColor();
linux_ui_theme->GetFocusRingColor(&prefs->focus_ring_color);
linux_ui_theme->GetActiveSelectionBgColor(
&prefs->active_selection_bg_color);
linux_ui_theme->GetActiveSelectionFgColor(
&prefs->active_selection_fg_color);
linux_ui_theme->GetInactiveSelectionBgColor(
&prefs->inactive_selection_bg_color);
linux_ui_theme->GetInactiveSelectionFgColor(
&prefs->inactive_selection_fg_color);
}
}

Expand Down
15 changes: 10 additions & 5 deletions printing/printing_context_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ mojom::ResultCode PrintingContextLinux::UseDefaultSettings() {

if (!print_dialog_)
print_dialog_ = ui::LinuxUi::instance()->CreatePrintDialog(this);
print_dialog_->UseDefaultSettings();

if (print_dialog_) {
print_dialog_->UseDefaultSettings();
}
#endif

return mojom::ResultCode::kSuccess;
Expand All @@ -101,10 +104,12 @@ mojom::ResultCode PrintingContextLinux::UpdatePrinterSettings(
if (!print_dialog_)
print_dialog_ = ui::LinuxUi::instance()->CreatePrintDialog(this);

// PrintDialogGtk::UpdateSettings() calls InitWithSettings() so settings_ will
// remain non-null after this line.
print_dialog_->UpdateSettings(std::move(settings_));
DCHECK(settings_);
if (print_dialog_) {
// PrintDialogGtk::UpdateSettings() calls InitWithSettings() so settings_ will
// remain non-null after this line.
print_dialog_->UpdateSettings(std::move(settings_));
DCHECK(settings_);
}
#endif

return mojom::ResultCode::kSuccess;
Expand Down
22 changes: 11 additions & 11 deletions ui/gtk/gtk_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ GtkUiPlatform* GtkUi::GetPlatform() {
}

bool GtkUi::Initialize() {
if (!LoadGtk()) {
if (!LoadGtk() || !GtkCheckVersion(3, 20)) {
return false;
}

Expand Down Expand Up @@ -278,24 +278,24 @@ bool GtkUi::GetDisplayProperty(int id, int* result) const {
return false;
}

SkColor GtkUi::GetFocusRingColor() const {
return focus_ring_color_;
void GtkUi::GetFocusRingColor(SkColor* color) const {
*color = focus_ring_color_;
}

SkColor GtkUi::GetActiveSelectionBgColor() const {
return active_selection_bg_color_;
void GtkUi::GetActiveSelectionBgColor(SkColor* color) const {
*color = active_selection_bg_color_;
}

SkColor GtkUi::GetActiveSelectionFgColor() const {
return active_selection_fg_color_;
void GtkUi::GetActiveSelectionFgColor(SkColor* color) const {
*color = active_selection_fg_color_;
}

SkColor GtkUi::GetInactiveSelectionBgColor() const {
return inactive_selection_bg_color_;
void GtkUi::GetInactiveSelectionBgColor(SkColor* color) const {
*color = inactive_selection_bg_color_;
}

SkColor GtkUi::GetInactiveSelectionFgColor() const {
return inactive_selection_fg_color_;
void GtkUi::GetInactiveSelectionFgColor(SkColor* color) const {
*color = inactive_selection_fg_color_;
}

base::TimeDelta GtkUi::GetCursorBlinkInterval() const {
Expand Down
10 changes: 5 additions & 5 deletions ui/gtk/gtk_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ class GtkUi : public ui::LinuxUiAndTheme {
ui::NativeTheme* GetNativeTheme() const override;
bool GetColor(int id, SkColor* color, bool use_custom_frame) const override;
bool GetDisplayProperty(int id, int* result) const override;
SkColor GetFocusRingColor() const override;
SkColor GetActiveSelectionBgColor() const override;
SkColor GetActiveSelectionFgColor() const override;
SkColor GetInactiveSelectionBgColor() const override;
SkColor GetInactiveSelectionFgColor() const override;
void GetFocusRingColor(SkColor* color) const override;
void GetActiveSelectionBgColor(SkColor* color) const override;
void GetActiveSelectionFgColor(SkColor* color) const override;
void GetInactiveSelectionBgColor(SkColor* color) const override;
void GetInactiveSelectionFgColor(SkColor* color) const override;
bool PreferDarkTheme() const override;
std::unique_ptr<ui::NavButtonProvider> CreateNavButtonProvider() override;
ui::WindowFrameProvider* GetWindowFrameProvider(bool solid_frame) override;
Expand Down
10 changes: 9 additions & 1 deletion ui/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ component("linux_ui") {
component("linux_ui_factory") {
defines = [ "IS_LINUX_UI_FACTORY_IMPL" ]
public = [ "linux_ui_factory.h" ]
sources = [ "linux_ui_factory.cc" ]
sources = [
"fallback_linux_ui.cc",
"fallback_linux_ui.h",
"linux_ui_factory.cc",
]

public_deps = [
":linux_ui",
Expand All @@ -48,7 +52,11 @@ component("linux_ui_factory") {
deps = [
"//base",
"//ui/base:buildflags",
"//ui/events:dom_keyboard_layout",
"//ui/gfx",
"//ui/native_theme",
"//ui/shell_dialogs",
"//ui/views",
]
if (use_gtk) {
# This is the only component that can interact with gtk.
Expand Down
4 changes: 4 additions & 0 deletions ui/linux/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ specific_include_rules = {
"+ui/gtk",
"+ui/qt",
],
"fallback_linux_ui.cc": [
"+ui/events/keycodes",
"+ui/views/controls",
],
}
20 changes: 10 additions & 10 deletions ui/linux/fake_linux_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,24 @@ bool FakeLinuxUi::GetDisplayProperty(int id, int* result) const {
return false;
}

SkColor FakeLinuxUi::GetFocusRingColor() const {
return gfx::kPlaceholderColor;
void FakeLinuxUi::GetFocusRingColor(SkColor* color) const {
*color = gfx::kPlaceholderColor;
}

SkColor FakeLinuxUi::GetActiveSelectionBgColor() const {
return gfx::kPlaceholderColor;
void FakeLinuxUi::GetActiveSelectionBgColor(SkColor* color) const {
*color = gfx::kPlaceholderColor;
}

SkColor FakeLinuxUi::GetActiveSelectionFgColor() const {
return gfx::kPlaceholderColor;
void FakeLinuxUi::GetActiveSelectionFgColor(SkColor* color) const {
*color = gfx::kPlaceholderColor;
}

SkColor FakeLinuxUi::GetInactiveSelectionBgColor() const {
return gfx::kPlaceholderColor;
void FakeLinuxUi::GetInactiveSelectionBgColor(SkColor* color) const {
*color = gfx::kPlaceholderColor;
}

SkColor FakeLinuxUi::GetInactiveSelectionFgColor() const {
return gfx::kPlaceholderColor;
void FakeLinuxUi::GetInactiveSelectionFgColor(SkColor* color) const {
*color = gfx::kPlaceholderColor;
}

base::TimeDelta FakeLinuxUi::GetCursorBlinkInterval() const {
Expand Down
10 changes: 5 additions & 5 deletions ui/linux/fake_linux_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class FakeLinuxUi : public LinuxUiAndTheme {
ui::NativeTheme* GetNativeTheme() const override;
bool GetColor(int id, SkColor* color, bool use_custom_frame) const override;
bool GetDisplayProperty(int id, int* result) const override;
SkColor GetFocusRingColor() const override;
SkColor GetActiveSelectionBgColor() const override;
SkColor GetActiveSelectionFgColor() const override;
SkColor GetInactiveSelectionBgColor() const override;
SkColor GetInactiveSelectionFgColor() const override;
void GetFocusRingColor(SkColor* color) const override;
void GetActiveSelectionBgColor(SkColor* color) const override;
void GetActiveSelectionFgColor(SkColor* color) const override;
void GetInactiveSelectionBgColor(SkColor* color) const override;
void GetInactiveSelectionFgColor(SkColor* color) const override;
bool PreferDarkTheme() const override;
std::unique_ptr<ui::NavButtonProvider> CreateNavButtonProvider() override;
ui::WindowFrameProvider* GetWindowFrameProvider(bool solid_frame) override;
Expand Down
183 changes: 183 additions & 0 deletions ui/linux/fallback_linux_ui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/linux/fallback_linux_ui.h"

#include "base/time/time.h"
#include "ui/events/keycodes/dom/dom_keyboard_layout_map.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/platform_font.h"
#include "ui/native_theme/native_theme.h"
#include "ui/shell_dialogs/select_file_policy.h"
#include "ui/views/controls/textfield/textfield.h"

namespace ui {

FallbackLinuxUi::FallbackLinuxUi() {
gfx::FontRenderParamsQuery query;
query.pixel_size = gfx::PlatformFont::kDefaultBaseFontSize;
query.style = gfx::Font::NORMAL;
query.weight = gfx::Font::Weight::NORMAL;
query.device_scale_factor = GetDeviceScaleFactor();
default_font_render_params_ =
gfx::GetFontRenderParams(query, &default_font_family_);
}

FallbackLinuxUi::~FallbackLinuxUi() = default;

std::unique_ptr<ui::LinuxInputMethodContext>
FallbackLinuxUi::CreateInputMethodContext(
ui::LinuxInputMethodContextDelegate* delegate) const {
// Fallback to FakeInputMethodContext.
return nullptr;
}

gfx::FontRenderParams FallbackLinuxUi::GetDefaultFontRenderParams() const {
return default_font_render_params_;
}

void FallbackLinuxUi::GetDefaultFontDescription(
std::string* family_out,
int* size_pixels_out,
int* style_out,
int* weight_out,
gfx::FontRenderParams* params_out) const {
*family_out = default_font_family_;
*size_pixels_out = gfx::PlatformFont::kDefaultBaseFontSize;
*style_out = gfx::Font::NORMAL;
*weight_out = static_cast<int>(gfx::Font::Weight::NORMAL);
*params_out = GetDefaultFontRenderParams();
}

ui::SelectFileDialog* FallbackLinuxUi::CreateSelectFileDialog(
void* listener,
std::unique_ptr<ui::SelectFilePolicy> policy) const {
// The toolkit select file dialog is a last choice used only when
// the freedesktop portal interface isn't available and the desktop
// isn't KDE. If neither condition is met, a dialog won't be created.
NOTIMPLEMENTED();
return nullptr;
}

bool FallbackLinuxUi::Initialize() {
return true;
}

bool FallbackLinuxUi::GetColor(int id,
SkColor* color,
bool use_custom_frame) const {
return false;
}

bool FallbackLinuxUi::GetDisplayProperty(int id, int* result) const {
return false;
}

void FallbackLinuxUi::GetFocusRingColor(SkColor* color) const {}

void FallbackLinuxUi::GetActiveSelectionBgColor(SkColor* color) const {}

void FallbackLinuxUi::GetActiveSelectionFgColor(SkColor* color) const {}

void FallbackLinuxUi::GetInactiveSelectionBgColor(SkColor* color) const {}

void FallbackLinuxUi::GetInactiveSelectionFgColor(SkColor* color) const {}

base::TimeDelta FallbackLinuxUi::GetCursorBlinkInterval() const {
return views::Textfield::GetCaretBlinkInterval();
}

gfx::Image FallbackLinuxUi::GetIconForContentType(
const std::string& content_type,
int size,
float scale) const {
// Fallback to using generic icons.
return gfx::Image();
}

LinuxUi::WindowFrameAction FallbackLinuxUi::GetWindowFrameAction(
WindowFrameActionSource source) {
switch (source) {
case WindowFrameActionSource::kDoubleClick:
return WindowFrameAction::kToggleMaximize;
case WindowFrameActionSource::kMiddleClick:
return WindowFrameAction::kNone;
case WindowFrameActionSource::kRightClick:
return WindowFrameAction::kMenu;
}
}

float FallbackLinuxUi::GetDeviceScaleFactor() const {
return 1.0f;
}

bool FallbackLinuxUi::PreferDarkTheme() const {
return false;
}

bool FallbackLinuxUi::AnimationsEnabled() const {
return true;
}

void FallbackLinuxUi::AddWindowButtonOrderObserver(
ui::WindowButtonOrderObserver* observer) {}

void FallbackLinuxUi::RemoveWindowButtonOrderObserver(
ui::WindowButtonOrderObserver* observer) {}

std::unique_ptr<ui::NavButtonProvider>
FallbackLinuxUi::CreateNavButtonProvider() {
return nullptr;
}

ui::WindowFrameProvider* FallbackLinuxUi::GetWindowFrameProvider(
bool solid_frame) {
return nullptr;
}

base::flat_map<std::string, std::string>
FallbackLinuxUi::GetKeyboardLayoutMap() {
return ui::GenerateDomKeyboardLayoutMap();
}

std::string FallbackLinuxUi::GetCursorThemeName() {
// This is only used on X11 where QT obtains the cursor theme from XSettings.
// However, ui/base/x/x11_cursor_loader.cc already handles this.
return std::string();
}

int FallbackLinuxUi::GetCursorThemeSize() {
// This is only used on X11 where QT obtains the cursor size from XSettings.
// However, ui/base/x/x11_cursor_loader.cc already handles this.
return 0;
}

ui::NativeTheme* FallbackLinuxUi::GetNativeTheme() const {
return ui::NativeTheme::GetInstanceForNativeUi();
}

bool FallbackLinuxUi::GetTextEditCommandsForEvent(
const ui::Event& event,
std::vector<ui::TextEditCommandAuraLinux>* commands) {
return false;
}

#if BUILDFLAG(ENABLE_PRINTING)
printing::PrintDialogLinuxInterface* FallbackLinuxUi::CreatePrintDialog(
printing::PrintingContextLinux* context) {
// A print dialog won't be created. Chrome's print dialog (Ctrl-P)
// should be used instead of the system (Ctrl-Shift-P) dialog.
NOTIMPLEMENTED();
return nullptr;
}

gfx::Size FallbackLinuxUi::GetPdfPaperSize(
printing::PrintingContextLinux* context) {
return gfx::Size();
}
#endif

} // namespace ui
Loading

0 comments on commit 38f7473

Please sign in to comment.