Bug 1354536 - Part 3 - When the Library view is shown, populate a new 'Recent Highlights' section with at most 12 items as in about:newtab. r=Gijs

MozReview-Commit-ID: Bs1RzL0uewH
This commit is contained in:
Mike de Boer
2017-09-19 16:17:16 +02:00
parent 16f74e0a53
commit 4e3ec7ecb7
5 changed files with 139 additions and 2 deletions

View File

@@ -1276,6 +1276,8 @@ pref("browser.newtabpage.activity-stream.enabled", true);
pref("browser.newtabpage.activity-stream.prerender", true);
pref("browser.newtabpage.activity-stream.aboutHome.enabled", true);
pref("browser.library.activity-stream.enabled", true);
// Enable the DOM fullscreen API.
pref("full-screen-api.enabled", true);

View File

@@ -505,6 +505,7 @@ toolbar:not(#TabsToolbar) > #personal-bookmarks {
#appMenu_historyMenu > .bookmark-item,
#appMenu-library-recentlyClosedTabs > .panel-subview-body > .bookmark-item,
#appMenu-library-recentlyClosedWindows > .panel-subview-body > .bookmark-item,
#appMenu-library-recentHighlights > .bookmark-item,
#panelMenu_bookmarksMenu > .bookmark-item {
max-width: none;
}

View File

@@ -721,6 +721,16 @@
label="&appMenuRemoteTabs.label;"
closemenu="none"
oncommand="PanelUI.showSubView('PanelUI-remotetabs', this)"/>
<toolbarseparator/>
<label value="&appMenuRecentHighlights.label;"
class="subview-subheader"/>
<toolbaritem id="appMenu-library-recentHighlights"
orient="vertical"
smoothscroll="false"
flatList="true"
tooltip="bhTooltip">
<!-- Recent Highlights will go here -->
</toolbaritem>
</vbox>
</panelview>

View File

@@ -2,10 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
XPCOMUtils.defineLazyModuleGetter(this, "ScrollbarSampler",
"resource:///modules/ScrollbarSampler.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AppMenuNotifications",
"resource://gre/modules/AppMenuNotifications.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NewTabUtils",
"resource://gre/modules/NewTabUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ScrollbarSampler",
"resource:///modules/ScrollbarSampler.jsm");
/**
* Maintains the state and dispatches events for the main menu panel.
@@ -25,6 +27,7 @@ const PanelUI = {
mainView: "appMenu-mainView",
multiView: "appMenu-multiView",
helpView: "PanelUI-helpView",
libraryView: "appMenu-libraryView",
menuButton: "PanelUI-menu-button",
panel: "appMenu-popup",
notificationPanel: "appMenu-notification-popup",
@@ -75,6 +78,12 @@ const PanelUI = {
window.addEventListener("MozDOMFullscreen:Exited", this);
}
XPCOMUtils.defineLazyPreferenceGetter(this, "libraryRecentHighlightsEnabled",
"browser.library.activity-stream.enabled", false, (pref, previousValue, newValue) => {
if (!newValue)
this.clearLibraryRecentHighlights();
});
window.addEventListener("activate", this);
window.matchMedia("(-moz-overlay-scrollbars)").addListener(this._overlayScrollListenerBoundFn);
CustomizableUI.addListener(this);
@@ -150,6 +159,7 @@ const PanelUI = {
window.matchMedia("(-moz-overlay-scrollbars)").removeListener(this._overlayScrollListenerBoundFn);
CustomizableUI.removeListener(this);
this._overlayScrollListenerBoundFn = null;
this.libraryView.removeEventListener("ViewShowing", this);
},
/**
@@ -293,6 +303,11 @@ const PanelUI = {
case "activate":
this._updateNotifications();
break;
case "ViewShowing":
if (aEvent.target == this.libraryView) {
this.onLibraryViewShowing(aEvent.target);
}
break;
}
},
@@ -384,6 +399,8 @@ const PanelUI = {
return;
}
this.ensureLibraryInitialized(viewNode);
let container = aAnchor.closest("panelmultiview,photonpanelmultiview");
if (container) {
container.showSubView(aViewId, aAnchor);
@@ -481,6 +498,95 @@ const PanelUI = {
}
},
/**
* Sets up the event listener for when the Library view is shown.
*
* @param {panelview} viewNode The library view.
*/
ensureLibraryInitialized(viewNode) {
if (viewNode != this.libraryView || viewNode._initialized)
return;
viewNode._initialized = true;
viewNode.addEventListener("ViewShowing", this);
},
/**
* When the Library view is showing, we can start fetching and populating the
* list of Recent Highlights.
* This is done asynchronously and may finish when the view is already visible.
*
* @param {panelview} viewNode The library view.
*/
async onLibraryViewShowing(viewNode) {
if (this._loadingRecentHighlights) {
return;
}
this._loadingRecentHighlights = true;
// Since the library is the first view shown, we don't want to add a blocker
// to the event, which would make PanelMultiView wait to show it.
let container = this.clearLibraryRecentHighlights();
if (!this.libraryRecentHighlightsEnabled) {
this._loadingRecentHighlights = false;
return;
}
let highlights = await NewTabUtils.activityStreamLinks.getHighlights({ withFavicons: true });
// If there's nothing to display, or the panel is already hidden, get out.
if (!highlights.length || viewNode.panelMultiView.getAttribute("panelopen") != "true") {
this._loadingRecentHighlights = false;
return;
}
container.hidden = container.previousSibling.hidden =
container.previousSibling.previousSibling.hidden = false;
let fragment = document.createDocumentFragment();
for (let highlight of highlights) {
let button = document.createElement("toolbarbutton");
button.classList.add("subviewbutton", "highlight", "subviewbutton-iconic", "bookmark-item");
let title = highlight.title || highlight.url;
button.setAttribute("label", title);
button.setAttribute("tooltiptext", title);
button.setAttribute("type", "highlight-" + highlight.type);
button.setAttribute("onclick", "PanelUI.onLibraryHighlightClick(event)");
if (highlight.favicon) {
button.setAttribute("image", highlight.favicon);
}
button._highlight = highlight;
fragment.appendChild(button);
}
container.appendChild(fragment);
this._loadingRecentHighlights = false;
},
/**
* Remove all the nodes from the 'Recent Highlights' section and hide it as well.
*/
clearLibraryRecentHighlights() {
let container = document.getElementById("appMenu-library-recentHighlights")
while (container.firstChild) {
container.firstChild.remove();
}
container.hidden = container.previousSibling.hidden =
container.previousSibling.previousSibling.hidden = true;
return container;
},
/**
* Event handler; invoked when an item of the Recent Highlights is clicked.
*
* @param {MouseEvent} event Click event, originating from the Highlight.
*/
onLibraryHighlightClick(event) {
let button = event.target;
if (event.button > 1 || !button._highlight) {
return;
}
window.openUILink(button._highlight.url, event);
},
/**
* NB: The enable- and disableSingleSubviewPanelAnimations methods only
* affect the hiding/showing animations of single-subview panels (tempPanel

View File

@@ -1306,6 +1306,24 @@ panelview .toolbarbutton-1,
margin-inline-start: 10px;
}
.subviewbutton[type="highlight-bookmark"]::after {
content: url("chrome://browser/skin/bookmark-hollow.svg");
}
.subviewbutton[type="highlight-history"]::after {
content: url("chrome://browser/skin/history.svg");
}
.subviewbutton[type="highlight-bookmark"]::after,
.subviewbutton[type="highlight-history"]::after {
-moz-context-properties: fill;
fill: GrayText;
float: right;
opacity: .5;
/* Centers the icon and resizes it to 12px square. */
transform: translateY(2px) scaleX(.75);
}
/* This is a <label> but it should fit in with the menu font- and colorwise. */
#PanelUI-characterEncodingView-autodetect-label {
font: menu;