| OLD | NEW |
| 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 #include <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h" | 7 #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h" |
| 8 | 8 |
| 9 ImageDecoration::ImageDecoration() { | 9 ImageDecoration::ImageDecoration() { |
| 10 } | 10 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 return frame; | 26 return frame; |
| 27 | 27 |
| 28 // Center the image within the frame. | 28 // Center the image within the frame. |
| 29 const CGFloat delta_height = NSHeight(frame) - [image size].height; | 29 const CGFloat delta_height = NSHeight(frame) - [image size].height; |
| 30 const CGFloat y_inset = std::floor(delta_height / 2.0); | 30 const CGFloat y_inset = std::floor(delta_height / 2.0); |
| 31 const CGFloat delta_width = NSWidth(frame) - [image size].width; | 31 const CGFloat delta_width = NSWidth(frame) - [image size].width; |
| 32 const CGFloat x_inset = std::floor(delta_width / 2.0); | 32 const CGFloat x_inset = std::floor(delta_width / 2.0); |
| 33 return NSInsetRect(frame, x_inset, y_inset); | 33 return NSInsetRect(frame, x_inset, y_inset); |
| 34 } | 34 } |
| 35 | 35 |
| 36 CGFloat ImageDecoration::GetWidthForSpace(CGFloat width) { | 36 CGFloat ImageDecoration::GetWidthForSpace(CGFloat width, CGFloat text_width) { |
| 37 NSImage* image = GetImage(); | 37 NSImage* image = GetImage(); |
| 38 if (image) { | 38 if (image) { |
| 39 const CGFloat image_width = [image size].width; | 39 const CGFloat image_width = [image size].width; |
| 40 if (image_width <= width) | 40 if (image_width <= width) |
| 41 return image_width; | 41 return image_width; |
| 42 } | 42 } |
| 43 return kOmittedWidth; | 43 return kOmittedWidth; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void ImageDecoration::DrawInFrame(NSRect frame, NSView* control_view) { | 46 void ImageDecoration::DrawInFrame(NSRect frame, NSView* control_view) { |
| 47 [GetImage() drawInRect:GetDrawRectInFrame(frame) | 47 [GetImage() drawInRect:GetDrawRectInFrame(frame) |
| 48 fromRect:NSZeroRect // Entire image | 48 fromRect:NSZeroRect // Entire image |
| 49 operation:NSCompositeSourceOver | 49 operation:NSCompositeSourceOver |
| 50 fraction:1.0 | 50 fraction:1.0 |
| 51 respectFlipped:YES | 51 respectFlipped:YES |
| 52 hints:nil]; | 52 hints:nil]; |
| 53 } | 53 } |
| OLD | NEW |