| 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 #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 | 14 // Holds a |LocationBarImageView| and its current rect. Do not keep references |
| 15 // to this object, only use it directly after calling |-layedOutIcons:|. | 15 // to this object, only use it directly after calling |-layedOutIcons:|. |
| 16 // TODO(shess): This class is basically a helper for laying out the |
| 17 // icons. Try to refactor it away. If that is not reasonable, at |
| 18 // least split the image and label cases into subclasses once the |
| 19 // Omnibox stuff is settled. |
| 16 @interface AutocompleteTextFieldIcon : NSObject { | 20 @interface AutocompleteTextFieldIcon : NSObject { |
| 21 // YES to draw the label part of |view_|, otherwise draw the image |
| 22 // part. |
| 23 BOOL isLabel_; |
| 24 |
| 17 // The frame rect of |view_|. | 25 // The frame rect of |view_|. |
| 18 NSRect rect_; | 26 NSRect rect_; |
| 19 | 27 |
| 20 // weak, owned by LocationBarViewMac. | 28 // weak, owned by LocationBarViewMac. |
| 21 LocationBarViewMac::LocationBarImageView* view_; | 29 LocationBarViewMac::LocationBarImageView* view_; |
| 22 } | 30 } |
| 23 | 31 |
| 24 // Returns a new AutocompleteTextFieldIcon object. | |
| 25 + (AutocompleteTextFieldIcon*) | |
| 26 iconWithRect:(NSRect)rect | |
| 27 view:(LocationBarViewMac::LocationBarImageView*)view; | |
| 28 @property(assign, nonatomic) NSRect rect; | 32 @property(assign, nonatomic) NSRect rect; |
| 29 @property(assign, nonatomic) LocationBarViewMac::LocationBarImageView* view; | 33 @property(assign, nonatomic) LocationBarViewMac::LocationBarImageView* view; |
| 34 |
| 35 - (id)initImageWithView:(LocationBarViewMac::LocationBarImageView*)view; |
| 36 - (id)initLabelWithView:(LocationBarViewMac::LocationBarImageView*)view; |
| 37 |
| 38 // Position |view_| right-justified in |frame|. |
| 39 - (void)positionInFrame:(NSRect)frame; |
| 40 |
| 41 // Draw image or label of |view_| in |rect_| within |controlView|. |
| 42 // Only call after |-positionInFrame:| has set |rect_| (or after an |
| 43 // explicit |-setRect:|). |
| 44 - (void)drawInView:(NSView*)controlView; |
| 45 |
| 30 @end | 46 @end |
| 31 | 47 |
| 32 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for | 48 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for |
| 33 // certain decorations to be applied to the field. These are the search hint | 49 // certain decorations to be applied to the field. These are the search hint |
| 34 // ("Type to search" on the right-hand side), the keyword hint ("Press [Tab] to | 50 // ("Type to search" on the right-hand side), the keyword hint ("Press [Tab] to |
| 35 // search Engine" on the right-hand side), and keyword mode ("Search Engine:" in | 51 // search Engine" on the right-hand side), and keyword mode ("Search Engine:" in |
| 36 // a button-like token on the left-hand side). | 52 // a button-like token on the left-hand side). |
| 37 @interface AutocompleteTextFieldCell : StyledTextFieldCell { | 53 @interface AutocompleteTextFieldCell : StyledTextFieldCell { |
| 38 @private | 54 @private |
| 39 // Set if there is a string to display in a rounded rect on the | 55 // Set if there is a string to display in a rounded rect on the |
| 40 // left-hand side of the field. Exclusive WRT |hintString_|. | 56 // left-hand side of the field. Exclusive WRT |hintString_|. |
| 41 scoped_nsobject<NSAttributedString> keywordString_; | 57 scoped_nsobject<NSAttributedString> keywordString_; |
| 42 | 58 |
| 43 // Set if there is a string to display as a hint on the right-hand | 59 // Set if there is a string to display as a hint on the right-hand |
| 44 // side of the field. Exclusive WRT |keywordString_|; | 60 // side of the field. Exclusive WRT |keywordString_|; |
| 45 scoped_nsobject<NSAttributedString> hintString_; | 61 scoped_nsobject<NSAttributedString> hintString_; |
| 46 | 62 |
| 47 // View showing an icon matching the current text. Owned by the location bar. | 63 // The location icon sits at the left-hand side of the field. |
| 48 // Exclusive WRT |keywordString_|. This may be NULL during testing. | 64 // |keywordString_| overrides. |
| 49 LocationBarViewMac::LocationIconView* location_icon_view_; | 65 LocationBarViewMac::LocationIconView* locationIconView_; |
| 66 |
| 67 // The security label floats to the left of page actions at the |
| 68 // right-hand side. |
| 69 LocationBarViewMac::LocationBarImageView* securityLabelView_; |
| 50 | 70 |
| 51 // List of views showing visible Page Actions. Owned by the location bar. | 71 // List of views showing visible Page Actions. Owned by the location bar. |
| 52 // Display is exclusive WRT the |hintString_| and |keywordString_|. | 72 // Display is exclusive WRT the |hintString_| and |keywordString_|. |
| 53 // This may be NULL during testing. | 73 // This may be NULL during testing. |
| 54 LocationBarViewMac::PageActionViewList* page_action_views_; | 74 LocationBarViewMac::PageActionViewList* page_action_views_; |
| 55 | 75 |
| 56 // List of content blocked icons. This may be NULL during testing. | 76 // List of content blocked icons. This may be NULL during testing. |
| 57 LocationBarViewMac::ContentSettingViews* content_setting_views_; | 77 LocationBarViewMac::ContentSettingViews* content_setting_views_; |
| 58 } | 78 } |
| 59 | 79 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 70 suffix:(NSString*)suffixString | 90 suffix:(NSString*)suffixString |
| 71 availableWidth:(CGFloat)width; | 91 availableWidth:(CGFloat)width; |
| 72 | 92 |
| 73 // Suppresses hint entirely if |aString| won't fit w/in |width|. | 93 // Suppresses hint entirely if |aString| won't fit w/in |width|. |
| 74 // String must be non-nil. | 94 // String must be non-nil. |
| 75 - (void)setSearchHintString:(NSString*)aString | 95 - (void)setSearchHintString:(NSString*)aString |
| 76 availableWidth:(CGFloat)width; | 96 availableWidth:(CGFloat)width; |
| 77 - (void)clearKeywordAndHint; | 97 - (void)clearKeywordAndHint; |
| 78 | 98 |
| 79 - (void)setLocationIconView:(LocationBarViewMac::LocationIconView*)view; | 99 - (void)setLocationIconView:(LocationBarViewMac::LocationIconView*)view; |
| 100 - (void)setSecurityLabelView:(LocationBarViewMac::LocationBarImageView*)view; |
| 80 - (void)setPageActionViewList:(LocationBarViewMac::PageActionViewList*)list; | 101 - (void)setPageActionViewList:(LocationBarViewMac::PageActionViewList*)list; |
| 81 - (void)setContentSettingViewsList: | 102 - (void)setContentSettingViewsList: |
| 82 (LocationBarViewMac::ContentSettingViews*)views; | 103 (LocationBarViewMac::ContentSettingViews*)views; |
| 83 | 104 |
| 84 // Returns an array of the visible AutocompleteTextFieldIcon objects. Returns | 105 // Returns an array of the visible AutocompleteTextFieldIcon objects. Returns |
| 85 // only visible icons. | 106 // only visible icons. |
| 86 - (NSArray*)layedOutIcons:(NSRect)cellFrame; | 107 - (NSArray*)layedOutIcons:(NSRect)cellFrame; |
| 87 | 108 |
| 109 // Returns the portion of the cell to use for displaying the Page |
| 110 // Action icon at the given index. May be NSZeroRect if the index's |
| 111 // action is not visible. This does a linear walk over all page |
| 112 // actions, so do not call this in a loop to get the position of all |
| 113 // page actions. Use |-layedOutIcons:| instead in that case. |
| 114 - (NSRect)pageActionFrameForIndex:(size_t)index inFrame:(NSRect)cellFrame; |
| 88 | 115 |
| 89 // Returns the portion of the cell to use for displaying the Page Action icon | 116 // Find the icon under the event. |nil| if |theEvent| is not over |
| 90 // at the given index. May be NSZeroRect if the index's action is not visible. | 117 // anything. |
| 91 // This does a linear walk over all page actions, so do not call this in a loop | 118 - (AutocompleteTextFieldIcon*)iconForEvent:(NSEvent*)theEvent |
| 92 // to get the position of all page actions. Use |-layedOutIcons:| instead in tha
t | 119 inRect:(NSRect)cellFrame |
| 93 // case. | 120 ofView:(AutocompleteTextField*)controlView; |
| 94 - (NSRect)pageActionFrameForIndex:(size_t)index inFrame:(NSRect)cellFrame; | |
| 95 | 121 |
| 96 // Return the appropriate menu for any page actions under event. | 122 // Return the appropriate menu for any page actions under event. |
| 97 // Returns nil if no menu is present for the action, or if the event | 123 // Returns nil if no menu is present for the action, or if the event |
| 98 // is not over an action. | 124 // is not over an action. |
| 99 - (NSMenu*)actionMenuForEvent:(NSEvent*)event | 125 - (NSMenu*)actionMenuForEvent:(NSEvent*)theEvent |
| 100 inRect:(NSRect)cellFrame | 126 inRect:(NSRect)cellFrame |
| 101 ofView:(NSView*)aView; | 127 ofView:(AutocompleteTextField*)controlView; |
| 128 |
| 129 // Called by |AutocompleteTextField| to let page actions intercept |
| 130 // clicks. Returns |YES| if the click has been intercepted. |
| 131 - (BOOL)mouseDown:(NSEvent*)theEvent |
| 132 inRect:(NSRect)cellFrame |
| 133 ofView:(AutocompleteTextField*)controlView; |
| 102 | 134 |
| 103 @end | 135 @end |
| 104 | 136 |
| 105 // Internal methods here exposed for unit testing. | 137 // Internal methods here exposed for unit testing. |
| 106 @interface AutocompleteTextFieldCell (UnitTesting) | 138 @interface AutocompleteTextFieldCell (UnitTesting) |
| 107 | 139 |
| 108 @property(readonly) NSAttributedString* keywordString; | 140 @property(readonly) NSAttributedString* keywordString; |
| 109 @property(readonly) NSAttributedString* hintString; | 141 @property(readonly) NSAttributedString* hintString; |
| 110 @property(readonly) NSAttributedString* hintIconLabel; | 142 @property(readonly) NSAttributedString* hintIconLabel; |
| 111 | 143 |
| 112 // Returns the total number of installed Page Actions, visible or not. | 144 // Returns the total number of installed Page Actions, visible or not. |
| 113 - (size_t)pageActionCount; | 145 - (size_t)pageActionCount; |
| 114 | 146 |
| 115 // Returns the portion of the cell to use for displaying the location icon, | 147 // Returns the portion of the cell to use for displaying the location |
| 116 // leaving space for its label if any. | 148 // icon. |
| 117 - (NSRect)locationIconFrameForFrame:(NSRect)cellFrame; | 149 - (NSRect)locationIconFrameForFrame:(NSRect)cellFrame; |
| 118 | 150 |
| 119 @end | 151 @end |
| OLD | NEW |