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