UI work on CombinedBookmarksHistory
  Adjust the CombinedBookmarksHistory activity to leave TabBar and UrlBar visible
  Enable clicks on the top bars to propagate back to the BrowserActivity

Change-Id: Ie6aed7dc0777d31dafc7c31807adf17a60f57767
diff --git a/res/values-xlarge/styles.xml b/res/values-xlarge/styles.xml
index 844f54f..2784e17 100644
--- a/res/values-xlarge/styles.xml
+++ b/res/values-xlarge/styles.xml
@@ -26,9 +26,8 @@
         <item name="android:windowActionBarStyle">@style/ActionBarStyle</item>
         <item name="android:windowContentOverlay">@null</item>
     </style>
-    <style name="BookmarkTheme" parent="@android:Theme.Black">
-        <item name="android:windowNoTitle">true</item>
-        <item name="android:windowContentOverlay">@null</item>
+    <style name="BookmarkTheme" parent="@android:Theme.Panel">
+        <item name="android:windowBackground">@color/black</item>
     </style>
     <style name="ActionBarStyle">
         <item name="android:background">#ffdddddd</item>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index a339b57..b860b42 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -24,12 +24,10 @@
         <item name="android:windowNoTitle">true</item>
         <item name="android:windowContentOverlay">@null</item>
     </style>
-
     <style name="BookmarkTheme" parent="@android:Theme.Black">
         <item name="android:windowNoTitle">true</item>
         <item name="android:windowContentOverlay">@null</item>
     </style>
-
     <style name="TitleBar">
         <item name="android:windowEnterAnimation">@anim/title_bar_enter</item>
         <item name="android:windowExitAnimation">@anim/title_bar_exit</item>
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 548eba6..e144f99 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -16,6 +16,10 @@
 
 package com.android.browser;
 
+import com.android.browser.ScrollWebView.ScrollListener;
+import com.android.common.Search;
+import com.android.common.speech.LoggingEvents;
+
 import android.app.ActionBar;
 import android.app.Activity;
 import android.app.AlertDialog;
@@ -82,6 +86,7 @@
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.MenuItem.OnMenuItemClickListener;
+import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.Window;
@@ -105,10 +110,6 @@
 import android.widget.TextView;
 import android.widget.Toast;
 
-import com.android.browser.ScrollWebView.ScrollListener;
-import com.android.common.Search;
-import com.android.common.speech.LoggingEvents;
-
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
@@ -3866,6 +3867,18 @@
                             loadUrl(getTopWindow(), data);
                         }
                     }
+                } else if (resultCode == RESULT_CANCELED) {
+                    if (intent != null) {
+                        float evtx = intent.getFloatExtra(CombinedBookmarkHistoryActivity.EVT_X, -1);
+                        float evty = intent.getFloatExtra(CombinedBookmarkHistoryActivity.EVT_Y, -1);
+                        long now = System.currentTimeMillis();
+                        MotionEvent evt = MotionEvent.obtain(now, now,
+                                MotionEvent.ACTION_DOWN, evtx, evty, 0);
+                        dispatchTouchEvent(evt);
+                        MotionEvent up = MotionEvent.obtain(evt);
+                        up.setAction(MotionEvent.ACTION_UP);
+                        dispatchTouchEvent(up);
+                    }
                 }
                 // Deliberately fall through to PREFERENCES_PAGE, since the
                 // same extra may be attached to the COMBO_PAGE
@@ -4002,7 +4015,13 @@
             intent.putExtra(CombinedBookmarkHistoryActivity.STARTING_FRAGMENT,
                     CombinedBookmarkHistoryActivity.FRAGMENT_ID_HISTORY);
         }
-        if (newTabMode) {
+        if (mXLargeScreenSize) {
+            showFakeTitleBar();
+            int titleBarHeight = ((TitleBarXLarge)mFakeTitleBar).getHeightWithoutProgress();
+            intent.putExtra(CombinedBookmarkHistoryActivity.EXTRA_TOP,
+                    mTabBar.getBottom() + titleBarHeight);
+            intent.putExtra(CombinedBookmarkHistoryActivity.EXTRA_HEIGHT,
+                    getTopWindow().getHeight() - titleBarHeight);
             intent.putExtra(CombinedBookmarkHistoryActivity.NEWTAB_MODE, true);
         }
         startActivityForResult(intent, COMBO_PAGE);
diff --git a/src/com/android/browser/CombinedBookmarkHistoryActivity.java b/src/com/android/browser/CombinedBookmarkHistoryActivity.java
index 35267c0..9422ac8 100644
--- a/src/com/android/browser/CombinedBookmarkHistoryActivity.java
+++ b/src/com/android/browser/CombinedBookmarkHistoryActivity.java
@@ -26,7 +26,10 @@
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.provider.Browser;
+import android.view.Gravity;
+import android.view.MotionEvent;
 import android.view.View;
+import android.view.WindowManager;
 import android.webkit.WebIconDatabase;
 import android.webkit.WebIconDatabase.IconListener;
 import android.widget.AdapterView;
@@ -46,6 +49,11 @@
         implements BookmarksHistoryCallbacks, OnItemClickListener {
     final static String NEWTAB_MODE = "newtab_mode";
     final static String STARTING_FRAGMENT = "fragment";
+    final static String EVT_X = "evt_x";
+    final static String EVT_Y = "evt_y";
+    final static String EXTRA_TOP = "top";
+    final static String EXTRA_HEIGHT = "height";
+
 
     final static int FRAGMENT_ID_BOOKMARKS = 1;
     final static int FRAGMENT_ID_HISTORY = 2;
@@ -70,6 +78,9 @@
      */
     private boolean mNewTabMode;
 
+    private int mRequestedTop;
+    private int mRequestedHeight;
+
     long mCurrentFragment;
 
     static class IconListenerSet implements IconListener {
@@ -124,10 +135,12 @@
         list.setAdapter(new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor,
                 new String[] { "name" }, new int[] { android.R.id.text1 }));
 
-        int startingFragment = FRAGMENT_ID_BOOKMARKS; 
+        int startingFragment = FRAGMENT_ID_BOOKMARKS;
         Bundle extras = getIntent().getExtras();
         if (extras != null) {
             mNewTabMode = extras.getBoolean(NEWTAB_MODE);
+            mRequestedTop = extras.getInt(EXTRA_TOP);
+            mRequestedHeight = extras.getInt(EXTRA_HEIGHT);
             startingFragment = extras.getInt(STARTING_FRAGMENT, FRAGMENT_ID_BOOKMARKS);
         }
 
@@ -150,6 +163,31 @@
         }).execute();
     }
 
+    @Override
+    public void onAttachedToWindow() {
+        if (mRequestedTop > -1) {
+            WindowManager.LayoutParams lp = getWindow().getAttributes();
+            lp.x = 0;
+            lp.y = mRequestedTop;
+            lp.height = mRequestedHeight;
+            lp.gravity = Gravity.TOP | Gravity.LEFT;
+            getWindow().setAttributes(lp);
+        }
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent evt) {
+        if (((evt.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) && (evt.getY() < 0)) {
+            Intent result = new Intent();
+            result.putExtra(EVT_X, evt.getRawX());
+            result.putExtra(EVT_Y, evt.getRawY());
+            setResultFromChild(Activity.RESULT_CANCELED, result);
+            finish();
+            return true;
+        }
+        return super.onTouchEvent(evt);
+    }
+
     private void loadFragment(int id) {
         String fragmentClassName;
         switch (id) {
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index f858e2e..a7957ab 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -44,6 +44,7 @@
     private Drawable mReloadDrawable;
     private Drawable mProgressDrawable;
 
+    private View mContainer;
     private View mBackButton;
     private View mForwardButton;
     private View mStar;
@@ -68,6 +69,7 @@
         LayoutInflater factory = LayoutInflater.from(context);
         factory.inflate(R.layout.url_bar, this);
 
+        mContainer = findViewById(R.id.taburlbar);
         mUrlView = (UrlInputView) findViewById(R.id.editurl);
         mAllButton = findViewById(R.id.all_btn);
         // TODO: Change enabled states based on whether you can go
@@ -107,6 +109,10 @@
         }
     }
 
+    int getHeightWithoutProgress() {
+        return mContainer.getHeight();
+    }
+
     void requestUrlInputFocus() {
         mUrlView.requestFocus();
     }