| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 NSString* const kBrowserActionVisibilityChangedNotification = | 33 NSString* const kBrowserActionVisibilityChangedNotification = |
| 34 @"BrowserActionVisibilityChangedNotification"; | 34 @"BrowserActionVisibilityChangedNotification"; |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 const CGFloat kAnimationDuration = 0.2; | 37 const CGFloat kAnimationDuration = 0.2; |
| 38 // When determining the opacity during a drag, we artificially reduce the | 38 // When determining the opacity during a drag, we artificially reduce the |
| 39 // distance to the edge in order to make the fade more apparent. | 39 // distance to the edge in order to make the fade more apparent. |
| 40 const CGFloat kButtonOpacityLeadPadding = 5.0; | 40 const CGFloat kButtonOpacityLeadPadding = 5.0; |
| 41 const CGFloat kChevronHeight = 28.0; | 41 const CGFloat kChevronHeight = 28.0; |
| 42 const CGFloat kChevronLowerPadding = 5.0; | 42 const CGFloat kChevronLowerPadding = 5.0; |
| 43 const CGFloat kChevronRightPadding = 5.0; | |
| 44 const CGFloat kChevronWidth = 14.0; | 43 const CGFloat kChevronWidth = 14.0; |
| 45 const CGFloat kContainerPadding = 2.0; | 44 const CGFloat kGrippyXOffset = 7.0; |
| 46 const CGFloat kGrippyXOffset = 8.0; | |
| 47 } // namespace | 45 } // namespace |
| 48 | 46 |
| 49 @interface BrowserActionsController(Private) | 47 @interface BrowserActionsController(Private) |
| 50 // Used during initialization to create the BrowserActionButton objects from the | 48 // Used during initialization to create the BrowserActionButton objects from the |
| 51 // stored toolbar model. | 49 // stored toolbar model. |
| 52 - (void)createButtons; | 50 - (void)createButtons; |
| 53 | 51 |
| 54 // Creates and then adds the given extension's action button to the container | 52 // Creates and then adds the given extension's action button to the container |
| 55 // at the given index within the container. It does not affect the toolbar model | 53 // at the given index within the container. It does not affect the toolbar model |
| 56 // object since it is called when the toolbar model changes. | 54 // object since it is called when the toolbar model changes. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 - (CGFloat)savedWidth { | 336 - (CGFloat)savedWidth { |
| 339 if (!toolbarModel_) | 337 if (!toolbarModel_) |
| 340 return 0; | 338 return 0; |
| 341 if (!profile_->GetPrefs()->HasPrefPath(prefs::kExtensionToolbarSize)) { | 339 if (!profile_->GetPrefs()->HasPrefPath(prefs::kExtensionToolbarSize)) { |
| 342 // Migration code to the new VisibleIconCount pref. | 340 // Migration code to the new VisibleIconCount pref. |
| 343 // TODO(mpcomplete): remove this at some point. | 341 // TODO(mpcomplete): remove this at some point. |
| 344 double predefinedWidth = | 342 double predefinedWidth = |
| 345 profile_->GetPrefs()->GetReal(prefs::kBrowserActionContainerWidth); | 343 profile_->GetPrefs()->GetReal(prefs::kBrowserActionContainerWidth); |
| 346 if (predefinedWidth != 0) { | 344 if (predefinedWidth != 0) { |
| 347 int iconWidth = kBrowserActionWidth + kBrowserActionButtonPadding; | 345 int iconWidth = kBrowserActionWidth + kBrowserActionButtonPadding; |
| 348 int extraWidth = kContainerPadding + kChevronWidth; | 346 int extraWidth = kChevronWidth; |
| 349 toolbarModel_->SetVisibleIconCount( | 347 toolbarModel_->SetVisibleIconCount( |
| 350 (predefinedWidth - extraWidth) / iconWidth); | 348 (predefinedWidth - extraWidth) / iconWidth); |
| 351 } | 349 } |
| 352 } | 350 } |
| 353 | 351 |
| 354 int savedButtonCount = toolbarModel_->GetVisibleIconCount(); | 352 int savedButtonCount = toolbarModel_->GetVisibleIconCount(); |
| 355 if (savedButtonCount < 0 || // all icons are visible | 353 if (savedButtonCount < 0 || // all icons are visible |
| 356 static_cast<NSUInteger>(savedButtonCount) > [self buttonCount]) | 354 static_cast<NSUInteger>(savedButtonCount) > [self buttonCount]) |
| 357 savedButtonCount = [self buttonCount]; | 355 savedButtonCount = [self buttonCount]; |
| 358 return [self containerWidthWithButtonCount:savedButtonCount]; | 356 return [self containerWidthWithButtonCount:savedButtonCount]; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 NSString* extensionId = base::SysUTF8ToNSString(extension->id()); | 543 NSString* extensionId = base::SysUTF8ToNSString(extension->id()); |
| 546 DCHECK(extensionId); | 544 DCHECK(extensionId); |
| 547 if (!extensionId) | 545 if (!extensionId) |
| 548 return nil; | 546 return nil; |
| 549 return [buttons_ objectForKey:extensionId]; | 547 return [buttons_ objectForKey:extensionId]; |
| 550 } | 548 } |
| 551 | 549 |
| 552 - (CGFloat)containerWidthWithButtonCount:(NSUInteger)buttonCount { | 550 - (CGFloat)containerWidthWithButtonCount:(NSUInteger)buttonCount { |
| 553 CGFloat width = 0.0; | 551 CGFloat width = 0.0; |
| 554 if (buttonCount > 0) { | 552 if (buttonCount > 0) { |
| 555 width = kGrippyXOffset + kContainerPadding + | 553 width = kGrippyXOffset + |
| 556 (buttonCount * (kBrowserActionWidth + kBrowserActionButtonPadding)); | 554 (buttonCount * (kBrowserActionWidth + kBrowserActionButtonPadding)); |
| 557 } | 555 } |
| 558 // Make room for the chevron if any buttons are hidden. | 556 // Make room for the chevron if any buttons are hidden. |
| 559 if ([self buttonCount] != [self visibleButtonCount]) { | 557 if ([self buttonCount] != [self visibleButtonCount]) |
| 560 width += kChevronWidth + kBrowserActionButtonPadding; | 558 width += kChevronWidth + kBrowserActionButtonPadding; |
| 561 // Add extra padding if all buttons are hidden. | 559 |
| 562 if ([self visibleButtonCount] == 0) | |
| 563 width += 3 * kBrowserActionButtonPadding; | |
| 564 } | |
| 565 return width; | 560 return width; |
| 566 } | 561 } |
| 567 | 562 |
| 568 - (NSUInteger)containerButtonCapacity { | 563 - (NSUInteger)containerButtonCapacity { |
| 569 CGFloat containerWidth = [self savedWidth]; | 564 CGFloat containerWidth = [self savedWidth]; |
| 570 return (containerWidth - kGrippyXOffset + kContainerPadding) / | 565 return (containerWidth - kGrippyXOffset) / |
| 571 (kBrowserActionWidth + kBrowserActionButtonPadding); | 566 (kBrowserActionWidth + kBrowserActionButtonPadding); |
| 572 } | 567 } |
| 573 | 568 |
| 574 - (void)containerFrameChanged:(NSNotification*)notification { | 569 - (void)containerFrameChanged:(NSNotification*)notification { |
| 575 [self updateButtonOpacity]; | 570 [self updateButtonOpacity]; |
| 576 [[containerView_ window] invalidateCursorRectsForView:containerView_]; | 571 [[containerView_ window] invalidateCursorRectsForView:containerView_]; |
| 577 [self updateChevronPositionInFrame:[containerView_ frame]]; | 572 [self updateChevronPositionInFrame:[containerView_ frame]]; |
| 578 } | 573 } |
| 579 | 574 |
| 580 - (void)containerDragStart:(NSNotification*)notification { | 575 - (void)containerDragStart:(NSNotification*)notification { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); | 721 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); |
| 727 } | 722 } |
| 728 | 723 |
| 729 - (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate { | 724 - (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate { |
| 730 [self setChevronHidden:([self buttonCount] == [self visibleButtonCount]) | 725 [self setChevronHidden:([self buttonCount] == [self visibleButtonCount]) |
| 731 inFrame:frame | 726 inFrame:frame |
| 732 animate:animate]; | 727 animate:animate]; |
| 733 } | 728 } |
| 734 | 729 |
| 735 - (void)updateChevronPositionInFrame:(NSRect)frame { | 730 - (void)updateChevronPositionInFrame:(NSRect)frame { |
| 736 CGFloat xPos = NSWidth(frame) - kChevronWidth - kChevronRightPadding; | 731 CGFloat xPos = NSWidth(frame) - kChevronWidth; |
| 737 NSRect buttonFrame = NSMakeRect(xPos, | 732 NSRect buttonFrame = NSMakeRect(xPos, |
| 738 kChevronLowerPadding, | 733 kChevronLowerPadding, |
| 739 kChevronWidth, | 734 kChevronWidth, |
| 740 kChevronHeight); | 735 kChevronHeight); |
| 741 [chevronMenuButton_ setFrame:buttonFrame]; | 736 [chevronMenuButton_ setFrame:buttonFrame]; |
| 742 } | 737 } |
| 743 | 738 |
| 744 - (void)setChevronHidden:(BOOL)hidden | 739 - (void)setChevronHidden:(BOOL)hidden |
| 745 inFrame:(NSRect)frame | 740 inFrame:(NSRect)frame |
| 746 animate:(BOOL)animate { | 741 animate:(BOOL)animate { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 if (profile_->IsOffTheRecord()) | 824 if (profile_->IsOffTheRecord()) |
| 830 index = toolbarModel_->IncognitoIndexToOriginal(index); | 825 index = toolbarModel_->IncognitoIndexToOriginal(index); |
| 831 if (index < toolbarModel_->size()) { | 826 if (index < toolbarModel_->size()) { |
| 832 Extension* extension = toolbarModel_->GetExtensionByIndex(index); | 827 Extension* extension = toolbarModel_->GetExtensionByIndex(index); |
| 833 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 828 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
| 834 } | 829 } |
| 835 return nil; | 830 return nil; |
| 836 } | 831 } |
| 837 | 832 |
| 838 @end | 833 @end |
| OLD | NEW |