Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h

Issue 2805070: [Mac] First part of Omnibox decoration refactor. Enable ev bubble. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: comment clarification Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/location_bar_view_mac.h" 10 #include "chrome/browser/cocoa/location_bar/location_bar_view_mac.h"
11 11
12 class ExtensionAction; 12 class ExtensionAction;
13 class LocationBarDecoration;
13 14
14 // Holds a |LocationBarImageView| and its current rect. Do not keep references 15 // Holds a |LocationBarImageView| and its current rect. Do not keep references
15 // to this object, only use it directly after calling |-layedOutIcons:|. 16 // to this object, only use it directly after calling |-layedOutIcons:|.
16 // TODO(shess): This class is basically a helper for laying out the 17 // 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 // 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 // least split the image and label cases into subclasses once the
19 // Omnibox stuff is settled. 20 // Omnibox stuff is settled.
20 @interface AutocompleteTextFieldIcon : NSObject { 21 @interface AutocompleteTextFieldIcon : NSObject {
21 // YES to draw the label part of |view_|, otherwise draw the image 22 // YES to draw the label part of |view_|, otherwise draw the image
22 // part. 23 // part.
(...skipping 22 matching lines...) Expand all
45 46
46 @end 47 @end
47 48
48 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for 49 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for
49 // certain decorations to be applied to the field. These are the search hint 50 // 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 51 // ("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 52 // search Engine" on the right-hand side), and keyword mode ("Search Engine:" in
52 // a button-like token on the left-hand side). 53 // a button-like token on the left-hand side).
53 @interface AutocompleteTextFieldCell : StyledTextFieldCell { 54 @interface AutocompleteTextFieldCell : StyledTextFieldCell {
54 @private 55 @private
55 // Set if there is a string to display in a rounded rect on the 56 // Decorations which live to the left of the text. Owned by
56 // left-hand side of the field. Exclusive WRT |hintString_|. 57 // |LocationBarViewMac|.
57 scoped_nsobject<NSAttributedString> keywordString_; 58 std::vector<LocationBarDecoration*> leftDecorations_;
58 59
59 // Set if there is a string to display as a hint on the right-hand 60 // Set if there is a string to display as a hint on the right-hand
60 // side of the field. Exclusive WRT |keywordString_|; 61 // side of the field. Exclusive WRT |keywordString_|;
61 scoped_nsobject<NSAttributedString> hintString_; 62 scoped_nsobject<NSAttributedString> hintString_;
62 63
63 // The location icon sits at the left-hand side of the field.
64 // |keywordString_| overrides.
65 LocationBarViewMac::LocationIconView* locationIconView_;
66
67 // The star icon sits at the right-hand side of the field when an 64 // The star icon sits at the right-hand side of the field when an
68 // URL is being shown. 65 // URL is being shown.
69 LocationBarViewMac::LocationBarImageView* starIconView_; 66 LocationBarViewMac::LocationBarImageView* starIconView_;
70 67
71 // The security label floats to the left of page actions at the
72 // right-hand side.
73 LocationBarViewMac::LocationBarImageView* securityLabelView_;
74
75 // List of views showing visible Page Actions. Owned by the location bar. 68 // List of views showing visible Page Actions. Owned by the location bar.
76 // Display is exclusive WRT the |hintString_| and |keywordString_|. 69 // Display is exclusive WRT the |hintString_| and |keywordString_|.
77 // This may be NULL during testing. 70 // This may be NULL during testing.
78 LocationBarViewMac::PageActionViewList* page_action_views_; 71 LocationBarViewMac::PageActionViewList* page_action_views_;
79 72
80 // List of content blocked icons. This may be NULL during testing. 73 // List of content blocked icons. This may be NULL during testing.
81 LocationBarViewMac::ContentSettingViews* content_setting_views_; 74 LocationBarViewMac::ContentSettingViews* content_setting_views_;
82 } 75 }
83 76
84 // Chooses |partialString| if |width| won't fit |fullString|. Strings
85 // must be non-nil.
86 - (void)setKeywordString:(NSString*)fullString
87 partialString:(NSString*)partialString
88 availableWidth:(CGFloat)width;
89
90 // Chooses |anImage| only if all pieces won't fit w/in |width|. 77 // Chooses |anImage| only if all pieces won't fit w/in |width|.
91 // Inputs must be non-nil. 78 // Inputs must be non-nil.
92 - (void)setKeywordHintPrefix:(NSString*)prefixString 79 - (void)setKeywordHintPrefix:(NSString*)prefixString
93 image:(NSImage*)anImage 80 image:(NSImage*)anImage
94 suffix:(NSString*)suffixString 81 suffix:(NSString*)suffixString
95 availableWidth:(CGFloat)width; 82 availableWidth:(CGFloat)width;
96 83
97 // Suppresses hint entirely if |aString| won't fit w/in |width|. 84 // Suppresses hint entirely if |aString| won't fit w/in |width|.
98 // String must be non-nil. 85 // String must be non-nil.
99 - (void)setSearchHintString:(NSString*)aString 86 - (void)setSearchHintString:(NSString*)aString
100 availableWidth:(CGFloat)width; 87 availableWidth:(CGFloat)width;
101 - (void)clearKeywordAndHint; 88 - (void)clearHint;
102 89
103 - (void)setLocationIconView:(LocationBarViewMac::LocationIconView*)view; 90 // Clear |leftDecorations_|.
91 - (void)clearDecorations;
92
93 // Add a new left-side decoration to the right of the existing
94 // left-side decorations.
95 - (void)addLeftDecoration:(LocationBarDecoration*)decoration;
96
97 // The width available after accounting for decorations.
98 - (CGFloat)availableWidthInFrame:(const NSRect)frame;
99
104 - (void)setStarIconView:(LocationBarViewMac::LocationBarImageView*)view; 100 - (void)setStarIconView:(LocationBarViewMac::LocationBarImageView*)view;
105 - (void)setSecurityLabelView:(LocationBarViewMac::LocationBarImageView*)view;
106 - (void)setPageActionViewList:(LocationBarViewMac::PageActionViewList*)list; 101 - (void)setPageActionViewList:(LocationBarViewMac::PageActionViewList*)list;
107 - (void)setContentSettingViewsList: 102 - (void)setContentSettingViewsList:
108 (LocationBarViewMac::ContentSettingViews*)views; 103 (LocationBarViewMac::ContentSettingViews*)views;
109 104
110 // Returns the portion of the cell to use for displaying the location
111 // icon.
112 - (NSRect)locationIconFrameForFrame:(NSRect)cellFrame;
113
114 // Returns an array of the visible AutocompleteTextFieldIcon objects. Returns 105 // Returns an array of the visible AutocompleteTextFieldIcon objects. Returns
115 // only visible icons. 106 // only visible icons.
116 - (NSArray*)layedOutIcons:(NSRect)cellFrame; 107 - (NSArray*)layedOutIcons:(NSRect)cellFrame;
117 108
118 // Return the rectangle the star is being shown in, for purposes of 109 // Return the rectangle the star is being shown in, for purposes of
119 // positioning the bookmark bubble. 110 // positioning the bookmark bubble.
120 - (NSRect)starIconFrameForFrame:(NSRect)cellFrame; 111 - (NSRect)starIconFrameForFrame:(NSRect)cellFrame;
121 112
113 // Return the frame for |aDecoration| if the cell is in |cellFrame|.
114 // Returns |NSZeroRect| for decorations which are not currently
115 // visible.
116 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration
117 inFrame:(NSRect)cellFrame;
118
122 // Returns the portion of the cell to use for displaying the Page 119 // Returns the portion of the cell to use for displaying the Page
123 // Action icon at the given index. May be NSZeroRect if the index's 120 // Action icon at the given index. May be NSZeroRect if the index's
124 // action is not visible. This does a linear walk over all page 121 // action is not visible. This does a linear walk over all page
125 // actions, so do not call this in a loop to get the position of all 122 // actions, so do not call this in a loop to get the position of all
126 // page actions. Use |-layedOutIcons:| instead in that case. 123 // page actions. Use |-layedOutIcons:| instead in that case.
127 - (NSRect)pageActionFrameForIndex:(size_t)index inFrame:(NSRect)cellFrame; 124 - (NSRect)pageActionFrameForIndex:(size_t)index inFrame:(NSRect)cellFrame;
128 125
129 // Similar to |pageActionFrameForIndex:inFrame| but accepts an 126 // Similar to |pageActionFrameForIndex:inFrame| but accepts an
130 // ExtensionAction for when the index is not known. 127 // ExtensionAction for when the index is not known.
131 - (NSRect)pageActionFrameForExtensionAction:(ExtensionAction*)action 128 - (NSRect)pageActionFrameForExtensionAction:(ExtensionAction*)action
(...skipping 11 matching lines...) Expand all
143 - (NSMenu*)actionMenuForEvent:(NSEvent*)theEvent 140 - (NSMenu*)actionMenuForEvent:(NSEvent*)theEvent
144 inRect:(NSRect)cellFrame 141 inRect:(NSRect)cellFrame
145 ofView:(AutocompleteTextField*)controlView; 142 ofView:(AutocompleteTextField*)controlView;
146 143
147 // Called by |AutocompleteTextField| to let page actions intercept 144 // Called by |AutocompleteTextField| to let page actions intercept
148 // clicks. Returns |YES| if the click has been intercepted. 145 // clicks. Returns |YES| if the click has been intercepted.
149 - (BOOL)mouseDown:(NSEvent*)theEvent 146 - (BOOL)mouseDown:(NSEvent*)theEvent
150 inRect:(NSRect)cellFrame 147 inRect:(NSRect)cellFrame
151 ofView:(AutocompleteTextField*)controlView; 148 ofView:(AutocompleteTextField*)controlView;
152 149
153 // If the location icon is draggable, return its drag pasteboard.
154 - (NSPasteboard*)locationDragPasteboard;
155
156 @end 150 @end
157 151
158 // Internal methods here exposed for unit testing. 152 // Internal methods here exposed for unit testing.
159 @interface AutocompleteTextFieldCell (UnitTesting) 153 @interface AutocompleteTextFieldCell (UnitTesting)
160 154
161 @property(nonatomic, readonly) NSAttributedString* keywordString;
162 @property(nonatomic, readonly) NSAttributedString* hintString; 155 @property(nonatomic, readonly) NSAttributedString* hintString;
163 @property(nonatomic, readonly) NSAttributedString* hintIconLabel; 156 @property(nonatomic, readonly) NSAttributedString* hintIconLabel;
164 157
165 // Returns the total number of installed Page Actions, visible or not. 158 // Returns the total number of installed Page Actions, visible or not.
166 - (size_t)pageActionCount; 159 - (size_t)pageActionCount;
167 160
168 @end 161 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698