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

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

Issue 2729603008: [Mac] Remove bookmark bar NIB (Closed)
Patch Set: Cleanup Created 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/cocoa/bookmarks/bookmark_bar_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #import "base/mac/bundle_locations.h" 9 #import "base/mac/bundle_locations.h"
10 #import "base/mac/foundation_util.h" 10 #import "base/mac/foundation_util.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 317 }
318 318
319 - (BookmarkBarToolbarView*)controlledView { 319 - (BookmarkBarToolbarView*)controlledView {
320 return base::mac::ObjCCastStrict<BookmarkBarToolbarView>([self view]); 320 return base::mac::ObjCCastStrict<BookmarkBarToolbarView>([self view]);
321 } 321 }
322 322
323 - (BookmarkContextMenuCocoaController*)menuController { 323 - (BookmarkContextMenuCocoaController*)menuController {
324 return contextMenuController_.get(); 324 return contextMenuController_.get();
325 } 325 }
326 326
327 - (void)loadView {
328 // Height is 0 because this is what the superview expects
329 [self setView:[[[BookmarkBarToolbarView alloc]
330 initWithFrame:NSMakeRect(0, 0, initialWidth_, 0)]
331 autorelease]];
332 [[self view] setHidden:YES];
333 [[self view] setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
334 [[self controlledView] setController:self];
335 [[self controlledView] setDelegate:self];
336
337 buttonView_.reset([[BookmarkBarView alloc]
338 initWithController:self
339 frame:NSMakeRect(0, -2, 584, 144)]);
340 [buttonView_ setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin |
341 NSViewMaxXMargin];
342 [[buttonView_ importBookmarksButton] setTarget:self];
343 [[buttonView_ importBookmarksButton] setAction:@selector(importBookmarks:)];
344
345 [self createOffTheSideButton];
346 [buttonView_ addSubview:offTheSideButton_];
347
348 [self.view addSubview:buttonView_];
349 // viewDidLoad became part of the API in 10.10
350 if (base::mac::IsAtMostOS10_9())
351 [self viewDidLoad];
352 }
353
327 - (BookmarkButton*)bookmarkButtonToPulseForNode:(const BookmarkNode*)node { 354 - (BookmarkButton*)bookmarkButtonToPulseForNode:(const BookmarkNode*)node {
328 // Find the closest parent that is visible on the bar. 355 // Find the closest parent that is visible on the bar.
329 while (node) { 356 while (node) {
330 // Check if we've reached one of the special buttons. Otherwise, if the next 357 // Check if we've reached one of the special buttons. Otherwise, if the next
331 // parent is the boomark bar, find the corresponding button. 358 // parent is the boomark bar, find the corresponding button.
332 if ([managedBookmarksButton_ bookmarkNode] == node) 359 if ([managedBookmarksButton_ bookmarkNode] == node)
333 return managedBookmarksButton_; 360 return managedBookmarksButton_;
334 361
335 if ([supervisedBookmarksButton_ bookmarkNode] == node) 362 if ([supervisedBookmarksButton_ bookmarkNode] == node)
336 return supervisedBookmarksButton_; 363 return supervisedBookmarksButton_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 - (void)stopPulsingBookmarkNode { 403 - (void)stopPulsingBookmarkNode {
377 if (!pulsingButton_) 404 if (!pulsingButton_)
378 return; 405 return;
379 406
380 [pulsingButton_ setPulseIsStuckOn:NO]; 407 [pulsingButton_ setPulseIsStuckOn:NO];
381 pulsingButton_.reset(); 408 pulsingButton_.reset();
382 pulsingBookmarkObserver_.reset(); 409 pulsingBookmarkObserver_.reset();
383 } 410 }
384 411
385 - (void)dealloc { 412 - (void)dealloc {
413 [buttonView_ setController:nil];
414 [[self controlledView] setController:nil];
415 [[self controlledView] setDelegate:nil];
386 [self browserWillBeDestroyed]; 416 [self browserWillBeDestroyed];
387 [super dealloc]; 417 [super dealloc];
388 } 418 }
389 419
390 - (void)browserWillBeDestroyed { 420 - (void)browserWillBeDestroyed {
391 // If |bridge_| is null it means -viewDidLoad has not yet been called, which 421 // If |bridge_| is null it means -viewDidLoad has not yet been called, which
392 // can only happen if the nib wasn't loaded. Retrieving it via -[self view] 422 // can only happen if the nib wasn't loaded. Retrieving it via -[self view]
393 // would load it now, but it's too late for that, so let it be nil. Note this 423 // would load it now, but it's too late for that, so let it be nil. Note this
394 // should only happen in tests. 424 // should only happen in tests.
395 BookmarkBarToolbarView* view = nil; 425 BookmarkBarToolbarView* view = nil;
(...skipping 21 matching lines...) Expand all
417 [button setTarget:nil]; 447 [button setTarget:nil];
418 [button setAction:nil]; 448 [button setAction:nil];
419 } 449 }
420 450
421 bridge_.reset(NULL); 451 bridge_.reset(NULL);
422 [[NSNotificationCenter defaultCenter] removeObserver:self]; 452 [[NSNotificationCenter defaultCenter] removeObserver:self];
423 [self watchForExitEvent:NO]; 453 [self watchForExitEvent:NO];
424 browser_ = nullptr; 454 browser_ = nullptr;
425 } 455 }
426 456
427 - (void)awakeFromNib {
428 [self viewDidLoad];
429 }
430
431 - (void)viewDidLoad { 457 - (void)viewDidLoad {
432 if (bridge_) {
433 // When running on 10.10, expect both -awakeFromNib and -viewDidLoad to be
434 // called, but only initialize once.
435 DCHECK(base::mac::IsAtLeastOS10_10());
436 return;
437 }
438
439 // We default to NOT open, which means height=0.
440 DCHECK([[self view] isHidden]); // Hidden so it's OK to change.
441
442 // Set our initial height to zero, since that is what the superview
443 // expects. We will resize ourselves open later if needed.
444 [[self view] setFrame:NSMakeRect(0, 0, initialWidth_, 0)];
445
446 // Complete init of the "off the side" button, as much as we can.
447 [offTheSideButton_ setImage:[self offTheSideButtonImage:NO]];
448 BookmarkButtonCell* offTheSideCell = [offTheSideButton_ cell];
449 [offTheSideCell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback];
450 [offTheSideCell setImagePosition:NSImageOnly];
451
452 // The cell is configured in the nib to draw a white highlight when clicked.
453 [offTheSideCell setHighlightsBy:NSNoCellMask];
454 [offTheSideButton_.draggableButton setDraggable:NO];
455 [offTheSideButton_.draggableButton setActsOnMouseDown:YES];
456
457 // We are enabled by default. 458 // We are enabled by default.
458 barIsEnabled_ = YES; 459 barIsEnabled_ = YES;
459 460
460 // Remember the original sizes of the 'no items' and 'import bookmarks' 461 // Remember the original sizes of the 'no items' and 'import bookmarks'
461 // fields to aid in resizing when the window frame changes. 462 // fields to aid in resizing when the window frame changes.
462 originalNoItemsRect_ = [[buttonView_ noItemTextfield] frame]; 463 originalNoItemsRect_ = [[buttonView_ noItemTextfield] frame];
463 originalImportBookmarksRect_ = [[buttonView_ importBookmarksButton] frame]; 464 originalImportBookmarksRect_ = [[buttonView_ importBookmarksButton] frame];
464 465
465 // Bookmark buttons start farther from the bookmark bar's left edge so 466 // Bookmark buttons start farther from the bookmark bar's left edge so
466 // adjust the positions of the noItems and importBookmarks textfields. 467 // adjust the positions of the noItems and importBookmarks textfields.
467 const CGFloat kBookmarksTextfieldOffsetX = 14; 468 const CGFloat kBookmarksTextfieldOffsetX = 14;
468 originalNoItemsRect_.origin.x += kBookmarksTextfieldOffsetX; 469 originalNoItemsRect_.origin.x += kBookmarksTextfieldOffsetX;
469 [[buttonView_ noItemTextfield] setFrame:originalNoItemsRect_]; 470 [[buttonView_ noItemTextfield] setFrame:originalNoItemsRect_];
470 471
471 originalImportBookmarksRect_.origin.x += kBookmarksTextfieldOffsetX; 472 originalImportBookmarksRect_.origin.x += kBookmarksTextfieldOffsetX;
472 [[buttonView_ importBookmarksButton] setFrame:originalImportBookmarksRect_]; 473 [[buttonView_ importBookmarksButton] setFrame:originalImportBookmarksRect_];
473 474
474 // Move the chevron button up 2pts from its position in the xib.
475 NSRect chevronButtonFrame = [offTheSideButton_ frame];
476 chevronButtonFrame.origin.y -= 2;
477 [offTheSideButton_ setFrame:chevronButtonFrame];
478
479 // To make life happier when the bookmark bar is floating, the chevron is a
480 // child of the button view.
481 [offTheSideButton_ removeFromSuperview];
482 [buttonView_ addSubview:offTheSideButton_];
483
484 // When resized we may need to add new buttons, or remove them (if 475 // When resized we may need to add new buttons, or remove them (if
485 // no longer visible), or add/remove the "off the side" menu. 476 // no longer visible), or add/remove the "off the side" menu.
486 [[self view] setPostsFrameChangedNotifications:YES]; 477 [[self view] setPostsFrameChangedNotifications:YES];
487 [[NSNotificationCenter defaultCenter] 478 [[NSNotificationCenter defaultCenter]
488 addObserver:self 479 addObserver:self
489 selector:@selector(frameDidChange) 480 selector:@selector(frameDidChange)
490 name:NSViewFrameDidChangeNotification 481 name:NSViewFrameDidChangeNotification
491 object:[self view]]; 482 object:[self view]];
492 483
493 // Watch for things going to or from fullscreen. 484 // Watch for things going to or from fullscreen.
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 DCHECK([sender isKindOfClass:[BookmarkButton class]]); 824 DCHECK([sender isKindOfClass:[BookmarkButton class]]);
834 DCHECK([[sender cell] isKindOfClass:[BookmarkButtonCell class]]); 825 DCHECK([[sender cell] isKindOfClass:[BookmarkButtonCell class]]);
835 826
836 // Only record the action if it's the initial folder being opened. 827 // Only record the action if it's the initial folder being opened.
837 if (!showFolderMenus_) 828 if (!showFolderMenus_)
838 RecordBookmarkFolderOpen([self bookmarkLaunchLocation]); 829 RecordBookmarkFolderOpen([self bookmarkLaunchLocation]);
839 showFolderMenus_ = !showFolderMenus_; 830 showFolderMenus_ = !showFolderMenus_;
840 831
841 // Middle click on chevron should not open bookmarks under it, instead just 832 // Middle click on chevron should not open bookmarks under it, instead just
842 // open its folder menu. 833 // open its folder menu.
843 if (sender == offTheSideButton_) { 834 if (sender == offTheSideButton_.get()) {
844 [[sender cell] setStartingChildIndex:displayedButtonCount_]; 835 [[sender cell] setStartingChildIndex:displayedButtonCount_];
845 NSEvent* event = [NSApp currentEvent]; 836 NSEvent* event = [NSApp currentEvent];
846 if ([event type] == NSOtherMouseUp) { 837 if ([event type] == NSOtherMouseUp) {
847 [self openOrCloseBookmarkFolderForOffTheSideButton]; 838 [self openOrCloseBookmarkFolderForOffTheSideButton];
848 return; 839 return;
849 } 840 }
850 } 841 }
851 // Toggle presentation of bar folder menus. 842 // Toggle presentation of bar folder menus.
852 [folderTarget_ openBookmarkFolderFromButton:sender]; 843 [folderTarget_ openBookmarkFolderFromButton:sender];
853 } 844 }
854 845
855 - (void)openOrCloseBookmarkFolderForOffTheSideButton { 846 - (void)openOrCloseBookmarkFolderForOffTheSideButton {
856 // If clicked on already opened folder, then close it and return. 847 // If clicked on already opened folder, then close it and return.
857 if ([folderController_ parentButton] == offTheSideButton_) 848 if ([folderController_ parentButton] == offTheSideButton_)
858 [self closeBookmarkFolder:self]; 849 [self closeBookmarkFolder:self];
859 else 850 else
860 [self addNewFolderControllerWithParentButton:offTheSideButton_]; 851 [self addNewFolderControllerWithParentButton:offTheSideButton_];
861 } 852 }
862 853
863 // Click on a bookmark folder button. 854 // Click on a bookmark folder button.
864 - (IBAction)openBookmarkFolderFromButton:(id)sender { 855 - (void)openBookmarkFolderFromButton:(id)sender {
865 [self openBookmarkFolder:sender]; 856 [self openBookmarkFolder:sender];
866 } 857 }
867 858
868 // Click on the "off the side" button (chevron), which opens like a folder 859 // Click on the "off the side" button (chevron), which opens like a folder
869 // button but isn't exactly a parent folder. 860 // button but isn't exactly a parent folder.
870 - (IBAction)openOffTheSideFolderFromButton:(id)sender { 861 - (void)openOffTheSideFolderFromButton:(id)sender {
871 [self openBookmarkFolder:sender]; 862 [self openBookmarkFolder:sender];
872 } 863 }
873 864
874 - (IBAction)importBookmarks:(id)sender { 865 - (void)importBookmarks:(id)sender {
875 chrome::ShowImportDialog(browser_); 866 chrome::ShowImportDialog(browser_);
876 } 867 }
877 868
878 - (NSButton*)appsPageShortcutButton { 869 - (NSButton*)appsPageShortcutButton {
879 return appsPageShortcutButton_; 870 return appsPageShortcutButton_;
880 } 871 }
881 872
882 - (NSButton*)offTheSideButton { 873 - (NSButton*)offTheSideButton {
883 return offTheSideButton_; 874 return offTheSideButton_;
884 } 875 }
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 [[appsPageShortcutButton_ draggableButton] setActsOnMouseDown:NO]; 1469 [[appsPageShortcutButton_ draggableButton] setActsOnMouseDown:NO];
1479 [appsPageShortcutButton_ setAction:@selector(openAppsPage:)]; 1470 [appsPageShortcutButton_ setAction:@selector(openAppsPage:)];
1480 NSString* tooltip = 1471 NSString* tooltip =
1481 l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP); 1472 l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP);
1482 [appsPageShortcutButton_ setToolTip:tooltip]; 1473 [appsPageShortcutButton_ setToolTip:tooltip];
1483 [buttonView_ addSubview:appsPageShortcutButton_.get()]; 1474 [buttonView_ addSubview:appsPageShortcutButton_.get()];
1484 1475
1485 [self setAppsPageShortcutButtonVisibility]; 1476 [self setAppsPageShortcutButtonVisibility];
1486 } 1477 }
1487 1478
1479 - (void)createOffTheSideButton {
1480 offTheSideButton_.reset(
1481 [[BookmarkButton alloc] initWithFrame:NSMakeRect(586, 0, 20, 24)]);
1482 id offTheSideCell = [BookmarkButtonCell offTheSideButtonCell];
1483 [offTheSideCell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback];
1484 [offTheSideCell setImagePosition:NSImageOnly];
1485
1486 [offTheSideCell setHighlightsBy:NSNoCellMask];
1487 [offTheSideCell setShowsBorderOnlyWhileMouseInside:YES];
1488 [offTheSideCell setBezelStyle:NSShadowlessSquareBezelStyle];
1489 [offTheSideButton_ setCell:offTheSideCell];
1490 [offTheSideButton_ setImage:[self offTheSideButtonImage:NO]];
1491 [offTheSideButton_ setButtonType:NSMomentaryLightButton];
1492
1493 [offTheSideButton_ setTarget:self];
1494 [offTheSideButton_ setAction:@selector(openOffTheSideFolderFromButton:)];
1495 [offTheSideButton_ setDelegate:self];
1496 [[offTheSideButton_ draggableButton] setDraggable:NO];
1497 [[offTheSideButton_ draggableButton] setActsOnMouseDown:YES];
1498 }
1499
1488 - (void)openAppsPage:(id)sender { 1500 - (void)openAppsPage:(id)sender {
1489 WindowOpenDisposition disposition = 1501 WindowOpenDisposition disposition =
1490 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); 1502 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]);
1491 [self openURL:GURL(chrome::kChromeUIAppsURL) disposition:disposition]; 1503 [self openURL:GURL(chrome::kChromeUIAppsURL) disposition:disposition];
1492 RecordBookmarkAppsPageOpen([self bookmarkLaunchLocation]); 1504 RecordBookmarkAppsPageOpen([self bookmarkLaunchLocation]);
1493 } 1505 }
1494 1506
1495 // To avoid problems with sync, changes that may impact the current 1507 // To avoid problems with sync, changes that may impact the current
1496 // bookmark (e.g. deletion) make sure context menus are closed. This 1508 // bookmark (e.g. deletion) make sure context menus are closed. This
1497 // prevents deleting a node which no longer exists. 1509 // prevents deleting a node which no longer exists.
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 // If the click is in my window but NOT in the bookmark bar, consider 2021 // If the click is in my window but NOT in the bookmark bar, consider
2010 // it a click 'outside'. Clicks directly on an active button (i.e. one 2022 // it a click 'outside'. Clicks directly on an active button (i.e. one
2011 // that is a folder and for which its folder menu is showing) are 'in'. 2023 // that is a folder and for which its folder menu is showing) are 'in'.
2012 // All other clicks on the bookmarks bar are counted as 'outside' 2024 // All other clicks on the bookmarks bar are counted as 'outside'
2013 // because they should close any open bookmark folder menu. 2025 // because they should close any open bookmark folder menu.
2014 if (eventWindow == myWindow) { 2026 if (eventWindow == myWindow) {
2015 NSView* hitView = 2027 NSView* hitView =
2016 [[eventWindow contentView] hitTest:[event locationInWindow]]; 2028 [[eventWindow contentView] hitTest:[event locationInWindow]];
2017 if (hitView == [folderController_ parentButton]) 2029 if (hitView == [folderController_ parentButton])
2018 return NO; 2030 return NO;
2019 if (![hitView isDescendantOf:[self view]] || hitView == buttonView_) 2031 if (![hitView isDescendantOf:[self view]] ||
2032 hitView == buttonView_.get())
2020 return YES; 2033 return YES;
2021 } 2034 }
2022 // If a click in a bookmark bar folder window and that isn't 2035 // If a click in a bookmark bar folder window and that isn't
2023 // one of my bookmark bar folders, YES is click outside. 2036 // one of my bookmark bar folders, YES is click outside.
2024 if (![eventWindow isKindOfClass:[BookmarkBarFolderWindow 2037 if (![eventWindow isKindOfClass:[BookmarkBarFolderWindow
2025 class]]) { 2038 class]]) {
2026 return YES; 2039 return YES;
2027 } 2040 }
2028 break; 2041 break;
2029 case NSKeyDown: { 2042 case NSKeyDown: {
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
3002 - (id<BookmarkButtonControllerProtocol>)controllerForNode: 3015 - (id<BookmarkButtonControllerProtocol>)controllerForNode:
3003 (const BookmarkNode*)node { 3016 (const BookmarkNode*)node {
3004 // See if it's in the bar, then if it is in the hierarchy of visible 3017 // See if it's in the bar, then if it is in the hierarchy of visible
3005 // folder menus. 3018 // folder menus.
3006 if (bookmarkModel_->bookmark_bar_node() == node) 3019 if (bookmarkModel_->bookmark_bar_node() == node)
3007 return self; 3020 return self;
3008 return [folderController_ controllerForNode:node]; 3021 return [folderController_ controllerForNode:node];
3009 } 3022 }
3010 3023
3011 @end 3024 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698