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

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

Issue 173044: This changelist represents the necessary merger of two others:... (Closed) Base URL: svn://svn.chromium.org/chrome/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
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/cocoa/bookmark_bar_controller_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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_editor.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
11 #import "chrome/browser/cocoa/bookmark_bar_bridge.h" 11 #import "chrome/browser/cocoa/bookmark_bar_bridge.h"
12 #import "chrome/browser/cocoa/bookmark_bar_controller.h" 12 #import "chrome/browser/cocoa/bookmark_bar_controller.h"
13 #import "chrome/browser/cocoa/bookmark_button_cell.h" 13 #import "chrome/browser/cocoa/bookmark_button_cell.h"
14 #import "chrome/browser/cocoa/bookmark_editor_controller.h" 14 #import "chrome/browser/cocoa/bookmark_editor_controller.h"
15 #import "chrome/browser/cocoa/bookmark_name_folder_controller.h" 15 #import "chrome/browser/cocoa/bookmark_name_folder_controller.h"
16 #import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h" 16 #import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h"
17 #import "chrome/browser/cocoa/event_utils.h"
17 #import "chrome/browser/cocoa/view_resizer.h" 18 #import "chrome/browser/cocoa/view_resizer.h"
18 #include "chrome/browser/cocoa/nsimage_cache.h" 19 #include "chrome/browser/cocoa/nsimage_cache.h"
19 #include "chrome/browser/profile.h" 20 #include "chrome/browser/profile.h"
20 #import "chrome/common/cocoa_utils.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/common/pref_service.h" 22 #include "chrome/common/pref_service.h"
23 #include "skia/ext/skia_utils_mac.h" 23 #include "skia/ext/skia_utils_mac.h"
24 24
25 // Specialization of NSButton that responds to middle-clicks. By default,
26 // NSButton ignores them.
27 @interface BookmarkButton : NSButton
28 @end
29
30 @implementation BookmarkButton
31 - (void)otherMouseUp:(NSEvent*) event {
32 [self performClick:self];
33 }
34 @end
35
25 @interface BookmarkBarController(Private) 36 @interface BookmarkBarController(Private)
26 - (void)applyContentAreaOffset:(BOOL)apply immediately:(BOOL)immediately; 37 - (void)applyContentAreaOffset:(BOOL)apply immediately:(BOOL)immediately;
27 - (void)showBookmarkBar:(BOOL)enable immediately:(BOOL)immediately; 38 - (void)showBookmarkBar:(BOOL)enable immediately:(BOOL)immediately;
28 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu; 39 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu;
29 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu; 40 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu;
30 - (void)tagEmptyMenu:(NSMenu*)menu; 41 - (void)tagEmptyMenu:(NSMenu*)menu;
31 - (void)clearMenuTagMap; 42 - (void)clearMenuTagMap;
32 @end 43 @end
33 44
34 namespace { 45 namespace {
35 46
36 // Our height, when opened. 47 // Our height, when opened.
37 const int kBookmarkBarHeight = 30; 48 const int kBookmarkBarHeight = 30;
38 49
39 // Magic numbers from Cole 50 // Magic numbers from Cole
40 const CGFloat kDefaultBookmarkWidth = 150.0; 51 const CGFloat kDefaultBookmarkWidth = 150.0;
41 const CGFloat kBookmarkVerticalPadding = 2.0; 52 const CGFloat kBookmarkVerticalPadding = 2.0;
42 const CGFloat kBookmarkHorizontalPadding = 1.0; 53 const CGFloat kBookmarkHorizontalPadding = 1.0;
43 }; 54
55 } // namespace
44 56
45 @implementation BookmarkBarController 57 @implementation BookmarkBarController
46 58
47 - (id)initWithProfile:(Profile*)profile 59 - (id)initWithProfile:(Profile*)profile
48 initialWidth:(float)initialWidth 60 initialWidth:(float)initialWidth
49 resizeDelegate:(id<ViewResizer>)resizeDelegate 61 resizeDelegate:(id<ViewResizer>)resizeDelegate
50 urlDelegate:(id<BookmarkURLOpener>)urlDelegate { 62 urlDelegate:(id<BookmarkURLOpener>)urlDelegate {
51 if ((self = [super initWithNibName:@"BookmarkBar" 63 if ((self = [super initWithNibName:@"BookmarkBar"
52 bundle:mac_util::MainAppBundle()])) { 64 bundle:mac_util::MainAppBundle()])) {
53 profile_ = profile; 65 profile_ = profile;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 - (BookmarkNode*)nodeFromButton:(id)button { 191 - (BookmarkNode*)nodeFromButton:(id)button {
180 NSCell* cell = [button cell]; 192 NSCell* cell = [button cell];
181 BookmarkNode* node = static_cast<BookmarkNode*>( 193 BookmarkNode* node = static_cast<BookmarkNode*>(
182 [[cell representedObject] pointerValue]); 194 [[cell representedObject] pointerValue]);
183 DCHECK(node); 195 DCHECK(node);
184 return node; 196 return node;
185 } 197 }
186 198
187 - (IBAction)openBookmark:(id)sender { 199 - (IBAction)openBookmark:(id)sender {
188 BookmarkNode* node = [self nodeFromButton:sender]; 200 BookmarkNode* node = [self nodeFromButton:sender];
189 WindowOpenDisposition disposition = event_utils::DispositionFromEventFlags( 201 [urlDelegate_ openBookmarkURL:node->GetURL()
190 [[NSApp currentEvent] modifierFlags]); 202 disposition:event_utils::WindowOpenDispositionFromNSEvent(
191 [urlDelegate_ openBookmarkURL:node->GetURL() disposition:disposition]; 203 [NSApp currentEvent])];
192 } 204 }
193 205
194 // Given a NSMenuItem tag, return the appropriate bookmark node id. 206 // Given a NSMenuItem tag, return the appropriate bookmark node id.
195 - (int64)nodeIdFromMenuTag:(int32)tag { 207 - (int64)nodeIdFromMenuTag:(int32)tag {
196 return menuTagMap_[tag]; 208 return menuTagMap_[tag];
197 } 209 }
198 210
199 // Create and return a new tag for the given node id. 211 // Create and return a new tag for the given node id.
200 - (int32)menuTagFromNodeId:(int64)menuid { 212 - (int32)menuTagFromNodeId:(int64)menuid {
201 int tag = seedId_++; 213 int tag = seedId_++;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 each_frame.origin.x += delta; 506 each_frame.origin.x += delta;
495 [each_button setFrame:each_frame]; 507 [each_button setFrame:each_frame];
496 } 508 }
497 } 509 }
498 } 510 }
499 } 511 }
500 512
501 - (IBAction)openBookmarkMenuItem:(id)sender { 513 - (IBAction)openBookmarkMenuItem:(id)sender {
502 int64 tag = [self nodeIdFromMenuTag:[sender tag]]; 514 int64 tag = [self nodeIdFromMenuTag:[sender tag]];
503 const BookmarkNode* node = bookmarkModel_->GetNodeByID(tag); 515 const BookmarkNode* node = bookmarkModel_->GetNodeByID(tag);
504 WindowOpenDisposition disposition = event_utils::DispositionFromEventFlags( 516 WindowOpenDisposition disposition =
505 [[NSApp currentEvent] modifierFlags]); 517 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]);
506 [urlDelegate_ openBookmarkURL:node->GetURL() disposition:disposition]; 518 [urlDelegate_ openBookmarkURL:node->GetURL() disposition:disposition];
507 } 519 }
508 520
509 // Add all items from the given model to our bookmark bar. 521 // Add all items from the given model to our bookmark bar.
510 // TODO(jrg): lots of things! 522 // TODO(jrg): lots of things!
511 // - bookmark folders (e.g. menu from the button) 523 // - bookmark folders (e.g. menu from the button)
512 // - button and menu on the right for when bookmarks don't all fit on the 524 // - button and menu on the right for when bookmarks don't all fit on the
513 // screen 525 // screen
514 // - ... 526 // - ...
515 // 527 //
516 // TODO(jrg): write a "build bar" so there is a nice spot for things 528 // TODO(jrg): write a "build bar" so there is a nice spot for things
517 // like the contextual menu which is invoked when not over a 529 // like the contextual menu which is invoked when not over a
518 // bookmark. On Safari that menu has a "new folder" option. 530 // bookmark. On Safari that menu has a "new folder" option.
519 - (void)addNodesToBar:(const BookmarkNode*)node { 531 - (void)addNodesToBar:(const BookmarkNode*)node {
520 int x_offset = 0; 532 int x_offset = 0;
521 for (int i = 0; i < node->GetChildCount(); i++) { 533 for (int i = 0; i < node->GetChildCount(); i++) {
522 const BookmarkNode* child = node->GetChild(i); 534 const BookmarkNode* child = node->GetChild(i);
523 535
524 NSCell* cell = [self cellForBookmarkNode:child]; 536 NSCell* cell = [self cellForBookmarkNode:child];
525 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&x_offset]; 537 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&x_offset];
526 NSButton* button = [[[NSButton alloc] initWithFrame:frame] 538 NSButton* button = [[[BookmarkButton alloc] initWithFrame:frame]
527 autorelease]; 539 autorelease];
528 DCHECK(button); 540 DCHECK(button);
529 [buttons_ addObject:button]; 541 [buttons_ addObject:button];
530 542
531 // [NSButton setCell:] warns to NOT use setCell: other than in the 543 // [NSButton setCell:] warns to NOT use setCell: other than in the
532 // initializer of a control. However, we are using a basic 544 // initializer of a control. However, we are using a basic
533 // NSButton whose initializer does not take an NSCell as an 545 // NSButton whose initializer does not take an NSCell as an
534 // object. To honor the assumed semantics, we do nothing with 546 // object. To honor the assumed semantics, we do nothing with
535 // NSButton between alloc/init and setCell:. 547 // NSButton between alloc/init and setCell:.
536 [button setCell:cell]; 548 [button setCell:cell];
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 645
634 - (void)setUrlDelegate:(id<BookmarkURLOpener>)urlDelegate { 646 - (void)setUrlDelegate:(id<BookmarkURLOpener>)urlDelegate {
635 urlDelegate_ = urlDelegate; 647 urlDelegate_ = urlDelegate;
636 } 648 }
637 649
638 - (NSArray*)buttons { 650 - (NSArray*)buttons {
639 return buttons_.get(); 651 return buttons_.get();
640 } 652 }
641 653
642 @end 654 @end
OLDNEW
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/cocoa/bookmark_bar_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698