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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 118 |
113 current_location_ = point; | 119 current_location_ = point; |
114 | 120 |
115 ReleaseTouch(); | 121 ReleaseTouch(); |
116 } | 122 } |
117 | 123 |
118 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { | 124 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { |
119 PressMoveAndReleaseTouchTo(CenterOfWindowInRootWindowCoordinate(window)); | 125 PressMoveAndReleaseTouchTo(CenterOfWindowInRootWindowCoordinate(window)); |
120 } | 126 } |
121 | 127 |
| 128 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { |
| 129 DispatchKeyEvent(true, key_code, flags); |
| 130 } |
| 131 |
| 132 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { |
| 133 DispatchKeyEvent(false, key_code, flags); |
| 134 } |
| 135 |
122 void EventGenerator::Dispatch(Event& event) { | 136 void EventGenerator::Dispatch(Event& event) { |
123 switch (event.type()) { | 137 switch (event.type()) { |
124 case ui::ET_KEY_PRESSED: | 138 case ui::ET_KEY_PRESSED: |
125 case ui::ET_KEY_RELEASED: | 139 case ui::ET_KEY_RELEASED: |
126 aura::RootWindow::GetInstance()->DispatchKeyEvent( | 140 aura::RootWindow::GetInstance()->DispatchKeyEvent( |
127 static_cast<KeyEvent*>(&event)); | 141 static_cast<KeyEvent*>(&event)); |
128 break; | 142 break; |
129 case ui::ET_MOUSE_PRESSED: | 143 case ui::ET_MOUSE_PRESSED: |
130 case ui::ET_MOUSE_DRAGGED: | 144 case ui::ET_MOUSE_DRAGGED: |
131 case ui::ET_MOUSE_RELEASED: | 145 case ui::ET_MOUSE_RELEASED: |
(...skipping 11 matching lines...) Expand all Loading... |
143 case ui::ET_TOUCH_CANCELLED: | 157 case ui::ET_TOUCH_CANCELLED: |
144 aura::RootWindow::GetInstance()->DispatchTouchEvent( | 158 aura::RootWindow::GetInstance()->DispatchTouchEvent( |
145 static_cast<TouchEvent*>(&event)); | 159 static_cast<TouchEvent*>(&event)); |
146 break; | 160 break; |
147 default: | 161 default: |
148 NOTIMPLEMENTED(); | 162 NOTIMPLEMENTED(); |
149 break; | 163 break; |
150 } | 164 } |
151 } | 165 } |
152 | 166 |
| 167 void EventGenerator::DispatchKeyEvent(bool is_press, |
| 168 ui::KeyboardCode key_code, |
| 169 int flags) { |
| 170 #if defined(OS_WIN) |
| 171 MSG native_event = |
| 172 { NULL, (is_press ? WM_KEYDOWN : WM_KEYUP), key_code, flags }; |
| 173 KeyEvent keyev(native_event, false /* is_char */); |
| 174 #else |
| 175 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; |
| 176 #if defined(USE_X11) |
| 177 scoped_ptr<XEvent> native_event(new XEvent); |
| 178 ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get()); |
| 179 KeyEvent keyev(native_event.get(), false); |
| 180 #else |
| 181 KeyEvent keyev(type, key_code, flags); |
| 182 #endif // USE_X11 |
| 183 #endif // OS_WIN |
| 184 Dispatch(keyev); |
| 185 } |
| 186 |
153 } // namespace test | 187 } // namespace test |
154 } // namespace aura | 188 } // namespace aura |
OLD | NEW |