blob: ddc5ad24574b7246e0c1d055e9668824b43e335f [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;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700118 private boolean mFullScreen;
Michael Kolb8233fac2010-10-26 16:08:53 -0700119
120 public BaseUi(Activity browser, UiController controller) {
121 mActivity = browser;
122 mUiController = controller;
123 mTabControl = controller.getTabControl();
124 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800125 mInputManager = (InputMethodManager)
126 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Steve Block2466eff2011-10-03 15:33:09 +0100127 mLockIconSecure = res.getDrawable(R.drawable.ic_secure_holo_dark);
128 mLockIconMixed = res.getDrawable(R.drawable.ic_secure_partial_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700129 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
130 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700131 LayoutInflater.from(mActivity)
132 .inflate(R.layout.custom_screen, frameLayout);
John Reck2711fab2012-05-18 21:38:59 -0700133 mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(
134 R.id.fixed_titlebar_container);
John Reck7c6e1c92011-06-30 11:55:55 -0700135 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700136 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700137 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
138 R.id.fullscreen_custom_content);
John Reck7c6e1c92011-06-30 11:55:55 -0700139 mErrorConsoleContainer = (LinearLayout) frameLayout
Michael Kolb8233fac2010-10-26 16:08:53 -0700140 .findViewById(R.id.error_console);
Michael Kolbc38c6042011-04-27 10:46:06 -0700141 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb5a4372f2011-04-29 13:53:10 -0700142 mGenericFavicon = res.getDrawable(
143 R.drawable.app_web_browser_sm);
John Reck0f602f32011-07-07 15:38:43 -0700144 mTitleBar = new TitleBar(mActivity, mUiController, this,
145 mContentView);
146 mTitleBar.setProgress(100);
147 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700148 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700149 mFullScreen = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700150 }
151
Michael Kolb8233fac2010-10-26 16:08:53 -0700152 private void cancelStopToast() {
153 if (mStopToast != null) {
154 mStopToast.cancel();
155 mStopToast = null;
156 }
157 }
158
159 // lifecycle
160
161 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800162 if (isCustomViewShowing()) {
163 onHideCustomView();
164 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700165 cancelStopToast();
166 mActivityPaused = true;
167 }
168
169 public void onResume() {
170 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700171 // check if we exited without setting active tab
172 // b: 5188145
Michael Kolb1a4625a2011-08-24 13:40:44 -0700173 final Tab ct = mTabControl.getCurrentTab();
174 if (ct != null) {
175 setActiveTab(ct);
176 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700177 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700178 }
179
Michael Kolb66706532010-12-12 19:50:22 -0800180 protected boolean isActivityPaused() {
181 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700182 }
183
184 public void onConfigurationChanged(Configuration config) {
185 }
186
John Reck0f602f32011-07-07 15:38:43 -0700187 public Activity getActivity() {
188 return mActivity;
189 }
190
Michael Kolb8233fac2010-10-26 16:08:53 -0700191 // key handling
192
193 @Override
194 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700195 if (mCustomView != null) {
196 mUiController.hideCustomView();
197 return true;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700198 } else if (mFullScreen) {
199 setTabFullscreen(false);
200 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700201 }
202 return false;
203 }
204
Michael Kolb2814a362011-05-19 15:49:41 -0700205 @Override
206 public boolean onMenuKey() {
207 return false;
208 }
209
Michael Kolbda580632012-04-16 13:30:28 -0700210 @Override
211 public void setUseQuickControls(boolean useQuickControls) {
212 mUseQuickControls = useQuickControls;
213 mTitleBar.setUseQuickControls(mUseQuickControls);
214 if (useQuickControls) {
215 mPieControl = new PieControl(mActivity, mUiController, this);
216 mPieControl.attachToContainer(mContentView);
217 } else {
218 if (mPieControl != null) {
219 mPieControl.removeFromContainer(mContentView);
220 }
221 }
222 updateUrlBarAutoShowManagerTarget();
223 }
224
John Reck30c714c2010-12-16 17:30:34 -0800225 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700226 @Override
John Reck30c714c2010-12-16 17:30:34 -0800227 public void onTabDataChanged(Tab tab) {
228 setUrlTitle(tab);
229 setFavicon(tab);
230 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800231 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700232 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700233 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700234 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 }
236
237 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700238 public void onProgressChanged(Tab tab) {
239 int progress = tab.getLoadProgress();
240 if (tab.inForeground()) {
241 mTitleBar.setProgress(progress);
242 }
243 }
244
245 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500246 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800247 if (tab.inForeground()) {
248 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700249 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800250 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500251 }
252
253 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 public void onPageStopped(Tab tab) {
255 cancelStopToast();
256 if (tab.inForeground()) {
257 mStopToast = Toast
258 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
259 mStopToast.show();
260 }
261 }
262
263 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800264 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700265 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800266 }
267
268 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700269 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700270 }
271
272 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800273 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800274 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400275 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700276 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400277
Michael Kolbbae0cb22012-05-29 11:15:27 -0700278 // block unnecessary focus change animations during tab switch
279 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700280 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800281 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400282 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700283 WebView web = mActiveTab.getWebView();
284 if (web != null) {
285 web.setOnTouchListener(null);
286 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700287 }
Michael Kolb77df4562010-11-19 14:49:34 -0800288 mActiveTab = tab;
Michael Kolbda580632012-04-16 13:30:28 -0700289 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700290 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700291 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700292 if (web != null) {
293 // Request focus on the top window.
294 if (mUseQuickControls) {
295 mPieControl.forceToTop(mContentView);
296 web.setTitleBar(null);
Michael Kolbe8a82332012-04-25 14:14:26 -0700297 mTitleBar.hide();
Michael Kolbda580632012-04-16 13:30:28 -0700298 } else {
299 web.setTitleBar(mTitleBar);
300 mTitleBar.onScrollChanged();
301 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700302 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700303 }
Michael Kolb4923c222012-04-02 16:18:36 -0700304 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700305 tab.getTopWindow().requestFocus();
Michael Kolb8233fac2010-10-26 16:08:53 -0700306 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800307 onTabDataChanged(tab);
308 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700309 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700310 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400311
Vivek Sekhar943f0672014-05-01 18:35:22 -0700312 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400313 }
314
315 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700316 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400317 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700318 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400319
Vivek Sekhar943f0672014-05-01 18:35:22 -0700320 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400321 //remove previously scehduled tab
322 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700323 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700324 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400325 removeTabFromContentView(mTabToRemove);
326 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700327 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400328 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700329 mTabToRemove = tabToRemove;
330 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400331 mNumRemoveTries = 0;
332
333 if (mTabToRemove != null) {
334 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700335 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400336 }
337 }
338
339 protected void tryRemoveTab() {
340 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700341 // Ensure the webview is still valid
342 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
343 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700344 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700345 mRunnable = new Runnable() {
346 public void run() {
347 tryRemoveTab();
348 }
349 };
350 }
351 /*if the new tab is still not ready, wait another 2 frames
352 before trying again. 1 frame for the tab to render the first
353 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700354 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400355 return;
356 }
357 }
358 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700359 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700360 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400361 removeTabFromContentView(mTabToRemove);
362 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700363 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400364 }
365 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700366 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700367 }
368
John Reck718a24d2011-08-12 11:08:30 -0700369 protected void updateUrlBarAutoShowManagerTarget() {
370 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
371 if (!mUseQuickControls && web instanceof BrowserWebView) {
372 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
373 } else {
374 mUrlBarAutoShowManager.setTarget(null);
375 }
376 }
377
Michael Kolbcfa3af52010-12-14 10:36:11 -0800378 Tab getActiveTab() {
379 return mActiveTab;
380 }
381
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800383 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800384 }
385
386 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700387 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800388 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700389 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800390 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700391 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700392 }
393
394 @Override
395 public void detachTab(Tab tab) {
396 removeTabFromContentView(tab);
397 }
398
399 @Override
400 public void attachTab(Tab tab) {
401 attachTabToContentView(tab);
402 }
403
Michael Kolb377ea312011-02-17 14:36:56 -0800404 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800405 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700406 return;
407 }
408 View container = tab.getViewContainer();
409 WebView mainView = tab.getWebView();
410 // Attach the WebView to the container and then attach the
411 // container to the content view.
412 FrameLayout wrapper =
413 (FrameLayout) container.findViewById(R.id.webview_wrapper);
414 ViewGroup parent = (ViewGroup) mainView.getParent();
415 if (parent != wrapper) {
416 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 parent.removeView(mainView);
418 }
419 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700420 }
421 parent = (ViewGroup) container.getParent();
422 if (parent != mContentView) {
423 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700424 parent.removeView(container);
425 }
426 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700427 }
428 mUiController.attachSubWindow(tab);
429 }
430
431 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800432 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700433 // Remove the container that contains the main WebView.
434 WebView mainView = tab.getWebView();
435 View container = tab.getViewContainer();
436 if (mainView == null) {
437 return;
438 }
439 // Remove the container from the content and then remove the
440 // WebView from the container. This will trigger a focus change
441 // needed by WebView.
442 FrameLayout wrapper =
443 (FrameLayout) container.findViewById(R.id.webview_wrapper);
444 wrapper.removeView(mainView);
445 mContentView.removeView(container);
446 mUiController.endActionMode();
447 mUiController.removeSubWindow(tab);
448 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
449 if (errorConsole != null) {
450 mErrorConsoleContainer.removeView(errorConsole);
451 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700452 }
453
Michael Kolba713ec82010-11-29 17:27:06 -0800454 @Override
455 public void onSetWebView(Tab tab, WebView webView) {
456 View container = tab.getViewContainer();
457 if (container == null) {
458 // The tab consists of a container view, which contains the main
459 // WebView, as well as any other UI elements associated with the tab.
460 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700461 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800462 tab.setViewContainer(container);
463 }
464 if (tab.getWebView() != webView) {
465 // Just remove the old one.
466 FrameLayout wrapper =
467 (FrameLayout) container.findViewById(R.id.webview_wrapper);
468 wrapper.removeView(tab.getWebView());
469 }
470 }
471
Michael Kolb8233fac2010-10-26 16:08:53 -0700472 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800473 * create a sub window container and webview for the tab
474 * Note: this methods operates through side-effects for now
475 * it sets both the subView and subViewContainer for the given tab
476 * @param tab tab to create the sub window for
477 * @param subView webview to be set as a subwindow for the tab
478 */
479 @Override
480 public void createSubWindow(Tab tab, WebView subView) {
481 View subViewContainer = mActivity.getLayoutInflater().inflate(
482 R.layout.browser_subwindow, null);
483 ViewGroup inner = (ViewGroup) subViewContainer
484 .findViewById(R.id.inner_container);
485 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
486 LayoutParams.MATCH_PARENT));
487 final ImageButton cancel = (ImageButton) subViewContainer
488 .findViewById(R.id.subwindow_close);
489 final WebView cancelSubView = subView;
490 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800491 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800492 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800493 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800494 }
495 });
496 tab.setSubWebView(subView);
497 tab.setSubViewContainer(subViewContainer);
498 }
499
500 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700501 * Remove the sub window from the content view.
502 */
503 @Override
504 public void removeSubWindow(View subviewContainer) {
505 mContentView.removeView(subviewContainer);
506 mUiController.endActionMode();
507 }
508
509 /**
510 * Attach the sub window to the content view.
511 */
512 @Override
513 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800514 if (container.getParent() != null) {
515 // already attached, remove first
516 ((ViewGroup) container.getParent()).removeView(container);
517 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700518 mContentView.addView(container, COVER_SCREEN_PARAMS);
519 }
520
Michael Kolb11d19782011-03-20 10:17:40 -0700521 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700522 WebView web = getWebView();
523 if (web != null) {
524 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700525 }
526 }
527
Michael Kolb1f9b3562012-04-24 14:38:34 -0700528 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700529 if (mUiController.isInCustomActionMode()) {
530 mUiController.endActionMode();
531 }
532 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700533 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700534 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700535 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700536 }
537
Michael Kolb7cdc4902011-02-03 17:54:40 -0800538 boolean canShowTitleBar() {
539 return !isTitleBarShowing()
540 && !isActivityPaused()
541 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700542 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800543 && !mUiController.isInCustomActionMode();
544 }
545
John Reck0f602f32011-07-07 15:38:43 -0700546 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700547 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700548 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700549 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700550 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800551 }
552
553 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700554 if (mTitleBar.isShowing()) {
555 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700556 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800557 }
558
559 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700560 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800561 }
562
John Reck5d43ce82011-06-21 17:16:51 -0700563 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700564 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700565 }
566
Michael Kolb80f75082012-04-10 10:50:06 -0700567 public void stopEditingUrl() {
568 mTitleBar.getNavigationBar().stopEditingUrl();
569 }
570
John Reck0f602f32011-07-07 15:38:43 -0700571 public TitleBar getTitleBar() {
572 return mTitleBar;
573 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800574
Michael Kolb66706532010-12-12 19:50:22 -0800575 @Override
John Reck2bc80422011-06-30 15:11:49 -0700576 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700577 Intent intent = new Intent(mActivity, ComboViewActivity.class);
578 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
579 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
580 Tab t = getActiveTab();
581 if (t != null) {
582 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800583 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700584 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700585 }
586
587 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400588 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800589 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700590 // if a view already exists then immediately terminate the new one
591 if (mCustomView != null) {
592 callback.onCustomViewHidden();
593 return;
594 }
595
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400596 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700597 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
598 mFullscreenContainer = new FullscreenHolder(mActivity);
599 mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
600 decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
601 mCustomView = view;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700602 setFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700603 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700604 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400605 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700606 }
607
608 @Override
609 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700610 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700611 if (mCustomView == null)
612 return;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700613 setFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700614 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
615 decor.removeView(mFullscreenContainer);
616 mFullscreenContainer = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700618 mCustomViewCallback.onCustomViewHidden();
619 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400620 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700621 }
622
623 @Override
624 public boolean isCustomViewShowing() {
625 return mCustomView != null;
626 }
627
Michael Kolb66706532010-12-12 19:50:22 -0800628 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800629 if (mInputManager.isActive()) {
630 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
631 0);
632 }
633 }
634
Michael Kolb66706532010-12-12 19:50:22 -0800635 @Override
John Reck3ba45532011-08-11 16:26:53 -0700636 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700637 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800638 }
639
Michael Kolb8233fac2010-10-26 16:08:53 -0700640 // -------------------------------------------------------------------------
641
Michael Kolb5a72f182011-01-13 20:35:06 -0800642 protected void updateNavigationState(Tab tab) {
643 }
644
Michael Kolb8233fac2010-10-26 16:08:53 -0700645 /**
646 * Update the lock icon to correspond to our latest state.
647 */
Michael Kolb66706532010-12-12 19:50:22 -0800648 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800649 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100650 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700651 }
652 }
653
654 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 * Updates the lock-icon image in the title-bar.
656 */
Steve Block2466eff2011-10-03 15:33:09 +0100657 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700658 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100659 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
660 d = mLockIconSecure;
Steve Block4895b012011-10-03 16:26:46 +0100661 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
662 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
663 // TODO: It would be good to have different icons for insecure vs mixed content.
664 // See http://b/5403800
Steve Block2466eff2011-10-03 15:33:09 +0100665 d = mLockIconMixed;
Michael Kolb8233fac2010-10-26 16:08:53 -0700666 }
John Reck0f602f32011-07-07 15:38:43 -0700667 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700668 }
669
John Reck30c714c2010-12-16 17:30:34 -0800670 protected void setUrlTitle(Tab tab) {
671 String url = tab.getUrl();
672 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800673 if (TextUtils.isEmpty(title)) {
674 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800675 }
Michael Kolb66706532010-12-12 19:50:22 -0800676 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700677 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800678 }
679 }
680
681 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800682 protected void setFavicon(Tab tab) {
683 if (tab.inForeground()) {
684 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700685 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800686 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700687 }
688
Michael Kolb66706532010-12-12 19:50:22 -0800689 // active tabs page
690
691 public void showActiveTabsPage() {
692 }
693
694 /**
695 * Remove the active tabs page.
696 */
697 public void removeActiveTabsPage() {
698 }
699
Michael Kolb8233fac2010-10-26 16:08:53 -0700700 // menu handling callbacks
701
702 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800703 public boolean onPrepareOptionsMenu(Menu menu) {
704 return true;
705 }
706
707 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700708 public void updateMenuState(Tab tab, Menu menu) {
709 }
710
711 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700712 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700713 }
714
715 @Override
716 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700717 }
718
719 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700720 public boolean onOptionsItemSelected(MenuItem item) {
721 return false;
722 }
723
724 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700725 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700726 }
727
728 @Override
729 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700730 }
731
732 @Override
733 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700734 }
735
736 @Override
737 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700738 }
739
740 // error console
741
742 @Override
743 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800744 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700745 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
746 if (flag) {
747 // Setting the show state of the console will cause it's the layout
748 // to be inflated.
749 if (errorConsole.numberOfErrors() > 0) {
750 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
751 } else {
752 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
753 }
754 if (errorConsole.getParent() != null) {
755 mErrorConsoleContainer.removeView(errorConsole);
756 }
757 // Now we can add it to the main view.
758 mErrorConsoleContainer.addView(errorConsole,
759 new LinearLayout.LayoutParams(
760 ViewGroup.LayoutParams.MATCH_PARENT,
761 ViewGroup.LayoutParams.WRAP_CONTENT));
762 } else {
763 mErrorConsoleContainer.removeView(errorConsole);
764 }
765 }
766
Michael Kolb8233fac2010-10-26 16:08:53 -0700767 // -------------------------------------------------------------------------
768 // Helper function for WebChromeClient
769 // -------------------------------------------------------------------------
770
771 @Override
772 public Bitmap getDefaultVideoPoster() {
773 if (mDefaultVideoPoster == null) {
774 mDefaultVideoPoster = BitmapFactory.decodeResource(
775 mActivity.getResources(), R.drawable.default_video_poster);
776 }
777 return mDefaultVideoPoster;
778 }
779
780 @Override
781 public View getVideoLoadingProgressView() {
782 if (mVideoProgressView == null) {
783 LayoutInflater inflater = LayoutInflater.from(mActivity);
784 mVideoProgressView = inflater.inflate(
785 R.layout.video_loading_progress, null);
786 }
787 return mVideoProgressView;
788 }
789
Michael Kolb843510f2010-12-09 10:51:49 -0800790 @Override
791 public void showMaxTabsWarning() {
792 Toast warning = Toast.makeText(mActivity,
793 mActivity.getString(R.string.max_tabs_warning),
794 Toast.LENGTH_SHORT);
795 warning.show();
796 }
797
Michael Kolb46f987e2011-04-05 10:39:10 -0700798 protected WebView getWebView() {
799 if (mActiveTab != null) {
800 return mActiveTab.getWebView();
801 } else {
802 return null;
803 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700804 }
805
Michael Kolbc38c6042011-04-27 10:46:06 -0700806 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700807 Window win = mActivity.getWindow();
808 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800809 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Michael Kolbc38c6042011-04-27 10:46:06 -0700810 if (enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700811 winParams.flags |= bits;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700812 mFullScreen = true;
Michael Kolbc38c6042011-04-27 10:46:06 -0700813 } else {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700814 mFullScreen = false;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700815 winParams.flags &= ~bits;
816 if (mCustomView != null) {
817 mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
818 } else {
819 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
820 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700821 }
Michael Kolbc5675ad2011-10-21 13:34:28 -0700822 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700823 }
824
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700825 public boolean isTabFullScreen() {
826 return mFullScreen;
827 }
828
829 public void setTabFullscreen(boolean enabled) {
830 setFullscreen(enabled);
831 FrameLayout main = (FrameLayout) mActivity.getWindow()
832 .getDecorView().findViewById(android.R.id.content);
833
834 LinearLayout titleBarParent = (LinearLayout) main.findViewById(R.id.vertical_layout);
835 if (titleBarParent != null) {
836 if (enabled) {
837 titleBarParent.removeView(mFixedTitlebarContainer);
838 } else {
839 titleBarParent.addView(mFixedTitlebarContainer, 1);
840 }
841 }
842 }
843
John Reck0f602f32011-07-07 15:38:43 -0700844 public Drawable getFaviconDrawable(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700845 Drawable[] array = new Drawable[3];
846 array[0] = new PaintDrawable(Color.BLACK);
847 PaintDrawable p = new PaintDrawable(Color.WHITE);
848 array[1] = p;
849 if (icon == null) {
850 array[2] = mGenericFavicon;
851 } else {
852 array[2] = new BitmapDrawable(icon);
853 }
854 LayerDrawable d = new LayerDrawable(array);
855 d.setLayerInset(1, 1, 1, 1, 1);
856 d.setLayerInset(2, 2, 2, 2, 2);
857 return d;
858 }
859
John Reck5d43ce82011-06-21 17:16:51 -0700860 public boolean isLoading() {
861 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
862 }
863
864 /**
865 * Suggest to the UI that the title bar can be hidden. The UI will then
866 * decide whether or not to hide based off a number of factors, such
867 * as if the user is editing the URL bar or if the page is loading
868 */
869 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700870 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
871 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700872 hideTitleBar();
873 }
874 }
875
John Reckbc6adb42011-09-01 18:03:20 -0700876 protected final void showTitleBarForDuration() {
877 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
878 }
879
880 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700881 showTitleBar();
882 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700883 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700884 }
885
John Reck9c5004e2011-10-07 16:00:12 -0700886 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700887
888 @Override
889 public void handleMessage(Message msg) {
890 if (msg.what == MSG_HIDE_TITLEBAR) {
891 suggestHideTitleBar();
892 }
John Reck9c5004e2011-10-07 16:00:12 -0700893 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700894 }
895 };
John Reck3ba45532011-08-11 16:26:53 -0700896
John Reck9c5004e2011-10-07 16:00:12 -0700897 protected void handleMessage(Message msg) {}
898
John Reck3ba45532011-08-11 16:26:53 -0700899 @Override
900 public void showWeb(boolean animate) {
901 mUiController.hideCustomView();
902 }
903
Michael Kolb31065b12011-10-06 13:51:32 -0700904 static class FullscreenHolder extends FrameLayout {
Michael Kolb53ed62c2011-10-04 16:18:44 -0700905
Michael Kolb31065b12011-10-06 13:51:32 -0700906 public FullscreenHolder(Context ctx) {
907 super(ctx);
908 setBackgroundColor(ctx.getResources().getColor(R.color.black));
Michael Kolb53ed62c2011-10-04 16:18:44 -0700909 }
910
Michael Kolb31065b12011-10-06 13:51:32 -0700911 @Override
912 public boolean onTouchEvent(MotionEvent evt) {
913 return true;
Michael Kolb53ed62c2011-10-04 16:18:44 -0700914 }
Michael Kolb31065b12011-10-06 13:51:32 -0700915
Michael Kolb53ed62c2011-10-04 16:18:44 -0700916 }
John Reck2711fab2012-05-18 21:38:59 -0700917
918 public void addFixedTitleBar(View view) {
919 mFixedTitlebarContainer.addView(view);
920 }
921
922 public void setContentViewMarginTop(int margin) {
923 LinearLayout.LayoutParams params =
924 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
925 if (params.topMargin != margin) {
926 params.topMargin = margin;
927 mContentView.setLayoutParams(params);
928 }
929 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700930
931 @Override
932 public boolean blockFocusAnimations() {
933 return mBlockFocusAnimations;
934 }
935
Michael Kolb0b129122012-06-04 16:31:58 -0700936 @Override
937 public void onVoiceResult(String result) {
938 mNavigationBar.onVoiceResult(result);
939 }
940
kaiyizbb2db872013-08-01 22:24:07 -0400941 protected UiController getUiController() {
942 return mUiController;
943 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700944
945 @Override
946 public void onActionModeStarted(ActionMode mode) {
947 int fixedTbarHeight = mTitleBar.isFixed() ? mTitleBar.calculateEmbeddedHeight() : 0;
948 mFixedTitlebarContainer.setY(fixedTbarHeight);
949 setContentViewMarginTop(fixedTbarHeight);
950 }
951
952 @Override
953 public void onActionModeFinished(boolean inLoad) {
954 mFixedTitlebarContainer.setY(0);
955 setContentViewMarginTop(0);
956 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700957}