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

Side by Side Diff: chrome/browser/cocoa/toolbar_controller.mm

Issue 149308: a bunch of bookmark bar changes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | 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 #import "chrome/browser/cocoa/toolbar_controller.h" 5 #import "chrome/browser/cocoa/toolbar_controller.h"
6 6
7 #include "base/mac_util.h" 7 #include "base/mac_util.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #import "chrome/browser/cocoa/location_bar_view_mac.h" 10 #import "chrome/browser/cocoa/location_bar_view_mac.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 private: 67 private:
68 ToolbarController* controller_; // weak, owns us 68 ToolbarController* controller_; // weak, owns us
69 }; 69 };
70 70
71 } // namespace 71 } // namespace
72 72
73 @implementation ToolbarController 73 @implementation ToolbarController
74 74
75 - (id)initWithModel:(ToolbarModel*)model 75 - (id)initWithModel:(ToolbarModel*)model
76 commands:(CommandUpdater*)commands 76 commands:(CommandUpdater*)commands
77 profile:(Profile*)profile { 77 profile:(Profile*)profile
78 webContentView:(NSView*)webContentView
79 bookmarkDelegate:(id<BookmarkURLOpener>)delegate {
78 DCHECK(model && commands && profile); 80 DCHECK(model && commands && profile);
79 if ((self = [super initWithNibName:@"Toolbar" 81 if ((self = [super initWithNibName:@"Toolbar"
80 bundle:mac_util::MainAppBundle()])) { 82 bundle:mac_util::MainAppBundle()])) {
81 toolbarModel_ = model; 83 toolbarModel_ = model;
82 commands_ = commands; 84 commands_ = commands;
83 profile_ = profile; 85 profile_ = profile;
86 bookmarkBarDelegate_ = delegate;
87 webContentView_ = webContentView;
84 88
85 // Register for notifications about state changes for the toolbar buttons 89 // Register for notifications about state changes for the toolbar buttons
86 commandObserver_.reset(new CommandObserverBridge(self, commands)); 90 commandObserver_.reset(new CommandObserverBridge(self, commands));
87 commandObserver_->ObserveCommand(IDC_BACK); 91 commandObserver_->ObserveCommand(IDC_BACK);
88 commandObserver_->ObserveCommand(IDC_FORWARD); 92 commandObserver_->ObserveCommand(IDC_FORWARD);
89 commandObserver_->ObserveCommand(IDC_RELOAD); 93 commandObserver_->ObserveCommand(IDC_RELOAD);
90 commandObserver_->ObserveCommand(IDC_HOME); 94 commandObserver_->ObserveCommand(IDC_HOME);
91 commandObserver_->ObserveCommand(IDC_STAR); 95 commandObserver_->ObserveCommand(IDC_STAR);
92 } 96 }
93 return self; 97 return self;
(...skipping 10 matching lines...) Expand all
104 108
105 // Register pref observers for the optional home and page/options buttons 109 // Register pref observers for the optional home and page/options buttons
106 // and then add them to the toolbar them based on those prefs. 110 // and then add them to the toolbar them based on those prefs.
107 prefObserver_.reset(new ToolbarControllerInternal::PrefObserverBridge(self)); 111 prefObserver_.reset(new ToolbarControllerInternal::PrefObserverBridge(self));
108 PrefService* prefs = profile_->GetPrefs(); 112 PrefService* prefs = profile_->GetPrefs();
109 showHomeButton_.Init(prefs::kShowHomeButton, prefs, prefObserver_.get()); 113 showHomeButton_.Init(prefs::kShowHomeButton, prefs, prefObserver_.get());
110 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs, 114 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs,
111 prefObserver_.get()); 115 prefObserver_.get());
112 [self showOptionalHomeButton]; 116 [self showOptionalHomeButton];
113 [self showOptionalPageWrenchButtons]; 117 [self showOptionalPageWrenchButtons];
118
119 // Create a sub-controller for the bookmark bar.
120 bookmarkBarController_.reset([[BookmarkBarController alloc]
121 initWithProfile:profile_
122 view:bookmarkBarView_
123 webContentView:webContentView_
124 delegate:bookmarkBarDelegate_]);
114 } 125 }
115 126
116 - (LocationBar*)locationBar { 127 - (LocationBar*)locationBar {
117 return locationBarView_.get(); 128 return locationBarView_.get();
118 } 129 }
119 130
120 - (void)focusLocationBar { 131 - (void)focusLocationBar {
121 if (locationBarView_.get()) { 132 if (locationBarView_.get()) {
122 locationBarView_->FocusLocation(); 133 locationBarView_->FocusLocation();
123 } 134 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 NSString* imageName = @"go"; 182 NSString* imageName = @"go";
172 NSInteger tag = IDC_GO; 183 NSInteger tag = IDC_GO;
173 if (isLoading) { 184 if (isLoading) {
174 imageName = @"stop"; 185 imageName = @"stop";
175 tag = IDC_STOP; 186 tag = IDC_STOP;
176 } 187 }
177 [goButton_ setImage:[NSImage imageNamed:imageName]]; 188 [goButton_ setImage:[NSImage imageNamed:imageName]];
178 [goButton_ setTag:tag]; 189 [goButton_ setTag:tag];
179 } 190 }
180 191
192 - (BookmarkBarController*)bookmarkBarController {
193 return bookmarkBarController_.get();
194 }
195
181 - (id)customFieldEditorForObject:(id)obj { 196 - (id)customFieldEditorForObject:(id)obj {
182 if (obj == locationBar_) { 197 if (obj == locationBar_) {
183 // Lazilly construct Field editor, Cocoa UI code always runs on the 198 // Lazilly construct Field editor, Cocoa UI code always runs on the
184 // same thread, so there shoudn't be a race condition here. 199 // same thread, so there shoudn't be a race condition here.
185 if (locationBarFieldEditor_.get() == nil) { 200 if (locationBarFieldEditor_.get() == nil) {
186 locationBarFieldEditor_.reset([[LocationBarFieldEditor alloc] init]); 201 locationBarFieldEditor_.reset([[LocationBarFieldEditor alloc] init]);
187 } 202 }
188 203
189 // This needs to be called every time, otherwise notifications 204 // This needs to be called every time, otherwise notifications
190 // aren't sent correctly. 205 // aren't sent correctly.
191 DCHECK(locationBarFieldEditor_.get()); 206 DCHECK(locationBarFieldEditor_.get());
192 [locationBarFieldEditor_.get() setFieldEditor:YES]; 207 [locationBarFieldEditor_.get() setFieldEditor:YES];
193 return locationBarFieldEditor_.get(); 208 return locationBarFieldEditor_.get();
194 } 209 }
195 return nil; 210 return nil;
196 } 211 }
197 212
198 // Returns an array of views in the order of the outlets above. 213 // Returns an array of views in the order of the outlets above.
199 - (NSArray*)toolbarViews { 214 - (NSArray*)toolbarViews {
200 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, 215 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_,
201 homeButton_, starButton_, goButton_, pageButton_, wrenchButton_, 216 homeButton_, starButton_, goButton_, pageButton_, wrenchButton_,
202 locationBar_, nil]; 217 locationBar_, bookmarkBarView_, nil];
203 } 218 }
204 219
205 // Moves |rect| to the right by |delta|, keeping the right side fixed by 220 // Moves |rect| to the right by |delta|, keeping the right side fixed by
206 // shrinking the width to compensate. Passing a negative value for |deltaX| 221 // shrinking the width to compensate. Passing a negative value for |deltaX|
207 // moves to the left and increases the width. 222 // moves to the left and increases the width.
208 - (NSRect)adjustRect:(NSRect)rect byAmount:(float)deltaX { 223 - (NSRect)adjustRect:(NSRect)rect byAmount:(float)deltaX {
209 NSRect frame = NSOffsetRect(rect, deltaX, 0); 224 NSRect frame = NSOffsetRect(rect, deltaX, 0);
210 frame.size.width -= deltaX; 225 frame.size.width -= deltaX;
211 return frame; 226 return frame;
212 } 227 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 forView:pageButton_]; 295 forView:pageButton_];
281 } 296 }
282 297
283 - (IBAction)showWrenchMenu:(id)sender { 298 - (IBAction)showWrenchMenu:(id)sender {
284 [NSMenu popUpContextMenu:wrenchMenu_ 299 [NSMenu popUpContextMenu:wrenchMenu_
285 withEvent:[NSApp currentEvent] 300 withEvent:[NSApp currentEvent]
286 forView:wrenchButton_]; 301 forView:wrenchButton_];
287 } 302 }
288 303
289 @end 304 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698