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 <Cocoa/Cocoa.h>
9 #import "chrome/browser/ui/cocoa/styled_text_field_cell.h"
11 @class AutocompleteTextField;
12 class LocationBarDecoration;
14 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for
15 // certain decorations to be applied to the field. These are the search hint
16 // ("Type to search" on the right-hand side), the keyword hint ("Press [Tab] to
17 // search Engine" on the right-hand side), and keyword mode ("Search Engine:" in
18 // a button-like token on the left-hand side).
19 @interface AutocompleteTextFieldCell : StyledTextFieldCell {
21 // Decorations which live to the left and right of the text, ordered
22 // from outside in. Decorations are owned by |LocationBarViewMac|.
23 std::vector<LocationBarDecoration*> leftDecorations_;
24 std::vector<LocationBarDecoration*> rightDecorations_;
26 // If YES then the text field will not draw a focus ring or show the insertion
30 // YES if this field is shown in a popup window.
34 @property(assign, nonatomic) BOOL isPopupMode;
36 // Line height used for text in this cell.
37 - (CGFloat)lineHeight;
39 // Clear |leftDecorations_| and |rightDecorations_|.
40 - (void)clearDecorations;
42 // Add a new left-side decoration to the right of the existing
43 // left-side decorations.
44 - (void)addLeftDecoration:(LocationBarDecoration*)decoration;
46 // Add a new right-side decoration to the left of the existing
47 // right-side decorations.
48 - (void)addRightDecoration:(LocationBarDecoration*)decoration;
50 // The width available after accounting for decorations.
51 - (CGFloat)availableWidthInFrame:(const NSRect)frame;
53 // Return the frame for |aDecoration| if the cell is in |cellFrame|.
54 // Returns |NSZeroRect| for decorations which are not currently
56 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration
57 inFrame:(NSRect)cellFrame;
59 // Find the decoration under the event. |NULL| if |theEvent| is not
61 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent
62 inRect:(NSRect)cellFrame
63 ofView:(AutocompleteTextField*)field;
65 // Return the appropriate menu for any decorations under event.
66 // Returns nil if no menu is present for the decoration, or if the
67 // event is not over a decoration.
68 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent
69 inRect:(NSRect)cellFrame
70 ofView:(AutocompleteTextField*)controlView;
72 // Called by |AutocompleteTextField| to let page actions intercept
73 // clicks. Returns |YES| if the click has been intercepted.
74 - (BOOL)mouseDown:(NSEvent*)theEvent
75 inRect:(NSRect)cellFrame
76 ofView:(AutocompleteTextField*)controlView;
78 // These messages are passed down from the AutocompleteTextField, where they are
79 // received from tracking areas registered for decorations that act as buttons.
80 - (void)mouseEntered:(NSEvent*)theEvent
81 inView:(AutocompleteTextField*)controlView;
82 - (void)mouseExited:(NSEvent*)theEvent
83 inView:(AutocompleteTextField*)controlView;
85 // Setup tracking areas for the decorations that are part of this cell, so they
86 // can receive |mouseEntered:| and |mouseExited:| events.
87 - (void)setUpTrackingAreasInRect:(NSRect)frame
88 ofView:(AutocompleteTextField*)view;
90 // Overridden from StyledTextFieldCell to include decorations adjacent
91 // to the text area which don't handle mouse clicks themselves.
92 // Keyword-search bubble, for instance.
93 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame;
95 // Setup decoration tooltips on |controlView| by calling
96 // |-addToolTip:forRect:|.
97 - (void)updateToolTipsInRect:(NSRect)cellFrame
98 ofView:(AutocompleteTextField*)controlView;
100 // Gets and sets |hideFocusState|. This allows the text field to have focus but
101 // to appear unfocused.
102 - (BOOL)hideFocusState;
103 - (void)setHideFocusState:(BOOL)hideFocusState
104 ofView:(AutocompleteTextField*)controlView;