From bc5a361470702c5a355f6ea747d3e83fa5bd6f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 19 Jun 2019 22:44:54 +0200 Subject: [PATCH] Fix Color change propagation again Closes #1672 --- src/style/Color.js | 33 +++++---------------------------- src/style/Style.js | 40 +++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 45 deletions(-) diff --git a/src/style/Color.js b/src/style/Color.js index d751d824..1c7f2e31 100644 --- a/src/style/Color.js +++ b/src/style/Color.js @@ -712,7 +712,11 @@ var Color = Base.extend(new function() { _changed: function() { this._canvasStyle = null; if (this._owner) { - this._owner[this._setter](this); + if (this._setter) { + this._owner[this._setter](this); + } else { + this._owner._changed(/*#=*/Change.STYLE); + } } }, @@ -1390,30 +1394,3 @@ new function() { */ }); }); - -/** - * @name LinkedColor - * - * @class An internal version of Color that notifies its owner of each change - * through setting itself again on the setter that corresponds to the getter - * that produced this LinkedColor. This is used to solve group color update - * problem (#1152) with the same principle used in LinkedPoint. - * - * @private - */ -var LinkedColor = Color.extend({ - // Make sure LinkedColor is displayed as Color in debugger. - initialize: function Color(color, item, setter) { - // Rely on real constructor for instantiation. - paper.Color.apply(this, [color]); - // Store references. - this._item = item; - this._setter = setter; - }, - - // Rely on Color#_changed() method to detect changes. - _changed: function(){ - // Update owner color by calling setter. - this._item[this._setter](this); - } -}); diff --git a/src/style/Style.js b/src/style/Style.js index ea27669b..b30e090a 100644 --- a/src/style/Style.js +++ b/src/style/Style.js @@ -187,7 +187,10 @@ var Style = Base.extend(new function() { if (value && value.constructor === Color) { // NOTE: If value is not a Color, it is only // converted and cloned in the getter further down. - value = Color._setOwner(value, owner, set); + value = Color._setOwner(value, owner, + // Only provide a color-setter if the style + // is to be applied to the children: + applyToChildren && set); } } // NOTE: We do not convert the values to Colors in the @@ -204,12 +207,24 @@ var Style = Base.extend(new function() { fields[get] = function(_dontMerge) { var owner = this._owner, children = owner && owner._children, + applyToChildren = children && children.length > 0 + && !(owner instanceof CompoundPath), value; // If the owner has children, walk through all of them and see if // they all have the same style. - // If true is passed for _dontMerge, don't merge children styles - if (key in this._defaults && (!children || !children.length - || _dontMerge || owner instanceof CompoundPath)) { + // If true is passed for _dontMerge, don't merge children styles. + if (applyToChildren && !_dontMerge) { + for (var i = 0, l = children.length; i < l; i++) { + var childValue = children[i]._style[get](); + if (!i) { + value = childValue; + } else if (!Base.equals(value, childValue)) { + // If there is another child with a different + // style, the style is not defined: + return undefined; + } + } + } else if (key in this._defaults) { var value = this._values[key]; if (value === undefined) { value = this._defaults[key]; @@ -226,22 +241,13 @@ var Style = Base.extend(new function() { { readNull: true, clone: true }); } } - } else if (children) { - for (var i = 0, l = children.length; i < l; i++) { - var childValue = children[i]._style[get](); - if (!i) { - value = childValue; - } else if (!Base.equals(value, childValue)) { - // If there is another child with a different - // style, the style is not defined: - return undefined; - } - } } if (value && isColor) { // Color._setOwner() may clone the color if it already has a - // different owner (e.g. resulting from `childValue` above): - value = Color._setOwner(value, owner, set); + // different owner (e.g. resulting from `childValue` above). + // Only provide a color-setter if the style is to be applied to + // the children: + value = Color._setOwner(value, owner, applyToChildren && set); } return value; };