Bug 855805 - Create the Bookmarks widget with subview - Functional part.

r=mconley
This commit is contained in:
Marco Bonardo 2013-07-25 12:02:05 +02:00
parent b1fbc145f3
commit 545697bb91
11 changed files with 349 additions and 71 deletions

View File

@ -996,29 +996,27 @@ let PlacesToolbarHelper = {
let BookmarkingUI = {
get button() {
if (!this._button) {
this._button = document.getElementById("bookmarks-menu-button");
}
return this._button;
let widget = CustomizableUI.getWidget("bookmarks-menu-button")
.forWindow(window);
return widget.areaType == CustomizableUI.TYPE_TOOLBAR ? widget.node
: null;
},
get star() {
if (!this._star && this.button) {
this._star = document.getAnonymousElementByAttribute(this.button,
"anonid",
"button");
}
return this._star;
let button = this.button;
return button && document.getAnonymousElementByAttribute(button, "anonid",
"button");
},
get anchor() {
if (!this._anchor && this.star && isElementVisible(this.star)) {
// Anchor to the icon, so the panel looks more natural.
this._anchor = document.getAnonymousElementByAttribute(this.star,
"class",
"toolbarbutton-icon");
}
return this._anchor;
let widget = CustomizableUI.getWidget("bookmarks-menu-button")
.forWindow(window);
if (widget.overflowed)
return widget.anchor;
let star = this.star;
return star && document.getAnonymousElementByAttribute(star, "class",
"toolbarbutton-icon");
},
STATUS_UPDATING: -1,
@ -1027,9 +1025,9 @@ let BookmarkingUI = {
get status() {
if (this._pendingStmt)
return this.STATUS_UPDATING;
return this.button &&
this.button.hasAttribute("starred") ? this.STATUS_STARRED
: this.STATUS_UNSTARRED;
let button = this.button;
return button && button.hasAttribute("starred") ? this.STATUS_STARRED
: this.STATUS_UNSTARRED;
},
get _starredTooltip()
@ -1062,6 +1060,16 @@ let BookmarkingUI = {
if (event.target != event.currentTarget)
return;
let widget = CustomizableUI.getWidget("bookmarks-menu-button")
.forWindow(window);
if (widget.overflowed) {
// Don't open a popup in the overflow popup, rather just open the Library.
event.preventDefault();
widget.node.removeAttribute("noautoclose");
PlacesCommandHook.showPlacesOrganizer("BookmarksMenu");
return;
}
if (!this._popupNeedsUpdate)
return;
this._popupNeedsUpdate = false;
@ -1078,14 +1086,6 @@ let BookmarkingUI = {
let personalToolbar = document.getElementById("PersonalToolbar");
viewToolbarMenuitem.setAttribute("checked", !personalToolbar.collapsed);
}
let toolbarMenuitem = getPlacesAnonymousElement("toolbar-autohide");
if (toolbarMenuitem) {
// If bookmarks items are visible, hide Bookmarks Toolbar menu and the
// separator after it.
toolbarMenuitem.collapsed = toolbarMenuitem.nextSibling.collapsed =
isElementVisible(document.getElementById("personal-bookmarks"));
}
},
/**
@ -1107,21 +1107,21 @@ let BookmarkingUI = {
},
_updateToolbarStyle: function BUI__updateToolbarStyle() {
if (!this.button) {
let button = this.button;
if (!button)
return;
}
let personalToolbar = document.getElementById("PersonalToolbar");
let onPersonalToolbar = this.button.parentNode == personalToolbar ||
this.button.parentNode.parentNode == personalToolbar;
let onPersonalToolbar = button.parentNode == personalToolbar ||
button.parentNode.parentNode == personalToolbar;
if (onPersonalToolbar) {
this.button.classList.add("bookmark-item");
this.button.classList.remove("toolbarbutton-1");
button.classList.add("bookmark-item");
button.classList.remove("toolbarbutton-1");
}
else {
this.button.classList.remove("bookmark-item");
this.button.classList.add("toolbarbutton-1");
button.classList.remove("bookmark-item");
button.classList.add("toolbarbutton-1");
}
},
@ -1129,9 +1129,9 @@ let BookmarkingUI = {
// When an element with a placesView attached is removed and re-inserted,
// XBL reapplies the binding causing any kind of issues and possible leaks,
// so kill current view and let popupshowing generate a new one.
if (this.button && this.button._placesView) {
this.button._placesView.uninit();
}
let button = this.button;
if (button && button._placesView)
button._placesView.uninit();
},
customizeStart: function BUI_customizeStart() {
@ -1143,9 +1143,6 @@ let BookmarkingUI = {
},
customizeDone: function BUI_customizeDone() {
delete this._button;
delete this._star;
delete this._anchor;
this.onToolbarVisibilityChange();
this._updateToolbarStyle();
},
@ -1214,17 +1211,17 @@ let BookmarkingUI = {
},
_updateStar: function BUI__updateStar() {
if (!this.button) {
let button = this.button;
if (!button)
return;
}
if (this._itemIds.length > 0) {
this.button.setAttribute("starred", "true");
this.button.setAttribute("tooltiptext", this._starredTooltip);
button.setAttribute("starred", "true");
button.setAttribute("tooltiptext", this._starredTooltip);
}
else {
this.button.removeAttribute("starred");
this.button.setAttribute("tooltiptext", this._unstarredTooltip);
button.removeAttribute("starred");
button.setAttribute("tooltiptext", this._unstarredTooltip);
}
},
@ -1232,12 +1229,64 @@ let BookmarkingUI = {
if (aEvent.target != aEvent.currentTarget) {
return;
}
// Handle special case when the button is in the panel.
let widget = CustomizableUI.getWidget("bookmarks-menu-button")
.forWindow(window);
if (widget.areaType == CustomizableUI.TYPE_MENU_PANEL) {
let view = document.getElementById("PanelUI-bookmarks");
view.addEventListener("ViewShowing", this.onPanelMenuViewShowing);
view.addEventListener("ViewHiding", this.onPanelMenuViewHiding);
widget.node.setAttribute("noautoclose", "true");
PanelUI.showSubView("PanelUI-bookmarks", widget.node,
CustomizableUI.AREA_PANEL);
return;
}
else if (widget.overflowed) {
// Allow to close the panel if the page is already bookmarked, cause
// we are going to open the edit bookmark panel.
if (this._itemIds.length > 0)
widget.node.removeAttribute("noautoclose");
else
widget.node.setAttribute("noautoclose", "true");
}
// Ignore clicks on the star if we are updating its state.
if (!this._pendingStmt) {
PlacesCommandHook.bookmarkCurrentPage(this._itemIds.length > 0);
}
},
onPanelMenuViewShowing: function BUI_onViewShowing(aEvent) {
// Update checked status of the toolbar toggle.
let viewToolbar = document.getElementById("panelMenu_viewBookmarksToolbar");
let personalToolbar = document.getElementById("PersonalToolbar");
if (personalToolbar.collapsed)
viewToolbar.removeAttribute("checked");
else
viewToolbar.setAttribute("checked", "true");
// Setup the Places view.
this._panelMenuView = new PlacesPanelMenuView("place:folder=BOOKMARKS_MENU",
"panelMenu_bookmarksMenu",
"panelMenu_bookmarksMenu");
},
onPanelMenuViewHiding: function BUI_onViewHiding(aEvent) {
this._panelMenuView.uninit();
delete this._panelMenuView;
},
onPanelMenuViewCommand: function BUI_onPanelMenuViewCommand(aEvent, aView) {
let target = aEvent.originalTarget;
if (!target._placesNode)
return;
if (PlacesUtils.nodeIsContainer(target._placesNode))
PlacesCommandHook.showPlacesOrganizer([ "BookmarksMenu", target._placesNode.itemId ]);
else
PlacesUIUtils.openNodeWithEvent(target._placesNode, aEvent, aView);
PanelUI.hide();
},
// nsINavBookmarkObserver
onItemAdded: function BUI_onItemAdded(aItemId, aParentId, aIndex, aItemType,
aURI) {

View File

@ -208,6 +208,14 @@ toolbar[overflowable]:not([overflowing]) > .overflow-button {
direction: rtl;
}
#panelMenu_bookmarksMenu {
overflow-x: hidden;
overflow-y: auto;
}
#panelMenu_bookmarksMenu > .bookmark-item {
max-width: none;
}
#urlbar-container {
min-width: 50ch;
}

View File

@ -689,17 +689,16 @@
if (!this.parentNode._placesView)
new PlacesMenu(event, 'place:folder=BOOKMARKS_MENU');"
tooltip="bhTooltip" popupsinherittooltip="true">
<menuitem id="BMB_viewBookmarksToolbar"
placesanonid="view-toolbar"
toolbarId="PersonalToolbar"
type="checkbox"
oncommand="onViewToolbarCommand(event)"
label="&viewBookmarksToolbar.label;"/>
<menuseparator/>
<menuitem id="BMB_bookmarksShowAll"
label="&showAllBookmarks2.label;"
command="Browser:ShowAllBookmarks"
key="manBookmarkKb"/>
<menuitem id="BMB_viewBookmarksSidebar"
label="&viewBookmarksSidebar2.label;"
type="checkbox"
oncommand="toggleSidebar('viewBookmarksSidebar');">
<observes element="viewBookmarksSidebar" attribute="checked"/>
</menuitem>
<menuseparator/>
<menuitem id="BMB_subscribeToPageMenuitem"
#ifndef XP_MACOSX
@ -722,7 +721,6 @@
</menu>
<menuseparator/>
<menu id="BMB_bookmarksToolbar"
placesanonid="toolbar-autohide"
class="menu-iconic bookmark-item"
label="&personalbarCmd.label;"
container="true">
@ -730,16 +728,29 @@
placespopup="true"
context="placesContext"
onpopupshowing="if (!this.parentNode._placesView)
new PlacesMenu(event, 'place:folder=TOOLBAR');"/>
new PlacesMenu(event, 'place:folder=TOOLBAR');">
<menuitem id="BMB_viewBookmarksToolbar"
placesanonid="view-toolbar"
toolbarId="PersonalToolbar"
type="checkbox"
oncommand="onViewToolbarCommand(event)"
label="&viewBookmarksToolbar.label;"/>
<menuseparator/>
<!-- Bookmarks toolbar items -->
</menupopup>
</menu>
<menu id="BMB_unsortedBookmarks"
class="menu-iconic bookmark-item"
label="&bookmarksMenuButton.unsorted.label;"
container="true">
<menupopup id="BMB_unsortedBookmarksPopup"
placespopup="true"
context="placesContext"
onpopupshowing="if (!this.parentNode._placesView)
new PlacesMenu(event, 'place:folder=UNFILED_BOOKMARKS');"/>
</menu>
<menuseparator/>
<!-- Bookmarks menu items -->
<menuseparator builder="end"
class="hide-if-empty-places-result"/>
<menuitem id="BMB_unsortedBookmarks"
label="&bookmarksMenuButton.unsorted.label;"
oncommand="PlacesCommandHook.showPlacesOrganizer('UnfiledBookmarks');"
class="menuitem-iconic"/>
</menupopup>
</toolbarbutton>

View File

@ -40,6 +40,47 @@
onclick="PlacesCommandHook.showPlacesOrganizer('History'); CustomizableUI.hidePanelForNode(this);"/>
</panelview>
<panelview id="PanelUI-bookmarks" flex="1">
<toolbarbutton id="panelMenuBookmarkThisPage"
label="&bookmarkThisPageCmd.label;"
command="Browser:AddBookmarkAs"
onclick="PanelUI.hide();"/>
<toolbarseparator/>
<toolbarbutton id="panelMenu_showAllBookmarks"
label="&showAllBookmarks2.label;"
command="Browser:ShowAllBookmarks"
onclick="PanelUI.hide();"/>
<toolbarbutton id="panelMenu_viewBookmarksSidebar"
label="&viewBookmarksSidebar2.label;"
oncommand="toggleSidebar('viewBookmarksSidebar'); PanelUI.hide();">
<observes element="viewBookmarksSidebar" attribute="checked"/>
</toolbarbutton>
<toolbarbutton id="panelMenu_viewBookmarksToolbar"
label="&viewBookmarksToolbar.label;"
type="checkbox"
toolbarId="PersonalToolbar"
oncommand="onViewToolbarCommand(event); PanelUI.hide();"/>
<toolbarseparator/>
<toolbarbutton id="panelMenu_bookmarksToolbar"
label="&personalbarCmd.label;"
oncommand="PlacesCommandHook.showPlacesOrganizer('BookmarksToolbar'); PanelUI.hide();"/>
<toolbarbutton id="panelMenu_unsortedBookmarks"
label="&unsortedBookmarksCmd.label;"
oncommand="PlacesCommandHook.showPlacesOrganizer('UnfiledBookmarks'); PanelUI.hide();"/>
<toolbarseparator/>
<toolbaritem id="panelMenu_bookmarksMenu"
flex="1"
orient="vertical"
smoothscroll="false"
onclick="if (event.button == 1) BookmarkingUI.onPanelMenuViewCommand(event, this._placesView);"
oncommand="BookmarkingUI.onPanelMenuViewCommand(event, this._placesView);"
flatList="true"
tooltip="bhTooltip">
<!-- bookmarks menu items -->
</toolbaritem>
</panelview>
<panelview id="PanelUI-feeds" flex="1" oncommand="FeedHandler.subscribeToFeed(null, event);"></panelview>
<panelview id="PanelUI-help" flex="1">

View File

@ -140,6 +140,7 @@ let CustomizableUIInternal = {
});
this.registerArea(CustomizableUI.AREA_NAVBAR, {
legacy: true,
anchor: "nav-bar-overflow-button",
type: CustomizableUI.TYPE_TOOLBAR,
overflowable: true,
defaultPlacements: [

View File

@ -1745,3 +1745,157 @@ PlacesMenu.prototype = {
}
};
function PlacesPanelMenuView(aPlace, aViewId, aRootId) {
this._viewElt = document.getElementById(aViewId);
this._rootElt = document.getElementById(aRootId);
this._viewElt._placesView = this;
PlacesViewBase.call(this, aPlace);
}
PlacesPanelMenuView.prototype = {
__proto__: PlacesViewBase.prototype,
QueryInterface: function PAMV_QueryInterface(aIID) {
return PlacesViewBase.prototype.QueryInterface.apply(this, arguments);
},
uninit: function PAMV_uninit() {
PlacesViewBase.prototype.uninit.apply(this, arguments);
},
_insertNewItem:
function PAMV__insertNewItem(aChild, aBefore) {
this._domNodes.delete(aChild);
let type = aChild.type;
let button;
if (type == Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR) {
button = document.createElement("toolbarseparator");
}
else {
button = document.createElement("toolbarbutton");
button.className = "bookmark-item";
button.setAttribute("label", aChild.title);
let icon = aChild.icon;
if (icon)
button.setAttribute("image", icon);
if (PlacesUtils.containerTypes.indexOf(type) != -1) {
button.setAttribute("container", "true");
if (PlacesUtils.nodeIsQuery(aChild)) {
button.setAttribute("query", "true");
if (PlacesUtils.nodeIsTagQuery(aChild))
button.setAttribute("tagContainer", "true");
}
else if (PlacesUtils.nodeIsFolder(aChild)) {
PlacesUtils.livemarks.getLivemark(
{ id: aChild.itemId },
function (aStatus, aLivemark) {
if (Components.isSuccessCode(aStatus)) {
button.setAttribute("livemark", "true");
this.controller.cacheLivemarkInfo(aChild, aLivemark);
}
}.bind(this)
);
}
}
else if (PlacesUtils.nodeIsURI(aChild)) {
button.setAttribute("scheme",
PlacesUIUtils.guessUrlSchemeForUI(aChild.uri));
}
}
button._placesNode = aChild;
if (!this._domNodes.has(aChild))
this._domNodes.set(aChild, button);
this._rootElt.insertBefore(button, aBefore);
},
nodeInserted:
function PAMV_nodeInserted(aParentPlacesNode, aPlacesNode, aIndex) {
let parentElt = this._getDOMNodeForPlacesNode(aParentPlacesNode);
if (parentElt != this._rootElt)
return;
let children = this._rootElt.childNodes;
this._insertNewItem(aPlacesNode,
aIndex < children.length ? children[aIndex] : null);
},
nodeRemoved:
function PAMV_nodeRemoved(aParentPlacesNode, aPlacesNode, aIndex) {
let parentElt = this._getDOMNodeForPlacesNode(aParentPlacesNode);
if (parentElt != this._rootElt)
return;
let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
this._removeChild(elt);
},
nodeMoved:
function PAMV_nodeMoved(aPlacesNode,
aOldParentPlacesNode, aOldIndex,
aNewParentPlacesNode, aNewIndex) {
let parentElt = this._getDOMNodeForPlacesNode(aNewParentPlacesNode);
if (parentElt != this._rootElt)
return;
let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
this._removeChild(elt);
this._rootElt.insertBefore(elt, this._rootElt.childNodes[aNewIndex]);
},
nodeAnnotationChanged:
function PAMV_nodeAnnotationChanged(aPlacesNode, aAnno) {
let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
// There's no UI representation for the root node.
if (elt == this._rootElt)
return;
if (elt.parentNode != this._rootElt)
return;
// All livemarks have a feedURI, so use it as our indicator.
if (aAnno == PlacesUtils.LMANNO_FEEDURI) {
elt.setAttribute("livemark", true);
PlacesUtils.livemarks.getLivemark(
{ id: aPlacesNode.itemId },
function (aStatus, aLivemark) {
if (Components.isSuccessCode(aStatus)) {
this.controller.cacheLivemarkInfo(aPlacesNode, aLivemark);
this.invalidateContainer(aPlacesNode);
}
}.bind(this)
);
}
},
nodeTitleChanged: function PAMV_nodeTitleChanged(aPlacesNode, aNewTitle) {
let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
// There's no UI representation for the root node.
if (elt == this._rootElt)
return;
PlacesViewBase.prototype.nodeTitleChanged.apply(this, arguments);
},
invalidateContainer: function PAMV_invalidateContainer(aPlacesNode) {
let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
if (elt != this._rootElt)
return;
// Container is the toolbar itself.
while (this._rootElt.hasChildNodes()) {
this._rootElt.removeChild(this._rootElt.firstChild);
}
for (let i = 0; i < this._resultNode.childCount; ++i) {
this._insertNewItem(this._resultNode.getChild(i), null);
}
}
};

View File

@ -179,7 +179,7 @@ These should match what Safari and other Apple applications use on OS X Lion. --
<!ENTITY bookmarksMenuButton.label "Bookmarks">
<!ENTITY bookmarksMenuButton.tooltip "Display your bookmarks">
<!ENTITY bookmarksMenuButton.unsorted.label "Unsorted Bookmarks">
<!ENTITY viewBookmarksSidebar.label "Show in Sidebar">
<!ENTITY viewBookmarksSidebar2.label "View Bookmarks Sidebar">
<!ENTITY viewBookmarksToolbar.label "View Bookmarks Toolbar">
<!-- LOCALIZATION NOTE (bookmarksSidebarGtkCmd.commandkey): This command
@ -324,7 +324,6 @@ These should match what Safari and other Apple applications use on OS X Lion. --
<!ENTITY showAllHistoryCmd.commandkey "H">
<!ENTITY appMenuCustomize.label "Customize">
<!ENTITY appMenuBookmarks.label "Bookmarks">
<!ENTITY appMenuHistory.label "History">
<!ENTITY appMenuHistory.showAll.label "Show All History">
<!ENTITY appMenuHistory.clearRecent.label "Clear Recent History…">
@ -727,5 +726,7 @@ just addresses the organization to follow, e.g. "This site is run by " -->
<!ENTITY addonBarCloseButton.tooltip "Close Add-on Bar">
<!ENTITY toggleAddonBarCmd.key "/">
<!ENTITY backForwardItem.title "Back/Forward">
<!ENTITY viewBookmarksSidebar.label "Show in Sidebar">
<!ENTITY appMenuBookmarks.label "Bookmarks">
<!-- end of strings to be removed post-Australis -->

View File

@ -465,11 +465,13 @@ menuitem:not([type]):not(.menuitem-tooltip):not(.menuitem-iconic-tooltip) {
}
#bookmarksToolbarFolderMenu,
#BMB_bookmarksToolbar {
#BMB_bookmarksToolbar,
#panelMenu_bookmarksToolbar {
list-style-image: url("chrome://browser/skin/places/bookmarksToolbar.png");
}
#BMB_unsortedBookmarks {
#BMB_unsortedBookmarks,
#panelMenu_unsortedBookmarks {
list-style-image: url("chrome://browser/skin/places/unsortedBookmarks.png");
}

View File

@ -360,11 +360,13 @@ toolbarbutton.bookmark-item > menupopup {
}
#bookmarksToolbarFolderMenu,
#BMB_bookmarksToolbar {
#BMB_bookmarksToolbar,
#panelMenu_bookmarksToolbar {
list-style-image: url("chrome://browser/skin/places/bookmarksToolbar.png");
}
#BMB_unsortedBookmarks {
#BMB_unsortedBookmarks,
#panelMenu_unsortedBookmarks {
list-style-image: url("chrome://browser/skin/places/unfiledBookmarks.png");
}

View File

@ -288,6 +288,13 @@ panelview toolbarbutton:not([disabled]):-moz-any([open],[checked],:hover:active)
transition: none;
}
panelview toolbarseparator {
-moz-appearance: none;
min-height: 0;
border-top: 1px solid ThreeDShadow;
margin: 5px 0;
}
#PanelUI-historyItems > toolbarbutton {
list-style-image: url("chrome://mozapps/skin/places/defaultFavicon.png");
}

View File

@ -1970,12 +1970,14 @@ toolbarbutton.bookmark-item[dragover="true"][open="true"] {
}
#bookmarksToolbarFolderMenu,
#BMB_bookmarksToolbar {
#BMB_bookmarksToolbar,
#panelMenu_bookmarksToolbar {
list-style-image: url("chrome://browser/skin/places/bookmarksToolbar.png");
-moz-image-region: auto;
}
#BMB_unsortedBookmarks {
#BMB_unsortedBookmarks,
#panelMenu_unsortedBookmarks {
list-style-image: url("chrome://browser/skin/places/unsortedBookmarks.png");
-moz-image-region: auto;
}