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

Side by Side Diff: chrome/browser/ui/cocoa/event_utils.mm

Issue 6893046: added CTRL+Click and SHIFT+Click handler for context menu, Back and Forward. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: make this patch applicable to the latest trunk Created 9 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/event_utils.h ('k') | chrome/browser/ui/cocoa/event_utils_unittest.mm » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/event_utils.h" 5 #import "chrome/browser/ui/cocoa/event_utils.h"
6 6
7 #include "content/browser/disposition_utils.h" 7 #include "content/browser/disposition_utils.h"
8 #include "ui/base/events.h"
9
10 namespace {
11 bool isLeftButtonEvent(NSEvent* event) {
12 NSEventType type = [event type];
13 return type == NSLeftMouseDown ||
14 type == NSLeftMouseDragged ||
15 type == NSLeftMouseUp;
16 }
17
18 bool isRightButtonEvent(NSEvent* event) {
19 NSEventType type = [event type];
20 return type == NSRightMouseDown ||
21 type == NSRightMouseDragged ||
22 type == NSRightMouseUp;
23 }
24
25 bool isMiddleButtonEvent(NSEvent* event) {
26 if ([event buttonNumber] != 2)
27 return false;
28
29 NSEventType type = [event type];
30 return type == NSOtherMouseDown ||
31 type == NSOtherMouseDragged ||
32 type == NSOtherMouseUp;
33 }
34 }
8 35
9 namespace event_utils { 36 namespace event_utils {
10 37
38 // Retrieves a bitsum of ui::EventFlags from NSEvent.
39 int EventFlagsFromNSEvent(NSEvent* event) {
40 NSUInteger modifiers = [event modifierFlags];
41
42 int flags = 0;
43 flags |= (modifiers & NSAlphaShiftKeyMask) ? ui::EF_CAPS_LOCK_DOWN : 0;
44 flags |= (modifiers & NSShiftKeyMask) ? ui::EF_SHIFT_DOWN : 0;
45 flags |= (modifiers & NSControlKeyMask) ? ui::EF_CONTROL_DOWN : 0;
46 flags |= (modifiers & NSAlternateKeyMask) ? ui::EF_ALT_DOWN : 0;
47 flags |= (modifiers & NSCommandKeyMask) ? ui::EF_COMMAND_DOWN : 0;
48 flags |= isLeftButtonEvent(event) ? ui::EF_LEFT_BUTTON_DOWN : 0;
49 flags |= isRightButtonEvent(event) ? ui::EF_RIGHT_BUTTON_DOWN : 0;
50 flags |= isMiddleButtonEvent(event) ? ui::EF_MIDDLE_BUTTON_DOWN : 0;
51 return flags;
52 }
53
54
11 WindowOpenDisposition WindowOpenDispositionFromNSEvent(NSEvent* event) { 55 WindowOpenDisposition WindowOpenDispositionFromNSEvent(NSEvent* event) {
12 NSUInteger modifiers = [event modifierFlags]; 56 NSUInteger modifiers = [event modifierFlags];
13 return WindowOpenDispositionFromNSEventWithFlags(event, modifiers); 57 return WindowOpenDispositionFromNSEventWithFlags(event, modifiers);
14 } 58 }
15 59
16 WindowOpenDisposition WindowOpenDispositionFromNSEventWithFlags( 60 WindowOpenDisposition WindowOpenDispositionFromNSEventWithFlags(
17 NSEvent* event, NSUInteger flags) { 61 NSEvent* event, NSUInteger flags) {
18 return disposition_utils::DispositionFromClick( 62 return disposition_utils::DispositionFromClick(
19 [event buttonNumber] == 2, 63 [event buttonNumber] == 2,
20 flags & NSAlternateKeyMask, 64 flags & NSAlternateKeyMask,
21 flags & NSControlKeyMask, 65 flags & NSControlKeyMask,
22 flags & NSCommandKeyMask, 66 flags & NSCommandKeyMask,
23 flags & NSShiftKeyMask); 67 flags & NSShiftKeyMask);
24 } 68 }
25 69
26 } // namespace event_utils 70 } // namespace event_utils
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/event_utils.h ('k') | chrome/browser/ui/cocoa/event_utils_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698