| 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 #include "base/mac/objc_release_properties.h" |
| 9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 10 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 11 #import "ios/chrome/browser/ui/rtl_geometry.h" | 11 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 12 | 12 |
| 13 // The position of the MenuViewWrapper doesn't change, but its subview menuView | 13 // The position of the MenuViewWrapper doesn't change, but its subview menuView |
| 14 // can slide horizontally. This UIView subclass decides whether to swallow | 14 // can slide horizontally. This UIView subclass decides whether to swallow |
| 15 // touches based on the transform of its subview, since its subview might lie | 15 // touches based on the transform of its subview, since its subview might lie |
| 16 // outsides the bounds of itself. | 16 // outsides the bounds of itself. |
| 17 @interface MenuViewWrapper : UIView { | 17 @interface MenuViewWrapper : UIView |
| 18 base::mac::ObjCPropertyReleaser _propertyReleaser_MenuViewWrapper; | |
| 19 } | |
| 20 @property(nonatomic, retain) UIView* menuView; | 18 @property(nonatomic, retain) UIView* menuView; |
| 21 @end | 19 @end |
| 22 | 20 |
| 23 @implementation MenuViewWrapper | 21 @implementation MenuViewWrapper |
| 24 @synthesize menuView = _menuView; | 22 @synthesize menuView = _menuView; |
| 25 | 23 |
| 26 - (id)initWithFrame:(CGRect)frame { | 24 - (void)dealloc { |
| 27 self = [super initWithFrame:frame]; | 25 base::mac::ReleaseProperties(self); |
| 28 if (self) { | 26 [super dealloc]; |
| 29 _propertyReleaser_MenuViewWrapper.Init(self, [MenuViewWrapper class]); | |
| 30 } | |
| 31 return self; | |
| 32 } | 27 } |
| 33 | 28 |
| 34 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event { | 29 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event { |
| 35 return CGRectContainsPoint(self.menuView.frame, point); | 30 return CGRectContainsPoint(self.menuView.frame, point); |
| 36 } | 31 } |
| 37 | 32 |
| 38 @end | 33 @end |
| 39 | 34 |
| 40 @interface BookmarkPanelView ()<UIGestureRecognizerDelegate> { | 35 @interface BookmarkPanelView ()<UIGestureRecognizerDelegate> |
| 41 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkPanelView; | |
| 42 } | |
| 43 // The content view always has the same size as this view. | 36 // The content view always has the same size as this view. |
| 44 // Redefined to be read-write. | 37 // Redefined to be read-write. |
| 45 @property(nonatomic, retain) UIView* contentView; | 38 @property(nonatomic, retain) UIView* contentView; |
| 46 // When the menu is showing, the cover partially obscures the content view. | 39 // When the menu is showing, the cover partially obscures the content view. |
| 47 @property(nonatomic, retain) UIView* contentViewCover; | 40 @property(nonatomic, retain) UIView* contentViewCover; |
| 48 // The menu view's frame never changes. Sliding it left and right is performed | 41 // The menu view's frame never changes. Sliding it left and right is performed |
| 49 // by changing its transform property. | 42 // by changing its transform property. |
| 50 // Redefined to be read-write. | 43 // Redefined to be read-write. |
| 51 @property(nonatomic, retain) UIView* menuView; | 44 @property(nonatomic, retain) UIView* menuView; |
| 52 // The menu view's layout is adjusted by changing its transform property. | 45 // The menu view's layout is adjusted by changing its transform property. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 109 } |
| 117 | 110 |
| 118 - (id)initWithFrame:(CGRect)frame { | 111 - (id)initWithFrame:(CGRect)frame { |
| 119 NOTREACHED(); | 112 NOTREACHED(); |
| 120 return nil; | 113 return nil; |
| 121 } | 114 } |
| 122 | 115 |
| 123 - (id)initWithFrame:(CGRect)frame menuViewWidth:(CGFloat)width { | 116 - (id)initWithFrame:(CGRect)frame menuViewWidth:(CGFloat)width { |
| 124 self = [super initWithFrame:frame]; | 117 self = [super initWithFrame:frame]; |
| 125 if (self) { | 118 if (self) { |
| 126 _propertyReleaser_BookmarkPanelView.Init(self, [BookmarkPanelView class]); | |
| 127 | |
| 128 DCHECK(width); | 119 DCHECK(width); |
| 129 _menuWidth = width; | 120 _menuWidth = width; |
| 130 | 121 |
| 131 self.contentView = base::scoped_nsobject<UIView>([[UIView alloc] init]); | 122 self.contentView = base::scoped_nsobject<UIView>([[UIView alloc] init]); |
| 132 self.contentView.autoresizingMask = | 123 self.contentView.autoresizingMask = |
| 133 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | 124 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
| 134 [self addSubview:self.contentView]; | 125 [self addSubview:self.contentView]; |
| 135 | 126 |
| 136 self.contentViewCover = | 127 self.contentViewCover = |
| 137 base::scoped_nsobject<UIView>([[UIView alloc] init]); | 128 base::scoped_nsobject<UIView>([[UIView alloc] init]); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 161 [[UIPanGestureRecognizer alloc] | 152 [[UIPanGestureRecognizer alloc] |
| 162 initWithTarget:self | 153 initWithTarget:self |
| 163 action:@selector(panRecognized:)]); | 154 action:@selector(panRecognized:)]); |
| 164 [self addGestureRecognizer:self.panRecognizer]; | 155 [self addGestureRecognizer:self.panRecognizer]; |
| 165 | 156 |
| 166 [self updateLayout]; | 157 [self updateLayout]; |
| 167 } | 158 } |
| 168 return self; | 159 return self; |
| 169 } | 160 } |
| 170 | 161 |
| 162 - (void)dealloc { |
| 163 base::mac::ReleaseProperties(self); |
| 164 [super dealloc]; |
| 165 } |
| 166 |
| 171 #pragma mark Gesture recognizer | 167 #pragma mark Gesture recognizer |
| 172 | 168 |
| 173 - (void)panRecognized:(id)target { | 169 - (void)panRecognized:(id)target { |
| 174 switch (self.panRecognizer.state) { | 170 switch (self.panRecognizer.state) { |
| 175 case UIGestureRecognizerStatePossible: | 171 case UIGestureRecognizerStatePossible: |
| 176 case UIGestureRecognizerStateBegan: | 172 case UIGestureRecognizerStateBegan: |
| 177 [self updateLastPoint]; | 173 [self updateLastPoint]; |
| 178 break; | 174 break; |
| 179 | 175 |
| 180 case UIGestureRecognizerStateChanged: { | 176 case UIGestureRecognizerStateChanged: { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 385 |
| 390 - (void)updateMenuPositionWithPeekWidth:(CGFloat)peekWidth { | 386 - (void)updateMenuPositionWithPeekWidth:(CGFloat)peekWidth { |
| 391 DCHECK(peekWidth >= 0); | 387 DCHECK(peekWidth >= 0); |
| 392 DCHECK(peekWidth <= self.menuWidth); | 388 DCHECK(peekWidth <= self.menuWidth); |
| 393 | 389 |
| 394 self.menuView.transform = CGAffineTransformMakeTranslation( | 390 self.menuView.transform = CGAffineTransformMakeTranslation( |
| 395 UseRTLLayout() ? -peekWidth : peekWidth, 0); | 391 UseRTLLayout() ? -peekWidth : peekWidth, 0); |
| 396 } | 392 } |
| 397 | 393 |
| 398 @end | 394 @end |
| OLD | NEW |