OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "views/focus/accelerator_handler.h" | 5 #include "views/focus/accelerator_handler.h" |
6 | 6 |
7 #include <bitset> | 7 #include <bitset> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #if defined(HAVE_XINPUT2) | 9 #if defined(HAVE_XINPUT2) |
10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 default: | 55 default: |
56 return false; | 56 return false; |
57 } | 57 } |
58 } | 58 } |
59 #endif // HAVE_XINPUT2 | 59 #endif // HAVE_XINPUT2 |
60 | 60 |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 #if defined(HAVE_XINPUT2) | 63 #if defined(HAVE_XINPUT2) |
64 bool DispatchX2Event(RootView* root, XEvent* xev) { | 64 bool DispatchX2Event(RootView* root, XEvent* xev) { |
| 65 XGenericEventCookie* cookie = &xev->xcookie; |
| 66 bool touch_event = false; |
| 67 |
65 if (X2EventIsTouchEvent(xev)) { | 68 if (X2EventIsTouchEvent(xev)) { |
| 69 // Hide the cursor when a touch event comes in. |
| 70 TouchFactory::GetInstance()->SetCursorVisible(false, false); |
| 71 touch_event = true; |
| 72 |
66 // Create a TouchEvent, and send it off to |root|. If the event | 73 // Create a TouchEvent, and send it off to |root|. If the event |
67 // is processed by |root|, then return. Otherwise let it fall through so it | 74 // is processed by |root|, then return. Otherwise let it fall through so it |
68 // can be used (if desired) as a mouse event. | 75 // can be used (if desired) as a mouse event. |
69 | |
70 TouchEvent touch(xev); | 76 TouchEvent touch(xev); |
71 if (root->OnTouchEvent(touch) != views::View::TOUCH_STATUS_UNKNOWN) | 77 if (root->OnTouchEvent(touch) != views::View::TOUCH_STATUS_UNKNOWN) |
72 return true; | 78 return true; |
73 } | 79 } |
74 | 80 |
75 XGenericEventCookie* cookie = &xev->xcookie; | |
76 | |
77 switch (cookie->evtype) { | 81 switch (cookie->evtype) { |
78 case XI_KeyPress: | 82 case XI_KeyPress: |
79 case XI_KeyRelease: { | 83 case XI_KeyRelease: { |
80 // TODO(sad): We don't capture XInput2 events from keyboard yet. | 84 // TODO(sad): We don't capture XInput2 events from keyboard yet. |
81 break; | 85 break; |
82 } | 86 } |
83 case XI_ButtonPress: | 87 case XI_ButtonPress: |
84 case XI_ButtonRelease: { | 88 case XI_ButtonRelease: |
85 MouseEvent mouseev(xev); | |
86 if (cookie->evtype == XI_ButtonPress) { | |
87 return root->OnMousePressed(mouseev); | |
88 } else { | |
89 root->OnMouseReleased(mouseev, false); | |
90 return true; | |
91 } | |
92 } | |
93 | |
94 case XI_Motion: { | 89 case XI_Motion: { |
95 MouseEvent mouseev(xev); | 90 MouseEvent mouseev(xev); |
96 if (mouseev.GetType() == Event::ET_MOUSE_DRAGGED) { | 91 if (!touch_event) { |
97 return root->OnMouseDragged(mouseev); | 92 // Show the cursor, and decide whether or not the cursor should be |
98 } else { | 93 // automatically hidden after a certain time of inactivity. |
99 root->OnMouseMoved(mouseev); | 94 int button_flags = mouseev.GetFlags() & (Event::EF_RIGHT_BUTTON_DOWN | |
100 return true; | 95 Event::EF_MIDDLE_BUTTON_DOWN | Event::EF_LEFT_BUTTON_DOWN); |
| 96 bool start_timer = false; |
| 97 |
| 98 switch (cookie->evtype) { |
| 99 case XI_ButtonPress: |
| 100 start_timer = false; |
| 101 break; |
| 102 case XI_ButtonRelease: |
| 103 // For a release, start the timer if this was only button pressed |
| 104 // that is being released. |
| 105 if (button_flags == Event::EF_RIGHT_BUTTON_DOWN || |
| 106 button_flags == Event::EF_LEFT_BUTTON_DOWN || |
| 107 button_flags == Event::EF_MIDDLE_BUTTON_DOWN) |
| 108 start_timer = true; |
| 109 break; |
| 110 case XI_Motion: |
| 111 start_timer = !button_flags; |
| 112 break; |
| 113 } |
| 114 TouchFactory::GetInstance()->SetCursorVisible(true, start_timer); |
101 } | 115 } |
102 break; | 116 |
| 117 // Dispatch the event. |
| 118 switch (cookie->evtype) { |
| 119 case XI_ButtonPress: |
| 120 return root->OnMousePressed(mouseev); |
| 121 case XI_ButtonRelease: |
| 122 root->OnMouseReleased(mouseev, false); |
| 123 return true; |
| 124 case XI_Motion: { |
| 125 if (mouseev.GetType() == Event::ET_MOUSE_DRAGGED) { |
| 126 return root->OnMouseDragged(mouseev); |
| 127 } else { |
| 128 root->OnMouseMoved(mouseev); |
| 129 return true; |
| 130 } |
| 131 } |
| 132 } |
103 } | 133 } |
104 } | 134 } |
105 | 135 |
106 return false; | 136 return false; |
107 } | 137 } |
108 | 138 |
109 #endif // HAVE_XINPUT2 | 139 #endif // HAVE_XINPUT2 |
110 | 140 |
111 bool DispatchXEvent(XEvent* xev) { | 141 bool DispatchXEvent(XEvent* xev) { |
112 GdkDisplay* gdisp = gdk_display_get_default(); | 142 GdkDisplay* gdisp = gdk_display_get_default(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 213 } |
184 | 214 |
185 base::MessagePumpGlibXDispatcher::DispatchStatus AcceleratorHandler::Dispatch( | 215 base::MessagePumpGlibXDispatcher::DispatchStatus AcceleratorHandler::Dispatch( |
186 XEvent* xev) { | 216 XEvent* xev) { |
187 return DispatchXEvent(xev) ? | 217 return DispatchXEvent(xev) ? |
188 base::MessagePumpGlibXDispatcher::EVENT_PROCESSED : | 218 base::MessagePumpGlibXDispatcher::EVENT_PROCESSED : |
189 base::MessagePumpGlibXDispatcher::EVENT_IGNORED; | 219 base::MessagePumpGlibXDispatcher::EVENT_IGNORED; |
190 } | 220 } |
191 | 221 |
192 } // namespace views | 222 } // namespace views |
OLD | NEW |