OLD | NEW |
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_constants.h" | 5 #include "ui/events/event_constants.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <X11/extensions/XInput.h> | 9 #include <X11/extensions/XInput.h> |
10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 flags |= ui::EF_ALTGR_DOWN; | 141 flags |= ui::EF_ALTGR_DOWN; |
142 if (state & Button1Mask) | 142 if (state & Button1Mask) |
143 flags |= ui::EF_LEFT_MOUSE_BUTTON; | 143 flags |= ui::EF_LEFT_MOUSE_BUTTON; |
144 if (state & Button2Mask) | 144 if (state & Button2Mask) |
145 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; | 145 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; |
146 if (state & Button3Mask) | 146 if (state & Button3Mask) |
147 flags |= ui::EF_RIGHT_MOUSE_BUTTON; | 147 flags |= ui::EF_RIGHT_MOUSE_BUTTON; |
148 return flags; | 148 return flags; |
149 } | 149 } |
150 | 150 |
| 151 int GetEventFlagsFromXKeyEvent(XEvent* xevent) { |
| 152 DCHECK(xevent->type == KeyPress || xevent->type == KeyRelease); |
| 153 |
| 154 #if defined(OS_CHROMEOS) |
| 155 const int ime_fabricated_flag = 0; |
| 156 #else |
| 157 // XIM fabricates key events for the character compositions by XK_Multi_key. |
| 158 // For example, when a user hits XK_Multi_key, XK_apostrophe, and XK_e in |
| 159 // order to input "é", then XIM generates a key event with keycode=0 and |
| 160 // state=0 for the composition, and the sequence of X11 key events will be |
| 161 // XK_Multi_key, XK_apostrophe, **NoSymbol**, and XK_e. |
| 162 // |
| 163 // We have to send these fabricated key events to XIM so it can correctly |
| 164 // handle the character compositions. |
| 165 const bool fabricated_by_xim = |
| 166 xevent->xkey.keycode == 0 && xevent->xkey.state == 0; |
| 167 const int ime_fabricated_flag = |
| 168 fabricated_by_xim ? ui::EF_IME_FABRICATED_KEY : 0; |
| 169 #endif |
| 170 |
| 171 return GetEventFlagsFromXState(xevent->xkey.state) | |
| 172 (IsKeypadKey(XLookupKeysym(&xevent->xkey, 0)) ? ui::EF_NUMPAD_KEY : 0) | |
| 173 ime_fabricated_flag; |
| 174 } |
| 175 |
151 // Get the event flag for the button in XButtonEvent. During a ButtonPress | 176 // Get the event flag for the button in XButtonEvent. During a ButtonPress |
152 // event, |state| in XButtonEvent does not include the button that has just been | 177 // event, |state| in XButtonEvent does not include the button that has just been |
153 // pressed. Instead |state| contains flags for the buttons (if any) that had | 178 // pressed. Instead |state| contains flags for the buttons (if any) that had |
154 // already been pressed before the current button, and |button| stores the most | 179 // already been pressed before the current button, and |button| stores the most |
155 // current pressed button. So, if you press down left mouse button, and while | 180 // current pressed button. So, if you press down left mouse button, and while |
156 // pressing it down, press down the right mouse button, then for the latter | 181 // pressing it down, press down the right mouse button, then for the latter |
157 // event, |state| would have Button1Mask set but not Button3Mask, and |button| | 182 // event, |state| would have Button1Mask set but not Button3Mask, and |button| |
158 // would be 3. | 183 // would be 3. |
159 int GetEventFlagsForButton(int button) { | 184 int GetEventFlagsForButton(int button) { |
160 switch (button) { | 185 switch (button) { |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 | 698 |
674 bool IsNaturalScrollEnabled() { | 699 bool IsNaturalScrollEnabled() { |
675 return DeviceDataManager::GetInstance()->natural_scroll_enabled(); | 700 return DeviceDataManager::GetInstance()->natural_scroll_enabled(); |
676 } | 701 } |
677 | 702 |
678 bool IsTouchpadEvent(const base::NativeEvent& event) { | 703 bool IsTouchpadEvent(const base::NativeEvent& event) { |
679 return DeviceDataManager::GetInstance()->IsTouchpadXInputEvent(event); | 704 return DeviceDataManager::GetInstance()->IsTouchpadXInputEvent(event); |
680 } | 705 } |
681 | 706 |
682 } // namespace ui | 707 } // namespace ui |
OLD | NEW |