qt_ui.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_QT_QT_UI_H_
  5. #define UI_QT_QT_UI_H_
  6. #include <memory>
  7. #include "base/component_export.h"
  8. #include "printing/buildflags/buildflags.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. #include "ui/color/color_provider.h"
  11. #include "ui/color/color_provider_manager.h"
  12. #include "ui/gfx/font_render_params.h"
  13. #include "ui/linux/linux_ui_base.h"
  14. #include "ui/qt/qt_interface.h"
  15. #if BUILDFLAG(ENABLE_PRINTING)
  16. #include "printing/printing_context_linux.h" // nogncheck
  17. #endif
  18. namespace qt {
  19. class QtNativeTheme;
  20. // Interface to QT desktop features.
  21. class QtUi : public ui::LinuxUiBase, QtInterface::Delegate {
  22. public:
  23. explicit QtUi(std::unique_ptr<ui::LinuxUi> fallback_linux_ui);
  24. QtUi(const QtUi&) = delete;
  25. QtUi& operator=(const QtUi&) = delete;
  26. ~QtUi() override;
  27. // ui::LinuxInputMethodContextFactory:
  28. std::unique_ptr<ui::LinuxInputMethodContext> CreateInputMethodContext(
  29. ui::LinuxInputMethodContextDelegate* delegate) const override;
  30. // gfx::LinuxFontDelegate:
  31. gfx::FontRenderParams GetDefaultFontRenderParams() const override;
  32. void GetDefaultFontDescription(
  33. std::string* family_out,
  34. int* size_pixels_out,
  35. int* style_out,
  36. int* weight_out,
  37. gfx::FontRenderParams* params_out) const override;
  38. // ui::ShellDialogLinux:
  39. ui::SelectFileDialog* CreateSelectFileDialog(
  40. void* listener,
  41. std::unique_ptr<ui::SelectFilePolicy> policy) const override;
  42. // ui::LinuxUi:
  43. bool Initialize() override;
  44. bool GetColor(int id, SkColor* color, bool use_custom_frame) const override;
  45. bool GetDisplayProperty(int id, int* result) const override;
  46. SkColor GetFocusRingColor() const override;
  47. SkColor GetActiveSelectionBgColor() const override;
  48. SkColor GetActiveSelectionFgColor() const override;
  49. SkColor GetInactiveSelectionBgColor() const override;
  50. SkColor GetInactiveSelectionFgColor() const override;
  51. base::TimeDelta GetCursorBlinkInterval() const override;
  52. gfx::Image GetIconForContentType(const std::string& content_type,
  53. int size,
  54. float scale) const override;
  55. WindowFrameAction GetWindowFrameAction(
  56. WindowFrameActionSource source) override;
  57. float GetDeviceScaleFactor() const override;
  58. bool PreferDarkTheme() const override;
  59. bool AnimationsEnabled() const override;
  60. std::unique_ptr<ui::NavButtonProvider> CreateNavButtonProvider() override;
  61. ui::WindowFrameProvider* GetWindowFrameProvider(bool solid_frame) override;
  62. base::flat_map<std::string, std::string> GetKeyboardLayoutMap() override;
  63. std::string GetCursorThemeName() override;
  64. int GetCursorThemeSize() override;
  65. ui::NativeTheme* GetNativeThemeImpl() const override;
  66. // ui::TextEditKeybindingDelegate:
  67. bool GetTextEditCommandsForEvent(
  68. const ui::Event& event,
  69. std::vector<ui::TextEditCommandAuraLinux>* commands) override;
  70. #if BUILDFLAG(ENABLE_PRINTING)
  71. // printing::PrintingContextLinuxDelegate:
  72. printing::PrintDialogLinuxInterface* CreatePrintDialog(
  73. printing::PrintingContextLinux* context) override;
  74. gfx::Size GetPdfPaperSize(printing::PrintingContextLinux* context) override;
  75. #endif
  76. // QtInterface::Delegate:
  77. void FontChanged() override;
  78. void ThemeChanged() override;
  79. private:
  80. void AddNativeColorMixer(ui::ColorProvider* provider,
  81. const ui::ColorProviderManager::Key& key);
  82. absl::optional<SkColor> GetColor(int id, bool use_custom_frame) const;
  83. // TODO(https://crbug.com/1317782): This is a fallback for any unimplemented
  84. // functionality in the QT backend and should eventually be removed.
  85. std::unique_ptr<ui::LinuxUi> fallback_linux_ui_;
  86. // QT modifies argc and argv, and they must be kept alive while
  87. // `shim_` is alive.
  88. CmdLineArgs cmd_line_;
  89. // Cached default font settings.
  90. std::string font_family_;
  91. int font_size_pixels_ = 0;
  92. int font_size_points_ = 0;
  93. gfx::Font::FontStyle font_style_ = gfx::Font::NORMAL;
  94. int font_weight_;
  95. gfx::FontRenderParams font_params_;
  96. std::unique_ptr<QtInterface> shim_;
  97. std::unique_ptr<QtNativeTheme> native_theme_;
  98. };
  99. // This should be the only symbol exported from this component.
  100. COMPONENT_EXPORT(QT)
  101. std::unique_ptr<ui::LinuxUi> CreateQtUi(
  102. std::unique_ptr<ui::LinuxUi> fallback_linux_ui);
  103. } // namespace qt
  104. #endif // UI_QT_QT_UI_H_