| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/test/event_generator.h" | 5 #include "ui/aura/test/event_generator.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 7 #include "ui/aura/event.h" | 8 #include "ui/aura/event.h" |
| 8 #include "ui/aura/root_window.h" | 9 #include "ui/aura/root_window.h" |
| 9 | 10 |
| 11 #if defined(USE_X11) |
| 12 #include <X11/Xlib.h> |
| 13 #include "ui/base/x/x11_util.h" |
| 14 #endif |
| 15 |
| 10 namespace { | 16 namespace { |
| 11 | 17 |
| 12 gfx::Point CenterOfWindowInRootWindowCoordinate(aura::Window* window) { | 18 gfx::Point CenterOfWindowInRootWindowCoordinate(aura::Window* window) { |
| 13 gfx::Point center = window->bounds().CenterPoint(); | 19 gfx::Point center = window->bounds().CenterPoint(); |
| 14 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); | 20 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); |
| 15 aura::Window::ConvertPointToWindow(window->parent(), root_window, ¢er); | 21 aura::Window::ConvertPointToWindow(window->parent(), root_window, ¢er); |
| 16 return center; | 22 return center; |
| 17 } | 23 } |
| 18 | 24 |
| 19 } // namespace | 25 } // namespace |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 89 } |
| 84 current_location_ = point; | 90 current_location_ = point; |
| 85 } | 91 } |
| 86 | 92 |
| 87 void EventGenerator::DragMouseTo(const gfx::Point& point) { | 93 void EventGenerator::DragMouseTo(const gfx::Point& point) { |
| 88 PressLeftButton(); | 94 PressLeftButton(); |
| 89 MoveMouseTo(point); | 95 MoveMouseTo(point); |
| 90 ReleaseLeftButton(); | 96 ReleaseLeftButton(); |
| 91 } | 97 } |
| 92 | 98 |
| 99 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { |
| 100 DispatchKeyEvent(true, key_code, flags); |
| 101 } |
| 102 |
| 103 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { |
| 104 DispatchKeyEvent(false, key_code, flags); |
| 105 } |
| 106 |
| 93 void EventGenerator::Dispatch(Event& event) { | 107 void EventGenerator::Dispatch(Event& event) { |
| 94 switch (event.type()) { | 108 switch (event.type()) { |
| 95 case ui::ET_KEY_PRESSED: | 109 case ui::ET_KEY_PRESSED: |
| 96 case ui::ET_KEY_RELEASED: | 110 case ui::ET_KEY_RELEASED: |
| 97 aura::RootWindow::GetInstance()->DispatchKeyEvent( | 111 aura::RootWindow::GetInstance()->DispatchKeyEvent( |
| 98 static_cast<KeyEvent*>(&event)); | 112 static_cast<KeyEvent*>(&event)); |
| 99 break; | 113 break; |
| 100 case ui::ET_MOUSE_PRESSED: | 114 case ui::ET_MOUSE_PRESSED: |
| 101 case ui::ET_MOUSE_DRAGGED: | 115 case ui::ET_MOUSE_DRAGGED: |
| 102 case ui::ET_MOUSE_RELEASED: | 116 case ui::ET_MOUSE_RELEASED: |
| 103 case ui::ET_MOUSE_MOVED: | 117 case ui::ET_MOUSE_MOVED: |
| 104 case ui::ET_MOUSE_ENTERED: | 118 case ui::ET_MOUSE_ENTERED: |
| 105 case ui::ET_MOUSE_EXITED: | 119 case ui::ET_MOUSE_EXITED: |
| 106 case ui::ET_MOUSEWHEEL: | 120 case ui::ET_MOUSEWHEEL: |
| 107 aura::RootWindow::GetInstance()->DispatchMouseEvent( | 121 aura::RootWindow::GetInstance()->DispatchMouseEvent( |
| 108 static_cast<MouseEvent*>(&event)); | 122 static_cast<MouseEvent*>(&event)); |
| 109 break; | 123 break; |
| 110 default: | 124 default: |
| 111 NOTIMPLEMENTED(); | 125 NOTIMPLEMENTED(); |
| 112 break; | 126 break; |
| 113 } | 127 } |
| 114 } | 128 } |
| 115 | 129 |
| 130 void EventGenerator::DispatchKeyEvent(bool is_press, |
| 131 ui::KeyboardCode key_code, |
| 132 int flags) { |
| 133 #if defined(OS_WIN) |
| 134 MSG native_event = |
| 135 { NULL, (is_press ? WM_KEYDOWN : WM_KEYUP), key_code, flags }; |
| 136 KeyEvent keyev(native_event, false /* is_char */); |
| 137 #else |
| 138 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; |
| 139 #if defined(USE_X11) |
| 140 scoped_ptr<XEvent> native_event(new XEvent); |
| 141 ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get()); |
| 142 KeyEvent keyev(native_event.get(), false); |
| 143 #else |
| 144 KeyEvent keyev(type, key_code, flags); |
| 145 #endif // USE_X11 |
| 146 #endif // OS_WIN |
| 147 Dispatch(keyev); |
| 148 } |
| 149 |
| 116 void EventGenerator::MoveMouseToCenterOf(Window* window) { | 150 void EventGenerator::MoveMouseToCenterOf(Window* window) { |
| 117 MoveMouseTo(CenterOfWindowInRootWindowCoordinate(window)); | 151 MoveMouseTo(CenterOfWindowInRootWindowCoordinate(window)); |
| 118 } | 152 } |
| 119 | 153 |
| 120 } // namespace test | 154 } // namespace test |
| 121 } // namespace aura | 155 } // namespace aura |
| OLD | NEW |