From 80af6ff1307d151d27fc8a3f44098a58ed202ec5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 4 Nov 2015 07:29:33 -0500 Subject: [PATCH] scrolledwindow: Port to CSS nodes Change GtkScrolledWindow to use transient named CSS nodes for drawing the overshoot, undershoot and scrollbar junction. --- gtk/gtkscrolledwindow.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index e679c4f2da..7afdeadba7 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -43,6 +43,7 @@ #include "gtkwindow.h" #include "gtkkineticscrolling.h" #include "a11y/gtkscrolledwindowaccessible.h" +#include "gtkstylecontextprivate.h" #include @@ -104,6 +105,16 @@ * scrollbars are desired although no mouse is present, this behaviour * can be turned off with the #GtkScrolledWindow:overlay-scrolling * property. + * + * # CSS nodes + * + * GtkScrolledWindow has a main CSS node with name scrolledwindow. + * It uses transient subnodes with names overshoot and undershoot to + * draw the overflow and underflow indications. These nodes get + * the .left, .right, .top or .bottom style class added depending + * on where the indictaion is drawn. If both scrollbars are visible, + * the area where they meet is drawn with a transient subnode named + * junction. */ @@ -722,6 +733,7 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class) add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD); gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE); + gtk_widget_class_set_css_name (widget_class, "scrolledwindow"); } static gboolean @@ -2142,8 +2154,7 @@ gtk_scrolled_window_draw_scrollbars_junction (GtkScrolledWindow *scrolled_window priv->window_placement == GTK_CORNER_TOP_RIGHT) junction_rect.y += vscr_allocation.height; - gtk_style_context_save (context); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCROLLBARS_JUNCTION); + gtk_style_context_save_named (context, "junction"); gtk_render_background (context, cr, junction_rect.x, junction_rect.y, @@ -2193,9 +2204,7 @@ gtk_scrolled_window_draw_overshoot (GtkScrolledWindow *scrolled_window, overshoot_x = CLAMP (overshoot_x, - MAX_OVERSHOOT_DISTANCE, MAX_OVERSHOOT_DISTANCE); overshoot_y = CLAMP (overshoot_y, - MAX_OVERSHOOT_DISTANCE, MAX_OVERSHOOT_DISTANCE); - gtk_style_context_save (context); - gtk_style_context_remove_class (context, GTK_STYLE_CLASS_FRAME); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_OVERSHOOT); + gtk_style_context_save_named (context, "overshoot"); if (overshoot_x > 0) { @@ -2214,9 +2223,7 @@ gtk_scrolled_window_draw_overshoot (GtkScrolledWindow *scrolled_window, gtk_style_context_restore (context); - gtk_style_context_save (context); - gtk_style_context_remove_class (context, GTK_STYLE_CLASS_FRAME); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_OVERSHOOT); + gtk_style_context_save_named (context, "overshoot"); if (overshoot_y > 0) { @@ -2249,51 +2256,49 @@ gtk_scrolled_window_draw_undershoot (GtkScrolledWindow *scrolled_window, context = gtk_widget_get_style_context (widget); gtk_scrolled_window_inner_allocation (widget, &rect); - gtk_style_context_save (context); - gtk_style_context_remove_class (context, GTK_STYLE_CLASS_FRAME); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_UNDERSHOOT); - adj = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)); if (gtk_adjustment_get_value (adj) < gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj)) { + gtk_style_context_save_named (context, "undershoot"); gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT); gtk_render_background (context, cr, rect.x + rect.width - UNDERSHOOT_SIZE, rect.y, UNDERSHOOT_SIZE, rect.height); gtk_render_frame (context, cr, rect.x + rect.width - UNDERSHOOT_SIZE, rect.y, UNDERSHOOT_SIZE, rect.height); - gtk_style_context_remove_class (context, GTK_STYLE_CLASS_RIGHT); + gtk_style_context_restore (context); } if (gtk_adjustment_get_value (adj) > gtk_adjustment_get_lower (adj)) { + gtk_style_context_save_named (context, "undershoot"); gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT); gtk_render_background (context, cr, rect.x, rect.y, UNDERSHOOT_SIZE, rect.height); gtk_render_frame (context, cr, rect.x, rect.y, UNDERSHOOT_SIZE, rect.height); - gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEFT); + gtk_style_context_restore (context); } adj = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)); if (gtk_adjustment_get_value (adj) < gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj)) { + gtk_style_context_save_named (context, "undershoot"); gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM); gtk_render_background (context, cr, rect.x, rect.y + rect.height - UNDERSHOOT_SIZE, rect.width, UNDERSHOOT_SIZE); gtk_render_frame (context, cr, rect.x, rect.y + rect.height - UNDERSHOOT_SIZE, rect.width, UNDERSHOOT_SIZE); - gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BOTTOM); + gtk_style_context_restore (context); } if (gtk_adjustment_get_value (adj) > gtk_adjustment_get_lower (adj)) { + gtk_style_context_save_named (context, "undershoot"); gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP); gtk_render_background (context, cr, rect.x, rect.y, rect.width, UNDERSHOOT_SIZE); gtk_render_frame (context, cr, rect.x, rect.y, rect.width, UNDERSHOOT_SIZE); - gtk_style_context_remove_class (context, GTK_STYLE_CLASS_TOP); + gtk_style_context_restore (context); } - - gtk_style_context_restore (context); } static gboolean