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

Side by Side Diff: third_party/WebKit/WebKit/chromium/src/mac/WebInputEventFactory.mm

Issue 56197: Unify all event modifier handling to a common place (and make it correct!). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 8 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2006-2009 Google Inc. 3 * Copyright (C) 2006-2009 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 // FIXME: We should use something other than the vendor-area Unicode val ues for the above keys. 818 // FIXME: We should use something other than the vendor-area Unicode val ues for the above keys.
819 // For now, just fall through to the default. 819 // For now, just fall through to the default.
820 default: 820 default:
821 return [NSString stringWithFormat:@"U+%04X", WTF::toASCIIUpper(c)]; 821 return [NSString stringWithFormat:@"U+%04X", WTF::toASCIIUpper(c)];
822 } 822 }
823 } 823 }
824 824
825 // End Apple code. 825 // End Apple code.
826 // ---------------------------------------------------------------------------- 826 // ----------------------------------------------------------------------------
827 827
828 static inline int modifiersFromEvent(NSEvent* event) {
829 int modifiers = 0;
830
831 if ([event modifierFlags] & NSControlKeyMask)
832 modifiers |= WebInputEvent::ControlKey;
833 if ([event modifierFlags] & NSShiftKeyMask)
834 modifiers |= WebInputEvent::ShiftKey;
835 if ([event modifierFlags] & NSAlternateKeyMask)
836 modifiers |= WebInputEvent::AltKey;
837 if ([event modifierFlags] & NSCommandKeyMask)
838 modifiers |= WebInputEvent::MetaKey;
839
840 return modifiers;
841 }
842
828 WebKeyboardEvent WebInputEventFactory::keyboardEvent(NSEvent* event) 843 WebKeyboardEvent WebInputEventFactory::keyboardEvent(NSEvent* event)
829 { 844 {
830 WebKeyboardEvent result; 845 WebKeyboardEvent result;
831 846
832 result.type = 847 result.type =
833 isKeyUpEvent(event) ? WebInputEvent::KeyUp : WebInputEvent::KeyDown; 848 isKeyUpEvent(event) ? WebInputEvent::KeyUp : WebInputEvent::KeyDown;
834 849
835 if ([event modifierFlags] & NSControlKeyMask) 850 result.modifiers = modifiersFromEvent(event);
836 result.modifiers |= WebInputEvent::ControlKey;
837 if ([event modifierFlags] & NSShiftKeyMask)
838 result.modifiers |= WebInputEvent::ShiftKey;
839 if ([event modifierFlags] & NSAlternateKeyMask)
840 result.modifiers |= WebInputEvent::AltKey;
841 if ([event modifierFlags] & NSCommandKeyMask)
842 result.modifiers |= WebInputEvent::MetaKey;
843 851
844 if (isKeypadEvent(event)) 852 if (isKeypadEvent(event))
845 result.modifiers |= WebInputEvent::IsKeyPad; 853 result.modifiers |= WebInputEvent::IsKeyPad;
846 854
847 if (([event type] != NSFlagsChanged) && [event isARepeat]) 855 if (([event type] != NSFlagsChanged) && [event isARepeat])
848 result.modifiers |= WebInputEvent::IsAutoRepeat; 856 result.modifiers |= WebInputEvent::IsAutoRepeat;
849 857
850 result.windowsKeyCode = windowsKeyCodeForKeyEvent(event); 858 result.windowsKeyCode = windowsKeyCodeForKeyEvent(event);
851 result.nativeKeyCode = [event keyCode]; 859 result.nativeKeyCode = [event keyCode];
852 860
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 result.button = WebMouseEvent::ButtonMiddle; 953 result.button = WebMouseEvent::ButtonMiddle;
946 break; 954 break;
947 case NSRightMouseDragged: 955 case NSRightMouseDragged:
948 result.type = WebInputEvent::MouseMove; 956 result.type = WebInputEvent::MouseMove;
949 result.button = WebMouseEvent::ButtonRight; 957 result.button = WebMouseEvent::ButtonRight;
950 break; 958 break;
951 default: 959 default:
952 ASSERT_NOT_REACHED(); 960 ASSERT_NOT_REACHED();
953 } 961 }
954 962
955 // set position fields:
956 NSPoint location = [NSEvent mouseLocation]; // global coordinates 963 NSPoint location = [NSEvent mouseLocation]; // global coordinates
957 result.globalX = location.x; 964 result.globalX = location.x;
958 result.globalY = location.y; 965 result.globalY = location.y;
959 966
960 NSPoint windowLocal = [event locationInWindow]; 967 NSPoint windowLocal = [event locationInWindow];
961 location = [view convertPoint:windowLocal fromView:nil]; 968 location = [view convertPoint:windowLocal fromView:nil];
962 result.y = [view frame].size.height - location.y; // flip y 969 result.y = [view frame].size.height - location.y; // flip y
963 result.x = location.x; 970 result.x = location.x;
964 971
965 // set modifiers: 972 result.modifiers = modifiersFromEvent(event);
966
967 if ([event modifierFlags] & NSControlKeyMask)
968 result.modifiers |= WebInputEvent::ControlKey;
969 if ([event modifierFlags] & NSShiftKeyMask)
970 result.modifiers |= WebInputEvent::ShiftKey;
971 if ([event modifierFlags] & NSAlternateKeyMask)
972 result.modifiers |= (WebInputEvent::AltKey | WebInputEvent::MetaKey); / / FIXME: set MetaKey properly
973 973
974 result.timeStampSeconds = [event timestamp]; 974 result.timeStampSeconds = [event timestamp];
975 975
976 return result; 976 return result;
977 } 977 }
978 978
979 // WebMouseWheelEvent --------------------------------------------------------- 979 // WebMouseWheelEvent ---------------------------------------------------------
980 980
981 WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(NSEvent* event, NSView* view) 981 WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(NSEvent* event, NSView* view)
982 { 982 {
983 WebMouseWheelEvent result; 983 WebMouseWheelEvent result;
984 984
985 result.type = WebInputEvent::MouseWheel; 985 result.type = WebInputEvent::MouseWheel;
986 result.button = WebMouseEvent::ButtonNone; 986 result.button = WebMouseEvent::ButtonNone;
987 987
988 // Set modifiers based on key state. 988 result.modifiers = modifiersFromEvent(event);
989 if ([event modifierFlags] & NSControlKeyMask)
990 result.modifiers |= WebInputEvent::ControlKey;
991 if ([event modifierFlags] & NSShiftKeyMask)
992 result.modifiers |= WebInputEvent::ShiftKey;
993 if ([event modifierFlags] & NSAlternateKeyMask)
994 result.modifiers |= WebInputEvent::AltKey;
995 989
996 // Set coordinates by translating event coordinates from screen to client. 990 // Set coordinates by translating event coordinates from screen to client.
997 NSPoint location = [NSEvent mouseLocation]; // global coordinates 991 NSPoint location = [NSEvent mouseLocation]; // global coordinates
998 result.globalX = location.x; 992 result.globalX = location.x;
999 result.globalY = location.y; 993 result.globalY = location.y;
1000 NSPoint windowLocal = [event locationInWindow]; 994 NSPoint windowLocal = [event locationInWindow];
1001 location = [view convertPoint:windowLocal fromView:nil]; 995 location = [view convertPoint:windowLocal fromView:nil];
1002 result.x = location.x; 996 result.x = location.x;
1003 result.y = [view frame].size.height - location.y; // flip y 997 result.y = [view frame].size.height - location.y; // flip y
1004 998
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 static const double scrollbarPixelsPerCocoaTick = 40.0; 1120 static const double scrollbarPixelsPerCocoaTick = 40.0;
1127 1121
1128 result.deltaX = [event deltaX] * scrollbarPixelsPerCocoaTick; 1122 result.deltaX = [event deltaX] * scrollbarPixelsPerCocoaTick;
1129 result.deltaY = [event deltaY] * scrollbarPixelsPerCocoaTick; 1123 result.deltaY = [event deltaY] * scrollbarPixelsPerCocoaTick;
1130 } 1124 }
1131 1125
1132 return result; 1126 return result;
1133 } 1127 }
1134 1128
1135 } // namespace WebKit 1129 } // namespace WebKit
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698