Chromium Code Reviews| Index: ios/chrome/browser/ui/toolbar/toolbar_tools_menu_button.mm |
| diff --git a/ios/chrome/browser/ui/toolbar/toolbar_tools_menu_button.mm b/ios/chrome/browser/ui/toolbar/toolbar_tools_menu_button.mm |
| index dff031ab80643357197193bb048d398b746cf5e2..c83c18990c173b4e7d761fc9faef0372a917d36e 100644 |
| --- a/ios/chrome/browser/ui/toolbar/toolbar_tools_menu_button.mm |
| +++ b/ios/chrome/browser/ui/toolbar/toolbar_tools_menu_button.mm |
| @@ -9,6 +9,10 @@ |
| #include "ios/chrome/browser/ui/toolbar/toolbar_button_tints.h" |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| namespace { |
| // The number of dots drawn. |
| const int kNumberOfDots = 3; |
| @@ -48,7 +52,7 @@ const CGFloat kLineWidthAtApogee = 3; |
| // Whether the reading list contains unseen items. |
| BOOL readingListContainsUnseenItems_; |
| // The CALayers containing the drawn dots. |
| - base::scoped_nsobject<CAShapeLayer> pathLayers_[kNumberOfDots]; |
| + NSMutableArray<CAShapeLayer*>* pathLayers_; |
| // Whether the CALayers are being animated. |
| BOOL animationOnGoing_; |
| } |
| @@ -76,6 +80,7 @@ const CGFloat kLineWidthAtApogee = 3; |
| style:(ToolbarControllerStyle)style { |
| if (self = [super initWithFrame:frame]) { |
| style_ = style; |
| + pathLayers_ = [[NSMutableArray alloc] initWithCapacity:kNumberOfDots]; |
| [self setTintColor:toolbar::NormalButtonTint(style_) |
| forState:UIControlStateNormal]; |
| @@ -112,29 +117,30 @@ const CGFloat kLineWidthAtApogee = 3; |
| } |
| - (void)initializeShapeLayers { |
| - for (int i = 0; i < kNumberOfDots; i++) { |
| - base::scoped_nsobject<CAShapeLayer>& pathLayer = pathLayers_[i]; |
| - if (pathLayer) { |
| - [pathLayer removeFromSuperlayer]; |
| + for (NSUInteger i = 0; i < pathLayers_.count; i++) { |
| + [pathLayers_[i] removeFromSuperlayer]; |
| } |
|
sdefresne
2017/05/03 12:34:16
Indentation appears to be incorrect here. I would
gambard
2017/05/03 14:21:31
Done.
|
| - const CGFloat x = kDotOffsetX; |
| - const CGFloat y = kDotOffsetY + kVerticalSpaceBetweenDots * i; |
| - |
| - UIBezierPath* path = [UIBezierPath bezierPath]; |
| - [path moveToPoint:CGPointMake(x - kMaxWidthOfSegment * 0.5, y)]; |
| - [path addLineToPoint:CGPointMake(x + kMaxWidthOfSegment * 0.5, y)]; |
| - |
| - pathLayer.reset([[CAShapeLayer layer] retain]); |
| - [pathLayer setFrame:self.bounds]; |
| - [pathLayer setPath:path.CGPath]; |
| - [pathLayer setStrokeColor:[self.tintColor CGColor]]; |
| - [pathLayer setFillColor:nil]; |
| - [pathLayer setLineWidth:kLineWidthAtRest]; |
| - [pathLayer setLineCap:kCALineCapRound]; |
| - [pathLayer setStrokeStart:kStrokeStartAtRest]; |
| - [pathLayer setStrokeEnd:kStrokeEndAtRest]; |
| - [self.layer addSublayer:pathLayer.get()]; |
| + pathLayers_ = [[NSMutableArray alloc] initWithCapacity:kNumberOfDots]; |
| + for (NSUInteger i = 0; i < kNumberOfDots; i++) { |
| + const CGFloat x = kDotOffsetX; |
| + const CGFloat y = kDotOffsetY + kVerticalSpaceBetweenDots * i; |
| + |
| + UIBezierPath* path = [UIBezierPath bezierPath]; |
| + [path moveToPoint:CGPointMake(x - kMaxWidthOfSegment * 0.5, y)]; |
| + [path addLineToPoint:CGPointMake(x + kMaxWidthOfSegment * 0.5, y)]; |
| + |
| + CAShapeLayer* pathLayer = [CAShapeLayer layer]; |
| + [pathLayer setFrame:self.bounds]; |
| + [pathLayer setPath:path.CGPath]; |
| + [pathLayer setStrokeColor:[self.tintColor CGColor]]; |
| + [pathLayer setFillColor:nil]; |
| + [pathLayer setLineWidth:kLineWidthAtRest]; |
| + [pathLayer setLineCap:kCALineCapRound]; |
| + [pathLayer setStrokeStart:kStrokeStartAtRest]; |
| + [pathLayer setStrokeEnd:kStrokeEndAtRest]; |
| + [self.layer addSublayer:pathLayer]; |
| + [pathLayers_ addObject:pathLayer]; |
| } |
| } |
| @@ -204,10 +210,10 @@ const CGFloat kLineWidthAtApogee = 3; |
| - (void)animateToColor:(UIColor*)targetColor { |
| animationOnGoing_ = YES; |
| + DCHECK(pathLayers_.count == kNumberOfDots); |
| // Add four animations for each stroke. |
| for (int i = 0; i < kNumberOfDots; i++) { |
| - base::scoped_nsobject<CAShapeLayer>& pathLayer = pathLayers_[i]; |
| - DCHECK(pathLayer.get()); |
| + CAShapeLayer* pathLayer = pathLayers_[i]; |
| const int frameStart = |
| (kNumberOfDots - i) * kFramesBetweenAnimationOfEachDot; |