From 1224e959b60a017aad5898f243e07f34d1db39c1 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 14 Feb 2011 09:20:22 -0500 Subject: [PATCH] StThemeNode: use (out caller-allocates) on ClutterColor-returning methods Properly annotate the themenode methods that return ClutterColors, and update their JS callers to take advantage of that. https://bugzilla.gnome.org/show_bug.cgi?id=642295 --- js/ui/boxpointer.js | 6 ++---- js/ui/dateMenu.js | 3 +-- js/ui/messageTray.js | 3 +-- js/ui/popupMenu.js | 18 ++++++------------ src/st/st-theme-node.c | 40 +++++++++++++++++++++++++++++++++++----- 5 files changed, 45 insertions(+), 25 deletions(-) diff --git a/js/ui/boxpointer.js b/js/ui/boxpointer.js index 206221b75..887f4a783 100644 --- a/js/ui/boxpointer.js +++ b/js/ui/boxpointer.js @@ -189,10 +189,8 @@ BoxPointer.prototype = { let halfBorder = borderWidth / 2; let halfBase = Math.floor(base/2); - let borderColor = new Clutter.Color(); - themeNode.get_color('-arrow-border-color', borderColor); - let backgroundColor = new Clutter.Color(); - themeNode.get_color('-arrow-background-color', backgroundColor); + let borderColor = themeNode.get_color('-arrow-border-color'); + let backgroundColor = themeNode.get_color('-arrow-background-color'); let [width, height] = area.get_surface_size(); let [boxWidth, boxHeight] = [width, height]; diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js index 09f8dfe17..f22cfd5f3 100644 --- a/js/ui/dateMenu.js +++ b/js/ui/dateMenu.js @@ -29,10 +29,9 @@ function _onVertSepRepaint (area) let cr = area.get_context(); let themeNode = area.get_theme_node(); let [width, height] = area.get_surface_size(); - let stippleColor = new Clutter.Color(); + let stippleColor = themeNode.get_color('-stipple-color'); let stippleWidth = themeNode.get_length('-stipple-width'); let x = Math.floor(width/2) + 0.5; - themeNode.lookup_color('-stipple-color', false, stippleColor); cr.moveTo(x, 0); cr.lineTo(x, height); Clutter.cairo_set_source_color(cr, stippleColor); diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 34f6b3f38..cd062b315 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -89,8 +89,7 @@ URLHighlighter.prototype = { this.actor = new St.Label({ reactive: true, style_class: 'url-highlighter' }); this._linkColor = '#ccccff'; this.actor.connect('style-changed', Lang.bind(this, function() { - let color = new Clutter.Color(); - let hasColor = this.actor.get_theme_node().get_color('link-color', color); + let [hasColor, color] = this.actor.get_theme_node().lookup_color('link-color', false); if (hasColor) { let linkColor = color.to_string().substr(0, 7); if (linkColor != this._linkColor) { diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js index 14b145077..05a67bd87 100644 --- a/js/ui/popupMenu.js +++ b/js/ui/popupMenu.js @@ -151,8 +151,7 @@ PopupBaseMenuItem.prototype = { _onRepaintDot: function(area) { let cr = area.get_context(); let [width, height] = area.get_surface_size(); - let color = new Clutter.Color(); - area.get_theme_node().get_foreground_color(color); + let color = area.get_theme_node().get_foreground_color(); cr.setSourceRGBA ( color.red / 255, @@ -309,10 +308,8 @@ PopupSeparatorMenuItem.prototype = { let [width, height] = area.get_surface_size(); let margin = themeNode.get_length('-margin-horizontal'); let gradientHeight = themeNode.get_length('-gradient-height'); - let startColor = new Clutter.Color(); - themeNode.get_color('-gradient-start', startColor); - let endColor = new Clutter.Color(); - themeNode.get_color('-gradient-end', endColor); + let startColor = themeNode.get_color('-gradient-start'); + let endColor = themeNode.get_color('-gradient-end'); let gradientWidth = (width - margin * 2); let gradientOffset = (height - gradientHeight) / 2; @@ -373,10 +370,8 @@ PopupSliderMenuItem.prototype = { let sliderBorderWidth = themeNode.get_length('-slider-border-width'); - let sliderBorderColor = new Clutter.Color(); - themeNode.get_color('-slider-border-color', sliderBorderColor); - let sliderColor = new Clutter.Color(); - themeNode.get_color('-slider-background-color', sliderColor); + let sliderBorderColor = themeNode.get_color('-slider-border-color'); + let sliderColor = themeNode.get_color('-slider-background-color'); cr.setSourceRGBA ( sliderColor.red / 255, @@ -396,8 +391,7 @@ PopupSliderMenuItem.prototype = { let handleY = height / 2; let handleX = handleRadius + (width - 2 * handleRadius) * this._value; - let color = new Clutter.Color(); - themeNode.get_foreground_color(color); + let color = themeNode.get_foreground_color(); cr.setSourceRGBA ( color.red / 255, color.green / 255, diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c index 5475bbc94..fd3b89db9 100644 --- a/src/st/st-theme-node.c +++ b/src/st/st-theme-node.c @@ -529,8 +529,8 @@ get_color_from_term (StThemeNode *node, * parent's parent, and so forth. Note that if the property has a * value of 'inherit' it will be inherited even if %FALSE is passed * in for @inherit; this only affects the default behavior for inheritance. - * @color: location to store the color that was determined. - * If the property is not found, the value in this location + * @color: (out caller-allocates): location to store the color that was + * determined. If the property is not found, the value in this location * will not be changed. * * Generically looks up a property containing a single color value. When @@ -585,7 +585,8 @@ st_theme_node_lookup_color (StThemeNode *node, * 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. + * @color: (out caller-allocates): 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 @@ -1479,6 +1480,13 @@ st_theme_node_get_outline_width (StThemeNode *node) return node->outline_width; } +/** + * st_theme_node_get_outline_color: + * @node: a #StThemeNode + * @color: (out caller-allocates): location to store the color + * + * Returns the color of @node's outline. + */ void st_theme_node_get_outline_color (StThemeNode *node, ClutterColor *color) @@ -1741,6 +1749,13 @@ _st_theme_node_ensure_background (StThemeNode *node) } } +/** + * st_theme_node_get_background_color: + * @node: a #StThemeNode + * @color: (out caller-allocates): location to store the color + * + * Returns @node's background color. + */ void st_theme_node_get_background_color (StThemeNode *node, ClutterColor *color) @@ -1762,6 +1777,13 @@ st_theme_node_get_background_image (StThemeNode *node) return node->background_image; } +/** + * st_theme_node_get_foreground_color: + * @node: a #StThemeNode + * @color: (out caller-allocates): location to store the color + * + * Returns @node's foreground color. + */ void st_theme_node_get_foreground_color (StThemeNode *node, ClutterColor *color) @@ -1805,8 +1827,8 @@ st_theme_node_get_foreground_color (StThemeNode *node, * st_theme_node_get_background_gradient: * @node: A #StThemeNode * @type: (out): Type of gradient - * @start: Color at start of gradient - * @end: Color at end of gradient + * @start: (out caller-allocates): Color at start of gradient + * @end: (out caller-allocates): Color at end of gradient * * The @start and @end arguments will only be set if @type is not #ST_GRADIENT_NONE. */ @@ -1828,6 +1850,14 @@ st_theme_node_get_background_gradient (StThemeNode *node, } } +/** + * st_theme_node_get_border_color: + * @node: a #StThemeNode + * @side: a #StSide + * @color: (out caller-allocates): location to store the color + * + * Returns the color of @node's border on @side + */ void st_theme_node_get_border_color (StThemeNode *node, StSide side,