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

Side by Side Diff: ui/events/event_utils.cc

Issue 862093002: Split the event library into a cross-platform and native part. Part 1. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT Created 5 years, 11 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
« no previous file with comments | « ui/events/event_utils.h ('k') | ui/events/events_stub.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "ui/events/event_utils.h" 5 #include "ui/events/event_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ui/events/event.h" 9 #include "ui/events/event.h"
10 #include "ui/gfx/display.h" 10 #include "ui/gfx/display.h"
11 11
12 namespace ui { 12 namespace ui {
13 13
14 namespace {
15 int g_custom_event_types = ET_LAST;
16 } // namespace
17
18 scoped_ptr<Event> EventFromNative(const base::NativeEvent& native_event) {
19 scoped_ptr<Event> event;
20 EventType type = EventTypeFromNative(native_event);
21 switch(type) {
22 case ET_KEY_PRESSED:
23 case ET_KEY_RELEASED:
24 event.reset(new KeyEvent(native_event));
25 break;
26
27 case ET_TRANSLATED_KEY_PRESS:
28 case ET_TRANSLATED_KEY_RELEASE:
29 // These should not be generated by native events.
30 NOTREACHED();
31 break;
32
33 case ET_MOUSE_PRESSED:
34 case ET_MOUSE_DRAGGED:
35 case ET_MOUSE_RELEASED:
36 case ET_MOUSE_MOVED:
37 case ET_MOUSE_ENTERED:
38 case ET_MOUSE_EXITED:
39 event.reset(new MouseEvent(native_event));
40 break;
41
42 case ET_MOUSEWHEEL:
43 event.reset(new MouseWheelEvent(native_event));
44 break;
45
46 case ET_SCROLL_FLING_START:
47 case ET_SCROLL_FLING_CANCEL:
48 case ET_SCROLL:
49 event.reset(new ScrollEvent(native_event));
50 break;
51
52 case ET_TOUCH_RELEASED:
53 case ET_TOUCH_PRESSED:
54 case ET_TOUCH_MOVED:
55 case ET_TOUCH_CANCELLED:
56 event.reset(new TouchEvent(native_event));
57 break;
58
59 default:
60 break;
61 }
62 return event.Pass();
63 }
64
65 // From third_party/WebKit/Source/web/gtk/WebInputEventFactory.cpp: 14 // From third_party/WebKit/Source/web/gtk/WebInputEventFactory.cpp:
66 base::char16 GetControlCharacterForKeycode(int windows_key_code, bool shift) { 15 base::char16 GetControlCharacterForKeycode(int windows_key_code, bool shift) {
67 if (windows_key_code >= ui::VKEY_A && 16 if (windows_key_code >= ui::VKEY_A &&
68 windows_key_code <= ui::VKEY_Z) { 17 windows_key_code <= ui::VKEY_Z) {
69 // ctrl-A ~ ctrl-Z map to \x01 ~ \x1A 18 // ctrl-A ~ ctrl-Z map to \x01 ~ \x1A
70 return windows_key_code - ui::VKEY_A + 1; 19 return windows_key_code - ui::VKEY_A + 1;
71 } 20 }
72 if (shift) { 21 if (shift) {
73 // following graphics chars require shift key to input. 22 // following graphics chars require shift key to input.
74 switch (windows_key_code) { 23 switch (windows_key_code) {
(...skipping 25 matching lines...) Expand all
100 case ui::VKEY_RETURN: 49 case ui::VKEY_RETURN:
101 return 0x0A; 50 return 0x0A;
102 // Returns 0 for all other keys to avoid inputting unexpected chars. 51 // Returns 0 for all other keys to avoid inputting unexpected chars.
103 default: 52 default:
104 break; 53 break;
105 } 54 }
106 } 55 }
107 return 0; 56 return 0;
108 } 57 }
109 58
110 int RegisterCustomEventType() {
111 return ++g_custom_event_types;
112 }
113
114 base::TimeDelta EventTimeForNow() { 59 base::TimeDelta EventTimeForNow() {
115 return base::TimeDelta::FromInternalValue( 60 return base::TimeDelta::FromInternalValue(
116 base::TimeTicks::Now().ToInternalValue()); 61 base::TimeTicks::Now().ToInternalValue());
117 } 62 }
118 63
119 } // namespace ui 64 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/event_utils.h ('k') | ui/events/events_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698