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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/throbber_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/tabs/throbber_view.h" 5 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
(...skipping 10 matching lines...) Expand all
21 // Is the current frame the last frame of the animation? 21 // Is the current frame the last frame of the animation?
22 - (BOOL)animationIsComplete; 22 - (BOOL)animationIsComplete;
23 23
24 // Draw the current frame into the current graphics context. 24 // Draw the current frame into the current graphics context.
25 - (void)drawFrameInRect:(NSRect)rect; 25 - (void)drawFrameInRect:(NSRect)rect;
26 26
27 // Update the frame counter. 27 // Update the frame counter.
28 - (void)advanceFrame; 28 - (void)advanceFrame;
29 @end 29 @end
30 30
31 @interface ThrobberFilmstripDelegate : NSObject
32 <ThrobberDataDelegate> {
33 base::scoped_nsobject<NSImage> image_;
34 unsigned int numFrames_; // Number of frames in this animation.
35 unsigned int animationFrame_; // Current frame of the animation,
36 // [0..numFrames_)
37 }
38
39 - (id)initWithImage:(NSImage*)image;
40
41 @end
42
43 @implementation ThrobberFilmstripDelegate
44
45 - (id)initWithImage:(NSImage*)image {
46 if ((self = [super init])) {
47 // Reset the animation counter so there's no chance we are off the end.
48 animationFrame_ = 0;
49
50 // Ensure that the height divides evenly into the width. Cache the
51 // number of frames in the animation for later.
52 NSSize imageSize = [image size];
53 DCHECK(imageSize.height && imageSize.width);
54 if (!imageSize.height)
55 return nil;
56 DCHECK((int)imageSize.width % (int)imageSize.height == 0);
57 numFrames_ = (int)imageSize.width / (int)imageSize.height;
58 DCHECK(numFrames_);
59 image_.reset([image retain]);
60 }
61 return self;
62 }
63
64 - (BOOL)animationIsComplete {
65 return NO;
66 }
67
68 - (void)drawFrameInRect:(NSRect)rect {
69 float imageDimension = [image_ size].height;
70 float xOffset = animationFrame_ * imageDimension;
71 NSRect sourceImageRect =
72 NSMakeRect(xOffset, 0, imageDimension, imageDimension);
73 [image_ drawInRect:rect
74 fromRect:sourceImageRect
75 operation:NSCompositeSourceOver
76 fraction:1.0];
77 }
78
79 - (void)advanceFrame {
80 animationFrame_ = ++animationFrame_ % numFrames_;
81 }
82
83 @end
84
31 @interface ThrobberToastDelegate : NSObject 85 @interface ThrobberToastDelegate : NSObject
32 <ThrobberDataDelegate> { 86 <ThrobberDataDelegate> {
33 base::scoped_nsobject<NSImage> image1_; 87 base::scoped_nsobject<NSImage> image1_;
34 base::scoped_nsobject<NSImage> image2_; 88 base::scoped_nsobject<NSImage> image2_;
35 NSSize image1Size_; 89 NSSize image1Size_;
36 NSSize image2Size_; 90 NSSize image2Size_;
37 int animationFrame_; // Current frame of the animation, 91 int animationFrame_; // Current frame of the animation,
38 } 92 }
39 93
40 - (id)initWithImage1:(NSImage*)image1 image2:(NSImage*)image2; 94 - (id)initWithImage1:(NSImage*)image1 image2:(NSImage*)image2;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 ++next; 278 ++next;
225 ThrobberView* throbber = *current; 279 ThrobberView* throbber = *current;
226 [throbber animate]; 280 [throbber animate];
227 current = next; 281 current = next;
228 } 282 }
229 } 283 }
230 @end 284 @end
231 285
232 @implementation ThrobberView 286 @implementation ThrobberView
233 287
288 + (id)filmstripThrobberViewWithFrame:(NSRect)frame
289 image:(NSImage*)image {
290 ThrobberFilmstripDelegate* delegate =
291 [[[ThrobberFilmstripDelegate alloc] initWithImage:image] autorelease];
292 if (!delegate)
293 return nil;
294
295 return [[[ThrobberView alloc] initWithFrame:frame
296 delegate:delegate] autorelease];
297 }
298
234 + (id)toastThrobberViewWithFrame:(NSRect)frame 299 + (id)toastThrobberViewWithFrame:(NSRect)frame
235 beforeImage:(NSImage*)beforeImage 300 beforeImage:(NSImage*)beforeImage
236 afterImage:(NSImage*)afterImage { 301 afterImage:(NSImage*)afterImage {
237 ThrobberToastDelegate* delegate = 302 ThrobberToastDelegate* delegate =
238 [[[ThrobberToastDelegate alloc] initWithImage1:beforeImage 303 [[[ThrobberToastDelegate alloc] initWithImage1:beforeImage
239 image2:afterImage] autorelease]; 304 image2:afterImage] autorelease];
240 if (!delegate) 305 if (!delegate)
241 return nil; 306 return nil;
242 307
243 return [[[ThrobberView alloc] initWithFrame:frame 308 return [[[ThrobberView alloc] initWithFrame:frame
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 [[ThrobberTimer sharedThrobberTimer] removeThrobber:self]; 364 [[ThrobberTimer sharedThrobberTimer] removeThrobber:self];
300 } 365 }
301 } 366 }
302 367
303 // Overridden to draw the appropriate frame in the image strip. 368 // Overridden to draw the appropriate frame in the image strip.
304 - (void)drawRect:(NSRect)rect { 369 - (void)drawRect:(NSRect)rect {
305 [dataDelegate_ drawFrameInRect:[self bounds]]; 370 [dataDelegate_ drawFrameInRect:[self bounds]];
306 } 371 }
307 372
308 @end 373 @end
OLDNEW
« 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