summaryrefslogtreecommitdiff
path: root/chromium/ui/qt/qt_ui.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/qt/qt_ui.cc')
-rw-r--r--chromium/ui/qt/qt_ui.cc233
1 files changed, 169 insertions, 64 deletions
diff --git a/chromium/ui/qt/qt_ui.cc b/chromium/ui/qt/qt_ui.cc
index 41e16bbb30f..5cb57982e34 100644
--- a/chromium/ui/qt/qt_ui.cc
+++ b/chromium/ui/qt/qt_ui.cc
@@ -9,23 +9,30 @@
#include "base/check.h"
#include "base/command_line.h"
#include "base/cxx17_backports.h"
+#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/path_service.h"
+#include "base/time/time.h"
+#include "chrome/browser/themes/theme_properties.h" // nogncheck
#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/base/ime/linux/linux_input_method_context.h"
#include "ui/color/color_mixer.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_recipe.h"
#include "ui/gfx/color_palette.h"
+#include "ui/gfx/color_utils.h"
#include "ui/gfx/font.h"
#include "ui/gfx/font_render_params.h"
#include "ui/gfx/font_render_params_linux.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia_rep.h"
#include "ui/gfx/image/image_skia_source.h"
+#include "ui/linux/linux_ui.h"
#include "ui/native_theme/native_theme_aura.h"
#include "ui/native_theme/native_theme_base.h"
#include "ui/qt/qt_interface.h"
#include "ui/shell_dialogs/select_file_policy.h"
+#include "ui/shell_dialogs/shell_dialog_linux.h"
#include "ui/views/controls/button/label_button_border.h"
namespace qt {
@@ -73,27 +80,54 @@ gfx::FontRenderParams::Hinting QtHintingToGfxHinting(
} // namespace
-// We currently don't render any QT widgets, so this class is just a stub.
class QtNativeTheme : public ui::NativeThemeAura {
public:
- QtNativeTheme()
+ explicit QtNativeTheme(QtInterface* shim)
: ui::NativeThemeAura(/*use_overlay_scrollbars=*/false,
/*should_only_use_dark_colors=*/false,
- /*is_custom_system_theme=*/true) {}
+ /*is_custom_system_theme=*/true),
+ shim_(shim) {}
QtNativeTheme(const QtNativeTheme&) = delete;
QtNativeTheme& operator=(const QtNativeTheme&) = delete;
~QtNativeTheme() override = default;
+
+ // ui::NativeTheme:
+ void PaintFrameTopArea(cc::PaintCanvas* canvas,
+ State state,
+ const gfx::Rect& rect,
+ const FrameTopAreaExtraParams& frame_top_area,
+ ColorScheme color_scheme) const override {
+ auto image = shim_->DrawHeader(
+ rect.width(), rect.height(), frame_top_area.default_background_color,
+ frame_top_area.is_active ? ColorState::kNormal : ColorState::kInactive,
+ frame_top_area.use_custom_frame);
+ SkImageInfo image_info = SkImageInfo::Make(
+ image.width, image.height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
+ SkBitmap bitmap;
+ bitmap.installPixels(
+ image_info, image.data_argb.Take(), image_info.minRowBytes(),
+ [](void* data, void*) { free(data); }, nullptr);
+ bitmap.setImmutable();
+ canvas->drawImage(cc::PaintImage::CreateFromBitmap(std::move(bitmap)),
+ rect.x(), rect.y());
+ }
+
+ private:
+ raw_ptr<QtInterface> const shim_;
};
-QtUi::QtUi() = default;
+QtUi::QtUi(std::unique_ptr<ui::LinuxUi> fallback_linux_ui)
+ : fallback_linux_ui_(std::move(fallback_linux_ui)) {}
-QtUi::~QtUi() = default;
+QtUi::~QtUi() {
+ shell_dialog_linux::Finalize();
+}
std::unique_ptr<ui::LinuxInputMethodContext> QtUi::CreateInputMethodContext(
- ui::LinuxInputMethodContextDelegate* delegate,
- bool is_simple) const {
- NOTIMPLEMENTED_LOG_ONCE();
- return nullptr;
+ ui::LinuxInputMethodContextDelegate* delegate) const {
+ return fallback_linux_ui_
+ ? fallback_linux_ui_->CreateInputMethodContext(delegate)
+ : nullptr;
}
gfx::FontRenderParams QtUi::GetDefaultFontRenderParams() const {
@@ -103,7 +137,7 @@ gfx::FontRenderParams QtUi::GetDefaultFontRenderParams() const {
void QtUi::GetDefaultFontDescription(std::string* family_out,
int* size_pixels_out,
int* style_out,
- gfx::Font::Weight* weight_out,
+ int* weight_out,
gfx::FontRenderParams* params_out) const {
if (family_out)
*family_out = font_family_;
@@ -118,10 +152,11 @@ void QtUi::GetDefaultFontDescription(std::string* family_out,
}
ui::SelectFileDialog* QtUi::CreateSelectFileDialog(
- ui::SelectFileDialog::Listener* listener,
+ void* listener,
std::unique_ptr<ui::SelectFilePolicy> policy) const {
- NOTIMPLEMENTED_LOG_ONCE();
- return nullptr;
+ return fallback_linux_ui_ ? fallback_linux_ui_->CreateSelectFileDialog(
+ listener, std::move(policy))
+ : nullptr;
}
bool QtUi::Initialize() {
@@ -138,57 +173,54 @@ bool QtUi::Initialize() {
cmd_line_ = CopyCmdLine(*base::CommandLine::ForCurrentProcess());
shim_.reset((reinterpret_cast<decltype(&CreateQtInterface)>(
create_qt_interface)(this, &cmd_line_.argc, cmd_line_.argv.data())));
- native_theme_ = std::make_unique<QtNativeTheme>();
+ native_theme_ = std::make_unique<QtNativeTheme>(shim_.get());
ui::ColorProviderManager::Get().AppendColorProviderInitializer(
base::BindRepeating(&QtUi::AddNativeColorMixer, base::Unretained(this)));
FontChanged();
+ shell_dialog_linux::Initialize();
return true;
}
-bool QtUi::GetTint(int id, color_utils::HSL* tint) const {
- NOTIMPLEMENTED_LOG_ONCE();
- return false;
-}
-
bool QtUi::GetColor(int id, SkColor* color, bool use_custom_frame) const {
- NOTIMPLEMENTED_LOG_ONCE();
- return false;
+ auto value = GetColor(id, use_custom_frame);
+ if (value)
+ *color = *value;
+ return value.has_value();
}
bool QtUi::GetDisplayProperty(int id, int* result) const {
- NOTIMPLEMENTED_LOG_ONCE();
- return false;
+ switch (id) {
+ case ThemeProperties::SHOULD_FILL_BACKGROUND_TAB_COLOR:
+ *result = false;
+ return true;
+ default:
+ return false;
+ }
}
SkColor QtUi::GetFocusRingColor() const {
- NOTIMPLEMENTED_LOG_ONCE();
- return gfx::kPlaceholderColor;
+ return shim_->GetColor(ColorType::kHighlightBg, ColorState::kNormal);
}
SkColor QtUi::GetActiveSelectionBgColor() const {
- NOTIMPLEMENTED_LOG_ONCE();
- return gfx::kPlaceholderColor;
+ return shim_->GetColor(ColorType::kHighlightBg, ColorState::kNormal);
}
SkColor QtUi::GetActiveSelectionFgColor() const {
- NOTIMPLEMENTED_LOG_ONCE();
- return gfx::kPlaceholderColor;
+ return shim_->GetColor(ColorType::kHighlightFg, ColorState::kNormal);
}
SkColor QtUi::GetInactiveSelectionBgColor() const {
- NOTIMPLEMENTED_LOG_ONCE();
- return gfx::kPlaceholderColor;
+ return shim_->GetColor(ColorType::kHighlightBg, ColorState::kInactive);
}
SkColor QtUi::GetInactiveSelectionFgColor() const {
- NOTIMPLEMENTED_LOG_ONCE();
- return gfx::kPlaceholderColor;
+ return shim_->GetColor(ColorType::kHighlightFg, ColorState::kInactive);
}
base::TimeDelta QtUi::GetCursorBlinkInterval() const {
- NOTIMPLEMENTED_LOG_ONCE();
- return base::TimeDelta();
+ return base::Milliseconds(shim_->GetCursorBlinkIntervalMs());
}
gfx::Image QtUi::GetIconForContentType(const std::string& content_type,
@@ -231,28 +263,27 @@ float QtUi::GetDeviceScaleFactor() const {
}
bool QtUi::PreferDarkTheme() const {
- NOTIMPLEMENTED_LOG_ONCE();
- return false;
+ return color_utils::IsDark(
+ shim_->GetColor(ColorType::kWindowBg, ColorState::kNormal));
}
bool QtUi::AnimationsEnabled() const {
- NOTIMPLEMENTED_LOG_ONCE();
- return true;
+ return shim_->GetAnimationDurationMs() > 0;
}
-std::unique_ptr<views::NavButtonProvider> QtUi::CreateNavButtonProvider() {
+std::unique_ptr<ui::NavButtonProvider> QtUi::CreateNavButtonProvider() {
// QT prefers server-side decorations.
return nullptr;
}
-views::WindowFrameProvider* QtUi::GetWindowFrameProvider(bool solid_frame) {
+ui::WindowFrameProvider* QtUi::GetWindowFrameProvider(bool solid_frame) {
// QT prefers server-side decorations.
return nullptr;
}
base::flat_map<std::string, std::string> QtUi::GetKeyboardLayoutMap() {
- NOTIMPLEMENTED_LOG_ONCE();
- return {};
+ return fallback_linux_ui_ ? fallback_linux_ui_->GetKeyboardLayoutMap()
+ : base::flat_map<std::string, std::string>{};
}
std::string QtUi::GetCursorThemeName() {
@@ -267,29 +298,29 @@ int QtUi::GetCursorThemeSize() {
return 0;
}
-std::vector<std::string> QtUi::GetAvailableSystemThemeNamesForTest() const {
- // In QT, themes are binary plugins that are loaded on start and can't be
- // changed at runtime. The style may change, but there's no common interface
- // for doing this from a client. Return a single empty theme here to
- // represent the current theme.
- return {std::string()};
+ui::NativeTheme* QtUi::GetNativeThemeImpl() const {
+ return native_theme_.get();
}
-void QtUi::SetSystemThemeByNameForTest(const std::string& theme_name) {
- // Ensure we only get passed the "current theme" name that we returned from
- // GetAvailableSystemThemeNamesForTest() above.
- DCHECK(theme_name.empty());
+bool QtUi::GetTextEditCommandsForEvent(
+ const ui::Event& event,
+ std::vector<ui::TextEditCommandAuraLinux>* commands) {
+ // QT doesn't have "key themes" (eg. readline bindings) like GTK.
+ return false;
}
-ui::NativeTheme* QtUi::GetNativeTheme() const {
- return native_theme_.get();
+#if BUILDFLAG(ENABLE_PRINTING)
+printing::PrintDialogLinuxInterface* QtUi::CreatePrintDialog(
+ printing::PrintingContextLinux* context) {
+ return fallback_linux_ui_ ? fallback_linux_ui_->CreatePrintDialog(context)
+ : nullptr;
}
-bool QtUi::MatchEvent(const ui::Event& event,
- std::vector<ui::TextEditCommandAuraLinux>* commands) {
- // QT doesn't have "key themes" (eg. readline bindings) like GTK.
- return false;
+gfx::Size QtUi::GetPdfPaperSize(printing::PrintingContextLinux* context) {
+ return fallback_linux_ui_ ? fallback_linux_ui_->GetPdfPaperSize(context)
+ : gfx::Size();
}
+#endif
void QtUi::FontChanged() {
auto params = shim_->GetFontRenderParams();
@@ -304,15 +335,14 @@ void QtUi::FontChanged() {
font_size_pixels_ = font_size_points_ * GetDeviceScaleFactor();
}
font_style_ = desc.is_italic ? gfx::Font::ITALIC : gfx::Font::NORMAL;
- font_weight_ =
- static_cast<gfx::Font::Weight>(QtWeightToCssWeight(desc.weight));
+ font_weight_ = QtWeightToCssWeight(desc.weight);
gfx::FontRenderParamsQuery query;
query.families = {font_family_};
query.pixel_size = font_size_pixels_;
query.point_size = font_size_points_;
query.style = font_style_;
- query.weight = font_weight_;
+ query.weight = static_cast<gfx::Font::Weight>(font_weight_);
gfx::FontRenderParams fc_params;
gfx::QueryFontconfig(query, &fc_params, nullptr);
@@ -326,6 +356,10 @@ void QtUi::FontChanged() {
};
}
+void QtUi::ThemeChanged() {
+ native_theme_->NotifyOnNativeThemeUpdated();
+}
+
void QtUi::AddNativeColorMixer(ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key) {
if (key.system_theme == ui::ColorProviderManager::SystemTheme::kDefault)
@@ -385,10 +419,81 @@ void QtUi::AddNativeColorMixer(ui::ColorProvider* provider,
};
for (const auto& map : kMaps)
mixer[map.id] = {shim_->GetColor(map.role, map.state)};
+
+ mixer[ui::kColorFrameActive] = {
+ shim_->GetFrameColor(ColorState::kNormal, true)};
+ mixer[ui::kColorFrameInactive] = {
+ shim_->GetFrameColor(ColorState::kInactive, true)};
+}
+
+absl::optional<SkColor> QtUi::GetColor(int id, bool use_custom_frame) const {
+ switch (id) {
+ case ThemeProperties::COLOR_LOCATION_BAR_BORDER:
+ return shim_->GetColor(ColorType::kEntryFg, ColorState::kNormal);
+ case ThemeProperties::COLOR_TOOLBAR_CONTENT_AREA_SEPARATOR:
+ return shim_->GetColor(ColorType::kButtonFg, ColorState::kNormal);
+ case ThemeProperties::COLOR_TOOLBAR_VERTICAL_SEPARATOR:
+ return shim_->GetColor(ColorType::kButtonFg, ColorState::kNormal);
+ case ThemeProperties::COLOR_NTP_BACKGROUND:
+ return shim_->GetColor(ColorType::kEntryBg, ColorState::kNormal);
+ case ThemeProperties::COLOR_NTP_TEXT:
+ return shim_->GetColor(ColorType::kEntryFg, ColorState::kNormal);
+ case ThemeProperties::COLOR_NTP_HEADER:
+ return shim_->GetColor(ColorType::kButtonFg, ColorState::kNormal);
+ case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON:
+ return shim_->GetColor(ColorType::kWindowFg, ColorState::kNormal);
+ case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_HOVERED:
+ return shim_->GetColor(ColorType::kWindowFg, ColorState::kNormal);
+ case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_PRESSED:
+ return shim_->GetColor(ColorType::kWindowFg, ColorState::kNormal);
+ case ThemeProperties::COLOR_TOOLBAR_TEXT:
+ return shim_->GetColor(ColorType::kWindowFg, ColorState::kNormal);
+ case ThemeProperties::COLOR_NTP_LINK:
+ return shim_->GetColor(ColorType::kHighlightBg, ColorState::kNormal);
+ case ThemeProperties::COLOR_FRAME_ACTIVE:
+ return shim_->GetFrameColor(ColorState::kNormal, use_custom_frame);
+ case ThemeProperties::COLOR_FRAME_INACTIVE:
+ return shim_->GetFrameColor(ColorState::kInactive, use_custom_frame);
+ case ThemeProperties::COLOR_FRAME_ACTIVE_INCOGNITO:
+ return shim_->GetFrameColor(ColorState::kNormal, use_custom_frame);
+ case ThemeProperties::COLOR_FRAME_INACTIVE_INCOGNITO:
+ return shim_->GetFrameColor(ColorState::kInactive, use_custom_frame);
+ case ThemeProperties::COLOR_TOOLBAR:
+ return shim_->GetColor(ColorType::kButtonBg, ColorState::kNormal);
+ case ThemeProperties::COLOR_TAB_BACKGROUND_ACTIVE_FRAME_ACTIVE:
+ return shim_->GetColor(ColorType::kButtonBg, ColorState::kNormal);
+ case ThemeProperties::COLOR_TAB_BACKGROUND_ACTIVE_FRAME_INACTIVE:
+ return shim_->GetColor(ColorType::kButtonBg, ColorState::kInactive);
+ case ThemeProperties::COLOR_TAB_FOREGROUND_INACTIVE_FRAME_ACTIVE:
+ return color_utils::BlendForMinContrast(
+ shim_->GetColor(ColorType::kButtonBg, ColorState::kNormal),
+ shim_->GetFrameColor(ColorState::kNormal, use_custom_frame))
+ .color;
+ case ThemeProperties::COLOR_TAB_FOREGROUND_INACTIVE_FRAME_INACTIVE:
+ return color_utils::BlendForMinContrast(
+ shim_->GetColor(ColorType::kButtonBg, ColorState::kInactive),
+ shim_->GetFrameColor(ColorState::kInactive, use_custom_frame))
+ .color;
+ case ThemeProperties::COLOR_TAB_STROKE_FRAME_ACTIVE:
+ return color_utils::BlendForMinContrast(
+ shim_->GetColor(ColorType::kButtonBg, ColorState::kNormal),
+ shim_->GetColor(ColorType::kButtonBg, ColorState::kNormal),
+ SK_ColorBLACK, 2.0)
+ .color;
+ case ThemeProperties::COLOR_TAB_STROKE_FRAME_INACTIVE:
+ return color_utils::BlendForMinContrast(
+ shim_->GetColor(ColorType::kButtonBg, ColorState::kInactive),
+ shim_->GetColor(ColorType::kButtonBg, ColorState::kInactive),
+ SK_ColorBLACK, 2.0)
+ .color;
+ default:
+ return absl::nullopt;
+ }
}
-std::unique_ptr<views::LinuxUI> CreateQtUi() {
- return std::make_unique<QtUi>();
+std::unique_ptr<ui::LinuxUi> CreateQtUi(
+ std::unique_ptr<ui::LinuxUi> fallback_linux_ui) {
+ return std::make_unique<QtUi>(std::move(fallback_linux_ui));
}
} // namespace qt