blob: 3682d69aeccc555a0d02dbe4e85651eed95c6ef2 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolb8233fac2010-10-26 16:08:53 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
John Reckd3e4d5b2011-07-13 15:48:43 -070020import android.content.Intent;
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.content.res.Configuration;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.graphics.Bitmap;
23import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070024import android.graphics.Color;
25import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070027import android.graphics.drawable.LayerDrawable;
28import android.graphics.drawable.PaintDrawable;
Sagar Dhawan1e040c72014-12-11 20:24:12 -080029import android.os.Build;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.os.Bundle;
John Reck5d43ce82011-06-21 17:16:51 -070031import android.os.Handler;
32import android.os.Message;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.text.TextUtils;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -070034import android.view.ActionMode;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.Gravity;
36import android.view.LayoutInflater;
37import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070038import android.view.MenuItem;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080040import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.view.ViewGroup.LayoutParams;
Michael Kolbc5675ad2011-10-21 13:34:28 -070043import android.view.Window;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080045import android.view.inputmethod.InputMethodManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080046import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080048import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070050import android.content.res.TypedArray;
Pankaj Garg62fef2f2015-03-31 10:48:53 -070051
Pankaj Garg18aa0a12015-06-22 11:06:12 -070052import org.codeaurora.swe.BrowserCommandLine;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080053import org.codeaurora.swe.WebView;
John Reckbf2ec202011-06-29 17:47:38 -070054
Michael Kolb1bf23132010-11-19 12:55:12 -080055import java.util.List;
56
Michael Kolb8233fac2010-10-26 16:08:53 -070057/**
58 * UI interface definitions
59 */
John Reck718a24d2011-08-12 11:08:30 -070060public abstract class BaseUi implements UI {
Michael Kolb8233fac2010-10-26 16:08:53 -070061
Enrico Ros1f5a0952014-11-18 20:15:48 -080062 protected static final boolean ENABLE_BORDER_AROUND_FAVICON = false;
Michael Kolb8233fac2010-10-26 16:08:53 -070063
Michael Kolb66706532010-12-12 19:50:22 -080064 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070065 new FrameLayout.LayoutParams(
66 ViewGroup.LayoutParams.MATCH_PARENT,
67 ViewGroup.LayoutParams.MATCH_PARENT);
68
Michael Kolb66706532010-12-12 19:50:22 -080069 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070070 new FrameLayout.LayoutParams(
71 ViewGroup.LayoutParams.MATCH_PARENT,
72 ViewGroup.LayoutParams.MATCH_PARENT,
73 Gravity.CENTER);
74
John Reck5d43ce82011-06-21 17:16:51 -070075 private static final int MSG_HIDE_TITLEBAR = 1;
John Reckef654f12011-07-12 16:42:08 -070076 public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
John Reck5d43ce82011-06-21 17:16:51 -070077
Michael Kolb8233fac2010-10-26 16:08:53 -070078 Activity mActivity;
79 UiController mUiController;
80 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080081 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080082 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070083
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070084 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070085
Michael Kolb66706532010-12-12 19:50:22 -080086 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070087 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070088
Michael Kolb31065b12011-10-06 13:51:32 -070089 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080090 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040091 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070092
John Reck718a24d2011-08-12 11:08:30 -070093 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070094
John Reck718a24d2011-08-12 11:08:30 -070095 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -070096
Michael Kolb8233fac2010-10-26 16:08:53 -070097 // the default <video> poster
98 private Bitmap mDefaultVideoPoster;
99 // the video progress view
100 private View mVideoProgressView;
101
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800102 private final View mDecorView;
103
Michael Kolb8233fac2010-10-26 16:08:53 -0700104 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700105 protected TitleBar mTitleBar;
106 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700107 private boolean mBlockFocusAnimations;
Pankaj Garg62bc7912015-04-14 16:08:59 -0700108 private boolean mFullscreenModeLocked;
Michael Kolb8233fac2010-10-26 16:08:53 -0700109
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700110 private EdgeSwipeController mEdgeSwipeController;
111 private EdgeSwipeSettings mEdgeSwipeSettings;
112
Michael Kolb8233fac2010-10-26 16:08:53 -0700113 public BaseUi(Activity browser, UiController controller) {
114 mActivity = browser;
115 mUiController = controller;
116 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800117 mInputManager = (InputMethodManager)
118 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800119 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
120 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700121 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
122 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700123 LayoutInflater.from(mActivity)
124 .inflate(R.layout.custom_screen, frameLayout);
125 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700126 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700127 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
128 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700129 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700130 mTitleBar = new TitleBar(mActivity, mUiController, this,
131 mContentView);
132 mTitleBar.setProgress(100);
133 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700134 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800135
136 // install system ui visibility listeners
137 mDecorView = mActivity.getWindow().getDecorView();
138 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700139 mFullscreenModeLocked = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700140 }
141
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800142 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
143 new View.OnSystemUiVisibilityChangeListener() {
144 @Override
145 public void onSystemUiVisibilityChange(int visFlags) {
146 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
147 if (lostFullscreen)
148 setFullscreen(BrowserSettings.getInstance().useFullscreen());
149 }
150 };
151
Michael Kolb8233fac2010-10-26 16:08:53 -0700152 private void cancelStopToast() {
153 if (mStopToast != null) {
154 mStopToast.cancel();
155 mStopToast = null;
156 }
157 }
158
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700159 protected Drawable getGenericFavicon() {
160 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800161 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700162 }
163 return mGenericFavicon;
164 }
165
Michael Kolb8233fac2010-10-26 16:08:53 -0700166 // lifecycle
167
168 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800169 if (isCustomViewShowing()) {
170 onHideCustomView();
171 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500172 if (mTabControl.getCurrentTab() != null) {
173 mTabControl.getCurrentTab().exitFullscreen();
174 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700175 cancelStopToast();
176 mActivityPaused = true;
177 }
178
179 public void onResume() {
180 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700181 // check if we exited without setting active tab
182 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800183 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700184 final Tab ct = mTabControl.getCurrentTab();
185 if (ct != null) {
186 setActiveTab(ct);
187 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700188 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 }
190
Michael Kolb66706532010-12-12 19:50:22 -0800191 protected boolean isActivityPaused() {
192 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700193 }
194
195 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700196 if (mEdgeSwipeController != null) {
197 mEdgeSwipeController.onConfigurationChanged();
198 }
199 if (mEdgeSwipeSettings != null) {
200 mEdgeSwipeSettings.onConfigurationChanged();
201 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700202 }
203
John Reck0f602f32011-07-07 15:38:43 -0700204 public Activity getActivity() {
205 return mActivity;
206 }
207
Michael Kolb8233fac2010-10-26 16:08:53 -0700208 // key handling
209
210 @Override
211 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700212 if (mCustomView != null) {
213 mUiController.hideCustomView();
214 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700215 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700216 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700217 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700218 }
219 return false;
220 }
221
Michael Kolb2814a362011-05-19 15:49:41 -0700222 @Override
223 public boolean onMenuKey() {
224 return false;
225 }
226
John Reck30c714c2010-12-16 17:30:34 -0800227 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 @Override
John Reck30c714c2010-12-16 17:30:34 -0800229 public void onTabDataChanged(Tab tab) {
230 setUrlTitle(tab);
231 setFavicon(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()) {
243 mTitleBar.setProgress(progress);
244 }
245 }
246
247 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500248 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800249 if (tab.inForeground()) {
250 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700251 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800252 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500253 }
254
255 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700256 public void onPageStopped(Tab tab) {
257 cancelStopToast();
258 if (tab.inForeground()) {
259 mStopToast = Toast
260 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
261 mStopToast.show();
262 }
263 }
264
265 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800266 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700267 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800268 }
269
270 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700272 }
273
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800274 public void cancelNavScreenRequest(){
275 }
276
Michael Kolb377ea312011-02-17 14:36:56 -0800277 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800278 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400279 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700280 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400281
Michael Kolbbae0cb22012-05-29 11:15:27 -0700282 // block unnecessary focus change animations during tab switch
283 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700284 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800285 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400286 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700287 WebView web = mActiveTab.getWebView();
288 if (web != null) {
289 web.setOnTouchListener(null);
290 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700291 }
Michael Kolb77df4562010-11-19 14:49:34 -0800292 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800293
Michael Kolbda580632012-04-16 13:30:28 -0700294 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700295 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700296 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700297 if (web != null) {
298 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700299 web.setTitleBar(mTitleBar);
300 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700301 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700302 }
Michael Kolb4923c222012-04-02 16:18:36 -0700303 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700304 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800305 onTabDataChanged(tab);
306 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700307 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700308 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400309
Vivek Sekhar943f0672014-05-01 18:35:22 -0700310 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700311
312 updateTabSecurityState(tab);
313 mTitleBar.setSkipTitleBarAnimations(false);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400314 }
315
316 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700317 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400318 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700319 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400320
Vivek Sekhar943f0672014-05-01 18:35:22 -0700321 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800322
323 if(tabToWaitFor == mTabToRemove) {
324 if (mRunnable != null) {
325 mTitleBar.removeCallbacks(mRunnable);
326 }
327 mTabToRemove = null;
328 mTabToWaitFor = null;
329 mRunnable = null;
330 return;
331 }
332
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400333 //remove previously scehduled tab
334 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700335 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700336 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400337 removeTabFromContentView(mTabToRemove);
338 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700339 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400340 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700341 mTabToRemove = tabToRemove;
342 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400343 mNumRemoveTries = 0;
344
345 if (mTabToRemove != null) {
346 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700347 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400348 }
349 }
350
351 protected void tryRemoveTab() {
352 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700353 // Ensure the webview is still valid
354 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
355 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700356 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700357 mRunnable = new Runnable() {
358 public void run() {
359 tryRemoveTab();
360 }
361 };
362 }
363 /*if the new tab is still not ready, wait another 2 frames
364 before trying again. 1 frame for the tab to render the first
365 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700366 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400367 return;
368 }
369 }
370 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700371 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700372 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400373 removeTabFromContentView(mTabToRemove);
374 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700375 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400376 }
377 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700378 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700379 }
380
John Reck718a24d2011-08-12 11:08:30 -0700381 protected void updateUrlBarAutoShowManagerTarget() {
382 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700383 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700384 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700385 }
386 }
387
Michael Kolbcfa3af52010-12-14 10:36:11 -0800388 Tab getActiveTab() {
389 return mActiveTab;
390 }
391
Michael Kolb8233fac2010-10-26 16:08:53 -0700392 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800393 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800394 }
395
396 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700397 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800398 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700399 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800400 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700401 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700402 }
403
404 @Override
405 public void detachTab(Tab tab) {
406 removeTabFromContentView(tab);
407 }
408
409 @Override
410 public void attachTab(Tab tab) {
411 attachTabToContentView(tab);
412 }
413
Michael Kolb377ea312011-02-17 14:36:56 -0800414 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800415 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700416 return;
417 }
418 View container = tab.getViewContainer();
419 WebView mainView = tab.getWebView();
420 // Attach the WebView to the container and then attach the
421 // container to the content view.
422 FrameLayout wrapper =
423 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700424 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
425
426 if (wrapper != parentView) {
427 // clean up old view before attaching new view
428 // this helping in fixing issues such touch event
429 // getting triggered on old view instead of new one
430 if (parentView != null) {
431 parentView.removeView(mainView.getView());
432 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800433 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700434 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800435 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700436 if (parent != mContentView) {
437 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700438 parent.removeView(container);
439 }
440 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700441 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700442
443 refreshEdgeSwipeController(container);
444
Michael Kolb8233fac2010-10-26 16:08:53 -0700445 mUiController.attachSubWindow(tab);
446 }
447
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700448 public void refreshEdgeSwipeController(View container) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700449 if (BrowserCommandLine.hasSwitch("ui-low-power-mode")) {
450 return;
451 }
452
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700453 if (mEdgeSwipeController != null) {
454 mEdgeSwipeController.cleanup();
455 }
456
457 mEdgeSwipeSettings = null;
458
459 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
460
461 if (action.equalsIgnoreCase(
462 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
463 mEdgeSwipeController = new EdgeSwipeController(
464 container,
465 R.id.stationary_navview,
466 R.id.sliding_navview,
467 R.id.sliding_navview_shadow,
468 R.id.navview_opacity,
469 R.id.webview_wrapper,
470 R.id.draggable_mainframe,
471 this);
472 } else if (action.equalsIgnoreCase(
473 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
474 mEdgeSwipeSettings = new EdgeSwipeSettings(
475 container,
476 R.id.stationary_navview,
477 R.id.edge_sliding_settings,
478 R.id.sliding_navview_shadow,
479 R.id.webview_wrapper,
480 R.id.draggable_mainframe,
481 this);
482 } else {
483 DraggableFrameLayout draggableView = (DraggableFrameLayout)
484 container.findViewById(R.id.draggable_mainframe);
485 draggableView.setDragHelper(null);
486 }
487 }
488
Michael Kolb8233fac2010-10-26 16:08:53 -0700489 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800490 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700491 // Remove the container that contains the main WebView.
492 WebView mainView = tab.getWebView();
493 View container = tab.getViewContainer();
494 if (mainView == null) {
495 return;
496 }
497 // Remove the container from the content and then remove the
498 // WebView from the container. This will trigger a focus change
499 // needed by WebView.
500 FrameLayout wrapper =
501 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800502 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700503 mContentView.removeView(container);
504 mUiController.endActionMode();
505 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700506 }
507
Michael Kolba713ec82010-11-29 17:27:06 -0800508 @Override
509 public void onSetWebView(Tab tab, WebView webView) {
510 View container = tab.getViewContainer();
511 if (container == null) {
512 // The tab consists of a container view, which contains the main
513 // WebView, as well as any other UI elements associated with the tab.
514 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700515 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800516 tab.setViewContainer(container);
517 }
518 if (tab.getWebView() != webView) {
519 // Just remove the old one.
520 FrameLayout wrapper =
521 (FrameLayout) container.findViewById(R.id.webview_wrapper);
522 wrapper.removeView(tab.getWebView());
523 }
524 }
525
Michael Kolb8233fac2010-10-26 16:08:53 -0700526 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800527 * create a sub window container and webview for the tab
528 * Note: this methods operates through side-effects for now
529 * it sets both the subView and subViewContainer for the given tab
530 * @param tab tab to create the sub window for
531 * @param subView webview to be set as a subwindow for the tab
532 */
533 @Override
534 public void createSubWindow(Tab tab, WebView subView) {
535 View subViewContainer = mActivity.getLayoutInflater().inflate(
536 R.layout.browser_subwindow, null);
537 ViewGroup inner = (ViewGroup) subViewContainer
538 .findViewById(R.id.inner_container);
539 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
540 LayoutParams.MATCH_PARENT));
541 final ImageButton cancel = (ImageButton) subViewContainer
542 .findViewById(R.id.subwindow_close);
543 final WebView cancelSubView = subView;
544 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800545 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800546 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800547 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800548 }
549 });
550 tab.setSubWebView(subView);
551 tab.setSubViewContainer(subViewContainer);
552 }
553
554 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700555 * Remove the sub window from the content view.
556 */
557 @Override
558 public void removeSubWindow(View subviewContainer) {
559 mContentView.removeView(subviewContainer);
560 mUiController.endActionMode();
561 }
562
563 /**
564 * Attach the sub window to the content view.
565 */
566 @Override
567 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800568 if (container.getParent() != null) {
569 // already attached, remove first
570 ((ViewGroup) container.getParent()).removeView(container);
571 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700572 mContentView.addView(container, COVER_SCREEN_PARAMS);
573 }
574
Michael Kolb11d19782011-03-20 10:17:40 -0700575 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700576 WebView web = getWebView();
577 if (web != null) {
578 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700579 }
580 }
581
Michael Kolb1f9b3562012-04-24 14:38:34 -0700582 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700583 if (mUiController.isInCustomActionMode()) {
584 mUiController.endActionMode();
585 }
586 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700587 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700588 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700589 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700590 }
591
Michael Kolb7cdc4902011-02-03 17:54:40 -0800592 boolean canShowTitleBar() {
593 return !isTitleBarShowing()
594 && !isActivityPaused()
595 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700596 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800597 && !mUiController.isInCustomActionMode();
598 }
599
John Reck0f602f32011-07-07 15:38:43 -0700600 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700601 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700602 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700603 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700604 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800605 }
606
607 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700608 if (mTitleBar.isShowing()) {
609 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700610 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800611 }
612
613 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700614 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800615 }
616
John Reck5d43ce82011-06-21 17:16:51 -0700617 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700618 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700619 }
620
Michael Kolb80f75082012-04-10 10:50:06 -0700621 public void stopEditingUrl() {
622 mTitleBar.getNavigationBar().stopEditingUrl();
623 }
624
John Reck0f602f32011-07-07 15:38:43 -0700625 public TitleBar getTitleBar() {
626 return mTitleBar;
627 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800628
Michael Kolb66706532010-12-12 19:50:22 -0800629 @Override
John Reck2bc80422011-06-30 15:11:49 -0700630 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700631 Intent intent = new Intent(mActivity, ComboViewActivity.class);
632 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
633 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
634 Tab t = getActiveTab();
635 if (t != null) {
636 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800637 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700638 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700639 }
640
641 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800642 public void hideComboView() {
643 }
644
645 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400646 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800647 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700648 // if a view already exists then immediately terminate the new one
649 if (mCustomView != null) {
650 callback.onCustomViewHidden();
651 return;
652 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400653 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700654 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400655 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700656 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400657 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700658 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700659 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400660 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700661 }
662
663 @Override
664 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700665 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700666 if (mCustomView == null)
667 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400668 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700669 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400670 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700671 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700672 mCustomViewCallback.onCustomViewHidden();
673 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400674 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700675 }
676
677 @Override
678 public boolean isCustomViewShowing() {
679 return mCustomView != null;
680 }
681
Michael Kolb66706532010-12-12 19:50:22 -0800682 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800683 if (mInputManager.isActive()) {
684 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
685 0);
686 }
687 }
688
Michael Kolb66706532010-12-12 19:50:22 -0800689 @Override
John Reck3ba45532011-08-11 16:26:53 -0700690 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700691 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800692 }
693
Tarun Nainani87a86682015-02-05 11:47:35 -0800694 @Override
695 public boolean isComboViewShowing() {
696 return false;
697 }
698
Michael Kolb8233fac2010-10-26 16:08:53 -0700699 // -------------------------------------------------------------------------
700
Michael Kolb5a72f182011-01-13 20:35:06 -0800701 protected void updateNavigationState(Tab tab) {
702 }
703
Michael Kolb8233fac2010-10-26 16:08:53 -0700704 /**
705 * Update the lock icon to correspond to our latest state.
706 */
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700707 private void updateTabSecurityState(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800708 if (t != null && t.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700709 mNavigationBar.setSecurityState(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700710 }
711 }
712
John Reck30c714c2010-12-16 17:30:34 -0800713 protected void setUrlTitle(Tab tab) {
714 String url = tab.getUrl();
715 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800716 if (TextUtils.isEmpty(title)) {
717 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800718 }
Michael Kolb66706532010-12-12 19:50:22 -0800719 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700720 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800721 }
722 }
723
724 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800725 protected void setFavicon(Tab tab) {
726 if (tab.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700727 mNavigationBar.setFavicon(tab.getWebView().getFavicon());
John Reck30c714c2010-12-16 17:30:34 -0800728 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700729 }
730
Michael Kolb66706532010-12-12 19:50:22 -0800731 // active tabs page
732
733 public void showActiveTabsPage() {
734 }
735
736 /**
737 * Remove the active tabs page.
738 */
739 public void removeActiveTabsPage() {
740 }
741
Michael Kolb8233fac2010-10-26 16:08:53 -0700742 // menu handling callbacks
743
744 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800745 public boolean onPrepareOptionsMenu(Menu menu) {
746 return true;
747 }
748
749 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700750 public void updateMenuState(Tab tab, Menu menu) {
751 }
752
753 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700754 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700755 }
756
757 @Override
758 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700759 }
760
761 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700762 public boolean onOptionsItemSelected(MenuItem item) {
763 return false;
764 }
765
766 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700767 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700768 }
769
770 @Override
771 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700772 }
773
774 @Override
775 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700776 }
777
778 @Override
779 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700780 }
781
Michael Kolb8233fac2010-10-26 16:08:53 -0700782 // -------------------------------------------------------------------------
783 // Helper function for WebChromeClient
784 // -------------------------------------------------------------------------
785
786 @Override
787 public Bitmap getDefaultVideoPoster() {
788 if (mDefaultVideoPoster == null) {
789 mDefaultVideoPoster = BitmapFactory.decodeResource(
790 mActivity.getResources(), R.drawable.default_video_poster);
791 }
792 return mDefaultVideoPoster;
793 }
794
795 @Override
796 public View getVideoLoadingProgressView() {
797 if (mVideoProgressView == null) {
798 LayoutInflater inflater = LayoutInflater.from(mActivity);
799 mVideoProgressView = inflater.inflate(
800 R.layout.video_loading_progress, null);
801 }
802 return mVideoProgressView;
803 }
804
Michael Kolb843510f2010-12-09 10:51:49 -0800805 @Override
806 public void showMaxTabsWarning() {
807 Toast warning = Toast.makeText(mActivity,
808 mActivity.getString(R.string.max_tabs_warning),
809 Toast.LENGTH_SHORT);
810 warning.show();
811 }
812
Michael Kolb46f987e2011-04-05 10:39:10 -0700813 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800814
Michael Kolb46f987e2011-04-05 10:39:10 -0700815 if (mActiveTab != null) {
816 return mActiveTab.getWebView();
817 } else {
818 return null;
819 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700820 }
821
Pankaj Garg62bc7912015-04-14 16:08:59 -0700822 public void forceDisableFullscreenMode(boolean disabled) {
823 mFullscreenModeLocked = false;
824 setFullscreen(!disabled);
825 mFullscreenModeLocked = disabled;
826 }
827
Michael Kolbc38c6042011-04-27 10:46:06 -0700828 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700829 if (mFullscreenModeLocked)
830 return;
831
Michael Kolbc5675ad2011-10-21 13:34:28 -0700832 Window win = mActivity.getWindow();
833 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800834 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500835 final int fullscreenImmersiveSetting =
836 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
837 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
838 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
839 View.SYSTEM_UI_FLAG_FULLSCREEN |
840 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
841
842 if (mCustomView != null) {
843 mCustomView.setSystemUiVisibility(enabled ?
844 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800845 } else if (Build.VERSION.SDK_INT >= 19) {
846 mContentView.setSystemUiVisibility(enabled ?
847 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700848 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500849 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800850 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700851 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500852 if (enabled)
853 winParams.flags |= bits;
854 else
855 winParams.flags &= ~bits;
856
Michael Kolbc5675ad2011-10-21 13:34:28 -0700857 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700858 }
859
Denise LaFayetteda31d742014-10-10 18:03:13 -0400860 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700861 public void showFullscreen(boolean fullScreen) {
862 //Hide/show system ui bar as needed
863 if (!BrowserSettings.getInstance().useFullscreen())
864 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700865 //Hide/show topbar as needed
866 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700867 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700868 if (fullScreen) {
869 //hide topbar
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700870 bwv.enableTopControls(false);
Vivek Sekhare337acf2015-04-02 21:00:48 -0700871 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700872 } else {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700873 bwv.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700874 //show the topbar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700875 mTitleBar.showTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700876 //enable for auto-hide
877 if (!mTitleBar.isFixed())
Vivek Sekhare337acf2015-04-02 21:00:48 -0700878 mTitleBar.enableTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700879 }
880 }
881 }
882
Tarun Nainani8eb00912014-07-17 12:28:32 -0700883 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700884 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700885 if (topControlsOffsetYPix != 0.0) {
886 mTitleBar.setEnabled(false);
887 } else {
888 mTitleBar.setEnabled(true);
889 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800890 if (!mTitleBar.isFixed()) {
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800891 float currentY = mTitleBar.getTranslationY();
Devdeep Choudhury904c7062015-03-17 19:47:29 -0700892 float height = mNavigationBar.getHeight();
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800893 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
894 mTitleBar.requestLayout();
895 } else if ((height + topControlsOffsetYPix) <= 0) {
896 topControlsOffsetYPix -= 1;
897 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
898 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800899 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800900 // This was done to get HTML5 fullscreen API to work with fixed mode since
901 // topcontrols are used to implement HTML5 fullscreen
902 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700903 }
904 }
905
John Reck0f602f32011-07-07 15:38:43 -0700906 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800907 if (ENABLE_BORDER_AROUND_FAVICON) {
908 Drawable[] array = new Drawable[3];
909 array[0] = new PaintDrawable(Color.BLACK);
910 PaintDrawable p = new PaintDrawable(Color.WHITE);
911 array[1] = p;
912 if (icon == null) {
913 array[2] = getGenericFavicon();
914 } else {
915 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
916 }
917 LayerDrawable d = new LayerDrawable(array);
918 d.setLayerInset(1, 1, 1, 1, 1);
919 d.setLayerInset(2, 2, 2, 2, 2);
920 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700921 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800922 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700923 }
924
John Reck5d43ce82011-06-21 17:16:51 -0700925 public boolean isLoading() {
926 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
927 }
928
929 /**
930 * Suggest to the UI that the title bar can be hidden. The UI will then
931 * decide whether or not to hide based off a number of factors, such
932 * as if the user is editing the URL bar or if the page is loading
933 */
934 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700935 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
936 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700937 hideTitleBar();
938 }
939 }
940
John Reckbc6adb42011-09-01 18:03:20 -0700941 protected final void showTitleBarForDuration() {
942 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
943 }
944
945 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700946 showTitleBar();
947 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700948 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700949 }
950
Enrico Ros1f5a0952014-11-18 20:15:48 -0800951 protected void setMenuItemVisibility(Menu menu, int id,
952 boolean visibility) {
953 MenuItem item = menu.findItem(id);
954 if (item != null) {
955 item.setVisible(visibility);
956 }
957 }
958
John Reck9c5004e2011-10-07 16:00:12 -0700959 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700960
961 @Override
962 public void handleMessage(Message msg) {
963 if (msg.what == MSG_HIDE_TITLEBAR) {
964 suggestHideTitleBar();
965 }
John Reck9c5004e2011-10-07 16:00:12 -0700966 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700967 }
968 };
John Reck3ba45532011-08-11 16:26:53 -0700969
John Reck9c5004e2011-10-07 16:00:12 -0700970 protected void handleMessage(Message msg) {}
971
John Reck3ba45532011-08-11 16:26:53 -0700972 @Override
973 public void showWeb(boolean animate) {
974 mUiController.hideCustomView();
975 }
976
John Reck2711fab2012-05-18 21:38:59 -0700977 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800978 FrameLayout.LayoutParams params =
979 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700980 if (params.topMargin != margin) {
981 params.topMargin = margin;
982 mContentView.setLayoutParams(params);
983 }
984 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700985
986 @Override
987 public boolean blockFocusAnimations() {
988 return mBlockFocusAnimations;
989 }
990
Michael Kolb0b129122012-06-04 16:31:58 -0700991 @Override
992 public void onVoiceResult(String result) {
993 mNavigationBar.onVoiceResult(result);
994 }
995
kaiyizbb2db872013-08-01 22:24:07 -0400996 protected UiController getUiController() {
997 return mUiController;
998 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700999
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001000 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001001 private float getActionModeHeight() {
1002 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
1003 new int[] { android.R.attr.actionBarSize });
1004 float size = actionBarSizeTypedArray.getDimension(0, 0f);
1005 actionBarSizeTypedArray.recycle();
1006 return size;
1007 }
1008
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001009
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001010 @Override
1011 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001012 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001013
1014 if (mTitleBar.isFixed()) {
1015 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001016 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001017 } else {
1018 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001019 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001020 }
1021
1022 @Override
1023 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -07001024 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -07001025 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001026 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001027 } else {
1028 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001029 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001030 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -07001031
1032 @Override
1033 public boolean shouldCaptureThumbnails() {
1034 return true;
1035 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001036}