blob: 7c166aa0e556bd537b525bb1a0622e915b90b7c5 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolb8233fac2010-10-26 16:08:53 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
Michael Kolb53ed62c2011-10-04 16:18:44 -070020import android.content.Context;
John Reckd3e4d5b2011-07-13 15:48:43 -070021import android.content.Intent;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070026import android.graphics.Color;
27import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070028import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070029import android.graphics.drawable.LayerDrawable;
30import android.graphics.drawable.PaintDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.os.Bundle;
John Reck5d43ce82011-06-21 17:16:51 -070032import android.os.Handler;
33import android.os.Message;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.text.TextUtils;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -070035import android.view.ActionMode;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.Gravity;
37import android.view.LayoutInflater;
38import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070039import android.view.MenuItem;
Michael Kolb31065b12011-10-06 13:51:32 -070040import android.view.MotionEvent;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080044import android.view.ViewGroup.LayoutParams;
Michael Kolbc5675ad2011-10-21 13:34:28 -070045import android.view.Window;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080047import android.view.inputmethod.InputMethodManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080048import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080050import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070051import android.widget.LinearLayout;
52import android.widget.Toast;
53
Bijan Amirzada41242f22014-03-21 12:12:18 -070054import com.android.browser.R;
55import com.android.browser.Tab.SecurityState;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080056
57import org.codeaurora.swe.WebView;
John Reckbf2ec202011-06-29 17:47:38 -070058
Michael Kolb1bf23132010-11-19 12:55:12 -080059import java.util.List;
60
Michael Kolb8233fac2010-10-26 16:08:53 -070061/**
62 * UI interface definitions
63 */
John Reck718a24d2011-08-12 11:08:30 -070064public abstract class BaseUi implements UI {
Michael Kolb8233fac2010-10-26 16:08:53 -070065
66 private static final String LOGTAG = "BaseUi";
67
Michael Kolb66706532010-12-12 19:50:22 -080068 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070069 new FrameLayout.LayoutParams(
70 ViewGroup.LayoutParams.MATCH_PARENT,
71 ViewGroup.LayoutParams.MATCH_PARENT);
72
Michael Kolb66706532010-12-12 19:50:22 -080073 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070074 new FrameLayout.LayoutParams(
75 ViewGroup.LayoutParams.MATCH_PARENT,
76 ViewGroup.LayoutParams.MATCH_PARENT,
77 Gravity.CENTER);
78
John Reck5d43ce82011-06-21 17:16:51 -070079 private static final int MSG_HIDE_TITLEBAR = 1;
John Reckef654f12011-07-12 16:42:08 -070080 public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
John Reck5d43ce82011-06-21 17:16:51 -070081
Michael Kolb8233fac2010-10-26 16:08:53 -070082 Activity mActivity;
83 UiController mUiController;
84 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080085 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080086 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070087
Steve Block2466eff2011-10-03 15:33:09 +010088 private Drawable mLockIconSecure;
89 private Drawable mLockIconMixed;
Michael Kolb5a4372f2011-04-29 13:53:10 -070090 protected Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070091
Michael Kolb66706532010-12-12 19:50:22 -080092 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070093 protected FrameLayout mCustomViewContainer;
Michael Kolb31065b12011-10-06 13:51:32 -070094 protected FrameLayout mFullscreenContainer;
John Reck2711fab2012-05-18 21:38:59 -070095 private FrameLayout mFixedTitlebarContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070096
Michael Kolb31065b12011-10-06 13:51:32 -070097 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080098 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040099 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -0700100
Michael Kolb8233fac2010-10-26 16:08:53 -0700101 private LinearLayout mErrorConsoleContainer = null;
102
John Reck718a24d2011-08-12 11:08:30 -0700103 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -0700104
John Reck718a24d2011-08-12 11:08:30 -0700105 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 // the default <video> poster
108 private Bitmap mDefaultVideoPoster;
109 // the video progress view
110 private View mVideoProgressView;
111
Michael Kolb8233fac2010-10-26 16:08:53 -0700112 private boolean mActivityPaused;
John Reckbf2ec202011-06-29 17:47:38 -0700113 protected boolean mUseQuickControls;
John Reck0f602f32011-07-07 15:38:43 -0700114 protected TitleBar mTitleBar;
115 private NavigationBarBase mNavigationBar;
Michael Kolbda580632012-04-16 13:30:28 -0700116 protected PieControl mPieControl;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700117 private boolean mBlockFocusAnimations;
Michael Kolb8233fac2010-10-26 16:08:53 -0700118
119 public BaseUi(Activity browser, UiController controller) {
120 mActivity = browser;
121 mUiController = controller;
122 mTabControl = controller.getTabControl();
123 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800124 mInputManager = (InputMethodManager)
125 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Steve Block2466eff2011-10-03 15:33:09 +0100126 mLockIconSecure = res.getDrawable(R.drawable.ic_secure_holo_dark);
127 mLockIconMixed = res.getDrawable(R.drawable.ic_secure_partial_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700128 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
129 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700130 LayoutInflater.from(mActivity)
131 .inflate(R.layout.custom_screen, frameLayout);
John Reck2711fab2012-05-18 21:38:59 -0700132 mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(
133 R.id.fixed_titlebar_container);
John Reck7c6e1c92011-06-30 11:55:55 -0700134 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700135 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700136 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
137 R.id.fullscreen_custom_content);
John Reck7c6e1c92011-06-30 11:55:55 -0700138 mErrorConsoleContainer = (LinearLayout) frameLayout
Michael Kolb8233fac2010-10-26 16:08:53 -0700139 .findViewById(R.id.error_console);
Michael Kolbc38c6042011-04-27 10:46:06 -0700140 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb5a4372f2011-04-29 13:53:10 -0700141 mGenericFavicon = res.getDrawable(
142 R.drawable.app_web_browser_sm);
John Reck0f602f32011-07-07 15:38:43 -0700143 mTitleBar = new TitleBar(mActivity, mUiController, this,
144 mContentView);
145 mTitleBar.setProgress(100);
146 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700147 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Michael Kolb8233fac2010-10-26 16:08:53 -0700148 }
149
Michael Kolb8233fac2010-10-26 16:08:53 -0700150 private void cancelStopToast() {
151 if (mStopToast != null) {
152 mStopToast.cancel();
153 mStopToast = null;
154 }
155 }
156
157 // lifecycle
158
159 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800160 if (isCustomViewShowing()) {
161 onHideCustomView();
162 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700163 cancelStopToast();
164 mActivityPaused = true;
165 }
166
167 public void onResume() {
168 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700169 // check if we exited without setting active tab
170 // b: 5188145
Michael Kolb1a4625a2011-08-24 13:40:44 -0700171 final Tab ct = mTabControl.getCurrentTab();
172 if (ct != null) {
173 setActiveTab(ct);
174 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700175 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700176 }
177
Michael Kolb66706532010-12-12 19:50:22 -0800178 protected boolean isActivityPaused() {
179 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700180 }
181
182 public void onConfigurationChanged(Configuration config) {
183 }
184
John Reck0f602f32011-07-07 15:38:43 -0700185 public Activity getActivity() {
186 return mActivity;
187 }
188
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 // key handling
190
191 @Override
192 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700193 if (mCustomView != null) {
194 mUiController.hideCustomView();
195 return true;
196 }
197 return false;
198 }
199
Michael Kolb2814a362011-05-19 15:49:41 -0700200 @Override
201 public boolean onMenuKey() {
202 return false;
203 }
204
Michael Kolbda580632012-04-16 13:30:28 -0700205 @Override
206 public void setUseQuickControls(boolean useQuickControls) {
207 mUseQuickControls = useQuickControls;
208 mTitleBar.setUseQuickControls(mUseQuickControls);
209 if (useQuickControls) {
210 mPieControl = new PieControl(mActivity, mUiController, this);
211 mPieControl.attachToContainer(mContentView);
212 } else {
213 if (mPieControl != null) {
214 mPieControl.removeFromContainer(mContentView);
215 }
216 }
217 updateUrlBarAutoShowManagerTarget();
218 }
219
John Reck30c714c2010-12-16 17:30:34 -0800220 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700221 @Override
John Reck30c714c2010-12-16 17:30:34 -0800222 public void onTabDataChanged(Tab tab) {
223 setUrlTitle(tab);
224 setFavicon(tab);
225 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800226 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700227 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700228 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700229 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700230 }
231
232 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700233 public void onProgressChanged(Tab tab) {
234 int progress = tab.getLoadProgress();
235 if (tab.inForeground()) {
236 mTitleBar.setProgress(progress);
237 }
238 }
239
240 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500241 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800242 if (tab.inForeground()) {
243 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700244 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800245 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500246 }
247
248 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 public void onPageStopped(Tab tab) {
250 cancelStopToast();
251 if (tab.inForeground()) {
252 mStopToast = Toast
253 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
254 mStopToast.show();
255 }
256 }
257
258 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800259 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700260 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800261 }
262
263 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700264 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700265 }
266
267 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800268 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800269 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400270 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700271 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400272
Michael Kolbbae0cb22012-05-29 11:15:27 -0700273 // block unnecessary focus change animations during tab switch
274 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700275 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800276 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400277 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700278 WebView web = mActiveTab.getWebView();
279 if (web != null) {
280 web.setOnTouchListener(null);
281 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700282 }
Michael Kolb77df4562010-11-19 14:49:34 -0800283 mActiveTab = tab;
Michael Kolbda580632012-04-16 13:30:28 -0700284 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700285 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700286 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700287 if (web != null) {
288 // Request focus on the top window.
289 if (mUseQuickControls) {
290 mPieControl.forceToTop(mContentView);
291 web.setTitleBar(null);
Michael Kolbe8a82332012-04-25 14:14:26 -0700292 mTitleBar.hide();
Michael Kolbda580632012-04-16 13:30:28 -0700293 } else {
294 web.setTitleBar(mTitleBar);
295 mTitleBar.onScrollChanged();
296 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700297 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700298 }
Michael Kolb4923c222012-04-02 16:18:36 -0700299 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700300 tab.getTopWindow().requestFocus();
Michael Kolb8233fac2010-10-26 16:08:53 -0700301 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800302 onTabDataChanged(tab);
303 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700304 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700305 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400306
Vivek Sekhar943f0672014-05-01 18:35:22 -0700307 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400308 }
309
310 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700311 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400312 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700313 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400314
Vivek Sekhar943f0672014-05-01 18:35:22 -0700315 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
316 android.os.Handler handler = mTitleBar.getHandler();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400317 //remove previously scehduled tab
318 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700319 if (mRunnable != null)
320 handler.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400321 removeTabFromContentView(mTabToRemove);
322 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700323 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400324 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700325 mTabToRemove = tabToRemove;
326 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400327 mNumRemoveTries = 0;
328
329 if (mTabToRemove != null) {
330 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700331 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400332 }
333 }
334
335 protected void tryRemoveTab() {
336 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700337 android.os.Handler handler = mTitleBar.getHandler();
338 // Ensure the webview is still valid
339 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
340 if (!mTabToWaitFor.getWebView().isReady()) {
341 if (mRunnable != null) {
342 mRunnable = new Runnable() {
343 public void run() {
344 tryRemoveTab();
345 }
346 };
347 }
348 /*if the new tab is still not ready, wait another 2 frames
349 before trying again. 1 frame for the tab to render the first
350 frame, another 1 frame to make sure the swap is done*/
351 handler.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400352 return;
353 }
354 }
355 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700356 if (mRunnable != null)
357 handler.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400358 removeTabFromContentView(mTabToRemove);
359 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700360 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400361 }
362 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700363 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700364 }
365
John Reck718a24d2011-08-12 11:08:30 -0700366 protected void updateUrlBarAutoShowManagerTarget() {
367 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
368 if (!mUseQuickControls && web instanceof BrowserWebView) {
369 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
370 } else {
371 mUrlBarAutoShowManager.setTarget(null);
372 }
373 }
374
Michael Kolbcfa3af52010-12-14 10:36:11 -0800375 Tab getActiveTab() {
376 return mActiveTab;
377 }
378
Michael Kolb8233fac2010-10-26 16:08:53 -0700379 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800380 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800381 }
382
383 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700384 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800385 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700386 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800387 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700388 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700389 }
390
391 @Override
392 public void detachTab(Tab tab) {
393 removeTabFromContentView(tab);
394 }
395
396 @Override
397 public void attachTab(Tab tab) {
398 attachTabToContentView(tab);
399 }
400
Michael Kolb377ea312011-02-17 14:36:56 -0800401 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800402 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700403 return;
404 }
405 View container = tab.getViewContainer();
406 WebView mainView = tab.getWebView();
407 // Attach the WebView to the container and then attach the
408 // container to the content view.
409 FrameLayout wrapper =
410 (FrameLayout) container.findViewById(R.id.webview_wrapper);
411 ViewGroup parent = (ViewGroup) mainView.getParent();
412 if (parent != wrapper) {
413 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700414 parent.removeView(mainView);
415 }
416 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 }
418 parent = (ViewGroup) container.getParent();
419 if (parent != mContentView) {
420 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700421 parent.removeView(container);
422 }
423 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700424 }
425 mUiController.attachSubWindow(tab);
426 }
427
428 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800429 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700430 // Remove the container that contains the main WebView.
431 WebView mainView = tab.getWebView();
432 View container = tab.getViewContainer();
433 if (mainView == null) {
434 return;
435 }
436 // Remove the container from the content and then remove the
437 // WebView from the container. This will trigger a focus change
438 // needed by WebView.
439 FrameLayout wrapper =
440 (FrameLayout) container.findViewById(R.id.webview_wrapper);
441 wrapper.removeView(mainView);
442 mContentView.removeView(container);
443 mUiController.endActionMode();
444 mUiController.removeSubWindow(tab);
445 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
446 if (errorConsole != null) {
447 mErrorConsoleContainer.removeView(errorConsole);
448 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700449 }
450
Michael Kolba713ec82010-11-29 17:27:06 -0800451 @Override
452 public void onSetWebView(Tab tab, WebView webView) {
453 View container = tab.getViewContainer();
454 if (container == null) {
455 // The tab consists of a container view, which contains the main
456 // WebView, as well as any other UI elements associated with the tab.
457 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700458 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800459 tab.setViewContainer(container);
460 }
461 if (tab.getWebView() != webView) {
462 // Just remove the old one.
463 FrameLayout wrapper =
464 (FrameLayout) container.findViewById(R.id.webview_wrapper);
465 wrapper.removeView(tab.getWebView());
466 }
467 }
468
Michael Kolb8233fac2010-10-26 16:08:53 -0700469 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800470 * create a sub window container and webview for the tab
471 * Note: this methods operates through side-effects for now
472 * it sets both the subView and subViewContainer for the given tab
473 * @param tab tab to create the sub window for
474 * @param subView webview to be set as a subwindow for the tab
475 */
476 @Override
477 public void createSubWindow(Tab tab, WebView subView) {
478 View subViewContainer = mActivity.getLayoutInflater().inflate(
479 R.layout.browser_subwindow, null);
480 ViewGroup inner = (ViewGroup) subViewContainer
481 .findViewById(R.id.inner_container);
482 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
483 LayoutParams.MATCH_PARENT));
484 final ImageButton cancel = (ImageButton) subViewContainer
485 .findViewById(R.id.subwindow_close);
486 final WebView cancelSubView = subView;
487 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800488 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800489 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800490 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800491 }
492 });
493 tab.setSubWebView(subView);
494 tab.setSubViewContainer(subViewContainer);
495 }
496
497 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700498 * Remove the sub window from the content view.
499 */
500 @Override
501 public void removeSubWindow(View subviewContainer) {
502 mContentView.removeView(subviewContainer);
503 mUiController.endActionMode();
504 }
505
506 /**
507 * Attach the sub window to the content view.
508 */
509 @Override
510 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800511 if (container.getParent() != null) {
512 // already attached, remove first
513 ((ViewGroup) container.getParent()).removeView(container);
514 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700515 mContentView.addView(container, COVER_SCREEN_PARAMS);
516 }
517
Michael Kolb11d19782011-03-20 10:17:40 -0700518 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700519 WebView web = getWebView();
520 if (web != null) {
521 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700522 }
523 }
524
Michael Kolb1f9b3562012-04-24 14:38:34 -0700525 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700526 if (mUiController.isInCustomActionMode()) {
527 mUiController.endActionMode();
528 }
529 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700530 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700531 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700532 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700533 }
534
Michael Kolb7cdc4902011-02-03 17:54:40 -0800535 boolean canShowTitleBar() {
536 return !isTitleBarShowing()
537 && !isActivityPaused()
538 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700539 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800540 && !mUiController.isInCustomActionMode();
541 }
542
John Reck0f602f32011-07-07 15:38:43 -0700543 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700544 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700545 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700546 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700547 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800548 }
549
550 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700551 if (mTitleBar.isShowing()) {
552 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700553 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800554 }
555
556 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700557 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800558 }
559
John Reck5d43ce82011-06-21 17:16:51 -0700560 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700561 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700562 }
563
Michael Kolb80f75082012-04-10 10:50:06 -0700564 public void stopEditingUrl() {
565 mTitleBar.getNavigationBar().stopEditingUrl();
566 }
567
John Reck0f602f32011-07-07 15:38:43 -0700568 public TitleBar getTitleBar() {
569 return mTitleBar;
570 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800571
Michael Kolb66706532010-12-12 19:50:22 -0800572 @Override
John Reck2bc80422011-06-30 15:11:49 -0700573 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700574 Intent intent = new Intent(mActivity, ComboViewActivity.class);
575 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
576 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
577 Tab t = getActiveTab();
578 if (t != null) {
579 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800580 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700581 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700582 }
583
584 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400585 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800586 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700587 // if a view already exists then immediately terminate the new one
588 if (mCustomView != null) {
589 callback.onCustomViewHidden();
590 return;
591 }
592
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400593 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700594 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
595 mFullscreenContainer = new FullscreenHolder(mActivity);
596 mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
597 decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
598 mCustomView = view;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700599 setFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700600 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700601 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400602 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700603 }
604
605 @Override
606 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700607 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700608 if (mCustomView == null)
609 return;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700610 setFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700611 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
612 decor.removeView(mFullscreenContainer);
613 mFullscreenContainer = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700614 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700615 mCustomViewCallback.onCustomViewHidden();
616 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400617 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700618 }
619
620 @Override
621 public boolean isCustomViewShowing() {
622 return mCustomView != null;
623 }
624
Michael Kolb66706532010-12-12 19:50:22 -0800625 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800626 if (mInputManager.isActive()) {
627 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
628 0);
629 }
630 }
631
Michael Kolb66706532010-12-12 19:50:22 -0800632 @Override
John Reck3ba45532011-08-11 16:26:53 -0700633 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700634 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800635 }
636
Michael Kolb8233fac2010-10-26 16:08:53 -0700637 // -------------------------------------------------------------------------
638
Michael Kolb5a72f182011-01-13 20:35:06 -0800639 protected void updateNavigationState(Tab tab) {
640 }
641
Michael Kolb8233fac2010-10-26 16:08:53 -0700642 /**
643 * Update the lock icon to correspond to our latest state.
644 */
Michael Kolb66706532010-12-12 19:50:22 -0800645 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800646 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100647 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700648 }
649 }
650
651 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700652 * Updates the lock-icon image in the title-bar.
653 */
Steve Block2466eff2011-10-03 15:33:09 +0100654 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100656 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
657 d = mLockIconSecure;
Steve Block4895b012011-10-03 16:26:46 +0100658 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
659 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
660 // TODO: It would be good to have different icons for insecure vs mixed content.
661 // See http://b/5403800
Steve Block2466eff2011-10-03 15:33:09 +0100662 d = mLockIconMixed;
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 }
John Reck0f602f32011-07-07 15:38:43 -0700664 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700665 }
666
John Reck30c714c2010-12-16 17:30:34 -0800667 protected void setUrlTitle(Tab tab) {
668 String url = tab.getUrl();
669 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800670 if (TextUtils.isEmpty(title)) {
671 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800672 }
Michael Kolb66706532010-12-12 19:50:22 -0800673 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700674 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800675 }
676 }
677
678 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800679 protected void setFavicon(Tab tab) {
680 if (tab.inForeground()) {
681 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700682 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800683 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700684 }
685
Michael Kolb66706532010-12-12 19:50:22 -0800686 // active tabs page
687
688 public void showActiveTabsPage() {
689 }
690
691 /**
692 * Remove the active tabs page.
693 */
694 public void removeActiveTabsPage() {
695 }
696
Michael Kolb8233fac2010-10-26 16:08:53 -0700697 // menu handling callbacks
698
699 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800700 public boolean onPrepareOptionsMenu(Menu menu) {
701 return true;
702 }
703
704 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700705 public void updateMenuState(Tab tab, Menu menu) {
706 }
707
708 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700709 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700710 }
711
712 @Override
713 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700714 }
715
716 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700717 public boolean onOptionsItemSelected(MenuItem item) {
718 return false;
719 }
720
721 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700722 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700723 }
724
725 @Override
726 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700727 }
728
729 @Override
730 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700731 }
732
733 @Override
734 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700735 }
736
737 // error console
738
739 @Override
740 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800741 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700742 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
743 if (flag) {
744 // Setting the show state of the console will cause it's the layout
745 // to be inflated.
746 if (errorConsole.numberOfErrors() > 0) {
747 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
748 } else {
749 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
750 }
751 if (errorConsole.getParent() != null) {
752 mErrorConsoleContainer.removeView(errorConsole);
753 }
754 // Now we can add it to the main view.
755 mErrorConsoleContainer.addView(errorConsole,
756 new LinearLayout.LayoutParams(
757 ViewGroup.LayoutParams.MATCH_PARENT,
758 ViewGroup.LayoutParams.WRAP_CONTENT));
759 } else {
760 mErrorConsoleContainer.removeView(errorConsole);
761 }
762 }
763
Michael Kolb8233fac2010-10-26 16:08:53 -0700764 // -------------------------------------------------------------------------
765 // Helper function for WebChromeClient
766 // -------------------------------------------------------------------------
767
768 @Override
769 public Bitmap getDefaultVideoPoster() {
770 if (mDefaultVideoPoster == null) {
771 mDefaultVideoPoster = BitmapFactory.decodeResource(
772 mActivity.getResources(), R.drawable.default_video_poster);
773 }
774 return mDefaultVideoPoster;
775 }
776
777 @Override
778 public View getVideoLoadingProgressView() {
779 if (mVideoProgressView == null) {
780 LayoutInflater inflater = LayoutInflater.from(mActivity);
781 mVideoProgressView = inflater.inflate(
782 R.layout.video_loading_progress, null);
783 }
784 return mVideoProgressView;
785 }
786
Michael Kolb843510f2010-12-09 10:51:49 -0800787 @Override
788 public void showMaxTabsWarning() {
789 Toast warning = Toast.makeText(mActivity,
790 mActivity.getString(R.string.max_tabs_warning),
791 Toast.LENGTH_SHORT);
792 warning.show();
793 }
794
Michael Kolb46f987e2011-04-05 10:39:10 -0700795 protected WebView getWebView() {
796 if (mActiveTab != null) {
797 return mActiveTab.getWebView();
798 } else {
799 return null;
800 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700801 }
802
Michael Kolbc38c6042011-04-27 10:46:06 -0700803 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700804 Window win = mActivity.getWindow();
805 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800806 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Michael Kolbc38c6042011-04-27 10:46:06 -0700807 if (enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700808 winParams.flags |= bits;
Michael Kolbc38c6042011-04-27 10:46:06 -0700809 } else {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700810 winParams.flags &= ~bits;
811 if (mCustomView != null) {
812 mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
813 } else {
814 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
815 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700816 }
Michael Kolbc5675ad2011-10-21 13:34:28 -0700817 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700818 }
819
John Reck0f602f32011-07-07 15:38:43 -0700820 public Drawable getFaviconDrawable(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700821 Drawable[] array = new Drawable[3];
822 array[0] = new PaintDrawable(Color.BLACK);
823 PaintDrawable p = new PaintDrawable(Color.WHITE);
824 array[1] = p;
825 if (icon == null) {
826 array[2] = mGenericFavicon;
827 } else {
828 array[2] = new BitmapDrawable(icon);
829 }
830 LayerDrawable d = new LayerDrawable(array);
831 d.setLayerInset(1, 1, 1, 1, 1);
832 d.setLayerInset(2, 2, 2, 2, 2);
833 return d;
834 }
835
John Reck5d43ce82011-06-21 17:16:51 -0700836 public boolean isLoading() {
837 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
838 }
839
840 /**
841 * Suggest to the UI that the title bar can be hidden. The UI will then
842 * decide whether or not to hide based off a number of factors, such
843 * as if the user is editing the URL bar or if the page is loading
844 */
845 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700846 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
847 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700848 hideTitleBar();
849 }
850 }
851
John Reckbc6adb42011-09-01 18:03:20 -0700852 protected final void showTitleBarForDuration() {
853 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
854 }
855
856 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700857 showTitleBar();
858 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700859 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700860 }
861
John Reck9c5004e2011-10-07 16:00:12 -0700862 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700863
864 @Override
865 public void handleMessage(Message msg) {
866 if (msg.what == MSG_HIDE_TITLEBAR) {
867 suggestHideTitleBar();
868 }
John Reck9c5004e2011-10-07 16:00:12 -0700869 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700870 }
871 };
John Reck3ba45532011-08-11 16:26:53 -0700872
John Reck9c5004e2011-10-07 16:00:12 -0700873 protected void handleMessage(Message msg) {}
874
John Reck3ba45532011-08-11 16:26:53 -0700875 @Override
876 public void showWeb(boolean animate) {
877 mUiController.hideCustomView();
878 }
879
Michael Kolb31065b12011-10-06 13:51:32 -0700880 static class FullscreenHolder extends FrameLayout {
Michael Kolb53ed62c2011-10-04 16:18:44 -0700881
Michael Kolb31065b12011-10-06 13:51:32 -0700882 public FullscreenHolder(Context ctx) {
883 super(ctx);
884 setBackgroundColor(ctx.getResources().getColor(R.color.black));
Michael Kolb53ed62c2011-10-04 16:18:44 -0700885 }
886
Michael Kolb31065b12011-10-06 13:51:32 -0700887 @Override
888 public boolean onTouchEvent(MotionEvent evt) {
889 return true;
Michael Kolb53ed62c2011-10-04 16:18:44 -0700890 }
Michael Kolb31065b12011-10-06 13:51:32 -0700891
Michael Kolb53ed62c2011-10-04 16:18:44 -0700892 }
John Reck2711fab2012-05-18 21:38:59 -0700893
894 public void addFixedTitleBar(View view) {
895 mFixedTitlebarContainer.addView(view);
896 }
897
898 public void setContentViewMarginTop(int margin) {
899 LinearLayout.LayoutParams params =
900 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
901 if (params.topMargin != margin) {
902 params.topMargin = margin;
903 mContentView.setLayoutParams(params);
904 }
905 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700906
907 @Override
908 public boolean blockFocusAnimations() {
909 return mBlockFocusAnimations;
910 }
911
Michael Kolb0b129122012-06-04 16:31:58 -0700912 @Override
913 public void onVoiceResult(String result) {
914 mNavigationBar.onVoiceResult(result);
915 }
916
kaiyizbb2db872013-08-01 22:24:07 -0400917 protected UiController getUiController() {
918 return mUiController;
919 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700920
921 @Override
922 public void onActionModeStarted(ActionMode mode) {
923 int fixedTbarHeight = mTitleBar.isFixed() ? mTitleBar.calculateEmbeddedHeight() : 0;
924 mFixedTitlebarContainer.setY(fixedTbarHeight);
925 setContentViewMarginTop(fixedTbarHeight);
926 }
927
928 @Override
929 public void onActionModeFinished(boolean inLoad) {
930 mFixedTitlebarContainer.setY(0);
931 setContentViewMarginTop(0);
932 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700933}