StThemeNode: simplify use of get_color/get_double/get_length

Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.

So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)

And update the code to use either the old or new methods as appropriate.

https://bugzilla.gnome.org/show_bug.cgi?id=632590
This commit is contained in:
Dan Winship 2010-09-26 17:38:36 -04:00
parent 85d3336245
commit 8886b7433c
16 changed files with 185 additions and 118 deletions

View File

@ -102,9 +102,7 @@ AltTabPopup.prototype = {
childBox.x1 = Math.max(primary.x + leftPadding, childBox.x1 - offset - hPadding); childBox.x1 = Math.max(primary.x + leftPadding, childBox.x1 - offset - hPadding);
} }
let [found, spacing] = this.actor.get_theme_node().get_length('spacing', false); let spacing = this.actor.get_theme_node().get_length('spacing');
if (!found)
spacing = 0;
childBox.x2 = childBox.x1 + childNaturalWidth; childBox.x2 = childBox.x1 + childNaturalWidth;
if (childBox.x2 > primary.x + primary.width - rightPadding) if (childBox.x2 > primary.x + primary.width - rightPadding)
@ -501,8 +499,7 @@ SwitcherList.prototype = {
this._list = new Shell.GenericContainer({ style_class: 'switcher-list-item-container' }); this._list = new Shell.GenericContainer({ style_class: 'switcher-list-item-container' });
this._list.spacing = 0; this._list.spacing = 0;
this._list.connect('style-changed', Lang.bind(this, function() { this._list.connect('style-changed', Lang.bind(this, function() {
let [found, spacing] = this._list.get_theme_node().get_length('spacing', false); this._list.spacing = this._list.get_theme_node().get_length('spacing');
this._list.spacing = (found) ? spacing : 0;
})); }));
this._list.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth)); this._list.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
@ -1035,9 +1032,7 @@ ThumbnailList.prototype = {
let totalPadding = this._items[0].get_theme_node().get_horizontal_padding() + this._items[0].get_theme_node().get_vertical_padding(); let totalPadding = this._items[0].get_theme_node().get_horizontal_padding() + this._items[0].get_theme_node().get_vertical_padding();
totalPadding += this.actor.get_theme_node().get_horizontal_padding() + this.actor.get_theme_node().get_vertical_padding(); totalPadding += this.actor.get_theme_node().get_horizontal_padding() + this.actor.get_theme_node().get_vertical_padding();
let [labelMinHeight, labelNaturalHeight] = this._labels[0].get_preferred_height(-1); let [labelMinHeight, labelNaturalHeight] = this._labels[0].get_preferred_height(-1);
let [found, spacing] = this._items[0].child.get_theme_node().get_length('spacing', false); let spacing = this._items[0].child.get_theme_node().get_length('spacing');
if (!found)
spacing = 0;
availHeight = Math.min(availHeight - labelNaturalHeight - totalPadding - spacing, THUMBNAIL_DEFAULT_SIZE); availHeight = Math.min(availHeight - labelNaturalHeight - totalPadding - spacing, THUMBNAIL_DEFAULT_SIZE);
let binHeight = availHeight + this._items[0].get_theme_node().get_vertical_padding() + this.actor.get_theme_node().get_vertical_padding() - spacing; let binHeight = availHeight + this._items[0].get_theme_node().get_vertical_padding() + this.actor.get_theme_node().get_vertical_padding() - spacing;

View File

@ -46,9 +46,7 @@ BoxPointer.prototype = {
let x = this.actor.x; let x = this.actor.x;
let y = this.actor.y; let y = this.actor.y;
let themeNode = this.actor.get_theme_node(); let themeNode = this.actor.get_theme_node();
let [found, rise] = themeNode.get_length('-arrow-rise', false); let rise = themeNode.get_length('-arrow-rise');
if (!found)
rise = 0;
this.actor.opacity = 0; this.actor.opacity = 0;
this.actor.show(); this.actor.show();
@ -82,9 +80,7 @@ BoxPointer.prototype = {
let originalX = this.actor.x; let originalX = this.actor.x;
let originalY = this.actor.y; let originalY = this.actor.y;
let themeNode = this.actor.get_theme_node(); let themeNode = this.actor.get_theme_node();
let [found, rise] = themeNode.get_length('-arrow-rise', false); let rise = themeNode.get_length('-arrow-rise');
if (!found)
rise = 0;
switch (this._arrowSide) { switch (this._arrowSide) {
case St.Side.TOP: case St.Side.TOP:
@ -118,13 +114,12 @@ BoxPointer.prototype = {
_adjustAllocationForArrow: function(isWidth, alloc) { _adjustAllocationForArrow: function(isWidth, alloc) {
let themeNode = this.actor.get_theme_node(); let themeNode = this.actor.get_theme_node();
let found, borderWidth, base, rise; let borderWidth = themeNode.get_length('-arrow-border-width');
[found, borderWidth] = themeNode.get_length('-arrow-border-width', false);
alloc.min_size += borderWidth * 2; alloc.min_size += borderWidth * 2;
alloc.natural_size += borderWidth * 2; alloc.natural_size += borderWidth * 2;
if ((!isWidth && (this._arrowSide == St.Side.TOP || this._arrowSide == St.Side.BOTTOM)) if ((!isWidth && (this._arrowSide == St.Side.TOP || this._arrowSide == St.Side.BOTTOM))
|| (isWidth && (this._arrowSide == St.Side.LEFT || this._arrowSide == St.Side.RIGHT))) { || (isWidth && (this._arrowSide == St.Side.LEFT || this._arrowSide == St.Side.RIGHT))) {
let [found, rise] = themeNode.get_length('-arrow-rise', false); let rise = themeNode.get_length('-arrow-rise');
alloc.min_size += rise; alloc.min_size += rise;
alloc.natural_size += rise; alloc.natural_size += rise;
} }
@ -146,9 +141,8 @@ BoxPointer.prototype = {
_allocate: function(actor, box, flags) { _allocate: function(actor, box, flags) {
let themeNode = this.actor.get_theme_node(); let themeNode = this.actor.get_theme_node();
let found, borderWidth, borderRadius, rise, base; let borderWidth = themeNode.get_length('-arrow-border-width');
[found, borderWidth] = themeNode.get_length('-arrow-border-width', false); let rise = themeNode.get_length('-arrow-rise');
[found, rise] = themeNode.get_length('-arrow-rise', false);
let childBox = new Clutter.ActorBox(); let childBox = new Clutter.ActorBox();
let availWidth = box.x2 - box.x1; let availWidth = box.x2 - box.x1;
let availHeight = box.y2 - box.y1; let availHeight = box.y2 - box.y1;
@ -183,19 +177,18 @@ BoxPointer.prototype = {
_drawBorder: function(area) { _drawBorder: function(area) {
let themeNode = this.actor.get_theme_node(); let themeNode = this.actor.get_theme_node();
let found, borderWidth, borderRadius, rise, base; let borderWidth = themeNode.get_length('-arrow-border-width');
[found, borderWidth] = themeNode.get_length('-arrow-border-width', false); let base = themeNode.get_length('-arrow-base');
[found, base] = themeNode.get_length('-arrow-base', false); let rise = themeNode.get_length('-arrow-rise');
[found, rise] = themeNode.get_length('-arrow-rise', false); let borderRadius = themeNode.get_length('-arrow-border-radius');
[found, borderRadius] = themeNode.get_length('-arrow-border-radius', false);
let halfBorder = borderWidth / 2; let halfBorder = borderWidth / 2;
let halfBase = Math.floor(base/2); let halfBase = Math.floor(base/2);
let borderColor = new Clutter.Color(); let borderColor = new Clutter.Color();
themeNode.get_color('-arrow-border-color', false, borderColor); themeNode.get_color('-arrow-border-color', borderColor);
let backgroundColor = new Clutter.Color(); let backgroundColor = new Clutter.Color();
themeNode.get_color('-arrow-background-color', false, backgroundColor); themeNode.get_color('-arrow-background-color', backgroundColor);
let [width, height] = area.get_surface_size(); let [width, height] = area.get_surface_size();
let [boxWidth, boxHeight] = [width, height]; let [boxWidth, boxHeight] = [width, height];

View File

@ -113,18 +113,14 @@ BaseIcon.prototype = {
}, },
_onStyleChanged: function() { _onStyleChanged: function() {
let success, len;
let node = this.actor.get_theme_node(); let node = this.actor.get_theme_node();
this._spacing = node.get_length('spacing');
[success, len] = node.get_length('spacing', false);
if (success)
this._spacing = spacing;
if (this._setSizeManually) if (this._setSizeManually)
return; return;
[success, len] = node.get_length('icon-size', false); let len = node.get_length('icon-size');
if (success) if (len > 0)
this._setIconSize(len); this._setIconSize(len);
} }
}; };
@ -269,12 +265,8 @@ IconGrid.prototype = {
_onStyleChanged: function() { _onStyleChanged: function() {
let themeNode = this.actor.get_theme_node(); let themeNode = this.actor.get_theme_node();
let [success, len] = themeNode.get_length('spacing', false); this._spacing = themeNode.get_length('spacing');
if (success) this._item_size = themeNode.get_length('-shell-grid-item-size');
this._spacing = len;
[success, len] = themeNode.get_length('-shell-grid-item-size', false);
if (success)
this._item_size = len;
this._grid.queue_relayout(); this._grid.queue_relayout();
}, },

View File

@ -360,8 +360,7 @@ Notification.prototype = {
}, },
_styleChanged: function() { _styleChanged: function() {
let [hasSpacing, spacing] = this.actor.get_theme_node().get_length('spacing-columns', false); this._spacing = this.actor.get_theme_node().get_length('spacing-columns');
this._spacing = hasSpacing ? spacing : 0;
}, },
_bannerBoxGetPreferredWidth: function(actor, forHeight, alloc) { _bannerBoxGetPreferredWidth: function(actor, forHeight, alloc) {

View File

@ -143,13 +143,12 @@ PopupSeparatorMenuItem.prototype = {
let cr = area.get_context(); let cr = area.get_context();
let themeNode = area.get_theme_node(); let themeNode = area.get_theme_node();
let [width, height] = area.get_surface_size(); let [width, height] = area.get_surface_size();
let found, margin, gradientHeight; let margin = themeNode.get_length('-margin-horizontal');
[found, margin] = themeNode.get_length('-margin-horizontal', false); let gradientHeight = themeNode.get_length('-gradient-height');
[found, gradientHeight] = themeNode.get_length('-gradient-height', false);
let startColor = new Clutter.Color(); let startColor = new Clutter.Color();
themeNode.get_color('-gradient-start', false, startColor); themeNode.get_color('-gradient-start', startColor);
let endColor = new Clutter.Color(); let endColor = new Clutter.Color();
themeNode.get_color('-gradient-end', false, endColor); themeNode.get_color('-gradient-end', endColor);
let gradientWidth = (width - margin * 2); let gradientWidth = (width - margin * 2);
let gradientOffset = (height - gradientHeight) / 2; let gradientOffset = (height - gradientHeight) / 2;
@ -200,20 +199,17 @@ PopupSliderMenuItem.prototype = {
let themeNode = area.get_theme_node(); let themeNode = area.get_theme_node();
let [width, height] = area.get_surface_size(); let [width, height] = area.get_surface_size();
let found, handleRadius; let handleRadius = themeNode.get_length('-slider-handle-radius');
[found, handleRadius] = themeNode.get_length('-slider-handle-radius', false);
let sliderWidth = width - 2 * handleRadius; let sliderWidth = width - 2 * handleRadius;
let sliderHeight; let sliderHeight = themeNode.get_length('-slider-height');
[found, sliderHeight] = themeNode.get_length('-slider-height', false);
let sliderBorderWidth; let sliderBorderWidth = themeNode.get_length('-slider-border-width');
[found, sliderBorderWidth] = themeNode.get_length('-slider-border-width', false);
let sliderBorderColor = new Clutter.Color(); let sliderBorderColor = new Clutter.Color();
themeNode.get_color('-slider-border-color', false, sliderBorderColor); themeNode.get_color('-slider-border-color', sliderBorderColor);
let sliderColor = new Clutter.Color(); let sliderColor = new Clutter.Color();
themeNode.get_color('-slider-background-color', false, sliderColor); themeNode.get_color('-slider-background-color', sliderColor);
cr.setSourceRGBA ( cr.setSourceRGBA (
sliderColor.red / 255, sliderColor.red / 255,
@ -288,8 +284,7 @@ PopupSliderMenuItem.prototype = {
relY = absY - sliderY; relY = absY - sliderY;
let width = this._slider.width; let width = this._slider.width;
let found, handleRadius; let handleRadius = this._slider.get_theme_node().get_length('-slider-handle-radius');
[found, handleRadius] = this._slider.get_theme_node().get_length('-slider-handle-radius', false);
let newvalue; let newvalue;
if (relX < handleRadius) if (relX < handleRadius)

View File

@ -553,18 +553,10 @@ WindowOverlay.prototype = {
_onStyleChanged: function() { _onStyleChanged: function() {
let titleNode = this.title.get_theme_node(); let titleNode = this.title.get_theme_node();
this.title._spacing = titleNode.get_length('-shell-caption-spacing');
let [success, len] = titleNode.get_length('-shell-caption-spacing',
false);
if (success)
this.title._spacing = len;
let closeNode = this.closeButton.get_theme_node(); let closeNode = this.closeButton.get_theme_node();
this.closeButton._overlap = closeNode.get_length('-shell-close-overlap');
[success, len] = closeNode.get_length('-shell-close-overlap',
false);
if (success)
this.closeButton._overlap = len;
this._parentActor.queue_relayout(); this._parentActor.queue_relayout();
} }

View File

@ -33,8 +33,7 @@ WorkspaceSwitcherPopup.prototype = {
this._list = new Shell.GenericContainer({ style_class: 'workspace-switcher' }); this._list = new Shell.GenericContainer({ style_class: 'workspace-switcher' });
this._itemSpacing = 0; this._itemSpacing = 0;
this._list.connect('style-changed', Lang.bind(this, function() { this._list.connect('style-changed', Lang.bind(this, function() {
let [found, spacing] = this._list.get_theme_node().get_length('spacing', false); this._itemSpacing = this._list.get_theme_node().get_length('spacing');
this._itemSpacing = (found) ? spacing : 0;
})); }));
this._list.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth)); this._list.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));

View File

@ -43,8 +43,7 @@ GenericWorkspacesView.prototype = {
this.actor.connect('style-changed', Lang.bind(this, this.actor.connect('style-changed', Lang.bind(this,
function() { function() {
let node = this.actor.get_theme_node(); let node = this.actor.get_theme_node();
let [a, spacing] = node.get_length('spacing', false); this._spacing = node.get_length('spacing');
this._spacing = spacing;
if (Main.overview.animationInProgress) if (Main.overview.animationInProgress)
this._computeWorkspacePositions(); this._computeWorkspacePositions();
else else
@ -609,7 +608,7 @@ WorkspaceIndicator.prototype = {
this._indicatorsPanel.add_actor(actor); this._indicatorsPanel.add_actor(actor);
let [a, spacing] = actor.get_theme_node().get_length('border-spacing', false); let spacing = actor.get_theme_node().get_length('border-spacing');
actor.x = spacing * i + actor.width * i; actor.x = spacing * i + actor.width * i;
}, },

View File

@ -1018,9 +1018,9 @@ st_box_layout_style_changed (StWidget *self)
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (self)->priv; StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (self)->priv;
StThemeNode *theme_node = st_widget_get_theme_node (self); StThemeNode *theme_node = st_widget_get_theme_node (self);
int old_spacing = priv->spacing; int old_spacing = priv->spacing;
double spacing = 0; double spacing;
st_theme_node_get_length (theme_node, "spacing", FALSE, &spacing); spacing = st_theme_node_get_length (theme_node, "spacing");
priv->spacing = (int)(spacing + 0.5); priv->spacing = (int)(spacing + 0.5);
if (priv->spacing != old_spacing) if (priv->spacing != old_spacing)
clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); clutter_actor_queue_relayout (CLUTTER_ACTOR (self));

View File

@ -109,7 +109,7 @@ st_button_style_changed (StWidget *widget)
ST_WIDGET_CLASS (st_button_parent_class)->style_changed (widget); ST_WIDGET_CLASS (st_button_parent_class)->style_changed (widget);
spacing = 6; spacing = 6;
st_theme_node_get_length (theme_node, "border-spacing", FALSE, &spacing); st_theme_node_lookup_length (theme_node, "border-spacing", FALSE, &spacing);
priv->spacing = (int)(0.5 + spacing); priv->spacing = (int)(0.5 + spacing);
/* update the label styling */ /* update the label styling */

View File

@ -202,13 +202,13 @@ st_entry_style_changed (StWidget *self)
st_theme_node_get_foreground_color (theme_node, &color); st_theme_node_get_foreground_color (theme_node, &color);
clutter_text_set_color (CLUTTER_TEXT (priv->entry), &color); clutter_text_set_color (CLUTTER_TEXT (priv->entry), &color);
if (st_theme_node_get_length (theme_node, "caret-size", FALSE, &size)) if (st_theme_node_lookup_length (theme_node, "caret-size", FALSE, &size))
clutter_text_set_cursor_size (CLUTTER_TEXT (priv->entry), (int)(.5 + size)); clutter_text_set_cursor_size (CLUTTER_TEXT (priv->entry), (int)(.5 + size));
if (st_theme_node_get_color (theme_node, "caret-color", FALSE, &color)) if (st_theme_node_lookup_color (theme_node, "caret-color", FALSE, &color))
clutter_text_set_cursor_color (CLUTTER_TEXT (priv->entry), &color); clutter_text_set_cursor_color (CLUTTER_TEXT (priv->entry), &color);
if (st_theme_node_get_color (theme_node, "selection-background-color", FALSE, &color)) if (st_theme_node_lookup_color (theme_node, "selection-background-color", FALSE, &color))
clutter_text_set_selection_color (CLUTTER_TEXT (priv->entry), &color); clutter_text_set_selection_color (CLUTTER_TEXT (priv->entry), &color);
font = st_theme_node_get_font (theme_node); font = st_theme_node_get_font (theme_node);

View File

@ -369,9 +369,9 @@ st_overflow_box_style_changed (StWidget *self)
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (self)->priv; StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (self)->priv;
StThemeNode *theme_node = st_widget_get_theme_node (self); StThemeNode *theme_node = st_widget_get_theme_node (self);
int old_spacing = priv->spacing; int old_spacing = priv->spacing;
double spacing = 0; double spacing;
st_theme_node_get_length (theme_node, "spacing", FALSE, &spacing); spacing = st_theme_node_get_length (theme_node, "spacing");
priv->spacing = (int)(spacing + 0.5); priv->spacing = (int)(spacing + 0.5);
if (priv->spacing != old_spacing) if (priv->spacing != old_spacing)
clutter_actor_queue_relayout (CLUTTER_ACTOR (self)); clutter_actor_queue_relayout (CLUTTER_ACTOR (self));

View File

@ -410,9 +410,9 @@ scroll_bar_allocate_children (StScrollBar *bar,
increment = page_size / (upper - lower); increment = page_size / (upper - lower);
min_size = 32.; min_size = 32.;
st_theme_node_get_length (theme_node, "min-size", FALSE, &min_size); st_theme_node_lookup_length (theme_node, "min-size", FALSE, &min_size);
max_size = G_MAXINT16; max_size = G_MAXINT16;
st_theme_node_get_length (theme_node, "max-size", FALSE, &max_size); st_theme_node_lookup_length (theme_node, "max-size", FALSE, &max_size);
if (upper - lower - page_size <= 0) if (upper - lower - page_size <= 0)
position = 0; position = 0;

View File

@ -988,11 +988,11 @@ st_table_style_changed (StWidget *self)
StThemeNode *theme_node = st_widget_get_theme_node (self); StThemeNode *theme_node = st_widget_get_theme_node (self);
int old_row_spacing = priv->row_spacing; int old_row_spacing = priv->row_spacing;
int old_col_spacing = priv->col_spacing; int old_col_spacing = priv->col_spacing;
double row_spacing = 0., col_spacing = 0.; double row_spacing, col_spacing;
st_theme_node_get_length (theme_node, "spacing-rows", FALSE, &row_spacing); row_spacing = st_theme_node_get_length (theme_node, "spacing-rows");
priv->row_spacing = (int)(row_spacing + 0.5); priv->row_spacing = (int)(row_spacing + 0.5);
st_theme_node_get_length (theme_node, "spacing-columns", FALSE, &col_spacing); col_spacing = st_theme_node_get_length (theme_node, "spacing-columns");
priv->col_spacing = (int)(col_spacing + 0.5); priv->col_spacing = (int)(col_spacing + 0.5);
if (priv->row_spacing != old_row_spacing || if (priv->row_spacing != old_row_spacing ||

View File

@ -490,7 +490,7 @@ get_color_from_term (StThemeNode *node,
} }
/** /**
* st_theme_node_get_color: * st_theme_node_lookup_color:
* @node: a #StThemeNode * @node: a #StThemeNode
* @property_name: The name of the color property * @property_name: The name of the color property
* @inherit: if %TRUE, if a value is not found for the property on the * @inherit: if %TRUE, if a value is not found for the property on the
@ -507,14 +507,16 @@ get_color_from_term (StThemeNode *node,
* should be used instead. They are cached, so more efficient, and have * should be used instead. They are cached, so more efficient, and have
* handling for shortcut properties and other details of CSS. * handling for shortcut properties and other details of CSS.
* *
* See also st_theme_node_get_color(), which provides a simpler API.
*
* Return value: %TRUE if the property was found in the properties for this * Return value: %TRUE if the property was found in the properties for this
* theme node (or in the properties of parent nodes when inheriting.) * theme node (or in the properties of parent nodes when inheriting.)
*/ */
gboolean gboolean
st_theme_node_get_color (StThemeNode *node, st_theme_node_lookup_color (StThemeNode *node,
const char *property_name, const char *property_name,
gboolean inherit, gboolean inherit,
ClutterColor *color) ClutterColor *color)
{ {
int i; int i;
@ -535,7 +537,7 @@ st_theme_node_get_color (StThemeNode *node,
else if (result == VALUE_INHERIT) else if (result == VALUE_INHERIT)
{ {
if (node->parent_node) if (node->parent_node)
return st_theme_node_get_color (node->parent_node, property_name, inherit, color); return st_theme_node_lookup_color (node->parent_node, property_name, inherit, color);
else else
break; break;
} }
@ -543,13 +545,43 @@ st_theme_node_get_color (StThemeNode *node,
} }
if (inherit && node->parent_node) if (inherit && node->parent_node)
return st_theme_node_get_color (node->parent_node, property_name, inherit, color); return st_theme_node_lookup_color (node->parent_node, property_name, inherit, color);
return FALSE; return FALSE;
} }
/** /**
* st_theme_node_get_double: * st_theme_node_get_color:
* @node: a #StThemeNode
* @property_name: The name of the color property
* @color: location to store the color that was determined.
*
* Generically looks up a property containing a single color value. When
* specific getters (like st_theme_node_get_background_color()) exist, they
* should be used instead. They are cached, so more efficient, and have
* handling for shortcut properties and other details of CSS.
*
* If @property_name is not found, a warning will be logged and a
* default color returned.
*
* See also st_theme_node_lookup_color(), which provides more options,
* and lets you handle the case where the theme does not specify the
* indicated color.
*/
void
st_theme_node_get_color (StThemeNode *node,
const char *property_name,
ClutterColor *color)
{
if (!st_theme_node_lookup_color (node, property_name, FALSE, color))
{
g_warning ("Did not find color property '%s'", property_name);
memset (color, 0, sizeof (ClutterColor));
}
}
/**
* st_theme_node_lookup_double:
* @node: a #StThemeNode * @node: a #StThemeNode
* @property_name: The name of the numeric property * @property_name: The name of the numeric property
* @inherit: if %TRUE, if a value is not found for the property on the * @inherit: if %TRUE, if a value is not found for the property on the
@ -564,14 +596,16 @@ st_theme_node_get_color (StThemeNode *node,
* Generically looks up a property containing a single numeric value * Generically looks up a property containing a single numeric value
* without units. * without units.
* *
* See also st_theme_node_get_double(), which provides a simpler API.
*
* Return value: %TRUE if the property was found in the properties for this * Return value: %TRUE if the property was found in the properties for this
* theme node (or in the properties of parent nodes when inheriting.) * theme node (or in the properties of parent nodes when inheriting.)
*/ */
gboolean gboolean
st_theme_node_get_double (StThemeNode *node, st_theme_node_lookup_double (StThemeNode *node,
const char *property_name, const char *property_name,
gboolean inherit, gboolean inherit,
double *value) double *value)
{ {
gboolean result = FALSE; gboolean result = FALSE;
int i; int i;
@ -596,11 +630,41 @@ st_theme_node_get_double (StThemeNode *node,
} }
if (!result && inherit && node->parent_node) if (!result && inherit && node->parent_node)
result = st_theme_node_get_double (node->parent_node, property_name, inherit, value); result = st_theme_node_lookup_double (node->parent_node, property_name, inherit, value);
return result; return result;
} }
/**
* st_theme_node_get_double:
* @node: a #StThemeNode
* @property_name: The name of the numeric property
*
* Generically looks up a property containing a single numeric value
* without units.
*
* See also st_theme_node_lookup_double(), which provides more options,
* and lets you handle the case where the theme does not specify the
* indicated value.
*
* Return value: the value found. If @property_name is not
* found, a warning will be logged and 0 will be returned.
*/
gdouble
st_theme_node_get_double (StThemeNode *node,
const char *property_name)
{
gdouble value;
if (st_theme_node_lookup_double (node, property_name, FALSE, &value))
return value;
else
{
g_warning ("Did not find double property '%s'", property_name);
return 0.0;
}
}
static const PangoFontDescription * static const PangoFontDescription *
get_parent_font (StThemeNode *node) get_parent_font (StThemeNode *node)
{ {
@ -802,7 +866,7 @@ get_length_internal (StThemeNode *node,
} }
/** /**
* st_theme_node_get_length: * st_theme_node_lookup_length:
* @node: a #StThemeNode * @node: a #StThemeNode
* @property_name: The name of the length property * @property_name: The name of the length property
* @inherit: if %TRUE, if a value is not found for the property on the * @inherit: if %TRUE, if a value is not found for the property on the
@ -820,14 +884,16 @@ get_length_internal (StThemeNode *node,
* should be used instead. They are cached, so more efficient, and have * should be used instead. They are cached, so more efficient, and have
* handling for shortcut properties and other details of CSS. * handling for shortcut properties and other details of CSS.
* *
* See also st_theme_node_get_length(), which provides a simpler API.
*
* Return value: %TRUE if the property was found in the properties for this * Return value: %TRUE if the property was found in the properties for this
* theme node (or in the properties of parent nodes when inheriting.) * theme node (or in the properties of parent nodes when inheriting.)
*/ */
gboolean gboolean
st_theme_node_get_length (StThemeNode *node, st_theme_node_lookup_length (StThemeNode *node,
const char *property_name, const char *property_name,
gboolean inherit, gboolean inherit,
gdouble *length) gdouble *length)
{ {
GetFromTermResult result = get_length_internal (node, property_name, NULL, length); GetFromTermResult result = get_length_internal (node, property_name, NULL, length);
if (result == VALUE_FOUND) if (result == VALUE_FOUND)
@ -836,12 +902,42 @@ st_theme_node_get_length (StThemeNode *node,
inherit = TRUE; inherit = TRUE;
if (inherit && node->parent_node && if (inherit && node->parent_node &&
st_theme_node_get_length (node->parent_node, property_name, inherit, length)) st_theme_node_lookup_length (node->parent_node, property_name, inherit, length))
return TRUE; return TRUE;
else else
return FALSE; return FALSE;
} }
/**
* st_theme_node_get_length:
* @node: a #StThemeNode
* @property_name: The name of the length property
*
* Generically looks up a property containing a single length value. When
* specific getters (like st_theme_node_get_border_width()) exist, they
* should be used instead. They are cached, so more efficient, and have
* handling for shortcut properties and other details of CSS.
*
* Unlike st_theme_node_get_color() and st_theme_node_get_double(),
* this does not print a warning if the property is not found; it just
* returns 0.
*
* See also st_theme_node_lookup_length(), which provides more options.
*
* Return value: the length, in pixels, or 0 if the property was not found.
*/
gdouble
st_theme_node_get_length (StThemeNode *node,
const char *property_name)
{
gdouble length;
if (st_theme_node_lookup_length (node, property_name, FALSE, &length))
return length;
else
return 0.0;
}
static void static void
do_border_radius_term (StThemeNode *node, do_border_radius_term (StThemeNode *node,
CRTerm *term, CRTerm *term,
@ -1730,7 +1826,7 @@ st_theme_node_get_transition_duration (StThemeNode *node)
if (node->transition_duration > -1) if (node->transition_duration > -1)
return st_slow_down_factor * node->transition_duration; return st_slow_down_factor * node->transition_duration;
st_theme_node_get_double (node, "transition-duration", FALSE, &value); st_theme_node_lookup_double (node, "transition-duration", FALSE, &value);
node->transition_duration = (int)value; node->transition_duration = (int)value;

View File

@ -99,20 +99,27 @@ const char *st_theme_node_get_pseudo_class (StThemeNode *node);
* details of the actual CSS rules, which can be complicated, especially * details of the actual CSS rules, which can be complicated, especially
* for fonts * for fonts
*/ */
gboolean st_theme_node_get_color (StThemeNode *node, gboolean st_theme_node_lookup_color (StThemeNode *node,
const char *property_name, const char *property_name,
gboolean inherit, gboolean inherit,
ClutterColor *color); ClutterColor *color);
gboolean st_theme_node_lookup_double (StThemeNode *node,
const char *property_name,
gboolean inherit,
double *value);
gboolean st_theme_node_lookup_length (StThemeNode *node,
const char *property_name,
gboolean inherit,
gdouble *length);
gboolean st_theme_node_get_double (StThemeNode *node, /* Easier-to-use variants of the above, for application-level use */
const char *property_name, void st_theme_node_get_color (StThemeNode *node,
gboolean inherit, const char *property_name,
double *value); ClutterColor *color);
gdouble st_theme_node_get_double (StThemeNode *node,
gboolean st_theme_node_get_length (StThemeNode *node, const char *property_name);
const char *property_name, gdouble st_theme_node_get_length (StThemeNode *node,
gboolean inherit, const char *property_name);
gdouble *length);
/* Specific getters for particular properties: cached /* Specific getters for particular properties: cached
*/ */