Schedule relayout whenever children are added to BlobItemContainer.

This fixes some bugs where we don't relayout when items are added
to BlobItemContainer for various reasons.

Change-Id: Ie434acc12e660af438b93d2dabd41f3d75fb7493
This commit is contained in:
Aaron Boodman 2013-08-04 23:55:17 -07:00
parent c44d89e22f
commit 5e24502348
1 changed files with 32 additions and 4 deletions

View File

@ -49,6 +49,13 @@ camlistore.BlobItemContainer = function(connection, opt_domHelper) {
*/ */
this.currentCollec_ = ""; this.currentCollec_ = "";
/**
* Whether our content has changed since last layout.
* @type {boolean}
* @private
*/
this.isLayoutDirty_ = false;
/** /**
* @type {goog.events.EventHandler} * @type {goog.events.EventHandler}
* @private * @private
@ -189,6 +196,26 @@ camlistore.BlobItemContainer.prototype.disposeInternal = function() {
}; };
/** @override */
camlistore.BlobItemContainer.prototype.addChildAt =
function(child, index, opt_render) {
goog.base(this, "addChildAt", child, index, opt_render);
if (!this.isLayoutDirty_) {
var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
// It's OK if raf not supported, the timer loop we have going will pick up
// the layout a little later.
if (raf) {
raf(goog.bind(function() {
this.layout_(false);
}, this, false));
}
this.isLayoutDirty_ = true;
}
};
/** /**
* Called when component's element is known to be in the document. * Called when component's element is known to be in the document.
*/ */
@ -208,7 +235,9 @@ camlistore.BlobItemContainer.prototype.enterDocument = function() {
// We can't catch everything that could cause us to need to relayout. Instead, // We can't catch everything that could cause us to need to relayout. Instead,
// be lazy and just poll every second. // be lazy and just poll every second.
window.setInterval(goog.bind(this.layout_, this, false), 1000); window.setInterval(goog.bind(function() {
this.layout_(false);
}, this, false), 1000);
}; };
@ -461,8 +490,6 @@ camlistore.BlobItemContainer.prototype.showRecentDone_ = function(result) {
var item = new camlistore.BlobItem(blobRef, result.meta); var item = new camlistore.BlobItem(blobRef, result.meta);
this.addChild(item, true); this.addChild(item, true);
} }
this.layout_(true);
}; };
/** /**
@ -472,10 +499,11 @@ camlistore.BlobItemContainer.prototype.layout_ = function(force) {
var el = this.getElement(); var el = this.getElement();
var availWidth = el.clientWidth; var availWidth = el.clientWidth;
if (!force && availWidth == this.lastClientWidth_) { if (!force && !this.isLayoutDirty_ && availWidth == this.lastClientWidth_) {
return; return;
} }
this.isLayoutDirty_ = false;
this.lastClientWidth_ = availWidth; this.lastClientWidth_ = availWidth;
// If you change blobItemMarginWidth, also change .cam-blobitem in // If you change blobItemMarginWidth, also change .cam-blobitem in