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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 // Determine what index the dragged button should lie in, alter the model and | 673 // Determine what index the dragged button should lie in, alter the model and |
674 // reposition the buttons. | 674 // reposition the buttons. |
675 BrowserActionButton* draggedButton = [notification object]; | 675 BrowserActionButton* draggedButton = [notification object]; |
676 NSRect draggedButtonFrame = [draggedButton frame]; | 676 NSRect draggedButtonFrame = [draggedButton frame]; |
677 // Find the mid-point. We flip the y-coordinates so that y = 0 is at the | 677 // Find the mid-point. We flip the y-coordinates so that y = 0 is at the |
678 // top of the container to make row calculation more logical. | 678 // top of the container to make row calculation more logical. |
679 NSPoint midPoint = | 679 NSPoint midPoint = |
680 NSMakePoint(NSMidX(draggedButtonFrame), | 680 NSMakePoint(NSMidX(draggedButtonFrame), |
681 NSMaxY([containerView_ bounds]) - NSMidY(draggedButtonFrame)); | 681 NSMaxY([containerView_ bounds]) - NSMidY(draggedButtonFrame)); |
682 | 682 |
| 683 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) |
| 684 midPoint.x = NSWidth([containerView_ frame]) - midPoint.x; |
| 685 |
683 // Calculate the row index and the index in the row. We bound the latter | 686 // Calculate the row index and the index in the row. We bound the latter |
684 // because the view can go farther right than the right-most icon in the last | 687 // because the view can go farther right than the right-most icon in the last |
685 // row of the overflow menu. | 688 // row of the overflow menu. |
686 NSInteger rowIndex = midPoint.y / ToolbarActionsBar::IconHeight(); | 689 NSInteger rowIndex = midPoint.y / ToolbarActionsBar::IconHeight(); |
687 int icons_per_row = isOverflow_ ? | 690 int icons_per_row = isOverflow_ ? |
688 toolbarActionsBar_->platform_settings().icons_per_overflow_menu_row : | 691 toolbarActionsBar_->platform_settings().icons_per_overflow_menu_row : |
689 toolbarActionsBar_->GetIconCount(); | 692 toolbarActionsBar_->GetIconCount(); |
690 NSInteger indexInRow = std::min(icons_per_row - 1, | 693 NSInteger indexInRow = std::min(icons_per_row - 1, |
691 static_cast<int>(midPoint.x / ToolbarActionsBar::IconWidth(true))); | 694 static_cast<int>(midPoint.x / ToolbarActionsBar::IconWidth(true))); |
692 | 695 |
(...skipping 19 matching lines...) Expand all Loading... |
712 // The toolbar actions bar will return an empty rect if the index is for an | 715 // The toolbar actions bar will return an empty rect if the index is for an |
713 // action that is before range we show (i.e., is for a button that's on the | 716 // action that is before range we show (i.e., is for a button that's on the |
714 // main bar, and this is the overflow). Set the frame to be outside the bounds | 717 // main bar, and this is the overflow). Set the frame to be outside the bounds |
715 // of the view. | 718 // of the view. |
716 NSRect frame = frameRect.IsEmpty() ? | 719 NSRect frame = frameRect.IsEmpty() ? |
717 NSMakeRect(-iconWidth - 1, 0, iconWidth, | 720 NSMakeRect(-iconWidth - 1, 0, iconWidth, |
718 ToolbarActionsBar::IconHeight()) : | 721 ToolbarActionsBar::IconHeight()) : |
719 NSRectFromCGRect(frameRect.ToCGRect()); | 722 NSRectFromCGRect(frameRect.ToCGRect()); |
720 // We need to flip the y coordinate for Cocoa's view system. | 723 // We need to flip the y coordinate for Cocoa's view system. |
721 frame.origin.y = NSHeight([containerView_ frame]) - NSMaxY(frame); | 724 frame.origin.y = NSHeight([containerView_ frame]) - NSMaxY(frame); |
| 725 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) |
| 726 frame.origin.x = |
| 727 NSWidth([containerView_ frame]) - NSWidth(frame) - NSMinX(frame); |
722 return frame; | 728 return frame; |
723 } | 729 } |
724 | 730 |
725 - (NSPoint)popupPointForView:(NSView*)view | 731 - (NSPoint)popupPointForView:(NSView*)view |
726 withBounds:(NSRect)bounds { | 732 withBounds:(NSRect)bounds { |
727 // Anchor point just above the center of the bottom. | 733 // Anchor point just above the center of the bottom. |
728 int y = [view isFlipped] ? NSMaxY(bounds) - kBrowserActionBubbleYOffset : | 734 int y = [view isFlipped] ? NSMaxY(bounds) - kBrowserActionBubbleYOffset : |
729 kBrowserActionBubbleYOffset; | 735 kBrowserActionBubbleYOffset; |
730 NSPoint anchor = NSMakePoint(NSMidX(bounds), y); | 736 NSPoint anchor = NSMakePoint(NSMidX(bounds), y); |
731 // Convert the point to the container view's frame, and adjust for animation. | 737 // Convert the point to the container view's frame, and adjust for animation. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 } | 831 } |
826 | 832 |
827 #pragma mark - | 833 #pragma mark - |
828 #pragma mark Testing Methods | 834 #pragma mark Testing Methods |
829 | 835 |
830 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { | 836 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { |
831 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; | 837 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; |
832 } | 838 } |
833 | 839 |
834 @end | 840 @end |
OLD | NEW |