| 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/Xfixes.h> | 9 #include <X11/extensions/Xfixes.h> |
| 10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "base/sys_info.h" | 29 #include "base/sys_info.h" |
| 30 #include "ui/aura/client/cursor_client.h" | 30 #include "ui/aura/client/cursor_client.h" |
| 31 #include "ui/aura/client/screen_position_client.h" | 31 #include "ui/aura/client/screen_position_client.h" |
| 32 #include "ui/aura/client/user_action_client.h" | 32 #include "ui/aura/client/user_action_client.h" |
| 33 #include "ui/aura/env.h" | 33 #include "ui/aura/env.h" |
| 34 #include "ui/aura/window_event_dispatcher.h" | 34 #include "ui/aura/window_event_dispatcher.h" |
| 35 #include "ui/base/cursor/cursor.h" | 35 #include "ui/base/cursor/cursor.h" |
| 36 #include "ui/base/ui_base_switches.h" | 36 #include "ui/base/ui_base_switches.h" |
| 37 #include "ui/base/view_prop.h" | 37 #include "ui/base/view_prop.h" |
| 38 #include "ui/base/x/x11_util.h" | 38 #include "ui/base/x/x11_util.h" |
| 39 #include "ui/compositor/compositor.h" | |
| 40 #include "ui/compositor/dip_util.h" | 39 #include "ui/compositor/dip_util.h" |
| 41 #include "ui/compositor/layer.h" | 40 #include "ui/compositor/layer.h" |
| 42 #include "ui/events/event.h" | 41 #include "ui/events/event.h" |
| 43 #include "ui/events/event_utils.h" | 42 #include "ui/events/event_utils.h" |
| 44 #include "ui/events/keycodes/keyboard_codes.h" | 43 #include "ui/events/keycodes/keyboard_codes.h" |
| 45 #include "ui/events/x/device_data_manager.h" | 44 #include "ui/events/x/device_data_manager.h" |
| 46 #include "ui/events/x/device_list_cache_x.h" | 45 #include "ui/events/x/device_list_cache_x.h" |
| 47 #include "ui/events/x/touch_factory_x11.h" | 46 #include "ui/events/x/touch_factory_x11.h" |
| 48 #include "ui/gfx/screen.h" | 47 #include "ui/gfx/screen.h" |
| 49 | 48 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 396 } |
| 398 case KeyRelease: { | 397 case KeyRelease: { |
| 399 ui::KeyEvent keyup_event(xev, false); | 398 ui::KeyEvent keyup_event(xev, false); |
| 400 SendEventToProcessor(&keyup_event); | 399 SendEventToProcessor(&keyup_event); |
| 401 break; | 400 break; |
| 402 } | 401 } |
| 403 case ButtonPress: { | 402 case ButtonPress: { |
| 404 if (static_cast<int>(xev->xbutton.button) == kBackMouseButton || | 403 if (static_cast<int>(xev->xbutton.button) == kBackMouseButton || |
| 405 static_cast<int>(xev->xbutton.button) == kForwardMouseButton) { | 404 static_cast<int>(xev->xbutton.button) == kForwardMouseButton) { |
| 406 client::UserActionClient* gesture_client = | 405 client::UserActionClient* gesture_client = |
| 407 client::GetUserActionClient(window()); | 406 client::GetUserActionClient(delegate_->AsDispatcher()->window()); |
| 408 if (gesture_client) { | 407 if (gesture_client) { |
| 409 gesture_client->OnUserAction( | 408 gesture_client->OnUserAction( |
| 410 static_cast<int>(xev->xbutton.button) == kBackMouseButton ? | 409 static_cast<int>(xev->xbutton.button) == kBackMouseButton ? |
| 411 client::UserActionClient::BACK : | 410 client::UserActionClient::BACK : |
| 412 client::UserActionClient::FORWARD); | 411 client::UserActionClient::FORWARD); |
| 413 } | 412 } |
| 414 break; | 413 break; |
| 415 } | 414 } |
| 416 } // fallthrough | 415 } // fallthrough |
| 417 case ButtonRelease: { | 416 case ButtonRelease: { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 430 case ui::ET_UNKNOWN: | 429 case ui::ET_UNKNOWN: |
| 431 // No event is created for X11-release events for mouse-wheel buttons. | 430 // No event is created for X11-release events for mouse-wheel buttons. |
| 432 break; | 431 break; |
| 433 default: | 432 default: |
| 434 NOTREACHED(); | 433 NOTREACHED(); |
| 435 } | 434 } |
| 436 break; | 435 break; |
| 437 } | 436 } |
| 438 case FocusOut: | 437 case FocusOut: |
| 439 if (xev->xfocus.mode != NotifyGrab) | 438 if (xev->xfocus.mode != NotifyGrab) |
| 440 OnHostLostWindowCapture(); | 439 delegate_->OnHostLostWindowCapture(); |
| 441 break; | 440 break; |
| 442 case ConfigureNotify: { | 441 case ConfigureNotify: { |
| 443 DCHECK_EQ(xwindow_, xev->xconfigure.event); | 442 DCHECK_EQ(xwindow_, xev->xconfigure.event); |
| 444 DCHECK_EQ(xwindow_, xev->xconfigure.window); | 443 DCHECK_EQ(xwindow_, xev->xconfigure.window); |
| 445 // It's possible that the X window may be resized by some other means | 444 // It's possible that the X window may be resized by some other means |
| 446 // than from within aura (e.g. the X window manager can change the | 445 // than from within aura (e.g. the X window manager can change the |
| 447 // size). Make sure the root window size is maintained properly. | 446 // size). Make sure the root window size is maintained properly. |
| 448 gfx::Rect bounds(xev->xconfigure.x, xev->xconfigure.y, | 447 gfx::Rect bounds(xev->xconfigure.x, xev->xconfigure.y, |
| 449 xev->xconfigure.width, xev->xconfigure.height); | 448 xev->xconfigure.width, xev->xconfigure.height); |
| 450 bool size_changed = bounds_.size() != bounds.size(); | 449 bool size_changed = bounds_.size() != bounds.size(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 } | 562 } |
| 564 | 563 |
| 565 gfx::Rect WindowTreeHostX11::GetBounds() const { | 564 gfx::Rect WindowTreeHostX11::GetBounds() const { |
| 566 return bounds_; | 565 return bounds_; |
| 567 } | 566 } |
| 568 | 567 |
| 569 void WindowTreeHostX11::SetBounds(const gfx::Rect& bounds) { | 568 void WindowTreeHostX11::SetBounds(const gfx::Rect& bounds) { |
| 570 // Even if the host window's size doesn't change, aura's root window | 569 // Even if the host window's size doesn't change, aura's root window |
| 571 // size, which is in DIP, changes when the scale changes. | 570 // size, which is in DIP, changes when the scale changes. |
| 572 float current_scale = compositor()->device_scale_factor(); | 571 float current_scale = compositor()->device_scale_factor(); |
| 573 float new_scale = gfx::Screen::GetScreenFor(window())-> | 572 float new_scale = gfx::Screen::GetScreenFor( |
| 574 GetDisplayNearestWindow(window()).device_scale_factor(); | 573 delegate_->AsDispatcher()->window())->GetDisplayNearestWindow( |
| 574 delegate_->AsDispatcher()->window()).device_scale_factor(); |
| 575 bool origin_changed = bounds_.origin() != bounds.origin(); | 575 bool origin_changed = bounds_.origin() != bounds.origin(); |
| 576 bool size_changed = bounds_.size() != bounds.size(); | 576 bool size_changed = bounds_.size() != bounds.size(); |
| 577 XWindowChanges changes = {0}; | 577 XWindowChanges changes = {0}; |
| 578 unsigned value_mask = 0; | 578 unsigned value_mask = 0; |
| 579 | 579 |
| 580 if (size_changed) { | 580 if (size_changed) { |
| 581 changes.width = bounds.width(); | 581 changes.width = bounds.width(); |
| 582 changes.height = bounds.height(); | 582 changes.height = bounds.height(); |
| 583 value_mask = CWHeight | CWWidth; | 583 value_mask = CWHeight | CWWidth; |
| 584 } | 584 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 596 // manager, it can modify or ignore the request, but (per ICCCM) we'll get a | 596 // manager, it can modify or ignore the request, but (per ICCCM) we'll get a |
| 597 // (possibly synthetic) ConfigureNotify about the actual size and correct | 597 // (possibly synthetic) ConfigureNotify about the actual size and correct |
| 598 // |bounds_| later. | 598 // |bounds_| later. |
| 599 bounds_ = bounds; | 599 bounds_ = bounds; |
| 600 UpdateIsInternalDisplay(); | 600 UpdateIsInternalDisplay(); |
| 601 if (origin_changed) | 601 if (origin_changed) |
| 602 OnHostMoved(bounds.origin()); | 602 OnHostMoved(bounds.origin()); |
| 603 if (size_changed || current_scale != new_scale) { | 603 if (size_changed || current_scale != new_scale) { |
| 604 OnHostResized(bounds.size()); | 604 OnHostResized(bounds.size()); |
| 605 } else { | 605 } else { |
| 606 window()->SchedulePaintInRect(window()->bounds()); | 606 delegate_->AsDispatcher()->window()->SchedulePaintInRect( |
| 607 delegate_->AsDispatcher()->window()->bounds()); |
| 607 } | 608 } |
| 608 } | 609 } |
| 609 | 610 |
| 610 gfx::Insets WindowTreeHostX11::GetInsets() const { | 611 gfx::Insets WindowTreeHostX11::GetInsets() const { |
| 611 return insets_; | 612 return insets_; |
| 612 } | 613 } |
| 613 | 614 |
| 614 void WindowTreeHostX11::SetInsets(const gfx::Insets& insets) { | 615 void WindowTreeHostX11::SetInsets(const gfx::Insets& insets) { |
| 615 insets_ = insets; | 616 insets_ = insets; |
| 616 if (pointer_barriers_) { | 617 if (pointer_barriers_) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 case KeyRelease: | 720 case KeyRelease: |
| 720 case ButtonPress: | 721 case ButtonPress: |
| 721 case ButtonRelease: { | 722 case ButtonRelease: { |
| 722 // The fields used below are in the same place for all of events | 723 // The fields used below are in the same place for all of events |
| 723 // above. Using xmotion from XEvent's unions to avoid repeating | 724 // above. Using xmotion from XEvent's unions to avoid repeating |
| 724 // the code. | 725 // the code. |
| 725 xevent.xmotion.root = x_root_window_; | 726 xevent.xmotion.root = x_root_window_; |
| 726 xevent.xmotion.time = CurrentTime; | 727 xevent.xmotion.time = CurrentTime; |
| 727 | 728 |
| 728 gfx::Point point(xevent.xmotion.x, xevent.xmotion.y); | 729 gfx::Point point(xevent.xmotion.x, xevent.xmotion.y); |
| 729 ConvertPointToNativeScreen(&point); | 730 delegate_->AsDispatcher()->host()->ConvertPointToNativeScreen(&point); |
| 730 xevent.xmotion.x_root = point.x(); | 731 xevent.xmotion.x_root = point.x(); |
| 731 xevent.xmotion.y_root = point.y(); | 732 xevent.xmotion.y_root = point.y(); |
| 732 } | 733 } |
| 733 default: | 734 default: |
| 734 break; | 735 break; |
| 735 } | 736 } |
| 736 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); | 737 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); |
| 737 } | 738 } |
| 738 | 739 |
| 739 void WindowTreeHostX11::OnDeviceScaleFactorChanged( | 740 void WindowTreeHostX11::OnDeviceScaleFactorChanged( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 759 | 760 |
| 760 void WindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { | 761 void WindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { |
| 761 SetCrOSTapPaused(!show); | 762 SetCrOSTapPaused(!show); |
| 762 } | 763 } |
| 763 | 764 |
| 764 void WindowTreeHostX11::OnWindowInitialized(Window* window) { | 765 void WindowTreeHostX11::OnWindowInitialized(Window* window) { |
| 765 } | 766 } |
| 766 | 767 |
| 767 void WindowTreeHostX11::OnRootWindowInitialized( | 768 void WindowTreeHostX11::OnRootWindowInitialized( |
| 768 WindowEventDispatcher* d) { | 769 WindowEventDispatcher* d) { |
| 769 // UpdateIsInternalDisplay relies on WED's kDisplayIdKey property being set | 770 // UpdateIsInternalDisplay relies on: |
| 770 // available by the time WED::Init is called. (set in | 771 // 1. delegate_ pointing to WindowEventDispatcher - available after |
| 771 // DisplayManager::CreateRootWindowForDisplay) | 772 // SetDelegate. |
| 773 // 2. WED's kDisplayIdKey property set - available by the time |
| 774 // WED::Init is called. |
| 775 // (set in DisplayManager::CreateRootWindowForDisplay) |
| 772 // Ready when NotifyRootWindowInitialized is called from WED::Init. | 776 // Ready when NotifyRootWindowInitialized is called from WED::Init. |
| 773 if (d != dispatcher()) | 777 if (!delegate_ || d != dispatcher()) |
| 774 return; | 778 return; |
| 775 UpdateIsInternalDisplay(); | 779 UpdateIsInternalDisplay(); |
| 776 | 780 |
| 777 // We have to enable Tap-to-click by default because the cursor is set to | 781 // We have to enable Tap-to-click by default because the cursor is set to |
| 778 // visible in Shell::InitRootWindowController. | 782 // visible in Shell::InitRootWindowController. |
| 779 SetCrOSTapPaused(false); | 783 SetCrOSTapPaused(false); |
| 780 } | 784 } |
| 781 | 785 |
| 782 ui::EventProcessor* WindowTreeHostX11::GetEventProcessor() { | 786 ui::EventProcessor* WindowTreeHostX11::GetEventProcessor() { |
| 783 return dispatcher(); | 787 return delegate_->GetEventProcessor(); |
| 784 } | 788 } |
| 785 | 789 |
| 786 void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { | 790 void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { |
| 787 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 791 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
| 788 XEvent* xev = event; | 792 XEvent* xev = event; |
| 789 if (!factory->ShouldProcessXI2Event(xev)) | 793 if (!factory->ShouldProcessXI2Event(xev)) |
| 790 return; | 794 return; |
| 791 | 795 |
| 792 TRACE_EVENT1("input", "WindowTreeHostX11::DispatchXI2Event", | 796 TRACE_EVENT1("input", "WindowTreeHostX11::DispatchXI2Event", |
| 793 "event_latency_us", | 797 "event_latency_us", |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 xev = &last_event; | 867 xev = &last_event; |
| 864 } else if (type == ui::ET_MOUSE_PRESSED || | 868 } else if (type == ui::ET_MOUSE_PRESSED || |
| 865 type == ui::ET_MOUSE_RELEASED) { | 869 type == ui::ET_MOUSE_RELEASED) { |
| 866 XIDeviceEvent* xievent = | 870 XIDeviceEvent* xievent = |
| 867 static_cast<XIDeviceEvent*>(xev->xcookie.data); | 871 static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 868 int button = xievent->detail; | 872 int button = xievent->detail; |
| 869 if (button == kBackMouseButton || button == kForwardMouseButton) { | 873 if (button == kBackMouseButton || button == kForwardMouseButton) { |
| 870 if (type == ui::ET_MOUSE_RELEASED) | 874 if (type == ui::ET_MOUSE_RELEASED) |
| 871 break; | 875 break; |
| 872 client::UserActionClient* gesture_client = | 876 client::UserActionClient* gesture_client = |
| 873 client::GetUserActionClient(window()); | 877 client::GetUserActionClient(delegate_->AsDispatcher()->window()); |
| 874 if (gesture_client) { | 878 if (gesture_client) { |
| 875 bool reverse_direction = | 879 bool reverse_direction = |
| 876 ui::IsTouchpadEvent(xev) && ui::IsNaturalScrollEnabled(); | 880 ui::IsTouchpadEvent(xev) && ui::IsNaturalScrollEnabled(); |
| 877 gesture_client->OnUserAction( | 881 gesture_client->OnUserAction( |
| 878 (button == kBackMouseButton && !reverse_direction) || | 882 (button == kBackMouseButton && !reverse_direction) || |
| 879 (button == kForwardMouseButton && reverse_direction) ? | 883 (button == kForwardMouseButton && reverse_direction) ? |
| 880 client::UserActionClient::BACK : | 884 client::UserActionClient::BACK : |
| 881 client::UserActionClient::FORWARD); | 885 client::UserActionClient::FORWARD); |
| 882 } | 886 } |
| 883 break; | 887 break; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 } | 998 } |
| 995 | 999 |
| 996 namespace test { | 1000 namespace test { |
| 997 | 1001 |
| 998 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { | 1002 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { |
| 999 default_override_redirect = override_redirect; | 1003 default_override_redirect = override_redirect; |
| 1000 } | 1004 } |
| 1001 | 1005 |
| 1002 } // namespace test | 1006 } // namespace test |
| 1003 } // namespace aura | 1007 } // namespace aura |
| OLD | NEW |