OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bookmarks/bookmark_panel_view.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_panel_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/objc_property_releaser.h" | 8 |
9 #include "base/mac/scoped_nsobject.h" | |
10 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 9 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
11 #import "ios/chrome/browser/ui/rtl_geometry.h" | 10 #import "ios/chrome/browser/ui/rtl_geometry.h" |
12 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
13 // The position of the MenuViewWrapper doesn't change, but its subview menuView | 16 // The position of the MenuViewWrapper doesn't change, but its subview menuView |
14 // can slide horizontally. This UIView subclass decides whether to swallow | 17 // can slide horizontally. This UIView subclass decides whether to swallow |
15 // touches based on the transform of its subview, since its subview might lie | 18 // touches based on the transform of its subview, since its subview might lie |
16 // outsides the bounds of itself. | 19 // outsides the bounds of itself. |
17 @interface MenuViewWrapper : UIView { | 20 @interface MenuViewWrapper : UIView |
18 base::mac::ObjCPropertyReleaser _propertyReleaser_MenuViewWrapper; | 21 @property(nonatomic, strong) UIView* menuView; |
19 } | |
20 @property(nonatomic, retain) UIView* menuView; | |
21 @end | 22 @end |
22 | 23 |
23 @implementation MenuViewWrapper | 24 @implementation MenuViewWrapper |
24 @synthesize menuView = _menuView; | 25 @synthesize menuView = _menuView; |
25 | 26 |
26 - (id)initWithFrame:(CGRect)frame { | |
27 self = [super initWithFrame:frame]; | |
28 if (self) { | |
29 _propertyReleaser_MenuViewWrapper.Init(self, [MenuViewWrapper class]); | |
30 } | |
31 return self; | |
32 } | |
33 | |
34 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event { | 27 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event { |
35 return CGRectContainsPoint(self.menuView.frame, point); | 28 return CGRectContainsPoint(self.menuView.frame, point); |
36 } | 29 } |
37 | 30 |
38 @end | 31 @end |
39 | 32 |
40 @interface BookmarkPanelView ()<UIGestureRecognizerDelegate> { | 33 @interface BookmarkPanelView ()<UIGestureRecognizerDelegate> { |
41 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkPanelView; | |
42 } | 34 } |
43 // The content view always has the same size as this view. | 35 // The content view always has the same size as this view. |
44 // Redefined to be read-write. | 36 // Redefined to be read-write. |
45 @property(nonatomic, retain) UIView* contentView; | 37 @property(nonatomic, strong) UIView* contentView; |
46 // When the menu is showing, the cover partially obscures the content view. | 38 // When the menu is showing, the cover partially obscures the content view. |
47 @property(nonatomic, retain) UIView* contentViewCover; | 39 @property(nonatomic, strong) UIView* contentViewCover; |
48 // The menu view's frame never changes. Sliding it left and right is performed | 40 // The menu view's frame never changes. Sliding it left and right is performed |
49 // by changing its transform property. | 41 // by changing its transform property. |
50 // Redefined to be read-write. | 42 // Redefined to be read-write. |
51 @property(nonatomic, retain) UIView* menuView; | 43 @property(nonatomic, strong) UIView* menuView; |
52 // The menu view's layout is adjusted by changing its transform property. | 44 // The menu view's layout is adjusted by changing its transform property. |
53 // Changing the transform property results in a layoutSubviews call to the | 45 // Changing the transform property results in a layoutSubviews call to the |
54 // parentView. To prevent confusion to the origin of the layoutSubview call, the | 46 // parentView. To prevent confusion to the origin of the layoutSubview call, the |
55 // menu is placed inside a wrapper. The wrapper is always placed offscreen to | 47 // menu is placed inside a wrapper. The wrapper is always placed offscreen to |
56 // the left. It requires a UIView subclass to correctly decide whether touches | 48 // the left. It requires a UIView subclass to correctly decide whether touches |
57 // should make it to the menuView. | 49 // should make it to the menuView. |
58 @property(nonatomic, retain) MenuViewWrapper* menuViewWrapper; | 50 @property(nonatomic, strong) MenuViewWrapper* menuViewWrapper; |
59 @property(nonatomic, assign) CGFloat menuWidth; | 51 @property(nonatomic, assign) CGFloat menuWidth; |
60 @property(nonatomic, retain) UIPanGestureRecognizer* panRecognizer; | 52 @property(nonatomic, strong) UIPanGestureRecognizer* panRecognizer; |
61 | 53 |
62 // This property corresponds to whether startPoint is valid. It also reflects | 54 // This property corresponds to whether startPoint is valid. It also reflects |
63 // whether this class is responding to a user-driven animation. | 55 // whether this class is responding to a user-driven animation. |
64 @property(nonatomic, assign) BOOL hasStartPoint; | 56 @property(nonatomic, assign) BOOL hasStartPoint; |
65 @property(nonatomic, assign) CGPoint startPoint; | 57 @property(nonatomic, assign) CGPoint startPoint; |
66 // The most recent point of the user's pan gesture. | 58 // The most recent point of the user's pan gesture. |
67 @property(nonatomic, assign) CGPoint lastPoint; | 59 @property(nonatomic, assign) CGPoint lastPoint; |
68 | 60 |
69 // When an animation that tracks the user's gesture is in progress, this | 61 // When an animation that tracks the user's gesture is in progress, this |
70 // property reflects the state of the menu at the beginning of the animation. | 62 // property reflects the state of the menu at the beginning of the animation. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 108 } |
117 | 109 |
118 - (id)initWithFrame:(CGRect)frame { | 110 - (id)initWithFrame:(CGRect)frame { |
119 NOTREACHED(); | 111 NOTREACHED(); |
120 return nil; | 112 return nil; |
121 } | 113 } |
122 | 114 |
123 - (id)initWithFrame:(CGRect)frame menuViewWidth:(CGFloat)width { | 115 - (id)initWithFrame:(CGRect)frame menuViewWidth:(CGFloat)width { |
124 self = [super initWithFrame:frame]; | 116 self = [super initWithFrame:frame]; |
125 if (self) { | 117 if (self) { |
126 _propertyReleaser_BookmarkPanelView.Init(self, [BookmarkPanelView class]); | |
127 | |
128 DCHECK(width); | 118 DCHECK(width); |
129 _menuWidth = width; | 119 _menuWidth = width; |
130 | 120 |
131 self.contentView = base::scoped_nsobject<UIView>([[UIView alloc] init]); | 121 self.contentView = [[UIView alloc] init]; |
132 self.contentView.autoresizingMask = | 122 self.contentView.autoresizingMask = |
133 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | 123 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
134 [self addSubview:self.contentView]; | 124 [self addSubview:self.contentView]; |
135 | 125 |
136 self.contentViewCover = | 126 self.contentViewCover = [[UIView alloc] init]; |
137 base::scoped_nsobject<UIView>([[UIView alloc] init]); | |
138 [self addSubview:self.contentViewCover]; | 127 [self addSubview:self.contentViewCover]; |
139 self.contentViewCover.backgroundColor = | 128 self.contentViewCover.backgroundColor = |
140 [UIColor colorWithWhite:0 alpha:0.8]; | 129 [UIColor colorWithWhite:0 alpha:0.8]; |
141 self.contentViewCover.alpha = 0; | 130 self.contentViewCover.alpha = 0; |
142 | 131 |
143 base::scoped_nsobject<UITapGestureRecognizer> tapRecognizer( | 132 UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] |
144 [[UITapGestureRecognizer alloc] | 133 initWithTarget:self |
145 initWithTarget:self | 134 action:@selector(contentViewCoverTapped)]; |
146 action:@selector(contentViewCoverTapped)]); | |
147 [self.contentViewCover addGestureRecognizer:tapRecognizer]; | 135 [self.contentViewCover addGestureRecognizer:tapRecognizer]; |
148 self.contentViewCover.autoresizingMask = | 136 self.contentViewCover.autoresizingMask = |
149 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | 137 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
150 | 138 |
151 self.menuViewWrapper = | 139 self.menuViewWrapper = [[MenuViewWrapper alloc] init]; |
152 base::scoped_nsobject<MenuViewWrapper>([[MenuViewWrapper alloc] init]); | |
153 self.menuViewWrapper.backgroundColor = [UIColor clearColor]; | 140 self.menuViewWrapper.backgroundColor = [UIColor clearColor]; |
154 [self addSubview:self.menuViewWrapper]; | 141 [self addSubview:self.menuViewWrapper]; |
155 | 142 |
156 self.menuView = base::scoped_nsobject<UIView>([[UIView alloc] init]); | 143 self.menuView = [[UIView alloc] init]; |
157 [self.menuViewWrapper addSubview:self.menuView]; | 144 [self.menuViewWrapper addSubview:self.menuView]; |
158 self.menuViewWrapper.menuView = self.menuView; | 145 self.menuViewWrapper.menuView = self.menuView; |
159 | 146 |
160 self.panRecognizer = base::scoped_nsobject<UIPanGestureRecognizer>( | 147 self.panRecognizer = [[UIPanGestureRecognizer alloc] |
161 [[UIPanGestureRecognizer alloc] | 148 initWithTarget:self |
162 initWithTarget:self | 149 action:@selector(panRecognized:)]; |
163 action:@selector(panRecognized:)]); | |
164 [self addGestureRecognizer:self.panRecognizer]; | 150 [self addGestureRecognizer:self.panRecognizer]; |
165 | 151 |
166 [self updateLayout]; | 152 [self updateLayout]; |
167 } | 153 } |
168 return self; | 154 return self; |
169 } | 155 } |
170 | 156 |
171 #pragma mark Gesture recognizer | 157 #pragma mark Gesture recognizer |
172 | 158 |
173 - (void)panRecognized:(id)target { | 159 - (void)panRecognized:(id)target { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 375 |
390 - (void)updateMenuPositionWithPeekWidth:(CGFloat)peekWidth { | 376 - (void)updateMenuPositionWithPeekWidth:(CGFloat)peekWidth { |
391 DCHECK(peekWidth >= 0); | 377 DCHECK(peekWidth >= 0); |
392 DCHECK(peekWidth <= self.menuWidth); | 378 DCHECK(peekWidth <= self.menuWidth); |
393 | 379 |
394 self.menuView.transform = CGAffineTransformMakeTranslation( | 380 self.menuView.transform = CGAffineTransformMakeTranslation( |
395 UseRTLLayout() ? -peekWidth : peekWidth, 0); | 381 UseRTLLayout() ? -peekWidth : peekWidth, 0); |
396 } | 382 } |
397 | 383 |
398 @end | 384 @end |
OLD | NEW |