[gnome-shell/shell-toolkit: 23/32] Rename StThemeImage to StBorderImage
- From: Owen Taylor <otaylor src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-shell/shell-toolkit: 23/32] Rename StThemeImage to StBorderImage
- Date: Wed, 30 Sep 2009 00:03:01 +0000 (UTC)
commit d92b1d8da2d4a5987c3be53940c7b9724f10a95d
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Sun Sep 20 16:50:42 2009 -0400
Rename StThemeImage to StBorderImage
The current CSS3 border-image is close to a superset of what we were
doing for -hippo-background-image. Woot! rename StThemeImage to
StBorderImage and change parsing to look for:
border-image: <url> <number>...
Rather than
-st-background-image: <url> <length>...
percentanges for the border sizes are not currently supported, neither
are the keywords for handling of the middle part. We always do 'stretch'
for now.
https://bugzilla.gnome.org/show_bug.cgi?id=595990
data/theme/gnome-shell.css | 12 +++---
src/Makefile-st.am | 4 +-
src/st/st-border-image.c | 92 ++++++++++++++++++++++++++++++++++++++++++++
src/st/st-border-image.h | 38 ++++++++++++++++++
src/st/st-theme-image.c | 92 --------------------------------------------
src/st/st-theme-image.h | 38 ------------------
src/st/st-theme-node.c | 87 +++++++++++++++++++++++------------------
src/st/st-theme-node.h | 7 +--
src/st/st-widget.c | 12 +++---
tests/testcommon/test.css | 2 +-
10 files changed, 196 insertions(+), 188 deletions(-)
---
diff --git a/data/theme/gnome-shell.css b/data/theme/gnome-shell.css
index c8d6989..f7b8c13 100644
--- a/data/theme/gnome-shell.css
+++ b/data/theme/gnome-shell.css
@@ -31,32 +31,32 @@ StScrollView
StButton#up-stepper
{
- -st-background-image: url("scroll-button-up.png") 5px;
+ border-image: url("scroll-button-up.png") 5;
}
StButton#up-stepper:hover,
StButton#up-stepper:active
{
- -st-background-image: url("scroll-button-up-hover.png") 5px;
+ border-image: url("scroll-button-up-hover.png") 5;
}
StButton#down-stepper
{
- -st-background-image: url("scroll-button-down.png") 5px;
+ border-image: url("scroll-button-down.png") 5;
}
StButton#down-stepper:hover,
StButton#down-stepper:active
{
- -st-background-image: url("scroll-button-down-hover.png") 5px;
+ border-image: url("scroll-button-down-hover.png") 5;
}
StScrollBar StButton#vhandle
{
- -st-background-image: url("scroll-vhandle.png") 5px;
+ border-image: url("scroll-vhandle.png") 5;
}
StScrollBar StButton#vhandle:hover
{
- -st-background-image: url("scroll-vhandle.png") 5px;
+ border-image: url("scroll-vhandle.png") 5;
}
diff --git a/src/Makefile-st.am b/src/Makefile-st.am
index d8070ce..d5e5dc4 100644
--- a/src/Makefile-st.am
+++ b/src/Makefile-st.am
@@ -67,6 +67,7 @@ st-enum-types.c: stamp-st-enum-types.h st/st-enum-types.c.in
st_source_h = \
st/st-adjustment.h \
st/st-bin.h \
+ st/st-border-image.h \
st/st-box-layout.h \
st/st-box-layout-child.h \
st/st-button.h \
@@ -81,7 +82,6 @@ st_source_h = \
st/st-texture-frame.h \
st/st-theme.h \
st/st-theme-context.h \
- st/st-theme-image.h \
st/st-theme-node.h \
st/st-tooltip.h \
st/st-types.h \
@@ -96,6 +96,7 @@ st_source_private_h = \
st_source_c = \
st/st-adjustment.c \
st/st-bin.c \
+ st/st-border-image.c \
st/st-box-layout.c \
st/st-box-layout-child.c \
st/st-button.c \
@@ -111,7 +112,6 @@ st_source_c = \
st/st-texture-frame.c \
st/st-theme.c \
st/st-theme-context.c \
- st/st-theme-image.c \
st/st-theme-node.c \
st/st-tooltip.c \
st/st-widget.c \
diff --git a/src/st/st-border-image.c b/src/st/st-border-image.c
new file mode 100644
index 0000000..373b4ab
--- /dev/null
+++ b/src/st/st-border-image.c
@@ -0,0 +1,92 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+#include <config.h>
+
+#include "st-border-image.h"
+
+struct _StBorderImage {
+ GObject parent;
+
+ char *filename;
+ int border_top;
+ int border_right;
+ int border_bottom;
+ int border_left;
+};
+
+struct _StBorderImageClass {
+ GObjectClass parent_class;
+
+};
+
+G_DEFINE_TYPE (StBorderImage, st_border_image, G_TYPE_OBJECT)
+
+static void
+st_border_image_finalize (GObject *object)
+{
+ StBorderImage *image = ST_BORDER_IMAGE (object);
+
+ g_free (image->filename);
+
+ G_OBJECT_CLASS (st_border_image_parent_class)->finalize (object);
+}
+
+static void
+st_border_image_class_init (StBorderImageClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = st_border_image_finalize;
+}
+
+static void
+st_border_image_init (StBorderImage *image)
+{
+}
+
+StBorderImage *
+st_border_image_new (const char *filename,
+ int border_top,
+ int border_right,
+ int border_bottom,
+ int border_left)
+{
+ StBorderImage *image;
+
+ image = g_object_new (ST_TYPE_BORDER_IMAGE, NULL);
+
+ image->filename = g_strdup (filename);
+ image->border_top = border_top;
+ image->border_right = border_right;
+ image->border_bottom = border_bottom;
+ image->border_left = border_left;
+
+ return image;
+}
+
+const char *
+st_border_image_get_filename (StBorderImage *image)
+{
+ g_return_val_if_fail (ST_IS_BORDER_IMAGE (image), NULL);
+
+ return image->filename;
+}
+
+void
+st_border_image_get_borders (StBorderImage *image,
+ int *border_top,
+ int *border_right,
+ int *border_bottom,
+ int *border_left)
+{
+ g_return_if_fail (ST_IS_BORDER_IMAGE (image));
+
+ if (border_top)
+ *border_top = image->border_top;
+ if (border_right)
+ *border_right = image->border_right;
+ if (border_bottom)
+ *border_bottom = image->border_bottom;
+ if (border_left)
+ *border_left = image->border_left;
+}
diff --git a/src/st/st-border-image.h b/src/st/st-border-image.h
new file mode 100644
index 0000000..3f96473
--- /dev/null
+++ b/src/st/st-border-image.h
@@ -0,0 +1,38 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+#ifndef __ST_BORDER_IMAGE_H__
+#define __ST_BORDER_IMAGE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* A StBorderImage encapsulates an image with specified unscaled borders on each edge.
+ */
+typedef struct _StBorderImage StBorderImage;
+typedef struct _StBorderImageClass StBorderImageClass;
+
+#define ST_TYPE_BORDER_IMAGE (st_border_image_get_type ())
+#define ST_BORDER_IMAGE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), ST_TYPE_BORDER_IMAGE, StBorderImage))
+#define ST_BORDER_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ST_TYPE_BORDER_IMAGE, StBorderImageClass))
+#define ST_IS_BORDER_IMAGE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), ST_TYPE_BORDER_IMAGE))
+#define ST_IS_BORDER_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ST_TYPE_BORDER_IMAGE))
+#define ST_BORDER_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ST_TYPE_BORDER_IMAGE, StBorderImageClass))
+
+GType st_border_image_get_type (void) G_GNUC_CONST;
+
+StBorderImage *st_border_image_new (const char *filename,
+ int border_top,
+ int border_right,
+ int border_bottom,
+ int border_left);
+
+const char *st_border_image_get_filename (StBorderImage *image);
+void st_border_image_get_borders (StBorderImage *image,
+ int *border_top,
+ int *border_right,
+ int *border_bottom,
+ int *border_left);
+
+G_END_DECLS
+
+#endif /* __ST_BORDER_IMAGE_H__ */
diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c
index 0b633f9..1428453 100644
--- a/src/st/st-theme-node.c
+++ b/src/st/st-theme-node.c
@@ -39,7 +39,7 @@ struct _StThemeNode {
guint padding[4];
char *background_image;
- StThemeImage *background_theme_image;
+ StBorderImage *border_image;
GType element_type;
char *element_id;
@@ -58,7 +58,7 @@ struct _StThemeNode {
guint borders_computed : 1;
guint background_computed : 1;
guint foreground_computed : 1;
- guint background_theme_image_computed : 1;
+ guint border_image_computed : 1;
guint link_type : 2;
};
@@ -121,10 +121,10 @@ st_theme_node_finalize (GObject *object)
node->font_desc = NULL;
}
- if (node->background_theme_image)
+ if (node->border_image)
{
- g_object_unref (node->background_theme_image);
- node->background_theme_image = NULL;
+ g_object_unref (node->border_image);
+ node->border_image = NULL;
}
if (node->background_image)
@@ -1811,24 +1811,24 @@ st_theme_node_get_font (StThemeNode *node)
}
/**
- * st_theme_node_get_background_theme_image:
+ * st_theme_node_get_border_image:
* @node: a #StThemeNode
*
- * Gets the value for the -st-background-image style property
+ * Gets the value for the border-image style property
*
- * Return value: (transfer none): the background image, or %NULL
- * if there is no background theme image.
+ * Return value: (transfer none): the border image, or %NULL
+ * if there is no border image.
*/
-StThemeImage *
-st_theme_node_get_background_theme_image (StThemeNode *node)
+StBorderImage *
+st_theme_node_get_border_image (StThemeNode *node)
{
int i;
- if (node->background_theme_image_computed)
- return node->background_theme_image;
+ if (node->border_image_computed)
+ return node->border_image;
- node->background_theme_image = NULL;
- node->background_theme_image_computed = TRUE;
+ node->border_image = NULL;
+ node->border_image_computed = TRUE;
ensure_properties (node);
@@ -1836,11 +1836,11 @@ st_theme_node_get_background_theme_image (StThemeNode *node)
{
CRDeclaration *decl = node->properties[i];
- if (strcmp (decl->property->stryng->str, "-st-background-image") == 0)
+ if (strcmp (decl->property->stryng->str, "border-image") == 0)
{
CRTerm *term = decl->value;
- int lengths[4];
- int n_lengths = 0;
+ int borders[4];
+ int n_borders = 0;
int i;
const char *url;
@@ -1859,46 +1859,57 @@ st_theme_node_get_background_theme_image (StThemeNode *node)
term = term->next;
- /* Followed by 0 to 4 lengths */
+ /* Followed by 0 to 4 numbers or percentages. *Not lengths*. The interpretation
+ * of a number is supposed to be pixels if the image is pixel based, otherwise CSS pixels.
+ */
for (i = 0; i < 4; i++)
{
- double value;
-
if (term == NULL)
break;
- if (get_length_from_term (node, term, FALSE, &value) != VALUE_FOUND)
+ if (term->type != TERM_NUMBER)
goto next_property;
- lengths[n_lengths] = (int)(0.5 + value);
- n_lengths++;
+ if (term->content.num->type == NUM_GENERIC)
+ {
+ borders[n_borders] = round (0.5 + term->content.num->val);
+ n_borders++;
+ }
+ else if (term->content.num->type == NUM_PERCENTAGE)
+ {
+ /* This would be easiest to support if we moved image handling into StBorderImage */
+ g_warning ("Percentages not supported for border-image");
+ goto next_property;
+ }
+ else
+ goto next_property;
term = term->next;
}
- switch (n_lengths)
+ switch (n_borders)
{
case 0:
border_top = border_right = border_bottom = border_left = 0;
break;
case 1:
- border_top = border_right = border_bottom = border_left = lengths[0];
+ border_top = border_right = border_bottom = border_left = borders[0];
break;
case 2:
- border_top = border_bottom = lengths[0];
- border_left = border_right = lengths[1];
+ border_top = border_bottom = borders[0];
+ border_left = border_right = borders[1];
break;
case 3:
- border_top = lengths[0];
- border_left = border_right = lengths[1];
- border_bottom = lengths[2];
+ border_top = borders[0];
+ border_left = border_right = borders[1];
+ border_bottom = borders[2];
break;
case 4:
default:
- border_top = lengths[0];
- border_right = lengths[1];
- border_bottom = lengths[2];
- border_left = lengths[3];
+ border_top = borders[0];
+ border_right = borders[1];
+ border_bottom = borders[2];
+ border_left = borders[3];
break;
}
@@ -1906,12 +1917,12 @@ st_theme_node_get_background_theme_image (StThemeNode *node)
if (filename == NULL)
goto next_property;
- node->background_theme_image = st_theme_image_new (filename,
- border_top, border_right, border_bottom, border_left);
+ node->border_image = st_border_image_new (filename,
+ border_top, border_right, border_bottom, border_left);
g_free (filename);
- return node->background_theme_image;
+ return node->border_image;
}
next_property:
diff --git a/src/st/st-theme-node.h b/src/st/st-theme-node.h
index fc5f8bf..2e7f536 100644
--- a/src/st/st-theme-node.h
+++ b/src/st/st-theme-node.h
@@ -3,7 +3,7 @@
#define __ST_THEME_NODE_H__
#include <clutter/clutter.h>
-#include "st-theme-image.h"
+#include "st-border-image.h"
G_BEGIN_DECLS
@@ -116,10 +116,7 @@ StTextDecoration st_theme_node_get_text_decoration (StThemeNode *node);
*/
const PangoFontDescription *st_theme_node_get_font (StThemeNode *node);
-/* This is the getter for -st-background-image, which is different from
- * background-image in having provisions for unscaled borders.
- */
-StThemeImage *st_theme_node_get_background_theme_image (StThemeNode *node);
+StBorderImage *st_theme_node_get_border_image (StThemeNode *node);
/* Helpers for get_preferred_width()/get_preferred_height() ClutterActor vfuncs */
void st_theme_node_adjust_for_height (StThemeNode *node,
diff --git a/src/st/st-widget.c b/src/st/st-widget.c
index bc2e0c9..6605ce7 100644
--- a/src/st/st-widget.c
+++ b/src/st/st-widget.c
@@ -480,7 +480,7 @@ st_widget_real_style_changed (StWidget *self)
{
StWidgetPrivate *priv = ST_WIDGET (self)->priv;
StThemeNode *theme_node;
- StThemeImage *theme_image;
+ StBorderImage *border_image;
StTextureCache *texture_cache;
ClutterTexture *texture;
const char *bg_file = NULL;
@@ -577,14 +577,14 @@ st_widget_real_style_changed (StWidget *self)
* and a single background image above it.
*/
- theme_image = st_theme_node_get_background_theme_image (theme_node);
- if (theme_image)
+ border_image = st_theme_node_get_border_image (theme_node);
+ if (border_image)
{
const char *filename;
gint border_left, border_right, border_top, border_bottom;
gint width, height;
- filename = st_theme_image_get_filename (theme_image);
+ filename = st_border_image_get_filename (border_image);
/* `border-image' takes precedence over `background-image'.
* Firefox lets the background-image shine thru when border-image has
@@ -595,8 +595,8 @@ st_widget_real_style_changed (StWidget *self)
clutter_texture_get_base_size (CLUTTER_TEXTURE (texture),
&width, &height);
- st_theme_image_get_borders (theme_image,
- &border_left, &border_right, &border_top, &border_bottom);
+ st_border_image_get_borders (border_image,
+ &border_left, &border_right, &border_top, &border_bottom);
priv->border_image = st_texture_frame_new (texture,
border_top,
diff --git a/tests/testcommon/test.css b/tests/testcommon/test.css
index e0e7b05..36e1b21 100644
--- a/tests/testcommon/test.css
+++ b/tests/testcommon/test.css
@@ -34,7 +34,7 @@ stage {
.border-image {
border: 15px;
- -st-background-image: url('border-image.png') 16px;
+ border-image: url('border-image.png') 16;
}
StButton {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]