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 27 matching lines...) Expand all Loading... | |
45 @implementation HistoryOverlayView | 46 @implementation HistoryOverlayView |
46 | 47 |
47 @synthesize shieldAlpha = shieldAlpha_; | 48 @synthesize shieldAlpha = shieldAlpha_; |
48 | 49 |
49 - (id)initWithMode:(HistoryOverlayMode)mode | 50 - (id)initWithMode:(HistoryOverlayMode)mode |
50 image:(NSImage*)image { | 51 image:(NSImage*)image { |
51 NSRect frame = NSMakeRect(0, 0, kShieldWidth, kShieldHeight); | 52 NSRect frame = NSMakeRect(0, 0, kShieldWidth, kShieldHeight); |
52 if ((self = [super initWithFrame:frame])) { | 53 if ((self = [super initWithFrame:frame])) { |
53 mode_ = mode; | 54 mode_ = mode; |
54 | 55 |
56 // A layer-hosting view. | |
57 [self setLayer:[CALayer layer]]; | |
58 [self setWantsLayer:YES]; | |
59 | |
55 // If going backward, the arrow needs to be in the right half of the circle, | 60 // If going backward, the arrow needs to be in the right half of the circle, |
56 // so offset the X position. | 61 // so offset the X position. |
57 CGFloat offset = mode_ == kHistoryOverlayModeBack ? kShieldRadius : 0; | 62 CGFloat offset = mode_ == kHistoryOverlayModeBack ? kShieldRadius : 0; |
58 NSRect arrowRect = NSMakeRect(offset, 0, kShieldRadius, kShieldHeight); | 63 NSRect arrowRect = NSMakeRect(offset, 0, kShieldRadius, kShieldHeight); |
59 arrowRect = NSInsetRect(arrowRect, 10, 0); // Give a little padding. | 64 arrowRect = NSInsetRect(arrowRect, 10, 0); // Give a little padding. |
60 | 65 |
61 base::scoped_nsobject<NSImageView> imageView( | 66 base::scoped_nsobject<NSImageView> imageView( |
62 [[NSImageView alloc] initWithFrame:arrowRect]); | 67 [[NSImageView alloc] initWithFrame:arrowRect]); |
63 [imageView setImage:image]; | 68 [imageView setImage:image]; |
64 [imageView setAutoresizingMask:NSViewMinYMargin | NSViewMaxYMargin]; | 69 [imageView setAutoresizingMask:NSViewMinYMargin | NSViewMaxYMargin]; |
65 [self addSubview:imageView]; | 70 [self addSubview:imageView]; |
66 } | 71 } |
67 return self; | 72 return self; |
68 } | 73 } |
69 | 74 |
70 - (void)drawRect:(NSRect)dirtyRect { | 75 - (void)setFrameSize:(CGSize)frameSize { |
71 NSBezierPath* path = [NSBezierPath bezierPathWithOvalInRect:self.bounds]; | 76 [super setFrameSize:frameSize]; |
72 NSColor* fillColor = [NSColor colorWithCalibratedWhite:0 alpha:shieldAlpha_]; | 77 // Draw an oval. |
73 [fillColor set]; | 78 CGFloat radius = std::min(frameSize.width, frameSize.height) / 2.0; |
Robert Sesek
2015/02/04 00:21:13
Why min here instead of just always width?
Andre
2015/02/04 01:08:55
height >= width always, so that would work.
Done.
| |
74 [path fill]; | 79 [[self layer] setCornerRadius:radius]; |
80 } | |
81 | |
82 - (void)setShieldAlpha:(CGFloat)shieldAlpha { | |
83 shieldAlpha_ = shieldAlpha; | |
84 base::ScopedCFTypeRef<CGColorRef> fillColor( | |
85 CGColorCreateGenericGray(0, shieldAlpha)); | |
86 [[self layer] setBackgroundColor:fillColor]; | |
75 } | 87 } |
76 | 88 |
77 @end | 89 @end |
78 | 90 |
79 // HistoryOverlayController //////////////////////////////////////////////////// | 91 // HistoryOverlayController //////////////////////////////////////////////////// |
80 | 92 |
81 @implementation HistoryOverlayController | 93 @implementation HistoryOverlayController |
82 | 94 |
83 - (id)initForMode:(HistoryOverlayMode)mode { | 95 - (id)initForMode:(HistoryOverlayMode)mode { |
84 if ((self = [super init])) { | 96 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); | 134 frame.origin.y = (NSHeight(parentFrame) / 2) - (height / 2); |
123 | 135 |
124 CGFloat width = std::min(kShieldRadius * gestureAmount, kShieldRadius); | 136 CGFloat width = std::min(kShieldRadius * gestureAmount, kShieldRadius); |
125 if (mode_ == kHistoryOverlayModeForward) | 137 if (mode_ == kHistoryOverlayModeForward) |
126 frame.origin.x = NSMaxX(parentFrame) - width; | 138 frame.origin.x = NSMaxX(parentFrame) - width; |
127 else if (mode_ == kHistoryOverlayModeBack) | 139 else if (mode_ == kHistoryOverlayModeBack) |
128 frame.origin.x = NSMinX(parentFrame) - kShieldWidth + width; | 140 frame.origin.x = NSMinX(parentFrame) - kShieldWidth + width; |
129 | 141 |
130 self.view.frame = frame; | 142 self.view.frame = frame; |
131 [contentView_ setShieldAlpha:shieldAlpha]; | 143 [contentView_ setShieldAlpha:shieldAlpha]; |
132 [contentView_ setNeedsDisplay:YES]; | |
133 } | 144 } |
134 | 145 |
135 - (void)showPanelForView:(NSView*)view { | 146 - (void)showPanelForView:(NSView*)view { |
136 parent_.reset([view retain]); | 147 parent_.reset([view retain]); |
137 [self setProgress:0 finished:NO]; // Set initial view position. | 148 [self setProgress:0 finished:NO]; // Set initial view position. |
138 [parent_ addSubview:self.view]; | 149 [parent_ addSubview:self.view]; |
139 } | 150 } |
140 | 151 |
141 - (void)dismiss { | 152 - (void)dismiss { |
142 const CGFloat kFadeOutDurationSeconds = 0.4; | 153 const CGFloat kFadeOutDurationSeconds = 0.4; |
(...skipping 15 matching lines...) Expand all Loading... | |
158 } | 169 } |
159 | 170 |
160 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished { | 171 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished { |
161 [self.view removeFromSuperview]; | 172 [self.view removeFromSuperview]; |
162 // Destroy the CAAnimation and its strong reference to its delegate (this | 173 // Destroy the CAAnimation and its strong reference to its delegate (this |
163 // class). | 174 // class). |
164 [self.view setAnimations:nil]; | 175 [self.view setAnimations:nil]; |
165 } | 176 } |
166 | 177 |
167 @end | 178 @end |
OLD | NEW |