OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.toolbar; | 5 package org.chromium.chrome.browser.toolbar; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.ColorStateList; | |
8 import android.graphics.Canvas; | 9 import android.graphics.Canvas; |
9 import android.graphics.Rect; | 10 import android.graphics.Rect; |
10 import android.graphics.drawable.Drawable; | 11 import android.graphics.drawable.Drawable; |
11 import android.os.Build; | 12 import android.os.Build; |
13 import android.os.SystemClock; | |
12 import android.support.v7.widget.Toolbar; | 14 import android.support.v7.widget.Toolbar; |
13 import android.util.AttributeSet; | 15 import android.util.AttributeSet; |
14 import android.view.View; | 16 import android.view.View; |
15 import android.view.ViewGroup; | 17 import android.view.ViewGroup; |
16 import android.widget.ImageView; | 18 import android.widget.ImageView; |
17 | 19 |
18 import org.chromium.base.ApiCompatibilityUtils; | 20 import org.chromium.base.ApiCompatibilityUtils; |
19 import org.chromium.base.SysUtils; | 21 import org.chromium.base.SysUtils; |
20 import org.chromium.chrome.R; | 22 import org.chromium.chrome.R; |
21 import org.chromium.chrome.browser.util.ColorUtils; | 23 import org.chromium.chrome.browser.util.ColorUtils; |
24 import org.chromium.chrome.browser.util.FeatureUtilities; | |
25 import org.chromium.chrome.browser.widget.TintedImageButton; | |
22 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; | 26 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; |
23 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetMetrics; | 27 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetMetrics; |
24 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver; | 28 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver; |
25 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver; | 29 import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver; |
26 | 30 |
27 /** | 31 /** |
28 * Phone specific toolbar that exists at the bottom of the screen. | 32 * Phone specific toolbar that exists at the bottom of the screen. |
29 */ | 33 */ |
30 public class BottomToolbarPhone extends ToolbarPhone { | 34 public class BottomToolbarPhone extends ToolbarPhone { |
31 /** | 35 /** |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 | 85 |
82 /** The white version of the toolbar handle; used for dark themes and incogn ito. */ | 86 /** The white version of the toolbar handle; used for dark themes and incogn ito. */ |
83 private final Drawable mHandleLight; | 87 private final Drawable mHandleLight; |
84 | 88 |
85 /** The dark version of the toolbar handle; this is the default handle to us e. */ | 89 /** The dark version of the toolbar handle; this is the default handle to us e. */ |
86 private final Drawable mHandleDark; | 90 private final Drawable mHandleDark; |
87 | 91 |
88 /** A handle to the bottom sheet. */ | 92 /** A handle to the bottom sheet. */ |
89 private BottomSheet mBottomSheet; | 93 private BottomSheet mBottomSheet; |
90 | 94 |
95 /** A handle to the expand button that Chrome Home may or may not use. */ | |
96 private TintedImageButton mExpandButton; | |
97 | |
91 /** | 98 /** |
92 * Whether the end toolbar buttons should be hidden regardless of whether th e URL bar is | 99 * Whether the end toolbar buttons should be hidden regardless of whether th e URL bar is |
93 * focused. | 100 * focused. |
94 */ | 101 */ |
95 private boolean mShouldHideEndToolbarButtons; | 102 private boolean mShouldHideEndToolbarButtons; |
96 | 103 |
97 /** | 104 /** |
98 * This tracks the height fraction of the bottom bar to determine if it is m oving up or down. | 105 * This tracks the height fraction of the bottom bar to determine if it is m oving up or down. |
99 */ | 106 */ |
100 private float mLastHeightFraction; | 107 private float mLastHeightFraction; |
101 | 108 |
102 /** The toolbar handle view that indicates the toolbar can be pulled upward. */ | 109 /** The toolbar handle view that indicates the toolbar can be pulled upward. */ |
103 private ImageView mToolbarHandleView; | 110 private ImageView mToolbarHandleView; |
104 | 111 |
105 /** Whether accessibility is enabled. */ | 112 /** Whether accessibility is enabled. */ |
106 private boolean mAccessibilityEnabled; | 113 private boolean mAccessibilityEnabled; |
107 | 114 |
115 /** Whether or not the toolbar handle should be used. */ | |
116 private boolean mUseToolbarHandle; | |
117 | |
108 /** | 118 /** |
109 * Constructs a BottomToolbarPhone object. | 119 * Constructs a BottomToolbarPhone object. |
110 * @param context The Context in which this View object is created. | 120 * @param context The Context in which this View object is created. |
111 * @param attrs The AttributeSet that was specified with this View. | 121 * @param attrs The AttributeSet that was specified with this View. |
112 */ | 122 */ |
113 public BottomToolbarPhone(Context context, AttributeSet attrs) { | 123 public BottomToolbarPhone(Context context, AttributeSet attrs) { |
114 super(context, attrs); | 124 super(context, attrs); |
115 | 125 |
116 mHandleDark = ApiCompatibilityUtils.getDrawable( | 126 mHandleDark = ApiCompatibilityUtils.getDrawable( |
117 context.getResources(), R.drawable.toolbar_handle_dark); | 127 context.getResources(), R.drawable.toolbar_handle_dark); |
118 mHandleLight = ApiCompatibilityUtils.getDrawable( | 128 mHandleLight = ApiCompatibilityUtils.getDrawable( |
119 context.getResources(), R.drawable.toolbar_handle_light); | 129 context.getResources(), R.drawable.toolbar_handle_light); |
120 mLocationBarVerticalMargin = | 130 mLocationBarVerticalMargin = |
121 getResources().getDimensionPixelOffset(R.dimen.bottom_location_b ar_vertical_margin); | 131 getResources().getDimensionPixelOffset(R.dimen.bottom_location_b ar_vertical_margin); |
132 mUseToolbarHandle = true; | |
122 } | 133 } |
123 | 134 |
124 /** | 135 /** |
125 * Set the color of the pull handle used by the toolbar. | 136 * Set the color of the pull handle used by the toolbar. |
126 * @param useLightDrawable If the handle color should be light. | 137 * @param useLightDrawable If the handle color should be light. |
127 */ | 138 */ |
128 public void updateHandleTint(boolean useLightDrawable) { | 139 public void updateHandleTint(boolean useLightDrawable) { |
140 if (!mUseToolbarHandle) return; | |
129 mToolbarHandleView.setImageDrawable(useLightDrawable ? mHandleLight : mH andleDark); | 141 mToolbarHandleView.setImageDrawable(useLightDrawable ? mHandleLight : mH andleDark); |
130 } | 142 } |
131 | 143 |
132 /** | 144 /** |
133 * @return Whether or not the toolbar is currently using a light theme color . | 145 * @return Whether or not the toolbar is currently using a light theme color . |
134 */ | 146 */ |
135 public boolean isLightTheme() { | 147 public boolean isLightTheme() { |
136 return !ColorUtils.shouldUseLightForegroundOnBackground(getTabThemeColor ()); | 148 return !ColorUtils.shouldUseLightForegroundOnBackground(getTabThemeColor ()); |
137 } | 149 } |
138 | 150 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 ViewGroup coordinator = (ViewGroup) getRootView().findViewById(R.id.coor dinator); | 208 ViewGroup coordinator = (ViewGroup) getRootView().findViewById(R.id.coor dinator); |
197 coordinator.addView(mProgressBar); | 209 coordinator.addView(mProgressBar); |
198 mProgressBar.setProgressBarContainer(coordinator); | 210 mProgressBar.setProgressBarContainer(coordinator); |
199 } | 211 } |
200 | 212 |
201 /** | 213 /** |
202 * @return The extra top margin that should be applied to the browser contro ls views to | 214 * @return The extra top margin that should be applied to the browser contro ls views to |
203 * correctly offset them from the handle that sits above them. | 215 * correctly offset them from the handle that sits above them. |
204 */ | 216 */ |
205 private int getExtraTopMargin() { | 217 private int getExtraTopMargin() { |
218 if (!mUseToolbarHandle) return 0; | |
206 return getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_top_m argin); | 219 return getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_top_m argin); |
207 } | 220 } |
208 | 221 |
209 @Override | 222 @Override |
223 protected int getBoundsAfterAccountingForLeftButton() { | |
224 int padding = 0; | |
225 if (!mUseToolbarHandle && mExpandButton != null && mExpandButton.getVisi bility() != GONE) { | |
226 padding = mExpandButton.getMeasuredWidth(); | |
227 } | |
228 return padding + super.getBoundsAfterAccountingForLeftButton(); | |
229 } | |
230 | |
231 @Override | |
232 public void updateButtonVisibility() { | |
233 super.updateButtonVisibility(); | |
234 if (!mUseToolbarHandle && mExpandButton != null) { | |
235 mExpandButton.setVisibility( | |
236 urlHasFocus() || isTabSwitcherAnimationRunning() ? INVISIBLE : VISIBLE); | |
237 } | |
238 } | |
239 | |
240 @Override | |
241 protected void updateUrlExpansionAnimation() { | |
242 super.updateUrlExpansionAnimation(); | |
243 | |
244 if (!mUseToolbarHandle && mExpandButton != null) { | |
245 mExpandButton.setVisibility(mShouldHideEndToolbarButtons ? View.GONE : View.VISIBLE); | |
246 } | |
247 } | |
248 | |
249 @Override | |
210 public void onFinishInflate() { | 250 public void onFinishInflate() { |
211 super.onFinishInflate(); | 251 super.onFinishInflate(); |
212 | 252 |
213 // Add extra top margin to the URL bar to compensate for the change to l ocation bar's | 253 // Add extra top margin to the URL bar to compensate for the change to l ocation bar's |
214 // vertical margin in the constructor. | 254 // vertical margin in the constructor. |
215 ((MarginLayoutParams) mLocationBar.findViewById(R.id.url_bar).getLayoutP arams()).topMargin = | 255 ((MarginLayoutParams) mLocationBar.findViewById(R.id.url_bar).getLayoutP arams()).topMargin = |
216 getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_url_ bar_top_margin); | 256 getResources().getDimensionPixelSize(R.dimen.bottom_toolbar_url_ bar_top_margin); |
217 | 257 |
218 // Exclude the location bar from the list of browsing mode views. This p revents its | 258 // Exclude the location bar from the list of browsing mode views. This p revents its |
219 // visibility from changing during transitions. | 259 // visibility from changing during transitions. |
220 mBrowsingModeViews.remove(mLocationBar); | 260 mBrowsingModeViews.remove(mLocationBar); |
221 | 261 |
262 updateToolbarTopMargin(); | |
263 } | |
264 | |
265 /** | |
266 * Update the top margin of all the components inside the toolbar. If the to olbar handle is | |
267 * being used, extra margin is added. | |
268 */ | |
269 private void updateToolbarTopMargin() { | |
222 // Programmatically apply a top margin to all the children of the toolba r container. This | 270 // Programmatically apply a top margin to all the children of the toolba r container. This |
223 // is done so the view hierarchy does not need to be changed. | 271 // is done so the view hierarchy does not need to be changed. |
224 int topMarginForControls = getExtraTopMargin(); | 272 int topMarginForControls = getExtraTopMargin(); |
Theresa
2017/04/28 21:50:32
Should we return early if getExtraTopMargin() == 0
mdjones
2017/04/28 22:15:30
Yep, done.
mdjones
2017/05/01 20:46:08
Turns out we can't do this. Since the toolbar is i
| |
225 | 273 |
226 View topShadow = findViewById(R.id.bottom_toolbar_shadow); | 274 View topShadow = findViewById(R.id.bottom_toolbar_shadow); |
227 | 275 |
228 for (int i = 0; i < getChildCount(); i++) { | 276 for (int i = 0; i < getChildCount(); i++) { |
229 View curView = getChildAt(i); | 277 View curView = getChildAt(i); |
230 | 278 |
231 // Skip the shadow that sits at the top of the toolbar since this ne eds to sit on top | 279 // Skip the shadow that sits at the top of the toolbar since this ne eds to sit on top |
232 // of the toolbar. | 280 // of the toolbar. |
233 if (curView == topShadow) continue; | 281 if (curView == topShadow) continue; |
234 | 282 |
235 ((MarginLayoutParams) curView.getLayoutParams()).topMargin = topMarg inForControls; | 283 ((MarginLayoutParams) curView.getLayoutParams()).topMargin = topMarg inForControls; |
236 } | 284 } |
237 } | 285 } |
238 | 286 |
239 @Override | 287 @Override |
240 public void onAttachedToWindow() { | 288 public void onAttachedToWindow() { |
241 super.onAttachedToWindow(); | 289 super.onAttachedToWindow(); |
242 | 290 |
243 // The toolbar handle is part of the control container so it can draw on top of the other | 291 // The toolbar handle is part of the control container so it can draw on top of the |
244 // toolbar views. Get the root view and search for the handle. | 292 // other toolbar views. Get the root view and search for the handle. |
245 mToolbarHandleView = (ImageView) getRootView().findViewById(R.id.toolbar _handle); | 293 mToolbarHandleView = (ImageView) getRootView().findViewById(R.id.toolbar _handle); |
246 mToolbarHandleView.setImageDrawable(mHandleDark); | 294 mToolbarHandleView.setImageDrawable(mHandleDark); |
247 } | 295 } |
248 | 296 |
249 @Override | 297 @Override |
298 public void onNativeLibraryReady() { | |
299 super.onNativeLibraryReady(); | |
300 | |
301 mUseToolbarHandle = !FeatureUtilities.isChromeHomeExpandButtonEnabled(); | |
302 mExpandButton = (TintedImageButton) findViewById(R.id.expand_sheet_butto n); | |
303 mExpandButton.setOnClickListener(new OnClickListener() { | |
304 @Override | |
305 public void onClick(View v) { | |
306 if (mBottomSheet == null) return; | |
307 | |
308 mBottomSheet.setSheetState(BottomSheet.SHEET_STATE_HALF, true); | |
309 } | |
310 }); | |
311 | |
312 if (!mUseToolbarHandle) { | |
313 mToolbarHandleView.setVisibility(View.GONE); | |
314 | |
315 // If not using the toolbar handle, change the height of the control container to be | |
316 // the same as the top toolbar. | |
317 getRootView().findViewById(R.id.control_container).getLayoutParams() .height = | |
318 getResources().getDimensionPixelSize(R.dimen.control_contain er_height) | |
319 + getResources().getDimensionPixelSize(R.dimen.toolbar_shado w_height); | |
320 } else { | |
321 mExpandButton.setVisibility(View.VISIBLE); | |
322 mBrowsingModeViews.add(mExpandButton); | |
323 } | |
324 | |
325 updateToolbarTopMargin(); | |
326 } | |
327 | |
328 @Override | |
250 protected void updateVisualsForToolbarState() { | 329 protected void updateVisualsForToolbarState() { |
251 super.updateVisualsForToolbarState(); | 330 super.updateVisualsForToolbarState(); |
252 | 331 |
253 // TODO(mdjones): Creating a new tab from the tab switcher skips the | 332 // TODO(mdjones): Creating a new tab from the tab switcher skips the |
254 // drawTabSwitcherFadeAnimation which would otherwise make this line unn ecessary. | 333 // drawTabSwitcherFadeAnimation which would otherwise make this line unn ecessary. |
255 if (mTabSwitcherState == STATIC_TAB) mToolbarHandleView.setAlpha(1f); | 334 if (mTabSwitcherState == STATIC_TAB && mUseToolbarHandle) mToolbarHandle View.setAlpha(1f); |
256 | 335 |
257 // The tab switcher's background color should not affect the toolbar han dle; it should only | 336 // The tab switcher's background color should not affect the toolbar han dle; it should only |
258 // switch color based on the static tab's theme color. This is done so f ade in/out looks | 337 // switch color based on the static tab's theme color. This is done so f ade in/out looks |
259 // correct. | 338 // correct. |
260 mToolbarHandleView.setImageDrawable(isLightTheme() ? mHandleDark : mHand leLight); | 339 if (mUseToolbarHandle) { |
340 mToolbarHandleView.setImageDrawable(isLightTheme() ? mHandleDark : m HandleLight); | |
341 } else { | |
342 ColorStateList tint = mUseLightToolbarDrawables ? mLightModeTint : m DarkModeTint; | |
343 mExpandButton.setTint(tint); | |
344 } | |
261 } | 345 } |
262 | 346 |
263 @Override | 347 @Override |
264 protected void updateLocationBarBackgroundBounds(Rect out, VisualState visua lState) { | 348 protected void updateLocationBarBackgroundBounds(Rect out, VisualState visua lState) { |
265 super.updateLocationBarBackgroundBounds(out, visualState); | 349 super.updateLocationBarBackgroundBounds(out, visualState); |
266 | 350 |
267 // Allow the location bar to expand to the full height of the control co ntainer. | 351 // Allow the location bar to expand to the full height of the control co ntainer. |
268 out.top -= getExtraTopMargin() * mUrlExpansionPercent; | 352 out.top -= getExtraTopMargin() * mUrlExpansionPercent; |
269 } | 353 } |
270 | 354 |
271 @Override | 355 @Override |
272 protected boolean shouldDrawLocationBar() { | 356 protected boolean shouldDrawLocationBar() { |
273 return true; | 357 return true; |
274 } | 358 } |
275 | 359 |
276 @Override | 360 @Override |
277 protected void drawTabSwitcherFadeAnimation(boolean animationFinished, float progress) { | 361 protected void drawTabSwitcherFadeAnimation(boolean animationFinished, float progress) { |
278 mNewTabButton.setAlpha(progress); | 362 mNewTabButton.setAlpha(progress); |
279 | 363 |
280 mLocationBar.setAlpha(1f - progress); | 364 mLocationBar.setAlpha(1f - progress); |
281 mToolbarHandleView.setAlpha(1f - progress); | 365 if (mUseToolbarHandle) mToolbarHandleView.setAlpha(1f - progress); |
282 | 366 |
283 int tabSwitcherThemeColor = getToolbarColorForVisualState(VisualState.TA B_SWITCHER_NORMAL); | 367 int tabSwitcherThemeColor = getToolbarColorForVisualState(VisualState.TA B_SWITCHER_NORMAL); |
284 | 368 |
285 updateToolbarBackground(ColorUtils.getColorWithOverlay( | 369 updateToolbarBackground(ColorUtils.getColorWithOverlay( |
286 getTabThemeColor(), tabSwitcherThemeColor, progress)); | 370 getTabThemeColor(), tabSwitcherThemeColor, progress)); |
287 | 371 |
288 // Don't use transparency for accessibility mode or low-end devices sinc e the | 372 // Don't use transparency for accessibility mode or low-end devices sinc e the |
289 // {@link OverviewListLayout} will be used instead of the normal tab swi tcher. | 373 // {@link OverviewListLayout} will be used instead of the normal tab swi tcher. |
290 if (!mAccessibilityEnabled && !SysUtils.isLowEndDevice()) { | 374 if (!mAccessibilityEnabled && !SysUtils.isLowEndDevice()) { |
291 float alphaTransition = 1f - TAB_SWITCHER_TOOLBAR_ALPHA; | 375 float alphaTransition = 1f - TAB_SWITCHER_TOOLBAR_ALPHA; |
(...skipping 10 matching lines...) Expand all Loading... | |
302 @Override | 386 @Override |
303 protected void onAccessibilityStatusChanged(boolean enabled) { | 387 protected void onAccessibilityStatusChanged(boolean enabled) { |
304 super.onAccessibilityStatusChanged(enabled); | 388 super.onAccessibilityStatusChanged(enabled); |
305 mAccessibilityEnabled = enabled; | 389 mAccessibilityEnabled = enabled; |
306 } | 390 } |
307 | 391 |
308 @Override | 392 @Override |
309 protected void drawTabSwitcherAnimationOverlay(Canvas canvas, float animatio nProgress) { | 393 protected void drawTabSwitcherAnimationOverlay(Canvas canvas, float animatio nProgress) { |
310 // Intentionally overridden to block everything but the compositor scree n shot. Otherwise | 394 // Intentionally overridden to block everything but the compositor scree n shot. Otherwise |
311 // the toolbar in Chrome Home does not have an animation overlay compone nt. | 395 // the toolbar in Chrome Home does not have an animation overlay compone nt. |
312 if (mTextureCaptureMode) super.drawTabSwitcherAnimationOverlay(canvas, 0 f); | 396 if (mTextureCaptureMode) { |
397 super.drawTabSwitcherAnimationOverlay(canvas, 0f); | |
398 float previousAlpha = 0.f; | |
399 if (mExpandButton != null && mExpandButton.getVisibility() != View.G ONE) { | |
400 drawChild(canvas, mExpandButton, SystemClock.uptimeMillis()); | |
401 } | |
402 } | |
313 } | 403 } |
314 | 404 |
315 @Override | 405 @Override |
316 protected void resetNtpAnimationValues() { | 406 protected void resetNtpAnimationValues() { |
317 // The NTP animations don't matter if the browser is in tab switcher mod e. | 407 // The NTP animations don't matter if the browser is in tab switcher mod e. |
318 if (mTabSwitcherState != ToolbarPhone.STATIC_TAB) return; | 408 if (mTabSwitcherState != ToolbarPhone.STATIC_TAB) return; |
319 super.resetNtpAnimationValues(); | 409 super.resetNtpAnimationValues(); |
320 } | 410 } |
321 | 411 |
322 @Override | 412 @Override |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 otherToolbar.setTitleTextAppearance( | 447 otherToolbar.setTitleTextAppearance( |
358 otherToolbar.getContext(), R.style.BottomSheetContentTitle); | 448 otherToolbar.getContext(), R.style.BottomSheetContentTitle); |
359 ApiCompatibilityUtils.setPaddingRelative(otherToolbar, | 449 ApiCompatibilityUtils.setPaddingRelative(otherToolbar, |
360 ApiCompatibilityUtils.getPaddingStart(otherToolbar), | 450 ApiCompatibilityUtils.getPaddingStart(otherToolbar), |
361 otherToolbar.getPaddingTop() + extraTopMargin, | 451 otherToolbar.getPaddingTop() + extraTopMargin, |
362 ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar. getPaddingBottom()); | 452 ApiCompatibilityUtils.getPaddingEnd(otherToolbar), otherToolbar. getPaddingBottom()); |
363 | 453 |
364 otherToolbar.requestLayout(); | 454 otherToolbar.requestLayout(); |
365 } | 455 } |
366 } | 456 } |
OLD | NEW |