2013-06-27 17:37:10 -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/. */
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
// Fired when the tabtray is displayed
|
|
|
|
const kContextUITabsShowEvent = "MozContextUITabsShow";
|
|
|
|
// add more as needed...
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manages context UI (navbar, tabbar, appbar) and track visibility. Also
|
|
|
|
* tracks events that summon and hide the context UI.
|
2013-06-27 17:37:10 -07:00
|
|
|
*/
|
|
|
|
var ContextUI = {
|
|
|
|
_expandable: true,
|
|
|
|
_hidingId: 0,
|
|
|
|
|
|
|
|
/*******************************************
|
|
|
|
* init
|
|
|
|
*/
|
|
|
|
|
|
|
|
init: function init() {
|
2013-06-27 17:37:11 -07:00
|
|
|
Elements.browsers.addEventListener('URLChanged', this, true);
|
2013-09-11 14:26:43 -07:00
|
|
|
Elements.browsers.addEventListener("AlertActive", this, true);
|
|
|
|
Elements.browsers.addEventListener("AlertClose", this, true);
|
2014-03-04 19:16:08 -08:00
|
|
|
Elements.tabList.addEventListener('TabSelect', this, true);
|
2013-06-27 17:37:11 -07:00
|
|
|
Elements.panelUI.addEventListener('ToolPanelShown', this, false);
|
|
|
|
Elements.panelUI.addEventListener('ToolPanelHidden', this, false);
|
|
|
|
|
2013-11-18 15:29:00 -08:00
|
|
|
Elements.tray.addEventListener("mousemove", this, false);
|
|
|
|
Elements.tray.addEventListener("mouseleave", this, false);
|
|
|
|
|
2013-08-27 07:58:43 -07:00
|
|
|
window.addEventListener("touchstart", this, true);
|
|
|
|
window.addEventListener("mousedown", this, true);
|
2013-06-27 17:37:10 -07:00
|
|
|
window.addEventListener("MozEdgeUIStarted", this, true);
|
|
|
|
window.addEventListener("MozEdgeUICanceled", this, true);
|
|
|
|
window.addEventListener("MozEdgeUICompleted", this, true);
|
|
|
|
window.addEventListener("keypress", this, true);
|
|
|
|
window.addEventListener("KeyboardChanged", this, false);
|
2013-08-27 07:58:43 -07:00
|
|
|
window.addEventListener("MozFlyoutPanelShowing", this, false);
|
2013-06-27 17:37:10 -07:00
|
|
|
|
|
|
|
Elements.tray.addEventListener("transitionend", this, true);
|
|
|
|
|
|
|
|
Appbar.init();
|
|
|
|
},
|
|
|
|
|
|
|
|
/*******************************************
|
|
|
|
* Context UI state getters & setters
|
|
|
|
*/
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
// any visiblilty
|
2013-06-27 17:37:10 -07:00
|
|
|
get isVisible() {
|
2013-06-27 17:37:11 -07:00
|
|
|
return this.navbarVisible || this.tabbarVisible || this.contextAppbarVisible;
|
|
|
|
},
|
|
|
|
|
|
|
|
// navbar visiblilty
|
|
|
|
get navbarVisible() {
|
2013-06-27 17:37:10 -07:00
|
|
|
return (Elements.navbar.hasAttribute("visible") ||
|
|
|
|
Elements.navbar.hasAttribute("startpage"));
|
|
|
|
},
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
// tabbar visiblilty
|
|
|
|
get tabbarVisible() {
|
|
|
|
return Elements.tray.hasAttribute("expanded");
|
|
|
|
},
|
|
|
|
|
|
|
|
// appbar visiblilty
|
|
|
|
get contextAppbarVisible() {
|
|
|
|
return Elements.contextappbar.isShowing;
|
|
|
|
},
|
|
|
|
|
|
|
|
// currently not in use, for the always show tabs feature
|
|
|
|
get isExpandable() { return this._expandable; },
|
2013-06-27 17:37:10 -07:00
|
|
|
set isExpandable(aFlag) {
|
|
|
|
this._expandable = aFlag;
|
|
|
|
if (!this._expandable)
|
|
|
|
this.dismiss();
|
|
|
|
},
|
|
|
|
|
|
|
|
/*******************************************
|
2013-06-27 17:37:11 -07:00
|
|
|
* Public api
|
2013-06-27 17:37:10 -07:00
|
|
|
*/
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
/*
|
|
|
|
* Toggle the current nav UI state. Fires context ui events.
|
|
|
|
*/
|
|
|
|
toggleNavUI: function () {
|
|
|
|
// The navbar is forced open when the start page is visible. appbar.js
|
|
|
|
// controls the "visible" property, and browser-ui controls the "startpage"
|
|
|
|
// property. Hence we rely on the tabbar for current toggle state.
|
|
|
|
if (this.tabbarVisible) {
|
|
|
|
this.dismiss();
|
|
|
|
} else {
|
|
|
|
this.displayNavUI();
|
2013-06-27 17:37:10 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
/*
|
|
|
|
* Show the nav and tabs bar. Returns true if any non-visible UI
|
|
|
|
* was shown. Fires context ui events.
|
|
|
|
*/
|
|
|
|
displayNavUI: function () {
|
2013-06-27 17:37:10 -07:00
|
|
|
let shown = false;
|
2013-06-27 17:37:11 -07:00
|
|
|
|
|
|
|
if (!this.navbarVisible) {
|
2013-07-25 17:25:14 -07:00
|
|
|
BrowserUI.updateURI();
|
2013-06-27 17:37:11 -07:00
|
|
|
this.displayNavbar();
|
2013-06-27 17:37:10 -07:00
|
|
|
shown = true;
|
|
|
|
}
|
2013-06-27 17:37:11 -07:00
|
|
|
|
|
|
|
if (!this.tabbarVisible) {
|
|
|
|
this.displayTabs();
|
2013-06-27 17:37:10 -07:00
|
|
|
shown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shown) {
|
2014-01-14 12:35:53 -08:00
|
|
|
ContentAreaObserver.updateContentArea();
|
2013-06-27 17:37:10 -07:00
|
|
|
}
|
2013-06-27 17:37:11 -07:00
|
|
|
|
2013-06-27 17:37:10 -07:00
|
|
|
return shown;
|
|
|
|
},
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
/*
|
|
|
|
* Dismiss any context UI currently visible. Returns true if any
|
|
|
|
* visible UI was dismissed. Fires context ui events.
|
|
|
|
*/
|
|
|
|
dismiss: function () {
|
|
|
|
let dismissed = false;
|
2013-06-27 17:37:10 -07:00
|
|
|
|
|
|
|
this._clearDelayedTimeout();
|
2013-06-27 17:37:11 -07:00
|
|
|
|
|
|
|
// No assurances this will hide the nav bar. It may have the
|
|
|
|
// 'startpage' property set. This removes the 'visible' property.
|
|
|
|
if (this.navbarVisible) {
|
2013-09-12 14:20:30 -07:00
|
|
|
BrowserUI.blurNavBar();
|
2013-06-27 17:37:11 -07:00
|
|
|
this.dismissNavbar();
|
|
|
|
dismissed = true;
|
|
|
|
}
|
|
|
|
if (this.tabbarVisible) {
|
|
|
|
this.dismissTabs();
|
|
|
|
dismissed = true;
|
|
|
|
}
|
|
|
|
if (Elements.contextappbar.isShowing) {
|
|
|
|
this.dismissContextAppbar();
|
|
|
|
dismissed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dismissed) {
|
2014-01-14 12:35:53 -08:00
|
|
|
ContentAreaObserver.updateContentArea();
|
2013-06-27 17:37:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return dismissed;
|
2013-06-27 17:37:10 -07:00
|
|
|
},
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
/*
|
|
|
|
* Briefly show the tab bar and then hide it. Fires context ui events.
|
|
|
|
*/
|
2013-07-12 17:12:46 -07:00
|
|
|
peekTabs: function peekTabs(aDelay) {
|
|
|
|
if (!this.tabbarVisible)
|
2013-06-27 17:37:10 -07:00
|
|
|
this.displayTabs();
|
2013-07-12 17:12:46 -07:00
|
|
|
|
|
|
|
ContextUI.dismissTabsWithDelay(aDelay);
|
2013-06-27 17:37:10 -07:00
|
|
|
},
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
/*
|
2013-07-09 16:17:22 -07:00
|
|
|
* Dismiss tab bar after a delay. Fires context ui events.
|
2013-06-27 17:37:11 -07:00
|
|
|
*/
|
2013-07-09 16:17:22 -07:00
|
|
|
dismissTabsWithDelay: function (aDelay) {
|
2013-11-12 18:05:55 -08:00
|
|
|
aDelay = aDelay || kForegroundTabAnimationDelay;
|
2013-06-27 17:37:10 -07:00
|
|
|
this._clearDelayedTimeout();
|
2013-11-18 15:29:00 -08:00
|
|
|
this._lastTimeoutDelay = aDelay;
|
2013-06-27 17:37:10 -07:00
|
|
|
this._hidingId = setTimeout(function () {
|
2013-07-09 16:17:22 -07:00
|
|
|
ContextUI.dismissTabs();
|
2013-06-27 17:37:10 -07:00
|
|
|
}, aDelay);
|
|
|
|
},
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
// Display the nav bar
|
|
|
|
displayNavbar: function () {
|
|
|
|
Elements.navbar.show();
|
2014-03-04 19:16:07 -08:00
|
|
|
Elements.chromeState.setAttribute("navbar", "visible");
|
2013-08-15 10:06:42 -07:00
|
|
|
ContentAreaObserver.updateContentArea();
|
2013-06-27 17:37:11 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Display the tab tray
|
|
|
|
displayTabs: function () {
|
|
|
|
this._clearDelayedTimeout();
|
|
|
|
this._setIsExpanded(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Dismiss the navbar if visible.
|
|
|
|
dismissNavbar: function dismissNavbar() {
|
2013-08-09 02:50:58 -07:00
|
|
|
if (!BrowserUI.isStartTabVisible) {
|
2013-09-17 07:08:18 -07:00
|
|
|
Elements.autocomplete.closePopup();
|
2013-08-01 11:59:17 -07:00
|
|
|
Elements.navbar.dismiss();
|
2014-03-04 19:16:07 -08:00
|
|
|
Elements.chromeState.removeAttribute("navbar");
|
2013-08-15 10:06:42 -07:00
|
|
|
ContentAreaObserver.updateContentArea();
|
2013-08-01 11:59:17 -07:00
|
|
|
}
|
2013-06-27 17:37:11 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Dismiss the tabstray if visible.
|
2013-06-27 17:37:10 -07:00
|
|
|
dismissTabs: function dimissTabs() {
|
|
|
|
this._clearDelayedTimeout();
|
2013-06-27 17:37:11 -07:00
|
|
|
this._setIsExpanded(false);
|
2013-06-27 17:37:10 -07:00
|
|
|
},
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
// Dismiss the appbar if visible.
|
|
|
|
dismissContextAppbar: function dismissContextAppbar() {
|
|
|
|
Elements.contextappbar.dismiss();
|
2013-06-27 17:37:10 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/*******************************************
|
2013-06-27 17:37:11 -07:00
|
|
|
* Internal utils
|
2013-06-27 17:37:10 -07:00
|
|
|
*/
|
|
|
|
|
2013-06-27 17:37:11 -07:00
|
|
|
// tabtray state
|
2013-06-27 17:37:10 -07:00
|
|
|
_setIsExpanded: function _setIsExpanded(aFlag, setSilently) {
|
|
|
|
// if the tray can't be expanded, don't expand it.
|
2013-06-27 17:37:11 -07:00
|
|
|
if (!this.isExpandable || this.tabbarVisible == aFlag)
|
2013-06-27 17:37:10 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (aFlag)
|
|
|
|
Elements.tray.setAttribute("expanded", "true");
|
|
|
|
else
|
|
|
|
Elements.tray.removeAttribute("expanded");
|
|
|
|
|
|
|
|
if (!setSilently)
|
2013-06-27 17:37:11 -07:00
|
|
|
this._fire(kContextUITabsShowEvent);
|
2013-06-27 17:37:10 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_clearDelayedTimeout: function _clearDelayedTimeout() {
|
|
|
|
if (this._hidingId) {
|
|
|
|
clearTimeout(this._hidingId);
|
|
|
|
this._hidingId = 0;
|
2013-11-18 15:29:00 -08:00
|
|
|
this._delayedHide = false;
|
2013-06-27 17:37:10 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-18 15:29:00 -08:00
|
|
|
_resetDelayedTimeout: function () {
|
|
|
|
this._hidingId = setTimeout(function () {
|
|
|
|
ContextUI.dismissTabs();
|
|
|
|
}, this._lastTimeoutDelay);
|
|
|
|
},
|
|
|
|
|
2013-06-27 17:37:10 -07:00
|
|
|
/*******************************************
|
|
|
|
* Events
|
|
|
|
*/
|
|
|
|
|
|
|
|
_onEdgeUIStarted: function(aEvent) {
|
|
|
|
this._hasEdgeSwipeStarted = true;
|
|
|
|
this._clearDelayedTimeout();
|
2013-06-27 17:37:11 -07:00
|
|
|
this.toggleNavUI();
|
2013-06-27 17:37:10 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_onEdgeUICanceled: function(aEvent) {
|
|
|
|
this._hasEdgeSwipeStarted = false;
|
|
|
|
this.dismiss();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onEdgeUICompleted: function(aEvent) {
|
|
|
|
if (this._hasEdgeSwipeStarted) {
|
|
|
|
this._hasEdgeSwipeStarted = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._clearDelayedTimeout();
|
2013-06-27 17:37:11 -07:00
|
|
|
this.toggleNavUI();
|
2013-06-27 17:37:10 -07:00
|
|
|
},
|
|
|
|
|
2013-08-27 07:58:43 -07:00
|
|
|
onDownInput: function onDownInput(aEvent) {
|
|
|
|
if (!this.isVisible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Various ui element containers we do not update context ui for.
|
|
|
|
let whitelist = [
|
|
|
|
// Clicks on tab bar elements should not close the tab bar. the tabbar
|
|
|
|
// handles this.
|
|
|
|
Elements.tabs,
|
|
|
|
// Don't let a click on an infobar button dismiss the appbar or navbar.
|
|
|
|
// Note the notification box should always hover above these other two
|
|
|
|
// bars.
|
|
|
|
Browser.getNotificationBox()
|
|
|
|
];
|
|
|
|
|
|
|
|
if (whitelist.some(elem => elem.contains(aEvent.target))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a start tab is visible only dismiss the tab bar.
|
|
|
|
if (BrowserUI.isStartTabVisible) {
|
|
|
|
ContextUI.dismissTabs();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// content, dismiss anything visible
|
|
|
|
if (aEvent.target.ownerDocument.defaultView.top == getBrowser().contentWindow) {
|
|
|
|
this.dismiss();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// dismiss tabs and context app bar if visible
|
|
|
|
this.dismissTabs();
|
|
|
|
this.dismissContextAppbar();
|
|
|
|
},
|
|
|
|
|
2013-11-18 15:29:00 -08:00
|
|
|
onMouseMove: function (aEvent) {
|
|
|
|
if (this._hidingId) {
|
|
|
|
this._clearDelayedTimeout();
|
|
|
|
this._delayedHide = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onMouseLeave: function (aEvent) {
|
|
|
|
if (this._delayedHide) {
|
|
|
|
this._delayedHide = false;
|
|
|
|
this._resetDelayedTimeout();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-06-27 17:37:10 -07:00
|
|
|
handleEvent: function handleEvent(aEvent) {
|
|
|
|
switch (aEvent.type) {
|
2013-08-27 07:58:43 -07:00
|
|
|
case "URLChanged":
|
2014-01-17 08:58:39 -08:00
|
|
|
// "aEvent.detail" is a boolean value that indicates whether actual URL
|
|
|
|
// has changed ignoring URL fragment changes.
|
|
|
|
if (aEvent.target == Browser.selectedBrowser && aEvent.detail) {
|
2013-11-06 12:06:47 -08:00
|
|
|
this.displayNavbar();
|
|
|
|
}
|
2013-08-27 07:58:43 -07:00
|
|
|
break;
|
2013-06-27 17:37:10 -07:00
|
|
|
case "MozEdgeUIStarted":
|
|
|
|
this._onEdgeUIStarted(aEvent);
|
|
|
|
break;
|
|
|
|
case "MozEdgeUICanceled":
|
|
|
|
this._onEdgeUICanceled(aEvent);
|
|
|
|
break;
|
|
|
|
case "MozEdgeUICompleted":
|
|
|
|
this._onEdgeUICompleted(aEvent);
|
|
|
|
break;
|
|
|
|
case "keypress":
|
|
|
|
if (String.fromCharCode(aEvent.which) == "z" &&
|
|
|
|
aEvent.getModifierState("Win"))
|
2013-06-27 17:37:11 -07:00
|
|
|
this.toggleNavUI();
|
2013-06-27 17:37:10 -07:00
|
|
|
break;
|
|
|
|
case "transitionend":
|
|
|
|
setTimeout(function () {
|
|
|
|
ContentAreaObserver.updateContentArea();
|
|
|
|
}, 0);
|
|
|
|
break;
|
|
|
|
case "KeyboardChanged":
|
|
|
|
this.dismissTabs();
|
|
|
|
break;
|
2013-06-27 17:37:11 -07:00
|
|
|
case "mousedown":
|
2013-08-27 07:58:43 -07:00
|
|
|
if (aEvent.button != 0) {
|
2013-08-09 02:50:59 -07:00
|
|
|
break;
|
2013-08-15 10:06:42 -07:00
|
|
|
}
|
2013-08-27 07:58:43 -07:00
|
|
|
this.onDownInput(aEvent);
|
|
|
|
break;
|
2013-11-18 15:29:00 -08:00
|
|
|
case "mousemove":
|
|
|
|
this.onMouseMove(aEvent);
|
|
|
|
break;
|
|
|
|
case "mouseleave":
|
|
|
|
this.onMouseLeave(aEvent);
|
|
|
|
break;
|
2013-08-27 07:58:43 -07:00
|
|
|
case "touchstart":
|
|
|
|
this.onDownInput(aEvent);
|
2013-06-27 17:37:11 -07:00
|
|
|
break;
|
2013-07-12 17:12:46 -07:00
|
|
|
case "ToolPanelShown":
|
|
|
|
case "ToolPanelHidden":
|
2013-06-27 17:37:11 -07:00
|
|
|
this.dismiss();
|
|
|
|
break;
|
2013-09-11 14:26:43 -07:00
|
|
|
case "AlertActive":
|
|
|
|
case "AlertClose":
|
2014-03-04 19:16:08 -08:00
|
|
|
case "TabSelect":
|
2013-09-11 14:26:43 -07:00
|
|
|
ContentAreaObserver.updateContentArea();
|
|
|
|
break;
|
2013-08-27 07:58:43 -07:00
|
|
|
case "MozFlyoutPanelShowing":
|
|
|
|
if (BrowserUI.isStartTabVisible) {
|
|
|
|
this.dismissTabs();
|
|
|
|
this.dismissContextAppbar();
|
|
|
|
} else {
|
|
|
|
this.dismiss();
|
|
|
|
}
|
|
|
|
break;
|
2013-06-27 17:37:10 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_fire: function (name) {
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent(name, true, true);
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
};
|