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

Side by Side Diff: webkit/glue/webinputevent_linux.cc

Issue 7633: First stab at webinputevent_linux.cc. Coverts GDK events to (Closed)
Patch Set: portish Created 12 years, 2 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 | « webkit/glue/webinputevent.h ('k') | webkit/port/platform/chromium/KeyCodeConversion.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6
7 #include "webkit/glue/webinputevent.h"
8
9 #include "webkit/glue/event_conversion.h"
10
11 #include "KeyboardCodes.h"
12 #include "KeyCodeConversion.h"
13
14 #include <gdk/gdk.h>
15 #include <gdk/gdkkeysyms.h>
16 #include <gtk/gtkversion.h>
17
18 namespace {
19
20 double GdkEventTimeToWebEventTime(guint32 time) {
21 // Convert from time in ms to time in sec.
22 return time / 1000.0;
23 }
24
25 int GdkStateToWebEventModifiers(guint state) {
26 int modifiers = 0;
27 if (state & GDK_SHIFT_MASK)
28 modifiers |= WebInputEvent::SHIFT_KEY;
29 if (state & GDK_CONTROL_MASK)
30 modifiers |= WebInputEvent::CTRL_KEY;
31 if (state & GDK_MOD1_MASK)
32 modifiers |= WebInputEvent::ALT_KEY;
33 #if GTK_CHECK_VERSION(2,10,0)
34 if (state & GDK_META_MASK)
35 modifiers |= WebInputEvent::META_KEY;
36 #endif
37 return modifiers;
38 }
39
40 } // namespace
41
42 WebMouseEvent::WebMouseEvent(const GdkEventButton* event) {
43 timestamp_sec = GdkEventTimeToWebEventTime(event->time);
44 modifiers = GdkStateToWebEventModifiers(event->state);
45 x = static_cast<int>(event->x);
46 y = static_cast<int>(event->y);
47 global_x = static_cast<int>(event->x_root);
48 global_y = static_cast<int>(event->y_root);
49
50 switch (event->type) {
51 case GDK_BUTTON_PRESS:
52 case GDK_2BUTTON_PRESS:
53 case GDK_3BUTTON_PRESS:
54 type = MOUSE_DOWN;
55 break;
56 case GDK_BUTTON_RELEASE:
57 type = MOUSE_UP;
58 break;
59
60 default:
61 ASSERT_NOT_REACHED();
62 };
63
64 button = BUTTON_NONE;
65 if (event->button == 1) {
66 button = BUTTON_LEFT;
67 } else if (event->button == 2) {
68 button = BUTTON_MIDDLE;
69 } else if (event->button == 3) {
70 button = BUTTON_RIGHT;
71 }
72 }
73
74 WebMouseEvent::WebMouseEvent(const GdkEventMotion* event) {
75 timestamp_sec = GdkEventTimeToWebEventTime(event->time);
76 modifiers = GdkStateToWebEventModifiers(event->state);
77 x = static_cast<int>(event->x);
78 y = static_cast<int>(event->y);
79 global_x = static_cast<int>(event->x_root);
80 global_y = static_cast<int>(event->y_root);
81
82 switch (event->type) {
83 case GDK_MOTION_NOTIFY:
84 type = MOUSE_MOVE;
85 break;
86 default:
87 ASSERT_NOT_REACHED();
88 }
89
90 button = BUTTON_NONE;
91 if (event->state & GDK_BUTTON1_MASK) {
92 button = BUTTON_LEFT;
93 } else if (event->state & GDK_BUTTON2_MASK) {
94 button = BUTTON_MIDDLE;
95 } else if (event->state & GDK_BUTTON3_MASK) {
96 button = BUTTON_RIGHT;
97 }
98 }
99
100 WebMouseWheelEvent::WebMouseWheelEvent(const GdkEventScroll* event) {
101 timestamp_sec = GdkEventTimeToWebEventTime(event->time);
102 modifiers = GdkStateToWebEventModifiers(event->state);
103 x = static_cast<int>(event->x);
104 y = static_cast<int>(event->y);
105 global_x = static_cast<int>(event->x_root);
106 global_y = static_cast<int>(event->y_root);
107
108 type = MOUSE_WHEEL;
109
110 // TODO(tc): Figure out what the right value for this is.
111 static const int kWheelDelta = 1;
112
113 delta_x = 0;
114 delta_y = 0;
115
116 switch (event->direction) {
117 case GDK_SCROLL_UP:
118 delta_y = kWheelDelta;
119 break;
120 case GDK_SCROLL_DOWN:
121 delta_y = -kWheelDelta;
122 break;
123 case GDK_SCROLL_LEFT:
124 delta_x = -kWheelDelta;
125 break;
126 case GDK_SCROLL_RIGHT:
127 delta_x = kWheelDelta;
128 break;
129 default:
130 break;
131 }
132 }
133
134 WebKeyboardEvent::WebKeyboardEvent(const GdkEventKey* event) {
135 modifiers = GdkStateToWebEventModifiers(event->state);
136
137 switch (event->type) {
138 case GDK_KEY_RELEASE:
139 type = KEY_UP;
140 break;
141 case GDK_KEY_PRESS:
142 type = KEY_DOWN;
143 break;
144 default:
145 break;
146 }
147 key_code = WebCore::windowsKeyCodeForKeyEvent(event->keyval);
148
149 // TODO(tc): Do we need to set IS_AUTO_REPEAT or IS_KEYPAD?
150 }
OLDNEW
« no previous file with comments | « webkit/glue/webinputevent.h ('k') | webkit/port/platform/chromium/KeyCodeConversion.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698