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 3// found in the LICENSE file. 4 5#import "chrome/browser/ui/cocoa/image_utils.h" 6 7@implementation NSImage (FlippedAdditions) 8 9- (void)drawInRect:(NSRect)dstRect 10 fromRect:(NSRect)srcRect 11 operation:(NSCompositingOperation)op 12 fraction:(CGFloat)requestedAlpha 13 neverFlipped:(BOOL)neverFlipped { 14 NSAffineTransform *transform = nil; 15 16 // Flip drawing and adjust the origin to make the image come out 17 // right. 18 if (neverFlipped && [[NSGraphicsContext currentContext] isFlipped]) { 19 transform = [NSAffineTransform transform]; 20 [transform scaleXBy:1.0 yBy:-1.0]; 21 [transform concat]; 22 23 // The lower edge of the image is as far from the origin as the 24 // upper edge was, plus it's on the other side of the origin. 25 dstRect.origin.y -= NSMaxY(dstRect) + NSMinY(dstRect); 26 } 27 28 [self drawInRect:dstRect 29 fromRect:srcRect 30 operation:op 31 fraction:requestedAlpha]; 32 33 // Flip drawing back, if needed. 34 [transform concat]; 35} 36 37@end 38