| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.
h" | 5 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.
h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include "base/ios/ios_util.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/mac/objc_property_releaser.h" | 12 #include "base/mac/objc_property_releaser.h" |
| 12 #include "base/mac/scoped_nsobject.h" | 13 #include "base/mac/scoped_nsobject.h" |
| 13 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 14 #import "ios/chrome/browser/ui/browser_view_controller.h" | 15 #import "ios/chrome/browser/ui/browser_view_controller.h" |
| 15 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.h" | 16 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.h" |
| 16 #include "ios/chrome/browser/ui/rtl_geometry.h" | 17 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 17 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" | 18 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" |
| 18 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" | 19 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" |
| 19 #import "ios/chrome/browser/ui/voice/voice_search_notification_names.h" | 20 #import "ios/chrome/browser/ui/voice/voice_search_notification_names.h" |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 // Not doing so would result in a graphic issue where the scrollview jumps | 645 // Not doing so would result in a graphic issue where the scrollview jumps |
| 645 // when scrolling after a change in UI orientation. | 646 // when scrolling after a change in UI orientation. |
| 646 [[self scrollView] panGestureRecognizer].enabled = NO; | 647 [[self scrollView] panGestureRecognizer].enabled = NO; |
| 647 [[self scrollView] panGestureRecognizer].enabled = YES; | 648 [[self scrollView] panGestureRecognizer].enabled = YES; |
| 648 | 649 |
| 649 [self setScrollViewContentInset:UIEdgeInsetsMake(self.initialContentInset, 0, | 650 [self setScrollViewContentInset:UIEdgeInsetsMake(self.initialContentInset, 0, |
| 650 0, 0)]; | 651 0, 0)]; |
| 651 [self clear]; | 652 [self clear]; |
| 652 } | 653 } |
| 653 | 654 |
| 655 // On iOS10 and above, trigger a haptic vibration for the user selecting an |
| 656 // action. This is a no-op for devices that do not support it. |
| 657 - (void)triggerHapticFeedbackForAction { |
| 658 if (base::ios::IsRunningOnIOS10OrLater()) { |
| 659 base::scoped_nsobject<UIImpactFeedbackGenerator> generator( |
| 660 [[UIImpactFeedbackGenerator alloc] init]); |
| 661 [generator impactOccurred]; |
| 662 } |
| 663 } |
| 664 |
| 665 // On iOS10 and above, trigger a haptic vibration for the change in selection. |
| 666 // This is a no-op for devices that do not support it. |
| 667 - (void)triggerHapticFeedbackForSelectionChange { |
| 668 if (base::ios::IsRunningOnIOS10OrLater()) { |
| 669 base::scoped_nsobject<UISelectionFeedbackGenerator> generator( |
| 670 [[UISelectionFeedbackGenerator alloc] init]); |
| 671 [generator selectionChanged]; |
| 672 } |
| 673 } |
| 674 |
| 654 - (BOOL)isOverscrollActionEnabled { | 675 - (BOOL)isOverscrollActionEnabled { |
| 655 return _overscrollActionLock == 0 && _allowPullingActions && | 676 return _overscrollActionLock == 0 && _allowPullingActions && |
| 656 !_isOverscrollActionsDisabledForLoading; | 677 !_isOverscrollActionsDisabledForLoading; |
| 657 } | 678 } |
| 658 | 679 |
| 659 - (void)triggerActionIfNeeded { | 680 - (void)triggerActionIfNeeded { |
| 660 if ([self isOverscrollActionEnabled]) { | 681 if ([self isOverscrollActionEnabled]) { |
| 661 const BOOL isOverscrollStateActionReady = | 682 const BOOL isOverscrollStateActionReady = |
| 662 self.overscrollState == OverscrollState::ACTION_READY; | 683 self.overscrollState == OverscrollState::ACTION_READY; |
| 663 const BOOL isOverscrollActionNone = | 684 const BOOL isOverscrollActionNone = |
| 664 self.overscrollActionView.selectedAction == OverscrollAction::NONE; | 685 self.overscrollActionView.selectedAction == OverscrollAction::NONE; |
| 665 | 686 |
| 666 if ((!isOverscrollStateActionReady && _didTransitionToActionReady) || | 687 if ((!isOverscrollStateActionReady && _didTransitionToActionReady) || |
| 667 (isOverscrollStateActionReady && isOverscrollActionNone)) { | 688 (isOverscrollStateActionReady && isOverscrollActionNone)) { |
| 668 [self recordMetricForTriggeredAction:OverscrollAction::NONE]; | 689 [self recordMetricForTriggeredAction:OverscrollAction::NONE]; |
| 669 } else if (isOverscrollStateActionReady && !isOverscrollActionNone) { | 690 } else if (isOverscrollStateActionReady && !isOverscrollActionNone) { |
| 670 if (CACurrentMediaTime() - _lastScrollBeginTime >= | 691 if (CACurrentMediaTime() - _lastScrollBeginTime >= |
| 671 kMinimumPullDurationToTriggerActionInSeconds) { | 692 kMinimumPullDurationToTriggerActionInSeconds) { |
| 672 _performingScrollViewIndependentAnimation = YES; | 693 _performingScrollViewIndependentAnimation = YES; |
| 673 [self setScrollViewContentInset:UIEdgeInsetsMake( | 694 [self setScrollViewContentInset:UIEdgeInsetsMake( |
| 674 self.initialContentInset, 0, 0, 0)]; | 695 self.initialContentInset, 0, 0, 0)]; |
| 675 CGPoint contentOffset = [[self scrollView] contentOffset]; | 696 CGPoint contentOffset = [[self scrollView] contentOffset]; |
| 676 contentOffset.y = -self.initialContentInset; | 697 contentOffset.y = -self.initialContentInset; |
| 677 [[self scrollView] setContentOffset:contentOffset animated:YES]; | 698 [[self scrollView] setContentOffset:contentOffset animated:YES]; |
| 678 [self.overscrollActionView displayActionAnimation]; | 699 [self.overscrollActionView displayActionAnimation]; |
| 679 dispatch_async(dispatch_get_main_queue(), ^{ | 700 dispatch_async(dispatch_get_main_queue(), ^{ |
| 680 [self recordMetricForTriggeredAction:self.overscrollActionView | 701 [self recordMetricForTriggeredAction:self.overscrollActionView |
| 681 .selectedAction]; | 702 .selectedAction]; |
| 703 [self triggerHapticFeedbackForAction]; |
| 682 [self.delegate overscrollActionsController:self | 704 [self.delegate overscrollActionsController:self |
| 683 didTriggerAction:self.overscrollActionView | 705 didTriggerAction:self.overscrollActionView |
| 684 .selectedAction]; | 706 .selectedAction]; |
| 685 }); | 707 }); |
| 686 } | 708 } |
| 687 } | 709 } |
| 688 } | 710 } |
| 689 } | 711 } |
| 690 | 712 |
| 691 - (void)setOverscrollState:(OverscrollState)overscrollState { | 713 - (void)setOverscrollState:(OverscrollState)overscrollState { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 [self | 909 [self |
| 888 recordMetricForTriggeredAction:self.overscrollActionView.selectedAction]; | 910 recordMetricForTriggeredAction:self.overscrollActionView.selectedAction]; |
| 889 | 911 |
| 890 // Reset all pan gesture recognizers. | 912 // Reset all pan gesture recognizers. |
| 891 _allowPullingActions = NO; | 913 _allowPullingActions = NO; |
| 892 _panGestureRecognizer.enabled = NO; | 914 _panGestureRecognizer.enabled = NO; |
| 893 _panGestureRecognizer.enabled = YES; | 915 _panGestureRecognizer.enabled = YES; |
| 894 [self scrollView].panGestureRecognizer.enabled = NO; | 916 [self scrollView].panGestureRecognizer.enabled = NO; |
| 895 [self scrollView].panGestureRecognizer.enabled = YES; | 917 [self scrollView].panGestureRecognizer.enabled = YES; |
| 896 [self startBounceWithInitialVelocity:CGPointZero]; | 918 [self startBounceWithInitialVelocity:CGPointZero]; |
| 919 |
| 920 [self triggerHapticFeedbackForAction]; |
| 897 [self.delegate | 921 [self.delegate |
| 898 overscrollActionsController:self | 922 overscrollActionsController:self |
| 899 didTriggerAction:self.overscrollActionView.selectedAction]; | 923 didTriggerAction:self.overscrollActionView.selectedAction]; |
| 900 } | 924 } |
| 901 | 925 |
| 926 - (void)overscrollActionsView:(OverscrollActionsView*)view |
| 927 selectedActionDidChange:(OverscrollAction)newAction { |
| 928 [self triggerHapticFeedbackForSelectionChange]; |
| 929 } |
| 930 |
| 902 @end | 931 @end |
| OLD | NEW |