mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 1216051 - Delegated NativeWindow.toast to Snackbar API. r=sebastian
--HG-- extra : transplant_source : %00%E9%92n%0E%08%E3%13z%F1o%7F%89%ED%7C%1C%3E%12%B0_
This commit is contained in:
parent
6bc52e91c7
commit
375337849c
@ -669,19 +669,6 @@ public abstract class GeckoApp
|
||||
} else if ("SystemUI:Visibility".equals(event)) {
|
||||
setSystemUiVisible(message.getBoolean("visible"));
|
||||
|
||||
} else if ("Toast:Show".equals(event)) {
|
||||
final String msg = message.getString("message");
|
||||
final String duration = message.getString("duration");
|
||||
final NativeJSObject button = message.optObject("button", null);
|
||||
if (button != null) {
|
||||
final String label = button.optString("label", "");
|
||||
final String icon = button.optString("icon", "");
|
||||
final String id = button.optString("id", "");
|
||||
showButtonToast(msg, duration, label, icon, id);
|
||||
} else {
|
||||
showNormalToast(msg, duration);
|
||||
}
|
||||
|
||||
} else if ("ToggleChrome:Focus".equals(event)) {
|
||||
focusChrome();
|
||||
|
||||
@ -850,21 +837,6 @@ public abstract class GeckoApp
|
||||
});
|
||||
}
|
||||
|
||||
public void showNormalToast(final String message, final String duration) {
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast toast;
|
||||
if (duration.equals("long")) {
|
||||
toast = Toast.makeText(GeckoApp.this, message, Toast.LENGTH_LONG);
|
||||
} else {
|
||||
toast = Toast.makeText(GeckoApp.this, message, Toast.LENGTH_SHORT);
|
||||
}
|
||||
toast.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ButtonToast getButtonToast() {
|
||||
if (mToast != null) {
|
||||
return mToast;
|
||||
@ -1364,7 +1336,6 @@ public abstract class GeckoApp
|
||||
"Share:Text",
|
||||
"Snackbar:Show",
|
||||
"SystemUI:Visibility",
|
||||
"Toast:Show",
|
||||
"ToggleChrome:Focus",
|
||||
"ToggleChrome:Hide",
|
||||
"ToggleChrome:Show",
|
||||
@ -2189,7 +2160,6 @@ public abstract class GeckoApp
|
||||
"Session:StatePurged",
|
||||
"Share:Text",
|
||||
"SystemUI:Visibility",
|
||||
"Toast:Show",
|
||||
"ToggleChrome:Focus",
|
||||
"ToggleChrome:Hide",
|
||||
"ToggleChrome:Show",
|
||||
|
@ -2268,8 +2268,6 @@ var NativeWindow = {
|
||||
init: function() {
|
||||
Services.obs.addObserver(this, "Menu:Clicked", false);
|
||||
Services.obs.addObserver(this, "Doorhanger:Reply", false);
|
||||
Services.obs.addObserver(this, "Toast:Click", false);
|
||||
Services.obs.addObserver(this, "Toast:Hidden", false);
|
||||
this.contextmenus.init();
|
||||
},
|
||||
|
||||
@ -2288,38 +2286,6 @@ var NativeWindow = {
|
||||
});
|
||||
},
|
||||
|
||||
toast: {
|
||||
_callbacks: {},
|
||||
show: function(aMessage, aDuration, aOptions) {
|
||||
let msg = {
|
||||
type: "Toast:Show",
|
||||
message: aMessage,
|
||||
duration: aDuration
|
||||
};
|
||||
|
||||
if (aOptions && aOptions.button) {
|
||||
msg.button = {
|
||||
id: uuidgen.generateUUID().toString(),
|
||||
};
|
||||
|
||||
// null is badly handled by the receiver, so try to avoid including nulls.
|
||||
if (aOptions.button.label) {
|
||||
msg.button.label = aOptions.button.label;
|
||||
}
|
||||
|
||||
if (aOptions.button.icon) {
|
||||
// If the caller specified a button, make sure we convert any chrome urls
|
||||
// to jar:jar urls so that the frontend can show them
|
||||
msg.button.icon = resolveGeckoURI(aOptions.button.icon);
|
||||
};
|
||||
|
||||
this._callbacks[msg.button.id] = aOptions.button.callback;
|
||||
}
|
||||
|
||||
Messaging.sendRequest(msg);
|
||||
}
|
||||
},
|
||||
|
||||
menu: {
|
||||
_callbacks: [],
|
||||
_menuId: 1,
|
||||
@ -2432,14 +2398,6 @@ var NativeWindow = {
|
||||
if (aTopic == "Menu:Clicked") {
|
||||
if (this.menu._callbacks[aData])
|
||||
this.menu._callbacks[aData]();
|
||||
} else if (aTopic == "Toast:Click") {
|
||||
if (this.toast._callbacks[aData]) {
|
||||
this.toast._callbacks[aData]();
|
||||
delete this.toast._callbacks[aData];
|
||||
}
|
||||
} else if (aTopic == "Toast:Hidden") {
|
||||
if (this.toast._callbacks[aData])
|
||||
delete this.toast._callbacks[aData];
|
||||
} else if (aTopic == "Doorhanger:Reply") {
|
||||
let data = JSON.parse(aData);
|
||||
let reply_id = data["callback"];
|
||||
@ -3135,7 +3093,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "PageActions",
|
||||
|
||||
// These alias to the old, deprecated NativeWindow interfaces
|
||||
[
|
||||
["pageactions", "resource://gre/modules/PageActions.jsm", "PageActions"]
|
||||
["pageactions", "resource://gre/modules/PageActions.jsm", "PageActions"],
|
||||
["toast", "resource://gre/modules/Snackbars.jsm", "Snackbars"]
|
||||
].forEach(item => {
|
||||
let [name, script, exprt] = item;
|
||||
|
||||
|
@ -22,6 +22,12 @@ var Snackbars = {
|
||||
LENGTH_SHORT: LENGTH_SHORT,
|
||||
|
||||
show: function(aMessage, aDuration, aOptions) {
|
||||
|
||||
// Takes care of the deprecated toast calls
|
||||
if (typeof aDuration === "string") {
|
||||
[aDuration, aOptions] = migrateToastIfNeeded(aDuration, aOptions);
|
||||
}
|
||||
|
||||
let msg = {
|
||||
type: 'Snackbar:Show',
|
||||
message: aMessage,
|
||||
@ -41,3 +47,22 @@ var Snackbars = {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function migrateToastIfNeeded(aDuration, aOptions) {
|
||||
let duration;
|
||||
if (aDuration === "long") {
|
||||
duration = LENGTH_LONG;
|
||||
}
|
||||
else {
|
||||
duration = LENGTH_SHORT;
|
||||
}
|
||||
|
||||
let options = {};
|
||||
if (aOptions && aOptions.button) {
|
||||
options.action = {
|
||||
label: aOptions.button.label,
|
||||
callback: () => aOptions.button.callback(),
|
||||
};
|
||||
}
|
||||
return [duration, options];
|
||||
}
|
Loading…
Reference in New Issue
Block a user