blob: 5934fe1be7cbfbac4ae7dbb230c42e26471be40e [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;
Sagar Dhawan55165b82015-09-03 15:33:02 -0700105 private final static int mFullScreenImmersiveSetting =
106 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
107 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
108 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
109 View.SYSTEM_UI_FLAG_FULLSCREEN |
110 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
Michael Kolb8233fac2010-10-26 16:08:53 -0700111
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700112 private EdgeSwipeController mEdgeSwipeController;
113 private EdgeSwipeSettings mEdgeSwipeSettings;
114
Sagar Dhawan55165b82015-09-03 15:33:02 -0700115 // This Runnable is used to re-set fullscreen mode after resume.
116 // The immersive mode API on android <6.0 is buggy and will more
117 // often then not glitch out. Using a runnable really helps reduce
118 // the repeatability of this framework bug, however some corner cases
119 // remain. Specifically when interacting with pop-up windows(menu).
120 private Runnable mFullScreenModeRunnable = new Runnable() {
121 @Override
122 public void run() {
123 if (BrowserSettings.getInstance() != null)
124 setFullscreen(BrowserSettings.getInstance().useFullscreen());
125 }
126 };
127
Michael Kolb8233fac2010-10-26 16:08:53 -0700128 public BaseUi(Activity browser, UiController controller) {
129 mActivity = browser;
130 mUiController = controller;
131 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800132 mInputManager = (InputMethodManager)
133 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800134 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
135 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700136 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
137 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700138 LayoutInflater.from(mActivity)
139 .inflate(R.layout.custom_screen, frameLayout);
140 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700141 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700142 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
143 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700144 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700145 mTitleBar = new TitleBar(mActivity, mUiController, this,
146 mContentView);
147 mTitleBar.setProgress(100);
148 mNavigationBar = mTitleBar.getNavigationBar();
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800149
150 // install system ui visibility listeners
151 mDecorView = mActivity.getWindow().getDecorView();
152 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700153 mFullscreenModeLocked = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700154 }
155
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800156 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
157 new View.OnSystemUiVisibilityChangeListener() {
158 @Override
159 public void onSystemUiVisibilityChange(int visFlags) {
Sagar Dhawan55165b82015-09-03 15:33:02 -0700160 final boolean lostFullscreen = (visFlags & mFullScreenImmersiveSetting) == 0;
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800161 if (lostFullscreen)
162 setFullscreen(BrowserSettings.getInstance().useFullscreen());
163 }
164 };
165
Michael Kolb8233fac2010-10-26 16:08:53 -0700166 private void cancelStopToast() {
167 if (mStopToast != null) {
168 mStopToast.cancel();
169 mStopToast = null;
170 }
171 }
172
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700173 protected Drawable getGenericFavicon() {
174 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800175 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700176 }
177 return mGenericFavicon;
178 }
179
Michael Kolb8233fac2010-10-26 16:08:53 -0700180 // lifecycle
181
182 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800183 if (isCustomViewShowing()) {
184 onHideCustomView();
185 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500186 if (mTabControl.getCurrentTab() != null) {
187 mTabControl.getCurrentTab().exitFullscreen();
188 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 cancelStopToast();
190 mActivityPaused = true;
191 }
192
193 public void onResume() {
194 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700195 // check if we exited without setting active tab
196 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800197 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Sagar Dhawan55165b82015-09-03 15:33:02 -0700198 //Work around for < Android M
199 if (Build.VERSION.SDK_INT <= 22 && BrowserSettings.getInstance().useFullscreen())
200 mHandler.postDelayed(mFullScreenModeRunnable, 500);
201
Michael Kolb1a4625a2011-08-24 13:40:44 -0700202 final Tab ct = mTabControl.getCurrentTab();
203 if (ct != null) {
204 setActiveTab(ct);
205 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700206 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700207 }
208
Michael Kolb66706532010-12-12 19:50:22 -0800209 protected boolean isActivityPaused() {
210 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700211 }
212
213 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700214 if (mEdgeSwipeController != null) {
215 mEdgeSwipeController.onConfigurationChanged();
216 }
217 if (mEdgeSwipeSettings != null) {
218 mEdgeSwipeSettings.onConfigurationChanged();
219 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 }
221
John Reck0f602f32011-07-07 15:38:43 -0700222 public Activity getActivity() {
223 return mActivity;
224 }
225
Michael Kolb8233fac2010-10-26 16:08:53 -0700226 // key handling
227
228 @Override
229 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700230 if (mCustomView != null) {
231 mUiController.hideCustomView();
232 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700233 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700234 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700235 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 }
237 return false;
238 }
239
Vivek Sekhard4de6162015-07-21 15:01:45 -0700240 public boolean isFullScreen() {
241 if (mTabControl.getCurrentTab() != null)
242 return mTabControl.getCurrentTab().isTabFullScreen();
243 return false;
244 }
245
Michael Kolb2814a362011-05-19 15:49:41 -0700246 @Override
247 public boolean onMenuKey() {
248 return false;
249 }
250
John Reck30c714c2010-12-16 17:30:34 -0800251 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 @Override
John Reck30c714c2010-12-16 17:30:34 -0800253 public void onTabDataChanged(Tab tab) {
254 setUrlTitle(tab);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700255 updateTabSecurityState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800256 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700257 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700258 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700259 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700260 }
261
262 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700263 public void onProgressChanged(Tab tab) {
264 int progress = tab.getLoadProgress();
265 if (tab.inForeground()) {
Pankaj Gargf9040c82015-08-14 10:19:31 -0700266 if (tab.inPageLoad()) {
267 mTitleBar.setProgress(progress);
268 } else {
269 mTitleBar.setProgress(100);
270 }
Michael Kolbe8a82332012-04-25 14:14:26 -0700271 }
272 }
273
274 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500275 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800276 if (tab.inForeground()) {
277 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700278 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800279 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500280 }
281
282 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700283 public void onPageStopped(Tab tab) {
284 cancelStopToast();
285 if (tab.inForeground()) {
286 mStopToast = Toast
287 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
288 mStopToast.show();
289 }
290 }
291
292 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800293 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700294 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800295 }
296
297 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700298 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700299 }
300
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800301 public void cancelNavScreenRequest(){
302 }
303
Michael Kolb377ea312011-02-17 14:36:56 -0800304 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800305 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400306 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700307 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400308
Michael Kolbbae0cb22012-05-29 11:15:27 -0700309 // block unnecessary focus change animations during tab switch
310 mBlockFocusAnimations = true;
Michael Kolb77df4562010-11-19 14:49:34 -0800311 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400312 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700313 WebView web = mActiveTab.getWebView();
314 if (web != null) {
315 web.setOnTouchListener(null);
316 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700317 }
Michael Kolb77df4562010-11-19 14:49:34 -0800318 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800319
Michael Kolbda580632012-04-16 13:30:28 -0700320 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck5d43ce82011-06-21 17:16:51 -0700321 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700322 if (web != null) {
323 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700324 web.setTitleBar(mTitleBar);
325 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700326 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700327 }
Michael Kolb4923c222012-04-02 16:18:36 -0700328 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700329 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800330 onTabDataChanged(tab);
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700331 setFavicon(tab);
John Reck30c714c2010-12-16 17:30:34 -0800332 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700333 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700334 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400335
Vivek Sekhar943f0672014-05-01 18:35:22 -0700336 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700337
338 updateTabSecurityState(tab);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400339 }
340
341 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700342 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400343 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700344 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400345
Vivek Sekhar943f0672014-05-01 18:35:22 -0700346 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800347
348 if(tabToWaitFor == mTabToRemove) {
349 if (mRunnable != null) {
350 mTitleBar.removeCallbacks(mRunnable);
351 }
352 mTabToRemove = null;
353 mTabToWaitFor = null;
354 mRunnable = null;
355 return;
356 }
357
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400358 //remove previously scehduled tab
359 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700360 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700361 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400362 removeTabFromContentView(mTabToRemove);
363 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700364 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400365 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700366 mTabToRemove = tabToRemove;
367 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400368 mNumRemoveTries = 0;
369
370 if (mTabToRemove != null) {
371 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700372 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400373 }
374 }
375
376 protected void tryRemoveTab() {
377 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700378 // Ensure the webview is still valid
379 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
380 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700381 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700382 mRunnable = new Runnable() {
383 public void run() {
384 tryRemoveTab();
385 }
386 };
387 }
388 /*if the new tab is still not ready, wait another 2 frames
389 before trying again. 1 frame for the tab to render the first
390 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700391 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400392 return;
393 }
394 }
395 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700396 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700397 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400398 removeTabFromContentView(mTabToRemove);
399 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700400 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400401 }
402 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700403 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700404 }
405
Michael Kolbcfa3af52010-12-14 10:36:11 -0800406 Tab getActiveTab() {
407 return mActiveTab;
408 }
409
Michael Kolb8233fac2010-10-26 16:08:53 -0700410 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800411 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800412 }
413
414 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700415 public void removeTab(Tab tab) {
Sagar Dhawan20b1deb2015-10-12 11:13:18 -0700416 removeTabFromContentView(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 }
418
419 @Override
420 public void detachTab(Tab tab) {
421 removeTabFromContentView(tab);
422 }
423
424 @Override
425 public void attachTab(Tab tab) {
426 attachTabToContentView(tab);
427 }
428
Michael Kolb377ea312011-02-17 14:36:56 -0800429 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800430 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700431 return;
432 }
433 View container = tab.getViewContainer();
434 WebView mainView = tab.getWebView();
435 // Attach the WebView to the container and then attach the
436 // container to the content view.
437 FrameLayout wrapper =
438 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700439 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
440
441 if (wrapper != parentView) {
442 // clean up old view before attaching new view
443 // this helping in fixing issues such touch event
444 // getting triggered on old view instead of new one
445 if (parentView != null) {
446 parentView.removeView(mainView.getView());
447 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800448 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700449 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800450 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700451 if (parent != mContentView) {
452 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700453 parent.removeView(container);
454 }
455 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700456 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700457
458 refreshEdgeSwipeController(container);
459
Michael Kolb8233fac2010-10-26 16:08:53 -0700460 mUiController.attachSubWindow(tab);
461 }
462
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700463 public void refreshEdgeSwipeController(View container) {
Site Mao61b68212015-07-16 10:56:31 -0700464 if (isUiLowPowerMode()) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700465 return;
466 }
467
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700468 if (mEdgeSwipeController != null) {
469 mEdgeSwipeController.cleanup();
470 }
471
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700472 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
473
Sagar Dhawan05e3c352015-09-07 15:24:33 +0200474 if (mEdgeSwipeSettings != null) {
475 mEdgeSwipeSettings.cleanup();
476 }
477 mEdgeSwipeSettings = null;
478
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700479 if (action.equalsIgnoreCase(
480 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
481 mEdgeSwipeController = new EdgeSwipeController(
482 container,
483 R.id.stationary_navview,
484 R.id.sliding_navview,
485 R.id.sliding_navview_shadow,
486 R.id.navview_opacity,
487 R.id.webview_wrapper,
488 R.id.draggable_mainframe,
489 this);
490 } else if (action.equalsIgnoreCase(
491 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
492 mEdgeSwipeSettings = new EdgeSwipeSettings(
493 container,
494 R.id.stationary_navview,
495 R.id.edge_sliding_settings,
496 R.id.sliding_navview_shadow,
497 R.id.webview_wrapper,
498 R.id.draggable_mainframe,
499 this);
500 } else {
501 DraggableFrameLayout draggableView = (DraggableFrameLayout)
502 container.findViewById(R.id.draggable_mainframe);
503 draggableView.setDragHelper(null);
504 }
505 }
506
Michael Kolb8233fac2010-10-26 16:08:53 -0700507 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800508 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700509 // Remove the container that contains the main WebView.
510 WebView mainView = tab.getWebView();
511 View container = tab.getViewContainer();
512 if (mainView == null) {
513 return;
514 }
515 // Remove the container from the content and then remove the
516 // WebView from the container. This will trigger a focus change
517 // needed by WebView.
518 FrameLayout wrapper =
519 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800520 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700521 mContentView.removeView(container);
522 mUiController.endActionMode();
523 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700524 }
525
Michael Kolba713ec82010-11-29 17:27:06 -0800526 @Override
527 public void onSetWebView(Tab tab, WebView webView) {
528 View container = tab.getViewContainer();
529 if (container == null) {
530 // The tab consists of a container view, which contains the main
531 // WebView, as well as any other UI elements associated with the tab.
532 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700533 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800534 tab.setViewContainer(container);
535 }
536 if (tab.getWebView() != webView) {
537 // Just remove the old one.
538 FrameLayout wrapper =
539 (FrameLayout) container.findViewById(R.id.webview_wrapper);
540 wrapper.removeView(tab.getWebView());
541 }
542 }
543
Michael Kolb8233fac2010-10-26 16:08:53 -0700544 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800545 * create a sub window container and webview for the tab
546 * Note: this methods operates through side-effects for now
547 * it sets both the subView and subViewContainer for the given tab
548 * @param tab tab to create the sub window for
549 * @param subView webview to be set as a subwindow for the tab
550 */
551 @Override
552 public void createSubWindow(Tab tab, WebView subView) {
553 View subViewContainer = mActivity.getLayoutInflater().inflate(
554 R.layout.browser_subwindow, null);
555 ViewGroup inner = (ViewGroup) subViewContainer
556 .findViewById(R.id.inner_container);
557 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
558 LayoutParams.MATCH_PARENT));
559 final ImageButton cancel = (ImageButton) subViewContainer
560 .findViewById(R.id.subwindow_close);
561 final WebView cancelSubView = subView;
562 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800563 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800564 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800565 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800566 }
567 });
568 tab.setSubWebView(subView);
569 tab.setSubViewContainer(subViewContainer);
570 }
571
572 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700573 * Remove the sub window from the content view.
574 */
575 @Override
576 public void removeSubWindow(View subviewContainer) {
577 mContentView.removeView(subviewContainer);
578 mUiController.endActionMode();
579 }
580
581 /**
582 * Attach the sub window to the content view.
583 */
584 @Override
585 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800586 if (container.getParent() != null) {
587 // already attached, remove first
588 ((ViewGroup) container.getParent()).removeView(container);
589 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700590 mContentView.addView(container, COVER_SCREEN_PARAMS);
591 }
592
Michael Kolb11d19782011-03-20 10:17:40 -0700593 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700594 WebView web = getWebView();
595 if (web != null) {
596 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700597 }
598 }
599
Michael Kolb1f9b3562012-04-24 14:38:34 -0700600 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700601 if (mUiController.isInCustomActionMode()) {
602 mUiController.endActionMode();
603 }
604 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700605 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700606 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700607 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700608 }
609
Michael Kolb7cdc4902011-02-03 17:54:40 -0800610 boolean canShowTitleBar() {
611 return !isTitleBarShowing()
612 && !isActivityPaused()
613 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700614 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800615 && !mUiController.isInCustomActionMode();
616 }
617
John Reck0f602f32011-07-07 15:38:43 -0700618 protected void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700619 if (canShowTitleBar()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700620 mTitleBar.showTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700621 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800622 }
623
624 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700625 if (mTitleBar.isShowing()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700626 mTitleBar.enableTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700627 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800628 }
629
630 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700631 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800632 }
633
John Reck5d43ce82011-06-21 17:16:51 -0700634 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700635 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700636 }
637
Michael Kolb80f75082012-04-10 10:50:06 -0700638 public void stopEditingUrl() {
639 mTitleBar.getNavigationBar().stopEditingUrl();
640 }
641
John Reck0f602f32011-07-07 15:38:43 -0700642 public TitleBar getTitleBar() {
643 return mTitleBar;
644 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800645
Michael Kolb66706532010-12-12 19:50:22 -0800646 @Override
John Reck2bc80422011-06-30 15:11:49 -0700647 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700648 Intent intent = new Intent(mActivity, ComboViewActivity.class);
649 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
650 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
651 Tab t = getActiveTab();
652 if (t != null) {
653 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800654 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700655 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700656 }
657
658 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800659 public void hideComboView() {
660 }
661
662 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400663 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800664 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700665 // if a view already exists then immediately terminate the new one
666 if (mCustomView != null) {
667 callback.onCustomViewHidden();
668 return;
669 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400670 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700671 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400672 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700673 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400674 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700675 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700676 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400677 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700678 }
679
680 @Override
681 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700682 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700683 if (mCustomView == null)
684 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400685 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700686 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400687 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700688 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700689 mCustomViewCallback.onCustomViewHidden();
690 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400691 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700692 }
693
694 @Override
695 public boolean isCustomViewShowing() {
696 return mCustomView != null;
697 }
698
Michael Kolb66706532010-12-12 19:50:22 -0800699 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800700 if (mInputManager.isActive()) {
701 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
702 0);
703 }
704 }
705
Michael Kolb66706532010-12-12 19:50:22 -0800706 @Override
John Reck3ba45532011-08-11 16:26:53 -0700707 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700708 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800709 }
710
Tarun Nainani87a86682015-02-05 11:47:35 -0800711 @Override
712 public boolean isComboViewShowing() {
713 return false;
714 }
715
Site Mao61b68212015-07-16 10:56:31 -0700716 public static boolean isUiLowPowerMode() {
Site Mao7521b092015-07-20 18:27:20 -0700717 return BrowserCommandLine.hasSwitch("ui-low-power-mode")
718 || BrowserSettings.getInstance().isPowerSaveModeEnabled()
719 || BrowserSettings.getInstance().isDisablePerfFeatures();
Site Mao61b68212015-07-16 10:56:31 -0700720 }
721
Michael Kolb8233fac2010-10-26 16:08:53 -0700722 // -------------------------------------------------------------------------
723
Michael Kolb5a72f182011-01-13 20:35:06 -0800724 protected void updateNavigationState(Tab tab) {
725 }
726
Michael Kolb8233fac2010-10-26 16:08:53 -0700727 /**
728 * Update the lock icon to correspond to our latest state.
729 */
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700730 private void updateTabSecurityState(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800731 if (t != null && t.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700732 mNavigationBar.setSecurityState(t.getSecurityState());
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700733 setUrlTitle(t);
Michael Kolb8233fac2010-10-26 16:08:53 -0700734 }
735 }
736
John Reck30c714c2010-12-16 17:30:34 -0800737 protected void setUrlTitle(Tab tab) {
738 String url = tab.getUrl();
739 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800740 if (TextUtils.isEmpty(title)) {
741 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800742 }
Michael Kolb66706532010-12-12 19:50:22 -0800743 if (tab.inForeground()) {
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700744 mNavigationBar.setDisplayTitle(title, url);
Michael Kolb66706532010-12-12 19:50:22 -0800745 }
746 }
747
748 // Set the favicon in the title bar.
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700749 public void setFavicon(Tab tab) {
750 mNavigationBar.showCurrentFavicon(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700751 }
752
Michael Kolb66706532010-12-12 19:50:22 -0800753 // active tabs page
754
755 public void showActiveTabsPage() {
756 }
757
758 /**
759 * Remove the active tabs page.
760 */
761 public void removeActiveTabsPage() {
762 }
763
Michael Kolb8233fac2010-10-26 16:08:53 -0700764 // menu handling callbacks
765
766 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800767 public boolean onPrepareOptionsMenu(Menu menu) {
768 return true;
769 }
770
771 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700772 public void updateMenuState(Tab tab, Menu menu) {
773 }
774
775 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700776 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700777 }
778
779 @Override
780 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700781 }
782
783 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700784 public boolean onOptionsItemSelected(MenuItem item) {
785 return false;
786 }
787
788 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700789 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700790 }
791
792 @Override
793 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700794 }
795
796 @Override
797 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700798 }
799
800 @Override
801 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700802 }
803
Michael Kolb8233fac2010-10-26 16:08:53 -0700804 // -------------------------------------------------------------------------
805 // Helper function for WebChromeClient
806 // -------------------------------------------------------------------------
807
808 @Override
809 public Bitmap getDefaultVideoPoster() {
810 if (mDefaultVideoPoster == null) {
811 mDefaultVideoPoster = BitmapFactory.decodeResource(
812 mActivity.getResources(), R.drawable.default_video_poster);
813 }
814 return mDefaultVideoPoster;
815 }
816
817 @Override
818 public View getVideoLoadingProgressView() {
819 if (mVideoProgressView == null) {
820 LayoutInflater inflater = LayoutInflater.from(mActivity);
821 mVideoProgressView = inflater.inflate(
822 R.layout.video_loading_progress, null);
823 }
824 return mVideoProgressView;
825 }
826
Michael Kolb843510f2010-12-09 10:51:49 -0800827 @Override
828 public void showMaxTabsWarning() {
829 Toast warning = Toast.makeText(mActivity,
830 mActivity.getString(R.string.max_tabs_warning),
831 Toast.LENGTH_SHORT);
832 warning.show();
833 }
834
Michael Kolb46f987e2011-04-05 10:39:10 -0700835 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800836
Michael Kolb46f987e2011-04-05 10:39:10 -0700837 if (mActiveTab != null) {
838 return mActiveTab.getWebView();
839 } else {
840 return null;
841 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700842 }
843
Pankaj Garg62bc7912015-04-14 16:08:59 -0700844 public void forceDisableFullscreenMode(boolean disabled) {
845 mFullscreenModeLocked = false;
846 setFullscreen(!disabled);
847 mFullscreenModeLocked = disabled;
848 }
849
Michael Kolbc38c6042011-04-27 10:46:06 -0700850 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700851 if (mFullscreenModeLocked)
852 return;
853
Michael Kolbc5675ad2011-10-21 13:34:28 -0700854 Window win = mActivity.getWindow();
855 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800856 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500857
858 if (mCustomView != null) {
859 mCustomView.setSystemUiVisibility(enabled ?
Sagar Dhawan55165b82015-09-03 15:33:02 -0700860 mFullScreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800861 } else if (Build.VERSION.SDK_INT >= 19) {
862 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan55165b82015-09-03 15:33:02 -0700863 mFullScreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700864 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500865 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800866 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700867 }
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700868 if (enabled) {
869 winParams.flags |= bits;
870 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500871 winParams.flags &= ~bits;
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700872 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500873
Michael Kolbc5675ad2011-10-21 13:34:28 -0700874 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700875 }
876
Denise LaFayetteda31d742014-10-10 18:03:13 -0400877 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700878 public void showFullscreen(boolean fullScreen) {
Sagar Dhawan2abecc62015-09-14 18:53:04 -0700879
Sudheer Koganti24766882014-10-02 10:58:09 -0700880 //Hide/show system ui bar as needed
881 if (!BrowserSettings.getInstance().useFullscreen())
882 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700883 //Hide/show topbar as needed
884 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700885 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700886 if (fullScreen) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700887 // hide titlebar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700888 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700889 } else {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700890 // show titlebar
891 mTitleBar.showTopControls(false);
892 // enable auto hide titlebar
Sudheer Koganti24766882014-10-02 10:58:09 -0700893 if (!mTitleBar.isFixed())
Vivek Sekhard4de6162015-07-21 15:01:45 -0700894 mTitleBar.enableTopControls(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700895 }
896 }
897 }
898
Tarun Nainani8eb00912014-07-17 12:28:32 -0700899 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700900 if (mTitleBar == null || mTitleBar.isFixed())
901 return;
902 if (!mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700903 if (topControlsOffsetYPix != 0.0) {
904 mTitleBar.setEnabled(false);
905 } else {
906 mTitleBar.setEnabled(true);
907 }
Vivek Sekhard4de6162015-07-21 15:01:45 -0700908 float currentY = mTitleBar.getTranslationY();
909 float height = mNavigationBar.getHeight();
Sagar Dhawaneecefa32015-09-25 12:02:34 -0700910
Vivek Sekhard4de6162015-07-21 15:01:45 -0700911 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
912 mTitleBar.requestLayout();
913 } else if ((height + topControlsOffsetYPix) <= 0) {
Sagar Dhawaneecefa32015-09-25 12:02:34 -0700914 // Need to add the progress bar's margin to the offest since it's height is not
915 // accounted for and the dropshadow draws inside it.
916 topControlsOffsetYPix +=
917 mActivity.getResources().getDimension(R.dimen.progress_bar_margin);
Vivek Sekhard4de6162015-07-21 15:01:45 -0700918 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
Sudheer Koganti56cba972014-11-13 15:15:46 -0800919 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800920 // This was done to get HTML5 fullscreen API to work with fixed mode since
921 // topcontrols are used to implement HTML5 fullscreen
922 mTitleBar.setTranslationY(topControlsOffsetYPix);
Sagar Dhawaneecefa32015-09-25 12:02:34 -0700923
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700924 }
925 }
926
John Reck0f602f32011-07-07 15:38:43 -0700927 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800928 if (ENABLE_BORDER_AROUND_FAVICON) {
929 Drawable[] array = new Drawable[3];
930 array[0] = new PaintDrawable(Color.BLACK);
931 PaintDrawable p = new PaintDrawable(Color.WHITE);
932 array[1] = p;
933 if (icon == null) {
934 array[2] = getGenericFavicon();
935 } else {
936 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
937 }
938 LayerDrawable d = new LayerDrawable(array);
939 d.setLayerInset(1, 1, 1, 1, 1);
940 d.setLayerInset(2, 2, 2, 2, 2);
941 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700942 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800943 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700944 }
945
John Reck5d43ce82011-06-21 17:16:51 -0700946 public boolean isLoading() {
947 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
948 }
949
Enrico Ros1f5a0952014-11-18 20:15:48 -0800950 protected void setMenuItemVisibility(Menu menu, int id,
951 boolean visibility) {
952 MenuItem item = menu.findItem(id);
953 if (item != null) {
954 item.setVisible(visibility);
955 }
956 }
957
John Reck9c5004e2011-10-07 16:00:12 -0700958 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700959
960 @Override
961 public void handleMessage(Message msg) {
John Reck9c5004e2011-10-07 16:00:12 -0700962 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700963 }
964 };
John Reck3ba45532011-08-11 16:26:53 -0700965
John Reck9c5004e2011-10-07 16:00:12 -0700966 protected void handleMessage(Message msg) {}
967
John Reck3ba45532011-08-11 16:26:53 -0700968 @Override
969 public void showWeb(boolean animate) {
970 mUiController.hideCustomView();
971 }
972
John Reck2711fab2012-05-18 21:38:59 -0700973 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800974 FrameLayout.LayoutParams params =
975 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700976 if (params.topMargin != margin) {
977 params.topMargin = margin;
978 mContentView.setLayoutParams(params);
979 }
980 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700981
982 @Override
983 public boolean blockFocusAnimations() {
984 return mBlockFocusAnimations;
985 }
986
Michael Kolb0b129122012-06-04 16:31:58 -0700987 @Override
988 public void onVoiceResult(String result) {
989 mNavigationBar.onVoiceResult(result);
990 }
991
kaiyizbb2db872013-08-01 22:24:07 -0400992 protected UiController getUiController() {
993 return mUiController;
994 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700995
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700996 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700997 private float getActionModeHeight() {
998 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
999 new int[] { android.R.attr.actionBarSize });
1000 float size = actionBarSizeTypedArray.getDimension(0, 0f);
1001 actionBarSizeTypedArray.recycle();
1002 return size;
1003 }
1004
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001005
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001006 @Override
1007 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001008 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001009
1010 if (mTitleBar.isFixed()) {
1011 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001012 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001013 } else {
1014 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001015 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001016 }
1017
1018 @Override
1019 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001020 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001021 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001022 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001023 } else {
1024 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001025 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001026 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -07001027
1028 @Override
1029 public boolean shouldCaptureThumbnails() {
1030 return true;
1031 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001032}