Fix issues in Autohide TitleBar

- Fixes issue when longpress of TitleBar
  shows copy/paste menu on top of titleBar.
- Fixes issue in landscape mode where the
  setTranslationY value is reused from portrait
  mode.

Change-Id: I521b4dd7a5385c621c941487f77894a3dcef42d3
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index 4648de7..c6238f4 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -855,7 +855,7 @@
     }
 
     public void transalateTitleBar(float topControlsOffsetYPix) {
-        if (mTitleBar != null) {
+        if (mTitleBar != null && !mInActionMode) {
             mTitleBar.bringToFront();
             if (topControlsOffsetYPix != 0.0) {
                 mTitleBar.setEnabled(false);
@@ -863,7 +863,6 @@
                 mTitleBar.setEnabled(true);
             }
             mTitleBar.setTranslationY(topControlsOffsetYPix);
-
         }
     }
 
@@ -968,8 +967,11 @@
         return mUiController;
     }
 
+    boolean mInActionMode = false;
+
     @Override
     public void onActionModeStarted(ActionMode mode) {
+        mInActionMode = true;
         boolean hide_title_on_scroll =
             mActivity.getResources().getBoolean(R.bool.hide_title_on_scroll);
         if (!hide_title_on_scroll) {
@@ -981,6 +983,7 @@
 
     @Override
     public void onActionModeFinished(boolean inLoad) {
+        mInActionMode = false;
         boolean hide_title_on_scroll =
             mActivity.getResources().getBoolean(R.bool.hide_title_on_scroll);
         if (!hide_title_on_scroll) {
diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java
index 900abff..78b3cc8 100644
--- a/src/com/android/browser/PhoneUi.java
+++ b/src/com/android/browser/PhoneUi.java
@@ -52,11 +52,12 @@
     private NavScreen mNavScreen;
     private AnimScreen mAnimScreen;
     private NavigationBarPhone mNavigationBar;
-    private int mActionBarHeight;
+    private Activity mBrowser;
 
     boolean mAnimating;
     boolean mShowNav = false;
 
+
     /**
      * @param browser
      * @param controller
@@ -65,11 +66,7 @@
         super(browser, controller);
         setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
         mNavigationBar = (NavigationBarPhone) mTitleBar.getNavigationBar();
-        TypedValue heightValue = new TypedValue();
-        browser.getTheme().resolveAttribute(
-                android.R.attr.actionBarSize, heightValue, true);
-        mActionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data,
-                browser.getResources().getDisplayMetrics());
+        mBrowser = browser;
     }
 
     @Override
@@ -238,7 +235,12 @@
         if (!isEditingUrl()) {
             hideTitleBar();
         } else {
-            mTitleBar.setTranslationY(mActionBarHeight);
+            TypedValue heightValue = new TypedValue();
+            mBrowser.getTheme().resolveAttribute(
+                android.R.attr.actionBarSize, heightValue, true);
+            int actionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data,
+                mBrowser.getResources().getDisplayMetrics());
+            mTitleBar.setTranslationY(actionBarHeight);
         }
     }
 
diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java
index 9963bc4..78f2d0e 100644
--- a/src/com/android/browser/TitleBar.java
+++ b/src/com/android/browser/TitleBar.java
@@ -102,9 +102,7 @@
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
-        boolean hide_title_on_scroll =
-          getContext().getResources().getBoolean(R.bool.hide_title_on_scroll);
-        if (mIsFixedTitleBar && !hide_title_on_scroll) {
+        if (mIsFixedTitleBar) {
             int margin = getMeasuredHeight() - calculateEmbeddedHeight();
             if (!isEditingUrl())
                 mBaseUi.setContentViewMarginTop(-margin);