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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 [self showChevronIfNecessaryInFrame:[containerView_ frame]]; | 593 [self showChevronIfNecessaryInFrame:[containerView_ frame]]; |
594 NSUInteger minIndex = isOverflow_ ? | 594 NSUInteger minIndex = isOverflow_ ? |
595 [buttons_ count] - toolbarActionsBar_->GetIconCount() : 0; | 595 [buttons_ count] - toolbarActionsBar_->GetIconCount() : 0; |
596 NSUInteger maxIndex = isOverflow_ ? | 596 NSUInteger maxIndex = isOverflow_ ? |
597 [buttons_ count] : toolbarActionsBar_->GetIconCount(); | 597 [buttons_ count] : toolbarActionsBar_->GetIconCount(); |
598 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { | 598 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { |
599 BrowserActionButton* button = [buttons_ objectAtIndex:i]; | 599 BrowserActionButton* button = [buttons_ objectAtIndex:i]; |
600 if ([button isBeingDragged]) | 600 if ([button isBeingDragged]) |
601 continue; | 601 continue; |
602 | 602 |
603 [self moveButton:[buttons_ objectAtIndex:i] toIndex:i - minIndex]; | 603 [self moveButton:[buttons_ objectAtIndex:i] toIndex:i]; |
604 | 604 |
605 if (i >= minIndex && i < maxIndex) { | 605 if (i >= minIndex && i < maxIndex) { |
606 // Make sure the button is within the visible container. | 606 // Make sure the button is within the visible container. |
607 if ([button superview] != containerView_) { | 607 if ([button superview] != containerView_) { |
608 // We add the subview under the sibling views so that when it | 608 // We add the subview under the sibling views so that when it |
609 // "slides in", it does so under its neighbors. | 609 // "slides in", it does so under its neighbors. |
610 [containerView_ addSubview:button | 610 [containerView_ addSubview:button |
611 positioned:NSWindowBelow | 611 positioned:NSWindowBelow |
612 relativeTo:nil]; | 612 relativeTo:nil]; |
613 } | 613 } |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 } | 858 } |
859 | 859 |
860 - (void)actionButtonDragFinished:(NSNotification*)notification { | 860 - (void)actionButtonDragFinished:(NSNotification*)notification { |
861 suppressChevron_ = NO; | 861 suppressChevron_ = NO; |
862 [self redraw]; | 862 [self redraw]; |
863 } | 863 } |
864 | 864 |
865 - (NSRect)frameForIndex:(NSUInteger)index { | 865 - (NSRect)frameForIndex:(NSUInteger)index { |
866 const ToolbarActionsBar::PlatformSettings& platformSettings = | 866 const ToolbarActionsBar::PlatformSettings& platformSettings = |
867 toolbarActionsBar_->platform_settings(); | 867 toolbarActionsBar_->platform_settings(); |
| 868 int startIndex = isOverflow_ ? |
| 869 [buttons_ count] - toolbarActionsBar_->GetIconCount() : 0; |
| 870 int relativeIndex = index - startIndex; |
| 871 |
| 872 int iconWidth = ToolbarActionsBar::IconWidth(false); |
| 873 int iconHeight = ToolbarActionsBar::IconHeight(); |
| 874 |
| 875 // If the index is for an action that is before range we show (i.e., is for |
| 876 // a button that's on the main bar, and this is the overflow), the frame is |
| 877 // set outside the bounds of the view. |
| 878 if (relativeIndex < 0) |
| 879 return NSMakeRect(-iconWidth - 1, 0, iconWidth, iconHeight); |
| 880 |
868 int icons_per_overflow_row = platformSettings.icons_per_overflow_menu_row; | 881 int icons_per_overflow_row = platformSettings.icons_per_overflow_menu_row; |
869 NSUInteger rowIndex = isOverflow_ ? index / icons_per_overflow_row : 0; | 882 NSUInteger rowIndex = isOverflow_ ? |
870 NSUInteger indexInRow = isOverflow_ ? index % icons_per_overflow_row : index; | 883 relativeIndex / icons_per_overflow_row : 0; |
| 884 NSUInteger indexInRow = isOverflow_ ? |
| 885 relativeIndex % icons_per_overflow_row : relativeIndex; |
871 | 886 |
872 CGFloat xOffset = platformSettings.left_padding + | 887 CGFloat xOffset = platformSettings.left_padding + |
873 (indexInRow * ToolbarActionsBar::IconWidth(true)); | 888 (indexInRow * ToolbarActionsBar::IconWidth(true)); |
874 CGFloat yOffset = NSHeight([containerView_ frame]) - | 889 CGFloat yOffset = NSHeight([containerView_ frame]) - |
875 (ToolbarActionsBar::IconHeight() * (rowIndex + 1)); | 890 (ToolbarActionsBar::IconHeight() * (rowIndex + 1)); |
876 | 891 |
877 return NSMakeRect(xOffset, | 892 return NSMakeRect(xOffset, |
878 yOffset, | 893 yOffset, |
879 ToolbarActionsBar::IconWidth(false), | 894 ToolbarActionsBar::IconWidth(false), |
880 ToolbarActionsBar::IconHeight()); | 895 ToolbarActionsBar::IconHeight()); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 } | 1066 } |
1052 | 1067 |
1053 #pragma mark - | 1068 #pragma mark - |
1054 #pragma mark Testing Methods | 1069 #pragma mark Testing Methods |
1055 | 1070 |
1056 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { | 1071 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { |
1057 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; | 1072 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; |
1058 } | 1073 } |
1059 | 1074 |
1060 @end | 1075 @end |
OLD | NEW |