| 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> |
| 6 |
| 5 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 6 | 8 |
| 7 #import "chrome/browser/cocoa/styled_text_field_cell.h" | 9 #import "chrome/browser/cocoa/styled_text_field_cell.h" |
| 8 | 10 |
| 9 #include "base/scoped_nsobject.h" | 11 #include "base/scoped_nsobject.h" |
| 10 #include "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" | |
| 11 | 12 |
| 13 @class AutocompleteTextField; |
| 12 class LocationBarDecoration; | 14 class LocationBarDecoration; |
| 13 | 15 |
| 14 // Holds a |LocationBarImageView| and its current rect. Do not keep references | |
| 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. | |
| 20 @interface AutocompleteTextFieldIcon : NSObject { | |
| 21 // YES to draw the label part of |view_|, otherwise draw the image | |
| 22 // part. | |
| 23 BOOL isLabel_; | |
| 24 | |
| 25 // The frame rect of |view_|. | |
| 26 NSRect rect_; | |
| 27 | |
| 28 // weak, owned by LocationBarViewMac. | |
| 29 LocationBarViewMac::LocationBarImageView* view_; | |
| 30 } | |
| 31 | |
| 32 @property(assign, nonatomic) NSRect rect; | |
| 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 | |
| 46 @end | |
| 47 | |
| 48 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for | 16 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for |
| 49 // certain decorations to be applied to the field. These are the search hint | 17 // certain decorations to be applied to the field. These are the search hint |
| 50 // ("Type to search" on the right-hand side), the keyword hint ("Press [Tab] to | 18 // ("Type to search" on the right-hand side), the keyword hint ("Press [Tab] to |
| 51 // search Engine" on the right-hand side), and keyword mode ("Search Engine:" in | 19 // search Engine" on the right-hand side), and keyword mode ("Search Engine:" in |
| 52 // a button-like token on the left-hand side). | 20 // a button-like token on the left-hand side). |
| 53 @interface AutocompleteTextFieldCell : StyledTextFieldCell { | 21 @interface AutocompleteTextFieldCell : StyledTextFieldCell { |
| 54 @private | 22 @private |
| 55 // Decorations which live to the left and right of the text, ordered | 23 // Decorations which live to the left and right of the text, ordered |
| 56 // from outside in. Decorations are owned by |LocationBarViewMac|. | 24 // from outside in. Decorations are owned by |LocationBarViewMac|. |
| 57 std::vector<LocationBarDecoration*> leftDecorations_; | 25 std::vector<LocationBarDecoration*> leftDecorations_; |
| 58 std::vector<LocationBarDecoration*> rightDecorations_; | 26 std::vector<LocationBarDecoration*> rightDecorations_; |
| 59 | 27 |
| 60 // Set if there is a string to display as a hint on the right-hand | 28 // Set if there is a string to display as a hint on the right-hand |
| 61 // side of the field. Exclusive WRT |keywordString_|; | 29 // side of the field. Exclusive WRT |keywordString_|; |
| 62 scoped_nsobject<NSAttributedString> hintString_; | 30 scoped_nsobject<NSAttributedString> hintString_; |
| 63 | |
| 64 // List of content blocked icons. This may be NULL during testing. | |
| 65 LocationBarViewMac::ContentSettingViews* content_setting_views_; | |
| 66 } | 31 } |
| 67 | 32 |
| 68 // Chooses |anImage| only if all pieces won't fit w/in |width|. | 33 // Chooses |anImage| only if all pieces won't fit w/in |width|. |
| 69 // Inputs must be non-nil. | 34 // Inputs must be non-nil. |
| 70 - (void)setKeywordHintPrefix:(NSString*)prefixString | 35 - (void)setKeywordHintPrefix:(NSString*)prefixString |
| 71 image:(NSImage*)anImage | 36 image:(NSImage*)anImage |
| 72 suffix:(NSString*)suffixString | 37 suffix:(NSString*)suffixString |
| 73 availableWidth:(CGFloat)width; | 38 availableWidth:(CGFloat)width; |
| 74 | 39 |
| 75 // Suppresses hint entirely if |aString| won't fit w/in |width|. | 40 // Suppresses hint entirely if |aString| won't fit w/in |width|. |
| 76 // String must be non-nil. | 41 // String must be non-nil. |
| 77 - (void)setSearchHintString:(NSString*)aString | 42 - (void)setSearchHintString:(NSString*)aString |
| 78 availableWidth:(CGFloat)width; | 43 availableWidth:(CGFloat)width; |
| 79 - (void)clearHint; | 44 - (void)clearHint; |
| 80 | 45 |
| 81 // Clear |leftDecorations_| and |rightDecorations_|. | 46 // Clear |leftDecorations_| and |rightDecorations_|. |
| 82 - (void)clearDecorations; | 47 - (void)clearDecorations; |
| 83 | 48 |
| 84 // Add a new left-side decoration to the right of the existing | 49 // Add a new left-side decoration to the right of the existing |
| 85 // left-side decorations. | 50 // left-side decorations. |
| 86 - (void)addLeftDecoration:(LocationBarDecoration*)decoration; | 51 - (void)addLeftDecoration:(LocationBarDecoration*)decoration; |
| 87 | 52 |
| 88 // Add a new right-side decoration to the left of the existing | 53 // Add a new right-side decoration to the left of the existing |
| 89 // right-side decorations. | 54 // right-side decorations. |
| 90 - (void)addRightDecoration:(LocationBarDecoration*)decoration; | 55 - (void)addRightDecoration:(LocationBarDecoration*)decoration; |
| 91 | 56 |
| 92 // The width available after accounting for decorations. | 57 // The width available after accounting for decorations. |
| 93 - (CGFloat)availableWidthInFrame:(const NSRect)frame; | 58 - (CGFloat)availableWidthInFrame:(const NSRect)frame; |
| 94 | 59 |
| 95 - (void)setContentSettingViewsList: | |
| 96 (LocationBarViewMac::ContentSettingViews*)views; | |
| 97 | |
| 98 // Returns an array of the visible AutocompleteTextFieldIcon objects. Returns | |
| 99 // only visible icons. | |
| 100 - (NSArray*)layedOutIcons:(NSRect)cellFrame; | |
| 101 | |
| 102 // Return the frame for |aDecoration| if the cell is in |cellFrame|. | 60 // Return the frame for |aDecoration| if the cell is in |cellFrame|. |
| 103 // Returns |NSZeroRect| for decorations which are not currently | 61 // Returns |NSZeroRect| for decorations which are not currently |
| 104 // visible. | 62 // visible. |
| 105 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration | 63 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration |
| 106 inFrame:(NSRect)cellFrame; | 64 inFrame:(NSRect)cellFrame; |
| 107 | 65 |
| 108 // Find the icon under the event. |nil| if |theEvent| is not over | 66 // Find the decoration under the event. |NULL| if |theEvent| is not |
| 109 // anything. | 67 // over anything. |
| 110 - (AutocompleteTextFieldIcon*)iconForEvent:(NSEvent*)theEvent | 68 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent |
| 111 inRect:(NSRect)cellFrame | 69 inRect:(NSRect)cellFrame |
| 112 ofView:(AutocompleteTextField*)controlView; | 70 ofView:(AutocompleteTextField*)field; |
| 113 | 71 |
| 114 // Return the appropriate menu for any decorations under event. | 72 // Return the appropriate menu for any decorations under event. |
| 115 // Returns nil if no menu is present for the decoration, or if the | 73 // Returns nil if no menu is present for the decoration, or if the |
| 116 // event is not over a decoration. | 74 // event is not over a decoration. |
| 117 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent | 75 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent |
| 118 inRect:(NSRect)cellFrame | 76 inRect:(NSRect)cellFrame |
| 119 ofView:(AutocompleteTextField*)controlView; | 77 ofView:(AutocompleteTextField*)controlView; |
| 120 | 78 |
| 121 // Called by |AutocompleteTextField| to let page actions intercept | 79 // Called by |AutocompleteTextField| to let page actions intercept |
| 122 // clicks. Returns |YES| if the click has been intercepted. | 80 // clicks. Returns |YES| if the click has been intercepted. |
| 123 - (BOOL)mouseDown:(NSEvent*)theEvent | 81 - (BOOL)mouseDown:(NSEvent*)theEvent |
| 124 inRect:(NSRect)cellFrame | 82 inRect:(NSRect)cellFrame |
| 125 ofView:(AutocompleteTextField*)controlView; | 83 ofView:(AutocompleteTextField*)controlView; |
| 126 | 84 |
| 127 @end | 85 @end |
| 128 | 86 |
| 129 // Internal methods here exposed for unit testing. | 87 // Internal methods here exposed for unit testing. |
| 130 @interface AutocompleteTextFieldCell (UnitTesting) | 88 @interface AutocompleteTextFieldCell (UnitTesting) |
| 131 | 89 |
| 132 @property(nonatomic, readonly) NSAttributedString* hintString; | 90 @property(nonatomic, readonly) NSAttributedString* hintString; |
| 133 @property(nonatomic, readonly) NSAttributedString* hintIconLabel; | 91 @property(nonatomic, readonly) NSAttributedString* hintIconLabel; |
| 134 | 92 |
| 135 @end | 93 @end |
| OLD | NEW |