* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#include "gtkcssstylepropertyprivate.h"
+#include "gtkcssenumvalueprivate.h"
+#include "gtkcssinheritvalueprivate.h"
+#include "gtkcssinitialvalueprivate.h"
#include "gtkcssstylefuncsprivate.h"
#include "gtkcsstypesprivate.h"
#include "gtkintl.h"
#include "gtkprivatetypebuiltins.h"
#include "gtkstylepropertiesprivate.h"
-/* for resolvage */
-#include <cairo-gobject.h>
-#include "gtkgradient.h"
-#include "gtkshadowprivate.h"
-#include "gtkwin32themeprivate.h"
-
+/* this is in case round() is not provided by the compiler,
+ * such as in the case of C89 compilers, like MSVC
+ */
+#include "fallback-c89.c"
enum {
PROP_0,
+ PROP_ANIMATED,
+ PROP_AFFECTS_SIZE,
+ PROP_AFFECTS_FONT,
PROP_ID,
PROP_INHERIT,
PROP_INITIAL
G_DEFINE_TYPE (GtkCssStyleProperty, _gtk_css_style_property, GTK_TYPE_STYLE_PROPERTY)
+static GtkBitmask *_properties_affecting_size = NULL;
+static GtkBitmask *_properties_affecting_font = NULL;
+
+static GtkCssStylePropertyClass *gtk_css_style_property_class = NULL;
+
static void
gtk_css_style_property_constructed (GObject *object)
{
property->id = klass->style_properties->len;
g_ptr_array_add (klass->style_properties, property);
+ if (property->affects_size)
+ _properties_affecting_size = _gtk_bitmask_set (_properties_affecting_size, property->id, TRUE);
+
+ if (property->affects_font)
+ _properties_affecting_font = _gtk_bitmask_set (_properties_affecting_font, property->id, TRUE);
+
G_OBJECT_CLASS (_gtk_css_style_property_parent_class)->constructed (object);
}
GParamSpec *pspec)
{
GtkCssStyleProperty *property = GTK_CSS_STYLE_PROPERTY (object);
- const GValue *initial;
switch (prop_id)
{
+ case PROP_ANIMATED:
+ property->animated = g_value_get_boolean (value);
+ break;
+ case PROP_AFFECTS_SIZE:
+ property->affects_size = g_value_get_boolean (value);
+ break;
+ case PROP_AFFECTS_FONT:
+ property->affects_font = g_value_get_boolean (value);
+ break;
case PROP_INHERIT:
property->inherit = g_value_get_boolean (value);
break;
case PROP_INITIAL:
- initial = g_value_get_boxed (value);
- g_assert (initial);
- g_value_init (&property->initial_value, G_VALUE_TYPE (initial));
- g_value_copy (initial, &property->initial_value);
+ property->initial_value = g_value_dup_boxed (value);
+ g_assert (property->initial_value != NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
switch (prop_id)
{
+ case PROP_ANIMATED:
+ g_value_set_boolean (value, property->animated);
+ break;
+ case PROP_AFFECTS_SIZE:
+ g_value_set_boolean (value, property->affects_size);
+ break;
+ case PROP_AFFECTS_FONT:
+ g_value_set_boolean (value, property->affects_font);
+ break;
case PROP_ID:
g_value_set_boolean (value, property->id);
break;
g_value_set_boolean (value, property->inherit);
break;
case PROP_INITIAL:
- g_value_set_boxed (value, &property->initial_value);
+ g_value_set_boxed (value, property->initial_value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
GtkStateFlags state,
const GValue *value)
{
+ GtkCssStyleProperty *style;
+ GtkCssValue *css_value;
+
+ style = GTK_CSS_STYLE_PROPERTY (property);
+ css_value = style->assign_value (style, value);
+
_gtk_style_properties_set_property_by_property (props,
- GTK_CSS_STYLE_PROPERTY (property),
+ style,
state,
- value);
-}
-
-static void
-_gtk_style_property_default_value (GtkStyleProperty *property,
- GtkStyleProperties *properties,
- GtkStateFlags state,
- GValue *value)
-{
- g_value_copy (_gtk_css_style_property_get_initial_value (GTK_CSS_STYLE_PROPERTY (property)), value);
-}
-
-static gboolean
-resolve_color (GtkStyleProperties *props,
- GValue *value)
-{
- GdkRGBA color;
-
- /* Resolve symbolic color to GdkRGBA */
- if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
- return FALSE;
-
- /* Store it back, this is where GdkRGBA caching happens */
- g_value_unset (value);
- g_value_init (value, GDK_TYPE_RGBA);
- g_value_set_boxed (value, &color);
-
- return TRUE;
-}
-
-static gboolean
-resolve_color_rgb (GtkStyleProperties *props,
- GValue *value)
-{
- GdkColor color = { 0 };
- GdkRGBA rgba;
-
- if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
- return FALSE;
-
- color.red = rgba.red * 65535. + 0.5;
- color.green = rgba.green * 65535. + 0.5;
- color.blue = rgba.blue * 65535. + 0.5;
-
- g_value_unset (value);
- g_value_init (value, GDK_TYPE_COLOR);
- g_value_set_boxed (value, &color);
-
- return TRUE;
+ css_value);
+ _gtk_css_value_unref (css_value);
}
static gboolean
-resolve_win32_theme_part (GtkStyleProperties *props,
- GValue *value,
- GValue *value_out,
- GtkStylePropertyContext *context)
+_gtk_css_style_property_query_special_case (GtkCssStyleProperty *property,
+ GValue *value,
+ GtkStyleQueryFunc query_func,
+ gpointer query_data)
{
- GtkWin32ThemePart *part;
- cairo_pattern_t *pattern;
+ GtkBorderStyle border_style;
- part = g_value_get_boxed (value);
- if (part == NULL)
- return FALSE;
-
- pattern = _gtk_win32_theme_part_render (part, context->width, context->height);
-
- g_value_take_boxed (value_out, pattern);
-
- return TRUE;
-}
-
-
-static gboolean
-resolve_gradient (GtkStyleProperties *props,
- GValue *value)
-{
- cairo_pattern_t *gradient;
-
- if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
- return FALSE;
-
- /* Store it back, this is where cairo_pattern_t caching happens */
- g_value_unset (value);
- g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
- g_value_take_boxed (value, gradient);
+ switch (property->id)
+ {
+ case GTK_CSS_PROPERTY_BORDER_TOP_WIDTH:
+ border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_TOP_STYLE, query_data));
+ if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+ {
+ g_value_init (value, G_TYPE_INT);
+ return TRUE;
+ }
+ break;
+ case GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH:
+ border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE, query_data));
+ if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+ {
+ g_value_init (value, G_TYPE_INT);
+ return TRUE;
+ }
+ break;
+ case GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH:
+ border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE, query_data));
+ if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+ {
+ g_value_init (value, G_TYPE_INT);
+ return TRUE;
+ }
+ break;
+ case GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH:
+ border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_LEFT_STYLE, query_data));
+ if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+ {
+ g_value_init (value, G_TYPE_INT);
+ return TRUE;
+ }
+ break;
+ case GTK_CSS_PROPERTY_OUTLINE_WIDTH:
+ border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_OUTLINE_STYLE, query_data));
+ if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+ {
+ g_value_init (value, G_TYPE_INT);
+ return TRUE;
+ }
+ break;
+ default:
+ break;
+ }
- return TRUE;
+ return FALSE;
}
-static gboolean
-resolve_shadow (GtkStyleProperties *props,
- GValue *value)
+static void
+_gtk_css_style_property_query (GtkStyleProperty *property,
+ GValue *value,
+ GtkStyleQueryFunc query_func,
+ gpointer query_data)
{
- GtkShadow *resolved, *base;
-
- base = g_value_get_boxed (value);
-
- if (base == NULL)
- return TRUE;
+ GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property);
+ GtkCssValue *css_value;
- if (_gtk_shadow_get_resolved (base))
- return TRUE;
-
- resolved = _gtk_shadow_resolve (base, props);
- if (resolved == NULL)
- return FALSE;
+ /* I don't like this special case being here in this generic code path, but no idea where else to put it. */
+ if (_gtk_css_style_property_query_special_case (style_property, value, query_func, query_data))
+ return;
- g_value_take_boxed (value, resolved);
+ css_value = (* query_func) (GTK_CSS_STYLE_PROPERTY (property)->id, query_data);
+ if (css_value == NULL)
+ css_value =_gtk_css_style_property_get_initial_value (style_property);
- return TRUE;
+ style_property->query_value (style_property, css_value, value);
}
-static void
-_gtk_style_property_resolve (GtkStyleProperty *property,
- GtkStyleProperties *props,
- GtkStateFlags state,
- GtkStylePropertyContext *context,
- GValue *val,
- GValue *val_out)
+static GtkCssValue *
+gtk_css_style_property_parse_value (GtkStyleProperty *property,
+ GtkCssParser *parser)
{
- if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_SPECIAL_VALUE)
- {
- GtkCssSpecialValue special = g_value_get_enum (val);
-
- g_value_unset (val);
- switch (special)
- {
- case GTK_CSS_CURRENT_COLOR:
- g_assert (_gtk_style_property_get_value_type (property) == GDK_TYPE_RGBA);
- gtk_style_properties_get_property (props, "color", state, val);
- break;
- case GTK_CSS_INHERIT:
- case GTK_CSS_INITIAL:
- default:
- g_assert_not_reached ();
- }
- }
- else if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
- {
- if (_gtk_style_property_get_value_type (property) == GDK_TYPE_RGBA)
- {
- if (resolve_color (props, val))
- goto out;
- }
- else if (_gtk_style_property_get_value_type (property) == GDK_TYPE_COLOR)
- {
- if (resolve_color_rgb (props, val))
- goto out;
- }
-
- g_value_unset (val);
- g_value_init (val, _gtk_style_property_get_value_type (property));
- _gtk_style_property_default_value (property, props, state, val);
- }
- else if (G_VALUE_TYPE (val) == GDK_TYPE_RGBA)
- {
- if (g_value_get_boxed (val) == NULL)
- _gtk_style_property_default_value (property, props, state, val);
- }
- else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
- {
- g_return_if_fail (_gtk_style_property_get_value_type (property) == CAIRO_GOBJECT_TYPE_PATTERN);
-
- if (!resolve_gradient (props, val))
- {
- g_value_unset (val);
- g_value_init (val, CAIRO_GOBJECT_TYPE_PATTERN);
- _gtk_style_property_default_value (property, props, state, val);
- }
- }
- else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
+ GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property);
+
+ if (_gtk_css_parser_try (parser, "initial", TRUE))
{
- if (!resolve_shadow (props, val))
- _gtk_style_property_default_value (property, props, state, val);
+ /* the initial value can be explicitly specified with the
+ * ‘initial’ keyword which all properties accept.
+ */
+ return _gtk_css_initial_value_new ();
}
- else if (G_VALUE_TYPE (val) == GTK_TYPE_WIN32_THEME_PART)
+ else if (_gtk_css_parser_try (parser, "inherit", TRUE))
{
- if (resolve_win32_theme_part (props, val, val_out, context))
- return; /* Don't copy val, this sets val_out */
- _gtk_style_property_default_value (property, props, state, val);
+ /* All properties accept the ‘inherit’ value which
+ * explicitly specifies that the value will be determined
+ * by inheritance. The ‘inherit’ value can be used to
+ * strengthen inherited values in the cascade, and it can
+ * also be used on properties that are not normally inherited.
+ */
+ return _gtk_css_inherit_value_new ();
}
- out:
- g_value_copy (val, val_out);
-}
-
-static void
-_gtk_css_style_property_query (GtkStyleProperty *property,
- GtkStyleProperties *props,
- GtkStateFlags state,
- GtkStylePropertyContext *context,
- GValue *value)
-{
- const GValue *val;
-
- val = _gtk_style_properties_peek_property (props, GTK_CSS_STYLE_PROPERTY (property), state);
- if (val)
- _gtk_style_property_resolve (property, props, state, context, (GValue *) val, value);
- else
- _gtk_style_property_default_value (property, props, state, value);
+ return (* style_property->parse_value) (style_property, parser);
}
static void
object_class->set_property = gtk_css_style_property_set_property;
object_class->get_property = gtk_css_style_property_get_property;
+ g_object_class_install_property (object_class,
+ PROP_ANIMATED,
+ g_param_spec_boolean ("animated",
+ P_("Animated"),
+ P_("Set if the value can be animated"),
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_AFFECTS_SIZE,
+ g_param_spec_boolean ("affects-size",
+ P_("Affects size"),
+ P_("Set if the value affects the sizing of elements"),
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_AFFECTS_FONT,
+ g_param_spec_boolean ("affects-font",
+ P_("Affects font"),
+ P_("Set if the value affects the font"),
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_ID,
g_param_spec_uint ("id",
g_param_spec_boxed ("initial-value",
P_("Initial value"),
P_("The initial specified value used for this property"),
- G_TYPE_VALUE,
+ GTK_TYPE_CSS_VALUE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
property_class->assign = _gtk_css_style_property_assign;
property_class->query = _gtk_css_style_property_query;
+ property_class->parse_value = gtk_css_style_property_parse_value;
klass->style_properties = g_ptr_array_new ();
+
+ _properties_affecting_size = _gtk_bitmask_new ();
+ _properties_affecting_font = _gtk_bitmask_new ();
+
+ gtk_css_style_property_class = klass;
}
+static GtkCssValue *
+gtk_css_style_property_real_parse_value (GtkCssStyleProperty *property,
+ GtkCssParser *parser)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
static void
-_gtk_css_style_property_init (GtkCssStyleProperty *style_property)
+_gtk_css_style_property_init (GtkCssStyleProperty *property)
{
+ property->parse_value = gtk_css_style_property_real_parse_value;
}
/**
guint
_gtk_css_style_property_get_n_properties (void)
{
- GtkCssStylePropertyClass *klass;
-
- klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY);
+ if (G_UNLIKELY (gtk_css_style_property_class == NULL))
+ {
+ _gtk_style_property_init_properties ();
+ g_assert (gtk_css_style_property_class);
+ }
- return klass->style_properties->len;
+ return gtk_css_style_property_class->style_properties->len;
}
/**
GtkCssStyleProperty *
_gtk_css_style_property_lookup_by_id (guint id)
{
- GtkCssStylePropertyClass *klass;
- klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY);
+ if (G_UNLIKELY (gtk_css_style_property_class == NULL))
+ {
+ _gtk_style_property_init_properties ();
+ g_assert (gtk_css_style_property_class);
+ }
- return g_ptr_array_index (klass->style_properties, id);
+ g_return_val_if_fail (id < gtk_css_style_property_class->style_properties->len, NULL);
+
+ return g_ptr_array_index (gtk_css_style_property_class->style_properties, id);
}
/**
gboolean
_gtk_css_style_property_is_inherit (GtkCssStyleProperty *property)
{
- g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0);
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
return property->inherit;
}
+/**
+ * _gtk_css_style_property_is_animated:
+ * @property: the property
+ *
+ * Queries if the given @property can be is animated. See
+ * <ulink url="http://www.w3.org/TR/css3-transitions/#animatable-css>
+ * the CSS documentation</ulink> for animatable properties.
+ *
+ * Returns: %TRUE if the property can be animated.
+ **/
+gboolean
+_gtk_css_style_property_is_animated (GtkCssStyleProperty *property)
+{
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
+
+ return property->animated;
+}
+
+/**
+ * _gtk_css_style_property_affects_size:
+ * @property: the property
+ *
+ * Queries if the given @property affects the size of elements. This is
+ * used for optimizations inside GTK, where a gtk_widget_queue_resize()
+ * can be avoided if the property does not affect size.
+ *
+ * Returns: %TRUE if the property affects sizing of elements.
+ **/
+gboolean
+_gtk_css_style_property_affects_size (GtkCssStyleProperty *property)
+{
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
+
+ return property->affects_size;
+}
+
+/**
+ * _gtk_css_style_property_affects_font:
+ * @property: the property
+ *
+ * Queries if the given @property affects the default font. This is
+ * used for optimizations inside GTK, where clearing pango
+ * layouts can be avoided if the font doesn't change.
+ *
+ * Returns: %TRUE if the property affects the font.
+ **/
+gboolean
+_gtk_css_style_property_affects_font (GtkCssStyleProperty *property)
+{
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
+
+ return property->affects_font;
+}
+
/**
* _gtk_css_style_property_get_id:
* @property: the property
*
* Returns: a reference to the initial value. The value will never change.
**/
-const GValue *
+GtkCssValue *
_gtk_css_style_property_get_initial_value (GtkCssStyleProperty *property)
{
g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), NULL);
- return &property->initial_value;
+ return property->initial_value;
}
-/**
- * _gtk_css_style_property_print_value:
- * @property: the property
- * @value: the value to print
- * @string: the string to print to
- *
- * Prints @value to the given @string in CSS format. The @value must be a
- * valid specified value as parsed using the parse functions or as assigned
- * via _gtk_style_property_assign().
- **/
-void
-_gtk_css_style_property_print_value (GtkCssStyleProperty *property,
- const GValue *value,
- GString *string)
+gboolean
+_gtk_css_style_property_changes_affect_size (const GtkBitmask *changes)
{
- g_return_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property));
- g_return_if_fail (value != NULL);
- g_return_if_fail (string != NULL);
-
- if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
- {
- GEnumClass *enum_class;
- GEnumValue *enum_value;
-
- enum_class = g_type_class_ref (GTK_TYPE_CSS_SPECIAL_VALUE);
- enum_value = g_enum_get_value (enum_class, g_value_get_enum (value));
-
- g_string_append (string, enum_value->value_nick);
-
- g_type_class_unref (enum_class);
- }
- else if (GTK_STYLE_PROPERTY (property)->print_func)
- (* GTK_STYLE_PROPERTY (property)->print_func) (value, string);
- else
- _gtk_css_style_print_value (value, string);
+ return _gtk_bitmask_intersects (changes, _properties_affecting_size);
}
+gboolean
+_gtk_css_style_property_changes_affect_font (const GtkBitmask *changes)
+{
+ return _gtk_bitmask_intersects (changes, _properties_affecting_font);
+}