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