Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.mm

Issue 2611673002: Moves overscroll code out of the ios_internal namespace. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_view.h" 5 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.h"
6 6
7 #import <QuartzCore/QuartzCore.h> 7 #import <QuartzCore/QuartzCore.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/objc_property_releaser.h" 10 #include "base/mac/objc_property_releaser.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // it. 131 // it.
132 base::scoped_nsobject<UITapGestureRecognizer> _tapGesture; 132 base::scoped_nsobject<UITapGestureRecognizer> _tapGesture;
133 // Array of layers that will be centered vertically. 133 // Array of layers that will be centered vertically.
134 // The array is built the first time the method -layersToCenterVertically is 134 // The array is built the first time the method -layersToCenterVertically is
135 // called. 135 // called.
136 base::scoped_nsobject<NSArray> _layersToCenterVertically; 136 base::scoped_nsobject<NSArray> _layersToCenterVertically;
137 base::mac::ObjCPropertyReleaser _propertyReleaser_OverscrollActionsView; 137 base::mac::ObjCPropertyReleaser _propertyReleaser_OverscrollActionsView;
138 } 138 }
139 139
140 // Redefined to readwrite. 140 // Redefined to readwrite.
141 @property(nonatomic, assign, readwrite) 141 @property(nonatomic, assign, readwrite) OverscrollAction selectedAction;
142 ios_internal::OverscrollAction selectedAction;
143 142
144 // Actions image views. 143 // Actions image views.
145 @property(nonatomic, retain) UIImageView* addTabActionImageView; 144 @property(nonatomic, retain) UIImageView* addTabActionImageView;
146 @property(nonatomic, retain) UIImageView* refreshActionImageView; 145 @property(nonatomic, retain) UIImageView* refreshActionImageView;
147 @property(nonatomic, retain) UIImageView* closeTabActionImageView; 146 @property(nonatomic, retain) UIImageView* closeTabActionImageView;
148 147
149 @property(nonatomic, retain) CALayer* highlightMaskLayer; 148 @property(nonatomic, retain) CALayer* highlightMaskLayer;
150 149
151 @property(nonatomic, retain) UIImageView* addTabActionImageViewHighlighted; 150 @property(nonatomic, retain) UIImageView* addTabActionImageViewHighlighted;
152 @property(nonatomic, retain) UIImageView* refreshActionImageViewHighlighted; 151 @property(nonatomic, retain) UIImageView* refreshActionImageViewHighlighted;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // Called when the state changes in order to perform state dependent animations. 200 // Called when the state changes in order to perform state dependent animations.
202 - (void)onStateChange; 201 - (void)onStateChange;
203 // Resets values related to selection state. 202 // Resets values related to selection state.
204 - (void)resetSelection; 203 - (void)resetSelection;
205 // Returns a newly allocated and configured selection circle shape. 204 // Returns a newly allocated and configured selection circle shape.
206 - (CAShapeLayer*)newSelectionCircleLayer; 205 - (CAShapeLayer*)newSelectionCircleLayer;
207 // Returns an autoreleased circular bezier path horizontally deformed according 206 // Returns an autoreleased circular bezier path horizontally deformed according
208 // to |dx|. 207 // to |dx|.
209 - (UIBezierPath*)circlePath:(CGFloat)dx; 208 - (UIBezierPath*)circlePath:(CGFloat)dx;
210 // Returns the action at the given location in the view. 209 // Returns the action at the given location in the view.
211 - (ios_internal::OverscrollAction)actionAtLocation:(CGPoint)location; 210 - (OverscrollAction)actionAtLocation:(CGPoint)location;
212 // Update the selection circle frame to select the given action. 211 // Update the selection circle frame to select the given action.
213 - (void)updateSelectionForTouchedAction:(ios_internal::OverscrollAction)action; 212 - (void)updateSelectionForTouchedAction:(OverscrollAction)action;
214 // Clear the direct touch interaction after a small delay to prevent graphic 213 // Clear the direct touch interaction after a small delay to prevent graphic
215 // glitch with pan gesture selection deformation animations. 214 // glitch with pan gesture selection deformation animations.
216 - (void)clearDirectTouchInteraction; 215 - (void)clearDirectTouchInteraction;
217 @end 216 @end
218 217
219 @implementation OverscrollActionsView 218 @implementation OverscrollActionsView
220 219
221 @synthesize selectedAction = _selectedAction; 220 @synthesize selectedAction = _selectedAction;
222 @synthesize addTabActionImageView = _addTabActionImageView; 221 @synthesize addTabActionImageView = _addTabActionImageView;
223 @synthesize refreshActionImageView = _refreshActionImageView; 222 @synthesize refreshActionImageView = _refreshActionImageView;
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 else 609 else
611 [CATransaction setAnimationDuration:kSelectionSnappingAnimationDuration]; 610 [CATransaction setAnimationDuration:kSelectionSnappingAnimationDuration];
612 self.selectionCircleLayer.position = [self selectionCirclePosition]; 611 self.selectionCircleLayer.position = [self selectionCirclePosition];
613 self.selectionCircleMaskLayer.position = self.selectionCircleLayer.position; 612 self.selectionCircleMaskLayer.position = self.selectionCircleLayer.position;
614 [CATransaction commit]; 613 [CATransaction commit];
615 } 614 }
616 } 615 }
617 616
618 - (void)updateSelectedAction { 617 - (void)updateSelectedAction {
619 if (self.overscrollState != OverscrollViewState::READY) { 618 if (self.overscrollState != OverscrollViewState::READY) {
620 self.selectedAction = ios_internal::OverscrollAction::NONE; 619 self.selectedAction = OverscrollAction::NONE;
621 return; 620 return;
622 } 621 }
623 622
624 // Update action index by checking that the action image layer is included 623 // Update action index by checking that the action image layer is included
625 // inside the selection layer. 624 // inside the selection layer.
626 const CGPoint selectionPosition = [self selectionCirclePosition]; 625 const CGPoint selectionPosition = [self selectionCirclePosition];
627 if (_deformationBehaviorEnabled) { 626 if (_deformationBehaviorEnabled) {
628 const CGFloat distanceBetweenTwoActions = 627 const CGFloat distanceBetweenTwoActions =
629 (self.refreshActionImageView.frame.origin.x - 628 (self.refreshActionImageView.frame.origin.x -
630 self.addTabActionImageView.frame.origin.x) / 629 self.addTabActionImageView.frame.origin.x) /
631 2; 630 2;
632 if (fabs(self.addTabActionImageView.center.x - selectionPosition.x) < 631 if (fabs(self.addTabActionImageView.center.x - selectionPosition.x) <
633 distanceBetweenTwoActions) { 632 distanceBetweenTwoActions) {
634 self.selectedAction = ios_internal::OverscrollAction::NEW_TAB; 633 self.selectedAction = OverscrollAction::NEW_TAB;
635 } 634 }
636 if (fabs(self.refreshActionImageView.center.x - selectionPosition.x) < 635 if (fabs(self.refreshActionImageView.center.x - selectionPosition.x) <
637 distanceBetweenTwoActions) { 636 distanceBetweenTwoActions) {
638 self.selectedAction = ios_internal::OverscrollAction::REFRESH; 637 self.selectedAction = OverscrollAction::REFRESH;
639 } 638 }
640 if (fabs(self.closeTabActionImageView.center.x - selectionPosition.x) < 639 if (fabs(self.closeTabActionImageView.center.x - selectionPosition.x) <
641 distanceBetweenTwoActions) { 640 distanceBetweenTwoActions) {
642 self.selectedAction = ios_internal::OverscrollAction::CLOSE_TAB; 641 self.selectedAction = OverscrollAction::CLOSE_TAB;
643 } 642 }
644 } else { 643 } else {
645 const CGRect selectionRect = 644 const CGRect selectionRect =
646 CGRectMake(selectionPosition.x - kSelectionEdge / 2.0, 645 CGRectMake(selectionPosition.x - kSelectionEdge / 2.0,
647 selectionPosition.y - kSelectionEdge / 2.0, kSelectionEdge, 646 selectionPosition.y - kSelectionEdge / 2.0, kSelectionEdge,
648 kSelectionEdge); 647 kSelectionEdge);
649 const CGRect addTabRect = self.addTabActionImageView.frame; 648 const CGRect addTabRect = self.addTabActionImageView.frame;
650 const CGRect closeTabRect = self.closeTabActionImageView.frame; 649 const CGRect closeTabRect = self.closeTabActionImageView.frame;
651 const CGRect refreshRect = self.refreshActionImageView.frame; 650 const CGRect refreshRect = self.refreshActionImageView.frame;
652 651
653 if (CGRectContainsRect(selectionRect, addTabRect)) { 652 if (CGRectContainsRect(selectionRect, addTabRect)) {
654 self.selectedAction = ios_internal::OverscrollAction::NEW_TAB; 653 self.selectedAction = OverscrollAction::NEW_TAB;
655 } else if (CGRectContainsRect(selectionRect, refreshRect)) { 654 } else if (CGRectContainsRect(selectionRect, refreshRect)) {
656 self.selectedAction = ios_internal::OverscrollAction::REFRESH; 655 self.selectedAction = OverscrollAction::REFRESH;
657 } else if (CGRectContainsRect(selectionRect, closeTabRect)) { 656 } else if (CGRectContainsRect(selectionRect, closeTabRect)) {
658 self.selectedAction = ios_internal::OverscrollAction::CLOSE_TAB; 657 self.selectedAction = OverscrollAction::CLOSE_TAB;
659 } else { 658 } else {
660 self.selectedAction = ios_internal::OverscrollAction::NONE; 659 self.selectedAction = OverscrollAction::NONE;
661 } 660 }
662 } 661 }
663 } 662 }
664 663
665 - (void)setSelectedAction:(ios_internal::OverscrollAction)action { 664 - (void)setSelectedAction:(OverscrollAction)action {
666 if (_selectedAction != action) { 665 if (_selectedAction != action) {
667 _selectedAction = action; 666 _selectedAction = action;
668 [self onSelectedActionChange]; 667 [self onSelectedActionChange];
669 } 668 }
670 } 669 }
671 670
672 - (void)onSelectedActionChange { 671 - (void)onSelectedActionChange {
673 if (self.overscrollState == OverscrollViewState::PREPARE || 672 if (self.overscrollState == OverscrollViewState::PREPARE ||
674 _animatingActionTrigger) 673 _animatingActionTrigger)
675 return; 674 return;
676 675
677 [UIView beginAnimations:@"transform" context:NULL]; 676 [UIView beginAnimations:@"transform" context:NULL];
678 [UIView setAnimationDuration:kSelectionSnappingAnimationDuration]; 677 [UIView setAnimationDuration:kSelectionSnappingAnimationDuration];
679 if (self.selectedAction == ios_internal::OverscrollAction::NONE) { 678 if (self.selectedAction == OverscrollAction::NONE) {
680 if (!_deformationBehaviorEnabled) { 679 if (!_deformationBehaviorEnabled) {
681 // Scale selection down. 680 // Scale selection down.
682 self.selectionCircleLayer.transform = 681 self.selectionCircleLayer.transform =
683 CATransform3DMakeScale(kSelectionDownScale, kSelectionDownScale, 1); 682 CATransform3DMakeScale(kSelectionDownScale, kSelectionDownScale, 1);
684 self.selectionCircleMaskLayer.transform = 683 self.selectionCircleMaskLayer.transform =
685 self.selectionCircleLayer.transform; 684 self.selectionCircleLayer.transform;
686 } 685 }
687 } else { 686 } else {
688 // Scale selection up. 687 // Scale selection up.
689 self.selectionCircleLayer.transform = CATransform3DMakeScale(1, 1, 1); 688 self.selectionCircleLayer.transform = CATransform3DMakeScale(1, 1, 1);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 [path moveToPoint:p]; 827 [path moveToPoint:p];
829 } else { 828 } else {
830 [path addLineToPoint:p]; 829 [path addLineToPoint:p];
831 } 830 }
832 } 831 }
833 832
834 [path closePath]; 833 [path closePath];
835 return path; 834 return path;
836 } 835 }
837 836
838 - (void)setStyle:(ios_internal::OverscrollStyle)style { 837 - (void)setStyle:(OverscrollStyle)style {
839 switch (style) { 838 switch (style) {
840 case ios_internal::OverscrollStyle::NTP_NON_INCOGNITO: 839 case OverscrollStyle::NTP_NON_INCOGNITO:
841 [self.shadowView setHidden:YES]; 840 [self.shadowView setHidden:YES];
842 self.backgroundColor = [UIColor whiteColor]; 841 self.backgroundColor = [UIColor whiteColor];
843 break; 842 break;
844 case ios_internal::OverscrollStyle::NTP_INCOGNITO: 843 case OverscrollStyle::NTP_INCOGNITO:
845 [self.shadowView setHidden:YES]; 844 [self.shadowView setHidden:YES];
846 self.backgroundColor = [UIColor colorWithWhite:0 alpha:0]; 845 self.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
847 break; 846 break;
848 case ios_internal::OverscrollStyle::REGULAR_PAGE_NON_INCOGNITO: 847 case OverscrollStyle::REGULAR_PAGE_NON_INCOGNITO:
849 [self.shadowView setHidden:NO]; 848 [self.shadowView setHidden:NO];
850 self.backgroundColor = [UIColor colorWithRed:242.0 / 256 849 self.backgroundColor = [UIColor colorWithRed:242.0 / 256
851 green:242.0 / 256 850 green:242.0 / 256
852 blue:242.0 / 256 851 blue:242.0 / 256
853 alpha:1.0]; 852 alpha:1.0];
854 break; 853 break;
855 case ios_internal::OverscrollStyle::REGULAR_PAGE_INCOGNITO: 854 case OverscrollStyle::REGULAR_PAGE_INCOGNITO:
856 [self.shadowView setHidden:NO]; 855 [self.shadowView setHidden:NO];
857 self.backgroundColor = [UIColor colorWithRed:80.0 / 256 856 self.backgroundColor = [UIColor colorWithRed:80.0 / 256
858 green:80.0 / 256 857 green:80.0 / 256
859 blue:80.0 / 256 858 blue:80.0 / 256
860 alpha:1.0]; 859 alpha:1.0];
861 break; 860 break;
862 } 861 }
863 862
864 BOOL incognito = 863 BOOL incognito = style == OverscrollStyle::NTP_INCOGNITO ||
865 style == ios_internal::OverscrollStyle::NTP_INCOGNITO || 864 style == OverscrollStyle::REGULAR_PAGE_INCOGNITO;
866 style == ios_internal::OverscrollStyle::REGULAR_PAGE_INCOGNITO;
867 if (incognito) { 865 if (incognito) {
868 [_addTabActionImageView 866 [_addTabActionImageView
869 setImage:[UIImage imageNamed:kNewTabActionActiveImage]]; 867 setImage:[UIImage imageNamed:kNewTabActionActiveImage]];
870 [_refreshActionImageView 868 [_refreshActionImageView
871 setImage:[UIImage imageNamed:kRefreshActionActiveImage]]; 869 setImage:[UIImage imageNamed:kRefreshActionActiveImage]];
872 [_closeTabActionImageView 870 [_closeTabActionImageView
873 setImage:[UIImage imageNamed:kCloseActionActiveImage]]; 871 setImage:[UIImage imageNamed:kCloseActionActiveImage]];
874 _selectionCircleLayer.fillColor = 872 _selectionCircleLayer.fillColor =
875 [[UIColor colorWithRed:1 green:1 blue:1 alpha:0.2] CGColor]; 873 [[UIColor colorWithRed:1 green:1 blue:1 alpha:0.2] CGColor];
876 _selectionCircleMaskLayer.fillColor = [[UIColor clearColor] CGColor]; 874 _selectionCircleMaskLayer.fillColor = [[UIColor clearColor] CGColor];
(...skipping 16 matching lines...) Expand all
893 _selectionCircleMaskLayer.fillColor = [[UIColor blackColor] CGColor]; 891 _selectionCircleMaskLayer.fillColor = [[UIColor blackColor] CGColor];
894 } 892 }
895 [_addTabActionImageView sizeToFit]; 893 [_addTabActionImageView sizeToFit];
896 [_refreshActionImageView sizeToFit]; 894 [_refreshActionImageView sizeToFit];
897 [_closeTabActionImageView sizeToFit]; 895 [_closeTabActionImageView sizeToFit];
898 [_addTabActionImageViewHighlighted sizeToFit]; 896 [_addTabActionImageViewHighlighted sizeToFit];
899 [_refreshActionImageViewHighlighted sizeToFit]; 897 [_refreshActionImageViewHighlighted sizeToFit];
900 [_closeTabActionImageViewHighlighted sizeToFit]; 898 [_closeTabActionImageViewHighlighted sizeToFit];
901 } 899 }
902 900
903 - (ios_internal::OverscrollAction)actionAtLocation:(CGPoint)location { 901 - (OverscrollAction)actionAtLocation:(CGPoint)location {
904 ios_internal::OverscrollAction action = ios_internal::OverscrollAction::NONE; 902 OverscrollAction action = OverscrollAction::NONE;
905 if (CGRectContainsPoint( 903 if (CGRectContainsPoint(
906 CGRectInset([_addTabActionImageView frame], 904 CGRectInset([_addTabActionImageView frame],
907 -kDirectTouchFrameExpansion, -kDirectTouchFrameExpansion), 905 -kDirectTouchFrameExpansion, -kDirectTouchFrameExpansion),
908 location)) { 906 location)) {
909 action = ios_internal::OverscrollAction::NEW_TAB; 907 action = OverscrollAction::NEW_TAB;
910 } else if (CGRectContainsPoint(CGRectInset([_refreshActionImageView frame], 908 } else if (CGRectContainsPoint(CGRectInset([_refreshActionImageView frame],
911 -kDirectTouchFrameExpansion, 909 -kDirectTouchFrameExpansion,
912 -kDirectTouchFrameExpansion), 910 -kDirectTouchFrameExpansion),
913 location)) { 911 location)) {
914 action = ios_internal::OverscrollAction::REFRESH; 912 action = OverscrollAction::REFRESH;
915 } else if (CGRectContainsPoint(CGRectInset([_closeTabActionImageView frame], 913 } else if (CGRectContainsPoint(CGRectInset([_closeTabActionImageView frame],
916 -kDirectTouchFrameExpansion, 914 -kDirectTouchFrameExpansion,
917 -kDirectTouchFrameExpansion), 915 -kDirectTouchFrameExpansion),
918 location)) { 916 location)) {
919 action = ios_internal::OverscrollAction::CLOSE_TAB; 917 action = OverscrollAction::CLOSE_TAB;
920 } 918 }
921 return action; 919 return action;
922 } 920 }
923 921
924 - (void)updateSelectionForTouchedAction:(ios_internal::OverscrollAction)action { 922 - (void)updateSelectionForTouchedAction:(OverscrollAction)action {
925 switch (action) { 923 switch (action) {
926 case ios_internal::OverscrollAction::NEW_TAB: 924 case OverscrollAction::NEW_TAB:
927 [self updateWithHorizontalOffset:-1]; 925 [self updateWithHorizontalOffset:-1];
928 break; 926 break;
929 case ios_internal::OverscrollAction::REFRESH: 927 case OverscrollAction::REFRESH:
930 [self updateWithHorizontalOffset:0]; 928 [self updateWithHorizontalOffset:0];
931 break; 929 break;
932 case ios_internal::OverscrollAction::CLOSE_TAB: 930 case OverscrollAction::CLOSE_TAB:
933 [self updateWithHorizontalOffset:1]; 931 [self updateWithHorizontalOffset:1];
934 break; 932 break;
935 case ios_internal::OverscrollAction::NONE: 933 case OverscrollAction::NONE:
936 return; 934 return;
937 break; 935 break;
938 } 936 }
939 } 937 }
940 938
941 // Clear the direct touch interaction after a small delay to prevent graphic 939 // Clear the direct touch interaction after a small delay to prevent graphic
942 // glitch with pan gesture selection deformation animations. 940 // glitch with pan gesture selection deformation animations.
943 - (void)clearDirectTouchInteraction { 941 - (void)clearDirectTouchInteraction {
944 if (!_viewTouched) 942 if (!_viewTouched)
945 return; 943 return;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer 979 - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
982 shouldRecognizeSimultaneouslyWithGestureRecognizer: 980 shouldRecognizeSimultaneouslyWithGestureRecognizer:
983 (UIGestureRecognizer*)otherGestureRecognizer { 981 (UIGestureRecognizer*)otherGestureRecognizer {
984 return YES; 982 return YES;
985 } 983 }
986 984
987 #pragma mark - Tap gesture action 985 #pragma mark - Tap gesture action
988 986
989 - (void)tapGesture:(UITapGestureRecognizer*)tapRecognizer { 987 - (void)tapGesture:(UITapGestureRecognizer*)tapRecognizer {
990 CGPoint tapLocation = [tapRecognizer locationInView:self]; 988 CGPoint tapLocation = [tapRecognizer locationInView:self];
991 ios_internal::OverscrollAction action = [self actionAtLocation:tapLocation]; 989 OverscrollAction action = [self actionAtLocation:tapLocation];
992 if (action != ios_internal::OverscrollAction::NONE) { 990 if (action != OverscrollAction::NONE) {
993 [self updateSelectionForTouchedAction:action]; 991 [self updateSelectionForTouchedAction:action];
994 [self setSelectedAction:action]; 992 [self setSelectedAction:action];
995 [self.delegate overscrollActionsViewDidTapTriggerAction:self]; 993 [self.delegate overscrollActionsViewDidTapTriggerAction:self];
996 } 994 }
997 } 995 }
998 996
999 @end 997 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698