Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1 | /* |
| 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 Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 18 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 20 | import android.content.Intent; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 21 | import android.content.res.Configuration; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 22 | import android.graphics.Bitmap; |
| 23 | import android.graphics.BitmapFactory; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 24 | import android.graphics.Color; |
| 25 | import android.graphics.drawable.BitmapDrawable; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 26 | import android.graphics.drawable.Drawable; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 27 | import android.graphics.drawable.LayerDrawable; |
| 28 | import android.graphics.drawable.PaintDrawable; |
Sagar Dhawan | 1e040c7 | 2014-12-11 20:24:12 -0800 | [diff] [blame] | 29 | import android.os.Build; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 30 | import android.os.Bundle; |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 31 | import android.os.Handler; |
| 32 | import android.os.Message; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 33 | import android.text.TextUtils; |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 34 | import android.view.ActionMode; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 35 | import android.view.Gravity; |
| 36 | import android.view.LayoutInflater; |
| 37 | import android.view.Menu; |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 38 | import android.view.MenuItem; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 39 | import android.view.View; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 40 | import android.view.View.OnClickListener; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 41 | import android.view.ViewGroup; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 42 | import android.view.ViewGroup.LayoutParams; |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 43 | import android.view.Window; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 44 | import android.view.WindowManager; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 45 | import android.view.inputmethod.InputMethodManager; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 46 | import android.webkit.WebChromeClient.CustomViewCallback; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 47 | import android.widget.FrameLayout; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 48 | import android.widget.ImageButton; |
Sagar Dhawan | 2abecc6 | 2015-09-14 18:53:04 -0700 | [diff] [blame] | 49 | import android.widget.ImageView; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 50 | import android.widget.Toast; |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 51 | import android.content.res.TypedArray; |
Pankaj Garg | 62fef2f | 2015-03-31 10:48:53 -0700 | [diff] [blame] | 52 | |
Pankaj Garg | 18aa0a1 | 2015-06-22 11:06:12 -0700 | [diff] [blame] | 53 | import org.codeaurora.swe.BrowserCommandLine; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 54 | import org.codeaurora.swe.WebView; |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 55 | |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 56 | import java.util.List; |
| 57 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 58 | /** |
| 59 | * UI interface definitions |
| 60 | */ |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 61 | public abstract class BaseUi implements UI { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 62 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 63 | protected static final boolean ENABLE_BORDER_AROUND_FAVICON = false; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 64 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 65 | protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 66 | new FrameLayout.LayoutParams( |
| 67 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 68 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 69 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 70 | protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 71 | new FrameLayout.LayoutParams( |
| 72 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 73 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 74 | Gravity.CENTER); |
| 75 | |
| 76 | Activity mActivity; |
| 77 | UiController mUiController; |
| 78 | TabControl mTabControl; |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 79 | protected Tab mActiveTab; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 80 | private InputMethodManager mInputManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 81 | |
Kulanthaivel Palanichamy | 3817bac | 2014-10-23 19:11:17 -0700 | [diff] [blame] | 82 | private Drawable mGenericFavicon; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 83 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 84 | protected FrameLayout mContentView; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 85 | protected FrameLayout mCustomViewContainer; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 86 | |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 87 | private View mCustomView; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 88 | private CustomViewCallback mCustomViewCallback; |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 89 | private int mOriginalOrientation; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 90 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 91 | private Toast mStopToast; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 92 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 93 | // the default <video> poster |
| 94 | private Bitmap mDefaultVideoPoster; |
| 95 | // the video progress view |
| 96 | private View mVideoProgressView; |
| 97 | |
Sagar Dhawan | 1e040c7 | 2014-12-11 20:24:12 -0800 | [diff] [blame] | 98 | private final View mDecorView; |
| 99 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 100 | private boolean mActivityPaused; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 101 | protected TitleBar mTitleBar; |
| 102 | private NavigationBarBase mNavigationBar; |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 103 | private boolean mBlockFocusAnimations; |
Pankaj Garg | 62bc791 | 2015-04-14 16:08:59 -0700 | [diff] [blame] | 104 | private boolean mFullscreenModeLocked; |
Sagar Dhawan | 55165b8 | 2015-09-03 15:33:02 -0700 | [diff] [blame] | 105 | private final static int mFullScreenImmersiveSetting = |
| 106 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | |
| 107 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | |
| 108 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 109 | View.SYSTEM_UI_FLAG_FULLSCREEN | |
| 110 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 111 | |
Pankaj Garg | 1c13cab | 2015-05-12 11:52:17 -0700 | [diff] [blame] | 112 | private EdgeSwipeController mEdgeSwipeController; |
| 113 | private EdgeSwipeSettings mEdgeSwipeSettings; |
| 114 | |
Sagar Dhawan | 55165b8 | 2015-09-03 15:33:02 -0700 | [diff] [blame] | 115 | // This Runnable is used to re-set fullscreen mode after resume. |
| 116 | // The immersive mode API on android <6.0 is buggy and will more |
| 117 | // often then not glitch out. Using a runnable really helps reduce |
| 118 | // the repeatability of this framework bug, however some corner cases |
| 119 | // remain. Specifically when interacting with pop-up windows(menu). |
| 120 | private Runnable mFullScreenModeRunnable = new Runnable() { |
| 121 | @Override |
| 122 | public void run() { |
| 123 | if (BrowserSettings.getInstance() != null) |
| 124 | setFullscreen(BrowserSettings.getInstance().useFullscreen()); |
| 125 | } |
| 126 | }; |
| 127 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 128 | public BaseUi(Activity browser, UiController controller) { |
| 129 | mActivity = browser; |
| 130 | mUiController = controller; |
| 131 | mTabControl = controller.getTabControl(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 132 | mInputManager = (InputMethodManager) |
| 133 | browser.getSystemService(Activity.INPUT_METHOD_SERVICE); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 134 | // This assumes that the top-level root of our layout has the 'android.R.id.content' id |
| 135 | // it's used in place of setContentView because we're attaching a <merge> here. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 136 | FrameLayout frameLayout = (FrameLayout) mActivity.getWindow() |
| 137 | .getDecorView().findViewById(android.R.id.content); |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 138 | LayoutInflater.from(mActivity) |
| 139 | .inflate(R.layout.custom_screen, frameLayout); |
| 140 | mContentView = (FrameLayout) frameLayout.findViewById( |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 141 | R.id.main_content); |
Michael Kolb | 53ed62c | 2011-10-04 16:18:44 -0700 | [diff] [blame] | 142 | mCustomViewContainer = (FrameLayout) frameLayout.findViewById( |
| 143 | R.id.fullscreen_custom_content); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 144 | setFullscreen(BrowserSettings.getInstance().useFullscreen()); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 145 | mTitleBar = new TitleBar(mActivity, mUiController, this, |
| 146 | mContentView); |
| 147 | mTitleBar.setProgress(100); |
| 148 | mNavigationBar = mTitleBar.getNavigationBar(); |
Sagar Dhawan | 1e040c7 | 2014-12-11 20:24:12 -0800 | [diff] [blame] | 149 | |
| 150 | // install system ui visibility listeners |
| 151 | mDecorView = mActivity.getWindow().getDecorView(); |
| 152 | mDecorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener); |
Pankaj Garg | 62bc791 | 2015-04-14 16:08:59 -0700 | [diff] [blame] | 153 | mFullscreenModeLocked = false; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Sagar Dhawan | 1e040c7 | 2014-12-11 20:24:12 -0800 | [diff] [blame] | 156 | private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener = |
| 157 | new View.OnSystemUiVisibilityChangeListener() { |
| 158 | @Override |
| 159 | public void onSystemUiVisibilityChange(int visFlags) { |
Sagar Dhawan | 55165b8 | 2015-09-03 15:33:02 -0700 | [diff] [blame] | 160 | final boolean lostFullscreen = (visFlags & mFullScreenImmersiveSetting) == 0; |
Sagar Dhawan | 1e040c7 | 2014-12-11 20:24:12 -0800 | [diff] [blame] | 161 | if (lostFullscreen) |
| 162 | setFullscreen(BrowserSettings.getInstance().useFullscreen()); |
| 163 | } |
| 164 | }; |
| 165 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 166 | private void cancelStopToast() { |
| 167 | if (mStopToast != null) { |
| 168 | mStopToast.cancel(); |
| 169 | mStopToast = null; |
| 170 | } |
| 171 | } |
| 172 | |
Kulanthaivel Palanichamy | 3817bac | 2014-10-23 19:11:17 -0700 | [diff] [blame] | 173 | protected Drawable getGenericFavicon() { |
| 174 | if (mGenericFavicon == null) { |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 175 | mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal); |
Kulanthaivel Palanichamy | 3817bac | 2014-10-23 19:11:17 -0700 | [diff] [blame] | 176 | } |
| 177 | return mGenericFavicon; |
| 178 | } |
| 179 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 180 | // lifecycle |
| 181 | |
| 182 | public void onPause() { |
Michael Kolb | 7a5cf47 | 2010-11-30 13:23:53 -0800 | [diff] [blame] | 183 | if (isCustomViewShowing()) { |
| 184 | onHideCustomView(); |
| 185 | } |
Denise LaFayette | f9ef98f | 2014-11-11 17:18:29 -0500 | [diff] [blame] | 186 | if (mTabControl.getCurrentTab() != null) { |
| 187 | mTabControl.getCurrentTab().exitFullscreen(); |
| 188 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 189 | cancelStopToast(); |
| 190 | mActivityPaused = true; |
| 191 | } |
| 192 | |
| 193 | public void onResume() { |
| 194 | mActivityPaused = false; |
Michael Kolb | 2ae6ef7 | 2011-08-22 14:49:34 -0700 | [diff] [blame] | 195 | // check if we exited without setting active tab |
| 196 | // b: 5188145 |
Sagar Dhawan | 1e040c7 | 2014-12-11 20:24:12 -0800 | [diff] [blame] | 197 | setFullscreen(BrowserSettings.getInstance().useFullscreen()); |
Sagar Dhawan | 55165b8 | 2015-09-03 15:33:02 -0700 | [diff] [blame] | 198 | //Work around for < Android M |
| 199 | if (Build.VERSION.SDK_INT <= 22 && BrowserSettings.getInstance().useFullscreen()) |
| 200 | mHandler.postDelayed(mFullScreenModeRunnable, 500); |
| 201 | |
Michael Kolb | 1a4625a | 2011-08-24 13:40:44 -0700 | [diff] [blame] | 202 | final Tab ct = mTabControl.getCurrentTab(); |
| 203 | if (ct != null) { |
| 204 | setActiveTab(ct); |
| 205 | } |
John Reck | 1cc1d1d | 2012-09-04 18:13:51 -0700 | [diff] [blame] | 206 | mTitleBar.onResume(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 209 | protected boolean isActivityPaused() { |
| 210 | return mActivityPaused; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | public void onConfigurationChanged(Configuration config) { |
Pankaj Garg | 1c13cab | 2015-05-12 11:52:17 -0700 | [diff] [blame] | 214 | if (mEdgeSwipeController != null) { |
| 215 | mEdgeSwipeController.onConfigurationChanged(); |
| 216 | } |
| 217 | if (mEdgeSwipeSettings != null) { |
| 218 | mEdgeSwipeSettings.onConfigurationChanged(); |
| 219 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 220 | } |
| 221 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 222 | public Activity getActivity() { |
| 223 | return mActivity; |
| 224 | } |
| 225 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 226 | // key handling |
| 227 | |
| 228 | @Override |
| 229 | public boolean onBackKey() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 230 | if (mCustomView != null) { |
| 231 | mUiController.hideCustomView(); |
| 232 | return true; |
Vivek Sekhar | f96064b | 2014-07-28 16:32:34 -0700 | [diff] [blame] | 233 | } else if ((mTabControl.getCurrentTab() != null) && |
Sudheer Koganti | 2476688 | 2014-10-02 10:58:09 -0700 | [diff] [blame] | 234 | (mTabControl.getCurrentTab().exitFullscreen())) { |
Vivek Sekhar | 13ad9b9 | 2014-06-16 15:49:54 -0700 | [diff] [blame] | 235 | return true; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 236 | } |
| 237 | return false; |
| 238 | } |
| 239 | |
Vivek Sekhar | d4de616 | 2015-07-21 15:01:45 -0700 | [diff] [blame] | 240 | public boolean isFullScreen() { |
| 241 | if (mTabControl.getCurrentTab() != null) |
| 242 | return mTabControl.getCurrentTab().isTabFullScreen(); |
| 243 | return false; |
| 244 | } |
| 245 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 246 | @Override |
| 247 | public boolean onMenuKey() { |
| 248 | return false; |
| 249 | } |
| 250 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 251 | // Tab callbacks |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 252 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 253 | public void onTabDataChanged(Tab tab) { |
| 254 | setUrlTitle(tab); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 255 | updateTabSecurityState(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 256 | updateNavigationState(tab); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 257 | mTitleBar.onTabDataChanged(tab); |
John Reck | 419f6b4 | 2011-08-16 16:10:51 -0700 | [diff] [blame] | 258 | mNavigationBar.onTabDataChanged(tab); |
Michael Kolb | a53c989 | 2011-10-05 13:31:40 -0700 | [diff] [blame] | 259 | onProgressChanged(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | @Override |
Michael Kolb | e8a8233 | 2012-04-25 14:14:26 -0700 | [diff] [blame] | 263 | public void onProgressChanged(Tab tab) { |
| 264 | int progress = tab.getLoadProgress(); |
| 265 | if (tab.inForeground()) { |
Pankaj Garg | f9040c8 | 2015-08-14 10:19:31 -0700 | [diff] [blame] | 266 | if (tab.inPageLoad()) { |
| 267 | mTitleBar.setProgress(progress); |
| 268 | } else { |
| 269 | mTitleBar.setProgress(100); |
| 270 | } |
Michael Kolb | e8a8233 | 2012-04-25 14:14:26 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
| 274 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 275 | public void bookmarkedStatusHasChanged(Tab tab) { |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 276 | if (tab.inForeground()) { |
| 277 | boolean isBookmark = tab.isBookmarkedSite(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 278 | mNavigationBar.setCurrentUrlIsBookmark(isBookmark); |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 279 | } |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 283 | public void onPageStopped(Tab tab) { |
| 284 | cancelStopToast(); |
| 285 | if (tab.inForeground()) { |
| 286 | mStopToast = Toast |
| 287 | .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT); |
| 288 | mStopToast.show(); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 293 | public boolean needsRestoreAllTabs() { |
John Reck | 847b532 | 2011-04-14 17:02:18 -0700 | [diff] [blame] | 294 | return true; |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 298 | public void addTab(Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 301 | public void cancelNavScreenRequest(){ |
| 302 | } |
| 303 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 304 | public void setActiveTab(final Tab tab) { |
Michael Kolb | 7ac63b6 | 2011-12-16 09:52:29 -0800 | [diff] [blame] | 305 | if (tab == null) return; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 306 | Tab tabToRemove = null; |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 307 | Tab tabToWaitFor = null; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 308 | |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 309 | // block unnecessary focus change animations during tab switch |
| 310 | mBlockFocusAnimations = true; |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 311 | if ((tab != mActiveTab) && (mActiveTab != null)) { |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 312 | tabToRemove = mActiveTab; |
John Reck | bf2ec20 | 2011-06-29 17:47:38 -0700 | [diff] [blame] | 313 | WebView web = mActiveTab.getWebView(); |
| 314 | if (web != null) { |
| 315 | web.setOnTouchListener(null); |
| 316 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 317 | } |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 318 | mActiveTab = tab; |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 319 | |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 320 | BrowserWebView web = (BrowserWebView) mActiveTab.getWebView(); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 321 | attachTabToContentView(tab); |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 322 | if (web != null) { |
| 323 | // Request focus on the top window. |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 324 | web.setTitleBar(mTitleBar); |
| 325 | mTitleBar.onScrollChanged(); |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 326 | tabToWaitFor = mActiveTab; |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 327 | } |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 328 | mTitleBar.bringToFront(); |
Michael Kolb | f896352 | 2012-04-10 10:52:34 -0700 | [diff] [blame] | 329 | tab.getTopWindow().requestFocus(); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 330 | onTabDataChanged(tab); |
Sagar Dhawan | ca9ecfb | 2015-08-10 17:27:58 -0700 | [diff] [blame] | 331 | setFavicon(tab); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 332 | onProgressChanged(tab); |
Michael Kolb | 03b6bc6 | 2011-09-02 16:19:53 -0700 | [diff] [blame] | 333 | mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled()); |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 334 | mBlockFocusAnimations = false; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 335 | |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 336 | scheduleRemoveTab(tabToRemove, tabToWaitFor); |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 337 | |
| 338 | updateTabSecurityState(tab); |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | Tab mTabToRemove = null; |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 342 | Tab mTabToWaitFor = null; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 343 | int mNumRemoveTries = 0; |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 344 | Runnable mRunnable = null; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 345 | |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 346 | protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) { |
Tarun Nainani | 30fd300 | 2015-02-12 17:46:45 -0800 | [diff] [blame] | 347 | |
| 348 | if(tabToWaitFor == mTabToRemove) { |
| 349 | if (mRunnable != null) { |
| 350 | mTitleBar.removeCallbacks(mRunnable); |
| 351 | } |
| 352 | mTabToRemove = null; |
| 353 | mTabToWaitFor = null; |
| 354 | mRunnable = null; |
| 355 | return; |
| 356 | } |
| 357 | |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 358 | //remove previously scehduled tab |
| 359 | if (mTabToRemove != null) { |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 360 | if (mRunnable != null) |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 361 | mTitleBar.removeCallbacks(mRunnable); |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 362 | removeTabFromContentView(mTabToRemove); |
| 363 | mTabToRemove.performPostponedDestroy(); |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 364 | mRunnable = null; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 365 | } |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 366 | mTabToRemove = tabToRemove; |
| 367 | mTabToWaitFor = tabToWaitFor; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 368 | mNumRemoveTries = 0; |
| 369 | |
| 370 | if (mTabToRemove != null) { |
| 371 | mTabToRemove.postponeDestroy(); |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 372 | tryRemoveTab(); |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
| 376 | protected void tryRemoveTab() { |
| 377 | mNumRemoveTries++; |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 378 | // Ensure the webview is still valid |
| 379 | if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) { |
| 380 | if (!mTabToWaitFor.getWebView().isReady()) { |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 381 | if (mRunnable == null) { |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 382 | mRunnable = new Runnable() { |
| 383 | public void run() { |
| 384 | tryRemoveTab(); |
| 385 | } |
| 386 | }; |
| 387 | } |
| 388 | /*if the new tab is still not ready, wait another 2 frames |
| 389 | before trying again. 1 frame for the tab to render the first |
| 390 | frame, another 1 frame to make sure the swap is done*/ |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 391 | mTitleBar.postDelayed(mRunnable, 33); |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 392 | return; |
| 393 | } |
| 394 | } |
| 395 | if (mTabToRemove != null) { |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 396 | if (mRunnable != null) |
Axesh R. Ajmera | 2e24124 | 2014-05-19 15:53:38 -0700 | [diff] [blame] | 397 | mTitleBar.removeCallbacks(mRunnable); |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 398 | removeTabFromContentView(mTabToRemove); |
| 399 | mTabToRemove.performPostponedDestroy(); |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 400 | mRunnable = null; |
Matthew Hui | b7f2e9c | 2014-04-16 11:12:37 -0400 | [diff] [blame] | 401 | } |
| 402 | mTabToRemove = null; |
Vivek Sekhar | 943f067 | 2014-05-01 18:35:22 -0700 | [diff] [blame] | 403 | mTabToWaitFor = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 406 | Tab getActiveTab() { |
| 407 | return mActiveTab; |
| 408 | } |
| 409 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 410 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 411 | public void updateTabs(List<Tab> tabs) { |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 415 | public void removeTab(Tab tab) { |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 416 | if (mActiveTab == tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 417 | removeTabFromContentView(tab); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 418 | mActiveTab = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 419 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | @Override |
| 423 | public void detachTab(Tab tab) { |
| 424 | removeTabFromContentView(tab); |
| 425 | } |
| 426 | |
| 427 | @Override |
| 428 | public void attachTab(Tab tab) { |
| 429 | attachTabToContentView(tab); |
| 430 | } |
| 431 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 432 | protected void attachTabToContentView(Tab tab) { |
Michael Kolb | d1e2ccc | 2011-01-24 11:38:31 -0800 | [diff] [blame] | 433 | if ((tab == null) || (tab.getWebView() == null)) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 434 | return; |
| 435 | } |
| 436 | View container = tab.getViewContainer(); |
| 437 | WebView mainView = tab.getWebView(); |
| 438 | // Attach the WebView to the container and then attach the |
| 439 | // container to the content view. |
| 440 | FrameLayout wrapper = |
| 441 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
Axesh R. Ajmera | 4fed949 | 2015-05-11 11:50:39 -0700 | [diff] [blame] | 442 | ViewGroup parentView = (ViewGroup)mainView.getView().getParent(); |
| 443 | |
| 444 | if (wrapper != parentView) { |
| 445 | // clean up old view before attaching new view |
| 446 | // this helping in fixing issues such touch event |
| 447 | // getting triggered on old view instead of new one |
| 448 | if (parentView != null) { |
| 449 | parentView.removeView(mainView.getView()); |
| 450 | } |
Vivek Sekhar | ed791da | 2015-02-22 12:39:05 -0800 | [diff] [blame] | 451 | wrapper.addView(mainView.getView()); |
Axesh R. Ajmera | 4fed949 | 2015-05-11 11:50:39 -0700 | [diff] [blame] | 452 | } |
Vivek Sekhar | ed791da | 2015-02-22 12:39:05 -0800 | [diff] [blame] | 453 | ViewGroup parent = (ViewGroup) container.getParent(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 454 | if (parent != mContentView) { |
| 455 | if (parent != null) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 456 | parent.removeView(container); |
| 457 | } |
| 458 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 459 | } |
Pankaj Garg | 1c13cab | 2015-05-12 11:52:17 -0700 | [diff] [blame] | 460 | |
| 461 | refreshEdgeSwipeController(container); |
| 462 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 463 | mUiController.attachSubWindow(tab); |
| 464 | } |
| 465 | |
Pankaj Garg | 1c13cab | 2015-05-12 11:52:17 -0700 | [diff] [blame] | 466 | public void refreshEdgeSwipeController(View container) { |
Site Mao | 61b6821 | 2015-07-16 10:56:31 -0700 | [diff] [blame] | 467 | if (isUiLowPowerMode()) { |
Pankaj Garg | 18aa0a1 | 2015-06-22 11:06:12 -0700 | [diff] [blame] | 468 | return; |
| 469 | } |
| 470 | |
Pankaj Garg | 1c13cab | 2015-05-12 11:52:17 -0700 | [diff] [blame] | 471 | if (mEdgeSwipeController != null) { |
| 472 | mEdgeSwipeController.cleanup(); |
| 473 | } |
| 474 | |
Pankaj Garg | 1c13cab | 2015-05-12 11:52:17 -0700 | [diff] [blame] | 475 | String action = BrowserSettings.getInstance().getEdgeSwipeAction(); |
| 476 | |
Sagar Dhawan | 05e3c35 | 2015-09-07 15:24:33 +0200 | [diff] [blame] | 477 | if (mEdgeSwipeSettings != null) { |
| 478 | mEdgeSwipeSettings.cleanup(); |
| 479 | } |
| 480 | mEdgeSwipeSettings = null; |
| 481 | |
Pankaj Garg | 1c13cab | 2015-05-12 11:52:17 -0700 | [diff] [blame] | 482 | if (action.equalsIgnoreCase( |
| 483 | mActivity.getResources().getString(R.string.value_temporal_edge_swipe))) { |
| 484 | mEdgeSwipeController = new EdgeSwipeController( |
| 485 | container, |
| 486 | R.id.stationary_navview, |
| 487 | R.id.sliding_navview, |
| 488 | R.id.sliding_navview_shadow, |
| 489 | R.id.navview_opacity, |
| 490 | R.id.webview_wrapper, |
| 491 | R.id.draggable_mainframe, |
| 492 | this); |
| 493 | } else if (action.equalsIgnoreCase( |
| 494 | mActivity.getResources().getString(R.string.value_unknown_edge_swipe))) { |
| 495 | mEdgeSwipeSettings = new EdgeSwipeSettings( |
| 496 | container, |
| 497 | R.id.stationary_navview, |
| 498 | R.id.edge_sliding_settings, |
| 499 | R.id.sliding_navview_shadow, |
| 500 | R.id.webview_wrapper, |
| 501 | R.id.draggable_mainframe, |
| 502 | this); |
| 503 | } else { |
| 504 | DraggableFrameLayout draggableView = (DraggableFrameLayout) |
| 505 | container.findViewById(R.id.draggable_mainframe); |
| 506 | draggableView.setDragHelper(null); |
| 507 | } |
| 508 | } |
| 509 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 510 | private void removeTabFromContentView(Tab tab) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 511 | hideTitleBar(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 512 | // Remove the container that contains the main WebView. |
| 513 | WebView mainView = tab.getWebView(); |
| 514 | View container = tab.getViewContainer(); |
| 515 | if (mainView == null) { |
| 516 | return; |
| 517 | } |
| 518 | // Remove the container from the content and then remove the |
| 519 | // WebView from the container. This will trigger a focus change |
| 520 | // needed by WebView. |
| 521 | FrameLayout wrapper = |
| 522 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
Vivek Sekhar | ed791da | 2015-02-22 12:39:05 -0800 | [diff] [blame] | 523 | wrapper.removeView(mainView.getView()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 524 | mContentView.removeView(container); |
| 525 | mUiController.endActionMode(); |
| 526 | mUiController.removeSubWindow(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 529 | @Override |
| 530 | public void onSetWebView(Tab tab, WebView webView) { |
| 531 | View container = tab.getViewContainer(); |
| 532 | if (container == null) { |
| 533 | // The tab consists of a container view, which contains the main |
| 534 | // WebView, as well as any other UI elements associated with the tab. |
| 535 | container = mActivity.getLayoutInflater().inflate(R.layout.tab, |
John Reck | 7c6e1c9 | 2011-06-30 11:55:55 -0700 | [diff] [blame] | 536 | mContentView, false); |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 537 | tab.setViewContainer(container); |
| 538 | } |
| 539 | if (tab.getWebView() != webView) { |
| 540 | // Just remove the old one. |
| 541 | FrameLayout wrapper = |
| 542 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 543 | wrapper.removeView(tab.getWebView()); |
| 544 | } |
| 545 | } |
| 546 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 547 | /** |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 548 | * create a sub window container and webview for the tab |
| 549 | * Note: this methods operates through side-effects for now |
| 550 | * it sets both the subView and subViewContainer for the given tab |
| 551 | * @param tab tab to create the sub window for |
| 552 | * @param subView webview to be set as a subwindow for the tab |
| 553 | */ |
| 554 | @Override |
| 555 | public void createSubWindow(Tab tab, WebView subView) { |
| 556 | View subViewContainer = mActivity.getLayoutInflater().inflate( |
| 557 | R.layout.browser_subwindow, null); |
| 558 | ViewGroup inner = (ViewGroup) subViewContainer |
| 559 | .findViewById(R.id.inner_container); |
| 560 | inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT, |
| 561 | LayoutParams.MATCH_PARENT)); |
| 562 | final ImageButton cancel = (ImageButton) subViewContainer |
| 563 | .findViewById(R.id.subwindow_close); |
| 564 | final WebView cancelSubView = subView; |
| 565 | cancel.setOnClickListener(new OnClickListener() { |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 566 | @Override |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 567 | public void onClick(View v) { |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 568 | ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView); |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 569 | } |
| 570 | }); |
| 571 | tab.setSubWebView(subView); |
| 572 | tab.setSubViewContainer(subViewContainer); |
| 573 | } |
| 574 | |
| 575 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 576 | * Remove the sub window from the content view. |
| 577 | */ |
| 578 | @Override |
| 579 | public void removeSubWindow(View subviewContainer) { |
| 580 | mContentView.removeView(subviewContainer); |
| 581 | mUiController.endActionMode(); |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * Attach the sub window to the content view. |
| 586 | */ |
| 587 | @Override |
| 588 | public void attachSubWindow(View container) { |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 589 | if (container.getParent() != null) { |
| 590 | // already attached, remove first |
| 591 | ((ViewGroup) container.getParent()).removeView(container); |
| 592 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 593 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 594 | } |
| 595 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 596 | protected void refreshWebView() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 597 | WebView web = getWebView(); |
| 598 | if (web != null) { |
| 599 | web.invalidate(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 603 | public void editUrl(boolean clearInput, boolean forceIME) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 604 | if (mUiController.isInCustomActionMode()) { |
| 605 | mUiController.endActionMode(); |
| 606 | } |
| 607 | showTitleBar(); |
Michael Kolb | ace2ff8 | 2011-08-12 13:36:07 -0700 | [diff] [blame] | 608 | if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 609 | mNavigationBar.startEditingUrl(clearInput, forceIME); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 610 | } |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 613 | boolean canShowTitleBar() { |
| 614 | return !isTitleBarShowing() |
| 615 | && !isActivityPaused() |
| 616 | && (getActiveTab() != null) |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 617 | && (getWebView() != null) |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 618 | && !mUiController.isInCustomActionMode(); |
| 619 | } |
| 620 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 621 | protected void showTitleBar() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 622 | if (canShowTitleBar()) { |
Vivek Sekhar | d4de616 | 2015-07-21 15:01:45 -0700 | [diff] [blame] | 623 | mTitleBar.showTopControls(false); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 624 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | protected void hideTitleBar() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 628 | if (mTitleBar.isShowing()) { |
Vivek Sekhar | d4de616 | 2015-07-21 15:01:45 -0700 | [diff] [blame] | 629 | mTitleBar.enableTopControls(false); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 630 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | protected boolean isTitleBarShowing() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 634 | return mTitleBar.isShowing(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 635 | } |
| 636 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 637 | public boolean isEditingUrl() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 638 | return mTitleBar.isEditingUrl(); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Michael Kolb | 80f7508 | 2012-04-10 10:50:06 -0700 | [diff] [blame] | 641 | public void stopEditingUrl() { |
| 642 | mTitleBar.getNavigationBar().stopEditingUrl(); |
| 643 | } |
| 644 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 645 | public TitleBar getTitleBar() { |
| 646 | return mTitleBar; |
| 647 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 648 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 649 | @Override |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 650 | public void showComboView(ComboViews startingView, Bundle extras) { |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 651 | Intent intent = new Intent(mActivity, ComboViewActivity.class); |
| 652 | intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name()); |
| 653 | intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras); |
| 654 | Tab t = getActiveTab(); |
| 655 | if (t != null) { |
| 656 | intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl()); |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 657 | } |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 658 | mActivity.startActivityForResult(intent, Controller.COMBO_VIEW); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | @Override |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 662 | public void hideComboView() { |
| 663 | } |
| 664 | |
| 665 | @Override |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 666 | public void showCustomView(View view, int requestedOrientation, |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 667 | CustomViewCallback callback) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 668 | // if a view already exists then immediately terminate the new one |
| 669 | if (mCustomView != null) { |
| 670 | callback.onCustomViewHidden(); |
| 671 | return; |
| 672 | } |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 673 | mOriginalOrientation = mActivity.getRequestedOrientation(); |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 674 | FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); |
Denise LaFayette | da31d74 | 2014-10-10 18:03:13 -0400 | [diff] [blame] | 675 | decor.addView(view, COVER_SCREEN_PARAMS); |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 676 | mCustomView = view; |
Denise LaFayette | da31d74 | 2014-10-10 18:03:13 -0400 | [diff] [blame] | 677 | showFullscreen(true); |
Michael Kolb | 54217b3 | 2012-05-15 13:24:24 -0700 | [diff] [blame] | 678 | ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 679 | mCustomViewCallback = callback; |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 680 | mActivity.setRequestedOrientation(requestedOrientation); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | @Override |
| 684 | public void onHideCustomView() { |
Michael Kolb | 54217b3 | 2012-05-15 13:24:24 -0700 | [diff] [blame] | 685 | ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 686 | if (mCustomView == null) |
| 687 | return; |
Denise LaFayette | da31d74 | 2014-10-10 18:03:13 -0400 | [diff] [blame] | 688 | showFullscreen(false); |
Michael Kolb | 31065b1 | 2011-10-06 13:51:32 -0700 | [diff] [blame] | 689 | FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); |
Denise LaFayette | da31d74 | 2014-10-10 18:03:13 -0400 | [diff] [blame] | 690 | decor.removeView(mCustomView); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 691 | mCustomView = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 692 | mCustomViewCallback.onCustomViewHidden(); |
| 693 | // Show the content view. |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 694 | mActivity.setRequestedOrientation(mOriginalOrientation); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | @Override |
| 698 | public boolean isCustomViewShowing() { |
| 699 | return mCustomView != null; |
| 700 | } |
| 701 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 702 | protected void dismissIME() { |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 703 | if (mInputManager.isActive()) { |
| 704 | mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(), |
| 705 | 0); |
| 706 | } |
| 707 | } |
| 708 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 709 | @Override |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 710 | public boolean isWebShowing() { |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 711 | return mCustomView == null; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 714 | @Override |
| 715 | public boolean isComboViewShowing() { |
| 716 | return false; |
| 717 | } |
| 718 | |
Site Mao | 61b6821 | 2015-07-16 10:56:31 -0700 | [diff] [blame] | 719 | public static boolean isUiLowPowerMode() { |
Site Mao | 7521b09 | 2015-07-20 18:27:20 -0700 | [diff] [blame] | 720 | return BrowserCommandLine.hasSwitch("ui-low-power-mode") |
| 721 | || BrowserSettings.getInstance().isPowerSaveModeEnabled() |
| 722 | || BrowserSettings.getInstance().isDisablePerfFeatures(); |
Site Mao | 61b6821 | 2015-07-16 10:56:31 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 725 | // ------------------------------------------------------------------------- |
| 726 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 727 | protected void updateNavigationState(Tab tab) { |
| 728 | } |
| 729 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 730 | /** |
| 731 | * Update the lock icon to correspond to our latest state. |
| 732 | */ |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 733 | private void updateTabSecurityState(Tab t) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 734 | if (t != null && t.inForeground()) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 735 | mNavigationBar.setSecurityState(t.getSecurityState()); |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 736 | setUrlTitle(t); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 740 | protected void setUrlTitle(Tab tab) { |
| 741 | String url = tab.getUrl(); |
| 742 | String title = tab.getTitle(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 743 | if (TextUtils.isEmpty(title)) { |
| 744 | title = url; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 745 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 746 | if (tab.inForeground()) { |
Pankaj Garg | 8d2e98f | 2015-08-07 10:01:49 -0700 | [diff] [blame] | 747 | mNavigationBar.setDisplayTitle(title, url); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | |
| 751 | // Set the favicon in the title bar. |
Sagar Dhawan | ca9ecfb | 2015-08-10 17:27:58 -0700 | [diff] [blame] | 752 | public void setFavicon(Tab tab) { |
| 753 | mNavigationBar.showCurrentFavicon(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 756 | // active tabs page |
| 757 | |
| 758 | public void showActiveTabsPage() { |
| 759 | } |
| 760 | |
| 761 | /** |
| 762 | * Remove the active tabs page. |
| 763 | */ |
| 764 | public void removeActiveTabsPage() { |
| 765 | } |
| 766 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 767 | // menu handling callbacks |
| 768 | |
| 769 | @Override |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 770 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 771 | return true; |
| 772 | } |
| 773 | |
| 774 | @Override |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 775 | public void updateMenuState(Tab tab, Menu menu) { |
| 776 | } |
| 777 | |
| 778 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 779 | public void onOptionsMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | @Override |
| 783 | public void onExtendedMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | @Override |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 787 | public boolean onOptionsItemSelected(MenuItem item) { |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 792 | public void onOptionsMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | @Override |
| 796 | public void onExtendedMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | @Override |
| 800 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | @Override |
| 804 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 807 | // ------------------------------------------------------------------------- |
| 808 | // Helper function for WebChromeClient |
| 809 | // ------------------------------------------------------------------------- |
| 810 | |
| 811 | @Override |
| 812 | public Bitmap getDefaultVideoPoster() { |
| 813 | if (mDefaultVideoPoster == null) { |
| 814 | mDefaultVideoPoster = BitmapFactory.decodeResource( |
| 815 | mActivity.getResources(), R.drawable.default_video_poster); |
| 816 | } |
| 817 | return mDefaultVideoPoster; |
| 818 | } |
| 819 | |
| 820 | @Override |
| 821 | public View getVideoLoadingProgressView() { |
| 822 | if (mVideoProgressView == null) { |
| 823 | LayoutInflater inflater = LayoutInflater.from(mActivity); |
| 824 | mVideoProgressView = inflater.inflate( |
| 825 | R.layout.video_loading_progress, null); |
| 826 | } |
| 827 | return mVideoProgressView; |
| 828 | } |
| 829 | |
Michael Kolb | 843510f | 2010-12-09 10:51:49 -0800 | [diff] [blame] | 830 | @Override |
| 831 | public void showMaxTabsWarning() { |
| 832 | Toast warning = Toast.makeText(mActivity, |
| 833 | mActivity.getString(R.string.max_tabs_warning), |
| 834 | Toast.LENGTH_SHORT); |
| 835 | warning.show(); |
| 836 | } |
| 837 | |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 838 | protected WebView getWebView() { |
Sagar Dhawan | f7b5d0b | 2015-02-06 15:47:20 -0800 | [diff] [blame] | 839 | |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 840 | if (mActiveTab != null) { |
| 841 | return mActiveTab.getWebView(); |
| 842 | } else { |
| 843 | return null; |
| 844 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Pankaj Garg | 62bc791 | 2015-04-14 16:08:59 -0700 | [diff] [blame] | 847 | public void forceDisableFullscreenMode(boolean disabled) { |
| 848 | mFullscreenModeLocked = false; |
| 849 | setFullscreen(!disabled); |
| 850 | mFullscreenModeLocked = disabled; |
| 851 | } |
| 852 | |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 853 | public void setFullscreen(boolean enabled) { |
Pankaj Garg | 62bc791 | 2015-04-14 16:08:59 -0700 | [diff] [blame] | 854 | if (mFullscreenModeLocked) |
| 855 | return; |
| 856 | |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 857 | Window win = mActivity.getWindow(); |
| 858 | WindowManager.LayoutParams winParams = win.getAttributes(); |
Michael Kolb | 76dff39 | 2011-12-06 09:51:18 -0800 | [diff] [blame] | 859 | final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN; |
Denise LaFayette | d74d702 | 2014-11-07 16:40:01 -0500 | [diff] [blame] | 860 | |
| 861 | if (mCustomView != null) { |
| 862 | mCustomView.setSystemUiVisibility(enabled ? |
Sagar Dhawan | 55165b8 | 2015-09-03 15:33:02 -0700 | [diff] [blame] | 863 | mFullScreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE); |
Sagar Dhawan | 1e040c7 | 2014-12-11 20:24:12 -0800 | [diff] [blame] | 864 | } else if (Build.VERSION.SDK_INT >= 19) { |
| 865 | mContentView.setSystemUiVisibility(enabled ? |
Sagar Dhawan | 55165b8 | 2015-09-03 15:33:02 -0700 | [diff] [blame] | 866 | mFullScreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 867 | } else { |
Denise LaFayette | d74d702 | 2014-11-07 16:40:01 -0500 | [diff] [blame] | 868 | mContentView.setSystemUiVisibility(enabled ? |
Sagar Dhawan | 1e040c7 | 2014-12-11 20:24:12 -0800 | [diff] [blame] | 869 | View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 870 | } |
Sagar Dhawan | 2abecc6 | 2015-09-14 18:53:04 -0700 | [diff] [blame] | 871 | if (enabled) { |
| 872 | winParams.flags |= bits; |
| 873 | } else { |
Denise LaFayette | d74d702 | 2014-11-07 16:40:01 -0500 | [diff] [blame] | 874 | winParams.flags &= ~bits; |
Sagar Dhawan | 2abecc6 | 2015-09-14 18:53:04 -0700 | [diff] [blame] | 875 | } |
Denise LaFayette | d74d702 | 2014-11-07 16:40:01 -0500 | [diff] [blame] | 876 | |
Michael Kolb | c5675ad | 2011-10-21 13:34:28 -0700 | [diff] [blame] | 877 | win.setAttributes(winParams); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Denise LaFayette | da31d74 | 2014-10-10 18:03:13 -0400 | [diff] [blame] | 880 | //make full screen by showing/hiding topbar and system status bar |
Sudheer Koganti | 2476688 | 2014-10-02 10:58:09 -0700 | [diff] [blame] | 881 | public void showFullscreen(boolean fullScreen) { |
Sagar Dhawan | 2abecc6 | 2015-09-14 18:53:04 -0700 | [diff] [blame] | 882 | |
Sudheer Koganti | 2476688 | 2014-10-02 10:58:09 -0700 | [diff] [blame] | 883 | //Hide/show system ui bar as needed |
| 884 | if (!BrowserSettings.getInstance().useFullscreen()) |
| 885 | setFullscreen(fullScreen); |
Sudheer Koganti | 2476688 | 2014-10-02 10:58:09 -0700 | [diff] [blame] | 886 | //Hide/show topbar as needed |
| 887 | if (getWebView() != null) { |
Vivek Sekhar | 6bd3217 | 2015-05-06 15:48:07 -0700 | [diff] [blame] | 888 | BrowserWebView bwv = (BrowserWebView) getWebView(); |
Sudheer Koganti | 2476688 | 2014-10-02 10:58:09 -0700 | [diff] [blame] | 889 | if (fullScreen) { |
Vivek Sekhar | d4de616 | 2015-07-21 15:01:45 -0700 | [diff] [blame] | 890 | // hide titlebar |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 891 | mTitleBar.hideTopControls(true); |
Sudheer Koganti | 2476688 | 2014-10-02 10:58:09 -0700 | [diff] [blame] | 892 | } else { |
Vivek Sekhar | d4de616 | 2015-07-21 15:01:45 -0700 | [diff] [blame] | 893 | // show titlebar |
| 894 | mTitleBar.showTopControls(false); |
| 895 | // enable auto hide titlebar |
Sudheer Koganti | 2476688 | 2014-10-02 10:58:09 -0700 | [diff] [blame] | 896 | if (!mTitleBar.isFixed()) |
Vivek Sekhar | d4de616 | 2015-07-21 15:01:45 -0700 | [diff] [blame] | 897 | mTitleBar.enableTopControls(false); |
Sudheer Koganti | 2476688 | 2014-10-02 10:58:09 -0700 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 902 | public void translateTitleBar(float topControlsOffsetYPix) { |
Vivek Sekhar | d4de616 | 2015-07-21 15:01:45 -0700 | [diff] [blame] | 903 | if (mTitleBar == null || mTitleBar.isFixed()) |
| 904 | return; |
| 905 | if (!mInActionMode) { |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 906 | if (topControlsOffsetYPix != 0.0) { |
| 907 | mTitleBar.setEnabled(false); |
| 908 | } else { |
| 909 | mTitleBar.setEnabled(true); |
| 910 | } |
Vivek Sekhar | d4de616 | 2015-07-21 15:01:45 -0700 | [diff] [blame] | 911 | float currentY = mTitleBar.getTranslationY(); |
| 912 | float height = mNavigationBar.getHeight(); |
Sagar Dhawan | eecefa3 | 2015-09-25 12:02:34 -0700 | [diff] [blame] | 913 | |
Vivek Sekhar | d4de616 | 2015-07-21 15:01:45 -0700 | [diff] [blame] | 914 | if ((height + currentY) <= 0 && (height + topControlsOffsetYPix) > 0) { |
| 915 | mTitleBar.requestLayout(); |
| 916 | } else if ((height + topControlsOffsetYPix) <= 0) { |
Sagar Dhawan | eecefa3 | 2015-09-25 12:02:34 -0700 | [diff] [blame] | 917 | // Need to add the progress bar's margin to the offest since it's height is not |
| 918 | // accounted for and the dropshadow draws inside it. |
| 919 | topControlsOffsetYPix += |
| 920 | mActivity.getResources().getDimension(R.dimen.progress_bar_margin); |
Vivek Sekhar | d4de616 | 2015-07-21 15:01:45 -0700 | [diff] [blame] | 921 | mTitleBar.getParent().requestTransparentRegion(mTitleBar); |
Sudheer Koganti | 56cba97 | 2014-11-13 15:15:46 -0800 | [diff] [blame] | 922 | } |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame] | 923 | // This was done to get HTML5 fullscreen API to work with fixed mode since |
| 924 | // topcontrols are used to implement HTML5 fullscreen |
| 925 | mTitleBar.setTranslationY(topControlsOffsetYPix); |
Sagar Dhawan | eecefa3 | 2015-09-25 12:02:34 -0700 | [diff] [blame] | 926 | |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 930 | public Drawable getFaviconDrawable(Bitmap icon) { |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 931 | if (ENABLE_BORDER_AROUND_FAVICON) { |
| 932 | Drawable[] array = new Drawable[3]; |
| 933 | array[0] = new PaintDrawable(Color.BLACK); |
| 934 | PaintDrawable p = new PaintDrawable(Color.WHITE); |
| 935 | array[1] = p; |
| 936 | if (icon == null) { |
| 937 | array[2] = getGenericFavicon(); |
| 938 | } else { |
| 939 | array[2] = new BitmapDrawable(mActivity.getResources(), icon); |
| 940 | } |
| 941 | LayerDrawable d = new LayerDrawable(array); |
| 942 | d.setLayerInset(1, 1, 1, 1, 1); |
| 943 | d.setLayerInset(2, 2, 2, 2, 2); |
| 944 | return d; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 945 | } |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 946 | return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon); |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 947 | } |
| 948 | |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 949 | public boolean isLoading() { |
| 950 | return mActiveTab != null ? mActiveTab.inPageLoad() : false; |
| 951 | } |
| 952 | |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 953 | protected void setMenuItemVisibility(Menu menu, int id, |
| 954 | boolean visibility) { |
| 955 | MenuItem item = menu.findItem(id); |
| 956 | if (item != null) { |
| 957 | item.setVisible(visibility); |
| 958 | } |
| 959 | } |
| 960 | |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 961 | protected Handler mHandler = new Handler() { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 962 | |
| 963 | @Override |
| 964 | public void handleMessage(Message msg) { |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 965 | BaseUi.this.handleMessage(msg); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 966 | } |
| 967 | }; |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 968 | |
John Reck | 9c5004e | 2011-10-07 16:00:12 -0700 | [diff] [blame] | 969 | protected void handleMessage(Message msg) {} |
| 970 | |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 971 | @Override |
| 972 | public void showWeb(boolean animate) { |
| 973 | mUiController.hideCustomView(); |
| 974 | } |
| 975 | |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 976 | public void setContentViewMarginTop(int margin) { |
Kulanthaivel Palanichamy | 033af09 | 2014-12-12 18:16:24 -0800 | [diff] [blame] | 977 | FrameLayout.LayoutParams params = |
| 978 | (FrameLayout.LayoutParams) mContentView.getLayoutParams(); |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 979 | if (params.topMargin != margin) { |
| 980 | params.topMargin = margin; |
| 981 | mContentView.setLayoutParams(params); |
| 982 | } |
| 983 | } |
Michael Kolb | bae0cb2 | 2012-05-29 11:15:27 -0700 | [diff] [blame] | 984 | |
| 985 | @Override |
| 986 | public boolean blockFocusAnimations() { |
| 987 | return mBlockFocusAnimations; |
| 988 | } |
| 989 | |
Michael Kolb | 0b12912 | 2012-06-04 16:31:58 -0700 | [diff] [blame] | 990 | @Override |
| 991 | public void onVoiceResult(String result) { |
| 992 | mNavigationBar.onVoiceResult(result); |
| 993 | } |
| 994 | |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 995 | protected UiController getUiController() { |
| 996 | return mUiController; |
| 997 | } |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 998 | |
Vivek Sekhar | 60eb980 | 2014-07-21 19:13:33 -0700 | [diff] [blame] | 999 | boolean mInActionMode = false; |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 1000 | private float getActionModeHeight() { |
| 1001 | TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes( |
| 1002 | new int[] { android.R.attr.actionBarSize }); |
| 1003 | float size = actionBarSizeTypedArray.getDimension(0, 0f); |
| 1004 | actionBarSizeTypedArray.recycle(); |
| 1005 | return size; |
| 1006 | } |
| 1007 | |
Vivek Sekhar | 60eb980 | 2014-07-21 19:13:33 -0700 | [diff] [blame] | 1008 | |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 1009 | @Override |
| 1010 | public void onActionModeStarted(ActionMode mode) { |
Vivek Sekhar | 60eb980 | 2014-07-21 19:13:33 -0700 | [diff] [blame] | 1011 | mInActionMode = true; |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 1012 | |
| 1013 | if (mTitleBar.isFixed()) { |
| 1014 | int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight(); |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 1015 | setContentViewMarginTop(fixedTbarHeight); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 1016 | } else { |
| 1017 | mTitleBar.setTranslationY(getActionModeHeight()); |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 1018 | } |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | @Override |
| 1022 | public void onActionModeFinished(boolean inLoad) { |
Vivek Sekhar | 60eb980 | 2014-07-21 19:13:33 -0700 | [diff] [blame] | 1023 | mInActionMode = false; |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 1024 | if (mTitleBar.isFixed()) { |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 1025 | setContentViewMarginTop(0); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 1026 | } else { |
| 1027 | mTitleBar.setTranslationY(0); |
Vivek Sekhar | 8ee3abb | 2014-07-14 12:32:05 -0700 | [diff] [blame] | 1028 | } |
Bijan Amirzada | 357ec8a | 2014-04-08 14:19:10 -0700 | [diff] [blame] | 1029 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 1030 | |
| 1031 | @Override |
| 1032 | public boolean shouldCaptureThumbnails() { |
| 1033 | return true; |
| 1034 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1035 | } |