diff options
author | s.singapati <s.singapati@gmail.com> | 2015-09-22 14:09:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-22 21:10:23 +0000 |
commit | a546b55cf5c4780b7717e518b58de5b5fbc2d8f0 (patch) | |
tree | 5da6a54acee2cceb53336ae235d70b5758e5ff69 | |
parent | 9887caf6bfa400bd8898d3268d224ff900f21331 (diff) | |
download | chromium_src-a546b55cf5c4780b7717e518b58de5b5fbc2d8f0.zip chromium_src-a546b55cf5c4780b7717e518b58de5b5fbc2d8f0.tar.gz chromium_src-a546b55cf5c4780b7717e518b58de5b5fbc2d8f0.tar.bz2 |
[Android] Fix <select> popup items alignment when "dir=rtl" on tablets.
This CL plumbs "right_aligned" bit from WebContentsViewAndroid to
ContentViewCore -> SelectPopupDropdown.java and sets the layout direction accordingly.
BUG=375267
Review URL: https://codereview.chromium.org/1350903005
Cr-Commit-Position: refs/heads/master@{#350222}
6 files changed, 25 insertions, 34 deletions
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index 6e7643a..37438d3 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -434,7 +434,8 @@ void ContentViewCoreImpl::ShowSelectPopupMenu( const gfx::Rect& bounds, const std::vector<MenuItem>& items, int selected_item, - bool multiple) { + bool multiple, + bool right_aligned) { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); if (j_obj.is_null()) @@ -478,14 +479,10 @@ void ContentViewCoreImpl::ShowSelectPopupMenu( } ScopedJavaLocalRef<jobjectArray> items_array( base::android::ToJavaArrayOfStrings(env, labels)); - Java_ContentViewCore_showSelectPopup(env, - j_obj.obj(), - reinterpret_cast<intptr_t>(frame), - bounds_rect.obj(), - items_array.obj(), - enabled_array.obj(), - multiple, - selected_array.obj()); + Java_ContentViewCore_showSelectPopup( + env, j_obj.obj(), reinterpret_cast<intptr_t>(frame), bounds_rect.obj(), + items_array.obj(), enabled_array.obj(), multiple, selected_array.obj(), + right_aligned); } void ContentViewCoreImpl::HideSelectPopupMenu() { diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h index fe0bcd8..2a6cb9b 100644 --- a/content/browser/android/content_view_core_impl.h +++ b/content/browser/android/content_view_core_impl.h @@ -226,7 +226,8 @@ class ContentViewCoreImpl : public ContentViewCore, const gfx::Rect& bounds, const std::vector<MenuItem>& items, int selected_item, - bool multiple); + bool multiple, + bool right_aligned); // Hides a visible popup menu. void HideSelectPopupMenu(); diff --git a/content/browser/web_contents/web_contents_view_android.cc b/content/browser/web_contents/web_contents_view_android.cc index c7e1cbb..48ccdc5 100644 --- a/content/browser/web_contents/web_contents_view_android.cc +++ b/content/browser/web_contents/web_contents_view_android.cc @@ -173,11 +173,9 @@ void WebContentsViewAndroid::ShowPopupMenu( bool right_aligned, bool allow_multiple_selection) { if (content_view_core_) { - content_view_core_->ShowSelectPopupMenu(render_frame_host, - bounds, - items, - selected_item, - allow_multiple_selection); + content_view_core_->ShowSelectPopupMenu( + render_frame_host, bounds, items, selected_item, + allow_multiple_selection, right_aligned); } } 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 0512c9a..9ed64cd 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 @@ -2508,7 +2508,7 @@ public class ContentViewCore implements @SuppressWarnings("unused") @CalledByNative private void showSelectPopup(long nativeSelectPopupSourceFrame, Rect bounds, String[] items, - int[] enabled, boolean multiple, int[] selectedIndices) { + int[] enabled, boolean multiple, int[] selectedIndices, boolean rightAligned) { if (mContainerView.getParent() == null || mContainerView.getVisibility() != View.VISIBLE) { mNativeSelectPopupSourceFrame = nativeSelectPopupSourceFrame; selectPopupMenuItems(null); @@ -2524,7 +2524,8 @@ public class ContentViewCore implements popupItems.add(new SelectPopupItem(items[i], enabled[i])); } if (DeviceFormFactor.isTablet(mContext) && !multiple && !isTouchExplorationEnabled()) { - mSelectPopup = new SelectPopupDropdown(this, popupItems, bounds, selectedIndices); + mSelectPopup = new SelectPopupDropdown( + this, popupItems, bounds, selectedIndices, rightAligned); } else { mSelectPopup = new SelectPopupDialog(this, popupItems, multiple, selectedIndices); } diff --git a/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupDropdown.java b/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupDropdown.java index f09837e..707ad2c 100644 --- a/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupDropdown.java +++ b/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupDropdown.java @@ -13,7 +13,6 @@ import android.widget.PopupWindow; import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.RenderCoordinates; import org.chromium.ui.DropdownAdapter; -import org.chromium.ui.DropdownItem; import org.chromium.ui.DropdownPopupWindow; import java.util.List; @@ -31,7 +30,7 @@ public class SelectPopupDropdown implements SelectPopup { private boolean mSelectionNotified; public SelectPopupDropdown(ContentViewCore contentViewCore, List<SelectPopupItem> items, - Rect bounds, int[] selected) { + Rect bounds, int[] selected, boolean rightAligned) { mContentViewCore = contentViewCore; mContext = mContentViewCore.getContext(); mDropdownPopupWindow = new DropdownPopupWindow(mContext, @@ -46,8 +45,8 @@ public class SelectPopupDropdown implements SelectPopup { if (selected.length > 0) { mInitialSelection = selected[0]; } - DropdownItem[] dropdownItems = items.toArray(new DropdownItem[items.size()]); - mDropdownPopupWindow.setAdapter(new DropdownAdapter(mContext, dropdownItems, null)); + mDropdownPopupWindow.setAdapter(new DropdownAdapter(mContext, items, null)); + mDropdownPopupWindow.setRtl(rightAligned); RenderCoordinates renderCoordinates = mContentViewCore.getRenderCoordinates(); float anchorX = renderCoordinates.fromPixToDip( renderCoordinates.fromLocalCssToPix(bounds.left)); diff --git a/ui/android/java/src/org/chromium/ui/DropdownAdapter.java b/ui/android/java/src/org/chromium/ui/DropdownAdapter.java index 1559228..ecfb8bf 100644 --- a/ui/android/java/src/org/chromium/ui/DropdownAdapter.java +++ b/ui/android/java/src/org/chromium/ui/DropdownAdapter.java @@ -26,19 +26,14 @@ import java.util.Set; * Dropdown item adapter for DropdownPopupWindow. */ public class DropdownAdapter extends ArrayAdapter<DropdownItem> { - private Context mContext; - private Set<Integer> mSeparators; - private boolean mAreAllItemsEnabled; - - public DropdownAdapter(Context context, List<DropdownItem> items, Set<Integer> separators) { - super(context, R.layout.dropdown_item, items); - mSeparators = separators; - mContext = context; - mAreAllItemsEnabled = checkAreAllItemsEnabled(); - } - - public DropdownAdapter(Context context, DropdownItem[] items, Set<Integer> separators) { - super(context, R.layout.dropdown_item, items); + private final Context mContext; + private final Set<Integer> mSeparators; + private final boolean mAreAllItemsEnabled; + + public DropdownAdapter( + Context context, List<? extends DropdownItem> items, Set<Integer> separators) { + super(context, R.layout.dropdown_item); + addAll(items); mSeparators = separators; mContext = context; mAreAllItemsEnabled = checkAreAllItemsEnabled(); |