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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/browser_action_button.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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/extensions/browser_actions_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_action_button.h" 5 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // same point along the button's x axis, and we avoid a "jump" when first 213 // same point along the button's x axis, and we avoid a "jump" when first
214 // starting to drag. 214 // starting to drag.
215 dragStartPoint_ = [self convertPoint:eventPoint fromView:nil]; 215 dragStartPoint_ = [self convertPoint:eventPoint fromView:nil];
216 216
217 isBeingDragged_ = YES; 217 isBeingDragged_ = YES;
218 } 218 }
219 219
220 NSRect buttonFrame = [self frame]; 220 NSRect buttonFrame = [self frame];
221 // The desired x is the current mouse point, minus the original offset of the 221 // The desired x is the current mouse point, minus the original offset of the
222 // mouse into the button. 222 // mouse into the button.
223 CGFloat desiredX = [[self superview] convertPoint:eventPoint fromView:nil].x - 223 NSPoint localPoint = [[self superview] convertPoint:eventPoint fromView:nil];
224 dragStartPoint_.x; 224 CGFloat desiredX = localPoint.x - dragStartPoint_.x;
225 // Clamp the button to be within its superview along the X-axis. 225 // Clamp the button to be within its superview along the X-axis.
226 NSRect containerBounds = [[self superview] bounds]; 226 NSRect containerBounds = [[self superview] bounds];
227 desiredX = std::min(std::max(NSMinX(containerBounds), desiredX), 227 desiredX = std::min(std::max(NSMinX(containerBounds), desiredX),
228 NSMaxX(containerBounds) - NSWidth(buttonFrame)); 228 NSMaxX(containerBounds) - NSWidth(buttonFrame));
229 buttonFrame.origin.x = desiredX;
229 230
230 buttonFrame.origin.x = desiredX; 231 // If the button is in the overflow menu, it could move along the y-axis, too.
232 if ([browserActionsController_ isOverflow]) {
233 CGFloat desiredY = localPoint.y - dragStartPoint_.y;
234 desiredY = std::min(std::max(NSMinY(containerBounds), desiredY),
235 NSMaxY(containerBounds) - NSHeight(buttonFrame));
236 buttonFrame.origin.y = desiredY;
237 }
238
231 [self setFrame:buttonFrame]; 239 [self setFrame:buttonFrame];
232 [self setNeedsDisplay:YES]; 240 [self setNeedsDisplay:YES];
233 [[NSNotificationCenter defaultCenter] 241 [[NSNotificationCenter defaultCenter]
234 postNotificationName:kBrowserActionButtonDraggingNotification 242 postNotificationName:kBrowserActionButtonDraggingNotification
235 object:self]; 243 object:self];
236 } 244 }
237 245
238 - (void)mouseUp:(NSEvent*)theEvent { 246 - (void)mouseUp:(NSEvent*)theEvent {
239 dragCouldStart_ = NO; 247 dragCouldStart_ = NO;
240 // There are non-drag cases where a mouseUp: may happen 248 // There are non-drag cases where a mouseUp: may happen
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 - (ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window { 412 - (ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window {
405 ui::ThemeProvider* themeProvider = [window themeProvider]; 413 ui::ThemeProvider* themeProvider = [window themeProvider];
406 if (!themeProvider) 414 if (!themeProvider)
407 themeProvider = 415 themeProvider =
408 [[browserActionsController_ browser]->window()->GetNativeWindow() 416 [[browserActionsController_ browser]->window()->GetNativeWindow()
409 themeProvider]; 417 themeProvider];
410 return themeProvider; 418 return themeProvider;
411 } 419 }
412 420
413 @end 421 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/extensions/browser_actions_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698