[gtk+/wip/otte/icon-size: 17/20] iconhelper: Query size via CSS
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/icon-size: 17/20] iconhelper: Query size via CSS
- Date: Fri, 10 Nov 2017 21:05:30 +0000 (UTC)
commit fd16897b2aca5b03af006fac4dfae268bc582efb
Author: Benjamin Otte <otte redhat com>
Date: Fri Jan 27 03:59:49 2017 +0100
iconhelper: Query size via CSS
Instead of looking at the icon size, look at the CSS value for
-gtk-icon-size. Set style classes depending on icon size instead.
Trivially change Adwaita and HighContrast to report the same values as
before.
gtk/gtkcellrendererpixbuf.c | 5 +-
gtk/gtkiconhelper.c | 63 ++++++++++------------
gtk/gtkiconhelperprivate.h | 6 +-
gtk/gtkimage.c | 24 +++++----
gtk/theme/Adwaita/_common.scss | 9 +++
gtk/theme/Adwaita/gtk-contained-dark.css | 17 ++++--
gtk/theme/Adwaita/gtk-contained.css | 17 ++++--
gtk/theme/HighContrast/_common.scss | 9 +++
gtk/theme/HighContrast/gtk-contained-inverse.css | 9 +++-
gtk/theme/HighContrast/gtk-contained.css | 9 +++-
10 files changed, 106 insertions(+), 62 deletions(-)
---
diff --git a/gtk/gtkcellrendererpixbuf.c b/gtk/gtkcellrendererpixbuf.c
index 9d57abb..092e08a 100644
--- a/gtk/gtkcellrendererpixbuf.c
+++ b/gtk/gtkcellrendererpixbuf.c
@@ -103,7 +103,6 @@ gtk_cell_renderer_pixbuf_init (GtkCellRendererPixbuf *cellpixbuf)
priv = cellpixbuf->priv;
priv->image_def = gtk_image_definition_new_empty ();
- priv->icon_size = GTK_ICON_SIZE_INHERIT;
}
static void
@@ -377,8 +376,6 @@ create_icon_helper (GtkCellRendererPixbuf *cellpixbuf,
helper = gtk_icon_helper_new (gtk_style_context_get_node (gtk_widget_get_style_context (widget)), widget);
_gtk_icon_helper_set_force_scale_pixbuf (helper, TRUE);
_gtk_icon_helper_set_definition (helper, priv->image_def);
- if (gtk_image_definition_get_storage_type (priv->image_def) != GTK_IMAGE_PIXBUF)
- _gtk_icon_helper_set_icon_size (helper, priv->icon_size);
return helper;
}
@@ -405,6 +402,7 @@ gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
+ gtk_icon_size_set_style_classes (gtk_style_context_get_node (context), priv->icon_size);
icon_helper = create_icon_helper (cellpixbuf, widget);
if (!_gtk_icon_helper_get_is_empty (icon_helper))
@@ -498,6 +496,7 @@ gtk_cell_renderer_pixbuf_snapshot (GtkCellRenderer *cell,
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
+ gtk_icon_size_set_style_classes (gtk_style_context_get_node (context), priv->icon_size);
g_object_get (cell, "is-expander", &is_expander, NULL);
if (is_expander)
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c
index bc12abb..1b85678 100644
--- a/gtk/gtkiconhelper.c
+++ b/gtk/gtkiconhelper.c
@@ -26,6 +26,7 @@
#include "gtkcssenumvalueprivate.h"
#include "gtkcssiconthemevalueprivate.h"
#include "gtkcssnodeprivate.h"
+#include "gtkcssnumbervalueprivate.h"
#include "gtkcssstyleprivate.h"
#include "gtkcssstylepropertyprivate.h"
#include "gtkcsstransientnodeprivate.h"
@@ -37,7 +38,6 @@
struct _GtkIconHelperPrivate {
GtkImageDefinition *def;
- GtkIconSize icon_size;
gint pixel_size;
guint use_fallback : 1;
@@ -212,7 +212,6 @@ gtk_icon_helper_init (GtkIconHelper *self)
self->priv->def = gtk_image_definition_new_empty ();
- self->priv->icon_size = GTK_ICON_SIZE_INHERIT;
self->priv->pixel_size = -1;
self->priv->rendered_surface_is_symbolic = FALSE;
}
@@ -228,17 +227,10 @@ ensure_icon_size (GtkIconHelper *self,
{
width = height = self->priv->pixel_size;
}
- else if (!gtk_icon_size_lookup (self->priv->icon_size, &width, &height))
+ else
{
- if (self->priv->icon_size == GTK_ICON_SIZE_INHERIT)
- {
- width = height = 0;
- }
- else
- {
- g_warning ("Invalid icon size %d", self->priv->icon_size);
- width = height = 24;
- }
+ GtkCssStyle *style = gtk_css_node_get_style (gtk_css_gadget_get_node (GTK_CSS_GADGET (self)));
+ width = height = _gtk_css_number_value_get (gtk_css_style_get_value (style,
GTK_CSS_PROPERTY_ICON_SIZE), 100);
}
*width_out = width;
@@ -333,8 +325,7 @@ get_pixbuf_size (GtkIconHelper *self,
scale_pixmap = FALSE;
if (self->priv->force_scale_pixbuf &&
- (self->priv->pixel_size != -1 ||
- self->priv->icon_size != GTK_ICON_SIZE_INHERIT))
+ self->priv->pixel_size != -1)
{
ensure_icon_size (self, &width, &height);
@@ -644,7 +635,7 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
{
get_surface_size (self, self->priv->rendered_surface, &width, &height);
}
- else if (self->priv->icon_size != GTK_ICON_SIZE_INHERIT)
+ else
{
ensure_icon_size (self, &width, &height);
}
@@ -702,19 +693,6 @@ _gtk_icon_helper_set_surface (GtkIconHelper *self,
}
gboolean
-_gtk_icon_helper_set_icon_size (GtkIconHelper *self,
- GtkIconSize icon_size)
-{
- if (self->priv->icon_size != icon_size)
- {
- self->priv->icon_size = icon_size;
- gtk_icon_helper_invalidate (self);
- return TRUE;
- }
- return FALSE;
-}
-
-gboolean
_gtk_icon_helper_set_pixel_size (GtkIconHelper *self,
gint pixel_size)
{
@@ -752,12 +730,6 @@ _gtk_icon_helper_get_use_fallback (GtkIconHelper *self)
return self->priv->use_fallback;
}
-GtkIconSize
-_gtk_icon_helper_get_icon_size (GtkIconHelper *self)
-{
- return self->priv->icon_size;
-}
-
gint
_gtk_icon_helper_get_pixel_size (GtkIconHelper *self)
{
@@ -916,3 +888,26 @@ _gtk_icon_helper_set_pixbuf_scale (GtkIconHelper *self,
break;
}
}
+
+void
+gtk_icon_size_set_style_classes (GtkCssNode *cssnode,
+ GtkIconSize icon_size)
+{
+ struct {
+ GtkIconSize icon_size;
+ const char *class_name;
+ } class_names[] = {
+ { GTK_ICON_SIZE_NORMAL, "normal-icons" },
+ { GTK_ICON_SIZE_LARGE, "large-icons" }
+ };
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (class_names); i++)
+ {
+ if (icon_size == class_names[i].icon_size)
+ gtk_css_node_add_class (cssnode, g_quark_from_string (class_names[i].class_name));
+ else
+ gtk_css_node_remove_class (cssnode, g_quark_from_string (class_names[i].class_name));
+ }
+}
+
diff --git a/gtk/gtkiconhelperprivate.h b/gtk/gtkiconhelperprivate.h
index 7dabeca..7d592d3 100644
--- a/gtk/gtkiconhelperprivate.h
+++ b/gtk/gtkiconhelperprivate.h
@@ -93,15 +93,12 @@ void _gtk_icon_helper_set_icon_name (GtkIconHelper *self,
void _gtk_icon_helper_set_surface (GtkIconHelper *self,
cairo_surface_t *surface);
-gboolean _gtk_icon_helper_set_icon_size (GtkIconHelper *self,
- GtkIconSize icon_size);
gboolean _gtk_icon_helper_set_pixel_size (GtkIconHelper *self,
gint pixel_size);
gboolean _gtk_icon_helper_set_use_fallback (GtkIconHelper *self,
gboolean use_fallback);
GtkImageType _gtk_icon_helper_get_storage_type (GtkIconHelper *self);
-GtkIconSize _gtk_icon_helper_get_icon_size (GtkIconHelper *self);
gint _gtk_icon_helper_get_pixel_size (GtkIconHelper *self);
gboolean _gtk_icon_helper_get_use_fallback (GtkIconHelper *self);
@@ -132,6 +129,9 @@ void gtk_icon_helper_invalidate (GtkIconHelper *self);
void gtk_icon_helper_invalidate_for_change (GtkIconHelper *self,
GtkCssStyleChange *change);
+void gtk_icon_size_set_style_classes (GtkCssNode *cssnode,
+ GtkIconSize icon_size);
+
G_END_DECLS
#endif /* __GTK_ICON_HELPER_H__ */
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 47dedeb..6d9cdbf 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -128,6 +128,7 @@
struct _GtkImagePrivate
{
GtkIconHelper *icon_helper;
+ GtkIconSize icon_size;
GdkPixbufAnimationIter *animation_iter;
gint animation_timeout;
@@ -141,7 +142,6 @@ struct _GtkImagePrivate
};
-#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_INHERIT
static void gtk_image_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot);
static void gtk_image_size_allocate (GtkWidget *widget,
@@ -251,7 +251,7 @@ gtk_image_class_init (GtkImageClass *class)
P_("Icon size"),
P_("Symbolic size to use for icon set or named icon"),
0, G_MAXINT,
- DEFAULT_ICON_SIZE,
+ GTK_ICON_SIZE_INHERIT,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
/**
@@ -367,7 +367,6 @@ gtk_image_init (GtkImage *image)
gtk_widget_set_has_window (GTK_WIDGET (image), FALSE);
priv->icon_helper = gtk_icon_helper_new (widget_node, GTK_WIDGET (image));
- _gtk_icon_helper_set_icon_size (priv->icon_helper, DEFAULT_ICON_SIZE);
priv->gadget = gtk_css_custom_gadget_new_for_node (widget_node,
GTK_WIDGET (image),
@@ -463,7 +462,7 @@ gtk_image_get_property (GObject *object,
g_value_set_string (value, priv->filename);
break;
case PROP_ICON_SIZE:
- g_value_set_int (value, _gtk_icon_helper_get_icon_size (priv->icon_helper));
+ g_value_set_int (value, priv->icon_size);
break;
case PROP_PIXEL_SIZE:
g_value_set_int (value, _gtk_icon_helper_get_pixel_size (priv->icon_helper));
@@ -1620,13 +1619,18 @@ void
gtk_image_set_icon_size (GtkImage *image,
GtkIconSize icon_size)
{
+ GtkImagePrivate *priv;
+
g_return_if_fail (GTK_IS_IMAGE (image));
- if (_gtk_icon_helper_set_icon_size (image->priv->icon_helper, icon_size))
- {
- gtk_widget_queue_resize (GTK_WIDGET (image));
- g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_ICON_SIZE]);
- }
+ priv = image->priv;
+
+ if (priv->icon_size == icon_size)
+ return;
+
+ priv->icon_size = icon_size;
+ gtk_icon_size_set_style_classes (gtk_widget_get_css_node (GTK_WIDGET (image)), icon_size);
+ g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_ICON_SIZE]);
}
/**
@@ -1644,5 +1648,5 @@ gtk_image_get_icon_size (GtkImage *image)
{
g_return_val_if_fail (GTK_IS_IMAGE (image), GTK_ICON_SIZE_INHERIT);
- return _gtk_icon_helper_get_icon_size (image->priv->icon_helper);
+ return image->priv->icon_size;
}
diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss
index 9690f76..d5c1d24 100644
--- a/gtk/theme/Adwaita/_common.scss
+++ b/gtk/theme/Adwaita/_common.scss
@@ -47,6 +47,7 @@ $button_transition: all 200ms $ease-out-quad;
.background {
color: $fg_color;
background-color: $bg_color;
+ -gtk-icon-size: 16px;
&:backdrop {
color: $backdrop_fg_color;
@@ -56,6 +57,14 @@ $button_transition: all 200ms $ease-out-quad;
}
}
+.normal-icons {
+ -gtk-icon-size: 16px;
+}
+
+.large-icons {
+ -gtk-icon-size: 32px;
+}
+
/*
These wildcard seems unavoidable, need to investigate.
Wildcards are bad and troublesome, use them with care,
diff --git a/gtk/theme/Adwaita/gtk-contained-dark.css b/gtk/theme/Adwaita/gtk-contained-dark.css
index 9a1dad9..4c53217 100644
--- a/gtk/theme/Adwaita/gtk-contained-dark.css
+++ b/gtk/theme/Adwaita/gtk-contained-dark.css
@@ -20,13 +20,20 @@
***************/
.background {
color: #eeeeec;
- background-color: #33393b; }
+ background-color: #33393b;
+ -gtk-icon-size: 16px; }
.background:backdrop {
color: #919494;
background-color: #33393b;
text-shadow: none;
-gtk-icon-shadow: none; }
+.normal-icons {
+ -gtk-icon-size: 16px; }
+
+.large-icons {
+ -gtk-icon-size: 32px; }
+
/*
These wildcard seems unavoidable, need to investigate.
Wildcards are bad and troublesome, use them with care,
@@ -2965,19 +2972,19 @@ radio {
check {
border-radius: 3px; }
check:checked {
- -gtk-icon-source: image(-gtk-recolor(url("assets/check-symbolic.svg")),
-gtk-recolor(url("assets/check-symbolic.symbolic.png"))); }
+ -gtk-icon-source: -gtk-recolor(url("assets/check-symbolic.symbolic.png")); }
check:indeterminate {
- -gtk-icon-source: image(-gtk-recolor(url("assets/dash-symbolic.svg")),
-gtk-recolor(url("assets/dash-symbolic.symbolic.png"))); }
+ -gtk-icon-source: -gtk-recolor(url("assets/dash-symbolic.symbolic.png")); }
treeview.view radio:selected:focus, treeview.view radio:selected,
radio {
border-radius: 100%; }
treeview.view radio:checked:selected,
radio:checked {
- -gtk-icon-source: image(-gtk-recolor(url("assets/bullet-symbolic.svg")),
-gtk-recolor(url("assets/bullet-symbolic.symbolic.png"))); }
+ -gtk-icon-source: -gtk-recolor(url("assets/bullet-symbolic.symbolic.png")); }
treeview.view radio:indeterminate:selected,
radio:indeterminate {
- -gtk-icon-source: image(-gtk-recolor(url("assets/dash-symbolic.svg")),
-gtk-recolor(url("assets/dash-symbolic.symbolic.png"))); }
+ -gtk-icon-source: -gtk-recolor(url("assets/dash-symbolic.symbolic.png")); }
radio:not(:indeterminate):not(:checked):active:not(:backdrop) {
-gtk-icon-transform: scale(0); }
diff --git a/gtk/theme/Adwaita/gtk-contained.css b/gtk/theme/Adwaita/gtk-contained.css
index 580af98..3a84dee 100644
--- a/gtk/theme/Adwaita/gtk-contained.css
+++ b/gtk/theme/Adwaita/gtk-contained.css
@@ -20,13 +20,20 @@
***************/
.background {
color: #2e3436;
- background-color: #e8e8e7; }
+ background-color: #e8e8e7;
+ -gtk-icon-size: 16px; }
.background:backdrop {
color: #8b8e8f;
background-color: #e8e8e7;
text-shadow: none;
-gtk-icon-shadow: none; }
+.normal-icons {
+ -gtk-icon-size: 16px; }
+
+.large-icons {
+ -gtk-icon-size: 32px; }
+
/*
These wildcard seems unavoidable, need to investigate.
Wildcards are bad and troublesome, use them with care,
@@ -2995,19 +3002,19 @@ radio {
check {
border-radius: 3px; }
check:checked {
- -gtk-icon-source: image(-gtk-recolor(url("assets/check-symbolic.svg")),
-gtk-recolor(url("assets/check-symbolic.symbolic.png"))); }
+ -gtk-icon-source: -gtk-recolor(url("assets/check-symbolic.symbolic.png")); }
check:indeterminate {
- -gtk-icon-source: image(-gtk-recolor(url("assets/dash-symbolic.svg")),
-gtk-recolor(url("assets/dash-symbolic.symbolic.png"))); }
+ -gtk-icon-source: -gtk-recolor(url("assets/dash-symbolic.symbolic.png")); }
treeview.view radio:selected:focus, treeview.view radio:selected,
radio {
border-radius: 100%; }
treeview.view radio:checked:selected,
radio:checked {
- -gtk-icon-source: image(-gtk-recolor(url("assets/bullet-symbolic.svg")),
-gtk-recolor(url("assets/bullet-symbolic.symbolic.png"))); }
+ -gtk-icon-source: -gtk-recolor(url("assets/bullet-symbolic.symbolic.png")); }
treeview.view radio:indeterminate:selected,
radio:indeterminate {
- -gtk-icon-source: image(-gtk-recolor(url("assets/dash-symbolic.svg")),
-gtk-recolor(url("assets/dash-symbolic.symbolic.png"))); }
+ -gtk-icon-source: -gtk-recolor(url("assets/dash-symbolic.symbolic.png")); }
radio:not(:indeterminate):not(:checked):active:not(:backdrop) {
-gtk-icon-transform: scale(0); }
diff --git a/gtk/theme/HighContrast/_common.scss b/gtk/theme/HighContrast/_common.scss
index d36cb42..152e336 100644
--- a/gtk/theme/HighContrast/_common.scss
+++ b/gtk/theme/HighContrast/_common.scss
@@ -44,6 +44,7 @@ $ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
.background {
color: $fg_color;
background-color: $bg_color;
+ -gtk-icon-size: 16px;
}
.background:backdrop {
@@ -88,6 +89,14 @@ $ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
}
+.normal-icons {
+ -gtk-icon-size: 16px;
+}
+
+.large-icons {
+ -gtk-icon-size: 32px;
+}
+
.view {
color: $fg_color;
background-color: $base_color;
diff --git a/gtk/theme/HighContrast/gtk-contained-inverse.css
b/gtk/theme/HighContrast/gtk-contained-inverse.css
index 5f4e55f..4b12492 100644
--- a/gtk/theme/HighContrast/gtk-contained-inverse.css
+++ b/gtk/theme/HighContrast/gtk-contained-inverse.css
@@ -53,7 +53,8 @@
***************/
.background {
color: #fff;
- background-color: #000; }
+ background-color: #000;
+ -gtk-icon-size: 16px; }
.background:backdrop {
text-shadow: none;
@@ -86,6 +87,12 @@
background-color: #ddd;
color: #000; }
+.normal-icons {
+ -gtk-icon-size: 16px; }
+
+.large-icons {
+ -gtk-icon-size: 32px; }
+
.view, textview text, iconview {
color: #fff;
background-color: #111; }
diff --git a/gtk/theme/HighContrast/gtk-contained.css b/gtk/theme/HighContrast/gtk-contained.css
index b580a3d..e31d3a8 100644
--- a/gtk/theme/HighContrast/gtk-contained.css
+++ b/gtk/theme/HighContrast/gtk-contained.css
@@ -53,7 +53,8 @@
***************/
.background {
color: #000;
- background-color: #fff; }
+ background-color: #fff;
+ -gtk-icon-size: 16px; }
.background:backdrop {
text-shadow: none;
@@ -86,6 +87,12 @@
background-color: #000;
color: #fff; }
+.normal-icons {
+ -gtk-icon-size: 16px; }
+
+.large-icons {
+ -gtk-icon-size: 32px; }
+
.view, textview text, iconview {
color: #000;
background-color: #fff; }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]