Bug 701725 - Create "undo close tab" super toast. r=bnicholson

This commit is contained in:
Margaret Leibovic 2014-05-01 16:46:46 -07:00
Родитель aff5786238
Коммит 5b1dc26e36
6 изменённых файлов: 55 добавлений и 7 удалений

Просмотреть файл

@ -11,7 +11,9 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.favicons.Favicons;
import org.mozilla.gecko.fxa.FirefoxAccounts;
@ -302,8 +304,16 @@ public class Tabs implements GeckoEventListener {
closeTab(tab, getNextTab(tab));
}
public synchronized void closeTab(Tab tab, Tab nextTab) {
closeTab(tab, nextTab, false);
}
public synchronized void closeTab(Tab tab, boolean showUndoToast) {
closeTab(tab, getNextTab(tab), showUndoToast);
}
/** Close tab and then select nextTab */
public synchronized void closeTab(final Tab tab, Tab nextTab) {
public synchronized void closeTab(final Tab tab, Tab nextTab, boolean showUndoToast) {
if (tab == null)
return;
@ -318,8 +328,16 @@ public class Tabs implements GeckoEventListener {
tab.onDestroy();
final JSONObject args = new JSONObject();
try {
args.put("tabId", String.valueOf(tabId));
args.put("showUndoToast", showUndoToast);
} catch (JSONException e) {
Log.e(LOGTAG, "Error building Tab:Closed arguments: " + e);
}
// Pass a message to Gecko to update tab state in BrowserApp
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Closed", String.valueOf(tabId)));
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Closed", args.toString()));
}
/** Return the tab that will be selected by default after this one is closed */

Просмотреть файл

@ -17,6 +17,8 @@
<item name="android:layout_gravity">center_vertical</item>
<item name="android:paddingLeft">@dimen/toast_button_padding</item>
<item name="android:layout_marginLeft">8dp</item>
<item name="android:ellipsize">end</item>
<item name="android:maxLines">1</item>
</style>
<style name="ToastButton">

Просмотреть файл

@ -627,6 +627,8 @@
<item name="android:layout_marginBottom">0dp</item>
<item name="android:layout_marginLeft">8dp</item>
<item name="android:layout_marginRight">0dp</item>
<item name="android:ellipsize">end</item>
<item name="android:maxLines">1</item>
</style>
<style name="ToastButton">

Просмотреть файл

@ -366,9 +366,11 @@ class TabsTray extends TwoWayView
TabRow tab = (TabRow)view.getTag();
final int tabId = tab.id;
// Caching this assumes that all rows are the same height
if (mOriginalSize == 0)
if (mOriginalSize == 0) {
mOriginalSize = (isVertical ? view.getHeight() : view.getWidth());
}
animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override
@ -377,7 +379,7 @@ class TabsTray extends TwoWayView
public void onPropertyAnimationEnd() {
Tabs tabs = Tabs.getInstance();
Tab tab = tabs.getTab(tabId);
tabs.closeTab(tab);
tabs.closeTab(tab, true);
}
});

Просмотреть файл

@ -964,7 +964,7 @@ var BrowserApp = {
// Calling this will update the state in BrowserApp after a tab has been
// closed in the Java UI.
_handleTabClosed: function _handleTabClosed(aTab) {
_handleTabClosed: function _handleTabClosed(aTab, aShowUndoToast) {
if (aTab == this.selectedTab)
this.selectedTab = null;
@ -972,8 +972,24 @@ var BrowserApp = {
evt.initUIEvent("TabClose", true, false, window, null);
aTab.browser.dispatchEvent(evt);
// Get a title for the undo close toast. Fall back to the URL if there is no title.
let title = aTab.browser.contentDocument.title || aTab.browser.contentDocument.URL;
aTab.destroy();
this._tabs.splice(this._tabs.indexOf(aTab), 1);
if (aShowUndoToast) {
let message = Strings.browser.formatStringFromName("undoCloseToast.message", [title], 1);
NativeWindow.toast.show(message, "short", {
button: {
label: Strings.browser.GetStringFromName("undoCloseToast.action"),
callback: function() {
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
ss.undoCloseTab(window, 0);
}
}
});
}
},
// Use this method to select a tab from JS. This method sends a message
@ -1503,9 +1519,11 @@ var BrowserApp = {
this._handleTabSelected(this.getTabForId(parseInt(aData)));
break;
case "Tab:Closed":
this._handleTabClosed(this.getTabForId(parseInt(aData)));
case "Tab:Closed": {
let data = JSON.parse(aData);
this._handleTabClosed(this.getTabForId(data.tabId), data.showUndoToast);
break;
}
case "keyword-search":
// This event refers to a search via the URL bar, not a bookmarks

Просмотреть файл

@ -123,6 +123,12 @@ contacts.dontAskAgain=Don't ask again for this site
newtabpopup.opened=New tab opened;#1 new tabs opened
newprivatetabpopup.opened=New private tab opened;#1 new private tabs opened
# Undo close tab toast
# LOCALIZATION NOTE (undoCloseToast.message): This message appears in a toast
# when the user closes a tab. %S is the title of the tab that was closed.
undoCloseToast.message=Closed %S
undoCloseToast.action=Undo
# Offline web applications
offlineApps.ask=Allow %S to store data on your device for offline use?
offlineApps.dontAskAgain=Don't ask again for this site