Backed out changeset 5bef1f8045fd (bug 1027137) for breaking talos remote-trobopan

This commit is contained in:
Carsten "Tomcat" Book 2014-07-15 12:23:10 +02:00
parent ced636da75
commit c697516add

View File

@ -15,7 +15,6 @@ import org.mozilla.gecko.util.NativeEventListener;
import org.mozilla.gecko.util.NativeJSObject; import org.mozilla.gecko.util.NativeJSObject;
import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.widget.GeckoPopupMenu; import org.mozilla.gecko.widget.GeckoPopupMenu;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -28,8 +27,6 @@ import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import java.util.Iterator;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.ArrayList; import java.util.ArrayList;
@ -39,11 +36,10 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
private static final String MENU_BUTTON_KEY = "MENU_BUTTON_KEY"; private static final String MENU_BUTTON_KEY = "MENU_BUTTON_KEY";
private static final int DEFAULT_PAGE_ACTIONS_SHOWN = 2; private static final int DEFAULT_PAGE_ACTIONS_SHOWN = 2;
private final Context mContext; private ArrayList<PageAction> mPageActionList;
private final LinearLayout mLayout;
private final List<PageAction> mPageActionList;
private GeckoPopupMenu mPageActionsMenu; private GeckoPopupMenu mPageActionsMenu;
private Context mContext;
private LinearLayout mLayout;
// By default it's two, can be changed by calling setNumberShown(int) // By default it's two, can be changed by calling setNumberShown(int)
private int mMaxVisiblePageActions; private int mMaxVisiblePageActions;
@ -67,8 +63,8 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
mMaxVisiblePageActions = count; mMaxVisiblePageActions = count;
for (int index = 0; index < count; index++) { for(int index = 0; index < count; index++) {
if ((getChildCount() - 1) < index) { if ((this.getChildCount() - 1) < index) {
mLayout.addView(createImageButton()); mLayout.addView(createImageButton());
} }
} }
@ -121,15 +117,14 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
} }
} }
private void addPageAction(final String id, final String title, final String imageData, private void addPageAction(final String id, final String title, final String imageData, final OnPageActionClickListeners mOnPageActionClickListeners, boolean mImportant) {
final OnPageActionClickListeners onPageActionClickListeners, boolean important) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
final PageAction pageAction = new PageAction(id, title, null, onPageActionClickListeners, important); final PageAction pageAction = new PageAction(id, title, null, mOnPageActionClickListeners, mImportant);
int insertAt = mPageActionList.size(); int insertAt = mPageActionList.size();
while (insertAt > 0 && mPageActionList.get(insertAt - 1).isImportant()) { while(insertAt > 0 && mPageActionList.get(insertAt-1).isImportant()) {
insertAt--; insertAt--;
} }
mPageActionList.add(insertAt, pageAction); mPageActionList.add(insertAt, pageAction);
@ -147,11 +142,9 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
private void removePageAction(String id) { private void removePageAction(String id) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
final Iterator<PageAction> iter = mPageActionList.iterator(); for(int i = 0; i < mPageActionList.size(); i++) {
while (iter.hasNext()) { if (mPageActionList.get(i).getID().equals(id)) {
final PageAction pageAction = iter.next(); mPageActionList.remove(i);
if (pageAction.getID().equals(id)) {
iter.remove();
refreshPageActionIcons(); refreshPageActionIcons();
return; return;
} }
@ -161,9 +154,8 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
private ImageButton createImageButton() { private ImageButton createImageButton() {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
final int width = mContext.getResources().getDimensionPixelSize(R.dimen.page_action_button_width);
ImageButton imageButton = new ImageButton(mContext, null, R.style.UrlBar_ImageButton_Icon); ImageButton imageButton = new ImageButton(mContext, null, R.style.UrlBar_ImageButton_Icon);
imageButton.setLayoutParams(new LayoutParams(width, LayoutParams.MATCH_PARENT)); imageButton.setLayoutParams(new LayoutParams(mContext.getResources().getDimensionPixelSize(R.dimen.page_action_button_width), LayoutParams.MATCH_PARENT));
imageButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imageButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageButton.setOnClickListener(this); imageButton.setOnClickListener(this);
imageButton.setOnLongClickListener(this); imageButton.setOnLongClickListener(this);
@ -194,8 +186,6 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
} }
private void setActionForView(final ImageButton view, final PageAction pageAction) { private void setActionForView(final ImageButton view, final PageAction pageAction) {
ThreadUtils.assertOnUiThread();
if (pageAction == null) { if (pageAction == null) {
view.setTag(null); view.setTag(null);
view.setImageDrawable(null); view.setImageDrawable(null);
@ -214,13 +204,12 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
final Resources resources = mContext.getResources(); final Resources resources = mContext.getResources();
for (int i = 0; i < this.getChildCount(); i++) { for(int index = 0; index < this.getChildCount(); index++) {
final ImageButton v = (ImageButton) this.getChildAt(i); final ImageButton v = (ImageButton)this.getChildAt(index);
final PageAction pageAction = getPageActionForViewAt(i); final PageAction pageAction = getPageActionForViewAt(index);
// If there are more page actions than buttons, set the menu icon. // If there are more pageactions then buttons, set the menu icon. Otherwise set the page action's icon if there is a page action.
// Otherwise, set the page action's icon if there is a page action. if (index == (this.getChildCount() - 1) && mPageActionList.size() > mMaxVisiblePageActions) {
if ((i == this.getChildCount() - 1) && (mPageActionList.size() > mMaxVisiblePageActions)) {
v.setTag(MENU_BUTTON_KEY); v.setTag(MENU_BUTTON_KEY);
v.setImageDrawable(resources.getDrawable(R.drawable.icon_pageaction)); v.setImageDrawable(resources.getDrawable(R.drawable.icon_pageaction));
v.setVisibility((pageAction != null) ? View.VISIBLE : View.GONE); v.setVisibility((pageAction != null) ? View.VISIBLE : View.GONE);
@ -244,12 +233,12 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
* and hence we maintain the insertion order of the child Views which is essentially the reverse of their index * and hence we maintain the insertion order of the child Views which is essentially the reverse of their index
*/ */
final int buttonIndex = (this.getChildCount() - 1) - index; int buttonIndex = (this.getChildCount() - 1) - index;
int totalVisibleButtons = ((mPageActionList.size() < this.getChildCount()) ? mPageActionList.size() : this.getChildCount());
if (mPageActionList.size() > buttonIndex) { if (mPageActionList.size() > buttonIndex) {
// Return the pageactions starting from the end of the list for the number of visible pageactions. // Return the pageactions starting from the end of the list for the number of visible pageactions.
final int buttonCount = Math.min(mPageActionList.size(), getChildCount()); return mPageActionList.get((mPageActionList.size() - totalVisibleButtons) + buttonIndex);
return mPageActionList.get((mPageActionList.size() - buttonCount) + buttonIndex);
} }
return null; return null;
} }
@ -257,7 +246,8 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
private PageAction getPageActionWithId(String id) { private PageAction getPageActionWithId(String id) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
for (PageAction pageAction : mPageActionList) { for(int i = 0; i < mPageActionList.size(); i++) {
PageAction pageAction = mPageActionList.get(i);
if (pageAction.getID().equals(id)) { if (pageAction.getID().equals(id)) {
return pageAction; return pageAction;
} }
@ -265,17 +255,17 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
return null; return null;
} }
private void showMenu(View pageActionButton, int toShow) { private void showMenu(View mPageActionButton, int toShow) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
if (mPageActionsMenu == null) { if (mPageActionsMenu == null) {
mPageActionsMenu = new GeckoPopupMenu(pageActionButton.getContext(), pageActionButton); mPageActionsMenu = new GeckoPopupMenu(mPageActionButton.getContext(), mPageActionButton);
mPageActionsMenu.inflate(0); mPageActionsMenu.inflate(0);
mPageActionsMenu.setOnMenuItemClickListener(new GeckoPopupMenu.OnMenuItemClickListener() { mPageActionsMenu.setOnMenuItemClickListener(new GeckoPopupMenu.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId(); int id = item.getItemId();
for (int i = 0; i < mPageActionList.size(); i++) { for(int i = 0; i < mPageActionList.size(); i++) {
PageAction pageAction = mPageActionList.get(i); PageAction pageAction = mPageActionList.get(i);
if (pageAction.key() == id) { if (pageAction.key() == id) {
pageAction.onClick(); pageAction.onClick();
@ -289,10 +279,12 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
Menu menu = mPageActionsMenu.getMenu(); Menu menu = mPageActionsMenu.getMenu();
menu.clear(); menu.clear();
for (int i = 0; i < mPageActionList.size() && i < toShow; i++) { for(int i = 0; i < mPageActionList.size(); i++) {
PageAction pageAction = mPageActionList.get(i); if (i < toShow) {
MenuItem item = menu.add(Menu.NONE, pageAction.key(), Menu.NONE, pageAction.getTitle()); PageAction pageAction = mPageActionList.get(i);
item.setIcon(pageAction.getDrawable()); MenuItem item = menu.add(Menu.NONE, pageAction.key(), Menu.NONE, pageAction.getTitle());
item.setIcon(pageAction.getDrawable());
}
} }
mPageActionsMenu.show(); mPageActionsMenu.show();
} }