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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 int right_; | 259 int right_; |
260 int top_; | 260 int top_; |
261 int bottom_; | 261 int bottom_; |
262 | 262 |
263 DISALLOW_COPY_AND_ASSIGN(TouchEventCalibrate); | 263 DISALLOW_COPY_AND_ASSIGN(TouchEventCalibrate); |
264 }; | 264 }; |
265 | 265 |
266 } // namespace internal | 266 } // namespace internal |
267 | 267 |
268 //////////////////////////////////////////////////////////////////////////////// | 268 //////////////////////////////////////////////////////////////////////////////// |
269 // RootWindowHostX11::MouseMoveFilter filters out the move events that | 269 // WindowTreeHostX11::MouseMoveFilter filters out the move events that |
270 // jump back and forth between two points. This happens when sub pixel mouse | 270 // jump back and forth between two points. This happens when sub pixel mouse |
271 // move is enabled and mouse move events could be jumping between two neighbor | 271 // move is enabled and mouse move events could be jumping between two neighbor |
272 // pixels, e.g. move(0,0), move(1,0), move(0,0), move(1,0) and on and on. | 272 // pixels, e.g. move(0,0), move(1,0), move(0,0), move(1,0) and on and on. |
273 // The filtering is done by keeping track of the last two event locations and | 273 // The filtering is done by keeping track of the last two event locations and |
274 // provides a Filter method to find out whether a mouse event is in a different | 274 // provides a Filter method to find out whether a mouse event is in a different |
275 // location and should be processed. | 275 // location and should be processed. |
276 | 276 |
277 class RootWindowHostX11::MouseMoveFilter { | 277 class WindowTreeHostX11::MouseMoveFilter { |
278 public: | 278 public: |
279 MouseMoveFilter() : insert_index_(0) { | 279 MouseMoveFilter() : insert_index_(0) { |
280 for (size_t i = 0; i < kMaxEvents; ++i) { | 280 for (size_t i = 0; i < kMaxEvents; ++i) { |
281 const int int_max = std::numeric_limits<int>::max(); | 281 const int int_max = std::numeric_limits<int>::max(); |
282 recent_locations_[i] = gfx::Point(int_max, int_max); | 282 recent_locations_[i] = gfx::Point(int_max, int_max); |
283 } | 283 } |
284 } | 284 } |
285 ~MouseMoveFilter() {} | 285 ~MouseMoveFilter() {} |
286 | 286 |
287 // Returns true if |event| is known and should be ignored. | 287 // Returns true if |event| is known and should be ignored. |
(...skipping 12 matching lines...) Expand all Loading... |
300 private: | 300 private: |
301 static const size_t kMaxEvents = 2; | 301 static const size_t kMaxEvents = 2; |
302 | 302 |
303 gfx::Point recent_locations_[kMaxEvents]; | 303 gfx::Point recent_locations_[kMaxEvents]; |
304 size_t insert_index_; | 304 size_t insert_index_; |
305 | 305 |
306 DISALLOW_COPY_AND_ASSIGN(MouseMoveFilter); | 306 DISALLOW_COPY_AND_ASSIGN(MouseMoveFilter); |
307 }; | 307 }; |
308 | 308 |
309 //////////////////////////////////////////////////////////////////////////////// | 309 //////////////////////////////////////////////////////////////////////////////// |
310 // RootWindowHostX11 | 310 // WindowTreeHostX11 |
311 | 311 |
312 RootWindowHostX11::RootWindowHostX11(const gfx::Rect& bounds) | 312 WindowTreeHostX11::WindowTreeHostX11(const gfx::Rect& bounds) |
313 : xdisplay_(gfx::GetXDisplay()), | 313 : xdisplay_(gfx::GetXDisplay()), |
314 xwindow_(0), | 314 xwindow_(0), |
315 x_root_window_(DefaultRootWindow(xdisplay_)), | 315 x_root_window_(DefaultRootWindow(xdisplay_)), |
316 current_cursor_(ui::kCursorNull), | 316 current_cursor_(ui::kCursorNull), |
317 window_mapped_(false), | 317 window_mapped_(false), |
318 bounds_(bounds), | 318 bounds_(bounds), |
319 is_internal_display_(false), | 319 is_internal_display_(false), |
320 touch_calibrate_(new internal::TouchEventCalibrate), | 320 touch_calibrate_(new internal::TouchEventCalibrate), |
321 mouse_move_filter_(new MouseMoveFilter), | 321 mouse_move_filter_(new MouseMoveFilter), |
322 atom_cache_(xdisplay_, kAtomsToCache), | 322 atom_cache_(xdisplay_, kAtomsToCache), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 32, | 375 32, |
376 PropModeReplace, | 376 PropModeReplace, |
377 reinterpret_cast<unsigned char*>(&pid), 1); | 377 reinterpret_cast<unsigned char*>(&pid), 1); |
378 | 378 |
379 XRRSelectInput(xdisplay_, x_root_window_, | 379 XRRSelectInput(xdisplay_, x_root_window_, |
380 RRScreenChangeNotifyMask | RROutputChangeNotifyMask); | 380 RRScreenChangeNotifyMask | RROutputChangeNotifyMask); |
381 Env::GetInstance()->AddObserver(this); | 381 Env::GetInstance()->AddObserver(this); |
382 CreateCompositor(GetAcceleratedWidget()); | 382 CreateCompositor(GetAcceleratedWidget()); |
383 } | 383 } |
384 | 384 |
385 RootWindowHostX11::~RootWindowHostX11() { | 385 WindowTreeHostX11::~WindowTreeHostX11() { |
386 Env::GetInstance()->RemoveObserver(this); | 386 Env::GetInstance()->RemoveObserver(this); |
387 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); | 387 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); |
388 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); | 388 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); |
389 | 389 |
390 UnConfineCursor(); | 390 UnConfineCursor(); |
391 | 391 |
392 XDestroyWindow(xdisplay_, xwindow_); | 392 XDestroyWindow(xdisplay_, xwindow_); |
393 } | 393 } |
394 | 394 |
395 bool RootWindowHostX11::Dispatch(const base::NativeEvent& event) { | 395 bool WindowTreeHostX11::Dispatch(const base::NativeEvent& event) { |
396 XEvent* xev = event; | 396 XEvent* xev = event; |
397 | 397 |
398 if (FindEventTarget(event) == x_root_window_) | 398 if (FindEventTarget(event) == x_root_window_) |
399 return DispatchEventForRootWindow(event); | 399 return DispatchEventForRootWindow(event); |
400 | 400 |
401 switch (xev->type) { | 401 switch (xev->type) { |
402 case EnterNotify: { | 402 case EnterNotify: { |
403 aura::Window* root_window = GetRootWindow()->window(); | 403 aura::Window* root_window = GetRootWindow()->window(); |
404 client::CursorClient* cursor_client = | 404 client::CursorClient* cursor_client = |
405 client::GetCursorClient(root_window); | 405 client::GetCursorClient(root_window); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 delegate_->OnHostMoved(bounds_.origin()); | 499 delegate_->OnHostMoved(bounds_.origin()); |
500 break; | 500 break; |
501 } | 501 } |
502 case GenericEvent: | 502 case GenericEvent: |
503 DispatchXI2Event(event); | 503 DispatchXI2Event(event); |
504 break; | 504 break; |
505 case ClientMessage: { | 505 case ClientMessage: { |
506 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); | 506 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); |
507 if (message_type == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { | 507 if (message_type == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { |
508 // We have received a close message from the window manager. | 508 // We have received a close message from the window manager. |
509 delegate_->AsRootWindow()->OnRootWindowHostCloseRequested(); | 509 delegate_->AsRootWindow()->OnWindowTreeHostCloseRequested(); |
510 } else if (message_type == atom_cache_.GetAtom("_NET_WM_PING")) { | 510 } else if (message_type == atom_cache_.GetAtom("_NET_WM_PING")) { |
511 XEvent reply_event = *xev; | 511 XEvent reply_event = *xev; |
512 reply_event.xclient.window = x_root_window_; | 512 reply_event.xclient.window = x_root_window_; |
513 | 513 |
514 XSendEvent(xdisplay_, | 514 XSendEvent(xdisplay_, |
515 reply_event.xclient.window, | 515 reply_event.xclient.window, |
516 False, | 516 False, |
517 SubstructureRedirectMask | SubstructureNotifyMask, | 517 SubstructureRedirectMask | SubstructureNotifyMask, |
518 &reply_event); | 518 &reply_event); |
519 } | 519 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 } | 554 } |
555 | 555 |
556 ui::MouseEvent mouseev(xev); | 556 ui::MouseEvent mouseev(xev); |
557 TranslateAndDispatchMouseEvent(&mouseev); | 557 TranslateAndDispatchMouseEvent(&mouseev); |
558 break; | 558 break; |
559 } | 559 } |
560 } | 560 } |
561 return true; | 561 return true; |
562 } | 562 } |
563 | 563 |
564 RootWindow* RootWindowHostX11::GetRootWindow() { | 564 RootWindow* WindowTreeHostX11::GetRootWindow() { |
565 return delegate_->AsRootWindow(); | 565 return delegate_->AsRootWindow(); |
566 } | 566 } |
567 | 567 |
568 gfx::AcceleratedWidget RootWindowHostX11::GetAcceleratedWidget() { | 568 gfx::AcceleratedWidget WindowTreeHostX11::GetAcceleratedWidget() { |
569 return xwindow_; | 569 return xwindow_; |
570 } | 570 } |
571 | 571 |
572 void RootWindowHostX11::Show() { | 572 void WindowTreeHostX11::Show() { |
573 if (!window_mapped_) { | 573 if (!window_mapped_) { |
574 // Before we map the window, set size hints. Otherwise, some window managers | 574 // Before we map the window, set size hints. Otherwise, some window managers |
575 // will ignore toplevel XMoveWindow commands. | 575 // will ignore toplevel XMoveWindow commands. |
576 XSizeHints size_hints; | 576 XSizeHints size_hints; |
577 size_hints.flags = PPosition | PWinGravity; | 577 size_hints.flags = PPosition | PWinGravity; |
578 size_hints.x = bounds_.x(); | 578 size_hints.x = bounds_.x(); |
579 size_hints.y = bounds_.y(); | 579 size_hints.y = bounds_.y(); |
580 // Set StaticGravity so that the window position is not affected by the | 580 // Set StaticGravity so that the window position is not affected by the |
581 // frame width when running with window manager. | 581 // frame width when running with window manager. |
582 size_hints.win_gravity = StaticGravity; | 582 size_hints.win_gravity = StaticGravity; |
583 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); | 583 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); |
584 | 584 |
585 XMapWindow(xdisplay_, xwindow_); | 585 XMapWindow(xdisplay_, xwindow_); |
586 | 586 |
587 // We now block until our window is mapped. Some X11 APIs will crash and | 587 // We now block until our window is mapped. Some X11 APIs will crash and |
588 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is | 588 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is |
589 // asynchronous. | 589 // asynchronous. |
590 base::MessagePumpX11::Current()->BlockUntilWindowMapped(xwindow_); | 590 base::MessagePumpX11::Current()->BlockUntilWindowMapped(xwindow_); |
591 window_mapped_ = true; | 591 window_mapped_ = true; |
592 } | 592 } |
593 } | 593 } |
594 | 594 |
595 void RootWindowHostX11::Hide() { | 595 void WindowTreeHostX11::Hide() { |
596 if (window_mapped_) { | 596 if (window_mapped_) { |
597 XWithdrawWindow(xdisplay_, xwindow_, 0); | 597 XWithdrawWindow(xdisplay_, xwindow_, 0); |
598 window_mapped_ = false; | 598 window_mapped_ = false; |
599 } | 599 } |
600 } | 600 } |
601 | 601 |
602 void RootWindowHostX11::ToggleFullScreen() { | 602 void WindowTreeHostX11::ToggleFullScreen() { |
603 NOTIMPLEMENTED(); | 603 NOTIMPLEMENTED(); |
604 } | 604 } |
605 | 605 |
606 gfx::Rect RootWindowHostX11::GetBounds() const { | 606 gfx::Rect WindowTreeHostX11::GetBounds() const { |
607 return bounds_; | 607 return bounds_; |
608 } | 608 } |
609 | 609 |
610 void RootWindowHostX11::SetBounds(const gfx::Rect& bounds) { | 610 void WindowTreeHostX11::SetBounds(const gfx::Rect& bounds) { |
611 // Even if the host window's size doesn't change, aura's root window | 611 // Even if the host window's size doesn't change, aura's root window |
612 // size, which is in DIP, changes when the scale changes. | 612 // size, which is in DIP, changes when the scale changes. |
613 float current_scale = compositor()->device_scale_factor(); | 613 float current_scale = compositor()->device_scale_factor(); |
614 float new_scale = gfx::Screen::GetScreenFor( | 614 float new_scale = gfx::Screen::GetScreenFor( |
615 delegate_->AsRootWindow()->window())->GetDisplayNearestWindow( | 615 delegate_->AsRootWindow()->window())->GetDisplayNearestWindow( |
616 delegate_->AsRootWindow()->window()).device_scale_factor(); | 616 delegate_->AsRootWindow()->window()).device_scale_factor(); |
617 bool origin_changed = bounds_.origin() != bounds.origin(); | 617 bool origin_changed = bounds_.origin() != bounds.origin(); |
618 bool size_changed = bounds_.size() != bounds.size(); | 618 bool size_changed = bounds_.size() != bounds.size(); |
619 XWindowChanges changes = {0}; | 619 XWindowChanges changes = {0}; |
620 unsigned value_mask = 0; | 620 unsigned value_mask = 0; |
(...skipping 22 matching lines...) Expand all Loading... |
643 if (origin_changed) | 643 if (origin_changed) |
644 delegate_->OnHostMoved(bounds.origin()); | 644 delegate_->OnHostMoved(bounds.origin()); |
645 if (size_changed || current_scale != new_scale) { | 645 if (size_changed || current_scale != new_scale) { |
646 NotifyHostResized(bounds.size()); | 646 NotifyHostResized(bounds.size()); |
647 } else { | 647 } else { |
648 delegate_->AsRootWindow()->window()->SchedulePaintInRect( | 648 delegate_->AsRootWindow()->window()->SchedulePaintInRect( |
649 delegate_->AsRootWindow()->window()->bounds()); | 649 delegate_->AsRootWindow()->window()->bounds()); |
650 } | 650 } |
651 } | 651 } |
652 | 652 |
653 gfx::Insets RootWindowHostX11::GetInsets() const { | 653 gfx::Insets WindowTreeHostX11::GetInsets() const { |
654 return insets_; | 654 return insets_; |
655 } | 655 } |
656 | 656 |
657 void RootWindowHostX11::SetInsets(const gfx::Insets& insets) { | 657 void WindowTreeHostX11::SetInsets(const gfx::Insets& insets) { |
658 insets_ = insets; | 658 insets_ = insets; |
659 if (pointer_barriers_) { | 659 if (pointer_barriers_) { |
660 UnConfineCursor(); | 660 UnConfineCursor(); |
661 ConfineCursorToRootWindow(); | 661 ConfineCursorToRootWindow(); |
662 } | 662 } |
663 } | 663 } |
664 | 664 |
665 gfx::Point RootWindowHostX11::GetLocationOnNativeScreen() const { | 665 gfx::Point WindowTreeHostX11::GetLocationOnNativeScreen() const { |
666 return bounds_.origin(); | 666 return bounds_.origin(); |
667 } | 667 } |
668 | 668 |
669 void RootWindowHostX11::SetCapture() { | 669 void WindowTreeHostX11::SetCapture() { |
670 // TODO(oshima): Grab x input. | 670 // TODO(oshima): Grab x input. |
671 } | 671 } |
672 | 672 |
673 void RootWindowHostX11::ReleaseCapture() { | 673 void WindowTreeHostX11::ReleaseCapture() { |
674 // TODO(oshima): Release x input. | 674 // TODO(oshima): Release x input. |
675 } | 675 } |
676 | 676 |
677 void RootWindowHostX11::SetCursor(gfx::NativeCursor cursor) { | 677 void WindowTreeHostX11::SetCursor(gfx::NativeCursor cursor) { |
678 if (cursor == current_cursor_) | 678 if (cursor == current_cursor_) |
679 return; | 679 return; |
680 current_cursor_ = cursor; | 680 current_cursor_ = cursor; |
681 SetCursorInternal(cursor); | 681 SetCursorInternal(cursor); |
682 } | 682 } |
683 | 683 |
684 bool RootWindowHostX11::QueryMouseLocation(gfx::Point* location_return) { | 684 bool WindowTreeHostX11::QueryMouseLocation(gfx::Point* location_return) { |
685 client::CursorClient* cursor_client = | 685 client::CursorClient* cursor_client = |
686 client::GetCursorClient(GetRootWindow()->window()); | 686 client::GetCursorClient(GetRootWindow()->window()); |
687 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { | 687 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { |
688 *location_return = gfx::Point(0, 0); | 688 *location_return = gfx::Point(0, 0); |
689 return false; | 689 return false; |
690 } | 690 } |
691 | 691 |
692 ::Window root_return, child_return; | 692 ::Window root_return, child_return; |
693 int root_x_return, root_y_return, win_x_return, win_y_return; | 693 int root_x_return, root_y_return, win_x_return, win_y_return; |
694 unsigned int mask_return; | 694 unsigned int mask_return; |
695 XQueryPointer(xdisplay_, | 695 XQueryPointer(xdisplay_, |
696 xwindow_, | 696 xwindow_, |
697 &root_return, | 697 &root_return, |
698 &child_return, | 698 &child_return, |
699 &root_x_return, &root_y_return, | 699 &root_x_return, &root_y_return, |
700 &win_x_return, &win_y_return, | 700 &win_x_return, &win_y_return, |
701 &mask_return); | 701 &mask_return); |
702 *location_return = gfx::Point(max(0, min(bounds_.width(), win_x_return)), | 702 *location_return = gfx::Point(max(0, min(bounds_.width(), win_x_return)), |
703 max(0, min(bounds_.height(), win_y_return))); | 703 max(0, min(bounds_.height(), win_y_return))); |
704 return (win_x_return >= 0 && win_x_return < bounds_.width() && | 704 return (win_x_return >= 0 && win_x_return < bounds_.width() && |
705 win_y_return >= 0 && win_y_return < bounds_.height()); | 705 win_y_return >= 0 && win_y_return < bounds_.height()); |
706 } | 706 } |
707 | 707 |
708 bool RootWindowHostX11::ConfineCursorToRootWindow() { | 708 bool WindowTreeHostX11::ConfineCursorToRootWindow() { |
709 #if XFIXES_MAJOR >= 5 | 709 #if XFIXES_MAJOR >= 5 |
710 DCHECK(!pointer_barriers_.get()); | 710 DCHECK(!pointer_barriers_.get()); |
711 if (pointer_barriers_) | 711 if (pointer_barriers_) |
712 return false; | 712 return false; |
713 pointer_barriers_.reset(new XID[4]); | 713 pointer_barriers_.reset(new XID[4]); |
714 gfx::Rect bounds(bounds_); | 714 gfx::Rect bounds(bounds_); |
715 bounds.Inset(insets_); | 715 bounds.Inset(insets_); |
716 // Horizontal, top barriers. | 716 // Horizontal, top barriers. |
717 pointer_barriers_[0] = XFixesCreatePointerBarrier( | 717 pointer_barriers_[0] = XFixesCreatePointerBarrier( |
718 xdisplay_, x_root_window_, | 718 xdisplay_, x_root_window_, |
(...skipping 15 matching lines...) Expand all Loading... |
734 // Vertical, right barriers. | 734 // Vertical, right barriers. |
735 pointer_barriers_[3] = XFixesCreatePointerBarrier( | 735 pointer_barriers_[3] = XFixesCreatePointerBarrier( |
736 xdisplay_, x_root_window_, | 736 xdisplay_, x_root_window_, |
737 bounds.right(), bounds.y(), bounds.right(), bounds.bottom(), | 737 bounds.right(), bounds.y(), bounds.right(), bounds.bottom(), |
738 BarrierNegativeX, | 738 BarrierNegativeX, |
739 0, XIAllDevices); | 739 0, XIAllDevices); |
740 #endif | 740 #endif |
741 return true; | 741 return true; |
742 } | 742 } |
743 | 743 |
744 void RootWindowHostX11::UnConfineCursor() { | 744 void WindowTreeHostX11::UnConfineCursor() { |
745 #if XFIXES_MAJOR >= 5 | 745 #if XFIXES_MAJOR >= 5 |
746 if (pointer_barriers_) { | 746 if (pointer_barriers_) { |
747 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[0]); | 747 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[0]); |
748 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[1]); | 748 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[1]); |
749 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[2]); | 749 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[2]); |
750 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[3]); | 750 XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[3]); |
751 pointer_barriers_.reset(); | 751 pointer_barriers_.reset(); |
752 } | 752 } |
753 #endif | 753 #endif |
754 } | 754 } |
755 | 755 |
756 void RootWindowHostX11::OnCursorVisibilityChanged(bool show) { | 756 void WindowTreeHostX11::OnCursorVisibilityChanged(bool show) { |
757 SetCrOSTapPaused(!show); | 757 SetCrOSTapPaused(!show); |
758 } | 758 } |
759 | 759 |
760 void RootWindowHostX11::MoveCursorTo(const gfx::Point& location) { | 760 void WindowTreeHostX11::MoveCursorTo(const gfx::Point& location) { |
761 XWarpPointer(xdisplay_, None, x_root_window_, 0, 0, 0, 0, | 761 XWarpPointer(xdisplay_, None, x_root_window_, 0, 0, 0, 0, |
762 bounds_.x() + location.x(), | 762 bounds_.x() + location.x(), |
763 bounds_.y() + location.y()); | 763 bounds_.y() + location.y()); |
764 } | 764 } |
765 | 765 |
766 void RootWindowHostX11::PostNativeEvent( | 766 void WindowTreeHostX11::PostNativeEvent( |
767 const base::NativeEvent& native_event) { | 767 const base::NativeEvent& native_event) { |
768 DCHECK(xwindow_); | 768 DCHECK(xwindow_); |
769 DCHECK(xdisplay_); | 769 DCHECK(xdisplay_); |
770 XEvent xevent = *native_event; | 770 XEvent xevent = *native_event; |
771 xevent.xany.display = xdisplay_; | 771 xevent.xany.display = xdisplay_; |
772 xevent.xany.window = xwindow_; | 772 xevent.xany.window = xwindow_; |
773 | 773 |
774 switch (xevent.type) { | 774 switch (xevent.type) { |
775 case EnterNotify: | 775 case EnterNotify: |
776 case LeaveNotify: | 776 case LeaveNotify: |
(...skipping 12 matching lines...) Expand all Loading... |
789 delegate_->AsRootWindow()->host()->ConvertPointToNativeScreen(&point); | 789 delegate_->AsRootWindow()->host()->ConvertPointToNativeScreen(&point); |
790 xevent.xmotion.x_root = point.x(); | 790 xevent.xmotion.x_root = point.x(); |
791 xevent.xmotion.y_root = point.y(); | 791 xevent.xmotion.y_root = point.y(); |
792 } | 792 } |
793 default: | 793 default: |
794 break; | 794 break; |
795 } | 795 } |
796 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); | 796 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); |
797 } | 797 } |
798 | 798 |
799 void RootWindowHostX11::OnDeviceScaleFactorChanged( | 799 void WindowTreeHostX11::OnDeviceScaleFactorChanged( |
800 float device_scale_factor) { | 800 float device_scale_factor) { |
801 } | 801 } |
802 | 802 |
803 void RootWindowHostX11::PrepareForShutdown() { | 803 void WindowTreeHostX11::PrepareForShutdown() { |
804 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); | 804 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); |
805 } | 805 } |
806 | 806 |
807 void RootWindowHostX11::OnWindowInitialized(Window* window) { | 807 void WindowTreeHostX11::OnWindowInitialized(Window* window) { |
808 } | 808 } |
809 | 809 |
810 void RootWindowHostX11::OnRootWindowInitialized(RootWindow* root_window) { | 810 void WindowTreeHostX11::OnRootWindowInitialized(RootWindow* root_window) { |
811 // UpdateIsInternalDisplay relies on: | 811 // UpdateIsInternalDisplay relies on: |
812 // 1. delegate_ pointing to RootWindow - available after SetDelegate. | 812 // 1. delegate_ pointing to RootWindow - available after SetDelegate. |
813 // 2. RootWindow's kDisplayIdKey property set - available by the time | 813 // 2. RootWindow's kDisplayIdKey property set - available by the time |
814 // RootWindow::Init is called. | 814 // RootWindow::Init is called. |
815 // (set in DisplayManager::CreateRootWindowForDisplay) | 815 // (set in DisplayManager::CreateRootWindowForDisplay) |
816 // Ready when NotifyRootWindowInitialized is called from RootWindow::Init. | 816 // Ready when NotifyRootWindowInitialized is called from RootWindow::Init. |
817 if (!delegate_ || root_window != GetRootWindow()) | 817 if (!delegate_ || root_window != GetRootWindow()) |
818 return; | 818 return; |
819 UpdateIsInternalDisplay(); | 819 UpdateIsInternalDisplay(); |
820 | 820 |
821 // We have to enable Tap-to-click by default because the cursor is set to | 821 // We have to enable Tap-to-click by default because the cursor is set to |
822 // visible in Shell::InitRootWindowController. | 822 // visible in Shell::InitRootWindowController. |
823 SetCrOSTapPaused(false); | 823 SetCrOSTapPaused(false); |
824 } | 824 } |
825 | 825 |
826 ui::EventProcessor* RootWindowHostX11::GetEventProcessor() { | 826 ui::EventProcessor* WindowTreeHostX11::GetEventProcessor() { |
827 return delegate_->GetEventProcessor(); | 827 return delegate_->GetEventProcessor(); |
828 } | 828 } |
829 | 829 |
830 bool RootWindowHostX11::DispatchEventForRootWindow( | 830 bool WindowTreeHostX11::DispatchEventForRootWindow( |
831 const base::NativeEvent& event) { | 831 const base::NativeEvent& event) { |
832 switch (event->type) { | 832 switch (event->type) { |
833 case GenericEvent: | 833 case GenericEvent: |
834 DispatchXI2Event(event); | 834 DispatchXI2Event(event); |
835 break; | 835 break; |
836 } | 836 } |
837 | 837 |
838 return true; | 838 return true; |
839 } | 839 } |
840 | 840 |
841 void RootWindowHostX11::DispatchXI2Event(const base::NativeEvent& event) { | 841 void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { |
842 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 842 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
843 XEvent* xev = event; | 843 XEvent* xev = event; |
844 if (!factory->ShouldProcessXI2Event(xev)) | 844 if (!factory->ShouldProcessXI2Event(xev)) |
845 return; | 845 return; |
846 | 846 |
847 TRACE_EVENT1("input", "RootWindowHostX11::DispatchXI2Event", | 847 TRACE_EVENT1("input", "WindowTreeHostX11::DispatchXI2Event", |
848 "event_latency_us", | 848 "event_latency_us", |
849 (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). | 849 (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). |
850 InMicroseconds()); | 850 InMicroseconds()); |
851 | 851 |
852 ui::EventType type = ui::EventTypeFromNative(xev); | 852 ui::EventType type = ui::EventTypeFromNative(xev); |
853 XEvent last_event; | 853 XEvent last_event; |
854 int num_coalesced = 0; | 854 int num_coalesced = 0; |
855 | 855 |
856 switch (type) { | 856 switch (type) { |
857 case ui::ET_TOUCH_MOVED: | 857 case ui::ET_TOUCH_MOVED: |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 break; | 963 break; |
964 default: | 964 default: |
965 NOTREACHED(); | 965 NOTREACHED(); |
966 } | 966 } |
967 | 967 |
968 // If we coalesced an event we need to free its cookie. | 968 // If we coalesced an event we need to free its cookie. |
969 if (num_coalesced > 0) | 969 if (num_coalesced > 0) |
970 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); | 970 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); |
971 } | 971 } |
972 | 972 |
973 bool RootWindowHostX11::IsWindowManagerPresent() { | 973 bool WindowTreeHostX11::IsWindowManagerPresent() { |
974 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership | 974 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership |
975 // of WM_Sn selections (where n is a screen number). | 975 // of WM_Sn selections (where n is a screen number). |
976 return XGetSelectionOwner( | 976 return XGetSelectionOwner( |
977 xdisplay_, atom_cache_.GetAtom("WM_S0")) != None; | 977 xdisplay_, atom_cache_.GetAtom("WM_S0")) != None; |
978 } | 978 } |
979 | 979 |
980 void RootWindowHostX11::SetCursorInternal(gfx::NativeCursor cursor) { | 980 void WindowTreeHostX11::SetCursorInternal(gfx::NativeCursor cursor) { |
981 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); | 981 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); |
982 } | 982 } |
983 | 983 |
984 void RootWindowHostX11::TranslateAndDispatchMouseEvent( | 984 void WindowTreeHostX11::TranslateAndDispatchMouseEvent( |
985 ui::MouseEvent* event) { | 985 ui::MouseEvent* event) { |
986 Window* root_window = GetRootWindow()->window(); | 986 Window* root_window = GetRootWindow()->window(); |
987 client::ScreenPositionClient* screen_position_client = | 987 client::ScreenPositionClient* screen_position_client = |
988 client::GetScreenPositionClient(root_window); | 988 client::GetScreenPositionClient(root_window); |
989 gfx::Rect local(bounds_.size()); | 989 gfx::Rect local(bounds_.size()); |
990 | 990 |
991 if (screen_position_client && !local.Contains(event->location())) { | 991 if (screen_position_client && !local.Contains(event->location())) { |
992 gfx::Point location(event->location()); | 992 gfx::Point location(event->location()); |
993 // In order to get the correct point in screen coordinates | 993 // In order to get the correct point in screen coordinates |
994 // during passive grab, we first need to find on which host window | 994 // during passive grab, we first need to find on which host window |
995 // the mouse is on, and find out the screen coordinates on that | 995 // the mouse is on, and find out the screen coordinates on that |
996 // host window, then convert it back to this host window's coordinate. | 996 // host window, then convert it back to this host window's coordinate. |
997 screen_position_client->ConvertHostPointToScreen(root_window, &location); | 997 screen_position_client->ConvertHostPointToScreen(root_window, &location); |
998 screen_position_client->ConvertPointFromScreen(root_window, &location); | 998 screen_position_client->ConvertPointFromScreen(root_window, &location); |
999 ConvertPointToHost(&location); | 999 ConvertPointToHost(&location); |
1000 event->set_location(location); | 1000 event->set_location(location); |
1001 event->set_root_location(location); | 1001 event->set_root_location(location); |
1002 } | 1002 } |
1003 delegate_->OnHostMouseEvent(event); | 1003 delegate_->OnHostMouseEvent(event); |
1004 } | 1004 } |
1005 | 1005 |
1006 void RootWindowHostX11::UpdateIsInternalDisplay() { | 1006 void WindowTreeHostX11::UpdateIsInternalDisplay() { |
1007 Window* root_window = GetRootWindow()->window(); | 1007 Window* root_window = GetRootWindow()->window(); |
1008 gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window); | 1008 gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window); |
1009 gfx::Display display = screen->GetDisplayNearestWindow(root_window); | 1009 gfx::Display display = screen->GetDisplayNearestWindow(root_window); |
1010 is_internal_display_ = display.IsInternal(); | 1010 is_internal_display_ = display.IsInternal(); |
1011 } | 1011 } |
1012 | 1012 |
1013 void RootWindowHostX11::SetCrOSTapPaused(bool state) { | 1013 void WindowTreeHostX11::SetCrOSTapPaused(bool state) { |
1014 #if defined(OS_CHROMEOS) | 1014 #if defined(OS_CHROMEOS) |
1015 if (!ui::IsXInput2Available()) | 1015 if (!ui::IsXInput2Available()) |
1016 return; | 1016 return; |
1017 // Temporarily pause tap-to-click when the cursor is hidden. | 1017 // Temporarily pause tap-to-click when the cursor is hidden. |
1018 Atom prop = atom_cache_.GetAtom("Tap Paused"); | 1018 Atom prop = atom_cache_.GetAtom("Tap Paused"); |
1019 unsigned char value = state; | 1019 unsigned char value = state; |
1020 XIDeviceList dev_list = | 1020 XIDeviceList dev_list = |
1021 ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(xdisplay_); | 1021 ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(xdisplay_); |
1022 | 1022 |
1023 // Only slave pointer devices could possibly have tap-paused property. | 1023 // Only slave pointer devices could possibly have tap-paused property. |
(...skipping 10 matching lines...) Expand all Loading... |
1034 continue; | 1034 continue; |
1035 XFree(data); | 1035 XFree(data); |
1036 XIChangeProperty(xdisplay_, dev_list[i].deviceid, prop, XA_INTEGER, 8, | 1036 XIChangeProperty(xdisplay_, dev_list[i].deviceid, prop, XA_INTEGER, 8, |
1037 PropModeReplace, &value, 1); | 1037 PropModeReplace, &value, 1); |
1038 } | 1038 } |
1039 } | 1039 } |
1040 #endif | 1040 #endif |
1041 } | 1041 } |
1042 | 1042 |
1043 // static | 1043 // static |
1044 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { | 1044 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
1045 return new RootWindowHostX11(bounds); | 1045 return new WindowTreeHostX11(bounds); |
1046 } | 1046 } |
1047 | 1047 |
1048 // static | 1048 // static |
1049 gfx::Size RootWindowHost::GetNativeScreenSize() { | 1049 gfx::Size WindowTreeHost::GetNativeScreenSize() { |
1050 ::XDisplay* xdisplay = gfx::GetXDisplay(); | 1050 ::XDisplay* xdisplay = gfx::GetXDisplay(); |
1051 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 1051 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
1052 } | 1052 } |
1053 | 1053 |
1054 namespace test { | 1054 namespace test { |
1055 | 1055 |
1056 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { | 1056 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { |
1057 default_override_redirect = override_redirect; | 1057 default_override_redirect = override_redirect; |
1058 } | 1058 } |
1059 | 1059 |
1060 } // namespace test | 1060 } // namespace test |
1061 } // namespace aura | 1061 } // namespace aura |
OLD | NEW |