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/side_swipe/side_swipe_navigation_view.h" | 5 #import "ios/chrome/browser/ui/side_swipe/side_swipe_navigation_view.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/objc_property_releaser.h" | 10 |
11 #include "base/mac/scoped_nsobject.h" | |
12 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
13 #include "base/metrics/user_metrics_action.h" | 12 #include "base/metrics/user_metrics_action.h" |
14 #import "ios/chrome/browser/ui/side_swipe/side_swipe_util.h" | 13 #import "ios/chrome/browser/ui/side_swipe/side_swipe_util.h" |
15 #import "ios/chrome/browser/ui/side_swipe_gesture_recognizer.h" | 14 #import "ios/chrome/browser/ui/side_swipe_gesture_recognizer.h" |
16 #include "ios/chrome/browser/ui/ui_util.h" | 15 #include "ios/chrome/browser/ui/ui_util.h" |
17 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 16 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
18 #import "ios/chrome/common/material_timing.h" | 17 #import "ios/chrome/common/material_timing.h" |
19 | 18 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." |
| 21 #endif |
| 22 |
20 namespace { | 23 namespace { |
21 | 24 |
22 enum class SwipeType { CHANGE_TABS, NAVIGATION }; | 25 enum class SwipeType { CHANGE_TABS, NAVIGATION }; |
23 | 26 |
24 typedef struct { | 27 typedef struct { |
25 CGFloat min; | 28 CGFloat min; |
26 CGFloat max; | 29 CGFloat max; |
27 } FloatRange; | 30 } FloatRange; |
28 | 31 |
29 CGFloat MapValueToRange(FloatRange from, FloatRange to, CGFloat value) { | 32 CGFloat MapValueToRange(FloatRange from, FloatRange to, CGFloat value) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const CGFloat kSelectionAnimationDuration = 0.5; | 67 const CGFloat kSelectionAnimationDuration = 0.5; |
65 } | 68 } |
66 | 69 |
67 @interface SideSwipeNavigationView () { | 70 @interface SideSwipeNavigationView () { |
68 @private | 71 @private |
69 // Has the current swipe gone past the point where the action would trigger? | 72 // Has the current swipe gone past the point where the action would trigger? |
70 // Will be reset to NO if it recedes before that point (ie, not a latch). | 73 // Will be reset to NO if it recedes before that point (ie, not a latch). |
71 BOOL thresholdTriggered_; | 74 BOOL thresholdTriggered_; |
72 | 75 |
73 // The back or forward sprite image. | 76 // The back or forward sprite image. |
74 base::scoped_nsobject<UIImageView> arrowView_; | 77 UIImageView* arrowView_; |
75 | 78 |
76 // The selection bubble. | 79 // The selection bubble. |
77 CAShapeLayer* selectionCircleLayer_; | 80 CAShapeLayer* selectionCircleLayer_; |
78 | 81 |
79 // If |NO| this is an edge gesture and navigation isn't possible. Don't show | 82 // If |NO| this is an edge gesture and navigation isn't possible. Don't show |
80 // arrows and bubbles and don't allow navigate. | 83 // arrows and bubbles and don't allow navigate. |
81 BOOL canNavigate_; | 84 BOOL canNavigate_; |
82 | 85 |
83 // If |YES| arrowView_ is directionnal and must be rotated 180 degreed for the | 86 // If |YES| arrowView_ is directionnal and must be rotated 180 degreed for the |
84 // forward panes. | 87 // forward panes. |
85 BOOL rotateForward_; | 88 BOOL rotateForward_; |
86 | |
87 base::mac::ObjCPropertyReleaser _propertyReleaser_SideSwipeNavigationView; | |
88 } | 89 } |
89 // Returns a newly allocated and configured selection circle shape. | 90 // Returns a newly allocated and configured selection circle shape. |
90 - (CAShapeLayer*)newSelectionCircleLayer; | 91 - (CAShapeLayer*)newSelectionCircleLayer; |
91 // Pushes the touch towards the edge because it's difficult to touch the very | 92 // Pushes the touch towards the edge because it's difficult to touch the very |
92 // edge of the screen (touches tend to sit near x ~ 4). | 93 // edge of the screen (touches tend to sit near x ~ 4). |
93 - (CGPoint)adjustPointToEdge:(CGPoint)point; | 94 - (CGPoint)adjustPointToEdge:(CGPoint)point; |
94 @end | 95 @end |
95 | 96 |
96 @implementation SideSwipeNavigationView | 97 @implementation SideSwipeNavigationView |
97 | 98 |
98 @synthesize targetView = targetView_; | 99 @synthesize targetView = targetView_; |
99 | 100 |
100 - (instancetype)initWithFrame:(CGRect)frame | 101 - (instancetype)initWithFrame:(CGRect)frame |
101 withDirection:(UISwipeGestureRecognizerDirection)direction | 102 withDirection:(UISwipeGestureRecognizerDirection)direction |
102 canNavigate:(BOOL)canNavigate | 103 canNavigate:(BOOL)canNavigate |
103 image:(UIImage*)image | 104 image:(UIImage*)image |
104 rotateForward:(BOOL)rotateForward { | 105 rotateForward:(BOOL)rotateForward { |
105 self = [super initWithFrame:frame]; | 106 self = [super initWithFrame:frame]; |
106 if (self) { | 107 if (self) { |
107 _propertyReleaser_SideSwipeNavigationView.Init( | |
108 self, [SideSwipeNavigationView class]); | |
109 self.backgroundColor = [UIColor colorWithWhite:90.0 / 256 alpha:1.0]; | 108 self.backgroundColor = [UIColor colorWithWhite:90.0 / 256 alpha:1.0]; |
110 | 109 |
111 canNavigate_ = canNavigate; | 110 canNavigate_ = canNavigate; |
112 rotateForward_ = rotateForward; | 111 rotateForward_ = rotateForward; |
113 if (canNavigate) { | 112 if (canNavigate) { |
114 image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; | 113 image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
115 const CGRect imageSize = CGRectMake(0, 0, 24, 24); | 114 const CGRect imageSize = CGRectMake(0, 0, 24, 24); |
116 arrowView_.reset([[UIImageView alloc] initWithImage:image]); | 115 arrowView_ = [[UIImageView alloc] initWithImage:image]; |
117 [arrowView_ setTintColor:[UIColor whiteColor]]; | 116 [arrowView_ setTintColor:[UIColor whiteColor]]; |
118 selectionCircleLayer_ = [self newSelectionCircleLayer]; | 117 selectionCircleLayer_ = [self newSelectionCircleLayer]; |
119 [arrowView_ setFrame:imageSize]; | 118 [arrowView_ setFrame:imageSize]; |
120 } | 119 } |
121 | 120 |
122 UIImage* shadowImage = | 121 UIImage* shadowImage = |
123 [UIImage imageNamed:@"side_swipe_navigation_content_shadow"]; | 122 [UIImage imageNamed:@"side_swipe_navigation_content_shadow"]; |
124 CGRect borderFrame = | 123 CGRect borderFrame = |
125 CGRectMake(0, 0, shadowImage.size.width, self.frame.size.height); | 124 CGRectMake(0, 0, shadowImage.size.width, self.frame.size.height); |
126 base::scoped_nsobject<UIImageView> border( | 125 UIImageView* border = [[UIImageView alloc] initWithFrame:borderFrame]; |
127 [[UIImageView alloc] initWithFrame:borderFrame]); | |
128 [border setImage:shadowImage]; | 126 [border setImage:shadowImage]; |
129 [self addSubview:border]; | 127 [self addSubview:border]; |
130 if (direction == UISwipeGestureRecognizerDirectionRight) { | 128 if (direction == UISwipeGestureRecognizerDirectionRight) { |
131 borderFrame.origin.x = frame.size.width - shadowImage.size.width; | 129 borderFrame.origin.x = frame.size.width - shadowImage.size.width; |
132 [border setFrame:borderFrame]; | 130 [border setFrame:borderFrame]; |
133 [border setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; | 131 [border setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; |
134 } else { | 132 } else { |
135 [border setTransform:CGAffineTransformMakeRotation(M_PI)]; | 133 [border setTransform:CGAffineTransformMakeRotation(M_PI)]; |
136 [border setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin]; | 134 [border setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin]; |
137 } | 135 } |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 selectionCircleLayer.opacity = 0; | 426 selectionCircleLayer.opacity = 0; |
429 selectionCircleLayer.transform = | 427 selectionCircleLayer.transform = |
430 CATransform3DMakeScale(kSelectionDownScale, kSelectionDownScale, 1); | 428 CATransform3DMakeScale(kSelectionDownScale, kSelectionDownScale, 1); |
431 selectionCircleLayer.path = | 429 selectionCircleLayer.path = |
432 [[UIBezierPath bezierPathWithOvalInRect:bounds] CGPath]; | 430 [[UIBezierPath bezierPathWithOvalInRect:bounds] CGPath]; |
433 | 431 |
434 return selectionCircleLayer; | 432 return selectionCircleLayer; |
435 } | 433 } |
436 | 434 |
437 @end | 435 @end |
OLD | NEW |