qt_interface.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_INTERFACE_H_
  5. #define UI_QT_QT_INTERFACE_H_
  6. // This file shouldn't include any standard C++ headers (directly or indirectly)
  7. #include <stdint.h>
  8. #include <stdlib.h>
  9. using SkColor = uint32_t;
  10. namespace qt {
  11. // std::string cannot be passed over the library boundary, so this class acts
  12. // as an interface between QT and Chrome.
  13. class String {
  14. public:
  15. String();
  16. explicit String(const char* str);
  17. String(String&& other);
  18. String& operator=(String&& other);
  19. ~String();
  20. // May be nullptr.
  21. const char* c_str() const { return str_; }
  22. private:
  23. char* str_ = nullptr;
  24. };
  25. // A generic bag of bytes.
  26. class Buffer {
  27. public:
  28. Buffer();
  29. // Creates a copy of `data`.
  30. Buffer(const uint8_t* data, size_t size);
  31. Buffer(Buffer&& other);
  32. Buffer& operator=(Buffer&& other);
  33. ~Buffer();
  34. // Take ownership of the data in this buffer (resetting `this`).
  35. uint8_t* Take();
  36. uint8_t* data() { return data_; }
  37. size_t size() const { return size_; }
  38. private:
  39. uint8_t* data_ = nullptr;
  40. size_t size_ = 0;
  41. };
  42. enum class FontHinting {
  43. kDefault,
  44. kNone,
  45. kLight,
  46. kFull,
  47. };
  48. enum class ColorType {
  49. kWindowBg,
  50. kWindowFg,
  51. kHighlightBg,
  52. kHighlightFg,
  53. kEntryBg,
  54. kEntryFg,
  55. kButtonBg,
  56. kButtonFg,
  57. kLight,
  58. kMidlight,
  59. kDark,
  60. kMidground,
  61. kShadow,
  62. };
  63. enum class ColorState {
  64. kNormal,
  65. kDisabled,
  66. kInactive,
  67. };
  68. struct FontRenderParams {
  69. bool antialiasing;
  70. bool use_bitmaps;
  71. FontHinting hinting;
  72. };
  73. struct FontDescription {
  74. String family;
  75. int size_pixels;
  76. int size_points;
  77. bool is_italic;
  78. int weight;
  79. };
  80. struct Image {
  81. int width = 0;
  82. int height = 0;
  83. float scale = 1.0f;
  84. // The data is stored as ARGB32 (premultiplied).
  85. Buffer data_argb;
  86. };
  87. class QtInterface {
  88. public:
  89. class Delegate {
  90. public:
  91. virtual ~Delegate() = default;
  92. virtual void FontChanged() = 0;
  93. virtual void ThemeChanged() = 0;
  94. };
  95. QtInterface() = default;
  96. QtInterface(const QtInterface&) = delete;
  97. QtInterface& operator=(const QtInterface&) = delete;
  98. virtual ~QtInterface() = default;
  99. virtual double GetScaleFactor() const = 0;
  100. virtual FontRenderParams GetFontRenderParams() const = 0;
  101. virtual FontDescription GetFontDescription() const = 0;
  102. virtual Image GetIconForContentType(const String& content_type,
  103. int size) const = 0;
  104. virtual SkColor GetColor(ColorType role, ColorState state) const = 0;
  105. virtual SkColor GetFrameColor(ColorState state,
  106. bool use_custom_frame) const = 0;
  107. virtual Image DrawHeader(int width,
  108. int height,
  109. SkColor default_color,
  110. ColorState state,
  111. bool use_custom_frame) const = 0;
  112. virtual int GetCursorBlinkIntervalMs() const = 0;
  113. virtual int GetAnimationDurationMs() const = 0;
  114. };
  115. } // namespace qt
  116. // This should be the only thing exported from qt_shim.
  117. extern "C" __attribute__((visibility("default"))) qt::QtInterface*
  118. CreateQtInterface(qt::QtInterface::Delegate* delegate, int* argc, char** argv);
  119. #endif // UI_QT_QT_INTERFACE_H_