| OLD | NEW |
| 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/extensions/browser_actions_controller.h" | 5 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 @implementation BrowserActionsController | 228 @implementation BrowserActionsController |
| 229 | 229 |
| 230 @synthesize containerView = containerView_; | 230 @synthesize containerView = containerView_; |
| 231 @synthesize browser = browser_; | 231 @synthesize browser = browser_; |
| 232 | 232 |
| 233 #pragma mark - | 233 #pragma mark - |
| 234 #pragma mark Public Methods | 234 #pragma mark Public Methods |
| 235 | 235 |
| 236 - (id)initWithBrowser:(Browser*)browser | 236 - (id)initWithBrowser:(Browser*)browser |
| 237 containerView:(BrowserActionsContainerView*)container | 237 containerView:(BrowserActionsContainerView*)container |
| 238 isOverflow:(BOOL)isOverflow { | 238 mainController:(BrowserActionsController*)mainController { |
| 239 DCHECK(browser && container); | 239 DCHECK(browser && container); |
| 240 | 240 |
| 241 if ((self = [super init])) { | 241 if ((self = [super init])) { |
| 242 browser_ = browser; | 242 browser_ = browser; |
| 243 isOverflow_ = isOverflow; | 243 isOverflow_ = mainController != nil; |
| 244 | 244 |
| 245 toolbarActionsBarBridge_.reset(new ToolbarActionsBarBridge(self)); | 245 toolbarActionsBarBridge_.reset(new ToolbarActionsBarBridge(self)); |
| 246 ToolbarActionsBar* mainBar = |
| 247 mainController ? [mainController toolbarActionsBar] : nullptr; |
| 246 toolbarActionsBar_.reset( | 248 toolbarActionsBar_.reset( |
| 247 new ToolbarActionsBar(toolbarActionsBarBridge_.get(), | 249 new ToolbarActionsBar(toolbarActionsBarBridge_.get(), |
| 248 browser_, | 250 browser_, |
| 249 isOverflow)); | 251 mainBar)); |
| 250 | 252 |
| 251 containerView_ = container; | 253 containerView_ = container; |
| 252 [containerView_ setPostsFrameChangedNotifications:YES]; | 254 [containerView_ setPostsFrameChangedNotifications:YES]; |
| 253 [[NSNotificationCenter defaultCenter] | 255 [[NSNotificationCenter defaultCenter] |
| 254 addObserver:self | 256 addObserver:self |
| 255 selector:@selector(containerFrameChanged:) | 257 selector:@selector(containerFrameChanged:) |
| 256 name:NSViewFrameDidChangeNotification | 258 name:NSViewFrameDidChangeNotification |
| 257 object:containerView_]; | 259 object:containerView_]; |
| 258 [[NSNotificationCenter defaultCenter] | 260 [[NSNotificationCenter defaultCenter] |
| 259 addObserver:self | 261 addObserver:self |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { | 450 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { |
| 449 if ([[buttons_ objectAtIndex:i] viewController] != toolbar_actions[i]) { | 451 if ([[buttons_ objectAtIndex:i] viewController] != toolbar_actions[i]) { |
| 450 size_t j = i + 1; | 452 size_t j = i + 1; |
| 451 while (toolbar_actions[i] != [[buttons_ objectAtIndex:j] viewController]) | 453 while (toolbar_actions[i] != [[buttons_ objectAtIndex:j] viewController]) |
| 452 ++j; | 454 ++j; |
| 453 [buttons_ exchangeObjectAtIndex:i withObjectAtIndex: j]; | 455 [buttons_ exchangeObjectAtIndex:i withObjectAtIndex: j]; |
| 454 } | 456 } |
| 455 } | 457 } |
| 456 | 458 |
| 457 [self showChevronIfNecessaryInFrame:[containerView_ frame]]; | 459 [self showChevronIfNecessaryInFrame:[containerView_ frame]]; |
| 458 NSUInteger offset = isOverflow_ ? | 460 NSUInteger minIndex = isOverflow_ ? |
| 459 [buttons_ count] - toolbarActionsBar_->GetIconCount() : 0; | 461 [buttons_ count] - toolbarActionsBar_->GetIconCount() : 0; |
| 460 for (NSUInteger i = offset; i < [buttons_ count]; ++i) { | 462 NSUInteger maxIndex = isOverflow_ ? |
| 461 if (![[buttons_ objectAtIndex:i] isBeingDragged]) | 463 [buttons_ count] : toolbarActionsBar_->GetIconCount(); |
| 462 [self moveButton:[buttons_ objectAtIndex:i] toIndex:i - offset]; | 464 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { |
| 465 BrowserActionButton* button = [buttons_ objectAtIndex:i]; |
| 466 if ([button isBeingDragged]) |
| 467 continue; |
| 468 |
| 469 [self moveButton:[buttons_ objectAtIndex:i] toIndex:i - minIndex]; |
| 470 |
| 471 if (i >= minIndex && i < maxIndex) { |
| 472 // Make sure the button is within the visible container. |
| 473 if ([button superview] != containerView_) { |
| 474 // We add the subview under the sibling views so that when it |
| 475 // "slides in", it does so under its neighbors. |
| 476 [containerView_ addSubview:button |
| 477 positioned:NSWindowBelow |
| 478 relativeTo:nil]; |
| 479 } |
| 480 // We need to set the alpha value in case the container has resized. |
| 481 [button setAlphaValue:1.0]; |
| 482 } else if ([button superview] == containerView_) { |
| 483 [button removeFromSuperview]; |
| 484 [button setAlphaValue:0.0]; |
| 485 } |
| 463 } | 486 } |
| 464 } | 487 } |
| 465 | 488 |
| 466 - (void)removeViewForAction:(ToolbarActionViewController*)action { | 489 - (void)removeViewForAction:(ToolbarActionViewController*)action { |
| 467 BrowserActionButton* button = [self buttonForId:action->GetId()]; | 490 BrowserActionButton* button = [self buttonForId:action->GetId()]; |
| 468 | 491 |
| 469 [button removeFromSuperview]; | 492 [button removeFromSuperview]; |
| 470 [button onRemoved]; | 493 [button onRemoved]; |
| 471 [buttons_ removeObject:button]; | 494 [buttons_ removeObject:button]; |
| 472 } | 495 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 CGFloat xOffset = platformSettings.left_padding + | 643 CGFloat xOffset = platformSettings.left_padding + |
| 621 (indexInRow * ToolbarActionsBar::IconWidth(true)); | 644 (indexInRow * ToolbarActionsBar::IconWidth(true)); |
| 622 | 645 |
| 623 NSRect buttonFrame = [button frame]; | 646 NSRect buttonFrame = [button frame]; |
| 624 buttonFrame.origin.x = xOffset; | 647 buttonFrame.origin.x = xOffset; |
| 625 buttonFrame.origin.y = NSMaxY([containerView_ frame]) - | 648 buttonFrame.origin.y = NSMaxY([containerView_ frame]) - |
| 626 (ToolbarActionsBar::IconHeight() * (rowIndex + 1)); | 649 (ToolbarActionsBar::IconHeight() * (rowIndex + 1)); |
| 627 | 650 |
| 628 [button setFrame:buttonFrame | 651 [button setFrame:buttonFrame |
| 629 animate:!toolbarActionsBar_->suppress_animation()]; | 652 animate:!toolbarActionsBar_->suppress_animation()]; |
| 630 | |
| 631 if (index < toolbarActionsBar_->GetIconCount()) { | |
| 632 // Make sure the button is within the visible container. | |
| 633 if ([button superview] != containerView_) { | |
| 634 // We add the subview under the sibling views so that when it "slides in", | |
| 635 // it does so under its neighbors. | |
| 636 [containerView_ addSubview:button | |
| 637 positioned:NSWindowBelow | |
| 638 relativeTo:nil]; | |
| 639 } | |
| 640 // We need to set the alpha value in case the container has resized. | |
| 641 [button setAlphaValue:1.0]; | |
| 642 } else if ([button superview] == containerView_) { | |
| 643 [button removeFromSuperview]; | |
| 644 [button setAlphaValue:0.0]; | |
| 645 } | |
| 646 } | 653 } |
| 647 | 654 |
| 648 - (BOOL)browserActionClicked:(BrowserActionButton*)button { | 655 - (BOOL)browserActionClicked:(BrowserActionButton*)button { |
| 649 return [button viewController]->ExecuteAction(true); | 656 return [button viewController]->ExecuteAction(true); |
| 650 } | 657 } |
| 651 | 658 |
| 652 - (void)showChevronIfNecessaryInFrame:(NSRect)frame { | 659 - (void)showChevronIfNecessaryInFrame:(NSRect)frame { |
| 653 if (!toolbarActionsBar_->platform_settings().chevron_enabled) | 660 if (!toolbarActionsBar_->platform_settings().chevron_enabled) |
| 654 return; | 661 return; |
| 655 bool hidden = suppressChevron_ || | 662 bool hidden = suppressChevron_ || |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 - (ToolbarActionsBar*)toolbarActionsBar { | 748 - (ToolbarActionsBar*)toolbarActionsBar { |
| 742 return toolbarActionsBar_.get(); | 749 return toolbarActionsBar_.get(); |
| 743 } | 750 } |
| 744 | 751 |
| 745 + (BrowserActionsController*)fromToolbarActionsBarDelegate: | 752 + (BrowserActionsController*)fromToolbarActionsBarDelegate: |
| 746 (ToolbarActionsBarDelegate*)delegate { | 753 (ToolbarActionsBarDelegate*)delegate { |
| 747 return static_cast<ToolbarActionsBarBridge*>(delegate)->controller_for_test(); | 754 return static_cast<ToolbarActionsBarBridge*>(delegate)->controller_for_test(); |
| 748 } | 755 } |
| 749 | 756 |
| 750 @end | 757 @end |
| OLD | NEW |