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/window_tree_host_x11.h" | 5 #include "ui/aura/window_tree_host_x11.h" |
| 6 | 6 |
| 7 #include <strings.h> | 7 #include <strings.h> |
| 8 #include <X11/cursorfont.h> | 8 #include <X11/cursorfont.h> |
| 9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/extensions/Xrandr.h> | 10 #include <X11/extensions/Xrandr.h> |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 | 324 |
| 325 uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { | 325 uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { |
| 326 XEvent* xev = event; | 326 XEvent* xev = event; |
| 327 if (FindEventTarget(xev) == x_root_window_) { | 327 if (FindEventTarget(xev) == x_root_window_) { |
| 328 if (xev->type == GenericEvent) | 328 if (xev->type == GenericEvent) |
| 329 DispatchXI2Event(xev); | 329 DispatchXI2Event(xev); |
| 330 return ui::POST_DISPATCH_NONE; | 330 return ui::POST_DISPATCH_NONE; |
| 331 } | 331 } |
| 332 | 332 |
| 333 switch (xev->type) { | 333 switch (xev->type) { |
| 334 case EnterNotify: { | |
| 335 aura::Window* root_window = window(); | |
| 336 client::CursorClient* cursor_client = | |
| 337 client::GetCursorClient(root_window); | |
| 338 if (cursor_client) { | |
| 339 const gfx::Display display = gfx::Screen::GetScreenFor(root_window)-> | |
| 340 GetDisplayNearestWindow(root_window); | |
| 341 cursor_client->SetDisplay(display); | |
| 342 } | |
| 343 ui::MouseEvent mouse_event(xev); | |
| 344 // EnterNotify creates ET_MOUSE_MOVE. Mark as synthesized as this is not | |
| 345 // real mouse move event. | |
| 346 mouse_event.set_flags(mouse_event.flags() | ui::EF_IS_SYNTHESIZED); | |
| 347 TranslateAndDispatchLocatedEvent(&mouse_event); | |
| 348 break; | |
| 349 } | |
| 350 case LeaveNotify: { | |
| 351 ui::MouseEvent mouse_event(xev); | |
| 352 TranslateAndDispatchLocatedEvent(&mouse_event); | |
| 353 break; | |
| 354 } | |
| 355 case Expose: { | 334 case Expose: { |
| 356 gfx::Rect damage_rect(xev->xexpose.x, xev->xexpose.y, | 335 gfx::Rect damage_rect(xev->xexpose.x, xev->xexpose.y, |
| 357 xev->xexpose.width, xev->xexpose.height); | 336 xev->xexpose.width, xev->xexpose.height); |
| 358 compositor()->ScheduleRedrawRect(damage_rect); | 337 compositor()->ScheduleRedrawRect(damage_rect); |
| 359 break; | 338 break; |
| 360 } | 339 } |
| 361 case KeyPress: { | 340 |
| 362 ui::KeyEvent keydown_event(xev, false); | |
| 363 SendEventToProcessor(&keydown_event); | |
| 364 break; | |
| 365 } | |
| 366 case KeyRelease: { | |
| 367 ui::KeyEvent keyup_event(xev, false); | |
| 368 SendEventToProcessor(&keyup_event); | |
| 369 break; | |
| 370 } | |
| 371 case ButtonPress: | |
| 372 case ButtonRelease: { | |
| 373 switch (ui::EventTypeFromNative(xev)) { | |
| 374 case ui::ET_MOUSEWHEEL: { | |
| 375 ui::MouseWheelEvent mouseev(xev); | |
| 376 TranslateAndDispatchLocatedEvent(&mouseev); | |
| 377 break; | |
| 378 } | |
| 379 case ui::ET_MOUSE_PRESSED: | |
| 380 case ui::ET_MOUSE_RELEASED: { | |
| 381 ui::MouseEvent mouseev(xev); | |
| 382 TranslateAndDispatchLocatedEvent(&mouseev); | |
| 383 break; | |
| 384 } | |
| 385 case ui::ET_UNKNOWN: | |
| 386 // No event is created for X11-release events for mouse-wheel buttons. | |
| 387 break; | |
| 388 default: | |
| 389 NOTREACHED(); | |
| 390 } | |
| 391 break; | |
| 392 } | |
| 393 case FocusOut: | 341 case FocusOut: |
| 394 if (xev->xfocus.mode != NotifyGrab) | 342 if (xev->xfocus.mode != NotifyGrab) |
| 395 OnHostLostWindowCapture(); | 343 OnHostLostWindowCapture(); |
| 396 break; | 344 break; |
| 397 case ConfigureNotify: { | 345 case ConfigureNotify: { |
| 398 DCHECK_EQ(xwindow_, xev->xconfigure.event); | 346 DCHECK_EQ(xwindow_, xev->xconfigure.event); |
| 399 DCHECK_EQ(xwindow_, xev->xconfigure.window); | 347 DCHECK_EQ(xwindow_, xev->xconfigure.window); |
| 400 // It's possible that the X window may be resized by some other means | 348 // It's possible that the X window may be resized by some other means |
| 401 // than from within aura (e.g. the X window manager can change the | 349 // than from within aura (e.g. the X window manager can change the |
| 402 // size). Make sure the root window size is maintained properly. | 350 // size). Make sure the root window size is maintained properly. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 break; | 389 break; |
| 442 case MappingPointer: | 390 case MappingPointer: |
| 443 ui::DeviceDataManager::GetInstance()->UpdateButtonMap(); | 391 ui::DeviceDataManager::GetInstance()->UpdateButtonMap(); |
| 444 break; | 392 break; |
| 445 default: | 393 default: |
| 446 NOTIMPLEMENTED() << " Unknown request: " << xev->xmapping.request; | 394 NOTIMPLEMENTED() << " Unknown request: " << xev->xmapping.request; |
| 447 break; | 395 break; |
| 448 } | 396 } |
| 449 break; | 397 break; |
| 450 } | 398 } |
| 399 case EnterNotify: | |
| 400 case LeaveNotify: | |
| 401 case KeyPress: | |
| 402 case KeyRelease: | |
| 403 case ButtonPress: | |
| 404 case ButtonRelease: | |
| 451 case MotionNotify: { | 405 case MotionNotify: { |
| 452 // Discard all but the most recent motion event that targets the same | 406 if (xev->type == MotionNotify) { |
| 453 // window with unchanged state. | 407 // Discard all but the most recent motion event that targets the same |
| 454 XEvent last_event; | 408 // window with unchanged state. |
| 455 while (XPending(xev->xany.display)) { | 409 XEvent last_event; |
| 456 XEvent next_event; | 410 while (XPending(xev->xany.display)) { |
| 457 XPeekEvent(xev->xany.display, &next_event); | 411 XEvent next_event; |
| 458 if (next_event.type == MotionNotify && | 412 XPeekEvent(xev->xany.display, &next_event); |
| 459 next_event.xmotion.window == xev->xmotion.window && | 413 if (next_event.type == MotionNotify && |
| 460 next_event.xmotion.subwindow == xev->xmotion.subwindow && | 414 next_event.xmotion.window == xev->xmotion.window && |
| 461 next_event.xmotion.state == xev->xmotion.state) { | 415 next_event.xmotion.subwindow == xev->xmotion.subwindow && |
| 462 XNextEvent(xev->xany.display, &last_event); | 416 next_event.xmotion.state == xev->xmotion.state) { |
| 463 xev = &last_event; | 417 XNextEvent(xev->xany.display, &last_event); |
| 464 } else { | 418 xev = &last_event; |
| 419 } else { | |
| 420 break; | |
| 421 } | |
| 422 } | |
| 423 } | |
|
sadrul
2014/06/12 21:02:27
Maybe this could move out of the switch/case (like
flackr
2014/06/18 05:28:31
Done.
| |
| 424 switch (ui::EventTypeFromNative(xev)) { | |
| 425 case ui::ET_MOUSE_ENTERED: { | |
| 426 aura::Window* root_window = window(); | |
| 427 client::CursorClient* cursor_client = | |
| 428 client::GetCursorClient(root_window); | |
| 429 if (cursor_client) { | |
| 430 const gfx::Display display = gfx::Screen::GetScreenFor( | |
| 431 root_window)->GetDisplayNearestWindow(root_window); | |
| 432 cursor_client->SetDisplay(display); | |
| 433 } | |
| 434 ui::MouseEvent mouse_event(xev); | |
| 435 // EnterNotify creates ET_MOUSE_MOVE. Mark as synthesized as this is | |
| 436 // not a real mouse move event. | |
| 437 mouse_event.set_flags(mouse_event.flags() | ui::EF_IS_SYNTHESIZED); | |
| 438 TranslateAndDispatchLocatedEvent(&mouse_event); | |
| 465 break; | 439 break; |
| 466 } | 440 } |
| 441 case ui::ET_KEY_PRESSED: | |
| 442 case ui::ET_KEY_RELEASED: { | |
| 443 ui::KeyEvent keydown_event(xev, false); | |
| 444 SendEventToProcessor(&keydown_event); | |
| 445 break; | |
| 446 } | |
| 447 case ui::ET_MOUSE_MOVED: | |
| 448 case ui::ET_MOUSE_DRAGGED: | |
| 449 case ui::ET_MOUSE_EXITED: | |
| 450 case ui::ET_MOUSE_PRESSED: | |
| 451 case ui::ET_MOUSE_RELEASED: { | |
| 452 ui::MouseEvent mouse_event(xev); | |
| 453 TranslateAndDispatchLocatedEvent(&mouse_event); | |
| 454 break; | |
| 455 } | |
| 456 case ui::ET_MOUSEWHEEL: { | |
| 457 ui::MouseWheelEvent mouseev(xev); | |
| 458 TranslateAndDispatchLocatedEvent(&mouseev); | |
| 459 break; | |
| 460 } | |
| 461 case ui::ET_UNKNOWN: | |
| 462 // No event is created for X11-release events for mouse-wheel buttons. | |
| 463 break; | |
| 464 default: | |
| 465 NOTREACHED(); | |
| 467 } | 466 } |
| 468 | |
| 469 ui::MouseEvent mouseev(xev); | |
| 470 TranslateAndDispatchLocatedEvent(&mouseev); | |
| 471 break; | 467 break; |
| 472 } | 468 } |
| 473 } | 469 } |
| 474 return ui::POST_DISPATCH_STOP_PROPAGATION; | 470 return ui::POST_DISPATCH_STOP_PROPAGATION; |
| 475 } | 471 } |
| 476 | 472 |
| 477 ui::EventSource* WindowTreeHostX11::GetEventSource() { | 473 ui::EventSource* WindowTreeHostX11::GetEventSource() { |
| 478 return this; | 474 return this; |
| 479 } | 475 } |
| 480 | 476 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 XEvent* xev = event; | 628 XEvent* xev = event; |
| 633 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 629 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 634 if (!factory->ShouldProcessXI2Event(xev)) | 630 if (!factory->ShouldProcessXI2Event(xev)) |
| 635 return; | 631 return; |
| 636 | 632 |
| 637 TRACE_EVENT1("input", "WindowTreeHostX11::DispatchXI2Event", | 633 TRACE_EVENT1("input", "WindowTreeHostX11::DispatchXI2Event", |
| 638 "event_latency_us", | 634 "event_latency_us", |
| 639 (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). | 635 (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). |
| 640 InMicroseconds()); | 636 InMicroseconds()); |
| 641 | 637 |
| 638 int num_coalesced = 0; | |
| 639 XEvent last_event; | |
| 640 if (xev->xgeneric.evtype == XI_Motion) { | |
| 641 // If this is a motion event, we want to coalesce all pending motion | |
| 642 // events that are at the top of the queue. Note, we don't coalesce | |
| 643 // touch update events here. | |
| 644 num_coalesced = ui::CoalescePendingMotionEvents(xev, &last_event); | |
| 645 if (num_coalesced > 0) | |
| 646 xev = &last_event; | |
| 647 } | |
| 642 ui::EventType type = ui::EventTypeFromNative(xev); | 648 ui::EventType type = ui::EventTypeFromNative(xev); |
| 643 XEvent last_event; | |
| 644 int num_coalesced = 0; | |
| 645 | 649 |
| 646 switch (type) { | 650 switch (type) { |
| 647 case ui::ET_TOUCH_MOVED: | 651 case ui::ET_TOUCH_MOVED: |
| 648 case ui::ET_TOUCH_PRESSED: | 652 case ui::ET_TOUCH_PRESSED: |
| 649 case ui::ET_TOUCH_CANCELLED: | 653 case ui::ET_TOUCH_CANCELLED: |
| 650 case ui::ET_TOUCH_RELEASED: { | 654 case ui::ET_TOUCH_RELEASED: { |
| 651 ui::TouchEvent touchev(xev); | 655 ui::TouchEvent touchev(xev); |
| 652 if (ui::DeviceDataManager::GetInstance()->TouchEventNeedsCalibrate( | 656 if (ui::DeviceDataManager::GetInstance()->TouchEventNeedsCalibrate( |
| 653 xiev->deviceid)) { | 657 xiev->deviceid)) { |
| 654 touch_calibrate_->Calibrate(&touchev, bounds_); | 658 touch_calibrate_->Calibrate(&touchev, bounds_); |
| 655 } | 659 } |
| 656 TranslateAndDispatchLocatedEvent(&touchev); | 660 TranslateAndDispatchLocatedEvent(&touchev); |
| 657 break; | 661 break; |
| 658 } | 662 } |
| 659 case ui::ET_MOUSE_MOVED: | 663 case ui::ET_MOUSE_MOVED: |
| 660 case ui::ET_MOUSE_DRAGGED: | 664 case ui::ET_MOUSE_DRAGGED: |
| 661 case ui::ET_MOUSE_PRESSED: | 665 case ui::ET_MOUSE_PRESSED: |
| 662 case ui::ET_MOUSE_RELEASED: | 666 case ui::ET_MOUSE_RELEASED: |
| 663 case ui::ET_MOUSE_ENTERED: | 667 case ui::ET_MOUSE_ENTERED: |
| 664 case ui::ET_MOUSE_EXITED: { | 668 case ui::ET_MOUSE_EXITED: { |
| 665 if (type == ui::ET_MOUSE_MOVED || type == ui::ET_MOUSE_DRAGGED) { | |
| 666 // If this is a motion event, we want to coalesce all pending motion | |
| 667 // events that are at the top of the queue. | |
| 668 num_coalesced = ui::CoalescePendingMotionEvents(xev, &last_event); | |
| 669 if (num_coalesced > 0) | |
| 670 xev = &last_event; | |
| 671 } | |
| 672 ui::MouseEvent mouseev(xev); | 669 ui::MouseEvent mouseev(xev); |
| 673 TranslateAndDispatchLocatedEvent(&mouseev); | 670 TranslateAndDispatchLocatedEvent(&mouseev); |
| 674 break; | 671 break; |
| 675 } | 672 } |
| 676 case ui::ET_MOUSEWHEEL: { | 673 case ui::ET_MOUSEWHEEL: { |
| 677 ui::MouseWheelEvent mouseev(xev); | 674 ui::MouseWheelEvent mouseev(xev); |
| 678 TranslateAndDispatchLocatedEvent(&mouseev); | 675 TranslateAndDispatchLocatedEvent(&mouseev); |
| 679 break; | 676 break; |
| 680 } | 677 } |
| 681 case ui::ET_SCROLL_FLING_START: | 678 case ui::ET_SCROLL_FLING_START: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 } | 718 } |
| 722 | 719 |
| 723 namespace test { | 720 namespace test { |
| 724 | 721 |
| 725 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { | 722 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { |
| 726 default_override_redirect = override_redirect; | 723 default_override_redirect = override_redirect; |
| 727 } | 724 } |
| 728 | 725 |
| 729 } // namespace test | 726 } // namespace test |
| 730 } // namespace aura | 727 } // namespace aura |
| OLD | NEW |