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

Side by Side Diff: views/event_x.cc

Issue 3801011: touchui: Directly process key and mouse events. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: nit Created 10 years, 1 month 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 | « views/event.h ('k') | views/focus/accelerator_handler.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) 2010 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 "views/event.h"
6
7 #include <gdk/gdkx.h>
8
9 #include "app/keyboard_code_conversion_x.h"
10 #include "views/widget/root_view.h"
11 #include "views/widget/widget_gtk.h"
12
13 namespace views {
14
15 namespace {
16
17 int GetEventFlagsFromXState(unsigned int state) {
18 int flags = 0;
19 if (state & ControlMask)
20 flags |= Event::EF_CONTROL_DOWN;
21 if (state & ShiftMask)
22 flags |= Event::EF_SHIFT_DOWN;
23 if (state & Mod1Mask)
24 flags |= Event::EF_ALT_DOWN;
25 if (state & Button1Mask)
26 flags |= Event::EF_LEFT_BUTTON_DOWN;
27 if (state & Button2Mask)
28 flags |= Event::EF_MIDDLE_BUTTON_DOWN;
29 if (state & Button3Mask)
30 flags |= Event::EF_RIGHT_BUTTON_DOWN;
31
32 return flags;
33 }
34
35 // Get the event flag for the button in XButtonEvent. During a KeyPress event,
36 // |state| in XButtonEvent does not include the button that has just been
37 // pressed. Instead |state| contains flags for the buttons (if any) that had
38 // already been pressed before the current button, and |button| stores the most
39 // current pressed button. So, if you press down left mouse button, and while
40 // pressing it down, press down the right mouse button, then for the latter
41 // event, |state| would have Button1Mask set but not Button3Mask, and |button|
42 // would be 3.
43 int GetEventFlagsForButton(int button) {
44 switch (button) {
45 case 1:
46 return Event::EF_LEFT_BUTTON_DOWN;
47 case 2:
48 return Event::EF_MIDDLE_BUTTON_DOWN;
49 case 3:
50 return Event::EF_RIGHT_BUTTON_DOWN;
51 }
52
53 DLOG(WARNING) << "Unexpected button (" << button << ") received.";
54 return 0;
55 }
56
57 Event::EventType GetMouseEventType(XEvent* xev) {
58 switch (xev->type) {
59 case ButtonPress:
60 return Event::ET_MOUSE_PRESSED;
61 case ButtonRelease:
62 return Event::ET_MOUSE_RELEASED;
63 case MotionNotify:
64 if (xev->xmotion.state & (Button1Mask | Button2Mask | Button3Mask)) {
65 return Event::ET_MOUSE_DRAGGED;
66 }
67 return Event::ET_MOUSE_MOVED;
68 }
69
70 return Event::ET_UNKNOWN;
71 }
72
73 gfx::Point GetMouseEventLocation(XEvent* xev) {
74 switch (xev->type) {
75 case ButtonPress:
76 case ButtonRelease:
77 return gfx::Point(xev->xbutton.x, xev->xbutton.y);
78
79 case MotionNotify:
80 return gfx::Point(xev->xmotion.x, xev->xmotion.y);
81 }
82
83 return gfx::Point();
84 }
85
86 int GetMouseEventFlags(XEvent* xev) {
87 switch (xev->type) {
88 case ButtonPress:
89 case ButtonRelease:
90 return GetEventFlagsFromXState(xev->xbutton.state) |
91 GetEventFlagsForButton(xev->xbutton.button);
92
93 case MotionNotify:
94 return GetEventFlagsFromXState(xev->xmotion.state);
95 }
96
97 return 0;
98 }
99
100 } // namespace
101
102 KeyEvent::KeyEvent(XEvent* xev)
103 : Event(xev->type == KeyPress ?
104 Event::ET_KEY_PRESSED : Event::ET_KEY_RELEASED,
105 GetEventFlagsFromXState(xev->xkey.state)),
106 key_code_(app::KeyboardCodeFromXKeyEvent(xev)),
107 repeat_count_(0),
108 message_flags_(0) {
109 }
110
111 MouseEvent::MouseEvent(XEvent* xev)
112 : LocatedEvent(GetMouseEventType(xev),
113 GetMouseEventLocation(xev),
114 GetMouseEventFlags(xev)) {
115 }
116
117 } // namespace views
OLDNEW
« no previous file with comments | « views/event.h ('k') | views/focus/accelerator_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698