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.
5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h"
7 #include "base/logging.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
11 const CGFloat LocationBarDecoration::kOmittedWidth = 0.0;
13 bool LocationBarDecoration::IsVisible() const {
17 void LocationBarDecoration::SetVisible(bool visible) {
22 CGFloat LocationBarDecoration::GetWidthForSpace(CGFloat width) {
27 void LocationBarDecoration::DrawInFrame(NSRect frame, NSView* control_view) {
31 void LocationBarDecoration::DrawWithBackgroundInFrame(NSRect background_frame,
33 NSView* control_view) {
34 // Default to no background.
35 DrawInFrame(frame, control_view);
38 NSString* LocationBarDecoration::GetToolTip() {
42 bool LocationBarDecoration::AcceptsMousePress() {
46 bool LocationBarDecoration::IsDraggable() {
50 NSImage* LocationBarDecoration::GetDragImage() {
54 NSRect LocationBarDecoration::GetDragImageFrame(NSRect frame) {
58 NSPasteboard* LocationBarDecoration::GetDragPasteboard() {
62 bool LocationBarDecoration::OnMousePressed(NSRect frame) {
66 NSMenu* LocationBarDecoration::GetMenu() {
70 NSFont* LocationBarDecoration::GetFont() const {
71 return OmniboxViewMac::GetFieldFont();
75 void LocationBarDecoration::DrawLabel(NSString* label,
76 NSDictionary* attributes,
77 const NSRect& frame) {
78 base::scoped_nsobject<NSAttributedString> str(
79 [[NSAttributedString alloc] initWithString:label attributes:attributes]);
80 DrawAttributedString(str, frame);
84 void LocationBarDecoration::DrawAttributedString(NSAttributedString* str,
85 const NSRect& frame) {
86 NSRect text_rect = frame;
87 text_rect.size.height = [str size].height;
88 text_rect.origin.y = roundf(NSMidY(frame) - NSHeight(text_rect) / 2.0) - 1;
89 [str drawInRect:text_rect];
93 NSSize LocationBarDecoration::GetLabelSize(NSString* label,
94 NSDictionary* attributes) {
95 return [label sizeWithAttributes:attributes];
98 ButtonDecoration* LocationBarDecoration::AsButtonDecoration() {