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

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

Issue 160496: Implement back/forward toolbar menus on Mac.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 4 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/autocomplete_text_field.h" 10 #import "chrome/browser/cocoa/autocomplete_text_field.h"
11 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" 11 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h"
12 #import "chrome/browser/cocoa/back_forward_menu_controller.h"
12 #import "chrome/browser/cocoa/gradient_button_cell.h" 13 #import "chrome/browser/cocoa/gradient_button_cell.h"
13 #import "chrome/browser/cocoa/location_bar_view_mac.h" 14 #import "chrome/browser/cocoa/location_bar_view_mac.h"
14 #include "chrome/browser/cocoa/nsimage_cache.h" 15 #include "chrome/browser/cocoa/nsimage_cache.h"
15 #include "chrome/browser/profile.h" 16 #include "chrome/browser/profile.h"
16 #include "chrome/browser/toolbar_model.h" 17 #include "chrome/browser/toolbar_model.h"
17 #include "chrome/common/notification_details.h" 18 #include "chrome/common/notification_details.h"
18 #include "chrome/common/notification_observer.h" 19 #include "chrome/common/notification_observer.h"
19 #include "chrome/common/notification_type.h" 20 #include "chrome/common/notification_type.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "chrome/common/pref_service.h" 22 #include "chrome/common/pref_service.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ToolbarController* controller_; // weak, owns us 54 ToolbarController* controller_; // weak, owns us
54 }; 55 };
55 56
56 } // namespace 57 } // namespace
57 58
58 @implementation ToolbarController 59 @implementation ToolbarController
59 60
60 - (id)initWithModel:(ToolbarModel*)model 61 - (id)initWithModel:(ToolbarModel*)model
61 commands:(CommandUpdater*)commands 62 commands:(CommandUpdater*)commands
62 profile:(Profile*)profile 63 profile:(Profile*)profile
64 browser:(Browser*)browser
63 resizeDelegate:(id<ViewResizer>)resizeDelegate 65 resizeDelegate:(id<ViewResizer>)resizeDelegate
64 bookmarkDelegate:(id<BookmarkURLOpener>)delegate { 66 bookmarkDelegate:(id<BookmarkURLOpener>)delegate {
65 DCHECK(model && commands && profile); 67 DCHECK(model && commands && profile);
66 if ((self = [super initWithNibName:@"Toolbar" 68 if ((self = [super initWithNibName:@"Toolbar"
67 bundle:mac_util::MainAppBundle()])) { 69 bundle:mac_util::MainAppBundle()])) {
68 toolbarModel_ = model; 70 toolbarModel_ = model;
69 commands_ = commands; 71 commands_ = commands;
70 profile_ = profile; 72 profile_ = profile;
73 browser_ = browser;
71 resizeDelegate_ = resizeDelegate; 74 resizeDelegate_ = resizeDelegate;
72 bookmarkBarDelegate_ = delegate; 75 bookmarkBarDelegate_ = delegate;
73 hasToolbar_ = YES; 76 hasToolbar_ = YES;
74 77
75 // Register for notifications about state changes for the toolbar buttons 78 // Register for notifications about state changes for the toolbar buttons
76 commandObserver_.reset(new CommandObserverBridge(self, commands)); 79 commandObserver_.reset(new CommandObserverBridge(self, commands));
77 commandObserver_->ObserveCommand(IDC_BACK); 80 commandObserver_->ObserveCommand(IDC_BACK);
78 commandObserver_->ObserveCommand(IDC_FORWARD); 81 commandObserver_->ObserveCommand(IDC_FORWARD);
79 commandObserver_->ObserveCommand(IDC_RELOAD); 82 commandObserver_->ObserveCommand(IDC_RELOAD);
80 commandObserver_->ObserveCommand(IDC_HOME); 83 commandObserver_->ObserveCommand(IDC_HOME);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 initWithProfile:profile_ 118 initWithProfile:profile_
116 initialWidth:NSWidth([[self view] frame]) 119 initialWidth:NSWidth([[self view] frame])
117 resizeDelegate:self 120 resizeDelegate:self
118 urlDelegate:bookmarkBarDelegate_]); 121 urlDelegate:bookmarkBarDelegate_]);
119 122
120 // Add bookmark bar to the view hierarchy. This also triggers the 123 // Add bookmark bar to the view hierarchy. This also triggers the
121 // nib load. The bookmark bar is defined (in the nib) to be 124 // nib load. The bookmark bar is defined (in the nib) to be
122 // bottom-aligned to it's parent view (among other things), so 125 // bottom-aligned to it's parent view (among other things), so
123 // position and resize properties don't need to be set. 126 // position and resize properties don't need to be set.
124 [[self view] addSubview:[bookmarkBarController_ view]]; 127 [[self view] addSubview:[bookmarkBarController_ view]];
128
129 // Create the controllers for the back/forward menus.
130 backMenuController_.reset([[BackForwardMenuController alloc]
131 initWithBrowser:browser_
132 modelType:BACK_FORWARD_MENU_TYPE_BACK
133 button:backButton_]);
134 forwardMenuController_.reset([[BackForwardMenuController alloc]
135 initWithBrowser:browser_
136 modelType:BACK_FORWARD_MENU_TYPE_FORWARD
137 button:forwardButton_]);
125 } 138 }
126 139
127 - (void)resizeView:(NSView*)view newHeight:(float)height { 140 - (void)resizeView:(NSView*)view newHeight:(float)height {
128 DCHECK(view == [bookmarkBarController_ view]); 141 DCHECK(view == [bookmarkBarController_ view]);
129 142
130 // The bookmark bar is always rooted at the bottom of the toolbar view, with 143 // The bookmark bar is always rooted at the bottom of the toolbar view, with
131 // width equal to the toolbar's width. The toolbar view is resized to 144 // width equal to the toolbar's width. The toolbar view is resized to
132 // accomodate the new bookmark bar height. 145 // accomodate the new bookmark bar height.
133 NSRect frame = NSMakeRect(0, 0, [[self view] bounds].size.width, height); 146 NSRect frame = NSMakeRect(0, 0, [[self view] bounds].size.width, height);
134 [view setFrame:frame]; 147 [view setFrame:frame];
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 forView:pageButton_]; 352 forView:pageButton_];
340 } 353 }
341 354
342 - (IBAction)showWrenchMenu:(id)sender { 355 - (IBAction)showWrenchMenu:(id)sender {
343 [NSMenu popUpContextMenu:wrenchMenu_ 356 [NSMenu popUpContextMenu:wrenchMenu_
344 withEvent:[NSApp currentEvent] 357 withEvent:[NSApp currentEvent]
345 forView:wrenchButton_]; 358 forView:wrenchButton_];
346 } 359 }
347 360
348 @end 361 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/toolbar_controller.h ('k') | chrome/browser/cocoa/toolbar_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698