2010-06-16 17:19:11 -07:00
|
|
|
/* ***** 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 ui.js.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2010-08-11 15:28:45 -07:00
|
|
|
* the Mozilla Foundation.
|
2010-06-16 17:19:11 -07:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2010-08-11 15:28:45 -07:00
|
|
|
* Ian Gilman <ian@iangilman.com>
|
2010-06-16 17:19:11 -07:00
|
|
|
* Aza Raskin <aza@mozilla.com>
|
|
|
|
* Michael Yoshitaka Erlewine <mitcho@mitcho.com>
|
|
|
|
* Ehsan Akhgari <ehsan@mozilla.com>
|
2010-06-21 17:27:12 -07:00
|
|
|
* Raymond Lee <raymond@appcoast.com>
|
2010-09-15 20:47:45 -07:00
|
|
|
* Sean Dunn <seanedunn@yahoo.com>
|
2010-06-16 17:19:11 -07:00
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
|
|
|
// **********
|
2010-07-18 08:58:10 -07:00
|
|
|
// Title: ui.js
|
2010-05-11 17:22:06 -07:00
|
|
|
|
2010-09-08 10:02:08 -07:00
|
|
|
let Keys = { meta: false };
|
2010-05-23 23:42:18 -07:00
|
|
|
|
2010-03-25 17:22:45 -07:00
|
|
|
// ##########
|
2010-09-08 10:02:08 -07:00
|
|
|
// Class: UI
|
2010-07-23 00:03:40 -07:00
|
|
|
// Singleton top-level UI manager.
|
2010-09-08 10:02:08 -07:00
|
|
|
let UI = {
|
2010-09-14 03:12:03 -07:00
|
|
|
// Variable: _frameInitialized
|
2010-07-30 02:54:30 -07:00
|
|
|
// True if the Tab View UI frame has been initialized.
|
2010-09-14 03:12:03 -07:00
|
|
|
_frameInitialized: false,
|
2010-07-23 00:03:40 -07:00
|
|
|
|
|
|
|
// Variable: _pageBounds
|
|
|
|
// Stores the page bounds.
|
|
|
|
_pageBounds : null,
|
|
|
|
|
|
|
|
// Variable: _closedLastVisibleTab
|
|
|
|
// If true, the last visible tab has just been closed in the tab strip.
|
|
|
|
_closedLastVisibleTab : false,
|
|
|
|
|
2010-07-29 12:37:25 -07:00
|
|
|
// Variable: _closedSelectedTabInTabView
|
|
|
|
// If true, a select tab has just been closed in TabView.
|
|
|
|
_closedSelectedTabInTabView : false,
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-11-29 21:03:51 -08:00
|
|
|
// Variable: restoredClosedTab
|
|
|
|
// If true, a closed tab has just been restored.
|
|
|
|
restoredClosedTab : false,
|
|
|
|
|
2010-07-25 20:53:21 -07:00
|
|
|
// Variable: _reorderTabItemsOnShow
|
2010-08-06 15:46:55 -07:00
|
|
|
// Keeps track of the <GroupItem>s which their tab items' tabs have been moved
|
2010-07-29 12:37:25 -07:00
|
|
|
// and re-orders the tab items when switching to TabView.
|
2010-07-25 20:53:21 -07:00
|
|
|
_reorderTabItemsOnShow : [],
|
|
|
|
|
|
|
|
// Variable: _reorderTabsOnHide
|
2010-08-06 15:46:55 -07:00
|
|
|
// Keeps track of the <GroupItem>s which their tab items have been moved in
|
2010-07-29 12:37:25 -07:00
|
|
|
// TabView UI and re-orders the tabs when switcing back to main browser.
|
2010-07-25 20:53:21 -07:00
|
|
|
_reorderTabsOnHide : [],
|
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
// Variable: _currentTab
|
2010-08-05 10:39:33 -07:00
|
|
|
// Keeps track of which xul:tab we are currently on.
|
2010-07-23 00:03:40 -07:00
|
|
|
// Used to facilitate zooming down from a previous tab.
|
2010-07-26 17:15:19 -07:00
|
|
|
_currentTab : null,
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-08-31 00:22:10 -07:00
|
|
|
// Variable: _eventListeners
|
|
|
|
// Keeps track of event listeners added to the AllTabs object.
|
|
|
|
_eventListeners: {},
|
|
|
|
|
2010-09-12 20:45:02 -07:00
|
|
|
// Variable: _cleanupFunctions
|
|
|
|
// An array of functions to be called at uninit time
|
|
|
|
_cleanupFunctions: [],
|
2010-09-24 17:24:31 -07:00
|
|
|
|
2010-09-09 22:29:00 -07:00
|
|
|
// Constant: _maxInteractiveWait
|
|
|
|
// If the UI is in the middle of an operation, this is the max amount of
|
|
|
|
// milliseconds to wait between input events before we no longer consider
|
|
|
|
// the operation interactive.
|
|
|
|
_maxInteractiveWait: 250,
|
|
|
|
|
2010-09-24 17:24:31 -07:00
|
|
|
// Variable: _privateBrowsing
|
|
|
|
// Keeps track of info related to private browsing, including:
|
|
|
|
// transitionStage - what step we're on in entering/exiting PB
|
|
|
|
// transitionMode - whether we're entering or exiting PB
|
|
|
|
// wasInTabView - whether TabView was visible before we went into PB
|
|
|
|
_privateBrowsing: {
|
|
|
|
transitionStage: 0,
|
|
|
|
transitionMode: "",
|
|
|
|
wasInTabView: false
|
|
|
|
},
|
2010-09-12 20:45:02 -07:00
|
|
|
|
2010-07-16 17:27:01 -07:00
|
|
|
// ----------
|
2010-07-23 00:03:40 -07:00
|
|
|
// Function: init
|
|
|
|
// Must be called after the object is created.
|
2010-09-08 10:02:08 -07:00
|
|
|
init: function UI_init() {
|
2010-07-23 00:03:40 -07:00
|
|
|
try {
|
2010-07-29 17:23:49 -07:00
|
|
|
let self = this;
|
|
|
|
|
2010-11-07 22:38:24 -08:00
|
|
|
// initialize the direction of the page
|
|
|
|
this._initPageDirection();
|
|
|
|
|
2010-07-29 17:23:49 -07:00
|
|
|
// ___ storage
|
2010-07-26 17:15:19 -07:00
|
|
|
Storage.init();
|
2010-07-29 17:23:49 -07:00
|
|
|
let data = Storage.readUIData(gWindow);
|
|
|
|
this._storageSanity(data);
|
|
|
|
this._pageBounds = data.pageBounds;
|
2010-07-30 02:54:30 -07:00
|
|
|
|
2010-07-29 17:23:49 -07:00
|
|
|
// ___ hook into the browser
|
|
|
|
gWindow.addEventListener("tabviewshow", function() {
|
|
|
|
self.showTabView(true);
|
|
|
|
}, false);
|
2010-08-11 21:36:58 -07:00
|
|
|
|
2010-08-09 17:24:08 -07:00
|
|
|
// ___ currentTab
|
2010-07-26 17:15:19 -07:00
|
|
|
this._currentTab = gBrowser.selectedTab;
|
2010-07-26 18:30:56 -07:00
|
|
|
|
2010-09-24 16:22:35 -07:00
|
|
|
// ___ exit button
|
|
|
|
iQ("#exit-button").click(function() {
|
|
|
|
self.exit();
|
|
|
|
self.blurAll();
|
|
|
|
});
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-07-29 12:37:25 -07:00
|
|
|
// When you click on the background/empty part of TabView,
|
2010-08-06 15:46:55 -07:00
|
|
|
// we create a new groupItem.
|
2010-07-30 02:54:30 -07:00
|
|
|
iQ(gTabViewFrame.contentDocument).mousedown(function(e) {
|
2010-08-01 23:34:52 -07:00
|
|
|
if (iQ(":focus").length > 0) {
|
|
|
|
iQ(":focus").each(function(element) {
|
2010-11-23 09:57:30 -08:00
|
|
|
// don't fire blur event if the same input element is clicked.
|
|
|
|
if (e.target != element && element.nodeName == "INPUT")
|
2010-08-01 23:34:52 -07:00
|
|
|
element.blur();
|
|
|
|
});
|
|
|
|
}
|
2010-07-30 02:54:30 -07:00
|
|
|
if (e.originalTarget.id == "content")
|
2010-08-06 15:46:55 -07:00
|
|
|
self._createGroupItemOnDrag(e)
|
2010-07-23 00:03:40 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
iQ(window).bind("beforeunload", function() {
|
2010-07-23 18:43:02 -07:00
|
|
|
Array.forEach(gBrowser.tabs, function(tab) {
|
2010-08-13 11:36:40 -07:00
|
|
|
gBrowser.showTab(tab);
|
2010-07-23 18:43:02 -07:00
|
|
|
});
|
2010-07-23 00:03:40 -07:00
|
|
|
});
|
2010-08-11 21:36:58 -07:00
|
|
|
iQ(window).bind("unload", function() {
|
|
|
|
self.uninit();
|
|
|
|
});
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-07-29 12:37:25 -07:00
|
|
|
gWindow.addEventListener("tabviewhide", function() {
|
2010-09-24 16:22:35 -07:00
|
|
|
self.exit();
|
2010-07-23 00:03:40 -07:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
// ___ setup key handlers
|
|
|
|
this._setTabViewFrameKeyHandlers();
|
|
|
|
|
|
|
|
// ___ add tab action handlers
|
|
|
|
this._addTabActionHandlers();
|
|
|
|
|
|
|
|
// ___ Storage
|
2010-10-11 11:57:00 -07:00
|
|
|
GroupItems.pauseArrange();
|
2010-08-06 17:02:21 -07:00
|
|
|
GroupItems.init();
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-09-20 18:26:00 -07:00
|
|
|
let firstTime = true;
|
|
|
|
if (gPrefBranch.prefHasUserValue("experienced_first_run"))
|
|
|
|
firstTime = !gPrefBranch.getBoolPref("experienced_first_run");
|
|
|
|
let groupItemsData = Storage.readGroupItemsData(gWindow);
|
|
|
|
let groupItemData = Storage.readGroupItemData(gWindow);
|
2010-08-06 15:46:55 -07:00
|
|
|
GroupItems.reconstitute(groupItemsData, groupItemData);
|
2010-08-08 15:47:06 -07:00
|
|
|
GroupItems.killNewTabGroup(); // temporary?
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-08-15 21:46:22 -07:00
|
|
|
// ___ tabs
|
|
|
|
TabItems.init();
|
|
|
|
TabItems.pausePainting();
|
|
|
|
|
2010-09-20 18:26:00 -07:00
|
|
|
// if first time in Panorama or no group data:
|
|
|
|
if (firstTime || !groupItemsData || Utils.isEmptyObject(groupItemsData))
|
|
|
|
this.reset(firstTime);
|
2010-07-23 00:03:40 -07:00
|
|
|
|
|
|
|
// ___ resizing
|
2010-07-30 02:54:30 -07:00
|
|
|
if (this._pageBounds)
|
2010-07-23 00:03:40 -07:00
|
|
|
this._resize(true);
|
2010-07-29 17:23:49 -07:00
|
|
|
else
|
2010-07-23 00:03:40 -07:00
|
|
|
this._pageBounds = Items.getPageBounds();
|
|
|
|
|
|
|
|
iQ(window).resize(function() {
|
|
|
|
self._resize();
|
|
|
|
});
|
|
|
|
|
|
|
|
// ___ setup observer to save canvas images
|
|
|
|
var observer = {
|
|
|
|
observe : function(subject, topic, data) {
|
|
|
|
if (topic == "quit-application-requested") {
|
2010-11-30 00:15:51 -08:00
|
|
|
if (self.isTabViewVisible()) {
|
2010-09-10 07:40:27 -07:00
|
|
|
GroupItems.removeHiddenGroups();
|
2010-07-23 00:03:40 -07:00
|
|
|
TabItems.saveAll(true);
|
2010-09-10 07:40:27 -07:00
|
|
|
}
|
2010-07-23 00:03:40 -07:00
|
|
|
self._save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Services.obs.addObserver(observer, "quit-application-requested", false);
|
|
|
|
|
|
|
|
// ___ Done
|
2010-09-14 03:12:03 -07:00
|
|
|
this._frameInitialized = true;
|
2010-07-23 00:03:40 -07:00
|
|
|
this._save();
|
2010-09-14 03:12:03 -07:00
|
|
|
|
|
|
|
// fire an iframe initialized event so everyone knows tab view is
|
|
|
|
// initialized.
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("tabviewframeinitialized", true, false);
|
2010-10-11 11:57:00 -07:00
|
|
|
dispatchEvent(event);
|
2010-07-23 00:03:40 -07:00
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
2010-10-11 11:57:00 -07:00
|
|
|
} finally {
|
|
|
|
GroupItems.resumeArrange();
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-09-08 10:02:08 -07:00
|
|
|
uninit: function UI_uninit() {
|
2010-09-12 20:45:02 -07:00
|
|
|
// call our cleanup functions
|
|
|
|
this._cleanupFunctions.forEach(function(func) {
|
|
|
|
func();
|
|
|
|
});
|
|
|
|
|
|
|
|
this._cleanupFunctions = [];
|
|
|
|
|
|
|
|
// additional clean up
|
2010-08-11 21:36:58 -07:00
|
|
|
TabItems.uninit();
|
|
|
|
GroupItems.uninit();
|
|
|
|
Storage.uninit();
|
|
|
|
|
2010-08-31 00:22:10 -07:00
|
|
|
this._removeTabActionHandlers();
|
2010-08-11 21:36:58 -07:00
|
|
|
this._currentTab = null;
|
|
|
|
this._pageBounds = null;
|
|
|
|
this._reorderTabItemsOnShow = null;
|
|
|
|
this._reorderTabsOnHide = null;
|
2010-09-14 03:12:03 -07:00
|
|
|
this._frameInitialized = false;
|
2010-08-11 21:36:58 -07:00
|
|
|
},
|
2010-11-07 22:38:24 -08:00
|
|
|
|
|
|
|
// Property: rtl
|
|
|
|
// Returns true if we are in RTL mode, false otherwise
|
2010-11-10 19:48:42 -08:00
|
|
|
rtl: false,
|
2010-11-07 22:38:24 -08:00
|
|
|
|
2010-09-20 18:26:00 -07:00
|
|
|
// Function: reset
|
|
|
|
// Resets the Panorama view to have just one group with all tabs
|
|
|
|
// and, if firstTime == true, add the welcome video/tab
|
|
|
|
reset: function UI_reset(firstTime) {
|
2010-10-26 14:06:20 -07:00
|
|
|
let padding = Trenches.defaultRadius;
|
|
|
|
let welcomeWidth = 300;
|
2010-09-20 18:26:00 -07:00
|
|
|
let pageBounds = Items.getPageBounds();
|
|
|
|
pageBounds.inset(padding, padding);
|
|
|
|
|
2010-10-26 14:06:20 -07:00
|
|
|
let $actions = iQ("#actions");
|
2010-11-10 19:48:43 -08:00
|
|
|
if ($actions) {
|
2010-10-26 14:06:20 -07:00
|
|
|
pageBounds.width -= $actions.width();
|
2010-11-10 19:48:43 -08:00
|
|
|
if (UI.rtl)
|
|
|
|
pageBounds.left += $actions.width() - padding;
|
|
|
|
}
|
2010-10-26 14:06:20 -07:00
|
|
|
|
2010-09-20 18:26:00 -07:00
|
|
|
// ___ make a fresh groupItem
|
|
|
|
let box = new Rect(pageBounds);
|
2010-10-26 14:06:20 -07:00
|
|
|
box.width = Math.min(box.width * 0.667,
|
|
|
|
pageBounds.width - (welcomeWidth + padding));
|
2010-09-20 18:26:00 -07:00
|
|
|
box.height = box.height * 0.667;
|
2010-11-07 22:38:24 -08:00
|
|
|
if (UI.rtl) {
|
2010-11-10 19:48:43 -08:00
|
|
|
box.left = pageBounds.left + welcomeWidth + 2 * padding;
|
2010-11-07 22:38:24 -08:00
|
|
|
}
|
2010-09-20 18:26:00 -07:00
|
|
|
|
|
|
|
GroupItems.groupItems.forEach(function(group) {
|
|
|
|
group.close();
|
|
|
|
});
|
2010-10-09 12:46:18 -07:00
|
|
|
|
|
|
|
let options = {
|
|
|
|
bounds: box,
|
|
|
|
immediately: true
|
|
|
|
};
|
|
|
|
let groupItem = new GroupItem([], options);
|
2010-09-20 18:26:00 -07:00
|
|
|
let items = TabItems.getItems();
|
|
|
|
items.forEach(function(item) {
|
|
|
|
if (item.parent)
|
|
|
|
item.parent.remove(item);
|
2010-10-09 12:46:18 -07:00
|
|
|
groupItem.add(item, null, {immediately: true});
|
2010-09-20 18:26:00 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
if (firstTime) {
|
|
|
|
gPrefBranch.setBoolPref("experienced_first_run", true);
|
|
|
|
|
2010-10-26 14:06:20 -07:00
|
|
|
let url = gPrefBranch.getCharPref("welcome_url");
|
|
|
|
let newTab = gBrowser.loadOneTab(url, {inBackground: true});
|
|
|
|
let newTabItem = newTab.tabItem;
|
|
|
|
let parent = newTabItem.parent;
|
|
|
|
Utils.assert(parent, "should have a parent");
|
|
|
|
|
|
|
|
newTabItem.parent.remove(newTabItem);
|
|
|
|
let aspect = TabItems.tabHeight / TabItems.tabWidth;
|
2010-11-10 19:48:43 -08:00
|
|
|
let welcomeBounds = new Rect(UI.rtl ? pageBounds.left : box.right, box.top,
|
2010-10-26 14:06:20 -07:00
|
|
|
welcomeWidth, welcomeWidth * aspect);
|
|
|
|
newTabItem.setBounds(welcomeBounds, true);
|
|
|
|
GroupItems.setActiveGroupItem(groupItem);
|
2010-09-20 18:26:00 -07:00
|
|
|
}
|
|
|
|
},
|
2010-08-11 21:36:58 -07:00
|
|
|
|
2010-09-15 20:47:45 -07:00
|
|
|
// Function: blurAll
|
|
|
|
// Blurs any currently focused element
|
|
|
|
//
|
|
|
|
blurAll: function UI_blurAll() {
|
|
|
|
iQ(":focus").each(function(element) {
|
|
|
|
element.blur();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-09-09 22:29:00 -07:00
|
|
|
// ----------
|
|
|
|
// Function: isIdle
|
|
|
|
// Returns true if the last interaction was long enough ago to consider the
|
|
|
|
// UI idle. Used to determine whether interactivity would be sacrificed if
|
|
|
|
// the CPU was to become busy.
|
|
|
|
//
|
|
|
|
isIdle: function UI_isIdle() {
|
|
|
|
let time = Date.now();
|
|
|
|
let maxEvent = Math.max(drag.lastMoveTime, resize.lastMoveTime);
|
|
|
|
return (time - maxEvent) > this._maxInteractiveWait;
|
|
|
|
},
|
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
// ----------
|
|
|
|
// Function: getActiveTab
|
|
|
|
// Returns the currently active tab as a <TabItem>
|
|
|
|
//
|
2010-09-08 10:02:08 -07:00
|
|
|
getActiveTab: function UI_getActiveTab() {
|
2010-07-23 00:03:40 -07:00
|
|
|
return this._activeTab;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: setActiveTab
|
|
|
|
// Sets the currently active tab. The idea of a focused tab is useful
|
|
|
|
// for keyboard navigation and returning to the last zoomed-in tab.
|
|
|
|
// Hitting return/esc brings you to the focused tab, and using the
|
|
|
|
// arrow keys lets you navigate between open tabs.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// - Takes a <TabItem>
|
2010-09-08 10:02:08 -07:00
|
|
|
setActiveTab: function UI_setActiveTab(tab) {
|
2010-07-23 00:03:40 -07:00
|
|
|
if (tab == this._activeTab)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._activeTab) {
|
|
|
|
this._activeTab.makeDeactive();
|
2010-07-27 20:02:51 -07:00
|
|
|
this._activeTab.removeSubscriber(this, "close");
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
|
|
|
this._activeTab = tab;
|
|
|
|
|
|
|
|
if (this._activeTab) {
|
|
|
|
var self = this;
|
2010-07-27 20:02:51 -07:00
|
|
|
this._activeTab.addSubscriber(this, "close", function() {
|
2010-07-23 00:03:40 -07:00
|
|
|
self._activeTab = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
this._activeTab.makeActive();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
2010-11-30 00:15:51 -08:00
|
|
|
// Function: isTabViewVisible
|
2010-07-29 12:37:25 -07:00
|
|
|
// Returns true if the TabView UI is currently shown.
|
2010-11-30 00:15:51 -08:00
|
|
|
isTabViewVisible: function UI_isTabViewVisible() {
|
2010-07-22 22:41:58 -07:00
|
|
|
return gTabViewDeck.selectedIndex == 1;
|
2010-05-21 19:51:34 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-11-07 22:38:24 -08:00
|
|
|
// ---------
|
|
|
|
// Function: _initPageDirection
|
|
|
|
// Initializes the page base direction
|
|
|
|
_initPageDirection: function UI__initPageDirection() {
|
|
|
|
let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
|
|
|
getService(Ci.nsIXULChromeRegistry);
|
2010-11-10 19:48:42 -08:00
|
|
|
let dir = chromeReg.isLocaleRTL("global");
|
|
|
|
document.documentElement.setAttribute("dir", dir ? "rtl" : "ltr");
|
|
|
|
this.rtl = dir;
|
2010-11-07 22:38:24 -08:00
|
|
|
},
|
|
|
|
|
2010-07-16 17:27:01 -07:00
|
|
|
// ----------
|
2010-07-29 12:37:25 -07:00
|
|
|
// Function: showTabView
|
|
|
|
// Shows TabView and hides the main browser UI.
|
2010-07-23 00:03:40 -07:00
|
|
|
// Parameters:
|
|
|
|
// zoomOut - true for zoom out animation, false for nothing.
|
2010-09-08 10:02:08 -07:00
|
|
|
showTabView: function UI_showTabView(zoomOut) {
|
2010-11-30 00:15:51 -08:00
|
|
|
if (this.isTabViewVisible())
|
2010-08-04 17:12:08 -07:00
|
|
|
return;
|
|
|
|
|
2010-11-07 22:38:24 -08:00
|
|
|
// initialize the direction of the page
|
2010-11-07 22:38:24 -08:00
|
|
|
this._initPageDirection();
|
2010-11-07 22:38:24 -08:00
|
|
|
|
2010-08-08 10:28:24 -07:00
|
|
|
var self = this;
|
2010-07-23 00:03:40 -07:00
|
|
|
var currentTab = this._currentTab;
|
|
|
|
var item = null;
|
|
|
|
|
2010-08-06 15:46:55 -07:00
|
|
|
this._reorderTabItemsOnShow.forEach(function(groupItem) {
|
|
|
|
groupItem.reorderTabItemsBasedOnTabOrder();
|
2010-07-25 20:53:21 -07:00
|
|
|
});
|
|
|
|
this._reorderTabItemsOnShow = [];
|
|
|
|
|
2010-08-12 09:38:21 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// Restore the full height when showing TabView
|
2010-08-16 13:33:32 -07:00
|
|
|
gTabViewFrame.style.marginTop = "";
|
2010-08-12 09:38:21 -07:00
|
|
|
#endif
|
2010-07-22 22:41:58 -07:00
|
|
|
gTabViewDeck.selectedIndex = 1;
|
|
|
|
gTabViewFrame.contentWindow.focus();
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-22 12:34:13 -07:00
|
|
|
gBrowser.updateTitlebar();
|
2010-07-19 02:37:22 -07:00
|
|
|
#ifdef XP_MACOSX
|
2010-07-12 21:04:04 -07:00
|
|
|
this._setActiveTitleColor(true);
|
2010-07-19 02:37:22 -07:00
|
|
|
#endif
|
2010-08-04 17:12:08 -07:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("tabviewshown", true, false);
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-07-27 20:02:51 -07:00
|
|
|
if (zoomOut && currentTab && currentTab.tabItem) {
|
|
|
|
item = currentTab.tabItem;
|
|
|
|
// If there was a previous currentTab we want to animate
|
|
|
|
// its thumbnail (canvas) for the zoom out.
|
|
|
|
// Note that we start the animation on the chrome thread.
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-07-27 20:02:51 -07:00
|
|
|
// Zoom out!
|
|
|
|
item.zoomOut(function() {
|
|
|
|
if (!currentTab.tabItem) // if the tab's been destroyed
|
|
|
|
item = null;
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-07-27 20:02:51 -07:00
|
|
|
self.setActiveTab(item);
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-08-08 18:49:43 -07:00
|
|
|
if (item.parent) {
|
|
|
|
var activeGroupItem = GroupItems.getActiveGroupItem();
|
|
|
|
if (activeGroupItem)
|
|
|
|
activeGroupItem.setTopChild(item);
|
|
|
|
}
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-07-27 20:02:51 -07:00
|
|
|
self._resize(true);
|
2010-08-04 17:12:08 -07:00
|
|
|
dispatchEvent(event);
|
2010-07-27 20:02:51 -07:00
|
|
|
});
|
2010-09-24 16:22:35 -07:00
|
|
|
} else {
|
|
|
|
if (currentTab && currentTab.tabItem)
|
|
|
|
currentTab.tabItem.setZoomPrep(false);
|
|
|
|
|
|
|
|
self.setActiveTab(null);
|
2010-08-04 17:12:08 -07:00
|
|
|
dispatchEvent(event);
|
2010-09-24 16:22:35 -07:00
|
|
|
}
|
2010-08-04 16:42:36 -07:00
|
|
|
|
|
|
|
TabItems.resumePainting();
|
2010-05-21 19:51:34 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-16 17:27:01 -07:00
|
|
|
// ----------
|
2010-07-29 12:37:25 -07:00
|
|
|
// Function: hideTabView
|
|
|
|
// Hides TabView and shows the main browser UI.
|
2010-09-08 10:02:08 -07:00
|
|
|
hideTabView: function UI_hideTabView() {
|
2010-11-30 00:15:51 -08:00
|
|
|
if (!this.isTabViewVisible())
|
2010-08-04 17:12:08 -07:00
|
|
|
return;
|
|
|
|
|
2010-11-14 19:12:10 -08:00
|
|
|
// another tab might be select if user decides to stay on a page when
|
|
|
|
// a onclose confirmation prompts.
|
2010-09-10 07:40:27 -07:00
|
|
|
GroupItems.removeHiddenGroups();
|
2010-08-04 16:42:36 -07:00
|
|
|
TabItems.pausePainting();
|
|
|
|
|
2010-08-06 15:46:55 -07:00
|
|
|
this._reorderTabsOnHide.forEach(function(groupItem) {
|
|
|
|
groupItem.reorderTabsBasedOnTabItemOrder();
|
2010-07-25 20:53:21 -07:00
|
|
|
});
|
|
|
|
this._reorderTabsOnHide = [];
|
|
|
|
|
2010-08-12 09:38:21 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// Push the top of TabView frame to behind the tabbrowser, so glass can show
|
|
|
|
// XXX bug 586679: avoid shrinking the iframe and squishing iframe contents
|
|
|
|
// as well as avoiding the flash of black as we animate out
|
|
|
|
gTabViewFrame.style.marginTop = gBrowser.boxObject.y + "px";
|
|
|
|
#endif
|
2010-07-22 22:41:58 -07:00
|
|
|
gTabViewDeck.selectedIndex = 0;
|
2010-07-22 12:34:13 -07:00
|
|
|
gBrowser.contentWindow.focus();
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-22 12:34:13 -07:00
|
|
|
gBrowser.updateTitlebar();
|
2010-07-19 02:37:22 -07:00
|
|
|
#ifdef XP_MACOSX
|
2010-07-12 21:04:04 -07:00
|
|
|
this._setActiveTitleColor(false);
|
2010-07-19 02:37:22 -07:00
|
|
|
#endif
|
2010-08-04 17:12:08 -07:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("tabviewhidden", true, false);
|
|
|
|
dispatchEvent(event);
|
2010-07-12 21:04:04 -07:00
|
|
|
},
|
|
|
|
|
2010-07-19 02:37:22 -07:00
|
|
|
#ifdef XP_MACOSX
|
2010-07-16 17:27:01 -07:00
|
|
|
// ----------
|
|
|
|
// Function: _setActiveTitleColor
|
2010-07-18 08:58:10 -07:00
|
|
|
// Used on the Mac to make the title bar match the gradient in the rest of the
|
2010-07-29 12:37:25 -07:00
|
|
|
// TabView UI.
|
2010-07-18 08:58:10 -07:00
|
|
|
//
|
|
|
|
// Parameters:
|
2010-07-29 12:37:25 -07:00
|
|
|
// set - true for the special TabView color, false for the normal color.
|
2010-09-08 10:02:08 -07:00
|
|
|
_setActiveTitleColor: function UI__setActiveTitleColor(set) {
|
2010-05-21 19:51:34 -07:00
|
|
|
// Mac Only
|
2010-07-22 12:34:13 -07:00
|
|
|
var mainWindow = gWindow.document.getElementById("main-window");
|
2010-07-19 02:37:22 -07:00
|
|
|
if (set)
|
|
|
|
mainWindow.setAttribute("activetitlebarcolor", "#C4C4C4");
|
|
|
|
else
|
|
|
|
mainWindow.removeAttribute("activetitlebarcolor");
|
2010-04-30 23:50:43 -07:00
|
|
|
},
|
2010-07-19 02:37:22 -07:00
|
|
|
#endif
|
2010-06-23 02:25:34 -07:00
|
|
|
|
2010-07-16 17:27:01 -07:00
|
|
|
// ----------
|
2010-07-23 00:03:40 -07:00
|
|
|
// Function: _addTabActionHandlers
|
|
|
|
// Adds handlers to handle tab actions.
|
2010-09-08 10:02:08 -07:00
|
|
|
_addTabActionHandlers: function UI__addTabActionHandlers() {
|
2010-05-12 19:56:35 -07:00
|
|
|
var self = this;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-09-24 17:24:31 -07:00
|
|
|
// session restore
|
|
|
|
function srObserver(aSubject, aTopic, aData) {
|
|
|
|
if (aTopic != "sessionstore-browser-state-restored")
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if we're transitioning into/out of private browsing, update appropriately
|
|
|
|
if (self._privateBrowsing.transitionStage == 1)
|
|
|
|
self._privateBrowsing.transitionStage = 2;
|
|
|
|
else if (self._privateBrowsing.transitionStage == 3) {
|
|
|
|
if (self._privateBrowsing.transitionMode == "exit" &&
|
|
|
|
self._privateBrowsing.wasInTabView)
|
|
|
|
self.showTabView(false);
|
|
|
|
|
|
|
|
self._privateBrowsing.transitionStage = 0;
|
|
|
|
self._privateBrowsing.transitionMode = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.obs.addObserver(srObserver, "sessionstore-browser-state-restored", false);
|
|
|
|
|
|
|
|
this._cleanupFunctions.push(function() {
|
|
|
|
Services.obs.removeObserver(srObserver, "sessionstore-browser-state-restored");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Private Browsing:
|
|
|
|
// We keep track of the transition to/from PB with the transitionStage
|
|
|
|
// and transitionMode properties of _privateBrowsing. The stage is 0 if
|
|
|
|
// not transitioning, 1 if just started ("change-granted"), 2 after the
|
|
|
|
// first sessionrestore, 3 after the "private-browsing" notification, and
|
|
|
|
// then back to 0 after the second sessionrestore. The mode is "" if not
|
|
|
|
// transitioning, otherwise it's "enter" or "exit" as appropriate. When
|
|
|
|
// transitioning to PB, we exit Panorama if necessary (making note of the
|
|
|
|
// fact that we were there so we can return after PB) and make sure we
|
|
|
|
// don't reenter Panorama due to all of the session restore tab
|
|
|
|
// manipulation (which otherwise we might). When transitioning away from
|
|
|
|
// PB, we reenter Panorama if we had been there directly before PB.
|
|
|
|
function pbObserver(aSubject, aTopic, aData) {
|
|
|
|
if (aTopic == "private-browsing") {
|
|
|
|
self._privateBrowsing.transitionStage = 3;
|
|
|
|
if (aData == "enter") {
|
|
|
|
// If we are in Tab View, exit.
|
2010-11-30 00:15:51 -08:00
|
|
|
self._privateBrowsing.wasInTabView = self.isTabViewVisible();
|
|
|
|
if (self.isTabViewVisible())
|
2010-09-24 17:24:31 -07:00
|
|
|
self.goToTab(gBrowser.selectedTab);
|
|
|
|
}
|
|
|
|
} else if (aTopic == "private-browsing-change-granted") {
|
|
|
|
if (aData == "enter" || aData == "exit") {
|
|
|
|
self._privateBrowsing.transitionStage = 1;
|
|
|
|
self._privateBrowsing.transitionMode = aData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.obs.addObserver(pbObserver, "private-browsing", false);
|
|
|
|
Services.obs.addObserver(pbObserver, "private-browsing-change-granted", false);
|
|
|
|
|
|
|
|
this._cleanupFunctions.push(function() {
|
|
|
|
Services.obs.removeObserver(pbObserver, "private-browsing");
|
|
|
|
Services.obs.removeObserver(pbObserver, "private-browsing-change-granted");
|
|
|
|
});
|
|
|
|
|
2010-10-06 11:33:18 -07:00
|
|
|
// TabOpen
|
|
|
|
this._eventListeners.open = function(tab) {
|
|
|
|
if (tab.ownerDocument.defaultView != gWindow)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if it's an app tab, add it to all the group items
|
|
|
|
if (tab.pinned)
|
|
|
|
GroupItems.addAppTab(tab);
|
|
|
|
};
|
|
|
|
|
|
|
|
// TabClose
|
2010-08-31 00:22:10 -07:00
|
|
|
this._eventListeners.close = function(tab) {
|
2010-08-09 17:19:04 -07:00
|
|
|
if (tab.ownerDocument.defaultView != gWindow)
|
2010-07-28 14:20:41 -07:00
|
|
|
return;
|
|
|
|
|
2010-10-06 11:33:18 -07:00
|
|
|
// if it's an app tab, remove it from all the group items
|
|
|
|
if (tab.pinned)
|
|
|
|
GroupItems.removeAppTab(tab);
|
|
|
|
|
2010-11-30 00:15:51 -08:00
|
|
|
if (self.isTabViewVisible()) {
|
2010-07-29 12:37:25 -07:00
|
|
|
// just closed the selected tab in the TabView interface.
|
2010-08-09 17:19:04 -07:00
|
|
|
if (self._currentTab == tab)
|
2010-07-29 12:37:25 -07:00
|
|
|
self._closedSelectedTabInTabView = true;
|
2010-07-09 12:44:59 -07:00
|
|
|
} else {
|
2010-09-24 17:24:31 -07:00
|
|
|
// If we're currently in the process of entering private browsing,
|
|
|
|
// we don't want to go to the Tab View UI.
|
|
|
|
if (self._privateBrowsing.transitionStage > 0)
|
|
|
|
return;
|
|
|
|
|
2010-07-27 18:24:52 -07:00
|
|
|
// if not closing the last tab
|
|
|
|
if (gBrowser.tabs.length > 1) {
|
2010-09-16 00:51:24 -07:00
|
|
|
// Don't return to TabView if there are any app tabs
|
|
|
|
for (let a = 0; a < gBrowser.tabs.length; a++) {
|
|
|
|
let theTab = gBrowser.tabs[a];
|
|
|
|
if (theTab.pinned && gBrowser._removingTabs.indexOf(theTab) == -1)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-06 15:46:55 -07:00
|
|
|
var groupItem = GroupItems.getActiveGroupItem();
|
2010-07-28 22:06:03 -07:00
|
|
|
|
2010-07-29 12:37:25 -07:00
|
|
|
// 1) Only go back to the TabView tab when there you close the last
|
2010-08-06 15:46:55 -07:00
|
|
|
// tab of a groupItem.
|
2010-10-06 11:33:18 -07:00
|
|
|
let closingLastOfGroup = (groupItem &&
|
|
|
|
groupItem._children.length == 1 &&
|
|
|
|
groupItem._children[0].tab == tab);
|
|
|
|
|
2010-07-27 18:24:52 -07:00
|
|
|
// 2) Take care of the case where you've closed the last tab in
|
2010-08-06 15:46:55 -07:00
|
|
|
// an un-named groupItem, which means that the groupItem is gone (null) and
|
2010-10-06 11:33:18 -07:00
|
|
|
// there are no visible tabs.
|
|
|
|
let closingUnnamedGroup = (groupItem == null &&
|
|
|
|
gBrowser.visibleTabs.length <= 1);
|
|
|
|
|
|
|
|
if (closingLastOfGroup || closingUnnamedGroup) {
|
2010-07-28 22:06:03 -07:00
|
|
|
// for the tab focus event to pick up.
|
2010-07-27 18:24:52 -07:00
|
|
|
self._closedLastVisibleTab = true;
|
|
|
|
// remove the zoom prep.
|
2010-08-09 17:19:04 -07:00
|
|
|
if (tab && tab.tabItem)
|
|
|
|
tab.tabItem.setZoomPrep(false);
|
2010-07-29 12:37:25 -07:00
|
|
|
self.showTabView();
|
2010-07-06 18:50:15 -07:00
|
|
|
}
|
2010-07-09 12:02:32 -07:00
|
|
|
}
|
2010-07-06 18:50:15 -07:00
|
|
|
}
|
2010-08-31 00:22:10 -07:00
|
|
|
};
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-10-06 11:33:18 -07:00
|
|
|
// TabMove
|
2010-08-31 00:22:10 -07:00
|
|
|
this._eventListeners.move = function(tab) {
|
2010-08-09 17:19:04 -07:00
|
|
|
if (tab.ownerDocument.defaultView != gWindow)
|
2010-07-28 14:20:41 -07:00
|
|
|
return;
|
|
|
|
|
2010-08-15 21:46:22 -07:00
|
|
|
let activeGroupItem = GroupItems.getActiveGroupItem();
|
|
|
|
if (activeGroupItem)
|
|
|
|
self.setReorderTabItemsOnShow(activeGroupItem);
|
2010-08-31 00:22:10 -07:00
|
|
|
};
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-10-06 11:33:18 -07:00
|
|
|
// TabSelect
|
2010-08-31 00:22:10 -07:00
|
|
|
this._eventListeners.select = function(tab) {
|
2010-08-09 17:19:04 -07:00
|
|
|
if (tab.ownerDocument.defaultView != gWindow)
|
2010-07-28 14:20:41 -07:00
|
|
|
return;
|
|
|
|
|
2010-08-17 07:13:45 -07:00
|
|
|
self.onTabSelect(tab);
|
2010-08-31 00:22:10 -07:00
|
|
|
};
|
|
|
|
|
2010-11-09 19:39:31 -08:00
|
|
|
// TabPinned
|
|
|
|
this._eventListeners.pinned = function(tab) {
|
|
|
|
if (tab.ownerDocument.defaultView != gWindow)
|
|
|
|
return;
|
2010-09-12 20:45:02 -07:00
|
|
|
|
2010-11-09 19:39:31 -08:00
|
|
|
TabItems.handleTabPin(tab);
|
|
|
|
GroupItems.addAppTab(tab);
|
|
|
|
};
|
2010-09-12 20:45:02 -07:00
|
|
|
|
2010-11-09 19:39:31 -08:00
|
|
|
// TabUnpinned
|
|
|
|
this._eventListeners.unpinned = function(tab) {
|
|
|
|
if (tab.ownerDocument.defaultView != gWindow)
|
|
|
|
return;
|
2010-09-12 20:45:02 -07:00
|
|
|
|
2010-11-09 19:39:31 -08:00
|
|
|
TabItems.handleTabUnpin(tab);
|
|
|
|
GroupItems.removeAppTab(tab);
|
|
|
|
};
|
2010-09-12 20:45:02 -07:00
|
|
|
|
2010-11-09 19:39:31 -08:00
|
|
|
// Actually register the above handlers
|
|
|
|
for (let name in this._eventListeners)
|
|
|
|
AllTabs.register(name, this._eventListeners[name]);
|
2010-08-31 00:22:10 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: _removeTabActionHandlers
|
|
|
|
// Removes handlers to handle tab actions.
|
2010-09-08 10:02:08 -07:00
|
|
|
_removeTabActionHandlers: function UI__removeTabActionHandlers() {
|
2010-08-31 00:22:10 -07:00
|
|
|
for (let name in this._eventListeners)
|
|
|
|
AllTabs.unregister(name, this._eventListeners[name]);
|
2010-07-02 02:28:53 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-09-10 02:50:14 -07:00
|
|
|
// ----------
|
2010-11-14 19:12:10 -08:00
|
|
|
// Function: goToTab
|
2010-09-10 02:50:14 -07:00
|
|
|
// Selects the given xul:tab in the browser.
|
|
|
|
goToTab: function UI_goToTab(xulTab) {
|
|
|
|
// If it's not focused, the onFocus listener would handle it.
|
|
|
|
if (gBrowser.selectedTab == xulTab)
|
|
|
|
this.onTabSelect(xulTab);
|
|
|
|
else
|
|
|
|
gBrowser.selectedTab = xulTab;
|
|
|
|
},
|
|
|
|
|
2010-07-18 08:58:10 -07:00
|
|
|
// ----------
|
2010-08-17 07:13:45 -07:00
|
|
|
// Function: onTabSelect
|
2010-07-29 12:37:25 -07:00
|
|
|
// Called when the user switches from one tab to another outside of the TabView UI.
|
2010-09-08 10:02:08 -07:00
|
|
|
onTabSelect: function UI_onTabSelect(tab) {
|
2010-08-17 07:13:45 -07:00
|
|
|
let currentTab = this._currentTab;
|
|
|
|
this._currentTab = tab;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-09 12:02:32 -07:00
|
|
|
// if the last visible tab has just been closed, don't show the chrome UI.
|
2010-11-30 00:15:51 -08:00
|
|
|
if (this.isTabViewVisible() &&
|
2010-11-29 21:03:51 -08:00
|
|
|
(this._closedLastVisibleTab || this._closedSelectedTabInTabView ||
|
|
|
|
this.restoredClosedTab)) {
|
|
|
|
if (this.restoredClosedTab) {
|
|
|
|
// when the tab view UI is being displayed, update the thumb for the
|
|
|
|
// restored closed tab after the page load
|
|
|
|
tab.linkedBrowser.addEventListener("load", function (event) {
|
|
|
|
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
|
|
|
|
TabItems._update(tab);
|
|
|
|
}, true);
|
|
|
|
}
|
2010-07-19 22:26:27 -07:00
|
|
|
this._closedLastVisibleTab = false;
|
2010-07-29 12:37:25 -07:00
|
|
|
this._closedSelectedTabInTabView = false;
|
2010-11-29 21:03:51 -08:00
|
|
|
this.restoredClosedTab = false;
|
2010-07-18 08:58:10 -07:00
|
|
|
return;
|
2010-07-09 12:44:59 -07:00
|
|
|
}
|
2010-08-17 07:13:45 -07:00
|
|
|
// reset these vars, just in case.
|
|
|
|
this._closedLastVisibleTab = false;
|
|
|
|
this._closedSelectedTabInTabView = false;
|
2010-11-29 21:03:51 -08:00
|
|
|
this.restoredClosedTab = false;
|
2010-07-13 12:07:24 -07:00
|
|
|
|
2010-07-29 12:37:25 -07:00
|
|
|
// if TabView is visible but we didn't just close the last tab or
|
2010-07-16 00:00:20 -07:00
|
|
|
// selected tab, show chrome.
|
2010-11-30 00:15:51 -08:00
|
|
|
if (this.isTabViewVisible())
|
2010-07-29 12:37:25 -07:00
|
|
|
this.hideTabView();
|
2010-07-13 12:07:24 -07:00
|
|
|
|
2010-11-14 19:12:10 -08:00
|
|
|
// another tab might be selected when hideTabView() is invoked so a
|
|
|
|
// validation is needed.
|
|
|
|
if (this._currentTab != tab)
|
|
|
|
return;
|
|
|
|
|
2010-08-15 21:46:22 -07:00
|
|
|
let oldItem = null;
|
2010-08-17 07:13:45 -07:00
|
|
|
let newItem = null;
|
2010-09-10 02:50:14 -07:00
|
|
|
|
2010-08-15 21:46:22 -07:00
|
|
|
if (currentTab && currentTab.tabItem)
|
|
|
|
oldItem = currentTab.tabItem;
|
2010-11-29 18:02:22 -08:00
|
|
|
|
2010-09-24 16:22:35 -07:00
|
|
|
// update the tab bar for the new tab's group
|
2010-08-17 07:13:45 -07:00
|
|
|
if (tab && tab.tabItem) {
|
|
|
|
newItem = tab.tabItem;
|
|
|
|
GroupItems.updateActiveGroupItemAndTabBar(newItem);
|
2010-09-24 16:22:35 -07:00
|
|
|
} else {
|
|
|
|
// No tabItem; must be an app tab. Base the tab bar on the current group.
|
|
|
|
// If no current group or orphan tab, figure it out based on what's
|
|
|
|
// already in the tab bar.
|
|
|
|
if (!GroupItems.getActiveGroupItem() && !GroupItems.getActiveOrphanTab()) {
|
|
|
|
for (let a = 0; a < gBrowser.tabs.length; a++) {
|
|
|
|
let theTab = gBrowser.tabs[a];
|
|
|
|
if (!theTab.pinned) {
|
|
|
|
let tabItem = theTab.tabItem;
|
|
|
|
if (tabItem.parent)
|
|
|
|
GroupItems.setActiveGroupItem(tabItem.parent);
|
|
|
|
else
|
|
|
|
GroupItems.setActiveOrphanTab(tabItem);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GroupItems.getActiveGroupItem() || GroupItems.getActiveOrphanTab())
|
|
|
|
GroupItems._updateTabBar();
|
2010-08-17 07:13:45 -07:00
|
|
|
}
|
2010-07-13 12:07:24 -07:00
|
|
|
|
2010-08-17 07:13:45 -07:00
|
|
|
// ___ prepare for when we return to TabView
|
2010-08-15 21:46:22 -07:00
|
|
|
if (newItem != oldItem) {
|
|
|
|
if (oldItem)
|
|
|
|
oldItem.setZoomPrep(false);
|
2010-08-17 07:13:45 -07:00
|
|
|
if (newItem)
|
2010-08-15 21:46:22 -07:00
|
|
|
newItem.setZoomPrep(true);
|
2010-08-17 07:13:45 -07:00
|
|
|
} else if (oldItem)
|
|
|
|
oldItem.setZoomPrep(true);
|
2010-07-01 22:27:49 -07:00
|
|
|
},
|
2010-07-16 00:00:20 -07:00
|
|
|
|
2010-07-25 20:53:21 -07:00
|
|
|
// ----------
|
|
|
|
// Function: setReorderTabsOnHide
|
2010-08-06 15:46:55 -07:00
|
|
|
// Sets the groupItem which the tab items' tabs should be re-ordered when
|
2010-07-25 20:53:21 -07:00
|
|
|
// switching to the main browser UI.
|
|
|
|
// Parameters:
|
2010-08-06 15:46:55 -07:00
|
|
|
// groupItem - the groupItem which would be used for re-ordering tabs.
|
2010-09-08 10:02:08 -07:00
|
|
|
setReorderTabsOnHide: function UI_setReorderTabsOnHide(groupItem) {
|
2010-11-30 00:15:51 -08:00
|
|
|
if (this.isTabViewVisible()) {
|
2010-08-06 15:46:55 -07:00
|
|
|
var index = this._reorderTabsOnHide.indexOf(groupItem);
|
2010-07-25 20:53:21 -07:00
|
|
|
if (index == -1)
|
2010-08-06 15:46:55 -07:00
|
|
|
this._reorderTabsOnHide.push(groupItem);
|
2010-07-25 20:53:21 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-08-06 07:17:01 -07:00
|
|
|
// ----------
|
|
|
|
// Function: setReorderTabItemsOnShow
|
2010-08-06 15:46:55 -07:00
|
|
|
// Sets the groupItem which the tab items should be re-ordered when
|
2010-08-06 07:17:01 -07:00
|
|
|
// switching to the tab view UI.
|
|
|
|
// Parameters:
|
2010-08-06 15:46:55 -07:00
|
|
|
// groupItem - the groupItem which would be used for re-ordering tab items.
|
2010-09-08 10:02:08 -07:00
|
|
|
setReorderTabItemsOnShow: function UI_setReorderTabItemsOnShow(groupItem) {
|
2010-11-30 00:15:51 -08:00
|
|
|
if (!this.isTabViewVisible()) {
|
2010-08-06 15:46:55 -07:00
|
|
|
var index = this._reorderTabItemsOnShow.indexOf(groupItem);
|
2010-08-06 07:17:01 -07:00
|
|
|
if (index == -1)
|
2010-08-06 15:46:55 -07:00
|
|
|
this._reorderTabItemsOnShow.push(groupItem);
|
2010-08-06 07:17:01 -07:00
|
|
|
}
|
|
|
|
},
|
2010-09-10 14:51:14 -07:00
|
|
|
|
|
|
|
// ----------
|
2010-11-23 09:28:02 -08:00
|
|
|
updateTabButton: function UI__updateTabButton() {
|
2010-09-10 14:51:14 -07:00
|
|
|
let groupsNumber = gWindow.document.getElementById("tabviewGroupsNumber");
|
2010-11-23 09:28:02 -08:00
|
|
|
let exitButton = document.getElementById("exit-button");
|
2010-09-10 14:51:14 -07:00
|
|
|
let numberOfGroups = GroupItems.groupItems.length;
|
2010-11-23 09:28:02 -08:00
|
|
|
|
2010-09-10 14:51:14 -07:00
|
|
|
groupsNumber.setAttribute("groups", numberOfGroups);
|
2010-11-23 09:28:02 -08:00
|
|
|
exitButton.setAttribute("groups", numberOfGroups);
|
2010-09-10 14:51:14 -07:00
|
|
|
},
|
2010-08-06 07:17:01 -07:00
|
|
|
|
2010-09-27 16:12:00 -07:00
|
|
|
// ----------
|
|
|
|
// Function: getClosestTab
|
|
|
|
// Convenience function to get the next tab closest to the entered position
|
|
|
|
getClosestTab: function UI_getClosestTab(tabCenter) {
|
|
|
|
let cl = null;
|
|
|
|
let clDist;
|
|
|
|
for each(item in TabItems.getItems()) {
|
|
|
|
if (item.parent && item.parent.hidden) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let testDist = tabCenter.distance(item.bounds.center());
|
|
|
|
if (cl==null || testDist < clDist) {
|
|
|
|
cl = item;
|
|
|
|
clDist = testDist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cl;
|
|
|
|
},
|
|
|
|
|
2010-04-26 16:48:46 -07:00
|
|
|
// ----------
|
2010-07-23 00:03:40 -07:00
|
|
|
// Function: _setTabViewFrameKeyHandlers
|
2010-07-29 12:37:25 -07:00
|
|
|
// Sets up the key handlers for navigating between tabs within the TabView UI.
|
2010-09-08 10:02:08 -07:00
|
|
|
_setTabViewFrameKeyHandlers: function UI__setTabViewFrameKeyHandlers() {
|
2010-07-23 00:03:40 -07:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
iQ(window).keyup(function(event) {
|
2010-11-17 02:49:59 -08:00
|
|
|
if (!event.metaKey)
|
|
|
|
Keys.meta = false;
|
2010-07-23 00:03:40 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
iQ(window).keydown(function(event) {
|
2010-11-17 02:49:59 -08:00
|
|
|
if (event.metaKey)
|
|
|
|
Keys.meta = true;
|
|
|
|
|
2010-11-23 09:57:30 -08:00
|
|
|
if ((iQ(":focus").length > 0 && iQ(":focus")[0].nodeName == "INPUT") ||
|
|
|
|
isSearchEnabled())
|
2010-11-17 02:49:59 -08:00
|
|
|
return;
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-07-30 02:54:30 -07:00
|
|
|
function getClosestTabBy(norm) {
|
2010-09-24 16:22:35 -07:00
|
|
|
if (!self.getActiveTab())
|
|
|
|
return null;
|
2010-07-23 00:03:40 -07:00
|
|
|
var centers =
|
2010-09-12 20:45:02 -07:00
|
|
|
[[item.bounds.center(), item]
|
2010-09-10 07:40:27 -07:00
|
|
|
for each(item in TabItems.getItems()) if (!item.parent || !item.parent.hidden)];
|
2010-07-23 00:03:40 -07:00
|
|
|
var myCenter = self.getActiveTab().bounds.center();
|
|
|
|
var matches = centers
|
|
|
|
.filter(function(item){return norm(item[0], myCenter)})
|
|
|
|
.sort(function(a,b){
|
|
|
|
return myCenter.distance(a[0]) - myCenter.distance(b[0]);
|
|
|
|
});
|
2010-07-30 02:54:30 -07:00
|
|
|
if (matches.length > 0)
|
2010-07-23 00:03:40 -07:00
|
|
|
return matches[0][1];
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var norm = null;
|
2010-08-13 00:18:29 -07:00
|
|
|
switch (event.keyCode) {
|
|
|
|
case KeyEvent.DOM_VK_RIGHT:
|
2010-07-23 00:03:40 -07:00
|
|
|
norm = function(a, me){return a.x > me.x};
|
|
|
|
break;
|
2010-08-13 00:18:29 -07:00
|
|
|
case KeyEvent.DOM_VK_LEFT:
|
2010-07-23 00:03:40 -07:00
|
|
|
norm = function(a, me){return a.x < me.x};
|
|
|
|
break;
|
2010-08-13 00:18:29 -07:00
|
|
|
case KeyEvent.DOM_VK_DOWN:
|
2010-07-23 00:03:40 -07:00
|
|
|
norm = function(a, me){return a.y > me.y};
|
|
|
|
break;
|
2010-08-13 00:18:29 -07:00
|
|
|
case KeyEvent.DOM_VK_UP:
|
2010-07-23 00:03:40 -07:00
|
|
|
norm = function(a, me){return a.y < me.y}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (norm != null) {
|
|
|
|
var nextTab = getClosestTabBy(norm);
|
|
|
|
if (nextTab) {
|
|
|
|
if (nextTab.inStack() && !nextTab.parent.expanded)
|
|
|
|
nextTab = nextTab.parent.getChild(0);
|
|
|
|
self.setActiveTab(nextTab);
|
|
|
|
}
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2010-09-24 16:22:35 -07:00
|
|
|
} else if (event.keyCode == KeyEvent.DOM_VK_ESCAPE) {
|
2010-08-19 02:13:58 -07:00
|
|
|
let activeGroupItem = GroupItems.getActiveGroupItem();
|
2010-09-24 16:22:35 -07:00
|
|
|
if (activeGroupItem && activeGroupItem.expanded)
|
2010-08-19 02:13:58 -07:00
|
|
|
activeGroupItem.collapse();
|
2010-09-24 16:22:35 -07:00
|
|
|
else
|
|
|
|
self.exit();
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
} else if (event.keyCode == KeyEvent.DOM_VK_RETURN ||
|
|
|
|
event.keyCode == KeyEvent.DOM_VK_ENTER) {
|
|
|
|
let activeTab = self.getActiveTab();
|
|
|
|
if (activeTab)
|
2010-11-14 19:12:10 -08:00
|
|
|
activeTab.zoomIn();
|
2010-08-19 02:13:58 -07:00
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2010-08-13 00:18:29 -07:00
|
|
|
} else if (event.keyCode == KeyEvent.DOM_VK_TAB) {
|
2010-07-23 00:03:40 -07:00
|
|
|
// tab/shift + tab to go to the next tab.
|
|
|
|
var activeTab = self.getActiveTab();
|
|
|
|
if (activeTab) {
|
|
|
|
var tabItems = (activeTab.parent ? activeTab.parent.getChildren() :
|
2010-08-08 18:49:43 -07:00
|
|
|
[activeTab]);
|
2010-07-23 00:03:40 -07:00
|
|
|
var length = tabItems.length;
|
|
|
|
var currentIndex = tabItems.indexOf(activeTab);
|
|
|
|
|
|
|
|
if (length > 1) {
|
|
|
|
if (event.shiftKey) {
|
|
|
|
if (currentIndex == 0)
|
|
|
|
newIndex = (length - 1);
|
|
|
|
else
|
|
|
|
newIndex = (currentIndex - 1);
|
|
|
|
} else {
|
|
|
|
if (currentIndex == (length - 1))
|
|
|
|
newIndex = 0;
|
|
|
|
else
|
|
|
|
newIndex = (currentIndex + 1);
|
|
|
|
}
|
|
|
|
self.setActiveTab(tabItems[newIndex]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2010-11-23 23:55:18 -08:00
|
|
|
} else if (event.keyCode == KeyEvent.DOM_VK_SLASH) {
|
|
|
|
// the / event handler for find bar is defined in the findbar.xml
|
|
|
|
// binding. To keep things in its own module, we handle our slash here.
|
|
|
|
self.enableSearch(event);
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-11-23 23:55:18 -08:00
|
|
|
// ----------
|
|
|
|
// Function: enableSearch
|
|
|
|
// Enables the search feature.
|
|
|
|
// Parameters:
|
|
|
|
// event - the event triggers this action.
|
|
|
|
enableSearch: function UI_enableSearch(event) {
|
|
|
|
if (!isSearchEnabled()) {
|
|
|
|
ensureSearchShown(null);
|
|
|
|
SearchEventHandler.switchToInMode();
|
|
|
|
|
|
|
|
if (event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
// ----------
|
2010-08-06 15:46:55 -07:00
|
|
|
// Function: _createGroupItemOnDrag
|
2010-07-29 12:37:25 -07:00
|
|
|
// Called in response to a mousedown in empty space in the TabView UI;
|
2010-08-06 15:46:55 -07:00
|
|
|
// creates a new groupItem based on the user's drag.
|
2010-09-08 10:02:08 -07:00
|
|
|
_createGroupItemOnDrag: function UI__createGroupItemOnDrag(e) {
|
2010-07-23 00:03:40 -07:00
|
|
|
const minSize = 60;
|
|
|
|
const minMinSize = 15;
|
|
|
|
|
2010-08-08 18:49:43 -07:00
|
|
|
let lastActiveGroupItem = GroupItems.getActiveGroupItem();
|
|
|
|
GroupItems.setActiveGroupItem(null);
|
2010-08-08 17:27:47 -07:00
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
var startPos = { x: e.clientX, y: e.clientY };
|
|
|
|
var phantom = iQ("<div>")
|
2010-08-08 17:27:47 -07:00
|
|
|
.addClass("groupItem phantom activeGroupItem")
|
2010-07-23 00:03:40 -07:00
|
|
|
.css({
|
|
|
|
position: "absolute",
|
|
|
|
opacity: .7,
|
|
|
|
zIndex: -1,
|
|
|
|
cursor: "default"
|
|
|
|
})
|
|
|
|
.appendTo("body");
|
|
|
|
|
|
|
|
var item = { // a faux-Item
|
|
|
|
container: phantom,
|
|
|
|
isAFauxItem: true,
|
|
|
|
bounds: {},
|
|
|
|
getBounds: function FauxItem_getBounds() {
|
|
|
|
return this.container.bounds();
|
|
|
|
},
|
|
|
|
setBounds: function FauxItem_setBounds(bounds) {
|
|
|
|
this.container.css(bounds);
|
|
|
|
},
|
|
|
|
setZ: function FauxItem_setZ(z) {
|
|
|
|
this.container.css("z-index", z);
|
|
|
|
},
|
2010-07-30 02:54:30 -07:00
|
|
|
setOpacity: function FauxItem_setOpacity(opacity) {
|
2010-07-23 00:03:40 -07:00
|
|
|
this.container.css("opacity", opacity);
|
|
|
|
},
|
|
|
|
// we don't need to pushAway the phantom item at the end, because
|
2010-08-06 15:46:55 -07:00
|
|
|
// when we create a new GroupItem, it'll do the actual pushAway.
|
2010-07-23 00:03:40 -07:00
|
|
|
pushAway: function () {},
|
|
|
|
};
|
|
|
|
item.setBounds(new Rect(startPos.y, startPos.x, 0, 0));
|
|
|
|
|
2010-11-24 13:19:47 -08:00
|
|
|
var dragOutInfo = new Drag(item, e);
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-07-30 02:54:30 -07:00
|
|
|
function updateSize(e) {
|
2010-07-23 00:03:40 -07:00
|
|
|
var box = new Rect();
|
|
|
|
box.left = Math.min(startPos.x, e.clientX);
|
|
|
|
box.right = Math.max(startPos.x, e.clientX);
|
|
|
|
box.top = Math.min(startPos.y, e.clientY);
|
|
|
|
box.bottom = Math.max(startPos.y, e.clientY);
|
|
|
|
item.setBounds(box);
|
|
|
|
|
|
|
|
// compute the stationaryCorner
|
|
|
|
var stationaryCorner = "";
|
|
|
|
|
|
|
|
if (startPos.y == box.top)
|
|
|
|
stationaryCorner += "top";
|
|
|
|
else
|
|
|
|
stationaryCorner += "bottom";
|
|
|
|
|
|
|
|
if (startPos.x == box.left)
|
|
|
|
stationaryCorner += "left";
|
|
|
|
else
|
|
|
|
stationaryCorner += "right";
|
|
|
|
|
|
|
|
dragOutInfo.snap(stationaryCorner, false, false); // null for ui, which we don't use anyway.
|
|
|
|
|
|
|
|
box = item.getBounds();
|
2010-08-10 16:20:05 -07:00
|
|
|
if (box.width > minMinSize && box.height > minMinSize &&
|
|
|
|
(box.width > minSize || box.height > minSize))
|
2010-07-23 00:03:40 -07:00
|
|
|
item.setOpacity(1);
|
|
|
|
else
|
|
|
|
item.setOpacity(0.7);
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
function collapse() {
|
2010-11-09 17:50:41 -08:00
|
|
|
let center = phantom.bounds().center();
|
2010-07-23 00:03:40 -07:00
|
|
|
phantom.animate({
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
2010-11-09 17:50:41 -08:00
|
|
|
top: center.y,
|
|
|
|
left: center.x
|
2010-07-23 00:03:40 -07:00
|
|
|
}, {
|
|
|
|
duration: 300,
|
|
|
|
complete: function() {
|
|
|
|
phantom.remove();
|
|
|
|
}
|
|
|
|
});
|
2010-08-08 17:27:47 -07:00
|
|
|
GroupItems.setActiveGroupItem(lastActiveGroupItem);
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function finalize(e) {
|
|
|
|
iQ(window).unbind("mousemove", updateSize);
|
|
|
|
dragOutInfo.stop();
|
|
|
|
if (phantom.css("opacity") != 1)
|
|
|
|
collapse();
|
|
|
|
else {
|
|
|
|
var bounds = item.getBounds();
|
|
|
|
|
2010-08-06 15:46:55 -07:00
|
|
|
// Add all of the orphaned tabs that are contained inside the new groupItem
|
|
|
|
// to that groupItem.
|
|
|
|
var tabs = GroupItems.getOrphanedTabs();
|
2010-07-23 00:03:40 -07:00
|
|
|
var insideTabs = [];
|
|
|
|
for each(tab in tabs) {
|
|
|
|
if (bounds.contains(tab.bounds))
|
|
|
|
insideTabs.push(tab);
|
|
|
|
}
|
|
|
|
|
2010-08-06 15:46:55 -07:00
|
|
|
var groupItem = new GroupItem(insideTabs,{bounds:bounds});
|
2010-08-08 17:27:47 -07:00
|
|
|
GroupItems.setActiveGroupItem(groupItem);
|
2010-07-23 00:03:40 -07:00
|
|
|
phantom.remove();
|
|
|
|
dragOutInfo = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iQ(window).mousemove(updateSize)
|
|
|
|
iQ(gWindow).one("mouseup", finalize);
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: _resize
|
2010-07-29 12:37:25 -07:00
|
|
|
// Update the TabView UI contents in response to a window size change.
|
2010-07-18 08:58:10 -07:00
|
|
|
// Won't do anything if it doesn't deem the resize necessary.
|
|
|
|
// Parameters:
|
2010-07-16 17:27:01 -07:00
|
|
|
// force - true to update even when "unnecessary"; default false
|
2010-09-08 10:02:08 -07:00
|
|
|
_resize: function UI__resize(force) {
|
2010-08-10 16:20:05 -07:00
|
|
|
if (typeof force == "undefined")
|
2010-07-23 00:03:40 -07:00
|
|
|
force = false;
|
2010-05-21 19:51:34 -07:00
|
|
|
|
2010-10-09 12:46:18 -07:00
|
|
|
if (!this._pageBounds)
|
|
|
|
return;
|
|
|
|
|
2010-07-29 12:37:25 -07:00
|
|
|
// If TabView isn't focused and is not showing, don't perform a resize.
|
2010-07-19 22:26:27 -07:00
|
|
|
// This resize really slows things down.
|
2010-11-30 00:15:51 -08:00
|
|
|
if (!force && !this.isTabViewVisible())
|
2010-07-11 18:08:33 -07:00
|
|
|
return;
|
2010-07-03 18:41:31 -07:00
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
var oldPageBounds = new Rect(this._pageBounds);
|
2010-07-03 18:41:31 -07:00
|
|
|
var newPageBounds = Items.getPageBounds();
|
|
|
|
if (newPageBounds.equals(oldPageBounds))
|
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-26 16:48:46 -07:00
|
|
|
var items = Items.getTopLevelItems();
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-03 18:41:31 -07:00
|
|
|
// compute itemBounds: the union of all the top-level items' bounds.
|
2010-07-23 00:03:40 -07:00
|
|
|
var itemBounds = new Rect(this._pageBounds);
|
|
|
|
// We start with pageBounds so that we respect the empty space the user
|
|
|
|
// has left on the page.
|
2010-04-26 16:48:46 -07:00
|
|
|
itemBounds.width = 1;
|
|
|
|
itemBounds.height = 1;
|
2010-07-13 16:38:51 -07:00
|
|
|
items.forEach(function(item) {
|
2010-07-11 17:54:42 -07:00
|
|
|
if (item.locked.bounds)
|
2010-04-26 16:48:46 -07:00
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-26 16:48:46 -07:00
|
|
|
var bounds = item.getBounds();
|
|
|
|
itemBounds = (itemBounds ? itemBounds.union(bounds) : new Rect(bounds));
|
|
|
|
});
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
if (newPageBounds.width < this._pageBounds.width &&
|
|
|
|
newPageBounds.width > itemBounds.width)
|
|
|
|
newPageBounds.width = this._pageBounds.width;
|
2010-04-26 16:48:46 -07:00
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
if (newPageBounds.height < this._pageBounds.height &&
|
|
|
|
newPageBounds.height > itemBounds.height)
|
|
|
|
newPageBounds.height = this._pageBounds.height;
|
2010-04-26 16:48:46 -07:00
|
|
|
|
|
|
|
var wScale;
|
|
|
|
var hScale;
|
2010-07-30 02:54:30 -07:00
|
|
|
if (Math.abs(newPageBounds.width - this._pageBounds.width)
|
|
|
|
> Math.abs(newPageBounds.height - this._pageBounds.height)) {
|
2010-07-23 00:03:40 -07:00
|
|
|
wScale = newPageBounds.width / this._pageBounds.width;
|
2010-04-26 16:48:46 -07:00
|
|
|
hScale = newPageBounds.height / itemBounds.height;
|
|
|
|
} else {
|
|
|
|
wScale = newPageBounds.width / itemBounds.width;
|
2010-07-23 00:03:40 -07:00
|
|
|
hScale = newPageBounds.height / this._pageBounds.height;
|
2010-04-26 16:48:46 -07:00
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-26 16:48:46 -07:00
|
|
|
var scale = Math.min(hScale, wScale);
|
|
|
|
var self = this;
|
2010-05-07 15:49:54 -07:00
|
|
|
var pairs = [];
|
2010-07-13 16:38:51 -07:00
|
|
|
items.forEach(function(item) {
|
2010-07-11 17:54:42 -07:00
|
|
|
if (item.locked.bounds)
|
2010-04-26 16:48:46 -07:00
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-04-26 16:48:46 -07:00
|
|
|
var bounds = item.getBounds();
|
2010-11-07 22:38:24 -08:00
|
|
|
bounds.left += (UI.rtl ? -1 : 1) * (newPageBounds.left - self._pageBounds.left);
|
2010-04-26 16:48:46 -07:00
|
|
|
bounds.left *= scale;
|
|
|
|
bounds.width *= scale;
|
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
bounds.top += newPageBounds.top - self._pageBounds.top;
|
2010-04-26 16:48:46 -07:00
|
|
|
bounds.top *= scale;
|
|
|
|
bounds.height *= scale;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-07 15:49:54 -07:00
|
|
|
pairs.push({
|
|
|
|
item: item,
|
|
|
|
bounds: bounds
|
|
|
|
});
|
2010-04-26 16:48:46 -07:00
|
|
|
});
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-07 15:49:54 -07:00
|
|
|
Items.unsquish(pairs);
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-13 16:38:51 -07:00
|
|
|
pairs.forEach(function(pair) {
|
2010-05-07 15:49:54 -07:00
|
|
|
pair.item.setBounds(pair.bounds, true);
|
2010-07-03 18:41:31 -07:00
|
|
|
pair.item.snap();
|
2010-05-07 15:49:54 -07:00
|
|
|
});
|
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
this._pageBounds = Items.getPageBounds();
|
2010-07-19 22:26:27 -07:00
|
|
|
this._save();
|
2010-04-26 16:48:46 -07:00
|
|
|
},
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-09-10 07:51:08 -07:00
|
|
|
// ----------
|
2010-09-24 16:22:35 -07:00
|
|
|
// Function: exit
|
2010-09-10 07:51:08 -07:00
|
|
|
// Exits TabView UI.
|
2010-09-24 16:22:35 -07:00
|
|
|
exit: function UI_exit() {
|
|
|
|
let self = this;
|
2010-11-23 23:55:18 -08:00
|
|
|
let zoomedIn = false;
|
|
|
|
|
|
|
|
if (isSearchEnabled()) {
|
|
|
|
let matcher = createSearchTabMacher();
|
|
|
|
let matches = matcher.matched();
|
|
|
|
|
|
|
|
if (matches.length > 0) {
|
|
|
|
matches[0].zoomIn();
|
|
|
|
zoomedIn = true;
|
|
|
|
}
|
|
|
|
hideSearch(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!zoomedIn) {
|
2010-11-29 18:02:22 -08:00
|
|
|
let unhiddenGroups = GroupItems.groupItems.filter(function(groupItem) {
|
|
|
|
return (!groupItem.hidden && groupItem.getChildren().length > 0);
|
|
|
|
});
|
|
|
|
// no visible groups, no orphaned tabs and no apps tabs, open a new group
|
|
|
|
// with a blank tab
|
|
|
|
if (unhiddenGroups.length == 0 && GroupItems.getOrphanedTabs().length == 0 &&
|
|
|
|
gBrowser._numPinnedTabs == 0) {
|
|
|
|
let box = new Rect(20, 20, 250, 200);
|
|
|
|
let groupItem = new GroupItem([], { bounds: box, immediately: true });
|
|
|
|
groupItem.newTab();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-23 23:55:18 -08:00
|
|
|
// If there's an active TabItem, zoom into it. If not (for instance when the
|
|
|
|
// selected tab is an app tab), just go there.
|
|
|
|
let activeTabItem = this.getActiveTab();
|
2010-11-29 18:02:22 -08:00
|
|
|
if (!activeTabItem) {
|
|
|
|
let tabItem = gBrowser.selectedTab.tabItem;
|
|
|
|
if (tabItem) {
|
|
|
|
if (!tabItem.parent || !tabItem.parent.hidden) {
|
|
|
|
activeTabItem = tabItem;
|
|
|
|
} else { // set active tab item if there is at least one unhidden group
|
|
|
|
if (unhiddenGroups.length > 0)
|
|
|
|
activeTabItem = unhiddenGroups[0].getActiveTab();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-23 23:55:18 -08:00
|
|
|
|
2010-11-29 18:02:22 -08:00
|
|
|
if (activeTabItem) {
|
2010-11-23 23:55:18 -08:00
|
|
|
activeTabItem.zoomIn();
|
2010-11-29 18:02:22 -08:00
|
|
|
} else {
|
|
|
|
if (gBrowser._numPinnedTabs > 0) {
|
|
|
|
if (gBrowser.selectedTab.pinned) {
|
|
|
|
self.goToTab(gBrowser.selectedTab);
|
|
|
|
} else {
|
|
|
|
Array.some(gBrowser.tabs, function(tab) {
|
|
|
|
if (tab.pinned) {
|
|
|
|
self.goToTab(tab);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-23 23:55:18 -08:00
|
|
|
}
|
2010-09-10 07:51:08 -07:00
|
|
|
},
|
|
|
|
|
2010-05-03 15:32:11 -07:00
|
|
|
// ----------
|
2010-07-16 17:27:01 -07:00
|
|
|
// Function: storageSanity
|
2010-07-18 08:58:10 -07:00
|
|
|
// Given storage data for this object, returns true if it looks valid.
|
2010-09-08 10:02:08 -07:00
|
|
|
_storageSanity: function UI__storageSanity(data) {
|
2010-07-23 14:33:02 -07:00
|
|
|
if (Utils.isEmptyObject(data))
|
2010-05-11 17:22:06 -07:00
|
|
|
return true;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-22 12:46:51 -07:00
|
|
|
if (!Utils.isRect(data.pageBounds)) {
|
2010-07-23 00:03:40 -07:00
|
|
|
Utils.log("UI.storageSanity: bad pageBounds", data.pageBounds);
|
2010-05-24 14:49:03 -07:00
|
|
|
data.pageBounds = null;
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-05-24 14:49:03 -07:00
|
|
|
return true;
|
2010-05-03 15:32:11 -07:00
|
|
|
},
|
2010-07-12 21:04:04 -07:00
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
// ----------
|
|
|
|
// Function: _save
|
|
|
|
// Saves the data for this object to persistent storage
|
2010-09-08 10:02:08 -07:00
|
|
|
_save: function UI__save() {
|
2010-09-14 03:12:03 -07:00
|
|
|
if (!this._frameInitialized)
|
2010-07-23 00:03:40 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
pageBounds: this._pageBounds
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this._storageSanity(data))
|
|
|
|
Storage.saveUIData(gWindow, data);
|
|
|
|
},
|
|
|
|
|
2010-07-12 21:04:04 -07:00
|
|
|
// ----------
|
2010-07-22 19:05:22 -07:00
|
|
|
// Function: _saveAll
|
2010-07-29 12:37:25 -07:00
|
|
|
// Saves all data associated with TabView.
|
2010-07-22 19:05:22 -07:00
|
|
|
// TODO: Save info items
|
2010-09-08 10:02:08 -07:00
|
|
|
_saveAll: function UI__saveAll() {
|
2010-07-22 19:05:22 -07:00
|
|
|
this._save();
|
2010-08-06 15:46:55 -07:00
|
|
|
GroupItems.saveAll();
|
2010-07-22 19:05:22 -07:00
|
|
|
TabItems.saveAll();
|
2010-07-12 21:04:04 -07:00
|
|
|
},
|
2010-04-14 17:12:06 -07:00
|
|
|
};
|
2010-02-24 01:47:55 -08:00
|
|
|
|
2010-04-14 17:12:06 -07:00
|
|
|
// ----------
|
2010-09-08 10:02:08 -07:00
|
|
|
UI.init();
|