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