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 #include "base/scoped_nsobject.h" | 7 #include "base/scoped_nsobject.h" |
| 8 #include "chrome/browser/cocoa/location_bar_view_mac.h" |
8 | 9 |
9 // AutocompleteTextFieldCell customizes the look of the Omnibox text | 10 // AutocompleteTextFieldCell customizes the look of the Omnibox text |
10 // field. The border and focus ring are modified, as is the font | 11 // field. The border and focus ring are modified, as is the font |
11 // baseline. | 12 // baseline. |
12 | 13 |
13 // The cell also provides support for certain decorations to be | 14 // The cell also provides support for certain decorations to be |
14 // applied to the field. These are the search hint ("Type to search" | 15 // 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 // 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 // Engine" on the right-hand side), and keyword mode ("Search Engine:" |
17 // in a button-like token on the left-hand side). | 18 // in a button-like token on the left-hand side). |
18 | 19 |
19 @interface AutocompleteTextFieldCell : NSTextFieldCell { | 20 @interface AutocompleteTextFieldCell : NSTextFieldCell { |
20 @private | 21 @private |
21 // Set if there is a string to display in a rounded rect on the | 22 // Set if there is a string to display in a rounded rect on the |
22 // left-hand side of the field. Exclusive WRT |hintString_|. | 23 // left-hand side of the field. Exclusive WRT |hintString_|. |
23 scoped_nsobject<NSAttributedString> keywordString_; | 24 scoped_nsobject<NSAttributedString> keywordString_; |
24 | 25 |
25 // Set if there is a string to display as a hint on the right-hand | 26 // Set if there is a string to display as a hint on the right-hand |
26 // side of the field. Exclusive WRT |keywordString_|; | 27 // side of the field. Exclusive WRT |keywordString_|; |
27 scoped_nsobject<NSAttributedString> hintString_; | 28 scoped_nsobject<NSAttributedString> hintString_; |
28 | 29 |
29 // Icon that represents the state of the SSL connection | 30 // View showing the state of the SSL connection. Owned by the location bar. |
30 scoped_nsobject<NSImage> hintIcon_; | 31 // Display is exclusive WRT the |hintString_| and |keywordString_|. |
31 | 32 // This may be NULL during testing. |
32 // Optional text that appears to the right of the hint icon which | 33 LocationBarViewMac::SecurityImageView* security_image_view_; |
33 // appears only alongside the icon (i.e., it's possible to display a | |
34 // hintIcon without an hintIconLabel, but not vice-versa). | |
35 scoped_nsobject<NSAttributedString> hintIconLabel_; | |
36 } | 34 } |
37 | 35 |
38 // Chooses |partialString| if |width| won't fit |fullString|. Strings | 36 // Chooses |partialString| if |width| won't fit |fullString|. Strings |
39 // must be non-nil. | 37 // must be non-nil. |
40 - (void)setKeywordString:(NSString*)fullString | 38 - (void)setKeywordString:(NSString*)fullString |
41 partialString:(NSString*)partialString | 39 partialString:(NSString*)partialString |
42 availableWidth:(CGFloat)width; | 40 availableWidth:(CGFloat)width; |
43 | 41 |
44 // Chooses |anImage| only if all pieces won't fit w/in |width|. | 42 // Chooses |anImage| only if all pieces won't fit w/in |width|. |
45 // Inputs must be non-nil. | 43 // Inputs must be non-nil. |
46 - (void)setKeywordHintPrefix:(NSString*)prefixString | 44 - (void)setKeywordHintPrefix:(NSString*)prefixString |
47 image:(NSImage*)anImage | 45 image:(NSImage*)anImage |
48 suffix:(NSString*)suffixString | 46 suffix:(NSString*)suffixString |
49 availableWidth:(CGFloat)width; | 47 availableWidth:(CGFloat)width; |
50 | 48 |
51 // Suppresses hint entirely if |aString| won't fit w/in |width|. | 49 // Suppresses hint entirely if |aString| won't fit w/in |width|. |
52 // String must be non-nil. | 50 // String must be non-nil. |
53 - (void)setSearchHintString:(NSString*)aString | 51 - (void)setSearchHintString:(NSString*)aString |
54 availableWidth:(CGFloat)width; | 52 availableWidth:(CGFloat)width; |
55 - (void)clearKeywordAndHint; | 53 - (void)clearKeywordAndHint; |
56 | 54 |
57 // Sets the hint icon and optional icon label. If |icon| is nil, the current | 55 - (void)setSecurityImageView:(LocationBarViewMac::SecurityImageView*)view; |
58 // icon is cleared. If |label| is provided, |color| must be provided as well. | 56 |
59 - (void)setHintIcon:(NSImage*)icon label:(NSString*)label color:(NSColor*)color; | 57 // Called when the security icon is visible and clicked. Passed through to the |
| 58 // security_image_view_ to handle the click (i.e., show the page info dialog). |
| 59 - (void)onSecurityIconMousePressed; |
60 | 60 |
61 // Return the portion of the cell to show the text cursor over. | 61 // Return the portion of the cell to show the text cursor over. |
62 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame; | 62 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame; |
63 | 63 |
64 // Return the portion of the cell to use for text display. This | 64 // Return the portion of the cell to use for text display. This |
65 // corresponds to the frame with our added decorations sliced off. | 65 // corresponds to the frame with our added decorations sliced off. |
66 - (NSRect)textFrameForFrame:(NSRect)cellFrame; | 66 - (NSRect)textFrameForFrame:(NSRect)cellFrame; |
67 | 67 |
68 // Return the portion of the cell to use for displaing the |hintIcon_|. | 68 // Return the portion of the cell to use for displaying the security (SSL lock) |
69 - (NSRect)hintImageFrameForFrame:(NSRect)cellFrame; | 69 // icon, leaving space for its label if any. |
| 70 - (NSRect)securityImageFrameForFrame:(NSRect)cellFrame; |
70 | 71 |
71 @end | 72 @end |
72 | 73 |
73 // Internal methods here exposed for unit testing. | 74 // Internal methods here exposed for unit testing. |
74 @interface AutocompleteTextFieldCell (UnitTesting) | 75 @interface AutocompleteTextFieldCell (UnitTesting) |
75 | 76 |
76 @property(readonly) NSAttributedString* keywordString; | 77 @property(readonly) NSAttributedString* keywordString; |
77 @property(readonly) NSAttributedString* hintString; | 78 @property(readonly) NSAttributedString* hintString; |
78 @property(readonly) NSImage* hintIcon; | |
79 @property(readonly) NSAttributedString* hintIconLabel; | 79 @property(readonly) NSAttributedString* hintIconLabel; |
80 | 80 |
81 @end | 81 @end |
OLD | NEW |