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

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

Issue 2685001: [Mac] Adapt browser-action image-drawing to ignore flipped. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: 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"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "chrome/browser/cocoa/extensions/extension_action_context_menu.h" 12 #include "chrome/browser/cocoa/extensions/extension_action_context_menu.h"
13 #import "chrome/browser/cocoa/image_utils.h"
13 #include "chrome/browser/extensions/image_loading_tracker.h" 14 #include "chrome/browser/extensions/image_loading_tracker.h"
14 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_action.h" 16 #include "chrome/common/extensions/extension_action.h"
16 #include "chrome/common/extensions/extension_resource.h" 17 #include "chrome/common/extensions/extension_resource.h"
17 #include "chrome/common/notification_observer.h" 18 #include "chrome/common/notification_observer.h"
18 #include "chrome/common/notification_registrar.h" 19 #include "chrome/common/notification_registrar.h"
19 #include "chrome/common/notification_source.h" 20 #include "chrome/common/notification_source.h"
20 #include "chrome/common/notification_type.h" 21 #include "chrome/common/notification_type.h"
21 #include "gfx/canvas_paint.h" 22 #include "gfx/canvas_paint.h"
22 #include "gfx/rect.h" 23 #include "gfx/rect.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 bitsPerPixel:0]; 297 bitsPerPixel:0];
297 298
298 [NSGraphicsContext saveGraphicsState]; 299 [NSGraphicsContext saveGraphicsState];
299 [NSGraphicsContext setCurrentContext: 300 [NSGraphicsContext setCurrentContext:
300 [NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap]]; 301 [NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap]];
301 [[NSColor clearColor] set]; 302 [[NSColor clearColor] set];
302 NSRectFill(bounds); 303 NSRectFill(bounds);
303 [[self cell] setIconShadow]; 304 [[self cell] setIconShadow];
304 305
305 NSImage* actionImage = [self image]; 306 NSImage* actionImage = [self image];
306 // Never draw within a flipped coordinate system. 307 const NSSize imageSize = [actionImage size];
307 // TODO(andybons): Figure out why |flipped| can be yes in certain cases. 308 const NSRect imageRect =
308 // http://crbug.com/38943 309 NSMakeRect(std::floor((NSWidth(bounds) - imageSize.width) / 2.0),
309 [actionImage setFlipped:NO]; 310 std::floor((NSHeight(bounds) - imageSize.height) / 2.0),
310 CGFloat xPos = std::floor((NSWidth(bounds) - [actionImage size].width) / 2); 311 imageSize.width, imageSize.height);
311 CGFloat yPos = std::floor((NSHeight(bounds) - [actionImage size].height) / 2); 312 [actionImage drawInRect:imageRect
312 [actionImage drawAtPoint:NSMakePoint(xPos, yPos) 313 fromRect:NSZeroRect
313 fromRect:NSZeroRect 314 operation:NSCompositeSourceOver
314 operation:NSCompositeSourceOver 315 fraction:1.0
315 fraction:1.0]; 316 neverFlipped:YES];
316 317
317 bounds.origin.y += kShadowOffset - kBrowserActionBadgeOriginYOffset; 318 bounds.origin.y += kShadowOffset - kBrowserActionBadgeOriginYOffset;
318 bounds.origin.x -= kShadowOffset; 319 bounds.origin.x -= kShadowOffset;
319 [[self cell] drawBadgeWithinFrame:bounds]; 320 [[self cell] drawBadgeWithinFrame:bounds];
320 321
321 [NSGraphicsContext restoreGraphicsState]; 322 [NSGraphicsContext restoreGraphicsState];
322 NSImage* compositeImage = 323 NSImage* compositeImage =
323 [[[NSImage alloc] initWithSize:[bitmap size]] autorelease]; 324 [[[NSImage alloc] initWithSize:[bitmap size]] autorelease];
324 [compositeImage addRepresentation:bitmap]; 325 [compositeImage addRepresentation:bitmap];
325 return compositeImage; 326 return compositeImage;
(...skipping 26 matching lines...) Expand all
352 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { 353 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
353 [NSGraphicsContext saveGraphicsState]; 354 [NSGraphicsContext saveGraphicsState];
354 [self setIconShadow]; 355 [self setIconShadow];
355 [super drawInteriorWithFrame:cellFrame inView:controlView]; 356 [super drawInteriorWithFrame:cellFrame inView:controlView];
356 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; 357 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset;
357 [self drawBadgeWithinFrame:cellFrame]; 358 [self drawBadgeWithinFrame:cellFrame];
358 [NSGraphicsContext restoreGraphicsState]; 359 [NSGraphicsContext restoreGraphicsState];
359 } 360 }
360 361
361 @end 362 @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