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);
}
let [found, spacing] = this.actor.get_theme_node().get_length('spacing', false);
if (!found)
spacing = 0;
let spacing = this.actor.get_theme_node().get_length('spacing');
childBox.x2 = childBox.x1 + childNaturalWidth;
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.spacing = 0;
this._list.connect('style-changed', Lang.bind(this, function() {
let [found, spacing] = this._list.get_theme_node().get_length('spacing', false);
this._list.spacing = (found) ? spacing : 0;
this._list.spacing = this._list.get_theme_node().get_length('spacing');
}));
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();
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 [found, spacing] = this._items[0].child.get_theme_node().get_length('spacing', false);
if (!found)
spacing = 0;
let spacing = this._items[0].child.get_theme_node().get_length('spacing');
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;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,8 +33,7 @@ WorkspaceSwitcherPopup.prototype = {
this._list = new Shell.GenericContainer({ style_class: 'workspace-switcher' });
this._itemSpacing = 0;
this._list.connect('style-changed', Lang.bind(this, function() {
let [found, spacing] = this._list.get_theme_node().get_length('spacing', false);
this._itemSpacing = (found) ? spacing : 0;
this._itemSpacing = this._list.get_theme_node().get_length('spacing');
}));
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,
function() {
let node = this.actor.get_theme_node();
let [a, spacing] = node.get_length('spacing', false);
this._spacing = spacing;
this._spacing = node.get_length('spacing');
if (Main.overview.animationInProgress)
this._computeWorkspacePositions();
else
@ -609,7 +608,7 @@ WorkspaceIndicator.prototype = {
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;
},