mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 997288 - Add select tab button to "New [private] tab opened" toasts. r=wesj
This commit is contained in:
parent
91ac240000
commit
21bfe1a799
@ -798,7 +798,7 @@ public abstract class GeckoApp
|
||||
});
|
||||
}
|
||||
|
||||
protected ButtonToast getButtonToast() {
|
||||
public ButtonToast getButtonToast() {
|
||||
if (mToast != null) {
|
||||
return mToast;
|
||||
}
|
||||
|
@ -6,11 +6,13 @@
|
||||
package org.mozilla.gecko.home;
|
||||
|
||||
import org.mozilla.gecko.EditBookmarkDialog;
|
||||
import org.mozilla.gecko.GeckoApp;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoEvent;
|
||||
import org.mozilla.gecko.GeckoProfile;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.ReaderModeUtils;
|
||||
import org.mozilla.gecko.Tab;
|
||||
import org.mozilla.gecko.Tabs;
|
||||
import org.mozilla.gecko.Telemetry;
|
||||
import org.mozilla.gecko.TelemetryContract;
|
||||
@ -21,6 +23,7 @@ import org.mozilla.gecko.home.TopSitesGridView.TopSitesGridContextMenuInfo;
|
||||
import org.mozilla.gecko.util.Clipboard;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.util.UiAsyncTask;
|
||||
import org.mozilla.gecko.widget.ButtonToast;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
@ -176,8 +179,10 @@ abstract class HomeFragment extends Fragment {
|
||||
}
|
||||
|
||||
int flags = Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_BACKGROUND;
|
||||
if (item.getItemId() == R.id.home_open_private_tab)
|
||||
final boolean isPrivate = (item.getItemId() == R.id.home_open_private_tab);
|
||||
if (isPrivate) {
|
||||
flags |= Tabs.LOADURL_PRIVATE;
|
||||
}
|
||||
|
||||
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.CONTEXT_MENU);
|
||||
|
||||
@ -185,8 +190,26 @@ abstract class HomeFragment extends Fragment {
|
||||
|
||||
// Some pinned site items have "user-entered" urls. URLs entered in the PinSiteDialog are wrapped in
|
||||
// a special URI until we can get a valid URL. If the url is a user-entered url, decode the URL before loading it.
|
||||
Tabs.getInstance().loadUrl(decodeUserEnteredUrl(url), flags);
|
||||
Toast.makeText(context, R.string.new_tab_opened, Toast.LENGTH_SHORT).show();
|
||||
final Tab newTab = Tabs.getInstance().loadUrl(decodeUserEnteredUrl(url), flags);
|
||||
final int newTabId = newTab.getId(); // We don't want to hold a reference to the Tab.
|
||||
|
||||
final String message = isPrivate ?
|
||||
getResources().getString(R.string.new_private_tab_opened) :
|
||||
getResources().getString(R.string.new_tab_opened);
|
||||
final GeckoApp geckoApp = (GeckoApp) context;
|
||||
geckoApp.getButtonToast().show(false,
|
||||
message,
|
||||
null,
|
||||
R.drawable.select_opened_tab,
|
||||
new ButtonToast.ToastListener() {
|
||||
@Override
|
||||
public void onButtonClicked() {
|
||||
Tabs.getInstance().selectTab(newTabId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onToastHidden(ButtonToast.ReasonHidden reason) { }
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@
|
||||
We can't use android plural forms, sadly. See bug #753859. -->
|
||||
<!ENTITY num_tabs2 "&formatD; tabs">
|
||||
<!ENTITY new_tab_opened "New tab opened">
|
||||
<!ENTITY new_private_tab_opened "New private tab opened">
|
||||
|
||||
<!ENTITY settings "Settings">
|
||||
<!ENTITY settings_title "Settings">
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 875 B |
Binary file not shown.
After Width: | Height: | Size: 689 B |
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
@ -236,6 +236,7 @@
|
||||
<string name="site_security">&site_security;</string>
|
||||
<string name="close_tab">&close_tab;</string>
|
||||
<string name="new_tab_opened">&new_tab_opened;</string>
|
||||
<string name="new_private_tab_opened">&new_private_tab_opened;</string>
|
||||
<string name="one_tab">&one_tab;</string>
|
||||
<string name="num_tabs">&num_tabs2;</string>
|
||||
<string name="addons">&addons;</string>
|
||||
|
@ -29,7 +29,9 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ButtonToast {
|
||||
@SuppressWarnings("unused")
|
||||
private final static String LOGTAG = "GeckoButtonToast";
|
||||
|
||||
private final static int TOAST_DURATION = 5000;
|
||||
|
||||
private final View mView;
|
||||
@ -37,7 +39,6 @@ public class ButtonToast {
|
||||
private final Button mButton;
|
||||
private final Handler mHideHandler = new Handler();
|
||||
|
||||
private final ToastListener mListener;
|
||||
private final LinkedList<Toast> mQueue = new LinkedList<Toast>();
|
||||
private Toast mCurrentToast;
|
||||
|
||||
@ -70,7 +71,6 @@ public class ButtonToast {
|
||||
|
||||
public ButtonToast(View view) {
|
||||
mView = view;
|
||||
mListener = null;
|
||||
mMessageView = (TextView) mView.findViewById(R.id.toast_message);
|
||||
mButton = (Button) mView.findViewById(R.id.toast_button);
|
||||
mButton.setOnClickListener(new View.OnClickListener() {
|
||||
@ -90,6 +90,13 @@ public class ButtonToast {
|
||||
hide(true, ReasonHidden.STARTUP);
|
||||
}
|
||||
|
||||
public void show(boolean immediate, CharSequence message,
|
||||
CharSequence buttonMessage, int buttonDrawableId,
|
||||
ToastListener listener) {
|
||||
final Drawable d = mView.getContext().getResources().getDrawable(buttonDrawableId);
|
||||
show(false, message, buttonMessage, d, listener);
|
||||
}
|
||||
|
||||
public void show(boolean immediate, CharSequence message,
|
||||
CharSequence buttonMessage, Drawable buttonDrawable,
|
||||
ToastListener listener) {
|
||||
@ -106,10 +113,16 @@ public class ButtonToast {
|
||||
mCurrentToast = t;
|
||||
mButton.setEnabled(true);
|
||||
|
||||
mMessageView.setText(t.message);
|
||||
mButton.setText(t.buttonMessage);
|
||||
mButton.setCompoundDrawablePadding(mView.getContext().getResources().getDimensionPixelSize(R.dimen.toast_button_padding));
|
||||
mButton.setCompoundDrawablesWithIntrinsicBounds(t.buttonDrawable, null, null, null);
|
||||
// Our toast is re-used, so we update all fields to clear any old values.
|
||||
mMessageView.setText(null != t.message ? t.message : "");
|
||||
mButton.setText(null != t.buttonMessage ? t.buttonMessage : "");
|
||||
if (null != t.buttonDrawable) {
|
||||
mButton.setCompoundDrawablePadding(mView.getContext().getResources().getDimensionPixelSize(R.dimen.toast_button_padding));
|
||||
mButton.setCompoundDrawablesWithIntrinsicBounds(t.buttonDrawable, null, null, null);
|
||||
} else {
|
||||
mButton.setCompoundDrawablePadding(0);
|
||||
mButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
||||
}
|
||||
|
||||
mHideHandler.removeCallbacks(mHideRunnable);
|
||||
mHideHandler.postDelayed(mHideRunnable, TOAST_DURATION);
|
||||
|
@ -485,11 +485,16 @@ var BrowserApp = {
|
||||
function(aTarget) {
|
||||
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
|
||||
ContentAreaUtils.urlSecurityCheck(url, aTarget.ownerDocument.nodePrincipal);
|
||||
BrowserApp.addTab(url, { selected: false, parentId: BrowserApp.selectedTab.id });
|
||||
let tab = BrowserApp.addTab(url, { selected: false, parentId: BrowserApp.selectedTab.id });
|
||||
|
||||
let newtabStrings = Strings.browser.GetStringFromName("newtabpopup.opened");
|
||||
let label = PluralForm.get(1, newtabStrings).replace("#1", 1);
|
||||
NativeWindow.toast.show(label, "short");
|
||||
NativeWindow.toast.show(label, "long", {
|
||||
button: {
|
||||
icon: "drawable://select_opened_tab",
|
||||
callback: () => { BrowserApp.selectTab(tab); },
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.openInPrivateTab"),
|
||||
@ -497,11 +502,16 @@ var BrowserApp = {
|
||||
function(aTarget) {
|
||||
let url = NativeWindow.contextmenus._getLinkURL(aTarget);
|
||||
ContentAreaUtils.urlSecurityCheck(url, aTarget.ownerDocument.nodePrincipal);
|
||||
BrowserApp.addTab(url, { selected: false, parentId: BrowserApp.selectedTab.id, isPrivate: true });
|
||||
let tab = BrowserApp.addTab(url, { selected: false, parentId: BrowserApp.selectedTab.id, isPrivate: true });
|
||||
|
||||
let newtabStrings = Strings.browser.GetStringFromName("newprivatetabpopup.opened");
|
||||
let label = PluralForm.get(1, newtabStrings).replace("#1", 1);
|
||||
NativeWindow.toast.show(label, "short");
|
||||
NativeWindow.toast.show(label, "long", {
|
||||
button: {
|
||||
icon: "drawable://select_opened_tab",
|
||||
callback: () => { BrowserApp.selectTab(tab); },
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
NativeWindow.contextmenus.add(Strings.browser.GetStringFromName("contextmenu.copyLink"),
|
||||
@ -1764,12 +1774,20 @@ var NativeWindow = {
|
||||
|
||||
if (aOptions && aOptions.button) {
|
||||
msg.button = {
|
||||
label: aOptions.button.label,
|
||||
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
|
||||
icon: aOptions.button.icon ? resolveGeckoURI(aOptions.button.icon) : null,
|
||||
msg.button.icon = resolveGeckoURI(aOptions.button.icon);
|
||||
};
|
||||
|
||||
this._callbacks[msg.button.id] = aOptions.button.callback;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user