OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #import "chrome/browser/cocoa/styled_text_field_cell.h" | 9 #import "chrome/browser/cocoa/styled_text_field_cell.h" |
10 | 10 |
11 #include "base/scoped_nsobject.h" | |
12 | |
13 @class AutocompleteTextField; | 11 @class AutocompleteTextField; |
14 class LocationBarDecoration; | 12 class LocationBarDecoration; |
15 | 13 |
16 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for | 14 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for |
17 // certain decorations to be applied to the field. These are the search hint | 15 // certain decorations to be applied to the field. These are the search hint |
18 // ("Type to search" on the right-hand side), the keyword hint ("Press [Tab] to | 16 // ("Type to search" on the right-hand side), the keyword hint ("Press [Tab] to |
19 // search Engine" on the right-hand side), and keyword mode ("Search Engine:" in | 17 // search Engine" on the right-hand side), and keyword mode ("Search Engine:" in |
20 // a button-like token on the left-hand side). | 18 // a button-like token on the left-hand side). |
21 @interface AutocompleteTextFieldCell : StyledTextFieldCell { | 19 @interface AutocompleteTextFieldCell : StyledTextFieldCell { |
22 @private | 20 @private |
23 // Decorations which live to the left and right of the text, ordered | 21 // Decorations which live to the left and right of the text, ordered |
24 // from outside in. Decorations are owned by |LocationBarViewMac|. | 22 // from outside in. Decorations are owned by |LocationBarViewMac|. |
25 std::vector<LocationBarDecoration*> leftDecorations_; | 23 std::vector<LocationBarDecoration*> leftDecorations_; |
26 std::vector<LocationBarDecoration*> rightDecorations_; | 24 std::vector<LocationBarDecoration*> rightDecorations_; |
27 | |
28 // Set if there is a string to display as a hint on the right-hand | |
29 // side of the field. Exclusive WRT |keywordString_|; | |
30 scoped_nsobject<NSAttributedString> hintString_; | |
31 } | 25 } |
32 | 26 |
33 // Chooses |anImage| only if all pieces won't fit w/in |width|. | |
34 // Inputs must be non-nil. | |
35 - (void)setKeywordHintPrefix:(NSString*)prefixString | |
36 image:(NSImage*)anImage | |
37 suffix:(NSString*)suffixString | |
38 availableWidth:(CGFloat)width; | |
39 | |
40 // Suppresses hint entirely if |aString| won't fit w/in |width|. | |
41 // String must be non-nil. | |
42 - (void)setSearchHintString:(NSString*)aString | |
43 availableWidth:(CGFloat)width; | |
44 - (void)clearHint; | |
45 | |
46 // Clear |leftDecorations_| and |rightDecorations_|. | 27 // Clear |leftDecorations_| and |rightDecorations_|. |
47 - (void)clearDecorations; | 28 - (void)clearDecorations; |
48 | 29 |
49 // Add a new left-side decoration to the right of the existing | 30 // Add a new left-side decoration to the right of the existing |
50 // left-side decorations. | 31 // left-side decorations. |
51 - (void)addLeftDecoration:(LocationBarDecoration*)decoration; | 32 - (void)addLeftDecoration:(LocationBarDecoration*)decoration; |
52 | 33 |
53 // Add a new right-side decoration to the left of the existing | 34 // Add a new right-side decoration to the left of the existing |
54 // right-side decorations. | 35 // right-side decorations. |
55 - (void)addRightDecoration:(LocationBarDecoration*)decoration; | 36 - (void)addRightDecoration:(LocationBarDecoration*)decoration; |
(...skipping 25 matching lines...) Expand all Loading... |
81 - (BOOL)mouseDown:(NSEvent*)theEvent | 62 - (BOOL)mouseDown:(NSEvent*)theEvent |
82 inRect:(NSRect)cellFrame | 63 inRect:(NSRect)cellFrame |
83 ofView:(AutocompleteTextField*)controlView; | 64 ofView:(AutocompleteTextField*)controlView; |
84 | 65 |
85 // Overridden from StyledTextFieldCell to include decorations adjacent | 66 // Overridden from StyledTextFieldCell to include decorations adjacent |
86 // to the text area which don't handle mouse clicks themselves. | 67 // to the text area which don't handle mouse clicks themselves. |
87 // Keyword-search bubble, for instance. | 68 // Keyword-search bubble, for instance. |
88 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame; | 69 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame; |
89 | 70 |
90 @end | 71 @end |
91 | |
92 // Internal methods here exposed for unit testing. | |
93 @interface AutocompleteTextFieldCell (UnitTesting) | |
94 | |
95 @property(nonatomic, readonly) NSAttributedString* hintString; | |
96 @property(nonatomic, readonly) NSAttributedString* hintIconLabel; | |
97 | |
98 @end | |
OLD | NEW |