| OLD | NEW |
| 1 // Copyright (c) 2009 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #import "chrome/browser/cocoa/styled_text_field_cell.h" | 7 #import "chrome/browser/cocoa/styled_text_field_cell.h" |
| 8 | 8 |
| 9 #include "base/scoped_nsobject.h" | 9 #include "base/scoped_nsobject.h" |
| 10 #include "chrome/browser/cocoa/location_bar_view_mac.h" | 10 #include "chrome/browser/cocoa/location_bar_view_mac.h" |
| 11 | 11 |
| 12 class ExtensionAction; | 12 class ExtensionAction; |
| 13 | 13 |
| 14 // Holds a |LocationBarImageView| and its current rect. Do not keep references |
| 15 // to this object, only use it directly after calling |-layedOutIcons:|. |
| 16 @interface AutocompleteTextFieldIcon : NSObject { |
| 17 // The frame rect of |view_|. |
| 18 NSRect rect_; |
| 19 |
| 20 // weak, owned by LocationBarViewMac. |
| 21 LocationBarViewMac::LocationBarImageView* view_; |
| 22 } |
| 23 |
| 24 // Returns a new AutocompleteTextFieldIcon object. |
| 25 + (AutocompleteTextFieldIcon*) |
| 26 iconWithRect:(NSRect)rect |
| 27 view:(LocationBarViewMac::LocationBarImageView*)view; |
| 28 @property(assign, nonatomic) NSRect rect; |
| 29 @property(assign, nonatomic) LocationBarViewMac::LocationBarImageView* view; |
| 30 @end |
| 31 |
| 14 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for | 32 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for |
| 15 // certain decorations to be applied to the field. These are the search hint | 33 // 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 | 34 // ("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 | 35 // search Engine" on the right-hand side), and keyword mode ("Search Engine:" in |
| 18 // a button-like token on the left-hand side). | 36 // a button-like token on the left-hand side). |
| 19 @interface AutocompleteTextFieldCell : StyledTextFieldCell { | 37 @interface AutocompleteTextFieldCell : StyledTextFieldCell { |
| 20 @private | 38 @private |
| 21 // Set if there is a string to display in a rounded rect on the | 39 // Set if there is a string to display in a rounded rect on the |
| 22 // left-hand side of the field. Exclusive WRT |hintString_|. | 40 // left-hand side of the field. Exclusive WRT |hintString_|. |
| 23 scoped_nsobject<NSAttributedString> keywordString_; | 41 scoped_nsobject<NSAttributedString> keywordString_; |
| 24 | 42 |
| 25 // Set if there is a string to display as a hint on the right-hand | 43 // Set if there is a string to display as a hint on the right-hand |
| 26 // side of the field. Exclusive WRT |keywordString_|; | 44 // side of the field. Exclusive WRT |keywordString_|; |
| 27 scoped_nsobject<NSAttributedString> hintString_; | 45 scoped_nsobject<NSAttributedString> hintString_; |
| 28 | 46 |
| 29 // View showing the state of the SSL connection. Owned by the location bar. | 47 // View showing the state of the SSL connection. Owned by the location bar. |
| 30 // Display is exclusive WRT the |hintString_| and |keywordString_|. | 48 // Display is exclusive WRT the |hintString_| and |keywordString_|. |
| 31 // This may be NULL during testing. | 49 // This may be NULL during testing. |
| 32 LocationBarViewMac::SecurityImageView* security_image_view_; | 50 LocationBarViewMac::SecurityImageView* security_image_view_; |
| 33 | 51 |
| 34 // List of views showing visible Page Actions. Owned by the location bar. | 52 // List of views showing visible Page Actions. Owned by the location bar. |
| 35 // Display is exclusive WRT the |hintString_| and |keywordString_|. | 53 // Display is exclusive WRT the |hintString_| and |keywordString_|. |
| 36 // This may be NULL during testing. | 54 // This may be NULL during testing. |
| 37 LocationBarViewMac::PageActionViewList* page_action_views_; | 55 LocationBarViewMac::PageActionViewList* page_action_views_; |
| 56 |
| 57 // List of content blocked icons. This may be NULL during testing. |
| 58 LocationBarViewMac::ContentBlockedViews* content_blocked_views_; |
| 38 } | 59 } |
| 39 | 60 |
| 40 // Chooses |partialString| if |width| won't fit |fullString|. Strings | 61 // Chooses |partialString| if |width| won't fit |fullString|. Strings |
| 41 // must be non-nil. | 62 // must be non-nil. |
| 42 - (void)setKeywordString:(NSString*)fullString | 63 - (void)setKeywordString:(NSString*)fullString |
| 43 partialString:(NSString*)partialString | 64 partialString:(NSString*)partialString |
| 44 availableWidth:(CGFloat)width; | 65 availableWidth:(CGFloat)width; |
| 45 | 66 |
| 46 // Chooses |anImage| only if all pieces won't fit w/in |width|. | 67 // Chooses |anImage| only if all pieces won't fit w/in |width|. |
| 47 // Inputs must be non-nil. | 68 // Inputs must be non-nil. |
| 48 - (void)setKeywordHintPrefix:(NSString*)prefixString | 69 - (void)setKeywordHintPrefix:(NSString*)prefixString |
| 49 image:(NSImage*)anImage | 70 image:(NSImage*)anImage |
| 50 suffix:(NSString*)suffixString | 71 suffix:(NSString*)suffixString |
| 51 availableWidth:(CGFloat)width; | 72 availableWidth:(CGFloat)width; |
| 52 | 73 |
| 53 // Suppresses hint entirely if |aString| won't fit w/in |width|. | 74 // Suppresses hint entirely if |aString| won't fit w/in |width|. |
| 54 // String must be non-nil. | 75 // String must be non-nil. |
| 55 - (void)setSearchHintString:(NSString*)aString | 76 - (void)setSearchHintString:(NSString*)aString |
| 56 availableWidth:(CGFloat)width; | 77 availableWidth:(CGFloat)width; |
| 57 - (void)clearKeywordAndHint; | 78 - (void)clearKeywordAndHint; |
| 58 | 79 |
| 59 - (void)setSecurityImageView:(LocationBarViewMac::SecurityImageView*)view; | 80 - (void)setSecurityImageView:(LocationBarViewMac::SecurityImageView*)view; |
| 60 - (void)setPageActionViewList:(LocationBarViewMac::PageActionViewList*)list; | 81 - (void)setPageActionViewList:(LocationBarViewMac::PageActionViewList*)list; |
| 82 - (void)setContentBlockedViewList: |
| 83 (LocationBarViewMac::ContentBlockedViews*)views; |
| 61 | 84 |
| 62 // Returns the total number of installed Page Actions, visible or not. | 85 // Returns an array of the visible AutocompleteTextFieldIcon objects. Returns |
| 63 - (size_t)pageActionCount; | 86 // only visible icons. |
| 87 - (NSArray*)layedOutIcons:(NSRect)cellFrame; |
| 64 | 88 |
| 65 // Called when the security icon is visible and clicked. Passed through to the | |
| 66 // security_image_view_ to handle the click (i.e., show the page info dialog). | |
| 67 - (void)onSecurityIconMousePressed; | |
| 68 | |
| 69 // Returns the portion of the cell to use for displaying the security (SSL lock) | |
| 70 // icon, leaving space for its label if any. | |
| 71 - (NSRect)securityImageFrameForFrame:(NSRect)cellFrame; | |
| 72 | 89 |
| 73 // Returns the portion of the cell to use for displaying the Page Action icon | 90 // Returns the portion of the cell to use for displaying the Page Action icon |
| 74 // at the given index. May be NSZeroRect if the index's action is not visible. | 91 // at the given index. May be NSZeroRect if the index's action is not visible. |
| 92 // This does a linear walk over all page actions, so do not call this in a loop |
| 93 // to get the position of all page actions. Use |-layedOutIcons:| instead in tha
t |
| 94 // case. |
| 75 - (NSRect)pageActionFrameForIndex:(size_t)index inFrame:(NSRect)cellFrame; | 95 - (NSRect)pageActionFrameForIndex:(size_t)index inFrame:(NSRect)cellFrame; |
| 76 | 96 |
| 77 // Returns the string to be shown on hover for the Page Action icon at the | |
| 78 // given index. | |
| 79 - (NSString*)pageActionToolTipForIndex:(size_t)index; | |
| 80 | |
| 81 // Returns a pointer to the ExtensionAction object that the view at the | |
| 82 // specified index represents. | |
| 83 - (ExtensionAction*)pageActionForIndex:(size_t)index; | |
| 84 | |
| 85 // Called when the Page Action at the given index, whose icon is drawn in the | |
| 86 // iconFrame, is visible and clicked. Passed through to the list of views to | |
| 87 // handle the click. | |
| 88 - (void)onPageActionMousePressedIn:(NSRect)iconFrame forIndex:(size_t)index; | |
| 89 | 97 |
| 90 @end | 98 @end |
| 91 | 99 |
| 92 // Internal methods here exposed for unit testing. | 100 // Internal methods here exposed for unit testing. |
| 93 @interface AutocompleteTextFieldCell (UnitTesting) | 101 @interface AutocompleteTextFieldCell (UnitTesting) |
| 94 | 102 |
| 95 @property(readonly) NSAttributedString* keywordString; | 103 @property(readonly) NSAttributedString* keywordString; |
| 96 @property(readonly) NSAttributedString* hintString; | 104 @property(readonly) NSAttributedString* hintString; |
| 97 @property(readonly) NSAttributedString* hintIconLabel; | 105 @property(readonly) NSAttributedString* hintIconLabel; |
| 98 | 106 |
| 107 // Returns the total number of installed Page Actions, visible or not. |
| 108 - (size_t)pageActionCount; |
| 109 |
| 110 // Returns the portion of the cell to use for displaying the security (SSL lock) |
| 111 // icon, leaving space for its label if any. |
| 112 - (NSRect)securityImageFrameForFrame:(NSRect)cellFrame; |
| 113 |
| 99 @end | 114 @end |
| OLD | NEW |