gecko/browser/base/content/tabview/infoitems.js

255 lines
6.6 KiB
JavaScript
Raw Normal View History

/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is infoitems.js.
*
* The Initial Developer of the Original Code is
* the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ian Gilman <ian@iangilman.com>
* Aza Raskin <aza@mozilla.com>
* Michael Yoshitaka Erlewine <mitcho@mitcho.com>
* Ehsan Akhgari <ehsan@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// **********
// Title: infoitems.js
// ##########
// Class: InfoItem
Bug 583044 - Rename code references of TabCandy to TabView Move files and update references to tabview from tabcandy. Only remaining candy reference is the link to aza's webm video. --HG-- rename : browser/base/content/browser-tabcandy.js => browser/base/content/browser-tabview.js rename : browser/base/content/tabcandy/app/drag.js => browser/base/content/tabview/drag.js rename : browser/base/content/tabcandy/app/groups.js => browser/base/content/tabview/groups.js rename : browser/base/content/tabcandy/app/infoitems.js => browser/base/content/tabview/infoitems.js rename : browser/base/content/tabcandy/core/iq.js => browser/base/content/tabview/iq.js rename : browser/base/content/tabcandy/app/items.js => browser/base/content/tabview/items.js rename : browser/base/content/tabcandy/core/profile.js => browser/base/content/tabview/profile.js rename : browser/base/content/tabcandy/app/storage.js => browser/base/content/tabview/storage.js rename : browser/base/content/tabcandy/app/tabitems.js => browser/base/content/tabview/tabitems.js rename : browser/base/content/tabcandy/tabcandy.css => browser/base/content/tabview/tabview.css rename : browser/base/content/tabcandy/tabcandy.html => browser/base/content/tabview/tabview.html rename : browser/base/content/tabcandy/tabcandy.js => browser/base/content/tabview/tabview.js rename : browser/base/content/tabcandy/app/trench.js => browser/base/content/tabview/trench.js rename : browser/base/content/tabcandy/app/ui.js => browser/base/content/tabview/ui.js rename : browser/themes/gnomestripe/browser/tabcandy/edit-light.png => browser/themes/gnomestripe/browser/tabview/edit-light.png rename : browser/themes/gnomestripe/browser/tabcandy/edit.png => browser/themes/gnomestripe/browser/tabview/edit.png rename : browser/themes/gnomestripe/browser/tabcandy/new-tab.png => browser/themes/gnomestripe/browser/tabview/new-tab.png rename : browser/themes/gnomestripe/browser/tabcandy/platform.css => browser/themes/gnomestripe/browser/tabview/platform.css rename : browser/themes/gnomestripe/browser/tabcandy/stack-expander.png => browser/themes/gnomestripe/browser/tabview/stack-expander.png rename : browser/themes/gnomestripe/browser/tabcandy/tabcandy.png => browser/themes/gnomestripe/browser/tabview/tabview.png rename : browser/themes/pinstripe/browser/tabcandy/edit-light.png => browser/themes/pinstripe/browser/tabview/edit-light.png rename : browser/themes/pinstripe/browser/tabcandy/edit.png => browser/themes/pinstripe/browser/tabview/edit.png rename : browser/themes/pinstripe/browser/tabcandy/new-tab.png => browser/themes/pinstripe/browser/tabview/new-tab.png rename : browser/themes/pinstripe/browser/tabcandy/platform.css => browser/themes/pinstripe/browser/tabview/platform.css rename : browser/themes/pinstripe/browser/tabcandy/stack-expander.png => browser/themes/pinstripe/browser/tabview/stack-expander.png rename : browser/themes/pinstripe/browser/tabcandy/tabcandy.png => browser/themes/pinstripe/browser/tabview/tabview.png rename : browser/themes/winstripe/browser/tabcandy/edit-light.png => browser/themes/winstripe/browser/tabview/edit-light.png rename : browser/themes/winstripe/browser/tabcandy/edit.png => browser/themes/winstripe/browser/tabview/edit.png rename : browser/themes/winstripe/browser/tabcandy/new-tab.png => browser/themes/winstripe/browser/tabview/new-tab.png rename : browser/themes/winstripe/browser/tabcandy/platform.css => browser/themes/winstripe/browser/tabview/platform.css rename : browser/themes/winstripe/browser/tabcandy/stack-expander.png => browser/themes/winstripe/browser/tabview/stack-expander.png rename : browser/themes/winstripe/browser/tabcandy/tabcandy.png => browser/themes/winstripe/browser/tabview/tabview.png
2010-07-29 12:37:25 -07:00
// An <Item> in TabView used for displaying information, such as the welcome video.
// Note that it implements the <Subscribable> interface.
2010-07-18 08:58:10 -07:00
//
// ----------
// Constructor: InfoItem
2010-07-18 08:58:10 -07:00
//
// Parameters:
// bounds - a <Rect> for where the item should be located
// options - various options for this infoItem (see below)
2010-07-18 08:58:10 -07:00
//
// Possible options:
// locked - see <Item.locked>; default is {}
// dontPush - true if this infoItem shouldn't push away on creation; default is false
function InfoItem(bounds, options) {
try {
Utils.assertThrow(Utils.isRect(bounds), 'bounds');
2010-07-18 08:58:10 -07:00
if (typeof options == 'undefined')
options = {};
2010-07-18 08:58:10 -07:00
this._inited = false;
this.isAnInfoItem = true;
this.defaultSize = bounds.size();
this.locked = (options.locked ? Utils.copy(options.locked) : {});
this.bounds = new Rect(bounds);
this.isDragging = false;
2010-07-18 08:58:10 -07:00
var self = this;
var $container = iQ('<div>')
.addClass('info-item')
.css(this.bounds)
.appendTo('body');
2010-07-18 08:58:10 -07:00
this.$contents = iQ('<div>')
.appendTo($container);
2010-07-18 08:58:10 -07:00
var $close = iQ('<div>')
.addClass('close')
.click(function() {
self.close();
})
.appendTo($container);
2010-07-18 08:58:10 -07:00
// ___ locking
if (this.locked.bounds)
2010-07-18 08:58:10 -07:00
$container.css({cursor: 'default'});
if (this.locked.close)
$close.hide();
2010-07-18 08:58:10 -07:00
// ___ Superclass initialization
this._init($container[0]);
2010-07-18 08:58:10 -07:00
if (this.$debug)
this.$debug.css({zIndex: -1000});
2010-07-18 08:58:10 -07:00
// ___ Finish Up
if (!this.locked.bounds)
this.draggable();
2010-07-18 08:58:10 -07:00
// ___ Position
this.snap();
2010-07-18 08:58:10 -07:00
// ___ Push other objects away
if (!options.dontPush)
2010-07-18 08:58:10 -07:00
this.pushAway();
this._inited = true;
this.save();
} catch(e) {
Utils.log(e);
}
};
// ----------
InfoItem.prototype = Utils.extend(new Item(), new Subscribable(), {
2010-07-18 08:58:10 -07:00
// ----------
// Function: getStorageData
// Returns all of the info worth storing about this item.
getStorageData: function InfoItem_getStorageData() {
var data = null;
2010-07-18 08:58:10 -07:00
try {
data = {
2010-07-18 08:58:10 -07:00
bounds: this.getBounds(),
locked: Utils.copy(this.locked)
};
} catch(e) {
Utils.log(e);
}
2010-07-18 08:58:10 -07:00
return data;
},
// ----------
// Function: save
2010-07-18 08:58:10 -07:00
// Saves this item to persistent storage.
save: function InfoItem_save() {
try {
if (!this._inited) // too soon to save now
return;
2010-07-18 08:58:10 -07:00
var data = this.getStorageData();
} catch(e) {
Utils.log(e);
}
},
2010-07-18 08:58:10 -07:00
// ----------
// Function: setBounds
// Sets the bounds with the given <Rect>, animating unless "immediately" is false.
setBounds: function InfoItem_setBounds(rect, immediately) {
try {
Utils.assertThrow(Utils.isRect(rect), 'InfoItem.setBounds: rect must be a real rectangle!');
// ___ Determine what has changed
var css = {};
2010-07-18 08:58:10 -07:00
if (rect.left != this.bounds.left)
css.left = rect.left;
2010-07-18 08:58:10 -07:00
if (rect.top != this.bounds.top)
css.top = rect.top;
2010-07-18 08:58:10 -07:00
if (rect.width != this.bounds.width)
css.width = rect.width;
2010-07-18 08:58:10 -07:00
if (rect.height != this.bounds.height)
2010-07-18 08:58:10 -07:00
css.height = rect.height;
if (Utils.isEmptyObject(css))
return;
2010-07-18 08:58:10 -07:00
this.bounds = new Rect(rect);
Utils.assertThrow(Utils.isRect(this.bounds),
'InfoItem.setBounds: this.bounds must be a real rectangle!');
2010-07-18 08:58:10 -07:00
// ___ Update our representation
if (immediately) {
iQ(this.container).css(css);
} else {
TabItems.pausePainting();
iQ(this.container).animate(css, {
2010-07-18 08:58:10 -07:00
duration: 350,
Bug 583044 - Rename code references of TabCandy to TabView Move files and update references to tabview from tabcandy. Only remaining candy reference is the link to aza's webm video. --HG-- rename : browser/base/content/browser-tabcandy.js => browser/base/content/browser-tabview.js rename : browser/base/content/tabcandy/app/drag.js => browser/base/content/tabview/drag.js rename : browser/base/content/tabcandy/app/groups.js => browser/base/content/tabview/groups.js rename : browser/base/content/tabcandy/app/infoitems.js => browser/base/content/tabview/infoitems.js rename : browser/base/content/tabcandy/core/iq.js => browser/base/content/tabview/iq.js rename : browser/base/content/tabcandy/app/items.js => browser/base/content/tabview/items.js rename : browser/base/content/tabcandy/core/profile.js => browser/base/content/tabview/profile.js rename : browser/base/content/tabcandy/app/storage.js => browser/base/content/tabview/storage.js rename : browser/base/content/tabcandy/app/tabitems.js => browser/base/content/tabview/tabitems.js rename : browser/base/content/tabcandy/tabcandy.css => browser/base/content/tabview/tabview.css rename : browser/base/content/tabcandy/tabcandy.html => browser/base/content/tabview/tabview.html rename : browser/base/content/tabcandy/tabcandy.js => browser/base/content/tabview/tabview.js rename : browser/base/content/tabcandy/app/trench.js => browser/base/content/tabview/trench.js rename : browser/base/content/tabcandy/app/ui.js => browser/base/content/tabview/ui.js rename : browser/themes/gnomestripe/browser/tabcandy/edit-light.png => browser/themes/gnomestripe/browser/tabview/edit-light.png rename : browser/themes/gnomestripe/browser/tabcandy/edit.png => browser/themes/gnomestripe/browser/tabview/edit.png rename : browser/themes/gnomestripe/browser/tabcandy/new-tab.png => browser/themes/gnomestripe/browser/tabview/new-tab.png rename : browser/themes/gnomestripe/browser/tabcandy/platform.css => browser/themes/gnomestripe/browser/tabview/platform.css rename : browser/themes/gnomestripe/browser/tabcandy/stack-expander.png => browser/themes/gnomestripe/browser/tabview/stack-expander.png rename : browser/themes/gnomestripe/browser/tabcandy/tabcandy.png => browser/themes/gnomestripe/browser/tabview/tabview.png rename : browser/themes/pinstripe/browser/tabcandy/edit-light.png => browser/themes/pinstripe/browser/tabview/edit-light.png rename : browser/themes/pinstripe/browser/tabcandy/edit.png => browser/themes/pinstripe/browser/tabview/edit.png rename : browser/themes/pinstripe/browser/tabcandy/new-tab.png => browser/themes/pinstripe/browser/tabview/new-tab.png rename : browser/themes/pinstripe/browser/tabcandy/platform.css => browser/themes/pinstripe/browser/tabview/platform.css rename : browser/themes/pinstripe/browser/tabcandy/stack-expander.png => browser/themes/pinstripe/browser/tabview/stack-expander.png rename : browser/themes/pinstripe/browser/tabcandy/tabcandy.png => browser/themes/pinstripe/browser/tabview/tabview.png rename : browser/themes/winstripe/browser/tabcandy/edit-light.png => browser/themes/winstripe/browser/tabview/edit-light.png rename : browser/themes/winstripe/browser/tabcandy/edit.png => browser/themes/winstripe/browser/tabview/edit.png rename : browser/themes/winstripe/browser/tabcandy/new-tab.png => browser/themes/winstripe/browser/tabview/new-tab.png rename : browser/themes/winstripe/browser/tabcandy/platform.css => browser/themes/winstripe/browser/tabview/platform.css rename : browser/themes/winstripe/browser/tabcandy/stack-expander.png => browser/themes/winstripe/browser/tabview/stack-expander.png rename : browser/themes/winstripe/browser/tabcandy/tabcandy.png => browser/themes/winstripe/browser/tabview/tabview.png
2010-07-29 12:37:25 -07:00
easing: "tabviewBounce",
complete: function() {
TabItems.resumePainting();
}
});
}
2010-07-18 08:58:10 -07:00
this._updateDebugBounds();
2010-07-18 08:58:10 -07:00
this.setTrenches(rect);
this.save();
} catch(e) {
Utils.log(e);
}
},
2010-07-18 08:58:10 -07:00
// ----------
// Function: setZ
2010-07-18 08:58:10 -07:00
// Set the Z order for the item's container.
setZ: function InfoItem_setZ(value) {
try {
Utils.assertThrow(typeof value == 'number', 'value must be a number');
2010-07-18 08:58:10 -07:00
this.zIndex = value;
2010-07-18 08:58:10 -07:00
iQ(this.container).css({zIndex: value});
2010-07-18 08:58:10 -07:00
if (this.$debug)
this.$debug.css({zIndex: value + 1});
} catch(e) {
Utils.log(e);
}
},
2010-07-18 08:58:10 -07:00
// ----------
// Function: close
2010-07-18 08:58:10 -07:00
// Closes the item.
close: function InfoItem_close() {
try {
this._sendToSubscribers("close");
this.removeTrenches();
iQ(this.container).fadeOut(function() {
iQ(this).remove();
Items.unsquish();
});
2010-07-18 08:58:10 -07:00
} catch(e) {
Utils.log(e);
}
},
2010-07-18 08:58:10 -07:00
// ----------
// Function: html
// Sets the item's container's html to the specified value.
html: function InfoItem_html(value) {
try {
Utils.assertThrow(typeof value == 'string', 'value must be a string');
this.$contents.html(value);
} catch(e) {
Utils.log(e);
}
}
});