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>
|
|
|
|
*
|
|
|
|
* 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");
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-04-22 13:45:51 -07:00
|
|
|
const TOOLBARSTATE_LOADING = 1;
|
|
|
|
const TOOLBARSTATE_LOADED = 2;
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2008-09-29 06:53:49 -07:00
|
|
|
[
|
2009-03-05 15:30:28 -08:00
|
|
|
[
|
|
|
|
"gHistSvc",
|
|
|
|
"@mozilla.org/browser/nav-history-service;1",
|
|
|
|
[Ci.nsINavHistoryService, Ci.nsIBrowserHistory]
|
|
|
|
],
|
2009-10-09 05:34:02 -07:00
|
|
|
[
|
|
|
|
"gFaviconService",
|
|
|
|
"@mozilla.org/browser/favicon-service;1",
|
|
|
|
[Ci.nsIFaviconService]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"gIOService",
|
|
|
|
"@mozilla.org/network/io-service;1",
|
|
|
|
[Ci.nsIIOService],
|
|
|
|
],
|
2009-03-05 15:30:28 -08:00
|
|
|
[
|
|
|
|
"gURIFixup",
|
|
|
|
"@mozilla.org/docshell/urifixup;1",
|
|
|
|
[Ci.nsIURIFixup]
|
2009-03-05 18:45:52 -08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
"gPrefService",
|
|
|
|
"@mozilla.org/preferences-service;1",
|
|
|
|
[Ci.nsIPrefBranch2]
|
2009-10-12 11:23:29 -07:00
|
|
|
],
|
|
|
|
[
|
|
|
|
"gFocusManager",
|
|
|
|
"@mozilla.org/focus-manager;1",
|
|
|
|
[Ci.nsIFocusManager]
|
2009-11-23 23:46:01 -08:00
|
|
|
],
|
2010-03-26 08:11:03 -07:00
|
|
|
[
|
|
|
|
"gWindowMediator",
|
|
|
|
"@mozilla.org/appshell/window-mediator;1",
|
|
|
|
[Ci.nsIWindowMediator]
|
|
|
|
],
|
2009-11-23 23:46:01 -08:00
|
|
|
[
|
|
|
|
"gObserverService",
|
|
|
|
"@mozilla.org/observer-service;1",
|
|
|
|
[Ci.nsIObserverService]
|
2009-03-05 15:30:28 -08:00
|
|
|
]
|
|
|
|
].forEach(function (service) {
|
|
|
|
let [name, contract, ifaces] = service;
|
2008-09-29 06:53:49 -07:00
|
|
|
window.__defineGetter__(name, function () {
|
|
|
|
delete window[name];
|
2009-03-05 15:30:28 -08:00
|
|
|
window[name] = Cc[contract].getService(ifaces.splice(0, 1)[0]);
|
|
|
|
if (ifaces.length)
|
2009-04-17 07:41:44 -07:00
|
|
|
ifaces.forEach(function (i) { return window[name].QueryInterface(i); });
|
2009-03-05 15:30:28 -08:00
|
|
|
return window[name];
|
2008-09-29 06:53:49 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2008-07-03 23:39:25 -07:00
|
|
|
var BrowserUI = {
|
2008-05-02 13:15:45 -07:00
|
|
|
_edit : 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-06-08 08:22:20 -07:00
|
|
|
|
|
|
|
return { };
|
2009-09-30 12:14:06 -07:00
|
|
|
},
|
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
_titleChanged : function(aBrowser) {
|
2009-01-08 22:51:13 -08:00
|
|
|
var 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-04-08 22:08:53 -07:00
|
|
|
var url = this.getDisplayURI(browser);
|
2010-06-08 08:22:20 -07:00
|
|
|
var 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
|
|
|
|
|
|
|
this._setURI(caption);
|
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-06-08 08:22:20 -07:00
|
|
|
|
|
|
|
return { };
|
2009-07-16 08:45:50 -07:00
|
|
|
},
|
|
|
|
|
2009-06-24 15:43:26 -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() {
|
2009-11-22 20:08:18 -08:00
|
|
|
let icons = document.getElementById("urlbar-icons");
|
2010-05-06 07:32:24 -07:00
|
|
|
let mode = icons.getAttribute("mode");
|
|
|
|
if (Browser.selectedTab.isLoading() && mode != "loading") {
|
2009-11-22 20:08:18 -08:00
|
|
|
icons.setAttribute("mode", "loading");
|
|
|
|
}
|
2010-05-06 07:32:24 -07:00
|
|
|
else if (mode != "view") {
|
2009-11-22 20:08:18 -08:00
|
|
|
icons.setAttribute("mode", "view");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-08-19 23:09:22 -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 08:00:28 -07:00
|
|
|
showToolbar : function showToolbar(aEdit) {
|
2009-04-22 13:45:51 -07:00
|
|
|
this.hidePanel();
|
2009-09-18 21:17:52 -07:00
|
|
|
this._editURI(aEdit);
|
2010-05-21 10:05:46 -07:00
|
|
|
if (aEdit)
|
|
|
|
this.showAutoComplete();
|
2008-08-19 12:19:47 -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 = "";
|
|
|
|
},
|
|
|
|
|
2009-09-18 21:17:52 -07:00
|
|
|
_setURI: function _setURI(aCaption) {
|
|
|
|
if (this.isAutoCompleteOpen())
|
|
|
|
this._edit.defaultValue = aCaption;
|
|
|
|
else
|
|
|
|
this._edit.value = aCaption;
|
|
|
|
},
|
|
|
|
|
|
|
|
_editURI : function _editURI(aEdit) {
|
2008-12-09 22:21:08 -08:00
|
|
|
var icons = document.getElementById("urlbar-icons");
|
2009-06-25 21:48:10 -07:00
|
|
|
if (aEdit && icons.getAttribute("mode") != "edit") {
|
2008-12-09 22:21:08 -08:00
|
|
|
icons.setAttribute("mode", "edit");
|
2009-06-25 21:23:01 -07:00
|
|
|
this._edit.defaultValue = this._edit.value;
|
2008-12-10 23:05:55 -08:00
|
|
|
|
2009-01-08 22:51:13 -08:00
|
|
|
let urlString = this.getDisplayURI(Browser.selectedBrowser);
|
2010-04-08 22:08:53 -07:00
|
|
|
if (Util.isURLEmpty(urlString))
|
2008-12-10 23:05:55 -08:00
|
|
|
urlString = "";
|
|
|
|
this._edit.value = urlString;
|
2009-09-30 12:19:42 -07:00
|
|
|
|
|
|
|
// This is a workaround for bug 488420, needed to cycle focus for the
|
|
|
|
// IME state to be set properly. Testing shows we only really need to
|
|
|
|
// do this the first time.
|
|
|
|
this._edit.blur();
|
2009-10-12 11:23:29 -07:00
|
|
|
gFocusManager.setFocus(this._edit, Ci.nsIFocusManager.FLAG_NOSCROLL);
|
2008-09-11 18:11:46 -07:00
|
|
|
}
|
2009-11-22 20:08:18 -08:00
|
|
|
else if (!aEdit) {
|
2010-04-29 22:28:40 -07:00
|
|
|
this._updateToolbar();
|
2008-09-11 18:11:46 -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.
|
|
|
|
let dialog = this.activeDialog;
|
2010-03-30 10:27:59 -07:00
|
|
|
if (dialog) {
|
2009-07-08 07:55:07 -07:00
|
|
|
dialog.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
|
|
|
},
|
|
|
|
|
|
|
|
get activeDialog() {
|
|
|
|
// Return the topmost dialog
|
|
|
|
if (this._dialogs.length)
|
|
|
|
return this._dialogs[this._dialogs.length - 1];
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
pushDialog : function pushDialog(aDialog) {
|
|
|
|
// 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
|
|
|
|
2009-07-08 07:55:07 -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] };
|
2009-12-04 12:03:56 -08:00
|
|
|
this._dispatchPopupChanged();
|
2009-08-14 10:30:50 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
popPopup: function popPopup() {
|
|
|
|
this._popup = null;
|
2009-12-04 12:03:56 -08:00
|
|
|
this._dispatchPopupChanged();
|
2009-08-14 10:30:50 -07:00
|
|
|
},
|
|
|
|
|
2009-12-04 12:03:56 -08:00
|
|
|
_dispatchPopupChanged: function _dispatchPopupChanged() {
|
|
|
|
let stack = document.getElementById("stack");
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("PopupChanged", true, false);
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2009-12-17 14:35:48 -08:00
|
|
|
switchPane : function switchPane(id) {
|
2009-11-03 10:32:44 -08:00
|
|
|
let button = document.getElementsByAttribute("linkedpanel", id)[0];
|
|
|
|
if (button)
|
|
|
|
button.checked = true;
|
2009-12-17 14:35:48 -08:00
|
|
|
|
2010-06-14 06:14:16 -07:00
|
|
|
this.blurFocusedElement();
|
|
|
|
|
2009-12-17 14:35:48 -08:00
|
|
|
let pane = document.getElementById(id);
|
|
|
|
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() {
|
|
|
|
if (!this._sidebarW) {
|
|
|
|
let sidebar = document.getElementById("browser-controls");
|
|
|
|
this._sidebarW = sidebar.boxObject.width;
|
|
|
|
}
|
|
|
|
return this._sidebarW;
|
|
|
|
},
|
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
|
|
|
|
2009-03-31 11:45:24 -07:00
|
|
|
sizeControls : function(windowW, windowH) {
|
2009-10-15 09:54:36 -07:00
|
|
|
// tabs
|
|
|
|
document.getElementById("tabs").resize();
|
|
|
|
|
2009-09-09 20:32:13 -07:00
|
|
|
// awesomebar
|
2009-01-13 14:04:36 -08:00
|
|
|
let popup = document.getElementById("popup_autocomplete");
|
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
|
|
|
|
2009-10-23 21:04:51 -07:00
|
|
|
// form helper
|
|
|
|
let formHelper = document.getElementById("form-helper-container");
|
|
|
|
formHelper.top = windowH - formHelper.getBoundingClientRect().height;
|
2008-08-19 12:19:47 -07:00
|
|
|
},
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
init : function() {
|
2008-07-03 23:39:25 -07:00
|
|
|
this._edit = document.getElementById("urlbar-edit");
|
|
|
|
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
|
|
|
|
2009-08-17 23:07:48 -07:00
|
|
|
document.getElementById("toolbar-main").ignoreDrag = true;
|
|
|
|
|
2009-08-25 21:49:26 -07:00
|
|
|
let tabs = document.getElementById("tabs");
|
|
|
|
tabs.addEventListener("TabSelect", this, true);
|
|
|
|
tabs.addEventListener("TabOpen", 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-21 13:16:37 -07:00
|
|
|
messageManager.addMessageListener("Browser:Highlight", this);
|
2010-06-29 11:15:07 -07:00
|
|
|
messageManager.addMessageListener("Browser:OpenURI", this);
|
|
|
|
messageManager.addMessageListener("Browser:ContextMenu", ContextHelper);
|
|
|
|
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);
|
|
|
|
|
2009-12-17 14:35:48 -08:00
|
|
|
// Push the panel initialization out of the startup path
|
2010-06-08 08:22:20 -07:00
|
|
|
// (Using a message because we have no good way to delay-init [Bug 535366])
|
|
|
|
messageManager.addMessageListener("DOMContentLoaded", function() {
|
2010-03-20 14:33:35 -07:00
|
|
|
// We only want to delay one time
|
2010-06-08 08:22:20 -07:00
|
|
|
messageManager.removeMessageListener("DOMContentLoaded", arguments.callee, true);
|
2010-06-21 13:16:37 -07:00
|
|
|
|
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-06-29 08:09:04 -07:00
|
|
|
|
|
|
|
// Init the sync system
|
|
|
|
WeaveGlue.init();
|
2010-06-08 08:22:20 -07:00
|
|
|
});
|
2010-06-21 13:36:56 -07:00
|
|
|
|
|
|
|
FormMessageReceiver.start();
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2009-05-26 18:46:44 -07:00
|
|
|
uninit : function() {
|
|
|
|
ExtensionsView.uninit();
|
2009-10-14 12:04:33 -07:00
|
|
|
ConsoleView.uninit();
|
2009-05-26 18:46:44 -07:00
|
|
|
},
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
update : function(aState) {
|
2009-06-18 22:14:04 -07:00
|
|
|
let icons = document.getElementById("urlbar-icons");
|
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:
|
2009-09-21 09:32:50 -07:00
|
|
|
if (icons.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:
|
2009-09-21 09:32:50 -07:00
|
|
|
if (icons.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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-10-09 05:34:02 -07:00
|
|
|
_updateIcon : function(aIconSrc) {
|
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-09-27 07:07:04 -07:00
|
|
|
getDisplayURI : function(browser) {
|
|
|
|
if (!this._URIFixup)
|
|
|
|
this._URIFixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup);
|
|
|
|
|
2010-03-31 06:39:05 -07:00
|
|
|
let uri = browser.currentURI;
|
2008-09-27 07:07:04 -07:00
|
|
|
try {
|
|
|
|
uri = this._URIFixup.createExposableURI(uri);
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
return uri.spec;
|
|
|
|
},
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
/* Set the location to the current content */
|
2009-09-18 21:17:52 -07:00
|
|
|
updateURI : function() {
|
2009-01-08 22:51:13 -08:00
|
|
|
var 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
|
|
|
|
2009-10-23 21:04:51 -07:00
|
|
|
// Close the forms assistant
|
|
|
|
FormHelper.close();
|
|
|
|
|
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
|
|
|
|
2008-09-27 07:07:04 -07:00
|
|
|
var 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
|
|
|
|
2009-09-18 21:17:52 -07:00
|
|
|
this._setURI(urlString);
|
2008-05-02 13:15:45 -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();
|
2009-11-30 22:04:55 -08:00
|
|
|
this.closeAutoComplete(true);
|
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-05-25 08:32:24 -07:00
|
|
|
let fixupFlags = Ci.nsIURIFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
|
|
|
|
let uri = gURIFixup.createFixupURI(aURI, fixupFlags);
|
2009-03-05 15:30:28 -08:00
|
|
|
|
2010-06-17 09:27:26 -07:00
|
|
|
// We need to keep about: pages opening in new "local" tabs. We also want to spawn
|
|
|
|
// new "remote" tabs if opening web pages from a "local" about: page.
|
|
|
|
let currentURI = getBrowser().currentURI;
|
|
|
|
let useLocal = (uri.schemeIs("about") && uri.spec != "about:blank");
|
|
|
|
let hasLocal = (currentURI.schemeIs("about") && currentURI.spec != "about:blank");
|
|
|
|
if (useLocal || hasLocal != useLocal) {
|
|
|
|
BrowserUI.newTab(uri.spec);
|
|
|
|
} else {
|
|
|
|
let loadFlags = Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
|
|
|
|
getBrowser().loadURIWithFlags(uri.spec, loadFlags, null, null);
|
|
|
|
}
|
2010-05-25 08:32:24 -07:00
|
|
|
|
|
|
|
gHistSvc.markPageAsTyped(uri);
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2009-12-03 06:04:57 -08:00
|
|
|
showAutoComplete : function showAutoComplete() {
|
2009-09-18 21:17:52 -07:00
|
|
|
if (this.isAutoCompleteOpen())
|
|
|
|
return;
|
2009-12-03 06:04:57 -08:00
|
|
|
|
2009-08-26 12:29:46 -07:00
|
|
|
BrowserSearch.updateSearchButtons();
|
2009-12-03 06:04:57 -08:00
|
|
|
|
2010-05-21 10:05:46 -07:00
|
|
|
this._hidePopup();
|
2008-12-09 10:38:31 -08:00
|
|
|
this._edit.showHistoryPopup();
|
2008-07-16 08:41:38 -07:00
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-11-30 22:04:55 -08:00
|
|
|
closeAutoComplete: function closeAutoComplete(aResetInput) {
|
2010-02-16 18:21:13 -08:00
|
|
|
if (!this.isAutoCompleteOpen())
|
|
|
|
return;
|
|
|
|
|
2009-11-30 22:04:55 -08:00
|
|
|
if (aResetInput)
|
|
|
|
this._edit.popup.close();
|
|
|
|
else
|
|
|
|
this._edit.popup.closePopup();
|
|
|
|
},
|
2008-07-16 08:41:38 -07:00
|
|
|
|
2009-09-18 21:17:52 -07:00
|
|
|
isAutoCompleteOpen: function isAutoCompleteOpen() {
|
|
|
|
return this._edit.popup.popupOpen;
|
|
|
|
},
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
doButtonSearch : function(button) {
|
2008-07-16 08:41:38 -07:00
|
|
|
if (!("engine" in button) || !button.engine)
|
|
|
|
return;
|
|
|
|
|
2009-09-18 21:17:52 -07:00
|
|
|
// We don't want the button to look pressed for now
|
|
|
|
button.parentNode.selectedItem = null;
|
2009-10-28 20:55:47 -07:00
|
|
|
|
|
|
|
// Give the new page lots of room
|
|
|
|
Browser.hideSidebars();
|
2009-11-30 22:04:55 -08:00
|
|
|
this.closeAutoComplete(false);
|
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-03-10 11:19:05 -08:00
|
|
|
let submission = button.engine.getSubmission(this._edit.value, null);
|
|
|
|
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
|
|
|
getBrowser().loadURIWithFlags(submission.uri.spec, flags, null, null, submission.postData);
|
2008-07-16 08:41:38 -07:00
|
|
|
},
|
|
|
|
|
2008-12-15 08:44:27 -08: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-06-15 14:56:13 -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
|
2009-09-18 21:17:52 -07:00
|
|
|
this.showToolbar(true);
|
|
|
|
}
|
2009-10-28 20:55:47 -07:00
|
|
|
else {
|
|
|
|
// Give the new page lots of room
|
|
|
|
Browser.hideSidebars();
|
2009-11-30 22:04:55 -08:00
|
|
|
this.closeAutoComplete(true);
|
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
|
|
|
},
|
|
|
|
|
2009-04-17 07:41:44 -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
|
|
|
},
|
|
|
|
|
2009-04-17 07:41:44 -07:00
|
|
|
selectTab : function selectTab(aTab) {
|
2009-01-08 22:51:13 -08:00
|
|
|
Browser.selectedTab = aTab;
|
2009-02-10 13:52:23 -08:00
|
|
|
},
|
|
|
|
|
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) {
|
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
|
|
|
|
2009-11-18 13:09:01 -08:00
|
|
|
#ifdef WINCE
|
|
|
|
updateDefaultBrowser: function updateDefaultBrowser(aSet) {
|
|
|
|
try {
|
|
|
|
let phone = Cc["@mozilla.org/phone/support;1"].getService(Ci.nsIPhoneSupport);
|
|
|
|
if (aSet)
|
|
|
|
phone.setDefaultBrowser();
|
|
|
|
else
|
|
|
|
phone.restoreDefaultBrowser();
|
|
|
|
} catch(e) { }
|
|
|
|
},
|
|
|
|
#endif
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2010-04-28 11:32:17 -07:00
|
|
|
handleEscape: function () {
|
|
|
|
// Check open dialogs
|
|
|
|
let dialog = this.activeDialog;
|
|
|
|
if (dialog) {
|
|
|
|
dialog.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check open popups
|
|
|
|
if (this._popup) {
|
|
|
|
this._hidePopup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check open modal elements
|
|
|
|
let modalElementsLength = document.getElementsByClassName("modal-block").length;
|
|
|
|
if (modalElementsLength > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check open panel
|
|
|
|
if (this.isPanelVisible()) {
|
|
|
|
this.hidePanel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-06-17 10:36:38 -07:00
|
|
|
if (browser.canGoBack) {
|
2010-06-15 14:56:13 -07:00
|
|
|
browser.goBack();
|
2010-06-17 10:36:38 -07:00
|
|
|
} else if (tab.owner) {
|
2010-06-15 14:56:13 -07:00
|
|
|
this.closeTab(tab);
|
2010-06-17 10:36:38 -07:00
|
|
|
}
|
|
|
|
#ifdef ANDROID
|
|
|
|
else if (Browser.tabs.length == 1) {
|
|
|
|
this.doCommand("cmd_quit");
|
|
|
|
} else {
|
|
|
|
this.closeTab(tab);
|
|
|
|
window.QueryInterface(Ci.nsIDOMChromeWindow).minimize();
|
|
|
|
}
|
|
|
|
#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
|
|
|
let [tabsVisibility,,,] = Browser.computeSidebarVisibility();
|
|
|
|
if (!(tabsVisibility == 1.0) && Browser.selectedTab.chromeTab != aEvent.target)
|
2009-08-25 21:49:26 -07:00
|
|
|
NewTabPopup.show(aEvent.target);
|
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
|
|
|
|
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-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)
|
|
|
|
this.handleEscape();
|
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":
|
|
|
|
this.doCommand("cmd_openLocation");
|
|
|
|
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":
|
|
|
|
this.doCommand("cmd_openLocation");
|
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-04-06 16:42:36 -07:00
|
|
|
let selectAll = gPrefService.getBoolPref("browser.urlbar.doubleClickSelectsAll");
|
|
|
|
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-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) {}
|
|
|
|
gObserverService.notifyObservers(download, "dl-done", null);
|
|
|
|
break;
|
2010-06-21 13:16:37 -07:00
|
|
|
|
|
|
|
case "Browser:Highlight":
|
|
|
|
let rects = [];
|
|
|
|
for (let i = 0; i < json.rects.length; i++) {
|
|
|
|
let rect = json.rects[i];
|
|
|
|
rects.push(new Rect(rect.left, rect.top, rect.width, rect.height));
|
|
|
|
}
|
|
|
|
TapHighlightHelper.show(rects);
|
|
|
|
break;
|
2010-06-29 11:15:07 -07:00
|
|
|
|
|
|
|
case "Browser:OpenURI":
|
|
|
|
Browser.addTab(json.uri, false, Browser.selectedTab);
|
2010-06-08 08:22:20 -07:00
|
|
|
}
|
2010-06-11 07:23:24 -07:00
|
|
|
|
|
|
|
return {};
|
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":
|
|
|
|
case "cmd_bookmarks":
|
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":
|
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) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
doCommand : function(cmd) {
|
|
|
|
var browser = getBrowser();
|
|
|
|
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":
|
2009-08-24 08:00:28 -07:00
|
|
|
this.showToolbar(true);
|
2008-11-12 18:40:57 -08:00
|
|
|
break;
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_star":
|
|
|
|
{
|
|
|
|
var bookmarkURI = browser.currentURI;
|
2010-06-08 08:22:20 -07:00
|
|
|
var bookmarkTitle = browser.contentTitle || bookmarkURI.spec;
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2009-08-17 14:05:06 -07:00
|
|
|
let autoClose = false;
|
|
|
|
|
2008-10-01 12:54:16 -07:00
|
|
|
if (PlacesUtils.getMostRecentBookmarkForURI(bookmarkURI) == -1) {
|
2009-11-19 11:40:54 -08:00
|
|
|
let bmsvc = PlacesUtils.bookmarks;
|
|
|
|
let bookmarkId = bmsvc.insertBookmark(BookmarkList.mobileRoot, bookmarkURI,
|
|
|
|
bmsvc.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;
|
|
|
|
}
|
|
|
|
case "cmd_bookmarks":
|
2009-10-14 15:43:20 -07:00
|
|
|
BookmarkList.show();
|
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;
|
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":
|
|
|
|
{
|
|
|
|
let locked = gPrefService.getBoolPref("toolkit.screen.lock");
|
|
|
|
gPrefService.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) {
|
|
|
|
let bv = Browser._browserView;
|
|
|
|
let union = aRects.reduce(function(a, b) {
|
|
|
|
return a.expandToContain(b);
|
|
|
|
}, new Rect(0, 0, 0, 0)).map(bv.browserToViewport);
|
|
|
|
|
|
|
|
let vis = Browser.getVisibleRect();
|
|
|
|
let canvasArea = vis.intersect(union);
|
|
|
|
|
|
|
|
let overlay = this._overlay;
|
|
|
|
overlay.width = canvasArea.width;
|
|
|
|
overlay.style.width = canvasArea.width + "px";
|
|
|
|
overlay.height = canvasArea.height;
|
|
|
|
overlay.style.height = canvasArea.height + "px";
|
|
|
|
|
|
|
|
let ctx = overlay.getContext("2d");
|
|
|
|
ctx.save();
|
|
|
|
ctx.translate(-canvasArea.left, -canvasArea.top);
|
|
|
|
bv.browserToViewportCanvasContext(ctx);
|
|
|
|
|
|
|
|
overlay.style.left = canvasArea.left + "px";
|
|
|
|
overlay.style.top = canvasArea.top + "px";
|
|
|
|
ctx.fillStyle = "rgba(0, 145, 255, .5)";
|
|
|
|
for (let i = aRects.length - 1; i >= 0; i--) {
|
|
|
|
let rect = aRects[i];
|
|
|
|
ctx.fillRect(rect.left, rect.top, rect.width, rect.height);
|
|
|
|
}
|
|
|
|
ctx.restore();
|
|
|
|
overlay.style.display = "block";
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function hide() {
|
|
|
|
this._overlay.style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-24 12:55:09 -07:00
|
|
|
var PageActions = {
|
|
|
|
get _permissionManager() {
|
|
|
|
delete this._permissionManager;
|
|
|
|
return this._permissionManager = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {
|
|
|
|
let pm = this._permissionManager;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
updatePagePermissions: function updatePagePermissions() {
|
2010-03-29 13:41:03 -07:00
|
|
|
this.removeItems("preferences");
|
|
|
|
|
2010-03-24 12:55:09 -07:00
|
|
|
let host = Browser.selectedBrowser.currentURI;
|
|
|
|
let permissions = [];
|
|
|
|
|
|
|
|
this._forEachPermissions(host, function(aType) {
|
|
|
|
permissions.push(aType);
|
|
|
|
});
|
|
|
|
|
|
|
|
let lm = this._loginManager;
|
|
|
|
if (!lm.getLoginSavingEnabled(host.prePath)) {
|
|
|
|
permissions.push("password");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show the clear site preferences button if needed
|
|
|
|
if (permissions.length) {
|
|
|
|
let title = Elements.browserBundle.getString("pageactions.reset");
|
|
|
|
let description = [];
|
|
|
|
for each(permission in permissions)
|
|
|
|
description.push(Elements.browserBundle.getString("pageactions." + permission));
|
|
|
|
|
2010-03-29 13:41:03 -07:00
|
|
|
let node = this.appendItem("preferences", title, description.join(", "));
|
2010-04-06 08:10:18 -07:00
|
|
|
node.addEventListener("click", function(event) {
|
|
|
|
PageActions.clearPagePermissions();
|
|
|
|
PageActions.removeItem(node);
|
|
|
|
},
|
|
|
|
false);
|
2010-03-24 12:55:09 -07:00
|
|
|
}
|
|
|
|
|
2010-04-06 08:10:18 -07:00
|
|
|
let siteLogins = [];
|
2010-04-14 14:14:50 -07:00
|
|
|
let allLogins = lm.findLogins({}, host.prePath, "", null);
|
2010-04-06 08:10:18 -07:00
|
|
|
for (let i = 0; i < allLogins.length; i++) {
|
|
|
|
let login = allLogins[i];
|
2010-03-24 12:55:09 -07:00
|
|
|
if (login.hostname != host.prePath)
|
|
|
|
continue;
|
|
|
|
|
2010-04-06 08:10:18 -07:00
|
|
|
siteLogins.push(login);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show only 1 password button for all the saved logins
|
|
|
|
if (siteLogins.length) {
|
2010-03-24 12:55:09 -07:00
|
|
|
let title = Elements.browserBundle.getString("pageactions.password.forget");
|
2010-03-29 13:41:03 -07:00
|
|
|
let node = this.appendItem("preferences", title, "");
|
2010-04-06 08:10:18 -07:00
|
|
|
node.addEventListener("click", function(event) {
|
|
|
|
for (let i = 0; i < siteLogins.length; i++)
|
|
|
|
lm.removeLogin(siteLogins[i]);
|
|
|
|
|
|
|
|
PageActions.removeItem(node);
|
|
|
|
},
|
|
|
|
false);
|
2010-03-24 12:55:09 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clearPagePermissions: function clearPagePermissions() {
|
|
|
|
let pm = this._permissionManager;
|
|
|
|
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-03-26 12:06:58 -07:00
|
|
|
_savePageAsPDF: function saveAsPDF() {
|
|
|
|
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";
|
2010-05-06 20:10:56 -07:00
|
|
|
|
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-06-22 13:20:56 -07:00
|
|
|
fileName = fileName.trim();
|
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
|
|
|
|
picker.defaultString = fileName + ".pdf";
|
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);
|
|
|
|
picker.displayDirectory = dm.defaultDownloadsDirectory;
|
2010-03-26 12:06:58 -07:00
|
|
|
let rv = picker.show();
|
|
|
|
if (rv == Ci.nsIFilePicker.returnCancel)
|
|
|
|
return;
|
|
|
|
|
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)"
|
|
|
|
);
|
|
|
|
|
|
|
|
let current = Browser.selectedBrowser.currentURI.spec;
|
|
|
|
stmt.params.name = picker.file.leafName;
|
|
|
|
stmt.params.source = current;
|
|
|
|
stmt.params.target = gIOService.newFileURI(picker.file).spec;
|
|
|
|
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) {}
|
|
|
|
gObserverService.notifyObservers(download, "dl-start", null);
|
|
|
|
|
2010-06-09 19:12:05 -07:00
|
|
|
let data = {
|
|
|
|
type: Ci.nsIPrintSettings.kOutputFormatPDF,
|
|
|
|
id: newItemId,
|
|
|
|
referrer: current,
|
|
|
|
filePath: picker.file.path
|
|
|
|
};
|
|
|
|
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("Browser:SaveAs", data);
|
2010-03-26 12:06:58 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
updatePageSaveAs: function updatePageSaveAs() {
|
2010-03-29 13:41:03 -07:00
|
|
|
this.removeItems("saveas");
|
2010-06-25 08:28:42 -07:00
|
|
|
|
|
|
|
// Check for local XUL content
|
|
|
|
let contentDocument = Browser.selectedBrowser.contentDocument;
|
|
|
|
if (contentDocument && contentDocument instanceof XULDocument)
|
|
|
|
return;
|
2010-03-26 12:06:58 -07:00
|
|
|
|
|
|
|
let strings = Elements.browserBundle;
|
2010-03-29 13:41:03 -07:00
|
|
|
let node = this.appendItem("saveas", strings.getString("pageactions.saveas.pdf"), "");
|
2010-03-26 12:06:58 -07:00
|
|
|
node.onclick = function(event) {
|
|
|
|
PageActions._savePageAsPDF();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-03-29 13:41:03 -07:00
|
|
|
appendItem: function appendItem(aType, aTitle, aDesc) {
|
2010-03-24 12:55:09 -07:00
|
|
|
let container = document.getElementById("pageactions-container");
|
|
|
|
let item = document.createElement("pageaction");
|
|
|
|
item.setAttribute("title", aTitle);
|
|
|
|
item.setAttribute("description", aDesc);
|
2010-03-29 13:41:03 -07:00
|
|
|
item.setAttribute("type", aType);
|
2010-03-24 12:55:09 -07:00
|
|
|
container.appendChild(item);
|
|
|
|
|
2010-03-29 13:41:03 -07:00
|
|
|
let identityContainer = document.getElementById("identity-container");
|
|
|
|
identityContainer.setAttribute("hasmenu", "true");
|
2010-03-24 12:55:09 -07:00
|
|
|
return item;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeItem: function removeItem(aItem) {
|
|
|
|
let container = document.getElementById("pageactions-container");
|
|
|
|
container.removeChild(aItem);
|
|
|
|
|
2010-03-29 13:41:03 -07:00
|
|
|
let identityContainer = document.getElementById("identity-container");
|
|
|
|
identityContainer.setAttribute("hasmenu", container.hasChildNodes() ? "true" : "false");
|
2010-03-24 12:55:09 -07:00
|
|
|
},
|
|
|
|
|
2010-03-29 13:41:03 -07:00
|
|
|
removeItems: function removeItems(aType) {
|
2010-03-24 12:55:09 -07:00
|
|
|
let container = document.getElementById("pageactions-container");
|
2010-03-29 13:41:03 -07:00
|
|
|
let count = container.childNodes.length;
|
|
|
|
for (let i = count - 1; i >= 0; i--) {
|
|
|
|
if (aType == "" || container.childNodes[i].getAttribute("type") == aType)
|
|
|
|
this.removeItem(container.childNodes[i]);
|
|
|
|
}
|
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;
|
|
|
|
return this.box = document.getElementById("newtab-popup");
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateLabel: function() {
|
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);
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
if (this._timeout) {
|
|
|
|
clearTimeout(this._timeout);
|
|
|
|
this._timeout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._tabs = [];
|
|
|
|
this.box.hidden = true;
|
2009-10-12 11:35:01 -07:00
|
|
|
BrowserUI.popPopup();
|
2009-08-25 21:49:26 -07:00
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-08-25 21:49:26 -07:00
|
|
|
show: function(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);
|
|
|
|
},
|
|
|
|
|
|
|
|
selectTab: function() {
|
|
|
|
BrowserUI.selectTab(this._tabs.pop());
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-17 14:05:06 -07:00
|
|
|
var BookmarkPopup = {
|
|
|
|
get box() {
|
|
|
|
delete this.box;
|
|
|
|
return this.box = document.getElementById("bookmark-popup");
|
|
|
|
},
|
|
|
|
|
|
|
|
_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;
|
2009-10-12 11:35:01 -07:00
|
|
|
BrowserUI.popPopup();
|
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) {
|
|
|
|
const margin = 10;
|
|
|
|
|
2009-08-17 14:05:06 -07:00
|
|
|
this.box.hidden = false;
|
|
|
|
|
2009-12-01 09:27:17 -08:00
|
|
|
let [,,,controlsW] = Browser.computeSidebarVisibility();
|
|
|
|
this.box.left = window.innerWidth - (this.box.getBoundingClientRect().width + controlsW + margin);
|
|
|
|
this.box.top = BrowserUI.starButton.getBoundingClientRect().top + margin;
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
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() {
|
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;
|
2009-10-28 23:12:10 -07:00
|
|
|
BrowserUI.popPopup();
|
2008-07-14 14:11:15 -07:00
|
|
|
},
|
2008-05-02 13:15:45 -07:00
|
|
|
};
|
2009-02-24 22:20:45 -08:00
|
|
|
|
|
|
|
var BookmarkList = {
|
|
|
|
_panel: null,
|
|
|
|
_bookmarks: null,
|
2009-10-20 20:32:36 -07:00
|
|
|
_manageButtton: null,
|
2009-02-24 22:20:45 -08:00
|
|
|
|
2009-11-19 11:40:54 -08:00
|
|
|
get mobileRoot() {
|
|
|
|
let items = PlacesUtils.annotations.getItemsWithAnnotation("mobile/bookmarksRoot", {});
|
|
|
|
if (!items.length)
|
|
|
|
throw "Couldn't find mobile bookmarks root!";
|
|
|
|
|
|
|
|
delete this.mobileRoot;
|
|
|
|
return this.mobileRoot = items[0];
|
|
|
|
},
|
|
|
|
|
2009-02-24 22:20:45 -08:00
|
|
|
show: function() {
|
|
|
|
this._panel = document.getElementById("bookmarklist-container");
|
2009-07-02 09:19:03 -07:00
|
|
|
this._panel.width = window.innerWidth;
|
|
|
|
this._panel.height = window.innerHeight;
|
2009-04-08 22:40:05 -07:00
|
|
|
this._panel.hidden = false;
|
2009-07-08 07:55:07 -07:00
|
|
|
BrowserUI.pushDialog(this);
|
2009-02-24 22:20:45 -08:00
|
|
|
|
|
|
|
this._bookmarks = document.getElementById("bookmark-items");
|
2009-10-20 20:32:36 -07:00
|
|
|
this._bookmarks.addEventListener("BookmarkRemove", this, true);
|
2009-02-24 22:20:45 -08:00
|
|
|
this._bookmarks.manageUI = false;
|
|
|
|
this._bookmarks.openFolder();
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-10-20 20:32:36 -07:00
|
|
|
this._manageButton = document.getElementById("tool-bookmarks-manage");
|
|
|
|
this._manageButton.disabled = (this._bookmarks.items.length == 0);
|
2009-02-24 22:20:45 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
close: function() {
|
|
|
|
BrowserUI.updateStar();
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-10-20 20:32:36 -07:00
|
|
|
if (this._bookmarks.manageUI)
|
|
|
|
this.toggleManage();
|
2009-02-24 22:20:45 -08:00
|
|
|
this._bookmarks.blur();
|
2009-10-20 20:32:36 -07:00
|
|
|
this._bookmarks.removeEventListener("BookmarkRemove", this, true);
|
|
|
|
|
2009-02-24 22:20:45 -08:00
|
|
|
this._panel.hidden = true;
|
2009-07-08 07:55:07 -07:00
|
|
|
BrowserUI.popDialog();
|
2009-02-24 22:20:45 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleManage: function() {
|
|
|
|
this._bookmarks.manageUI = !(this._bookmarks.manageUI);
|
2009-10-20 20:32:36 -07:00
|
|
|
this._manageButton.checked = this._bookmarks.manageUI;
|
2009-02-24 22:20:45 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
openBookmark: function() {
|
|
|
|
let item = this._bookmarks.activeItem;
|
2009-02-24 22:20:45 -08:00
|
|
|
if (item.spec) {
|
2009-08-17 10:56:51 -07:00
|
|
|
this.close();
|
2009-04-17 07:41:44 -07:00
|
|
|
BrowserUI.goToURI(item.spec);
|
2009-02-24 22:20:45 -08:00
|
|
|
}
|
2009-10-20 20:32:36 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
|
|
|
if (aEvent.type == "BookmarkRemove") {
|
|
|
|
if (this._bookmarks.isRootFolder && this._bookmarks.items.length == 1) {
|
|
|
|
this._manageButton.disabled = true;
|
|
|
|
this.toggleManage();
|
|
|
|
}
|
|
|
|
}
|
2009-02-24 22:20:45 -08:00
|
|
|
}
|
|
|
|
};
|
2009-06-24 09:42:53 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
/**
|
|
|
|
* Responsible for handling the interface for navigating forms and filling in information.
|
|
|
|
* - Navigating forms is handled by next and previous buttons.
|
|
|
|
* - When an element is focused, the browser view zooms in to the control.
|
|
|
|
* - Provides autocomplete box for input fields.
|
|
|
|
*/
|
2009-10-23 21:04:51 -07:00
|
|
|
var FormHelper = {
|
2010-03-01 13:10:31 -08:00
|
|
|
_open: false,
|
2010-06-21 13:36:56 -07:00
|
|
|
_navigator: null,
|
|
|
|
|
2009-10-23 21:04:51 -07:00
|
|
|
get _container() {
|
|
|
|
delete this._container;
|
|
|
|
return this._container = document.getElementById("form-helper-container");
|
|
|
|
},
|
|
|
|
|
|
|
|
get _helperSpacer() {
|
|
|
|
delete this._helperSpacer;
|
|
|
|
return this._helperSpacer = document.getElementById("form-helper-spacer");
|
|
|
|
},
|
|
|
|
|
2010-03-09 19:42:04 -08:00
|
|
|
get _autofillContainer() {
|
|
|
|
delete this._autofillContainer;
|
|
|
|
return this._autofillContainer = document.getElementById("form-helper-autofill");
|
|
|
|
},
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
doAutoFill: function formHelperDoAutoFill(aElement) {
|
|
|
|
// Suggestions are only in <label>s. Ignore the rest.
|
|
|
|
if (aElement instanceof Ci.nsIDOMXULLabelElement)
|
|
|
|
this._navigator.getCurrent().autocomplete(aElement.value);
|
2009-11-11 21:15:56 -08:00
|
|
|
},
|
2009-10-29 10:09:22 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
goToPrevious: function formHelperGoToPrevious() {
|
|
|
|
this._navigator.goToPrevious();
|
2010-06-04 01:58:33 -07:00
|
|
|
},
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
goToNext: function formHelperGoToNext() {
|
|
|
|
this._navigator.goToNext();
|
2009-10-23 21:04:51 -07:00
|
|
|
},
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
updateAutocompleteFor: function updateAutocompleteFor(aElement) {
|
|
|
|
let suggestions = this.getAutocompleteSuggestions(aElement);
|
|
|
|
this._setSuggestions(suggestions);
|
|
|
|
|
|
|
|
if (suggestions.length == 0) {
|
|
|
|
let height = Math.floor(this._container.getBoundingClientRect().height);
|
|
|
|
this._container.top = window.innerHeight - height;
|
|
|
|
let containerHeight = this._container.getBoundingClientRect().height;
|
|
|
|
this._helperSpacer.setAttribute("height", containerHeight);
|
2010-04-22 06:08:07 -07:00
|
|
|
}
|
2009-10-23 21:04:51 -07:00
|
|
|
},
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
getAutocompleteSuggestions: function(aElement) {
|
2010-03-09 19:42:04 -08:00
|
|
|
let suggestions = [];
|
2010-06-21 13:36:56 -07:00
|
|
|
let autocompleteService = Cc["@mozilla.org/satchel/form-autocomplete;1"].getService(Ci.nsIFormAutoComplete);
|
|
|
|
let results = autocompleteService.autoCompleteSearch(aElement.name, aElement.value, aElement, null);
|
2010-03-09 19:42:04 -08:00
|
|
|
if (results.matchCount > 0) {
|
|
|
|
for (let i = 0; i < results.matchCount; i++) {
|
|
|
|
let value = results.getValueAt(i);
|
|
|
|
suggestions.push(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return suggestions;
|
|
|
|
},
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
/**
|
|
|
|
* Shows form helper. If helper is already shown, then it selects the new element.
|
|
|
|
*/
|
|
|
|
open: function formHelperOpen(navigator) {
|
2009-12-11 11:27:23 -08:00
|
|
|
let bv = Browser._browserView;
|
2009-10-23 21:04:51 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
if (!this._open) {
|
|
|
|
this._open = true;
|
|
|
|
bv.ignorePageScroll(true);
|
|
|
|
this._container.hidden = false;
|
|
|
|
this._helperSpacer.hidden = false;
|
|
|
|
}
|
2009-10-23 21:04:51 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
let lastWrapper = this._navigator ? this._navigator.getCurrent() : null;
|
|
|
|
this._navigator = navigator;
|
|
|
|
this._currentElementChange(lastWrapper, navigator.getCurrent());
|
2010-03-30 10:56:06 -07:00
|
|
|
|
|
|
|
let evt = document.createEvent("UIEvents");
|
|
|
|
evt.initUIEvent("FormUI", true, true, window, this._open);
|
|
|
|
this._container.dispatchEvent(evt);
|
2009-10-23 21:04:51 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
close: function formHelperHide() {
|
|
|
|
if (!this._open)
|
|
|
|
return;
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
this._updateContainerForSelect(this._navigator.getCurrent(), null);
|
2009-10-23 21:04:51 -07:00
|
|
|
|
|
|
|
this._helperSpacer.hidden = true;
|
2010-03-09 19:42:04 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
this._zoomFinish();
|
|
|
|
|
2009-10-23 21:04:51 -07:00
|
|
|
// give the form spacer area back to the content
|
|
|
|
let bv = Browser._browserView;
|
2010-01-14 13:35:08 -08:00
|
|
|
Browser.forceChromeReflow();
|
2009-10-23 21:04:51 -07:00
|
|
|
Browser.contentScrollboxScroller.scrollBy(0, 0);
|
|
|
|
bv.onAfterVisibleMove();
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-12-11 11:27:23 -08:00
|
|
|
bv.ignorePageScroll(false);
|
2009-10-23 21:04:51 -07:00
|
|
|
|
|
|
|
this._container.hidden = true;
|
|
|
|
this._open = false;
|
2010-03-30 10:56:06 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
if (this._navigator) {
|
|
|
|
this._navigator.endSession();
|
|
|
|
this._navigator = null;
|
|
|
|
}
|
|
|
|
|
2010-03-30 10:56:06 -07:00
|
|
|
let evt = document.createEvent("UIEvents");
|
|
|
|
evt.initUIEvent("FormUI", true, true, window, this._open);
|
|
|
|
this._container.dispatchEvent(evt);
|
2009-10-23 21:04:51 -07:00
|
|
|
},
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
/** The currently selected element has changed. */
|
|
|
|
_currentElementChange: function(lastWrapper, currentWrapper) {
|
|
|
|
this._updateContainer(lastWrapper, currentWrapper);
|
|
|
|
this._zoom(currentWrapper.getRect());
|
|
|
|
},
|
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. */
|
|
|
|
_updateContainer: function(aLastWrapper, aCurrentWrapper) {
|
|
|
|
this._updateContainerForSelect(aLastWrapper, aCurrentWrapper);
|
2009-11-25 12:51:03 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
// Setup autofill UI
|
|
|
|
this.updateAutocompleteFor(this._navigator.getCurrent().element);
|
2009-11-25 12:51:03 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
let height = Math.floor(this._container.getBoundingClientRect().height);
|
|
|
|
this._container.top = window.innerHeight - height;
|
2010-03-09 19:42:04 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
let navigator = this._navigator;
|
|
|
|
document.getElementById("form-helper-previous").disabled = !navigator.hasPrevious();
|
|
|
|
document.getElementById("form-helper-next").disabled = !navigator.hasNext();
|
2010-03-09 19:42:04 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
let containerHeight = this._container.getBoundingClientRect().height;
|
|
|
|
this._helperSpacer.setAttribute("height", containerHeight);
|
|
|
|
},
|
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. */
|
|
|
|
_updateContainerForSelect: function(aLastWrapper, aCurrentWrapper) {
|
|
|
|
let lastHasChoices = aLastWrapper && aLastWrapper.hasChoices();
|
|
|
|
let currentHasChoices = aCurrentWrapper && aCurrentWrapper.hasChoices();
|
2010-04-14 08:22:23 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
if (!lastHasChoices && currentHasChoices) {
|
|
|
|
SelectHelper.dock(this._container);
|
|
|
|
SelectHelper.show(aCurrentWrapper);
|
|
|
|
}
|
|
|
|
else if (lastHasChoices && currentHasChoices) {
|
|
|
|
SelectHelper.reset();
|
|
|
|
SelectHelper.show(aCurrentWrapper);
|
|
|
|
}
|
|
|
|
else if (lastHasChoices && !currentHasChoices) {
|
|
|
|
SelectHelper.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. */
|
|
|
|
_zoom: function formHelperZoom(elRect) {
|
2010-04-29 12:29:01 -07:00
|
|
|
let bv = Browser._browserView;
|
|
|
|
if (!bv.allowZoom)
|
|
|
|
return;
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
let zoomLevel = Browser._getZoomLevelForRect(bv.browserToViewportRect(elRect.clone()));
|
2010-03-30 10:56:06 -07:00
|
|
|
if (gPrefService.getBoolPref("formhelper.autozoom")) {
|
2010-06-21 13:36:56 -07:00
|
|
|
this._restore = {
|
|
|
|
zoom: bv.getZoomLevel(),
|
|
|
|
contentScrollOffset: Browser.getScrollboxPosition(Browser.contentScrollboxScroller),
|
|
|
|
pageScrollOffset: Browser.getScrollboxPosition(Browser.pageScrollboxScroller)
|
|
|
|
};
|
|
|
|
|
2010-03-30 10:56:06 -07:00
|
|
|
zoomLevel = Math.min(Math.max(kBrowserFormZoomLevelMin, zoomLevel), kBrowserFormZoomLevelMax);
|
2010-06-21 13:36:56 -07:00
|
|
|
let zoomRect = Browser._getZoomRectForPoint(elRect.center().x, elRect.y, zoomLevel);
|
|
|
|
|
|
|
|
let caretRect = Rect.fromRect(this._navigator.getCurrent().element.caretRect);
|
|
|
|
if (caretRect) {
|
|
|
|
caretRect = Browser._browserView.browserToViewportRect(caretRect);
|
|
|
|
if (!zoomRect.contains(caretRect)) {
|
|
|
|
let [deltaX, deltaY] = this._getOffsetForCaret(caretRect, zoomRect);
|
|
|
|
zoomRect.translate(deltaX, deltaY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-25 14:16:01 -07:00
|
|
|
Browser.animatedZoomTo(zoomRect);
|
2010-03-30 10:56:06 -07:00
|
|
|
}
|
2010-06-21 13:36:56 -07:00
|
|
|
},
|
2009-10-23 21:04:51 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
/** Element is no longer selected. Restore zoom level if setting is enabled. */
|
|
|
|
_zoomFinish: function _zoomFinish() {
|
|
|
|
let restore = this._restore;
|
|
|
|
if (restore && gPrefService.getBoolPref("formhelper.restore")) {
|
|
|
|
bv.setZoomLevel(restore.zoom);
|
|
|
|
Browser.contentScrollboxScroller.scrollTo(restore.contentScrollOffset.x,
|
|
|
|
restore.contentScrollOffset.y);
|
|
|
|
Browser.pageScrollboxScroller.scrollTo(restore.pageScrollOffset.x,
|
|
|
|
restore.pageScrollOffset.y);
|
|
|
|
}
|
|
|
|
},
|
2010-05-20 06:46:22 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
/** Populate autofill container with list of strings for suggestions */
|
|
|
|
_setSuggestions: function(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);
|
|
|
|
fragment.appendChild(button);
|
2010-04-14 08:22:23 -07:00
|
|
|
}
|
2010-06-21 13:36:56 -07:00
|
|
|
autofill.appendChild(fragment);
|
|
|
|
autofill.collapsed = !aSuggestions.length;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-10-23 21:04:51 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
var FormMessageReceiver = {
|
|
|
|
start: function() {
|
|
|
|
messageManager.addMessageListener("FormAssist:Show", this);
|
|
|
|
messageManager.addMessageListener("FormAssist:Hide", this);
|
|
|
|
messageManager.addMessageListener("FormAssist:Update", this);
|
|
|
|
messageManager.addMessageListener("FormAssist:AutoComplete", this);
|
2009-11-27 21:37:01 -08:00
|
|
|
},
|
2010-06-21 13:36:56 -07:00
|
|
|
|
|
|
|
receiveMessage: function(aMessage) {
|
|
|
|
let json = aMessage.json;
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "FormAssist:Update":
|
|
|
|
let bv = Browser._browserView;
|
|
|
|
let visible = bv.getVisibleRect();
|
|
|
|
let caretRect = bv.browserToViewportRect(Rect.fromRect(json.caretRect));
|
|
|
|
let [deltaX, deltaY] = this._getOffsetForCaret(caretRect, visible);
|
|
|
|
|
|
|
|
if (deltaX != 0 || deltaY != 0) {
|
|
|
|
Browser.contentScrollboxScroller.scrollBy(deltaX, deltaY);
|
|
|
|
bv.onAfterVisibleMove();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "FormAssist:Show":
|
|
|
|
json.showNavigation ? FormHelper.open(new FormNavigator(json))
|
|
|
|
: SelectHelper.show(new FormWrapper(json.current));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "FormAssist:AutoComplete":
|
|
|
|
let current = json.current;
|
|
|
|
if (current.canAutocomplete) {
|
|
|
|
FormHelper.updateAutocompleteFor(current);
|
|
|
|
}
|
|
|
|
break;
|
2010-04-14 08:22:23 -07:00
|
|
|
}
|
|
|
|
},
|
2010-06-04 01:58:33 -07:00
|
|
|
|
2010-04-14 08:22:23 -07:00
|
|
|
_getOffsetForCaret: function formHelper_getOffsetForCaret(aCaretRect, aRect) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function FormNavigator(navObject) {
|
|
|
|
this._navObject = navObject;
|
|
|
|
this._current = new FormWrapper(navObject.current);
|
|
|
|
}
|
|
|
|
|
|
|
|
FormNavigator.prototype = {
|
|
|
|
hasPrevious: function() {
|
|
|
|
return this._navObject.hasPrevious;
|
2010-04-14 08:22:23 -07:00
|
|
|
},
|
2009-11-27 21:37:01 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
hasNext: function() {
|
|
|
|
return this._navObject.hasNext;
|
|
|
|
},
|
2010-01-13 11:56:32 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
getCurrent: function() {
|
|
|
|
return this._current;
|
|
|
|
},
|
2009-12-09 00:15:39 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
endSession: function endSession() {
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:Close", { });
|
|
|
|
},
|
|
|
|
|
|
|
|
goToPrevious: function goToPrevious() {
|
|
|
|
try {
|
|
|
|
let fl = getBrowser().QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
|
|
|
|
fl.activateRemoteFrame();
|
|
|
|
}
|
|
|
|
catch(e) {}
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:Previous", { });
|
|
|
|
},
|
2010-03-01 13:10:31 -08:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
goToNext: function goToNext() {
|
|
|
|
try {
|
|
|
|
let fl = getBrowser().QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
|
|
|
|
fl.activateRemoteFrame();
|
|
|
|
}
|
|
|
|
catch(e) {}
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:Next", { });
|
2009-10-23 21:04:51 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
function FormWrapper(aElementObject) {
|
|
|
|
this.element = aElementObject;
|
|
|
|
this._rect = Rect.fromRect(aElementObject.rect);
|
2009-09-17 13:17:57 -07:00
|
|
|
}
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
FormWrapper.prototype = {
|
|
|
|
hasChoices: function() {
|
|
|
|
return this.element.choiceData != null;
|
|
|
|
},
|
2009-09-17 13:17:57 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
choiceSelect: function(aIndex, aSelected, aClearAll) {
|
|
|
|
let json = {
|
|
|
|
index: aIndex,
|
|
|
|
selected: aSelected,
|
|
|
|
clearAll: aClearAll
|
|
|
|
};
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:ChoiceSelect", json);
|
|
|
|
},
|
|
|
|
|
|
|
|
choiceChange: function() {
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:ChoiceChange", { });
|
|
|
|
},
|
|
|
|
|
|
|
|
getChoiceData: function() {
|
|
|
|
return this.element.choiceData;
|
|
|
|
},
|
|
|
|
|
|
|
|
canAutocomplete: function() {
|
|
|
|
return this.element.canAutocomplete;
|
|
|
|
},
|
2009-09-17 13:17:57 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
autocomplete: function(aValue) {
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("FormAssist:AutoComplete", { value: aValue });
|
|
|
|
},
|
|
|
|
|
|
|
|
getRect: function() {
|
|
|
|
return this._rect;
|
2009-09-17 13:17:57 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
/**
|
|
|
|
* SelectHelper: Provides an interface for making a choice in a list.
|
|
|
|
* Supports simultaneous selection of choices and group headers.
|
|
|
|
* Needs a BasicWrapper for handling selected element.
|
|
|
|
*/
|
2009-06-24 09:42:53 -07:00
|
|
|
var SelectHelper = {
|
|
|
|
_list: null,
|
2010-06-21 13:36:56 -07:00
|
|
|
_selectedIndexes: null,
|
|
|
|
_navigator: 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-06-21 13:36:56 -07:00
|
|
|
show: function(wrapper) {
|
|
|
|
let choiceData = wrapper.getChoiceData();
|
|
|
|
this._wrapper = wrapper;
|
|
|
|
this._choiceData = choiceData;
|
2009-06-24 09:42:53 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
this._selectedIndexes = this._getSelectedIndexes(choiceData);
|
2009-06-24 09:42:53 -07:00
|
|
|
this._list = document.getElementById("select-list");
|
2010-06-21 13:36:56 -07:00
|
|
|
this._list.setAttribute("multiple", choiceData.multiple ? "true" : "false");
|
2009-06-24 09:42:53 -07:00
|
|
|
|
2009-07-28 20:36:00 -07:00
|
|
|
let firstSelected = null;
|
2009-08-13 16:41:45 -07:00
|
|
|
|
2010-06-21 13:36:56 -07:00
|
|
|
let choices = choiceData.choices;
|
|
|
|
for (let i = 0; i < choices.length; i++) {
|
|
|
|
let choice = choices[i];
|
|
|
|
if (choice.group) {
|
2009-06-24 09:42:53 -07:00
|
|
|
let group = document.createElement("option");
|
2010-06-21 13:36:56 -07:00
|
|
|
group.setAttribute("label", choice.text);
|
2009-06-24 09:42:53 -07:00
|
|
|
this._list.appendChild(group);
|
|
|
|
group.className = "optgroup";
|
2010-06-21 13:36:56 -07:00
|
|
|
} else {
|
2009-06-24 09:42:53 -07:00
|
|
|
let item = document.createElement("option");
|
2010-06-21 13:36:56 -07:00
|
|
|
item.setAttribute("label", choice.text);
|
|
|
|
item.optionIndex = choice.optionIndex;
|
|
|
|
item.choiceIndex = i;
|
|
|
|
if (choice.inGroup)
|
|
|
|
item.className = "in-optgroup";
|
2009-06-24 09:42:53 -07:00
|
|
|
this._list.appendChild(item);
|
2010-06-21 13:36:56 -07:00
|
|
|
if (choice.selected) {
|
2009-06-24 09:42:53 -07:00
|
|
|
item.setAttribute("selected", "true");
|
2010-06-21 13:36:56 -07:00
|
|
|
firstSelected = firstSelected || item;
|
2009-07-28 20:36:00 -07:00
|
|
|
}
|
2009-06-24 09:42:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._panel.hidden = false;
|
|
|
|
|
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);
|
|
|
|
|
2009-06-24 09:42:53 -07:00
|
|
|
this._list.addEventListener("click", this, false);
|
|
|
|
},
|
|
|
|
|
2010-06-17 20:55:58 -07:00
|
|
|
dock: function dock(aContainer) {
|
|
|
|
aContainer.insertBefore(this._panel, aContainer.lastChild);
|
|
|
|
this._panel.style.maxHeight = (window.innerHeight / 1.8) + "px";
|
|
|
|
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();
|
|
|
|
let empty = this._list.cloneNode(false);
|
|
|
|
this._list.parentNode.replaceChild(empty, this._list);
|
|
|
|
this._list = empty;
|
|
|
|
this._wrapper = null;
|
|
|
|
this._choiceData = null;
|
|
|
|
this._selectedIndexes = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this._list.removeEventListener("click", this, false);
|
|
|
|
this._panel.hidden = true;
|
|
|
|
|
|
|
|
if (this._docked)
|
|
|
|
this.undock();
|
|
|
|
else
|
|
|
|
BrowserUI.popPopup();
|
|
|
|
|
|
|
|
this.reset();
|
|
|
|
},
|
|
|
|
|
|
|
|
unselectAll: function() {
|
|
|
|
let choices = this._choiceData.choices;
|
|
|
|
this._forEachOption(function(aItem, aIndex) {
|
|
|
|
aItem.selected = false;
|
|
|
|
choices[aIndex].selected = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
selectByIndex: function(aIndex) {
|
|
|
|
let choices = this._choiceData.choices;
|
|
|
|
for (let i = 0; i < this._list.childNodes.length; i++) {
|
|
|
|
let option = this._list.childNodes[i];
|
|
|
|
if (option.optionIndex == aIndex) {
|
|
|
|
option.selected = true;
|
|
|
|
this._choices[i].selected = true;
|
|
|
|
this._scrollElementIntoView(option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_getSelectedIndexes: function(choiceData) {
|
|
|
|
let indexes = [];
|
|
|
|
let choices = choiceData.choices;
|
|
|
|
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-02-16 15:34:04 -08:00
|
|
|
let scrollBoxObject = this._list.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
|
2009-07-28 20:36:00 -07:00
|
|
|
let itemHeight = aElement.getBoundingClientRect().height;
|
|
|
|
let visibleItemsCount = this._list.boxObject.height / itemHeight;
|
|
|
|
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-06-21 13:36:56 -07:00
|
|
|
let children = this._list.children;
|
|
|
|
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-06-21 13:36:56 -07:00
|
|
|
let currentSelectedIndexes = this._getSelectedIndexes(this._choiceData);
|
2009-07-06 10:14:46 -07:00
|
|
|
|
|
|
|
let isIdentical = currentSelectedIndexes.length == this._selectedIndexes.length;
|
|
|
|
if (isIdentical) {
|
|
|
|
for (let i = 0; i < currentSelectedIndexes.length; i++) {
|
|
|
|
if (currentSelectedIndexes[i] != this._selectedIndexes[i]) {
|
|
|
|
isIdentical = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-15 21:41:48 -08:00
|
|
|
if (!isIdentical)
|
2010-06-21 13:36:56 -07:00
|
|
|
this._wrapper.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-06-21 13:36:56 -07:00
|
|
|
if (this._choiceData.multiple) {
|
2009-06-24 09:42:53 -07:00
|
|
|
// Toggle the item state
|
|
|
|
item.selected = !item.selected;
|
2010-06-21 13:36:56 -07:00
|
|
|
this._choiceData.choices[item.choiceIndex].selected = item.selected;
|
|
|
|
this._wrapper.choiceSelect(item.optionIndex, item.selected, false);
|
2009-06-24 09:42:53 -07:00
|
|
|
}
|
|
|
|
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-06-21 13:36:56 -07:00
|
|
|
this._choiceData.choices[item.choiceIndex].selected = true;
|
|
|
|
this._wrapper.choiceSelect(item.optionIndex, item.selected, true);
|
2009-06-24 09:42:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2009-08-17 14:05:06 -07:00
|
|
|
|
2010-03-24 11:22:18 -07:00
|
|
|
const kXLinkNamespace = "http://www.w3.org/1999/xlink";
|
|
|
|
|
|
|
|
var ContextHelper = {
|
2010-06-29 11:15:07 -07:00
|
|
|
popupState: null,
|
2010-03-25 20:52:31 -07:00
|
|
|
|
2010-06-29 11:15:07 -07:00
|
|
|
receiveMessage: function ch_receiveMessage(aMessage) {
|
|
|
|
this.popupState = aMessage.json;
|
|
|
|
this.popupState.browser = 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];
|
2010-05-05 13:54:47 -07:00
|
|
|
let types = command.getAttribute("type").split(/\s+/);
|
2010-03-24 11:22:18 -07:00
|
|
|
command.removeAttribute("selector");
|
2010-06-29 11:15:07 -07:00
|
|
|
if (types.indexOf("image") != -1 && this.popupState.onImage) {
|
2010-05-05 13:54:47 -07:00
|
|
|
first = (first ? first : command);
|
|
|
|
last = command;
|
|
|
|
command.hidden = false;
|
|
|
|
continue;
|
2010-06-29 11:15:07 -07:00
|
|
|
} else if (types.indexOf("image-loaded") != -1 && this.popupState.onLoadedImage) {
|
2010-05-05 13:54:47 -07:00
|
|
|
first = (first ? first : command);
|
|
|
|
last = command;
|
|
|
|
command.hidden = false;
|
|
|
|
continue;
|
2010-06-29 11:15:07 -07:00
|
|
|
} else if (types.indexOf("link") != -1 && this.popupState.onSaveableLink) {
|
2010-03-24 11:22:18 -07:00
|
|
|
first = (first ? first : command);
|
|
|
|
last = command;
|
|
|
|
command.hidden = false;
|
|
|
|
continue;
|
2010-06-29 11:15:07 -07:00
|
|
|
} else if (types.indexOf("callto") != -1 && this.popupState.onVoiceLink) {
|
2010-03-25 20:52:31 -07:00
|
|
|
first = (first ? first : command);
|
|
|
|
last = command;
|
|
|
|
command.hidden = false;
|
|
|
|
continue;
|
2010-06-29 11:15:07 -07:00
|
|
|
} else if (types.indexOf("mailto") != -1 && this.popupState.onLink && this.popupState.linkProtocol == "mailto") {
|
2010-03-24 11:22:18 -07:00
|
|
|
first = (first ? first : command);
|
|
|
|
last = command;
|
|
|
|
command.hidden = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
command.hidden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!first) {
|
2010-06-29 11:15:07 -07:00
|
|
|
this.popupState = null;
|
2010-03-24 11:22:18 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
first.setAttribute("selector", "first-child");
|
|
|
|
last.setAttribute("selector", "last-child");
|
|
|
|
|
|
|
|
let label = document.getElementById("context-hint");
|
2010-06-29 11:15:07 -07:00
|
|
|
if (this.popupState.onImage)
|
|
|
|
label.value = this.popupState.mediaURL;
|
|
|
|
if (this.popupState.onLink)
|
|
|
|
label.value = this.popupState.linkURL;
|
2010-03-24 11:22:18 -07:00
|
|
|
|
|
|
|
let container = document.getElementById("context-popup");
|
|
|
|
container.hidden = false;
|
|
|
|
|
2010-03-25 20:52:31 -07:00
|
|
|
// Make sure the container is at least sized to the content
|
|
|
|
let preferredHeight = 0;
|
|
|
|
for (let i=0; i<container.childElementCount; i++) {
|
|
|
|
preferredHeight += container.children[i].getBoundingClientRect().height;
|
|
|
|
}
|
|
|
|
|
2010-03-24 11:22:18 -07:00
|
|
|
let rect = container.getBoundingClientRect();
|
2010-03-25 20:52:31 -07:00
|
|
|
let height = Math.min(preferredHeight, 0.75 * window.innerWidth);
|
2010-03-24 11:22:18 -07:00
|
|
|
let width = Math.min(rect.width, 0.75 * window.innerWidth);
|
|
|
|
|
|
|
|
container.height = height;
|
|
|
|
container.width = width;
|
|
|
|
container.top = (window.innerHeight - height) / 2;
|
|
|
|
container.left = (window.innerWidth - width) / 2;
|
|
|
|
|
|
|
|
BrowserUI.pushPopup(this, [container]);
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function ch_hide() {
|
2010-06-29 11:15:07 -07:00
|
|
|
this.popupState = null;
|
2010-03-24 11:22:18 -07:00
|
|
|
|
|
|
|
let container = document.getElementById("context-popup");
|
|
|
|
container.hidden = true;
|
|
|
|
|
|
|
|
BrowserUI.popPopup();
|
2010-05-03 21:19:44 -07:00
|
|
|
}
|
|
|
|
};
|
2010-03-24 11:22:18 -07:00
|
|
|
|
|
|
|
var ContextCommands = {
|
|
|
|
openInNewTab: function cc_openInNewTab(aEvent) {
|
2010-06-29 11:15:07 -07:00
|
|
|
Browser.addTab(ContextHelper.popupState.linkURL, false, Browser.selectedTab);
|
2010-03-24 11:22:18 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
saveImage: function cc_saveImage(aEvent) {
|
2010-06-29 11:15:07 -07:00
|
|
|
let browser = ContextHelper.popupState.browser;
|
|
|
|
saveImageURL(ContextHelper.popupState.mediaURL, null, "SaveImageTitle", false, false, browser.documentURI);
|
2010-03-24 11:22:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-17 14:05:06 -07:00
|
|
|
function 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);
|
|
|
|
|
|
|
|
BrowserUI.updateStar();
|
|
|
|
}
|