Chromium Code Reviews| 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 /** | |
| 151 * The last non-default toolbar view that was attached to mToolbarHolder. | |
|
mdjones
2017/03/14 20:08:36
nit: comment can be made single-line
Theresa
2017/03/14 20:40:02
Done.
| |
| 152 */ | |
| 153 private View mLastToolbarView; | |
| 154 | |
| 141 /** | 155 /** |
| 142 * An interface defining content that can be displayed inside of the bottom sheet for Chrome | 156 * An interface defining content that can be displayed inside of the bottom sheet for Chrome |
| 143 * Home. | 157 * Home. |
| 144 */ | 158 */ |
| 145 public interface BottomSheetContent { | 159 public interface BottomSheetContent { |
| 146 /** | 160 /** |
| 147 * Gets the {@link View} that holds the content to be displayed in the C hrome Home bottom | 161 * Gets the {@link View} that holds the content to be displayed in the C hrome Home bottom |
| 148 * sheet. | 162 * sheet. |
| 149 * @return The content view. | 163 * @return The content view. |
| 150 */ | 164 */ |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 setSheetState(mCurrentState, false); | 398 setSheetState(mCurrentState, false); |
| 385 } | 399 } |
| 386 }); | 400 }); |
| 387 | 401 |
| 388 mPlaceholder = new View(getContext()); | 402 mPlaceholder = new View(getContext()); |
| 389 LayoutParams placeHolderParams = | 403 LayoutParams placeHolderParams = |
| 390 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_P ARENT); | 404 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_P ARENT); |
| 391 mPlaceholder.setBackgroundColor( | 405 mPlaceholder.setBackgroundColor( |
| 392 ApiCompatibilityUtils.getColor(getResources(), android.R.color.w hite)); | 406 ApiCompatibilityUtils.getColor(getResources(), android.R.color.w hite)); |
| 393 mBottomSheetContentContainer.addView(mPlaceholder, placeHolderParams); | 407 mBottomSheetContentContainer.addView(mPlaceholder, placeHolderParams); |
| 408 | |
| 409 mToolbarHolder = (FrameLayout) mControlContainer.findViewById(R.id.toolb ar_holder); | |
| 394 } | 410 } |
| 395 | 411 |
| 396 @Override | 412 @Override |
| 397 public int loadUrl(LoadUrlParams params, boolean incognito) { | 413 public int loadUrl(LoadUrlParams params, boolean incognito) { |
| 398 for (BottomSheetObserver o : mObservers) o.onLoadUrl(params.getUrl()); | 414 for (BottomSheetObserver o : mObservers) o.onLoadUrl(params.getUrl()); |
| 399 | 415 |
| 400 // Native page URLs in this context do not need to communicate with the tab. | 416 // Native page URLs in this context do not need to communicate with the tab. |
| 401 if (NativePageFactory.isNativePageUrl(params.getUrl(), incognito)) { | 417 if (NativePageFactory.isNativePageUrl(params.getUrl(), incognito)) { |
| 402 return TabLoadStatus.PAGE_LOAD_FAILED; | 418 return TabLoadStatus.PAGE_LOAD_FAILED; |
| 403 } | 419 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 } | 485 } |
| 470 | 486 |
| 471 if (content == null) { | 487 if (content == null) { |
| 472 mBottomSheetContentContainer.addView(mPlaceholder); | 488 mBottomSheetContentContainer.addView(mPlaceholder); |
| 473 return; | 489 return; |
| 474 } | 490 } |
| 475 | 491 |
| 476 mBottomSheetContentContainer.removeView(mPlaceholder); | 492 mBottomSheetContentContainer.removeView(mPlaceholder); |
| 477 mSheetContent = content; | 493 mSheetContent = content; |
| 478 mBottomSheetContentContainer.addView(mSheetContent.getContentView()); | 494 mBottomSheetContentContainer.addView(mSheetContent.getContentView()); |
| 495 | |
| 496 // This class is initialized before the toolbar is inflated, so mDefault Toolbar is | |
| 497 // initialized here rather than in #init(). | |
| 498 if (mDefaultToolbarView == null) { | |
|
mdjones
2017/03/14 20:08:36
It looks like it should be possible to swap the in
Theresa
2017/03/14 20:40:02
Done.
| |
| 499 mDefaultToolbarView = mControlContainer.findViewById(R.id.toolbar); | |
| 500 } | |
| 501 | |
| 502 if (mLastToolbarView != null) { | |
| 503 mToolbarHolder.removeView(mLastToolbarView); | |
| 504 mLastToolbarView = null; | |
| 505 } | |
| 506 | |
| 507 if (mSheetContent.getToolbarView() != null) { | |
| 508 mLastToolbarView = mSheetContent.getToolbarView(); | |
| 509 mToolbarHolder.addView(mSheetContent.getToolbarView()); | |
| 510 mDefaultToolbarView.setVisibility(View.GONE); | |
| 511 } else { | |
| 512 mDefaultToolbarView.setVisibility(View.VISIBLE); | |
| 513 } | |
| 479 } | 514 } |
| 480 | 515 |
| 481 /** | 516 /** |
| 482 * Determines if a touch event is inside the toolbar. This assumes the toolb ar is the full | 517 * Determines if a touch event is inside the toolbar. This assumes the toolb ar is the full |
| 483 * width of the screen and that the toolbar is at the top of the bottom shee t. | 518 * width of the screen and that the toolbar is at the top of the bottom shee t. |
| 484 * @param e The motion event to test. | 519 * @param e The motion event to test. |
| 485 * @return True if the event occured in the toolbar region. | 520 * @return True if the event occured in the toolbar region. |
| 486 */ | 521 */ |
| 487 private boolean isTouchEventInToolbar(MotionEvent e) { | 522 private boolean isTouchEventInToolbar(MotionEvent e) { |
| 488 if (mControlContainer == null) return false; | 523 if (mControlContainer == null) return false; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 797 @Override | 832 @Override |
| 798 public void onFadingViewVisibilityChanged(boolean visible) {} | 833 public void onFadingViewVisibilityChanged(boolean visible) {} |
| 799 | 834 |
| 800 private boolean canMoveSheet() { | 835 private boolean canMoveSheet() { |
| 801 boolean isInOverviewMode = mTabModelSelector != null | 836 boolean isInOverviewMode = mTabModelSelector != null |
| 802 && (mTabModelSelector.getCurrentTab() == null | 837 && (mTabModelSelector.getCurrentTab() == null |
| 803 || mTabModelSelector.getCurrentTab().getActivity().is InOverviewMode()); | 838 || mTabModelSelector.getCurrentTab().getActivity().is InOverviewMode()); |
| 804 return !isToolbarAndroidViewHidden() && !isInOverviewMode; | 839 return !isToolbarAndroidViewHidden() && !isInOverviewMode; |
| 805 } | 840 } |
| 806 } | 841 } |
| OLD | NEW |