| 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 "base/nsimage_cache_mac.h" | 10 #include "base/nsimage_cache_mac.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/common/notification_observer.h" | 26 #include "chrome/common/notification_observer.h" |
| 27 #include "chrome/common/notification_registrar.h" | 27 #include "chrome/common/notification_registrar.h" |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 29 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
| 30 | 30 |
| 31 NSString* const kBrowserActionVisibilityChangedNotification = | 31 NSString* const kBrowserActionVisibilityChangedNotification = |
| 32 @"BrowserActionVisibilityChangedNotification"; | 32 @"BrowserActionVisibilityChangedNotification"; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 const CGFloat kAnimationDuration = 0.2; | 35 const CGFloat kAnimationDuration = 0.2; |
| 36 // When determining the opacity during a drag, we artificially reduce the | 36 |
| 37 // distance to the edge in order to make the fade more apparent. | |
| 38 const CGFloat kButtonOpacityLeadPadding = 5.0; | |
| 39 const CGFloat kChevronWidth = 14.0; | 37 const CGFloat kChevronWidth = 14.0; |
| 40 | 38 |
| 41 // Image used for the overflow button. | 39 // Image used for the overflow button. |
| 42 NSString* const kOverflowChevronsName = | 40 NSString* const kOverflowChevronsName = |
| 43 @"browser_actions_overflow_Template.pdf"; | 41 @"browser_actions_overflow_Template.pdf"; |
| 44 | 42 |
| 45 // Since the container is the maximum height of the toolbar, we have | 43 // Since the container is the maximum height of the toolbar, we have |
| 46 // to move the buttons up by this amount in order to have them look | 44 // to move the buttons up by this amount in order to have them look |
| 47 // vertically centered within the toolbar. | 45 // vertically centered within the toolbar. |
| 48 const CGFloat kBrowserActionOriginYOffset = 5.0; | 46 const CGFloat kBrowserActionOriginYOffset = 5.0; |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 continue; | 534 continue; |
| 537 if (![button isBeingDragged]) | 535 if (![button isBeingDragged]) |
| 538 [self moveButton:button toIndex:i animate:animate]; | 536 [self moveButton:button toIndex:i animate:animate]; |
| 539 ++i; | 537 ++i; |
| 540 } | 538 } |
| 541 } | 539 } |
| 542 | 540 |
| 543 - (void)updateButtonOpacity { | 541 - (void)updateButtonOpacity { |
| 544 for (BrowserActionButton* button in [buttons_ allValues]) { | 542 for (BrowserActionButton* button in [buttons_ allValues]) { |
| 545 NSRect buttonFrame = [button frame]; | 543 NSRect buttonFrame = [button frame]; |
| 546 buttonFrame.origin.x += kButtonOpacityLeadPadding; | |
| 547 if (NSContainsRect([containerView_ bounds], buttonFrame)) { | 544 if (NSContainsRect([containerView_ bounds], buttonFrame)) { |
| 548 if ([button alphaValue] != 1.0) | 545 if ([button alphaValue] != 1.0) |
| 549 [button setAlphaValue:1.0]; | 546 [button setAlphaValue:1.0]; |
| 550 | 547 |
| 551 continue; | 548 continue; |
| 552 } | 549 } |
| 553 CGFloat intersectionWidth = | 550 CGFloat intersectionWidth = |
| 554 NSWidth(NSIntersectionRect([containerView_ bounds], buttonFrame)); | 551 NSWidth(NSIntersectionRect([containerView_ bounds], buttonFrame)); |
| 555 CGFloat alpha = std::max(0.0f, | 552 CGFloat alpha = std::max(0.0f, intersectionWidth / NSWidth(buttonFrame)); |
| 556 (intersectionWidth - kButtonOpacityLeadPadding) / NSWidth(buttonFrame)); | |
| 557 [button setAlphaValue:alpha]; | 553 [button setAlphaValue:alpha]; |
| 558 [button setNeedsDisplay:YES]; | 554 [button setNeedsDisplay:YES]; |
| 559 } | 555 } |
| 560 } | 556 } |
| 561 | 557 |
| 562 - (BrowserActionButton*)buttonForExtension:(Extension*)extension { | 558 - (BrowserActionButton*)buttonForExtension:(Extension*)extension { |
| 563 NSString* extensionId = base::SysUTF8ToNSString(extension->id()); | 559 NSString* extensionId = base::SysUTF8ToNSString(extension->id()); |
| 564 DCHECK(extensionId); | 560 DCHECK(extensionId); |
| 565 if (!extensionId) | 561 if (!extensionId) |
| 566 return nil; | 562 return nil; |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 if (profile_->IsOffTheRecord()) | 854 if (profile_->IsOffTheRecord()) |
| 859 index = toolbarModel_->IncognitoIndexToOriginal(index); | 855 index = toolbarModel_->IncognitoIndexToOriginal(index); |
| 860 if (index < toolbarModel_->size()) { | 856 if (index < toolbarModel_->size()) { |
| 861 Extension* extension = toolbarModel_->GetExtensionByIndex(index); | 857 Extension* extension = toolbarModel_->GetExtensionByIndex(index); |
| 862 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 858 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
| 863 } | 859 } |
| 864 return nil; | 860 return nil; |
| 865 } | 861 } |
| 866 | 862 |
| 867 @end | 863 @end |
| OLD | NEW |