- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / location_bar / autocomplete_text_field_cell.h
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 #include <vector>
6
7 #import <Cocoa/Cocoa.h>
8
9 #import "chrome/browser/ui/cocoa/styled_text_field_cell.h"
10
11 @class AutocompleteTextField;
12 class LocationBarDecoration;
13
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 {
20  @private
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_;
25
26   // If YES then the text field will not draw a focus ring or show the insertion
27   // pointer.
28   BOOL hideFocusState_;
29
30   // YES if this field is shown in a popup window.
31   BOOL isPopupMode_;
32 }
33
34 @property(assign, nonatomic) BOOL isPopupMode;
35
36 // Line height used for text in this cell.
37 - (CGFloat)lineHeight;
38
39 // Clear |leftDecorations_| and |rightDecorations_|.
40 - (void)clearDecorations;
41
42 // Add a new left-side decoration to the right of the existing
43 // left-side decorations.
44 - (void)addLeftDecoration:(LocationBarDecoration*)decoration;
45
46 // Add a new right-side decoration to the left of the existing
47 // right-side decorations.
48 - (void)addRightDecoration:(LocationBarDecoration*)decoration;
49
50 // The width available after accounting for decorations.
51 - (CGFloat)availableWidthInFrame:(const NSRect)frame;
52
53 // Return the frame for |aDecoration| if the cell is in |cellFrame|.
54 // Returns |NSZeroRect| for decorations which are not currently
55 // visible.
56 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration
57                      inFrame:(NSRect)cellFrame;
58
59 // Find the decoration under the event.  |NULL| if |theEvent| is not
60 // over anything.
61 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent
62                                       inRect:(NSRect)cellFrame
63                                       ofView:(AutocompleteTextField*)field;
64
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;
71
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;
77
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;
84
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;
89
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;
94
95 // Setup decoration tooltips on |controlView| by calling
96 // |-addToolTip:forRect:|.
97 - (void)updateToolTipsInRect:(NSRect)cellFrame
98                       ofView:(AutocompleteTextField*)controlView;
99
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;
105
106 @end