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/logging.h" | 10 #include "base/logging.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // overscroll controller is in OverscrollStateActionReady. | 189 // overscroll controller is in OverscrollStateActionReady. |
190 @property(nonatomic, assign) CGPoint panPointScreenOrigin; | 190 @property(nonatomic, assign) CGPoint panPointScreenOrigin; |
191 // Pan gesture recognizer used to track horizontal touches. | 191 // Pan gesture recognizer used to track horizontal touches. |
192 @property(nonatomic, retain) UIPanGestureRecognizer* panGestureRecognizer; | 192 @property(nonatomic, retain) UIPanGestureRecognizer* panGestureRecognizer; |
193 | 193 |
194 // Registers notifications to lock the overscroll actions on certain UI states. | 194 // Registers notifications to lock the overscroll actions on certain UI states. |
195 - (void)registerNotifications; | 195 - (void)registerNotifications; |
196 // Setup/tearDown methods are used to register values when the delegate is set. | 196 // Setup/tearDown methods are used to register values when the delegate is set. |
197 - (void)tearDown; | 197 - (void)tearDown; |
198 - (void)setup; | 198 - (void)setup; |
| 199 // Resets scroll view's top content inset to |self.initialContentInset|. |
| 200 - (void)resetScrollViewTopContentInset; |
199 // Access the headerView from the delegate. | 201 // Access the headerView from the delegate. |
200 - (UIView<RelaxedBoundsConstraintsHitTestSupport>*)headerView; | 202 - (UIView<RelaxedBoundsConstraintsHitTestSupport>*)headerView; |
201 // Locking/unlocking methods used to disable/enable the overscroll actions | 203 // Locking/unlocking methods used to disable/enable the overscroll actions |
202 // with a reference count. | 204 // with a reference count. |
203 - (void)incrementOverscrollActionLockForNotification: | 205 - (void)incrementOverscrollActionLockForNotification: |
204 (NSNotification*)notification; | 206 (NSNotification*)notification; |
205 - (void)decrementOverscrollActionLockForNotification: | 207 - (void)decrementOverscrollActionLockForNotification: |
206 (NSNotification*)notification; | 208 (NSNotification*)notification; |
207 // Indicates whether the overscroll action is allowed. | 209 // Indicates whether the overscroll action is allowed. |
208 - (BOOL)isOverscrollActionEnabled; | 210 - (BOOL)isOverscrollActionEnabled; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 (isScrolledToTop && isMinimumTimeBetweenScrollRespected && | 376 (isScrolledToTop && isMinimumTimeBetweenScrollRespected && |
375 delegateAllowOverscrollActions && !isZooming); | 377 delegateAllowOverscrollActions && !isZooming); |
376 } | 378 } |
377 | 379 |
378 - (void)scrollViewDidEndDraggingWillDecelerate:(BOOL)decelerate | 380 - (void)scrollViewDidEndDraggingWillDecelerate:(BOOL)decelerate |
379 contentOffset:(CGPoint)contentOffset { | 381 contentOffset:(CGPoint)contentOffset { |
380 // Content is now hidden behind toolbar, make sure that contentInset is | 382 // Content is now hidden behind toolbar, make sure that contentInset is |
381 // restored to initial value. | 383 // restored to initial value. |
382 if (contentOffset.y >= 0 || | 384 if (contentOffset.y >= 0 || |
383 self.overscrollState == ios_internal::OverscrollState::NO_PULL_STARTED) { | 385 self.overscrollState == ios_internal::OverscrollState::NO_PULL_STARTED) { |
384 [self setScrollViewContentInset:UIEdgeInsetsMake(self.initialContentInset, | 386 [self resetScrollViewTopContentInset]; |
385 0, 0, 0)]; | |
386 } | 387 } |
387 | 388 |
388 [self triggerActionIfNeeded]; | 389 [self triggerActionIfNeeded]; |
389 _allowPullingActions = NO; | 390 _allowPullingActions = NO; |
390 } | 391 } |
391 | 392 |
392 - (void)scrollViewWillEndDraggingWithVelocity:(CGPoint)velocity | 393 - (void)scrollViewWillEndDraggingWithVelocity:(CGPoint)velocity |
393 targetContentOffset: | 394 targetContentOffset: |
394 (inout CGPoint*)targetContentOffset { | 395 (inout CGPoint*)targetContentOffset { |
395 if (![self isOverscrollActionEnabled]) | 396 if (![self isOverscrollActionEnabled]) |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 } | 584 } |
584 } | 585 } |
585 | 586 |
586 - (void)setScrollViewContentInset:(UIEdgeInsets)contentInset { | 587 - (void)setScrollViewContentInset:(UIEdgeInsets)contentInset { |
587 if (_scrollview) | 588 if (_scrollview) |
588 [_scrollview setContentInset:contentInset]; | 589 [_scrollview setContentInset:contentInset]; |
589 else | 590 else |
590 [_webViewScrollViewProxy setContentInset:contentInset]; | 591 [_webViewScrollViewProxy setContentInset:contentInset]; |
591 } | 592 } |
592 | 593 |
| 594 - (void)resetScrollViewTopContentInset { |
| 595 UIEdgeInsets contentInset = self.scrollView.contentInset; |
| 596 contentInset.top = self.initialContentInset; |
| 597 [self setScrollViewContentInset:contentInset]; |
| 598 } |
| 599 |
593 - (UIView<RelaxedBoundsConstraintsHitTestSupport>*)headerView { | 600 - (UIView<RelaxedBoundsConstraintsHitTestSupport>*)headerView { |
594 return [self.delegate headerView]; | 601 return [self.delegate headerView]; |
595 } | 602 } |
596 | 603 |
597 - (void)incrementOverscrollActionLockForNotification:(NSNotification*)notif { | 604 - (void)incrementOverscrollActionLockForNotification:(NSNotification*)notif { |
598 if (![_lockIncrementNotifications containsObject:notif.name]) { | 605 if (![_lockIncrementNotifications containsObject:notif.name]) { |
599 [_lockIncrementNotifications addObject:notif.name]; | 606 [_lockIncrementNotifications addObject:notif.name]; |
600 ++_overscrollActionLock; | 607 ++_overscrollActionLock; |
601 } | 608 } |
602 } | 609 } |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 _panGestureRecognizer.enabled = YES; | 879 _panGestureRecognizer.enabled = YES; |
873 [self scrollView].panGestureRecognizer.enabled = NO; | 880 [self scrollView].panGestureRecognizer.enabled = NO; |
874 [self scrollView].panGestureRecognizer.enabled = YES; | 881 [self scrollView].panGestureRecognizer.enabled = YES; |
875 [self startBounceWithInitialVelocity:CGPointZero]; | 882 [self startBounceWithInitialVelocity:CGPointZero]; |
876 [self.delegate | 883 [self.delegate |
877 overscrollActionsController:self | 884 overscrollActionsController:self |
878 didTriggerAction:self.overscrollActionView.selectedAction]; | 885 didTriggerAction:self.overscrollActionView.selectedAction]; |
879 } | 886 } |
880 | 887 |
881 @end | 888 @end |
OLD | NEW |