| 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/aura/root_window_host_linux.h" | 5 #include "ui/aura/root_window_host_linux.h" |
| 6 | 6 |
| 7 #include <strings.h> | 7 #include <strings.h> |
| 8 #include <X11/cursorfont.h> | 8 #include <X11/cursorfont.h> |
| 9 #include <X11/extensions/Xfixes.h> | 9 #include <X11/extensions/Xfixes.h> |
| 10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 using std::min; | 54 using std::min; |
| 55 | 55 |
| 56 namespace aura { | 56 namespace aura { |
| 57 | 57 |
| 58 namespace { | 58 namespace { |
| 59 | 59 |
| 60 // Standard Linux mouse buttons for going back and forward. | 60 // Standard Linux mouse buttons for going back and forward. |
| 61 const int kBackMouseButton = 8; | 61 const int kBackMouseButton = 8; |
| 62 const int kForwardMouseButton = 9; | 62 const int kForwardMouseButton = 9; |
| 63 | 63 |
| 64 // These are the same values that are used to calibrate touch events in | |
| 65 // |CalibrateTouchCoordinates| (in ui/base/x/events_x.cc). | |
| 66 // TODO(sad|skuhne): Remove the duplication of values (http://crbug.com/147605) | |
| 67 const int kXRootWindowPaddingLeft = 40; | |
| 68 const int kXRootWindowPaddingRight = 40; | |
| 69 const int kXRootWindowPaddingBottom = 30; | |
| 70 const int kXRootWindowPaddingTop = 0; | |
| 71 | |
| 72 const char* kAtomsToCache[] = { | 64 const char* kAtomsToCache[] = { |
| 73 "WM_DELETE_WINDOW", | 65 "WM_DELETE_WINDOW", |
| 74 "_NET_WM_PING", | 66 "_NET_WM_PING", |
| 75 "_NET_WM_PID", | 67 "_NET_WM_PID", |
| 76 "WM_S0", | 68 "WM_S0", |
| 77 #if defined(OS_CHROMEOS) | 69 #if defined(OS_CHROMEOS) |
| 78 "Tap Paused", // Defined in the gestures library. | 70 "Tap Paused", // Defined in the gestures library. |
| 79 #endif | 71 #endif |
| 80 NULL | 72 NULL |
| 81 }; | 73 }; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 return false; | 160 return false; |
| 169 } | 161 } |
| 170 } | 162 } |
| 171 | 163 |
| 172 } // namespace | 164 } // namespace |
| 173 | 165 |
| 174 namespace internal { | 166 namespace internal { |
| 175 | 167 |
| 176 // A very lightweight message-pump observer that routes all the touch events to | 168 // A very lightweight message-pump observer that routes all the touch events to |
| 177 // the X root window so that they can be calibrated properly. | 169 // the X root window so that they can be calibrated properly. |
| 178 class TouchEventCalibrate : public base::MessagePumpObserver { | 170 class TouchEventRouter : public base::MessagePumpObserver { |
| 179 public: | 171 public: |
| 180 TouchEventCalibrate() { | 172 TouchEventRouter() { |
| 181 MessageLoopForUI::current()->AddObserver(this); | 173 MessageLoopForUI::current()->AddObserver(this); |
| 182 } | 174 } |
| 183 | 175 |
| 184 virtual ~TouchEventCalibrate() { | 176 virtual ~TouchEventRouter() { |
| 185 MessageLoopForUI::current()->RemoveObserver(this); | 177 MessageLoopForUI::current()->RemoveObserver(this); |
| 186 } | 178 } |
| 187 | 179 |
| 188 private: | 180 private: |
| 189 // Overridden from base::MessagePumpObserver: | 181 // Overridden from base::MessagePumpObserver: |
| 190 virtual base::EventStatus WillProcessEvent( | 182 virtual base::EventStatus WillProcessEvent( |
| 191 const base::NativeEvent& event) OVERRIDE { | 183 const base::NativeEvent& event) OVERRIDE { |
| 192 #if defined(USE_XI2_MT) | 184 #if defined(USE_XI2_MT) |
| 193 if (event->type == GenericEvent && | 185 if (event->type == GenericEvent && |
| 194 (event->xgeneric.evtype == XI_TouchBegin || | 186 (event->xgeneric.evtype == XI_TouchBegin || |
| 195 event->xgeneric.evtype == XI_TouchUpdate || | 187 event->xgeneric.evtype == XI_TouchUpdate || |
| 196 event->xgeneric.evtype == XI_TouchEnd)) { | 188 event->xgeneric.evtype == XI_TouchEnd)) { |
| 197 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event->xcookie.data); | 189 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event->xcookie.data); |
| 198 xievent->event = xievent->root; | 190 xievent->event = xievent->root; |
| 199 xievent->event_x = xievent->root_x; | 191 xievent->event_x = xievent->root_x; |
| 200 xievent->event_y = xievent->root_y; | 192 xievent->event_y = xievent->root_y; |
| 201 } | 193 } |
| 202 #endif | 194 #endif |
| 203 return base::EVENT_CONTINUE; | 195 return base::EVENT_CONTINUE; |
| 204 } | 196 } |
| 205 | 197 |
| 206 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE { | 198 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE { |
| 207 } | 199 } |
| 208 | 200 |
| 209 DISALLOW_COPY_AND_ASSIGN(TouchEventCalibrate); | 201 DISALLOW_COPY_AND_ASSIGN(TouchEventRouter); |
| 210 }; | 202 }; |
| 211 | 203 |
| 212 } // namespace internal | 204 } // namespace internal |
| 213 | 205 |
| 214 //////////////////////////////////////////////////////////////////////////////// | 206 //////////////////////////////////////////////////////////////////////////////// |
| 215 // RootWindowHostLinux::MouseMoveFilter filters out the move events that | 207 // RootWindowHostLinux::MouseMoveFilter filters out the move events that |
| 216 // jump back and forth between two points. This happens when sub pixel mouse | 208 // jump back and forth between two points. This happens when sub pixel mouse |
| 217 // move is enabled and mouse move events could be jumping between two neighbor | 209 // move is enabled and mouse move events could be jumping between two neighbor |
| 218 // pixels, e.g. move(0,0), move(1,0), move(0,0), move(1,0) and on and on. | 210 // pixels, e.g. move(0,0), move(1,0), move(0,0), move(1,0) and on and on. |
| 219 // The filtering is done by keeping track of the last two event locations and | 211 // The filtering is done by keeping track of the last two event locations and |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) | 250 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) |
| 259 : delegate_(NULL), | 251 : delegate_(NULL), |
| 260 xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), | 252 xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), |
| 261 xwindow_(0), | 253 xwindow_(0), |
| 262 x_root_window_(DefaultRootWindow(xdisplay_)), | 254 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 263 current_cursor_(ui::kCursorNull), | 255 current_cursor_(ui::kCursorNull), |
| 264 window_mapped_(false), | 256 window_mapped_(false), |
| 265 bounds_(bounds), | 257 bounds_(bounds), |
| 266 is_internal_display_(false), | 258 is_internal_display_(false), |
| 267 focus_when_shown_(false), | 259 focus_when_shown_(false), |
| 268 touch_calibrate_(new internal::TouchEventCalibrate), | 260 touch_router_(new internal::TouchEventRouter), |
| 269 mouse_move_filter_(new MouseMoveFilter), | 261 mouse_move_filter_(new MouseMoveFilter), |
| 270 atom_cache_(xdisplay_, kAtomsToCache) { | 262 atom_cache_(xdisplay_, kAtomsToCache) { |
| 271 XSetWindowAttributes swa; | 263 XSetWindowAttributes swa; |
| 272 memset(&swa, 0, sizeof(swa)); | 264 memset(&swa, 0, sizeof(swa)); |
| 273 swa.background_pixmap = None; | 265 swa.background_pixmap = None; |
| 274 xwindow_ = XCreateWindow( | 266 xwindow_ = XCreateWindow( |
| 275 xdisplay_, x_root_window_, | 267 xdisplay_, x_root_window_, |
| 276 bounds.x(), bounds.y(), bounds.width(), bounds.height(), | 268 bounds.x(), bounds.y(), bounds.width(), bounds.height(), |
| 277 0, // border width | 269 0, // border width |
| 278 CopyFromParent, // depth | 270 CopyFromParent, // depth |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 num_coalesced = ui::CoalescePendingMotionEvents(xev, &last_event); | 889 num_coalesced = ui::CoalescePendingMotionEvents(xev, &last_event); |
| 898 if (num_coalesced > 0) | 890 if (num_coalesced > 0) |
| 899 xev = &last_event; | 891 xev = &last_event; |
| 900 // fallthrough | 892 // fallthrough |
| 901 case ui::ET_TOUCH_PRESSED: | 893 case ui::ET_TOUCH_PRESSED: |
| 902 case ui::ET_TOUCH_CANCELLED: | 894 case ui::ET_TOUCH_CANCELLED: |
| 903 case ui::ET_TOUCH_RELEASED: { | 895 case ui::ET_TOUCH_RELEASED: { |
| 904 ui::TouchEvent touchev(xev); | 896 ui::TouchEvent touchev(xev); |
| 905 #if defined(OS_CHROMEOS) | 897 #if defined(OS_CHROMEOS) |
| 906 if (base::chromeos::IsRunningOnChromeOS()) { | 898 if (base::chromeos::IsRunningOnChromeOS()) { |
| 907 if (!bounds_.Contains(touchev.location())) { | 899 if (!bounds_.Contains(touchev.location())) |
| 908 // This might still be in the bezel region. | 900 break; |
| 909 gfx::Rect expanded(bounds_); | 901 // X maps the touch-surface to the size of the X root-window. |
| 910 expanded.Inset(-kXRootWindowPaddingLeft, | 902 // In multi-monitor setup, Coordinate Transformation Matrix |
| 911 -kXRootWindowPaddingTop, | 903 // repositions the touch-surface onto part of X root-window |
| 912 -kXRootWindowPaddingRight, | 904 // containing aura root-window corresponding to the touchscreen. |
| 913 -kXRootWindowPaddingBottom); | 905 // However, if aura root-window has non-zero origin, |
| 914 if (!expanded.Contains(touchev.location())) | 906 // we need to relocate the event into aura root-window coordinates. |
| 915 break; | 907 touchev.Relocate(bounds_.origin()); |
| 916 } | 908 #if defined(USE_XI2_MT) |
| 909 if (is_internal_display_) |
| 910 touchev.Calibrate(bounds_); |
| 911 #endif // defined(USE_XI2_MT) |
| 917 } | 912 } |
| 918 // X maps the touch-surface to the size of the X root-window. | |
| 919 // In multi-monitor setup, Coordinate Transformation Matrix | |
| 920 // repositions the touch-surface onto part of X root-window | |
| 921 // containing aura root-window corresponding to the touchscreen. | |
| 922 // However, if aura root-window has non-zero origin, | |
| 923 // we need to relocate the event into aura root-window coordinates. | |
| 924 touchev.Relocate(bounds_.origin()); | |
| 925 #endif // defined(OS_CHROMEOS) | 913 #endif // defined(OS_CHROMEOS) |
| 926 delegate_->OnHostTouchEvent(&touchev); | 914 delegate_->OnHostTouchEvent(&touchev); |
| 927 break; | 915 break; |
| 928 } | 916 } |
| 929 case ui::ET_MOUSE_MOVED: | 917 case ui::ET_MOUSE_MOVED: |
| 930 case ui::ET_MOUSE_DRAGGED: | 918 case ui::ET_MOUSE_DRAGGED: |
| 931 case ui::ET_MOUSE_PRESSED: | 919 case ui::ET_MOUSE_PRESSED: |
| 932 case ui::ET_MOUSE_RELEASED: | 920 case ui::ET_MOUSE_RELEASED: |
| 933 case ui::ET_MOUSE_ENTERED: | 921 case ui::ET_MOUSE_ENTERED: |
| 934 case ui::ET_MOUSE_EXITED: { | 922 case ui::ET_MOUSE_EXITED: { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 return new RootWindowHostLinux(bounds); | 1033 return new RootWindowHostLinux(bounds); |
| 1046 } | 1034 } |
| 1047 | 1035 |
| 1048 // static | 1036 // static |
| 1049 gfx::Size RootWindowHost::GetNativeScreenSize() { | 1037 gfx::Size RootWindowHost::GetNativeScreenSize() { |
| 1050 ::Display* xdisplay = base::MessagePumpAuraX11::GetDefaultXDisplay(); | 1038 ::Display* xdisplay = base::MessagePumpAuraX11::GetDefaultXDisplay(); |
| 1051 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 1039 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
| 1052 } | 1040 } |
| 1053 | 1041 |
| 1054 } // namespace aura | 1042 } // namespace aura |
| OLD | NEW |