From 5b1dc26e36a18ba750f0e47c083ba18581d3bfd6 Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Thu, 1 May 2014 16:46:46 -0700 Subject: [PATCH] Bug 701725 - Create "undo close tab" super toast. r=bnicholson --- mobile/android/base/Tabs.java | 22 +++++++++++++++-- .../base/resources/values-v19/styles.xml | 2 ++ .../android/base/resources/values/styles.xml | 2 ++ mobile/android/base/tabspanel/TabsTray.java | 6 +++-- mobile/android/chrome/content/browser.js | 24 ++++++++++++++++--- .../locales/en-US/chrome/browser.properties | 6 +++++ 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/mobile/android/base/Tabs.java b/mobile/android/base/Tabs.java index 7ded0898bd79..16448eb3e20f 100644 --- a/mobile/android/base/Tabs.java +++ b/mobile/android/base/Tabs.java @@ -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 */ diff --git a/mobile/android/base/resources/values-v19/styles.xml b/mobile/android/base/resources/values-v19/styles.xml index 51e2ee56d1b1..356d6e958ed6 100644 --- a/mobile/android/base/resources/values-v19/styles.xml +++ b/mobile/android/base/resources/values-v19/styles.xml @@ -17,6 +17,8 @@ center_vertical @dimen/toast_button_padding 8dp + end + 1