summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/profiles/avatar_button.mm
diff options
context:
space:
mode:
authoranthonyvd <anthonyvd@chromium.org>2015-02-23 11:56:38 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-23 19:57:27 +0000
commit95b89c2672ce7b0ed1a6803b59acee369b232a3c (patch)
tree89098c833b07891b550d8b88a93b23d5d4fa4ec7 /chrome/browser/ui/cocoa/profiles/avatar_button.mm
parent1e2555db3bd31e72396b24fbf7e9fdb93daf016e (diff)
downloadchromium_src-95b89c2672ce7b0ed1a6803b59acee369b232a3c.zip
chromium_src-95b89c2672ce7b0ed1a6803b59acee369b232a3c.tar.gz
chromium_src-95b89c2672ce7b0ed1a6803b59acee369b232a3c.tar.bz2
Bring up fast user switcher on right-click of the avatar menu on Mac.
Change the behavior of fast user switching on Mac from Command click to right click to be consistent with Windows and Linux. BUG=458755 TEST= 1. Disable #enable-fast-user-switcher and enable #new-avatar-menu flags in chrome://flags 2. Relaunch Chrome 3. Right click on the Avatar Button, the fast user switcher should be shown 4. Command+Click on the Avatar Button, nothing should happen Review URL: https://codereview.chromium.org/916523003 Cr-Commit-Position: refs/heads/master@{#317631}
Diffstat (limited to 'chrome/browser/ui/cocoa/profiles/avatar_button.mm')
-rw-r--r--chrome/browser/ui/cocoa/profiles/avatar_button.mm48
1 files changed, 48 insertions, 0 deletions
diff --git a/chrome/browser/ui/cocoa/profiles/avatar_button.mm b/chrome/browser/ui/cocoa/profiles/avatar_button.mm
new file mode 100644
index 0000000..a1d5c12
--- /dev/null
+++ b/chrome/browser/ui/cocoa/profiles/avatar_button.mm
@@ -0,0 +1,48 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/profiles/avatar_button.h"
+
+@interface AvatarButton (Private)
+
+- (void)rightMouseDown:(NSEvent*)event;
+- (void)performRightClick;
+
+@end
+
+@implementation AvatarButton
+
+// Overrides -rightMouseDown and implements a custom mouse tracking loop.
+- (void)rightMouseDown:(NSEvent*)event {
+ NSEvent* nextEvent = event;
+ BOOL mouseInBounds = NO;
+ hoverState_ = kHoverStateMouseDown;
+
+ do {
+ nextEvent = [[self window]
+ nextEventMatchingMask:NSRightMouseDraggedMask |
+ NSRightMouseUpMask];
+
+ mouseInBounds = NSPointInRect(
+ [self convertPoint:[nextEvent locationInWindow] fromView:nil],
+ [self convertRect:[self frame] fromView:nil]);
+ } while (NSRightMouseUp != [nextEvent type]);
+
+ hoverState_ = kHoverStateNone;
+
+ if (mouseInBounds) {
+ hoverState_ = kHoverStateMouseOver;
+ [self performRightClick];
+ }
+}
+
+- (void)performRightClick {
+ [[super target] performSelector:rightAction_ withObject:self];
+}
+
+- (void)setRightAction:(SEL)selector {
+ rightAction_ = selector;
+}
+
+@end