scrolledwindow: Resolve whether we use overlay scrollbars early.

Widgets should support size requests before being realized in general,
otherwise this can cause flicker/resize at initial display time as
the toplevel window can make a request before realize/allocate.

This also makes the added testsuite/gtk/scrolledwindow.c test work again,
this was broken because we only ever calculate whether we are going
to use overlay scrollbars once the scrolled window is realized (and
the test case does not realize any window).
This commit is contained in:
Tristan Van Berkom 2016-06-07 14:09:28 +09:00
parent d7e242eec0
commit 34feba1e7c

View File

@ -400,6 +400,7 @@ static gboolean _gtk_scrolled_window_get_overshoot (GtkScrolledWindow *scrolled_
static void gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window);
static gint _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window);
static void gtk_scrolled_window_update_use_indicators (GtkScrolledWindow *scrolled_window);
static void remove_indicator (GtkScrolledWindow *sw,
Indicator *indicator);
static void indicator_stop_fade (Indicator *indicator);
@ -2146,6 +2147,8 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
gtk_css_node_set_state (priv->undershoot_node[i], gtk_css_node_get_state (widget_node));
g_object_unref (priv->undershoot_node[i]);
}
gtk_scrolled_window_update_use_indicators (scrolled_window);
}
/**
@ -4316,6 +4319,23 @@ remove_indicator (GtkScrolledWindow *scrolled_window,
indicator->current_pos = 1.0;
}
static void
gtk_scrolled_window_sync_use_indicators (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
if (priv->use_indicators)
{
setup_indicator (scrolled_window, &priv->hindicator, priv->hscrollbar);
setup_indicator (scrolled_window, &priv->vindicator, priv->vscrollbar);
}
else
{
remove_indicator (scrolled_window, &priv->hindicator);
remove_indicator (scrolled_window, &priv->vindicator);
}
}
static void
gtk_scrolled_window_update_use_indicators (GtkScrolledWindow *scrolled_window)
{
@ -4331,16 +4351,8 @@ gtk_scrolled_window_update_use_indicators (GtkScrolledWindow *scrolled_window)
{
priv->use_indicators = use_indicators;
if (priv->use_indicators)
{
setup_indicator (scrolled_window, &priv->hindicator, priv->hscrollbar);
setup_indicator (scrolled_window, &priv->vindicator, priv->vscrollbar);
}
else
{
remove_indicator (scrolled_window, &priv->hindicator);
remove_indicator (scrolled_window, &priv->vindicator);
}
if (gtk_widget_get_realized (GTK_WIDGET (scrolled_window)))
gtk_scrolled_window_sync_use_indicators (scrolled_window);
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
}
@ -4383,7 +4395,7 @@ gtk_scrolled_window_realize (GtkWidget *widget)
priv->hindicator.scrollbar = priv->hscrollbar;
priv->vindicator.scrollbar = priv->vscrollbar;
gtk_scrolled_window_update_use_indicators (scrolled_window);
gtk_scrolled_window_sync_use_indicators (scrolled_window);
}
static void
@ -4587,8 +4599,7 @@ gtk_scrolled_window_set_overlay_scrolling (GtkScrolledWindow *scrolled_window,
{
priv->overlay_scrolling = overlay_scrolling;
if (gtk_widget_get_realized (GTK_WIDGET (scrolled_window)))
gtk_scrolled_window_update_use_indicators (scrolled_window);
gtk_scrolled_window_update_use_indicators (scrolled_window);
g_object_notify_by_pspec (G_OBJECT (scrolled_window), properties[PROP_OVERLAY_SCROLLING]);
}