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

Side by Side Diff: chrome/browser/cocoa/extensions/browser_action_button.mm

Issue 2635005: [Mac] Simplify generating composited browser-action image. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: scoped_nsobject -> earlier -autorelease Created 10 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
« no previous file with comments | « no previous file | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extensions/browser_action_button.h" 5 #import "chrome/browser/cocoa/extensions/browser_action_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 postNotificationName:kBrowserActionButtonUpdatedNotification 276 postNotificationName:kBrowserActionButtonUpdatedNotification
277 object:self]; 277 object:self];
278 } 278 }
279 279
280 - (BOOL)isAnimating { 280 - (BOOL)isAnimating {
281 return [moveAnimation_ isAnimating]; 281 return [moveAnimation_ isAnimating];
282 } 282 }
283 283
284 - (NSImage*)compositedImage { 284 - (NSImage*)compositedImage {
285 NSRect bounds = NSMakeRect(0, 0, kBrowserActionWidth, kBrowserActionHeight); 285 NSRect bounds = NSMakeRect(0, 0, kBrowserActionWidth, kBrowserActionHeight);
286 NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] 286 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease];
287 initWithBitmapDataPlanes:NULL 287 [image lockFocus];
288 pixelsWide:NSWidth(bounds)
289 pixelsHigh:NSHeight(bounds)
290 bitsPerSample:8
291 samplesPerPixel:4
292 hasAlpha:YES
293 isPlanar:NO
294 colorSpaceName:NSCalibratedRGBColorSpace
295 bitmapFormat:0
296 bytesPerRow:0
297 bitsPerPixel:0];
298 288
299 [NSGraphicsContext saveGraphicsState];
300 [NSGraphicsContext setCurrentContext:
301 [NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap]];
302 [[NSColor clearColor] set]; 289 [[NSColor clearColor] set];
303 NSRectFill(bounds); 290 NSRectFill(bounds);
304 [[self cell] setIconShadow]; 291 [[self cell] setIconShadow];
305 292
306 NSImage* actionImage = [self image]; 293 NSImage* actionImage = [self image];
307 const NSSize imageSize = [actionImage size]; 294 const NSSize imageSize = [actionImage size];
308 const NSRect imageRect = 295 const NSRect imageRect =
309 NSMakeRect(std::floor((NSWidth(bounds) - imageSize.width) / 2.0), 296 NSMakeRect(std::floor((NSWidth(bounds) - imageSize.width) / 2.0),
310 std::floor((NSHeight(bounds) - imageSize.height) / 2.0), 297 std::floor((NSHeight(bounds) - imageSize.height) / 2.0),
311 imageSize.width, imageSize.height); 298 imageSize.width, imageSize.height);
312 [actionImage drawInRect:imageRect 299 [actionImage drawInRect:imageRect
313 fromRect:NSZeroRect 300 fromRect:NSZeroRect
314 operation:NSCompositeSourceOver 301 operation:NSCompositeSourceOver
315 fraction:1.0 302 fraction:1.0
316 neverFlipped:YES]; 303 neverFlipped:YES];
317 304
318 bounds.origin.y += kShadowOffset - kBrowserActionBadgeOriginYOffset; 305 bounds.origin.y += kShadowOffset - kBrowserActionBadgeOriginYOffset;
319 bounds.origin.x -= kShadowOffset; 306 bounds.origin.x -= kShadowOffset;
320 [[self cell] drawBadgeWithinFrame:bounds]; 307 [[self cell] drawBadgeWithinFrame:bounds];
321 308
322 [NSGraphicsContext restoreGraphicsState]; 309 [image unlockFocus];
323 NSImage* compositeImage = 310 return image;
324 [[[NSImage alloc] initWithSize:[bitmap size]] autorelease];
325 [compositeImage addRepresentation:bitmap];
326 return compositeImage;
327 } 311 }
328 312
329 @end 313 @end
330 314
331 @implementation BrowserActionCell 315 @implementation BrowserActionCell
332 316
333 @synthesize tabId = tabId_; 317 @synthesize tabId = tabId_;
334 @synthesize extensionAction = extensionAction_; 318 @synthesize extensionAction = extensionAction_;
335 319
336 - (void)setIconShadow { 320 - (void)setIconShadow {
(...skipping 16 matching lines...) Expand all
353 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { 337 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
354 [NSGraphicsContext saveGraphicsState]; 338 [NSGraphicsContext saveGraphicsState];
355 [self setIconShadow]; 339 [self setIconShadow];
356 [super drawInteriorWithFrame:cellFrame inView:controlView]; 340 [super drawInteriorWithFrame:cellFrame inView:controlView];
357 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; 341 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset;
358 [self drawBadgeWithinFrame:cellFrame]; 342 [self drawBadgeWithinFrame:cellFrame];
359 [NSGraphicsContext restoreGraphicsState]; 343 [NSGraphicsContext restoreGraphicsState];
360 } 344 }
361 345
362 @end 346 @end
OLDNEW
« 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