limit pie submenu to screen

    Bug: 6050725

Change-Id: I3aa3154501a36a93aac50e1e5c0bae40cf0aeac2
diff --git a/src/com/android/browser/view/BasePieView.java b/src/com/android/browser/view/BasePieView.java
index ec02e3a..b9178be 100644
--- a/src/com/android/browser/view/BasePieView.java
+++ b/src/com/android/browser/view/BasePieView.java
@@ -109,7 +109,8 @@
      * needs to set top, left, width, height
      */
     @Override
-    public void layout(int anchorX, int anchorY, boolean left, float angle) {
+    public void layout(int anchorX, int anchorY, boolean left, float angle,
+            int parentHeight) {
         if (mListener != null) {
             mListener.onLayout(anchorX, anchorY, left);
         }
diff --git a/src/com/android/browser/view/PieListView.java b/src/com/android/browser/view/PieListView.java
index 04b512b..1043fc7 100644
--- a/src/com/android/browser/view/PieListView.java
+++ b/src/com/android/browser/view/PieListView.java
@@ -39,13 +39,17 @@
      * this will be called before the first draw call
      */
     @Override
-    public void layout(int anchorX, int anchorY, boolean left, float angle) {
-        super.layout(anchorX, anchorY, left, angle);
+    public void layout(int anchorX, int anchorY, boolean left, float angle,
+            int pHeight) {
+        super.layout(anchorX, anchorY, left, angle, pHeight);
         buildViews();
         mWidth = mChildWidth;
         mHeight = mChildHeight * mAdapter.getCount();
         mLeft = anchorX + (left ? 0 : - mChildWidth);
-        mTop = anchorY - mHeight / 2;
+        mTop = Math.max(anchorY - mHeight / 2, 0);
+        if (mTop + mHeight > pHeight) {
+            mTop = pHeight - mHeight;
+        }
         if (mViews != null) {
             layoutChildrenLinear();
         }
diff --git a/src/com/android/browser/view/PieMenu.java b/src/com/android/browser/view/PieMenu.java
index 536ac92..7f8dd6b 100644
--- a/src/com/android/browser/view/PieMenu.java
+++ b/src/com/android/browser/view/PieMenu.java
@@ -60,7 +60,8 @@
 
         public void setLayoutListener(OnLayoutListener l);
 
-        public void layout(int anchorX, int anchorY, boolean onleft, float angle);
+        public void layout(int anchorX, int anchorY, boolean onleft, float angle,
+                int parentHeight);
 
         public void draw(Canvas c);
 
@@ -383,7 +384,7 @@
     }
 
     private void layoutPieView(PieView pv, int x, int y, float angle) {
-        pv.layout(x, y, onTheLeft(), angle);
+        pv.layout(x, y, onTheLeft(), angle, getHeight());
     }
 
     /**
diff --git a/src/com/android/browser/view/PieStackView.java b/src/com/android/browser/view/PieStackView.java
index 7e1922d..16d42cb 100644
--- a/src/com/android/browser/view/PieStackView.java
+++ b/src/com/android/browser/view/PieStackView.java
@@ -59,8 +59,9 @@
      * this will be called before the first draw call
      */
     @Override
-    public void layout(int anchorX, int anchorY, boolean left, float angle) {
-        super.layout(anchorX, anchorY, left, angle);
+    public void layout(int anchorX, int anchorY, boolean left, float angle,
+            int pHeight) {
+        super.layout(anchorX, anchorY, left, angle, pHeight);
         buildViews();
         mWidth = mChildWidth;
         mHeight = mChildHeight + (mViews.size() - 1) * mMinHeight;