Remove second url bar

       Remove the overlay "fake" titlebar by telling the
       WebView where to render the embedded titlebar
       Simplify focus handling
       requires Ic979b641c8cc80acb83eeab49c4f700fc5c50e72
       in frameworks/base

Change-Id: I7896cd731949fdcc47cd18abfee5ef947b0e8cee
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 0dcece6..55347a0 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -35,7 +35,10 @@
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.View.OnFocusChangeListener;
+import android.view.ViewGroup;
 import android.webkit.WebView;
+import android.widget.AbsoluteLayout;
+import android.widget.FrameLayout;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 
@@ -76,7 +79,6 @@
     private boolean mInVoiceMode;
 
     private boolean mInLoad;
-    private boolean mEditable;
     private boolean mUseQuickControls;
 
     public TitleBarXLarge(Activity activity, UiController controller,
@@ -95,6 +97,18 @@
         mInVoiceMode = false;
     }
 
+    @Override
+    void setTitleGravity(int gravity) {
+        if (mUseQuickControls) {
+            FrameLayout.LayoutParams lp =
+                    (FrameLayout.LayoutParams) getLayoutParams();
+            lp.gravity = gravity;
+            setLayoutParams(lp);
+        } else {
+            super.setTitleGravity(gravity);
+        }
+    }
+
     private void initLayout(Context context) {
         LayoutInflater factory = LayoutInflater.from(context);
         factory.inflate(R.layout.url_bar, this);
@@ -126,7 +140,6 @@
         mGoButton.setOnClickListener(this);
         mClearButton.setOnClickListener(this);
         mVoiceSearch.setOnClickListener(this);
-        mUrlContainer.setOnClickListener(this);
         mUrlInput.setUrlInputListener(this);
         mUrlInput.setContainer(mUrlContainer);
         mUrlInput.setController(mUiController);
@@ -148,19 +161,21 @@
         }
     }
 
-    public void setEditable(boolean editable) {
-        mEditable = editable;
-        mUrlInput.setFocusable(mEditable);
-        if (!mEditable) {
-            mUrlInput.setOnClickListener(this);
+    private ViewGroup.LayoutParams makeLayoutParams() {
+        if (mUseQuickControls) {
+            return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
+                    LayoutParams.WRAP_CONTENT);
         } else {
-            mUrlContainer.setOnClickListener(null);
+            return new AbsoluteLayout.LayoutParams(
+                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
+                    0, 0);
         }
     }
 
     void setUseQuickControls(boolean useQuickControls) {
         mUseQuickControls = useQuickControls;
         mUrlInput.setUseQuickControls(mUseQuickControls);
+        setLayoutParams(makeLayoutParams());
         if (mUseQuickControls) {
             mBackButton.setVisibility(View.GONE);
             mForwardButton.setVisibility(View.GONE);
@@ -184,15 +199,7 @@
 
     @Override
     public void onFocusChange(View view, boolean hasFocus) {
-        if (!mEditable && hasFocus) {
-            mUi.editUrl(false);
-        } else {
-            if (hasFocus) {
-                setEditMode(hasFocus);
-            } else {
-                mUrlInput.stopEditing();
-            }
-        }
+        setEditMode(hasFocus);
         mUrlContainer.setBackgroundDrawable(hasFocus
                 ? mFocusDrawable : mUnfocusDrawable);
     }
@@ -203,8 +210,6 @@
 
     /**
      * called from the Ui when the user wants to edit
-     * Note: only the fake titlebar will get this callback
-     * independent of which input field started the edit mode
      * @param clearInput clear the input field
      */
     void onEditUrl(boolean clearInput) {
@@ -227,15 +232,13 @@
         return mUrlInput.hasFocus();
     }
 
+    void stopEditingUrl() {
+        mUrlInput.clearFocus();
+    }
+
     @Override
     public void onClick(View v) {
-        if (mUrlInput == v) {
-            mUi.editUrl(false);
-        } else if (mUrlContainer == v) {
-            if (!mUrlInput.hasFocus()) {
-                mUi.editUrl(false);
-            }
-        } else if (mBackButton == v) {
+        if (mBackButton == v) {
             mUiController.getCurrentTopWebView().goBack();
         } else if (mForwardButton == v) {
             mUiController.getCurrentTopWebView().goForward();
@@ -260,17 +263,13 @@
         }
     }
 
-    int getHeightWithoutProgress() {
-        return mContainer.getHeight();
-    }
-
     @Override
     void setFavicon(Bitmap icon) { }
 
     private void clearOrClose() {
         if (TextUtils.isEmpty(mUrlInput.getText())) {
             // close
-            mUrlInput.stopEditing();
+            mUrlInput.clearFocus();
         } else {
             // clear
             mUrlInput.setText("");
@@ -286,7 +285,7 @@
     @Override
     public void onAction(String text, String extra, String source) {
         mUiController.getCurrentTopWebView().requestFocus();
-        mUi.hideFakeTitleBar();
+        mUi.hideTitleBar();
         Intent i = new Intent();
         String action = null;
         if (UrlInputView.VOICE.equals(source)) {
@@ -312,7 +311,7 @@
     @Override
     public void onDismiss() {
         final Tab currentTab = mUi.getActiveTab();
-        mUi.hideFakeTitleBar();
+        mUi.hideTitleBar();
         post(new Runnable() {
             public void run() {
                 TitleBarXLarge.this.clearFocus();
@@ -328,14 +327,14 @@
      * copy text to input field and stay in edit mode
      */
     @Override
-    public void onEdit(String text) {
+    public void onCopySuggestion(String text) {
         mUrlInput.setText(text, true);
         if (text != null) {
             mUrlInput.setSelection(text.length());
         }
     }
 
-    void setEditMode(boolean edit) {
+    private void setEditMode(boolean edit) {
         if (edit) {
             mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
             mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());