add_maximized_parameter_to_linuxui_getwindowframeprovider.patch 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: msizanoen1 <[email protected]>
  3. Date: Tue, 19 Jul 2022 05:11:06 +0200
  4. Subject: Add maximized parameter to LinuxUI::GetWindowFrameProvider
  5. This allows ClientFrameViewLinux to instruct the toolkit to draw the window
  6. decorations in maximized mode where needed, preventing empty space caused
  7. by decoration shadows and rounded titlebars around the window while maximized.
  8. diff --git a/ui/gtk/gtk_ui.cc b/ui/gtk/gtk_ui.cc
  9. index c61bac00076822ae729882c64f3ad89e0d849e91..28cd9fb14783651ee651917f135c68faa0f2059a 100644
  10. --- a/ui/gtk/gtk_ui.cc
  11. +++ b/ui/gtk/gtk_ui.cc
  12. @@ -507,13 +507,15 @@ std::unique_ptr<ui::NavButtonProvider> GtkUi::CreateNavButtonProvider() {
  13. return nullptr;
  14. }
  15. -ui::WindowFrameProvider* GtkUi::GetWindowFrameProvider(bool solid_frame) {
  16. +ui::WindowFrameProvider* GtkUi::GetWindowFrameProvider(bool solid_frame, bool maximized) {
  17. if (!GtkCheckVersion(3, 14))
  18. return nullptr;
  19. auto& provider =
  20. - solid_frame ? solid_frame_provider_ : transparent_frame_provider_;
  21. + maximized
  22. + ? (solid_frame ? solid_maximized_frame_provider_ : transparent_maximized_frame_provider_)
  23. + : (solid_frame ? solid_frame_provider_ : transparent_frame_provider_);
  24. if (!provider)
  25. - provider = std::make_unique<gtk::WindowFrameProviderGtk>(solid_frame);
  26. + provider = std::make_unique<gtk::WindowFrameProviderGtk>(solid_frame, maximized);
  27. return provider.get();
  28. }
  29. diff --git a/ui/gtk/gtk_ui.h b/ui/gtk/gtk_ui.h
  30. index ebc31db3dad9ba7904fbd345c6a1ba31ed6fd813..1d2ffc82bb67ed80f508631c8c7d045be76f6761 100644
  31. --- a/ui/gtk/gtk_ui.h
  32. +++ b/ui/gtk/gtk_ui.h
  33. @@ -106,7 +106,7 @@ class GtkUi : public ui::LinuxUiAndTheme {
  34. SkColor GetInactiveSelectionFgColor() const override;
  35. bool PreferDarkTheme() const override;
  36. std::unique_ptr<ui::NavButtonProvider> CreateNavButtonProvider() override;
  37. - ui::WindowFrameProvider* GetWindowFrameProvider(bool solid_frame) override;
  38. + ui::WindowFrameProvider* GetWindowFrameProvider(bool solid_frame, bool maximized) override;
  39. private:
  40. using TintMap = std::map<int, color_utils::HSL>;
  41. @@ -195,10 +195,13 @@ class GtkUi : public ui::LinuxUiAndTheme {
  42. // while Chrome is running.
  43. std::unique_ptr<ui::WindowFrameProvider> solid_frame_provider_;
  44. std::unique_ptr<ui::WindowFrameProvider> transparent_frame_provider_;
  45. + std::unique_ptr<ui::WindowFrameProvider> solid_maximized_frame_provider_;
  46. + std::unique_ptr<ui::WindowFrameProvider> transparent_maximized_frame_provider_;
  47. // Objects to notify when the window frame button order changes.
  48. base::ObserverList<ui::WindowButtonOrderObserver>::Unchecked
  49. window_button_order_observer_list_;
  50. +
  51. };
  52. } // namespace gtk
  53. diff --git a/ui/gtk/window_frame_provider_gtk.cc b/ui/gtk/window_frame_provider_gtk.cc
  54. index c7857a3e316554e6b5f46c023a1a8084a3263074..5ad7d4ffa7e9c12ec4640a845a4c763420c23ec2 100644
  55. --- a/ui/gtk/window_frame_provider_gtk.cc
  56. +++ b/ui/gtk/window_frame_provider_gtk.cc
  57. @@ -38,16 +38,18 @@ std::string GetThemeName() {
  58. return theme_string;
  59. }
  60. -GtkCssContext WindowContext(bool solid_frame, bool focused) {
  61. +GtkCssContext WindowContext(bool solid_frame, bool maximized, bool focused) {
  62. std::string selector = "#window.background.";
  63. selector += solid_frame ? "solid-csd" : "csd";
  64. + if (maximized)
  65. + selector += ".maximized";
  66. if (!focused)
  67. selector += ":inactive";
  68. return AppendCssNodeToStyleContext({}, selector);
  69. }
  70. -GtkCssContext DecorationContext(bool solid_frame, bool focused) {
  71. - auto context = WindowContext(solid_frame, focused);
  72. +GtkCssContext DecorationContext(bool solid_frame, bool maximized, bool focused) {
  73. + auto context = WindowContext(solid_frame, maximized, focused);
  74. // GTK4 renders the decoration directly on the window.
  75. if (!GtkCheckVersion(4))
  76. context = AppendCssNodeToStyleContext(context, "#decoration");
  77. @@ -64,8 +66,8 @@ GtkCssContext DecorationContext(bool solid_frame, bool focused) {
  78. return context;
  79. }
  80. -GtkCssContext HeaderContext(bool solid_frame, bool focused) {
  81. - auto context = WindowContext(solid_frame, focused);
  82. +GtkCssContext HeaderContext(bool solid_frame, bool maximized, bool focused) {
  83. + auto context = WindowContext(solid_frame, maximized, focused);
  84. context =
  85. AppendCssNodeToStyleContext(context, "#headerbar.header-bar.titlebar");
  86. if (!focused)
  87. @@ -110,8 +112,8 @@ int ComputeTopCornerRadius() {
  88. // need to experimentally determine the corner radius by rendering a sample.
  89. // Additionally, in GTK4, the headerbar corners get clipped by the window
  90. // rather than the headerbar having its own rounded corners.
  91. - auto context = GtkCheckVersion(4) ? DecorationContext(false, false)
  92. - : HeaderContext(false, false);
  93. + auto context = GtkCheckVersion(4) ? DecorationContext(false, false, false)
  94. + : HeaderContext(false, false, false);
  95. ApplyCssToContext(context, R"(window, headerbar {
  96. background-image: none;
  97. background-color: black;
  98. @@ -169,8 +171,8 @@ void WindowFrameProviderGtk::Asset::CloneFrom(
  99. unfocused_bitmap = src.unfocused_bitmap;
  100. }
  101. -WindowFrameProviderGtk::WindowFrameProviderGtk(bool solid_frame)
  102. - : solid_frame_(solid_frame) {}
  103. +WindowFrameProviderGtk::WindowFrameProviderGtk(bool solid_frame, bool maximized)
  104. + : solid_frame_(solid_frame), maximized_(maximized) {}
  105. WindowFrameProviderGtk::~WindowFrameProviderGtk() = default;
  106. @@ -272,7 +274,7 @@ void WindowFrameProviderGtk::PaintWindowFrame(
  107. top_area_height_dip * scale - effective_frame_thickness_px.top();
  108. auto header = PaintHeaderbar({client_bounds_px.width(), top_area_height_px},
  109. - HeaderContext(solid_frame_, focused), scale);
  110. + HeaderContext(solid_frame_, maximized_, focused), scale);
  111. image = gfx::ImageSkia::CreateFrom1xBitmap(header);
  112. // In GTK4, the headerbar gets clipped by the window.
  113. if (GtkCheckVersion(4)) {
  114. @@ -304,7 +306,7 @@ void WindowFrameProviderGtk::MaybeUpdateBitmaps(float scale) {
  115. gfx::Rect frame_bounds_dip(kMaxFrameSizeDip, kMaxFrameSizeDip,
  116. 2 * kMaxFrameSizeDip, 2 * kMaxFrameSizeDip);
  117. - auto focused_context = DecorationContext(solid_frame_, true);
  118. + auto focused_context = DecorationContext(solid_frame_, maximized_, true);
  119. frame_bounds_dip.Inset(-GtkStyleContextGetPadding(focused_context));
  120. frame_bounds_dip.Inset(-GtkStyleContextGetBorder(focused_context));
  121. gfx::Size bitmap_size(BitmapSizePx(asset), BitmapSizePx(asset));
  122. @@ -312,7 +314,7 @@ void WindowFrameProviderGtk::MaybeUpdateBitmaps(float scale) {
  123. PaintBitmap(bitmap_size, frame_bounds_dip, focused_context, scale);
  124. asset.unfocused_bitmap =
  125. PaintBitmap(bitmap_size, frame_bounds_dip,
  126. - DecorationContext(solid_frame_, false), scale);
  127. + DecorationContext(solid_frame_, maximized_, false), scale);
  128. // In GTK4, there's no way to obtain the frame thickness from CSS values
  129. // directly, so we must determine it experimentally based on the drawn
  130. diff --git a/ui/gtk/window_frame_provider_gtk.h b/ui/gtk/window_frame_provider_gtk.h
  131. index d8cb2c6aab333cc55ad1daa70ac91b0569d33a7c..558aa3979301f79df789a29ba3ad1cf134bd6494 100644
  132. --- a/ui/gtk/window_frame_provider_gtk.h
  133. +++ b/ui/gtk/window_frame_provider_gtk.h
  134. @@ -14,7 +14,7 @@ namespace gtk {
  135. class WindowFrameProviderGtk : public ui::WindowFrameProvider {
  136. public:
  137. - explicit WindowFrameProviderGtk(bool solid_frame);
  138. + explicit WindowFrameProviderGtk(bool solid_frame, bool maximized);
  139. WindowFrameProviderGtk(const WindowFrameProviderGtk&) = delete;
  140. WindowFrameProviderGtk& operator=(const WindowFrameProviderGtk&) = delete;
  141. @@ -70,6 +70,9 @@ class WindowFrameProviderGtk : public ui::WindowFrameProvider {
  142. // Cached bitmaps and metrics. The scale is rounded to percent.
  143. base::flat_map<int, Asset> assets_;
  144. +
  145. + // Whether to draw the window decorations as maximized.
  146. + bool maximized_;
  147. };
  148. } // namespace gtk
  149. diff --git a/ui/linux/linux_ui.h b/ui/linux/linux_ui.h
  150. index b5fd57741d2f47bda9499cf10e73cc9b3dd1b4dc..35e5bedb719af699485b575ece4bdb4f90df07df 100644
  151. --- a/ui/linux/linux_ui.h
  152. +++ b/ui/linux/linux_ui.h
  153. @@ -273,7 +273,7 @@ class COMPONENT_EXPORT(LINUX_UI) LinuxUiTheme {
  154. // if transparency is unsupported and the frame should be rendered opaque.
  155. // The returned object is not owned by the caller and will remain alive until
  156. // the process ends.
  157. - virtual WindowFrameProvider* GetWindowFrameProvider(bool solid_frame) = 0;
  158. + virtual WindowFrameProvider* GetWindowFrameProvider(bool solid_frame, bool maximized) = 0;
  159. protected:
  160. LinuxUiTheme();