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 #ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_DECORATION_H_ 6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_DECORATION_H_ 7 8 #import <Cocoa/Cocoa.h> 9 10 #import "base/basictypes.h" 11 12 class ButtonDecoration; 13 14 // Base class for decorations at the left and right of the location 15 // bar. For instance, the location icon. 16 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. 23 24 class LocationBarDecoration { 25 public: 26 LocationBarDecoration() 27 : visible_(false) { 28 } 29 virtual ~LocationBarDecoration() {} 30 31 // Determines whether the decoration is visible. 32 virtual bool IsVisible() const; 33 virtual void SetVisible(bool visible); 34 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); 39 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); 43 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, 50 NSRect frame, 51 NSView* control_view); 52 53 // Returns the tooltip for this decoration, return |nil| for no tooltip. 54 virtual NSString* GetToolTip(); 55 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(); 62 63 // Determine if the item can act as a drag source. 64 virtual bool IsDraggable(); 65 66 // The image to drag. 67 virtual NSImage* GetDragImage(); 68 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); 74 75 // The pasteboard to drag. 76 virtual NSPasteboard* GetDragPasteboard(); 77 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); 81 82 // Called to get the right-click menu, return |nil| for no menu. 83 virtual NSMenu* GetMenu(); 84 85 // Gets the font used to draw text in the decoration. 86 virtual NSFont* GetFont() const; 87 88 static void DrawLabel(NSString* label, 89 NSDictionary* attributes, 90 const NSRect& frame); 91 static void DrawAttributedString(NSAttributedString* str, 92 const NSRect& frame); 93 static NSSize GetLabelSize(NSString* label, 94 NSDictionary* attributes); 95 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(); 99 100 // Width returned by |GetWidthForSpace()| when the item should be 101 // omitted for this width; 102 static const CGFloat kOmittedWidth; 103 104 private: 105 bool visible_; 106 107 DISALLOW_COPY_AND_ASSIGN(LocationBarDecoration); 108 }; 109 110 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_DECORATION_H_ 111