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