separatortoolitem: don't use custom sizing/rendering

Instead, just rely on the CSS gadget; we can stop using wide-separators,
separator-height and separator-width, and at the same time deprecate the
space-size style property of GtkToolbar.
This commit is contained in:
Cosimo Cecchi 2015-12-29 12:34:16 -08:00
parent 55e80f9379
commit eff8865ab1
6 changed files with 48 additions and 196 deletions

View File

@ -83,7 +83,6 @@ static gboolean gtk_separator_tool_item_draw (GtkWidget
cairo_t *cr); cairo_t *cr);
static void gtk_separator_tool_item_add (GtkContainer *container, static void gtk_separator_tool_item_add (GtkContainer *container,
GtkWidget *child); GtkWidget *child);
static gint get_space_size (GtkToolItem *tool_item);
static void gtk_separator_tool_item_realize (GtkWidget *widget); static void gtk_separator_tool_item_realize (GtkWidget *widget);
static void gtk_separator_tool_item_unrealize (GtkWidget *widget); static void gtk_separator_tool_item_unrealize (GtkWidget *widget);
static void gtk_separator_tool_item_map (GtkWidget *widget); static void gtk_separator_tool_item_map (GtkWidget *widget);
@ -93,43 +92,8 @@ static gboolean gtk_separator_tool_item_button_event (GtkWidget
static gboolean gtk_separator_tool_item_motion_event (GtkWidget *widget, static gboolean gtk_separator_tool_item_motion_event (GtkWidget *widget,
GdkEventMotion *event); GdkEventMotion *event);
static void gtk_separator_tool_item_get_size (GtkCssGadget *gadget,
GtkOrientation orientation,
gint for_size,
gint *minimum_size,
gint *natural_size,
gint *minimum_baseline,
gint *natural_baseline,
gpointer data);
static gboolean gtk_separator_tool_item_render (GtkCssGadget *gadget,
cairo_t *cr,
int x,
int y,
int width,
int height,
gpointer data);
G_DEFINE_TYPE_WITH_PRIVATE (GtkSeparatorToolItem, gtk_separator_tool_item, GTK_TYPE_TOOL_ITEM) G_DEFINE_TYPE_WITH_PRIVATE (GtkSeparatorToolItem, gtk_separator_tool_item, GTK_TYPE_TOOL_ITEM)
static gint
get_space_size (GtkToolItem *tool_item)
{
gint space_size = _gtk_toolbar_get_default_space_size();
GtkWidget *parent;
parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
if (GTK_IS_TOOLBAR (parent))
{
gtk_widget_style_get (parent,
"space-size", &space_size,
NULL);
}
return space_size;
}
static void static void
gtk_separator_tool_item_finalize (GObject *object) gtk_separator_tool_item_finalize (GObject *object)
{ {
@ -201,11 +165,8 @@ gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item)
separator_item->priv->gadget = separator_item->priv->gadget =
gtk_css_custom_gadget_new_for_node (widget_node, gtk_css_custom_gadget_new_for_node (widget_node,
widget, widget,
gtk_separator_tool_item_get_size, NULL, NULL, NULL,
NULL, NULL, NULL);
gtk_separator_tool_item_render,
NULL,
NULL);
} }
static void static void
@ -487,54 +448,13 @@ gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
if (draw != item->priv->draw) if (draw != item->priv->draw)
{ {
item->priv->draw = draw; item->priv->draw = draw;
if (draw)
gtk_css_gadget_remove_class (item->priv->gadget, "invisible");
else
gtk_css_gadget_add_class (item->priv->gadget, "invisible");
gtk_widget_queue_draw (GTK_WIDGET (item)); gtk_widget_queue_draw (GTK_WIDGET (item));
g_object_notify (G_OBJECT (item), "draw"); g_object_notify (G_OBJECT (item), "draw");
} }
} }
static void
gtk_separator_tool_item_get_size (GtkCssGadget *gadget,
GtkOrientation orientation,
gint for_size,
gint *minimum,
gint *natural,
gint *minimum_baseline,
gint *natural_baseline,
gpointer data)
{
GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
if (gtk_tool_item_get_orientation (GTK_TOOL_ITEM (widget)) == orientation)
*minimum = *natural = get_space_size (GTK_TOOL_ITEM (widget));
else
*minimum = *natural = 1;
}
static gboolean
gtk_separator_tool_item_render (GtkCssGadget *gadget,
cairo_t *cr,
int x,
int y,
int width,
int height,
gpointer data)
{
GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
GtkToolbar *toolbar;
GtkWidget *parent;
if (GTK_SEPARATOR_TOOL_ITEM (widget)->priv->draw)
{
parent = gtk_widget_get_parent (widget);
if (GTK_IS_TOOLBAR (parent))
toolbar = GTK_TOOLBAR (parent);
else
toolbar = NULL;
_gtk_toolbar_paint_space_line (widget, toolbar, cr);
}
return FALSE;
}

View File

@ -594,7 +594,14 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
FALSE, FALSE,
GTK_PARAM_READWRITE)); GTK_PARAM_READWRITE));
/* style properties */ /**
* GtkToolbar:space-size:
*
* Size of toolbar spacers.
*
* Deprecated: 3.20: Use the standard margin/padding CSS properties on the
* separator elements; the value of this style property is ignored.
*/
gtk_widget_class_install_style_property (widget_class, gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("space-size", g_param_spec_int ("space-size",
P_("Spacer size"), P_("Spacer size"),
@ -602,7 +609,7 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
0, 0,
G_MAXINT, G_MAXINT,
DEFAULT_SPACE_SIZE, DEFAULT_SPACE_SIZE,
GTK_PARAM_READABLE)); GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
/** /**
* GtkToolbar:internal-padding: * GtkToolbar:internal-padding:
@ -3600,97 +3607,6 @@ get_max_child_expand (GtkToolbar *toolbar)
} }
/* GTK+ internal methods */ /* GTK+ internal methods */
gint
_gtk_toolbar_get_default_space_size (void)
{
return DEFAULT_SPACE_SIZE;
}
void
_gtk_toolbar_paint_space_line (GtkWidget *widget,
GtkToolbar *toolbar,
cairo_t *cr)
{
GtkOrientation orientation;
GtkStyleContext *context;
GtkBorder padding;
gint width, height;
const gdouble start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
const gdouble end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
g_return_if_fail (GTK_IS_WIDGET (widget));
orientation = toolbar ? toolbar->priv->orientation : GTK_ORIENTATION_HORIZONTAL;
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
context = gtk_widget_get_style_context (widget);
gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
gboolean wide_separators;
gint separator_width;
gtk_widget_style_get (widget,
"wide-separators", &wide_separators,
"separator-width", &separator_width,
NULL);
if (wide_separators)
{
gtk_render_background (context, cr,
(width - separator_width) / 2,
padding.top,
separator_width,
height - padding.bottom);
gtk_render_frame (context, cr,
(width - separator_width) / 2,
padding.top,
separator_width,
height - padding.bottom);
}
else
gtk_render_line (context, cr,
(width - padding.left) / 2,
height * start_fraction,
(width - padding.left) / 2,
height * end_fraction);
}
else
{
gboolean wide_separators;
gint separator_height;
gtk_widget_style_get (widget,
"wide-separators", &wide_separators,
"separator-height", &separator_height,
NULL);
if (wide_separators)
{
gtk_render_background (context, cr,
padding.left,
(height - separator_height) / 2,
width - padding.right,
separator_height);
gtk_render_frame (context, cr,
padding.left,
(height - separator_height) / 2,
width - padding.right,
separator_height);
}
else
gtk_render_line (context, cr,
width * start_fraction,
(height - padding.top) / 2,
width * end_fraction,
(height - padding.top) / 2);
}
}
gchar * gchar *
_gtk_toolbar_elide_underscores (const gchar *original) _gtk_toolbar_elide_underscores (const gchar *original)
{ {

View File

@ -35,11 +35,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
gchar * _gtk_toolbar_elide_underscores (const gchar *original); gchar * _gtk_toolbar_elide_underscores (const gchar *original);
void _gtk_toolbar_paint_space_line (GtkWidget *widget,
GtkToolbar *toolbar,
cairo_t *cr);
gint _gtk_toolbar_get_default_space_size (void);
G_END_DECLS G_END_DECLS

View File

@ -671,10 +671,6 @@ toolbar.inline-toolbar toolbutton:backdrop {
&:only-child > button.flat { @extend %linked:only-child; } &:only-child > button.flat { @extend %linked:only-child; }
} }
toolbar separator {
background: none;
}
%linked_middle { %linked_middle {
border-radius: 0; border-radius: 0;
border-right-style: none; border-right-style: none;
@ -1049,6 +1045,21 @@ toolbar {
&.osd.right, &.osd.right,
&.osd.top, &.osd.top,
&.osd.bottom { border-radius: 0; } // positional classes for `attached` osd toolbars &.osd.bottom { border-radius: 0; } // positional classes for `attached` osd toolbars
// toolbar separators
& separator {
background: none;
}
&.horizontal {
& separator {
margin: 0 6px;
}
}
&.vertical {
& separator {
margin: 6px 0;
}
}
} }
//searchbar, location-bar & inline-toolbar //searchbar, location-bar & inline-toolbar

View File

@ -1106,10 +1106,6 @@ button, headerbar button.titlebutton,
.inline-toolbar toolbutton > button:backdrop:disabled:active > .label, .inline-toolbar toolbutton > button:backdrop:disabled:checked > .label { .inline-toolbar toolbutton > button:backdrop:disabled:active > .label, .inline-toolbar toolbutton > button:backdrop:disabled:checked > .label {
color: inherit; } color: inherit; }
toolbar separator, .inline-toolbar separator, searchbar separator,
.location-bar separator {
background: none; }
toolbar.inline-toolbar toolbutton > button.flat, .inline-toolbar toolbutton > button.flat, searchbar.inline-toolbar toolbutton > button.flat, toolbar.inline-toolbar toolbutton > button.flat, .inline-toolbar toolbutton > button.flat, searchbar.inline-toolbar toolbutton > button.flat,
.inline-toolbar.location-bar toolbutton > button.flat, toolbar.inline-toolbar toolbutton > button.sidebar-button, .inline-toolbar toolbutton > button.sidebar-button, searchbar.inline-toolbar toolbutton > button.sidebar-button, .inline-toolbar.location-bar toolbutton > button.flat, toolbar.inline-toolbar toolbutton > button.sidebar-button, .inline-toolbar toolbutton > button.sidebar-button, searchbar.inline-toolbar toolbutton > button.sidebar-button,
.inline-toolbar.location-bar toolbutton > button.sidebar-button, .inline-toolbar headerbar toolbutton > button.titlebutton, headerbar .inline-toolbar toolbutton > button.titlebutton, .inline-toolbar.location-bar toolbutton > button.sidebar-button, .inline-toolbar headerbar toolbutton > button.titlebutton, headerbar .inline-toolbar toolbutton > button.titlebutton,
@ -1572,6 +1568,15 @@ toolbar, .inline-toolbar, searchbar,
.osd.top.location-bar, toolbar.osd.bottom, .osd.bottom.inline-toolbar, searchbar.osd.bottom, .osd.top.location-bar, toolbar.osd.bottom, .osd.bottom.inline-toolbar, searchbar.osd.bottom,
.osd.bottom.location-bar { .osd.bottom.location-bar {
border-radius: 0; } border-radius: 0; }
toolbar separator, .inline-toolbar separator, searchbar separator,
.location-bar separator {
background: none; }
toolbar.horizontal separator, .horizontal.inline-toolbar separator, searchbar.horizontal separator,
.horizontal.location-bar separator {
margin: 0 6px; }
toolbar.vertical separator, .vertical.inline-toolbar separator, searchbar.vertical separator,
.vertical.location-bar separator {
margin: 6px 0; }
.inline-toolbar { .inline-toolbar {
border-width: 0 1px 1px; border-width: 0 1px 1px;

View File

@ -1106,10 +1106,6 @@ button, headerbar button.titlebutton,
.inline-toolbar toolbutton > button:backdrop:disabled:active > .label, .inline-toolbar toolbutton > button:backdrop:disabled:checked > .label { .inline-toolbar toolbutton > button:backdrop:disabled:active > .label, .inline-toolbar toolbutton > button:backdrop:disabled:checked > .label {
color: inherit; } color: inherit; }
toolbar separator, .inline-toolbar separator, searchbar separator,
.location-bar separator {
background: none; }
toolbar.inline-toolbar toolbutton > button.flat, .inline-toolbar toolbutton > button.flat, searchbar.inline-toolbar toolbutton > button.flat, toolbar.inline-toolbar toolbutton > button.flat, .inline-toolbar toolbutton > button.flat, searchbar.inline-toolbar toolbutton > button.flat,
.inline-toolbar.location-bar toolbutton > button.flat, toolbar.inline-toolbar toolbutton > button.sidebar-button, .inline-toolbar toolbutton > button.sidebar-button, searchbar.inline-toolbar toolbutton > button.sidebar-button, .inline-toolbar.location-bar toolbutton > button.flat, toolbar.inline-toolbar toolbutton > button.sidebar-button, .inline-toolbar toolbutton > button.sidebar-button, searchbar.inline-toolbar toolbutton > button.sidebar-button,
.inline-toolbar.location-bar toolbutton > button.sidebar-button, .inline-toolbar headerbar toolbutton > button.titlebutton, headerbar .inline-toolbar toolbutton > button.titlebutton, .inline-toolbar.location-bar toolbutton > button.sidebar-button, .inline-toolbar headerbar toolbutton > button.titlebutton, headerbar .inline-toolbar toolbutton > button.titlebutton,
@ -1572,6 +1568,15 @@ toolbar, .inline-toolbar, searchbar,
.osd.top.location-bar, toolbar.osd.bottom, .osd.bottom.inline-toolbar, searchbar.osd.bottom, .osd.top.location-bar, toolbar.osd.bottom, .osd.bottom.inline-toolbar, searchbar.osd.bottom,
.osd.bottom.location-bar { .osd.bottom.location-bar {
border-radius: 0; } border-radius: 0; }
toolbar separator, .inline-toolbar separator, searchbar separator,
.location-bar separator {
background: none; }
toolbar.horizontal separator, .horizontal.inline-toolbar separator, searchbar.horizontal separator,
.horizontal.location-bar separator {
margin: 0 6px; }
toolbar.vertical separator, .vertical.inline-toolbar separator, searchbar.vertical separator,
.vertical.location-bar separator {
margin: 6px 0; }
.inline-toolbar { .inline-toolbar {
border-width: 0 1px 1px; border-width: 0 1px 1px;