Chromium Code Reviews| 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 <cstring> | 5 #include <cstring> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 #include <X11/Xutil.h> | 10 #include <X11/Xutil.h> |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 50)); | 282 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 50)); |
| 283 scoped_xevent.InitTouchEvent( | 283 scoped_xevent.InitTouchEvent( |
| 284 0, XI_TouchEnd, 6, gfx::Point(200, 200), valuators); | 284 0, XI_TouchEnd, 6, gfx::Point(200, 200), valuators); |
| 285 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); | 285 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); |
| 286 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); | 286 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); |
| 287 EXPECT_EQ(GetTouchId(scoped_xevent), 1); | 287 EXPECT_EQ(GetTouchId(scoped_xevent), 1); |
| 288 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 25); | 288 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 25); |
| 289 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); | 289 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); |
| 290 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); | 290 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); |
| 291 } | 291 } |
| 292 | |
| 293 int GetTouchIdForTrackingId(uint32 tracking_id) { | |
| 294 int slot = 0; | |
| 295 bool success = | |
| 296 TouchFactory::GetInstance()->QuerySlotForTrackingID(tracking_id, &slot); | |
| 297 if (success) | |
| 298 return slot; | |
| 299 return -1; | |
| 300 } | |
| 301 | |
| 302 TEST_F(EventsXTest, TouchEventIdRefcounting) { | |
| 303 std::vector<unsigned int> devices; | |
| 304 devices.push_back(0); | |
| 305 ui::SetUpTouchDevicesForTest(devices); | |
| 306 std::vector<Valuator> valuators; | |
| 307 | |
| 308 ui::ScopedXI2Event scoped_xevent0; | |
| 309 ui::ScopedXI2Event scoped_xevent1; | |
| 310 ui::ScopedXI2Event scoped_xevent2; | |
| 311 | |
| 312 const int kTrackingId0 = 5; | |
| 313 const int kTrackingId1 = 7; | |
| 314 | |
| 315 // Increment ref count once for first touch. | |
| 316 scoped_xevent0.InitTouchEvent( | |
| 317 0, XI_TouchBegin, kTrackingId0, gfx::Point(10, 10), valuators); | |
| 318 GetTouchId(scoped_xevent0); | |
| 319 IncrementTouchIdRefCount(scoped_xevent0); | |
|
sadrul
2014/07/22 21:23:20
Instead of calling GetTouchId()/IncrementTouchIdRe
tdresser
2014/07/23 15:15:50
Done.
| |
| 320 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId0)); | |
| 321 | |
| 322 // Increment ref count 4 times for second touch. | |
| 323 scoped_xevent1.InitTouchEvent( | |
| 324 0, XI_TouchBegin, kTrackingId1, gfx::Point(10, 10), valuators); | |
| 325 | |
| 326 for (int i = 0; i < 4; ++i) { | |
| 327 GetTouchId(scoped_xevent1); | |
| 328 IncrementTouchIdRefCount(scoped_xevent1); | |
| 329 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1)); | |
| 330 } | |
| 331 | |
| 332 // Decrement ref count 3 times for second touch. | |
| 333 scoped_xevent1.InitTouchEvent( | |
| 334 0, XI_TouchEnd, kTrackingId1, gfx::Point(10, 10), valuators); | |
| 335 | |
| 336 for (int i = 0; i < 3; ++i) { | |
| 337 ClearTouchIdIfReleased(scoped_xevent1); | |
| 338 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1)); | |
| 339 } | |
| 340 | |
| 341 // This should clear the touch id of the second touch. | |
| 342 ClearTouchIdIfReleased(scoped_xevent1); | |
| 343 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId1)); | |
| 344 | |
| 345 // This should clear the touch id of the first touch. | |
| 346 scoped_xevent0.InitTouchEvent( | |
| 347 0, XI_TouchEnd, kTrackingId0, gfx::Point(10, 10), valuators); | |
| 348 | |
| 349 ClearTouchIdIfReleased(scoped_xevent0); | |
| 350 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId0)); | |
| 351 } | |
| 292 #endif | 352 #endif |
| 293 | 353 |
| 294 TEST_F(EventsXTest, NumpadKeyEvents) { | 354 TEST_F(EventsXTest, NumpadKeyEvents) { |
| 295 XEvent event; | 355 XEvent event; |
| 296 Display* display = gfx::GetXDisplay(); | 356 Display* display = gfx::GetXDisplay(); |
| 297 | 357 |
| 298 struct { | 358 struct { |
| 299 bool is_numpad_key; | 359 bool is_numpad_key; |
| 300 int x_keysym; | 360 int x_keysym; |
| 301 } keys[] = { | 361 } keys[] = { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 XEvent x_event; | 593 XEvent x_event; |
| 534 InitKeyEvent(display, &x_event, true, 0, state); | 594 InitKeyEvent(display, &x_event, true, 0, state); |
| 535 ui::KeyEvent key_event(&x_event, is_char); | 595 ui::KeyEvent key_event(&x_event, is_char); |
| 536 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); | 596 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); |
| 537 } | 597 } |
| 538 } | 598 } |
| 539 } | 599 } |
| 540 #endif | 600 #endif |
| 541 | 601 |
| 542 } // namespace ui | 602 } // namespace ui |
| OLD | NEW |