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 "ui/aura/test/event_generator.h" | 5 #include "ui/aura/test/event_generator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop_proxy.h" | |
| 8 #include "ui/aura/client/screen_position_client.h" | 10 #include "ui/aura/client/screen_position_client.h" |
| 9 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
| 10 #include "ui/base/events/event.h" | 12 #include "ui/base/events/event.h" |
| 11 #include "ui/base/events/event_utils.h" | 13 #include "ui/base/events/event_utils.h" |
| 12 #include "ui/gfx/vector2d_conversions.h" | 14 #include "ui/gfx/vector2d_conversions.h" |
| 13 | 15 |
| 14 #if defined(USE_X11) | 16 #if defined(USE_X11) |
| 15 #include <X11/Xlib.h> | 17 #include <X11/Xlib.h> |
| 16 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" |
| 17 #endif | 19 #endif |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; | 72 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; |
| 71 | 73 |
| 72 } // namespace | 74 } // namespace |
| 73 | 75 |
| 74 EventGenerator::EventGenerator(RootWindow* root_window) | 76 EventGenerator::EventGenerator(RootWindow* root_window) |
| 75 : delegate_(new DefaultEventGeneratorDelegate(root_window)), | 77 : delegate_(new DefaultEventGeneratorDelegate(root_window)), |
| 76 current_root_window_(delegate_->GetRootWindowAt(current_location_)), | 78 current_root_window_(delegate_->GetRootWindowAt(current_location_)), |
| 77 flags_(0), | 79 flags_(0), |
| 78 grab_(false) { | 80 grab_(false), |
| 81 post_events_(false) { | |
| 79 } | 82 } |
| 80 | 83 |
| 81 EventGenerator::EventGenerator(RootWindow* root_window, const gfx::Point& point) | 84 EventGenerator::EventGenerator(RootWindow* root_window, const gfx::Point& point) |
| 82 : delegate_(new DefaultEventGeneratorDelegate(root_window)), | 85 : delegate_(new DefaultEventGeneratorDelegate(root_window)), |
| 83 current_location_(point), | 86 current_location_(point), |
| 84 current_root_window_(delegate_->GetRootWindowAt(current_location_)), | 87 current_root_window_(delegate_->GetRootWindowAt(current_location_)), |
| 85 flags_(0), | 88 flags_(0), |
| 86 grab_(false) { | 89 grab_(false), |
| 90 post_events_(false) { | |
| 87 } | 91 } |
| 88 | 92 |
| 89 EventGenerator::EventGenerator(RootWindow* root_window, Window* window) | 93 EventGenerator::EventGenerator(RootWindow* root_window, Window* window) |
| 90 : delegate_(new DefaultEventGeneratorDelegate(root_window)), | 94 : delegate_(new DefaultEventGeneratorDelegate(root_window)), |
| 91 current_location_(CenterOfWindow(window)), | 95 current_location_(CenterOfWindow(window)), |
| 92 current_root_window_(delegate_->GetRootWindowAt(current_location_)), | 96 current_root_window_(delegate_->GetRootWindowAt(current_location_)), |
| 93 flags_(0), | 97 flags_(0), |
| 94 grab_(false) { | 98 grab_(false), |
| 99 post_events_(false) { | |
| 95 } | 100 } |
| 96 | 101 |
| 97 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) | 102 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) |
| 98 : delegate_(delegate), | 103 : delegate_(delegate), |
| 99 current_root_window_(delegate_->GetRootWindowAt(current_location_)), | 104 current_root_window_(delegate_->GetRootWindowAt(current_location_)), |
| 100 flags_(0), | 105 flags_(0), |
| 101 grab_(false) { | 106 grab_(false), |
| 107 post_events_(false) { | |
| 102 } | 108 } |
| 103 | 109 |
| 104 EventGenerator::~EventGenerator() { | 110 EventGenerator::~EventGenerator() { |
| 105 } | 111 } |
| 106 | 112 |
| 107 void EventGenerator::PressLeftButton() { | 113 void EventGenerator::PressLeftButton() { |
| 108 PressButton(ui::EF_LEFT_MOUSE_BUTTON); | 114 PressButton(ui::EF_LEFT_MOUSE_BUTTON); |
| 109 } | 115 } |
| 110 | 116 |
| 111 void EventGenerator::ReleaseLeftButton() { | 117 void EventGenerator::ReleaseLeftButton() { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 139 | 145 |
| 140 gfx::Vector2dF diff(point - current_location_); | 146 gfx::Vector2dF diff(point - current_location_); |
| 141 for (float i = 1; i <= count; i++) { | 147 for (float i = 1; i <= count; i++) { |
| 142 gfx::Vector2dF step(diff); | 148 gfx::Vector2dF step(diff); |
| 143 step.Scale(i / count); | 149 step.Scale(i / count); |
| 144 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); | 150 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); |
| 145 if (!grab_) | 151 if (!grab_) |
| 146 UpdateCurrentRootWindow(move_point); | 152 UpdateCurrentRootWindow(move_point); |
| 147 ConvertPointToTarget(current_root_window_, &move_point); | 153 ConvertPointToTarget(current_root_window_, &move_point); |
| 148 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_); | 154 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_); |
| 149 Dispatch(mouseev); | 155 DispatchMouseEvent(mouseev); |
| 150 } | 156 } |
| 151 current_location_ = point; | 157 current_location_ = point; |
| 152 } | 158 } |
| 153 | 159 |
| 154 void EventGenerator::MoveMouseRelativeTo(const Window* window, | 160 void EventGenerator::MoveMouseRelativeTo(const Window* window, |
| 155 const gfx::Point& point_in_parent) { | 161 const gfx::Point& point_in_parent) { |
| 156 gfx::Point point(point_in_parent); | 162 gfx::Point point(point_in_parent); |
| 157 ConvertPointFromTarget(window, &point); | 163 ConvertPointFromTarget(window, &point); |
| 158 MoveMouseTo(point); | 164 MoveMouseTo(point); |
| 159 } | 165 } |
| 160 | 166 |
| 161 void EventGenerator::DragMouseTo(const gfx::Point& point) { | 167 void EventGenerator::DragMouseTo(const gfx::Point& point) { |
| 162 PressLeftButton(); | 168 PressLeftButton(); |
| 163 MoveMouseTo(point); | 169 MoveMouseTo(point); |
| 164 ReleaseLeftButton(); | 170 ReleaseLeftButton(); |
| 165 } | 171 } |
| 166 | 172 |
| 167 void EventGenerator::MoveMouseToCenterOf(Window* window) { | 173 void EventGenerator::MoveMouseToCenterOf(Window* window) { |
| 168 MoveMouseTo(CenterOfWindow(window)); | 174 MoveMouseTo(CenterOfWindow(window)); |
| 169 } | 175 } |
| 170 | 176 |
| 171 void EventGenerator::PressTouch() { | 177 void EventGenerator::PressTouch() { |
| 172 TestTouchEvent touchev( | 178 TestTouchEvent touchev( |
| 173 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), flags_); | 179 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), flags_); |
| 174 Dispatch(touchev); | 180 DispatchTouchEvent(touchev); |
| 175 } | 181 } |
| 176 | 182 |
| 177 void EventGenerator::MoveTouch(const gfx::Point& point) { | 183 void EventGenerator::MoveTouch(const gfx::Point& point) { |
| 178 TestTouchEvent touchev(ui::ET_TOUCH_MOVED, point, flags_); | 184 TestTouchEvent touchev(ui::ET_TOUCH_MOVED, point, flags_); |
| 179 Dispatch(touchev); | 185 DispatchTouchEvent(touchev); |
| 180 | 186 |
| 181 current_location_ = point; | 187 current_location_ = point; |
| 182 if (!grab_) | 188 if (!grab_) |
| 183 UpdateCurrentRootWindow(point); | 189 UpdateCurrentRootWindow(point); |
| 184 } | 190 } |
| 185 | 191 |
| 186 void EventGenerator::ReleaseTouch() { | 192 void EventGenerator::ReleaseTouch() { |
| 187 TestTouchEvent touchev( | 193 TestTouchEvent touchev( |
| 188 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), flags_); | 194 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), flags_); |
| 189 Dispatch(touchev); | 195 DispatchTouchEvent(touchev); |
| 190 } | 196 } |
| 191 | 197 |
| 192 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { | 198 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { |
| 193 PressTouch(); | 199 PressTouch(); |
| 194 MoveTouch(point); | 200 MoveTouch(point); |
| 195 ReleaseTouch(); | 201 ReleaseTouch(); |
| 196 } | 202 } |
| 197 | 203 |
| 198 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { | 204 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { |
| 199 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); | 205 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); |
| 200 } | 206 } |
| 201 | 207 |
| 202 void EventGenerator::GestureTapAt(const gfx::Point& location) { | 208 void EventGenerator::GestureTapAt(const gfx::Point& location) { |
| 203 const int kTouchId = 2; | 209 const int kTouchId = 2; |
| 204 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 210 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
| 205 location, | 211 location, |
| 206 kTouchId, | 212 kTouchId, |
| 207 ui::EventTimeForNow()); | 213 ui::EventTimeForNow()); |
| 208 Dispatch(press); | 214 DispatchTouchEvent(press); |
| 209 | 215 |
| 210 ui::TouchEvent release( | 216 ui::TouchEvent release( |
| 211 ui::ET_TOUCH_RELEASED, location, kTouchId, | 217 ui::ET_TOUCH_RELEASED, location, kTouchId, |
| 212 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); | 218 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); |
| 213 Dispatch(release); | 219 DispatchTouchEvent(release); |
| 214 } | 220 } |
| 215 | 221 |
| 216 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { | 222 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { |
| 217 const int kTouchId = 3; | 223 const int kTouchId = 3; |
| 218 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 224 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
| 219 location, | 225 location, |
| 220 kTouchId, | 226 kTouchId, |
| 221 ui::EventTimeForNow()); | 227 ui::EventTimeForNow()); |
| 222 Dispatch(press); | 228 DispatchTouchEvent(press); |
| 223 | 229 |
| 224 ui::TouchEvent release( | 230 ui::TouchEvent release( |
| 225 ui::ET_TOUCH_RELEASED, location, kTouchId, | 231 ui::ET_TOUCH_RELEASED, location, kTouchId, |
| 226 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); | 232 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); |
| 227 Dispatch(release); | 233 DispatchTouchEvent(release); |
| 228 } | 234 } |
| 229 | 235 |
| 230 void EventGenerator::GestureScrollSequence(const gfx::Point& start, | 236 void EventGenerator::GestureScrollSequence(const gfx::Point& start, |
| 231 const gfx::Point& end, | 237 const gfx::Point& end, |
| 232 const base::TimeDelta& step_delay, | 238 const base::TimeDelta& step_delay, |
| 233 int steps) { | 239 int steps) { |
| 234 const int kTouchId = 5; | 240 const int kTouchId = 5; |
| 235 base::TimeDelta timestamp = ui::EventTimeForNow(); | 241 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 236 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); | 242 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); |
| 237 Dispatch(press); | 243 DispatchTouchEvent(press); |
| 238 | 244 |
| 239 int dx = (end.x() - start.x()) / steps; | 245 int dx = (end.x() - start.x()) / steps; |
| 240 int dy = (end.y() - start.y()) / steps; | 246 int dy = (end.y() - start.y()) / steps; |
| 241 gfx::Point location = start; | 247 gfx::Point location = start; |
| 242 for (int i = 0; i < steps; ++i) { | 248 for (int i = 0; i < steps; ++i) { |
| 243 location.Offset(dx, dy); | 249 location.Offset(dx, dy); |
| 244 timestamp += step_delay; | 250 timestamp += step_delay; |
| 245 ui::TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp); | 251 ui::TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp); |
| 246 Dispatch(move); | 252 DispatchTouchEvent(move); |
| 247 } | 253 } |
| 248 | 254 |
| 249 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp); | 255 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp); |
| 250 Dispatch(release); | 256 DispatchTouchEvent(release); |
| 251 } | 257 } |
| 252 | 258 |
| 253 void EventGenerator::GestureMultiFingerScroll(int count, | 259 void EventGenerator::GestureMultiFingerScroll(int count, |
| 254 const gfx::Point* start, | 260 const gfx::Point* start, |
| 255 int event_separation_time_ms, | 261 int event_separation_time_ms, |
| 256 int steps, | 262 int steps, |
| 257 int move_x, | 263 int move_x, |
| 258 int move_y) { | 264 int move_y) { |
| 259 const int kMaxTouchPoints = 10; | 265 const int kMaxTouchPoints = 10; |
| 260 gfx::Point points[kMaxTouchPoints]; | 266 gfx::Point points[kMaxTouchPoints]; |
| 261 CHECK_LE(count, kMaxTouchPoints); | 267 CHECK_LE(count, kMaxTouchPoints); |
| 262 CHECK_GT(steps, 0); | 268 CHECK_GT(steps, 0); |
| 263 | 269 |
| 264 int delta_x = move_x / steps; | 270 int delta_x = move_x / steps; |
| 265 int delta_y = move_y / steps; | 271 int delta_y = move_y / steps; |
| 266 | 272 |
| 267 base::TimeDelta press_time = ui::EventTimeForNow(); | 273 base::TimeDelta press_time = ui::EventTimeForNow(); |
| 268 for (int i = 0; i < count; ++i) { | 274 for (int i = 0; i < count; ++i) { |
| 269 points[i] = start[i]; | 275 points[i] = start[i]; |
| 270 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, points[i], i, press_time); | 276 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, points[i], i, press_time); |
| 271 Dispatch(press); | 277 DispatchTouchEvent(press); |
| 272 } | 278 } |
| 273 | 279 |
| 274 for (int step = 0; step < steps; ++step) { | 280 for (int step = 0; step < steps; ++step) { |
| 275 base::TimeDelta move_time = press_time + | 281 base::TimeDelta move_time = press_time + |
| 276 base::TimeDelta::FromMilliseconds(event_separation_time_ms * step); | 282 base::TimeDelta::FromMilliseconds(event_separation_time_ms * step); |
| 277 for (int i = 0; i < count; ++i) { | 283 for (int i = 0; i < count; ++i) { |
| 278 points[i].Offset(delta_x, delta_y); | 284 points[i].Offset(delta_x, delta_y); |
| 279 ui::TouchEvent move(ui::ET_TOUCH_MOVED, points[i], i, move_time); | 285 ui::TouchEvent move(ui::ET_TOUCH_MOVED, points[i], i, move_time); |
| 280 Dispatch(move); | 286 DispatchTouchEvent(move); |
| 281 } | 287 } |
| 282 } | 288 } |
| 283 | 289 |
| 284 base::TimeDelta release_time = press_time + | 290 base::TimeDelta release_time = press_time + |
| 285 base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps); | 291 base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps); |
| 286 for (int i = 0; i < count; ++i) { | 292 for (int i = 0; i < count; ++i) { |
| 287 ui::TouchEvent release( | 293 ui::TouchEvent release( |
| 288 ui::ET_TOUCH_RELEASED, points[i], i, release_time); | 294 ui::ET_TOUCH_RELEASED, points[i], i, release_time); |
| 289 Dispatch(release); | 295 DispatchTouchEvent(release); |
| 290 } | 296 } |
| 291 } | 297 } |
| 292 | 298 |
| 299 void EventGenerator::ScrollSequence(const gfx::Point& start, | |
| 300 const base::TimeDelta& step_delay, | |
| 301 float x_offset, | |
| 302 float y_offset, | |
| 303 int steps, | |
| 304 int num_fingers) { | |
| 305 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue( | |
|
sky
2013/01/22 18:05:01
Should this use ui::EventTimeForNow ?
DaveMoore
2013/01/27 21:21:54
Done.
| |
| 306 base::TimeTicks::Now().ToInternalValue()); | |
| 307 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | |
| 308 start, | |
| 309 timestamp, | |
| 310 0, | |
| 311 0, | |
| 312 0, | |
| 313 num_fingers); | |
| 314 DispatchScrollEvent(fling_cancel); | |
| 315 | |
| 316 float dx = x_offset / steps; | |
| 317 float dy = y_offset / steps; | |
| 318 for (int i = 0; i < steps; ++i) { | |
| 319 timestamp += step_delay; | |
| 320 ui::ScrollEvent move(ui::ET_SCROLL, | |
| 321 start, | |
| 322 timestamp, | |
| 323 0, | |
| 324 dx, | |
| 325 dy, | |
| 326 num_fingers); | |
| 327 DispatchScrollEvent(move); | |
| 328 } | |
| 329 | |
| 330 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, | |
| 331 start, | |
| 332 timestamp, | |
| 333 0, | |
| 334 x_offset, | |
| 335 y_offset, | |
| 336 num_fingers); | |
| 337 DispatchScrollEvent(fling_start); | |
| 338 } | |
| 339 | |
| 340 void EventGenerator::ScrollSequence(const gfx::Point& start, | |
| 341 const base::TimeDelta& step_delay, | |
| 342 const std::vector<gfx::Point> offsets, | |
| 343 int num_fingers) { | |
| 344 int steps = offsets.size(); | |
| 345 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue( | |
| 346 base::TimeTicks::Now().ToInternalValue()); | |
| 347 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | |
| 348 start, | |
| 349 timestamp, | |
| 350 0, | |
| 351 0, | |
| 352 0, | |
| 353 num_fingers); | |
| 354 DispatchScrollEvent(fling_cancel); | |
| 355 | |
| 356 for (int i = 0; i < steps; ++i) { | |
| 357 timestamp += step_delay; | |
| 358 ui::ScrollEvent scroll(ui::ET_SCROLL, | |
| 359 start, | |
| 360 timestamp, | |
| 361 0, | |
| 362 offsets[i].x(), | |
| 363 offsets[i].y(), | |
| 364 num_fingers); | |
| 365 DispatchScrollEvent(scroll); | |
| 366 } | |
| 367 | |
| 368 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, | |
| 369 start, | |
| 370 timestamp, | |
| 371 0, | |
| 372 offsets[steps - 1].x(), | |
| 373 offsets[steps - 1].y(), | |
| 374 num_fingers); | |
| 375 DispatchScrollEvent(fling_start); | |
| 376 } | |
| 377 | |
| 293 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { | 378 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { |
| 294 DispatchKeyEvent(true, key_code, flags); | 379 DispatchKeyEvent(true, key_code, flags); |
| 295 } | 380 } |
| 296 | 381 |
| 297 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { | 382 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { |
| 298 DispatchKeyEvent(false, key_code, flags); | 383 DispatchKeyEvent(false, key_code, flags); |
| 299 } | 384 } |
| 300 | 385 |
| 301 void EventGenerator::Dispatch(ui::Event& event) { | 386 void EventGenerator::DispatchKeyEvent(ui::KeyEvent& key_event) { |
| 302 switch (event.type()) { | 387 if (post_events_) { |
| 303 case ui::ET_KEY_PRESSED: | 388 if (pending_key_events_.empty()) { |
| 304 case ui::ET_KEY_RELEASED: | 389 base::MessageLoopProxy::current()->PostTask( |
| 305 current_root_window_->AsRootWindowHostDelegate()->OnHostKeyEvent( | 390 FROM_HERE, |
| 306 static_cast<ui::KeyEvent*>(&event)); | 391 base::Bind(&EventGenerator::DoDispatchKeyEvent, |
| 307 break; | 392 base::Unretained(this))); |
| 308 case ui::ET_MOUSE_PRESSED: | 393 } |
| 309 case ui::ET_MOUSE_DRAGGED: | 394 pending_key_events_.push_back(key_event); |
| 310 case ui::ET_MOUSE_RELEASED: | 395 } else { |
| 311 case ui::ET_MOUSE_MOVED: | 396 current_root_window_->AsRootWindowHostDelegate()->OnHostKeyEvent( |
| 312 case ui::ET_MOUSE_ENTERED: | 397 &key_event); |
| 313 case ui::ET_MOUSE_EXITED: | |
| 314 case ui::ET_MOUSEWHEEL: | |
| 315 current_root_window_->AsRootWindowHostDelegate()->OnHostMouseEvent( | |
| 316 static_cast<ui::MouseEvent*>(&event)); | |
| 317 break; | |
| 318 case ui::ET_TOUCH_RELEASED: | |
| 319 case ui::ET_TOUCH_PRESSED: | |
| 320 case ui::ET_TOUCH_MOVED: | |
| 321 case ui::ET_TOUCH_STATIONARY: | |
| 322 case ui::ET_TOUCH_CANCELLED: | |
| 323 current_root_window_->AsRootWindowHostDelegate()->OnHostTouchEvent( | |
| 324 static_cast<ui::TouchEvent*>(&event)); | |
| 325 break; | |
| 326 default: | |
| 327 NOTIMPLEMENTED(); | |
| 328 break; | |
| 329 } | 398 } |
| 330 } | 399 } |
| 331 | 400 |
| 401 void EventGenerator::DispatchMouseEvent(ui::MouseEvent& mouse_event) { | |
| 402 if (post_events_) { | |
| 403 if (pending_mouse_events_.empty()) { | |
| 404 base::MessageLoopProxy::current()->PostTask( | |
| 405 FROM_HERE, | |
| 406 base::Bind(&EventGenerator::DoDispatchMouseEvent, | |
| 407 base::Unretained(this))); | |
| 408 } | |
| 409 pending_mouse_events_.push_back(mouse_event); | |
| 410 } else { | |
| 411 current_root_window_->AsRootWindowHostDelegate()->OnHostMouseEvent( | |
| 412 &mouse_event); | |
| 413 } | |
| 414 } | |
| 415 | |
| 416 void EventGenerator::DispatchTouchEvent(ui::TouchEvent& touch_event) { | |
| 417 if (post_events_) { | |
| 418 if (pending_touch_events_.empty()) { | |
| 419 base::MessageLoopProxy::current()->PostTask( | |
| 420 FROM_HERE, | |
| 421 base::Bind(&EventGenerator::DoDispatchTouchEvent, | |
| 422 base::Unretained(this))); | |
| 423 } | |
| 424 pending_touch_events_.push_back(touch_event); | |
| 425 } else { | |
| 426 current_root_window_->AsRootWindowHostDelegate()->OnHostTouchEvent( | |
| 427 &touch_event); | |
| 428 } | |
| 429 } | |
| 430 | |
| 431 void EventGenerator::DispatchScrollEvent(ui::ScrollEvent& scroll_event) { | |
| 432 if (post_events_) { | |
| 433 if (pending_scroll_events_.empty()) { | |
| 434 base::MessageLoopProxy::current()->PostTask( | |
| 435 FROM_HERE, | |
| 436 base::Bind(&EventGenerator::DoDispatchScrollEvent, | |
| 437 base::Unretained(this))); | |
| 438 } | |
| 439 pending_scroll_events_.push_back(scroll_event); | |
| 440 } else { | |
| 441 current_root_window_->AsRootWindowHostDelegate()->OnHostScrollEvent( | |
| 442 &scroll_event); | |
| 443 } | |
| 444 } | |
| 445 | |
| 332 void EventGenerator::DispatchKeyEvent(bool is_press, | 446 void EventGenerator::DispatchKeyEvent(bool is_press, |
| 333 ui::KeyboardCode key_code, | 447 ui::KeyboardCode key_code, |
| 334 int flags) { | 448 int flags) { |
| 335 #if defined(OS_WIN) | 449 #if defined(OS_WIN) |
| 336 UINT key_press = WM_KEYDOWN; | 450 UINT key_press = WM_KEYDOWN; |
| 337 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags); | 451 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags); |
| 338 if (is_press && character) { | 452 if (is_press && character) { |
| 339 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; | 453 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; |
| 340 TestKeyEvent keyev(native_event, flags, false); | 454 TestKeyEvent keyev(native_event, flags, false); |
| 341 Dispatch(keyev); | 455 DispatchKeyEvent(keyev); |
| 342 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character | 456 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character |
| 343 // if the key event cooresponds to a real character. | 457 // if the key event cooresponds to a real character. |
| 344 key_press = WM_CHAR; | 458 key_press = WM_CHAR; |
| 345 key_code = static_cast<ui::KeyboardCode>(character); | 459 key_code = static_cast<ui::KeyboardCode>(character); |
| 346 } | 460 } |
| 347 MSG native_event = | 461 MSG native_event = |
| 348 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; | 462 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; |
| 349 TestKeyEvent keyev(native_event, flags, key_press == WM_CHAR); | 463 TestKeyEvent keyev(native_event, flags, key_press == WM_CHAR); |
| 350 #else | 464 #else |
| 351 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; | 465 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; |
| 352 #if defined(USE_X11) | 466 #if defined(USE_X11) |
| 353 scoped_ptr<XEvent> native_event(new XEvent); | 467 scoped_ptr<XEvent> native_event(new XEvent); |
| 354 ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get()); | 468 ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get()); |
| 355 TestKeyEvent keyev(native_event.get(), flags, false); | 469 TestKeyEvent keyev(native_event.get(), flags, false); |
| 356 #else | 470 #else |
| 357 ui::KeyEvent keyev(type, key_code, flags, false); | 471 ui::KeyEvent keyev(type, key_code, flags, false); |
| 358 #endif // USE_X11 | 472 #endif // USE_X11 |
| 359 #endif // OS_WIN | 473 #endif // OS_WIN |
| 360 Dispatch(keyev); | 474 DispatchKeyEvent(keyev); |
| 361 } | 475 } |
| 362 | 476 |
| 363 void EventGenerator::UpdateCurrentRootWindow(const gfx::Point& point) { | 477 void EventGenerator::UpdateCurrentRootWindow(const gfx::Point& point) { |
| 364 current_root_window_ = delegate_->GetRootWindowAt(point); | 478 current_root_window_ = delegate_->GetRootWindowAt(point); |
| 365 } | 479 } |
| 366 | 480 |
| 367 void EventGenerator::PressButton(int flag) { | 481 void EventGenerator::PressButton(int flag) { |
| 368 if (!(flags_ & flag)) { | 482 if (!(flags_ & flag)) { |
| 369 flags_ |= flag; | 483 flags_ |= flag; |
| 370 grab_ = flags_ & kAllButtonMask; | 484 grab_ = flags_ & kAllButtonMask; |
| 371 gfx::Point location = GetLocationInCurrentRoot(); | 485 gfx::Point location = GetLocationInCurrentRoot(); |
| 372 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_); | 486 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_); |
| 373 Dispatch(mouseev); | 487 DispatchMouseEvent(mouseev); |
| 374 } | 488 } |
| 375 } | 489 } |
| 376 | 490 |
| 377 void EventGenerator::ReleaseButton(int flag) { | 491 void EventGenerator::ReleaseButton(int flag) { |
| 378 if (flags_ & flag) { | 492 if (flags_ & flag) { |
| 379 gfx::Point location = GetLocationInCurrentRoot(); | 493 gfx::Point location = GetLocationInCurrentRoot(); |
| 380 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, | 494 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, |
| 381 location, flags_); | 495 location, flags_); |
| 382 Dispatch(mouseev); | 496 DispatchMouseEvent(mouseev); |
| 383 flags_ ^= flag; | 497 flags_ ^= flag; |
| 384 } | 498 } |
| 385 grab_ = flags_ & kAllButtonMask; | 499 grab_ = flags_ & kAllButtonMask; |
| 386 } | 500 } |
| 387 | 501 |
| 388 void EventGenerator::ConvertPointFromTarget(const aura::Window* target, | 502 void EventGenerator::ConvertPointFromTarget(const aura::Window* target, |
| 389 gfx::Point* point) const { | 503 gfx::Point* point) const { |
| 390 DCHECK(point); | 504 DCHECK(point); |
| 391 aura::client::ScreenPositionClient* client = | 505 aura::client::ScreenPositionClient* client = |
| 392 delegate_->GetScreenPositionClient(target); | 506 delegate_->GetScreenPositionClient(target); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 412 ConvertPointToTarget(current_root_window_, &p); | 526 ConvertPointToTarget(current_root_window_, &p); |
| 413 return p; | 527 return p; |
| 414 } | 528 } |
| 415 | 529 |
| 416 gfx::Point EventGenerator::CenterOfWindow(const Window* window) const { | 530 gfx::Point EventGenerator::CenterOfWindow(const Window* window) const { |
| 417 gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint(); | 531 gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint(); |
| 418 ConvertPointFromTarget(window, ¢er); | 532 ConvertPointFromTarget(window, ¢er); |
| 419 return center; | 533 return center; |
| 420 } | 534 } |
| 421 | 535 |
| 536 void EventGenerator::DoDispatchKeyEvent() { | |
|
sky
2013/01/22 18:05:01
How about a single member for std::list<Event*> wi
DaveMoore
2013/01/27 21:21:54
rewritten to minimize copied code.
On 2013/01/22 1
| |
| 537 DCHECK(!pending_key_events_.empty()); | |
| 538 ui::KeyEvent key_event = pending_key_events_.front(); | |
| 539 current_root_window_->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_event); | |
| 540 pending_key_events_.pop_front(); | |
| 541 if (!pending_key_events_.empty()) { | |
| 542 base::MessageLoopProxy::current()->PostTask( | |
| 543 FROM_HERE, | |
| 544 base::Bind(&EventGenerator::DoDispatchKeyEvent, | |
| 545 base::Unretained(this))); | |
| 546 } | |
| 547 } | |
| 548 | |
| 549 void EventGenerator::DoDispatchMouseEvent() { | |
| 550 DCHECK(!pending_mouse_events_.empty()); | |
| 551 ui::MouseEvent mouse_event = pending_mouse_events_.front(); | |
| 552 current_root_window_->AsRootWindowHostDelegate()->OnHostMouseEvent( | |
| 553 &mouse_event); | |
| 554 pending_mouse_events_.pop_front(); | |
| 555 if (!pending_mouse_events_.empty()) { | |
| 556 base::MessageLoopProxy::current()->PostTask( | |
| 557 FROM_HERE, | |
| 558 base::Bind(&EventGenerator::DoDispatchMouseEvent, | |
| 559 base::Unretained(this))); | |
| 560 } | |
| 561 } | |
| 562 | |
| 563 void EventGenerator::DoDispatchTouchEvent() { | |
| 564 DCHECK(!pending_touch_events_.empty()); | |
| 565 ui::TouchEvent touch_event = pending_touch_events_.front(); | |
| 566 current_root_window_->AsRootWindowHostDelegate()->OnHostTouchEvent( | |
| 567 &touch_event); | |
| 568 pending_touch_events_.pop_front(); | |
| 569 if (!pending_touch_events_.empty()) { | |
| 570 base::MessageLoopProxy::current()->PostTask( | |
| 571 FROM_HERE, | |
| 572 base::Bind(&EventGenerator::DoDispatchTouchEvent, | |
| 573 base::Unretained(this))); | |
| 574 } | |
| 575 } | |
| 576 | |
| 577 void EventGenerator::DoDispatchScrollEvent() { | |
| 578 DCHECK(!pending_scroll_events_.empty()); | |
| 579 ui::ScrollEvent scroll_event = pending_scroll_events_.front(); | |
| 580 current_root_window_->AsRootWindowHostDelegate()->OnHostScrollEvent( | |
| 581 &scroll_event); | |
| 582 pending_scroll_events_.pop_front(); | |
| 583 if (!pending_scroll_events_.empty()) { | |
| 584 base::MessageLoopProxy::current()->PostTask( | |
| 585 FROM_HERE, | |
| 586 base::Bind(&EventGenerator::DoDispatchScrollEvent, | |
| 587 base::Unretained(this))); | |
| 588 } | |
| 589 } | |
| 590 | |
| 422 } // namespace test | 591 } // namespace test |
| 423 } // namespace aura | 592 } // namespace aura |
| OLD | NEW |