Commit 8f9980eb authored by jaekyun@chromium.org's avatar jaekyun@chromium.org

Handle abnormal location information

View.getWindowVisibleDisplayFrame() and View.getLocationOnScreen()
sometimes return abnormal values in MultiWindow mode.

BUG=387668

Review URL: https://codereview.chromium.org/437423006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287948 0039d316-1c4b-4281-b951-d872f2087c98
parent e129ac1d
...@@ -84,9 +84,10 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -84,9 +84,10 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
* button) * button)
* @param screenRotation Current device screen rotation. * @param screenRotation Current device screen rotation.
* @param visibleDisplayFrame The display area rect in which AppMenu is supposed to fit in. * @param visibleDisplayFrame The display area rect in which AppMenu is supposed to fit in.
* @param screenHeight Current device screen height.
*/ */
void show(Context context, View anchorView, boolean isByHardwareButton, int screenRotation, void show(Context context, View anchorView, boolean isByHardwareButton, int screenRotation,
Rect visibleDisplayFrame) { Rect visibleDisplayFrame, int screenHeight) {
mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyle); mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyle);
mPopup.setModal(true); mPopup.setModal(true);
mPopup.setAnchorView(anchorView); mPopup.setAnchorView(anchorView);
...@@ -140,7 +141,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -140,7 +141,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
this, menuItems, LayoutInflater.from(context), showMenuButton); this, menuItems, LayoutInflater.from(context), showMenuButton);
mPopup.setAdapter(mAdapter); mPopup.setAdapter(mAdapter);
setMenuHeight(menuItems.size(), visibleDisplayFrame); setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight);
setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame); setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame);
mPopup.setOnItemClickListener(this); mPopup.setOnItemClickListener(this);
mPopup.show(); mPopup.show();
...@@ -263,7 +264,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -263,7 +264,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
return mPopup; return mPopup;
} }
private void setMenuHeight(int numMenuItems, Rect appDimensions) { private void setMenuHeight(int numMenuItems, Rect appDimensions, int screenHeight) {
assert mPopup.getAnchorView() != null; assert mPopup.getAnchorView() != null;
View anchorView = mPopup.getAnchorView(); View anchorView = mPopup.getAnchorView();
int[] anchorViewLocation = new int[2]; int[] anchorViewLocation = new int[2];
...@@ -271,6 +272,10 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -271,6 +272,10 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
anchorViewLocation[1] -= appDimensions.top; anchorViewLocation[1] -= appDimensions.top;
int anchorViewImpactHeight = mIsByHardwareButton ? anchorView.getHeight() : 0; int anchorViewImpactHeight = mIsByHardwareButton ? anchorView.getHeight() : 0;
// Set appDimensions.height() for abnormal anchorViewLocation.
if (anchorViewLocation[1] > screenHeight) {
anchorViewLocation[1] = appDimensions.height();
}
int availableScreenSpace = Math.max(anchorViewLocation[1], int availableScreenSpace = Math.max(anchorViewLocation[1],
appDimensions.height() - anchorViewLocation[1] - anchorViewImpactHeight); appDimensions.height() - anchorViewLocation[1] - anchorViewImpactHeight);
......
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.appmenu; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.appmenu;
import android.app.Activity; import android.app.Activity;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
...@@ -94,8 +95,18 @@ public class AppMenuHandler { ...@@ -94,8 +95,18 @@ public class AppMenuHandler {
// Get the height and width of the display. // Get the height and width of the display.
Rect appRect = new Rect(); Rect appRect = new Rect();
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(appRect); mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(appRect);
// Use full size of window for abnormal appRect.
if (appRect.left < 0 && appRect.top < 0) {
appRect.left = 0;
appRect.top = 0;
appRect.right = mActivity.getWindow().getDecorView().getWidth();
appRect.bottom = mActivity.getWindow().getDecorView().getHeight();
}
int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation(); int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
mAppMenu.show(wrapper, anchorView, isByHardwareButton, rotation, appRect); Point pt = new Point();
mActivity.getWindowManager().getDefaultDisplay().getSize(pt);
mAppMenu.show(wrapper, anchorView, isByHardwareButton, rotation, appRect, pt.y);
mAppMenuDragHelper.onShow(startDragging); mAppMenuDragHelper.onShow(startDragging);
UmaBridge.menuShow(); UmaBridge.menuShow();
return true; return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment