blob: 374bc15b690418cce992683ec13537eadb2fb67a [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
451 mEdgeSwipeSettings = null;
452
453 String action = BrowserSettings.getInstance().getEdgeSwipeAction();
454
455 if (action.equalsIgnoreCase(
456 mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) {
457 mEdgeSwipeController = new EdgeSwipeController(
458 container,
459 R.id.stationary_navview,
460 R.id.sliding_navview,
461 R.id.sliding_navview_shadow,
462 R.id.navview_opacity,
463 R.id.webview_wrapper,
464 R.id.draggable_mainframe,
465 this);
466 } else if (action.equalsIgnoreCase(
467 mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) {
468 mEdgeSwipeSettings = new EdgeSwipeSettings(
469 container,
470 R.id.stationary_navview,
471 R.id.edge_sliding_settings,
472 R.id.sliding_navview_shadow,
473 R.id.webview_wrapper,
474 R.id.draggable_mainframe,
475 this);
476 } else {
477 DraggableFrameLayout draggableView = (DraggableFrameLayout)
478 container.findViewById(R.id.draggable_mainframe);
479 draggableView.setDragHelper(null);
480 }
481 }
482
Michael Kolb8233fac2010-10-26 16:08:53 -0700483 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800484 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700485 // Remove the container that contains the main WebView.
486 WebView mainView = tab.getWebView();
487 View container = tab.getViewContainer();
488 if (mainView == null) {
489 return;
490 }
491 // Remove the container from the content and then remove the
492 // WebView from the container. This will trigger a focus change
493 // needed by WebView.
494 FrameLayout wrapper =
495 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800496 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700497 mContentView.removeView(container);
498 mUiController.endActionMode();
499 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700500 }
501
Michael Kolba713ec82010-11-29 17:27:06 -0800502 @Override
503 public void onSetWebView(Tab tab, WebView webView) {
504 View container = tab.getViewContainer();
505 if (container == null) {
506 // The tab consists of a container view, which contains the main
507 // WebView, as well as any other UI elements associated with the tab.
508 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700509 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800510 tab.setViewContainer(container);
511 }
512 if (tab.getWebView() != webView) {
513 // Just remove the old one.
514 FrameLayout wrapper =
515 (FrameLayout) container.findViewById(R.id.webview_wrapper);
516 wrapper.removeView(tab.getWebView());
517 }
518 }
519
Michael Kolb8233fac2010-10-26 16:08:53 -0700520 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800521 * create a sub window container and webview for the tab
522 * Note: this methods operates through side-effects for now
523 * it sets both the subView and subViewContainer for the given tab
524 * @param tab tab to create the sub window for
525 * @param subView webview to be set as a subwindow for the tab
526 */
527 @Override
528 public void createSubWindow(Tab tab, WebView subView) {
529 View subViewContainer = mActivity.getLayoutInflater().inflate(
530 R.layout.browser_subwindow, null);
531 ViewGroup inner = (ViewGroup) subViewContainer
532 .findViewById(R.id.inner_container);
533 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
534 LayoutParams.MATCH_PARENT));
535 final ImageButton cancel = (ImageButton) subViewContainer
536 .findViewById(R.id.subwindow_close);
537 final WebView cancelSubView = subView;
538 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800539 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800540 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800541 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800542 }
543 });
544 tab.setSubWebView(subView);
545 tab.setSubViewContainer(subViewContainer);
546 }
547
548 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700549 * Remove the sub window from the content view.
550 */
551 @Override
552 public void removeSubWindow(View subviewContainer) {
553 mContentView.removeView(subviewContainer);
554 mUiController.endActionMode();
555 }
556
557 /**
558 * Attach the sub window to the content view.
559 */
560 @Override
561 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800562 if (container.getParent() != null) {
563 // already attached, remove first
564 ((ViewGroup) container.getParent()).removeView(container);
565 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700566 mContentView.addView(container, COVER_SCREEN_PARAMS);
567 }
568
Michael Kolb11d19782011-03-20 10:17:40 -0700569 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700570 WebView web = getWebView();
571 if (web != null) {
572 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700573 }
574 }
575
Michael Kolb1f9b3562012-04-24 14:38:34 -0700576 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700577 if (mUiController.isInCustomActionMode()) {
578 mUiController.endActionMode();
579 }
580 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700581 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700582 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700583 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700584 }
585
Michael Kolb7cdc4902011-02-03 17:54:40 -0800586 boolean canShowTitleBar() {
587 return !isTitleBarShowing()
588 && !isActivityPaused()
589 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700590 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800591 && !mUiController.isInCustomActionMode();
592 }
593
John Reck0f602f32011-07-07 15:38:43 -0700594 protected void showTitleBar() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700595 if (canShowTitleBar()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700596 mTitleBar.showTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700597 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800598 }
599
600 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700601 if (mTitleBar.isShowing()) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700602 mTitleBar.enableTopControls(false);
Michael Kolb46f987e2011-04-05 10:39:10 -0700603 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800604 }
605
606 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700607 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800608 }
609
John Reck5d43ce82011-06-21 17:16:51 -0700610 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700611 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700612 }
613
Michael Kolb80f75082012-04-10 10:50:06 -0700614 public void stopEditingUrl() {
615 mTitleBar.getNavigationBar().stopEditingUrl();
616 }
617
John Reck0f602f32011-07-07 15:38:43 -0700618 public TitleBar getTitleBar() {
619 return mTitleBar;
620 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800621
Michael Kolb66706532010-12-12 19:50:22 -0800622 @Override
John Reck2bc80422011-06-30 15:11:49 -0700623 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700624 Intent intent = new Intent(mActivity, ComboViewActivity.class);
625 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
626 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
627 Tab t = getActiveTab();
628 if (t != null) {
629 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800630 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700631 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700632 }
633
634 @Override
Tarun Nainani87a86682015-02-05 11:47:35 -0800635 public void hideComboView() {
636 }
637
638 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400639 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800640 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700641 // if a view already exists then immediately terminate the new one
642 if (mCustomView != null) {
643 callback.onCustomViewHidden();
644 return;
645 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400646 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700647 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400648 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700649 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400650 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700651 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700652 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400653 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700654 }
655
656 @Override
657 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700658 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700659 if (mCustomView == null)
660 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400661 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700662 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400663 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700664 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700665 mCustomViewCallback.onCustomViewHidden();
666 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400667 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700668 }
669
670 @Override
671 public boolean isCustomViewShowing() {
672 return mCustomView != null;
673 }
674
Michael Kolb66706532010-12-12 19:50:22 -0800675 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800676 if (mInputManager.isActive()) {
677 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
678 0);
679 }
680 }
681
Michael Kolb66706532010-12-12 19:50:22 -0800682 @Override
John Reck3ba45532011-08-11 16:26:53 -0700683 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700684 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800685 }
686
Tarun Nainani87a86682015-02-05 11:47:35 -0800687 @Override
688 public boolean isComboViewShowing() {
689 return false;
690 }
691
Site Mao61b68212015-07-16 10:56:31 -0700692 public static boolean isUiLowPowerMode() {
Site Mao7521b092015-07-20 18:27:20 -0700693 return BrowserCommandLine.hasSwitch("ui-low-power-mode")
694 || BrowserSettings.getInstance().isPowerSaveModeEnabled()
695 || BrowserSettings.getInstance().isDisablePerfFeatures();
Site Mao61b68212015-07-16 10:56:31 -0700696 }
697
Michael Kolb8233fac2010-10-26 16:08:53 -0700698 // -------------------------------------------------------------------------
699
Michael Kolb5a72f182011-01-13 20:35:06 -0800700 protected void updateNavigationState(Tab tab) {
701 }
702
Michael Kolb8233fac2010-10-26 16:08:53 -0700703 /**
704 * Update the lock icon to correspond to our latest state.
705 */
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700706 private void updateTabSecurityState(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800707 if (t != null && t.inForeground()) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700708 mNavigationBar.setSecurityState(t.getSecurityState());
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700709 setUrlTitle(t);
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()) {
Pankaj Garg8d2e98f2015-08-07 10:01:49 -0700720 mNavigationBar.setDisplayTitle(title, url);
Michael Kolb66706532010-12-12 19:50:22 -0800721 }
722 }
723
724 // Set the favicon in the title bar.
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700725 public void setFavicon(Tab tab) {
726 mNavigationBar.showCurrentFavicon(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700727 }
728
Michael Kolb66706532010-12-12 19:50:22 -0800729 // active tabs page
730
731 public void showActiveTabsPage() {
732 }
733
734 /**
735 * Remove the active tabs page.
736 */
737 public void removeActiveTabsPage() {
738 }
739
Michael Kolb8233fac2010-10-26 16:08:53 -0700740 // menu handling callbacks
741
742 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800743 public boolean onPrepareOptionsMenu(Menu menu) {
744 return true;
745 }
746
747 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700748 public void updateMenuState(Tab tab, Menu menu) {
749 }
750
751 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700752 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700753 }
754
755 @Override
756 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700757 }
758
759 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700760 public boolean onOptionsItemSelected(MenuItem item) {
761 return false;
762 }
763
764 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700765 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700766 }
767
768 @Override
769 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700770 }
771
772 @Override
773 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700774 }
775
776 @Override
777 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700778 }
779
Michael Kolb8233fac2010-10-26 16:08:53 -0700780 // -------------------------------------------------------------------------
781 // Helper function for WebChromeClient
782 // -------------------------------------------------------------------------
783
784 @Override
785 public Bitmap getDefaultVideoPoster() {
786 if (mDefaultVideoPoster == null) {
787 mDefaultVideoPoster = BitmapFactory.decodeResource(
788 mActivity.getResources(), R.drawable.default_video_poster);
789 }
790 return mDefaultVideoPoster;
791 }
792
793 @Override
794 public View getVideoLoadingProgressView() {
795 if (mVideoProgressView == null) {
796 LayoutInflater inflater = LayoutInflater.from(mActivity);
797 mVideoProgressView = inflater.inflate(
798 R.layout.video_loading_progress, null);
799 }
800 return mVideoProgressView;
801 }
802
Michael Kolb843510f2010-12-09 10:51:49 -0800803 @Override
804 public void showMaxTabsWarning() {
805 Toast warning = Toast.makeText(mActivity,
806 mActivity.getString(R.string.max_tabs_warning),
807 Toast.LENGTH_SHORT);
808 warning.show();
809 }
810
Michael Kolb46f987e2011-04-05 10:39:10 -0700811 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800812
Michael Kolb46f987e2011-04-05 10:39:10 -0700813 if (mActiveTab != null) {
814 return mActiveTab.getWebView();
815 } else {
816 return null;
817 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700818 }
819
Pankaj Garg62bc7912015-04-14 16:08:59 -0700820 public void forceDisableFullscreenMode(boolean disabled) {
821 mFullscreenModeLocked = false;
822 setFullscreen(!disabled);
823 mFullscreenModeLocked = disabled;
824 }
825
Michael Kolbc38c6042011-04-27 10:46:06 -0700826 public void setFullscreen(boolean enabled) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700827 if (mFullscreenModeLocked)
828 return;
829
Michael Kolbc5675ad2011-10-21 13:34:28 -0700830 Window win = mActivity.getWindow();
831 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800832 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500833 final int fullscreenImmersiveSetting =
834 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
835 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
836 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
837 View.SYSTEM_UI_FLAG_FULLSCREEN |
838 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
839
840 if (mCustomView != null) {
841 mCustomView.setSystemUiVisibility(enabled ?
842 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800843 } else if (Build.VERSION.SDK_INT >= 19) {
844 mContentView.setSystemUiVisibility(enabled ?
845 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700846 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500847 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800848 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700849 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500850 if (enabled)
851 winParams.flags |= bits;
852 else
853 winParams.flags &= ~bits;
854
Michael Kolbc5675ad2011-10-21 13:34:28 -0700855 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700856 }
857
Denise LaFayetteda31d742014-10-10 18:03:13 -0400858 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700859 public void showFullscreen(boolean fullScreen) {
860 //Hide/show system ui bar as needed
861 if (!BrowserSettings.getInstance().useFullscreen())
862 setFullscreen(fullScreen);
Sudheer Koganti24766882014-10-02 10:58:09 -0700863 //Hide/show topbar as needed
864 if (getWebView() != null) {
Vivek Sekhar6bd32172015-05-06 15:48:07 -0700865 BrowserWebView bwv = (BrowserWebView) getWebView();
Sudheer Koganti24766882014-10-02 10:58:09 -0700866 if (fullScreen) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700867 // hide titlebar
Vivek Sekhare337acf2015-04-02 21:00:48 -0700868 mTitleBar.hideTopControls(true);
Sudheer Koganti24766882014-10-02 10:58:09 -0700869 } else {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700870 // show titlebar
871 mTitleBar.showTopControls(false);
872 // enable auto hide titlebar
Sudheer Koganti24766882014-10-02 10:58:09 -0700873 if (!mTitleBar.isFixed())
Vivek Sekhard4de6162015-07-21 15:01:45 -0700874 mTitleBar.enableTopControls(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700875 }
876 }
877 }
878
Tarun Nainani8eb00912014-07-17 12:28:32 -0700879 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700880 if (mTitleBar == null || mTitleBar.isFixed())
881 return;
882 if (!mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700883 if (topControlsOffsetYPix != 0.0) {
884 mTitleBar.setEnabled(false);
885 } else {
886 mTitleBar.setEnabled(true);
887 }
Vivek Sekhard4de6162015-07-21 15:01:45 -0700888 float currentY = mTitleBar.getTranslationY();
889 float height = mNavigationBar.getHeight();
890 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
891 mTitleBar.requestLayout();
892 } else if ((height + topControlsOffsetYPix) <= 0) {
893 topControlsOffsetYPix -= 1;
894 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
Sudheer Koganti56cba972014-11-13 15:15:46 -0800895 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800896 // This was done to get HTML5 fullscreen API to work with fixed mode since
897 // topcontrols are used to implement HTML5 fullscreen
898 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700899 }
900 }
901
John Reck0f602f32011-07-07 15:38:43 -0700902 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800903 if (ENABLE_BORDER_AROUND_FAVICON) {
904 Drawable[] array = new Drawable[3];
905 array[0] = new PaintDrawable(Color.BLACK);
906 PaintDrawable p = new PaintDrawable(Color.WHITE);
907 array[1] = p;
908 if (icon == null) {
909 array[2] = getGenericFavicon();
910 } else {
911 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
912 }
913 LayerDrawable d = new LayerDrawable(array);
914 d.setLayerInset(1, 1, 1, 1, 1);
915 d.setLayerInset(2, 2, 2, 2, 2);
916 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700917 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800918 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700919 }
920
John Reck5d43ce82011-06-21 17:16:51 -0700921 public boolean isLoading() {
922 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
923 }
924
Enrico Ros1f5a0952014-11-18 20:15:48 -0800925 protected void setMenuItemVisibility(Menu menu, int id,
926 boolean visibility) {
927 MenuItem item = menu.findItem(id);
928 if (item != null) {
929 item.setVisible(visibility);
930 }
931 }
932
John Reck9c5004e2011-10-07 16:00:12 -0700933 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700934
935 @Override
936 public void handleMessage(Message msg) {
John Reck9c5004e2011-10-07 16:00:12 -0700937 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700938 }
939 };
John Reck3ba45532011-08-11 16:26:53 -0700940
John Reck9c5004e2011-10-07 16:00:12 -0700941 protected void handleMessage(Message msg) {}
942
John Reck3ba45532011-08-11 16:26:53 -0700943 @Override
944 public void showWeb(boolean animate) {
945 mUiController.hideCustomView();
946 }
947
John Reck2711fab2012-05-18 21:38:59 -0700948 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800949 FrameLayout.LayoutParams params =
950 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700951 if (params.topMargin != margin) {
952 params.topMargin = margin;
953 mContentView.setLayoutParams(params);
954 }
955 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700956
957 @Override
958 public boolean blockFocusAnimations() {
959 return mBlockFocusAnimations;
960 }
961
Michael Kolb0b129122012-06-04 16:31:58 -0700962 @Override
963 public void onVoiceResult(String result) {
964 mNavigationBar.onVoiceResult(result);
965 }
966
kaiyizbb2db872013-08-01 22:24:07 -0400967 protected UiController getUiController() {
968 return mUiController;
969 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700970
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700971 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700972 private float getActionModeHeight() {
973 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
974 new int[] { android.R.attr.actionBarSize });
975 float size = actionBarSizeTypedArray.getDimension(0, 0f);
976 actionBarSizeTypedArray.recycle();
977 return size;
978 }
979
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700980
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700981 @Override
982 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700983 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700984
985 if (mTitleBar.isFixed()) {
986 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700987 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700988 } else {
989 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700990 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700991 }
992
993 @Override
994 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700995 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700996 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700997 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700998 } else {
999 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -07001000 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -07001001 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -07001002
1003 @Override
1004 public boolean shouldCaptureThumbnails() {
1005 return true;
1006 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001007}