2008-09-26 00:34:54 -07:00
|
|
|
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
|
2008-05-02 13:15:45 -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 Mozilla Mobile Browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2008
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Mark Finkle <mfinkle@mozilla.com>
|
2010-10-16 06:25:15 -07:00
|
|
|
* Matt Brubeck <mbrubeck@mozilla.com>
|
2008-05-02 13:15:45 -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-03-22 07:05:27 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-07-13 07:36:09 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2010-03-22 07:05:27 -07:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "PluralForm", function() {
|
|
|
|
Cu.import("resource://gre/modules/PluralForm.jsm");
|
|
|
|
return PluralForm;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "PlacesUtils", function() {
|
2010-06-03 15:55:46 -07:00
|
|
|
Cu.import("resource://gre/modules/PlacesUtils.jsm");
|
2010-03-22 07:05:27 -07:00
|
|
|
return PlacesUtils;
|
|
|
|
});
|
2008-10-01 12:54:16 -07:00
|
|
|
|
2010-09-03 02:01:25 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(window, "gHistSvc", "@mozilla.org/browser/nav-history-service;1", "nsINavHistoryService", "nsIBrowserHistory");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(window, "gURIFixup", "@mozilla.org/docshell/urifixup;1", "nsIURIFixup");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(window, "gFaviconService", "@mozilla.org/browser/favicon-service;1", "nsIFaviconService");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(window, "gFocusManager", "@mozilla.org/focus-manager;1", "nsIFocusManager");
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2008-09-29 06:53:49 -07:00
|
|
|
[
|
2010-09-03 02:01:25 -07:00
|
|
|
["AllPagesList", "popup_autocomplete", "cmd_openLocation"],
|
|
|
|
["HistoryList", "history-items", "cmd_history"],
|
|
|
|
["BookmarkList", "bookmarks-items", "cmd_bookmarks"],
|
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
|
|
|
["RemoteTabsList", "remotetabs-items", "cmd_remoteTabs"]
|
|
|
|
#endif
|
|
|
|
].forEach(function(aPanel) {
|
|
|
|
let [name, id, command] = aPanel;
|
|
|
|
XPCOMUtils.defineLazyGetter(window, name, function() {
|
|
|
|
return new AwesomePanel(id, command);
|
2008-09-29 06:53:49 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-09-03 02:01:25 -07:00
|
|
|
/**
|
|
|
|
* Cache of commonly used elements.
|
|
|
|
*/
|
|
|
|
let Elements = {};
|
|
|
|
|
|
|
|
[
|
|
|
|
["browserBundle", "bundle_browser"],
|
|
|
|
["contentShowing", "bcast_contentShowing"],
|
|
|
|
["urlbarState", "bcast_urlbarState"],
|
|
|
|
["stack", "stack"],
|
|
|
|
["tabs", "tabs-container"],
|
|
|
|
["controls", "browser-controls"],
|
|
|
|
["panelUI", "panel-container"],
|
|
|
|
["viewBuffer", "view-buffer"],
|
|
|
|
["toolbarContainer", "toolbar-container"],
|
2010-09-29 10:43:00 -07:00
|
|
|
["browsers", "browsers"]
|
2010-09-03 02:01:25 -07:00
|
|
|
].forEach(function (aElementGlobal) {
|
|
|
|
let [name, id] = aElementGlobal;
|
|
|
|
XPCOMUtils.defineLazyGetter(Elements, name, function() {
|
|
|
|
return document.getElementById(id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const TOOLBARSTATE_LOADING = 1;
|
|
|
|
const TOOLBARSTATE_LOADED = 2;
|
|
|
|
|
2008-07-03 23:39:25 -07:00
|
|
|
var BrowserUI = {
|
2010-11-02 12:20:11 -07:00
|
|
|
_edit: null,
|
|
|
|
_title: null,
|
|
|
|
_throbber: null,
|
|
|
|
_favicon: null,
|
2009-07-08 07:55:07 -07:00
|
|
|
_dialogs: [],
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
_domWillOpenModalDialog: function(aBrowser) {
|
2009-09-30 12:14:06 -07:00
|
|
|
// We're about to open a modal dialog, make sure the opening
|
|
|
|
// tab is brought to the front.
|
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
for (let i = 0; i < Browser.tabs.length; i++) {
|
|
|
|
if (Browser._tabs[i].browser == aBrowser) {
|
|
|
|
Browser.selectedTab = Browser.tabs[i];
|
2009-10-14 13:44:09 -07:00
|
|
|
break;
|
2009-09-30 12:14:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
_titleChanged: function(aBrowser) {
|
2010-10-10 14:23:28 -07:00
|
|
|
let browser = Browser.selectedBrowser;
|
2010-06-08 08:22:20 -07:00
|
|
|
if (browser && aBrowser != browser)
|
2008-05-02 13:15:45 -07:00
|
|
|
return;
|
|
|
|
|
2010-10-10 14:23:28 -07:00
|
|
|
let url = this.getDisplayURI(browser);
|
|
|
|
let caption = browser.contentTitle || url;
|
2010-04-08 22:08:53 -07:00
|
|
|
|
|
|
|
if (Util.isURLEmpty(url))
|
|
|
|
caption = "";
|
2009-09-18 21:17:52 -07:00
|
|
|
|
2010-11-02 12:20:11 -07:00
|
|
|
if (caption) {
|
|
|
|
this._title.value = caption;
|
|
|
|
this._title.classList.remove("placeholder");
|
|
|
|
} else {
|
|
|
|
this._title.value = this._title.getAttribute("placeholder");
|
|
|
|
this._title.classList.add("placeholder");
|
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2009-07-16 08:45:50 -07:00
|
|
|
/*
|
|
|
|
* Dispatched by window.close() to allow us to turn window closes into tabs
|
|
|
|
* closes.
|
|
|
|
*/
|
2010-06-08 08:22:20 -07:00
|
|
|
_domWindowClose: function(aBrowser) {
|
|
|
|
// Find the relevant tab, and close it.
|
|
|
|
let browsers = Browser.browsers;
|
|
|
|
for (let i = 0; i < browsers.length; i++) {
|
|
|
|
if (browsers[i] == aBrowser) {
|
2009-07-16 08:45:50 -07:00
|
|
|
Browser.closeTab(Browser.getTabAtIndex(i));
|
2010-06-08 08:22:20 -07:00
|
|
|
return { preventDefault: true };
|
2009-07-16 08:45:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
_updateButtons: function(aBrowser) {
|
2009-11-22 20:08:18 -08:00
|
|
|
let back = document.getElementById("cmd_back");
|
|
|
|
let forward = document.getElementById("cmd_forward");
|
2009-06-24 15:43:26 -07:00
|
|
|
|
|
|
|
back.setAttribute("disabled", !aBrowser.canGoBack);
|
|
|
|
forward.setAttribute("disabled", !aBrowser.canGoForward);
|
|
|
|
},
|
|
|
|
|
2010-04-29 22:28:40 -07:00
|
|
|
_updateToolbar: function _updateToolbar() {
|
2010-08-26 15:48:27 -07:00
|
|
|
let mode = Elements.urlbarState.getAttribute("mode");
|
2010-05-06 07:32:24 -07:00
|
|
|
if (Browser.selectedTab.isLoading() && mode != "loading") {
|
2010-08-26 15:48:27 -07:00
|
|
|
Elements.urlbarState.setAttribute("mode", "loading");
|
2009-11-22 20:08:18 -08:00
|
|
|
}
|
2010-05-06 07:32:24 -07:00
|
|
|
else if (mode != "view") {
|
2010-08-26 15:48:27 -07:00
|
|
|
Elements.urlbarState.setAttribute("mode", "view");
|
2009-11-22 20:08:18 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
_tabSelect: function(aEvent) {
|
2009-11-22 20:08:18 -08:00
|
|
|
let browser = Browser.selectedBrowser;
|
2010-06-08 08:22:20 -07:00
|
|
|
this._titleChanged(browser);
|
2010-04-29 22:28:40 -07:00
|
|
|
this._updateToolbar();
|
2009-06-24 15:43:26 -07:00
|
|
|
this._updateButtons(browser);
|
2009-10-09 05:34:02 -07:00
|
|
|
this._updateIcon(browser.mIconURL);
|
2009-07-05 09:22:09 -07:00
|
|
|
this.updateStar();
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2009-08-24 07:18:26 -07:00
|
|
|
_toolbarLocked: 0,
|
2009-11-23 23:46:01 -08:00
|
|
|
|
|
|
|
isToolbarLocked: function isToolbarLocked() {
|
|
|
|
return this._toolbarLocked;
|
|
|
|
},
|
|
|
|
|
2009-08-24 07:18:26 -07:00
|
|
|
lockToolbar: function lockToolbar() {
|
|
|
|
this._toolbarLocked++;
|
|
|
|
document.getElementById("toolbar-moveable-container").top = "0";
|
2009-11-02 21:13:42 -08:00
|
|
|
if (this._toolbarLocked == 1)
|
|
|
|
Browser.forceChromeReflow();
|
2009-08-24 07:18:26 -07:00
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-08-24 07:18:26 -07:00
|
|
|
unlockToolbar: function unlockToolbar() {
|
|
|
|
if (!this._toolbarLocked)
|
|
|
|
return;
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-08-24 07:18:26 -07:00
|
|
|
this._toolbarLocked--;
|
2009-08-26 10:18:13 -07:00
|
|
|
if (!this._toolbarLocked)
|
2009-08-24 07:18:26 -07:00
|
|
|
document.getElementById("toolbar-moveable-container").top = "";
|
|
|
|
},
|
|
|
|
|
2010-11-02 12:20:11 -07:00
|
|
|
_setURL: function _setURL(aURL) {
|
2010-10-14 06:15:29 -07:00
|
|
|
if (this.activePanel)
|
2010-11-02 12:20:11 -07:00
|
|
|
this._edit.defaultValue = aURL;
|
2009-09-18 21:17:52 -07:00
|
|
|
else
|
2010-11-02 12:20:11 -07:00
|
|
|
this._edit.value = aURL;
|
2009-09-18 21:17:52 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
_editURI: function _editURI(aEdit) {
|
2010-10-14 06:15:29 -07:00
|
|
|
Elements.urlbarState.setAttribute("mode", "edit");
|
|
|
|
this._edit.defaultValue = this._edit.value;
|
|
|
|
},
|
|
|
|
|
|
|
|
_showURI: function _showURI() {
|
|
|
|
// Replace the web page title by the url of the page
|
|
|
|
let urlString = this.getDisplayURI(Browser.selectedBrowser);
|
|
|
|
if (Util.isURLEmpty(urlString))
|
|
|
|
urlString = "";
|
|
|
|
|
|
|
|
this._edit.value = urlString;
|
2008-09-11 18:11:46 -07:00
|
|
|
},
|
|
|
|
|
2010-10-10 14:23:28 -07:00
|
|
|
updateAwesomeHeader: function updateAwesomeHeader(aString) {
|
2010-10-14 06:15:29 -07:00
|
|
|
document.getElementById("awesome-header").hidden = (aString != "");
|
|
|
|
|
2010-10-10 14:23:28 -07:00
|
|
|
// During an awesome search we always show the popup_autocomplete/AllPagesList
|
|
|
|
// panel since this looks in every places and the rationale behind typing
|
|
|
|
// is to find something, whereever it is.
|
|
|
|
if (this.activePanel != AllPagesList) {
|
|
|
|
let inputField = this._edit;
|
|
|
|
let oldClickSelectsAll = inputField.clickSelectsAll;
|
|
|
|
inputField.clickSelectsAll = false;
|
|
|
|
|
|
|
|
this.activePanel = AllPagesList;
|
|
|
|
|
|
|
|
// changing the searchString property call updateAwesomeHeader again
|
|
|
|
inputField.controller.searchString = aString;
|
|
|
|
inputField.readOnly = false;
|
|
|
|
inputField.clickSelectsAll = oldClickSelectsAll;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("onsearchbegin", true, true);
|
|
|
|
this._edit.dispatchEvent(event);
|
2010-08-24 01:42:28 -07:00
|
|
|
},
|
|
|
|
|
2009-07-08 07:55:07 -07:00
|
|
|
_closeOrQuit: function _closeOrQuit() {
|
|
|
|
// Close active dialog, if we have one. If not then close the application.
|
2010-08-24 01:42:28 -07:00
|
|
|
if (this.activePanel) {
|
|
|
|
this.activePanel = null;
|
|
|
|
} else if (this.activeDialog) {
|
|
|
|
this.activeDialog.close();
|
2010-03-30 10:27:59 -07:00
|
|
|
} else {
|
|
|
|
// Check to see if we should really close the window
|
|
|
|
if (Browser.closing())
|
|
|
|
window.close();
|
|
|
|
}
|
2009-07-08 07:55:07 -07:00
|
|
|
},
|
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
_activePanel: null,
|
|
|
|
get activePanel() {
|
|
|
|
return this._activePanel;
|
|
|
|
},
|
|
|
|
|
|
|
|
set activePanel(aPanel) {
|
2010-08-27 01:25:04 -07:00
|
|
|
if (this._activePanel == aPanel)
|
|
|
|
return;
|
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
let awesomePanel = document.getElementById("awesome-panels");
|
|
|
|
let awesomeHeader = document.getElementById("awesome-header");
|
|
|
|
|
|
|
|
let willShowPanel = (!this._activePanel && aPanel);
|
|
|
|
if (willShowPanel) {
|
|
|
|
this.pushDialog(aPanel);
|
|
|
|
this._edit.attachController();
|
|
|
|
this._editURI();
|
|
|
|
awesomePanel.hidden = awesomeHeader.hidden = false;
|
|
|
|
};
|
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
if (aPanel) {
|
|
|
|
aPanel.open();
|
2010-10-14 06:15:29 -07:00
|
|
|
if (this._edit.value == "")
|
|
|
|
this._showURI();
|
2010-08-24 01:42:28 -07:00
|
|
|
}
|
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
let willHidePanel = (this._activePanel && !aPanel);
|
|
|
|
if (willHidePanel) {
|
|
|
|
awesomePanel.hidden = true;
|
|
|
|
awesomeHeader.hidden = false;
|
|
|
|
this._updateToolbar();
|
|
|
|
this._edit.reset();
|
|
|
|
this._edit.detachController();
|
|
|
|
this.popDialog();
|
|
|
|
}
|
2010-10-10 14:23:28 -07:00
|
|
|
|
2010-08-27 01:25:04 -07:00
|
|
|
if (this._activePanel)
|
2010-08-24 01:42:28 -07:00
|
|
|
this._activePanel.close();
|
2010-10-10 14:23:28 -07:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
// The readOnly state of the field enabled/disabled the VKB
|
2010-11-04 11:47:09 -07:00
|
|
|
let isReadOnly = !(aPanel == AllPagesList && Util.isPortrait() && (willShowPanel || !this._edit.readOnly));
|
2010-10-14 06:15:29 -07:00
|
|
|
this._edit.readOnly = isReadOnly;
|
|
|
|
if (isReadOnly)
|
|
|
|
this._edit.blur();
|
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
this._activePanel = aPanel;
|
2010-10-14 06:15:29 -07:00
|
|
|
if (willHidePanel || willShowPanel) {
|
|
|
|
let event = document.createEvent("UIEvents");
|
|
|
|
event.initUIEvent("NavigationPanel" + (willHidePanel ? "Hidden" : "Shown"), true, true, window, false);
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
}
|
2010-08-24 01:42:28 -07:00
|
|
|
},
|
|
|
|
|
2009-07-08 07:55:07 -07:00
|
|
|
get activeDialog() {
|
|
|
|
// Return the topmost dialog
|
|
|
|
if (this._dialogs.length)
|
|
|
|
return this._dialogs[this._dialogs.length - 1];
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
pushDialog: function pushDialog(aDialog) {
|
2009-07-08 07:55:07 -07:00
|
|
|
// If we have a dialog push it on the stack and set the attr for CSS
|
|
|
|
if (aDialog) {
|
2009-08-24 07:18:26 -07:00
|
|
|
this.lockToolbar();
|
2009-07-08 07:55:07 -07:00
|
|
|
this._dialogs.push(aDialog);
|
2009-07-20 13:22:22 -07:00
|
|
|
document.getElementById("toolbar-main").setAttribute("dialog", "true");
|
2009-11-23 09:23:59 -08:00
|
|
|
Elements.contentShowing.setAttribute("disabled", "true");
|
2009-07-08 07:55:07 -07:00
|
|
|
}
|
|
|
|
},
|
2009-07-21 08:28:29 -07:00
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
popDialog: function popDialog() {
|
2009-08-24 07:22:26 -07:00
|
|
|
if (this._dialogs.length) {
|
2009-07-08 07:55:07 -07:00
|
|
|
this._dialogs.pop();
|
2009-08-24 07:22:26 -07:00
|
|
|
this.unlockToolbar();
|
|
|
|
}
|
2009-07-08 07:55:07 -07:00
|
|
|
|
|
|
|
// If no more dialogs are being displayed, remove the attr for CSS
|
2009-11-23 09:23:59 -08:00
|
|
|
if (!this._dialogs.length) {
|
2009-07-20 13:22:22 -07:00
|
|
|
document.getElementById("toolbar-main").removeAttribute("dialog");
|
2009-11-23 09:23:59 -08:00
|
|
|
Elements.contentShowing.removeAttribute("disabled");
|
|
|
|
}
|
2009-07-08 07:55:07 -07:00
|
|
|
},
|
|
|
|
|
2009-08-14 10:30:50 -07:00
|
|
|
pushPopup: function pushPopup(aPanel, aElements) {
|
2009-12-04 12:03:56 -08:00
|
|
|
this._hidePopup();
|
2010-01-15 21:41:48 -08:00
|
|
|
this._popup = { "panel": aPanel,
|
2009-08-14 10:30:50 -07:00
|
|
|
"elements": (aElements instanceof Array) ? aElements : [aElements] };
|
2010-10-14 10:19:04 -07:00
|
|
|
this._dispatchPopupChanged(true);
|
2009-08-14 10:30:50 -07:00
|
|
|
},
|
|
|
|
|
2010-11-01 08:42:13 -07:00
|
|
|
popPopup: function popPopup(aPanel) {
|
2010-11-01 16:58:56 -07:00
|
|
|
if (!this._popup || aPanel != this._popup.panel)
|
2010-11-01 08:42:13 -07:00
|
|
|
return;
|
2009-08-14 10:30:50 -07:00
|
|
|
this._popup = null;
|
2010-10-14 10:19:04 -07:00
|
|
|
this._dispatchPopupChanged(false);
|
2009-08-14 10:30:50 -07:00
|
|
|
},
|
|
|
|
|
2010-10-14 10:19:04 -07:00
|
|
|
_dispatchPopupChanged: function _dispatchPopupChanged(aVisible) {
|
2009-12-04 12:03:56 -08:00
|
|
|
let stack = document.getElementById("stack");
|
2010-10-14 10:19:04 -07:00
|
|
|
let event = document.createEvent("UIEvents");
|
|
|
|
event.initUIEvent("PopupChanged", true, true, window, aVisible);
|
2009-12-04 12:03:56 -08:00
|
|
|
event.popup = this._popup;
|
|
|
|
stack.dispatchEvent(event);
|
|
|
|
},
|
|
|
|
|
|
|
|
_hidePopup: function _hidePopup() {
|
2009-08-14 10:30:50 -07:00
|
|
|
if (!this._popup)
|
|
|
|
return;
|
2009-12-04 12:03:56 -08:00
|
|
|
let panel = this._popup.panel;
|
|
|
|
if (panel.hide)
|
|
|
|
panel.hide();
|
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-12-04 12:03:56 -08:00
|
|
|
_isEventInsidePopup: function _isEventInsidePopup(aEvent) {
|
|
|
|
if (!this._popup)
|
2009-12-17 14:35:48 -08:00
|
|
|
return false;
|
2009-12-04 12:03:56 -08:00
|
|
|
let elements = this._popup.elements;
|
2009-10-28 23:12:10 -07:00
|
|
|
let targetNode = aEvent ? aEvent.target : null;
|
2009-12-04 12:03:56 -08:00
|
|
|
while (targetNode && elements.indexOf(targetNode) == -1)
|
2009-08-14 10:30:50 -07:00
|
|
|
targetNode = targetNode.parentNode;
|
2009-12-04 12:03:56 -08:00
|
|
|
return targetNode ? true : false;
|
2009-08-14 10:30:50 -07:00
|
|
|
},
|
|
|
|
|
2010-09-30 14:30:27 -07:00
|
|
|
switchPane: function switchPane(aPanelId) {
|
|
|
|
let button = document.getElementsByAttribute("linkedpanel", aPanelId)[0];
|
2009-11-03 10:32:44 -08:00
|
|
|
if (button)
|
|
|
|
button.checked = true;
|
2009-12-17 14:35:48 -08:00
|
|
|
|
2010-06-14 06:14:16 -07:00
|
|
|
this.blurFocusedElement();
|
|
|
|
|
2010-09-30 14:30:27 -07:00
|
|
|
let pane = document.getElementById(aPanelId);
|
2009-12-17 14:35:48 -08:00
|
|
|
document.getElementById("panel-items").selectedPanel = pane;
|
2008-09-28 06:45:47 -07:00
|
|
|
},
|
|
|
|
|
2009-05-28 22:58:30 -07:00
|
|
|
get toolbarH() {
|
|
|
|
if (!this._toolbarH) {
|
|
|
|
let toolbar = document.getElementById("toolbar-main");
|
|
|
|
this._toolbarH = toolbar.boxObject.height;
|
|
|
|
}
|
|
|
|
return this._toolbarH;
|
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-08-17 14:05:06 -07:00
|
|
|
get sidebarW() {
|
2010-09-02 18:27:20 -07:00
|
|
|
delete this._sidebarW;
|
|
|
|
return this._sidebarW = Elements.controls.getBoundingClientRect().width;
|
2009-08-17 14:05:06 -07:00
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-08-17 14:05:06 -07:00
|
|
|
get starButton() {
|
|
|
|
delete this.starButton;
|
|
|
|
return this.starButton = document.getElementById("tool-star");
|
|
|
|
},
|
2009-05-28 22:58:30 -07:00
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
sizeControls: function(windowW, windowH) {
|
2009-10-15 09:54:36 -07:00
|
|
|
// tabs
|
|
|
|
document.getElementById("tabs").resize();
|
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
// awesomebar and related panels
|
|
|
|
let popup = document.getElementById("awesome-panels");
|
2009-05-28 22:58:30 -07:00
|
|
|
popup.top = this.toolbarH;
|
2009-09-01 20:35:08 -07:00
|
|
|
popup.height = windowH - this.toolbarH;
|
|
|
|
popup.width = windowW;
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2010-07-19 07:51:03 -07:00
|
|
|
// content navigator helper
|
|
|
|
let contentHelper = document.getElementById("content-navigator");
|
|
|
|
contentHelper.top = windowH - contentHelper.getBoundingClientRect().height;
|
2008-08-19 12:19:47 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
init: function() {
|
2008-07-03 23:39:25 -07:00
|
|
|
this._edit = document.getElementById("urlbar-edit");
|
2010-11-02 12:20:11 -07:00
|
|
|
this._title = document.getElementById("urlbar-title");
|
2008-07-03 23:39:25 -07:00
|
|
|
this._throbber = document.getElementById("urlbar-throbber");
|
|
|
|
this._favicon = document.getElementById("urlbar-favicon");
|
2008-05-02 13:15:45 -07:00
|
|
|
this._favicon.addEventListener("error", this, false);
|
|
|
|
|
2010-06-24 15:25:40 -07:00
|
|
|
this._edit.addEventListener("click", this, false);
|
|
|
|
this._edit.addEventListener("mousedown", this, false);
|
2009-07-14 07:16:23 -07:00
|
|
|
|
2010-09-09 10:45:40 -07:00
|
|
|
BadgeHandlers.register(this._edit.popup);
|
|
|
|
|
2010-10-14 10:19:04 -07:00
|
|
|
window.addEventListener("NavigationPanelShown", this, false);
|
|
|
|
window.addEventListener("NavigationPanelHidden", this, false);
|
2010-08-26 15:48:27 -07:00
|
|
|
|
2009-08-25 21:49:26 -07:00
|
|
|
let tabs = document.getElementById("tabs");
|
|
|
|
tabs.addEventListener("TabSelect", this, true);
|
|
|
|
tabs.addEventListener("TabOpen", this, true);
|
2010-11-04 10:14:11 -07:00
|
|
|
tabs.addEventListener("TabOpen", NewTabPopup, true);
|
2010-10-06 08:08:56 -07:00
|
|
|
window.addEventListener("PanFinished", this, true);
|
2009-07-14 07:16:23 -07:00
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
// listen content messages
|
|
|
|
messageManager.addMessageListener("DOMLinkAdded", this);
|
|
|
|
messageManager.addMessageListener("DOMTitleChanged", this);
|
|
|
|
messageManager.addMessageListener("DOMWillOpenModalDialog", this);
|
|
|
|
messageManager.addMessageListener("DOMWindowClose", this);
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2010-06-29 11:15:07 -07:00
|
|
|
messageManager.addMessageListener("Browser:OpenURI", this);
|
|
|
|
messageManager.addMessageListener("Browser:SaveAs:Return", this);
|
2010-06-09 19:12:05 -07:00
|
|
|
|
2009-08-14 10:30:50 -07:00
|
|
|
// listening mousedown for automatically dismiss some popups (e.g. larry)
|
|
|
|
window.addEventListener("mousedown", this, true);
|
2009-07-16 08:45:50 -07:00
|
|
|
|
2009-08-24 08:00:28 -07:00
|
|
|
// listening escape to dismiss dialog on VK_ESCAPE
|
|
|
|
window.addEventListener("keypress", this, true);
|
|
|
|
|
2010-04-27 13:33:59 -07:00
|
|
|
// listening AppCommand to handle special keys
|
|
|
|
window.addEventListener("AppCommand", this, true);
|
|
|
|
|
2010-10-12 11:30:19 -07:00
|
|
|
// We can delay some initialization until after startup. We wait until
|
|
|
|
// the first page is shown, then dispatch a UIReadyDelayed event.
|
2010-10-11 08:13:33 -07:00
|
|
|
messageManager.addMessageListener("pageshow", function() {
|
|
|
|
if (getBrowser().currentURI.spec == "about:blank")
|
|
|
|
return;
|
|
|
|
|
|
|
|
messageManager.removeMessageListener("pageshow", arguments.callee, true);
|
2010-06-21 13:16:37 -07:00
|
|
|
|
2010-10-12 11:30:19 -07:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("UIReadyDelayed", true, false);
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Delay the panel UI and Sync initialization.
|
|
|
|
window.addEventListener("UIReadyDelayed", function(aEvent) {
|
|
|
|
window.removeEventListener(aEvent.type, arguments.callee, false);
|
|
|
|
|
2009-12-17 14:35:48 -08:00
|
|
|
// We unhide the panelUI so the XBL and settings can initialize
|
|
|
|
Elements.panelUI.hidden = false;
|
2010-03-20 14:33:35 -07:00
|
|
|
|
|
|
|
// Init the views
|
2009-12-17 14:35:48 -08:00
|
|
|
ExtensionsView.init();
|
|
|
|
DownloadsView.init();
|
|
|
|
PreferencesView.init();
|
|
|
|
ConsoleView.init();
|
2010-10-16 06:25:15 -07:00
|
|
|
FullScreenVideo.init();
|
2010-06-29 08:09:04 -07:00
|
|
|
|
2010-08-04 16:19:16 -07:00
|
|
|
#ifdef MOZ_IPC
|
2010-07-30 12:48:52 -07:00
|
|
|
// Pre-start the content process
|
|
|
|
Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
|
|
|
|
.ensureContentProcess();
|
2010-08-04 16:19:16 -07:00
|
|
|
#endif
|
2010-07-30 12:48:52 -07:00
|
|
|
|
2010-08-24 01:49:32 -07:00
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
2010-06-29 08:09:04 -07:00
|
|
|
// Init the sync system
|
|
|
|
WeaveGlue.init();
|
2010-08-24 01:49:32 -07:00
|
|
|
#endif
|
2010-10-12 11:30:19 -07:00
|
|
|
}, false);
|
2010-06-21 13:36:56 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
FormHelperUI.init();
|
2010-07-19 07:51:03 -07:00
|
|
|
FindHelperUI.init();
|
2010-08-13 11:41:00 -07:00
|
|
|
PageActions.init();
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
uninit: function() {
|
2009-05-26 18:46:44 -07:00
|
|
|
ExtensionsView.uninit();
|
2009-10-14 12:04:33 -07:00
|
|
|
ConsoleView.uninit();
|
2010-08-27 13:30:45 -07:00
|
|
|
FormHelperUI.uninit();
|
2009-05-26 18:46:44 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
update: function(aState) {
|
2009-10-09 05:34:02 -07:00
|
|
|
let browser = Browser.selectedBrowser;
|
2009-09-08 11:14:59 -07:00
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
switch (aState) {
|
|
|
|
case TOOLBARSTATE_LOADED:
|
2010-08-26 15:48:27 -07:00
|
|
|
if (Elements.urlbarState.getAttribute("mode") != "edit")
|
2010-04-29 22:28:40 -07:00
|
|
|
this._updateToolbar();
|
2009-10-09 05:34:02 -07:00
|
|
|
|
|
|
|
this._updateIcon(browser.mIconURL);
|
2010-06-02 10:04:03 -07:00
|
|
|
this.unlockToolbar();
|
2008-11-21 21:12:25 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOOLBARSTATE_LOADING:
|
2010-08-26 15:48:27 -07:00
|
|
|
if (Elements.urlbarState.getAttribute("mode") != "edit")
|
2010-04-29 22:28:40 -07:00
|
|
|
this._updateToolbar();
|
2009-06-18 22:14:04 -07:00
|
|
|
|
2009-10-09 05:34:02 -07:00
|
|
|
browser.mIconURL = "";
|
|
|
|
this._updateIcon();
|
2010-06-02 10:04:03 -07:00
|
|
|
this.lockToolbar();
|
2008-11-21 21:12:25 -08:00
|
|
|
break;
|
2008-10-22 08:39:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
_updateIcon: function(aIconSrc) {
|
2009-10-09 05:34:02 -07:00
|
|
|
this._favicon.src = aIconSrc || "";
|
2009-01-08 22:51:13 -08:00
|
|
|
if (Browser.selectedTab.isLoading()) {
|
2008-11-21 21:12:25 -08:00
|
|
|
this._throbber.hidden = false;
|
2008-10-22 08:39:00 -07:00
|
|
|
this._throbber.setAttribute("loading", "true");
|
2008-11-21 21:12:25 -08:00
|
|
|
this._favicon.hidden = true;
|
2008-10-22 08:39:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2008-11-21 21:12:25 -08:00
|
|
|
this._favicon.hidden = false;
|
|
|
|
this._throbber.hidden = true;
|
2008-10-22 08:39:00 -07:00
|
|
|
this._throbber.removeAttribute("loading");
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
getDisplayURI: function(browser) {
|
2010-03-31 06:39:05 -07:00
|
|
|
let uri = browser.currentURI;
|
2008-09-27 07:07:04 -07:00
|
|
|
try {
|
2010-07-22 20:55:58 -07:00
|
|
|
uri = gURIFixup.createExposableURI(uri);
|
2008-09-27 07:07:04 -07:00
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
return uri.spec;
|
|
|
|
},
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
/* Set the location to the current content */
|
2010-07-18 22:27:52 -07:00
|
|
|
updateURI: function() {
|
2010-10-14 06:15:29 -07:00
|
|
|
let browser = Browser.selectedBrowser;
|
2008-09-06 21:06:04 -07:00
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
// FIXME: deckbrowser should not fire TabSelect on the initial tab (bug 454028)
|
2008-09-06 21:06:04 -07:00
|
|
|
if (!browser.currentURI)
|
|
|
|
return;
|
|
|
|
|
2009-06-24 15:43:26 -07:00
|
|
|
// Update the navigation buttons
|
|
|
|
this._updateButtons(browser);
|
2008-05-02 13:15:45 -07:00
|
|
|
|
|
|
|
// Check for a bookmarked page
|
2008-12-15 08:44:27 -08:00
|
|
|
this.updateStar();
|
2008-07-03 23:39:25 -07:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
let urlString = this.getDisplayURI(browser);
|
2010-04-08 22:08:53 -07:00
|
|
|
if (Util.isURLEmpty(urlString))
|
2008-07-03 23:39:25 -07:00
|
|
|
urlString = "";
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2010-11-02 12:20:11 -07:00
|
|
|
this._setURL(urlString);
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
goToURI: function(aURI) {
|
2009-09-13 21:49:09 -07:00
|
|
|
aURI = aURI || this._edit.value;
|
2008-05-02 13:15:45 -07:00
|
|
|
if (!aURI)
|
2009-09-13 21:49:09 -07:00
|
|
|
return;
|
|
|
|
|
2009-11-24 10:23:41 -08:00
|
|
|
// Make sure we're online before attempting to load
|
|
|
|
Util.forceOnline();
|
|
|
|
|
2009-10-28 20:55:47 -07:00
|
|
|
// Give the new page lots of room
|
|
|
|
Browser.hideSidebars();
|
2010-10-14 06:15:29 -07:00
|
|
|
this.closeAutoComplete();
|
2009-10-28 20:55:47 -07:00
|
|
|
|
2009-10-08 22:49:43 -07:00
|
|
|
this._edit.value = aURI;
|
2008-05-06 07:56:21 -07:00
|
|
|
|
2010-11-01 16:36:07 -07:00
|
|
|
let postData = {};
|
|
|
|
aURI = Browser.getShortcutOrURI(aURI, postData);
|
|
|
|
Browser.loadURI(aURI, { flags: Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP, postData: postData });
|
2010-07-23 06:02:44 -07:00
|
|
|
|
2010-07-22 20:55:58 -07:00
|
|
|
// Delay doing the fixup so the raw URI is passed to loadURIWithFlags
|
|
|
|
// and the proper third-party fixup can be done
|
|
|
|
let fixupFlags = Ci.nsIURIFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
|
|
|
|
let uri = gURIFixup.createFixupURI(aURI, fixupFlags);
|
2010-05-25 08:32:24 -07:00
|
|
|
gHistSvc.markPageAsTyped(uri);
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
showAutoComplete: function showAutoComplete() {
|
2009-09-18 21:17:52 -07:00
|
|
|
if (this.isAutoCompleteOpen())
|
|
|
|
return;
|
2009-12-03 06:04:57 -08:00
|
|
|
|
2010-11-04 11:42:07 -07:00
|
|
|
this.hidePanel();
|
2010-05-21 10:05:46 -07:00
|
|
|
this._hidePopup();
|
2010-08-24 01:42:28 -07:00
|
|
|
this.activePanel = AllPagesList;
|
2008-07-16 08:41:38 -07:00
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
closeAutoComplete: function closeAutoComplete() {
|
|
|
|
if (this.isAutoCompleteOpen())
|
|
|
|
this._edit.popup.closePopup();
|
2010-09-09 02:08:43 -07:00
|
|
|
|
|
|
|
this.activePanel = null;
|
2009-11-30 22:04:55 -08:00
|
|
|
},
|
2008-07-16 08:41:38 -07:00
|
|
|
|
2009-09-18 21:17:52 -07:00
|
|
|
isAutoCompleteOpen: function isAutoCompleteOpen() {
|
2010-10-10 14:23:28 -07:00
|
|
|
return this.activePanel == AllPagesList;
|
2009-09-18 21:17:52 -07:00
|
|
|
},
|
|
|
|
|
2010-08-26 16:09:56 -07:00
|
|
|
doOpenSearch: function doOpenSearch(aName) {
|
2010-08-25 08:44:18 -07:00
|
|
|
// save the current value of the urlbar
|
|
|
|
let searchValue = this._edit.value;
|
2009-10-28 20:55:47 -07:00
|
|
|
|
|
|
|
// Give the new page lots of room
|
|
|
|
Browser.hideSidebars();
|
2010-10-14 06:15:29 -07:00
|
|
|
this.closeAutoComplete();
|
2008-07-16 08:41:38 -07:00
|
|
|
|
2009-11-24 10:23:41 -08:00
|
|
|
// Make sure we're online before attempting to load
|
|
|
|
Util.forceOnline();
|
|
|
|
|
2010-08-26 16:09:56 -07:00
|
|
|
let engine = Services.search.getEngineByName(aName);
|
|
|
|
let submission = engine.getSubmission(searchValue, null);
|
2010-08-10 14:32:32 -07:00
|
|
|
Browser.loadURI(submission.uri.spec, { postData: submission.postData });
|
2008-07-16 08:41:38 -07:00
|
|
|
},
|
|
|
|
|
2010-09-30 14:28:07 -07:00
|
|
|
updateUIFocus: function _updateUIFocus() {
|
2010-09-30 14:14:47 -07:00
|
|
|
let state = (Elements.contentShowing.getAttribute("disabled") == "true") ? "Blur" : "Focus";
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("Browser:" + state, {});
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
updateStar: function() {
|
2009-01-08 22:51:13 -08:00
|
|
|
if (PlacesUtils.getMostRecentBookmarkForURI(Browser.selectedBrowser.currentURI) != -1)
|
2009-08-17 14:05:06 -07:00
|
|
|
this.starButton.setAttribute("starred", "true");
|
2008-12-15 08:44:27 -08:00
|
|
|
else
|
2009-08-17 14:05:06 -07:00
|
|
|
this.starButton.removeAttribute("starred");
|
2008-12-15 08:44:27 -08:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
newTab: function newTab(aURI, aOwner) {
|
2009-08-26 10:24:27 -07:00
|
|
|
aURI = aURI || "about:blank";
|
2010-06-15 14:56:13 -07:00
|
|
|
let tab = Browser.addTab(aURI, true, aOwner);
|
2009-08-26 10:24:27 -07:00
|
|
|
|
2009-09-22 15:05:20 -07:00
|
|
|
this.hidePanel();
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-09-18 21:17:52 -07:00
|
|
|
if (aURI == "about:blank") {
|
2009-11-30 22:04:55 -08:00
|
|
|
// Display awesomebar UI
|
2010-10-14 06:15:29 -07:00
|
|
|
this.showAutoComplete();
|
2009-09-18 21:17:52 -07:00
|
|
|
}
|
2009-10-28 20:55:47 -07:00
|
|
|
else {
|
|
|
|
// Give the new page lots of room
|
|
|
|
Browser.hideSidebars();
|
2010-10-14 06:15:29 -07:00
|
|
|
this.closeAutoComplete();
|
2009-10-28 20:55:47 -07:00
|
|
|
}
|
|
|
|
|
2009-08-25 20:45:11 -07:00
|
|
|
return tab;
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2010-07-16 08:48:53 -07:00
|
|
|
newOrSelectTab: function newOrSelectTab(aURI, aOwner) {
|
|
|
|
let tabs = Browser.tabs;
|
|
|
|
for (let i = 0; i < tabs.length; i++) {
|
|
|
|
if (tabs[i].browser.currentURI.spec == aURI) {
|
|
|
|
Browser.selectedTab = tabs[i];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.newTab(aURI, aOwner);
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
closeTab: function closeTab(aTab) {
|
2009-06-15 05:44:30 -07:00
|
|
|
// If no tab is passed in, assume the current tab
|
|
|
|
Browser.closeTab(aTab || Browser.selectedTab);
|
2008-09-28 23:43:33 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
selectTab: function selectTab(aTab) {
|
2010-09-09 03:16:43 -07:00
|
|
|
this.activePanel = null;
|
2009-01-08 22:51:13 -08:00
|
|
|
Browser.selectedTab = aTab;
|
2009-02-10 13:52:23 -08:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
undoCloseTab: function undoCloseTab(aIndex) {
|
|
|
|
let tab = null;
|
|
|
|
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
|
|
|
|
if (ss.getClosedTabCount(window) > (aIndex || 0)) {
|
|
|
|
tab = ss.undoCloseTab(window, aIndex || 0);
|
|
|
|
}
|
|
|
|
return tab;
|
|
|
|
},
|
|
|
|
|
2009-08-25 21:49:26 -07:00
|
|
|
isTabsVisible: function isTabsVisible() {
|
2009-08-28 12:08:39 -07:00
|
|
|
// The _1, _2 and _3 are to make the js2 emacs mode happy
|
|
|
|
let [leftvis,_1,_2,_3] = Browser.computeSidebarVisibility();
|
2009-08-25 21:49:26 -07:00
|
|
|
return (leftvis > 0.002);
|
|
|
|
},
|
|
|
|
|
2009-04-17 07:41:44 -07:00
|
|
|
showPanel: function showPanel(aPage) {
|
2010-09-29 12:54:50 -07:00
|
|
|
if (this.activePanel)
|
|
|
|
this.activePanel = null;
|
|
|
|
|
2009-12-17 14:35:48 -08:00
|
|
|
Elements.panelUI.left = 0;
|
|
|
|
Elements.panelUI.hidden = false;
|
2009-11-23 09:23:59 -08:00
|
|
|
Elements.contentShowing.setAttribute("disabled", "true");
|
|
|
|
|
2009-04-17 07:41:44 -07:00
|
|
|
if (aPage != undefined)
|
|
|
|
this.switchPane(aPage);
|
|
|
|
},
|
|
|
|
|
|
|
|
hidePanel: function hidePanel() {
|
2010-06-22 13:20:56 -07:00
|
|
|
if (!this.isPanelVisible())
|
|
|
|
return;
|
2009-12-17 14:35:48 -08:00
|
|
|
Elements.panelUI.hidden = true;
|
2009-11-23 09:23:59 -08:00
|
|
|
Elements.contentShowing.removeAttribute("disabled");
|
2010-06-14 06:14:16 -07:00
|
|
|
this.blurFocusedElement();
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
2009-12-17 14:35:48 -08:00
|
|
|
|
|
|
|
isPanelVisible: function isPanelVisible() {
|
|
|
|
return (!Elements.panelUI.hidden && Elements.panelUI.left == 0);
|
|
|
|
},
|
|
|
|
|
2010-06-14 06:14:16 -07:00
|
|
|
blurFocusedElement: function blurFocusedElement() {
|
|
|
|
let focusedElement = document.commandDispatcher.focusedElement;
|
|
|
|
if (focusedElement)
|
|
|
|
focusedElement.blur();
|
|
|
|
},
|
|
|
|
|
2009-09-23 09:09:44 -07:00
|
|
|
switchTask: function switchTask() {
|
|
|
|
try {
|
|
|
|
let phone = Cc["@mozilla.org/phone/support;1"].createInstance(Ci.nsIPhoneSupport);
|
|
|
|
phone.switchTask();
|
|
|
|
} catch(e) { }
|
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2010-08-17 09:38:45 -07:00
|
|
|
handleEscape: function (aEvent) {
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
|
2010-08-27 01:24:17 -07:00
|
|
|
// Check open popups
|
|
|
|
if (this._popup) {
|
|
|
|
this._hidePopup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check active panel
|
2010-09-07 10:53:10 -07:00
|
|
|
if (this.activePanel) {
|
|
|
|
this.activePanel = null;
|
2010-08-24 01:43:50 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-28 11:32:17 -07:00
|
|
|
// Check open dialogs
|
|
|
|
let dialog = this.activeDialog;
|
|
|
|
if (dialog) {
|
|
|
|
dialog.close();
|
|
|
|
return;
|
|
|
|
}
|
2010-07-28 17:41:42 -07:00
|
|
|
|
2010-04-28 11:32:17 -07:00
|
|
|
// Check open modal elements
|
|
|
|
let modalElementsLength = document.getElementsByClassName("modal-block").length;
|
2010-07-28 14:27:23 -07:00
|
|
|
if (modalElementsLength > 0)
|
2010-04-28 11:32:17 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Check open panel
|
|
|
|
if (this.isPanelVisible()) {
|
|
|
|
this.hidePanel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-28 16:19:00 -07:00
|
|
|
// Check content helper
|
|
|
|
let contentHelper = document.getElementById("content-navigator");
|
|
|
|
if (contentHelper.isActive) {
|
|
|
|
contentHelper.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-28 11:32:17 -07:00
|
|
|
// Only if there are no dialogs, popups, or panels open
|
2010-06-15 14:56:13 -07:00
|
|
|
let tab = Browser.selectedTab;
|
|
|
|
let browser = tab.browser;
|
|
|
|
|
2010-09-30 14:05:43 -07:00
|
|
|
if (browser.canGoBack) {
|
2010-06-15 14:56:13 -07:00
|
|
|
browser.goBack();
|
2010-09-30 14:05:43 -07:00
|
|
|
} else if (tab.owner) {
|
2010-06-15 14:56:13 -07:00
|
|
|
this.closeTab(tab);
|
2010-09-30 14:05:43 -07:00
|
|
|
}
|
2010-06-17 10:36:38 -07:00
|
|
|
#ifdef ANDROID
|
2010-09-30 14:05:43 -07:00
|
|
|
else {
|
2010-06-17 10:36:38 -07:00
|
|
|
window.QueryInterface(Ci.nsIDOMChromeWindow).minimize();
|
2010-09-30 14:05:43 -07:00
|
|
|
if (tab.closeOnExit)
|
|
|
|
this.closeTab(tab);
|
|
|
|
}
|
2010-06-17 10:36:38 -07:00
|
|
|
#endif
|
2010-04-28 11:32:17 -07:00
|
|
|
},
|
|
|
|
|
2010-06-09 19:12:05 -07:00
|
|
|
handleEvent: function handleEvent(aEvent) {
|
2008-05-02 13:15:45 -07:00
|
|
|
switch (aEvent.type) {
|
2008-07-03 23:39:25 -07:00
|
|
|
// Browser events
|
2008-08-19 23:09:22 -07:00
|
|
|
case "TabSelect":
|
|
|
|
this._tabSelect(aEvent);
|
|
|
|
break;
|
2009-08-25 21:49:26 -07:00
|
|
|
case "TabOpen":
|
2009-12-01 20:20:58 -08:00
|
|
|
{
|
2010-04-14 09:59:47 -07:00
|
|
|
// Workaround to hide the tabstrip if it is partially visible
|
|
|
|
// See bug 524469
|
2010-11-04 10:14:11 -07:00
|
|
|
let [tabsVisibility,,,] = Browser.computeSidebarVisibility();
|
2010-04-14 09:59:47 -07:00
|
|
|
if (tabsVisibility > 0.0 && tabsVisibility < 1.0)
|
|
|
|
Browser.hideSidebars();
|
2009-12-01 20:20:58 -08:00
|
|
|
|
2009-08-25 21:49:26 -07:00
|
|
|
break;
|
2009-12-01 20:20:58 -08:00
|
|
|
}
|
2010-10-06 08:08:56 -07:00
|
|
|
case "PanFinished":
|
|
|
|
let [tabsVisibility,,,] = Browser.computeSidebarVisibility();
|
|
|
|
if (tabsVisibility == 0.0)
|
|
|
|
document.getElementById("tabs").removeClosedTab();
|
|
|
|
break;
|
2010-04-06 16:42:36 -07:00
|
|
|
// Window events
|
2008-05-02 13:15:45 -07:00
|
|
|
case "keypress":
|
2010-04-28 11:32:17 -07:00
|
|
|
if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE)
|
2010-08-17 09:38:45 -07:00
|
|
|
this.handleEscape(aEvent);
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
2010-04-27 13:33:59 -07:00
|
|
|
case "AppCommand":
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
switch (aEvent.command) {
|
|
|
|
case "Menu":
|
|
|
|
this.doCommand("cmd_menu");
|
|
|
|
break;
|
|
|
|
case "Search":
|
2010-11-03 06:45:19 -07:00
|
|
|
if (!this.activePanel)
|
|
|
|
AllPagesList.doCommand();
|
|
|
|
else
|
|
|
|
this.doCommand("cmd_opensearch");
|
2010-04-27 13:33:59 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2010-04-06 16:42:36 -07:00
|
|
|
// URL textbox events
|
2010-05-24 09:11:23 -07:00
|
|
|
case "click":
|
2010-11-02 12:20:11 -07:00
|
|
|
if (this._edit.readOnly)
|
2010-10-10 14:23:28 -07:00
|
|
|
this._edit.readOnly = false;
|
2010-04-06 16:42:36 -07:00
|
|
|
break;
|
2009-07-21 17:05:01 -07:00
|
|
|
case "mousedown":
|
2009-12-04 12:03:56 -08:00
|
|
|
if (!this._isEventInsidePopup(aEvent))
|
|
|
|
this._hidePopup();
|
2009-08-14 10:30:50 -07:00
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
let selectAll = Services.prefs.getBoolPref("browser.urlbar.doubleClickSelectsAll");
|
2010-04-06 16:42:36 -07:00
|
|
|
if (aEvent.detail == 2 && aEvent.button == 0 && selectAll && aEvent.target == this._edit) {
|
2009-07-21 17:05:01 -07:00
|
|
|
this._edit.editor.selectAll();
|
|
|
|
aEvent.preventDefault();
|
|
|
|
}
|
|
|
|
break;
|
2008-07-03 23:39:25 -07:00
|
|
|
// Favicon events
|
2008-05-02 13:15:45 -07:00
|
|
|
case "error":
|
2009-10-09 05:34:02 -07:00
|
|
|
this._favicon.src = "";
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
2010-08-26 15:48:27 -07:00
|
|
|
// Awesome popup event
|
2010-10-14 10:19:04 -07:00
|
|
|
case "NavigationPanelShown":
|
2010-11-02 12:20:11 -07:00
|
|
|
this._edit.collapsed = false;
|
|
|
|
this._title.collapsed = true;
|
|
|
|
|
|
|
|
if (!this._edit.readOnly)
|
|
|
|
this._edit.focus();
|
2010-10-21 10:53:15 -07:00
|
|
|
|
|
|
|
// Disabled the search button if no search engines are available
|
|
|
|
let button = document.getElementById("urlbar-icons");
|
|
|
|
if (BrowserSearch.engines.length)
|
|
|
|
button.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
button.setAttribute("disabled", "true");
|
|
|
|
|
2010-08-26 15:48:27 -07:00
|
|
|
break;
|
2010-11-03 06:45:19 -07:00
|
|
|
case "NavigationPanelHidden": {
|
2010-11-02 12:20:11 -07:00
|
|
|
this._edit.collapsed = true;
|
|
|
|
this._title.collapsed = false;
|
|
|
|
|
2010-11-03 06:45:19 -07:00
|
|
|
let button = document.getElementById("urlbar-icons");
|
|
|
|
button.removeAttribute("open");
|
|
|
|
button.removeAttribute("disabled");
|
2010-08-26 15:48:27 -07:00
|
|
|
break;
|
2010-11-03 06:45:19 -07:00
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-06-09 19:12:05 -07:00
|
|
|
receiveMessage: function receiveMessage(aMessage) {
|
2010-06-08 08:22:20 -07:00
|
|
|
let browser = aMessage.target;
|
2010-06-21 13:16:37 -07:00
|
|
|
let json = aMessage.json;
|
2010-06-08 08:22:20 -07:00
|
|
|
switch (aMessage.name) {
|
|
|
|
case "DOMTitleChanged":
|
|
|
|
this._titleChanged(browser);
|
|
|
|
break;
|
|
|
|
case "DOMWillOpenModalDialog":
|
|
|
|
return this._domWillOpenModalDialog(browser);
|
|
|
|
break;
|
|
|
|
case "DOMWindowClose":
|
|
|
|
return this._domWindowClose(browser);
|
|
|
|
break;
|
|
|
|
case "DOMLinkAdded":
|
|
|
|
if (Browser.selectedBrowser == browser)
|
|
|
|
this._updateIcon(Browser.selectedBrowser.mIconURL);
|
|
|
|
break;
|
2010-06-09 19:12:05 -07:00
|
|
|
case "Browser:SaveAs:Return":
|
|
|
|
if (json.type != Ci.nsIPrintSettings.kOutputFormatPDF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
|
|
|
|
let db = dm.DBConnection;
|
|
|
|
let stmt = db.createStatement("UPDATE moz_downloads SET endTime = :endTime, state = :state WHERE id = :id");
|
|
|
|
stmt.params.endTime = Date.now() * 1000;
|
|
|
|
stmt.params.state = Ci.nsIDownloadManager.DOWNLOAD_FINISHED;
|
|
|
|
stmt.params.id = json.id;
|
|
|
|
stmt.execute();
|
|
|
|
stmt.finalize();
|
|
|
|
|
|
|
|
let download = dm.getDownload(json.id);
|
|
|
|
try {
|
|
|
|
DownloadsView.downloadCompleted(download);
|
|
|
|
let element = DownloadsView.getElementForDownload(json.id);
|
|
|
|
element.setAttribute("state", Ci.nsIDownloadManager.DOWNLOAD_FINISHED);
|
|
|
|
element.setAttribute("endTime", Date.now());
|
|
|
|
element.setAttribute("referrer", json.referrer);
|
|
|
|
DownloadsView._updateTime(element);
|
|
|
|
DownloadsView._updateStatus(element);
|
|
|
|
}
|
|
|
|
catch(e) {}
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.obs.notifyObservers(download, "dl-done", null);
|
2010-06-09 19:12:05 -07:00
|
|
|
break;
|
2010-06-21 13:16:37 -07:00
|
|
|
|
2010-06-29 11:15:07 -07:00
|
|
|
case "Browser:OpenURI":
|
2010-09-15 23:28:12 -07:00
|
|
|
Browser.addTab(json.uri, json.bringFront, Browser.selectedTab);
|
2010-09-22 16:27:11 -07:00
|
|
|
break;
|
2010-06-08 08:22:20 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
supportsCommand : function(cmd) {
|
|
|
|
var isSupported = false;
|
|
|
|
switch (cmd) {
|
|
|
|
case "cmd_back":
|
|
|
|
case "cmd_forward":
|
|
|
|
case "cmd_reload":
|
2010-02-16 15:38:37 -08:00
|
|
|
case "cmd_forceReload":
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_stop":
|
|
|
|
case "cmd_go":
|
2008-11-12 18:40:57 -08:00
|
|
|
case "cmd_openLocation":
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_star":
|
2010-08-26 16:09:56 -07:00
|
|
|
case "cmd_opensearch":
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_bookmarks":
|
2010-08-24 01:42:28 -07:00
|
|
|
case "cmd_history":
|
|
|
|
case "cmd_remoteTabs":
|
2009-03-19 16:20:32 -07:00
|
|
|
case "cmd_quit":
|
|
|
|
case "cmd_close":
|
2008-07-25 11:10:35 -07:00
|
|
|
case "cmd_menu":
|
|
|
|
case "cmd_newTab":
|
|
|
|
case "cmd_closeTab":
|
2010-07-18 22:27:52 -07:00
|
|
|
case "cmd_undoCloseTab":
|
2008-08-19 19:18:36 -07:00
|
|
|
case "cmd_actions":
|
2008-09-10 17:38:02 -07:00
|
|
|
case "cmd_panel":
|
2008-09-06 23:54:06 -07:00
|
|
|
case "cmd_sanitize":
|
2008-10-09 21:11:27 -07:00
|
|
|
case "cmd_zoomin":
|
|
|
|
case "cmd_zoomout":
|
2010-04-30 12:30:28 -07:00
|
|
|
case "cmd_volumeLeft":
|
|
|
|
case "cmd_volumeRight":
|
2010-04-12 07:58:38 -07:00
|
|
|
case "cmd_lockscreen":
|
2008-05-02 13:15:45 -07:00
|
|
|
isSupported = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
isSupported = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return isSupported;
|
|
|
|
},
|
|
|
|
|
|
|
|
isCommandEnabled : function(cmd) {
|
2010-09-23 02:00:00 -07:00
|
|
|
let elem = document.getElementById(cmd);
|
|
|
|
if (elem && (elem.getAttribute("disabled") == "true"))
|
|
|
|
return false;
|
2008-05-02 13:15:45 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
doCommand : function(cmd) {
|
2010-09-23 02:00:00 -07:00
|
|
|
if (!this.isCommandEnabled(cmd))
|
|
|
|
return;
|
2010-08-24 01:42:28 -07:00
|
|
|
let browser = getBrowser();
|
2008-05-02 13:15:45 -07:00
|
|
|
switch (cmd) {
|
|
|
|
case "cmd_back":
|
|
|
|
browser.goBack();
|
|
|
|
break;
|
|
|
|
case "cmd_forward":
|
|
|
|
browser.goForward();
|
|
|
|
break;
|
|
|
|
case "cmd_reload":
|
|
|
|
browser.reload();
|
|
|
|
break;
|
2010-02-16 15:38:37 -08:00
|
|
|
case "cmd_forceReload":
|
|
|
|
{
|
2010-04-30 13:53:25 -07:00
|
|
|
// Simulate a new page
|
2010-06-04 06:15:13 -07:00
|
|
|
browser.lastLocation = null;
|
2010-04-30 13:53:25 -07:00
|
|
|
|
2010-02-16 15:38:37 -08:00
|
|
|
const reloadFlags = Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY |
|
|
|
|
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
|
|
|
|
browser.reloadWithFlags(reloadFlags);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_stop":
|
|
|
|
browser.stop();
|
|
|
|
break;
|
|
|
|
case "cmd_go":
|
|
|
|
this.goToURI();
|
|
|
|
break;
|
2008-11-12 18:40:57 -08:00
|
|
|
case "cmd_openLocation":
|
2010-10-14 06:15:29 -07:00
|
|
|
this.showAutoComplete();
|
2008-11-12 18:40:57 -08:00
|
|
|
break;
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_star":
|
|
|
|
{
|
2010-08-24 01:33:43 -07:00
|
|
|
let bookmarkURI = browser.currentURI;
|
2009-08-17 14:05:06 -07:00
|
|
|
let autoClose = false;
|
|
|
|
|
2008-10-01 12:54:16 -07:00
|
|
|
if (PlacesUtils.getMostRecentBookmarkForURI(bookmarkURI) == -1) {
|
2010-08-24 01:43:50 -07:00
|
|
|
let bookmarkTitle = browser.contentTitle || bookmarkURI.spec;
|
|
|
|
let bookmarkService = PlacesUtils.bookmarks;
|
|
|
|
let bookmarkId = bookmarkService.insertBookmark(BookmarkList.panel.mobileRoot, bookmarkURI,
|
|
|
|
bookmarkService.DEFAULT_INDEX,
|
|
|
|
bookmarkTitle);
|
2009-07-05 09:22:09 -07:00
|
|
|
this.updateStar();
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2009-08-17 14:05:06 -07:00
|
|
|
// autoclose the bookmark popup
|
|
|
|
autoClose = true;
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
2009-08-17 14:05:06 -07:00
|
|
|
|
|
|
|
// Show/hide bookmark popup
|
|
|
|
BookmarkPopup.toggle(autoClose);
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
|
|
|
}
|
2010-08-26 16:09:56 -07:00
|
|
|
case "cmd_opensearch":
|
2010-10-19 17:51:12 -07:00
|
|
|
this.blurFocusedElement();
|
2010-10-19 15:54:45 -07:00
|
|
|
BrowserSearch.toggle();
|
2010-08-26 16:09:56 -07:00
|
|
|
break;
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_bookmarks":
|
2010-08-24 01:42:28 -07:00
|
|
|
this.activePanel = BookmarkList;
|
|
|
|
break;
|
|
|
|
case "cmd_history":
|
|
|
|
this.activePanel = HistoryList;
|
|
|
|
break;
|
|
|
|
case "cmd_remoteTabs":
|
|
|
|
this.activePanel = RemoteTabsList;
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
2009-03-19 16:20:32 -07:00
|
|
|
case "cmd_quit":
|
|
|
|
goQuitApplication();
|
|
|
|
break;
|
|
|
|
case "cmd_close":
|
2009-07-08 07:55:07 -07:00
|
|
|
this._closeOrQuit();
|
2009-03-19 16:20:32 -07:00
|
|
|
break;
|
2008-07-25 11:10:35 -07:00
|
|
|
case "cmd_menu":
|
2010-04-27 13:33:59 -07:00
|
|
|
getIdentityHandler().toggle();
|
2008-07-25 11:10:35 -07:00
|
|
|
break;
|
|
|
|
case "cmd_newTab":
|
|
|
|
this.newTab();
|
|
|
|
break;
|
|
|
|
case "cmd_closeTab":
|
2008-11-21 21:12:25 -08:00
|
|
|
this.closeTab();
|
2008-08-19 19:18:36 -07:00
|
|
|
break;
|
2010-07-18 22:27:52 -07:00
|
|
|
case "cmd_undoCloseTab":
|
|
|
|
this.undoCloseTab();
|
|
|
|
break;
|
2008-09-06 23:54:06 -07:00
|
|
|
case "cmd_sanitize":
|
2009-05-20 10:31:53 -07:00
|
|
|
{
|
|
|
|
// disable the button temporarily to indicate something happened
|
|
|
|
let button = document.getElementById("prefs-clear-data");
|
|
|
|
button.disabled = true;
|
|
|
|
setTimeout(function() { button.disabled = false; }, 5000);
|
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
Sanitizer.sanitize();
|
2008-08-19 19:18:36 -07:00
|
|
|
break;
|
2009-05-20 10:31:53 -07:00
|
|
|
}
|
2008-09-10 17:38:02 -07:00
|
|
|
case "cmd_panel":
|
|
|
|
{
|
2009-12-17 14:35:48 -08:00
|
|
|
if (BrowserUI.isPanelVisible())
|
2009-04-17 07:41:44 -07:00
|
|
|
this.hidePanel();
|
2009-12-17 14:35:48 -08:00
|
|
|
else
|
|
|
|
this.showPanel();
|
2008-09-10 12:30:52 -07:00
|
|
|
break;
|
2008-09-10 17:38:02 -07:00
|
|
|
}
|
2008-10-09 21:11:27 -07:00
|
|
|
case "cmd_zoomin":
|
2009-11-24 11:44:05 -08:00
|
|
|
Browser.zoom(-1);
|
2008-10-09 21:11:27 -07:00
|
|
|
break;
|
|
|
|
case "cmd_zoomout":
|
2009-11-24 11:44:05 -08:00
|
|
|
Browser.zoom(1);
|
2008-10-09 21:11:27 -07:00
|
|
|
break;
|
2010-04-30 12:30:28 -07:00
|
|
|
case "cmd_volumeLeft":
|
|
|
|
// Zoom in (portrait) or out (landscape)
|
|
|
|
Browser.zoom(Util.isPortrait() ? -1 : 1);
|
|
|
|
break;
|
|
|
|
case "cmd_volumeRight":
|
|
|
|
// Zoom out (portrait) or in (landscape)
|
|
|
|
Browser.zoom(Util.isPortrait() ? 1 : -1);
|
|
|
|
break;
|
2010-04-12 07:58:38 -07:00
|
|
|
case "cmd_lockscreen":
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
let locked = Services.prefs.getBoolPref("toolkit.screen.lock");
|
|
|
|
Services.prefs.setBoolPref("toolkit.screen.lock", !locked);
|
2010-05-06 12:16:58 -07:00
|
|
|
|
|
|
|
let strings = Elements.browserBundle;
|
|
|
|
let alerts = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
|
|
|
|
alerts.showAlertNotification(null, strings.getString("alertLockScreen"),
|
2010-05-10 20:42:44 -07:00
|
|
|
strings.getString("alertLockScreen." + (!locked ? "locked" : "unlocked")), false, "", null);
|
2010-04-12 07:58:38 -07:00
|
|
|
break;
|
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-21 13:16:37 -07:00
|
|
|
var TapHighlightHelper = {
|
|
|
|
get _overlay() {
|
|
|
|
delete this._overlay;
|
|
|
|
return this._overlay = document.getElementById("content-overlay");
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function show(aRects) {
|
2010-09-15 15:05:50 -07:00
|
|
|
let browser = getBrowser();
|
|
|
|
let scroll = browser.getPosition();
|
2010-08-31 12:25:47 -07:00
|
|
|
|
2010-09-16 10:27:27 -07:00
|
|
|
let canvasArea = aRects.reduce(function(a, b) {
|
2010-06-21 13:16:37 -07:00
|
|
|
return a.expandToContain(b);
|
2010-09-15 15:05:50 -07:00
|
|
|
}, new Rect(0, 0, 0, 0)).map(function(val) val * browser.scale)
|
|
|
|
.translate(-scroll.x, -scroll.y);
|
2010-06-21 13:16:37 -07:00
|
|
|
|
|
|
|
let overlay = this._overlay;
|
2010-10-06 12:58:05 -07:00
|
|
|
overlay.setAttribute("width", canvasArea.width);
|
|
|
|
overlay.setAttribute("height", canvasArea.height);
|
2010-06-21 13:16:37 -07:00
|
|
|
|
|
|
|
let ctx = overlay.getContext("2d");
|
|
|
|
ctx.save();
|
|
|
|
ctx.translate(-canvasArea.left, -canvasArea.top);
|
2010-09-15 15:05:50 -07:00
|
|
|
ctx.scale(browser.scale, browser.scale);
|
2010-06-21 13:16:37 -07:00
|
|
|
|
2010-10-06 12:58:05 -07:00
|
|
|
overlay.setAttribute("left", canvasArea.left);
|
|
|
|
overlay.setAttribute("top", canvasArea.top);
|
2010-06-21 13:16:37 -07:00
|
|
|
ctx.fillStyle = "rgba(0, 145, 255, .5)";
|
|
|
|
for (let i = aRects.length - 1; i >= 0; i--) {
|
|
|
|
let rect = aRects[i];
|
2010-09-15 15:05:50 -07:00
|
|
|
ctx.fillRect(rect.left - scroll.x / browser.scale, rect.top - scroll.y / browser.scale, rect.width, rect.height);
|
2010-06-21 13:16:37 -07:00
|
|
|
}
|
|
|
|
ctx.restore();
|
|
|
|
overlay.style.display = "block";
|
2010-09-17 11:48:20 -07:00
|
|
|
|
|
|
|
addEventListener("MozBeforePaint", this, false);
|
|
|
|
mozRequestAnimationFrame();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the highlight. aGuaranteeShowMsecs specifies how many milliseconds the
|
|
|
|
* highlight should be shown before it disappears.
|
|
|
|
*/
|
|
|
|
hide: function hide(aGuaranteeShowMsecs) {
|
|
|
|
if (this._overlay.style.display == "none")
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._guaranteeShow = Math.max(0, aGuaranteeShowMsecs);
|
|
|
|
if (this._guaranteeShow) {
|
|
|
|
// _shownAt is set once highlight has been painted
|
|
|
|
if (this._shownAt)
|
|
|
|
setTimeout(this._hide.bind(this),
|
|
|
|
Math.max(0, this._guaranteeShow - (mozAnimationStartTime - this._shownAt)));
|
|
|
|
} else {
|
|
|
|
this._hide();
|
|
|
|
}
|
2010-06-21 13:16:37 -07:00
|
|
|
},
|
|
|
|
|
2010-09-17 11:48:20 -07:00
|
|
|
/** Helper function that hides popup immediately. */
|
|
|
|
_hide: function _hide() {
|
|
|
|
this._shownAt = 0;
|
|
|
|
this._guaranteeShow = 0;
|
2010-06-21 13:16:37 -07:00
|
|
|
this._overlay.style.display = "none";
|
2010-09-17 11:48:20 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function handleEvent(ev) {
|
|
|
|
removeEventListener("MozBeforePaint", this, false);
|
|
|
|
this._shownAt = ev.timeStamp;
|
|
|
|
// hide has been called, so hide the tap highlight after it has
|
|
|
|
// been shown for a moment.
|
|
|
|
if (this._guaranteeShow)
|
|
|
|
this.hide(this._guaranteeShow);
|
2010-06-21 13:16:37 -07:00
|
|
|
}
|
2010-08-13 11:41:00 -07:00
|
|
|
};
|
2010-06-21 13:16:37 -07:00
|
|
|
|
2010-03-24 12:55:09 -07:00
|
|
|
var PageActions = {
|
2010-08-13 11:41:00 -07:00
|
|
|
init: function init() {
|
2010-09-30 13:57:33 -07:00
|
|
|
document.getElementById("pageactions-container").addEventListener("click", this, false);
|
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
this.register("pageaction-reset", this.updatePagePermissions, this);
|
|
|
|
this.register("pageaction-password", this.updateForgetPassword, this);
|
2010-09-14 13:46:49 -07:00
|
|
|
#ifdef NS_PRINTING
|
2010-08-13 11:41:00 -07:00
|
|
|
this.register("pageaction-saveas", this.updatePageSaveAs, this);
|
2010-09-14 13:46:49 -07:00
|
|
|
#endif
|
2010-08-23 17:27:40 -07:00
|
|
|
this.register("pageaction-share", this.updateShare, this);
|
2010-08-13 11:41:00 -07:00
|
|
|
this.register("pageaction-search", BrowserSearch.updatePageSearchEngines, BrowserSearch);
|
|
|
|
},
|
|
|
|
|
2010-09-30 13:57:33 -07:00
|
|
|
handleEvent: function handleEvent(aEvent) {
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "click":
|
|
|
|
getIdentityHandler().hide();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
/**
|
|
|
|
* @param aId id of a pageaction element
|
|
|
|
* @param aCallback function that takes an element and returns true if it should be visible
|
|
|
|
* @param aThisObj (optional) scope object for aCallback
|
|
|
|
*/
|
|
|
|
register: function register(aId, aCallback, aThisObj) {
|
|
|
|
this._handlers.push({id: aId, callback: aCallback, obj: aThisObj});
|
|
|
|
},
|
|
|
|
|
|
|
|
_handlers: [],
|
|
|
|
|
|
|
|
updateSiteMenu: function updateSiteMenu() {
|
|
|
|
this._handlers.forEach(function(action) {
|
|
|
|
let node = document.getElementById(action.id);
|
|
|
|
node.hidden = !action.callback.call(action.obj, node);
|
|
|
|
});
|
|
|
|
this._updateAttributes();
|
|
|
|
},
|
|
|
|
|
2010-03-24 12:55:09 -07:00
|
|
|
get _loginManager() {
|
|
|
|
delete this._loginManager;
|
|
|
|
return this._loginManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
|
|
|
},
|
|
|
|
|
|
|
|
// This is easy for an addon to add his own perm type here
|
|
|
|
_permissions: ["popup", "offline-app", "geo"],
|
|
|
|
|
|
|
|
_forEachPermissions: function _forEachPermissions(aHost, aCallback) {
|
2010-07-13 07:36:09 -07:00
|
|
|
let pm = Services.perms;
|
2010-03-24 12:55:09 -07:00
|
|
|
for (let i = 0; i < this._permissions.length; i++) {
|
|
|
|
let type = this._permissions[i];
|
|
|
|
if (!pm.testPermission(aHost, type))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
let perms = pm.enumerator;
|
|
|
|
while (perms.hasMoreElements()) {
|
|
|
|
let permission = perms.getNext().QueryInterface(Ci.nsIPermission);
|
|
|
|
if (permission.host == aHost.asciiHost && permission.type == type)
|
|
|
|
aCallback(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
updatePagePermissions: function updatePagePermissions(aNode) {
|
2010-03-24 12:55:09 -07:00
|
|
|
let host = Browser.selectedBrowser.currentURI;
|
|
|
|
let permissions = [];
|
|
|
|
|
|
|
|
this._forEachPermissions(host, function(aType) {
|
2010-08-13 11:41:00 -07:00
|
|
|
permissions.push("pageactions." + aType);
|
2010-03-24 12:55:09 -07:00
|
|
|
});
|
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
if (!this._loginManager.getLoginSavingEnabled(host.prePath)) {
|
2010-10-01 11:44:27 -07:00
|
|
|
// If rememberSignons is false, then getLoginSavingEnabled returns false
|
|
|
|
// for all pages, so we should just ignore it (Bug 601163).
|
|
|
|
if (Services.prefs.getBoolPref("signon.rememberSignons"))
|
|
|
|
permissions.push("pageactions.password");
|
2010-03-24 12:55:09 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
let descriptions = permissions.map(function(s) Elements.browserBundle.getString(s));
|
|
|
|
aNode.setAttribute("description", descriptions.join(", "));
|
2010-03-24 12:55:09 -07:00
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
return (permissions.length > 0);
|
|
|
|
},
|
2010-03-24 12:55:09 -07:00
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
updateForgetPassword: function updateForgetPassword(aNode) {
|
|
|
|
let host = Browser.selectedBrowser.currentURI;
|
2010-10-06 12:51:30 -07:00
|
|
|
let logins = this._loginManager.findLogins({}, host.prePath, "", "");
|
2010-04-06 08:10:18 -07:00
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
return logins.some(function(login) login.hostname == host.prePath);
|
|
|
|
},
|
|
|
|
|
2010-09-30 13:57:33 -07:00
|
|
|
forgetPassword: function forgetPassword(aEvent) {
|
2010-08-13 11:41:00 -07:00
|
|
|
let host = Browser.selectedBrowser.currentURI;
|
|
|
|
let lm = this._loginManager;
|
|
|
|
|
2010-10-06 12:51:30 -07:00
|
|
|
lm.findLogins({}, host.prePath, "", "").forEach(function(login) {
|
2010-08-13 11:41:00 -07:00
|
|
|
if (login.hostname == host.prePath)
|
2010-08-16 21:20:44 -07:00
|
|
|
lm.removeLogin(login);
|
2010-08-13 11:41:00 -07:00
|
|
|
});
|
2010-09-30 13:57:33 -07:00
|
|
|
|
|
|
|
this.hideItem(aEvent.target);
|
|
|
|
aEvent.stopPropagation(); // Don't hide the site menu.
|
2010-03-24 12:55:09 -07:00
|
|
|
},
|
|
|
|
|
2010-09-30 13:57:33 -07:00
|
|
|
clearPagePermissions: function clearPagePermissions(aEvent) {
|
2010-07-13 07:36:09 -07:00
|
|
|
let pm = Services.perms;
|
2010-03-24 12:55:09 -07:00
|
|
|
let host = Browser.selectedBrowser.currentURI;
|
|
|
|
this._forEachPermissions(host, function(aType) {
|
|
|
|
pm.remove(host.asciiHost, aType);
|
|
|
|
});
|
|
|
|
|
|
|
|
let lm = this._loginManager;
|
|
|
|
if (!lm.getLoginSavingEnabled(host.prePath))
|
|
|
|
lm.setLoginSavingEnabled(host.prePath, true);
|
2010-09-30 13:57:33 -07:00
|
|
|
|
|
|
|
this.hideItem(aEvent.target);
|
|
|
|
aEvent.stopPropagation(); // Don't hide the site menu.
|
2010-03-24 12:55:09 -07:00
|
|
|
},
|
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
savePageAsPDF: function saveAsPDF() {
|
2010-06-09 19:12:05 -07:00
|
|
|
let browser = Browser.selectedBrowser;
|
2010-06-22 06:15:15 -07:00
|
|
|
let fileName = getDefaultFileName(browser.contentTitle, browser.documentURI, null, null);
|
2010-09-13 14:56:17 -07:00
|
|
|
fileName = fileName.trim() + ".pdf";
|
2010-05-06 20:10:56 -07:00
|
|
|
#ifdef MOZ_PLATFORM_MAEMO
|
2010-06-22 13:20:56 -07:00
|
|
|
fileName = fileName.replace(/[\*\:\?]+/g, " ");
|
2010-05-06 20:10:56 -07:00
|
|
|
#endif
|
2010-03-26 12:06:58 -07:00
|
|
|
|
2010-05-10 20:39:10 -07:00
|
|
|
let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
|
2010-09-13 14:56:17 -07:00
|
|
|
let downloadsDir = dm.defaultDownloadsDirectory;
|
|
|
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
let file = downloadsDir.clone();
|
|
|
|
file.append(fileName);
|
|
|
|
#else
|
|
|
|
let strings = Elements.browserBundle;
|
|
|
|
let picker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
|
|
|
|
picker.init(window, strings.getString("pageactions.saveas.pdf"), Ci.nsIFilePicker.modeSave);
|
|
|
|
picker.appendFilter("PDF", "*.pdf");
|
|
|
|
picker.defaultExtension = "pdf";
|
|
|
|
|
|
|
|
picker.defaultString = fileName;
|
|
|
|
|
|
|
|
picker.displayDirectory = downloadsDir;
|
2010-03-26 12:06:58 -07:00
|
|
|
let rv = picker.show();
|
|
|
|
if (rv == Ci.nsIFilePicker.returnCancel)
|
|
|
|
return;
|
|
|
|
|
2010-09-13 14:56:17 -07:00
|
|
|
let file = picker.file;
|
|
|
|
#endif
|
|
|
|
|
2010-04-26 13:55:04 -07:00
|
|
|
// We must manually add this to the download system
|
|
|
|
let db = dm.DBConnection;
|
|
|
|
|
|
|
|
let stmt = db.createStatement(
|
|
|
|
"INSERT INTO moz_downloads (name, source, target, startTime, endTime, state, referrer) " +
|
|
|
|
"VALUES (:name, :source, :target, :startTime, :endTime, :state, :referrer)"
|
|
|
|
);
|
|
|
|
|
2010-09-13 14:56:17 -07:00
|
|
|
let current = browser.currentURI.spec;
|
|
|
|
stmt.params.name = file.leafName;
|
2010-04-26 13:55:04 -07:00
|
|
|
stmt.params.source = current;
|
2010-09-13 14:56:17 -07:00
|
|
|
stmt.params.target = Services.io.newFileURI(file).spec;
|
2010-04-26 13:55:04 -07:00
|
|
|
stmt.params.startTime = Date.now() * 1000;
|
|
|
|
stmt.params.endTime = Date.now() * 1000;
|
|
|
|
stmt.params.state = Ci.nsIDownloadManager.DOWNLOAD_NOTSTARTED;
|
|
|
|
stmt.params.referrer = current;
|
|
|
|
stmt.execute();
|
|
|
|
stmt.finalize();
|
|
|
|
|
2010-06-09 19:12:05 -07:00
|
|
|
let newItemId = db.lastInsertRowID;
|
|
|
|
let download = dm.getDownload(newItemId);
|
2010-04-26 13:55:04 -07:00
|
|
|
try {
|
|
|
|
DownloadsView.downloadStarted(download);
|
|
|
|
}
|
|
|
|
catch(e) {}
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.obs.notifyObservers(download, "dl-start", null);
|
2010-04-26 13:55:04 -07:00
|
|
|
|
2010-06-09 19:12:05 -07:00
|
|
|
let data = {
|
|
|
|
type: Ci.nsIPrintSettings.kOutputFormatPDF,
|
|
|
|
id: newItemId,
|
|
|
|
referrer: current,
|
2010-09-13 14:56:17 -07:00
|
|
|
filePath: file.path
|
2010-06-09 19:12:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("Browser:SaveAs", data);
|
2010-03-26 12:06:58 -07:00
|
|
|
},
|
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
updatePageSaveAs: function updatePageSaveAs(aNode) {
|
2010-06-25 08:28:42 -07:00
|
|
|
// Check for local XUL content
|
2010-09-29 11:48:19 -07:00
|
|
|
let contentWindow = Browser.selectedBrowser.contentWindow;
|
|
|
|
return !(contentWindow && contentWindow.document instanceof XULDocument);
|
2010-07-29 21:51:31 -07:00
|
|
|
},
|
|
|
|
|
2010-08-23 17:27:40 -07:00
|
|
|
updateShare: function updateShare(aNode) {
|
|
|
|
return Util.isShareableScheme(Browser.selectedBrowser.currentURI.scheme);
|
|
|
|
},
|
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
hideItem: function hideItem(aNode) {
|
|
|
|
aNode.hidden = true;
|
|
|
|
this._updateAttributes();
|
2010-03-24 12:55:09 -07:00
|
|
|
},
|
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
_updateAttributes: function _updateAttributes() {
|
2010-03-24 12:55:09 -07:00
|
|
|
let container = document.getElementById("pageactions-container");
|
2010-08-13 11:41:00 -07:00
|
|
|
let visibleNodes = container.querySelectorAll("pageaction:not([hidden=true])");
|
2010-08-17 10:02:30 -07:00
|
|
|
let visibleCount = visibleNodes.length;
|
2010-08-13 11:41:00 -07:00
|
|
|
|
2010-10-16 21:30:00 -07:00
|
|
|
for (let i = 0; i < visibleCount; i++)
|
|
|
|
visibleNodes[i].classList.remove("odd-last-child");
|
2010-08-17 10:02:30 -07:00
|
|
|
|
2010-10-16 21:30:00 -07:00
|
|
|
if (visibleCount % 2)
|
|
|
|
visibleNodes[visibleCount - 1].classList.add("odd-last-child");
|
2010-03-24 12:55:09 -07:00
|
|
|
}
|
2010-08-13 11:41:00 -07:00
|
|
|
};
|
2010-03-24 12:55:09 -07:00
|
|
|
|
2009-08-25 21:49:26 -07:00
|
|
|
var NewTabPopup = {
|
|
|
|
_timeout: 0,
|
|
|
|
_tabs: [],
|
|
|
|
|
|
|
|
get box() {
|
|
|
|
delete this.box;
|
2010-09-02 18:27:20 -07:00
|
|
|
let box = document.getElementById("newtab-popup");
|
|
|
|
|
|
|
|
// Move the popup on the other side if we are in RTL
|
|
|
|
let [leftSidebar, rightSidebar] = [Elements.tabs.getBoundingClientRect(), Elements.controls.getBoundingClientRect()];
|
|
|
|
if (leftSidebar.left > rightSidebar.left) {
|
|
|
|
let margin = box.getAttribute("left");
|
|
|
|
box.removeAttribute("left");
|
|
|
|
box.setAttribute("right", margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.box = box;
|
2009-08-25 21:49:26 -07:00
|
|
|
},
|
|
|
|
|
2010-11-04 10:14:11 -07:00
|
|
|
_updateLabel: function nt_updateLabel() {
|
2009-11-19 13:40:13 -08:00
|
|
|
let newtabStrings = Elements.browserBundle.getString("newtabpopup.opened");
|
2009-08-25 21:49:26 -07:00
|
|
|
let label = PluralForm.get(this._tabs.length, newtabStrings).replace("#1", this._tabs.length);
|
|
|
|
|
|
|
|
this.box.firstChild.setAttribute("value", label);
|
|
|
|
},
|
|
|
|
|
2010-11-04 10:14:11 -07:00
|
|
|
hide: function nt_hide() {
|
2009-08-25 21:49:26 -07:00
|
|
|
if (this._timeout) {
|
|
|
|
clearTimeout(this._timeout);
|
|
|
|
this._timeout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._tabs = [];
|
|
|
|
this.box.hidden = true;
|
2010-11-01 08:42:13 -07:00
|
|
|
BrowserUI.popPopup(this);
|
2009-08-25 21:49:26 -07:00
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2010-11-04 10:14:11 -07:00
|
|
|
show: function nt_show(aTab) {
|
2009-12-01 20:20:58 -08:00
|
|
|
BrowserUI.pushPopup(this, this.box);
|
|
|
|
|
2009-08-25 21:49:26 -07:00
|
|
|
this._tabs.push(aTab);
|
|
|
|
this._updateLabel();
|
|
|
|
|
|
|
|
this.box.top = aTab.getBoundingClientRect().top + (aTab.getBoundingClientRect().height / 3);
|
|
|
|
this.box.hidden = false;
|
|
|
|
|
|
|
|
if (this._timeout)
|
|
|
|
clearTimeout(this._timeout);
|
|
|
|
|
|
|
|
this._timeout = setTimeout(function(self) {
|
|
|
|
self.hide();
|
|
|
|
}, 2000, this);
|
|
|
|
},
|
|
|
|
|
2010-11-04 10:14:11 -07:00
|
|
|
selectTab: function nt_selectTab() {
|
2009-08-25 21:49:26 -07:00
|
|
|
BrowserUI.selectTab(this._tabs.pop());
|
|
|
|
this.hide();
|
2010-11-04 10:14:11 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function nt_handleEvent(aEvent) {
|
|
|
|
let [tabsVisibility,,,] = Browser.computeSidebarVisibility();
|
|
|
|
if (tabsVisibility != 1.0 && aEvent.detail)
|
|
|
|
this.show(aEvent.originalTarget);
|
2009-08-25 21:49:26 -07:00
|
|
|
}
|
2010-08-13 11:41:00 -07:00
|
|
|
};
|
2009-08-25 21:49:26 -07:00
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
var AwesomePanel = function(aElementId, aCommandId) {
|
|
|
|
let command = document.getElementById(aCommandId);
|
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
this.panel = document.getElementById(aElementId),
|
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
this.open = function aw_open() {
|
|
|
|
command.setAttribute("checked", "true");
|
2010-08-24 01:43:50 -07:00
|
|
|
this.panel.hidden = false;
|
2010-08-24 01:42:28 -07:00
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
if (this.panel.hasAttribute("onshow")) {
|
|
|
|
let func = new Function("panel", this.panel.getAttribute("onshow"));
|
|
|
|
func.call(this.panel);
|
2010-08-24 01:42:28 -07:00
|
|
|
}
|
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
if (this.panel.open)
|
|
|
|
this.panel.open();
|
2010-08-24 01:42:28 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
this.close = function aw_close() {
|
2010-08-24 01:43:50 -07:00
|
|
|
if (this.panel.hasAttribute("onhide")) {
|
|
|
|
let func = new Function("panel", this.panel.getAttribute("onhide"));
|
|
|
|
func.call(this.panel);
|
2010-08-24 01:42:28 -07:00
|
|
|
}
|
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
if (this.panel.close)
|
|
|
|
this.panel.close();
|
2010-08-24 01:42:28 -07:00
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
this.panel.hidden = true;
|
2010-08-24 01:42:28 -07:00
|
|
|
command.removeAttribute("checked", "true");
|
2010-10-14 06:15:29 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
this.doCommand = function aw_doCommand() {
|
|
|
|
BrowserUI.doCommand(aCommandId);
|
2010-08-24 01:42:28 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
this.openLink = function aw_openLink(aEvent) {
|
|
|
|
let item = aEvent.originalTarget;
|
|
|
|
let uri = item.getAttribute("url") || item.getAttribute("uri");
|
2010-10-10 14:23:28 -07:00
|
|
|
if (uri != "")
|
2010-08-24 01:42:28 -07:00
|
|
|
BrowserUI.goToURI(uri);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-08-17 14:05:06 -07:00
|
|
|
var BookmarkPopup = {
|
|
|
|
get box() {
|
2010-09-02 18:27:20 -07:00
|
|
|
delete this.box;
|
|
|
|
this.box = document.getElementById("bookmark-popup");
|
|
|
|
|
|
|
|
let [tabsSidebar, controlsSidebar] = [Elements.tabs.getBoundingClientRect(), Elements.controls.getBoundingClientRect()];
|
2010-10-16 21:30:00 -07:00
|
|
|
this.box.setAttribute(tabsSidebar.left < controlsSidebar.left ? "right" : "left", controlsSidebar.width - this.box.offset);
|
|
|
|
this.box.top = BrowserUI.starButton.getBoundingClientRect().top - this.box.offset;
|
2010-09-02 18:27:20 -07:00
|
|
|
|
2010-08-24 01:33:43 -07:00
|
|
|
// Hide the popup if there is any new page loading
|
2010-09-02 18:27:20 -07:00
|
|
|
let self = this;
|
2010-08-24 01:33:43 -07:00
|
|
|
messageManager.addMessageListener("pagehide", function(aMessage) {
|
|
|
|
self.hide();
|
|
|
|
});
|
|
|
|
|
2010-09-02 18:27:20 -07:00
|
|
|
return this.box;
|
2009-08-17 14:05:06 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_bookmarkPopupTimeout: -1,
|
|
|
|
|
2009-12-01 09:27:17 -08:00
|
|
|
hide : function hide() {
|
2009-08-17 14:05:06 -07:00
|
|
|
if (this._bookmarkPopupTimeout != -1) {
|
|
|
|
clearTimeout(this._bookmarkPopupTimeout);
|
|
|
|
this._bookmarkPopupTimeout = -1;
|
|
|
|
}
|
|
|
|
this.box.hidden = true;
|
2010-11-01 08:42:13 -07:00
|
|
|
BrowserUI.popPopup(this);
|
2009-08-17 14:05:06 -07:00
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-12-01 09:27:17 -08:00
|
|
|
show : function show(aAutoClose) {
|
2009-08-17 14:05:06 -07:00
|
|
|
this.box.hidden = false;
|
2010-10-16 21:30:00 -07:00
|
|
|
this.box.anchorTo(BrowserUI.starButton);
|
2009-08-17 14:05:06 -07:00
|
|
|
|
|
|
|
if (aAutoClose) {
|
|
|
|
this._bookmarkPopupTimeout = setTimeout(function (self) {
|
|
|
|
self._bookmarkPopupTimeout = -1;
|
|
|
|
self.hide();
|
|
|
|
}, 2000, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// include starButton here, so that click-to-dismiss works as expected
|
|
|
|
BrowserUI.pushPopup(this, [this.box, BrowserUI.starButton]);
|
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-12-01 09:27:17 -08:00
|
|
|
toggle : function toggle(aAutoClose) {
|
2009-08-17 14:05:06 -07:00
|
|
|
if (this.box.hidden)
|
|
|
|
this.show(aAutoClose);
|
|
|
|
else
|
|
|
|
this.hide();
|
|
|
|
}
|
2010-08-13 11:41:00 -07:00
|
|
|
};
|
2009-08-17 14:05:06 -07:00
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
var BookmarkHelper = {
|
2009-02-24 22:20:45 -08:00
|
|
|
_panel: null,
|
|
|
|
_editor: null,
|
|
|
|
|
2009-07-08 07:55:07 -07:00
|
|
|
edit: function BH_edit(aURI) {
|
2009-08-17 14:05:06 -07:00
|
|
|
if (!aURI)
|
|
|
|
aURI = getBrowser().currentURI;
|
|
|
|
|
2009-02-24 22:20:45 -08:00
|
|
|
let itemId = PlacesUtils.getMostRecentBookmarkForURI(aURI);
|
|
|
|
if (itemId == -1)
|
|
|
|
return;
|
|
|
|
|
2009-04-08 22:40:05 -07:00
|
|
|
let title = PlacesUtils.bookmarks.getItemTitle(itemId);
|
2009-04-21 13:55:05 -07:00
|
|
|
let tags = PlacesUtils.tagging.getTagsForURI(aURI, {});
|
|
|
|
|
2009-11-23 08:44:34 -08:00
|
|
|
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
this._editor = document.createElementNS(XULNS, "placeitem");
|
2009-04-21 13:55:05 -07:00
|
|
|
this._editor.setAttribute("id", "bookmark-item");
|
|
|
|
this._editor.setAttribute("flex", "1");
|
|
|
|
this._editor.setAttribute("type", "bookmark");
|
|
|
|
this._editor.setAttribute("ui", "manage");
|
|
|
|
this._editor.setAttribute("title", title);
|
|
|
|
this._editor.setAttribute("uri", aURI.spec);
|
2009-11-23 08:44:34 -08:00
|
|
|
this._editor.setAttribute("itemid", itemId);
|
2009-07-07 06:45:01 -07:00
|
|
|
this._editor.setAttribute("tags", tags.join(", "));
|
2009-10-28 23:12:10 -07:00
|
|
|
this._editor.setAttribute("onclose", "BookmarkHelper.hide()");
|
2009-04-21 13:55:05 -07:00
|
|
|
document.getElementById("bookmark-form").appendChild(this._editor);
|
2009-04-08 22:40:05 -07:00
|
|
|
|
2009-05-06 22:51:47 -07:00
|
|
|
let toolbar = document.getElementById("toolbar-main");
|
|
|
|
let top = toolbar.top + toolbar.boxObject.height;
|
|
|
|
|
2009-02-24 22:20:45 -08:00
|
|
|
this._panel = document.getElementById("bookmark-container");
|
2009-05-06 22:51:47 -07:00
|
|
|
this._panel.top = (top < 0 ? 0 : top);
|
2009-04-21 13:55:05 -07:00
|
|
|
this._panel.hidden = false;
|
2009-10-28 23:12:10 -07:00
|
|
|
BrowserUI.pushPopup(this, this._panel);
|
2009-02-24 22:20:45 -08:00
|
|
|
|
2009-04-21 13:55:05 -07:00
|
|
|
let self = this;
|
2010-10-14 10:26:58 -07:00
|
|
|
BrowserUI.lockToolbar();
|
2009-12-04 12:03:56 -08:00
|
|
|
Browser.forceChromeReflow();
|
|
|
|
self._editor.startEditing();
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2009-10-25 21:21:49 -07:00
|
|
|
save: function BH_save() {
|
|
|
|
this._editor.stopEditing(true);
|
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-10-28 23:12:10 -07:00
|
|
|
hide: function BH_hide() {
|
2010-10-14 10:26:58 -07:00
|
|
|
BrowserUI.unlockToolbar();
|
2008-12-15 08:44:27 -08:00
|
|
|
BrowserUI.updateStar();
|
2009-02-24 22:20:45 -08:00
|
|
|
|
2009-07-08 07:55:07 -07:00
|
|
|
// Note: the _editor will have already saved the data, if needed, by the time
|
|
|
|
// this method is called, since this method is called via the "close" event.
|
2009-04-21 13:55:05 -07:00
|
|
|
this._editor.parentNode.removeChild(this._editor);
|
2009-07-08 07:55:07 -07:00
|
|
|
this._editor = null;
|
|
|
|
|
|
|
|
this._panel.hidden = true;
|
2010-11-01 08:42:13 -07:00
|
|
|
BrowserUI.popPopup(this);
|
2008-07-14 14:11:15 -07:00
|
|
|
},
|
2009-02-24 22:20:45 -08:00
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
removeBookmarksForURI: function BH_removeBookmarksForURI(aURI) {
|
|
|
|
//XXX blargle xpconnect! might not matter, but a method on
|
|
|
|
// nsINavBookmarksService that takes an array of items to
|
|
|
|
// delete would be faster. better yet, a method that takes a URI!
|
|
|
|
let itemIds = PlacesUtils.getBookmarksForURI(aURI);
|
|
|
|
itemIds.forEach(PlacesUtils.bookmarks.removeItem);
|
2009-02-24 22:20:45 -08:00
|
|
|
|
|
|
|
BrowserUI.updateStar();
|
|
|
|
}
|
|
|
|
};
|
2009-06-24 09:42:53 -07:00
|
|
|
|
2010-07-19 07:51:03 -07:00
|
|
|
var FindHelperUI = {
|
|
|
|
type: "find",
|
|
|
|
commands: {
|
|
|
|
next: "cmd_findNext",
|
|
|
|
previous: "cmd_findPrevious",
|
|
|
|
close: "cmd_findClose"
|
|
|
|
},
|
|
|
|
|
2010-10-18 15:20:04 -07:00
|
|
|
_status: null,
|
|
|
|
|
|
|
|
get status() {
|
|
|
|
return this._status;
|
|
|
|
},
|
|
|
|
|
|
|
|
set status(val) {
|
|
|
|
if (val != this._status) {
|
|
|
|
this._status = val;
|
|
|
|
this._textbox.setAttribute("status", val);
|
|
|
|
this.updateCommands(this._textbox.value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-19 07:51:03 -07:00
|
|
|
init: function findHelperInit() {
|
|
|
|
this._textbox = document.getElementById("find-helper-textbox");
|
|
|
|
this._container = document.getElementById("content-navigator");
|
|
|
|
|
2010-07-21 02:34:19 -07:00
|
|
|
this._cmdPrevious = document.getElementById(this.commands.previous);
|
|
|
|
this._cmdNext = document.getElementById(this.commands.next);
|
|
|
|
|
2010-07-19 07:51:03 -07:00
|
|
|
// Listen for form assistant messages from content
|
|
|
|
messageManager.addMessageListener("FindAssist:Show", this);
|
2010-07-21 16:35:47 -07:00
|
|
|
messageManager.addMessageListener("FindAssist:Hide", this);
|
2010-07-19 07:51:03 -07:00
|
|
|
|
|
|
|
// Listen for events where form assistant should be closed
|
|
|
|
document.getElementById("tabs").addEventListener("TabSelect", this, true);
|
2010-09-29 10:43:00 -07:00
|
|
|
Elements.browsers.addEventListener("URLChanged", this, true);
|
2010-07-19 07:51:03 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function findHelperReceiveMessage(aMessage) {
|
|
|
|
let json = aMessage.json;
|
|
|
|
switch(aMessage.name) {
|
|
|
|
case "FindAssist:Show":
|
2010-10-18 15:20:04 -07:00
|
|
|
this.status = json.result;
|
2010-07-19 07:51:03 -07:00
|
|
|
if (json.rect)
|
|
|
|
this._zoom(Rect.fromRect(json.rect));
|
|
|
|
break;
|
2010-07-21 16:35:47 -07:00
|
|
|
|
|
|
|
case "FindAssist:Hide":
|
|
|
|
if (this._container.getAttribute("type") == this.type)
|
|
|
|
this.hide();
|
|
|
|
break;
|
2010-07-19 07:51:03 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function findHelperHandleEvent(aEvent) {
|
|
|
|
if (aEvent.type == "TabSelect" || aEvent.type == "URLChanged")
|
|
|
|
this.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function findHelperShow() {
|
|
|
|
this._container.show(this);
|
2010-07-21 02:34:19 -07:00
|
|
|
this.search("");
|
2010-07-19 07:51:03 -07:00
|
|
|
this._textbox.focus();
|
2010-10-25 07:35:13 -07:00
|
|
|
|
|
|
|
// Prevent the view to scroll automatically while searching
|
|
|
|
Browser.selectedBrowser.scrollSync = false;
|
2010-07-19 07:51:03 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function findHelperHide() {
|
|
|
|
this._textbox.value = "";
|
2010-11-04 03:46:46 -07:00
|
|
|
this.status = null;
|
2010-09-30 14:14:47 -07:00
|
|
|
this._textbox.blur();
|
2010-07-19 07:51:03 -07:00
|
|
|
this._container.hide(this);
|
2010-10-25 07:35:13 -07:00
|
|
|
Browser.selectedBrowser.scrollSync = true;
|
2010-07-19 07:51:03 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
goToPrevious: function findHelperGoToPrevious() {
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FindAssist:Previous", { });
|
|
|
|
},
|
|
|
|
|
|
|
|
goToNext: function findHelperGoToNext() {
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FindAssist:Next", { });
|
|
|
|
},
|
|
|
|
|
|
|
|
search: function findHelperSearch(aValue) {
|
2010-11-04 03:46:46 -07:00
|
|
|
// Don't bother searching if the value is empty
|
|
|
|
if (aValue == "") {
|
|
|
|
this.status = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-21 02:34:19 -07:00
|
|
|
this.updateCommands(aValue);
|
2010-07-19 07:51:03 -07:00
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FindAssist:Find", { searchString: aValue });
|
|
|
|
},
|
|
|
|
|
2010-07-21 02:34:19 -07:00
|
|
|
updateCommands: function findHelperUpdateCommands(aValue) {
|
2010-10-18 15:20:04 -07:00
|
|
|
let disabled = (this._status == Ci.nsITypeAheadFind.FIND_NOTFOUND) || (aValue == "");
|
|
|
|
this._cmdPrevious.setAttribute("disabled", disabled);
|
|
|
|
this._cmdNext.setAttribute("disabled", disabled);
|
2010-07-21 02:34:19 -07:00
|
|
|
},
|
|
|
|
|
2010-07-19 07:51:03 -07:00
|
|
|
_zoom: function _findHelperZoom(aElementRect) {
|
|
|
|
// Zoom to a specified Rect
|
2010-09-02 14:42:44 -07:00
|
|
|
if (aElementRect && Browser.selectedTab.allowZoom && Services.prefs.getBoolPref("findhelper.autozoom")) {
|
2010-08-02 13:54:52 -07:00
|
|
|
let zoomLevel = Browser._getZoomLevelForRect(aElementRect);
|
2010-07-19 07:51:03 -07:00
|
|
|
zoomLevel = Math.min(Math.max(kBrowserFormZoomLevelMin, zoomLevel), kBrowserFormZoomLevelMax);
|
2010-10-27 16:54:44 -07:00
|
|
|
zoomLevel = Browser.selectedTab.clampZoomLevel(zoomLevel);
|
2010-07-19 07:51:03 -07:00
|
|
|
|
2010-09-02 14:42:44 -07:00
|
|
|
let zoomRect = Browser._getZoomRectForPoint(aElementRect.center().x, aElementRect.y, zoomLevel);
|
2010-07-19 07:51:03 -07:00
|
|
|
Browser.animatedZoomTo(zoomRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
/**
|
2010-07-13 09:19:22 -07:00
|
|
|
* Responsible for navigating forms and filling in information.
|
|
|
|
* - Navigating forms is handled by next and previous commands.
|
2010-06-21 13:36:56 -07:00
|
|
|
* - When an element is focused, the browser view zooms in to the control.
|
2010-07-13 09:19:22 -07:00
|
|
|
* - The caret positionning and the view are sync to keep the type
|
|
|
|
* in text into view for input fields (text/textarea).
|
2010-06-21 13:36:56 -07:00
|
|
|
* - Provides autocomplete box for input fields.
|
|
|
|
*/
|
2010-07-13 09:19:22 -07:00
|
|
|
var FormHelperUI = {
|
2010-07-19 07:51:03 -07:00
|
|
|
type: "form",
|
|
|
|
commands: {
|
|
|
|
next: "cmd_formNext",
|
|
|
|
previous: "cmd_formPrevious",
|
|
|
|
close: "cmd_formClose"
|
|
|
|
},
|
|
|
|
|
2010-08-27 13:30:45 -07:00
|
|
|
//for resize/rotate case
|
|
|
|
_currentCaretRect: null,
|
|
|
|
_currentElementRect: null,
|
|
|
|
|
2010-10-26 12:12:42 -07:00
|
|
|
_visibleScreenArea: null,
|
|
|
|
get visibleScreenArea() {
|
|
|
|
let visibleRect = Rect.fromRect(Browser.selectedBrowser.getBoundingClientRect());
|
|
|
|
let visibleScreenArea = visibleRect;
|
|
|
|
if (this._visibleScreenArea) {
|
|
|
|
visibleScreenArea = this._visibleScreenArea.clone();
|
|
|
|
visibleScreenArea.x = visibleRect.x;
|
|
|
|
visibleScreenArea.y = visibleRect.y;
|
|
|
|
visibleScreenArea.width = visibleRect.width;
|
|
|
|
visibleScreenArea.height = visibleRect.height - this._container.getBoundingClientRect().height;
|
|
|
|
}
|
|
|
|
return visibleScreenArea;
|
|
|
|
},
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
init: function formHelperInit() {
|
2010-07-19 07:51:03 -07:00
|
|
|
this._container = document.getElementById("content-navigator");
|
2010-07-13 09:19:22 -07:00
|
|
|
this._autofillContainer = document.getElementById("form-helper-autofill");
|
2010-07-19 07:51:03 -07:00
|
|
|
this._cmdPrevious = document.getElementById(this.commands.previous);
|
|
|
|
this._cmdNext = document.getElementById(this.commands.next);
|
2010-09-23 21:48:52 -07:00
|
|
|
this._visibleScreenArea = new Rect(0, 0, 0, 0);
|
2010-07-13 09:19:22 -07:00
|
|
|
|
|
|
|
// Listen for form assistant messages from content
|
|
|
|
messageManager.addMessageListener("FormAssist:Show", this);
|
|
|
|
messageManager.addMessageListener("FormAssist:Hide", this);
|
|
|
|
messageManager.addMessageListener("FormAssist:Update", this);
|
2010-08-27 13:30:45 -07:00
|
|
|
messageManager.addMessageListener("FormAssist:Resize", this);
|
2010-07-13 09:19:22 -07:00
|
|
|
messageManager.addMessageListener("FormAssist:AutoComplete", this);
|
2010-06-21 13:36:56 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
// Listen for events where form assistant should be closed
|
|
|
|
document.getElementById("tabs").addEventListener("TabSelect", this, true);
|
2010-09-29 10:43:00 -07:00
|
|
|
Elements.browsers.addEventListener("URLChanged", this, true);
|
2010-08-24 01:53:22 -07:00
|
|
|
|
|
|
|
// Listen for modal dialog to show/hide the UI
|
|
|
|
messageManager.addMessageListener("DOMWillOpenModalDialog", this);
|
|
|
|
messageManager.addMessageListener("DOMModalDialogClosed", this);
|
2010-08-27 13:30:45 -07:00
|
|
|
|
|
|
|
Services.obs.addObserver(this, "softkb-change", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
uninit: function formHelperUninit() {
|
|
|
|
Services.obs.removeObserver(this, "softkb-change");
|
2009-10-23 21:04:51 -07:00
|
|
|
},
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
show: function formHelperShow(aElement, aHasPrevious, aHasNext) {
|
|
|
|
this._open = true;
|
2009-10-23 21:04:51 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
// Update the next/previous commands
|
|
|
|
this._cmdPrevious.setAttribute("disabled", !aHasPrevious);
|
|
|
|
this._cmdNext.setAttribute("disabled", !aHasNext);
|
2010-03-09 19:42:04 -08:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
let lastElement = this._currentElement || null;
|
|
|
|
this._currentElement = {
|
2010-07-30 17:39:31 -07:00
|
|
|
id: aElement.id,
|
2010-07-13 09:19:22 -07:00
|
|
|
name: aElement.name,
|
|
|
|
value: aElement.value,
|
|
|
|
maxLength: aElement.maxLength,
|
2010-07-30 17:39:31 -07:00
|
|
|
type: aElement.type,
|
2010-07-19 07:52:48 -07:00
|
|
|
isAutocomplete: aElement.isAutocomplete,
|
2010-07-13 09:19:22 -07:00
|
|
|
list: aElement.choices
|
|
|
|
}
|
2010-08-27 13:30:45 -07:00
|
|
|
|
2010-10-26 12:12:42 -07:00
|
|
|
this._updateContainer(lastElement, this._currentElement);
|
|
|
|
this._zoom(Rect.fromRect(aElement.rect), Rect.fromRect(aElement.caretRect));
|
2010-11-02 08:27:54 -07:00
|
|
|
|
|
|
|
// Prevent the view to scroll automatically while typing
|
|
|
|
Browser.selectedBrowser.scrollSync = false;
|
2010-06-04 01:58:33 -07:00
|
|
|
},
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
hide: function formHelperHide() {
|
|
|
|
if (!this._open)
|
|
|
|
return;
|
|
|
|
|
2010-11-02 08:27:54 -07:00
|
|
|
// Restore the scroll synchonisation
|
|
|
|
Browser.selectedBrowser.scrollSync = true;
|
|
|
|
|
2010-08-27 13:30:45 -07:00
|
|
|
// reset current Element and Caret Rect
|
|
|
|
this._currentElementRect = null;
|
|
|
|
this._currentCaretRect = null;
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
this._updateContainerForSelect(this._currentElement, null);
|
|
|
|
this._open = false;
|
2009-10-23 21:04:51 -07:00
|
|
|
},
|
|
|
|
|
2010-07-19 07:51:03 -07:00
|
|
|
handleEvent: function formHelperHandleEvent(aEvent) {
|
2010-07-13 09:19:22 -07:00
|
|
|
if (aEvent.type == "TabSelect" || aEvent.type == "URLChanged")
|
|
|
|
this.hide();
|
2009-10-23 21:04:51 -07:00
|
|
|
},
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
receiveMessage: function formHelperReceiveMessage(aMessage) {
|
|
|
|
let json = aMessage.json;
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "FormAssist:Show":
|
|
|
|
// if the user has manually disabled the Form Assistant UI we still
|
|
|
|
// want to show a UI for <select /> element but not managed by
|
|
|
|
// FormHelperUI
|
|
|
|
let enabled = Services.prefs.getBoolPref("formhelper.enabled");
|
2010-08-24 01:53:22 -07:00
|
|
|
enabled ? this.show(json.current, json.hasPrevious, json.hasNext)
|
|
|
|
: SelectHelperUI.show(json.current.choices);
|
2010-07-13 09:19:22 -07:00
|
|
|
break;
|
2010-07-01 13:21:21 -07:00
|
|
|
|
2010-07-19 16:23:27 -07:00
|
|
|
case "FormAssist:Hide":
|
|
|
|
this.hide();
|
|
|
|
break;
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
case "FormAssist:AutoComplete":
|
|
|
|
this._updateAutocompleteFor(json.current);
|
2010-07-19 07:51:03 -07:00
|
|
|
this._container.contentHasChanged();
|
2010-07-13 09:19:22 -07:00
|
|
|
break;
|
|
|
|
|
2010-08-27 13:30:45 -07:00
|
|
|
case "FormAssist:Resize":
|
2010-09-30 15:02:26 -07:00
|
|
|
SelectHelperUI.resize();
|
2010-08-27 13:30:45 -07:00
|
|
|
this._zoom(this._currentElementRect, this._currentCaretRect);
|
|
|
|
this._container.contentHasChanged();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "FormAssist:Update":
|
2010-10-26 12:12:42 -07:00
|
|
|
Browser.hideSidebars();
|
|
|
|
Browser.hideTitlebar();
|
|
|
|
this._zoom(null, Rect.fromRect(json.caretRect));
|
2010-07-13 09:19:22 -07:00
|
|
|
break;
|
2010-08-24 01:53:22 -07:00
|
|
|
|
|
|
|
case "DOMWillOpenModalDialog":
|
|
|
|
if (this._open && aMessage.target == Browser.selectedBrowser) {
|
|
|
|
this._container.style.display = "none";
|
|
|
|
this._container._spacer.hidden = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "DOMModalDialogClosed":
|
|
|
|
if (this._open && aMessage.target == Browser.selectedBrowser) {
|
|
|
|
this._container.style.display = "-moz-box";
|
|
|
|
this._container._spacer.hidden = false;
|
|
|
|
}
|
|
|
|
break;
|
2010-03-09 19:42:04 -08:00
|
|
|
}
|
|
|
|
},
|
2010-09-23 21:48:52 -07:00
|
|
|
|
2010-08-27 13:30:45 -07:00
|
|
|
observe: function formHelperObserve(aSubject, aTopic, aData) {
|
|
|
|
let rect = Rect.fromRect(JSON.parse(aData));
|
|
|
|
rect.height = rect.bottom - rect.top;
|
|
|
|
rect.width = rect.right - rect.left;
|
|
|
|
|
2010-09-23 21:48:52 -07:00
|
|
|
this._visibleScreenArea = rect;
|
2010-08-27 13:30:45 -07:00
|
|
|
BrowserUI.sizeControls(rect.width, rect.height);
|
2010-10-26 12:12:42 -07:00
|
|
|
if (this.open)
|
|
|
|
this._zoom(this._currentElementRect, this._currentCaretRect);
|
2010-08-27 13:30:45 -07:00
|
|
|
},
|
2010-03-09 19:42:04 -08:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
goToPrevious: function formHelperGoToPrevious() {
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:Previous", { });
|
|
|
|
},
|
2009-10-23 21:04:51 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
goToNext: function formHelperGoToNext() {
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:Next", { });
|
|
|
|
},
|
2009-10-23 21:04:51 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
doAutoComplete: function formHelperDoAutoComplete(aElement) {
|
|
|
|
// Suggestions are only in <label>s. Ignore the rest.
|
|
|
|
if (aElement instanceof Ci.nsIDOMXULLabelElement)
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:AutoComplete", { value: aElement.value });
|
|
|
|
},
|
2010-03-30 10:56:06 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
get _open() {
|
2010-07-19 07:51:03 -07:00
|
|
|
return (this._container.getAttribute("type") == this.type);
|
2009-10-23 21:04:51 -07:00
|
|
|
},
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
set _open(aVal) {
|
|
|
|
if (aVal == this._open)
|
2009-10-23 21:04:51 -07:00
|
|
|
return;
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
this._container.hidden = !aVal;
|
2010-08-27 13:30:45 -07:00
|
|
|
this._container.contentHasChanged();
|
2009-10-23 21:04:51 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
if (aVal) {
|
|
|
|
this._zoomStart();
|
2010-07-19 07:51:03 -07:00
|
|
|
this._container.show(this);
|
2010-07-13 09:19:22 -07:00
|
|
|
} else {
|
|
|
|
this._zoomFinish();
|
2010-07-19 07:51:03 -07:00
|
|
|
this._currentElement = null;
|
|
|
|
this._container.hide(this);
|
2010-06-21 13:36:56 -07:00
|
|
|
}
|
|
|
|
|
2010-03-30 10:56:06 -07:00
|
|
|
let evt = document.createEvent("UIEvents");
|
2010-07-13 09:19:22 -07:00
|
|
|
evt.initUIEvent("FormUI", true, true, window, aVal);
|
2010-03-30 10:56:06 -07:00
|
|
|
this._container.dispatchEvent(evt);
|
2009-10-23 21:04:51 -07:00
|
|
|
},
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
_updateAutocompleteFor: function _formHelperUpdateAutocompleteFor(aElement) {
|
|
|
|
let suggestions = this._getAutocompleteSuggestions(aElement);
|
|
|
|
this._displaySuggestions(suggestions);
|
|
|
|
},
|
|
|
|
|
|
|
|
_displaySuggestions: function _formHelperDisplaySuggestions(aSuggestions) {
|
|
|
|
let autofill = this._autofillContainer;
|
|
|
|
while (autofill.hasChildNodes())
|
|
|
|
autofill.removeChild(autofill.lastChild);
|
|
|
|
|
|
|
|
let fragment = document.createDocumentFragment();
|
|
|
|
for (let i = 0; i < aSuggestions.length; i++) {
|
|
|
|
let value = aSuggestions[i];
|
|
|
|
let button = document.createElement("label");
|
|
|
|
button.setAttribute("value", value);
|
2010-07-30 12:03:03 -07:00
|
|
|
button.className = "form-helper-autofill-label";
|
2010-07-13 09:19:22 -07:00
|
|
|
fragment.appendChild(button);
|
|
|
|
}
|
|
|
|
autofill.appendChild(fragment);
|
|
|
|
autofill.collapsed = !aSuggestions.length;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** Retrieve the autocomplete list from the autocomplete service for an element */
|
|
|
|
_getAutocompleteSuggestions: function _formHelperGetAutocompleteSuggestions(aElement) {
|
2010-07-19 07:52:48 -07:00
|
|
|
if (!aElement.isAutocomplete)
|
|
|
|
return [];
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
let suggestions = [];
|
2010-07-14 13:44:12 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
let autocompleteService = Cc["@mozilla.org/satchel/form-autocomplete;1"].getService(Ci.nsIFormAutoComplete);
|
2010-07-30 17:39:31 -07:00
|
|
|
let results = autocompleteService.autoCompleteSearch(aElement.name, aElement.value, aElement, null);
|
2010-07-19 07:52:48 -07:00
|
|
|
if (results.matchCount > 0) {
|
|
|
|
for (let i = 0; i < results.matchCount; i++) {
|
|
|
|
let value = results.getValueAt(i);
|
|
|
|
suggestions.push(value);
|
2010-07-13 09:19:22 -07:00
|
|
|
}
|
|
|
|
}
|
2010-07-14 13:44:12 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
return suggestions;
|
2010-06-21 13:36:56 -07:00
|
|
|
},
|
2009-11-25 12:51:03 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
/** Update the form helper container to reflect new element user is editing. */
|
2010-07-13 09:19:22 -07:00
|
|
|
_updateContainer: function _formHelperUpdateContainer(aLastElement, aCurrentElement) {
|
|
|
|
this._updateContainerForSelect(aLastElement, aCurrentElement);
|
2009-11-25 12:51:03 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
// Setup autofill UI
|
2010-07-13 09:19:22 -07:00
|
|
|
this._updateAutocompleteFor(aCurrentElement);
|
2010-07-19 07:51:03 -07:00
|
|
|
this._container.contentHasChanged();
|
2010-06-21 13:36:56 -07:00
|
|
|
},
|
2010-03-09 19:42:04 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
/** Helper for _updateContainer that handles the case where the new element is a select. */
|
2010-07-13 09:19:22 -07:00
|
|
|
_updateContainerForSelect: function _formHelperUpdateContainerForSelect(aLastElement, aCurrentElement) {
|
|
|
|
let lastHasChoices = aLastElement && (aLastElement.list != null);
|
|
|
|
let currentHasChoices = aCurrentElement && (aCurrentElement.list != null);
|
2010-04-14 08:22:23 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
if (!lastHasChoices && currentHasChoices) {
|
2010-07-13 09:19:22 -07:00
|
|
|
SelectHelperUI.dock(this._container);
|
|
|
|
SelectHelperUI.show(aCurrentElement.list);
|
|
|
|
} else if (lastHasChoices && currentHasChoices) {
|
|
|
|
SelectHelperUI.reset();
|
|
|
|
SelectHelperUI.show(aCurrentElement.list);
|
|
|
|
} else if (lastHasChoices && !currentHasChoices) {
|
|
|
|
SelectHelperUI.hide();
|
2009-11-25 12:51:03 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
/** Zoom and move viewport so that element is legible and touchable. */
|
2010-07-19 07:51:03 -07:00
|
|
|
_zoom: function _formHelperZoom(aElementRect, aCaretRect) {
|
2010-10-26 12:12:42 -07:00
|
|
|
let zoomRect = this.visibleScreenArea;
|
2010-09-15 15:05:50 -07:00
|
|
|
let browser = getBrowser();
|
2010-05-20 06:46:22 -07:00
|
|
|
|
2010-10-26 12:12:42 -07:00
|
|
|
// Zoom to a specified Rect
|
|
|
|
if (aElementRect && Browser.selectedTab.allowZoom && Services.prefs.getBoolPref("formhelper.autozoom")) {
|
|
|
|
this._currentElementRect = aElementRect;
|
|
|
|
// Zoom to an element by keeping the caret into view
|
2010-11-04 03:54:12 -07:00
|
|
|
let zoomLevel = Browser.selectedTab.clampZoomLevel(this._getZoomLevelForRect(aElementRect));
|
2010-08-27 13:30:45 -07:00
|
|
|
|
2010-10-26 12:12:42 -07:00
|
|
|
zoomRect = this._getZoomRectForPoint(aElementRect.center().x, aElementRect.y, zoomLevel);
|
|
|
|
Browser.animatedZoomTo(zoomRect);
|
|
|
|
}
|
2010-08-27 13:30:45 -07:00
|
|
|
|
2010-11-04 03:54:12 -07:00
|
|
|
this._ensureCaretVisible(aCaretRect);
|
|
|
|
},
|
2010-09-02 14:42:44 -07:00
|
|
|
|
2010-11-04 03:54:12 -07:00
|
|
|
_ensureCaretVisible: function _ensureCaretVisible(aCaretRect) {
|
|
|
|
if (!aCaretRect)
|
|
|
|
return;
|
2010-10-26 12:12:42 -07:00
|
|
|
|
2010-11-04 03:54:12 -07:00
|
|
|
// the scrollX/scrollY position can change because of the animated zoom so
|
|
|
|
// delay the caret adjustment
|
|
|
|
if (AnimatedZoom.isZooming()) {
|
|
|
|
let self = this;
|
|
|
|
window.addEventListener("AnimatedZoomEnd", function() {
|
|
|
|
window.removeEventListener("AnimatedZoomEnd", arguments.callee, true);
|
|
|
|
self._ensureCaretVisible(aCaretRect);
|
|
|
|
}, true);
|
|
|
|
return;
|
2010-04-14 08:22:23 -07:00
|
|
|
}
|
2010-11-04 03:54:12 -07:00
|
|
|
|
|
|
|
let browser = getBrowser();
|
|
|
|
let zoomRect = this.visibleScreenArea;
|
|
|
|
|
|
|
|
this._currentCaretRect = aCaretRect;
|
|
|
|
let caretRect = aCaretRect.scale(browser.scale, browser.scale);
|
|
|
|
|
|
|
|
let scroll = browser.getPosition();
|
|
|
|
zoomRect = new Rect(scroll.x, scroll.y, zoomRect.width, zoomRect.height);
|
|
|
|
if (zoomRect.contains(caretRect))
|
|
|
|
return;
|
|
|
|
|
|
|
|
let [deltaX, deltaY] = this._getOffsetForCaret(caretRect, zoomRect);
|
|
|
|
if (deltaX != 0 || deltaY != 0)
|
|
|
|
browser.scrollBy(deltaX, deltaY);
|
2009-11-27 21:37:01 -08:00
|
|
|
},
|
2010-06-21 13:36:56 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
/* Store the current zoom level, and scroll positions to restore them if needed */
|
|
|
|
_zoomStart: function _formHelperZoomStart() {
|
|
|
|
if (!Services.prefs.getBoolPref("formhelper.restore"))
|
|
|
|
return;
|
2010-06-21 13:36:56 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
this._restore = {
|
2010-09-23 21:48:52 -07:00
|
|
|
scale: getBrowser().scale,
|
2010-07-13 09:19:22 -07:00
|
|
|
contentScrollOffset: Browser.getScrollboxPosition(Browser.contentScrollboxScroller),
|
|
|
|
pageScrollOffset: Browser.getScrollboxPosition(Browser.pageScrollboxScroller)
|
|
|
|
};
|
2010-04-14 08:22:23 -07:00
|
|
|
},
|
2010-06-04 01:58:33 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
/** Element is no longer selected. Restore zoom level if setting is enabled. */
|
|
|
|
_zoomFinish: function _formHelperZoomFinish() {
|
2010-07-19 07:51:03 -07:00
|
|
|
if(!Services.prefs.getBoolPref("formhelper.restore"))
|
2010-07-13 09:19:22 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
let restore = this._restore;
|
2010-09-23 21:48:52 -07:00
|
|
|
getBrowser().scale = restore.scale;
|
2010-07-13 09:19:22 -07:00
|
|
|
Browser.contentScrollboxScroller.scrollTo(restore.contentScrollOffset.x, restore.contentScrollOffset.y);
|
|
|
|
Browser.pageScrollboxScroller.scrollTo(restore.pageScrollOffset.x, restore.pageScrollOffset.y);
|
2010-07-01 22:50:47 -07:00
|
|
|
},
|
|
|
|
|
2010-10-26 12:12:42 -07:00
|
|
|
_getZoomRectForPoint: function _getZoomRectForPoint(x, y, zoomLevel) {
|
|
|
|
let browser = getBrowser();
|
|
|
|
x = x * browser.scale;
|
|
|
|
y = y * browser.scale;
|
|
|
|
|
|
|
|
let vis = this.visibleScreenArea
|
|
|
|
zoomLevel = Math.min(ZoomManager.MAX, zoomLevel);
|
|
|
|
let oldScale = browser.scale;
|
|
|
|
let zoomRatio = zoomLevel / oldScale;
|
|
|
|
let newVisW = vis.width / zoomRatio, newVisH = vis.height / zoomRatio;
|
2010-10-27 16:54:44 -07:00
|
|
|
let result = new Rect(x - newVisW / 2, y - newVisH / 2, newVisW, newVisH);
|
2010-10-26 12:12:42 -07:00
|
|
|
|
|
|
|
// Make sure rectangle doesn't poke out of viewport
|
|
|
|
return result.translateInside(new Rect(0, 0, browser.contentDocumentWidth * oldScale,
|
|
|
|
browser.contentDocumentHeight * oldScale));
|
|
|
|
},
|
|
|
|
|
|
|
|
_getZoomLevelForRect: function _getZoomLevelForRect(aRect) {
|
2010-10-27 16:54:44 -07:00
|
|
|
const margin = 30;
|
|
|
|
let zoomLevel = this.visibleScreenArea.width / (aRect.width + margin);
|
2010-10-26 12:12:42 -07:00
|
|
|
return Util.clamp(zoomLevel, kBrowserFormZoomLevelMin, kBrowserFormZoomLevelMax);
|
|
|
|
},
|
|
|
|
|
2010-07-19 07:51:03 -07:00
|
|
|
_getOffsetForCaret: function _formHelperGetOffsetForCaret(aCaretRect, aRect) {
|
2010-04-14 08:22:23 -07:00
|
|
|
// Determine if we need to move left or right to bring the caret into view
|
|
|
|
let deltaX = 0;
|
|
|
|
if (aCaretRect.right > aRect.right)
|
|
|
|
deltaX = aCaretRect.right - aRect.right;
|
|
|
|
if (aCaretRect.left < aRect.left)
|
|
|
|
deltaX = aCaretRect.left - aRect.left;
|
2010-06-21 13:36:56 -07:00
|
|
|
|
2010-04-14 08:22:23 -07:00
|
|
|
// Determine if we need to move up or down to bring the caret into view
|
|
|
|
let deltaY = 0;
|
|
|
|
if (aCaretRect.bottom > aRect.bottom)
|
|
|
|
deltaY = aCaretRect.bottom - aRect.bottom;
|
|
|
|
if (aCaretRect.top < aRect.top)
|
|
|
|
deltaY = aCaretRect.top - aRect.top;
|
|
|
|
|
|
|
|
return [deltaX, deltaY];
|
2010-06-21 13:36:56 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2010-07-13 09:19:22 -07:00
|
|
|
* SelectHelperUI: Provides an interface for making a choice in a list.
|
2010-06-21 13:36:56 -07:00
|
|
|
* Supports simultaneous selection of choices and group headers.
|
|
|
|
*/
|
2010-07-13 09:19:22 -07:00
|
|
|
var SelectHelperUI = {
|
2009-06-24 09:42:53 -07:00
|
|
|
_list: null,
|
2010-06-21 13:36:56 -07:00
|
|
|
_selectedIndexes: null,
|
2010-06-17 20:55:58 -07:00
|
|
|
|
|
|
|
get _panel() {
|
|
|
|
delete this._panel;
|
|
|
|
return this._panel = document.getElementById("select-container");
|
|
|
|
},
|
2009-07-06 10:14:46 -07:00
|
|
|
|
2010-07-21 16:39:43 -07:00
|
|
|
get _textbox() {
|
|
|
|
delete this._textbox;
|
|
|
|
return this._textbox = document.getElementById("select-helper-textbox");
|
|
|
|
},
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
show: function(aList) {
|
|
|
|
this._list = aList;
|
2009-06-24 09:42:53 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
this._container = document.getElementById("select-list");
|
|
|
|
this._container.setAttribute("multiple", aList.multiple ? "true" : "false");
|
2009-06-24 09:42:53 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
this._selectedIndexes = this._getSelectedIndexes();
|
2009-07-28 20:36:00 -07:00
|
|
|
let firstSelected = null;
|
2009-08-13 16:41:45 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
let choices = aList.choices;
|
2010-06-21 13:36:56 -07:00
|
|
|
for (let i = 0; i < choices.length; i++) {
|
|
|
|
let choice = choices[i];
|
2010-07-14 13:44:12 -07:00
|
|
|
let item = document.createElement("option");
|
2010-07-30 11:20:48 -07:00
|
|
|
item.className = "chrome-select-option";
|
2010-07-14 13:44:12 -07:00
|
|
|
item.setAttribute("label", choice.text);
|
|
|
|
choice.disabled ? item.setAttribute("disabled", choice.disabled)
|
|
|
|
: item.removeAttribute("disabled");
|
|
|
|
this._container.appendChild(item);
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
if (choice.group) {
|
2010-07-30 11:20:48 -07:00
|
|
|
item.classList.add("optgroup");
|
2010-07-14 13:44:12 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
item.optionIndex = choice.optionIndex;
|
|
|
|
item.choiceIndex = i;
|
|
|
|
|
|
|
|
if (choice.inGroup)
|
2010-07-30 11:20:48 -07:00
|
|
|
item.classList.add("in-optgroup");
|
2010-07-14 13:44:12 -07:00
|
|
|
|
|
|
|
if (choice.selected) {
|
|
|
|
item.setAttribute("selected", "true");
|
|
|
|
firstSelected = firstSelected || item;
|
2009-06-24 09:42:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._panel.hidden = false;
|
2010-07-21 16:39:43 -07:00
|
|
|
this._panel.height = this._panel.getBoundingClientRect().height;
|
2009-06-24 09:42:53 -07:00
|
|
|
|
2010-06-17 20:55:58 -07:00
|
|
|
if (!this._docked)
|
|
|
|
BrowserUI.pushPopup(this, this._panel);
|
|
|
|
|
2009-07-28 20:36:00 -07:00
|
|
|
this._scrollElementIntoView(firstSelected);
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
this._container.addEventListener("click", this, false);
|
2009-06-24 09:42:53 -07:00
|
|
|
},
|
|
|
|
|
2010-06-17 20:55:58 -07:00
|
|
|
dock: function dock(aContainer) {
|
|
|
|
aContainer.insertBefore(this._panel, aContainer.lastChild);
|
2010-09-30 15:02:26 -07:00
|
|
|
this.resize();
|
2010-07-21 16:39:43 -07:00
|
|
|
this._textbox.hidden = false;
|
|
|
|
|
2010-06-17 20:55:58 -07:00
|
|
|
this._docked = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
undock: function undock() {
|
|
|
|
let rootNode = Elements.stack;
|
|
|
|
rootNode.insertBefore(this._panel, rootNode.lastChild);
|
|
|
|
this._panel.style.maxHeight = "";
|
|
|
|
this._docked = false;
|
|
|
|
},
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
reset: function() {
|
|
|
|
this._updateControl();
|
2010-07-13 09:19:22 -07:00
|
|
|
let empty = this._container.cloneNode(false);
|
|
|
|
this._container.parentNode.replaceChild(empty, this._container);
|
|
|
|
this._container = empty;
|
|
|
|
this._list = null;
|
2010-06-21 13:36:56 -07:00
|
|
|
this._selectedIndexes = null;
|
2010-07-21 16:39:43 -07:00
|
|
|
this._panel.height = "";
|
|
|
|
this._textbox.value = "";
|
2010-06-21 13:36:56 -07:00
|
|
|
},
|
|
|
|
|
2010-09-30 15:02:26 -07:00
|
|
|
resize: function resize() {
|
|
|
|
this._panel.style.maxHeight = (window.innerHeight / 1.8) + "px";
|
|
|
|
},
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
hide: function() {
|
2010-07-13 09:19:22 -07:00
|
|
|
this._container.removeEventListener("click", this, false);
|
2010-07-21 16:39:43 -07:00
|
|
|
this._panel.hidden = this._textbox.hidden = true;
|
2010-06-21 13:36:56 -07:00
|
|
|
|
|
|
|
if (this._docked)
|
|
|
|
this.undock();
|
|
|
|
else
|
2010-11-01 08:42:13 -07:00
|
|
|
BrowserUI.popPopup(this);
|
2010-06-21 13:36:56 -07:00
|
|
|
|
|
|
|
this.reset();
|
|
|
|
},
|
|
|
|
|
2010-07-21 16:39:43 -07:00
|
|
|
filter: function(aValue) {
|
|
|
|
let reg = new RegExp(aValue, "gi");
|
|
|
|
let options = this._container.childNodes;
|
|
|
|
for (let i = 0; i < options.length; i++) {
|
|
|
|
let option = options[i];
|
|
|
|
option.getAttribute("label").match(reg) ? option.removeAttribute("filtered")
|
|
|
|
: option.setAttribute("filtered", "true");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
unselectAll: function() {
|
2010-07-13 09:19:22 -07:00
|
|
|
let choices = this._list.choices;
|
2010-06-21 13:36:56 -07:00
|
|
|
this._forEachOption(function(aItem, aIndex) {
|
|
|
|
aItem.selected = false;
|
|
|
|
choices[aIndex].selected = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
selectByIndex: function(aIndex) {
|
2010-07-13 09:19:22 -07:00
|
|
|
let choices = this._list.choices;
|
|
|
|
for (let i = 0; i < this._container.childNodes.length; i++) {
|
|
|
|
let option = this._container.childNodes[i];
|
2010-06-21 13:36:56 -07:00
|
|
|
if (option.optionIndex == aIndex) {
|
|
|
|
option.selected = true;
|
|
|
|
this._choices[i].selected = true;
|
|
|
|
this._scrollElementIntoView(option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
_getSelectedIndexes: function() {
|
2010-06-21 13:36:56 -07:00
|
|
|
let indexes = [];
|
2010-07-13 09:19:22 -07:00
|
|
|
let choices = this._list.choices;
|
2010-06-21 13:36:56 -07:00
|
|
|
let choiceLength = choices.length;
|
|
|
|
for (let i = 0; i < choiceLength; i++) {
|
|
|
|
let choice = choices[i];
|
|
|
|
if (choice.selected)
|
|
|
|
indexes.push(choice.optionIndex);
|
|
|
|
}
|
|
|
|
return indexes;
|
|
|
|
},
|
|
|
|
|
2009-07-28 20:36:00 -07:00
|
|
|
_scrollElementIntoView: function(aElement) {
|
|
|
|
if (!aElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let index = -1;
|
|
|
|
this._forEachOption(
|
|
|
|
function(aItem, aIndex) {
|
|
|
|
if (aElement.optionIndex == aItem.optionIndex)
|
|
|
|
index = aIndex;
|
|
|
|
}
|
|
|
|
);
|
2009-08-13 16:41:45 -07:00
|
|
|
|
2009-07-28 20:36:00 -07:00
|
|
|
if (index == -1)
|
|
|
|
return;
|
2009-08-13 16:41:45 -07:00
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
let scrollBoxObject = this._container.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
|
2009-07-28 20:36:00 -07:00
|
|
|
let itemHeight = aElement.getBoundingClientRect().height;
|
2010-07-13 09:19:22 -07:00
|
|
|
let visibleItemsCount = this._container.boxObject.height / itemHeight;
|
2009-07-28 20:36:00 -07:00
|
|
|
if ((index + 1) > visibleItemsCount) {
|
|
|
|
let delta = Math.ceil(visibleItemsCount / 2);
|
|
|
|
scrollBoxObject.scrollTo(0, ((index + 1) - delta) * itemHeight);
|
|
|
|
}
|
2010-02-16 15:34:04 -08:00
|
|
|
else {
|
|
|
|
scrollBoxObject.scrollTo(0, 0);
|
|
|
|
}
|
2009-07-28 20:36:00 -07:00
|
|
|
},
|
|
|
|
|
2009-06-24 09:42:53 -07:00
|
|
|
_forEachOption: function(aCallback) {
|
2010-07-13 09:19:22 -07:00
|
|
|
let children = this._container.children;
|
2010-06-21 13:36:56 -07:00
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let item = children[i];
|
|
|
|
if (!item.hasOwnProperty("optionIndex"))
|
|
|
|
continue;
|
|
|
|
aCallback(item, i);
|
|
|
|
}
|
2009-06-24 09:42:53 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateControl: function() {
|
2010-07-13 09:19:22 -07:00
|
|
|
let currentSelectedIndexes = this._getSelectedIndexes();
|
2009-07-06 10:14:46 -07:00
|
|
|
|
2010-07-14 13:44:12 -07:00
|
|
|
let isIdentical = (this._selectedIndexes && this._selectedIndexes.length == currentSelectedIndexes.length);
|
2009-07-06 10:14:46 -07:00
|
|
|
if (isIdentical) {
|
|
|
|
for (let i = 0; i < currentSelectedIndexes.length; i++) {
|
|
|
|
if (currentSelectedIndexes[i] != this._selectedIndexes[i]) {
|
|
|
|
isIdentical = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-13 09:19:22 -07:00
|
|
|
if (isIdentical)
|
|
|
|
return;
|
|
|
|
|
2010-08-24 01:53:22 -07:00
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:ChoiceChange", { });
|
2010-02-16 15:34:04 -08:00
|
|
|
},
|
|
|
|
|
2009-06-24 09:42:53 -07:00
|
|
|
handleEvent: function(aEvent) {
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "click":
|
|
|
|
let item = aEvent.target;
|
|
|
|
if (item && item.hasOwnProperty("optionIndex")) {
|
2010-07-13 09:19:22 -07:00
|
|
|
if (this._list.multiple) {
|
2009-06-24 09:42:53 -07:00
|
|
|
// Toggle the item state
|
|
|
|
item.selected = !item.selected;
|
|
|
|
}
|
|
|
|
else {
|
2010-02-16 15:34:04 -08:00
|
|
|
this.unselectAll();
|
2009-06-24 09:42:53 -07:00
|
|
|
|
|
|
|
// Select the new one and update the control
|
|
|
|
item.selected = true;
|
|
|
|
}
|
2010-07-14 13:44:12 -07:00
|
|
|
this.onSelect(item.optionIndex, item.selected, !this._list.multiple);
|
2009-06-24 09:42:53 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-07-13 09:19:22 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onSelect: function(aIndex, aSelected, aClearAll) {
|
|
|
|
let json = {
|
|
|
|
index: aIndex,
|
|
|
|
selected: aSelected,
|
|
|
|
clearAll: aClearAll
|
|
|
|
};
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:ChoiceSelect", json);
|
2009-06-24 09:42:53 -07:00
|
|
|
}
|
|
|
|
};
|
2009-08-17 14:05:06 -07:00
|
|
|
|
2010-08-24 01:53:22 -07:00
|
|
|
var MenuListHelperUI = {
|
|
|
|
get _container() {
|
|
|
|
delete this._container;
|
|
|
|
return this._container = document.getElementById("menulist-container");
|
|
|
|
},
|
|
|
|
|
|
|
|
get _popup() {
|
|
|
|
delete this._popup;
|
|
|
|
return this._popup = document.getElementById("menulist-popup");
|
|
|
|
},
|
|
|
|
|
2010-08-26 16:09:56 -07:00
|
|
|
get _title() {
|
|
|
|
delete this._title;
|
|
|
|
return this._title = document.getElementById("menulist-title");
|
|
|
|
},
|
|
|
|
|
2010-08-24 01:53:22 -07:00
|
|
|
_currentList: null,
|
|
|
|
show: function mn_show(aMenulist) {
|
|
|
|
this._currentList = aMenulist;
|
2010-08-26 16:09:56 -07:00
|
|
|
this._title.value = aMenulist.title || "";
|
2010-08-24 01:53:22 -07:00
|
|
|
|
|
|
|
let container = this._container;
|
2010-08-26 16:09:56 -07:00
|
|
|
let listbox = this._popup.lastChild;
|
2010-08-24 01:53:22 -07:00
|
|
|
while (listbox.firstChild)
|
|
|
|
listbox.removeChild(listbox.firstChild);
|
|
|
|
|
|
|
|
let children = this._currentList.menupopup.children;
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let child = children[i];
|
|
|
|
let item = document.createElement("richlistitem");
|
2010-08-25 08:31:22 -07:00
|
|
|
// Add selected as a class name instead of an attribute to not being overidden
|
|
|
|
// by the richlistbox behavior (it sets the "current" and "selected" attribute
|
2010-10-21 12:19:58 -07:00
|
|
|
item.setAttribute("class", "menulist-command prompt-button" + (child.selected ? " selected" : ""));
|
2010-08-24 01:53:22 -07:00
|
|
|
|
2010-08-26 16:09:56 -07:00
|
|
|
let image = document.createElement("image");
|
|
|
|
image.setAttribute("src", child.image || "");
|
|
|
|
item.appendChild(image);
|
2010-08-24 01:53:22 -07:00
|
|
|
|
|
|
|
let label = document.createElement("label");
|
|
|
|
label.setAttribute("value", child.label);
|
|
|
|
item.appendChild(label);
|
|
|
|
|
|
|
|
listbox.appendChild(item);
|
|
|
|
}
|
|
|
|
|
2010-08-26 16:09:56 -07:00
|
|
|
window.addEventListener("resize", this, true);
|
2010-08-24 01:53:22 -07:00
|
|
|
container.hidden = false;
|
2010-08-26 16:09:56 -07:00
|
|
|
this.sizeToContent();
|
2010-08-24 01:53:22 -07:00
|
|
|
BrowserUI.pushPopup(this, [this._popup]);
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function mn_hide() {
|
|
|
|
this._currentList = null;
|
|
|
|
this._container.hidden = true;
|
2010-08-26 16:09:56 -07:00
|
|
|
window.removeEventListener("resize", this, true);
|
2010-11-01 08:42:13 -07:00
|
|
|
BrowserUI.popPopup(this);
|
2010-08-24 01:53:22 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
selectByIndex: function mn_selectByIndex(aIndex) {
|
|
|
|
this._currentList.selectedIndex = aIndex;
|
|
|
|
|
|
|
|
// Dispatch a xul command event to the attached menulist
|
2010-08-26 16:09:56 -07:00
|
|
|
if (this._currentList.dispatchEvent) {
|
|
|
|
let evt = document.createEvent("XULCommandEvent");
|
|
|
|
evt.initCommandEvent("command", true, true, window, 0, false, false, false, false, null);
|
|
|
|
this._currentList.dispatchEvent(evt);
|
|
|
|
}
|
2010-08-24 01:53:22 -07:00
|
|
|
|
|
|
|
this.hide();
|
2010-08-26 16:09:56 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
sizeToContent: function sizeToContent() {
|
2010-09-01 12:13:42 -07:00
|
|
|
this._popup.maxWidth = window.innerWidth * 0.75;
|
2010-08-26 16:09:56 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function handleEvent(aEvent) {
|
|
|
|
this.sizeToContent();
|
2010-08-24 01:53:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-24 11:22:18 -07:00
|
|
|
var ContextHelper = {
|
2010-06-29 11:15:07 -07:00
|
|
|
popupState: null,
|
2010-07-26 10:52:17 -07:00
|
|
|
|
|
|
|
get _panel() {
|
|
|
|
delete this._panel;
|
|
|
|
return this._panel = document.getElementById("context-container");
|
|
|
|
},
|
|
|
|
|
|
|
|
get _popup() {
|
|
|
|
delete this._popup;
|
|
|
|
return this._popup = document.getElementById("context-popup");
|
|
|
|
},
|
|
|
|
|
2010-09-22 15:12:41 -07:00
|
|
|
showPopup: function ch_showPopup(aMessage) {
|
2010-06-29 11:15:07 -07:00
|
|
|
this.popupState = aMessage.json;
|
2010-07-23 13:49:56 -07:00
|
|
|
this.popupState.target = aMessage.target;
|
2010-03-24 11:22:18 -07:00
|
|
|
|
2010-06-29 11:15:07 -07:00
|
|
|
let first = null;
|
|
|
|
let last = null;
|
2010-03-24 11:22:18 -07:00
|
|
|
let commands = document.getElementById("context-commands");
|
|
|
|
for (let i=0; i<commands.childElementCount; i++) {
|
|
|
|
let command = commands.children[i];
|
|
|
|
command.removeAttribute("selector");
|
|
|
|
command.hidden = true;
|
2010-07-28 21:13:31 -07:00
|
|
|
|
|
|
|
let types = command.getAttribute("type").split(/\s+/);
|
|
|
|
for (let i=0; i<types.length; i++) {
|
|
|
|
if (this.popupState.types.indexOf(types[i]) != -1) {
|
|
|
|
first = first || command;
|
|
|
|
last = command;
|
|
|
|
command.hidden = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-03-24 11:22:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!first) {
|
2010-06-29 11:15:07 -07:00
|
|
|
this.popupState = null;
|
2010-09-22 15:12:41 -07:00
|
|
|
return false;
|
2010-03-24 11:22:18 -07:00
|
|
|
}
|
2010-07-21 16:39:43 -07:00
|
|
|
|
2010-07-28 21:13:31 -07:00
|
|
|
// Allow the first and last *non-hidden* elements to be selected in CSS.
|
2010-03-24 11:22:18 -07:00
|
|
|
first.setAttribute("selector", "first-child");
|
|
|
|
last.setAttribute("selector", "last-child");
|
|
|
|
|
|
|
|
let label = document.getElementById("context-hint");
|
2010-10-01 08:27:12 -07:00
|
|
|
label.value = this.popupState.label || "";
|
2010-03-24 11:22:18 -07:00
|
|
|
|
2010-07-26 10:52:17 -07:00
|
|
|
this._panel.hidden = false;
|
2010-10-18 14:41:22 -07:00
|
|
|
BrowserUI.blurFocusedElement();
|
2010-07-27 15:54:09 -07:00
|
|
|
window.addEventListener("resize", this, true);
|
2010-03-24 11:22:18 -07:00
|
|
|
|
2010-07-27 15:54:09 -07:00
|
|
|
this.sizeToContent();
|
|
|
|
BrowserUI.pushPopup(this, [this._popup]);
|
2010-09-22 15:12:41 -07:00
|
|
|
return true;
|
2010-07-27 15:54:09 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function ch_hide() {
|
2010-11-01 08:42:13 -07:00
|
|
|
if (this._panel.hidden)
|
|
|
|
return;
|
2010-07-27 15:54:09 -07:00
|
|
|
this.popupState = null;
|
|
|
|
this._panel.hidden = true;
|
|
|
|
window.removeEventListener("resize", this, true);
|
|
|
|
|
2010-11-01 08:42:13 -07:00
|
|
|
BrowserUI.popPopup(this);
|
2010-07-27 15:54:09 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
sizeToContent: function sizeToContent() {
|
2010-09-01 12:13:42 -07:00
|
|
|
this._popup.maxWidth = window.innerWidth * 0.75;
|
2010-03-24 11:22:18 -07:00
|
|
|
},
|
2010-07-19 07:51:03 -07:00
|
|
|
|
2010-07-27 15:54:09 -07:00
|
|
|
handleEvent: function handleEvent(aEvent) {
|
|
|
|
this.sizeToContent();
|
2010-05-03 21:19:44 -07:00
|
|
|
}
|
|
|
|
};
|
2010-03-24 11:22:18 -07:00
|
|
|
|
|
|
|
var ContextCommands = {
|
2010-10-01 08:27:12 -07:00
|
|
|
copy: function cc_copy() {
|
|
|
|
let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
|
|
|
|
clipboard.copyString(ContextHelper.popupState.string);
|
|
|
|
},
|
|
|
|
|
2010-07-29 21:51:31 -07:00
|
|
|
openInNewTab: function cc_openInNewTab() {
|
2010-06-29 11:15:07 -07:00
|
|
|
Browser.addTab(ContextHelper.popupState.linkURL, false, Browser.selectedTab);
|
2010-03-24 11:22:18 -07:00
|
|
|
},
|
|
|
|
|
2010-08-31 22:54:38 -07:00
|
|
|
saveLink: function cc_saveLink() {
|
|
|
|
let browser = ContextHelper.popupState.target;
|
2010-09-03 07:56:00 -07:00
|
|
|
saveURL(ContextHelper.popupState.linkURL, null, "SaveLinkTitle", false, true, browser.documentURI);
|
2010-08-31 22:54:38 -07:00
|
|
|
},
|
|
|
|
|
2010-07-29 21:51:31 -07:00
|
|
|
saveImage: function cc_saveImage() {
|
2010-07-23 13:49:56 -07:00
|
|
|
let browser = ContextHelper.popupState.target;
|
2010-09-03 07:56:00 -07:00
|
|
|
saveImageURL(ContextHelper.popupState.mediaURL, null, "SaveImageTitle", false, true, browser.documentURI);
|
2010-07-23 13:49:56 -07:00
|
|
|
},
|
|
|
|
|
2010-07-29 21:51:31 -07:00
|
|
|
shareLink: function cc_shareLink() {
|
|
|
|
let state = ContextHelper.popupState;
|
|
|
|
SharingUI.show(state.linkURL, state.linkTitle);
|
|
|
|
},
|
|
|
|
|
|
|
|
shareMedia: function cc_shareMedia() {
|
2010-08-13 11:41:00 -07:00
|
|
|
SharingUI.show(ContextHelper.popupState.mediaURL, null);
|
2010-07-29 21:51:31 -07:00
|
|
|
},
|
|
|
|
|
2010-10-16 06:25:15 -07:00
|
|
|
sendCommand: function cc_playVideo(aCommand) {
|
2010-10-12 08:57:03 -07:00
|
|
|
let browser = ContextHelper.popupState.target;
|
2010-10-16 06:25:15 -07:00
|
|
|
browser.messageManager.sendAsyncMessage("Browser:ContextCommand", { command: aCommand });
|
2010-10-12 08:57:03 -07:00
|
|
|
},
|
|
|
|
|
2010-07-29 21:51:31 -07:00
|
|
|
editBookmark: function cc_editBookmark() {
|
2010-07-23 13:49:56 -07:00
|
|
|
let target = ContextHelper.popupState.target;
|
|
|
|
target.startEditing();
|
|
|
|
},
|
|
|
|
|
2010-07-29 21:51:31 -07:00
|
|
|
removeBookmark: function cc_removeBookmark() {
|
2010-07-23 13:49:56 -07:00
|
|
|
let target = ContextHelper.popupState.target;
|
|
|
|
target.remove();
|
2010-03-24 11:22:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-29 21:51:31 -07:00
|
|
|
var SharingUI = {
|
|
|
|
_dialog: null,
|
|
|
|
|
2010-10-01 17:07:58 -07:00
|
|
|
show: function show(aURL, aTitle) {
|
2010-09-22 01:02:00 -07:00
|
|
|
try {
|
2010-10-01 17:07:58 -07:00
|
|
|
this.showSharingUI(aURL, aTitle);
|
2010-09-22 01:02:00 -07:00
|
|
|
} catch (ex) {
|
|
|
|
this.showFallback(aURL, aTitle);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-10-01 17:07:58 -07:00
|
|
|
showSharingUI: function showSharingUI(aURL, aTitle) {
|
2010-09-22 01:02:00 -07:00
|
|
|
let sharingSvc = Cc["@mozilla.org/uriloader/external-sharing-app-service;1"].getService(Ci.nsIExternalSharingAppService);
|
2010-10-01 17:07:58 -07:00
|
|
|
sharingSvc.shareWithDefault(aURL, "text/plain", aTitle);
|
2010-09-22 01:02:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
showFallback: function showFallback(aURL, aTitle) {
|
2010-07-29 21:51:31 -07:00
|
|
|
this._dialog = importDialog(window, "chrome://browser/content/share.xul", null);
|
|
|
|
document.getElementById("share-title").value = aTitle || aURL;
|
|
|
|
|
|
|
|
BrowserUI.pushPopup(this, this._dialog);
|
|
|
|
|
|
|
|
let bbox = document.getElementById("share-buttons-box");
|
|
|
|
this._handlers.forEach(function(handler) {
|
|
|
|
let button = document.createElement("button");
|
2010-07-30 12:03:03 -07:00
|
|
|
button.className = "prompt-button";
|
2010-07-29 21:51:31 -07:00
|
|
|
button.setAttribute("label", handler.name);
|
|
|
|
button.addEventListener("command", function() {
|
|
|
|
SharingUI.hide();
|
2010-09-05 07:21:12 -07:00
|
|
|
handler.callback(aURL || "", aTitle || "");
|
2010-07-29 21:51:31 -07:00
|
|
|
}, false);
|
|
|
|
bbox.appendChild(button);
|
|
|
|
});
|
|
|
|
this._dialog.waitForClose();
|
2010-11-01 08:42:13 -07:00
|
|
|
BrowserUI.popPopup(this);
|
2010-07-29 21:51:31 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function hide() {
|
|
|
|
this._dialog.close();
|
|
|
|
this._dialog = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_handlers: [
|
|
|
|
{
|
|
|
|
name: "Email",
|
|
|
|
callback: function callback(aURL, aTitle) {
|
2010-09-05 07:21:12 -07:00
|
|
|
let url = "mailto:?subject=" + encodeURIComponent(aTitle) +
|
2010-07-29 21:51:31 -07:00
|
|
|
"&body=" + encodeURIComponent(aURL);
|
|
|
|
let uri = Services.io.newURI(url, null, null);
|
|
|
|
let extProtocolSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"]
|
|
|
|
.getService(Ci.nsIExternalProtocolService);
|
|
|
|
extProtocolSvc.loadUrl(uri);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Twitter",
|
|
|
|
callback: function callback(aURL, aTitle) {
|
|
|
|
let url = "http://twitter.com/home?status=" + encodeURIComponent((aTitle ? aTitle+": " : "")+aURL);
|
|
|
|
Browser.addTab(url, true, Browser.selectedTab);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Google Reader",
|
|
|
|
callback: function callback(aURL, aTitle) {
|
|
|
|
let url = "http://www.google.com/reader/link?url=" + encodeURIComponent(aURL) +
|
|
|
|
"&title=" + encodeURIComponent(aTitle);
|
|
|
|
Browser.addTab(url, true, Browser.selectedTab);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Facebook",
|
|
|
|
callback: function callback(aURL, aTitle) {
|
|
|
|
let url = "http://www.facebook.com/share.php?u=" + encodeURIComponent(aURL);
|
|
|
|
Browser.addTab(url, true, Browser.selectedTab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2010-09-09 10:45:40 -07:00
|
|
|
var BadgeHandlers = {
|
|
|
|
_handlers: [
|
|
|
|
{
|
|
|
|
_lastUpdate: 0,
|
2010-09-10 11:45:52 -07:00
|
|
|
_lastCount: 0,
|
2010-10-13 07:57:12 -07:00
|
|
|
url: "https://mail.google.com/mail",
|
2010-09-12 07:25:41 -07:00
|
|
|
updateBadge: function(aBadge) {
|
2010-09-09 10:45:40 -07:00
|
|
|
// Use the cache if possible
|
|
|
|
let now = Date.now();
|
|
|
|
if (this._lastCount && this._lastUpdate > now - 1000) {
|
2010-09-12 07:25:41 -07:00
|
|
|
aBadge.set(this._lastCount);
|
2010-09-09 10:45:40 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._lastUpdate = now;
|
|
|
|
|
|
|
|
// Use any saved username and password. If we don't have any login and we are not
|
|
|
|
// currently logged into Gmail, we won't get any count.
|
2010-09-10 11:45:52 -07:00
|
|
|
let login = BadgeHandlers.getLogin("https://www.google.com");
|
2010-09-09 10:45:40 -07:00
|
|
|
|
|
|
|
// Get the feed and read the count, passing any saved username and password
|
|
|
|
// but do not show any security dialogs if we fail
|
|
|
|
let req = new XMLHttpRequest();
|
|
|
|
req.mozBackgroundRequest = true;
|
2010-09-10 11:45:52 -07:00
|
|
|
req.open("GET", "https://mail.google.com/mail/feed/atom", true, login.username, login.password);
|
2010-09-09 10:45:40 -07:00
|
|
|
req.onreadystatechange = function(aEvent) {
|
|
|
|
if (req.readyState == 4) {
|
2010-10-15 05:40:29 -07:00
|
|
|
if (req.status == 200 && req.responseXML) {
|
2010-09-16 10:17:40 -07:00
|
|
|
let count = req.responseXML.getElementsByTagName("fullcount");
|
|
|
|
this._lastCount = count ? count[0].childNodes[0].nodeValue : 0;
|
2010-09-09 10:45:40 -07:00
|
|
|
} else {
|
2010-09-10 11:45:52 -07:00
|
|
|
this._lastCount = 0;
|
2010-09-09 10:45:40 -07:00
|
|
|
}
|
2010-09-12 07:25:41 -07:00
|
|
|
this._lastCount = BadgeHandlers.setNumberBadge(aBadge, this._lastCount);
|
2010-09-09 10:45:40 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
req.send(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
register: function(aPopup) {
|
|
|
|
let handlers = this._handlers;
|
|
|
|
for (let i = 0; i < handlers.length; i++)
|
|
|
|
aPopup.registerBadgeHandler(handlers[i].url, handlers[i]);
|
2010-09-10 11:45:52 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getLogin: function(aURL) {
|
|
|
|
let lm = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
|
|
|
let logins = lm.findLogins({}, aURL, aURL, null);
|
|
|
|
let username = logins.length > 0 ? logins[0].username : "";
|
|
|
|
let password = logins.length > 0 ? logins[0].password : "";
|
|
|
|
return { username: username, password: password };
|
|
|
|
},
|
|
|
|
|
|
|
|
clampBadge: function(aValue) {
|
|
|
|
if (aValue > 100)
|
|
|
|
aValue = "99+";
|
|
|
|
return aValue;
|
|
|
|
},
|
|
|
|
|
2010-09-12 07:25:41 -07:00
|
|
|
setNumberBadge: function(aBadge, aValue) {
|
2010-09-10 11:45:52 -07:00
|
|
|
if (parseInt(aValue) != 0) {
|
|
|
|
aValue = this.clampBadge(aValue);
|
2010-09-12 07:25:41 -07:00
|
|
|
aBadge.set(aValue);
|
2010-09-10 11:45:52 -07:00
|
|
|
} else {
|
2010-09-12 07:25:41 -07:00
|
|
|
aBadge.set("");
|
2010-09-10 11:45:52 -07:00
|
|
|
}
|
|
|
|
return aValue;
|
2010-09-09 10:45:40 -07:00
|
|
|
}
|
|
|
|
};
|
2010-10-16 06:25:15 -07:00
|
|
|
|
|
|
|
var FullScreenVideo = {
|
|
|
|
browser: null,
|
|
|
|
|
|
|
|
init: function fsv_init() {
|
|
|
|
messageManager.addMessageListener("Browser:FullScreenVideo:Start", this.show.bind(this));
|
|
|
|
messageManager.addMessageListener("Browser:FullScreenVideo:Close", this.hide.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function fsv_show() {
|
|
|
|
this.createBrowser();
|
|
|
|
window.fullScreen = true;
|
|
|
|
BrowserUI.pushPopup(this, this.browser);
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function fsv_hide() {
|
|
|
|
this.destroyBrowser();
|
|
|
|
window.fullScreen = false;
|
2010-11-01 08:42:13 -07:00
|
|
|
BrowserUI.popPopup(this);
|
2010-10-16 06:25:15 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
createBrowser: function fsv_createBrowser() {
|
|
|
|
let browser = this.browser = document.createElement("browser");
|
|
|
|
browser.className = "window-width window-height full-screen";
|
|
|
|
browser.setAttribute("type", "content");
|
|
|
|
browser.setAttribute("remote", "true");
|
|
|
|
browser.setAttribute("src", "chrome://browser/content/fullscreen-video.xhtml");
|
|
|
|
document.getElementById("main-window").appendChild(browser);
|
|
|
|
|
|
|
|
let mm = browser.messageManager;
|
|
|
|
mm.loadFrameScript("chrome://browser/content/fullscreen-video.js", true);
|
|
|
|
|
|
|
|
browser.addEventListener("TapDown", this, true);
|
|
|
|
browser.addEventListener("TapSingle", this, false);
|
|
|
|
|
|
|
|
return browser;
|
|
|
|
},
|
|
|
|
|
|
|
|
destroyBrowser: function fsv_destroyBrowser() {
|
|
|
|
let browser = this.browser;
|
|
|
|
browser.removeEventListener("TapDown", this, false);
|
|
|
|
browser.removeEventListener("TapSingle", this, false);
|
|
|
|
browser.parentNode.removeChild(browser);
|
|
|
|
this.browser = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function fsv_handleEvent(aEvent) {
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "TapDown":
|
|
|
|
this._dispatchMouseEvent("Browser:MouseDown", aEvent.clientX, aEvent.clientY);
|
|
|
|
break;
|
|
|
|
case "TapSingle":
|
|
|
|
this._dispatchMouseEvent("Browser:MouseUp", aEvent.clientX, aEvent.clientY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_dispatchMouseEvent: function fsv_dispatchMouseEvent(aName, aX, aY) {
|
|
|
|
let pos = this.browser.transformClientToBrowser(aX, aY);
|
|
|
|
this.browser.messageManager.sendAsyncMessage(aName, {
|
|
|
|
x: pos.x,
|
|
|
|
y: pos.y,
|
|
|
|
messageId: null
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|