mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 06:35:42 +00:00
Bug 618715 - Make bookmark star toggle async [r=mfinkle]
--HG-- extra : rebase_source : 0376e72499339168f6e42cbaa3311ab5c809ab33
This commit is contained in:
parent
0a419b41f8
commit
82044fd4d7
@ -1048,23 +1048,32 @@ var BrowserUI = {
|
||||
break;
|
||||
case "cmd_star":
|
||||
{
|
||||
let bookmarkURI = browser.currentURI;
|
||||
let autoClose = false;
|
||||
|
||||
if (PlacesUtils.getMostRecentBookmarkForURI(bookmarkURI) == -1) {
|
||||
let bookmarkTitle = browser.contentTitle || bookmarkURI.spec;
|
||||
let bookmarkService = PlacesUtils.bookmarks;
|
||||
let bookmarkId = bookmarkService.insertBookmark(BookmarkList.panel.mobileRoot, bookmarkURI,
|
||||
bookmarkService.DEFAULT_INDEX,
|
||||
bookmarkTitle);
|
||||
this.updateStar();
|
||||
|
||||
// autoclose the bookmark popup
|
||||
autoClose = true;
|
||||
BookmarkPopup.toggle();
|
||||
if (!this.starButton.hasAttribute("starred")) {
|
||||
this.starButton.setAttribute("starred", "true");
|
||||
BookmarkPopup.autoHide();
|
||||
}
|
||||
|
||||
// Show/hide bookmark popup
|
||||
BookmarkPopup.toggle(autoClose);
|
||||
let bookmarkURI = browser.currentURI;
|
||||
PlacesUtils.asyncGetBookmarkIds(bookmarkURI, function (aItemIds) {
|
||||
if (!aItemIds.length) {
|
||||
let bookmarkTitle = browser.contentTitle || bookmarkURI.spec;
|
||||
try {
|
||||
let bookmarkService = PlacesUtils.bookmarks;
|
||||
let bookmarkId = bookmarkService.insertBookmark(BookmarkList.panel.mobileRoot, bookmarkURI,
|
||||
bookmarkService.DEFAULT_INDEX,
|
||||
bookmarkTitle);
|
||||
} catch (e) {
|
||||
// Insert failed; reset the star state.
|
||||
this.updateStar();
|
||||
}
|
||||
|
||||
// XXX Used for browser-chrome tests
|
||||
let event = document.createEvent("Events");
|
||||
event.initEvent("BookmarkCreated", true, false);
|
||||
window.dispatchEvent(event);
|
||||
}
|
||||
}, this);
|
||||
break;
|
||||
}
|
||||
case "cmd_opensearch":
|
||||
@ -1619,24 +1628,27 @@ var BookmarkPopup = {
|
||||
BrowserUI.popPopup(this);
|
||||
},
|
||||
|
||||
show : function show(aAutoClose) {
|
||||
show : function show() {
|
||||
this.box.hidden = false;
|
||||
this.box.anchorTo(BrowserUI.starButton);
|
||||
|
||||
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]);
|
||||
},
|
||||
|
||||
toggle : function toggle(aAutoClose) {
|
||||
autoHide: function autoHide() {
|
||||
if (this._bookmarkPopupTimeout != -1 || this.box.hidden)
|
||||
return;
|
||||
|
||||
this._bookmarkPopupTimeout = setTimeout(function (self) {
|
||||
self._bookmarkPopupTimeout = -1;
|
||||
self.hide();
|
||||
}, 2000, this);
|
||||
},
|
||||
|
||||
toggle : function toggle() {
|
||||
if (this.box.hidden)
|
||||
this.show(aAutoClose);
|
||||
this.show();
|
||||
else
|
||||
this.hide();
|
||||
}
|
||||
|
@ -78,13 +78,15 @@ gTests.push({
|
||||
onPageReady: function() {
|
||||
let starbutton = document.getElementById("tool-star");
|
||||
starbutton.click();
|
||||
window.addEventListener("BookmarkCreated", function(aEvent) {
|
||||
window.removeEventListener(aEvent.type, arguments.callee, false);
|
||||
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
|
||||
ok(bookmark != -1, testURL_01 + " should be added.");
|
||||
|
||||
let bookmark = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_01));
|
||||
ok(bookmark != -1, testURL_01 + " should be added.");
|
||||
Browser.closeTab(gCurrentTest._currentTab);
|
||||
|
||||
Browser.closeTab(gCurrentTest._currentTab);
|
||||
|
||||
runNextTest();
|
||||
runNextTest();
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -62,12 +62,15 @@ gTests.push({
|
||||
let starbutton = document.getElementById("tool-star");
|
||||
starbutton.click();
|
||||
|
||||
let bookmarkItem = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
|
||||
ok(bookmarkItem != -1, testURL_02 + " should be added.");
|
||||
window.addEventListener("BookmarkCreated", function(aEvent) {
|
||||
window.removeEventListener(aEvent.type, arguments.callee, false);
|
||||
let bookmarkItem = PlacesUtils.getMostRecentBookmarkForURI(makeURI(testURL_02));
|
||||
ok(bookmarkItem != -1, testURL_02 + " should be added.");
|
||||
|
||||
// Wait for the bookmarks to load, then do the test
|
||||
window.addEventListener("NavigationPanelShown", gCurrentTest.onBookmarksReady, false);
|
||||
BrowserUI.doCommand("cmd_bookmarks");
|
||||
// Wait for the bookmarks to load, then do the test
|
||||
window.addEventListener("NavigationPanelShown", gCurrentTest.onBookmarksReady, false);
|
||||
BrowserUI.doCommand("cmd_bookmarks");
|
||||
}, false);
|
||||
},
|
||||
|
||||
onBookmarksReady: function() {
|
||||
|
Loading…
Reference in New Issue
Block a user