blob: 4c17b8bca547e27186527c5e7a402a59cde00697 [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;
Michael Kolb53ed62c2011-10-04 16:18:44 -070020import android.content.Context;
John Reckd3e4d5b2011-07-13 15:48:43 -070021import android.content.Intent;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070026import android.graphics.Color;
27import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070028import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070029import android.graphics.drawable.LayerDrawable;
30import android.graphics.drawable.PaintDrawable;
Sagar Dhawan1e040c72014-12-11 20:24:12 -080031import android.os.Build;
Michael Kolb8233fac2010-10-26 16:08:53 -070032import android.os.Bundle;
John Reck5d43ce82011-06-21 17:16:51 -070033import android.os.Handler;
34import android.os.Message;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.text.TextUtils;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -070036import android.view.ActionMode;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.Gravity;
38import android.view.LayoutInflater;
39import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070040import android.view.MenuItem;
Michael Kolb31065b12011-10-06 13:51:32 -070041import android.view.MotionEvent;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080043import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080045import android.view.ViewGroup.LayoutParams;
Michael Kolbc5675ad2011-10-21 13:34:28 -070046import android.view.Window;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080048import android.view.inputmethod.InputMethodManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080049import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb8233fac2010-10-26 16:08:53 -070050import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080051import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070052import android.widget.LinearLayout;
53import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070054import android.content.res.TypedArray;
Bijan Amirzada41242f22014-03-21 12:12:18 -070055import com.android.browser.R;
56import com.android.browser.Tab.SecurityState;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080057
58import org.codeaurora.swe.WebView;
John Reckbf2ec202011-06-29 17:47:38 -070059
Michael Kolb1bf23132010-11-19 12:55:12 -080060import java.util.List;
61
Michael Kolb8233fac2010-10-26 16:08:53 -070062/**
63 * UI interface definitions
64 */
John Reck718a24d2011-08-12 11:08:30 -070065public abstract class BaseUi implements UI {
Michael Kolb8233fac2010-10-26 16:08:53 -070066
Enrico Ros1f5a0952014-11-18 20:15:48 -080067 protected static final boolean ENABLE_BORDER_AROUND_FAVICON = false;
Michael Kolb8233fac2010-10-26 16:08:53 -070068
Michael Kolb66706532010-12-12 19:50:22 -080069 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070070 new FrameLayout.LayoutParams(
71 ViewGroup.LayoutParams.MATCH_PARENT,
72 ViewGroup.LayoutParams.MATCH_PARENT);
73
Michael Kolb66706532010-12-12 19:50:22 -080074 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070075 new FrameLayout.LayoutParams(
76 ViewGroup.LayoutParams.MATCH_PARENT,
77 ViewGroup.LayoutParams.MATCH_PARENT,
78 Gravity.CENTER);
79
John Reck5d43ce82011-06-21 17:16:51 -070080 private static final int MSG_HIDE_TITLEBAR = 1;
John Reckef654f12011-07-12 16:42:08 -070081 public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
John Reck5d43ce82011-06-21 17:16:51 -070082
Michael Kolb8233fac2010-10-26 16:08:53 -070083 Activity mActivity;
84 UiController mUiController;
85 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080086 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080087 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070088
Steve Block2466eff2011-10-03 15:33:09 +010089 private Drawable mLockIconSecure;
90 private Drawable mLockIconMixed;
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070091 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070092
Michael Kolb66706532010-12-12 19:50:22 -080093 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070094 protected FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070095
Michael Kolb31065b12011-10-06 13:51:32 -070096 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080097 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040098 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070099
John Reck718a24d2011-08-12 11:08:30 -0700100 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -0700101
John Reck718a24d2011-08-12 11:08:30 -0700102 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700103
Michael Kolb8233fac2010-10-26 16:08:53 -0700104 // the default <video> poster
105 private Bitmap mDefaultVideoPoster;
106 // the video progress view
107 private View mVideoProgressView;
108
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800109 private final View mDecorView;
110
Michael Kolb8233fac2010-10-26 16:08:53 -0700111 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700112 protected TitleBar mTitleBar;
113 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700114 private boolean mBlockFocusAnimations;
Michael Kolb8233fac2010-10-26 16:08:53 -0700115
116 public BaseUi(Activity browser, UiController controller) {
117 mActivity = browser;
118 mUiController = controller;
119 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800120 mInputManager = (InputMethodManager)
121 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800122 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
123 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700124 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
125 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700126 LayoutInflater.from(mActivity)
127 .inflate(R.layout.custom_screen, frameLayout);
128 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700129 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700130 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
131 R.id.fullscreen_custom_content);
Michael Kolbc38c6042011-04-27 10:46:06 -0700132 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700133 mTitleBar = new TitleBar(mActivity, mUiController, this,
134 mContentView);
135 mTitleBar.setProgress(100);
136 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700137 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800138
139 // install system ui visibility listeners
140 mDecorView = mActivity.getWindow().getDecorView();
141 mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
Michael Kolb8233fac2010-10-26 16:08:53 -0700142 }
143
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800144 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener =
145 new View.OnSystemUiVisibilityChangeListener() {
146 @Override
147 public void onSystemUiVisibilityChange(int visFlags) {
148 final boolean lostFullscreen = (visFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
149 if (lostFullscreen)
150 setFullscreen(BrowserSettings.getInstance().useFullscreen());
151 }
152 };
153
Michael Kolb8233fac2010-10-26 16:08:53 -0700154 private void cancelStopToast() {
155 if (mStopToast != null) {
156 mStopToast.cancel();
157 mStopToast = null;
158 }
159 }
160
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700161 private Drawable getLockIconSecure() {
162 if (mLockIconSecure == null) {
163 mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_secure_holo_dark);
164 }
165 return mLockIconSecure;
166 }
167
168 private Drawable getLockIconMixed() {
169 if (mLockIconMixed == null) {
170 mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_secure_partial_holo_dark);
171 }
172 return mLockIconMixed;
173 }
174
175 protected Drawable getGenericFavicon() {
176 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800177 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700178 }
179 return mGenericFavicon;
180 }
181
Michael Kolb8233fac2010-10-26 16:08:53 -0700182 // lifecycle
183
184 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800185 if (isCustomViewShowing()) {
186 onHideCustomView();
187 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500188 if (mTabControl.getCurrentTab() != null) {
189 mTabControl.getCurrentTab().exitFullscreen();
190 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700191 cancelStopToast();
192 mActivityPaused = true;
193 }
194
195 public void onResume() {
196 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700197 // check if we exited without setting active tab
198 // b: 5188145
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800199 setFullscreen(BrowserSettings.getInstance().useFullscreen());
Michael Kolb1a4625a2011-08-24 13:40:44 -0700200 final Tab ct = mTabControl.getCurrentTab();
201 if (ct != null) {
202 setActiveTab(ct);
203 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700204 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700205 }
206
Michael Kolb66706532010-12-12 19:50:22 -0800207 protected boolean isActivityPaused() {
208 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700209 }
210
211 public void onConfigurationChanged(Configuration config) {
212 }
213
John Reck0f602f32011-07-07 15:38:43 -0700214 public Activity getActivity() {
215 return mActivity;
216 }
217
Michael Kolb8233fac2010-10-26 16:08:53 -0700218 // key handling
219
220 @Override
221 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700222 if (mCustomView != null) {
223 mUiController.hideCustomView();
224 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700225 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700226 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700227 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 }
229 return false;
230 }
231
Michael Kolb2814a362011-05-19 15:49:41 -0700232 @Override
233 public boolean onMenuKey() {
234 return false;
235 }
236
John Reck30c714c2010-12-16 17:30:34 -0800237 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700238 @Override
John Reck30c714c2010-12-16 17:30:34 -0800239 public void onTabDataChanged(Tab tab) {
240 setUrlTitle(tab);
241 setFavicon(tab);
242 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800243 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700244 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700245 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700246 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 }
248
249 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700250 public void onProgressChanged(Tab tab) {
251 int progress = tab.getLoadProgress();
252 if (tab.inForeground()) {
253 mTitleBar.setProgress(progress);
254 }
255 }
256
257 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500258 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800259 if (tab.inForeground()) {
260 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700261 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800262 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500263 }
264
265 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700266 public void onPageStopped(Tab tab) {
267 cancelStopToast();
268 if (tab.inForeground()) {
269 mStopToast = Toast
270 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
271 mStopToast.show();
272 }
273 }
274
275 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800276 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700277 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800278 }
279
280 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700281 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700282 }
283
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800284 public void cancelNavScreenRequest(){
285 }
286
Michael Kolb377ea312011-02-17 14:36:56 -0800287 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800288 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400289 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700290 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400291
Michael Kolbbae0cb22012-05-29 11:15:27 -0700292 // block unnecessary focus change animations during tab switch
293 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700294 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800295 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400296 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700297 WebView web = mActiveTab.getWebView();
298 if (web != null) {
299 web.setOnTouchListener(null);
300 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700301 }
Michael Kolb77df4562010-11-19 14:49:34 -0800302 mActiveTab = tab;
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800303
Michael Kolbda580632012-04-16 13:30:28 -0700304 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700305 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700306 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700307 if (web != null) {
308 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700309 web.setTitleBar(mTitleBar);
310 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700311 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700312 }
Michael Kolb4923c222012-04-02 16:18:36 -0700313 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700314 tab.getTopWindow().requestFocus();
John Reck30c714c2010-12-16 17:30:34 -0800315 onTabDataChanged(tab);
316 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700317 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700318 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400319
Vivek Sekhar943f0672014-05-01 18:35:22 -0700320 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400321 }
322
323 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700324 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400325 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700326 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400327
Vivek Sekhar943f0672014-05-01 18:35:22 -0700328 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Tarun Nainani30fd3002015-02-12 17:46:45 -0800329
330 if(tabToWaitFor == mTabToRemove) {
331 if (mRunnable != null) {
332 mTitleBar.removeCallbacks(mRunnable);
333 }
334 mTabToRemove = null;
335 mTabToWaitFor = null;
336 mRunnable = null;
337 return;
338 }
339
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400340 //remove previously scehduled tab
341 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700342 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700343 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400344 removeTabFromContentView(mTabToRemove);
345 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700346 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400347 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700348 mTabToRemove = tabToRemove;
349 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400350 mNumRemoveTries = 0;
351
352 if (mTabToRemove != null) {
353 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700354 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400355 }
356 }
357
358 protected void tryRemoveTab() {
359 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700360 // Ensure the webview is still valid
361 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
362 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700363 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700364 mRunnable = new Runnable() {
365 public void run() {
366 tryRemoveTab();
367 }
368 };
369 }
370 /*if the new tab is still not ready, wait another 2 frames
371 before trying again. 1 frame for the tab to render the first
372 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700373 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400374 return;
375 }
376 }
377 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700378 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700379 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400380 removeTabFromContentView(mTabToRemove);
381 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700382 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400383 }
384 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700385 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700386 }
387
John Reck718a24d2011-08-12 11:08:30 -0700388 protected void updateUrlBarAutoShowManagerTarget() {
389 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700390 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700391 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700392 }
393 }
394
Michael Kolbcfa3af52010-12-14 10:36:11 -0800395 Tab getActiveTab() {
396 return mActiveTab;
397 }
398
Michael Kolb8233fac2010-10-26 16:08:53 -0700399 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800400 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800401 }
402
403 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700404 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800405 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700406 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800407 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700408 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700409 }
410
411 @Override
412 public void detachTab(Tab tab) {
413 removeTabFromContentView(tab);
414 }
415
416 @Override
417 public void attachTab(Tab tab) {
418 attachTabToContentView(tab);
419 }
420
Michael Kolb377ea312011-02-17 14:36:56 -0800421 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800422 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700423 return;
424 }
425 View container = tab.getViewContainer();
426 WebView mainView = tab.getWebView();
427 // Attach the WebView to the container and then attach the
428 // container to the content view.
429 FrameLayout wrapper =
430 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800431 if (wrapper != mainView.getView().getParent())
432 wrapper.addView(mainView.getView());
433 ViewGroup parent = (ViewGroup) container.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -0700434 if (parent != mContentView) {
435 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700436 parent.removeView(container);
437 }
438 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700439 }
440 mUiController.attachSubWindow(tab);
441 }
442
443 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800444 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700445 // Remove the container that contains the main WebView.
446 WebView mainView = tab.getWebView();
447 View container = tab.getViewContainer();
448 if (mainView == null) {
449 return;
450 }
451 // Remove the container from the content and then remove the
452 // WebView from the container. This will trigger a focus change
453 // needed by WebView.
454 FrameLayout wrapper =
455 (FrameLayout) container.findViewById(R.id.webview_wrapper);
Vivek Sekhared791da2015-02-22 12:39:05 -0800456 wrapper.removeView(mainView.getView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700457 mContentView.removeView(container);
458 mUiController.endActionMode();
459 mUiController.removeSubWindow(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700460 }
461
Michael Kolba713ec82010-11-29 17:27:06 -0800462 @Override
463 public void onSetWebView(Tab tab, WebView webView) {
464 View container = tab.getViewContainer();
465 if (container == null) {
466 // The tab consists of a container view, which contains the main
467 // WebView, as well as any other UI elements associated with the tab.
468 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700469 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800470 tab.setViewContainer(container);
471 }
472 if (tab.getWebView() != webView) {
473 // Just remove the old one.
474 FrameLayout wrapper =
475 (FrameLayout) container.findViewById(R.id.webview_wrapper);
476 wrapper.removeView(tab.getWebView());
477 }
478 }
479
Michael Kolb8233fac2010-10-26 16:08:53 -0700480 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800481 * create a sub window container and webview for the tab
482 * Note: this methods operates through side-effects for now
483 * it sets both the subView and subViewContainer for the given tab
484 * @param tab tab to create the sub window for
485 * @param subView webview to be set as a subwindow for the tab
486 */
487 @Override
488 public void createSubWindow(Tab tab, WebView subView) {
489 View subViewContainer = mActivity.getLayoutInflater().inflate(
490 R.layout.browser_subwindow, null);
491 ViewGroup inner = (ViewGroup) subViewContainer
492 .findViewById(R.id.inner_container);
493 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
494 LayoutParams.MATCH_PARENT));
495 final ImageButton cancel = (ImageButton) subViewContainer
496 .findViewById(R.id.subwindow_close);
497 final WebView cancelSubView = subView;
498 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800499 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800500 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800501 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800502 }
503 });
504 tab.setSubWebView(subView);
505 tab.setSubViewContainer(subViewContainer);
506 }
507
508 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700509 * Remove the sub window from the content view.
510 */
511 @Override
512 public void removeSubWindow(View subviewContainer) {
513 mContentView.removeView(subviewContainer);
514 mUiController.endActionMode();
515 }
516
517 /**
518 * Attach the sub window to the content view.
519 */
520 @Override
521 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800522 if (container.getParent() != null) {
523 // already attached, remove first
524 ((ViewGroup) container.getParent()).removeView(container);
525 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700526 mContentView.addView(container, COVER_SCREEN_PARAMS);
527 }
528
Michael Kolb11d19782011-03-20 10:17:40 -0700529 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700530 WebView web = getWebView();
531 if (web != null) {
532 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700533 }
534 }
535
Michael Kolb1f9b3562012-04-24 14:38:34 -0700536 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700537 if (mUiController.isInCustomActionMode()) {
538 mUiController.endActionMode();
539 }
540 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700541 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700542 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700543 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700544 }
545
Michael Kolb7cdc4902011-02-03 17:54:40 -0800546 boolean canShowTitleBar() {
547 return !isTitleBarShowing()
548 && !isActivityPaused()
549 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700550 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800551 && !mUiController.isInCustomActionMode();
552 }
553
John Reck0f602f32011-07-07 15:38:43 -0700554 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700555 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700556 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700557 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700558 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800559 }
560
561 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700562 if (mTitleBar.isShowing()) {
563 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700564 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800565 }
566
567 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700568 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800569 }
570
John Reck5d43ce82011-06-21 17:16:51 -0700571 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700572 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700573 }
574
Michael Kolb80f75082012-04-10 10:50:06 -0700575 public void stopEditingUrl() {
576 mTitleBar.getNavigationBar().stopEditingUrl();
577 }
578
John Reck0f602f32011-07-07 15:38:43 -0700579 public TitleBar getTitleBar() {
580 return mTitleBar;
581 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800582
Michael Kolb66706532010-12-12 19:50:22 -0800583 @Override
John Reck2bc80422011-06-30 15:11:49 -0700584 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700585 Intent intent = new Intent(mActivity, ComboViewActivity.class);
586 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
587 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
588 Tab t = getActiveTab();
589 if (t != null) {
590 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800591 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700592 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700593 }
594
595 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400596 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800597 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700598 // if a view already exists then immediately terminate the new one
599 if (mCustomView != null) {
600 callback.onCustomViewHidden();
601 return;
602 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400603 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700604 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400605 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700606 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400607 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700608 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700609 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400610 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700611 }
612
613 @Override
614 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700615 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 if (mCustomView == null)
617 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400618 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700619 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400620 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700621 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700622 mCustomViewCallback.onCustomViewHidden();
623 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400624 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700625 }
626
627 @Override
628 public boolean isCustomViewShowing() {
629 return mCustomView != null;
630 }
631
Michael Kolb66706532010-12-12 19:50:22 -0800632 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800633 if (mInputManager.isActive()) {
634 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
635 0);
636 }
637 }
638
Michael Kolb66706532010-12-12 19:50:22 -0800639 @Override
John Reck3ba45532011-08-11 16:26:53 -0700640 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700641 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800642 }
643
Michael Kolb8233fac2010-10-26 16:08:53 -0700644 // -------------------------------------------------------------------------
645
Michael Kolb5a72f182011-01-13 20:35:06 -0800646 protected void updateNavigationState(Tab tab) {
647 }
648
Michael Kolb8233fac2010-10-26 16:08:53 -0700649 /**
650 * Update the lock icon to correspond to our latest state.
651 */
Michael Kolb66706532010-12-12 19:50:22 -0800652 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800653 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100654 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 }
656 }
657
658 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700659 * Updates the lock-icon image in the title-bar.
660 */
Steve Block2466eff2011-10-03 15:33:09 +0100661 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700662 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100663 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700664 d = getLockIconSecure();
Steve Block4895b012011-10-03 16:26:46 +0100665 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
666 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
667 // TODO: It would be good to have different icons for insecure vs mixed content.
668 // See http://b/5403800
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700669 d = getLockIconMixed();
Michael Kolb8233fac2010-10-26 16:08:53 -0700670 }
John Reck0f602f32011-07-07 15:38:43 -0700671 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700672 }
673
John Reck30c714c2010-12-16 17:30:34 -0800674 protected void setUrlTitle(Tab tab) {
675 String url = tab.getUrl();
676 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800677 if (TextUtils.isEmpty(title)) {
678 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800679 }
Michael Kolb66706532010-12-12 19:50:22 -0800680 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700681 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800682 }
683 }
684
685 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800686 protected void setFavicon(Tab tab) {
687 if (tab.inForeground()) {
688 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700689 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800690 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700691 }
692
Michael Kolb66706532010-12-12 19:50:22 -0800693 // active tabs page
694
695 public void showActiveTabsPage() {
696 }
697
698 /**
699 * Remove the active tabs page.
700 */
701 public void removeActiveTabsPage() {
702 }
703
Michael Kolb8233fac2010-10-26 16:08:53 -0700704 // menu handling callbacks
705
706 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800707 public boolean onPrepareOptionsMenu(Menu menu) {
708 return true;
709 }
710
711 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700712 public void updateMenuState(Tab tab, Menu menu) {
713 }
714
715 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700716 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700717 }
718
719 @Override
720 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700721 }
722
723 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700724 public boolean onOptionsItemSelected(MenuItem item) {
725 return false;
726 }
727
728 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700729 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700730 }
731
732 @Override
733 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700734 }
735
736 @Override
737 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700738 }
739
740 @Override
741 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700742 }
743
Michael Kolb8233fac2010-10-26 16:08:53 -0700744 // -------------------------------------------------------------------------
745 // Helper function for WebChromeClient
746 // -------------------------------------------------------------------------
747
748 @Override
749 public Bitmap getDefaultVideoPoster() {
750 if (mDefaultVideoPoster == null) {
751 mDefaultVideoPoster = BitmapFactory.decodeResource(
752 mActivity.getResources(), R.drawable.default_video_poster);
753 }
754 return mDefaultVideoPoster;
755 }
756
757 @Override
758 public View getVideoLoadingProgressView() {
759 if (mVideoProgressView == null) {
760 LayoutInflater inflater = LayoutInflater.from(mActivity);
761 mVideoProgressView = inflater.inflate(
762 R.layout.video_loading_progress, null);
763 }
764 return mVideoProgressView;
765 }
766
Michael Kolb843510f2010-12-09 10:51:49 -0800767 @Override
768 public void showMaxTabsWarning() {
769 Toast warning = Toast.makeText(mActivity,
770 mActivity.getString(R.string.max_tabs_warning),
771 Toast.LENGTH_SHORT);
772 warning.show();
773 }
774
Michael Kolb46f987e2011-04-05 10:39:10 -0700775 protected WebView getWebView() {
Sagar Dhawanf7b5d0b2015-02-06 15:47:20 -0800776
Michael Kolb46f987e2011-04-05 10:39:10 -0700777 if (mActiveTab != null) {
778 return mActiveTab.getWebView();
779 } else {
780 return null;
781 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700782 }
783
Michael Kolbc38c6042011-04-27 10:46:06 -0700784 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700785 Window win = mActivity.getWindow();
786 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800787 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500788 final int fullscreenImmersiveSetting =
789 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
790 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
791 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
792 View.SYSTEM_UI_FLAG_FULLSCREEN |
793 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
794
795 if (mCustomView != null) {
796 mCustomView.setSystemUiVisibility(enabled ?
797 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800798 } else if (Build.VERSION.SDK_INT >= 19) {
799 mContentView.setSystemUiVisibility(enabled ?
800 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700801 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500802 mContentView.setSystemUiVisibility(enabled ?
Sagar Dhawan1e040c72014-12-11 20:24:12 -0800803 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700804 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500805 if (enabled)
806 winParams.flags |= bits;
807 else
808 winParams.flags &= ~bits;
809
Michael Kolbc5675ad2011-10-21 13:34:28 -0700810 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700811 }
812
Denise LaFayetteda31d742014-10-10 18:03:13 -0400813 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700814 public void showFullscreen(boolean fullScreen) {
815 //Hide/show system ui bar as needed
816 if (!BrowserSettings.getInstance().useFullscreen())
817 setFullscreen(fullScreen);
818
819 //Hide/show topbar as needed
820 if (getWebView() != null) {
821 if (fullScreen) {
822 //hide topbar
823 getWebView().updateTopControls(true, false, false);
824 } else {
825 //show the topbar
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800826 getWebView().updateTopControls(false, true, false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700827 //enable for auto-hide
828 if (!mTitleBar.isFixed())
829 getWebView().updateTopControls(true, true, false);
830 }
831 }
832 }
833
Tarun Nainani8eb00912014-07-17 12:28:32 -0700834 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700835 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700836 if (topControlsOffsetYPix != 0.0) {
837 mTitleBar.setEnabled(false);
838 } else {
839 mTitleBar.setEnabled(true);
840 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800841 if (!mTitleBar.isFixed()) {
Kulanthaivel Palanichamy1b163272014-12-03 11:06:36 -0800842 float currentY = mTitleBar.getTranslationY();
843 float height = mTitleBar.getHeight();
844 if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) {
845 mTitleBar.requestLayout();
846 } else if ((height + topControlsOffsetYPix) <= 0) {
847 topControlsOffsetYPix -= 1;
848 mTitleBar.getParent().requestTransparentRegion(mTitleBar);
849 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800850 }
Pankaj Garg16053b42014-12-17 15:23:01 -0800851 // This was done to get HTML5 fullscreen API to work with fixed mode since
852 // topcontrols are used to implement HTML5 fullscreen
853 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700854 }
855 }
856
John Reck0f602f32011-07-07 15:38:43 -0700857 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800858 if (ENABLE_BORDER_AROUND_FAVICON) {
859 Drawable[] array = new Drawable[3];
860 array[0] = new PaintDrawable(Color.BLACK);
861 PaintDrawable p = new PaintDrawable(Color.WHITE);
862 array[1] = p;
863 if (icon == null) {
864 array[2] = getGenericFavicon();
865 } else {
866 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
867 }
868 LayerDrawable d = new LayerDrawable(array);
869 d.setLayerInset(1, 1, 1, 1, 1);
870 d.setLayerInset(2, 2, 2, 2, 2);
871 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700872 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800873 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700874 }
875
John Reck5d43ce82011-06-21 17:16:51 -0700876 public boolean isLoading() {
877 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
878 }
879
880 /**
881 * Suggest to the UI that the title bar can be hidden. The UI will then
882 * decide whether or not to hide based off a number of factors, such
883 * as if the user is editing the URL bar or if the page is loading
884 */
885 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700886 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
887 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700888 hideTitleBar();
889 }
890 }
891
John Reckbc6adb42011-09-01 18:03:20 -0700892 protected final void showTitleBarForDuration() {
893 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
894 }
895
896 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700897 showTitleBar();
898 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700899 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700900 }
901
Enrico Ros1f5a0952014-11-18 20:15:48 -0800902 protected void setMenuItemVisibility(Menu menu, int id,
903 boolean visibility) {
904 MenuItem item = menu.findItem(id);
905 if (item != null) {
906 item.setVisible(visibility);
907 }
908 }
909
John Reck9c5004e2011-10-07 16:00:12 -0700910 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700911
912 @Override
913 public void handleMessage(Message msg) {
914 if (msg.what == MSG_HIDE_TITLEBAR) {
915 suggestHideTitleBar();
916 }
John Reck9c5004e2011-10-07 16:00:12 -0700917 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700918 }
919 };
John Reck3ba45532011-08-11 16:26:53 -0700920
John Reck9c5004e2011-10-07 16:00:12 -0700921 protected void handleMessage(Message msg) {}
922
John Reck3ba45532011-08-11 16:26:53 -0700923 @Override
924 public void showWeb(boolean animate) {
925 mUiController.hideCustomView();
926 }
927
John Reck2711fab2012-05-18 21:38:59 -0700928 public void setContentViewMarginTop(int margin) {
Kulanthaivel Palanichamy033af092014-12-12 18:16:24 -0800929 FrameLayout.LayoutParams params =
930 (FrameLayout.LayoutParams) mContentView.getLayoutParams();
John Reck2711fab2012-05-18 21:38:59 -0700931 if (params.topMargin != margin) {
932 params.topMargin = margin;
933 mContentView.setLayoutParams(params);
934 }
935 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700936
937 @Override
938 public boolean blockFocusAnimations() {
939 return mBlockFocusAnimations;
940 }
941
Michael Kolb0b129122012-06-04 16:31:58 -0700942 @Override
943 public void onVoiceResult(String result) {
944 mNavigationBar.onVoiceResult(result);
945 }
946
kaiyizbb2db872013-08-01 22:24:07 -0400947 protected UiController getUiController() {
948 return mUiController;
949 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700950
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700951 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700952 private float getActionModeHeight() {
953 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
954 new int[] { android.R.attr.actionBarSize });
955 float size = actionBarSizeTypedArray.getDimension(0, 0f);
956 actionBarSizeTypedArray.recycle();
957 return size;
958 }
959
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700960
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700961 @Override
962 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700963 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700964
965 if (mTitleBar.isFixed()) {
966 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700967 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700968 } else {
969 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700970 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700971 }
972
973 @Override
974 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700975 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700976 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700977 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700978 } else {
979 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700980 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700981 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700982}