| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/test/event_generator.h" | 5 #include "ui/events/test/event_generator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 namespace ui { | 27 namespace ui { |
| 28 namespace test { | 28 namespace test { |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 void DummyCallback(EventType, const gfx::Vector2dF&) { | 31 void DummyCallback(EventType, const gfx::Vector2dF&) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 class TestKeyEvent : public ui::KeyEvent { | 34 class TestKeyEvent : public ui::KeyEvent { |
| 35 public: | 35 public: |
| 36 TestKeyEvent(const base::NativeEvent& native_event, int flags, bool is_char) | 36 TestKeyEvent(const base::NativeEvent& native_event, int flags) |
| 37 : KeyEvent(native_event, is_char) { | 37 : KeyEvent(native_event) { |
| 38 set_flags(flags); | 38 set_flags(flags); |
| 39 } | 39 } |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class TestTouchEvent : public ui::TouchEvent { | 42 class TestTouchEvent : public ui::TouchEvent { |
| 43 public: | 43 public: |
| 44 TestTouchEvent(ui::EventType type, | 44 TestTouchEvent(ui::EventType type, |
| 45 const gfx::Point& root_location, | 45 const gfx::Point& root_location, |
| 46 int touch_id, | 46 int touch_id, |
| 47 int flags, | 47 int flags, |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 } | 495 } |
| 496 | 496 |
| 497 void EventGenerator::DispatchKeyEvent(bool is_press, | 497 void EventGenerator::DispatchKeyEvent(bool is_press, |
| 498 ui::KeyboardCode key_code, | 498 ui::KeyboardCode key_code, |
| 499 int flags) { | 499 int flags) { |
| 500 #if defined(OS_WIN) | 500 #if defined(OS_WIN) |
| 501 UINT key_press = WM_KEYDOWN; | 501 UINT key_press = WM_KEYDOWN; |
| 502 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags); | 502 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags); |
| 503 if (is_press && character) { | 503 if (is_press && character) { |
| 504 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; | 504 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; |
| 505 TestKeyEvent keyev(native_event, flags, false); | 505 TestKeyEvent keyev(native_event, flags); |
| 506 Dispatch(&keyev); | 506 Dispatch(&keyev); |
| 507 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character | 507 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character |
| 508 // if the key event cooresponds to a real character. | 508 // if the key event cooresponds to a real character. |
| 509 key_press = WM_CHAR; | 509 key_press = WM_CHAR; |
| 510 key_code = static_cast<ui::KeyboardCode>(character); | 510 key_code = static_cast<ui::KeyboardCode>(character); |
| 511 } | 511 } |
| 512 MSG native_event = | 512 MSG native_event = |
| 513 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; | 513 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; |
| 514 TestKeyEvent keyev(native_event, flags, key_press == WM_CHAR); | 514 TestKeyEvent keyev(native_event, flags); |
| 515 #elif defined(USE_X11) | 515 #elif defined(USE_X11) |
| 516 ui::ScopedXI2Event xevent; | 516 ui::ScopedXI2Event xevent; |
| 517 xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, | 517 xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, |
| 518 key_code, | 518 key_code, |
| 519 flags); | 519 flags); |
| 520 ui::KeyEvent keyev(xevent, false); | 520 ui::KeyEvent keyev(xevent); |
| 521 #else | 521 #else |
| 522 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; | 522 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; |
| 523 ui::KeyEvent keyev(type, key_code, flags, false); | 523 ui::KeyEvent keyev(type, key_code, flags); |
| 524 #endif // OS_WIN | 524 #endif // OS_WIN |
| 525 Dispatch(&keyev); | 525 Dispatch(&keyev); |
| 526 } | 526 } |
| 527 | 527 |
| 528 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { | 528 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { |
| 529 current_target_ = delegate_->GetTargetAt(point); | 529 current_target_ = delegate_->GetTargetAt(point); |
| 530 } | 530 } |
| 531 | 531 |
| 532 void EventGenerator::PressButton(int flag) { | 532 void EventGenerator::PressButton(int flag) { |
| 533 if (!(flags_ & flag)) { | 533 if (!(flags_ & flag)) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 if (!pending_events_.empty()) { | 602 if (!pending_events_.empty()) { |
| 603 base::MessageLoopProxy::current()->PostTask( | 603 base::MessageLoopProxy::current()->PostTask( |
| 604 FROM_HERE, | 604 FROM_HERE, |
| 605 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 605 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
| 606 base::Unretained(this))); | 606 base::Unretained(this))); |
| 607 } | 607 } |
| 608 } | 608 } |
| 609 | 609 |
| 610 } // namespace test | 610 } // namespace test |
| 611 } // namespace ui | 611 } // namespace ui |
| OLD | NEW |