| 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 // The amount of horizontal padding around the image. |
| 10 const CGFloat kImageHorizontalPadding = 9.0; |
| 11 |
| 9 ImageDecoration::ImageDecoration() { | 12 ImageDecoration::ImageDecoration() { |
| 10 } | 13 } |
| 11 | 14 |
| 12 ImageDecoration::~ImageDecoration() { | 15 ImageDecoration::~ImageDecoration() { |
| 13 } | 16 } |
| 14 | 17 |
| 15 NSImage* ImageDecoration::GetImage() { | 18 NSImage* ImageDecoration::GetImage() { |
| 16 return image_; | 19 return image_; |
| 17 } | 20 } |
| 18 | 21 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 31 const CGFloat delta_width = NSWidth(frame) - [image size].width; | 34 const CGFloat delta_width = NSWidth(frame) - [image size].width; |
| 32 const CGFloat x_inset = std::floor(delta_width / 2.0); | 35 const CGFloat x_inset = std::floor(delta_width / 2.0); |
| 33 return NSInsetRect(frame, x_inset, y_inset); | 36 return NSInsetRect(frame, x_inset, y_inset); |
| 34 } | 37 } |
| 35 | 38 |
| 36 CGFloat ImageDecoration::GetWidthForSpace(CGFloat width) { | 39 CGFloat ImageDecoration::GetWidthForSpace(CGFloat width) { |
| 37 NSImage* image = GetImage(); | 40 NSImage* image = GetImage(); |
| 38 if (image) { | 41 if (image) { |
| 39 const CGFloat image_width = [image size].width; | 42 const CGFloat image_width = [image size].width; |
| 40 if (image_width <= width) | 43 if (image_width <= width) |
| 41 return image_width; | 44 return image_width + kImageHorizontalPadding; |
| 42 } | 45 } |
| 43 return kOmittedWidth; | 46 return kOmittedWidth; |
| 44 } | 47 } |
| 45 | 48 |
| 46 void ImageDecoration::DrawInFrame(NSRect frame, NSView* control_view) { | 49 void ImageDecoration::DrawInFrame(NSRect frame, NSView* control_view) { |
| 47 [GetImage() drawInRect:GetDrawRectInFrame(frame) | 50 [GetImage() drawInRect:GetDrawRectInFrame(frame) |
| 48 fromRect:NSZeroRect // Entire image | 51 fromRect:NSZeroRect // Entire image |
| 49 operation:NSCompositeSourceOver | 52 operation:NSCompositeSourceOver |
| 50 fraction:1.0 | 53 fraction:1.0 |
| 51 respectFlipped:YES | 54 respectFlipped:YES |
| 52 hints:nil]; | 55 hints:nil]; |
| 53 } | 56 } |
| OLD | NEW |