/* ***** 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 * * 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 ***** */ const TOOLBARSTATE_LOADING = 1; const TOOLBARSTATE_LOADED = 2; const TOOLBARSTATE_INDETERMINATE = 3; const PANELMODE_VIEW = 1; const PANELMODE_EDIT = 2; const PANELMODE_BOOKMARK = 3; const PANELMODE_BOOKMARKLIST = 4; var BrowserUI = { _panel : null, _caption : null, _edit : null, _throbber : null, _favicon : null, _faviconAdded : false, _fadeoutID : null, _allowHide : true, _titleChanged : function(aEvent) { if (aEvent.target != getBrowser().contentDocument) return; this._caption.value = aEvent.target.title; }, _linkAdded : function(aEvent) { var link = aEvent.originalTarget; if (!link || !link.ownerDocument || !link.href) return; var rel = link.rel && link.rel.toLowerCase(); var rels = rel.split(/\s+/); if (rels.indexOf("icon") != -1) { this._throbber.setAttribute("src", ""); this._setIcon(link.href); } }, _setIcon : function(aURI) { var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var faviconURI = ios.newURI(aURI, null, null); if (faviconURI.schemeIs("javascript")) return; var fis = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService); if (fis.isFailedFavicon(faviconURI)) faviconURI = ios.newURI("chrome://browser/skin/images/default-favicon.png", null, null); fis.setAndLoadFaviconForPage(getBrowser().currentURI, faviconURI, true); this._favicon.setAttribute("src", faviconURI.spec); this._faviconAdded = true; }, _getBookmarks : function(aFolders) { var items = []; var hs = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService); var options = hs.getNewQueryOptions(); //options.resultType = options.RESULTS_AS_URI; var query = hs.getNewQuery(); query.setFolders(aFolders, 1); var result = hs.executeQuery(query, options); var rootNode = result.root; rootNode.containerOpen = true; var cc = rootNode.childCount; for (var i=0; i 0) { star.setAttribute("starred", "true"); } else { star.removeAttribute("starred"); } var uri = browser.currentURI; if (!this._URIFixup) this._URIFixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup); try { uri = this._URIFixup.createExposableURI(uri); } catch (ex) {} var urlString = uri.spec; if (urlString == "about:blank") { urlString = ""; this._showMode(PANELMODE_EDIT); this._allowHide = false; } this._caption.value = urlString; this._edit.value = urlString; }, goToURI : function(aURI) { if (!aURI) aURI = this._edit.value; getBrowser().loadURI(aURI.spec, null, null, false); this._showMode(PANELMODE_VIEW); }, search : function() { var queryURI = "http://www.google.com/search?q=" + this._edit.value + "&hl=en&lr=&btnG=Search"; getBrowser().loadURI(queryURI, null, null, false); this._showMode(PANELMODE_VIEW); }, _showMode : function(aMode) { if (this._fadeoutID) { clearTimeout(this._fadeoutID); this._fadeoutID = null; } var toolbar = document.getElementById("toolbar-main"); var bookmark = document.getElementById("bookmark-container"); var urllist = document.getElementById("urllist-container"); if (aMode == PANELMODE_VIEW) { toolbar.setAttribute("mode", "view"); this._edit.hidden = true; this._caption.hidden = false; bookmark.hidden = true; urllist.hidden = true; } else if (aMode == PANELMODE_EDIT) { toolbar.setAttribute("mode", "edit"); this._caption.hidden = true; this._edit.hidden = false; this._edit.focus(); this.showHistory(); bookmark.hidden = true; urllist.hidden = false; } else if (aMode == PANELMODE_BOOKMARK) { toolbar.setAttribute("mode", "view"); this._edit.hidden = true; this._caption.hidden = false; urllist.hidden = true; bookmark.hidden = false; } else if (aMode == PANELMODE_BOOKMARKLIST) { toolbar.setAttribute("mode", "view"); this._edit.hidden = true; this._caption.hidden = false; urllist.hidden = false; bookmark.hidden = true; } }, _showPlaces : function(aItems) { var list = document.getElementById("urllist-items"); while (list.firstChild) { list.removeChild(list.firstChild); } var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var fis = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService); for (var i=0; i 0) { this._item = bookmarkIDs[0]; document.getElementById("bookmark-name").value = this._bmksvc.getItemTitle(this._item); var currentTags = this._tagsvc.getTagsForURI(this._uri, {}); document.getElementById("bookmark-tags").value = currentTags.join(" "); } }, remove : function() { if (this._item) { this._bmksvc.removeItem(this._item); document.getElementById("tool-star").removeAttribute("starred"); } this.close(); }, save : function() { if (this._item) { // Update the name this._bmksvc.setItemTitle(this._item, document.getElementById("bookmark-name").value); // Update the tags var taglist = document.getElementById("hudbookmark-tags").value; var currentTags = this._tagsvc.getTagsForURI(this._uri, {}); var tags = taglist.split(" "); if (tags.length > 0 || currentTags.length > 0) { var tagsToRemove = []; var tagsToAdd = []; var i; for (i=0; i 0) this._tagsvc.tagURI(this._uri, tagsToAdd); if (tagsToRemove.length > 0) this._tagsvc.untagURI(this._uri, tagsToRemove); } } this.close(); }, close : function() { this._item = null; BrowserUI.hide(); } };