scrolledwindow: Fix scrollbar allocations

Use the content size everywhere. Fixes scrollbar positions with padding
and/or css borders applied to the scrolledwindow.
This commit is contained in:
Timm Bäder 2017-06-15 16:03:08 +02:00 committed by Matthias Clasen
parent 3a20bc5e9a
commit 9e43d267bd

View File

@ -330,8 +330,7 @@ static void gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrol
static void gtk_scrolled_window_relative_allocation(GtkWidget *widget, static void gtk_scrolled_window_relative_allocation(GtkWidget *widget,
GtkAllocation *allocation); GtkAllocation *allocation);
static void gtk_scrolled_window_inner_allocation (GtkWidget *widget, static void gtk_scrolled_window_inner_allocation (GtkWidget *widget,
GtkAllocation *rect, GtkAllocation *rect);
gboolean widget_relative);
static void gtk_scrolled_window_allocate_scrollbar (GtkScrolledWindow *scrolled_window, static void gtk_scrolled_window_allocate_scrollbar (GtkScrolledWindow *scrolled_window,
GtkWidget *scrollbar, GtkWidget *scrollbar,
GtkAllocation *allocation); GtkAllocation *allocation);
@ -1767,7 +1766,7 @@ gtk_scrolled_window_snapshot_overshoot (GtkScrolledWindow *scrolled_window,
return; return;
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
gtk_scrolled_window_inner_allocation (widget, &rect, TRUE); gtk_scrolled_window_inner_allocation (widget, &rect);
overshoot_x = CLAMP (overshoot_x, - MAX_OVERSHOOT_DISTANCE, MAX_OVERSHOOT_DISTANCE); overshoot_x = CLAMP (overshoot_x, - MAX_OVERSHOOT_DISTANCE, MAX_OVERSHOOT_DISTANCE);
overshoot_y = CLAMP (overshoot_y, - MAX_OVERSHOOT_DISTANCE, MAX_OVERSHOOT_DISTANCE); overshoot_y = CLAMP (overshoot_y, - MAX_OVERSHOOT_DISTANCE, MAX_OVERSHOOT_DISTANCE);
@ -1814,7 +1813,7 @@ gtk_scrolled_window_snapshot_undershoot (GtkScrolledWindow *scrolled_window,
GtkAdjustment *adj; GtkAdjustment *adj;
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
gtk_scrolled_window_inner_allocation (widget, &rect, TRUE); gtk_scrolled_window_inner_allocation (widget, &rect);
adj = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->hscrollbar)); adj = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->hscrollbar));
if (gtk_adjustment_get_value (adj) < gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj)) if (gtk_adjustment_get_value (adj) < gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj))
@ -2706,13 +2705,14 @@ gtk_scrolled_window_get_property (GObject *object,
static void static void
gtk_scrolled_window_inner_allocation (GtkWidget *widget, gtk_scrolled_window_inner_allocation (GtkWidget *widget,
GtkAllocation *rect, GtkAllocation *rect)
gboolean widget_relative)
{ {
GtkWidget *child; GtkWidget *child;
GtkBorder border = { 0 }; GtkBorder border = { 0 };
gtk_scrolled_window_relative_allocation (widget, rect); gtk_scrolled_window_relative_allocation (widget, rect);
rect->x = 0;
rect->y = 0;
child = gtk_bin_get_child (GTK_BIN (widget)); child = gtk_bin_get_child (GTK_BIN (widget));
if (child && gtk_scrollable_get_border (GTK_SCROLLABLE (child), &border)) if (child && gtk_scrollable_get_border (GTK_SCROLLABLE (child), &border))
{ {
@ -2721,14 +2721,6 @@ gtk_scrolled_window_inner_allocation (GtkWidget *widget,
rect->width -= border.left + border.right; rect->width -= border.left + border.right;
rect->height -= border.top + border.bottom; rect->height -= border.top + border.bottom;
} }
if (widget_relative)
{
GtkAllocation allocation;
gtk_widget_get_allocation (widget, &allocation);
rect->x -= allocation.x;
rect->y -= allocation.y;
}
} }
static void static void
@ -2886,7 +2878,6 @@ gtk_scrolled_window_relative_allocation (GtkWidget *widget,
gint sb_width; gint sb_width;
gint sb_height; gint sb_height;
GtkAllocation content_allocation; GtkAllocation content_allocation;
GtkAllocation widget_allocation;
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
g_return_if_fail (allocation != NULL); g_return_if_fail (allocation != NULL);
@ -2901,7 +2892,6 @@ gtk_scrolled_window_relative_allocation (GtkWidget *widget,
&sb_height, NULL, NULL, NULL); &sb_height, NULL, NULL, NULL);
gtk_widget_get_content_allocation (widget, &content_allocation); gtk_widget_get_content_allocation (widget, &content_allocation);
gtk_widget_get_allocation (widget, &widget_allocation);
allocation->x = content_allocation.x; allocation->x = content_allocation.x;
allocation->y = content_allocation.y; allocation->y = content_allocation.y;
@ -2923,7 +2913,7 @@ gtk_scrolled_window_relative_allocation (GtkWidget *widget,
priv->window_placement == GTK_CORNER_BOTTOM_LEFT))) priv->window_placement == GTK_CORNER_BOTTOM_LEFT)))
allocation->x += sb_width; allocation->x += sb_width;
allocation->width = MAX (1, allocation->width - sb_width); allocation->width = MAX (1, content_allocation.width - sb_width);
} }
if (priv->hscrollbar_visible && !priv->use_indicators) if (priv->hscrollbar_visible && !priv->use_indicators)
@ -2933,7 +2923,7 @@ gtk_scrolled_window_relative_allocation (GtkWidget *widget,
priv->window_placement == GTK_CORNER_BOTTOM_RIGHT) priv->window_placement == GTK_CORNER_BOTTOM_RIGHT)
allocation->y += (sb_height); allocation->y += (sb_height);
allocation->height = MAX (1, allocation->height - sb_height); allocation->height = MAX (1, content_allocation.height - sb_height);
} }
} }
@ -3044,7 +3034,7 @@ gtk_scrolled_window_allocate_scrollbar (GtkScrolledWindow *scrolled_window,
priv = scrolled_window->priv; priv = scrolled_window->priv;
gtk_scrolled_window_inner_allocation (widget, &content_allocation, TRUE); gtk_scrolled_window_inner_allocation (widget, &content_allocation);
gtk_widget_measure (priv->vscrollbar, GTK_ORIENTATION_HORIZONTAL, -1, gtk_widget_measure (priv->vscrollbar, GTK_ORIENTATION_HORIZONTAL, -1,
&sb_width, NULL, NULL, NULL); &sb_width, NULL, NULL, NULL);
gtk_widget_measure (priv->hscrollbar, GTK_ORIENTATION_VERTICAL, -1, gtk_widget_measure (priv->hscrollbar, GTK_ORIENTATION_VERTICAL, -1,