| 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 <cmath> | 7 #include <cmath> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 #pragma mark Private Methods | 480 #pragma mark Private Methods |
| 481 | 481 |
| 482 - (void)createButtons { | 482 - (void)createButtons { |
| 483 if (!toolbarModel_) | 483 if (!toolbarModel_) |
| 484 return; | 484 return; |
| 485 | 485 |
| 486 NSUInteger i = 0; | 486 NSUInteger i = 0; |
| 487 for (ExtensionList::const_iterator iter = | 487 for (ExtensionList::const_iterator iter = |
| 488 toolbarModel_->toolbar_items().begin(); | 488 toolbarModel_->toolbar_items().begin(); |
| 489 iter != toolbarModel_->toolbar_items().end(); ++iter) { | 489 iter != toolbarModel_->toolbar_items().end(); ++iter) { |
| 490 if (![self shouldDisplayBrowserAction:*iter]) | 490 if (![self shouldDisplayBrowserAction:iter->get()]) |
| 491 continue; | 491 continue; |
| 492 | 492 |
| 493 [self createActionButtonForExtension:*iter withIndex:i++]; | 493 [self createActionButtonForExtension:iter->get() withIndex:i++]; |
| 494 } | 494 } |
| 495 | 495 |
| 496 CGFloat width = [self savedWidth]; | 496 CGFloat width = [self savedWidth]; |
| 497 [containerView_ resizeToWidth:width animate:NO]; | 497 [containerView_ resizeToWidth:width animate:NO]; |
| 498 } | 498 } |
| 499 | 499 |
| 500 - (void)createActionButtonForExtension:(const Extension*)extension | 500 - (void)createActionButtonForExtension:(const Extension*)extension |
| 501 withIndex:(NSUInteger)index { | 501 withIndex:(NSUInteger)index { |
| 502 if (!extensions::ExtensionActionManager::Get(profile_)-> | 502 if (!extensions::ExtensionActionManager::Get(profile_)-> |
| 503 GetBrowserAction(*extension)) | 503 GetBrowserAction(*extension)) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 [containerView_ setMaxWidth: | 572 [containerView_ setMaxWidth: |
| 573 [self containerWidthWithButtonCount:[self buttonCount]]]; | 573 [self containerWidthWithButtonCount:[self buttonCount]]]; |
| 574 [containerView_ setNeedsDisplay:YES]; | 574 [containerView_ setNeedsDisplay:YES]; |
| 575 } | 575 } |
| 576 | 576 |
| 577 - (void)positionActionButtonsAndAnimate:(BOOL)animate { | 577 - (void)positionActionButtonsAndAnimate:(BOOL)animate { |
| 578 NSUInteger i = 0; | 578 NSUInteger i = 0; |
| 579 for (ExtensionList::const_iterator iter = | 579 for (ExtensionList::const_iterator iter = |
| 580 toolbarModel_->toolbar_items().begin(); | 580 toolbarModel_->toolbar_items().begin(); |
| 581 iter != toolbarModel_->toolbar_items().end(); ++iter) { | 581 iter != toolbarModel_->toolbar_items().end(); ++iter) { |
| 582 if (![self shouldDisplayBrowserAction:*iter]) | 582 if (![self shouldDisplayBrowserAction:iter->get()]) |
| 583 continue; | 583 continue; |
| 584 BrowserActionButton* button = [self buttonForExtension:(*iter)]; | 584 BrowserActionButton* button = [self buttonForExtension:(iter->get())]; |
| 585 if (!button) | 585 if (!button) |
| 586 continue; | 586 continue; |
| 587 if (![button isBeingDragged]) | 587 if (![button isBeingDragged]) |
| 588 [self moveButton:button toIndex:i animate:animate]; | 588 [self moveButton:button toIndex:i animate:animate]; |
| 589 ++i; | 589 ++i; |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| 593 - (void)updateButtonOpacity { | 593 - (void)updateButtonOpacity { |
| 594 for (BrowserActionButton* button in [buttons_ allValues]) { | 594 for (BrowserActionButton* button in [buttons_ allValues]) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 - (void)containerDragging:(NSNotification*)notification { | 665 - (void)containerDragging:(NSNotification*)notification { |
| 666 [[NSNotificationCenter defaultCenter] | 666 [[NSNotificationCenter defaultCenter] |
| 667 postNotificationName:kBrowserActionGrippyDraggingNotification | 667 postNotificationName:kBrowserActionGrippyDraggingNotification |
| 668 object:self]; | 668 object:self]; |
| 669 } | 669 } |
| 670 | 670 |
| 671 - (void)containerDragFinished:(NSNotification*)notification { | 671 - (void)containerDragFinished:(NSNotification*)notification { |
| 672 for (ExtensionList::const_iterator iter = | 672 for (ExtensionList::const_iterator iter = |
| 673 toolbarModel_->toolbar_items().begin(); | 673 toolbarModel_->toolbar_items().begin(); |
| 674 iter != toolbarModel_->toolbar_items().end(); ++iter) { | 674 iter != toolbarModel_->toolbar_items().end(); ++iter) { |
| 675 BrowserActionButton* button = [self buttonForExtension:(*iter)]; | 675 BrowserActionButton* button = [self buttonForExtension:(iter->get())]; |
| 676 NSRect buttonFrame = [button frame]; | 676 NSRect buttonFrame = [button frame]; |
| 677 if (NSContainsRect([containerView_ bounds], buttonFrame)) | 677 if (NSContainsRect([containerView_ bounds], buttonFrame)) |
| 678 continue; | 678 continue; |
| 679 | 679 |
| 680 CGFloat intersectionWidth = | 680 CGFloat intersectionWidth = |
| 681 NSWidth(NSIntersectionRect([containerView_ bounds], buttonFrame)); | 681 NSWidth(NSIntersectionRect([containerView_ bounds], buttonFrame)); |
| 682 // Pad the threshold by 5 pixels in order to have the buttons hide more | 682 // Pad the threshold by 5 pixels in order to have the buttons hide more |
| 683 // easily. | 683 // easily. |
| 684 if (([containerView_ grippyPinned] && intersectionWidth > 0) || | 684 if (([containerView_ grippyPinned] && intersectionWidth > 0) || |
| 685 (intersectionWidth <= (NSWidth(buttonFrame) / 2) + 5.0)) { | 685 (intersectionWidth <= (NSWidth(buttonFrame) / 2) + 5.0)) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 705 // Determine what index the dragged button should lie in, alter the model and | 705 // Determine what index the dragged button should lie in, alter the model and |
| 706 // reposition the buttons. | 706 // reposition the buttons. |
| 707 CGFloat dragThreshold = std::floor(kBrowserActionWidth / 2); | 707 CGFloat dragThreshold = std::floor(kBrowserActionWidth / 2); |
| 708 BrowserActionButton* draggedButton = [notification object]; | 708 BrowserActionButton* draggedButton = [notification object]; |
| 709 NSRect draggedButtonFrame = [draggedButton frame]; | 709 NSRect draggedButtonFrame = [draggedButton frame]; |
| 710 | 710 |
| 711 NSUInteger index = 0; | 711 NSUInteger index = 0; |
| 712 for (ExtensionList::const_iterator iter = | 712 for (ExtensionList::const_iterator iter = |
| 713 toolbarModel_->toolbar_items().begin(); | 713 toolbarModel_->toolbar_items().begin(); |
| 714 iter != toolbarModel_->toolbar_items().end(); ++iter) { | 714 iter != toolbarModel_->toolbar_items().end(); ++iter) { |
| 715 BrowserActionButton* button = [self buttonForExtension:(*iter)]; | 715 BrowserActionButton* button = [self buttonForExtension:(iter->get())]; |
| 716 CGFloat intersectionWidth = | 716 CGFloat intersectionWidth = |
| 717 NSWidth(NSIntersectionRect(draggedButtonFrame, [button frame])); | 717 NSWidth(NSIntersectionRect(draggedButtonFrame, [button frame])); |
| 718 | 718 |
| 719 if (intersectionWidth > dragThreshold && button != draggedButton && | 719 if (intersectionWidth > dragThreshold && button != draggedButton && |
| 720 ![button isAnimating] && index < [self visibleButtonCount]) { | 720 ![button isAnimating] && index < [self visibleButtonCount]) { |
| 721 toolbarModel_->MoveBrowserAction([draggedButton extension], index); | 721 toolbarModel_->MoveBrowserAction([draggedButton extension], index); |
| 722 [self positionActionButtonsAndAnimate:YES]; | 722 [self positionActionButtonsAndAnimate:YES]; |
| 723 return; | 723 return; |
| 724 } | 724 } |
| 725 ++index; | 725 ++index; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 | 871 |
| 872 #pragma mark - | 872 #pragma mark - |
| 873 #pragma mark Testing Methods | 873 #pragma mark Testing Methods |
| 874 | 874 |
| 875 - (NSButton*)buttonWithIndex:(NSUInteger)index { | 875 - (NSButton*)buttonWithIndex:(NSUInteger)index { |
| 876 if (profile_->IsOffTheRecord()) | 876 if (profile_->IsOffTheRecord()) |
| 877 index = toolbarModel_->IncognitoIndexToOriginal(index); | 877 index = toolbarModel_->IncognitoIndexToOriginal(index); |
| 878 const extensions::ExtensionList& toolbar_items = | 878 const extensions::ExtensionList& toolbar_items = |
| 879 toolbarModel_->toolbar_items(); | 879 toolbarModel_->toolbar_items(); |
| 880 if (index < toolbar_items.size()) { | 880 if (index < toolbar_items.size()) { |
| 881 const Extension* extension = toolbar_items[index]; | 881 const Extension* extension = toolbar_items[index].get(); |
| 882 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 882 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
| 883 } | 883 } |
| 884 return nil; | 884 return nil; |
| 885 } | 885 } |
| 886 | 886 |
| 887 @end | 887 @end |
| OLD | NEW |