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/root_window_host_x11.h" | 5 #include "ui/aura/root_window_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/Xfixes.h> | 9 #include <X11/extensions/Xfixes.h> |
10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 int right_; | 269 int right_; |
270 int top_; | 270 int top_; |
271 int bottom_; | 271 int bottom_; |
272 | 272 |
273 DISALLOW_COPY_AND_ASSIGN(TouchEventCalibrate); | 273 DISALLOW_COPY_AND_ASSIGN(TouchEventCalibrate); |
274 }; | 274 }; |
275 | 275 |
276 } // namespace internal | 276 } // namespace internal |
277 | 277 |
278 //////////////////////////////////////////////////////////////////////////////// | 278 //////////////////////////////////////////////////////////////////////////////// |
279 // WindowTreeHostX11::MouseMoveFilter filters out the move events that | 279 // RootWindowHostX11::MouseMoveFilter filters out the move events that |
280 // jump back and forth between two points. This happens when sub pixel mouse | 280 // jump back and forth between two points. This happens when sub pixel mouse |
281 // move is enabled and mouse move events could be jumping between two neighbor | 281 // move is enabled and mouse move events could be jumping between two neighbor |
282 // pixels, e.g. move(0,0), move(1,0), move(0,0), move(1,0) and on and on. | 282 // pixels, e.g. move(0,0), move(1,0), move(0,0), move(1,0) and on and on. |
283 // The filtering is done by keeping track of the last two event locations and | 283 // The filtering is done by keeping track of the last two event locations and |
284 // provides a Filter method to find out whether a mouse event is in a different | 284 // provides a Filter method to find out whether a mouse event is in a different |
285 // location and should be processed. | 285 // location and should be processed. |
286 | 286 |
287 class WindowTreeHostX11::MouseMoveFilter { | 287 class RootWindowHostX11::MouseMoveFilter { |
288 public: | 288 public: |
289 MouseMoveFilter() : insert_index_(0) { | 289 MouseMoveFilter() : insert_index_(0) { |
290 for (size_t i = 0; i < kMaxEvents; ++i) { | 290 for (size_t i = 0; i < kMaxEvents; ++i) { |
291 const int int_max = std::numeric_limits<int>::max(); | 291 const int int_max = std::numeric_limits<int>::max(); |
292 recent_locations_[i] = gfx::Point(int_max, int_max); | 292 recent_locations_[i] = gfx::Point(int_max, int_max); |
293 } | 293 } |
294 } | 294 } |
295 ~MouseMoveFilter() {} | 295 ~MouseMoveFilter() {} |
296 | 296 |
297 // Returns true if |event| is known and should be ignored. | 297 // Returns true if |event| is known and should be ignored. |
(...skipping 12 matching lines...) Expand all Loading... |
310 private: | 310 private: |
311 static const size_t kMaxEvents = 2; | 311 static const size_t kMaxEvents = 2; |
312 | 312 |
313 gfx::Point recent_locations_[kMaxEvents]; | 313 gfx::Point recent_locations_[kMaxEvents]; |
314 size_t insert_index_; | 314 size_t insert_index_; |
315 | 315 |
316 DISALLOW_COPY_AND_ASSIGN(MouseMoveFilter); | 316 DISALLOW_COPY_AND_ASSIGN(MouseMoveFilter); |
317 }; | 317 }; |
318 | 318 |
319 //////////////////////////////////////////////////////////////////////////////// | 319 //////////////////////////////////////////////////////////////////////////////// |
320 // WindowTreeHostX11 | 320 // RootWindowHostX11 |
321 | 321 |
322 WindowTreeHostX11::WindowTreeHostX11(const gfx::Rect& bounds) | 322 RootWindowHostX11::RootWindowHostX11(const gfx::Rect& bounds) |
323 : xdisplay_(gfx::GetXDisplay()), | 323 : xdisplay_(gfx::GetXDisplay()), |
324 xwindow_(0), | 324 xwindow_(0), |
325 x_root_window_(DefaultRootWindow(xdisplay_)), | 325 x_root_window_(DefaultRootWindow(xdisplay_)), |
326 current_cursor_(ui::kCursorNull), | 326 current_cursor_(ui::kCursorNull), |
327 window_mapped_(false), | 327 window_mapped_(false), |
328 bounds_(bounds), | 328 bounds_(bounds), |
329 is_internal_display_(false), | 329 is_internal_display_(false), |
330 focus_when_shown_(false), | 330 focus_when_shown_(false), |
331 touch_calibrate_(new internal::TouchEventCalibrate), | 331 touch_calibrate_(new internal::TouchEventCalibrate), |
332 mouse_move_filter_(new MouseMoveFilter), | 332 mouse_move_filter_(new MouseMoveFilter), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 32, | 391 32, |
392 PropModeReplace, | 392 PropModeReplace, |
393 reinterpret_cast<unsigned char*>(&pid), 1); | 393 reinterpret_cast<unsigned char*>(&pid), 1); |
394 | 394 |
395 XRRSelectInput(xdisplay_, x_root_window_, | 395 XRRSelectInput(xdisplay_, x_root_window_, |
396 RRScreenChangeNotifyMask | RROutputChangeNotifyMask); | 396 RRScreenChangeNotifyMask | RROutputChangeNotifyMask); |
397 Env::GetInstance()->AddObserver(this); | 397 Env::GetInstance()->AddObserver(this); |
398 CreateCompositor(GetAcceleratedWidget()); | 398 CreateCompositor(GetAcceleratedWidget()); |
399 } | 399 } |
400 | 400 |
401 WindowTreeHostX11::~WindowTreeHostX11() { | 401 RootWindowHostX11::~RootWindowHostX11() { |
402 Env::GetInstance()->RemoveObserver(this); | 402 Env::GetInstance()->RemoveObserver(this); |
403 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); | 403 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); |
404 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); | 404 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); |
405 | 405 |
406 UnConfineCursor(); | 406 UnConfineCursor(); |
407 | 407 |
408 XDestroyWindow(xdisplay_, xwindow_); | 408 XDestroyWindow(xdisplay_, xwindow_); |
409 } | 409 } |
410 | 410 |
411 bool WindowTreeHostX11::Dispatch(const base::NativeEvent& event) { | 411 bool RootWindowHostX11::Dispatch(const base::NativeEvent& event) { |
412 XEvent* xev = event; | 412 XEvent* xev = event; |
413 | 413 |
414 if (FindEventTarget(event) == x_root_window_) | 414 if (FindEventTarget(event) == x_root_window_) |
415 return DispatchEventForRootWindow(event); | 415 return DispatchEventForRootWindow(event); |
416 | 416 |
417 switch (xev->type) { | 417 switch (xev->type) { |
418 case EnterNotify: { | 418 case EnterNotify: { |
419 aura::Window* root_window = GetRootWindow()->window(); | 419 aura::Window* root_window = GetRootWindow()->window(); |
420 client::CursorClient* cursor_client = | 420 client::CursorClient* cursor_client = |
421 client::GetCursorClient(root_window); | 421 client::GetCursorClient(root_window); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 // If there's no window manager running, we need to assign the X input | 522 // If there's no window manager running, we need to assign the X input |
523 // focus to our host window. | 523 // focus to our host window. |
524 if (!IsWindowManagerPresent() && focus_when_shown_) | 524 if (!IsWindowManagerPresent() && focus_when_shown_) |
525 XSetInputFocus(xdisplay_, xwindow_, RevertToNone, CurrentTime); | 525 XSetInputFocus(xdisplay_, xwindow_, RevertToNone, CurrentTime); |
526 break; | 526 break; |
527 } | 527 } |
528 case ClientMessage: { | 528 case ClientMessage: { |
529 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); | 529 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); |
530 if (message_type == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { | 530 if (message_type == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { |
531 // We have received a close message from the window manager. | 531 // We have received a close message from the window manager. |
532 delegate_->AsRootWindow()->OnWindowTreeHostCloseRequested(); | 532 delegate_->AsRootWindow()->OnRootWindowHostCloseRequested(); |
533 } else if (message_type == atom_cache_.GetAtom("_NET_WM_PING")) { | 533 } else if (message_type == atom_cache_.GetAtom("_NET_WM_PING")) { |
534 XEvent reply_event = *xev; | 534 XEvent reply_event = *xev; |
535 reply_event.xclient.window = x_root_window_; | 535 reply_event.xclient.window = x_root_window_; |
536 | 536 |
537 XSendEvent(xdisplay_, | 537 XSendEvent(xdisplay_, |
538 reply_event.xclient.window, | 538 reply_event.xclient.window, |
539 False, | 539 False, |
540 SubstructureRedirectMask | SubstructureNotifyMask, | 540 SubstructureRedirectMask | SubstructureNotifyMask, |
541 &reply_event); | 541 &reply_event); |
542 } | 542 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 } | 577 } |
578 | 578 |
579 ui::MouseEvent mouseev(xev); | 579 ui::MouseEvent mouseev(xev); |
580 TranslateAndDispatchMouseEvent(&mouseev); | 580 TranslateAndDispatchMouseEvent(&mouseev); |
581 break; | 581 break; |
582 } | 582 } |
583 } | 583 } |
584 return true; | 584 return true; |
585 } | 585 } |
586 | 586 |
587 RootWindow* WindowTreeHostX11::GetRootWindow() { | 587 RootWindow* RootWindowHostX11::GetRootWindow() { |
588 return delegate_->AsRootWindow(); | 588 return delegate_->AsRootWindow(); |
589 } | 589 } |
590 | 590 |
591 gfx::AcceleratedWidget WindowTreeHostX11::GetAcceleratedWidget() { | 591 gfx::AcceleratedWidget RootWindowHostX11::GetAcceleratedWidget() { |
592 return xwindow_; | 592 return xwindow_; |
593 } | 593 } |
594 | 594 |
595 void WindowTreeHostX11::Show() { | 595 void RootWindowHostX11::Show() { |
596 if (!window_mapped_) { | 596 if (!window_mapped_) { |
597 // Before we map the window, set size hints. Otherwise, some window managers | 597 // Before we map the window, set size hints. Otherwise, some window managers |
598 // will ignore toplevel XMoveWindow commands. | 598 // will ignore toplevel XMoveWindow commands. |
599 XSizeHints size_hints; | 599 XSizeHints size_hints; |
600 size_hints.flags = PPosition | PWinGravity; | 600 size_hints.flags = PPosition | PWinGravity; |
601 size_hints.x = bounds_.x(); | 601 size_hints.x = bounds_.x(); |
602 size_hints.y = bounds_.y(); | 602 size_hints.y = bounds_.y(); |
603 // Set StaticGravity so that the window position is not affected by the | 603 // Set StaticGravity so that the window position is not affected by the |
604 // frame width when running with window manager. | 604 // frame width when running with window manager. |
605 size_hints.win_gravity = StaticGravity; | 605 size_hints.win_gravity = StaticGravity; |
606 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); | 606 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); |
607 | 607 |
608 XMapWindow(xdisplay_, xwindow_); | 608 XMapWindow(xdisplay_, xwindow_); |
609 | 609 |
610 // We now block until our window is mapped. Some X11 APIs will crash and | 610 // We now block until our window is mapped. Some X11 APIs will crash and |
611 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is | 611 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is |
612 // asynchronous. | 612 // asynchronous. |
613 base::MessagePumpX11::Current()->BlockUntilWindowMapped(xwindow_); | 613 base::MessagePumpX11::Current()->BlockUntilWindowMapped(xwindow_); |
614 window_mapped_ = true; | 614 window_mapped_ = true; |
615 } | 615 } |
616 } | 616 } |
617 | 617 |
618 void WindowTreeHostX11::Hide() { | 618 void RootWindowHostX11::Hide() { |
619 if (window_mapped_) { | 619 if (window_mapped_) { |
620 XWithdrawWindow(xdisplay_, xwindow_, 0); | 620 XWithdrawWindow(xdisplay_, xwindow_, 0); |
621 window_mapped_ = false; | 621 window_mapped_ = false; |
622 } | 622 } |
623 } | 623 } |
624 | 624 |
625 void WindowTreeHostX11::ToggleFullScreen() { | 625 void RootWindowHostX11::ToggleFullScreen() { |
626 NOTIMPLEMENTED(); | 626 NOTIMPLEMENTED(); |
627 } | 627 } |
628 | 628 |
629 gfx::Rect WindowTreeHostX11::GetBounds() const { | 629 gfx::Rect RootWindowHostX11::GetBounds() const { |
630 return bounds_; | 630 return bounds_; |
631 } | 631 } |
632 | 632 |
633 void WindowTreeHostX11::SetBounds(const gfx::Rect& bounds) { | 633 void RootWindowHostX11::SetBounds(const gfx::Rect& bounds) { |
634 // Even if the host window's size doesn't change, aura's root window | 634 // Even if the host window's size doesn't change, aura's root window |
635 // size, which is in DIP, changes when the scale changes. | 635 // size, which is in DIP, changes when the scale changes. |
636 float current_scale = compositor()->device_scale_factor(); | 636 float current_scale = compositor()->device_scale_factor(); |
637 float new_scale = gfx::Screen::GetScreenFor( | 637 float new_scale = gfx::Screen::GetScreenFor( |
638 delegate_->AsRootWindow()->window())->GetDisplayNearestWindow( | 638 delegate_->AsRootWindow()->window())->GetDisplayNearestWindow( |
639 delegate_->AsRootWindow()->window()).device_scale_factor(); | 639 delegate_->AsRootWindow()->window()).device_scale_factor(); |
640 bool origin_changed = bounds_.origin() != bounds.origin(); | 640 bool origin_changed = bounds_.origin() != bounds.origin(); |
641 bool size_changed = bounds_.size() != bounds.size(); | 641 bool size_changed = bounds_.size() != bounds.size(); |
642 XWindowChanges changes = {0}; | 642 XWindowChanges changes = {0}; |
643 unsigned value_mask = 0; | 643 unsigned value_mask = 0; |
(...skipping 22 matching lines...) Expand all Loading... |
666 if (origin_changed) | 666 if (origin_changed) |
667 delegate_->OnHostMoved(bounds.origin()); | 667 delegate_->OnHostMoved(bounds.origin()); |
668 if (size_changed || current_scale != new_scale) { | 668 if (size_changed || current_scale != new_scale) { |
669 NotifyHostResized(bounds.size()); | 669 NotifyHostResized(bounds.size()); |
670 } else { | 670 } else { |
671 delegate_->AsRootWindow()->window()->SchedulePaintInRect( | 671 delegate_->AsRootWindow()->window()->SchedulePaintInRect( |
672 delegate_->AsRootWindow()->window()->bounds()); | 672 delegate_->AsRootWindow()->window()->bounds()); |
673 } | 673 } |
674 } | 674 } |
675 | 675 |
676 gfx::Insets WindowTreeHostX11::GetInsets() const { | 676 gfx::Insets RootWindowHostX11::GetInsets() const { |
677 return insets_; | 677 return insets_; |
678 } | 678 } |
679 | 679 |
680 void WindowTreeHostX11::SetInsets(const gfx::Insets& insets) { | 680 void RootWindowHostX11::SetInsets(const gfx::Insets& insets) { |
681 insets_ = insets; | 681 insets_ = insets; |
682 if (pointer_barriers_) { | 682 if (pointer_barriers_) { |
683 UnConfineCursor(); | 683 UnConfineCursor(); |
684 ConfineCursorToRootWindow(); | 684 ConfineCursorToRootWindow(); |
685 } | 685 } |
686 } | 686 } |
687 | 687 |
688 gfx::Point WindowTreeHostX11::GetLocationOnNativeScreen() const { | 688 gfx::Point RootWindowHostX11::GetLocationOnNativeScreen() const { |
689 return bounds_.origin(); | 689 return bounds_.origin(); |
690 } | 690 } |
691 | 691 |
692 void WindowTreeHostX11::SetCapture() { | 692 void RootWindowHostX11::SetCapture() { |
693 // TODO(oshima): Grab x input. | 693 // TODO(oshima): Grab x input. |
694 } | 694 } |
695 | 695 |
696 void WindowTreeHostX11::ReleaseCapture() { | 696 void RootWindowHostX11::ReleaseCapture() { |
697 // TODO(oshima): Release x input. | 697 // TODO(oshima): Release x input. |
698 } | 698 } |
699 | 699 |
700 void WindowTreeHostX11::SetCursor(gfx::NativeCursor cursor) { | 700 void RootWindowHostX11::SetCursor(gfx::NativeCursor cursor) { |
701 if (cursor == current_cursor_) | 701 if (cursor == current_cursor_) |
702 return; | 702 return; |
703 current_cursor_ = cursor; | 703 current_cursor_ = cursor; |
704 SetCursorInternal(cursor); | 704 SetCursorInternal(cursor); |
705 } | 705 } |
706 | 706 |
707 bool WindowTreeHostX11::QueryMouseLocation(gfx::Point* location_return) { | 707 bool RootWindowHostX11::QueryMouseLocation(gfx::Point* location_return) { |
708 client::CursorClient* cursor_client = | 708 client::CursorClient* cursor_client = |
709 client::GetCursorClient(GetRootWindow()->window()); | 709 client::GetCursorClient(GetRootWindow()->window()); |
710 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { | 710 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { |
711 *location_return = gfx::Point(0, 0); | 711 *location_return = gfx::Point(0, 0); |
712 return false; | 712 return false; |
713 } | 713 } |
714 | 714 |
715 ::Window root_return, child_return; | 715 ::Window root_return, child_return; |
716 int root_x_return, root_y_return, win_x_return, win_y_return; | 716 int root_x_return, root_y_return, win_x_return, win_y_return; |
717 unsigned int mask_return; | 717 unsigned int mask_return; |
718 XQueryPointer(xdisplay_, | 718 XQueryPointer(xdisplay_, |
719 xwindow_, | 719 xwindow_, |
720 &root_return, | 720 &root_return, |
721 &child_return, | 721 &child_return, |
722 &root_x_return, &root_y_return, | 722 &root_x_return, &root_y_return, |
723 &win_x_return, &win_y_return, | 723 &win_x_return, &win_y_return, |
724 &mask_return); | 724 &mask_return); |
725 *location_return = gfx::Point(max(0, min(bounds_.width(), win_x_return)), | 725 *location_return = gfx::Point(max(0, min(bounds_.width(), win_x_return)), |
726 max(0, min(bounds_.height(), win_y_return))); | 726 max(0, min(bounds_.height(), win_y_return))); |
727 return (win_x_return >= 0 && win_x_return < bounds_.width() && | 727 return (win_x_return >= 0 && win_x_return < bounds_.width() && |
728 win_y_return >= 0 && win_y_return < bounds_.height()); | 728 win_y_return >= 0 && win_y_return < bounds_.height()); |
729 } | 729 } |
730 | 730 |
731 bool WindowTreeHostX11::ConfineCursorToRootWindow() { | 731 bool RootWindowHostX11::ConfineCursorToRootWindow() { |
732 #if XFIXES_MAJOR >= 5 | 732 #if XFIXES_MAJOR >= 5 |
733 DCHECK(!pointer_barriers_.get()); | 733 DCHECK(!pointer_barriers_.get()); |
734 if (pointer_barriers_) | 734 if (pointer_barriers_) |
735 return false; | 735 return false; |
736 pointer_barriers_.reset(new XID[4]); | 736 pointer_barriers_.reset(new XID[4]); |
737 gfx::Rect bounds(bounds_); | 737 gfx::Rect bounds(bounds_); |
738 bounds.Inset(insets_); | 738 bounds.Inset(insets_); |
739 // Horizontal, top barriers. | 739 // Horizontal, top barriers. |
740 pointer_barriers_[0] = XFixesCreatePointerBarrier( | 740 pointer_barriers_[0] = XFixesCreatePointerBarrier( |
741 xdisplay_, x_root_window_, | 741 xdisplay_, x_root_window_, |
(...skipping 15 matching lines...) Expand all Loading... |
757 // Vertical, right barriers. | 757 // Vertical, right barriers. |
758 pointer_barriers_[3] = XFixesCreatePointerBarrier( | 758 pointer_barriers_[3] = XFixesCreatePointerBarrier( |
759 xdisplay_, x_root_window_, | 759 xdisplay_, x_root_window_, |
760 bounds.right(), bounds.y(), bounds.right(), bounds.bottom(), | 760 bounds.right(), bounds.y(), bounds.right(), bounds.bottom(), |
761 BarrierNegativeX, | 761 BarrierNegativeX, |
762 0, XIAllDevices); | 762 0, XIAllDevices); |
763 #endif | 763 #endif |
764 return true; | 764 return true; |
765 } | 765 } |
766 | 766 |
767 void WindowTreeHostX11::UnConfineCursor() { | 767 void RootWindowHostX11::UnConfineCursor() { |
768 #if XFIXES_MAJOR >= 5 | 768 #if XFIXES_MAJOR >= 5 |
769 if (pointer_barriers_) { | 769 if (pointer_barriers_) { |
770 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[0]); | 770 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[0]); |
771 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[1]); | 771 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[1]); |
772 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[2]); | 772 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[2]); |
773 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[3]); | 773 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[3]); |
774 pointer_barriers_.reset(); | 774 pointer_barriers_.reset(); |
775 } | 775 } |
776 #endif | 776 #endif |
777 } | 777 } |
778 | 778 |
779 void WindowTreeHostX11::OnCursorVisibilityChanged(bool show) { | 779 void RootWindowHostX11::OnCursorVisibilityChanged(bool show) { |
780 SetCrOSTapPaused(!show); | 780 SetCrOSTapPaused(!show); |
781 } | 781 } |
782 | 782 |
783 void WindowTreeHostX11::MoveCursorTo(const gfx::Point& location) { | 783 void RootWindowHostX11::MoveCursorTo(const gfx::Point& location) { |
784 XWarpPointer(xdisplay_, None, x_root_window_, 0, 0, 0, 0, | 784 XWarpPointer(xdisplay_, None, x_root_window_, 0, 0, 0, 0, |
785 bounds_.x() + location.x(), | 785 bounds_.x() + location.x(), |
786 bounds_.y() + location.y()); | 786 bounds_.y() + location.y()); |
787 } | 787 } |
788 | 788 |
789 void WindowTreeHostX11::PostNativeEvent( | 789 void RootWindowHostX11::PostNativeEvent( |
790 const base::NativeEvent& native_event) { | 790 const base::NativeEvent& native_event) { |
791 DCHECK(xwindow_); | 791 DCHECK(xwindow_); |
792 DCHECK(xdisplay_); | 792 DCHECK(xdisplay_); |
793 XEvent xevent = *native_event; | 793 XEvent xevent = *native_event; |
794 xevent.xany.display = xdisplay_; | 794 xevent.xany.display = xdisplay_; |
795 xevent.xany.window = xwindow_; | 795 xevent.xany.window = xwindow_; |
796 | 796 |
797 switch (xevent.type) { | 797 switch (xevent.type) { |
798 case EnterNotify: | 798 case EnterNotify: |
799 case LeaveNotify: | 799 case LeaveNotify: |
(...skipping 12 matching lines...) Expand all Loading... |
812 delegate_->AsRootWindow()->host()->ConvertPointToNativeScreen(&point); | 812 delegate_->AsRootWindow()->host()->ConvertPointToNativeScreen(&point); |
813 xevent.xmotion.x_root = point.x(); | 813 xevent.xmotion.x_root = point.x(); |
814 xevent.xmotion.y_root = point.y(); | 814 xevent.xmotion.y_root = point.y(); |
815 } | 815 } |
816 default: | 816 default: |
817 break; | 817 break; |
818 } | 818 } |
819 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); | 819 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); |
820 } | 820 } |
821 | 821 |
822 void WindowTreeHostX11::OnDeviceScaleFactorChanged( | 822 void RootWindowHostX11::OnDeviceScaleFactorChanged( |
823 float device_scale_factor) { | 823 float device_scale_factor) { |
824 } | 824 } |
825 | 825 |
826 void WindowTreeHostX11::PrepareForShutdown() { | 826 void RootWindowHostX11::PrepareForShutdown() { |
827 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); | 827 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); |
828 } | 828 } |
829 | 829 |
830 void WindowTreeHostX11::OnWindowInitialized(Window* window) { | 830 void RootWindowHostX11::OnWindowInitialized(Window* window) { |
831 } | 831 } |
832 | 832 |
833 void WindowTreeHostX11::OnRootWindowInitialized(RootWindow* root_window) { | 833 void RootWindowHostX11::OnRootWindowInitialized(RootWindow* root_window) { |
834 // UpdateIsInternalDisplay relies on: | 834 // UpdateIsInternalDisplay relies on: |
835 // 1. delegate_ pointing to RootWindow - available after SetDelegate. | 835 // 1. delegate_ pointing to RootWindow - available after SetDelegate. |
836 // 2. RootWindow's kDisplayIdKey property set - available by the time | 836 // 2. RootWindow's kDisplayIdKey property set - available by the time |
837 // RootWindow::Init is called. | 837 // RootWindow::Init is called. |
838 // (set in DisplayManager::CreateRootWindowForDisplay) | 838 // (set in DisplayManager::CreateRootWindowForDisplay) |
839 // Ready when NotifyRootWindowInitialized is called from RootWindow::Init. | 839 // Ready when NotifyRootWindowInitialized is called from RootWindow::Init. |
840 if (!delegate_ || root_window != GetRootWindow()) | 840 if (!delegate_ || root_window != GetRootWindow()) |
841 return; | 841 return; |
842 UpdateIsInternalDisplay(); | 842 UpdateIsInternalDisplay(); |
843 | 843 |
844 // We have to enable Tap-to-click by default because the cursor is set to | 844 // We have to enable Tap-to-click by default because the cursor is set to |
845 // visible in Shell::InitRootWindowController. | 845 // visible in Shell::InitRootWindowController. |
846 SetCrOSTapPaused(false); | 846 SetCrOSTapPaused(false); |
847 } | 847 } |
848 | 848 |
849 bool WindowTreeHostX11::DispatchEventForRootWindow( | 849 bool RootWindowHostX11::DispatchEventForRootWindow( |
850 const base::NativeEvent& event) { | 850 const base::NativeEvent& event) { |
851 switch (event->type) { | 851 switch (event->type) { |
852 case ConfigureNotify: | 852 case ConfigureNotify: |
853 DCHECK_EQ(x_root_window_, event->xconfigure.event); | 853 DCHECK_EQ(x_root_window_, event->xconfigure.event); |
854 x_root_bounds_.SetRect(event->xconfigure.x, event->xconfigure.y, | 854 x_root_bounds_.SetRect(event->xconfigure.x, event->xconfigure.y, |
855 event->xconfigure.width, event->xconfigure.height); | 855 event->xconfigure.width, event->xconfigure.height); |
856 break; | 856 break; |
857 | 857 |
858 case GenericEvent: | 858 case GenericEvent: |
859 DispatchXI2Event(event); | 859 DispatchXI2Event(event); |
860 break; | 860 break; |
861 } | 861 } |
862 | 862 |
863 return true; | 863 return true; |
864 } | 864 } |
865 | 865 |
866 void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { | 866 void RootWindowHostX11::DispatchXI2Event(const base::NativeEvent& event) { |
867 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 867 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
868 XEvent* xev = event; | 868 XEvent* xev = event; |
869 if (!factory->ShouldProcessXI2Event(xev)) | 869 if (!factory->ShouldProcessXI2Event(xev)) |
870 return; | 870 return; |
871 | 871 |
872 TRACE_EVENT1("input", "WindowTreeHostX11::DispatchXI2Event", | 872 TRACE_EVENT1("input", "RootWindowHostX11::DispatchXI2Event", |
873 "event_latency_us", | 873 "event_latency_us", |
874 (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). | 874 (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). |
875 InMicroseconds()); | 875 InMicroseconds()); |
876 | 876 |
877 ui::EventType type = ui::EventTypeFromNative(xev); | 877 ui::EventType type = ui::EventTypeFromNative(xev); |
878 XEvent last_event; | 878 XEvent last_event; |
879 int num_coalesced = 0; | 879 int num_coalesced = 0; |
880 | 880 |
881 switch (type) { | 881 switch (type) { |
882 case ui::ET_TOUCH_MOVED: | 882 case ui::ET_TOUCH_MOVED: |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 break; | 988 break; |
989 default: | 989 default: |
990 NOTREACHED(); | 990 NOTREACHED(); |
991 } | 991 } |
992 | 992 |
993 // If we coalesced an event we need to free its cookie. | 993 // If we coalesced an event we need to free its cookie. |
994 if (num_coalesced > 0) | 994 if (num_coalesced > 0) |
995 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); | 995 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); |
996 } | 996 } |
997 | 997 |
998 bool WindowTreeHostX11::IsWindowManagerPresent() { | 998 bool RootWindowHostX11::IsWindowManagerPresent() { |
999 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership | 999 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership |
1000 // of WM_Sn selections (where n is a screen number). | 1000 // of WM_Sn selections (where n is a screen number). |
1001 return XGetSelectionOwner( | 1001 return XGetSelectionOwner( |
1002 xdisplay_, atom_cache_.GetAtom("WM_S0")) != None; | 1002 xdisplay_, atom_cache_.GetAtom("WM_S0")) != None; |
1003 } | 1003 } |
1004 | 1004 |
1005 void WindowTreeHostX11::SetCursorInternal(gfx::NativeCursor cursor) { | 1005 void RootWindowHostX11::SetCursorInternal(gfx::NativeCursor cursor) { |
1006 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); | 1006 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); |
1007 } | 1007 } |
1008 | 1008 |
1009 void WindowTreeHostX11::TranslateAndDispatchMouseEvent( | 1009 void RootWindowHostX11::TranslateAndDispatchMouseEvent( |
1010 ui::MouseEvent* event) { | 1010 ui::MouseEvent* event) { |
1011 Window* root_window = GetRootWindow()->window(); | 1011 Window* root_window = GetRootWindow()->window(); |
1012 client::ScreenPositionClient* screen_position_client = | 1012 client::ScreenPositionClient* screen_position_client = |
1013 client::GetScreenPositionClient(root_window); | 1013 client::GetScreenPositionClient(root_window); |
1014 gfx::Rect local(bounds_.size()); | 1014 gfx::Rect local(bounds_.size()); |
1015 | 1015 |
1016 if (screen_position_client && !local.Contains(event->location())) { | 1016 if (screen_position_client && !local.Contains(event->location())) { |
1017 gfx::Point location(event->location()); | 1017 gfx::Point location(event->location()); |
1018 // In order to get the correct point in screen coordinates | 1018 // In order to get the correct point in screen coordinates |
1019 // during passive grab, we first need to find on which host window | 1019 // during passive grab, we first need to find on which host window |
1020 // the mouse is on, and find out the screen coordinates on that | 1020 // the mouse is on, and find out the screen coordinates on that |
1021 // host window, then convert it back to this host window's coordinate. | 1021 // host window, then convert it back to this host window's coordinate. |
1022 screen_position_client->ConvertHostPointToScreen(root_window, &location); | 1022 screen_position_client->ConvertHostPointToScreen(root_window, &location); |
1023 screen_position_client->ConvertPointFromScreen(root_window, &location); | 1023 screen_position_client->ConvertPointFromScreen(root_window, &location); |
1024 ConvertPointToHost(&location); | 1024 ConvertPointToHost(&location); |
1025 event->set_location(location); | 1025 event->set_location(location); |
1026 event->set_root_location(location); | 1026 event->set_root_location(location); |
1027 } | 1027 } |
1028 delegate_->OnHostMouseEvent(event); | 1028 delegate_->OnHostMouseEvent(event); |
1029 } | 1029 } |
1030 | 1030 |
1031 void WindowTreeHostX11::UpdateIsInternalDisplay() { | 1031 void RootWindowHostX11::UpdateIsInternalDisplay() { |
1032 Window* root_window = GetRootWindow()->window(); | 1032 Window* root_window = GetRootWindow()->window(); |
1033 gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window); | 1033 gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window); |
1034 gfx::Display display = screen->GetDisplayNearestWindow(root_window); | 1034 gfx::Display display = screen->GetDisplayNearestWindow(root_window); |
1035 is_internal_display_ = display.IsInternal(); | 1035 is_internal_display_ = display.IsInternal(); |
1036 } | 1036 } |
1037 | 1037 |
1038 void WindowTreeHostX11::SetCrOSTapPaused(bool state) { | 1038 void RootWindowHostX11::SetCrOSTapPaused(bool state) { |
1039 #if defined(OS_CHROMEOS) | 1039 #if defined(OS_CHROMEOS) |
1040 if (!ui::IsXInput2Available()) | 1040 if (!ui::IsXInput2Available()) |
1041 return; | 1041 return; |
1042 // Temporarily pause tap-to-click when the cursor is hidden. | 1042 // Temporarily pause tap-to-click when the cursor is hidden. |
1043 Atom prop = atom_cache_.GetAtom("Tap Paused"); | 1043 Atom prop = atom_cache_.GetAtom("Tap Paused"); |
1044 unsigned char value = state; | 1044 unsigned char value = state; |
1045 XIDeviceList dev_list = | 1045 XIDeviceList dev_list = |
1046 ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(xdisplay_); | 1046 ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(xdisplay_); |
1047 | 1047 |
1048 // Only slave pointer devices could possibly have tap-paused property. | 1048 // Only slave pointer devices could possibly have tap-paused property. |
(...skipping 10 matching lines...) Expand all Loading... |
1059 continue; | 1059 continue; |
1060 XFree(data); | 1060 XFree(data); |
1061 XIChangeProperty(xdisplay_, dev_list[i].deviceid, prop, XA_INTEGER, 8, | 1061 XIChangeProperty(xdisplay_, dev_list[i].deviceid, prop, XA_INTEGER, 8, |
1062 PropModeReplace, &value, 1); | 1062 PropModeReplace, &value, 1); |
1063 } | 1063 } |
1064 } | 1064 } |
1065 #endif | 1065 #endif |
1066 } | 1066 } |
1067 | 1067 |
1068 // static | 1068 // static |
1069 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { | 1069 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { |
1070 return new WindowTreeHostX11(bounds); | 1070 return new RootWindowHostX11(bounds); |
1071 } | 1071 } |
1072 | 1072 |
1073 // static | 1073 // static |
1074 gfx::Size WindowTreeHost::GetNativeScreenSize() { | 1074 gfx::Size RootWindowHost::GetNativeScreenSize() { |
1075 ::XDisplay* xdisplay = gfx::GetXDisplay(); | 1075 ::XDisplay* xdisplay = gfx::GetXDisplay(); |
1076 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 1076 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
1077 } | 1077 } |
1078 | 1078 |
1079 namespace test { | 1079 namespace test { |
1080 | 1080 |
1081 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { | 1081 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { |
1082 default_override_redirect = override_redirect; | 1082 default_override_redirect = override_redirect; |
1083 } | 1083 } |
1084 | 1084 |
1085 } // namespace test | 1085 } // namespace test |
1086 } // namespace aura | 1086 } // namespace aura |
OLD | NEW |