Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/toolbar/ToolbarTablet.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.toolbar;
6
7 import android.annotation.SuppressLint;
8 import android.content.Context;
9 import android.content.res.ColorStateList;
10 import android.util.AttributeSet;
11 import android.view.View;
12 import android.view.View.OnClickListener;
13 import android.widget.ImageButton;
14
15 import com.google.android.apps.chrome.R;
16
17 import org.chromium.base.ApiCompatibilityUtils;
18 import org.chromium.base.CommandLine;
19 import org.chromium.base.metrics.RecordUserAction;
20 import org.chromium.chrome.browser.ChromeSwitches;
21 import org.chromium.chrome.browser.NavigationPopup;
22 import org.chromium.chrome.browser.Tab;
23 import org.chromium.chrome.browser.device.DeviceClassManager;
24 import org.chromium.chrome.browser.omnibox.LocationBar;
25 import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
26 import org.chromium.chrome.browser.widget.TintedImageButton;
27
28 /**
29 * The Toolbar object for Tablet screens.
30 */
31 @SuppressLint("Instantiatable")
32
33 public class ToolbarTablet extends ToolbarLayout implements OnClickListener {
34
35 private TintedImageButton mHomeButton;
36 private TintedImageButton mBackButton;
37 private TintedImageButton mForwardButton;
38 private TintedImageButton mReloadButton;
39 private TintedImageButton mBookmarkButton;
40 private ImageButton mAccessibilitySwitcherButton;
41
42 private OnClickListener mBookmarkListener;
43 private OnClickListener mTabSwitcherListener;
44
45 private boolean mInTabSwitcherwMode = false;
46
47 private boolean mShowTabStack;
48
49 private NavigationPopup mNavigationPopup;
50
51 private TabSwitcherDrawable mTabSwitcherButtonDrawable;
52 private TabSwitcherDrawable mTabSwitcherButtonDrawableLight;
53
54 private Boolean mUseLightColorAssets;
55 private LocationBar mLocationBar;
56
57 /**
58 * Constructs a ToolbarTablet object.
59 * @param context The Context in which this View object is created.
60 * @param attrs The AttributeSet that was specified with this View.
61 */
62 public ToolbarTablet(Context context, AttributeSet attrs) {
63 super(context, attrs);
64 }
65
66 @Override
67 public void onFinishInflate() {
68 super.onFinishInflate();
69 mLocationBar = (LocationBar) findViewById(R.id.location_bar);
70
71 mHomeButton = (TintedImageButton) findViewById(R.id.home_button);
72 mBackButton = (TintedImageButton) findViewById(R.id.back_button);
73 mForwardButton = (TintedImageButton) findViewById(R.id.forward_button);
74 mReloadButton = (TintedImageButton) findViewById(R.id.refresh_button);
75 mShowTabStack = DeviceClassManager.isAccessibilityModeEnabled(getContext ())
76 || CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_TAB LET_TAB_STACK);
77
78 mTabSwitcherButtonDrawable =
79 TabSwitcherDrawable.createTabSwitcherDrawable(getResources(), fa lse);
80 mTabSwitcherButtonDrawableLight =
81 TabSwitcherDrawable.createTabSwitcherDrawable(getResources(), tr ue);
82
83 mAccessibilitySwitcherButton = (ImageButton) findViewById(R.id.tab_switc her_button);
84 mAccessibilitySwitcherButton.setImageDrawable(mTabSwitcherButtonDrawable );
85 updateSwitcherButtonVisibility(mShowTabStack);
86
87 mBookmarkButton = (TintedImageButton) findViewById(R.id.bookmark_button) ;
88
89 mMenuButton = (TintedImageButton) findViewById(R.id.menu_button);
90 mMenuButton.setVisibility(
91 shouldShowMenuButton() ? View.VISIBLE : View.GONE);
92
93 if (mAccessibilitySwitcherButton.getVisibility() == View.GONE
94 && mMenuButton.getVisibility() == View.GONE) {
95 ApiCompatibilityUtils.setPaddingRelative((View) mMenuButton.getParen t(), 0, 0,
96 getResources().getDimensionPixelSize(R.dimen.tablet_toolbar_ end_padding), 0);
97 }
98 }
99
100 /**
101 * Sets up key listeners after native initialization is complete, so that we can invoke
102 * native functions.
103 */
104 @Override
105 public void onNativeLibraryReady() {
106 super.onNativeLibraryReady();
107 mLocationBar.onNativeLibraryReady();
108 mHomeButton.setOnClickListener(this);
109 mHomeButton.setOnKeyListener(new KeyboardNavigationListener() {
110 @Override
111 public View getNextFocusForward() {
112 if (mBackButton.isFocusable()) {
113 return findViewById(R.id.back_button);
114 } else if (mForwardButton.isFocusable()) {
115 return findViewById(R.id.forward_button);
116 } else {
117 return findViewById(R.id.refresh_button);
118 }
119 }
120
121 @Override
122 public View getNextFocusBackward() {
123 return findViewById(R.id.menu_button);
124 }
125 });
126
127 mBackButton.setOnClickListener(this);
128 mBackButton.setLongClickable(true);
129 mBackButton.setOnKeyListener(new KeyboardNavigationListener() {
130 @Override
131 public View getNextFocusForward() {
132 if (mForwardButton.isFocusable()) {
133 return findViewById(R.id.forward_button);
134 } else {
135 return findViewById(R.id.refresh_button);
136 }
137 }
138
139 @Override
140 public View getNextFocusBackward() {
141 if (mHomeButton.getVisibility() == VISIBLE) {
142 return findViewById(R.id.home_button);
143 } else {
144 return findViewById(R.id.menu_button);
145 }
146 }
147 });
148
149 mForwardButton.setOnClickListener(this);
150 mForwardButton.setLongClickable(true);
151 mForwardButton.setOnKeyListener(new KeyboardNavigationListener() {
152 @Override
153 public View getNextFocusForward() {
154 return findViewById(R.id.refresh_button);
155 }
156
157 @Override
158 public View getNextFocusBackward() {
159 if (mBackButton.isFocusable()) {
160 return mBackButton;
161 } else if (mHomeButton.getVisibility() == VISIBLE) {
162 return findViewById(R.id.home_button);
163 } else {
164 return findViewById(R.id.menu_button);
165 }
166 }
167 });
168
169 mReloadButton.setOnClickListener(this);
170 mReloadButton.setOnKeyListener(new KeyboardNavigationListener() {
171 @Override
172 public View getNextFocusForward() {
173 return findViewById(R.id.url_bar);
174 }
175
176 @Override
177 public View getNextFocusBackward() {
178 if (mForwardButton.isFocusable()) {
179 return mForwardButton;
180 } else if (mBackButton.isFocusable()) {
181 return mBackButton;
182 } else if (mHomeButton.getVisibility() == VISIBLE) {
183 return findViewById(R.id.home_button);
184 } else {
185 return findViewById(R.id.menu_button);
186 }
187 }
188 });
189
190 mAccessibilitySwitcherButton.setOnClickListener(this);
191 mBookmarkButton.setOnClickListener(this);
192 mMenuButton.setOnKeyListener(new KeyboardNavigationListener() {
193 @Override
194 public View getNextFocusForward() {
195 return getCurrentTabView();
196 }
197
198 @Override
199 public View getNextFocusBackward() {
200 return findViewById(R.id.url_bar);
201 }
202
203 @Override
204 protected boolean handleEnterKeyPress() {
205 return getMenuButtonHelper().onEnterKeyPress(mMenuButton);
206 }
207 });
208 if (HomepageManager.isHomepageEnabled(getContext())) {
209 mHomeButton.setVisibility(VISIBLE);
210 }
211 }
212
213 @Override
214 public boolean showContextMenuForChild(View originalView) {
215 if (mBackButton == originalView) {
216 // Display backwards navigation popup.
217 displayNavigationPopup(false, mBackButton);
218 return true;
219 } else if (mForwardButton == originalView) {
220 // Display forwards navigation popup.
221 displayNavigationPopup(true, mForwardButton);
222 return true;
223 }
224 return super.showContextMenuForChild(originalView);
225 }
226
227 @Override
228 public void onWindowFocusChanged(boolean hasWindowFocus) {
229 // Ensure the the popup is not shown after resuming activity from backgr ound.
230 if (hasWindowFocus && mNavigationPopup != null) {
231 mNavigationPopup.dismiss();
232 mNavigationPopup = null;
233 }
234 super.onWindowFocusChanged(hasWindowFocus);
235 }
236
237 private void displayNavigationPopup(boolean isForward, View anchorView) {
238 Tab tab = getToolbarDataProvider().getTab();
239 if (tab == null || tab.getWebContents() == null) return;
240 mNavigationPopup = new NavigationPopup(
241 getContext(), tab.getWebContents().getNavigationController(), is Forward);
242
243 mNavigationPopup.setAnchorView(anchorView);
244
245 int menuWidth = getResources().getDimensionPixelSize(R.dimen.menu_width) ;
246 mNavigationPopup.setWidth(menuWidth);
247
248 if (mNavigationPopup.shouldBeShown()) mNavigationPopup.show();
249 }
250
251 @Override
252 public void onClick(View v) {
253 if (mHomeButton == v) {
254 openHomepage();
255 } else if (mBackButton == v) {
256 if (!back()) return;
257 RecordUserAction.record("MobileToolbarBack");
258 RecordUserAction.record("MobileTabClobbered");
259 } else if (mForwardButton == v) {
260 forward();
261 RecordUserAction.record("MobileToolbarForward");
262 RecordUserAction.record("MobileTabClobbered");
263 } else if (mReloadButton == v) {
264 stopOrReloadCurrentTab();
265 } else if (mBookmarkButton == v) {
266 if (mBookmarkListener != null) {
267 mBookmarkListener.onClick(mBookmarkButton);
268 RecordUserAction.record("MobileToolbarToggleBookmark");
269 }
270 } else if (mAccessibilitySwitcherButton == v) {
271 if (mTabSwitcherListener != null) {
272 mTabSwitcherListener.onClick(mAccessibilitySwitcherButton);
273 }
274 }
275 }
276
277 private void updateSwitcherButtonVisibility(boolean enabled) {
278 mAccessibilitySwitcherButton.setVisibility(mShowTabStack || enabled
279 ? View.VISIBLE : View.GONE);
280 }
281
282 @Override
283 public boolean isReadyForTextureCapture() {
284 return !urlHasFocus();
285 }
286
287 @Override
288 public void onTabOrModelChanged() {
289 super.onTabOrModelChanged();
290 boolean incognito = isIncognito();
291 if (mUseLightColorAssets == null || mUseLightColorAssets != incognito) {
292 setBackgroundResource(incognito
293 ? R.color.incognito_primary_color : R.color.default_primary_ color);
294
295 ColorStateList dark = getResources().getColorStateList(R.color.dark_ mode_tint);
296 ColorStateList white = getResources().getColorStateList(R.color.ligh t_mode_tint);
297 mMenuButton.setTint(incognito ? white : dark);
298 mHomeButton.setTint(incognito ? white : dark);
299 mBackButton.setTint(incognito ? white : dark);
300 mForwardButton.setTint(incognito ? white : dark);
301 if (incognito) {
302 mLocationBar.getContainerView().getBackground().setAlpha(
303 ToolbarPhone.LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA);
304 } else {
305 mLocationBar.getContainerView().getBackground().setAlpha(255);
306 }
307 mAccessibilitySwitcherButton.setImageDrawable(
308 incognito ? mTabSwitcherButtonDrawableLight : mTabSwitcherBu ttonDrawable);
309 mLocationBar.updateVisualsForState();
310 mUseLightColorAssets = incognito;
311 }
312 mLocationBar.setUrlBarFocus(false);
313 }
314
315 @Override
316 protected void updateBackButtonVisibility(boolean canGoBack) {
317 boolean enableButton = canGoBack && !mInTabSwitcherwMode;
318 mBackButton.setEnabled(enableButton);
319 mBackButton.setFocusable(enableButton);
320 }
321
322 @Override
323 protected void updateForwardButtonVisibility(boolean canGoForward) {
324 boolean enableButton = canGoForward && !mInTabSwitcherwMode;
325 mForwardButton.setEnabled(enableButton);
326 mForwardButton.setFocusable(enableButton);
327 }
328
329 @Override
330 protected void updateReloadButtonVisibility(boolean isReloading) {
331 if (isReloading) {
332 mReloadButton.setImageResource(R.drawable.btn_close);
333 mReloadButton.setContentDescription(getContext().getString(
334 R.string.accessibility_btn_stop_loading));
335 } else {
336 mReloadButton.setImageResource(R.drawable.btn_toolbar_reload);
337 mReloadButton.setContentDescription(getContext().getString(
338 R.string.accessibility_btn_refresh));
339 }
340 ColorStateList dark = getResources().getColorStateList(R.color.dark_mode _tint);
341 ColorStateList white = getResources().getColorStateList(R.color.light_mo de_tint);
342 mReloadButton.setTint(isIncognito() ? white : dark);
343 mReloadButton.setEnabled(!mInTabSwitcherwMode);
344 }
345
346 @Override
347 protected void updateBookmarkButtonVisibility(boolean isBookmarked) {
348 int tintColor = isIncognito() ? R.color.light_mode_tint : R.color.dark_m ode_tint;
349 if (isBookmarked) {
350 mBookmarkButton.setImageResource(R.drawable.btn_star_filled);
351 // Non-incognito mode shows a blue filled star.
352 if (!isIncognito()) tintColor = R.color.blue_mode_tint;
353 } else {
354 mBookmarkButton.setImageResource(R.drawable.btn_star);
355 }
356 ColorStateList tint = getResources().getColorStateList(tintColor);
357 mBookmarkButton.setTint(tint);
358 }
359
360 @Override
361 protected void setTabSwitcherMode(
362 boolean inTabSwitcherMode, boolean showToolbar, boolean delayAnimati on) {
363 if (mShowTabStack && inTabSwitcherMode) {
364 mInTabSwitcherwMode = true;
365 mBackButton.setEnabled(false);
366 mForwardButton.setEnabled(false);
367 mReloadButton.setEnabled(false);
368 mLocationBar.getContainerView().setVisibility(View.INVISIBLE);
369 } else {
370 mInTabSwitcherwMode = false;
371 mLocationBar.getContainerView().setVisibility(View.VISIBLE);
372 }
373 }
374
375 @Override
376 protected void updateTabCountVisuals(int numberOfTabs) {
377 mAccessibilitySwitcherButton.setContentDescription(
378 getResources().getString(R.string.accessibility_toolbar_btn_tabs witcher_toggle,
379 numberOfTabs));
380 mTabSwitcherButtonDrawable.updateForTabCount(numberOfTabs, isIncognito() );
381 mTabSwitcherButtonDrawableLight.updateForTabCount(numberOfTabs, isIncogn ito());
382 }
383
384 @Override
385 public void onAccessibilityStatusChanged(boolean enabled) {
386 mShowTabStack = enabled || CommandLine.getInstance().hasSwitch(
387 ChromeSwitches.ENABLE_TABLET_TAB_STACK);
388 updateSwitcherButtonVisibility(enabled);
389 }
390
391 @Override
392 public void setBookmarkClickHandler(OnClickListener listener) {
393 mBookmarkListener = listener;
394 }
395
396 @Override
397 public void setOnTabSwitcherClickHandler(OnClickListener listener) {
398 mTabSwitcherListener = listener;
399 }
400
401 @Override
402 protected void onHomeButtonUpdate(boolean homeButtonEnabled) {
403 mHomeButton.setVisibility(homeButtonEnabled ? VISIBLE : GONE);
404 }
405
406 @Override
407 public LocationBar getLocationBar() {
408 return mLocationBar;
409 }
410
411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698