blob: 8c34fc9505dbbbbcb3af0c536985f2f8d000a0ff [file] [log] [blame]
Michael Kolb66706532010-12-12 19:50:22 -08001/*
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
17package com.android.browser;
18
19import com.android.browser.ScrollWebView.ScrollListener;
20
John Recke5c21d92011-03-11 15:09:46 -080021import android.animation.Animator;
22import android.animation.Animator.AnimatorListener;
23import android.animation.ObjectAnimator;
Michael Kolb66706532010-12-12 19:50:22 -080024import android.app.ActionBar;
25import android.app.Activity;
Michael Kolb24915222011-02-24 11:38:49 -080026import android.content.pm.PackageManager;
Michael Kolbeb95db42011-03-03 10:38:40 -080027import android.graphics.Bitmap;
Michael Kolbac35bdc2011-01-17 17:06:04 -080028import android.os.Bundle;
Michael Kolbba238702011-03-08 10:40:50 -080029import android.os.Handler;
Michael Kolb376b5412010-12-15 11:52:57 -080030import android.util.Log;
Michael Kolb66706532010-12-12 19:50:22 -080031import android.view.ActionMode;
Michael Kolb376b5412010-12-15 11:52:57 -080032import android.view.Gravity;
Michael Kolba4183062011-01-16 10:43:21 -080033import android.view.KeyEvent;
Michael Kolb1acef692011-03-08 14:12:06 -080034import android.view.Menu;
John Reckd73c5a22010-12-22 10:22:50 -080035import android.view.View;
36import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb66706532010-12-12 19:50:22 -080037import android.webkit.WebView;
Michael Kolb2a56eca2011-02-25 09:45:06 -080038import android.widget.FrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080039
40import java.util.List;
41
42/**
43 * Ui for xlarge screen sizes
44 */
45public class XLargeUi extends BaseUi implements ScrollListener {
46
47 private static final String LOGTAG = "XLargeUi";
48
Michael Kolb376b5412010-12-15 11:52:57 -080049 private ActionBar mActionBar;
Michael Kolb66706532010-12-12 19:50:22 -080050 private TabBar mTabBar;
51
52 private TitleBarXLarge mTitleBar;
John Recke5c21d92011-03-11 15:09:46 -080053 private Animator mTitleBarAnimator;
John Reck6e8d2e92011-03-14 11:29:56 -070054 private boolean mSkipTitleBarAnimations;
Michael Kolb66706532010-12-12 19:50:22 -080055
Michael Kolb376b5412010-12-15 11:52:57 -080056 private boolean mUseQuickControls;
57 private PieControl mPieControl;
Michael Kolbba238702011-03-08 10:40:50 -080058 private Handler mHandler;
Michael Kolb376b5412010-12-15 11:52:57 -080059
Michael Kolb66706532010-12-12 19:50:22 -080060 /**
61 * @param browser
62 * @param controller
63 */
64 public XLargeUi(Activity browser, UiController controller) {
65 super(browser, controller);
Michael Kolbba238702011-03-08 10:40:50 -080066 mHandler = new Handler();
Michael Kolb66706532010-12-12 19:50:22 -080067 mTitleBar = new TitleBarXLarge(mActivity, mUiController, this);
68 mTitleBar.setProgress(100);
Michael Kolb66706532010-12-12 19:50:22 -080069 mTabBar = new TabBar(mActivity, mUiController, this);
Michael Kolb376b5412010-12-15 11:52:57 -080070 mActionBar = mActivity.getActionBar();
John Reckb3417f02011-01-14 11:01:05 -080071 setupActionBar();
72 setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
73 }
74
75 private void setupActionBar() {
76 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Michael Kolb376b5412010-12-15 11:52:57 -080077 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
78 mActionBar.setCustomView(mTabBar);
John Reckb3417f02011-01-14 11:01:05 -080079 }
80
81 @Override
Michael Kolbac35bdc2011-01-17 17:06:04 -080082 public void showComboView(boolean startWithHistory, Bundle extras) {
83 super.showComboView(startWithHistory, extras);
84 if (mUseQuickControls) {
85 mActionBar.show();
86 }
87 }
88
89 @Override
John Reckb3417f02011-01-14 11:01:05 -080090 public void hideComboView() {
Michael Kolbba238702011-03-08 10:40:50 -080091 if (isComboViewShowing()) {
92 super.hideComboView();
93 // ComboView changes the action bar, set it back up to what we want
94 setupActionBar();
95 checkTabCount();
96 }
Michael Kolb376b5412010-12-15 11:52:57 -080097 }
98
99 private void setUseQuickControls(boolean useQuickControls) {
100 mUseQuickControls = useQuickControls;
Michael Kolb7cdc4902011-02-03 17:54:40 -0800101 mTitleBar.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800102 if (useQuickControls) {
103 checkTabCount();
104 mPieControl = new PieControl(mActivity, mUiController, this);
105 mPieControl.attachToContainer(mContentView);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800106 Tab tab = getActiveTab();
107 if ((tab != null) && (tab.getWebView() != null)) {
108 tab.getWebView().setEmbeddedTitleBar(null);
Michael Kolb376b5412010-12-15 11:52:57 -0800109 }
110 } else {
111 mActivity.getActionBar().show();
112 if (mPieControl != null) {
113 mPieControl.removeFromContainer(mContentView);
114 }
Michael Kolb376b5412010-12-15 11:52:57 -0800115 WebView web = mTabControl.getCurrentWebView();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800116 if (web != null) {
Michael Kolb376b5412010-12-15 11:52:57 -0800117 web.setEmbeddedTitleBar(mTitleBar);
118 }
Michael Kolb8a4c3822011-03-15 14:52:05 -0700119 setTitleGravity(Gravity.NO_GRAVITY);
Michael Kolb376b5412010-12-15 11:52:57 -0800120 }
121 mTabBar.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800122 }
123
124 private void checkTabCount() {
125 if (mUseQuickControls) {
Michael Kolbeb95db42011-03-03 10:38:40 -0800126 mHandler.post(new Runnable() {
127 public void run() {
128 mActionBar.hide();
129 }
130 });
Michael Kolb376b5412010-12-15 11:52:57 -0800131 }
Michael Kolb66706532010-12-12 19:50:22 -0800132 }
133
134 @Override
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000135 public void onResume() {
136 super.onResume();
137 if (!BrowserSettings.getInstance().useInstant()) {
138 mTitleBar.clearCompletions();
139 }
140 }
141
142 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800143 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800144 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800145 }
146
147 // webview factory
148
149 @Override
150 public WebView createWebView(boolean privateBrowsing) {
151 // Create a new WebView
152 ScrollWebView w = new ScrollWebView(mActivity, null,
153 android.R.attr.webViewStyle, privateBrowsing);
154 initWebViewSettings(w);
155 w.setScrollListener(this);
Michael Kolb24915222011-02-24 11:38:49 -0800156 boolean supportsMultiTouch = mActivity.getPackageManager()
157 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
158 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
Dave Burke20b6f1f2011-02-01 12:59:04 +0000159 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb66706532010-12-12 19:50:22 -0800160 return w;
161 }
162
163 @Override
164 public WebView createSubWebView(boolean privateBrowsing) {
165 ScrollWebView web = (ScrollWebView) createWebView(privateBrowsing);
166 // no scroll listener for subview
167 web.setScrollListener(null);
168 return web;
169 }
170
171 @Override
Michael Kolb5ee018e2011-02-18 15:47:21 -0800172 public void onScroll(int visibleTitleHeight, boolean userInitiated) {
173 mTabBar.onScroll(visibleTitleHeight, userInitiated);
Michael Kolb66706532010-12-12 19:50:22 -0800174 }
175
176 void stopWebViewScrolling() {
177 ScrollWebView web = (ScrollWebView) mUiController.getCurrentWebView();
178 if (web != null) {
179 web.stopScroll();
180 }
181 }
182
183 // WebView callbacks
184
185 @Override
John Reck30c714c2010-12-16 17:30:34 -0800186 public void onProgressChanged(Tab tab) {
187 int progress = tab.getLoadProgress();
Michael Kolb66706532010-12-12 19:50:22 -0800188 mTabBar.onProgress(tab, progress);
189 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800190 mTitleBar.setProgress(progress);
Michael Kolb66706532010-12-12 19:50:22 -0800191 if (progress == 100) {
Michael Kolb8a4c3822011-03-15 14:52:05 -0700192 if (!mTitleBar.isEditingUrl() && !mTitleBar.inAutoLogin()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800193 hideTitleBar();
Michael Kolbbd018d42010-12-15 15:43:39 -0800194 if (mUseQuickControls) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800195 mTitleBar.setShowProgressOnly(false);
Michael Kolbbd018d42010-12-15 15:43:39 -0800196 }
Michael Kolb376b5412010-12-15 11:52:57 -0800197 }
Michael Kolb66706532010-12-12 19:50:22 -0800198 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800199 if (!isTitleBarShowing()) {
200 if (mUseQuickControls && !mTitleBar.isEditingUrl()) {
201 mTitleBar.setShowProgressOnly(true);
202 setTitleGravity(Gravity.TOP);
Michael Kolb376b5412010-12-15 11:52:57 -0800203 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800204 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800205 }
Michael Kolb66706532010-12-12 19:50:22 -0800206 }
207 }
208 }
209
210 @Override
211 public boolean needsRestoreAllTabs() {
212 return true;
213 }
214
215 @Override
216 public void addTab(Tab tab) {
217 mTabBar.onNewTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800218 }
219
220 protected void onAddTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800221 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800222 }
223
224 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800225 public void setActiveTab(final Tab tab) {
John Reck6e8d2e92011-03-14 11:29:56 -0700226 cancelTitleBarAnimation(true);
227 mSkipTitleBarAnimations = true;
Michael Kolb2786da52011-03-24 16:17:47 -0700228 stopEditingUrl();
Michael Kolbeb95db42011-03-03 10:38:40 -0800229 if (mUseQuickControls) {
230 if (mActiveTab != null) {
231 captureTab(mActiveTab);
232 }
233 }
Michael Kolbf2628922011-03-09 17:15:28 -0800234 super.setActiveTab(tab, true);
235 setActiveTab(tab, true);
John Reck6e8d2e92011-03-14 11:29:56 -0700236 mSkipTitleBarAnimations = false;
Michael Kolb377ea312011-02-17 14:36:56 -0800237 }
238
239 @Override
240 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb376b5412010-12-15 11:52:57 -0800241 ScrollWebView view = (ScrollWebView) tab.getWebView();
242 // TabControl.setCurrentTab has been called before this,
243 // so the tab is guaranteed to have a webview
244 if (view == null) {
245 Log.e(LOGTAG, "active tab with no webview detected");
246 return;
247 }
248 // Request focus on the top window.
249 if (mUseQuickControls) {
250 mPieControl.forceToTop(mContentView);
251 view.setScrollListener(null);
252 mTabBar.showTitleBarIndicator(false);
253 } else {
Michael Kolb377ea312011-02-17 14:36:56 -0800254 // check if title bar is already attached by animation
255 if (mTitleBar.getParent() == null) {
256 view.setEmbeddedTitleBar(mTitleBar);
257 }
Michael Kolb376b5412010-12-15 11:52:57 -0800258 view.setScrollListener(this);
259 }
Michael Kolb66706532010-12-12 19:50:22 -0800260 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800261 if (tab.isInVoiceSearchMode()) {
262 showVoiceTitleBar(tab.getVoiceDisplayTitle());
263 } else {
264 revertVoiceTitleBar(tab);
265 }
Michael Kolb376b5412010-12-15 11:52:57 -0800266 updateLockIconToLatest(tab);
267 tab.getTopWindow().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800268 }
269
Michael Kolbeb95db42011-03-03 10:38:40 -0800270 public void captureTab(final Tab tab) {
271 Bitmap sshot = Controller.createScreenshot(tab,
272 (int) mActivity.getResources()
273 .getDimension(R.dimen.qc_thumb_width),
274 (int) mActivity.getResources()
275 .getDimension(R.dimen.qc_thumb_height));
276 tab.setScreenshot(sshot);
277 }
278
Michael Kolb66706532010-12-12 19:50:22 -0800279 @Override
280 public void updateTabs(List<Tab> tabs) {
281 mTabBar.updateTabs(tabs);
Michael Kolb376b5412010-12-15 11:52:57 -0800282 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800283 }
284
285 @Override
286 public void removeTab(Tab tab) {
John Reck6e8d2e92011-03-14 11:29:56 -0700287 cancelTitleBarAnimation(true);
288 mSkipTitleBarAnimations = true;
Michael Kolb66706532010-12-12 19:50:22 -0800289 super.removeTab(tab);
290 mTabBar.onRemoveTab(tab);
John Reck6e8d2e92011-03-14 11:29:56 -0700291 mSkipTitleBarAnimations = false;
Michael Kolb8814d732011-01-26 11:22:30 -0800292 }
293
294 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800295 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800296 }
297
Michael Kolb376b5412010-12-15 11:52:57 -0800298 int getContentWidth() {
299 if (mContentView != null) {
300 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800301 }
302 return 0;
303 }
304
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800305 @Override
306 public void editUrl(boolean clearInput) {
Michael Kolbd72ea3b2011-01-09 15:56:37 -0800307 if (mUiController.isInCustomActionMode()) {
308 mUiController.endActionMode();
309 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800310 showTitleBar();
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800311 mTitleBar.startEditingUrl(clearInput);
Michael Kolb66706532010-12-12 19:50:22 -0800312 }
313
Michael Kolb7cdc4902011-02-03 17:54:40 -0800314 void showTitleBarAndEdit() {
315 mTitleBar.setShowProgressOnly(false);
316 showTitleBar();
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800317 mTitleBar.startEditingUrl(false);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800318 }
319
320 void stopEditingUrl() {
321 mTitleBar.stopEditingUrl();
322 }
323
324 @Override
325 protected void showTitleBar() {
326 if (canShowTitleBar()) {
327 if (mUseQuickControls) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800328 mContentView.addView(mTitleBar);
329 } else {
John Reck6e8d2e92011-03-14 11:29:56 -0700330 if (!mSkipTitleBarAnimations) {
331 cancelTitleBarAnimation(false);
332 int visibleHeight = getVisibleTitleHeight();
333 float startPos = (-mTitleBar.getEmbeddedHeight() + visibleHeight);
334 if (mTitleBar.getTranslationY() != 0) {
335 startPos = Math.max(startPos, mTitleBar.getTranslationY());
336 }
337 mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar,
338 "translationY",
339 startPos, 0);
340 mTitleBarAnimator.start();
John Recke5c21d92011-03-11 15:09:46 -0800341 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800342 setTitleGravity(Gravity.TOP);
343 }
344 super.showTitleBar();
345 mTabBar.onShowTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800346 }
Michael Kolb376b5412010-12-15 11:52:57 -0800347 }
348
Michael Kolb66706532010-12-12 19:50:22 -0800349 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800350 protected void hideTitleBar() {
351 if (isTitleBarShowing()) {
Michael Kolb66706532010-12-12 19:50:22 -0800352 mTabBar.onHideTitleBar();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800353 if (mUseQuickControls) {
354 mContentView.removeView(mTitleBar);
Michael Kolb2a56eca2011-02-25 09:45:06 -0800355 } else {
John Reck6e8d2e92011-03-14 11:29:56 -0700356 if (!mSkipTitleBarAnimations) {
357 cancelTitleBarAnimation(false);
358 int visibleHeight = getVisibleTitleHeight();
359 mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar,
360 "translationY", mTitleBar.getTranslationY(),
361 (-mTitleBar.getEmbeddedHeight() + visibleHeight));
362 mTitleBarAnimator.addListener(mHideTileBarAnimatorListener);
363 mTitleBarAnimator.start();
364 } else {
365 setTitleGravity(Gravity.NO_GRAVITY);
John Recke5c21d92011-03-11 15:09:46 -0800366 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800367 }
368 super.hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800369 }
370 }
371
John Reck6e8d2e92011-03-14 11:29:56 -0700372 private void cancelTitleBarAnimation(boolean reset) {
373 if (mTitleBarAnimator != null) {
374 mTitleBarAnimator.cancel();
375 mTitleBarAnimator = null;
376 }
377 if (reset) {
378 mTitleBar.setTranslationY(0);
379 }
380 }
381
John Recke5c21d92011-03-11 15:09:46 -0800382 private int getVisibleTitleHeight() {
383 WebView webview = mActiveTab != null ? mActiveTab.getWebView() : null;
384 return webview != null ? webview.getVisibleTitleHeight() : 0;
385 }
386
387 private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() {
388
389 boolean mWasCanceled;
390 @Override
391 public void onAnimationStart(Animator animation) {
392 mWasCanceled = false;
393 }
394
395 @Override
396 public void onAnimationRepeat(Animator animation) {
397 }
398
399 @Override
400 public void onAnimationEnd(Animator animation) {
401 if (!mWasCanceled) {
402 mTitleBar.setTranslationY(0);
John Recke5c21d92011-03-11 15:09:46 -0800403 }
John Reck6e8d2e92011-03-14 11:29:56 -0700404 setTitleGravity(Gravity.NO_GRAVITY);
John Recke5c21d92011-03-11 15:09:46 -0800405 }
406
407 @Override
408 public void onAnimationCancel(Animator animation) {
409 mWasCanceled = true;
410 }
411 };
412
Michael Kolb5ee018e2011-02-18 15:47:21 -0800413 public boolean isEditingUrl() {
414 return mTitleBar.isEditingUrl();
415 }
416
Michael Kolb66706532010-12-12 19:50:22 -0800417 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800418 protected TitleBarBase getTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800419 return mTitleBar;
420 }
421
Michael Kolb2a56eca2011-02-25 09:45:06 -0800422 @Override
423 protected void setTitleGravity(int gravity) {
424 if (mUseQuickControls) {
425 FrameLayout.LayoutParams lp =
426 (FrameLayout.LayoutParams) mTitleBar.getLayoutParams();
427 lp.gravity = gravity;
428 mTitleBar.setLayoutParams(lp);
429 } else {
430 super.setTitleGravity(gravity);
431 }
432 }
433
Michael Kolb66706532010-12-12 19:50:22 -0800434 // action mode callbacks
435
436 @Override
437 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800438 if (!mTitleBar.isEditingUrl()) {
Michael Kolb66706532010-12-12 19:50:22 -0800439 // hide the fake title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800440 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800441 }
442 }
443
444 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800445 public void onActionModeFinished(boolean inLoad) {
446 checkTabCount();
447 if (inLoad) {
448 // the titlebar was removed when the CAB was shown
449 // if the page is loading, show it again
Michael Kolb1544f3b2011-03-10 09:06:10 -0800450 if (mUseQuickControls) {
451 mTitleBar.setShowProgressOnly(true);
Michael Kolb376b5412010-12-15 11:52:57 -0800452 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800453 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800454 }
455 }
456
457 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800458 protected void updateNavigationState(Tab tab) {
459 mTitleBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800460 }
461
462 @Override
Patrick Scott92066772011-03-10 08:46:27 -0500463 protected void updateAutoLogin(Tab tab, boolean animate) {
464 mTitleBar.updateAutoLogin(tab, animate);
465 }
466
Michael Kolb2ba24b92011-03-17 10:59:10 -0700467 protected void refreshWebView() {
468 Tab tab = getActiveTab();
469 if ((tab != null) && (tab.getWebView() != null)) {
470 tab.getWebView().invalidate();
471 }
472 }
473
Patrick Scott92066772011-03-10 08:46:27 -0500474 @Override
John Reck30c714c2010-12-16 17:30:34 -0800475 public void setUrlTitle(Tab tab) {
476 super.setUrlTitle(tab);
477 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800478 }
479
480 // Set the favicon in the title bar.
481 @Override
John Reck30c714c2010-12-16 17:30:34 -0800482 public void setFavicon(Tab tab) {
483 super.setFavicon(tab);
484 mTabBar.onFavicon(tab, tab.getFavicon());
Michael Kolb66706532010-12-12 19:50:22 -0800485 }
486
Michael Kolbcfa3af52010-12-14 10:36:11 -0800487 @Override
488 public void showVoiceTitleBar(String title) {
489 List<String> vsresults = null;
490 if (getActiveTab() != null) {
491 vsresults = getActiveTab().getVoiceSearchResults();
492 }
Michael Kolb3a2a1642011-02-15 10:52:07 -0800493 mTitleBar.setInVoiceMode(true, vsresults);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800494 mTitleBar.setDisplayTitle(title);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800495 }
496
497 @Override
498 public void revertVoiceTitleBar(Tab tab) {
499 mTitleBar.setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800500 String url = tab.getUrl();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800501 mTitleBar.setDisplayTitle(url);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800502 }
503
John Reckd73c5a22010-12-22 10:22:50 -0800504 @Override
505 public void showCustomView(View view, CustomViewCallback callback) {
506 super.showCustomView(view, callback);
507 mActivity.getActionBar().hide();
508 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800509
John Reckd73c5a22010-12-22 10:22:50 -0800510 @Override
511 public void onHideCustomView() {
512 super.onHideCustomView();
513 if (mUseQuickControls) {
514 checkTabCount();
515 } else {
516 mActivity.getActionBar().show();
517 }
518 }
Michael Kolba4183062011-01-16 10:43:21 -0800519
520 @Override
521 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800522 if (mActiveTab != null) {
523 WebView web = mActiveTab.getWebView();
524 if (event.getAction() == KeyEvent.ACTION_DOWN) {
525 switch (code) {
526 case KeyEvent.KEYCODE_TAB:
527 case KeyEvent.KEYCODE_DPAD_UP:
528 case KeyEvent.KEYCODE_DPAD_LEFT:
529 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
530 editUrl(false);
531 return true;
532 }
533 }
534 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
535 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
536 editUrl(true);
537 return mContentView.dispatchKeyEvent(event);
538 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800539 }
Michael Kolba4183062011-01-16 10:43:21 -0800540 }
541 return false;
542 }
543
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800544 private boolean isTypingKey(KeyEvent evt) {
545 return evt.getUnicodeChar() > 0;
546 }
547
548 TabBar getTabBar() {
549 return mTabBar;
550 }
551
Narayan Kamath5119edd2011-02-23 15:49:17 +0000552 @Override
553 public void registerDropdownChangeListener(DropdownChangeListener d) {
554 mTitleBar.registerDropdownChangeListener(d);
555 }
Michael Kolb0860d992011-03-07 15:26:33 -0800556
Michael Kolb1acef692011-03-08 14:12:06 -0800557 @Override
558 public boolean onPrepareOptionsMenu(Menu menu) {
559 if (mUseQuickControls) {
560 mPieControl.onMenuOpened(menu);
561 return false;
562 } else {
563 return true;
564 }
565 }
566
Michael Kolb66706532010-12-12 19:50:22 -0800567}