blob: 4f7ad3f875446b02883ce82e9ef8979125bd3570 [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
75 Activity mActivity;
76 UiController mUiController;
77 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080078 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080079 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070080
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070081 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070082
Michael Kolb66706532010-12-12 19:50:22 -080083 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070084 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070085
Michael Kolb31065b12011-10-06 13:51:32 -070086 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080087 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040088 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070089
John Reck718a24d2011-08-12 11:08:30 -070090 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -070091
Michael Kolb8233fac2010-10-26 16:08:53 -070092 // the default <video> poster
93 private Bitmap mDefaultVideoPoster;
94 // the video progress view
95 private View mVideoProgressView;
96
Sagar Dhawan1e040c72014-12-11 20:24:12 -080097 private final View mDecorView;
98
Michael Kolb8233fac2010-10-26 16:08:53 -070099 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700100 protected TitleBar mTitleBar;
101 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700102 private boolean mBlockFocusAnimations;
Pankaj Garg62bc7912015-04-14 16:08:59 -0700103 private boolean mFullscreenModeLocked;
Michael Kolb8233fac2010-10-26 16:08:53 -0700104
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700105 private EdgeSwipeController mEdgeSwipeController;
106 private EdgeSwipeSettings mEdgeSwipeSettings;
107
Michael Kolb8233fac2010-10-26 16:08:53 -0700108 public BaseUi(Activity browser, UiController controller) {
109 mActivity = browser;
110 mUiController = controller;
111 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800112 mInputManager = (InputMethodManager)
113 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800114 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
115 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700116 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
117 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700118 LayoutInflater.from(mActivity)
119 .inflate(R.layout.custom_screen, frameLayout);
120 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700121 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700122 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
123 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700124 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700125 mTitleBar = new TitleBar(mActivity, mUiController, this,
126 mContentView);
127 mTitleBar.setProgress(100);
128 mNavigationBar = mTitleBar.getNavigationBar();
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800129
130 // install system ui visibility listeners
131 mDecorView = mActivity.getWindow().getDecorView();
132 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700133 mFullscreenModeLocked = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700134 }
135
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800136 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
137 new View.OnSystemUiVisibilityChangeListener() {
138 @Override
139 public void onSystemUiVisibilityChange(int visFlags) {
140 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
141 if (lostFullscreen)
142 setFullscreen(BrowserSettings.getInstance().useFullscreen());
143 }
144 };
145
Michael Kolb8233fac2010-10-26 16:08:53 -0700146 private void cancelStopToast() {
147 if (mStopToast != null) {
148 mStopToast.cancel();
149 mStopToast = null;
150 }
151 }
152
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700153 protected Drawable getGenericFavicon() {
154 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800155 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700156 }
157 return mGenericFavicon;
158 }
159
Michael Kolb8233fac2010-10-26 16:08:53 -0700160 // lifecycle
161
162 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800163 if (isCustomViewShowing()) {
164 onHideCustomView();
165 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500166 if (mTabControl.getCurrentTab() != null) {
167 mTabControl.getCurrentTab().exitFullscreen();
168 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700169 cancelStopToast();
170 mActivityPaused = true;
171 }
172
173 public void onResume() {
174 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700175 // check if we exited without setting active tab
176 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800177 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700178 final Tab ct = mTabControl.getCurrentTab();
179 if (ct != null) {
180 setActiveTab(ct);
181 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700182 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700183 }
184
Michael Kolb66706532010-12-12 19:50:22 -0800185 protected boolean isActivityPaused() {
186 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700187 }
188
189 public void onConfigurationChanged(Configuration config) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700190 if (mEdgeSwipeController != null) {
191 mEdgeSwipeController.onConfigurationChanged();
192 }
193 if (mEdgeSwipeSettings != null) {
194 mEdgeSwipeSettings.onConfigurationChanged();
195 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700196 }
197
John Reck0f602f32011-07-07 15:38:43 -0700198 public Activity getActivity() {
199 return mActivity;
200 }
201
Michael Kolb8233fac2010-10-26 16:08:53 -0700202 // key handling
203
204 @Override
205 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700206 if (mCustomView != null) {
207 mUiController.hideCustomView();
208 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700209 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700210 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700211 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700212 }
213 return false;
214 }
215
Vivek Sekhard4de6162015-07-21 15:01:45 -0700216 public boolean isFullScreen() {
217 if (mTabControl.getCurrentTab() != null)
218 return mTabControl.getCurrentTab().isTabFullScreen();
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);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700231 updateTabSecurityState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800232 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700233 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700234 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700235 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 }
237
238 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700239 public void onProgressChanged(Tab tab) {
240 int progress = tab.getLoadProgress();
241 if (tab.inForeground()) {
Pankaj Gargf9040c82015-08-14 10:19:31 -0700242 if (tab.inPageLoad()) {
243 mTitleBar.setProgress(progress);
244 } else {
245 mTitleBar.setProgress(100);
246 }
Michael Kolbe8a82332012-04-25 14:14:26 -0700247 }
248 }
249
250 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500251 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800252 if (tab.inForeground()) {
253 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700254 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800255 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500256 }
257
258 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700259 public void onPageStopped(Tab tab) {
260 cancelStopToast();
261 if (tab.inForeground()) {
262 mStopToast = Toast
263 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
264 mStopToast.show();
265 }
266 }
267
268 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800269 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700270 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800271 }
272
273 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700274 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700275 }
276
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800277 public void cancelNavScreenRequest(){
278 }
279
Michael Kolb377ea312011-02-17 14:36:56 -0800280 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800281 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400282 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700283 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400284
Michael Kolbbae0cb22012-05-29 11:15:27 -0700285 // block unnecessary focus change animations during tab switch
286 mBlockFocusAnimations = true;
Michael Kolb77df4562010-11-19 14:49:34 -0800287 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400288 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700289 WebView web = mActiveTab.getWebView();
290 if (web != null) {
291 web.setOnTouchListener(null);
292 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700293 }
Michael Kolb77df4562010-11-19 14:49:34 -0800294 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800295
Michael Kolbda580632012-04-16 13:30:28 -0700296 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck5d43ce82011-06-21 17:16:51 -0700297 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700298 if (web != null) {
299 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700300 web.setTitleBar(mTitleBar);
301 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700302 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700303 }
Michael Kolb4923c222012-04-02 16:18:36 -0700304 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700305 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800306 onTabDataChanged(tab);
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700307 setFavicon(tab);
John Reck30c714c2010-12-16 17:30:34 -0800308 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700309 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700310 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400311
Vivek Sekhar943f0672014-05-01 18:35:22 -0700312 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700313
314 updateTabSecurityState(tab);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400315 }
316
317 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700318 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400319 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700320 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400321
Vivek Sekhar943f0672014-05-01 18:35:22 -0700322 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800323
324 if(tabToWaitFor == mTabToRemove) {
325 if (mRunnable != null) {
326 mTitleBar.removeCallbacks(mRunnable);
327 }
328 mTabToRemove = null;
329 mTabToWaitFor = null;
330 mRunnable = null;
331 return;
332 }
333
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400334 //remove previously scehduled tab
335 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700336 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700337 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400338 removeTabFromContentView(mTabToRemove);
339 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700340 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400341 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700342 mTabToRemove = tabToRemove;
343 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400344 mNumRemoveTries = 0;
345
346 if (mTabToRemove != null) {
347 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700348 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400349 }
350 }
351
352 protected void tryRemoveTab() {
353 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700354 // Ensure the webview is still valid
355 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
356 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700357 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700358 mRunnable = new Runnable() {
359 public void run() {
360 tryRemoveTab();
361 }
362 };
363 }
364 /*if the new tab is still not ready, wait another 2 frames
365 before trying again. 1 frame for the tab to render the first
366 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700367 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400368 return;
369 }
370 }
371 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700372 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700373 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400374 removeTabFromContentView(mTabToRemove);
375 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700376 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400377 }
378 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700379 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 }
381
Michael Kolbcfa3af52010-12-14 10:36:11 -0800382 Tab getActiveTab() {
383 return mActiveTab;
384 }
385
Michael Kolb8233fac2010-10-26 16:08:53 -0700386 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800387 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800388 }
389
390 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700391 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800392 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700393 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800394 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700395 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700396 }
397
398 @Override
399 public void detachTab(Tab tab) {
400 removeTabFromContentView(tab);
401 }
402
403 @Override
404 public void attachTab(Tab tab) {
405 attachTabToContentView(tab);
406 }
407
Michael Kolb377ea312011-02-17 14:36:56 -0800408 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800409 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700410 return;
411 }
412 View container = tab.getViewContainer();
413 WebView mainView = tab.getWebView();
414 // Attach the WebView to the container and then attach the
415 // container to the content view.
416 FrameLayout wrapper =
417 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700418 ViewGroup parentView = (ViewGroup)mainView.getView().getParent();
419
420 if (wrapper != parentView) {
421 // clean up old view before attaching new view
422 // this helping in fixing issues such touch event
423 // getting triggered on old view instead of new one
424 if (parentView != null) {
425 parentView.removeView(mainView.getView());
426 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800427 wrapper.addView(mainView.getView());
Axesh R. Ajmera4fed9492015-05-11 11:50:39 -0700428 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800429 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700430 if (parent != mContentView) {
431 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700432 parent.removeView(container);
433 }
434 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700435 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700436
437 refreshEdgeSwipeController(container);
438
Michael Kolb8233fac2010-10-26 16:08:53 -0700439 mUiController.attachSubWindow(tab);
440 }
441
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700442 public void refreshEdgeSwipeController(View container) {
Site Mao61b68212015-07-16 10:56:31 -0700443 if (isUiLowPowerMode()) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700444 return;
445 }
446
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700447 if (mEdgeSwipeController != null) {
448 mEdgeSwipeController.cleanup();
449 }
450
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700451 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
452
Sagar Dhawan05e3c352015-09-07 15:24:33 +0200453 if (mEdgeSwipeSettings != null) {
454 mEdgeSwipeSettings.cleanup();
455 }
456 mEdgeSwipeSettings = null;
457
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700458 if (action.equalsIgnoreCase(
459 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
460 mEdgeSwipeController = new EdgeSwipeController(
461 container,
462 R.id.stationary_navview,
463 R.id.sliding_navview,
464 R.id.sliding_navview_shadow,
465 R.id.navview_opacity,
466 R.id.webview_wrapper,
467 R.id.draggable_mainframe,
468 this);
469 } else if (action.equalsIgnoreCase(
470 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
471 mEdgeSwipeSettings = new EdgeSwipeSettings(
472 container,
473 R.id.stationary_navview,
474 R.id.edge_sliding_settings,
475 R.id.sliding_navview_shadow,
476 R.id.webview_wrapper,
477 R.id.draggable_mainframe,
478 this);
479 } else {
480 DraggableFrameLayout draggableView = (DraggableFrameLayout)
481 container.findViewById(R.id.draggable_mainframe);
482 draggableView.setDragHelper(null);
483 }
484 }
485
Michael Kolb8233fac2010-10-26 16:08:53 -0700486 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800487 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700488 // Remove the container that contains the main WebView.
489 WebView mainView = tab.getWebView();
490 View container = tab.getViewContainer();
491 if (mainView == null) {
492 return;
493 }
494 // Remove the container from the content and then remove the
495 // WebView from the container. This will trigger a focus change
496 // needed by WebView.
497 FrameLayout wrapper =
498 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800499 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700500 mContentView.removeView(container);
501 mUiController.endActionMode();
502 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700503 }
504
Michael Kolba713ec82010-11-29 17:27:06 -0800505 @Override
506 public void onSetWebView(Tab tab, WebView webView) {
507 View container = tab.getViewContainer();
508 if (container == null) {
509 // The tab consists of a container view, which contains the main
510 // WebView, as well as any other UI elements associated with the tab.
511 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700512 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800513 tab.setViewContainer(container);
514 }
515 if (tab.getWebView() != webView) {
516 // Just remove the old one.
517 FrameLayout wrapper =
518 (FrameLayout) container.findViewById(R.id.webview_wrapper);
519 wrapper.removeView(tab.getWebView());
520 }
521 }
522
Michael Kolb8233fac2010-10-26 16:08:53 -0700523 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800524 * create a sub window container and webview for the tab
525 * Note: this methods operates through side-effects for now
526 * it sets both the subView and subViewContainer for the given tab
527 * @param tab tab to create the sub window for
528 * @param subView webview to be set as a subwindow for the tab
529 */
530 @Override
531 public void createSubWindow(Tab tab, WebView subView) {
532 View subViewContainer = mActivity.getLayoutInflater().inflate(
533 R.layout.browser_subwindow, null);
534 ViewGroup inner = (ViewGroup) subViewContainer
535 .findViewById(R.id.inner_container);
536 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
537 LayoutParams.MATCH_PARENT));
538 final ImageButton cancel = (ImageButton) subViewContainer
539 .findViewById(R.id.subwindow_close);
540 final WebView cancelSubView = subView;
541 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800542 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800543 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800544 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800545 }
546 });
547 tab.setSubWebView(subView);
548 tab.setSubViewContainer(subViewContainer);
549 }
550
551 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700552 * Remove the sub window from the content view.
553 */
554 @Override
555 public void removeSubWindow(View subviewContainer) {
556 mContentView.removeView(subviewContainer);
557 mUiController.endActionMode();
558 }
559
560 /**
561 * Attach the sub window to the content view.
562 */
563 @Override
564 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800565 if (container.getParent() != null) {
566 // already attached, remove first
567 ((ViewGroup) container.getParent()).removeView(container);
568 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700569 mContentView.addView(container, COVER_SCREEN_PARAMS);
570 }
571
Michael Kolb11d19782011-03-20 10:17:40 -0700572 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700573 WebView web = getWebView();
574 if (web != null) {
575 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700576 }
577 }
578
Michael Kolb1f9b3562012-04-24 14:38:34 -0700579 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700580 if (mUiController.isInCustomActionMode()) {
581 mUiController.endActionMode();
582 }
583 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700584 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700585 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700586 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700587 }
588
Michael Kolb7cdc4902011-02-03 17:54:40 -0800589 boolean canShowTitleBar() {
590 return !isTitleBarShowing()
591 && !isActivityPaused()
592 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700593 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800594 && !mUiController.isInCustomActionMode();
595 }
596
John Reck0f602f32011-07-07 15:38:43 -0700597 protected void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700598 if (canShowTitleBar()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700599 mTitleBar.showTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700600 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800601 }
602
603 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700604 if (mTitleBar.isShowing()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700605 mTitleBar.enableTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700606 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800607 }
608
609 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700610 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800611 }
612
John Reck5d43ce82011-06-21 17:16:51 -0700613 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700614 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700615 }
616
Michael Kolb80f75082012-04-10 10:50:06 -0700617 public void stopEditingUrl() {
618 mTitleBar.getNavigationBar().stopEditingUrl();
619 }
620
John Reck0f602f32011-07-07 15:38:43 -0700621 public TitleBar getTitleBar() {
622 return mTitleBar;
623 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800624
Michael Kolb66706532010-12-12 19:50:22 -0800625 @Override
John Reck2bc80422011-06-30 15:11:49 -0700626 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700627 Intent intent = new Intent(mActivity, ComboViewActivity.class);
628 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
629 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
630 Tab t = getActiveTab();
631 if (t != null) {
632 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800633 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700634 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700635 }
636
637 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800638 public void hideComboView() {
639 }
640
641 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400642 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800643 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700644 // if a view already exists then immediately terminate the new one
645 if (mCustomView != null) {
646 callback.onCustomViewHidden();
647 return;
648 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400649 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700650 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400651 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700652 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400653 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700654 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400656 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700657 }
658
659 @Override
660 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700661 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700662 if (mCustomView == null)
663 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400664 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700665 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400666 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700667 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700668 mCustomViewCallback.onCustomViewHidden();
669 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400670 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700671 }
672
673 @Override
674 public boolean isCustomViewShowing() {
675 return mCustomView != null;
676 }
677
Michael Kolb66706532010-12-12 19:50:22 -0800678 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800679 if (mInputManager.isActive()) {
680 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
681 0);
682 }
683 }
684
Michael Kolb66706532010-12-12 19:50:22 -0800685 @Override
John Reck3ba45532011-08-11 16:26:53 -0700686 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700687 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800688 }
689
Tarun Nainani87a86682015-02-05 11:47:35 -0800690 @Override
691 public boolean isComboViewShowing() {
692 return false;
693 }
694
Site Mao61b68212015-07-16 10:56:31 -0700695 public static boolean isUiLowPowerMode() {
Site Mao7521b092015-07-20 18:27:20 -0700696 return BrowserCommandLine.hasSwitch("ui-low-power-mode")
697 || BrowserSettings.getInstance().isPowerSaveModeEnabled()
698 || BrowserSettings.getInstance().isDisablePerfFeatures();
Site Mao61b68212015-07-16 10:56:31 -0700699 }
700
Michael Kolb8233fac2010-10-26 16:08:53 -0700701 // -------------------------------------------------------------------------
702
Michael Kolb5a72f182011-01-13 20:35:06 -0800703 protected void updateNavigationState(Tab tab) {
704 }
705
Michael Kolb8233fac2010-10-26 16:08:53 -0700706 /**
707 * Update the lock icon to correspond to our latest state.
708 */
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700709 private void updateTabSecurityState(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800710 if (t != null && t.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700711 mNavigationBar.setSecurityState(t.getSecurityState());
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700712 setUrlTitle(t);
Michael Kolb8233fac2010-10-26 16:08:53 -0700713 }
714 }
715
John Reck30c714c2010-12-16 17:30:34 -0800716 protected void setUrlTitle(Tab tab) {
717 String url = tab.getUrl();
718 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800719 if (TextUtils.isEmpty(title)) {
720 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800721 }
Michael Kolb66706532010-12-12 19:50:22 -0800722 if (tab.inForeground()) {
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700723 mNavigationBar.setDisplayTitle(title, url);
Michael Kolb66706532010-12-12 19:50:22 -0800724 }
725 }
726
727 // Set the favicon in the title bar.
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700728 public void setFavicon(Tab tab) {
729 mNavigationBar.showCurrentFavicon(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700730 }
731
Michael Kolb66706532010-12-12 19:50:22 -0800732 // active tabs page
733
734 public void showActiveTabsPage() {
735 }
736
737 /**
738 * Remove the active tabs page.
739 */
740 public void removeActiveTabsPage() {
741 }
742
Michael Kolb8233fac2010-10-26 16:08:53 -0700743 // menu handling callbacks
744
745 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800746 public boolean onPrepareOptionsMenu(Menu menu) {
747 return true;
748 }
749
750 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700751 public void updateMenuState(Tab tab, Menu menu) {
752 }
753
754 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700755 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700756 }
757
758 @Override
759 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700760 }
761
762 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700763 public boolean onOptionsItemSelected(MenuItem item) {
764 return false;
765 }
766
767 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700768 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700769 }
770
771 @Override
772 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700773 }
774
775 @Override
776 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700777 }
778
779 @Override
780 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700781 }
782
Michael Kolb8233fac2010-10-26 16:08:53 -0700783 // -------------------------------------------------------------------------
784 // Helper function for WebChromeClient
785 // -------------------------------------------------------------------------
786
787 @Override
788 public Bitmap getDefaultVideoPoster() {
789 if (mDefaultVideoPoster == null) {
790 mDefaultVideoPoster = BitmapFactory.decodeResource(
791 mActivity.getResources(), R.drawable.default_video_poster);
792 }
793 return mDefaultVideoPoster;
794 }
795
796 @Override
797 public View getVideoLoadingProgressView() {
798 if (mVideoProgressView == null) {
799 LayoutInflater inflater = LayoutInflater.from(mActivity);
800 mVideoProgressView = inflater.inflate(
801 R.layout.video_loading_progress, null);
802 }
803 return mVideoProgressView;
804 }
805
Michael Kolb843510f2010-12-09 10:51:49 -0800806 @Override
807 public void showMaxTabsWarning() {
808 Toast warning = Toast.makeText(mActivity,
809 mActivity.getString(R.string.max_tabs_warning),
810 Toast.LENGTH_SHORT);
811 warning.show();
812 }
813
Michael Kolb46f987e2011-04-05 10:39:10 -0700814 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800815
Michael Kolb46f987e2011-04-05 10:39:10 -0700816 if (mActiveTab != null) {
817 return mActiveTab.getWebView();
818 } else {
819 return null;
820 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700821 }
822
Pankaj Garg62bc7912015-04-14 16:08:59 -0700823 public void forceDisableFullscreenMode(boolean disabled) {
824 mFullscreenModeLocked = false;
825 setFullscreen(!disabled);
826 mFullscreenModeLocked = disabled;
827 }
828
Michael Kolbc38c6042011-04-27 10:46:06 -0700829 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700830 if (mFullscreenModeLocked)
831 return;
832
Michael Kolbc5675ad2011-10-21 13:34:28 -0700833 Window win = mActivity.getWindow();
834 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800835 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500836 final int fullscreenImmersiveSetting =
837 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
838 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
839 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
840 View.SYSTEM_UI_FLAG_FULLSCREEN |
841 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
842
843 if (mCustomView != null) {
844 mCustomView.setSystemUiVisibility(enabled ?
845 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800846 } else if (Build.VERSION.SDK_INT >= 19) {
847 mContentView.setSystemUiVisibility(enabled ?
848 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700849 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500850 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800851 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700852 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500853 if (enabled)
854 winParams.flags |= bits;
855 else
856 winParams.flags &= ~bits;
857
Michael Kolbc5675ad2011-10-21 13:34:28 -0700858 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700859 }
860
Denise LaFayetteda31d742014-10-10 18:03:13 -0400861 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700862 public void showFullscreen(boolean fullScreen) {
863 //Hide/show system ui bar as needed
864 if (!BrowserSettings.getInstance().useFullscreen())
865 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700866 //Hide/show topbar as needed
867 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700868 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700869 if (fullScreen) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700870 // hide titlebar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700871 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700872 } else {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700873 // show titlebar
874 mTitleBar.showTopControls(false);
875 // enable auto hide titlebar
Sudheer Koganti24766882014-10-02 10:58:09 -0700876 if (!mTitleBar.isFixed())
Vivek Sekhard4de6162015-07-21 15:01:45 -0700877 mTitleBar.enableTopControls(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700878 }
879 }
880 }
881
Tarun Nainani8eb00912014-07-17 12:28:32 -0700882 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700883 if (mTitleBar == null || mTitleBar.isFixed())
884 return;
885 if (!mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700886 if (topControlsOffsetYPix != 0.0) {
887 mTitleBar.setEnabled(false);
888 } else {
889 mTitleBar.setEnabled(true);
890 }
Vivek Sekhard4de6162015-07-21 15:01:45 -0700891 float currentY = mTitleBar.getTranslationY();
892 float height = mNavigationBar.getHeight();
893 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
894 mTitleBar.requestLayout();
895 } else if ((height + topControlsOffsetYPix) <= 0) {
896 topControlsOffsetYPix -= 1;
897 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
Sudheer Koganti56cba972014-11-13 15:15:46 -0800898 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800899 // This was done to get HTML5 fullscreen API to work with fixed mode since
900 // topcontrols are used to implement HTML5 fullscreen
901 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700902 }
903 }
904
John Reck0f602f32011-07-07 15:38:43 -0700905 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800906 if (ENABLE_BORDER_AROUND_FAVICON) {
907 Drawable[] array = new Drawable[3];
908 array[0] = new PaintDrawable(Color.BLACK);
909 PaintDrawable p = new PaintDrawable(Color.WHITE);
910 array[1] = p;
911 if (icon == null) {
912 array[2] = getGenericFavicon();
913 } else {
914 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
915 }
916 LayerDrawable d = new LayerDrawable(array);
917 d.setLayerInset(1, 1, 1, 1, 1);
918 d.setLayerInset(2, 2, 2, 2, 2);
919 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700920 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800921 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700922 }
923
John Reck5d43ce82011-06-21 17:16:51 -0700924 public boolean isLoading() {
925 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
926 }
927
Enrico Ros1f5a0952014-11-18 20:15:48 -0800928 protected void setMenuItemVisibility(Menu menu, int id,
929 boolean visibility) {
930 MenuItem item = menu.findItem(id);
931 if (item != null) {
932 item.setVisible(visibility);
933 }
934 }
935
John Reck9c5004e2011-10-07 16:00:12 -0700936 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700937
938 @Override
939 public void handleMessage(Message msg) {
John Reck9c5004e2011-10-07 16:00:12 -0700940 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700941 }
942 };
John Reck3ba45532011-08-11 16:26:53 -0700943
John Reck9c5004e2011-10-07 16:00:12 -0700944 protected void handleMessage(Message msg) {}
945
John Reck3ba45532011-08-11 16:26:53 -0700946 @Override
947 public void showWeb(boolean animate) {
948 mUiController.hideCustomView();
949 }
950
John Reck2711fab2012-05-18 21:38:59 -0700951 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800952 FrameLayout.LayoutParams params =
953 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700954 if (params.topMargin != margin) {
955 params.topMargin = margin;
956 mContentView.setLayoutParams(params);
957 }
958 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700959
960 @Override
961 public boolean blockFocusAnimations() {
962 return mBlockFocusAnimations;
963 }
964
Michael Kolb0b129122012-06-04 16:31:58 -0700965 @Override
966 public void onVoiceResult(String result) {
967 mNavigationBar.onVoiceResult(result);
968 }
969
kaiyizbb2db872013-08-01 22:24:07 -0400970 protected UiController getUiController() {
971 return mUiController;
972 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700973
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700974 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700975 private float getActionModeHeight() {
976 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
977 new int[] { android.R.attr.actionBarSize });
978 float size = actionBarSizeTypedArray.getDimension(0, 0f);
979 actionBarSizeTypedArray.recycle();
980 return size;
981 }
982
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700983
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700984 @Override
985 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700986 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700987
988 if (mTitleBar.isFixed()) {
989 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700990 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700991 } else {
992 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700993 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700994 }
995
996 @Override
997 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700998 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700999 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001000 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -07001001 } else {
1002 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001003 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001004 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -07001005
1006 @Override
1007 public boolean shouldCaptureThumbnails() {
1008 return true;
1009 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001010}