зеркало из https://github.com/mozilla/gecko-dev.git
Bug 732169 - Associate prompts with tabs. r=lucasr
This commit is contained in:
Родитель
767440d5ac
Коммит
34e6f1c0c8
|
@ -63,6 +63,8 @@ public class Tabs implements GeckoEventListener {
|
||||||
|
|
||||||
private static final long PERSIST_TABS_AFTER_MILLISECONDS = 1000 * 5;
|
private static final long PERSIST_TABS_AFTER_MILLISECONDS = 1000 * 5;
|
||||||
|
|
||||||
|
public static final int INVALID_TAB_ID = -1;
|
||||||
|
|
||||||
private static AtomicInteger sTabId = new AtomicInteger(0);
|
private static AtomicInteger sTabId = new AtomicInteger(0);
|
||||||
private volatile boolean mInitialTabsAdded;
|
private volatile boolean mInitialTabsAdded;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ import org.mozilla.gecko.GeckoAppShell;
|
||||||
import org.mozilla.gecko.GeckoEvent;
|
import org.mozilla.gecko.GeckoEvent;
|
||||||
import org.mozilla.gecko.R;
|
import org.mozilla.gecko.R;
|
||||||
import org.mozilla.gecko.util.ThreadUtils;
|
import org.mozilla.gecko.util.ThreadUtils;
|
||||||
|
import org.mozilla.gecko.Tab;
|
||||||
|
import org.mozilla.gecko.Tabs;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -39,7 +41,7 @@ import android.widget.TextView;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Prompt implements OnClickListener, OnCancelListener, OnItemClickListener,
|
public class Prompt implements OnClickListener, OnCancelListener, OnItemClickListener,
|
||||||
PromptInput.OnChangeListener {
|
PromptInput.OnChangeListener, Tabs.OnTabsChangedListener {
|
||||||
private static final String LOGTAG = "GeckoPromptService";
|
private static final String LOGTAG = "GeckoPromptService";
|
||||||
|
|
||||||
private String[] mButtons;
|
private String[] mButtons;
|
||||||
|
@ -55,6 +57,8 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
||||||
private static boolean mInitialized;
|
private static boolean mInitialized;
|
||||||
private static int mInputPaddingSize;
|
private static int mInputPaddingSize;
|
||||||
|
|
||||||
|
private int mTabId = Tabs.INVALID_TAB_ID;
|
||||||
|
|
||||||
public Prompt(Context context, PromptCallback callback) {
|
public Prompt(Context context, PromptCallback callback) {
|
||||||
this(context);
|
this(context);
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
|
@ -105,6 +109,10 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
||||||
choiceMode = ListView.CHOICE_MODE_MULTIPLE;
|
choiceMode = ListView.CHOICE_MODE_MULTIPLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.has("tabId")) {
|
||||||
|
mTabId = message.optInt("tabId", Tabs.INVALID_TAB_ID);
|
||||||
|
}
|
||||||
|
|
||||||
show(title, text, menuitems, choiceMode);
|
show(title, text, menuitems, choiceMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +126,39 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mTabId != Tabs.INVALID_TAB_ID) {
|
||||||
|
Tabs.registerOnTabsChangedListener(this);
|
||||||
|
|
||||||
|
final Tab tab = Tabs.getInstance().getTab(mTabId);
|
||||||
|
if (Tabs.getInstance().getSelectedTab() == tab) {
|
||||||
mDialog.show();
|
mDialog.show();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
mDialog.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabChanged(final Tab tab, final Tabs.TabEvents msg, final Object data) {
|
||||||
|
if (tab != Tabs.getInstance().getTab(mTabId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(msg) {
|
||||||
|
case SELECTED:
|
||||||
|
Log.i(LOGTAG, "Selected");
|
||||||
|
mDialog.show();
|
||||||
|
break;
|
||||||
|
case UNSELECTED:
|
||||||
|
Log.i(LOGTAG, "Unselected");
|
||||||
|
mDialog.hide();
|
||||||
|
break;
|
||||||
|
case LOCATION_CHANGE:
|
||||||
|
Log.i(LOGTAG, "Location change");
|
||||||
|
mDialog.cancel();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void create(String title, String text, PromptListItem[] listItems, int choiceMode)
|
private void create(String title, String text, PromptListItem[] listItems, int choiceMode)
|
||||||
throws IllegalStateException {
|
throws IllegalStateException {
|
||||||
|
@ -140,8 +179,7 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
||||||
if (listItems != null && listItems.length > 0) {
|
if (listItems != null && listItems.length > 0) {
|
||||||
addListItems(builder, listItems, choiceMode);
|
addListItems(builder, listItems, choiceMode);
|
||||||
} else if (!addInputs(builder)) {
|
} else if (!addInputs(builder)) {
|
||||||
// If we failed to add any requested input elements, don't show the dialog
|
throw new IllegalStateException("Could not add inputs to dialog");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int length = mButtons == null ? 0 : mButtons.length;
|
int length = mButtons == null ? 0 : mButtons.length;
|
||||||
|
@ -452,6 +490,10 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
||||||
aReturn.put("guid", mGuid);
|
aReturn.put("guid", mGuid);
|
||||||
} catch(JSONException ex) { }
|
} catch(JSONException ex) { }
|
||||||
|
|
||||||
|
if (mTabId != Tabs.INVALID_TAB_ID) {
|
||||||
|
Tabs.unregisterOnTabsChangedListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
// poke the Gecko thread in case it's waiting for new events
|
// poke the Gecko thread in case it's waiting for new events
|
||||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createNoOpEvent());
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createNoOpEvent());
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,17 @@ function log(msg) {
|
||||||
|
|
||||||
function Prompt(aOptions) {
|
function Prompt(aOptions) {
|
||||||
this.window = "window" in aOptions ? aOptions.window : null;
|
this.window = "window" in aOptions ? aOptions.window : null;
|
||||||
|
|
||||||
this.msg = { async: true };
|
this.msg = { async: true };
|
||||||
|
|
||||||
|
if (this.window) {
|
||||||
|
let window = Services.wm.getMostRecentWindow("navigator:browser");
|
||||||
|
var tab = window.BrowserApp.getTabForWindow(this.window);
|
||||||
|
if (tab) {
|
||||||
|
this.msg.tabId = tab.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (aOptions.priority === 1)
|
if (aOptions.priority === 1)
|
||||||
this.msg.type = "Prompt:ShowTop"
|
this.msg.type = "Prompt:ShowTop"
|
||||||
else
|
else
|
||||||
|
@ -36,8 +45,6 @@ function Prompt(aOptions) {
|
||||||
|
|
||||||
if ("hint" in aOptions && aOptions.hint != null)
|
if ("hint" in aOptions && aOptions.hint != null)
|
||||||
this.msg.hint = aOptions.hint;
|
this.msg.hint = aOptions.hint;
|
||||||
|
|
||||||
let idService = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Prompt.prototype = {
|
Prompt.prototype = {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче