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

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

Issue 46078: Mac bookmark work. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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/app/chrome_dll_resource.h" // IDC_*
5 #import "chrome/browser/browser.h" 6 #import "chrome/browser/browser.h"
6 #import "chrome/browser/cocoa/browser_window_cocoa.h" 7 #import "chrome/browser/cocoa/browser_window_cocoa.h"
7 #import "chrome/browser/cocoa/browser_window_controller.h" 8 #import "chrome/browser/cocoa/browser_window_controller.h"
8 #import "chrome/browser/cocoa/tab_strip_view.h" 9 #import "chrome/browser/cocoa/tab_strip_view.h"
9 #import "chrome/browser/cocoa/tab_strip_controller.h" 10 #import "chrome/browser/cocoa/tab_strip_controller.h"
10 11
11 @implementation BrowserWindowController 12 @implementation BrowserWindowController
12 13
13 // Load the browser window nib and do any Cocoa-specific initialization. 14 // Load the browser window nib and do any Cocoa-specific initialization.
14 // Takes ownership of |browser|. Note that the nib also sets this controller 15 // Takes ownership of |browser|. Note that the nib also sets this controller
15 // up as the window's delegate. 16 // up as the window's delegate.
16 - (id)initWithBrowser:(Browser*)browser { 17 - (id)initWithBrowser:(Browser*)browser {
17 if ((self = [super initWithWindowNibName:@"BrowserWindow"])) { 18 if ((self = [super initWithWindowNibName:@"BrowserWindow"])) {
18 browser_ = browser; 19 browser_ = browser;
19 DCHECK(browser_); 20 DCHECK(browser_);
20 windowShim_ = new BrowserWindowCocoa(self, [self window]); 21 windowShim_ = new BrowserWindowCocoa(browser, self, [self window]);
22 windowShim_->Init();
21 } 23 }
22 return self; 24 return self;
23 } 25 }
24 26
25 - (void)dealloc { 27 - (void)dealloc {
26 browser_->CloseAllTabs(); 28 browser_->CloseAllTabs();
27 [tabStripController_ release]; 29 [tabStripController_ release];
28 delete browser_; 30 delete browser_;
29 delete windowShim_; 31 delete windowShim_;
30 [super dealloc]; 32 [super dealloc];
31 } 33 }
32 34
33 // Access the C++ bridge between the NSWindow and the rest of Chromium 35 // Access the C++ bridge between the NSWindow and the rest of Chromium
34 - (BrowserWindow*)browserWindow { 36 - (BrowserWindow*)browserWindow {
35 return windowShim_; 37 return windowShim_;
36 } 38 }
37 39
38 - (void)windowDidLoad { 40 - (void)windowDidLoad {
39 // Create a controller for the tab strip, giving it the model object for 41 // Create a controller for the tab strip, giving it the model object for
40 // this window's Browser and the tab strip view. The controller will handle 42 // this window's Browser and the tab strip view. The controller will handle
41 // registering for the appropriate tab notifications from the back-end and 43 // registering for the appropriate tab notifications from the back-end and
42 // managing the creation of new tabs. 44 // managing the creation of new tabs.
43 tabStripController_ = 45 tabStripController_ = [[TabStripController alloc]
44 [[TabStripController alloc] 46 initWithView:tabStripView_ browser:browser_];
45 initWithView:tabStripView_
46 tabModel:browser_->tabstrip_model()
47 toolbarModel:browser_->toolbar_model()
48 commands:browser_->command_updater()];
49 47
50 // Place the tab bar above the content box and add it to the view hierarchy 48 // Place the tab bar above the content box and add it to the view hierarchy
51 // as a sibling of the content view so it can overlap with the window frame. 49 // as a sibling of the content view so it can overlap with the window frame.
52 NSRect tabFrame = [contentBox_ frame]; 50 NSRect tabFrame = [contentBox_ frame];
53 tabFrame.origin = NSMakePoint(0, NSMaxY(tabFrame)); 51 tabFrame.origin = NSMakePoint(0, NSMaxY(tabFrame));
54 tabFrame.size.height = NSHeight([tabStripView_ frame]); 52 tabFrame.size.height = NSHeight([tabStripView_ frame]);
55 [tabStripView_ setFrame:tabFrame]; 53 [tabStripView_ setFrame:tabFrame];
56 [[[[self window] contentView] superview] addSubview:tabStripView_]; 54 [[[[self window] contentView] superview] addSubview:tabStripView_];
57 } 55 }
58 56
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // down. When the tab strip is empty we'll be called back again. 93 // down. When the tab strip is empty we'll be called back again.
96 [[self window] orderOut:self]; 94 [[self window] orderOut:self];
97 browser_->OnWindowClosing(); 95 browser_->OnWindowClosing();
98 return NO; 96 return NO;
99 } 97 }
100 98
101 // the tab strip is empty, it's ok to close the window 99 // the tab strip is empty, it's ok to close the window
102 return YES; 100 return YES;
103 } 101 }
104 102
103 // Update a toggle state for an NSMenuItem if modified.
104 // Take care to insure |item| looks like a NSMenuItem.
105 // Called by validateUserInterfaceItem:.
106 - (void)updateToggleStateWithTag:(NSInteger)tag forItem:(id)item {
107 if (![item respondsToSelector:@selector(state)] ||
108 ![item respondsToSelector:@selector(setState:)])
109 return;
110
111 // On Windows this logic happens in bookmark_bar_view.cc. On the
112 // Mac we're a lot more MVC happy so we've moved it into a
113 // controller. To be clear, this simply updates the menu item; it
114 // does not display the bookmark bar itself.
115 if (tag == IDC_SHOW_BOOKMARK_BAR) {
116 bool toggled = windowShim_->IsBookmarkBarVisible();
117 NSInteger oldState = [item state];
118 NSInteger newState = toggled ? NSOnState : NSOffState;
119 if (oldState != newState)
120 [item setState:newState];
121 }
122 }
123
105 // Called to validate menu and toolbar items when this window is key. All the 124 // Called to validate menu and toolbar items when this window is key. All the
106 // items we care about have been set with the |commandDispatch:| action and 125 // items we care about have been set with the |commandDispatch:| action and
107 // a target of FirstResponder in IB. If it's not one of those, let it 126 // a target of FirstResponder in IB. If it's not one of those, let it
108 // continue up the responder chain to be handled elsewhere. We pull out the 127 // continue up the responder chain to be handled elsewhere. We pull out the
109 // tag as the cross-platform constant to differentiate and dispatch the 128 // tag as the cross-platform constant to differentiate and dispatch the
110 // various commands. 129 // various commands.
111 // NOTE: we might have to handle state for app-wide menu items, 130 // NOTE: we might have to handle state for app-wide menu items,
112 // although we could cheat and directly ask the app controller if our 131 // although we could cheat and directly ask the app controller if our
113 // command_updater doesn't support the command. This may or may not be an issue, 132 // command_updater doesn't support the command. This may or may not be an issue,
114 // too early to tell. 133 // too early to tell.
115 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { 134 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
116 SEL action = [item action]; 135 SEL action = [item action];
117 BOOL enable = NO; 136 BOOL enable = NO;
118 if (action == @selector(commandDispatch:)) { 137 if (action == @selector(commandDispatch:)) {
119 NSInteger tag = [item tag]; 138 NSInteger tag = [item tag];
120 if (browser_->command_updater()->SupportsCommand(tag)) 139 if (browser_->command_updater()->SupportsCommand(tag)) {
140 // Generate return value (enabled state)
121 enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO; 141 enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO;
142
143 // If the item is toggleable, find it's toggle state and
144 // try to update it. This is a little awkward, but the alternative is
145 // to check after a commandDispatch, which seems worse.
146 [self updateToggleStateWithTag:tag forItem:item];
147 }
122 } 148 }
123 return enable; 149 return enable;
124 } 150 }
125 151
126 // Called when the user picks a menu or toolbar item when this window is key. 152 // Called when the user picks a menu or toolbar item when this window is key.
127 // Calls through to the browser object to execute the command. This assumes that 153 // Calls through to the browser object to execute the command. This assumes that
128 // the command is supported and doesn't check, otherwise it would have been 154 // the command is supported and doesn't check, otherwise it would have been
129 // disabled in the UI in validateUserInterfaceItem:. 155 // disabled in the UI in validateUserInterfaceItem:.
130 - (void)commandDispatch:(id)sender { 156 - (void)commandDispatch:(id)sender {
131 NSInteger tag = [sender tag]; 157 NSInteger tag = [sender tag];
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } else { 194 } else {
169 // TODO(pinkerton): stop the timer. 195 // TODO(pinkerton): stop the timer.
170 } 196 }
171 } 197 }
172 198
173 // Make the location bar the first responder, if possible. 199 // Make the location bar the first responder, if possible.
174 - (void)focusLocationBar { 200 - (void)focusLocationBar {
175 [tabStripController_ focusLocationBar]; 201 [tabStripController_ focusLocationBar];
176 } 202 }
177 203
204 - (BOOL)isBookmarkBarVisible {
205 return [tabStripController_ isBookmarkBarVisible];
206
207 }
208
209 - (void)toggleBookmarkBar {
210 [tabStripController_ toggleBookmarkBar];
211 }
212
213
178 @end 214 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.h ('k') | chrome/browser/cocoa/tab_contents_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698