-
Notifications
You must be signed in to change notification settings - Fork 15k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: implement WindowFrameProvider::SetMaximized for WindowFrameProvi…
…derGtk
- Loading branch information
1 parent
7877d9a
commit f1e3621
Showing
2 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
patches/chromium/implement_windowframeprovider_setmaximized_for.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: msizanoen1 <msizanoen@qtmlabs.xyz> | ||
Date: Tue, 19 Jul 2022 04:31:19 +0200 | ||
Subject: implement WindowFrameProvider::SetMaximized for | ||
WindowFrameProviderGtk | ||
|
||
This allows ClientFrameViewLinux to tell GTK to render the window title | ||
bar in maximized mode, preventing the window from having empty space | ||
around it while maximized. | ||
|
||
diff --git a/ui/gtk/window_frame_provider_gtk.cc b/ui/gtk/window_frame_provider_gtk.cc | ||
index e4dbdad327eb77994ffd7f068c67336a19897915..cec09922a0a4b16c46b4906368632f65f0bca336 100644 | ||
--- a/ui/gtk/window_frame_provider_gtk.cc | ||
+++ b/ui/gtk/window_frame_provider_gtk.cc | ||
@@ -38,16 +38,18 @@ std::string GetThemeName() { | ||
return theme_string; | ||
} | ||
|
||
-GtkCssContext WindowContext(bool solid_frame, bool focused) { | ||
+GtkCssContext WindowContext(bool solid_frame, bool focused, bool maximized) { | ||
std::string selector = "#window.background."; | ||
selector += solid_frame ? "solid-csd" : "csd"; | ||
+ if (maximized) | ||
+ selector += ".maximized"; | ||
if (!focused) | ||
selector += ":inactive"; | ||
return AppendCssNodeToStyleContext({}, selector); | ||
} | ||
|
||
-GtkCssContext DecorationContext(bool solid_frame, bool focused) { | ||
- auto context = WindowContext(solid_frame, focused); | ||
+GtkCssContext DecorationContext(bool solid_frame, bool focused, bool maximized) { | ||
+ auto context = WindowContext(solid_frame, focused, maximized); | ||
// GTK4 renders the decoration directly on the window. | ||
if (!GtkCheckVersion(4)) | ||
context = AppendCssNodeToStyleContext(context, "#decoration"); | ||
@@ -64,8 +66,8 @@ GtkCssContext DecorationContext(bool solid_frame, bool focused) { | ||
return context; | ||
} | ||
|
||
-GtkCssContext HeaderContext(bool solid_frame, bool focused) { | ||
- auto context = WindowContext(solid_frame, focused); | ||
+GtkCssContext HeaderContext(bool solid_frame, bool focused, bool maximized) { | ||
+ auto context = WindowContext(solid_frame, focused, maximized); | ||
context = | ||
AppendCssNodeToStyleContext(context, "#headerbar.header-bar.titlebar"); | ||
if (!focused) | ||
@@ -105,13 +107,13 @@ SkBitmap PaintHeaderbar(const gfx::Size& size, | ||
return PaintBitmap(size, tabstrip_bounds_dip, context, scale); | ||
} | ||
|
||
-int ComputeTopCornerRadius() { | ||
+int ComputeTopCornerRadius(bool maximized) { | ||
// In GTK4, there's no way to directly obtain CSS values for a context, so we | ||
// need to experimentally determine the corner radius by rendering a sample. | ||
// Additionally, in GTK4, the headerbar corners get clipped by the window | ||
// rather than the headerbar having its own rounded corners. | ||
- auto context = GtkCheckVersion(4) ? DecorationContext(false, false) | ||
- : HeaderContext(false, false); | ||
+ auto context = GtkCheckVersion(4) ? DecorationContext(false, false, maximized) | ||
+ : HeaderContext(false, false, maximized); | ||
ApplyCssToContext(context, R"(window, headerbar { | ||
background-image: none; | ||
background-color: black; | ||
@@ -184,6 +186,13 @@ gfx::Insets WindowFrameProviderGtk::GetFrameThicknessDip() { | ||
return frame_thickness_dip_; | ||
} | ||
|
||
+void WindowFrameProviderGtk::SetMaximized(bool maximized) { | ||
+ if (maximized_ == maximized) | ||
+ return; | ||
+ maximized_ = maximized; | ||
+ assets_.clear(); | ||
+} | ||
+ | ||
void WindowFrameProviderGtk::PaintWindowFrame(gfx::Canvas* canvas, | ||
const gfx::Rect& rect_dip, | ||
int top_area_height_dip, | ||
@@ -264,7 +273,7 @@ void WindowFrameProviderGtk::PaintWindowFrame(gfx::Canvas* canvas, | ||
top_area_height_dip * scale - asset.frame_thickness_px.top(); | ||
|
||
auto header = PaintHeaderbar({client_bounds_px.width(), top_area_height_px}, | ||
- HeaderContext(solid_frame_, focused), scale); | ||
+ HeaderContext(solid_frame_, focused, maximized_), scale); | ||
image = gfx::ImageSkia::CreateFrom1xBitmap(header); | ||
// In GTK4, the headerbar gets clipped by the window. | ||
if (GtkCheckVersion(4)) { | ||
@@ -296,7 +305,7 @@ void WindowFrameProviderGtk::MaybeUpdateBitmaps(float scale) { | ||
|
||
gfx::Rect frame_bounds_dip(kMaxFrameSizeDip, kMaxFrameSizeDip, | ||
2 * kMaxFrameSizeDip, 2 * kMaxFrameSizeDip); | ||
- auto focused_context = DecorationContext(solid_frame_, true); | ||
+ auto focused_context = DecorationContext(solid_frame_, true, maximized_); | ||
frame_bounds_dip.Inset(-GtkStyleContextGetPadding(focused_context)); | ||
frame_bounds_dip.Inset(-GtkStyleContextGetBorder(focused_context)); | ||
gfx::Size bitmap_size(BitmapSizePx(asset), BitmapSizePx(asset)); | ||
@@ -304,7 +313,7 @@ void WindowFrameProviderGtk::MaybeUpdateBitmaps(float scale) { | ||
PaintBitmap(bitmap_size, frame_bounds_dip, focused_context, scale); | ||
asset.unfocused_bitmap = | ||
PaintBitmap(bitmap_size, frame_bounds_dip, | ||
- DecorationContext(solid_frame_, false), scale); | ||
+ DecorationContext(solid_frame_, false, maximized_), scale); | ||
|
||
// In GTK4, there's no way to obtain the frame thickness from CSS values | ||
// directly, so we must determine it experimentally based on the drawn | ||
@@ -319,7 +328,7 @@ void WindowFrameProviderGtk::MaybeUpdateBitmaps(float scale) { | ||
return 0; | ||
}; | ||
|
||
- top_corner_radius_dip_ = ComputeTopCornerRadius(); | ||
+ top_corner_radius_dip_ = ComputeTopCornerRadius(maximized_); | ||
|
||
const auto previous_frame_thickness_dip_ = frame_thickness_dip_; | ||
frame_thickness_dip_ = gfx::Insets::TLBR( | ||
diff --git a/ui/gtk/window_frame_provider_gtk.h b/ui/gtk/window_frame_provider_gtk.h | ||
index d3039d73161378197557947aece88d2710c1e486..618c0c6b5eaaf04f98acc3a86733fd7ed0538346 100644 | ||
--- a/ui/gtk/window_frame_provider_gtk.h | ||
+++ b/ui/gtk/window_frame_provider_gtk.h | ||
@@ -24,6 +24,7 @@ class WindowFrameProviderGtk : public views::WindowFrameProvider { | ||
// views::WindowFrameProvider: | ||
int GetTopCornerRadiusDip() override; | ||
gfx::Insets GetFrameThicknessDip() override; | ||
+ void SetMaximized(bool maximized) override; | ||
void PaintWindowFrame(gfx::Canvas* canvas, | ||
const gfx::Rect& rect, | ||
int top_area_height, | ||
@@ -69,6 +70,9 @@ class WindowFrameProviderGtk : public views::WindowFrameProvider { | ||
|
||
// Cached bitmaps and metrics. The scale is rounded to percent. | ||
base::flat_map<int, Asset> assets_; | ||
+ | ||
+ // Whether the window should be drawn as maximized. | ||
+ bool maximized_ = false; | ||
}; | ||
|
||
} // namespace gtk |