blob: f4e7d164e92adcb091e0de86d458e9f66a5f7eb2 [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;
Sagar Dhawan2abecc62015-09-14 18:53:04 -070049import android.widget.ImageView;
Michael Kolb8233fac2010-10-26 16:08:53 -070050import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070051import android.content.res.TypedArray;
Pankaj Garg62fef2f2015-03-31 10:48:53 -070052
Pankaj Garg18aa0a12015-06-22 11:06:12 -070053import org.codeaurora.swe.BrowserCommandLine;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080054import 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
76 Activity mActivity;
77 UiController mUiController;
78 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080079 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080080 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070081
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070082 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070083
Michael Kolb66706532010-12-12 19:50:22 -080084 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070085 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070086
Michael Kolb31065b12011-10-06 13:51:32 -070087 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080088 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040089 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070090
John Reck718a24d2011-08-12 11:08:30 -070091 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -070092
Michael Kolb8233fac2010-10-26 16:08:53 -070093 // the default <video> poster
94 private Bitmap mDefaultVideoPoster;
95 // the video progress view
96 private View mVideoProgressView;
97
Sagar Dhawan1e040c72014-12-11 20:24:12 -080098 private final View mDecorView;
99
Michael Kolb8233fac2010-10-26 16:08:53 -0700100 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700101 protected TitleBar mTitleBar;
102 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700103 private boolean mBlockFocusAnimations;
Pankaj Garg62bc7912015-04-14 16:08:59 -0700104 private boolean mFullscreenModeLocked;
Michael Kolb8233fac2010-10-26 16:08:53 -0700105
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700106 private EdgeSwipeController mEdgeSwipeController;
107 private EdgeSwipeSettings mEdgeSwipeSettings;
108
Michael Kolb8233fac2010-10-26 16:08:53 -0700109 public BaseUi(Activity browser, UiController controller) {
110 mActivity = browser;
111 mUiController = controller;
112 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800113 mInputManager = (InputMethodManager)
114 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800115 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
116 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700117 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
118 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700119 LayoutInflater.from(mActivity)
120 .inflate(R.layout.custom_screen, frameLayout);
121 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700122 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700123 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
124 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700125 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700126 mTitleBar = new TitleBar(mActivity, mUiController, this,
127 mContentView);
128 mTitleBar.setProgress(100);
129 mNavigationBar = mTitleBar.getNavigationBar();
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800130
131 // install system ui visibility listeners
132 mDecorView = mActivity.getWindow().getDecorView();
133 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700134 mFullscreenModeLocked = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700135 }
136
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800137 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
138 new View.OnSystemUiVisibilityChangeListener() {
139 @Override
140 public void onSystemUiVisibilityChange(int visFlags) {
141 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
142 if (lostFullscreen)
143 setFullscreen(BrowserSettings.getInstance().useFullscreen());
144 }
145 };
146
Michael Kolb8233fac2010-10-26 16:08:53 -0700147 private void cancelStopToast() {
148 if (mStopToast != null) {
149 mStopToast.cancel();
150 mStopToast = null;
151 }
152 }
153
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700154 protected Drawable getGenericFavicon() {
155 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800156 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700157 }
158 return mGenericFavicon;
159 }
160
Michael Kolb8233fac2010-10-26 16:08:53 -0700161 // lifecycle
162
163 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800164 if (isCustomViewShowing()) {
165 onHideCustomView();
166 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500167 if (mTabControl.getCurrentTab() != null) {
168 mTabControl.getCurrentTab().exitFullscreen();
169 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700170 cancelStopToast();
171 mActivityPaused = true;
172 }
173
174 public void onResume() {
175 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700176 // check if we exited without setting active tab
177 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800178 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700179 final Tab ct = mTabControl.getCurrentTab();
180 if (ct != null) {
181 setActiveTab(ct);
182 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700183 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700184 }
185
Michael Kolb66706532010-12-12 19:50:22 -0800186 protected boolean isActivityPaused() {
187 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700188 }
189
190 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700191 if (mEdgeSwipeController != null) {
192 mEdgeSwipeController.onConfigurationChanged();
193 }
194 if (mEdgeSwipeSettings != null) {
195 mEdgeSwipeSettings.onConfigurationChanged();
196 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700197 }
198
John Reck0f602f32011-07-07 15:38:43 -0700199 public Activity getActivity() {
200 return mActivity;
201 }
202
Michael Kolb8233fac2010-10-26 16:08:53 -0700203 // key handling
204
205 @Override
206 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700207 if (mCustomView != null) {
208 mUiController.hideCustomView();
209 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700210 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700211 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700212 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700213 }
214 return false;
215 }
216
Vivek Sekhard4de6162015-07-21 15:01:45 -0700217 public boolean isFullScreen() {
218 if (mTabControl.getCurrentTab() != null)
219 return mTabControl.getCurrentTab().isTabFullScreen();
220 return false;
221 }
222
Michael Kolb2814a362011-05-19 15:49:41 -0700223 @Override
224 public boolean onMenuKey() {
225 return false;
226 }
227
John Reck30c714c2010-12-16 17:30:34 -0800228 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700229 @Override
John Reck30c714c2010-12-16 17:30:34 -0800230 public void onTabDataChanged(Tab tab) {
231 setUrlTitle(tab);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700232 updateTabSecurityState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800233 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700234 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700235 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700236 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700237 }
238
239 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700240 public void onProgressChanged(Tab tab) {
241 int progress = tab.getLoadProgress();
242 if (tab.inForeground()) {
Pankaj Gargf9040c82015-08-14 10:19:31 -0700243 if (tab.inPageLoad()) {
244 mTitleBar.setProgress(progress);
245 } else {
246 mTitleBar.setProgress(100);
247 }
Michael Kolbe8a82332012-04-25 14:14:26 -0700248 }
249 }
250
251 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500252 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800253 if (tab.inForeground()) {
254 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700255 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800256 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500257 }
258
259 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700260 public void onPageStopped(Tab tab) {
261 cancelStopToast();
262 if (tab.inForeground()) {
263 mStopToast = Toast
264 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
265 mStopToast.show();
266 }
267 }
268
269 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800270 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700271 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800272 }
273
274 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700275 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700276 }
277
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800278 public void cancelNavScreenRequest(){
279 }
280
Michael Kolb377ea312011-02-17 14:36:56 -0800281 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800282 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400283 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700284 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400285
Michael Kolbbae0cb22012-05-29 11:15:27 -0700286 // block unnecessary focus change animations during tab switch
287 mBlockFocusAnimations = true;
Michael Kolb77df4562010-11-19 14:49:34 -0800288 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400289 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700290 WebView web = mActiveTab.getWebView();
291 if (web != null) {
292 web.setOnTouchListener(null);
293 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700294 }
Michael Kolb77df4562010-11-19 14:49:34 -0800295 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800296
Michael Kolbda580632012-04-16 13:30:28 -0700297 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck5d43ce82011-06-21 17:16:51 -0700298 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700299 if (web != null) {
300 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700301 web.setTitleBar(mTitleBar);
302 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700303 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700304 }
Michael Kolb4923c222012-04-02 16:18:36 -0700305 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700306 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800307 onTabDataChanged(tab);
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700308 setFavicon(tab);
John Reck30c714c2010-12-16 17:30:34 -0800309 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700310 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700311 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400312
Vivek Sekhar943f0672014-05-01 18:35:22 -0700313 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700314
315 updateTabSecurityState(tab);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400316 }
317
318 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700319 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400320 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700321 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400322
Vivek Sekhar943f0672014-05-01 18:35:22 -0700323 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800324
325 if(tabToWaitFor == mTabToRemove) {
326 if (mRunnable != null) {
327 mTitleBar.removeCallbacks(mRunnable);
328 }
329 mTabToRemove = null;
330 mTabToWaitFor = null;
331 mRunnable = null;
332 return;
333 }
334
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400335 //remove previously scehduled tab
336 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700337 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700338 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400339 removeTabFromContentView(mTabToRemove);
340 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700341 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400342 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700343 mTabToRemove = tabToRemove;
344 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400345 mNumRemoveTries = 0;
346
347 if (mTabToRemove != null) {
348 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700349 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400350 }
351 }
352
353 protected void tryRemoveTab() {
354 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700355 // Ensure the webview is still valid
356 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
357 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700358 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700359 mRunnable = new Runnable() {
360 public void run() {
361 tryRemoveTab();
362 }
363 };
364 }
365 /*if the new tab is still not ready, wait another 2 frames
366 before trying again. 1 frame for the tab to render the first
367 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700368 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400369 return;
370 }
371 }
372 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700373 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700374 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400375 removeTabFromContentView(mTabToRemove);
376 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700377 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400378 }
379 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700380 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700381 }
382
Michael Kolbcfa3af52010-12-14 10:36:11 -0800383 Tab getActiveTab() {
384 return mActiveTab;
385 }
386
Michael Kolb8233fac2010-10-26 16:08:53 -0700387 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800388 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800389 }
390
391 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700392 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800393 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700394 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800395 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700396 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700397 }
398
399 @Override
400 public void detachTab(Tab tab) {
401 removeTabFromContentView(tab);
402 }
403
404 @Override
405 public void attachTab(Tab tab) {
406 attachTabToContentView(tab);
407 }
408
Michael Kolb377ea312011-02-17 14:36:56 -0800409 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800410 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700411 return;
412 }
413 View container = tab.getViewContainer();
414 WebView mainView = tab.getWebView();
415 // Attach the WebView to the container and then attach the
416 // container to the content view.
417 FrameLayout wrapper =
418 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700419 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
420
421 if (wrapper != parentView) {
422 // clean up old view before attaching new view
423 // this helping in fixing issues such touch event
424 // getting triggered on old view instead of new one
425 if (parentView != null) {
426 parentView.removeView(mainView.getView());
427 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800428 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700429 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800430 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700431 if (parent != mContentView) {
432 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700433 parent.removeView(container);
434 }
435 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700436 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700437
438 refreshEdgeSwipeController(container);
439
Michael Kolb8233fac2010-10-26 16:08:53 -0700440 mUiController.attachSubWindow(tab);
441 }
442
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700443 public void refreshEdgeSwipeController(View container) {
Site Mao61b68212015-07-16 10:56:31 -0700444 if (isUiLowPowerMode()) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700445 return;
446 }
447
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700448 if (mEdgeSwipeController != null) {
449 mEdgeSwipeController.cleanup();
450 }
451
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700452 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
453
Sagar Dhawan05e3c352015-09-07 15:24:33 +0200454 if (mEdgeSwipeSettings != null) {
455 mEdgeSwipeSettings.cleanup();
456 }
457 mEdgeSwipeSettings = null;
458
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700459 if (action.equalsIgnoreCase(
460 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
461 mEdgeSwipeController = new EdgeSwipeController(
462 container,
463 R.id.stationary_navview,
464 R.id.sliding_navview,
465 R.id.sliding_navview_shadow,
466 R.id.navview_opacity,
467 R.id.webview_wrapper,
468 R.id.draggable_mainframe,
469 this);
470 } else if (action.equalsIgnoreCase(
471 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
472 mEdgeSwipeSettings = new EdgeSwipeSettings(
473 container,
474 R.id.stationary_navview,
475 R.id.edge_sliding_settings,
476 R.id.sliding_navview_shadow,
477 R.id.webview_wrapper,
478 R.id.draggable_mainframe,
479 this);
480 } else {
481 DraggableFrameLayout draggableView = (DraggableFrameLayout)
482 container.findViewById(R.id.draggable_mainframe);
483 draggableView.setDragHelper(null);
484 }
485 }
486
Michael Kolb8233fac2010-10-26 16:08:53 -0700487 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800488 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700489 // Remove the container that contains the main WebView.
490 WebView mainView = tab.getWebView();
491 View container = tab.getViewContainer();
492 if (mainView == null) {
493 return;
494 }
495 // Remove the container from the content and then remove the
496 // WebView from the container. This will trigger a focus change
497 // needed by WebView.
498 FrameLayout wrapper =
499 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800500 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700501 mContentView.removeView(container);
502 mUiController.endActionMode();
503 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700504 }
505
Michael Kolba713ec82010-11-29 17:27:06 -0800506 @Override
507 public void onSetWebView(Tab tab, WebView webView) {
508 View container = tab.getViewContainer();
509 if (container == null) {
510 // The tab consists of a container view, which contains the main
511 // WebView, as well as any other UI elements associated with the tab.
512 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700513 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800514 tab.setViewContainer(container);
515 }
516 if (tab.getWebView() != webView) {
517 // Just remove the old one.
518 FrameLayout wrapper =
519 (FrameLayout) container.findViewById(R.id.webview_wrapper);
520 wrapper.removeView(tab.getWebView());
521 }
522 }
523
Michael Kolb8233fac2010-10-26 16:08:53 -0700524 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800525 * create a sub window container and webview for the tab
526 * Note: this methods operates through side-effects for now
527 * it sets both the subView and subViewContainer for the given tab
528 * @param tab tab to create the sub window for
529 * @param subView webview to be set as a subwindow for the tab
530 */
531 @Override
532 public void createSubWindow(Tab tab, WebView subView) {
533 View subViewContainer = mActivity.getLayoutInflater().inflate(
534 R.layout.browser_subwindow, null);
535 ViewGroup inner = (ViewGroup) subViewContainer
536 .findViewById(R.id.inner_container);
537 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
538 LayoutParams.MATCH_PARENT));
539 final ImageButton cancel = (ImageButton) subViewContainer
540 .findViewById(R.id.subwindow_close);
541 final WebView cancelSubView = subView;
542 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800543 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800544 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800545 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800546 }
547 });
548 tab.setSubWebView(subView);
549 tab.setSubViewContainer(subViewContainer);
550 }
551
552 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700553 * Remove the sub window from the content view.
554 */
555 @Override
556 public void removeSubWindow(View subviewContainer) {
557 mContentView.removeView(subviewContainer);
558 mUiController.endActionMode();
559 }
560
561 /**
562 * Attach the sub window to the content view.
563 */
564 @Override
565 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800566 if (container.getParent() != null) {
567 // already attached, remove first
568 ((ViewGroup) container.getParent()).removeView(container);
569 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700570 mContentView.addView(container, COVER_SCREEN_PARAMS);
571 }
572
Michael Kolb11d19782011-03-20 10:17:40 -0700573 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700574 WebView web = getWebView();
575 if (web != null) {
576 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700577 }
578 }
579
Michael Kolb1f9b3562012-04-24 14:38:34 -0700580 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700581 if (mUiController.isInCustomActionMode()) {
582 mUiController.endActionMode();
583 }
584 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700585 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700586 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700587 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700588 }
589
Michael Kolb7cdc4902011-02-03 17:54:40 -0800590 boolean canShowTitleBar() {
591 return !isTitleBarShowing()
592 && !isActivityPaused()
593 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700594 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800595 && !mUiController.isInCustomActionMode();
596 }
597
John Reck0f602f32011-07-07 15:38:43 -0700598 protected void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700599 if (canShowTitleBar()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700600 mTitleBar.showTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700601 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800602 }
603
604 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700605 if (mTitleBar.isShowing()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700606 mTitleBar.enableTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700607 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800608 }
609
610 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700611 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800612 }
613
John Reck5d43ce82011-06-21 17:16:51 -0700614 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700615 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700616 }
617
Michael Kolb80f75082012-04-10 10:50:06 -0700618 public void stopEditingUrl() {
619 mTitleBar.getNavigationBar().stopEditingUrl();
620 }
621
John Reck0f602f32011-07-07 15:38:43 -0700622 public TitleBar getTitleBar() {
623 return mTitleBar;
624 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800625
Michael Kolb66706532010-12-12 19:50:22 -0800626 @Override
John Reck2bc80422011-06-30 15:11:49 -0700627 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700628 Intent intent = new Intent(mActivity, ComboViewActivity.class);
629 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
630 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
631 Tab t = getActiveTab();
632 if (t != null) {
633 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800634 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700635 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700636 }
637
638 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800639 public void hideComboView() {
640 }
641
642 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400643 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800644 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700645 // if a view already exists then immediately terminate the new one
646 if (mCustomView != null) {
647 callback.onCustomViewHidden();
648 return;
649 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400650 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700651 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400652 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700653 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400654 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700655 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700656 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400657 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700658 }
659
660 @Override
661 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700662 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 if (mCustomView == null)
664 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400665 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700666 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400667 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700668 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700669 mCustomViewCallback.onCustomViewHidden();
670 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400671 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700672 }
673
674 @Override
675 public boolean isCustomViewShowing() {
676 return mCustomView != null;
677 }
678
Michael Kolb66706532010-12-12 19:50:22 -0800679 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800680 if (mInputManager.isActive()) {
681 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
682 0);
683 }
684 }
685
Michael Kolb66706532010-12-12 19:50:22 -0800686 @Override
John Reck3ba45532011-08-11 16:26:53 -0700687 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700688 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800689 }
690
Tarun Nainani87a86682015-02-05 11:47:35 -0800691 @Override
692 public boolean isComboViewShowing() {
693 return false;
694 }
695
Site Mao61b68212015-07-16 10:56:31 -0700696 public static boolean isUiLowPowerMode() {
Site Mao7521b092015-07-20 18:27:20 -0700697 return BrowserCommandLine.hasSwitch("ui-low-power-mode")
698 || BrowserSettings.getInstance().isPowerSaveModeEnabled()
699 || BrowserSettings.getInstance().isDisablePerfFeatures();
Site Mao61b68212015-07-16 10:56:31 -0700700 }
701
Michael Kolb8233fac2010-10-26 16:08:53 -0700702 // -------------------------------------------------------------------------
703
Michael Kolb5a72f182011-01-13 20:35:06 -0800704 protected void updateNavigationState(Tab tab) {
705 }
706
Michael Kolb8233fac2010-10-26 16:08:53 -0700707 /**
708 * Update the lock icon to correspond to our latest state.
709 */
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700710 private void updateTabSecurityState(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800711 if (t != null && t.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700712 mNavigationBar.setSecurityState(t.getSecurityState());
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700713 setUrlTitle(t);
Michael Kolb8233fac2010-10-26 16:08:53 -0700714 }
715 }
716
John Reck30c714c2010-12-16 17:30:34 -0800717 protected void setUrlTitle(Tab tab) {
718 String url = tab.getUrl();
719 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800720 if (TextUtils.isEmpty(title)) {
721 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800722 }
Michael Kolb66706532010-12-12 19:50:22 -0800723 if (tab.inForeground()) {
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700724 mNavigationBar.setDisplayTitle(title, url);
Michael Kolb66706532010-12-12 19:50:22 -0800725 }
726 }
727
728 // Set the favicon in the title bar.
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700729 public void setFavicon(Tab tab) {
730 mNavigationBar.showCurrentFavicon(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700731 }
732
Michael Kolb66706532010-12-12 19:50:22 -0800733 // active tabs page
734
735 public void showActiveTabsPage() {
736 }
737
738 /**
739 * Remove the active tabs page.
740 */
741 public void removeActiveTabsPage() {
742 }
743
Michael Kolb8233fac2010-10-26 16:08:53 -0700744 // menu handling callbacks
745
746 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800747 public boolean onPrepareOptionsMenu(Menu menu) {
748 return true;
749 }
750
751 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700752 public void updateMenuState(Tab tab, Menu menu) {
753 }
754
755 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700756 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700757 }
758
759 @Override
760 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700761 }
762
763 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700764 public boolean onOptionsItemSelected(MenuItem item) {
765 return false;
766 }
767
768 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700769 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700770 }
771
772 @Override
773 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700774 }
775
776 @Override
777 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700778 }
779
780 @Override
781 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700782 }
783
Michael Kolb8233fac2010-10-26 16:08:53 -0700784 // -------------------------------------------------------------------------
785 // Helper function for WebChromeClient
786 // -------------------------------------------------------------------------
787
788 @Override
789 public Bitmap getDefaultVideoPoster() {
790 if (mDefaultVideoPoster == null) {
791 mDefaultVideoPoster = BitmapFactory.decodeResource(
792 mActivity.getResources(), R.drawable.default_video_poster);
793 }
794 return mDefaultVideoPoster;
795 }
796
797 @Override
798 public View getVideoLoadingProgressView() {
799 if (mVideoProgressView == null) {
800 LayoutInflater inflater = LayoutInflater.from(mActivity);
801 mVideoProgressView = inflater.inflate(
802 R.layout.video_loading_progress, null);
803 }
804 return mVideoProgressView;
805 }
806
Michael Kolb843510f2010-12-09 10:51:49 -0800807 @Override
808 public void showMaxTabsWarning() {
809 Toast warning = Toast.makeText(mActivity,
810 mActivity.getString(R.string.max_tabs_warning),
811 Toast.LENGTH_SHORT);
812 warning.show();
813 }
814
Michael Kolb46f987e2011-04-05 10:39:10 -0700815 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800816
Michael Kolb46f987e2011-04-05 10:39:10 -0700817 if (mActiveTab != null) {
818 return mActiveTab.getWebView();
819 } else {
820 return null;
821 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700822 }
823
Pankaj Garg62bc7912015-04-14 16:08:59 -0700824 public void forceDisableFullscreenMode(boolean disabled) {
825 mFullscreenModeLocked = false;
826 setFullscreen(!disabled);
827 mFullscreenModeLocked = disabled;
828 }
829
Michael Kolbc38c6042011-04-27 10:46:06 -0700830 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700831 if (mFullscreenModeLocked)
832 return;
833
Michael Kolbc5675ad2011-10-21 13:34:28 -0700834 Window win = mActivity.getWindow();
835 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800836 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500837 final int fullscreenImmersiveSetting =
838 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
839 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
840 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
841 View.SYSTEM_UI_FLAG_FULLSCREEN |
842 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
843
844 if (mCustomView != null) {
845 mCustomView.setSystemUiVisibility(enabled ?
846 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800847 } else if (Build.VERSION.SDK_INT >= 19) {
848 mContentView.setSystemUiVisibility(enabled ?
849 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700850 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500851 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800852 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700853 }
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700854 if (enabled) {
855 winParams.flags |= bits;
856 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500857 winParams.flags &= ~bits;
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700858 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500859
Michael Kolbc5675ad2011-10-21 13:34:28 -0700860 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700861 }
862
Denise LaFayetteda31d742014-10-10 18:03:13 -0400863 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700864 public void showFullscreen(boolean fullScreen) {
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700865 ImageView shadow = (ImageView) mActivity.findViewById(R.id.titleBar_dropShadow);
866
Sudheer Koganti24766882014-10-02 10:58:09 -0700867 //Hide/show system ui bar as needed
868 if (!BrowserSettings.getInstance().useFullscreen())
869 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700870 //Hide/show topbar as needed
871 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700872 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700873 if (fullScreen) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700874 // hide titlebar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700875 mTitleBar.hideTopControls(true);
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700876 //Hide the Titlebar DropShadow
877 shadow.setVisibility(View.GONE);
Sudheer Koganti24766882014-10-02 10:58:09 -0700878 } else {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700879 // show titlebar
880 mTitleBar.showTopControls(false);
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700881 //Show the Titlebar DropShadow
882 shadow.setVisibility(View.VISIBLE);
Vivek Sekhard4de6162015-07-21 15:01:45 -0700883 // enable auto hide titlebar
Sudheer Koganti24766882014-10-02 10:58:09 -0700884 if (!mTitleBar.isFixed())
Vivek Sekhard4de6162015-07-21 15:01:45 -0700885 mTitleBar.enableTopControls(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700886 }
887 }
888 }
889
Tarun Nainani8eb00912014-07-17 12:28:32 -0700890 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700891 if (mTitleBar == null || mTitleBar.isFixed())
892 return;
893 if (!mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700894 if (topControlsOffsetYPix != 0.0) {
895 mTitleBar.setEnabled(false);
896 } else {
897 mTitleBar.setEnabled(true);
898 }
Vivek Sekhard4de6162015-07-21 15:01:45 -0700899 float currentY = mTitleBar.getTranslationY();
900 float height = mNavigationBar.getHeight();
901 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
902 mTitleBar.requestLayout();
903 } else if ((height + topControlsOffsetYPix) <= 0) {
904 topControlsOffsetYPix -= 1;
905 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
Sudheer Koganti56cba972014-11-13 15:15:46 -0800906 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800907 // This was done to get HTML5 fullscreen API to work with fixed mode since
908 // topcontrols are used to implement HTML5 fullscreen
909 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700910 }
911 }
912
John Reck0f602f32011-07-07 15:38:43 -0700913 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800914 if (ENABLE_BORDER_AROUND_FAVICON) {
915 Drawable[] array = new Drawable[3];
916 array[0] = new PaintDrawable(Color.BLACK);
917 PaintDrawable p = new PaintDrawable(Color.WHITE);
918 array[1] = p;
919 if (icon == null) {
920 array[2] = getGenericFavicon();
921 } else {
922 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
923 }
924 LayerDrawable d = new LayerDrawable(array);
925 d.setLayerInset(1, 1, 1, 1, 1);
926 d.setLayerInset(2, 2, 2, 2, 2);
927 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700928 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800929 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700930 }
931
John Reck5d43ce82011-06-21 17:16:51 -0700932 public boolean isLoading() {
933 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
934 }
935
Enrico Ros1f5a0952014-11-18 20:15:48 -0800936 protected void setMenuItemVisibility(Menu menu, int id,
937 boolean visibility) {
938 MenuItem item = menu.findItem(id);
939 if (item != null) {
940 item.setVisible(visibility);
941 }
942 }
943
John Reck9c5004e2011-10-07 16:00:12 -0700944 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700945
946 @Override
947 public void handleMessage(Message msg) {
John Reck9c5004e2011-10-07 16:00:12 -0700948 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700949 }
950 };
John Reck3ba45532011-08-11 16:26:53 -0700951
John Reck9c5004e2011-10-07 16:00:12 -0700952 protected void handleMessage(Message msg) {}
953
John Reck3ba45532011-08-11 16:26:53 -0700954 @Override
955 public void showWeb(boolean animate) {
956 mUiController.hideCustomView();
957 }
958
John Reck2711fab2012-05-18 21:38:59 -0700959 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800960 FrameLayout.LayoutParams params =
961 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700962 if (params.topMargin != margin) {
963 params.topMargin = margin;
964 mContentView.setLayoutParams(params);
965 }
966 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700967
968 @Override
969 public boolean blockFocusAnimations() {
970 return mBlockFocusAnimations;
971 }
972
Michael Kolb0b129122012-06-04 16:31:58 -0700973 @Override
974 public void onVoiceResult(String result) {
975 mNavigationBar.onVoiceResult(result);
976 }
977
kaiyizbb2db872013-08-01 22:24:07 -0400978 protected UiController getUiController() {
979 return mUiController;
980 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700981
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700982 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700983 private float getActionModeHeight() {
984 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
985 new int[] { android.R.attr.actionBarSize });
986 float size = actionBarSizeTypedArray.getDimension(0, 0f);
987 actionBarSizeTypedArray.recycle();
988 return size;
989 }
990
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700991
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700992 @Override
993 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700994 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700995
996 if (mTitleBar.isFixed()) {
997 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700998 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700999 } else {
1000 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001001 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001002 }
1003
1004 @Override
1005 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001006 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001007 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001008 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001009 } else {
1010 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001011 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001012 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -07001013
1014 @Override
1015 public boolean shouldCaptureThumbnails() {
1016 return true;
1017 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001018}