Rename ShellThemeImage to ShellBorderImage

The current CSS3 border-image is close to a superset of what we were
doing for -hippo-background-image. Woot! rename ShellThemeImage to
ShellBorderImage and change parsing to look for:

 border-image: <url> <number>...

Rather than

 -shell-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.
This commit is contained in:
Owen W. Taylor 2009-09-20 16:50:42 -04:00
parent 4743a8e750
commit 2232a92ba8
10 changed files with 196 additions and 188 deletions

View File

@ -31,32 +31,32 @@ NbtkScrollView
NbtkButton#up-stepper
{
-shell-background-image: url("scroll-button-up.png") 5px;
border-image: url("scroll-button-up.png") 5;
}
NbtkButton#up-stepper:hover,
NbtkButton#up-stepper:active
{
-shell-background-image: url("scroll-button-up-hover.png") 5px;
border-image: url("scroll-button-up-hover.png") 5;
}
NbtkButton#down-stepper
{
-shell-background-image: url("scroll-button-down.png") 5px;
border-image: url("scroll-button-down.png") 5;
}
NbtkButton#down-stepper:hover,
NbtkButton#down-stepper:active
{
-shell-background-image: url("scroll-button-down-hover.png") 5px;
border-image: url("scroll-button-down-hover.png") 5;
}
NbtkScrollBar NbtkButton#vhandle
{
-shell-background-image: url("scroll-vhandle.png") 5px;
border-image: url("scroll-vhandle.png") 5;
}
NbtkScrollBar NbtkButton#vhandle:hover
{
-shell-background-image: url("scroll-vhandle.png") 5px;
border-image: url("scroll-vhandle.png") 5;
}

View File

@ -8,12 +8,12 @@ toolkit_cflags = \
# please, keep this sorted alphabetically
toolkit_sources = \
toolkit/shell-border-image.c \
toolkit/shell-border-image.h \
toolkit/shell-theme.c \
toolkit/shell-theme.h \
toolkit/shell-theme-context.c \
toolkit/shell-theme-context.h \
toolkit/shell-theme-image.c \
toolkit/shell-theme-image.h \
toolkit/shell-theme-node.c \
toolkit/shell-theme-node.h \
toolkit/shell-theme-private.h

View File

@ -479,7 +479,7 @@ nbtk_widget_real_style_changed (NbtkWidget *self)
{
NbtkWidgetPrivate *priv = NBTK_WIDGET (self)->priv;
ShellThemeNode *theme_node;
ShellThemeImage *theme_image;
ShellBorderImage *border_image;
NbtkTextureCache *texture_cache;
ClutterTexture *texture;
const char *bg_file = NULL;
@ -576,14 +576,14 @@ nbtk_widget_real_style_changed (NbtkWidget *self)
* and a single background image above it.
*/
theme_image = shell_theme_node_get_background_theme_image (theme_node);
if (theme_image)
border_image = shell_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 = shell_theme_image_get_filename (theme_image);
filename = shell_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 @@ nbtk_widget_real_style_changed (NbtkWidget *self)
clutter_texture_get_base_size (CLUTTER_TEXTURE (texture),
&width, &height);
shell_theme_image_get_borders (theme_image,
&border_left, &border_right, &border_top, &border_bottom);
shell_border_image_get_borders (border_image,
&border_left, &border_right, &border_top, &border_bottom);
priv->border_image = nbtk_texture_frame_new (texture,
border_top,

View File

@ -0,0 +1,92 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
#include <config.h>
#include "shell-border-image.h"
struct _ShellBorderImage {
GObject parent;
char *filename;
int border_top;
int border_right;
int border_bottom;
int border_left;
};
struct _ShellBorderImageClass {
GObjectClass parent_class;
};
G_DEFINE_TYPE (ShellBorderImage, shell_border_image, G_TYPE_OBJECT)
static void
shell_border_image_finalize (GObject *object)
{
ShellBorderImage *image = SHELL_BORDER_IMAGE (object);
g_free (image->filename);
G_OBJECT_CLASS (shell_border_image_parent_class)->finalize (object);
}
static void
shell_border_image_class_init (ShellBorderImageClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = shell_border_image_finalize;
}
static void
shell_border_image_init (ShellBorderImage *image)
{
}
ShellBorderImage *
shell_border_image_new (const char *filename,
int border_top,
int border_right,
int border_bottom,
int border_left)
{
ShellBorderImage *image;
image = g_object_new (SHELL_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 *
shell_border_image_get_filename (ShellBorderImage *image)
{
g_return_val_if_fail (SHELL_IS_BORDER_IMAGE (image), NULL);
return image->filename;
}
void
shell_border_image_get_borders (ShellBorderImage *image,
int *border_top,
int *border_right,
int *border_bottom,
int *border_left)
{
g_return_if_fail (SHELL_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;
}

View File

@ -0,0 +1,38 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
#ifndef __SHELL_BORDER_IMAGE_H__
#define __SHELL_BORDER_IMAGE_H__
#include <glib-object.h>
G_BEGIN_DECLS
/* A ShellBorderImage encapsulates an image with specified unscaled borders on each edge.
*/
typedef struct _ShellBorderImage ShellBorderImage;
typedef struct _ShellBorderImageClass ShellBorderImageClass;
#define SHELL_TYPE_BORDER_IMAGE (shell_border_image_get_type ())
#define SHELL_BORDER_IMAGE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), SHELL_TYPE_BORDER_IMAGE, ShellBorderImage))
#define SHELL_BORDER_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SHELL_TYPE_BORDER_IMAGE, ShellBorderImageClass))
#define SHELL_IS_BORDER_IMAGE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), SHELL_TYPE_BORDER_IMAGE))
#define SHELL_IS_BORDER_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SHELL_TYPE_BORDER_IMAGE))
#define SHELL_BORDER_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SHELL_TYPE_BORDER_IMAGE, ShellBorderImageClass))
GType shell_border_image_get_type (void) G_GNUC_CONST;
ShellBorderImage *shell_border_image_new (const char *filename,
int border_top,
int border_right,
int border_bottom,
int border_left);
const char *shell_border_image_get_filename (ShellBorderImage *image);
void shell_border_image_get_borders (ShellBorderImage *image,
int *border_top,
int *border_right,
int *border_bottom,
int *border_left);
G_END_DECLS
#endif /* __SHELL_BORDER_IMAGE_H__ */

View File

@ -1,92 +0,0 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
#include <config.h>
#include "shell-theme-image.h"
struct _ShellThemeImage {
GObject parent;
char *filename;
int border_top;
int border_right;
int border_bottom;
int border_left;
};
struct _ShellThemeImageClass {
GObjectClass parent_class;
};
G_DEFINE_TYPE (ShellThemeImage, shell_theme_image, G_TYPE_OBJECT)
static void
shell_theme_image_finalize (GObject *object)
{
ShellThemeImage *image = SHELL_THEME_IMAGE (object);
g_free (image->filename);
G_OBJECT_CLASS (shell_theme_image_parent_class)->finalize (object);
}
static void
shell_theme_image_class_init (ShellThemeImageClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = shell_theme_image_finalize;
}
static void
shell_theme_image_init (ShellThemeImage *image)
{
}
ShellThemeImage *
shell_theme_image_new (const char *filename,
int border_top,
int border_right,
int border_bottom,
int border_left)
{
ShellThemeImage *image;
image = g_object_new (SHELL_TYPE_THEME_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 *
shell_theme_image_get_filename (ShellThemeImage *image)
{
g_return_val_if_fail (SHELL_IS_THEME_IMAGE (image), NULL);
return image->filename;
}
void
shell_theme_image_get_borders (ShellThemeImage *image,
int *border_top,
int *border_right,
int *border_bottom,
int *border_left)
{
g_return_if_fail (SHELL_IS_THEME_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;
}

View File

@ -1,38 +0,0 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
#ifndef __SHELL_THEME_IMAGE_H__
#define __SHELL_THEME_IMAGE_H__
#include <glib-object.h>
G_BEGIN_DECLS
/* A ShellThemeImage encapsulates an image with specified unscaled borders on each edge.
*/
typedef struct _ShellThemeImage ShellThemeImage;
typedef struct _ShellThemeImageClass ShellThemeImageClass;
#define SHELL_TYPE_THEME_IMAGE (shell_theme_image_get_type ())
#define SHELL_THEME_IMAGE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), SHELL_TYPE_THEME_IMAGE, ShellThemeImage))
#define SHELL_THEME_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SHELL_TYPE_THEME_IMAGE, ShellThemeImageClass))
#define SHELL_IS_THEME_IMAGE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), SHELL_TYPE_THEME_IMAGE))
#define SHELL_IS_THEME_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SHELL_TYPE_THEME_IMAGE))
#define SHELL_THEME_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SHELL_TYPE_THEME_IMAGE, ShellThemeImageClass))
GType shell_theme_image_get_type (void) G_GNUC_CONST;
ShellThemeImage *shell_theme_image_new (const char *filename,
int border_top,
int border_right,
int border_bottom,
int border_left);
const char *shell_theme_image_get_filename (ShellThemeImage *image);
void shell_theme_image_get_borders (ShellThemeImage *image,
int *border_top,
int *border_right,
int *border_bottom,
int *border_left);
G_END_DECLS
#endif /* __SHELL_THEME_IMAGE_H__ */

View File

@ -39,7 +39,7 @@ struct _ShellThemeNode {
guint padding[4];
char *background_image;
ShellThemeImage *background_theme_image;
ShellBorderImage *border_image;
GType element_type;
char *element_id;
@ -58,7 +58,7 @@ struct _ShellThemeNode {
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 @@ shell_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 @@ shell_theme_node_get_font (ShellThemeNode *node)
}
/**
* shell_theme_node_get_background_theme_image:
* shell_theme_node_get_border_image:
* @node: a #ShellThemeNode
*
* Gets the value for the -shell-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.
*/
ShellThemeImage *
shell_theme_node_get_background_theme_image (ShellThemeNode *node)
ShellBorderImage *
shell_theme_node_get_border_image (ShellThemeNode *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 @@ shell_theme_node_get_background_theme_image (ShellThemeNode *node)
{
CRDeclaration *decl = node->properties[i];
if (strcmp (decl->property->stryng->str, "-shell-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 @@ shell_theme_node_get_background_theme_image (ShellThemeNode *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 ShellBorderImage */
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 @@ shell_theme_node_get_background_theme_image (ShellThemeNode *node)
if (filename == NULL)
goto next_property;
node->background_theme_image = shell_theme_image_new (filename,
border_top, border_right, border_bottom, border_left);
node->border_image = shell_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:

View File

@ -3,7 +3,7 @@
#define __SHELL_THEME_NODE_H__
#include <clutter/clutter.h>
#include "shell-theme-image.h"
#include "shell-border-image.h"
G_BEGIN_DECLS
@ -116,10 +116,7 @@ ShellTextDecoration shell_theme_node_get_text_decoration (ShellThemeNode *node);
*/
const PangoFontDescription *shell_theme_node_get_font (ShellThemeNode *node);
/* This is the getter for -shell-background-image, which is different from
* background-image in having provisions for unscaled borders.
*/
ShellThemeImage *shell_theme_node_get_background_theme_image (ShellThemeNode *node);
ShellBorderImage *shell_theme_node_get_border_image (ShellThemeNode *node);
/* Helpers for get_preferred_width()/get_preferred_height() ClutterActor vfuncs */
void shell_theme_node_adjust_for_height (ShellThemeNode *node,

View File

@ -34,7 +34,7 @@ stage {
.border-image {
border: 15px;
-shell-background-image: url('border-image.png') 16px;
border-image: url('border-image.png') 16;
}
NbtkButton {