blob: 089c7f022e5eabf87dd87506c3335be4846e59b6 [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;
John Reckd3e4d5b2011-07-13 15:48:43 -070020import android.content.Intent;
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.content.res.Configuration;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.graphics.Bitmap;
23import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070024import android.graphics.Color;
25import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070027import android.graphics.drawable.LayerDrawable;
28import android.graphics.drawable.PaintDrawable;
Sagar Dhawan1e040c72014-12-11 20:24:12 -080029import android.os.Build;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.os.Bundle;
John Reck5d43ce82011-06-21 17:16:51 -070031import android.os.Handler;
32import android.os.Message;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.text.TextUtils;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -070034import android.view.ActionMode;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.Gravity;
36import android.view.LayoutInflater;
37import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070038import android.view.MenuItem;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080040import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.view.ViewGroup.LayoutParams;
Michael Kolbc5675ad2011-10-21 13:34:28 -070043import android.view.Window;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080045import android.view.inputmethod.InputMethodManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080046import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080048import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070050import android.content.res.TypedArray;
Pankaj Garg62fef2f2015-03-31 10:48:53 -070051
Bijan Amirzada41242f22014-03-21 12:12:18 -070052import com.android.browser.Tab.SecurityState;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080053
54import org.codeaurora.swe.WebView;
John Reckbf2ec202011-06-29 17:47:38 -070055
Michael Kolb1bf23132010-11-19 12:55:12 -080056import java.util.List;
57
Michael Kolb8233fac2010-10-26 16:08:53 -070058/**
59 * UI interface definitions
60 */
John Reck718a24d2011-08-12 11:08:30 -070061public abstract class BaseUi implements UI {
Michael Kolb8233fac2010-10-26 16:08:53 -070062
Enrico Ros1f5a0952014-11-18 20:15:48 -080063 protected static final boolean ENABLE_BORDER_AROUND_FAVICON = false;
Michael Kolb8233fac2010-10-26 16:08:53 -070064
Michael Kolb66706532010-12-12 19:50:22 -080065 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070066 new FrameLayout.LayoutParams(
67 ViewGroup.LayoutParams.MATCH_PARENT,
68 ViewGroup.LayoutParams.MATCH_PARENT);
69
Michael Kolb66706532010-12-12 19:50:22 -080070 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070071 new FrameLayout.LayoutParams(
72 ViewGroup.LayoutParams.MATCH_PARENT,
73 ViewGroup.LayoutParams.MATCH_PARENT,
74 Gravity.CENTER);
75
John Reck5d43ce82011-06-21 17:16:51 -070076 private static final int MSG_HIDE_TITLEBAR = 1;
John Reckef654f12011-07-12 16:42:08 -070077 public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
John Reck5d43ce82011-06-21 17:16:51 -070078
Michael Kolb8233fac2010-10-26 16:08:53 -070079 Activity mActivity;
80 UiController mUiController;
81 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080082 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080083 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070084
Steve Block2466eff2011-10-03 15:33:09 +010085 private Drawable mLockIconSecure;
86 private Drawable mLockIconMixed;
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070087 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070088
Michael Kolb66706532010-12-12 19:50:22 -080089 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070090 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070091
Michael Kolb31065b12011-10-06 13:51:32 -070092 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080093 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040094 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070095
John Reck718a24d2011-08-12 11:08:30 -070096 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070097
John Reck718a24d2011-08-12 11:08:30 -070098 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -070099
Michael Kolb8233fac2010-10-26 16:08:53 -0700100 // the default <video> poster
101 private Bitmap mDefaultVideoPoster;
102 // the video progress view
103 private View mVideoProgressView;
104
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800105 private final View mDecorView;
106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700108 protected TitleBar mTitleBar;
109 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700110 private boolean mBlockFocusAnimations;
Michael Kolb8233fac2010-10-26 16:08:53 -0700111
112 public BaseUi(Activity browser, UiController controller) {
113 mActivity = browser;
114 mUiController = controller;
115 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800116 mInputManager = (InputMethodManager)
117 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800118 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
119 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700120 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
121 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700122 LayoutInflater.from(mActivity)
123 .inflate(R.layout.custom_screen, frameLayout);
124 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700125 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700126 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
127 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700128 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700129 mTitleBar = new TitleBar(mActivity, mUiController, this,
130 mContentView);
131 mTitleBar.setProgress(100);
132 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700133 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800134
135 // install system ui visibility listeners
136 mDecorView = mActivity.getWindow().getDecorView();
137 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Michael Kolb8233fac2010-10-26 16:08:53 -0700138 }
139
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800140 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
141 new View.OnSystemUiVisibilityChangeListener() {
142 @Override
143 public void onSystemUiVisibilityChange(int visFlags) {
144 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
145 if (lostFullscreen)
146 setFullscreen(BrowserSettings.getInstance().useFullscreen());
147 }
148 };
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
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700157 private Drawable getLockIconSecure() {
158 if (mLockIconSecure == null) {
Pankaj Garg62fef2f2015-03-31 10:48:53 -0700159 mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_deco_secure);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700160 }
161 return mLockIconSecure;
162 }
163
164 private Drawable getLockIconMixed() {
165 if (mLockIconMixed == null) {
Pankaj Garg62fef2f2015-03-31 10:48:53 -0700166 mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_deco_secure_partial);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700167 }
168 return mLockIconMixed;
169 }
170
171 protected Drawable getGenericFavicon() {
172 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800173 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700174 }
175 return mGenericFavicon;
176 }
177
Michael Kolb8233fac2010-10-26 16:08:53 -0700178 // lifecycle
179
180 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800181 if (isCustomViewShowing()) {
182 onHideCustomView();
183 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500184 if (mTabControl.getCurrentTab() != null) {
185 mTabControl.getCurrentTab().exitFullscreen();
186 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700187 cancelStopToast();
188 mActivityPaused = true;
189 }
190
191 public void onResume() {
192 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700193 // check if we exited without setting active tab
194 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800195 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700196 final Tab ct = mTabControl.getCurrentTab();
197 if (ct != null) {
198 setActiveTab(ct);
199 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700200 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700201 }
202
Michael Kolb66706532010-12-12 19:50:22 -0800203 protected boolean isActivityPaused() {
204 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700205 }
206
207 public void onConfigurationChanged(Configuration config) {
208 }
209
John Reck0f602f32011-07-07 15:38:43 -0700210 public Activity getActivity() {
211 return mActivity;
212 }
213
Michael Kolb8233fac2010-10-26 16:08:53 -0700214 // key handling
215
216 @Override
217 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700218 if (mCustomView != null) {
219 mUiController.hideCustomView();
220 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700221 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700222 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700223 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700224 }
225 return false;
226 }
227
Michael Kolb2814a362011-05-19 15:49:41 -0700228 @Override
229 public boolean onMenuKey() {
230 return false;
231 }
232
John Reck30c714c2010-12-16 17:30:34 -0800233 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700234 @Override
John Reck30c714c2010-12-16 17:30:34 -0800235 public void onTabDataChanged(Tab tab) {
236 setUrlTitle(tab);
237 setFavicon(tab);
238 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800239 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700240 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700241 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700242 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 }
244
245 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700246 public void onProgressChanged(Tab tab) {
247 int progress = tab.getLoadProgress();
248 if (tab.inForeground()) {
249 mTitleBar.setProgress(progress);
250 }
251 }
252
253 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500254 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800255 if (tab.inForeground()) {
256 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700257 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800258 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500259 }
260
261 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700262 public void onPageStopped(Tab tab) {
263 cancelStopToast();
264 if (tab.inForeground()) {
265 mStopToast = Toast
266 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
267 mStopToast.show();
268 }
269 }
270
271 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800272 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700273 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800274 }
275
276 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700277 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700278 }
279
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800280 public void cancelNavScreenRequest(){
281 }
282
Michael Kolb377ea312011-02-17 14:36:56 -0800283 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800284 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400285 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700286 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400287
Michael Kolbbae0cb22012-05-29 11:15:27 -0700288 // block unnecessary focus change animations during tab switch
289 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700290 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800291 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400292 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700293 WebView web = mActiveTab.getWebView();
294 if (web != null) {
295 web.setOnTouchListener(null);
296 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700297 }
Michael Kolb77df4562010-11-19 14:49:34 -0800298 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800299
Michael Kolbda580632012-04-16 13:30:28 -0700300 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700301 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700302 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700303 if (web != null) {
304 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700305 web.setTitleBar(mTitleBar);
306 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700307 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700308 }
Michael Kolb4923c222012-04-02 16:18:36 -0700309 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700310 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800311 onTabDataChanged(tab);
312 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700313 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700314 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400315
Vivek Sekhar943f0672014-05-01 18:35:22 -0700316 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400317 }
318
319 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700320 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400321 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700322 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400323
Vivek Sekhar943f0672014-05-01 18:35:22 -0700324 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800325
326 if(tabToWaitFor == mTabToRemove) {
327 if (mRunnable != null) {
328 mTitleBar.removeCallbacks(mRunnable);
329 }
330 mTabToRemove = null;
331 mTabToWaitFor = null;
332 mRunnable = null;
333 return;
334 }
335
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400336 //remove previously scehduled tab
337 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700338 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700339 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400340 removeTabFromContentView(mTabToRemove);
341 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700342 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400343 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700344 mTabToRemove = tabToRemove;
345 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400346 mNumRemoveTries = 0;
347
348 if (mTabToRemove != null) {
349 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700350 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400351 }
352 }
353
354 protected void tryRemoveTab() {
355 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700356 // Ensure the webview is still valid
357 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
358 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700359 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700360 mRunnable = new Runnable() {
361 public void run() {
362 tryRemoveTab();
363 }
364 };
365 }
366 /*if the new tab is still not ready, wait another 2 frames
367 before trying again. 1 frame for the tab to render the first
368 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700369 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400370 return;
371 }
372 }
373 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700374 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700375 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400376 removeTabFromContentView(mTabToRemove);
377 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700378 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400379 }
380 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700381 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 }
383
John Reck718a24d2011-08-12 11:08:30 -0700384 protected void updateUrlBarAutoShowManagerTarget() {
385 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700386 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700387 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700388 }
389 }
390
Michael Kolbcfa3af52010-12-14 10:36:11 -0800391 Tab getActiveTab() {
392 return mActiveTab;
393 }
394
Michael Kolb8233fac2010-10-26 16:08:53 -0700395 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800396 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800397 }
398
399 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700400 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800401 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700402 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800403 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700404 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700405 }
406
407 @Override
408 public void detachTab(Tab tab) {
409 removeTabFromContentView(tab);
410 }
411
412 @Override
413 public void attachTab(Tab tab) {
414 attachTabToContentView(tab);
415 }
416
Michael Kolb377ea312011-02-17 14:36:56 -0800417 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800418 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700419 return;
420 }
421 View container = tab.getViewContainer();
422 WebView mainView = tab.getWebView();
423 // Attach the WebView to the container and then attach the
424 // container to the content view.
425 FrameLayout wrapper =
426 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700427 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
428
429 if (wrapper != parentView) {
430 // clean up old view before attaching new view
431 // this helping in fixing issues such touch event
432 // getting triggered on old view instead of new one
433 if (parentView != null) {
434 parentView.removeView(mainView.getView());
435 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800436 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700437 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800438 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700439 if (parent != mContentView) {
440 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700441 parent.removeView(container);
442 }
443 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700444 }
445 mUiController.attachSubWindow(tab);
446 }
447
448 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800449 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700450 // Remove the container that contains the main WebView.
451 WebView mainView = tab.getWebView();
452 View container = tab.getViewContainer();
453 if (mainView == null) {
454 return;
455 }
456 // Remove the container from the content and then remove the
457 // WebView from the container. This will trigger a focus change
458 // needed by WebView.
459 FrameLayout wrapper =
460 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800461 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700462 mContentView.removeView(container);
463 mUiController.endActionMode();
464 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700465 }
466
Michael Kolba713ec82010-11-29 17:27:06 -0800467 @Override
468 public void onSetWebView(Tab tab, WebView webView) {
469 View container = tab.getViewContainer();
470 if (container == null) {
471 // The tab consists of a container view, which contains the main
472 // WebView, as well as any other UI elements associated with the tab.
473 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700474 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800475 tab.setViewContainer(container);
476 }
477 if (tab.getWebView() != webView) {
478 // Just remove the old one.
479 FrameLayout wrapper =
480 (FrameLayout) container.findViewById(R.id.webview_wrapper);
481 wrapper.removeView(tab.getWebView());
482 }
483 }
484
Michael Kolb8233fac2010-10-26 16:08:53 -0700485 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800486 * create a sub window container and webview for the tab
487 * Note: this methods operates through side-effects for now
488 * it sets both the subView and subViewContainer for the given tab
489 * @param tab tab to create the sub window for
490 * @param subView webview to be set as a subwindow for the tab
491 */
492 @Override
493 public void createSubWindow(Tab tab, WebView subView) {
494 View subViewContainer = mActivity.getLayoutInflater().inflate(
495 R.layout.browser_subwindow, null);
496 ViewGroup inner = (ViewGroup) subViewContainer
497 .findViewById(R.id.inner_container);
498 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
499 LayoutParams.MATCH_PARENT));
500 final ImageButton cancel = (ImageButton) subViewContainer
501 .findViewById(R.id.subwindow_close);
502 final WebView cancelSubView = subView;
503 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800504 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800505 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800506 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800507 }
508 });
509 tab.setSubWebView(subView);
510 tab.setSubViewContainer(subViewContainer);
511 }
512
513 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700514 * Remove the sub window from the content view.
515 */
516 @Override
517 public void removeSubWindow(View subviewContainer) {
518 mContentView.removeView(subviewContainer);
519 mUiController.endActionMode();
520 }
521
522 /**
523 * Attach the sub window to the content view.
524 */
525 @Override
526 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800527 if (container.getParent() != null) {
528 // already attached, remove first
529 ((ViewGroup) container.getParent()).removeView(container);
530 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700531 mContentView.addView(container, COVER_SCREEN_PARAMS);
532 }
533
Michael Kolb11d19782011-03-20 10:17:40 -0700534 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700535 WebView web = getWebView();
536 if (web != null) {
537 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700538 }
539 }
540
Michael Kolb1f9b3562012-04-24 14:38:34 -0700541 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700542 if (mUiController.isInCustomActionMode()) {
543 mUiController.endActionMode();
544 }
545 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700546 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700547 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700548 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700549 }
550
Michael Kolb7cdc4902011-02-03 17:54:40 -0800551 boolean canShowTitleBar() {
552 return !isTitleBarShowing()
553 && !isActivityPaused()
554 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700555 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800556 && !mUiController.isInCustomActionMode();
557 }
558
John Reck0f602f32011-07-07 15:38:43 -0700559 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700560 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700561 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700562 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700563 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800564 }
565
566 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700567 if (mTitleBar.isShowing()) {
568 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700569 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800570 }
571
572 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700573 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800574 }
575
John Reck5d43ce82011-06-21 17:16:51 -0700576 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700577 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700578 }
579
Michael Kolb80f75082012-04-10 10:50:06 -0700580 public void stopEditingUrl() {
581 mTitleBar.getNavigationBar().stopEditingUrl();
582 }
583
John Reck0f602f32011-07-07 15:38:43 -0700584 public TitleBar getTitleBar() {
585 return mTitleBar;
586 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800587
Michael Kolb66706532010-12-12 19:50:22 -0800588 @Override
John Reck2bc80422011-06-30 15:11:49 -0700589 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700590 Intent intent = new Intent(mActivity, ComboViewActivity.class);
591 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
592 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
593 Tab t = getActiveTab();
594 if (t != null) {
595 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800596 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700597 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700598 }
599
600 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800601 public void hideComboView() {
602 }
603
604 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400605 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800606 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 // if a view already exists then immediately terminate the new one
608 if (mCustomView != null) {
609 callback.onCustomViewHidden();
610 return;
611 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400612 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700613 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400614 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700615 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400616 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700617 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700618 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400619 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700620 }
621
622 @Override
623 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700624 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700625 if (mCustomView == null)
626 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400627 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700628 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400629 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700630 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700631 mCustomViewCallback.onCustomViewHidden();
632 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400633 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700634 }
635
636 @Override
637 public boolean isCustomViewShowing() {
638 return mCustomView != null;
639 }
640
Michael Kolb66706532010-12-12 19:50:22 -0800641 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800642 if (mInputManager.isActive()) {
643 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
644 0);
645 }
646 }
647
Michael Kolb66706532010-12-12 19:50:22 -0800648 @Override
John Reck3ba45532011-08-11 16:26:53 -0700649 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700650 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800651 }
652
Tarun Nainani87a86682015-02-05 11:47:35 -0800653 @Override
654 public boolean isComboViewShowing() {
655 return false;
656 }
657
Michael Kolb8233fac2010-10-26 16:08:53 -0700658 // -------------------------------------------------------------------------
659
Michael Kolb5a72f182011-01-13 20:35:06 -0800660 protected void updateNavigationState(Tab tab) {
661 }
662
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 /**
664 * Update the lock icon to correspond to our latest state.
665 */
Michael Kolb66706532010-12-12 19:50:22 -0800666 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800667 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100668 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700669 }
670 }
671
672 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700673 * Updates the lock-icon image in the title-bar.
674 */
Steve Block2466eff2011-10-03 15:33:09 +0100675 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700676 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100677 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700678 d = getLockIconSecure();
Steve Block4895b012011-10-03 16:26:46 +0100679 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
680 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
681 // TODO: It would be good to have different icons for insecure vs mixed content.
682 // See http://b/5403800
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700683 d = getLockIconMixed();
Michael Kolb8233fac2010-10-26 16:08:53 -0700684 }
John Reck0f602f32011-07-07 15:38:43 -0700685 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700686 }
687
John Reck30c714c2010-12-16 17:30:34 -0800688 protected void setUrlTitle(Tab tab) {
689 String url = tab.getUrl();
690 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800691 if (TextUtils.isEmpty(title)) {
692 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800693 }
Michael Kolb66706532010-12-12 19:50:22 -0800694 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700695 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800696 }
697 }
698
699 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800700 protected void setFavicon(Tab tab) {
701 if (tab.inForeground()) {
702 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700703 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800704 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700705 }
706
Michael Kolb66706532010-12-12 19:50:22 -0800707 // active tabs page
708
709 public void showActiveTabsPage() {
710 }
711
712 /**
713 * Remove the active tabs page.
714 */
715 public void removeActiveTabsPage() {
716 }
717
Michael Kolb8233fac2010-10-26 16:08:53 -0700718 // menu handling callbacks
719
720 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800721 public boolean onPrepareOptionsMenu(Menu menu) {
722 return true;
723 }
724
725 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700726 public void updateMenuState(Tab tab, Menu menu) {
727 }
728
729 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700730 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700731 }
732
733 @Override
734 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700735 }
736
737 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700738 public boolean onOptionsItemSelected(MenuItem item) {
739 return false;
740 }
741
742 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700743 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700744 }
745
746 @Override
747 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700748 }
749
750 @Override
751 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700752 }
753
754 @Override
755 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700756 }
757
Michael Kolb8233fac2010-10-26 16:08:53 -0700758 // -------------------------------------------------------------------------
759 // Helper function for WebChromeClient
760 // -------------------------------------------------------------------------
761
762 @Override
763 public Bitmap getDefaultVideoPoster() {
764 if (mDefaultVideoPoster == null) {
765 mDefaultVideoPoster = BitmapFactory.decodeResource(
766 mActivity.getResources(), R.drawable.default_video_poster);
767 }
768 return mDefaultVideoPoster;
769 }
770
771 @Override
772 public View getVideoLoadingProgressView() {
773 if (mVideoProgressView == null) {
774 LayoutInflater inflater = LayoutInflater.from(mActivity);
775 mVideoProgressView = inflater.inflate(
776 R.layout.video_loading_progress, null);
777 }
778 return mVideoProgressView;
779 }
780
Michael Kolb843510f2010-12-09 10:51:49 -0800781 @Override
782 public void showMaxTabsWarning() {
783 Toast warning = Toast.makeText(mActivity,
784 mActivity.getString(R.string.max_tabs_warning),
785 Toast.LENGTH_SHORT);
786 warning.show();
787 }
788
Michael Kolb46f987e2011-04-05 10:39:10 -0700789 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800790
Michael Kolb46f987e2011-04-05 10:39:10 -0700791 if (mActiveTab != null) {
792 return mActiveTab.getWebView();
793 } else {
794 return null;
795 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700796 }
797
Michael Kolbc38c6042011-04-27 10:46:06 -0700798 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700799 Window win = mActivity.getWindow();
800 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800801 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500802 final int fullscreenImmersiveSetting =
803 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
804 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
805 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
806 View.SYSTEM_UI_FLAG_FULLSCREEN |
807 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
808
809 if (mCustomView != null) {
810 mCustomView.setSystemUiVisibility(enabled ?
811 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800812 } else if (Build.VERSION.SDK_INT >= 19) {
813 mContentView.setSystemUiVisibility(enabled ?
814 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700815 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500816 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800817 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700818 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500819 if (enabled)
820 winParams.flags |= bits;
821 else
822 winParams.flags &= ~bits;
823
Michael Kolbc5675ad2011-10-21 13:34:28 -0700824 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700825 }
826
Denise LaFayetteda31d742014-10-10 18:03:13 -0400827 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700828 public void showFullscreen(boolean fullScreen) {
829 //Hide/show system ui bar as needed
830 if (!BrowserSettings.getInstance().useFullscreen())
831 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700832 //Hide/show topbar as needed
833 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700834 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700835 if (fullScreen) {
836 //hide topbar
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700837 bwv.enableTopControls(false);
Vivek Sekhare337acf2015-04-02 21:00:48 -0700838 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700839 } else {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700840 bwv.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700841 //show the topbar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700842 mTitleBar.showTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700843 //enable for auto-hide
844 if (!mTitleBar.isFixed())
Vivek Sekhare337acf2015-04-02 21:00:48 -0700845 mTitleBar.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700846 }
847 }
848 }
849
Tarun Nainani8eb00912014-07-17 12:28:32 -0700850 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700851 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700852 if (topControlsOffsetYPix != 0.0) {
853 mTitleBar.setEnabled(false);
854 } else {
855 mTitleBar.setEnabled(true);
856 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800857 if (!mTitleBar.isFixed()) {
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800858 float currentY = mTitleBar.getTranslationY();
Devdeep Choudhury904c7062015-03-17 19:47:29 -0700859 float height = mNavigationBar.getHeight();
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800860 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
861 mTitleBar.requestLayout();
862 } else if ((height + topControlsOffsetYPix) <= 0) {
863 topControlsOffsetYPix -= 1;
864 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
865 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800866 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800867 // This was done to get HTML5 fullscreen API to work with fixed mode since
868 // topcontrols are used to implement HTML5 fullscreen
869 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700870 }
871 }
872
John Reck0f602f32011-07-07 15:38:43 -0700873 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800874 if (ENABLE_BORDER_AROUND_FAVICON) {
875 Drawable[] array = new Drawable[3];
876 array[0] = new PaintDrawable(Color.BLACK);
877 PaintDrawable p = new PaintDrawable(Color.WHITE);
878 array[1] = p;
879 if (icon == null) {
880 array[2] = getGenericFavicon();
881 } else {
882 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
883 }
884 LayerDrawable d = new LayerDrawable(array);
885 d.setLayerInset(1, 1, 1, 1, 1);
886 d.setLayerInset(2, 2, 2, 2, 2);
887 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700888 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800889 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700890 }
891
John Reck5d43ce82011-06-21 17:16:51 -0700892 public boolean isLoading() {
893 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
894 }
895
896 /**
897 * Suggest to the UI that the title bar can be hidden. The UI will then
898 * decide whether or not to hide based off a number of factors, such
899 * as if the user is editing the URL bar or if the page is loading
900 */
901 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700902 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
903 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700904 hideTitleBar();
905 }
906 }
907
John Reckbc6adb42011-09-01 18:03:20 -0700908 protected final void showTitleBarForDuration() {
909 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
910 }
911
912 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700913 showTitleBar();
914 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700915 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700916 }
917
Enrico Ros1f5a0952014-11-18 20:15:48 -0800918 protected void setMenuItemVisibility(Menu menu, int id,
919 boolean visibility) {
920 MenuItem item = menu.findItem(id);
921 if (item != null) {
922 item.setVisible(visibility);
923 }
924 }
925
John Reck9c5004e2011-10-07 16:00:12 -0700926 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700927
928 @Override
929 public void handleMessage(Message msg) {
930 if (msg.what == MSG_HIDE_TITLEBAR) {
931 suggestHideTitleBar();
932 }
John Reck9c5004e2011-10-07 16:00:12 -0700933 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700934 }
935 };
John Reck3ba45532011-08-11 16:26:53 -0700936
John Reck9c5004e2011-10-07 16:00:12 -0700937 protected void handleMessage(Message msg) {}
938
John Reck3ba45532011-08-11 16:26:53 -0700939 @Override
940 public void showWeb(boolean animate) {
941 mUiController.hideCustomView();
942 }
943
John Reck2711fab2012-05-18 21:38:59 -0700944 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800945 FrameLayout.LayoutParams params =
946 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700947 if (params.topMargin != margin) {
948 params.topMargin = margin;
949 mContentView.setLayoutParams(params);
950 }
951 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700952
953 @Override
954 public boolean blockFocusAnimations() {
955 return mBlockFocusAnimations;
956 }
957
Michael Kolb0b129122012-06-04 16:31:58 -0700958 @Override
959 public void onVoiceResult(String result) {
960 mNavigationBar.onVoiceResult(result);
961 }
962
kaiyizbb2db872013-08-01 22:24:07 -0400963 protected UiController getUiController() {
964 return mUiController;
965 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700966
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700967 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700968 private float getActionModeHeight() {
969 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
970 new int[] { android.R.attr.actionBarSize });
971 float size = actionBarSizeTypedArray.getDimension(0, 0f);
972 actionBarSizeTypedArray.recycle();
973 return size;
974 }
975
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700976
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700977 @Override
978 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700979 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700980
981 if (mTitleBar.isFixed()) {
982 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700983 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700984 } else {
985 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700986 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700987 }
988
989 @Override
990 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700991 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700992 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700993 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700994 } else {
995 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700996 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700997 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700998}