OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 // A cell that draws the autocomplete field. | 7 #include "base/scoped_nsobject.h" |
| 8 |
| 9 // AutocompleteTextFieldCell customizes the look of the Omnibox text |
| 10 // field. The border and focus ring are modified, as is the font |
| 11 // baseline. |
| 12 |
| 13 // The cell also provides support for certain decorations to be |
| 14 // applied to the field. These are the search hint ("Type to search" |
| 15 // on the right-hand side), the keyword hint ("Press [Tab] to search |
| 16 // Engine" on the right-hand side), and keyword mode ("Search Engine:" |
| 17 // in a button-like token on the left-hand side). |
| 18 // |
| 19 // The cell arranges the field-editor's placement via the standard |
| 20 // -editWithFrame:* and -selectWithFrame:* methods. When the visible |
| 21 // decoration changes, the cell's look may change, and if the cell is |
| 22 // currently being edited the field editor will require adjustment. |
| 23 // The cell signals this requirement by returning YES for |
| 24 // -fieldEditorNeedsReset, which is used by AutocompleteTextField's |
| 25 // -resetFieldEditorFrameIfNeeded in testing if re-layout is needed. |
8 | 26 |
9 @interface AutocompleteTextFieldCell : NSTextFieldCell { | 27 @interface AutocompleteTextFieldCell : NSTextFieldCell { |
| 28 @private |
| 29 // Set if there is a string to display in a rounded rect on the |
| 30 // left-hand side of the field. Exclusive WRT |hintString_|. |
| 31 scoped_nsobject<NSAttributedString> keywordString_; |
| 32 |
| 33 // Set if there is a string to display as a hint on the right-hand |
| 34 // side of the field. Exclusive WRT |keywordString_|; |
| 35 scoped_nsobject<NSAttributedString> hintString_; |
| 36 |
| 37 // YES if the info cell has been changed in a way which would result |
| 38 // in the cell needing to be laid out again. |
| 39 BOOL fieldEditorNeedsReset_; |
10 } | 40 } |
| 41 |
| 42 @property BOOL fieldEditorNeedsReset; |
| 43 |
| 44 // TODO(shess): There should be two alternatives for |
| 45 // -setKeywordString:, the normal string and the min string. Min can |
| 46 // be used when the text field's contents gets too wide to fit both it |
| 47 // and this. |
| 48 |
| 49 // The following setup |keywordString_| or |hintString_| based on the |
| 50 // input, and set |fieldEditorNeedsReset_| if the layout of the field |
| 51 // changed. |
| 52 - (void)setKeywordString:(NSString*)aString; |
| 53 - (void)setKeywordHintPrefix:(NSString*)prefixString |
| 54 image:(NSImage*)anImage |
| 55 suffix:(NSString*)suffixString; |
| 56 - (void)setSearchHintString:(NSString*)aString; |
| 57 - (void)clearKeywordAndHint; |
| 58 |
11 @end | 59 @end |
| 60 |
| 61 // Internal methods here exposed for unit testing. |
| 62 @interface AutocompleteTextFieldCell (UnitTesting) |
| 63 |
| 64 @property(readonly) NSAttributedString* keywordString; |
| 65 @property(readonly) NSAttributedString* hintString; |
| 66 |
| 67 // Return the portion of the cell to use for text display. |
| 68 - (NSRect)textFrameForFrame:(NSRect)cellFrame; |
| 69 |
| 70 @end |
OLD | NEW |