Remove _boundsCache and replace it with easier _simpleBounds flag.

This commit is contained in:
Jürg Lehni 2011-11-24 15:44:26 +01:00
parent 067e0a954b
commit 310fbb260b
4 changed files with 12 additions and 10 deletions

View file

@ -1260,8 +1260,10 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
// bounds on items without children, as we do not receive hierarchy
// change notifiers from children, and walking up the parents and
// merging cache bounds is not expensive.
// Allow subclasses to define _simpleBounds if they want to share the
// cache across all different bound types.
var cache = !this._children && !matrix
&& (this._boundsName[name] || name);
&& (this._simpleBounds && 'bounds' || name);
if (cache && this._bounds && this._bounds[cache])
return this._bounds[cache];
var bounds = this._getBounds(name, matrix);
@ -1281,12 +1283,6 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
return bounds;
};
}, /** @lends Item# */{
/**
* Used internally to override caching names, so bound types can share their
* cache, in case they return the same results.
*/
_boundsName: {},
/**
* Internal method used in all the bounds getters. It loops through all the
* children, gets their bounds and finds the bounds around all of them.

View file

@ -95,7 +95,7 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
},
_calculateBounds: function(type, matrix) {
// Ask the symbol definition to calculate the bounds for us
// Redirect the call to the symbol definition to calculate the bounds
return this.symbol._definition._getBounds(type, matrix);
},

View file

@ -22,6 +22,10 @@
* @extends PlacedItem
*/
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
// Raster doesn't make the distinction between the different bounds,
// so use the same cache for all of them
_simpleBounds: true,
// TODO: Implement url / type, width, height.
// TODO: Have PlacedSymbol & Raster inherit from a shared class?
// DOCS: Document Raster constructor.
@ -381,8 +385,6 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
},
_calculateBounds: function(type, matrix) {
// Note: Raster doesn't make the distinction between the different
// bounds
return matrix._transformBounds(
new Rectangle(this._size).setCenter(0, 0));
},

View file

@ -26,6 +26,10 @@
* @extends Item
*/
var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
// TextItem doesn't make the distinction between the different bounds,
// so use the same cache for all of them
_simpleBounds: true,
initialize: function() {
this.base();
this._content = '';