diff options
author | kingshuk.j@samsung.com <kingshuk.j@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-12 15:18:05 +0000 |
---|---|---|
committer | kingshuk.j@samsung.com <kingshuk.j@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-12 15:19:25 +0000 |
commit | 9952eb43eefab4b9c600a0777b0a5eff0a00e828 (patch) | |
tree | ed258d36abc107d8950f671586e924b6f5174da3 /content | |
parent | 49975655d151425953af95e510244a7b0f8a5e9b (diff) | |
download | chromium_src-9952eb43eefab4b9c600a0777b0a5eff0a00e828.zip chromium_src-9952eb43eefab4b9c600a0777b0a5eff0a00e828.tar.gz chromium_src-9952eb43eefab4b9c600a0777b0a5eff0a00e828.tar.bz2 |
Simplify PastePopupMenu delegate interface and layout attributes
Remove redundant calls to canPaste() in PastePopupMenu. Inhibit calls to show
PastePopupMenu if clipboard is empty. Removed unwanted layout attributes to
fix the greying of the PastePopupMenu when diplayed beside the insertion
handler.
BUG=400705
Review URL: https://codereview.chromium.org/449033002
Cr-Commit-Position: refs/heads/master@{#288973}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288973 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java | 13 | ||||
-rw-r--r-- | content/public/android/java/src/org/chromium/content/browser/input/PastePopupMenu.java | 67 |
2 files changed, 26 insertions, 54 deletions
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java index d02766d..6e34a3f 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java @@ -2438,7 +2438,7 @@ public class ContentViewCore @SuppressWarnings("unused") @CalledByNative private void showPastePopup(int xDip, int yDip) { - if (!mHasInsertion) return; + if (!mHasInsertion || !canPaste()) return; final float contentOffsetYPix = mRenderCoordinates.getContentOffsetYPix(); getPastePopup().showAt( (int) mRenderCoordinates.fromDipToPix(xDip), @@ -2453,16 +2453,17 @@ public class ContentViewCore mImeAdapter.paste(); hideTextHandles(); } - public boolean canPaste() { - if (!mFocusedNodeEditable) return false; - return ((ClipboardManager) mContext.getSystemService( - Context.CLIPBOARD_SERVICE)).hasPrimaryClip(); - } }); } return mPastePopupMenu; } + private boolean canPaste() { + if (!mFocusedNodeEditable) return false; + return ((ClipboardManager) mContext.getSystemService( + Context.CLIPBOARD_SERVICE)).hasPrimaryClip(); + } + @SuppressWarnings("unused") @CalledByNative private void onRenderProcessChange() { diff --git a/content/public/android/java/src/org/chromium/content/browser/input/PastePopupMenu.java b/content/public/android/java/src/org/chromium/content/browser/input/PastePopupMenu.java index 44726a9..c344268 100644 --- a/content/public/android/java/src/org/chromium/content/browser/input/PastePopupMenu.java +++ b/content/public/android/java/src/org/chromium/content/browser/input/PastePopupMenu.java @@ -28,8 +28,8 @@ public class PastePopupMenu implements OnClickListener { private int mPositionX; private int mPositionY; private int mStatusBarHeight; - private final View[] mPasteViews; - private final int[] mPasteViewLayouts; + private View mPasteView; + private final int mPasteViewLayout; private final int mLineOffsetY; private final int mWidthOffsetX; @@ -41,11 +41,6 @@ public class PastePopupMenu implements OnClickListener { * Called to initiate a paste after the popup has been tapped. */ void paste(); - - /** - * @return true iff content can be pasted to a focused editable region. - */ - boolean canPaste(); } public PastePopupMenu(View parent, PastePopupMenuDelegate delegate) { @@ -61,20 +56,12 @@ public class PastePopupMenu implements OnClickListener { mContainer.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); mContainer.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); - final int[] POPUP_LAYOUT_ATTRS = { - android.R.attr.textEditPasteWindowLayout, - android.R.attr.textEditNoPasteWindowLayout, - android.R.attr.textEditSidePasteWindowLayout, - android.R.attr.textEditSideNoPasteWindowLayout, - }; - - mPasteViews = new View[POPUP_LAYOUT_ATTRS.length]; - mPasteViewLayouts = new int[POPUP_LAYOUT_ATTRS.length]; + final int[] POPUP_LAYOUT_ATTRS = { android.R.attr.textEditPasteWindowLayout, }; + mPasteView = null; TypedArray attrs = mContext.getTheme().obtainStyledAttributes(POPUP_LAYOUT_ATTRS); - for (int i = 0; i < attrs.length(); ++i) { - mPasteViewLayouts[i] = attrs.getResourceId(attrs.getIndex(i), 0); - } + mPasteViewLayout = attrs.getResourceId(attrs.getIndex(0), 0); + attrs.recycle(); // Convert line offset dips to pixels. @@ -95,8 +82,7 @@ public class PastePopupMenu implements OnClickListener { * Shows the paste popup at an appropriate location relative to the specified position. */ public void showAt(int x, int y) { - if (!canPaste()) return; - updateContent(true); + updateContent(); positionAt(x, y); } @@ -116,9 +102,7 @@ public class PastePopupMenu implements OnClickListener { @Override public void onClick(View v) { - if (canPaste()) { - paste(); - } + paste(); hide(); } @@ -146,7 +130,6 @@ public class PastePopupMenu implements OnClickListener { final int screenWidth = mContext.getResources().getDisplayMetrics().widthPixels; if (coords[1] < minOffsetY) { - updateContent(false); // Update dimensions from new view contentView = mContainer.getContentView(); width = contentView.getMeasuredWidth(); @@ -178,41 +161,29 @@ public class PastePopupMenu implements OnClickListener { } } - private int viewIndex(boolean onTop) { - return (onTop ? 0 : 1 << 1) + (canPaste() ? 0 : 1 << 0); - } - - private void updateContent(boolean onTop) { - final int viewIndex = viewIndex(onTop); - View view = mPasteViews[viewIndex]; - - if (view == null) { - final int layout = mPasteViewLayouts[viewIndex]; + private void updateContent() { + if (mPasteView == null) { + final int layout = mPasteViewLayout; LayoutInflater inflater = (LayoutInflater) mContext. getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (inflater != null) { - view = inflater.inflate(layout, null); + mPasteView = inflater.inflate(layout, null); } - if (view == null) { + if (mPasteView == null) { throw new IllegalArgumentException("Unable to inflate TextEdit paste window"); } final int size = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); - view.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); - view.measure(size, size); + mPasteView.setLayoutParams( + new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT)); + mPasteView.measure(size, size); - view.setOnClickListener(this); - - mPasteViews[viewIndex] = view; + mPasteView.setOnClickListener(this); } - mContainer.setContentView(view); - } - - private boolean canPaste() { - return mDelegate.canPaste(); + mContainer.setContentView(mPasteView); } private void paste() { |