| 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 "browser_actions_controller.h" | 5 #import "browser_actions_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 436 } |
| 437 | 437 |
| 438 #pragma mark - | 438 #pragma mark - |
| 439 #pragma mark Private Methods | 439 #pragma mark Private Methods |
| 440 | 440 |
| 441 - (void)createButtons { | 441 - (void)createButtons { |
| 442 if (!toolbarModel_) | 442 if (!toolbarModel_) |
| 443 return; | 443 return; |
| 444 | 444 |
| 445 NSUInteger i = 0; | 445 NSUInteger i = 0; |
| 446 for (ExtensionList::iterator iter = toolbarModel_->begin(); | 446 for (ExtensionList::const_iterator iter = |
| 447 iter != toolbarModel_->end(); ++iter) { | 447 toolbarModel_->toolbar_items().begin(); |
| 448 iter != toolbarModel_->toolbar_items().end(); ++iter) { |
| 448 if (![self shouldDisplayBrowserAction:*iter]) | 449 if (![self shouldDisplayBrowserAction:*iter]) |
| 449 continue; | 450 continue; |
| 450 | 451 |
| 451 [self createActionButtonForExtension:*iter withIndex:i++]; | 452 [self createActionButtonForExtension:*iter withIndex:i++]; |
| 452 } | 453 } |
| 453 | 454 |
| 454 CGFloat width = [self savedWidth]; | 455 CGFloat width = [self savedWidth]; |
| 455 [containerView_ resizeToWidth:width animate:NO]; | 456 [containerView_ resizeToWidth:width animate:NO]; |
| 456 } | 457 } |
| 457 | 458 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } else { | 527 } else { |
| 527 [self positionActionButtonsAndAnimate:NO]; | 528 [self positionActionButtonsAndAnimate:NO]; |
| 528 } | 529 } |
| 529 [containerView_ setMaxWidth: | 530 [containerView_ setMaxWidth: |
| 530 [self containerWidthWithButtonCount:[self buttonCount]]]; | 531 [self containerWidthWithButtonCount:[self buttonCount]]]; |
| 531 [containerView_ setNeedsDisplay:YES]; | 532 [containerView_ setNeedsDisplay:YES]; |
| 532 } | 533 } |
| 533 | 534 |
| 534 - (void)positionActionButtonsAndAnimate:(BOOL)animate { | 535 - (void)positionActionButtonsAndAnimate:(BOOL)animate { |
| 535 NSUInteger i = 0; | 536 NSUInteger i = 0; |
| 536 for (ExtensionList::iterator iter = toolbarModel_->begin(); | 537 for (ExtensionList::const_iterator iter = |
| 537 iter != toolbarModel_->end(); ++iter) { | 538 toolbarModel_->toolbar_items().begin(); |
| 539 iter != toolbarModel_->toolbar_items().end(); ++iter) { |
| 538 if (![self shouldDisplayBrowserAction:*iter]) | 540 if (![self shouldDisplayBrowserAction:*iter]) |
| 539 continue; | 541 continue; |
| 540 BrowserActionButton* button = [self buttonForExtension:(*iter)]; | 542 BrowserActionButton* button = [self buttonForExtension:(*iter)]; |
| 541 if (!button) | 543 if (!button) |
| 542 continue; | 544 continue; |
| 543 if (![button isBeingDragged]) | 545 if (![button isBeingDragged]) |
| 544 [self moveButton:button toIndex:i animate:animate]; | 546 [self moveButton:button toIndex:i animate:animate]; |
| 545 ++i; | 547 ++i; |
| 546 } | 548 } |
| 547 } | 549 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 } | 619 } |
| 618 } | 620 } |
| 619 | 621 |
| 620 - (void)containerDragging:(NSNotification*)notification { | 622 - (void)containerDragging:(NSNotification*)notification { |
| 621 [[NSNotificationCenter defaultCenter] | 623 [[NSNotificationCenter defaultCenter] |
| 622 postNotificationName:kBrowserActionGrippyDraggingNotification | 624 postNotificationName:kBrowserActionGrippyDraggingNotification |
| 623 object:self]; | 625 object:self]; |
| 624 } | 626 } |
| 625 | 627 |
| 626 - (void)containerDragFinished:(NSNotification*)notification { | 628 - (void)containerDragFinished:(NSNotification*)notification { |
| 627 for (ExtensionList::iterator iter = toolbarModel_->begin(); | 629 for (ExtensionList::const_iterator iter = |
| 628 iter != toolbarModel_->end(); ++iter) { | 630 toolbarModel_->toolbar_items().begin(); |
| 631 iter != toolbarModel_->toolbar_items().end(); ++iter) { |
| 629 BrowserActionButton* button = [self buttonForExtension:(*iter)]; | 632 BrowserActionButton* button = [self buttonForExtension:(*iter)]; |
| 630 NSRect buttonFrame = [button frame]; | 633 NSRect buttonFrame = [button frame]; |
| 631 if (NSContainsRect([containerView_ bounds], buttonFrame)) | 634 if (NSContainsRect([containerView_ bounds], buttonFrame)) |
| 632 continue; | 635 continue; |
| 633 | 636 |
| 634 CGFloat intersectionWidth = | 637 CGFloat intersectionWidth = |
| 635 NSWidth(NSIntersectionRect([containerView_ bounds], buttonFrame)); | 638 NSWidth(NSIntersectionRect([containerView_ bounds], buttonFrame)); |
| 636 // Pad the threshold by 5 pixels in order to have the buttons hide more | 639 // Pad the threshold by 5 pixels in order to have the buttons hide more |
| 637 // easily. | 640 // easily. |
| 638 if (([containerView_ grippyPinned] && intersectionWidth > 0) || | 641 if (([containerView_ grippyPinned] && intersectionWidth > 0) || |
| (...skipping 17 matching lines...) Expand all Loading... |
| 656 if (![self chevronIsHidden]) | 659 if (![self chevronIsHidden]) |
| 657 [self setChevronHidden:YES inFrame:[containerView_ frame] animate:YES]; | 660 [self setChevronHidden:YES inFrame:[containerView_ frame] animate:YES]; |
| 658 | 661 |
| 659 // Determine what index the dragged button should lie in, alter the model and | 662 // Determine what index the dragged button should lie in, alter the model and |
| 660 // reposition the buttons. | 663 // reposition the buttons. |
| 661 CGFloat dragThreshold = std::floor(kBrowserActionWidth / 2); | 664 CGFloat dragThreshold = std::floor(kBrowserActionWidth / 2); |
| 662 BrowserActionButton* draggedButton = [notification object]; | 665 BrowserActionButton* draggedButton = [notification object]; |
| 663 NSRect draggedButtonFrame = [draggedButton frame]; | 666 NSRect draggedButtonFrame = [draggedButton frame]; |
| 664 | 667 |
| 665 NSUInteger index = 0; | 668 NSUInteger index = 0; |
| 666 for (ExtensionList::iterator iter = toolbarModel_->begin(); | 669 for (ExtensionList::const_iterator iter = |
| 667 iter != toolbarModel_->end(); ++iter) { | 670 toolbarModel_->toolbar_items().begin(); |
| 671 iter != toolbarModel_->toolbar_items().end(); ++iter) { |
| 668 BrowserActionButton* button = [self buttonForExtension:(*iter)]; | 672 BrowserActionButton* button = [self buttonForExtension:(*iter)]; |
| 669 CGFloat intersectionWidth = | 673 CGFloat intersectionWidth = |
| 670 NSWidth(NSIntersectionRect(draggedButtonFrame, [button frame])); | 674 NSWidth(NSIntersectionRect(draggedButtonFrame, [button frame])); |
| 671 | 675 |
| 672 if (intersectionWidth > dragThreshold && button != draggedButton && | 676 if (intersectionWidth > dragThreshold && button != draggedButton && |
| 673 ![button isAnimating] && index < [self visibleButtonCount]) { | 677 ![button isAnimating] && index < [self visibleButtonCount]) { |
| 674 toolbarModel_->MoveBrowserAction([draggedButton extension], index); | 678 toolbarModel_->MoveBrowserAction([draggedButton extension], index); |
| 675 [self positionActionButtonsAndAnimate:YES]; | 679 [self positionActionButtonsAndAnimate:YES]; |
| 676 return; | 680 return; |
| 677 } | 681 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 | 823 |
| 820 return selected_tab->restore_tab_helper()->session_id().id(); | 824 return selected_tab->restore_tab_helper()->session_id().id(); |
| 821 } | 825 } |
| 822 | 826 |
| 823 #pragma mark - | 827 #pragma mark - |
| 824 #pragma mark Testing Methods | 828 #pragma mark Testing Methods |
| 825 | 829 |
| 826 - (NSButton*)buttonWithIndex:(NSUInteger)index { | 830 - (NSButton*)buttonWithIndex:(NSUInteger)index { |
| 827 if (profile_->IsOffTheRecord()) | 831 if (profile_->IsOffTheRecord()) |
| 828 index = toolbarModel_->IncognitoIndexToOriginal(index); | 832 index = toolbarModel_->IncognitoIndexToOriginal(index); |
| 829 if (index < toolbarModel_->size()) { | 833 const extensions::ExtensionList& toolbar_items = |
| 830 const Extension* extension = toolbarModel_->GetExtensionByIndex(index); | 834 toolbarModel_->toolbar_items(); |
| 835 if (index < toolbar_items.size()) { |
| 836 const Extension* extension = toolbar_items[index]; |
| 831 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 837 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
| 832 } | 838 } |
| 833 return nil; | 839 return nil; |
| 834 } | 840 } |
| 835 | 841 |
| 836 @end | 842 @end |
| OLD | NEW |