mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 08:35:26 +00:00
Bug 1216114 - Context menu should be attached to url input instead of to the whole BrowserToolbar. r=sebastian
--HG-- extra : transplant_source : %86z%0B%05%B4b%D7%FD%3E%81%D7i%3CbA%8EE%8C%F5%2A
This commit is contained in:
parent
2bccb2b32f
commit
ce48298d03
@ -28,10 +28,8 @@ import org.mozilla.gecko.tabs.TabHistoryController;
|
||||
import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.OnStopListener;
|
||||
import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.OnTitleChangeListener;
|
||||
import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.UpdateFlags;
|
||||
import org.mozilla.gecko.util.Clipboard;
|
||||
import org.mozilla.gecko.util.ColorUtils;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
import org.mozilla.gecko.util.MenuUtils;
|
||||
import org.mozilla.gecko.widget.themed.ThemedFrameLayout;
|
||||
import org.mozilla.gecko.widget.themed.ThemedImageButton;
|
||||
import org.mozilla.gecko.widget.themed.ThemedImageView;
|
||||
@ -46,9 +44,7 @@ import android.graphics.drawable.StateListDrawable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
@ -123,7 +119,6 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout
|
||||
private MenuPopup menuPopup;
|
||||
protected final List<View> focusOrder;
|
||||
|
||||
private OnActivateListener activateListener;
|
||||
private OnFocusChangeListener focusChangeListener;
|
||||
private OnStartEditingListener startEditingListener;
|
||||
private OnStopEditingListener stopEditingListener;
|
||||
@ -222,55 +217,6 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout
|
||||
|
||||
prefs.open();
|
||||
|
||||
setOnClickListener(new Button.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (activateListener != null) {
|
||||
activateListener.onActivate();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
// We don't the context menu while editing or while dragging
|
||||
if (isEditing() || !contextMenuEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: Use MenuUtils.safeSetVisible because some actions might
|
||||
// be on the Page menu
|
||||
|
||||
MenuInflater inflater = activity.getMenuInflater();
|
||||
inflater.inflate(R.menu.titlebar_contextmenu, menu);
|
||||
|
||||
String clipboard = Clipboard.getText();
|
||||
if (TextUtils.isEmpty(clipboard)) {
|
||||
menu.findItem(R.id.pasteandgo).setVisible(false);
|
||||
menu.findItem(R.id.paste).setVisible(false);
|
||||
}
|
||||
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null) {
|
||||
String url = tab.getURL();
|
||||
if (url == null) {
|
||||
menu.findItem(R.id.copyurl).setVisible(false);
|
||||
menu.findItem(R.id.add_to_launcher).setVisible(false);
|
||||
}
|
||||
|
||||
MenuUtils.safeSetVisible(menu, R.id.subscribe, tab.hasFeeds());
|
||||
MenuUtils.safeSetVisible(menu, R.id.add_search_engine, tab.hasOpenSearch());
|
||||
} else {
|
||||
// if there is no tab, remove anything tab dependent
|
||||
menu.findItem(R.id.copyurl).setVisible(false);
|
||||
menu.findItem(R.id.add_to_launcher).setVisible(false);
|
||||
MenuUtils.safeSetVisible(menu, R.id.subscribe, false);
|
||||
MenuUtils.safeSetVisible(menu, R.id.add_search_engine, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
urlDisplayLayout.setOnStopListener(new OnStopListener() {
|
||||
@Override
|
||||
public Tab onStop() {
|
||||
@ -691,7 +637,7 @@ public abstract class BrowserToolbar extends ThemedRelativeLayout
|
||||
}
|
||||
|
||||
public void setOnActivateListener(OnActivateListener listener) {
|
||||
activateListener = listener;
|
||||
urlDisplayLayout.setOnActivateListener(listener);
|
||||
}
|
||||
|
||||
public void setOnCommitListener(OnCommitListener listener) {
|
||||
|
@ -19,12 +19,15 @@ import org.mozilla.gecko.SiteIdentity.SecurityMode;
|
||||
import org.mozilla.gecko.SiteIdentity.MixedMode;
|
||||
import org.mozilla.gecko.SiteIdentity.TrackingMode;
|
||||
import org.mozilla.gecko.Tab;
|
||||
import org.mozilla.gecko.Tabs;
|
||||
import org.mozilla.gecko.animation.PropertyAnimator;
|
||||
import org.mozilla.gecko.animation.ViewHelper;
|
||||
import org.mozilla.gecko.favicons.Favicons;
|
||||
import org.mozilla.gecko.toolbar.BrowserToolbarTabletBase.ForwardButtonAnimation;
|
||||
import org.mozilla.gecko.util.Clipboard;
|
||||
import org.mozilla.gecko.util.ColorUtils;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
import org.mozilla.gecko.util.MenuUtils;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
|
||||
import org.mozilla.gecko.widget.themed.ThemedTextView;
|
||||
@ -39,7 +42,9 @@ import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
@ -141,6 +146,8 @@ public class ToolbarDisplayLayout extends ThemedLinearLayout
|
||||
private final ForegroundColorSpan mDomainColor;
|
||||
private final ForegroundColorSpan mPrivateDomainColor;
|
||||
|
||||
private BrowserToolbar.OnActivateListener mActivateListener;
|
||||
|
||||
public ToolbarDisplayLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setOrientation(HORIZONTAL);
|
||||
@ -232,6 +239,56 @@ public class ToolbarDisplayLayout extends ThemedLinearLayout
|
||||
mLockFadeIn.setDuration(lockAnimDuration);
|
||||
mTitleSlideLeft.setDuration(lockAnimDuration);
|
||||
mTitleSlideRight.setDuration(lockAnimDuration);
|
||||
|
||||
// Context menu
|
||||
mTitle.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
// NOTE: Use MenuUtils.safeSetVisible because some actions might
|
||||
// be on the Page menu
|
||||
MenuInflater inflater = mActivity.getMenuInflater();
|
||||
inflater.inflate(R.menu.titlebar_contextmenu, menu);
|
||||
|
||||
String clipboard = Clipboard.getText();
|
||||
if (TextUtils.isEmpty(clipboard)) {
|
||||
menu.findItem(R.id.pasteandgo).setVisible(false);
|
||||
menu.findItem(R.id.paste).setVisible(false);
|
||||
}
|
||||
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null) {
|
||||
String url = tab.getURL();
|
||||
if (url == null) {
|
||||
menu.findItem(R.id.copyurl).setVisible(false);
|
||||
menu.findItem(R.id.add_to_launcher).setVisible(false);
|
||||
}
|
||||
|
||||
MenuUtils.safeSetVisible(menu, R.id.subscribe, tab.hasFeeds());
|
||||
MenuUtils.safeSetVisible(menu, R.id.add_search_engine, tab.hasOpenSearch());
|
||||
}
|
||||
else {
|
||||
// if there is no tab, remove anything tab dependent
|
||||
menu.findItem(R.id.copyurl).setVisible(false);
|
||||
menu.findItem(R.id.add_to_launcher).setVisible(false);
|
||||
MenuUtils.safeSetVisible(menu, R.id.subscribe, false);
|
||||
MenuUtils.safeSetVisible(menu, R.id.add_search_engine, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Edit activation
|
||||
mTitle.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mActivateListener != null) {
|
||||
mActivateListener.onActivate();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setOnActivateListener(BrowserToolbar.OnActivateListener listener) {
|
||||
mActivateListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user