summaryrefslogtreecommitdiffstats
path: root/widget/gtk/gtk3drawing.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'widget/gtk/gtk3drawing.cpp')
-rw-r--r--widget/gtk/gtk3drawing.cpp103
1 files changed, 23 insertions, 80 deletions
diff --git a/widget/gtk/gtk3drawing.cpp b/widget/gtk/gtk3drawing.cpp
index 1fa8b95606..122b43d688 100644
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -264,7 +264,6 @@ static void CalculateToolbarButtonMetrics(WidgetNodeType aAppearance,
gint iconWidth, iconHeight;
if (!gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &iconWidth, &iconHeight)) {
NS_WARNING("Failed to get Gtk+ icon size for titlebar button!");
-
// Use some reasonable fallback size
iconWidth = 16;
iconHeight = 16;
@@ -292,37 +291,7 @@ static void CalculateToolbarButtonMetrics(WidgetNodeType aAppearance,
// Place icon at button center.
aMetrics->iconXPosition = (width - iconWidth) / 2;
aMetrics->iconYPosition = (height - iconHeight) / 2;
-
- aMetrics->minSizeWithBorderMargin.width = width;
- aMetrics->minSizeWithBorderMargin.height = height;
-}
-
-// We support LTR layout only here for now.
-static void CalculateToolbarButtonSpacing(WidgetNodeType aAppearance,
- ToolbarButtonGTKMetrics* aMetrics) {
- GtkStyleContext* style = GetStyleContext(aAppearance);
- gtk_style_context_get_margin(style, gtk_style_context_get_state(style),
- &aMetrics->buttonMargin);
-
- // Get titlebar spacing, a default one is 6 pixels (gtk/gtkheaderbar.c)
- gint buttonSpacing = 6;
- g_object_get(GetWidget(MOZ_GTK_HEADER_BAR), "spacing", &buttonSpacing,
- nullptr);
-
- // We apply spacing as a margin equally to both adjacent buttons.
- buttonSpacing /= 2;
-
- if (!aMetrics->firstButton) {
- aMetrics->buttonMargin.left += buttonSpacing;
- }
- if (!aMetrics->lastButton) {
- aMetrics->buttonMargin.right += buttonSpacing;
- }
-
- aMetrics->minSizeWithBorderMargin.width +=
- aMetrics->buttonMargin.right + aMetrics->buttonMargin.left;
- aMetrics->minSizeWithBorderMargin.height +=
- aMetrics->buttonMargin.top + aMetrics->buttonMargin.bottom;
+ aMetrics->minSizeWithBorder = {width, height};
}
size_t GetGtkHeaderBarButtonLayout(Span<ButtonLayout> aButtonLayout,
@@ -388,26 +357,14 @@ static void EnsureToolbarMetrics() {
memset(&sToolbarMetrics, 0, sizeof(sToolbarMetrics));
// Calculate titlebar button visibility and positions.
- ButtonLayout aButtonLayout[TOOLBAR_BUTTONS];
+ ButtonLayout buttonLayout[TOOLBAR_BUTTONS];
size_t activeButtonNums =
- GetGtkHeaderBarButtonLayout(Span(aButtonLayout), nullptr);
-
- for (size_t i = 0; i < activeButtonNums; i++) {
- int buttonIndex =
- (aButtonLayout[i].mType - MOZ_GTK_HEADER_BAR_BUTTON_CLOSE);
- ToolbarButtonGTKMetrics* metrics = sToolbarMetrics.button + buttonIndex;
- metrics->visible = true;
- // Mark first button
- if (!i) {
- metrics->firstButton = true;
- }
- // Mark last button.
- if (i == (activeButtonNums - 1)) {
- metrics->lastButton = true;
- }
+ GetGtkHeaderBarButtonLayout(Span(buttonLayout), nullptr);
- CalculateToolbarButtonMetrics(aButtonLayout[i].mType, metrics);
- CalculateToolbarButtonSpacing(aButtonLayout[i].mType, metrics);
+ for (const auto& layout : Span(buttonLayout, activeButtonNums)) {
+ int buttonIndex = layout.mType - MOZ_GTK_HEADER_BAR_BUTTON_CLOSE;
+ ToolbarButtonGTKMetrics* metrics = &sToolbarMetrics.button[buttonIndex];
+ CalculateToolbarButtonMetrics(layout.mType, metrics);
}
sToolbarMetrics.initialized = true;
@@ -506,26 +463,27 @@ static gint moz_gtk_button_paint(cairo_t* cr, const GdkRectangle* rect,
return MOZ_GTK_SUCCESS;
}
-static gint moz_gtk_header_bar_button_paint(cairo_t* cr,
- const GdkRectangle* aRect,
+static gint moz_gtk_header_bar_button_paint(cairo_t* cr, GdkRectangle* aRect,
GtkWidgetState* state,
GtkReliefStyle relief,
WidgetNodeType aIconWidgetType,
GtkTextDirection direction) {
- GdkRectangle rect = *aRect;
- // We need to inset our calculated margin because it also
- // contains titlebar button spacing.
+ GtkWidget* buttonWidget = GetWidget(aIconWidgetType);
+ if (!buttonWidget) {
+ return MOZ_GTK_UNKNOWN_WIDGET;
+ }
+
const ToolbarButtonGTKMetrics* metrics = GetToolbarButtonMetrics(
aIconWidgetType == MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE_RESTORE
? MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE
: aIconWidgetType);
- Inset(&rect, metrics->buttonMargin);
-
- GtkWidget* buttonWidget = GetWidget(aIconWidgetType);
- if (!buttonWidget) {
- return MOZ_GTK_UNKNOWN_WIDGET;
+ // Vertically center and clamp the rect to the desired size.
+ if (aRect->height > metrics->minSizeWithBorder.height) {
+ gint diff = aRect->height - metrics->minSizeWithBorder.height;
+ aRect->y += diff / 2;
+ aRect->height = metrics->minSizeWithBorder.height;
}
- moz_gtk_button_paint(cr, &rect, state, relief, buttonWidget, direction);
+ moz_gtk_button_paint(cr, aRect, state, relief, buttonWidget, direction);
GtkWidget* iconWidget =
gtk_bin_get_child(GTK_BIN(GetWidget(aIconWidgetType)));
@@ -544,8 +502,9 @@ static gint moz_gtk_header_bar_button_paint(cairo_t* cr,
gtk_style_context_set_state(style, state_flags);
/* This is available since Gtk+ 3.10 as well as GtkHeaderBar */
- gtk_render_icon_surface(style, cr, surface, rect.x + metrics->iconXPosition,
- rect.y + metrics->iconYPosition);
+ gtk_render_icon_surface(style, cr, surface,
+ aRect->x + metrics->iconXPosition,
+ aRect->y + metrics->iconYPosition);
gtk_style_context_restore(style);
}
@@ -1700,22 +1659,6 @@ gint moz_gtk_get_widget_border(WidgetNodeType widget, gint* left, gint* top,
return MOZ_GTK_SUCCESS;
}
- case MOZ_GTK_HEADER_BAR_BUTTON_BOX: {
- style = GetStyleContext(MOZ_GTK_HEADER_BAR);
- moz_gtk_add_border_padding(style, left, top, right, bottom);
- *top = *bottom = 0;
- bool leftButtonsPlacement = false;
- GetGtkHeaderBarButtonLayout({}, &leftButtonsPlacement);
- if (direction == GTK_TEXT_DIR_RTL) {
- leftButtonsPlacement = !leftButtonsPlacement;
- }
- if (leftButtonsPlacement) {
- *right = 0;
- } else {
- *left = 0;
- }
- return MOZ_GTK_SUCCESS;
- }
/* These widgets have no borders, since they are not containers. */
case MOZ_GTK_SPLITTER_HORIZONTAL:
case MOZ_GTK_SPLITTER_VERTICAL: