2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-16 17:19:11 -07:00
|
|
|
|
|
|
|
// **********
|
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.
|
2011-01-09 19:23:56 -08:00
|
|
|
_pageBounds: null,
|
2010-07-23 00:03:40 -07:00
|
|
|
|
|
|
|
// Variable: _closedLastVisibleTab
|
|
|
|
// If true, the last visible tab has just been closed in the tab strip.
|
2011-01-09 19:23:56 -08:00
|
|
|
_closedLastVisibleTab: false,
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-07-29 12:37:25 -07:00
|
|
|
// Variable: _closedSelectedTabInTabView
|
|
|
|
// If true, a select tab has just been closed in TabView.
|
2011-01-09 19:23:56 -08:00
|
|
|
_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.
|
2011-01-09 19:23:56 -08:00
|
|
|
restoredClosedTab: false,
|
2010-11-29 21:03:51 -08:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
// Variable: _isChangingVisibility
|
|
|
|
// Tracks whether we're currently in the process of showing/hiding the tabview.
|
|
|
|
_isChangingVisibility: 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.
|
2011-01-09 19:23:56 -08:00
|
|
|
_reorderTabItemsOnShow: [],
|
2010-07-25 20:53:21 -07:00
|
|
|
|
|
|
|
// 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.
|
2011-01-09 19:23:56 -08:00
|
|
|
_reorderTabsOnHide: [],
|
2010-07-25 20:53:21 -07:00
|
|
|
|
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.
|
2011-01-09 19:23:56 -08:00
|
|
|
_currentTab: null,
|
|
|
|
|
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:
|
|
|
|
// transitionMode - whether we're entering or exiting PB
|
|
|
|
// wasInTabView - whether TabView was visible before we went into PB
|
|
|
|
_privateBrowsing: {
|
|
|
|
transitionMode: "",
|
|
|
|
wasInTabView: false
|
|
|
|
},
|
2011-01-05 12:54:35 -08:00
|
|
|
|
2011-08-16 02:06:14 -07:00
|
|
|
// Variable: _storageBusy
|
|
|
|
// Tells whether the storage is currently busy or not.
|
|
|
|
_storageBusy: false,
|
2010-09-12 20:45:02 -07:00
|
|
|
|
2011-02-19 10:22:49 -08:00
|
|
|
// Variable: isDOMWindowClosing
|
2011-06-10 02:40:10 -07:00
|
|
|
// Tells wether the parent window is about to close
|
2011-02-19 10:22:49 -08:00
|
|
|
isDOMWindowClosing: false,
|
|
|
|
|
2011-03-28 19:51:26 -07:00
|
|
|
// Variable: _browserKeys
|
|
|
|
// Used to keep track of allowed browser keys.
|
|
|
|
_browserKeys: null,
|
|
|
|
|
2011-06-30 00:25:26 -07:00
|
|
|
// Variable: _browserKeysWithShift
|
|
|
|
// Used to keep track of allowed browser keys with Shift key combination.
|
|
|
|
_browserKeysWithShift: null,
|
|
|
|
|
2011-03-28 19:51:26 -07:00
|
|
|
// Variable: ignoreKeypressForSearch
|
|
|
|
// Used to prevent keypress being handled after quitting search mode.
|
|
|
|
ignoreKeypressForSearch: false,
|
|
|
|
|
2011-06-16 22:05:30 -07:00
|
|
|
// Variable: _lastOpenedTab
|
|
|
|
// Used to keep track of the last opened tab.
|
|
|
|
_lastOpenedTab: null,
|
|
|
|
|
2011-12-02 08:31:12 -08:00
|
|
|
// Variable: _originalSmoothScroll
|
|
|
|
// Used to keep track of the tab strip smooth scroll value.
|
|
|
|
_originalSmoothScroll: null,
|
|
|
|
|
2011-02-26 06:28:00 -08:00
|
|
|
// ----------
|
|
|
|
// Function: toString
|
|
|
|
// Prints [UI] for debug use
|
|
|
|
toString: function UI_toString() {
|
|
|
|
return "[UI]";
|
|
|
|
},
|
|
|
|
|
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();
|
2011-08-16 02:06:14 -07:00
|
|
|
|
|
|
|
if (Storage.readWindowBusyState(gWindow))
|
|
|
|
this.storageBusy();
|
|
|
|
|
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
|
|
|
|
2011-09-29 21:17:00 -07:00
|
|
|
// ___ search
|
|
|
|
Search.init();
|
|
|
|
|
2012-04-29 10:53:08 -07:00
|
|
|
Telemetry.init();
|
|
|
|
|
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();
|
2011-11-30 21:53:44 -08:00
|
|
|
})
|
|
|
|
.attr("title", tabviewString("button.exitTabGroups"));
|
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();
|
|
|
|
});
|
|
|
|
}
|
2012-02-03 05:10:30 -08:00
|
|
|
if (e.originalTarget.id == "content" &&
|
|
|
|
Utils.isLeftClick(e) &&
|
|
|
|
e.detail == 1) {
|
|
|
|
self._createGroupItemOnDrag(e);
|
2011-01-09 19:23:56 -08:00
|
|
|
}
|
2010-07-23 00:03:40 -07:00
|
|
|
});
|
|
|
|
|
2012-02-03 05:10:30 -08:00
|
|
|
iQ(gTabViewFrame.contentDocument).dblclick(function(e) {
|
2012-02-22 00:58:43 -08:00
|
|
|
if (e.originalTarget.id != "content")
|
|
|
|
return;
|
|
|
|
|
2012-02-03 05:10:30 -08:00
|
|
|
// Create a group with one tab on double click
|
|
|
|
let box =
|
|
|
|
new Rect(e.clientX - Math.floor(TabItems.tabWidth/2),
|
|
|
|
e.clientY - Math.floor(TabItems.tabHeight/2),
|
|
|
|
TabItems.tabWidth, TabItems.tabHeight);
|
|
|
|
box.inset(-30, -30);
|
|
|
|
|
|
|
|
let opts = {immediately: true, bounds: box};
|
|
|
|
let groupItem = new GroupItem([], opts);
|
|
|
|
groupItem.newTab();
|
|
|
|
|
|
|
|
gTabView.firstUseExperienced = true;
|
|
|
|
});
|
|
|
|
|
2010-08-11 21:36:58 -07:00
|
|
|
iQ(window).bind("unload", function() {
|
|
|
|
self.uninit();
|
|
|
|
});
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
// ___ setup DOMWillOpenModalDialog message handler
|
|
|
|
let mm = gWindow.messageManager;
|
|
|
|
let callback = this._onDOMWillOpenModalDialog.bind(this);
|
|
|
|
mm.addMessageListener("Panorama:DOMWillOpenModalDialog", callback);
|
|
|
|
|
|
|
|
this._cleanupFunctions.push(function () {
|
|
|
|
mm.removeMessageListener("Panorama:DOMWillOpenModalDialog", callback);
|
|
|
|
});
|
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
// ___ setup key handlers
|
|
|
|
this._setTabViewFrameKeyHandlers();
|
|
|
|
|
|
|
|
// ___ add tab action handlers
|
|
|
|
this._addTabActionHandlers();
|
|
|
|
|
2010-10-08 15:59:24 -07:00
|
|
|
// ___ groups
|
2010-08-06 17:02:21 -07:00
|
|
|
GroupItems.init();
|
2010-10-08 15:59:24 -07:00
|
|
|
GroupItems.pauseArrange();
|
|
|
|
let hasGroupItemsData = GroupItems.load();
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-08-15 21:46:22 -07:00
|
|
|
// ___ tabs
|
|
|
|
TabItems.init();
|
|
|
|
TabItems.pausePainting();
|
|
|
|
|
2012-04-13 16:04:57 -07:00
|
|
|
// ___ favicons
|
|
|
|
FavIcons.init();
|
|
|
|
|
2011-02-16 08:06:54 -08:00
|
|
|
if (!hasGroupItemsData)
|
|
|
|
this.reset();
|
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();
|
|
|
|
});
|
|
|
|
|
2011-06-10 02:40:10 -07:00
|
|
|
// ___ setup event listener to save canvas images
|
|
|
|
gWindow.addEventListener("SSWindowClosing", function onWindowClosing() {
|
|
|
|
gWindow.removeEventListener("SSWindowClosing", onWindowClosing, false);
|
|
|
|
|
2011-09-01 06:17:27 -07:00
|
|
|
// XXX bug #635975 - don't unlink the tab if the dom window is closing.
|
2011-06-10 02:40:10 -07:00
|
|
|
self.isDOMWindowClosing = true;
|
|
|
|
|
|
|
|
if (self.isTabViewVisible())
|
|
|
|
GroupItems.removeHiddenGroups();
|
|
|
|
|
2011-09-01 06:17:27 -07:00
|
|
|
TabItems.saveAll();
|
|
|
|
|
2011-06-10 02:40:10 -07:00
|
|
|
self._save();
|
|
|
|
}, false);
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
// ___ load frame script
|
|
|
|
let frameScript = "chrome://browser/content/tabview-content.js";
|
|
|
|
gWindow.messageManager.loadFrameScript(frameScript, true);
|
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
// ___ 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);
|
2011-05-30 13:02:04 -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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-05-30 13:02:04 -07:00
|
|
|
// Function: uninit
|
|
|
|
// Should be called when window is unloaded.
|
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();
|
2012-04-13 16:04:57 -07:00
|
|
|
FavIcons.uninit();
|
2010-08-11 21:36:58 -07:00
|
|
|
Storage.uninit();
|
2012-04-29 10:53:08 -07:00
|
|
|
Telemetry.uninit();
|
2010-08-11 21:36:58 -07:00
|
|
|
|
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
|
2011-02-16 08:06:54 -08:00
|
|
|
reset: function UI_reset() {
|
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);
|
2011-01-12 13:48:42 -08:00
|
|
|
groupItem.add(item, {immediately: true});
|
2010-09-20 18:26:00 -07:00
|
|
|
});
|
2011-04-22 13:05:11 -07:00
|
|
|
this.setActive(groupItem);
|
2010-09-20 18:26:00 -07:00
|
|
|
},
|
2010-08-11 21:36:58 -07:00
|
|
|
|
2011-04-03 19:27:50 -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;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
2011-04-22 13:05:11 -07:00
|
|
|
// Function: _setActiveTab
|
2010-07-23 00:03:40 -07:00
|
|
|
// 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>
|
2011-04-22 13:05:11 -07:00
|
|
|
_setActiveTab: function UI__setActiveTab(tabItem) {
|
2010-12-15 19:43:25 -08:00
|
|
|
if (tabItem == this._activeTab)
|
2010-07-23 00:03:40 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._activeTab) {
|
|
|
|
this._activeTab.makeDeactive();
|
2011-07-14 10:54:25 -07:00
|
|
|
this._activeTab.removeSubscriber("close", this._onActiveTabClosed);
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
2011-07-14 10:54:25 -07:00
|
|
|
|
2010-12-15 19:43:25 -08:00
|
|
|
this._activeTab = tabItem;
|
2010-07-23 00:03:40 -07:00
|
|
|
|
|
|
|
if (this._activeTab) {
|
2011-07-14 10:54:25 -07:00
|
|
|
this._activeTab.addSubscriber("close", this._onActiveTabClosed);
|
2010-07-23 00:03:40 -07:00
|
|
|
this._activeTab.makeActive();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-07-14 10:54:25 -07:00
|
|
|
// ----------
|
|
|
|
// Function: _onActiveTabClosed
|
|
|
|
// Handles when the currently active tab gets closed.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// - the <TabItem> that is closed
|
|
|
|
_onActiveTabClosed: function UI__onActiveTabClosed(tabItem){
|
|
|
|
if (UI._activeTab == tabItem)
|
|
|
|
UI._setActiveTab(null);
|
|
|
|
},
|
|
|
|
|
2011-04-22 13:05:11 -07:00
|
|
|
// ----------
|
|
|
|
// Function: setActive
|
|
|
|
// Sets the active tab item or group item
|
|
|
|
// Parameters:
|
|
|
|
//
|
|
|
|
// options
|
|
|
|
// dontSetActiveTabInGroup bool for not setting active tab in group
|
|
|
|
setActive: function UI_setActive(item, options) {
|
2011-07-04 15:23:35 -07:00
|
|
|
Utils.assert(item, "item must be given");
|
|
|
|
|
|
|
|
if (item.isATabItem) {
|
2011-08-03 18:49:38 -07:00
|
|
|
if (item.parent)
|
|
|
|
GroupItems.setActiveGroupItem(item.parent);
|
2011-11-30 20:49:28 -08:00
|
|
|
if (!options || !options.dontSetActiveTabInGroup)
|
|
|
|
this._setActiveTab(item);
|
2011-04-22 13:05:11 -07:00
|
|
|
} else {
|
2011-07-04 15:23:35 -07:00
|
|
|
GroupItems.setActiveGroupItem(item);
|
|
|
|
if (!options || !options.dontSetActiveTabInGroup) {
|
2011-12-07 06:28:50 -08:00
|
|
|
let activeTab = item.getActiveTab();
|
2011-07-04 15:23:35 -07:00
|
|
|
if (activeTab)
|
|
|
|
this._setActiveTab(activeTab);
|
2011-04-22 13:05:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-07-14 10:54:15 -07:00
|
|
|
// ----------
|
|
|
|
// Function: clearActiveTab
|
|
|
|
// Sets the active tab to 'null'.
|
|
|
|
clearActiveTab: function UI_clearActiveTab() {
|
|
|
|
this._setActiveTab(null);
|
|
|
|
},
|
|
|
|
|
2010-07-23 00:03:40 -07:00
|
|
|
// ----------
|
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() {
|
2011-04-13 20:28:58 -07:00
|
|
|
return gTabViewDeck.selectedPanel == gTabViewFrame;
|
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) {
|
2011-08-15 07:03:39 -07:00
|
|
|
if (this.isTabViewVisible() || this._isChangingVisibility)
|
2010-08-04 17:12:08 -07:00
|
|
|
return;
|
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
this._isChangingVisibility = true;
|
|
|
|
|
2011-12-02 08:31:12 -08:00
|
|
|
// store tab strip smooth scroll value and disable it.
|
|
|
|
let tabStrip = gBrowser.tabContainer.mTabstrip;
|
|
|
|
this._originalSmoothScroll = tabStrip.smoothScroll;
|
|
|
|
tabStrip.smoothScroll = false;
|
|
|
|
|
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;
|
|
|
|
|
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
|
2011-04-13 20:28:58 -07:00
|
|
|
gTabViewDeck.selectedPanel = gTabViewFrame;
|
2011-01-07 12:28:02 -08:00
|
|
|
gWindow.TabsInTitlebar.allowedBy("tabview-open", false);
|
2010-07-22 22:41:58 -07:00
|
|
|
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
|
2011-01-25 11:10:00 -08:00
|
|
|
this.setTitlebarColors(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
|
|
|
|
2011-02-15 10:56:57 -08:00
|
|
|
Storage.saveVisibilityData(gWindow, "true");
|
|
|
|
|
2011-01-11 00:20:08 -08:00
|
|
|
if (zoomOut && currentTab && currentTab._tabViewTabItem) {
|
2011-07-14 10:54:15 -07:00
|
|
|
let item = currentTab._tabViewTabItem;
|
2010-07-27 20:02:51 -07:00
|
|
|
// 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() {
|
2011-01-11 00:20:08 -08:00
|
|
|
if (!currentTab._tabViewTabItem) // if the tab's been destroyed
|
2010-07-27 20:02:51 -07:00
|
|
|
item = null;
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2011-04-22 13:05:11 -07:00
|
|
|
self.setActive(item);
|
2010-07-23 00:03:40 -07:00
|
|
|
|
2010-07-27 20:02:51 -07:00
|
|
|
self._resize(true);
|
2011-08-15 07:03:39 -07:00
|
|
|
self._isChangingVisibility = false;
|
2010-08-04 17:12:08 -07:00
|
|
|
dispatchEvent(event);
|
2011-01-14 12:15:29 -08:00
|
|
|
|
2010-11-16 14:35:00 -08:00
|
|
|
// Flush pending updates
|
|
|
|
GroupItems.flushAppTabUpdates();
|
|
|
|
|
2011-01-14 12:15:29 -08:00
|
|
|
TabItems.resumePainting();
|
2010-07-27 20:02:51 -07:00
|
|
|
});
|
2010-09-24 16:22:35 -07:00
|
|
|
} else {
|
2011-12-07 06:28:50 -08:00
|
|
|
if (!currentTab || !currentTab._tabViewTabItem)
|
|
|
|
self.clearActiveTab();
|
2011-08-15 07:03:39 -07:00
|
|
|
self._isChangingVisibility = false;
|
2010-08-04 17:12:08 -07:00
|
|
|
dispatchEvent(event);
|
2010-08-04 16:42:36 -07:00
|
|
|
|
2010-11-16 14:35:00 -08:00
|
|
|
// Flush pending updates
|
|
|
|
GroupItems.flushAppTabUpdates();
|
|
|
|
|
2011-01-14 12:15:29 -08:00
|
|
|
TabItems.resumePainting();
|
|
|
|
}
|
2011-05-17 15:00:05 -07:00
|
|
|
|
|
|
|
if (gTabView.firstUseExperienced)
|
|
|
|
gTabView.enableSessionRestore();
|
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() {
|
2011-08-15 07:03:39 -07:00
|
|
|
if (!this.isTabViewVisible() || this._isChangingVisibility)
|
2010-08-04 17:12:08 -07:00
|
|
|
return;
|
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
this._isChangingVisibility = true;
|
|
|
|
|
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
|
2011-04-13 20:28:58 -07:00
|
|
|
gTabViewDeck.selectedPanel = gBrowserPanel;
|
2011-01-07 12:28:02 -08:00
|
|
|
gWindow.TabsInTitlebar.allowedBy("tabview-open", true);
|
2011-10-09 22:24:01 -07:00
|
|
|
gBrowser.selectedBrowser.focus();
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2010-07-22 12:34:13 -07:00
|
|
|
gBrowser.updateTitlebar();
|
2011-12-02 08:31:12 -08:00
|
|
|
gBrowser.tabContainer.mTabstrip.smoothScroll = this._originalSmoothScroll;
|
2010-07-19 02:37:22 -07:00
|
|
|
#ifdef XP_MACOSX
|
2011-01-25 11:10:00 -08:00
|
|
|
this.setTitlebarColors(false);
|
2010-07-19 02:37:22 -07:00
|
|
|
#endif
|
2011-02-15 10:56:57 -08:00
|
|
|
Storage.saveVisibilityData(gWindow, "false");
|
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
this._isChangingVisibility = false;
|
|
|
|
|
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
|
|
|
// ----------
|
2011-01-25 11:10:00 -08:00
|
|
|
// Function: setTitlebarColors
|
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:
|
2011-01-25 11:10:00 -08:00
|
|
|
// colors - (bool or object) true for the special TabView color, false for
|
|
|
|
// the normal color, and an object with "active" and "inactive"
|
|
|
|
// properties to specify directly.
|
|
|
|
setTitlebarColors: function UI_setTitlebarColors(colors) {
|
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");
|
2011-01-25 11:10:00 -08:00
|
|
|
if (colors === true) {
|
2010-07-19 02:37:22 -07:00
|
|
|
mainWindow.setAttribute("activetitlebarcolor", "#C4C4C4");
|
2011-01-25 11:10:00 -08:00
|
|
|
mainWindow.setAttribute("inactivetitlebarcolor", "#EDEDED");
|
|
|
|
} else if (colors && "active" in colors && "inactive" in colors) {
|
|
|
|
mainWindow.setAttribute("activetitlebarcolor", colors.active);
|
|
|
|
mainWindow.setAttribute("inactivetitlebarcolor", colors.inactive);
|
|
|
|
} else {
|
2010-07-19 02:37:22 -07:00
|
|
|
mainWindow.removeAttribute("activetitlebarcolor");
|
2011-01-25 11:10:00 -08:00
|
|
|
mainWindow.removeAttribute("inactivetitlebarcolor");
|
|
|
|
}
|
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
|
|
|
|
2011-01-05 12:54:35 -08:00
|
|
|
// ----------
|
|
|
|
// Function: storageBusy
|
|
|
|
// Pauses the storage activity that conflicts with sessionstore updates and
|
|
|
|
// private browsing mode switches. Calls can be nested.
|
|
|
|
storageBusy: function UI_storageBusy() {
|
2011-08-16 02:06:14 -07:00
|
|
|
if (this._storageBusy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._storageBusy = true;
|
|
|
|
|
|
|
|
TabItems.pauseReconnecting();
|
|
|
|
GroupItems.pauseAutoclose();
|
2011-01-05 12:54:35 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: storageReady
|
|
|
|
// Resumes the activity paused by storageBusy, and updates for any new group
|
|
|
|
// information in sessionstore. Calls can be nested.
|
|
|
|
storageReady: function UI_storageReady() {
|
2011-08-16 02:06:14 -07:00
|
|
|
if (!this._storageBusy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._storageBusy = false;
|
|
|
|
|
|
|
|
let hasGroupItemsData = GroupItems.load();
|
|
|
|
if (!hasGroupItemsData)
|
|
|
|
this.reset();
|
|
|
|
|
|
|
|
TabItems.resumeReconnecting();
|
|
|
|
GroupItems._updateTabBar();
|
|
|
|
GroupItems.resumeAutoclose();
|
2011-01-05 12:54:35 -08: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
|
|
|
|
2011-01-05 12:54:35 -08:00
|
|
|
// session restore events
|
|
|
|
function handleSSWindowStateBusy() {
|
|
|
|
self.storageBusy();
|
2010-09-24 17:24:31 -07:00
|
|
|
}
|
2011-01-05 12:54:35 -08:00
|
|
|
|
|
|
|
function handleSSWindowStateReady() {
|
|
|
|
self.storageReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
gWindow.addEventListener("SSWindowStateBusy", handleSSWindowStateBusy, false);
|
|
|
|
gWindow.addEventListener("SSWindowStateReady", handleSSWindowStateReady, false);
|
2010-09-24 17:24:31 -07:00
|
|
|
|
|
|
|
this._cleanupFunctions.push(function() {
|
2011-01-05 12:54:35 -08:00
|
|
|
gWindow.removeEventListener("SSWindowStateBusy", handleSSWindowStateBusy, false);
|
|
|
|
gWindow.removeEventListener("SSWindowStateReady", handleSSWindowStateReady, false);
|
2010-09-24 17:24:31 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Private Browsing:
|
2010-11-03 11:14:27 -07:00
|
|
|
// When transitioning to PB, we exit Panorama if necessary (making note of the
|
2010-09-24 17:24:31 -07:00
|
|
|
// 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.
|
2011-05-30 13:02:04 -07:00
|
|
|
function pbObserver(subject, topic, data) {
|
|
|
|
if (topic == "private-browsing") {
|
2010-11-03 11:14:27 -07:00
|
|
|
// We could probably do this in private-browsing-change-granted, but
|
|
|
|
// this seems like a nicer spot, right in the middle of the process.
|
2011-05-30 13:02:04 -07:00
|
|
|
if (data == "enter") {
|
2010-09-24 17:24:31 -07:00
|
|
|
// 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);
|
|
|
|
}
|
2011-05-30 13:02:04 -07:00
|
|
|
} else if (topic == "private-browsing-change-granted") {
|
|
|
|
if (data == "enter" || data == "exit") {
|
2011-09-29 21:17:00 -07:00
|
|
|
Search.hide();
|
2011-05-30 13:02:04 -07:00
|
|
|
self._privateBrowsing.transitionMode = data;
|
2010-09-24 17:24:31 -07:00
|
|
|
}
|
2011-05-30 13:02:04 -07:00
|
|
|
} else if (topic == "private-browsing-transition-complete") {
|
2010-11-03 11:14:27 -07:00
|
|
|
// We use .transitionMode here, as aData is empty.
|
|
|
|
if (self._privateBrowsing.transitionMode == "exit" &&
|
|
|
|
self._privateBrowsing.wasInTabView)
|
|
|
|
self.showTabView(false);
|
|
|
|
|
|
|
|
self._privateBrowsing.transitionMode = "";
|
2010-09-24 17:24:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.obs.addObserver(pbObserver, "private-browsing", false);
|
|
|
|
Services.obs.addObserver(pbObserver, "private-browsing-change-granted", false);
|
2010-11-03 11:14:27 -07:00
|
|
|
Services.obs.addObserver(pbObserver, "private-browsing-transition-complete", false);
|
2010-09-24 17:24:31 -07:00
|
|
|
|
|
|
|
this._cleanupFunctions.push(function() {
|
|
|
|
Services.obs.removeObserver(pbObserver, "private-browsing");
|
|
|
|
Services.obs.removeObserver(pbObserver, "private-browsing-change-granted");
|
2010-11-03 11:14:27 -07:00
|
|
|
Services.obs.removeObserver(pbObserver, "private-browsing-transition-complete");
|
2010-09-24 17:24:31 -07:00
|
|
|
});
|
|
|
|
|
2010-10-06 11:33:18 -07:00
|
|
|
// TabOpen
|
2011-08-21 01:41:17 -07:00
|
|
|
this._eventListeners.open = function (event) {
|
|
|
|
let tab = event.target;
|
2010-10-06 11:33:18 -07:00
|
|
|
|
|
|
|
// if it's an app tab, add it to all the group items
|
|
|
|
if (tab.pinned)
|
|
|
|
GroupItems.addAppTab(tab);
|
2011-07-04 15:23:35 -07:00
|
|
|
else if (self.isTabViewVisible() && !self._storageBusyCount)
|
2011-06-16 22:05:30 -07:00
|
|
|
self._lastOpenedTab = tab;
|
2010-10-06 11:33:18 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// TabClose
|
2011-08-21 01:41:17 -07:00
|
|
|
this._eventListeners.close = function (event) {
|
|
|
|
let tab = event.target;
|
2010-07-28 14:20:41 -07:00
|
|
|
|
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.
|
2011-08-16 02:06:14 -07:00
|
|
|
if (self._storageBusy)
|
2011-05-19 14:44:51 -07:00
|
|
|
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
|
2011-04-07 22:19:48 -07:00
|
|
|
for (let a = 0; a < gBrowser._numPinnedTabs; a++) {
|
2012-04-10 11:13:36 -07:00
|
|
|
if (Utils.isValidXULTab(gBrowser.tabs[a]))
|
2010-09-16 00:51:24 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-28 08:08:32 -08:00
|
|
|
let 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);
|
2011-02-02 17:43:32 -08:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
// 2) When a blank tab is active while restoring a closed tab the
|
2011-02-02 17:43:32 -08:00
|
|
|
// blank tab gets removed. The active group is not closed as this is
|
|
|
|
// where the restored tab goes. So do not show the TabView.
|
2011-06-17 09:47:43 -07:00
|
|
|
let tabItem = tab && tab._tabViewTabItem;
|
2011-02-02 17:43:32 -08:00
|
|
|
let closingBlankTabAfterRestore =
|
2011-06-17 09:47:43 -07:00
|
|
|
(tabItem && tabItem.isRemovedAfterRestore);
|
2011-02-02 17:43:32 -08:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
if (closingLastOfGroup && !closingBlankTabAfterRestore) {
|
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;
|
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
|
2011-08-21 01:41:17 -07:00
|
|
|
this._eventListeners.move = function (event) {
|
|
|
|
let tab = event.target;
|
2010-07-28 14:20:41 -07:00
|
|
|
|
2011-04-04 02:04:52 -07:00
|
|
|
if (GroupItems.groupItems.length > 0) {
|
|
|
|
if (tab.pinned) {
|
|
|
|
if (gBrowser._numPinnedTabs > 1)
|
|
|
|
GroupItems.arrangeAppTab(tab);
|
|
|
|
} else {
|
|
|
|
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
|
2011-08-21 01:41:17 -07:00
|
|
|
this._eventListeners.select = function (event) {
|
|
|
|
self.onTabSelect(event.target);
|
2010-08-31 00:22:10 -07:00
|
|
|
};
|
|
|
|
|
2010-11-09 19:39:31 -08:00
|
|
|
// TabPinned
|
2011-08-21 01:41:17 -07:00
|
|
|
this._eventListeners.pinned = function (event) {
|
|
|
|
let tab = event.target;
|
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
|
2011-08-21 01:41:17 -07:00
|
|
|
this._eventListeners.unpinned = function (event) {
|
|
|
|
let tab = event.target;
|
2010-09-12 20:45:02 -07:00
|
|
|
|
2010-11-09 19:39:31 -08:00
|
|
|
TabItems.handleTabUnpin(tab);
|
|
|
|
GroupItems.removeAppTab(tab);
|
2011-02-03 07:59:27 -08:00
|
|
|
|
|
|
|
let groupItem = tab._tabViewTabItem.parent;
|
|
|
|
if (groupItem)
|
|
|
|
self.setReorderTabItemsOnShow(groupItem);
|
2010-11-09 19:39:31 -08:00
|
|
|
};
|
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
|
|
|
this._currentTab = tab;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2011-06-16 22:05:30 -07:00
|
|
|
if (this.isTabViewVisible()) {
|
2011-08-24 04:38:17 -07:00
|
|
|
// We want to zoom in if:
|
|
|
|
// 1) we didn't just restore a tab via Ctrl+Shift+T
|
|
|
|
// 2) we're not in the middle of switching from/to private browsing
|
|
|
|
// 3) the currently selected tab is the last created tab and has a tabItem
|
|
|
|
if (!this.restoredClosedTab && !this._privateBrowsing.transitionMode &&
|
|
|
|
this._lastOpenedTab == tab && tab._tabViewTabItem) {
|
2011-07-04 15:23:35 -07:00
|
|
|
tab._tabViewTabItem.zoomIn(true);
|
2011-06-16 22:05:30 -07:00
|
|
|
this._lastOpenedTab = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this._closedLastVisibleTab ||
|
|
|
|
(this._closedSelectedTabInTabView && !this.closedLastTabInTabView) ||
|
|
|
|
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
|
2011-07-23 08:07:39 -07:00
|
|
|
tab.linkedBrowser.addEventListener("load", function onLoad(event) {
|
|
|
|
tab.linkedBrowser.removeEventListener("load", onLoad, true);
|
2011-06-16 22:05:30 -07:00
|
|
|
TabItems._update(tab);
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
this._closedLastVisibleTab = false;
|
|
|
|
this._closedSelectedTabInTabView = false;
|
|
|
|
this.closedLastTabInTabView = false;
|
|
|
|
this.restoredClosedTab = false;
|
|
|
|
return;
|
2010-11-29 21:03:51 -08:00
|
|
|
}
|
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;
|
2011-06-16 22:05:30 -07:00
|
|
|
this.closedLastTabInTabView = false;
|
2010-11-29 21:03:51 -08:00
|
|
|
this.restoredClosedTab = false;
|
2011-06-16 22:05:30 -07:00
|
|
|
this._lastOpenedTab = null;
|
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.
|
2011-08-15 07:03:39 -07:00
|
|
|
if (this.isTabViewVisible()) {
|
|
|
|
// Unhide the group of the tab the user is activating.
|
|
|
|
if (tab && tab._tabViewTabItem && tab._tabViewTabItem.parent &&
|
|
|
|
tab._tabViewTabItem.parent.hidden)
|
|
|
|
tab._tabViewTabItem.parent._unhide({immediately: true});
|
|
|
|
|
2010-07-29 12:37:25 -07:00
|
|
|
this.hideTabView();
|
2011-08-15 07:03:39 -07:00
|
|
|
}
|
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-17 07:13:45 -07:00
|
|
|
let newItem = null;
|
2010-09-24 16:22:35 -07:00
|
|
|
// update the tab bar for the new tab's group
|
2011-01-11 00:20:08 -08:00
|
|
|
if (tab && tab._tabViewTabItem) {
|
2011-01-12 17:08:22 -08:00
|
|
|
if (!TabItems.reconnectingPaused()) {
|
|
|
|
newItem = tab._tabViewTabItem;
|
|
|
|
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.
|
2011-07-04 15:23:35 -07:00
|
|
|
// If no current group, figure it out based on what's already in the tab
|
|
|
|
// bar.
|
|
|
|
if (!GroupItems.getActiveGroupItem()) {
|
2010-09-24 16:22:35 -07:00
|
|
|
for (let a = 0; a < gBrowser.tabs.length; a++) {
|
2011-04-22 13:05:11 -07:00
|
|
|
let theTab = gBrowser.tabs[a];
|
2010-09-24 16:22:35 -07:00
|
|
|
if (!theTab.pinned) {
|
2011-04-22 13:05:11 -07:00
|
|
|
let tabItem = theTab._tabViewTabItem;
|
|
|
|
this.setActive(tabItem.parent);
|
2010-09-24 16:22:35 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-04 15:23:35 -07:00
|
|
|
if (GroupItems.getActiveGroupItem())
|
2010-09-24 16:22:35 -07:00
|
|
|
GroupItems._updateTabBar();
|
2010-08-17 07:13:45 -07:00
|
|
|
}
|
2010-07-01 22:27:49 -07:00
|
|
|
},
|
2010-07-16 00:00:20 -07:00
|
|
|
|
2011-08-15 07:03:39 -07:00
|
|
|
// ----------
|
|
|
|
// Function: _onDOMWillOpenModalDialog
|
|
|
|
// Called when a web page is about to show a modal dialog.
|
|
|
|
_onDOMWillOpenModalDialog: function UI__onDOMWillOpenModalDialog(cx) {
|
|
|
|
if (!this.isTabViewVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
let index = gBrowser.browsers.indexOf(cx.target);
|
|
|
|
if (index == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let tab = gBrowser.tabs[index];
|
|
|
|
|
|
|
|
// When TabView is visible, we need to call onTabSelect to make sure that
|
|
|
|
// TabView is hidden and that the correct group is activated. When a modal
|
|
|
|
// dialog is shown for currently selected tab the onTabSelect event handler
|
|
|
|
// is not called, so we need to do it.
|
|
|
|
if (gBrowser.selectedTab == tab && this._currentTab == tab)
|
|
|
|
this.onTabSelect(tab);
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
|
|
|
// ----------
|
2011-10-10 00:04:27 -07:00
|
|
|
updateTabButton: function UI_updateTabButton() {
|
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
|
|
|
|
|
|
|
exitButton.setAttribute("groups", numberOfGroups);
|
2011-05-25 18:33:08 -07:00
|
|
|
gTabView.updateGroupNumberBroadcaster(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;
|
2011-01-12 07:15:26 -08:00
|
|
|
TabItems.getItems().forEach(function (item) {
|
2011-07-04 15:23:35 -07:00
|
|
|
if (!item.parent || item.parent.hidden)
|
2011-01-12 07:15:26 -08:00
|
|
|
return;
|
2010-09-27 16:12:00 -07:00
|
|
|
let testDist = tabCenter.distance(item.bounds.center());
|
|
|
|
if (cl==null || testDist < clDist) {
|
|
|
|
cl = item;
|
|
|
|
clDist = testDist;
|
|
|
|
}
|
2011-01-12 07:15:26 -08:00
|
|
|
});
|
2010-09-27 16:12:00 -07:00
|
|
|
return cl;
|
|
|
|
},
|
|
|
|
|
2011-03-28 19:51:26 -07:00
|
|
|
// ----------
|
|
|
|
// Function: _setupBrowserKeys
|
|
|
|
// Sets up the allowed browser keys using key elements.
|
|
|
|
_setupBrowserKeys: function UI__setupKeyWhiteList() {
|
|
|
|
let keys = {};
|
|
|
|
|
|
|
|
[
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
"quitApplication",
|
2011-05-31 19:37:12 -07:00
|
|
|
#else
|
|
|
|
"redo",
|
2011-03-28 19:51:26 -07:00
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
2011-06-03 09:44:34 -07:00
|
|
|
"preferencesCmdMac", "minimizeWindow", "hideThisAppCmdMac",
|
2011-03-28 19:51:26 -07:00
|
|
|
#endif
|
2011-05-18 23:07:42 -07:00
|
|
|
"newNavigator", "newNavigatorTab", "undo", "cut", "copy", "paste",
|
|
|
|
"selectAll", "find"
|
2011-05-31 19:37:12 -07:00
|
|
|
].forEach(function(key) {
|
2011-03-28 19:51:26 -07:00
|
|
|
let element = gWindow.document.getElementById("key_" + key);
|
2011-06-30 00:25:26 -07:00
|
|
|
let code = element.getAttribute("key").toLocaleLowerCase().charCodeAt(0);
|
|
|
|
keys[code] = key;
|
2011-03-28 19:51:26 -07:00
|
|
|
});
|
2011-06-30 00:25:26 -07:00
|
|
|
this._browserKeys = keys;
|
2011-03-28 19:51:26 -07:00
|
|
|
|
2011-06-30 00:25:26 -07:00
|
|
|
keys = {};
|
|
|
|
// The lower case letters are passed to processBrowserKeys() even with shift
|
|
|
|
// key when stimulating a key press using EventUtils.synthesizeKey() so need
|
|
|
|
// to handle both upper and lower cases here.
|
2011-05-31 19:37:12 -07:00
|
|
|
[
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
"redo",
|
2011-07-23 09:06:06 -07:00
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
"fullScreen",
|
2011-05-31 19:37:12 -07:00
|
|
|
#endif
|
|
|
|
"closeWindow", "tabview", "undoCloseTab", "undoCloseWindow",
|
|
|
|
"privatebrowsing"
|
|
|
|
].forEach(function(key) {
|
2011-03-28 19:51:26 -07:00
|
|
|
let element = gWindow.document.getElementById("key_" + key);
|
2011-06-30 00:25:26 -07:00
|
|
|
let code = element.getAttribute("key").toLocaleLowerCase().charCodeAt(0);
|
|
|
|
keys[code] = key;
|
2011-03-28 19:51:26 -07:00
|
|
|
});
|
2011-06-30 00:25:26 -07:00
|
|
|
this._browserKeysWithShift = keys;
|
2011-03-28 19:51:26 -07:00
|
|
|
},
|
|
|
|
|
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() {
|
2011-03-28 19:51:26 -07:00
|
|
|
let self = this;
|
|
|
|
|
|
|
|
this._setupBrowserKeys();
|
2010-07-23 00:03:40 -07:00
|
|
|
|
|
|
|
iQ(window).keyup(function(event) {
|
2011-03-28 19:51:26 -07:00
|
|
|
if (!event.metaKey)
|
2010-11-17 02:49:59 -08:00
|
|
|
Keys.meta = false;
|
2010-07-23 00:03:40 -07:00
|
|
|
});
|
|
|
|
|
2011-03-28 19:51:26 -07:00
|
|
|
iQ(window).keypress(function(event) {
|
|
|
|
if (event.metaKey)
|
2010-11-17 02:49:59 -08:00
|
|
|
Keys.meta = true;
|
|
|
|
|
2011-03-28 19:51:26 -07:00
|
|
|
function processBrowserKeys(evt) {
|
2011-06-03 09:44:34 -07:00
|
|
|
// let any keys with alt to pass through
|
|
|
|
if (evt.altKey)
|
|
|
|
return;
|
|
|
|
|
2011-03-28 19:51:26 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (evt.metaKey) {
|
|
|
|
#else
|
|
|
|
if (evt.ctrlKey) {
|
|
|
|
#endif
|
|
|
|
let preventDefault = true;
|
|
|
|
if (evt.shiftKey) {
|
2011-06-30 00:25:26 -07:00
|
|
|
// when a user presses ctrl+shift+key, upper case letter charCode
|
|
|
|
// is passed to processBrowserKeys() so converting back to lower
|
|
|
|
// case charCode before doing the check
|
|
|
|
let lowercaseCharCode =
|
|
|
|
String.fromCharCode(evt.charCode).toLocaleLowerCase().charCodeAt(0);
|
|
|
|
if (lowercaseCharCode in self._browserKeysWithShift) {
|
|
|
|
let key = self._browserKeysWithShift[lowercaseCharCode];
|
|
|
|
if (key == "tabview")
|
2011-05-31 19:37:12 -07:00
|
|
|
self.exit();
|
2011-06-30 00:25:26 -07:00
|
|
|
else
|
2011-03-28 19:51:26 -07:00
|
|
|
preventDefault = false;
|
|
|
|
}
|
|
|
|
} else {
|
2011-06-30 00:25:26 -07:00
|
|
|
if (evt.charCode in self._browserKeys) {
|
|
|
|
let key = self._browserKeys[evt.charCode];
|
|
|
|
if (key == "find")
|
2011-03-28 19:51:26 -07:00
|
|
|
self.enableSearch();
|
2011-06-30 00:25:26 -07:00
|
|
|
else
|
2011-03-28 19:51:26 -07:00
|
|
|
preventDefault = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (preventDefault) {
|
|
|
|
evt.stopPropagation();
|
|
|
|
evt.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((iQ(":focus").length > 0 && iQ(":focus")[0].nodeName == "INPUT") ||
|
2011-09-29 21:17:00 -07:00
|
|
|
Search.isEnabled() || self.ignoreKeypressForSearch) {
|
2011-03-28 19:51:26 -07:00
|
|
|
self.ignoreKeypressForSearch = false;
|
|
|
|
processBrowserKeys(event);
|
2010-11-17 02:49:59 -08:00
|
|
|
return;
|
2011-03-28 19:51:26 -07:00
|
|
|
}
|
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;
|
2011-08-17 19:56:25 -07:00
|
|
|
|
|
|
|
let activeTab = self.getActiveTab();
|
|
|
|
let activeTabGroup = activeTab.parent;
|
|
|
|
let myCenter = activeTab.bounds.center();
|
|
|
|
let match;
|
|
|
|
|
|
|
|
TabItems.getItems().forEach(function (item) {
|
|
|
|
if (!item.parent.hidden &&
|
|
|
|
(!activeTabGroup.expanded || activeTabGroup.id == item.parent.id)) {
|
|
|
|
let itemCenter = item.bounds.center();
|
|
|
|
|
|
|
|
if (norm(itemCenter, myCenter)) {
|
|
|
|
let itemDist = myCenter.distance(itemCenter);
|
|
|
|
if (!match || match[0] > itemDist)
|
|
|
|
match = [itemDist, item];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return match && match[1];
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
|
|
|
|
2011-03-28 19:51:26 -07:00
|
|
|
let preventDefault = true;
|
|
|
|
let activeTab;
|
2012-03-28 12:34:20 -07:00
|
|
|
let activeGroupItem;
|
2011-03-28 19:51:26 -07:00
|
|
|
let 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) {
|
2012-03-28 12:34:20 -07:00
|
|
|
let nextTab = getClosestTabBy(norm);
|
2010-07-23 00:03:40 -07:00
|
|
|
if (nextTab) {
|
2010-09-26 23:25:00 -07:00
|
|
|
if (nextTab.isStacked && !nextTab.parent.expanded)
|
2010-07-23 00:03:40 -07:00
|
|
|
nextTab = nextTab.parent.getChild(0);
|
2011-04-22 13:05:11 -07:00
|
|
|
self.setActive(nextTab);
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
2011-03-28 19:51:26 -07:00
|
|
|
} else {
|
|
|
|
switch(event.keyCode) {
|
|
|
|
case KeyEvent.DOM_VK_ESCAPE:
|
2012-03-28 12:34:20 -07:00
|
|
|
activeGroupItem = GroupItems.getActiveGroupItem();
|
2011-03-28 19:51:26 -07:00
|
|
|
if (activeGroupItem && activeGroupItem.expanded)
|
|
|
|
activeGroupItem.collapse();
|
|
|
|
else
|
|
|
|
self.exit();
|
|
|
|
break;
|
|
|
|
case KeyEvent.DOM_VK_RETURN:
|
|
|
|
case KeyEvent.DOM_VK_ENTER:
|
2012-03-28 12:34:20 -07:00
|
|
|
activeGroupItem = GroupItems.getActiveGroupItem();
|
|
|
|
if (activeGroupItem) {
|
|
|
|
activeTab = self.getActiveTab();
|
|
|
|
|
|
|
|
if (!activeTab || activeTab.parent != activeGroupItem)
|
|
|
|
activeTab = activeGroupItem.getActiveTab();
|
|
|
|
|
|
|
|
if (activeTab)
|
|
|
|
activeTab.zoomIn();
|
|
|
|
else
|
|
|
|
activeGroupItem.newTab();
|
|
|
|
}
|
2011-03-28 19:51:26 -07:00
|
|
|
break;
|
|
|
|
case KeyEvent.DOM_VK_TAB:
|
|
|
|
// tab/shift + tab to go to the next tab.
|
|
|
|
activeTab = self.getActiveTab();
|
|
|
|
if (activeTab) {
|
|
|
|
let tabItems = (activeTab.parent ? activeTab.parent.getChildren() :
|
|
|
|
[activeTab]);
|
|
|
|
let length = tabItems.length;
|
|
|
|
let currentIndex = tabItems.indexOf(activeTab);
|
|
|
|
|
|
|
|
if (length > 1) {
|
2011-09-16 10:17:17 -07:00
|
|
|
let newIndex;
|
2011-03-28 19:51:26 -07:00
|
|
|
if (event.shiftKey) {
|
|
|
|
if (currentIndex == 0)
|
|
|
|
newIndex = (length - 1);
|
|
|
|
else
|
|
|
|
newIndex = (currentIndex - 1);
|
|
|
|
} else {
|
|
|
|
if (currentIndex == (length - 1))
|
|
|
|
newIndex = 0;
|
|
|
|
else
|
|
|
|
newIndex = (currentIndex + 1);
|
|
|
|
}
|
2011-04-22 13:05:11 -07:00
|
|
|
self.setActive(tabItems[newIndex]);
|
2011-03-28 19:51:26 -07:00
|
|
|
}
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
2011-03-28 19:51:26 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
processBrowserKeys(event);
|
|
|
|
preventDefault = false;
|
|
|
|
}
|
|
|
|
if (preventDefault) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-11-23 23:55:18 -08:00
|
|
|
// ----------
|
|
|
|
// Function: enableSearch
|
|
|
|
// Enables the search feature.
|
2011-03-28 19:51:26 -07:00
|
|
|
enableSearch: function UI_enableSearch() {
|
2011-09-29 21:17:00 -07:00
|
|
|
if (!Search.isEnabled()) {
|
|
|
|
Search.ensureShown();
|
|
|
|
Search.switchToInMode();
|
2010-11-23 23:55:18 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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();
|
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-12-12 14:36:19 -08:00
|
|
|
.addClass("groupItem phantom activeGroupItem dragRegion")
|
2010-07-23 00:03:40 -07:00
|
|
|
.css({
|
|
|
|
position: "absolute",
|
|
|
|
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) {
|
2010-12-12 14:36:19 -08:00
|
|
|
// don't set a z-index because we want to force it to be low.
|
2010-07-23 00:03:40 -07:00
|
|
|
},
|
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();
|
|
|
|
}
|
|
|
|
|
2011-04-22 13:05:11 -07:00
|
|
|
let self = this;
|
2010-07-23 00:03:40 -07:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2011-04-22 13:05:11 -07:00
|
|
|
self.setActive(lastActiveGroupItem);
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function finalize(e) {
|
|
|
|
iQ(window).unbind("mousemove", updateSize);
|
2010-12-12 14:36:19 -08:00
|
|
|
item.container.removeClass("dragRegion");
|
2010-07-23 00:03:40 -07:00
|
|
|
dragOutInfo.stop();
|
2011-01-17 18:44:50 -08:00
|
|
|
let box = item.getBounds();
|
2011-01-10 14:49:29 -08:00
|
|
|
if (box.width > minMinSize && box.height > minMinSize &&
|
|
|
|
(box.width > minSize || box.height > minSize)) {
|
2011-07-04 15:23:35 -07:00
|
|
|
let opts = {bounds: item.getBounds(), focusTitle: true};
|
|
|
|
let groupItem = new GroupItem([], opts);
|
2011-04-22 13:05:11 -07:00
|
|
|
self.setActive(groupItem);
|
2010-07-23 00:03:40 -07:00
|
|
|
phantom.remove();
|
|
|
|
dragOutInfo = null;
|
2011-02-16 08:06:54 -08:00
|
|
|
gTabView.firstUseExperienced = true;
|
2011-01-10 14:49:29 -08:00
|
|
|
} else {
|
|
|
|
collapse();
|
2010-07-23 00:03:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10-09 12:46:18 -07:00
|
|
|
if (!this._pageBounds)
|
|
|
|
return;
|
|
|
|
|
2011-01-21 07:21:30 -08:00
|
|
|
// Here are reasons why we *won't* resize:
|
|
|
|
// 1. Panorama isn't visible (in which case we will resize when we do display)
|
|
|
|
// 2. the screen dimensions haven't changed
|
|
|
|
// 3. everything on the screen fits and nothing feels cramped
|
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
|
|
|
|
2011-01-21 07:21:30 -08:00
|
|
|
let oldPageBounds = new Rect(this._pageBounds);
|
|
|
|
let newPageBounds = Items.getPageBounds();
|
2010-07-03 18:41:31 -07:00
|
|
|
if (newPageBounds.equals(oldPageBounds))
|
|
|
|
return;
|
2010-07-18 08:58:10 -07:00
|
|
|
|
2011-01-21 07:21:30 -08:00
|
|
|
if (!this.shouldResizeItems())
|
|
|
|
return;
|
|
|
|
|
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-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-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
|
|
|
},
|
2011-01-21 07:21:30 -08:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: shouldResizeItems
|
|
|
|
// Returns whether we should resize the items on the screen, based on whether
|
|
|
|
// the top-level items fit in the screen or not and whether they feel
|
|
|
|
// "cramped" or not.
|
|
|
|
// These computations may be done using cached values. The cache can be
|
|
|
|
// cleared with UI.clearShouldResizeItems().
|
|
|
|
shouldResizeItems: function UI_shouldResizeItems() {
|
|
|
|
let newPageBounds = Items.getPageBounds();
|
|
|
|
|
|
|
|
// If we don't have cached cached values...
|
|
|
|
if (this._minimalRect === undefined || this._feelsCramped === undefined) {
|
|
|
|
|
|
|
|
// Loop through every top-level Item for two operations:
|
|
|
|
// 1. check if it is feeling "cramped" due to squishing (a technical term),
|
|
|
|
// 2. union its bounds with the minimalRect
|
|
|
|
let feelsCramped = false;
|
|
|
|
let minimalRect = new Rect(0, 0, 1, 1);
|
|
|
|
|
|
|
|
Items.getTopLevelItems()
|
|
|
|
.forEach(function UI_shouldResizeItems_checkItem(item) {
|
|
|
|
let bounds = new Rect(item.getBounds());
|
|
|
|
feelsCramped = feelsCramped || (item.userSize &&
|
|
|
|
(item.userSize.x > bounds.width || item.userSize.y > bounds.height));
|
|
|
|
bounds.inset(-Trenches.defaultRadius, -Trenches.defaultRadius);
|
|
|
|
minimalRect = minimalRect.union(bounds);
|
|
|
|
});
|
|
|
|
|
|
|
|
// ensure the minimalRect extends to, but not beyond, the origin
|
|
|
|
minimalRect.left = 0;
|
|
|
|
minimalRect.top = 0;
|
|
|
|
|
|
|
|
this._minimalRect = minimalRect;
|
|
|
|
this._feelsCramped = feelsCramped;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._minimalRect.width > newPageBounds.width ||
|
|
|
|
this._minimalRect.height > newPageBounds.height ||
|
|
|
|
this._feelsCramped;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: clearShouldResizeItems
|
|
|
|
// Clear the cache of whether we should resize the items on the Panorama
|
|
|
|
// screen, forcing a recomputation on the next UI.shouldResizeItems()
|
|
|
|
// call.
|
|
|
|
clearShouldResizeItems: function UI_clearShouldResizeItems() {
|
|
|
|
delete this._minimalRect;
|
|
|
|
delete this._feelsCramped;
|
|
|
|
},
|
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;
|
|
|
|
|
2011-09-29 21:17:00 -07:00
|
|
|
if (Search.isEnabled()) {
|
|
|
|
let matcher = Search.createSearchTabMatcher();
|
2010-11-23 23:55:18 -08:00
|
|
|
let matches = matcher.matched();
|
|
|
|
|
|
|
|
if (matches.length > 0) {
|
|
|
|
matches[0].zoomIn();
|
|
|
|
zoomedIn = true;
|
|
|
|
}
|
2011-09-29 21:17:00 -07:00
|
|
|
Search.hide();
|
2010-11-23 23:55:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!zoomedIn) {
|
2010-11-29 18:02:22 -08:00
|
|
|
let unhiddenGroups = GroupItems.groupItems.filter(function(groupItem) {
|
|
|
|
return (!groupItem.hidden && groupItem.getChildren().length > 0);
|
|
|
|
});
|
2011-07-04 15:23:35 -07:00
|
|
|
// no pinned tabs and no visible groups: open a new group. open a blank
|
|
|
|
// tab and return
|
|
|
|
if (!unhiddenGroups.length) {
|
2011-01-20 19:25:18 -08:00
|
|
|
let emptyGroups = GroupItems.groupItems.filter(function (groupItem) {
|
|
|
|
return (!groupItem.hidden && !groupItem.getChildren().length);
|
|
|
|
});
|
|
|
|
let group = (emptyGroups.length ? emptyGroups[0] : GroupItems.newGroup());
|
|
|
|
if (!gBrowser._numPinnedTabs) {
|
2011-06-16 22:05:30 -07:00
|
|
|
group.newTab(null, { closedLastTab: true });
|
2011-01-20 19:25:18 -08:00
|
|
|
return;
|
|
|
|
}
|
2010-11-29 18:02:22 -08:00
|
|
|
}
|
|
|
|
|
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) {
|
2011-01-11 00:20:08 -08:00
|
|
|
let tabItem = gBrowser.selectedTab._tabViewTabItem;
|
2010-11-29 18:02:22 -08:00
|
|
|
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-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();
|
2011-05-03 03:23:44 -07:00
|
|
|
},
|
2011-07-13 10:36:13 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: notifySessionRestoreEnabled
|
|
|
|
// Notify the user that session restore has been automatically enabled
|
|
|
|
// by showing a banner that expects no user interaction. It fades out after
|
|
|
|
// some seconds.
|
|
|
|
notifySessionRestoreEnabled: function UI_notifySessionRestoreEnabled() {
|
|
|
|
let brandBundle = gWindow.document.getElementById("bundle_brand");
|
|
|
|
let brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
let notificationText = tabviewBundle.formatStringFromName(
|
|
|
|
"tabview.notification.sessionStore", [brandShortName], 1);
|
|
|
|
|
|
|
|
let banner = iQ("<div>")
|
|
|
|
.text(notificationText)
|
|
|
|
.addClass("banner")
|
|
|
|
.appendTo("body");
|
|
|
|
|
|
|
|
let onFadeOut = function () {
|
|
|
|
banner.remove();
|
|
|
|
};
|
|
|
|
|
|
|
|
let onFadeIn = function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
banner.animate({opacity: 0}, {duration: 1500, complete: onFadeOut});
|
|
|
|
}, 5000);
|
|
|
|
};
|
|
|
|
|
|
|
|
banner.animate({opacity: 0.7}, {duration: 1500, complete: onFadeIn});
|
2011-02-16 08:06:54 -08: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();
|