OLD | NEW |
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 #include "base/mac_util.h" | 5 #include "base/mac_util.h" |
6 #include "base/sys_string_conversions.h" | 6 #include "base/sys_string_conversions.h" |
| 7 #include "chrome/browser/bookmarks/bookmark_editor.h" |
7 #include "chrome/browser/bookmarks/bookmark_model.h" | 8 #include "chrome/browser/bookmarks/bookmark_model.h" |
8 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
9 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
10 #import "chrome/browser/cocoa/bookmark_bar_bridge.h" | 11 #import "chrome/browser/cocoa/bookmark_bar_bridge.h" |
11 #import "chrome/browser/cocoa/bookmark_bar_controller.h" | 12 #import "chrome/browser/cocoa/bookmark_bar_controller.h" |
12 #import "chrome/browser/cocoa/bookmark_bar_view.h" | 13 #import "chrome/browser/cocoa/bookmark_bar_view.h" |
13 #import "chrome/browser/cocoa/bookmark_button_cell.h" | 14 #import "chrome/browser/cocoa/bookmark_button_cell.h" |
| 15 #import "chrome/browser/cocoa/bookmark_editor_controller.h" |
14 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
15 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
16 #include "chrome/common/pref_service.h" | 18 #include "chrome/common/pref_service.h" |
17 #include "skia/ext/skia_utils_mac.h" | 19 #include "skia/ext/skia_utils_mac.h" |
18 | 20 |
19 @interface BookmarkBarController(Private) | 21 @interface BookmarkBarController(Private) |
20 - (void)applyContentAreaOffset:(BOOL)apply immediately:(BOOL)immediately; | 22 - (void)applyContentAreaOffset:(BOOL)apply immediately:(BOOL)immediately; |
21 - (void)showBookmarkBar:(BOOL)enable immediately:(BOOL)immediately; | 23 - (void)showBookmarkBar:(BOOL)enable immediately:(BOOL)immediately; |
22 @end | 24 @end |
23 | 25 |
(...skipping 17 matching lines...) Expand all Loading... |
41 | 43 |
42 @implementation BookmarkBarController | 44 @implementation BookmarkBarController |
43 | 45 |
44 - (id)initWithProfile:(Profile*)profile | 46 - (id)initWithProfile:(Profile*)profile |
45 parentView:(NSView*)parentView | 47 parentView:(NSView*)parentView |
46 webContentView:(NSView*)webContentView | 48 webContentView:(NSView*)webContentView |
47 infoBarsView:(NSView*)infoBarsView | 49 infoBarsView:(NSView*)infoBarsView |
48 delegate:(id<BookmarkURLOpener>)delegate { | 50 delegate:(id<BookmarkURLOpener>)delegate { |
49 if ((self = [super initWithNibName:@"BookmarkBar" | 51 if ((self = [super initWithNibName:@"BookmarkBar" |
50 bundle:mac_util::MainAppBundle()])) { | 52 bundle:mac_util::MainAppBundle()])) { |
| 53 profile_ = profile; |
51 bookmarkModel_ = profile->GetBookmarkModel(); | 54 bookmarkModel_ = profile->GetBookmarkModel(); |
52 preferences_ = profile->GetPrefs(); | |
53 parentView_ = parentView; | 55 parentView_ = parentView; |
54 webContentView_ = webContentView; | 56 webContentView_ = webContentView; |
55 infoBarsView_ = infoBarsView; | 57 infoBarsView_ = infoBarsView; |
56 buttons_.reset([[NSMutableArray alloc] init]); | 58 buttons_.reset([[NSMutableArray alloc] init]); |
57 delegate_ = delegate; | 59 delegate_ = delegate; |
58 } | 60 } |
59 return self; | 61 return self; |
60 } | 62 } |
61 | 63 |
62 - (void)awakeFromNib { | 64 - (void)awakeFromNib { |
63 // We default to NOT open, which means height=0. | 65 // We default to NOT open, which means height=0. |
64 DCHECK([[self view] isHidden]); // Hidden so it's OK to change. | 66 DCHECK([[self view] isHidden]); // Hidden so it's OK to change. |
65 NSRect frame = [[self view] frame]; | 67 NSRect frame = [[self view] frame]; |
66 frame.size.height = 0; | 68 frame.size.height = 0; |
67 frame.size.width = [parentView_ frame].size.width; | 69 frame.size.width = [parentView_ frame].size.width; |
68 [[self view] setFrame:frame]; | 70 [[self view] setFrame:frame]; |
69 | 71 |
70 // Make sure the nodes stay bottom-aligned. | 72 // Make sure the nodes stay bottom-aligned. |
71 [[self view] setAutoresizingMask:(NSViewWidthSizable | | 73 [[self view] setAutoresizingMask:(NSViewWidthSizable | |
72 NSViewMinYMargin)]; | 74 NSViewMinYMargin)]; |
73 // Be sure to enable the bar before trying to show it... | 75 // Be sure to enable the bar before trying to show it... |
74 barIsEnabled_ = YES; | 76 barIsEnabled_ = YES; |
75 if (preferences_->GetBoolean(prefs::kShowBookmarkBar)) | 77 if (profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) |
76 [self showBookmarkBar:YES immediately:YES]; | 78 [self showBookmarkBar:YES immediately:YES]; |
77 | 79 |
78 // Don't pass ourself along (as 'self') until our init is completely | 80 // Don't pass ourself along (as 'self') until our init is completely |
79 // done. Thus, this call is (almost) last. | 81 // done. Thus, this call is (almost) last. |
80 bridge_.reset(new BookmarkBarBridge(self, bookmarkModel_)); | 82 bridge_.reset(new BookmarkBarBridge(self, bookmarkModel_)); |
81 } | 83 } |
82 | 84 |
83 // Show or hide the bar based on the value of |show|. Handles | 85 // Show or hide the bar based on the value of |show|. Handles |
84 // animating the resize of the content view. if |immediately| is YES, | 86 // animating the resize of the content view. if |immediately| is YES, |
85 // make changes immediately instead of using an animator. If the bar | 87 // make changes immediately instead of using an animator. If the bar |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // Preference changing (global state) is handled in | 176 // Preference changing (global state) is handled in |
175 // BrowserWindowCocoa::ToggleBookmarkBar(). | 177 // BrowserWindowCocoa::ToggleBookmarkBar(). |
176 - (void)toggleBookmarkBar { | 178 - (void)toggleBookmarkBar { |
177 [self showBookmarkBar:!barShouldBeShown_ immediately:YES]; | 179 [self showBookmarkBar:!barShouldBeShown_ immediately:YES]; |
178 } | 180 } |
179 | 181 |
180 - (void)setBookmarkBarEnabled:(BOOL)enabled { | 182 - (void)setBookmarkBarEnabled:(BOOL)enabled { |
181 if (enabled) { | 183 if (enabled) { |
182 // Enabling the bar; set enabled then show if needed. | 184 // Enabling the bar; set enabled then show if needed. |
183 barIsEnabled_ = YES; | 185 barIsEnabled_ = YES; |
184 if (preferences_->GetBoolean(prefs::kShowBookmarkBar)) | 186 if (profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) |
185 [self showBookmarkBar:YES immediately:YES]; | 187 [self showBookmarkBar:YES immediately:YES]; |
186 } else { | 188 } else { |
187 // Disabling the bar; hide if visible. | 189 // Disabling the bar; hide if visible. |
188 if ([self isBookmarkBarVisible]) { | 190 if ([self isBookmarkBarVisible]) { |
189 [self showBookmarkBar:NO immediately:YES]; | 191 [self showBookmarkBar:NO immediately:YES]; |
190 } | 192 } |
191 barIsEnabled_ = NO; | 193 barIsEnabled_ = NO; |
192 } | 194 } |
193 } | 195 } |
194 | 196 |
(...skipping 30 matching lines...) Expand all Loading... |
225 - (IBAction)openBookmarkInNewWindow:(id)sender { | 227 - (IBAction)openBookmarkInNewWindow:(id)sender { |
226 BookmarkNode* node = [self nodeFromMenuItem:sender]; | 228 BookmarkNode* node = [self nodeFromMenuItem:sender]; |
227 [delegate_ openBookmarkURL:node->GetURL() disposition:NEW_WINDOW]; | 229 [delegate_ openBookmarkURL:node->GetURL() disposition:NEW_WINDOW]; |
228 } | 230 } |
229 | 231 |
230 - (IBAction)openBookmarkInIncognitoWindow:(id)sender { | 232 - (IBAction)openBookmarkInIncognitoWindow:(id)sender { |
231 BookmarkNode* node = [self nodeFromMenuItem:sender]; | 233 BookmarkNode* node = [self nodeFromMenuItem:sender]; |
232 [delegate_ openBookmarkURL:node->GetURL() disposition:OFF_THE_RECORD]; | 234 [delegate_ openBookmarkURL:node->GetURL() disposition:OFF_THE_RECORD]; |
233 } | 235 } |
234 | 236 |
| 237 - (IBAction)editBookmark:(id)sender { |
| 238 BookmarkNode* node = [self nodeFromMenuItem:sender]; |
| 239 // There is no real need to jump to a platform-common routine at |
| 240 // this point (which just jumps back to objc) other than consistency |
| 241 // across platforms. |
| 242 // |
| 243 // TODO(jrg): identify when we NO_TREE. I can see it in the code |
| 244 // for the other platforms but can't find a way to trigger it in the |
| 245 // UI. |
| 246 BookmarkEditor::Show([[[self view] window] contentView], |
| 247 profile_, |
| 248 node->GetParent(), |
| 249 node, |
| 250 BookmarkEditor::SHOW_TREE, |
| 251 nil); |
| 252 } |
| 253 |
235 - (IBAction)deleteBookmark:(id)sender { | 254 - (IBAction)deleteBookmark:(id)sender { |
236 BookmarkNode* node = [self nodeFromMenuItem:sender]; | 255 BookmarkNode* node = [self nodeFromMenuItem:sender]; |
237 bookmarkModel_->Remove(node->GetParent(), | 256 bookmarkModel_->Remove(node->GetParent(), |
238 node->GetParent()->IndexOfChild(node)); | 257 node->GetParent()->IndexOfChild(node)); |
239 } | 258 } |
240 | 259 |
| 260 - (void)openBookmarkNodesRecursive:(BookmarkNode*)node { |
| 261 for (int i = 0; i < node->GetChildCount(); i++) { |
| 262 BookmarkNode* child = node->GetChild(i); |
| 263 if (child->is_url()) |
| 264 [delegate_ openBookmarkURL:child->GetURL() |
| 265 disposition:NEW_BACKGROUND_TAB]; |
| 266 else |
| 267 [self openBookmarkNodesRecursive:child]; |
| 268 } |
| 269 } |
| 270 |
| 271 - (IBAction)openAllBookmarks:(id)sender { |
| 272 // TODO(jrg): |
| 273 // Is there an easier way to get a non-const root node for the bookmark bar? |
| 274 // I can't iterate over them unless it's non-const. |
| 275 |
| 276 BookmarkNode* node = (BookmarkNode*)bookmarkModel_->GetBookmarkBarNode(); |
| 277 [self openBookmarkNodesRecursive:node]; |
| 278 } |
| 279 |
| 280 - (IBAction)addPage:(id)sender { |
| 281 BookmarkEditor::Show([[[self view] window] contentView], |
| 282 profile_, |
| 283 bookmarkModel_->GetBookmarkBarNode(), |
| 284 nil, |
| 285 BookmarkEditor::SHOW_TREE, |
| 286 nil); |
| 287 } |
| 288 |
241 // Delete all bookmarks from the bookmark bar. | 289 // Delete all bookmarks from the bookmark bar. |
242 - (void)clearBookmarkBar { | 290 - (void)clearBookmarkBar { |
243 [buttons_ makeObjectsPerformSelector:@selector(removeFromSuperview)]; | 291 [buttons_ makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
244 [buttons_ removeAllObjects]; | 292 [buttons_ removeAllObjects]; |
245 } | 293 } |
246 | 294 |
247 // Return an autoreleased NSCell suitable for a bookmark button. | 295 // Return an autoreleased NSCell suitable for a bookmark button. |
248 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. | 296 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. |
249 - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)node { | 297 - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)node { |
250 NSString* title = base::SysWideToNSString(node->GetTitle()); | 298 NSString* title = base::SysWideToNSString(node->GetTitle()); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 496 |
449 - (void)setDelegate:(id<BookmarkURLOpener>)delegate { | 497 - (void)setDelegate:(id<BookmarkURLOpener>)delegate { |
450 delegate_ = delegate; | 498 delegate_ = delegate; |
451 } | 499 } |
452 | 500 |
453 - (NSArray*)buttons { | 501 - (NSArray*)buttons { |
454 return buttons_.get(); | 502 return buttons_.get(); |
455 } | 503 } |
456 | 504 |
457 @end | 505 @end |
OLD | NEW |