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

Side by Side Diff: chrome/browser/cocoa/throbber_view.mm

Issue 112065: Implement Clear Browser Data for Mac as an app modal dialog. Uses the profile... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/throbber_view.h ('k') | chrome/chrome.gyp » ('j') | 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/cocoa/throbber_view.h" 5 #import "chrome/browser/cocoa/throbber_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 const float kAnimationIntervalSeconds = 0.03; // 30ms, same as windows 9 const float kAnimationIntervalSeconds = 0.03; // 30ms, same as windows
10 10
(...skipping 21 matching lines...) Expand all
32 32
33 - (void)animate:(NSTimer*)timer { 33 - (void)animate:(NSTimer*)timer {
34 [throbber_ animate]; 34 [throbber_ animate];
35 } 35 }
36 @end 36 @end
37 37
38 @implementation ThrobberView 38 @implementation ThrobberView
39 39
40 - (id)initWithFrame:(NSRect)frame image:(NSImage*)image { 40 - (id)initWithFrame:(NSRect)frame image:(NSImage*)image {
41 if ((self = [super initWithFrame:frame])) { 41 if ((self = [super initWithFrame:frame])) {
42 // Ensure that the height divides evenly into the width. Cache the 42 [self setImage:image];
43 // number of frames in the animation for later.
44 NSSize imageSize = [image size];
45 DCHECK(imageSize.height && imageSize.width);
46 if (!imageSize.height)
47 return nil;
48 DCHECK((int)imageSize.width % (int)imageSize.height == 0);
49 numFrames_ = (int)imageSize.width / (int)imageSize.height;
50 DCHECK(numFrames_);
51
52 // First check if we have a bitmap image rep and use it, otherwise fall
53 // back to creating one.
54 NSBitmapImageRep* rep = [[image representations] objectAtIndex:0];
55 if (![rep isKindOfClass:[NSBitmapImageRep class]]) {
56 [image lockFocus];
57 NSRect imageRect = NSMakeRect(0, 0, imageSize.width, imageSize.height);
58 rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:imageRect]
59 autorelease];
60 [image unlockFocus];
61 }
62 image_.reset([[CIImage alloc] initWithBitmapImageRep:rep]);
63 43
64 #if 0 44 #if 0
65 // TODO(pinkerton): The invalidation of the view to trigger re-draw causes 45 // TODO(pinkerton): The invalidation of the view to trigger re-draw causes
TVL 2009/05/29 13:05:19 this should also move into the setImage call with
pink (ping after 24hrs) 2009/05/29 13:19:11 Done.
66 // the entire title-bar to redraw (you can see it with QuartzDebug). For some 46 // the entire title-bar to redraw (you can see it with QuartzDebug). For some
67 // reason, setting isOpaque on this view, or any of its parent views, doesn't 47 // reason, setting isOpaque on this view, or any of its parent views, doesn't
68 // help. As a result, enabling this timer causes new tab to take a very long 48 // help. As a result, enabling this timer causes new tab to take a very long
69 // time on a loaded machine, crushing our perf bot when it's under load. For 49 // time on a loaded machine, crushing our perf bot when it's under load. For
70 // now, I'm disabling the timer so we draw the first frame of the animation, 50 // now, I'm disabling the timer so we draw the first frame of the animation,
71 // but nothing more. There are a couple of ways we can fix this: 51 // but nothing more. There are a couple of ways we can fix this:
72 // 1) Try to figure out why the invalidate is invalidating the entire title bar 52 // 1) Try to figure out why the invalidate is invalidating the entire title bar
73 // 2) Find some way to draw only the pixels we want and nothing else, but I 53 // 2) Find some way to draw only the pixels we want and nothing else, but I
74 // don't know how we'd do that. 54 // don't know how we'd do that.
75 // Start a timer for the animation frames. 55 // Start a timer for the animation frames.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 float imageDimension = [image_ extent].size.height; 89 float imageDimension = [image_ extent].size.height;
110 float xOffset = animationFrame_ * imageDimension; 90 float xOffset = animationFrame_ * imageDimension;
111 NSRect sourceImageRect = 91 NSRect sourceImageRect =
112 NSMakeRect(xOffset, 0, imageDimension, imageDimension); 92 NSMakeRect(xOffset, 0, imageDimension, imageDimension);
113 [image_ drawInRect:[self bounds] 93 [image_ drawInRect:[self bounds]
114 fromRect:sourceImageRect 94 fromRect:sourceImageRect
115 operation:NSCompositeSourceOver 95 operation:NSCompositeSourceOver
116 fraction:1.0]; 96 fraction:1.0];
117 } 97 }
118 98
99 // Stores the internal representation of the image from |image|. We use
100 // CoreImage for speed (though this doesn't seem to help perf issues). We
101 // validate that the image is of the appropriate ratio.
102 - (void)setImage:(NSImage*)image {
103 // Reset the animation counter so there's no chance we are off the end.
104 animationFrame_ = 0;
105
106 // Ensure that the height divides evenly into the width. Cache the
107 // number of frames in the animation for later.
108 NSSize imageSize = [image size];
109 DCHECK(imageSize.height && imageSize.width);
110 if (!imageSize.height)
111 return;
112 DCHECK((int)imageSize.width % (int)imageSize.height == 0);
113 numFrames_ = (int)imageSize.width / (int)imageSize.height;
114 DCHECK(numFrames_);
115
116 // First check if we have a bitmap image rep and use it, otherwise fall
117 // back to creating one.
118 NSBitmapImageRep* rep = [[image representations] objectAtIndex:0];
119 if (![rep isKindOfClass:[NSBitmapImageRep class]]) {
120 [image lockFocus];
121 NSRect imageRect = NSMakeRect(0, 0, imageSize.width, imageSize.height);
122 rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:imageRect]
123 autorelease];
124 [image unlockFocus];
125 }
126 image_.reset([[CIImage alloc] initWithBitmapImageRep:rep]);
127 }
128
119 @end 129 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/throbber_view.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698