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