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

Unified Diff: chrome/browser/ui/cocoa/tabs/throbber_view.mm

Issue 174883003: mac: Disable CoreAnimation throbbers for now, while I investigate the performance regressions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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 | « chrome/browser/ui/cocoa/tabs/throbber_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/tabs/throbber_view.mm
diff --git a/chrome/browser/ui/cocoa/tabs/throbber_view.mm b/chrome/browser/ui/cocoa/tabs/throbber_view.mm
index 8df191a56b18a928eaf57e20d56570a075dc93bb..0d838a3a43d6788c06a9671ed955e9a650657abb 100644
--- a/chrome/browser/ui/cocoa/tabs/throbber_view.mm
+++ b/chrome/browser/ui/cocoa/tabs/throbber_view.mm
@@ -28,6 +28,60 @@ static const float kAnimationIntervalSeconds = 0.03; // 30ms, same as windows
- (void)advanceFrame;
@end
+@interface ThrobberFilmstripDelegate : NSObject
+ <ThrobberDataDelegate> {
+ base::scoped_nsobject<NSImage> image_;
+ unsigned int numFrames_; // Number of frames in this animation.
+ unsigned int animationFrame_; // Current frame of the animation,
+ // [0..numFrames_)
+}
+
+- (id)initWithImage:(NSImage*)image;
+
+@end
+
+@implementation ThrobberFilmstripDelegate
+
+- (id)initWithImage:(NSImage*)image {
+ if ((self = [super init])) {
+ // Reset the animation counter so there's no chance we are off the end.
+ animationFrame_ = 0;
+
+ // Ensure that the height divides evenly into the width. Cache the
+ // number of frames in the animation for later.
+ NSSize imageSize = [image size];
+ DCHECK(imageSize.height && imageSize.width);
+ if (!imageSize.height)
+ return nil;
+ DCHECK((int)imageSize.width % (int)imageSize.height == 0);
+ numFrames_ = (int)imageSize.width / (int)imageSize.height;
+ DCHECK(numFrames_);
+ image_.reset([image retain]);
+ }
+ return self;
+}
+
+- (BOOL)animationIsComplete {
+ return NO;
+}
+
+- (void)drawFrameInRect:(NSRect)rect {
+ float imageDimension = [image_ size].height;
+ float xOffset = animationFrame_ * imageDimension;
+ NSRect sourceImageRect =
+ NSMakeRect(xOffset, 0, imageDimension, imageDimension);
+ [image_ drawInRect:rect
+ fromRect:sourceImageRect
+ operation:NSCompositeSourceOver
+ fraction:1.0];
+}
+
+- (void)advanceFrame {
+ animationFrame_ = ++animationFrame_ % numFrames_;
+}
+
+@end
+
@interface ThrobberToastDelegate : NSObject
<ThrobberDataDelegate> {
base::scoped_nsobject<NSImage> image1_;
@@ -231,6 +285,17 @@ typedef std::set<ThrobberView*> ThrobberSet;
@implementation ThrobberView
++ (id)filmstripThrobberViewWithFrame:(NSRect)frame
+ image:(NSImage*)image {
+ ThrobberFilmstripDelegate* delegate =
+ [[[ThrobberFilmstripDelegate alloc] initWithImage:image] autorelease];
+ if (!delegate)
+ return nil;
+
+ return [[[ThrobberView alloc] initWithFrame:frame
+ delegate:delegate] autorelease];
+}
+
+ (id)toastThrobberViewWithFrame:(NSRect)frame
beforeImage:(NSImage*)beforeImage
afterImage:(NSImage*)afterImage {
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/throbber_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698