| 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> |
| 11 #include <X11/XKBlib.h> | 11 #include <X11/XKBlib.h> |
| 12 | 12 |
| 13 // Generically-named #defines from Xlib that conflict with symbols in GTest. | 13 // Generically-named #defines from Xlib that conflict with symbols in GTest. |
| 14 #undef Bool | 14 #undef Bool |
| 15 #undef None | 15 #undef None |
| 16 | 16 |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 20 #include "ui/events/event_constants.h" | 20 #include "ui/events/event_constants.h" |
| 21 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
| 22 #include "ui/events/platform/platform_event_builder.h" |
| 22 #include "ui/events/test/events_test_utils.h" | 23 #include "ui/events/test/events_test_utils.h" |
| 23 #include "ui/events/test/events_test_utils_x11.h" | 24 #include "ui/events/test/events_test_utils_x11.h" |
| 24 #include "ui/events/x/device_data_manager_x11.h" | 25 #include "ui/events/x/device_data_manager_x11.h" |
| 25 #include "ui/events/x/touch_factory_x11.h" | 26 #include "ui/events/x/touch_factory_x11.h" |
| 26 #include "ui/gfx/point.h" | 27 #include "ui/gfx/point.h" |
| 27 | 28 |
| 28 namespace ui { | 29 namespace ui { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 66 } |
| 66 | 67 |
| 67 // Returns true if the keysym maps to a KeyEvent with the EF_FUNCTION_KEY | 68 // Returns true if the keysym maps to a KeyEvent with the EF_FUNCTION_KEY |
| 68 // flag set, or the keysym maps to a zero key code. | 69 // flag set, or the keysym maps to a zero key code. |
| 69 bool HasFunctionKeyFlagSetIfSupported(Display* display, int x_keysym) { | 70 bool HasFunctionKeyFlagSetIfSupported(Display* display, int x_keysym) { |
| 70 XEvent event; | 71 XEvent event; |
| 71 int x_keycode = XKeysymToKeycode(display, x_keysym); | 72 int x_keycode = XKeysymToKeycode(display, x_keysym); |
| 72 // Exclude keysyms for which the server has no corresponding keycode. | 73 // Exclude keysyms for which the server has no corresponding keycode. |
| 73 if (x_keycode) { | 74 if (x_keycode) { |
| 74 InitKeyEvent(display, &event, true, x_keycode, 0); | 75 InitKeyEvent(display, &event, true, x_keycode, 0); |
| 75 ui::KeyEvent ui_key_event(&event); | 76 ui::KeyEvent ui_key_event = PlatformEventBuilder::BuildKeyEvent(&event); |
| 76 return (ui_key_event.flags() & ui::EF_FUNCTION_KEY); | 77 return (ui_key_event.flags() & ui::EF_FUNCTION_KEY); |
| 77 } | 78 } |
| 78 return true; | 79 return true; |
| 79 } | 80 } |
| 80 | 81 |
| 81 } // namespace | 82 } // namespace |
| 82 | 83 |
| 83 class EventsXTest : public testing::Test { | 84 class EventsXTest : public testing::Test { |
| 84 public: | 85 public: |
| 85 EventsXTest() {} | 86 EventsXTest() {} |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 EXPECT_EQ("230,240", ui::EventSystemLocationFromNative(&event).ToString()); | 195 EXPECT_EQ("230,240", ui::EventSystemLocationFromNative(&event).ToString()); |
| 195 } | 196 } |
| 196 | 197 |
| 197 TEST_F(EventsXTest, ClickCount) { | 198 TEST_F(EventsXTest, ClickCount) { |
| 198 XEvent event; | 199 XEvent event; |
| 199 gfx::Point location(5, 10); | 200 gfx::Point location(5, 10); |
| 200 | 201 |
| 201 for (int i = 1; i <= 3; ++i) { | 202 for (int i = 1; i <= 3; ++i) { |
| 202 InitButtonEvent(&event, true, location, 1, 0); | 203 InitButtonEvent(&event, true, location, 1, 0); |
| 203 { | 204 { |
| 204 MouseEvent mouseev(&event); | 205 MouseEvent mouseev = PlatformEventBuilder::BuildMouseEvent(&event); |
| 205 EXPECT_EQ(ui::ET_MOUSE_PRESSED, mouseev.type()); | 206 EXPECT_EQ(ui::ET_MOUSE_PRESSED, mouseev.type()); |
| 206 EXPECT_EQ(i, mouseev.GetClickCount()); | 207 EXPECT_EQ(i, mouseev.GetClickCount()); |
| 207 } | 208 } |
| 208 | 209 |
| 209 InitButtonEvent(&event, false, location, 1, 0); | 210 InitButtonEvent(&event, false, location, 1, 0); |
| 210 { | 211 { |
| 211 MouseEvent mouseev(&event); | 212 MouseEvent mouseev = PlatformEventBuilder::BuildMouseEvent(&event); |
| 212 EXPECT_EQ(ui::ET_MOUSE_RELEASED, mouseev.type()); | 213 EXPECT_EQ(ui::ET_MOUSE_RELEASED, mouseev.type()); |
| 213 EXPECT_EQ(i, mouseev.GetClickCount()); | 214 EXPECT_EQ(i, mouseev.GetClickCount()); |
| 214 } | 215 } |
| 215 } | 216 } |
| 216 } | 217 } |
| 217 | 218 |
| 218 #if defined(USE_XI2_MT) | 219 #if defined(USE_XI2_MT) |
| 219 TEST_F(EventsXTest, TouchEventBasic) { | 220 TEST_F(EventsXTest, TouchEventBasic) { |
| 220 std::vector<unsigned int> devices; | 221 std::vector<unsigned int> devices; |
| 221 devices.push_back(0); | 222 devices.push_back(0); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 { false, XK_A }, | 450 { false, XK_A }, |
| 450 }; | 451 }; |
| 451 | 452 |
| 452 for (size_t k = 0; k < arraysize(keys); ++k) { | 453 for (size_t k = 0; k < arraysize(keys); ++k) { |
| 453 int x_keycode = XKeysymToKeycode(display, keys[k].x_keysym); | 454 int x_keycode = XKeysymToKeycode(display, keys[k].x_keysym); |
| 454 // Exclude keysyms for which the server has no corresponding keycode. | 455 // Exclude keysyms for which the server has no corresponding keycode. |
| 455 if (x_keycode) { | 456 if (x_keycode) { |
| 456 InitKeyEvent(display, &event, true, x_keycode, 0); | 457 InitKeyEvent(display, &event, true, x_keycode, 0); |
| 457 // int keysym = XLookupKeysym(&event.xkey, 0); | 458 // int keysym = XLookupKeysym(&event.xkey, 0); |
| 458 // if (keysym) { | 459 // if (keysym) { |
| 459 ui::KeyEvent ui_key_event(&event); | 460 ui::KeyEvent ui_key_event = PlatformEventBuilder::BuildKeyEvent(&event); |
| 460 EXPECT_EQ(keys[k].is_numpad_key ? ui::EF_NUMPAD_KEY : 0, | 461 EXPECT_EQ(keys[k].is_numpad_key ? ui::EF_NUMPAD_KEY : 0, |
| 461 ui_key_event.flags() & ui::EF_NUMPAD_KEY); | 462 ui_key_event.flags() & ui::EF_NUMPAD_KEY); |
| 462 } | 463 } |
| 463 } | 464 } |
| 464 } | 465 } |
| 465 | 466 |
| 466 TEST_F(EventsXTest, FunctionKeyEvents) { | 467 TEST_F(EventsXTest, FunctionKeyEvents) { |
| 467 Display* display = gfx::GetXDisplay(); | 468 Display* display = gfx::GetXDisplay(); |
| 468 | 469 |
| 469 // Min function key code minus 1. | 470 // Min function key code minus 1. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 Display* display = gfx::GetXDisplay(); | 605 Display* display = gfx::GetXDisplay(); |
| 605 | 606 |
| 606 unsigned int state_to_be_fabricated[] = { | 607 unsigned int state_to_be_fabricated[] = { |
| 607 0, ShiftMask, LockMask, ShiftMask | LockMask, | 608 0, ShiftMask, LockMask, ShiftMask | LockMask, |
| 608 }; | 609 }; |
| 609 for (size_t i = 0; i < arraysize(state_to_be_fabricated); ++i) { | 610 for (size_t i = 0; i < arraysize(state_to_be_fabricated); ++i) { |
| 610 unsigned int state = state_to_be_fabricated[i]; | 611 unsigned int state = state_to_be_fabricated[i]; |
| 611 for (int is_char = 0; is_char < 2; ++is_char) { | 612 for (int is_char = 0; is_char < 2; ++is_char) { |
| 612 XEvent x_event; | 613 XEvent x_event; |
| 613 InitKeyEvent(display, &x_event, true, 0, state); | 614 InitKeyEvent(display, &x_event, true, 0, state); |
| 614 ui::KeyEvent key_event(&x_event); | 615 ui::KeyEvent key_event = PlatformEventBuilder::BuildKeyEvent(&x_event); |
| 615 if (is_char) { | 616 if (is_char) { |
| 616 KeyEventTestApi test_event(&key_event); | 617 KeyEventTestApi test_event(&key_event); |
| 617 test_event.set_is_char(true); | 618 test_event.set_is_char(true); |
| 618 } | 619 } |
| 619 EXPECT_TRUE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); | 620 EXPECT_TRUE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); |
| 620 } | 621 } |
| 621 } | 622 } |
| 622 | 623 |
| 623 unsigned int state_to_be_not_fabricated[] = { | 624 unsigned int state_to_be_not_fabricated[] = { |
| 624 ControlMask, Mod1Mask, Mod2Mask, ShiftMask | ControlMask, | 625 ControlMask, Mod1Mask, Mod2Mask, ShiftMask | ControlMask, |
| 625 }; | 626 }; |
| 626 for (size_t i = 0; i < arraysize(state_to_be_not_fabricated); ++i) { | 627 for (size_t i = 0; i < arraysize(state_to_be_not_fabricated); ++i) { |
| 627 unsigned int state = state_to_be_not_fabricated[i]; | 628 unsigned int state = state_to_be_not_fabricated[i]; |
| 628 for (int is_char = 0; is_char < 2; ++is_char) { | 629 for (int is_char = 0; is_char < 2; ++is_char) { |
| 629 XEvent x_event; | 630 XEvent x_event; |
| 630 InitKeyEvent(display, &x_event, true, 0, state); | 631 InitKeyEvent(display, &x_event, true, 0, state); |
| 631 ui::KeyEvent key_event(&x_event); | 632 ui::KeyEvent key_event = PlatformEventBuilder::BuildKeyEvent(&x_event); |
| 632 if (is_char) { | 633 if (is_char) { |
| 633 KeyEventTestApi test_event(&key_event); | 634 KeyEventTestApi test_event(&key_event); |
| 634 test_event.set_is_char(true); | 635 test_event.set_is_char(true); |
| 635 } | 636 } |
| 636 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); | 637 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); |
| 637 } | 638 } |
| 638 } | 639 } |
| 639 } | 640 } |
| 640 #endif | 641 #endif |
| 641 | 642 |
| 642 } // namespace ui | 643 } // namespace ui |
| OLD | NEW |