[gtk] scrolledwindow: Avoid a queue_resize path in size-allocate
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] scrolledwindow: Avoid a queue_resize path in size-allocate
- Date: Thu, 21 Jun 2018 18:59:23 +0000 (UTC)
commit e079fad1d5e4dd9392e68576b9d37324c5d8eb6b
Author: Timm Bäder <mail baedert org>
Date: Thu Jun 21 17:43:26 2018 +0200
scrolledwindow: Avoid a queue_resize path in size-allocate
gtk/gtkscrolledwindow.c | 71 ++++++++++++++++++++++++++++++++++---------------
1 file changed, 50 insertions(+), 21 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 928019098f..354fbcd0d1 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -1375,6 +1375,36 @@ scroll_controller_decelerate (GtkEventControllerScroll *scroll,
initial_vel_y * unit_y);
}
+static void
+gtk_scrolled_window_update_scrollbar_visibility_flags (GtkScrolledWindow *scrolled_window,
+ GtkWidget *scrollbar)
+{
+ GtkScrolledWindowPrivate *priv = gtk_scrolled_window_get_instance_private (scrolled_window);
+ GtkAdjustment *adjustment;
+
+ if (scrollbar == NULL)
+ return;
+
+ adjustment = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (scrollbar));
+
+ if (scrollbar == priv->hscrollbar)
+ {
+ if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ {
+ priv->hscrollbar_visible = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower
(adjustment) >
+ gtk_adjustment_get_page_size (adjustment));
+ }
+ }
+ else if (scrollbar == priv->vscrollbar)
+ {
+ if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ {
+ priv->vscrollbar_visible = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower
(adjustment) >
+ gtk_adjustment_get_page_size (adjustment));
+ }
+ }
+}
+
static void
gtk_scrolled_window_size_allocate (GtkWidget *widget,
const GtkAllocation *allocation,
@@ -1560,20 +1590,21 @@ gtk_scrolled_window_size_allocate (GtkWidget *widget,
{
previous_hvis = priv->hscrollbar_visible;
previous_vvis = priv->vscrollbar_visible;
+
gtk_scrolled_window_allocate_child (scrolled_window, allocation);
- /* Explicitly force scrollbar visibility checks.
- *
- * Since we make a guess above, the child might not decide to update the adjustments
- * if they logically did not change since the last configuration
- */
- if (priv->hscrollbar)
- gtk_scrolled_window_adjustment_changed
- (gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->hscrollbar)), scrolled_window);
+ /* Explicitly force scrollbar visibility checks.
+ *
+ * Since we make a guess above, the child might not decide to update the adjustments
+ * if they logically did not change since the last configuration
+ *
+ * These will update priv->hscrollbar_visible and priv->vscrollbar_visible.
+ */
+ gtk_scrolled_window_update_scrollbar_visibility_flags (scrolled_window,
+ priv->hscrollbar);
- if (priv->vscrollbar)
- gtk_scrolled_window_adjustment_changed
- (gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->vscrollbar)), scrolled_window);
+ gtk_scrolled_window_update_scrollbar_visibility_flags (scrolled_window,
+ priv->vscrollbar);
/* If, after the first iteration, the hscrollbar and the
* vscrollbar flip visiblity... or if one of the scrollbars flip
@@ -3377,12 +3408,11 @@ gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
{
gboolean visible;
- visible = priv->hscrollbar_visible;
- priv->hscrollbar_visible = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower
(adjustment) >
- gtk_adjustment_get_page_size (adjustment));
+ visible = priv->hscrollbar_visible;
+ gtk_scrolled_window_update_scrollbar_visibility_flags (scrolled_window, priv->hscrollbar);
- if (priv->hscrollbar_visible != visible)
- gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+ if (priv->hscrollbar_visible != visible)
+ gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
}
}
else if (adjustment == gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->vscrollbar)))
@@ -3391,12 +3421,11 @@ gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
{
gboolean visible;
- visible = priv->vscrollbar_visible;
- priv->vscrollbar_visible = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower
(adjustment) >
- gtk_adjustment_get_page_size (adjustment));
+ visible = priv->vscrollbar_visible;
+ gtk_scrolled_window_update_scrollbar_visibility_flags (scrolled_window, priv->vscrollbar);
- if (priv->vscrollbar_visible != visible)
- gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+ if (priv->vscrollbar_visible != visible)
+ gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]