Bug 618715 - Make bookmark star toggle async [r=mfinkle]

--HG--
extra : rebase_source : 0376e72499339168f6e42cbaa3311ab5c809ab33
This commit is contained in:
Matt Brubeck 2010-12-30 09:58:31 -08:00
parent 0a419b41f8
commit 82044fd4d7
3 changed files with 52 additions and 35 deletions

View File

@ -1048,23 +1048,32 @@ var BrowserUI = {
break;
case "cmd_star":
{
let bookmarkURI = browser.currentURI;
let autoClose = false;
BookmarkPopup.toggle();
if (!this.starButton.hasAttribute("starred")) {
this.starButton.setAttribute("starred", "true");
BookmarkPopup.autoHide();
}
if (PlacesUtils.getMostRecentBookmarkForURI(bookmarkURI) == -1) {
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();
// autoclose the bookmark popup
autoClose = true;
}
// Show/hide bookmark popup
BookmarkPopup.toggle(autoClose);
// 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();
}

View File

@ -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.");
Browser.closeTab(gCurrentTest._currentTab);
runNextTest();
}, false);
}
});

View File

@ -62,12 +62,15 @@ gTests.push({
let starbutton = document.getElementById("tool-star");
starbutton.click();
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");
}, false);
},
onBookmarksReady: function() {