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

Side by Side Diff: chrome/browser/cocoa/location_bar_view_mac.h

Issue 427009: Preliminary work toward page actions on Mac. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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 | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ 5 #ifndef CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
6 #define CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ 6 #define CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
7 7
8 #include <string>
9 #include <map>
10 #include <vector>
11
8 #import <Cocoa/Cocoa.h> 12 #import <Cocoa/Cocoa.h>
9 13
10 #include "base/scoped_nsobject.h" 14 #include "base/scoped_nsobject.h"
11 #include "base/scoped_ptr.h" 15 #include "base/scoped_ptr.h"
12 #include "chrome/browser/autocomplete/autocomplete_edit.h" 16 #include "chrome/browser/autocomplete/autocomplete_edit.h"
13 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" 17 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
18 #include "chrome/browser/extensions/image_loading_tracker.h"
14 #include "chrome/browser/location_bar.h" 19 #include "chrome/browser/location_bar.h"
15 #include "chrome/browser/toolbar_model.h" 20 #include "chrome/browser/toolbar_model.h"
16 21
17 @class AutocompleteTextField; 22 @class AutocompleteTextField;
18 class BubblePositioner; 23 class BubblePositioner;
19 class CommandUpdater; 24 class CommandUpdater;
20 class Profile; 25 class Profile;
21 class ToolbarModel; 26 class ToolbarModel;
22 27
23 // A C++ bridge class that represents the location bar UI element to 28 // A C++ bridge class that represents the location bar UI element to
(...skipping 13 matching lines...) Expand all
37 42
38 // Overridden from LocationBar: 43 // Overridden from LocationBar:
39 virtual void ShowFirstRunBubble(bool use_OEM_bubble) { NOTIMPLEMENTED(); } 44 virtual void ShowFirstRunBubble(bool use_OEM_bubble) { NOTIMPLEMENTED(); }
40 virtual std::wstring GetInputString() const; 45 virtual std::wstring GetInputString() const;
41 virtual WindowOpenDisposition GetWindowOpenDisposition() const; 46 virtual WindowOpenDisposition GetWindowOpenDisposition() const;
42 virtual PageTransition::Type GetPageTransition() const; 47 virtual PageTransition::Type GetPageTransition() const;
43 virtual void AcceptInput(); 48 virtual void AcceptInput();
44 virtual void AcceptInputWithDisposition(WindowOpenDisposition disposition); 49 virtual void AcceptInputWithDisposition(WindowOpenDisposition disposition);
45 virtual void FocusLocation(); 50 virtual void FocusLocation();
46 virtual void FocusSearch(); 51 virtual void FocusSearch();
47 virtual void UpdatePageActions() { /* http://crbug.com/12281 */ } 52 virtual void UpdatePageActions();
48 virtual void InvalidatePageActions() { /* TODO(port): implement this */ } 53 virtual void InvalidatePageActions();
49 virtual void SaveStateToContents(TabContents* contents); 54 virtual void SaveStateToContents(TabContents* contents);
50 virtual void Revert(); 55 virtual void Revert();
51 virtual AutocompleteEditView* location_entry() { 56 virtual AutocompleteEditView* location_entry() {
52 return edit_view_.get(); 57 return edit_view_.get();
53 } 58 }
54 virtual LocationBarTesting* GetLocationBarForTesting() { return this; } 59 virtual LocationBarTesting* GetLocationBarForTesting() { return this; }
55 60
56 // Overriden from LocationBarTesting: 61 // Overriden from LocationBarTesting:
57 virtual int PageActionCount(); 62 virtual int PageActionCount();
58 virtual int PageActionVisibleCount(); 63 virtual int PageActionVisibleCount();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // Used to display a clickable icon in the location bar. 96 // Used to display a clickable icon in the location bar.
92 class LocationBarImageView { 97 class LocationBarImageView {
93 public: 98 public:
94 explicit LocationBarImageView() : image_(nil), 99 explicit LocationBarImageView() : image_(nil),
95 label_(nil), 100 label_(nil),
96 visible_(false) {} 101 visible_(false) {}
97 virtual ~LocationBarImageView() {} 102 virtual ~LocationBarImageView() {}
98 103
99 // Sets the image. 104 // Sets the image.
100 void SetImage(NSImage* image); 105 void SetImage(NSImage* image);
106 void SetImage(SkBitmap* image);
101 107
102 // Sets the label text, font, and color. |text| may be nil; |color| and 108 // Sets the label text, font, and color. |text| may be nil; |color| and
103 // |font| are ignored if |text| is nil. 109 // |font| are ignored if |text| is nil.
104 void SetLabel(NSString* text, NSFont* baseFont, NSColor* color); 110 void SetLabel(NSString* text, NSFont* baseFont, NSColor* color);
105 111
106 // Sets the visibility. SetImage() should be called with a valid image 112 // Sets the visibility. SetImage() should be called with a valid image
107 // before the visibility is set to |true|. 113 // before the visibility is set to |true|.
108 void SetVisible(bool visible); 114 void SetVisible(bool visible);
109 115
110 const NSImage* GetImage() const { return image_; } 116 const NSImage* GetImage() const { return image_; }
111 const NSAttributedString* GetLabel() const { return label_; } 117 const NSAttributedString* GetLabel() const { return label_; }
112 bool IsVisible() const { return visible_; } 118 bool IsVisible() const { return visible_; }
113 119
114 virtual bool OnMousePressed() = 0;
115
116 private: 120 private:
117 scoped_nsobject<NSImage> image_; 121 scoped_nsobject<NSImage> image_;
118 122
119 // The label shown next to the icon, or nil if none. 123 // The label shown next to the icon, or nil if none.
120 scoped_nsobject<NSAttributedString> label_; 124 scoped_nsobject<NSAttributedString> label_;
121 125
122 bool visible_; 126 bool visible_;
123 127
124 DISALLOW_COPY_AND_ASSIGN(LocationBarImageView); 128 DISALLOW_COPY_AND_ASSIGN(LocationBarImageView);
125 }; 129 };
126 130
127 // SecurityImageView is used to display the lock or warning icon when the 131 // SecurityImageView is used to display the lock or warning icon when the
128 // current URL's scheme is https. 132 // current URL's scheme is https.
129 class SecurityImageView : public LocationBarImageView { 133 class SecurityImageView : public LocationBarImageView {
130 public: 134 public:
131 enum Image { 135 enum Image {
132 LOCK = 0, 136 LOCK = 0,
133 WARNING 137 WARNING
134 }; 138 };
135 139
136 SecurityImageView(Profile* profile, ToolbarModel* model); 140 SecurityImageView(Profile* profile, ToolbarModel* model);
137 virtual ~SecurityImageView(); 141 virtual ~SecurityImageView();
138 142
139 // Sets the image to the appropriate icon. 143 // Sets the image to the appropriate icon.
140 void SetImageShown(Image image); 144 void SetImageShown(Image image);
141 145
142 // Shows the page info dialog. 146 // Shows the page info dialog. Virtual so it can be overridden for testing.
143 virtual bool OnMousePressed(); 147 virtual bool OnMousePressed();
144 148
145 private: 149 private:
146 // The lock icon shown when using HTTPS. Loaded lazily, the first time it's 150 // The lock icon shown when using HTTPS. Loaded lazily, the first time it's
147 // needed. 151 // needed.
148 scoped_nsobject<NSImage> lock_icon_; 152 scoped_nsobject<NSImage> lock_icon_;
149 153
150 // The warning icon shown when HTTPS is broken. Loaded lazily, the first 154 // The warning icon shown when HTTPS is broken. Loaded lazily, the first
151 // time it's needed. 155 // time it's needed.
152 scoped_nsobject<NSImage> warning_icon_; 156 scoped_nsobject<NSImage> warning_icon_;
153 157
154 Profile* profile_; 158 Profile* profile_;
155 ToolbarModel* model_; 159 ToolbarModel* model_;
156 160
157 DISALLOW_COPY_AND_ASSIGN(SecurityImageView); 161 DISALLOW_COPY_AND_ASSIGN(SecurityImageView);
158 }; 162 };
159 163
164 // PageActionImageView is used to display the icon for a given Page Action
165 // and notify the extension when the icon is clicked.
166 class PageActionImageView : public LocationBarImageView,
167 public ImageLoadingTracker::Observer,
168 public NotificationObserver {
169 public:
170 PageActionImageView(LocationBarViewMac* owner,
171 Profile* profile,
172 ExtensionAction* page_action);
173 virtual ~PageActionImageView();
174
175 ExtensionAction* page_action() { return page_action_; }
176
177 int current_tab_id() { return current_tab_id_; }
178
179 void set_preview_enabled(bool preview_enabled) {
180 preview_enabled_ = preview_enabled;
181 }
182
183 // Either notify listeners or show a popup depending on the Page Action.
184 // Virtual so it can be overridden for testing.
185 virtual bool OnMousePressed(NSRect bounds);
186
187 // Overridden from ImageLoadingTracker.
188 virtual void OnImageLoaded(SkBitmap* image, size_t index);
189
190 // Called to notify the Page Action that it should determine whether to be
191 // visible or hidden. |contents| is the TabContents that is active, |url|
192 // is the current page URL.
193 void UpdateVisibility(TabContents* contents, const GURL& url);
194
195 private:
196 // Overridden from NotificationObserver:
197 virtual void Observe(NotificationType type,
198 const NotificationSource& source,
199 const NotificationDetails& details);
200
201 // The location bar view that owns us.
202 LocationBarViewMac* owner_;
203
204 // The current profile (not owned by us).
205 Profile* profile_;
206
207 // The Page Action that this view represents. The Page Action is not owned
208 // by us, it resides in the extension of this particular profile.
209 ExtensionAction* page_action_;
210
211 // A cache of images the Page Actions might need to show, mapped by path.
212 typedef std::map<std::string, SkBitmap> PageActionMap;
213 PageActionMap page_action_icons_;
214
215 // The object that is waiting for the image loading to complete
216 // asynchronously.
217 ImageLoadingTracker* tracker_;
218
219 // The tab id we are currently showing the icon for.
220 int current_tab_id_;
221
222 // The URL we are currently showing the icon for.
223 GURL current_url_;
224
225 // The string to show for a tooltip.
226 std::string tooltip_;
227
228 // This is used for post-install visual feedback. The page_action icon
229 // is briefly shown even if it hasn't been enabled by it's extension.
230 bool preview_enabled_;
231
232 // Used to register for notifications received by NotificationObserver.
233 NotificationRegistrar registrar_;
234
235 DISALLOW_COPY_AND_ASSIGN(PageActionImageView);
236 };
237
238 class PageActionViewList {
239 public:
240 PageActionViewList(LocationBarViewMac* location_bar,
241 Profile* profile,
242 ToolbarModel* toolbar_model)
243 : owner_(location_bar),
244 profile_(profile),
245 toolbar_model_(toolbar_model) {}
246
247 void DeleteAll();
248 void RefreshViews();
249
250 PageActionImageView* ViewAt(size_t index);
251
252 size_t Count();
253 size_t VisibleCount();
254
255 // Called when the action at |index| is clicked. The |iconFrame| should
256 // describe the bounds of the affected action's icon.
257 void OnMousePressed(NSRect iconFrame, size_t index);
258
259 private:
260 // Any installed Page Actions.
261 std::vector<PageActionImageView*> views_;
262
263 // The location bar view that owns us.
264 LocationBarViewMac* owner_;
265
266 Profile* profile_;
267 ToolbarModel* toolbar_model_;
268
269 DISALLOW_COPY_AND_ASSIGN(PageActionViewList);
270 };
271
160 private: 272 private:
161 // Sets the SSL icon we should be showing. 273 // Sets the SSL icon we should be showing.
162 void SetSecurityIcon(ToolbarModel::Icon icon); 274 void SetSecurityIcon(ToolbarModel::Icon icon);
163 275
164 // Sets the label for the SSL icon. 276 // Sets the label for the SSL icon.
165 void SetSecurityIconLabel(); 277 void SetSecurityIconLabel();
166 278
167 scoped_ptr<AutocompleteEditViewMac> edit_view_; 279 scoped_ptr<AutocompleteEditViewMac> edit_view_;
168 280
169 CommandUpdater* command_updater_; // Weak, owned by Browser. 281 CommandUpdater* command_updater_; // Weak, owned by Browser.
170 282
171 AutocompleteTextField* field_; // owned by tab controller 283 AutocompleteTextField* field_; // owned by tab controller
172 284
173 // When we get an OnAutocompleteAccept notification from the autocomplete 285 // When we get an OnAutocompleteAccept notification from the autocomplete
174 // edit, we save the input string so we can give it back to the browser on 286 // edit, we save the input string so we can give it back to the browser on
175 // the LocationBar interface via GetInputString(). 287 // the LocationBar interface via GetInputString().
176 std::wstring location_input_; 288 std::wstring location_input_;
177 289
178 // The user's desired disposition for how their input should be opened. 290 // The user's desired disposition for how their input should be opened.
179 WindowOpenDisposition disposition_; 291 WindowOpenDisposition disposition_;
180 292
181 // The view that shows the lock/warning when in HTTPS mode. 293 // The view that shows the lock/warning when in HTTPS mode.
182 SecurityImageView security_image_view_; 294 SecurityImageView security_image_view_;
183 295
296 // Any installed Page Actions.
297 PageActionViewList* page_action_views_;
298
184 Profile* profile_; 299 Profile* profile_;
185 300
186 ToolbarModel* toolbar_model_; // Weak, owned by Browser. 301 ToolbarModel* toolbar_model_; // Weak, owned by Browser.
187 302
188 // Image used in drawing keyword hint. 303 // Image used in drawing keyword hint.
189 scoped_nsobject<NSImage> tab_button_image_; 304 scoped_nsobject<NSImage> tab_button_image_;
190 305
191 // The transition type to use for the navigation. 306 // The transition type to use for the navigation.
192 PageTransition::Type transition_; 307 PageTransition::Type transition_;
193 308
194 DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac); 309 DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac);
195 }; 310 };
196 311
197 #endif // CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ 312 #endif // CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_unittest.mm ('k') | chrome/browser/cocoa/location_bar_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698