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 #ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_DECORATION_H_
6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_DECORATION_H_
8 #import <Cocoa/Cocoa.h>
10 #import "base/basictypes.h"
12 class ButtonDecoration;
14 // Base class for decorations at the left and right of the location
15 // bar. For instance, the location icon.
17 // |LocationBarDecoration| and subclasses should approximately
18 // parallel the classes provided under views/location_bar/. The term
19 // "decoration" is used because "view" has strong connotations in
20 // Cocoa, and while these are view-like, they aren't views at all.
21 // Decorations are more like Cocoa cells, except implemented in C++ to
22 // allow more similarity to the other platform implementations.
24 class LocationBarDecoration {
26 LocationBarDecoration()
29 virtual ~LocationBarDecoration() {}
31 // Determines whether the decoration is visible.
32 virtual bool IsVisible() const;
33 virtual void SetVisible(bool visible);
35 // Decorations can change their size to fit the available space.
36 // Returns the width the decoration will use in the space allotted,
37 // or |kOmittedWidth| if it should be omitted.
38 virtual CGFloat GetWidthForSpace(CGFloat width);
40 // Draw the decoration in the frame provided. The frame will be
41 // generated from an earlier call to |GetWidthForSpace()|.
42 virtual void DrawInFrame(NSRect frame, NSView* control_view);
44 // Draw the decoration in the frame provided, possibly including a
45 // background that fills |background_frame|. The frame will be
46 // generated from an earlier call to |GetWidthForSpace()|, and the
47 // |background_frame| will include the column of pixels exactly
48 // between two decorations.
49 virtual void DrawWithBackgroundInFrame(NSRect background_frame,
51 NSView* control_view);
53 // Returns the tooltip for this decoration, return |nil| for no tooltip.
54 virtual NSString* GetToolTip();
56 // Decorations which do not accept mouse events are treated like the
57 // field's background for purposes of selecting text. When such
58 // decorations are adjacent to the text area, they will show the
59 // I-beam cursor. Decorations which do accept mouse events will get
60 // an arrow cursor when the mouse is over them.
61 virtual bool AcceptsMousePress();
63 // Determine if the item can act as a drag source.
64 virtual bool IsDraggable();
67 virtual NSImage* GetDragImage();
69 // Return the place within the decoration's frame where the
70 // |GetDragImage()| comes from. This is used to make sure the image
71 // appears correctly under the mouse while dragging. |frame|
72 // matches the frame passed to |DrawInFrame()|.
73 virtual NSRect GetDragImageFrame(NSRect frame);
75 // The pasteboard to drag.
76 virtual NSPasteboard* GetDragPasteboard();
78 // Called on mouse down. Return |false| to indicate that the press
79 // was not processed and should be handled by the cell.
80 virtual bool OnMousePressed(NSRect frame);
82 // Called to get the right-click menu, return |nil| for no menu.
83 virtual NSMenu* GetMenu();
85 // Gets the font used to draw text in the decoration.
86 virtual NSFont* GetFont() const;
88 static void DrawLabel(NSString* label,
89 NSDictionary* attributes,
91 static void DrawAttributedString(NSAttributedString* str,
93 static NSSize GetLabelSize(NSString* label,
94 NSDictionary* attributes);
96 // Returns the current |LocationBarDecoration| as a |ButtonDecoration|, if it
97 // inherits from that class (i.e. if it needs to act as a button).
98 virtual ButtonDecoration* AsButtonDecoration();
100 // Width returned by |GetWidthForSpace()| when the item should be
101 // omitted for this width;
102 static const CGFloat kOmittedWidth;
107 DISALLOW_COPY_AND_ASSIGN(LocationBarDecoration);
110 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_DECORATION_H_