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.
7 #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h"
9 ImageDecoration::ImageDecoration() {
12 ImageDecoration::~ImageDecoration() {
15 NSImage* ImageDecoration::GetImage() {
19 void ImageDecoration::SetImage(NSImage* image) {
20 image_.reset([image retain]);
23 NSRect ImageDecoration::GetDrawRectInFrame(NSRect frame) {
24 NSImage* image = GetImage();
28 // Center the image within the frame.
29 const CGFloat delta_height = NSHeight(frame) - [image size].height;
30 const CGFloat y_inset = std::floor(delta_height / 2.0);
31 const CGFloat delta_width = NSWidth(frame) - [image size].width;
32 const CGFloat x_inset = std::floor(delta_width / 2.0);
33 return NSInsetRect(frame, x_inset, y_inset);
36 CGFloat ImageDecoration::GetWidthForSpace(CGFloat width) {
37 NSImage* image = GetImage();
39 const CGFloat image_width = [image size].width;
40 if (image_width <= width)
46 void ImageDecoration::DrawInFrame(NSRect frame, NSView* control_view) {
47 [GetImage() drawInRect:GetDrawRectInFrame(frame)
48 fromRect:NSZeroRect // Entire image
49 operation:NSCompositeSourceOver