summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/profiles/avatar_button.mm
blob: a1d5c12c1c0122bfd5661dfa6b51480b16aa304c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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