Bug 942270 - Gingerbread compatibility of GeckoActionView. r=margaret

This commit is contained in:
Wes Johnston 2014-03-26 10:18:02 -07:00
parent 83aa1d4341
commit f004248966
5 changed files with 35 additions and 21 deletions

View File

@ -43,6 +43,7 @@ import org.mozilla.gecko.home.HomePager;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.SearchEngine;
import org.mozilla.gecko.menu.GeckoMenu;
import org.mozilla.gecko.menu.GeckoMenuItem;
import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.prompts.Prompt;
import org.mozilla.gecko.prompts.PromptListItem;
@ -2076,7 +2077,7 @@ abstract public class BrowserApp extends GeckoApp
// Action providers are available only ICS+.
if (Build.VERSION.SDK_INT >= 14) {
MenuItem share = mMenu.findItem(R.id.share);
GeckoMenuItem share = (GeckoMenuItem) mMenu.findItem(R.id.share);
GeckoActionProvider provider = new GeckoActionProvider(this);
share.setActionProvider(provider);
}
@ -2210,7 +2211,7 @@ abstract public class BrowserApp extends GeckoApp
// Action providers are available only ICS+.
if (Build.VERSION.SDK_INT >= 14) {
GeckoActionProvider provider = (GeckoActionProvider) share.getActionProvider();
final GeckoActionProvider provider = ((GeckoMenuItem) share).getGeckoActionProvider();
if (provider != null) {
Intent shareIntent = provider.getIntent();

View File

@ -8,6 +8,7 @@ import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.R;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.ThreadUtils.AssertBehavior;
import org.mozilla.gecko.widget.GeckoActionProvider;
import android.content.ComponentName;
import android.content.Context;
@ -542,7 +543,7 @@ public class GeckoMenu extends ListView
close();
} else if (item.hasSubMenu()) {
// Refresh the submenu for the provider.
ActionProvider provider = item.getActionProvider();
GeckoActionProvider provider = item.getGeckoActionProvider();
if (provider != null) {
GeckoSubMenu subMenu = new GeckoSubMenu(getContext());
subMenu.setShowIcons(true);
@ -738,7 +739,7 @@ public class GeckoMenu extends ListView
@Override
public int getItemViewType(int position) {
return getItem(position).getActionProvider() == null ? VIEW_TYPE_DEFAULT : VIEW_TYPE_ACTION_MODE;
return getItem(position).getGeckoActionProvider() == null ? VIEW_TYPE_DEFAULT : VIEW_TYPE_ACTION_MODE;
}
@Override

View File

@ -47,7 +47,7 @@ public class GeckoMenuItem implements MenuItem {
private boolean mEnabled = true;
private Drawable mIcon;
private int mIconRes;
private ActionProvider mActionProvider;
private GeckoActionProvider mActionProvider;
private GeckoMenu mMenu;
private GeckoSubMenu mSubMenu;
private MenuItem.OnMenuItemClickListener mMenuItemClickListener = null;
@ -89,15 +89,19 @@ public class GeckoMenuItem implements MenuItem {
return mActionEnum;
}
@Override
public ActionProvider getActionProvider() {
public GeckoActionProvider getGeckoActionProvider() {
return mActionProvider;
}
@Override
public ActionProvider getActionProvider() {
return null;
}
@Override
public View getActionView() {
if (mActionProvider != null && mActionProvider instanceof GeckoActionProvider) {
return ((GeckoActionProvider) mActionProvider).getView();
if (mActionProvider != null) {
return mActionProvider.getView();
}
return mActionView;
@ -204,10 +208,13 @@ public class GeckoMenuItem implements MenuItem {
@Override
public MenuItem setActionProvider(ActionProvider actionProvider) {
return this;
}
public MenuItem setActionProvider(GeckoActionProvider actionProvider) {
mActionProvider = actionProvider;
if (mActionProvider != null && mActionProvider instanceof GeckoActionProvider) {
GeckoActionProvider provider = (GeckoActionProvider) mActionProvider;
provider.setOnTargetSelectedListener(new GeckoActionProvider.OnTargetSelectedListener() {
if (mActionProvider != null) {
actionProvider.setOnTargetSelectedListener(new GeckoActionProvider.OnTargetSelectedListener() {
@Override
public void onTargetSelected() {
mMenu.close();

View File

@ -12,7 +12,6 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.view.ActionProvider;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.SubMenu;
@ -23,7 +22,7 @@ import android.text.TextUtils;
import java.util.ArrayList;
import java.util.HashMap;
public class GeckoActionProvider extends ActionProvider {
public class GeckoActionProvider {
private static int MAX_HISTORY_SIZE = 2;
/**
@ -85,11 +84,9 @@ public class GeckoActionProvider extends ActionProvider {
}
public GeckoActionProvider(Context context) {
super(context);
mContext = context;
}
@Override
public View onCreateActionView() {
// Create the view and set its data model.
ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName);
@ -121,12 +118,10 @@ public class GeckoActionProvider extends ActionProvider {
return onCreateActionView();
}
@Override
public boolean hasSubMenu() {
return true;
}
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
// Clear since the order of items may change.
subMenu.clear();

View File

@ -8391,9 +8391,19 @@ HTMLContextMenuItem.prototype = Object.create(ContextMenuItem.prototype, {
// If this is a menu item, show a new context menu with the submenu in it
if (elt instanceof Ci.nsIDOMHTMLMenuElement) {
try {
NativeWindow.contextmenus.menuitems = [];
NativeWindow.contextmenus._addHTMLContextMenuItemsForMenu(elt, target);
NativeWindow.contextmenus._innerShow(target);
NativeWindow.contextmenus.menus = {};
let elt = this.menuElementRef.get();
let target = this.targetElementRef.get();
if (!elt) {
return;
}
var items = NativeWindow.contextmenus._getHTMLContextMenuItemsForMenu(elt, target);
if (items.length > 0) {
NativeWindow.contextmenus._addMenuItems(items, "link");
}
} catch(ex) {
Cu.reportError(ex);
}