Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Unified Diff: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm

Issue 820713008: [Extensions Toolbar Mac] Implement drag-and-drop for the overflow menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
diff --git a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
index c72d8021460843269fbe79c2ecc8a43d6a5482dd..a55a259df7fa69c0e9ab28fa5d2a90a0fb176b0f 100644
--- a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
+++ b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
@@ -238,6 +238,7 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
@synthesize containerView = containerView_;
@synthesize browser = browser_;
+@synthesize isOverflow = isOverflow_;
#pragma mark -
#pragma mark Public Methods
@@ -633,27 +634,34 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
// Determine what index the dragged button should lie in, alter the model and
// reposition the buttons.
- CGFloat dragThreshold = ToolbarActionsBar::IconWidth(false) / 2;
BrowserActionButton* draggedButton = [notification object];
NSRect draggedButtonFrame = [draggedButton frame];
+ // Find the mid-point. We flip the y-coordinates so that y = 0 is at the
+ // top of the container to make row calculation more logical.
+ NSPoint midPoint =
+ NSMakePoint(NSMidX(draggedButtonFrame),
+ NSMaxY([containerView_ bounds]) - NSMidY(draggedButtonFrame));
+
+ // Calculate the row index and the index in the row. We bound the latter
+ // because the view can go farther right than the right-most icon in the last
+ // row of the overflow menu.
+ NSInteger rowIndex = midPoint.y / ToolbarActionsBar::IconHeight();
+ int icons_per_row = isOverflow_ ?
+ toolbarActionsBar_->platform_settings().icons_per_overflow_menu_row :
+ toolbarActionsBar_->GetIconCount();
+ NSInteger indexInRow = std::min(icons_per_row - 1,
+ static_cast<int>(midPoint.x / ToolbarActionsBar::IconWidth(true)));
+
+ // Find the desired index for the button.
+ NSInteger maxIndex = [buttons_ count] - 1;
+ NSInteger offset = isOverflow_ ?
+ [buttons_ count] - toolbarActionsBar_->GetIconCount() : 0;
+ NSInteger index =
+ std::min(maxIndex, offset + rowIndex * icons_per_row + indexInRow);
- NSUInteger index = 0;
- for (BrowserActionButton* button in buttons_.get()) {
- CGFloat intersectionWidth =
- NSWidth(NSIntersectionRect(draggedButtonFrame, [button frame]));
-
- NSUInteger maxIndex =
- isOverflow_ ? [buttons_ count] : [self visibleButtonCount];
- if (intersectionWidth > dragThreshold && button != draggedButton &&
- ![button isAnimating] && index < maxIndex) {
- toolbarActionsBar_->OnDragDrop(
- [buttons_ indexOfObject:draggedButton],
- index,
- ToolbarActionsBar::DRAG_TO_SAME);
- return;
- }
- ++index;
- }
+ toolbarActionsBar_->OnDragDrop([buttons_ indexOfObject:draggedButton],
+ index,
+ ToolbarActionsBar::DRAG_TO_SAME);
}
- (void)actionButtonDragFinished:(NSNotification*)notification {
« no previous file with comments | « chrome/browser/ui/cocoa/extensions/browser_actions_controller.h ('k') | chrome/browser/ui/toolbar/wrench_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698