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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 mPlaceholder = new View(getContext()); | 386 mPlaceholder = new View(getContext()); |
387 LayoutParams placeHolderParams = | 387 LayoutParams placeHolderParams = |
388 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_P ARENT); | 388 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_P ARENT); |
389 mPlaceholder.setBackgroundColor( | 389 mPlaceholder.setBackgroundColor( |
390 ApiCompatibilityUtils.getColor(getResources(), android.R.color.w hite)); | 390 ApiCompatibilityUtils.getColor(getResources(), android.R.color.w hite)); |
391 mBottomSheetContentContainer.addView(mPlaceholder, placeHolderParams); | 391 mBottomSheetContentContainer.addView(mPlaceholder, placeHolderParams); |
392 } | 392 } |
393 | 393 |
394 @Override | 394 @Override |
395 public int loadUrl(LoadUrlParams params) { | 395 public int loadUrl(LoadUrlParams params) { |
396 for (BottomSheetObserver o : mObservers) o.onLoadUrl(params.getUrl()); | |
Theresa
2017/02/17 18:54:48
Should this happen after the early return for nati
mdjones
2017/02/17 21:33:19
That depends on how we consider navigations inside
Theresa
2017/02/17 21:48:07
The early return is to handle bookmarks/downloads
mdjones
2017/02/17 21:52:11
That's the plan right now. There needs to be some
| |
397 | |
396 // Native page URLs in this context do not need to communicate with the tab. | 398 // Native page URLs in this context do not need to communicate with the tab. |
397 if (NativePageFactory.isNativePageUrl(params.getUrl(), isIncognito())) { | 399 if (NativePageFactory.isNativePageUrl(params.getUrl(), isIncognito())) { |
398 return TabLoadStatus.PAGE_LOAD_FAILED; | 400 return TabLoadStatus.PAGE_LOAD_FAILED; |
399 } | 401 } |
400 | 402 |
401 // In all non-native cases, minimize the sheet. | 403 // In all non-native cases, minimize the sheet. |
402 setSheetState(SHEET_STATE_PEEK, true); | 404 setSheetState(SHEET_STATE_PEEK, true); |
403 | 405 |
404 assert mTabModelSelector != null; | 406 assert mTabModelSelector != null; |
405 | 407 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 if (mControlContainer == null) return false; | 442 if (mControlContainer == null) return false; |
441 | 443 |
442 mControlContainer.getLocationInWindow(mLocationArray); | 444 mControlContainer.getLocationInWindow(mLocationArray); |
443 | 445 |
444 return e.getRawY() < mLocationArray[1] + mToolbarHeight; | 446 return e.getRawY() < mLocationArray[1] + mToolbarHeight; |
445 } | 447 } |
446 | 448 |
447 /** | 449 /** |
448 * A notification that the sheet is exiting the peek state into one that sho ws content. | 450 * A notification that the sheet is exiting the peek state into one that sho ws content. |
449 */ | 451 */ |
450 private void onExitPeekState() { | 452 private void onSheetOpened() { |
451 if (mSuggestionsContent == null) { | 453 if (mSuggestionsContent == null) { |
452 mSuggestionsContent = new SuggestionsBottomSheetContent( | 454 mSuggestionsContent = new SuggestionsBottomSheetContent( |
453 mTabModelSelector.getCurrentTab().getActivity(), this, mTabM odelSelector); | 455 mTabModelSelector.getCurrentTab().getActivity(), this, mTabM odelSelector); |
454 } | 456 } |
455 | 457 |
456 showContent(mSuggestionsContent); | 458 showContent(mSuggestionsContent); |
459 | |
460 for (BottomSheetObserver o : mObservers) o.onSheetOpened(); | |
457 } | 461 } |
458 | 462 |
459 /** | 463 /** |
464 * A notification that the sheet has returned to the peeking state. | |
465 */ | |
466 private void onSheetClosed() { | |
467 for (BottomSheetObserver o : mObservers) o.onSheetClosed(); | |
468 } | |
469 | |
470 /** | |
460 * Show content in the bottom sheet's content area. | 471 * Show content in the bottom sheet's content area. |
461 * @param content The {@link BottomSheetContent} to show. | 472 * @param content The {@link BottomSheetContent} to show. |
462 */ | 473 */ |
463 private void showContent(BottomSheetContent content) { | 474 private void showContent(BottomSheetContent content) { |
464 // If the desired content is already showing, do nothing. | 475 // If the desired content is already showing, do nothing. |
465 if (mSheetContent == content) return; | 476 if (mSheetContent == content) return; |
466 | 477 |
467 if (mSheetContent != null) { | 478 if (mSheetContent != null) { |
468 mBottomSheetContentContainer.removeView(mSheetContent.getScrollingCo ntentView()); | 479 mBottomSheetContentContainer.removeView(mSheetContent.getScrollingCo ntentView()); |
469 mSheetContent = null; | 480 mSheetContent = null; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 /** | 597 /** |
587 * Gets the sheet's offset from the bottom of the screen. | 598 * Gets the sheet's offset from the bottom of the screen. |
588 * @return The sheet's distance from the bottom of the screen. | 599 * @return The sheet's distance from the bottom of the screen. |
589 */ | 600 */ |
590 private float getSheetOffsetFromBottom() { | 601 private float getSheetOffsetFromBottom() { |
591 return mContainerHeight - getTranslationY(); | 602 return mContainerHeight - getTranslationY(); |
592 } | 603 } |
593 | 604 |
594 /** | 605 /** |
595 * Sets the sheet's offset relative to the bottom of the screen. | 606 * Sets the sheet's offset relative to the bottom of the screen. |
607 * THIS SHOULD NOT BE CALLED PUBLICLY OUTSIDE OF TESTS. | |
596 * @param offset The offset that the sheet should be. | 608 * @param offset The offset that the sheet should be. |
597 */ | 609 */ |
598 private void setSheetOffsetFromBottom(float offset) { | 610 @VisibleForTesting |
611 public void setSheetOffsetFromBottom(float offset) { | |
gone
2017/02/17 20:02:32
If you feel strongly enough to yell, maybe keep th
mdjones
2017/02/17 21:33:18
Good plan; done.
| |
599 if (MathUtils.areFloatsEqual(getSheetOffsetFromBottom(), getMinOffset()) | 612 if (MathUtils.areFloatsEqual(getSheetOffsetFromBottom(), getMinOffset()) |
600 && offset > getMinOffset()) { | 613 && offset > getMinOffset()) { |
601 onExitPeekState(); | 614 onSheetOpened(); |
615 } | |
616 | |
617 if (MathUtils.areFloatsEqual(offset, getMinOffset()) | |
618 && getSheetOffsetFromBottom() > getMinOffset()) { | |
Theresa
2017/02/17 18:54:48
Would this second line fail if the sheet were offs
mdjones
2017/02/17 21:33:19
Yes but the sheet's android view never moves below
| |
619 onSheetClosed(); | |
602 } | 620 } |
603 | 621 |
604 setTranslationY(mContainerHeight - offset); | 622 setTranslationY(mContainerHeight - offset); |
605 sendUpdatePeekToHalfEvent(); | 623 sendUpdatePeekToHalfEvent(); |
606 } | 624 } |
607 | 625 |
608 /** | 626 /** |
609 * @return The ratio of the height of the screen that the peeking state is. | 627 * @return The ratio of the height of the screen that the peeking state is. |
610 */ | 628 */ |
611 private float getPeekRatio() { | 629 @VisibleForTesting |
630 public float getPeekRatio() { | |
612 return mStateRatios[0]; | 631 return mStateRatios[0]; |
613 } | 632 } |
614 | 633 |
615 /** | 634 /** |
616 * @return The ratio of the height of the screen that the half expanded stat e is. | 635 * @return The ratio of the height of the screen that the half expanded stat e is. |
617 */ | 636 */ |
618 private float getHalfRatio() { | 637 @VisibleForTesting |
638 public float getHalfRatio() { | |
619 return mStateRatios[1]; | 639 return mStateRatios[1]; |
620 } | 640 } |
621 | 641 |
622 /** | 642 /** |
623 * @return The ratio of the height of the screen that the fully expanded sta te is. | 643 * @return The ratio of the height of the screen that the fully expanded sta te is. |
624 */ | 644 */ |
625 private float getFullRatio() { | 645 @VisibleForTesting |
646 public float getFullRatio() { | |
626 return mStateRatios[2]; | 647 return mStateRatios[2]; |
627 } | 648 } |
628 | 649 |
629 /** | 650 /** |
651 * @return The height of the container that the bottom sheet exists in. | |
652 */ | |
653 @VisibleForTesting | |
654 public float getSheetContainerHeight() { | |
655 return mContainerHeight; | |
656 } | |
657 | |
658 /** | |
630 * Sends a notification if the sheet is transitioning from the peeking to ha lf expanded state. | 659 * Sends a notification if the sheet is transitioning from the peeking to ha lf expanded state. |
631 * This method only sends events when the sheet is between the peeking and h alf states. | 660 * This method only sends events when the sheet is between the peeking and h alf states. |
632 */ | 661 */ |
633 private void sendUpdatePeekToHalfEvent() { | 662 private void sendUpdatePeekToHalfEvent() { |
634 float screenRatio = | 663 float screenRatio = |
635 mContainerHeight > 0 ? getSheetOffsetFromBottom() / mContainerHe ight : 0; | 664 mContainerHeight > 0 ? getSheetOffsetFromBottom() / mContainerHe ight : 0; |
636 | 665 |
637 // This ratio is relative to the peek and half positions of the sheet ra ther than the height | 666 // This ratio is relative to the peek and half positions of the sheet ra ther than the height |
638 // of the screen. | 667 // of the screen. |
639 float peekHalfRatio = MathUtils.clamp( | 668 float peekHalfRatio = MathUtils.clamp( |
640 (screenRatio - getPeekRatio()) / (getHalfRatio() - getPeekRatio( )), 0, 1); | 669 (screenRatio - getPeekRatio()) / (getHalfRatio() - getPeekRatio( )), 0, 1); |
641 | 670 |
642 // If the ratio is close enough to zero, just set it to zero. | 671 // If the ratio is close enough to zero, just set it to zero. |
643 if (MathUtils.areFloatsEqual(peekHalfRatio, 0f)) peekHalfRatio = 0f; | 672 if (MathUtils.areFloatsEqual(peekHalfRatio, 0f)) peekHalfRatio = 0f; |
644 | 673 |
645 for (BottomSheetObserver o : mObservers) { | 674 if (mLastPeekToHalfRatioSent < 1f || peekHalfRatio < 1f) { |
646 if (mLastPeekToHalfRatioSent < 1f || peekHalfRatio < 1f) { | 675 mLastPeekToHalfRatioSent = peekHalfRatio; |
647 mLastPeekToHalfRatioSent = peekHalfRatio; | 676 for (BottomSheetObserver o : mObservers) { |
648 o.onTransitionPeekToHalf(peekHalfRatio); | 677 o.onTransitionPeekToHalf(peekHalfRatio); |
649 } | 678 } |
650 } | 679 } |
651 } | 680 } |
652 | 681 |
653 /** | 682 /** |
654 * Moves the sheet to the provided state. | 683 * Moves the sheet to the provided state. |
655 * @param state The state to move the panel to. | 684 * @param state The state to move the panel to. |
656 * @param animate If true, the sheet will animate to the provided state, oth erwise it will | 685 * @param animate If true, the sheet will animate to the provided state, oth erwise it will |
657 * move there instantly. | 686 * move there instantly. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
748 } | 777 } |
749 | 778 |
750 @Override | 779 @Override |
751 public void onFadingViewClick() { | 780 public void onFadingViewClick() { |
752 setSheetState(SHEET_STATE_PEEK, true); | 781 setSheetState(SHEET_STATE_PEEK, true); |
753 } | 782 } |
754 | 783 |
755 @Override | 784 @Override |
756 public void onFadingViewHidden() {} | 785 public void onFadingViewHidden() {} |
757 } | 786 } |
OLD | NEW |