- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / location_bar / location_bar_decoration.mm
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/location_bar/location_bar_decoration.h"
6
7 #include "base/logging.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
10
11 const CGFloat LocationBarDecoration::kOmittedWidth = 0.0;
12
13 bool LocationBarDecoration::IsVisible() const {
14   return visible_;
15 }
16
17 void LocationBarDecoration::SetVisible(bool visible) {
18   visible_ = visible;
19 }
20
21
22 CGFloat LocationBarDecoration::GetWidthForSpace(CGFloat width) {
23   NOTREACHED();
24   return kOmittedWidth;
25 }
26
27 void LocationBarDecoration::DrawInFrame(NSRect frame, NSView* control_view) {
28   NOTREACHED();
29 }
30
31 void LocationBarDecoration::DrawWithBackgroundInFrame(NSRect background_frame,
32                                                       NSRect frame,
33                                                       NSView* control_view) {
34   // Default to no background.
35   DrawInFrame(frame, control_view);
36 }
37
38 NSString* LocationBarDecoration::GetToolTip() {
39   return nil;
40 }
41
42 bool LocationBarDecoration::AcceptsMousePress() {
43   return false;
44 }
45
46 bool LocationBarDecoration::IsDraggable() {
47   return false;
48 }
49
50 NSImage* LocationBarDecoration::GetDragImage() {
51   return nil;
52 }
53
54 NSRect LocationBarDecoration::GetDragImageFrame(NSRect frame) {
55   return NSZeroRect;
56 }
57
58 NSPasteboard* LocationBarDecoration::GetDragPasteboard() {
59   return nil;
60 }
61
62 bool LocationBarDecoration::OnMousePressed(NSRect frame) {
63   return false;
64 }
65
66 NSMenu* LocationBarDecoration::GetMenu() {
67   return nil;
68 }
69
70 NSFont* LocationBarDecoration::GetFont() const {
71   return OmniboxViewMac::GetFieldFont();
72 }
73
74 // static
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);
81 }
82
83 // static
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];
90 }
91
92 // static
93 NSSize LocationBarDecoration::GetLabelSize(NSString* label,
94                                            NSDictionary* attributes) {
95   return [label sizeWithAttributes:attributes];
96 }
97
98 ButtonDecoration* LocationBarDecoration::AsButtonDecoration() {
99   return NULL;
100 }