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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 if (ui::PlatformEventSource::GetInstance()) | 181 if (ui::PlatformEventSource::GetInstance()) |
182 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); | 182 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
183 | 183 |
184 DestroyCompositor(); | 184 DestroyCompositor(); |
185 DestroyDispatcher(); | 185 DestroyDispatcher(); |
186 XDestroyWindow(xdisplay_, xwindow_); | 186 XDestroyWindow(xdisplay_, xwindow_); |
187 } | 187 } |
188 | 188 |
189 bool WindowTreeHostX11::CanDispatchEvent(const ui::PlatformEvent& event) { | 189 bool WindowTreeHostX11::CanDispatchEvent(const ui::PlatformEvent& event) { |
190 ::Window target = FindEventTarget(event); | 190 ::Window target = FindEventTarget(event); |
191 return target == xwindow_ || target == x_root_window_; | 191 return target == xwindow_ || target == x_root_window_; |
sadrul
2014/04/30 16:58:58
You should update this function to decide whether
Yufeng Shen (Slow to review)
2014/04/30 19:16:44
Perfect.
Added the logic in AshWindowTreeHostX11:
| |
192 } | 192 } |
193 | 193 |
194 uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { | 194 uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { |
195 XEvent* xev = event; | 195 XEvent* xev = event; |
196 if (FindEventTarget(xev) == x_root_window_) { | 196 if (FindEventTarget(xev) == x_root_window_) { |
197 if (xev->type == GenericEvent) | 197 if (xev->type == GenericEvent) |
198 DispatchXI2Event(xev); | 198 DispatchXI2Event(xev); |
199 return ui::POST_DISPATCH_NONE; | 199 return ui::POST_DISPATCH_NONE; |
200 } | 200 } |
201 | 201 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 void WindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { | 492 void WindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { |
493 } | 493 } |
494 | 494 |
495 ui::EventProcessor* WindowTreeHostX11::GetEventProcessor() { | 495 ui::EventProcessor* WindowTreeHostX11::GetEventProcessor() { |
496 return dispatcher(); | 496 return dispatcher(); |
497 } | 497 } |
498 | 498 |
499 void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { | 499 void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { |
500 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 500 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
501 XEvent* xev = event; | 501 XEvent* xev = event; |
502 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
502 if (!factory->ShouldProcessXI2Event(xev)) | 503 if (!factory->ShouldProcessXI2Event(xev)) |
503 return; | 504 return; |
504 | 505 |
505 TRACE_EVENT1("input", "WindowTreeHostX11::DispatchXI2Event", | 506 TRACE_EVENT1("input", "WindowTreeHostX11::DispatchXI2Event", |
506 "event_latency_us", | 507 "event_latency_us", |
507 (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). | 508 (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). |
508 InMicroseconds()); | 509 InMicroseconds()); |
509 | 510 |
510 ui::EventType type = ui::EventTypeFromNative(xev); | 511 ui::EventType type = ui::EventTypeFromNative(xev); |
511 XEvent last_event; | 512 XEvent last_event; |
512 int num_coalesced = 0; | 513 int num_coalesced = 0; |
513 | 514 |
514 switch (type) { | 515 switch (type) { |
515 case ui::ET_TOUCH_MOVED: | 516 case ui::ET_TOUCH_MOVED: |
516 case ui::ET_TOUCH_PRESSED: | 517 case ui::ET_TOUCH_PRESSED: |
517 case ui::ET_TOUCH_CANCELLED: | 518 case ui::ET_TOUCH_CANCELLED: |
518 case ui::ET_TOUCH_RELEASED: { | 519 case ui::ET_TOUCH_RELEASED: { |
519 #if defined(OS_CHROMEOS) | |
520 // Bail out early before generating a ui::TouchEvent if this event | 520 // Bail out early before generating a ui::TouchEvent if this event |
521 // is not within the range of this RootWindow. Converting an xevent | 521 // is not within the range of this RootWindow. Converting an xevent |
522 // to ui::TouchEvent might change the state of the global touch tracking | 522 // to ui::TouchEvent might change the state of the global touch tracking |
523 // state, e.g. touch release event can remove the touch id from the | 523 // state, e.g. touch release event can remove the touch id from the |
524 // record, and doing this multiple time when there are multiple | 524 // record, and doing this multiple time when there are multiple |
525 // RootWindow will cause problem. So only generate the ui::TouchEvent | 525 // RootWindow will cause problem. So only generate the ui::TouchEvent |
526 // when we are sure it belongs to this RootWindow. | 526 // when we are sure it belongs to this RootWindow. |
527 if (base::SysInfo::IsRunningOnChromeOS() && | 527 if (!IsTouchEventTargetingThisRootWindow(xev)) |
528 !bounds().Contains(ui::EventLocationFromNative(xev))) | |
529 return; | 528 return; |
530 #endif | |
531 ui::TouchEvent touchev(xev); | 529 ui::TouchEvent touchev(xev); |
530 ui::DeviceDataManager::GetInstance()->CalibrateTouchEvent( | |
531 &touchev, xiev->deviceid, bounds_); | |
532 TranslateAndDispatchLocatedEvent(&touchev); | 532 TranslateAndDispatchLocatedEvent(&touchev); |
533 break; | 533 break; |
534 } | 534 } |
535 case ui::ET_MOUSE_MOVED: | 535 case ui::ET_MOUSE_MOVED: |
536 case ui::ET_MOUSE_DRAGGED: | 536 case ui::ET_MOUSE_DRAGGED: |
537 case ui::ET_MOUSE_PRESSED: | 537 case ui::ET_MOUSE_PRESSED: |
538 case ui::ET_MOUSE_RELEASED: | 538 case ui::ET_MOUSE_RELEASED: |
539 case ui::ET_MOUSE_ENTERED: | 539 case ui::ET_MOUSE_ENTERED: |
540 case ui::ET_MOUSE_EXITED: { | 540 case ui::ET_MOUSE_EXITED: { |
541 if (type == ui::ET_MOUSE_MOVED || type == ui::ET_MOUSE_DRAGGED) { | 541 if (type == ui::ET_MOUSE_MOVED || type == ui::ET_MOUSE_DRAGGED) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); | 585 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); |
586 } | 586 } |
587 | 587 |
588 void WindowTreeHostX11::OnConfigureNotify() {} | 588 void WindowTreeHostX11::OnConfigureNotify() {} |
589 | 589 |
590 void WindowTreeHostX11::TranslateAndDispatchLocatedEvent( | 590 void WindowTreeHostX11::TranslateAndDispatchLocatedEvent( |
591 ui::LocatedEvent* event) { | 591 ui::LocatedEvent* event) { |
592 SendEventToProcessor(event); | 592 SendEventToProcessor(event); |
593 } | 593 } |
594 | 594 |
595 bool WindowTreeHostX11::IsTouchEventTargetingThisRootWindow(XEvent* xev) { | |
596 #if defined(OS_CHROMEOS) | |
597 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
598 int64 touch_display_id = | |
599 ui::DeviceDataManager::GetInstance()->GetDisplayForTouchDevice( | |
600 xiev->deviceid); | |
601 // If we don't have record of display id for this touch device, check | |
602 // that if the event is within the bound of the root window. Note | |
603 // that in multi-monitor case, the event position is in framebuffer | |
604 // space so the bounds check will not work so well. | |
605 if (touch_display_id == gfx::Display::kInvalidDisplayID) { | |
606 if (base::SysInfo::IsRunningOnChromeOS() && | |
607 !bounds_.Contains(ui::EventLocationFromNative(xev))) | |
608 return false; | |
609 } else if (touch_display_id != display_ids().first && | |
610 touch_display_id != display_ids().second) { | |
611 return false; | |
612 } | |
oshima
2014/04/30 16:19:05
Can you move chromeos specific code to ash/host/as
Yufeng Shen (Slow to review)
2014/04/30 16:42:42
The thing is IsTouchEventTargetingThisRootWindow(x
Yufeng Shen (Slow to review)
2014/04/30 19:16:44
as Sadrul suggested, moved this into AshWindowTree
| |
613 #endif // defined(OS_CHROMEOS) | |
614 return true; | |
615 } | |
616 | |
595 // static | 617 // static |
596 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { | 618 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
597 return new WindowTreeHostX11(bounds); | 619 return new WindowTreeHostX11(bounds); |
598 } | 620 } |
599 | 621 |
600 // static | 622 // static |
601 gfx::Size WindowTreeHost::GetNativeScreenSize() { | 623 gfx::Size WindowTreeHost::GetNativeScreenSize() { |
602 ::XDisplay* xdisplay = gfx::GetXDisplay(); | 624 ::XDisplay* xdisplay = gfx::GetXDisplay(); |
603 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 625 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
604 } | 626 } |
605 | 627 |
606 namespace test { | 628 namespace test { |
607 | 629 |
608 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { | 630 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { |
609 default_override_redirect = override_redirect; | 631 default_override_redirect = override_redirect; |
610 } | 632 } |
611 | 633 |
612 } // namespace test | 634 } // namespace test |
613 } // namespace aura | 635 } // namespace aura |
OLD | NEW |