OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.widget; | 5 package org.chromium.chrome.browser.widget; |
6 | 6 |
7 import android.animation.Animator; | 7 import android.animation.Animator; |
8 import android.animation.AnimatorListenerAdapter; | 8 import android.animation.AnimatorListenerAdapter; |
9 import android.animation.ValueAnimator; | 9 import android.animation.ValueAnimator; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 131 |
132 /** A handle to the FrameLayout that holds the content of the bottom sheet.
*/ | 132 /** A handle to the FrameLayout that holds the content of the bottom sheet.
*/ |
133 private FrameLayout mBottomSheetContentContainer; | 133 private FrameLayout mBottomSheetContentContainer; |
134 | 134 |
135 /** | 135 /** |
136 * The last ratio sent to observers of onTransitionPeekToHalf(). This is use
d to ensure the | 136 * The last ratio sent to observers of onTransitionPeekToHalf(). This is use
d to ensure the |
137 * final value sent to these observers is 1.0f. | 137 * final value sent to these observers is 1.0f. |
138 */ | 138 */ |
139 private float mLastPeekToHalfRatioSent; | 139 private float mLastPeekToHalfRatioSent; |
140 | 140 |
| 141 /** The FrameLayout used to hold the bottom sheet toolbar. */ |
| 142 private FrameLayout mToolbarHolder; |
| 143 |
| 144 /** |
| 145 * The default toolbar view. This is shown when the current bottom sheet con
tent doesn't have |
| 146 * its own toolbar and when the bottom sheet is closed. |
| 147 */ |
| 148 private View mDefaultToolbarView; |
| 149 |
| 150 /** The last non-default toolbar view that was attached to mToolbarHolder. *
/ |
| 151 private View mLastToolbarView; |
| 152 |
141 /** | 153 /** |
142 * An interface defining content that can be displayed inside of the bottom
sheet for Chrome | 154 * An interface defining content that can be displayed inside of the bottom
sheet for Chrome |
143 * Home. | 155 * Home. |
144 */ | 156 */ |
145 public interface BottomSheetContent { | 157 public interface BottomSheetContent { |
146 /** | 158 /** |
147 * Gets the {@link View} that holds the content to be displayed in the C
hrome Home bottom | 159 * Gets the {@link View} that holds the content to be displayed in the C
hrome Home bottom |
148 * sheet. | 160 * sheet. |
149 * @return The content view. | 161 * @return The content view. |
150 */ | 162 */ |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 setSheetState(mCurrentState, false); | 398 setSheetState(mCurrentState, false); |
387 } | 399 } |
388 }); | 400 }); |
389 | 401 |
390 mPlaceholder = new View(getContext()); | 402 mPlaceholder = new View(getContext()); |
391 LayoutParams placeHolderParams = | 403 LayoutParams placeHolderParams = |
392 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_P
ARENT); | 404 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_P
ARENT); |
393 mPlaceholder.setBackgroundColor( | 405 mPlaceholder.setBackgroundColor( |
394 ApiCompatibilityUtils.getColor(getResources(), android.R.color.w
hite)); | 406 ApiCompatibilityUtils.getColor(getResources(), android.R.color.w
hite)); |
395 mBottomSheetContentContainer.addView(mPlaceholder, placeHolderParams); | 407 mBottomSheetContentContainer.addView(mPlaceholder, placeHolderParams); |
| 408 |
| 409 mToolbarHolder = (FrameLayout) mControlContainer.findViewById(R.id.toolb
ar_holder); |
| 410 mDefaultToolbarView = mControlContainer.findViewById(R.id.toolbar); |
396 } | 411 } |
397 | 412 |
398 @Override | 413 @Override |
399 public int loadUrl(LoadUrlParams params, boolean incognito) { | 414 public int loadUrl(LoadUrlParams params, boolean incognito) { |
400 for (BottomSheetObserver o : mObservers) o.onLoadUrl(params.getUrl()); | 415 for (BottomSheetObserver o : mObservers) o.onLoadUrl(params.getUrl()); |
401 | 416 |
402 // Native page URLs in this context do not need to communicate with the
tab. | 417 // Native page URLs in this context do not need to communicate with the
tab. |
403 if (NativePageFactory.isNativePageUrl(params.getUrl(), incognito)) { | 418 if (NativePageFactory.isNativePageUrl(params.getUrl(), incognito)) { |
404 return TabLoadStatus.PAGE_LOAD_FAILED; | 419 return TabLoadStatus.PAGE_LOAD_FAILED; |
405 } | 420 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 } | 486 } |
472 | 487 |
473 if (content == null) { | 488 if (content == null) { |
474 mBottomSheetContentContainer.addView(mPlaceholder); | 489 mBottomSheetContentContainer.addView(mPlaceholder); |
475 return; | 490 return; |
476 } | 491 } |
477 | 492 |
478 mBottomSheetContentContainer.removeView(mPlaceholder); | 493 mBottomSheetContentContainer.removeView(mPlaceholder); |
479 mSheetContent = content; | 494 mSheetContent = content; |
480 mBottomSheetContentContainer.addView(mSheetContent.getContentView()); | 495 mBottomSheetContentContainer.addView(mSheetContent.getContentView()); |
| 496 |
| 497 if (mLastToolbarView != null) { |
| 498 mToolbarHolder.removeView(mLastToolbarView); |
| 499 mLastToolbarView = null; |
| 500 } |
| 501 |
| 502 if (mSheetContent.getToolbarView() != null) { |
| 503 mLastToolbarView = mSheetContent.getToolbarView(); |
| 504 mToolbarHolder.addView(mSheetContent.getToolbarView()); |
| 505 mDefaultToolbarView.setVisibility(View.GONE); |
| 506 } else { |
| 507 mDefaultToolbarView.setVisibility(View.VISIBLE); |
| 508 } |
481 } | 509 } |
482 | 510 |
483 /** | 511 /** |
484 * Determines if a touch event is inside the toolbar. This assumes the toolb
ar is the full | 512 * Determines if a touch event is inside the toolbar. This assumes the toolb
ar is the full |
485 * width of the screen and that the toolbar is at the top of the bottom shee
t. | 513 * width of the screen and that the toolbar is at the top of the bottom shee
t. |
486 * @param e The motion event to test. | 514 * @param e The motion event to test. |
487 * @return True if the event occured in the toolbar region. | 515 * @return True if the event occured in the toolbar region. |
488 */ | 516 */ |
489 private boolean isTouchEventInToolbar(MotionEvent e) { | 517 private boolean isTouchEventInToolbar(MotionEvent e) { |
490 if (mControlContainer == null) return false; | 518 if (mControlContainer == null) return false; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 @Override | 827 @Override |
800 public void onFadingViewVisibilityChanged(boolean visible) {} | 828 public void onFadingViewVisibilityChanged(boolean visible) {} |
801 | 829 |
802 private boolean canMoveSheet() { | 830 private boolean canMoveSheet() { |
803 boolean isInOverviewMode = mTabModelSelector != null | 831 boolean isInOverviewMode = mTabModelSelector != null |
804 && (mTabModelSelector.getCurrentTab() == null | 832 && (mTabModelSelector.getCurrentTab() == null |
805 || mTabModelSelector.getCurrentTab().getActivity().is
InOverviewMode()); | 833 || mTabModelSelector.getCurrentTab().getActivity().is
InOverviewMode()); |
806 return !isToolbarAndroidViewHidden() && !isInOverviewMode; | 834 return !isToolbarAndroidViewHidden() && !isInOverviewMode; |
807 } | 835 } |
808 } | 836 } |
OLD | NEW |