1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file. 4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#import "ui/events/cocoa/cocoa_event_utils.h" 6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/events/event_constants.h" 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/events/event_utils.h" 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace { 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool IsLeftButtonEvent(NSEvent* event) { 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) NSEventType type = [event type]; 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return type == NSLeftMouseDown || type == NSLeftMouseDragged || 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) type == NSLeftMouseUp; 16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool IsRightButtonEvent(NSEvent* event) { 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) NSEventType type = [event type]; 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return type == NSRightMouseDown || type == NSRightMouseDragged || 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) type == NSRightMouseUp; 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool IsMiddleButtonEvent(NSEvent* event) { 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if ([event buttonNumber] != 2) 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return false; 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) NSEventType type = [event type]; 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return type == NSOtherMouseDown || type == NSOtherMouseDragged || 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) type == NSOtherMouseUp; 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} // namespace 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace ui { 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)int EventFlagsFromModifiers(NSUInteger modifiers) { 38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) int flags = 0; 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) flags |= (modifiers & NSAlphaShiftKeyMask) ? ui::EF_CAPS_LOCK_DOWN : 0; 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) flags |= (modifiers & NSShiftKeyMask) ? ui::EF_SHIFT_DOWN : 0; 41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) flags |= (modifiers & NSControlKeyMask) ? ui::EF_CONTROL_DOWN : 0; 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) flags |= (modifiers & NSAlternateKeyMask) ? ui::EF_ALT_DOWN : 0; 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) flags |= (modifiers & NSCommandKeyMask) ? ui::EF_COMMAND_DOWN : 0; 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return flags; 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)int EventFlagsFromNSEventWithModifiers(NSEvent* event, NSUInteger modifiers) { 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) int flags = EventFlagsFromModifiers(modifiers); 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) flags |= IsLeftButtonEvent(event) ? ui::EF_LEFT_MOUSE_BUTTON : 0; 50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) flags |= IsRightButtonEvent(event) ? ui::EF_RIGHT_MOUSE_BUTTON : 0; 51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) flags |= IsMiddleButtonEvent(event) ? ui::EF_MIDDLE_MOUSE_BUTTON : 0; 52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return flags; 53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} // namespace ui 56