| 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/window_tree_host_x11.h" | 5 #include "ui/aura/window_tree_host_x11.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/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/extensions/Xrandr.h> | 10 #include <X11/extensions/Xrandr.h> |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // 1. Being a message-pump observer, | 108 // 1. Being a message-pump observer, |
| 109 // routes all the touch events to the X root window, | 109 // routes all the touch events to the X root window, |
| 110 // where they can be calibrated later. | 110 // where they can be calibrated later. |
| 111 // 2. Has the Calibrate method that does the actual bezel calibration, | 111 // 2. Has the Calibrate method that does the actual bezel calibration, |
| 112 // when invoked from X root window's event dispatcher. | 112 // when invoked from X root window's event dispatcher. |
| 113 class TouchEventCalibrate : public ui::PlatformEventObserver { | 113 class TouchEventCalibrate : public ui::PlatformEventObserver { |
| 114 public: | 114 public: |
| 115 TouchEventCalibrate() : left_(0), right_(0), top_(0), bottom_(0) { | 115 TouchEventCalibrate() : left_(0), right_(0), top_(0), bottom_(0) { |
| 116 if (ui::PlatformEventSource::GetInstance()) | 116 if (ui::PlatformEventSource::GetInstance()) |
| 117 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); | 117 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); |
| 118 #if defined(USE_XI2_MT) | |
| 119 std::vector<std::string> parts; | 118 std::vector<std::string> parts; |
| 120 if (Tokenize(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 119 if (Tokenize(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 121 switches::kTouchCalibration), | 120 switches::kTouchCalibration), |
| 122 ",", | 121 ",", |
| 123 &parts) >= 4) { | 122 &parts) >= 4) { |
| 124 if (!base::StringToInt(parts[0], &left_)) | 123 if (!base::StringToInt(parts[0], &left_)) |
| 125 DLOG(ERROR) << "Incorrect left border calibration value passed."; | 124 DLOG(ERROR) << "Incorrect left border calibration value passed."; |
| 126 if (!base::StringToInt(parts[1], &right_)) | 125 if (!base::StringToInt(parts[1], &right_)) |
| 127 DLOG(ERROR) << "Incorrect right border calibration value passed."; | 126 DLOG(ERROR) << "Incorrect right border calibration value passed."; |
| 128 if (!base::StringToInt(parts[2], &top_)) | 127 if (!base::StringToInt(parts[2], &top_)) |
| 129 DLOG(ERROR) << "Incorrect top border calibration value passed."; | 128 DLOG(ERROR) << "Incorrect top border calibration value passed."; |
| 130 if (!base::StringToInt(parts[3], &bottom_)) | 129 if (!base::StringToInt(parts[3], &bottom_)) |
| 131 DLOG(ERROR) << "Incorrect bottom border calibration value passed."; | 130 DLOG(ERROR) << "Incorrect bottom border calibration value passed."; |
| 132 } | 131 } |
| 133 #endif // defined(USE_XI2_MT) | |
| 134 } | 132 } |
| 135 | 133 |
| 136 ~TouchEventCalibrate() override { | 134 ~TouchEventCalibrate() override { |
| 137 if (ui::PlatformEventSource::GetInstance()) | 135 if (ui::PlatformEventSource::GetInstance()) |
| 138 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); | 136 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); |
| 139 } | 137 } |
| 140 | 138 |
| 141 // Modify the location of the |event|, | 139 // Modify the location of the |event|, |
| 142 // expanding it from |bounds| to (|bounds| + bezels). | 140 // expanding it from |bounds| to (|bounds| + bezels). |
| 143 // Required when touchscreen is bigger than screen (i.e. has bezels), | 141 // Required when touchscreen is bigger than screen (i.e. has bezels), |
| 144 // because we receive events in touchscreen coordinates, | 142 // because we receive events in touchscreen coordinates, |
| 145 // which need to be expanded when converting to screen coordinates, | 143 // which need to be expanded when converting to screen coordinates, |
| 146 // so that location on bezels will be outside of screen area. | 144 // so that location on bezels will be outside of screen area. |
| 147 void Calibrate(ui::TouchEvent* event, const gfx::Rect& bounds) { | 145 void Calibrate(ui::TouchEvent* event, const gfx::Rect& bounds) { |
| 148 #if defined(USE_XI2_MT) | |
| 149 int x = event->x(); | 146 int x = event->x(); |
| 150 int y = event->y(); | 147 int y = event->y(); |
| 151 | 148 |
| 152 if (!left_ && !right_ && !top_ && !bottom_) | 149 if (!left_ && !right_ && !top_ && !bottom_) |
| 153 return; | 150 return; |
| 154 | 151 |
| 155 const int resolution_x = bounds.width(); | 152 const int resolution_x = bounds.width(); |
| 156 const int resolution_y = bounds.height(); | 153 const int resolution_y = bounds.height(); |
| 157 // The "grace area" (10% in this case) is to make it easier for the user to | 154 // The "grace area" (10% in this case) is to make it easier for the user to |
| 158 // navigate to the corner. | 155 // navigate to the corner. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 y = (y * resolution_y) / (resolution_y - (bottom_ + top_)); | 187 y = (y * resolution_y) / (resolution_y - (bottom_ + top_)); |
| 191 } | 188 } |
| 192 | 189 |
| 193 // Set the modified coordinate back to the event. | 190 // Set the modified coordinate back to the event. |
| 194 if (event->root_location() == event->location()) { | 191 if (event->root_location() == event->location()) { |
| 195 // Usually those will be equal, | 192 // Usually those will be equal, |
| 196 // if not, I am not sure what the correct value should be. | 193 // if not, I am not sure what the correct value should be. |
| 197 event->set_root_location(gfx::Point(x, y)); | 194 event->set_root_location(gfx::Point(x, y)); |
| 198 } | 195 } |
| 199 event->set_location(gfx::Point(x, y)); | 196 event->set_location(gfx::Point(x, y)); |
| 200 #endif // defined(USE_XI2_MT) | |
| 201 } | 197 } |
| 202 | 198 |
| 203 private: | 199 private: |
| 204 // ui::PlatformEventObserver: | 200 // ui::PlatformEventObserver: |
| 205 void WillProcessEvent(const ui::PlatformEvent& event) override { | 201 void WillProcessEvent(const ui::PlatformEvent& event) override { |
| 206 #if defined(USE_XI2_MT) | |
| 207 if (event->type == GenericEvent && | 202 if (event->type == GenericEvent && |
| 208 (event->xgeneric.evtype == XI_TouchBegin || | 203 (event->xgeneric.evtype == XI_TouchBegin || |
| 209 event->xgeneric.evtype == XI_TouchUpdate || | 204 event->xgeneric.evtype == XI_TouchUpdate || |
| 210 event->xgeneric.evtype == XI_TouchEnd)) { | 205 event->xgeneric.evtype == XI_TouchEnd)) { |
| 211 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event->xcookie.data); | 206 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event->xcookie.data); |
| 212 xievent->event = xievent->root; | 207 xievent->event = xievent->root; |
| 213 xievent->event_x = xievent->root_x; | 208 xievent->event_x = xievent->root_x; |
| 214 xievent->event_y = xievent->root_y; | 209 xievent->event_y = xievent->root_y; |
| 215 } | 210 } |
| 216 #endif // defined(USE_XI2_MT) | |
| 217 } | 211 } |
| 218 | 212 |
| 219 void DidProcessEvent(const ui::PlatformEvent& event) override {} | 213 void DidProcessEvent(const ui::PlatformEvent& event) override {} |
| 220 | 214 |
| 221 // The difference in screen's native resolution pixels between | 215 // The difference in screen's native resolution pixels between |
| 222 // the border of the touchscreen and the border of the screen, | 216 // the border of the touchscreen and the border of the screen, |
| 223 // aka bezel sizes. | 217 // aka bezel sizes. |
| 224 int left_; | 218 int left_; |
| 225 int right_; | 219 int right_; |
| 226 int top_; | 220 int top_; |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 } | 687 } |
| 694 | 688 |
| 695 namespace test { | 689 namespace test { |
| 696 | 690 |
| 697 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { | 691 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { |
| 698 default_override_redirect = override_redirect; | 692 default_override_redirect = override_redirect; |
| 699 } | 693 } |
| 700 | 694 |
| 701 } // namespace test | 695 } // namespace test |
| 702 } // namespace aura | 696 } // namespace aura |
| OLD | NEW |