File: fallback_linux_ui.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (198 lines) | stat: -rw-r--r-- 6,117 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// 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/base/ime/linux/linux_input_method_context.h"
#include "ui/base/ui_base_switches.h"
#include "ui/events/keycodes/dom/dom_keyboard_layout_map.h"
#include "ui/gfx/font_render_params.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/platform_font.h"
#include "ui/linux/nav_button_provider.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() = default;

FallbackLinuxUi::~FallbackLinuxUi() = default;

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

gfx::FontRenderParams FallbackLinuxUi::GetDefaultFontRenderParams() {
  if (!default_font_render_params_.has_value()) {
    InitializeFontSettings();
  }
  return *default_font_render_params_;
}

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;
}

void FallbackLinuxUi::InitializeFontSettings() {
  gfx::FontRenderParamsQuery query;
  query.pixel_size = gfx::PlatformFont::kDefaultBaseFontSize;
  query.style = gfx::Font::NORMAL;
  query.weight = gfx::Font::Weight::NORMAL;
  query.device_scale_factor = display_config().primary_scale;
  std::string default_font_family;
  // gfx::GetFontRenderParams() calls GetDefaultFontRenderParams(), so
  // initialize `default_font_render_params_`.  This is intended to use
  // the FontConfig settings when there's no toolkit to obtain font
  // settings from.
  default_font_render_params_ = gfx::FontRenderParams();
  default_font_render_params_ =
      gfx::GetFontRenderParams(query, &default_font_family);
  set_default_font_settings(FontSettings{
      .family = std::move(default_font_family),
      .size_pixels = query.pixel_size,
      .style = query.style,
      .weight = static_cast<int>(query.weight),
  });
}

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;
  }
}

std::vector<std::string> FallbackLinuxUi::GetCmdLineFlagsForCopy() const {
  return {std::string(switches::kUiToolkitFlag) + "=fallback"};
}

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

void FallbackLinuxUi::SetDarkTheme(bool dark) {
  theme_is_dark_ = dark;
}

void FallbackLinuxUi::SetAccentColor(std::optional<SkColor> accent_color) {}

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,
    bool tiled,
    bool maximized) {
  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();
}

ui::TextEditCommand FallbackLinuxUi::GetTextEditCommandForEvent(
    const ui::Event& event,
    int text_flags) {
  return ui::TextEditCommand::INVALID_COMMAND;
}

#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