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/extensions/extension_message_bubble_controller.h" | 10 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 [[self buttonAtIndex:j] viewController]; | 576 [[self buttonAtIndex:j] viewController]; |
577 if (other_controller == toolbar_actions[i]) | 577 if (other_controller == toolbar_actions[i]) |
578 break; | 578 break; |
579 ++j; | 579 ++j; |
580 } | 580 } |
581 [buttons_ exchangeObjectAtIndex:i withObjectAtIndex:j]; | 581 [buttons_ exchangeObjectAtIndex:i withObjectAtIndex:j]; |
582 } | 582 } |
583 } | 583 } |
584 | 584 |
585 [self showChevronIfNecessaryInFrame:[containerView_ frame]]; | 585 [self showChevronIfNecessaryInFrame:[containerView_ frame]]; |
586 NSUInteger minIndex = isOverflow_ ? | 586 NSUInteger startIndex = toolbarActionsBar_->GetStartIndexInBounds(); |
587 [buttons_ count] - toolbarActionsBar_->GetIconCount() : 0; | 587 NSUInteger endIndex = toolbarActionsBar_->GetEndIndexInBounds(); |
588 NSUInteger maxIndex = isOverflow_ ? | |
589 [buttons_ count] : toolbarActionsBar_->GetIconCount(); | |
590 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { | 588 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { |
591 BrowserActionButton* button = [buttons_ objectAtIndex:i]; | 589 BrowserActionButton* button = [buttons_ objectAtIndex:i]; |
592 if ([button isBeingDragged]) | 590 if ([button isBeingDragged]) |
593 continue; | 591 continue; |
594 | 592 |
595 [self moveButton:[buttons_ objectAtIndex:i] toIndex:i]; | 593 [self moveButton:[buttons_ objectAtIndex:i] toIndex:i]; |
596 | 594 |
597 if (i >= minIndex && i < maxIndex) { | 595 if (i >= startIndex && i < endIndex) { |
598 // Make sure the button is within the visible container. | 596 // Make sure the button is within the visible container. |
599 if ([button superview] != containerView_) { | 597 if ([button superview] != containerView_) { |
600 // We add the subview under the sibling views so that when it | 598 // We add the subview under the sibling views so that when it |
601 // "slides in", it does so under its neighbors. | 599 // "slides in", it does so under its neighbors. |
602 [containerView_ addSubview:button | 600 [containerView_ addSubview:button |
603 positioned:NSWindowBelow | 601 positioned:NSWindowBelow |
604 relativeTo:nil]; | 602 relativeTo:nil]; |
605 } | 603 } |
606 // We need to set the alpha value in case the container has resized. | 604 // We need to set the alpha value in case the container has resized. |
607 [button setAlphaValue:1.0]; | 605 [button setAlphaValue:1.0]; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 - (BOOL)updateContainerVisibility { | 660 - (BOOL)updateContainerVisibility { |
663 BOOL hidden = [buttons_ count] == 0; | 661 BOOL hidden = [buttons_ count] == 0; |
664 if ([containerView_ isHidden] != hidden) | 662 if ([containerView_ isHidden] != hidden) |
665 [containerView_ setHidden:hidden]; | 663 [containerView_ setHidden:hidden]; |
666 return !hidden; | 664 return !hidden; |
667 } | 665 } |
668 | 666 |
669 - (void)updateButtonOpacity { | 667 - (void)updateButtonOpacity { |
670 for (BrowserActionButton* button in buttons_.get()) { | 668 for (BrowserActionButton* button in buttons_.get()) { |
671 NSRect buttonFrame = [button frame]; | 669 NSRect buttonFrame = [button frame]; |
670 // Button is fully in the container view, and should get full opacity. | |
Avi (use Gerrit)
2015/09/10 20:58:56
*The* button?
Devlin
2015/09/11 16:46:15
Done.
| |
672 if (NSContainsRect([containerView_ bounds], buttonFrame)) { | 671 if (NSContainsRect([containerView_ bounds], buttonFrame)) { |
673 if ([button alphaValue] != 1.0) | 672 if ([button alphaValue] != 1.0) |
674 [button setAlphaValue:1.0]; | 673 [button setAlphaValue:1.0]; |
675 | 674 |
676 continue; | 675 continue; |
677 } | 676 } |
678 CGFloat intersectionWidth = | 677 // Button is only partially in the container view. If the user is resizing |
Avi (use Gerrit)
2015/09/10 20:58:56
*The* button?
Devlin
2015/09/11 16:46:15
Done.
| |
679 NSWidth(NSIntersectionRect([containerView_ bounds], buttonFrame)); | 678 // the container, we have partial alpha so the icon fades in as space is |
680 CGFloat alpha = std::max(static_cast<CGFloat>(0.0), | 679 // made. Otherwise, hide the icon fully. |
681 intersectionWidth / NSWidth(buttonFrame)); | 680 CGFloat alpha = 0.0; |
681 if ([containerView_ userIsResizing]) { | |
682 CGFloat intersectionWidth = | |
683 NSWidth(NSIntersectionRect([containerView_ bounds], buttonFrame)); | |
684 alpha = std::max(static_cast<CGFloat>(0.0), | |
685 intersectionWidth / NSWidth(buttonFrame)); | |
686 } | |
682 [button setAlphaValue:alpha]; | 687 [button setAlphaValue:alpha]; |
683 [button setNeedsDisplay:YES]; | 688 [button setNeedsDisplay:YES]; |
684 } | 689 } |
685 } | 690 } |
686 | 691 |
687 - (void)updateButtonPositions { | 692 - (void)updateButtonPositions { |
688 for (NSUInteger index = 0; index < [buttons_ count]; ++index) { | 693 for (NSUInteger index = 0; index < [buttons_ count]; ++index) { |
689 BrowserActionButton* button = [buttons_ objectAtIndex:index]; | 694 BrowserActionButton* button = [buttons_ objectAtIndex:index]; |
690 NSRect buttonFrame = [self frameForIndex:index]; | 695 NSRect buttonFrame = [self frameForIndex:index]; |
691 | 696 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1035 } | 1040 } |
1036 | 1041 |
1037 #pragma mark - | 1042 #pragma mark - |
1038 #pragma mark Testing Methods | 1043 #pragma mark Testing Methods |
1039 | 1044 |
1040 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { | 1045 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { |
1041 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; | 1046 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; |
1042 } | 1047 } |
1043 | 1048 |
1044 @end | 1049 @end |
OLD | NEW |