Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / appmenu / AppMenu.java
index 15afde5..af48e84 100644 (file)
@@ -88,9 +88,10 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
      *                            button)
      * @param screenRotation      Current device screen rotation.
      * @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,
-            Rect visibleDisplayFrame) {
+            Rect visibleDisplayFrame, int screenHeight) {
         mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyle);
         mPopup.setModal(true);
         mPopup.setAnchorView(anchorView);
@@ -147,7 +148,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
                 this, menuItems, LayoutInflater.from(context), showMenuButton);
         mPopup.setAdapter(mAdapter);
 
-        setMenuHeight(menuItems.size(), visibleDisplayFrame);
+        setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight);
         setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame);
         mPopup.setOnItemClickListener(this);
         mPopup.show();
@@ -273,7 +274,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
         return mPopup;
     }
 
-    private void setMenuHeight(int numMenuItems, Rect appDimensions) {
+    private void setMenuHeight(int numMenuItems, Rect appDimensions, int screenHeight) {
         assert mPopup.getAnchorView() != null;
         View anchorView = mPopup.getAnchorView();
         int[] anchorViewLocation = new int[2];
@@ -281,6 +282,10 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
         anchorViewLocation[1] -= appDimensions.top;
         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],
                 appDimensions.height() - anchorViewLocation[1] - anchorViewImpactHeight);