Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/history_overlay_controller.h" | 5 #import "chrome/browser/ui/cocoa/history_overlay_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/scoped_cftyperef.h" | |
| 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 9 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 9 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/image/image.h" | 12 #include "ui/gfx/image/image.h" |
| 12 | 13 |
| 13 #import <QuartzCore/QuartzCore.h> | 14 #import <QuartzCore/QuartzCore.h> |
| 14 | 15 |
| 15 #include <cmath> | 16 #include <cmath> |
| 16 | 17 |
| 17 // Constants /////////////////////////////////////////////////////////////////// | 18 // Constants /////////////////////////////////////////////////////////////////// |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 29 // considered complete. | 30 // considered complete. |
| 30 const CGFloat kShieldHeightCompletionAdjust = 10; | 31 const CGFloat kShieldHeightCompletionAdjust = 10; |
| 31 | 32 |
| 32 // HistoryOverlayView ////////////////////////////////////////////////////////// | 33 // HistoryOverlayView ////////////////////////////////////////////////////////// |
| 33 | 34 |
| 34 // The content view that draws the semicircle and the arrow. | 35 // The content view that draws the semicircle and the arrow. |
| 35 @interface HistoryOverlayView : NSView { | 36 @interface HistoryOverlayView : NSView { |
| 36 @private | 37 @private |
| 37 HistoryOverlayMode mode_; | 38 HistoryOverlayMode mode_; |
| 38 CGFloat shieldAlpha_; | 39 CGFloat shieldAlpha_; |
| 40 base::scoped_nsobject<CAShapeLayer> shapeLayer_; | |
| 39 } | 41 } |
| 40 @property(nonatomic) CGFloat shieldAlpha; | 42 @property(nonatomic) CGFloat shieldAlpha; |
| 41 - (id)initWithMode:(HistoryOverlayMode)mode | 43 - (id)initWithMode:(HistoryOverlayMode)mode |
| 42 image:(NSImage*)image; | 44 image:(NSImage*)image; |
| 43 @end | 45 @end |
| 44 | 46 |
| 45 @implementation HistoryOverlayView | 47 @implementation HistoryOverlayView |
| 46 | 48 |
| 47 @synthesize shieldAlpha = shieldAlpha_; | 49 @synthesize shieldAlpha = shieldAlpha_; |
| 48 | 50 |
| 49 - (id)initWithMode:(HistoryOverlayMode)mode | 51 - (id)initWithMode:(HistoryOverlayMode)mode |
| 50 image:(NSImage*)image { | 52 image:(NSImage*)image { |
| 51 NSRect frame = NSMakeRect(0, 0, kShieldWidth, kShieldHeight); | 53 NSRect frame = NSMakeRect(0, 0, kShieldWidth, kShieldHeight); |
| 52 if ((self = [super initWithFrame:frame])) { | 54 if ((self = [super initWithFrame:frame])) { |
| 53 mode_ = mode; | 55 mode_ = mode; |
| 56 shieldAlpha_ = 1.0; // CAShapeLayer's fillColor defaults to opaque black. | |
| 57 | |
| 58 // A layer-hosting view. | |
| 59 shapeLayer_.reset([[CAShapeLayer alloc] init]); | |
| 60 [self setLayer:shapeLayer_]; | |
| 61 [self setWantsLayer:YES]; | |
| 54 | 62 |
| 55 // If going backward, the arrow needs to be in the right half of the circle, | 63 // If going backward, the arrow needs to be in the right half of the circle, |
| 56 // so offset the X position. | 64 // so offset the X position. |
| 57 CGFloat offset = mode_ == kHistoryOverlayModeBack ? kShieldRadius : 0; | 65 CGFloat offset = mode_ == kHistoryOverlayModeBack ? kShieldRadius : 0; |
| 58 NSRect arrowRect = NSMakeRect(offset, 0, kShieldRadius, kShieldHeight); | 66 NSRect arrowRect = NSMakeRect(offset, 0, kShieldRadius, kShieldHeight); |
| 59 arrowRect = NSInsetRect(arrowRect, 10, 0); // Give a little padding. | 67 arrowRect = NSInsetRect(arrowRect, 10, 0); // Give a little padding. |
| 60 | 68 |
| 61 base::scoped_nsobject<NSImageView> imageView( | 69 base::scoped_nsobject<NSImageView> imageView( |
| 62 [[NSImageView alloc] initWithFrame:arrowRect]); | 70 [[NSImageView alloc] initWithFrame:arrowRect]); |
| 63 [imageView setImage:image]; | 71 [imageView setImage:image]; |
| 64 [imageView setAutoresizingMask:NSViewMinYMargin | NSViewMaxYMargin]; | 72 [imageView setAutoresizingMask:NSViewMinYMargin | NSViewMaxYMargin]; |
| 65 [self addSubview:imageView]; | 73 [self addSubview:imageView]; |
| 66 } | 74 } |
| 67 return self; | 75 return self; |
| 68 } | 76 } |
| 69 | 77 |
| 70 - (void)drawRect:(NSRect)dirtyRect { | 78 - (void)setFrameSize:(CGSize)newSize { |
| 71 NSBezierPath* path = [NSBezierPath bezierPathWithOvalInRect:self.bounds]; | 79 NSSize oldSize = [self frame].size; |
| 72 NSColor* fillColor = [NSColor colorWithCalibratedWhite:0 alpha:shieldAlpha_]; | 80 [super setFrameSize:newSize]; |
| 73 [fillColor set]; | 81 |
| 74 [path fill]; | 82 if (![shapeLayer_ path] || !NSEqualSizes(oldSize, newSize)) { |
| 83 base::ScopedCFTypeRef<CGMutablePathRef> oval(CGPathCreateMutable()); | |
| 84 CGRect ovalRect = CGRectMake(0, 0, newSize.width, newSize.height); | |
| 85 CGPathAddEllipseInRect(oval, nullptr, ovalRect); | |
| 86 [shapeLayer_ setPath:oval]; | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 - (void)setShieldAlpha:(CGFloat)shieldAlpha { | |
| 91 if (shieldAlpha != shieldAlpha_) { | |
| 92 shieldAlpha_ = shieldAlpha; | |
| 93 base::ScopedCFTypeRef<CGColorRef> fillColor( | |
| 94 CGColorCreateGenericGray(0, shieldAlpha)); | |
|
Robert Sesek
2015/02/04 16:08:20
nit: indent +2
Andre
2015/02/04 16:38:19
Oops, done.
| |
| 95 [shapeLayer_ setFillColor:fillColor]; | |
| 96 } | |
| 75 } | 97 } |
| 76 | 98 |
| 77 @end | 99 @end |
| 78 | 100 |
| 79 // HistoryOverlayController //////////////////////////////////////////////////// | 101 // HistoryOverlayController //////////////////////////////////////////////////// |
| 80 | 102 |
| 81 @implementation HistoryOverlayController | 103 @implementation HistoryOverlayController |
| 82 | 104 |
| 83 - (id)initForMode:(HistoryOverlayMode)mode { | 105 - (id)initForMode:(HistoryOverlayMode)mode { |
| 84 if ((self = [super init])) { | 106 if ((self = [super init])) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 frame.origin.y = (NSHeight(parentFrame) / 2) - (height / 2); | 144 frame.origin.y = (NSHeight(parentFrame) / 2) - (height / 2); |
| 123 | 145 |
| 124 CGFloat width = std::min(kShieldRadius * gestureAmount, kShieldRadius); | 146 CGFloat width = std::min(kShieldRadius * gestureAmount, kShieldRadius); |
| 125 if (mode_ == kHistoryOverlayModeForward) | 147 if (mode_ == kHistoryOverlayModeForward) |
| 126 frame.origin.x = NSMaxX(parentFrame) - width; | 148 frame.origin.x = NSMaxX(parentFrame) - width; |
| 127 else if (mode_ == kHistoryOverlayModeBack) | 149 else if (mode_ == kHistoryOverlayModeBack) |
| 128 frame.origin.x = NSMinX(parentFrame) - kShieldWidth + width; | 150 frame.origin.x = NSMinX(parentFrame) - kShieldWidth + width; |
| 129 | 151 |
| 130 self.view.frame = frame; | 152 self.view.frame = frame; |
| 131 [contentView_ setShieldAlpha:shieldAlpha]; | 153 [contentView_ setShieldAlpha:shieldAlpha]; |
| 132 [contentView_ setNeedsDisplay:YES]; | |
| 133 } | 154 } |
| 134 | 155 |
| 135 - (void)showPanelForView:(NSView*)view { | 156 - (void)showPanelForView:(NSView*)view { |
| 136 parent_.reset([view retain]); | 157 parent_.reset([view retain]); |
| 137 [self setProgress:0 finished:NO]; // Set initial view position. | 158 [self setProgress:0 finished:NO]; // Set initial view position. |
| 138 [parent_ addSubview:self.view]; | 159 [parent_ addSubview:self.view]; |
| 139 } | 160 } |
| 140 | 161 |
| 141 - (void)dismiss { | 162 - (void)dismiss { |
| 142 const CGFloat kFadeOutDurationSeconds = 0.4; | 163 const CGFloat kFadeOutDurationSeconds = 0.4; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 158 } | 179 } |
| 159 | 180 |
| 160 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished { | 181 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished { |
| 161 [self.view removeFromSuperview]; | 182 [self.view removeFromSuperview]; |
| 162 // Destroy the CAAnimation and its strong reference to its delegate (this | 183 // Destroy the CAAnimation and its strong reference to its delegate (this |
| 163 // class). | 184 // class). |
| 164 [self.view setAnimations:nil]; | 185 [self.view setAnimations:nil]; |
| 165 } | 186 } |
| 166 | 187 |
| 167 @end | 188 @end |
| OLD | NEW |