diff --git a/browser/base/content/browser.css b/browser/base/content/browser.css index 2888bda2a406..b9049e5e7987 100644 --- a/browser/base/content/browser.css +++ b/browser/base/content/browser.css @@ -23,12 +23,6 @@ window[chromehidden~="toolbar"] #navigator-throbber[busy="true"] { -moz-binding: url("chrome://browser/content/search.xml#searchbar"); } -bookmarks-toolbar { - -moz-binding: url("chrome://browser/content/bookmarks/bookmarksToolbar.xml#bookmarks-toolbar"); - min-width: 0px; - width:0px; -} - /* ::::: print preview toolbar ::::: */ toolbar[printpreview="true"] { diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 6b65d9f77ff6..b5fd7f72d9a2 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -406,9 +406,13 @@ function delayedStartup() // now load bookmarks after a delay BMSVC.ReadBookmarks(); - var bt = document.getElementById("bookmarks-toolbar"); - if (bt && "toolbar" in bt) - bt.toolbar.builder.rebuild(); + var bt = document.getElementById("bookmarks-ptf"); + if (bt) { + bt.builder.rebuild(); + bt.database.AddObserver(BookmarksToolbarRDFObserver); + } + window.addEventListener("resize", BookmarksToolbar.resizeFunc, false); + controllers.appendController(BookmarksMenuController); // called when we go into full screen, even if it is // initiated by a web page script @@ -1395,38 +1399,6 @@ function updateToolbarStates(toolbarMenuElt) } } -// Fill in tooltips for personal toolbar -function FillInPTTooltip(tipElement) -{ - - var title = tipElement.label; - var url = tipElement.statusText; - - if (!title && !url) { - // bail out early if there is nothing to show - return false; - } - - var tooltipTitle = document.getElementById("ptTitleText"); - var tooltipUrl = document.getElementById("ptUrlText"); - - if (title && title != url) { - tooltipTitle.removeAttribute("hidden"); - tooltipTitle.setAttribute("value", title); - } else { - tooltipTitle.setAttribute("hidden", "true"); - } - - if (url) { - tooltipUrl.removeAttribute("hidden"); - tooltipUrl.setAttribute("value", url); - } else { - tooltipUrl.setAttribute("hidden", "true"); - } - - return true; // show tooltip -} - function BrowserFullScreen() { window.fullScreen = !window.fullScreen; @@ -2014,387 +1986,6 @@ function OpenSearch(tabName, searchStr, newWindowFlag) } } -var personalToolbarDNDObserver = { - - //////////////////// - // Public methods // - //////////////////// - - onDragStart: function (aEvent, aXferData, aDragAction) - { - var target = aEvent.originalTarget; - - // Prevent dragging from an invalid region - if (!this.canDrop(aEvent)) - return; - - // Prevent dragging out of menupopups on non Win32 platforms. - // a) on Mac drag from menus is generally regarded as being satanic - // b) on Linux, this causes an X-server crash, (bug 151336) - // c) on Windows, there is no hang or crash associated with this, so we'll leave - // the functionality there. - if (navigator.platform != "Win32" && target.localName != "toolbarbutton") - return; - - // bail if dragging from the empty area of the bookmarks toolbar - if (target.localName == "hbox") - return - - // a drag start is fired when leaving an open toolbarbutton(type=menu) - // (see bug 143031) - if (this.isContainer(target) && - target.getAttribute("group") != "true") { - if (this.isPlatformNotSupported) - return; - if (!aEvent.shiftKey && !aEvent.altKey && !aEvent.ctrlKey) - return; - // menus open on mouse down - target.firstChild.hidePopup(); - } - var bt = document.getElementById("bookmarks-toolbar"); - var selection = bt.getBTSelection(target); - aXferData.data = BookmarksUtils.getXferDataFromSelection(selection); - }, - - onDragOver: function(aEvent, aFlavour, aDragSession) - { - var bt = document.getElementById("bookmarks-toolbar"); - var orientation = bt.getBTOrientation(aEvent) - if (aDragSession.canDrop) - this.onDragSetFeedBack(aEvent.originalTarget, orientation); - if (orientation != this.mCurrentDropPosition) { - // emulating onDragExit and onDragEnter events since the drop region - // has changed on the target. - this.onDragExit(aEvent, aDragSession); - this.onDragEnter(aEvent, aDragSession); - } - if (this.isPlatformNotSupported) - return; - if (this.isTimerSupported) - return; - this.onDragOverCheckTimers(); - }, - - onDragEnter: function (aEvent, aDragSession) - { - var target = aEvent.originalTarget; - var bt = document.getElementById("bookmarks-toolbar"); - var orientation = bt.getBTOrientation(aEvent); - if (target.localName == "menupopup" || target.localName == "hbox") - target = target.parentNode; - if (aDragSession.canDrop) { - this.onDragSetFeedBack(target, orientation); - this.onDragEnterSetTimer(target, aDragSession); - } - this.mCurrentDragOverTarget = target; - this.mCurrentDropPosition = orientation; - }, - - onDragExit: function (aEvent, aDragSession) - { - var target = aEvent.originalTarget; - if (target.localName == "menupopup" || target.localName == "hbox") - target = target.parentNode; - this.onDragRemoveFeedBack(target); - this.onDragExitSetTimer(target, aDragSession); - this.mCurrentDragOverTarget = null; - this.mCurrentDropPosition = null; - }, - - onDrop: function (aEvent, aXferData, aDragSession) - { - var target = aEvent.originalTarget; - this.onDragRemoveFeedBack(target); - - var bt = document.getElementById("bookmarks-toolbar"); - var selection = BookmarksUtils.getSelectionFromXferData(aDragSession); - - // if the personal toolbar does not exist, recreate it - if (target == "bookmarks-toolbar") { - //BookmarksUtils.recreatePersonalToolbarFolder(transactionSet); - //target = { parent: "NC:PersonalToolbarFolder", index: 1 }; - } else { - var orientation = bt.getBTOrientation(aEvent); - var selTarget = bt.getBTTarget(target, orientation); - } - - const kDSIID = Components.interfaces.nsIDragService; - const kCopyAction = kDSIID.DRAGDROP_ACTION_COPY + kDSIID.DRAGDROP_ACTION_LINK; - - // hide the 'open in tab' menuseparator because bookmarks - // can be inserted after it if they are dropped after the last bookmark - // a more comprehensive fix would be in the menupopup template builder - var menuTarget = (target.localName == "toolbarbutton" || - target.localName == "menu") && - orientation == BookmarksUtils.DROP_ON? - target.lastChild:target.parentNode; - if (menuTarget.hasChildNodes() && - menuTarget.lastChild.id == "openintabs-menuitem") { - menuTarget.removeChild(menuTarget.lastChild.previousSibling); - } - - if (aDragSession.dragAction & kCopyAction) - BookmarksUtils.insertSelection("drag", selection, selTarget, true); - else - BookmarksUtils.moveSelection("drag", selection, selTarget); - - // show again the menuseparator - if (menuTarget.hasChildNodes() && - menuTarget.lastChild.id == "openintabs-menuitem") { - var element = document.createElementNS(XUL_NS, "menuseparator"); - menuTarget.insertBefore(element, menuTarget.lastChild); - } - - }, - - canDrop: function (aEvent, aDragSession) - { - var target = aEvent.originalTarget; - var bt = document.getElementById("bookmarks-toolbar"); - return bt.isBTBookmark(target.id) && - target.id != "NC:SystemBookmarksStaticRoot" && - target.id.substring(0,5) != "find:" || - target.id == "bookmarks-menu" || - target.getAttribute("class") == "chevron" || - target.localName == "hbox"; - }, - - canHandleMultipleItems: true, - - getSupportedFlavours: function () - { - var flavourSet = new FlavourSet(); - flavourSet.appendFlavour("moz/rdfitem"); - flavourSet.appendFlavour("text/x-moz-url"); - flavourSet.appendFlavour("application/x-moz-file", "nsIFile"); - flavourSet.appendFlavour("text/unicode"); - return flavourSet; - }, - - - //////////////////////////////////// - // Private methods and properties // - //////////////////////////////////// - - springLoadedMenuDelay: 350, // milliseconds - isPlatformNotSupported: navigator.platform.indexOf("Mac") != -1, // see bug 136524 - isTimerSupported: navigator.platform.indexOf("Win") == -1, - - mCurrentDragOverTarget: null, - mCurrentDropPosition: null, - loadTimer : null, - closeTimer : null, - loadTarget : null, - closeTarget: null, - - _observers : null, - get mObservers () - { - if (!this._observers) { - var bt = document.getElementById("bookmarks-toolbar"); - this._observers = [ - document.getAnonymousElementByAttribute(bt , "anonid", "bookmarks-ptf"), - document.getElementById("bookmarks-menu").parentNode, - document.getAnonymousElementByAttribute(bt , "class", "chevron").parentNode - ] - } - return this._observers; - }, - - getObserverForNode: function (aNode) - { - if (!aNode) - return null; - var node = aNode; - var observer; - do { - for (var i=0; i < this.mObservers.length; i++) { - observer = this.mObservers[i]; - if (observer == node) - return observer; - } - node = node.parentNode; - } while (node != document) - return null; - }, - - onDragCloseMenu: function (aNode) - { - var children = aNode.childNodes; - for (var i = 0; i < children.length; i++) { - if (this.isContainer(children[i]) && - children[i].getAttribute("open") == "true") { - this.onDragCloseMenu(children[i].lastChild); - if (children[i] != this.mCurrentDragOverTarget || this.mCurrentDropPosition != BookmarksUtils.DROP_ON) - children[i].lastChild.hidePopup(); - } - } - }, - - onDragCloseTarget: function () - { - var currentObserver = this.getObserverForNode(this.mCurrentDragOverTarget); - // close all the menus not hovered by the mouse - for (var i=0; i < this.mObservers.length; i++) { - if (currentObserver != this.mObservers[i]) - this.onDragCloseMenu(this.mObservers[i]); - else - this.onDragCloseMenu(this.mCurrentDragOverTarget.parentNode); - } - }, - - onDragLoadTarget: function (aTarget) - { - if (!this.mCurrentDragOverTarget) - return; - // Load the current menu - if (this.mCurrentDropPosition == BookmarksUtils.DROP_ON && - this.isContainer(aTarget) && - aTarget.getAttribute("group") != "true") - aTarget.lastChild.showPopup(aTarget); - }, - - onDragOverCheckTimers: function () - { - var now = new Date().getTime(); - if (this.closeTimer && now-this.springLoadedMenuDelay>this.closeTimer) { - this.onDragCloseTarget(); - this.closeTimer = null; - } - if (this.loadTimer && (now-this.springLoadedMenuDelay>this.loadTimer)) { - this.onDragLoadTarget(this.loadTarget); - this.loadTimer = null; - } - }, - - onDragEnterSetTimer: function (aTarget, aDragSession) - { - if (this.isPlatformNotSupported) - return; - if (this.isTimerSupported) { - var targetToBeLoaded = aTarget; - clearTimeout(this.loadTimer); - if (aTarget == aDragSession.sourceNode) - return; - //XXX Hack: see bug 139645 - var thisHack = this; - this.loadTimer=setTimeout(function () {thisHack.onDragLoadTarget(targetToBeLoaded)}, this.springLoadedMenuDelay); - } else { - var now = new Date().getTime(); - this.loadTimer = now; - this.loadTarget = aTarget; - } - }, - - onDragExitSetTimer: function (aTarget, aDragSession) - { - if (this.isPlatformNotSupported) - return; - var thisHack = this; - if (this.isTimerSupported) { - clearTimeout(this.closeTimer) - this.closeTimer=setTimeout(function () {thisHack.onDragCloseTarget()}, this.springLoadedMenuDelay); - } else { - var now = new Date().getTime(); - this.closeTimer = now; - this.closeTarget = aTarget; - this.loadTimer = null; - - // If user isn't rearranging within the menu, close it - // To do so, we exploit a Mac bug: timeout set during - // drag and drop on Windows and Mac are fired only after that the drop is released. - // timeouts will pile up, we may have a better approach but for the moment, this one - // correctly close the menus after a drop/cancel outside the personal toolbar. - // The if statement in the function has been introduced to deal with rare but reproducible - // missing Exit events. - if (aDragSession.sourceNode.localName != "menuitem" && aDragSession.sourceNode.localName != "menu") - setTimeout(function () { if (thisHack.mCurrentDragOverTarget) {thisHack.onDragRemoveFeedBack(thisHack.mCurrentDragOverTarget); thisHack.mCurrentDragOverTarget=null} thisHack.loadTimer=null; thisHack.onDragCloseTarget() }, 0); - } - }, - - onDragSetFeedBack: function (aTarget, aOrientation) - { - switch (aTarget.localName) { - case "toolbarseparator": - case "toolbarbutton": - switch (aOrientation) { - case BookmarksUtils.DROP_BEFORE: - aTarget.setAttribute("dragover-left", "true"); - break; - case BookmarksUtils.DROP_AFTER: - aTarget.setAttribute("dragover-right", "true"); - break; - case BookmarksUtils.DROP_ON: - aTarget.setAttribute("dragover-top" , "true"); - aTarget.setAttribute("dragover-bottom", "true"); - aTarget.setAttribute("dragover-left" , "true"); - aTarget.setAttribute("dragover-right" , "true"); - break; - } - break; - case "menuseparator": - case "menu": - case "menuitem": - switch (aOrientation) { - case BookmarksUtils.DROP_BEFORE: - aTarget.setAttribute("dragover-top", "true"); - break; - case BookmarksUtils.DROP_AFTER: - aTarget.setAttribute("dragover-bottom", "true"); - break; - case BookmarksUtils.DROP_ON: - break; - } - break; - case "hbox" : - // hit between the last visible bookmark and the chevron - var bt = document.getElementById("bookmarks-toolbar"); - var newTarget = bt.getLastVisibleBookmark(); - if (newTarget) - newTarget.setAttribute("dragover-right", "true"); - break; - case "stack" : - case "menupopup": break; - default: dump("No feedback for: "+aTarget.localName+"\n"); - } - }, - - onDragRemoveFeedBack: function (aTarget) - { - var newTarget; - var bt; - if (aTarget.localName == "hbox") { - // hit when dropping in the bt or between the last visible bookmark - // and the chevron - bt = document.getElementById("bookmarks-toolbar"); - newTarget = bt.getLastVisibleBookmark(); - if (newTarget) - newTarget.removeAttribute("dragover-right"); - } else if (aTarget.localName == "stack") { - bt = document.getElementById("bookmarks-toolbar"); - newTarget = bt.getLastVisibleBookmark(); - newTarget.removeAttribute("dragover-right"); - } else { - aTarget.removeAttribute("dragover-left"); - aTarget.removeAttribute("dragover-right"); - aTarget.removeAttribute("dragover-top"); - aTarget.removeAttribute("dragover-bottom"); - } - }, - - onDropSetFeedBack: function (aTarget) - { - //XXX Not yet... - }, - - isContainer: function (aTarget) - { - return aTarget.localName == "menu" || - aTarget.localName == "toolbarbutton" && - aTarget.getAttribute("type") == "menu"; - } -} - function FillHistoryMenu(aParent, aMenu) { // Remove old entries if any diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index af43a6f40931..d502f0fc85d1 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -20,6 +20,10 @@ # Rights Reserved. # # Contributor(s): +# Blake Ross +# David Hyatt +# Joe Hewitt +# Pierre Chanial # Dean Tessman @@ -54,6 +58,7 @@