summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk/gtkcssenumvalue.c22
-rw-r--r--gtk/gtkcssenumvalueprivate.h1
-rw-r--r--gtk/gtkcssnumbervalue.c32
-rw-r--r--gtk/gtkcssstylepropertyimpl.c13
4 files changed, 45 insertions, 23 deletions
diff --git a/gtk/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c
index f4c17c4ae8..f91ba889a2 100644
--- a/gtk/gtkcssenumvalue.c
+++ b/gtk/gtkcssenumvalue.c
@@ -133,8 +133,8 @@ _gtk_css_border_style_value_get (const GtkCssValue *value)
*/
#define DEFAULT_FONT_SIZE 10
-static double
-get_default_font_size (GtkStyleProviderPrivate *provider)
+double
+_gtk_css_font_size_get_default (GtkStyleProviderPrivate *provider)
{
GtkSettings *settings;
PangoFontDescription *description;
@@ -173,35 +173,35 @@ gtk_css_value_font_size_compute (GtkCssValue *value,
switch (value->value)
{
case GTK_CSS_FONT_SIZE_XX_SMALL:
- font_size = get_default_font_size (provider) * 3. / 5;
+ font_size = _gtk_css_font_size_get_default (provider) * 3. / 5;
break;
case GTK_CSS_FONT_SIZE_X_SMALL:
- font_size = get_default_font_size (provider) * 3. / 4;
+ font_size = _gtk_css_font_size_get_default (provider) * 3. / 4;
break;
case GTK_CSS_FONT_SIZE_SMALL:
- font_size = get_default_font_size (provider) * 8. / 9;
+ font_size = _gtk_css_font_size_get_default (provider) * 8. / 9;
break;
default:
g_assert_not_reached ();
/* fall thru */
case GTK_CSS_FONT_SIZE_MEDIUM:
- font_size = get_default_font_size (provider);
+ font_size = _gtk_css_font_size_get_default (provider);
break;
case GTK_CSS_FONT_SIZE_LARGE:
- font_size = get_default_font_size (provider) * 6. / 5;
+ font_size = _gtk_css_font_size_get_default (provider) * 6. / 5;
break;
case GTK_CSS_FONT_SIZE_X_LARGE:
- font_size = get_default_font_size (provider) * 3. / 2;
+ font_size = _gtk_css_font_size_get_default (provider) * 3. / 2;
break;
case GTK_CSS_FONT_SIZE_XX_LARGE:
- font_size = get_default_font_size (provider) * 2;
+ font_size = _gtk_css_font_size_get_default (provider) * 2;
break;
case GTK_CSS_FONT_SIZE_SMALLER:
*dependencies = GTK_CSS_DEPENDS_ON_PARENT;
if (parent_values)
font_size = _gtk_css_number_value_get (_gtk_css_computed_values_get_value (parent_values, GTK_CSS_PROPERTY_FONT_SIZE), 100);
else
- font_size = get_default_font_size (provider);
+ font_size = _gtk_css_font_size_get_default (provider);
/* XXX: This is what WebKit does... */
font_size *= 1.2;
break;
@@ -210,7 +210,7 @@ gtk_css_value_font_size_compute (GtkCssValue *value,
if (parent_values)
font_size = _gtk_css_number_value_get (_gtk_css_computed_values_get_value (parent_values, GTK_CSS_PROPERTY_FONT_SIZE), 100);
else
- font_size = get_default_font_size (provider);
+ font_size = _gtk_css_font_size_get_default (provider);
/* XXX: This is what WebKit does... */
font_size /= 1.2;
break;
diff --git a/gtk/gtkcssenumvalueprivate.h b/gtk/gtkcssenumvalueprivate.h
index 56b6ea3c3b..b981008d53 100644
--- a/gtk/gtkcssenumvalueprivate.h
+++ b/gtk/gtkcssenumvalueprivate.h
@@ -34,6 +34,7 @@ GtkBorderStyle _gtk_css_border_style_value_get (const GtkCssValue *value)
GtkCssValue * _gtk_css_font_size_value_new (GtkCssFontSize size);
GtkCssValue * _gtk_css_font_size_value_try_parse (GtkCssParser *parser);
GtkCssFontSize _gtk_css_font_size_value_get (const GtkCssValue *value);
+double _gtk_css_font_size_get_default (GtkStyleProviderPrivate *provider);
GtkCssValue * _gtk_css_font_style_value_new (PangoStyle style);
GtkCssValue * _gtk_css_font_style_value_try_parse (GtkCssParser *parser);
diff --git a/gtk/gtkcssnumbervalue.c b/gtk/gtkcssnumbervalue.c
index 8d7eaa96ee..19a5f596ae 100644
--- a/gtk/gtkcssnumbervalue.c
+++ b/gtk/gtkcssnumbervalue.c
@@ -20,6 +20,7 @@
#include "gtkcssnumbervalueprivate.h"
#include "gtkcssenumvalueprivate.h"
+#include "gtkcssinitialvalueprivate.h"
#include "gtkstylepropertyprivate.h"
struct _GtkCssValue {
@@ -34,6 +35,26 @@ gtk_css_value_number_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
+static double
+get_base_font_size (guint property_id,
+ GtkStyleProviderPrivate *provider,
+ GtkCssComputedValues *values,
+ GtkCssComputedValues *parent_values,
+ GtkCssDependencies *dependencies)
+{
+ if (property_id == GTK_CSS_PROPERTY_FONT_SIZE)
+ {
+ *dependencies = GTK_CSS_DEPENDS_ON_PARENT;
+ if (parent_values)
+ return _gtk_css_number_value_get (_gtk_css_computed_values_get_value (parent_values, GTK_CSS_PROPERTY_FONT_SIZE), 100);
+ else
+ return _gtk_css_font_size_get_default (provider);
+ }
+
+ *dependencies = GTK_CSS_DEPENDS_ON_FONT_SIZE;
+ return _gtk_css_number_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_FONT_SIZE), 100);
+}
+
static GtkCssValue *
gtk_css_value_number_compute (GtkCssValue *number,
guint property_id,
@@ -48,6 +69,11 @@ gtk_css_value_number_compute (GtkCssValue *number,
g_assert_not_reached();
/* fall through */
case GTK_CSS_PERCENT:
+ /* percentages for font sizes are computed, other percentages aren't */
+ if (property_id == GTK_CSS_PROPERTY_FONT_SIZE)
+ return _gtk_css_number_value_new (number->value / 100.0 *
+ get_base_font_size (property_id, provider, values, parent_values, dependencies),
+ GTK_CSS_PX);
case GTK_CSS_NUMBER:
case GTK_CSS_PX:
case GTK_CSS_DEG:
@@ -73,16 +99,14 @@ gtk_css_value_number_compute (GtkCssValue *number,
GTK_CSS_PX);
break;
case GTK_CSS_EM:
- *dependencies = GTK_CSS_DEPENDS_ON_FONT_SIZE;
return _gtk_css_number_value_new (number->value *
- _gtk_css_number_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_FONT_SIZE), 100),
+ get_base_font_size (property_id, provider, values, parent_values, dependencies),
GTK_CSS_PX);
break;
case GTK_CSS_EX:
/* for now we pretend ex is half of em */
- *dependencies = GTK_CSS_DEPENDS_ON_FONT_SIZE;
return _gtk_css_number_value_new (number->value * 0.5 *
- _gtk_css_number_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_FONT_SIZE), 100),
+ get_base_font_size (property_id, provider, values, parent_values, dependencies),
GTK_CSS_PX);
case GTK_CSS_RAD:
return _gtk_css_number_value_new (number->value * 360.0 / (2 * G_PI),
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index bd22a7c1d7..3d8eb213c6 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -649,19 +649,16 @@ font_size_parse (GtkCssStyleProperty *property,
GtkCssParser *parser)
{
GtkCssValue *value;
- gdouble d;
value = _gtk_css_font_size_value_try_parse (parser);
if (value)
return value;
- if (!_gtk_css_parser_try_double (parser, &d))
- {
- _gtk_css_parser_error (parser, "Expected a number");
- return NULL;
- }
-
- return _gtk_css_number_value_new (d, GTK_CSS_PX);
+ return _gtk_css_number_value_parse (parser,
+ GTK_CSS_PARSE_LENGTH
+ | GTK_CSS_PARSE_PERCENT
+ | GTK_CSS_POSITIVE_ONLY
+ | GTK_CSS_NUMBER_AS_PIXELS);
}
static GtkCssValue *