Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1183)

Unified Diff: chrome/browser/ui/cocoa/history_overlay_controller.mm

Issue 894423003: Mac: Optimize HistoryOverlayView using layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@themed-drawing
Patch Set: Use CAShapeLayer Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/history_overlay_controller.mm
diff --git a/chrome/browser/ui/cocoa/history_overlay_controller.mm b/chrome/browser/ui/cocoa/history_overlay_controller.mm
index 88237a3c6f771d1cc37f5bb940f9d954df5a9270..0221a98581b3659c70a85c1c38acfd3bc2fc367d 100644
--- a/chrome/browser/ui/cocoa/history_overlay_controller.mm
+++ b/chrome/browser/ui/cocoa/history_overlay_controller.mm
@@ -5,6 +5,7 @@
#import "chrome/browser/ui/cocoa/history_overlay_controller.h"
#include "base/logging.h"
+#include "base/mac/scoped_cftyperef.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
@@ -36,6 +37,7 @@ const CGFloat kShieldHeightCompletionAdjust = 10;
@private
HistoryOverlayMode mode_;
CGFloat shieldAlpha_;
+ base::scoped_nsobject<CAShapeLayer> shapeLayer_;
}
@property(nonatomic) CGFloat shieldAlpha;
- (id)initWithMode:(HistoryOverlayMode)mode
@@ -51,6 +53,12 @@ const CGFloat kShieldHeightCompletionAdjust = 10;
NSRect frame = NSMakeRect(0, 0, kShieldWidth, kShieldHeight);
if ((self = [super initWithFrame:frame])) {
mode_ = mode;
+ shieldAlpha_ = 1.0; // CAShapeLayer's fillColor defaults to opaque black.
+
+ // A layer-hosting view.
+ shapeLayer_.reset([[CAShapeLayer alloc] init]);
+ [self setLayer:shapeLayer_];
+ [self setWantsLayer:YES];
// If going backward, the arrow needs to be in the right half of the circle,
// so offset the X position.
@@ -67,11 +75,25 @@ const CGFloat kShieldHeightCompletionAdjust = 10;
return self;
}
-- (void)drawRect:(NSRect)dirtyRect {
- NSBezierPath* path = [NSBezierPath bezierPathWithOvalInRect:self.bounds];
- NSColor* fillColor = [NSColor colorWithCalibratedWhite:0 alpha:shieldAlpha_];
- [fillColor set];
- [path fill];
+- (void)setFrameSize:(CGSize)newSize {
+ NSSize oldSize = [self frame].size;
+ [super setFrameSize:newSize];
+
+ if (![shapeLayer_ path] || !NSEqualSizes(oldSize, newSize)) {
+ base::ScopedCFTypeRef<CGMutablePathRef> oval(CGPathCreateMutable());
+ CGRect ovalRect = CGRectMake(0, 0, newSize.width, newSize.height);
+ CGPathAddEllipseInRect(oval, nullptr, ovalRect);
+ [shapeLayer_ setPath:oval];
+ }
+}
+
+- (void)setShieldAlpha:(CGFloat)shieldAlpha {
+ if (shieldAlpha != shieldAlpha_) {
+ shieldAlpha_ = shieldAlpha;
+ base::ScopedCFTypeRef<CGColorRef> fillColor(
+ CGColorCreateGenericGray(0, shieldAlpha));
Robert Sesek 2015/02/04 16:08:20 nit: indent +2
Andre 2015/02/04 16:38:19 Oops, done.
+ [shapeLayer_ setFillColor:fillColor];
+ }
}
@end
@@ -129,7 +151,6 @@ const CGFloat kShieldHeightCompletionAdjust = 10;
self.view.frame = frame;
[contentView_ setShieldAlpha:shieldAlpha];
- [contentView_ setNeedsDisplay:YES];
}
- (void)showPanelForView:(NSView*)view {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698