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/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 5 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
6 | 6 |
7 #include <X11/extensions/shape.h> | 7 #include <X11/extensions/shape.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
10 #include <X11/Xregion.h> | 10 #include <X11/Xregion.h> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "ui/views/ime/input_method.h" | 42 #include "ui/views/ime/input_method.h" |
43 #include "ui/views/linux_ui/linux_ui.h" | 43 #include "ui/views/linux_ui/linux_ui.h" |
44 #include "ui/views/views_delegate.h" | 44 #include "ui/views/views_delegate.h" |
45 #include "ui/views/views_switches.h" | 45 #include "ui/views/views_switches.h" |
46 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" | 46 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" |
47 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" | 47 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" |
48 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 48 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
49 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_observer_x11.h" | 49 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_observer_x11.h" |
50 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" | 50 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" |
51 #include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h" | 51 #include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h" |
52 #include "ui/views/widget/desktop_aura/x11_scoped_capture.h" | |
53 #include "ui/views/widget/desktop_aura/x11_window_event_filter.h" | 52 #include "ui/views/widget/desktop_aura/x11_window_event_filter.h" |
54 #include "ui/wm/core/compound_event_filter.h" | 53 #include "ui/wm/core/compound_event_filter.h" |
55 #include "ui/wm/core/window_util.h" | 54 #include "ui/wm/core/window_util.h" |
56 | 55 |
57 namespace views { | 56 namespace views { |
58 | 57 |
59 DesktopWindowTreeHostX11* DesktopWindowTreeHostX11::g_current_capture = | 58 DesktopWindowTreeHostX11* DesktopWindowTreeHostX11::g_current_capture = |
60 NULL; | 59 NULL; |
61 std::list<XID>* DesktopWindowTreeHostX11::open_windows_ = NULL; | 60 std::list<XID>* DesktopWindowTreeHostX11::open_windows_ = NULL; |
62 | 61 |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 OnHostResized(bounds.size()); | 924 OnHostResized(bounds.size()); |
926 ResetWindowRegion(); | 925 ResetWindowRegion(); |
927 } | 926 } |
928 } | 927 } |
929 | 928 |
930 gfx::Point DesktopWindowTreeHostX11::GetLocationOnNativeScreen() const { | 929 gfx::Point DesktopWindowTreeHostX11::GetLocationOnNativeScreen() const { |
931 return bounds_.origin(); | 930 return bounds_.origin(); |
932 } | 931 } |
933 | 932 |
934 void DesktopWindowTreeHostX11::SetCapture() { | 933 void DesktopWindowTreeHostX11::SetCapture() { |
935 // This is vaguely based on the old NativeWidgetGtk implementation. | 934 // Grabbing the mouse is asynchronous. However, we synchronously start |
936 // | 935 // forwarding all mouse events received by Chrome to the |
937 // X11's XPointerGrab() shouldn't be used for everything; it doesn't map | 936 // aura::WindowEventDispatcher which has capture. This makes capture |
938 // cleanly to Windows' SetCapture(). GTK only provides a separate concept of | 937 // synchronous for all intents and purposes if either: |
939 // a grab that wasn't the X11 pointer grab, but was instead a manual | 938 // - |g_current_capture|'s X window has capture. |
940 // redirection of the event. (You need to drop into GDK if you want to | 939 // OR |
941 // perform a raw X11 grab). | 940 // - The topmost window underneath the mouse is managed by Chrome. |
| 941 if (g_current_capture) |
| 942 g_current_capture->OnHostLostWindowCapture(); |
| 943 g_current_capture = this; |
942 | 944 |
943 if (g_current_capture) | 945 unsigned int event_mask = PointerMotionMask | ButtonReleaseMask | |
944 g_current_capture->OnCaptureReleased(); | 946 ButtonPressMask; |
945 | 947 XGrabPointer(xdisplay_, xwindow_, True, event_mask, GrabModeAsync, |
946 g_current_capture = this; | 948 GrabModeAsync, None, None, CurrentTime); |
947 x11_capture_.reset(new X11ScopedCapture(xwindow_)); | |
948 } | 949 } |
949 | 950 |
950 void DesktopWindowTreeHostX11::ReleaseCapture() { | 951 void DesktopWindowTreeHostX11::ReleaseCapture() { |
951 if (g_current_capture == this) | 952 if (g_current_capture == this) { |
952 g_current_capture->OnCaptureReleased(); | 953 // Release mouse grab asynchronously. A window managed by Chrome is likely |
| 954 // the topmost window underneath the mouse so the capture release being |
| 955 // asynchronous is likely inconsequential. |
| 956 g_current_capture = NULL; |
| 957 XUngrabPointer(xdisplay_, CurrentTime); |
| 958 |
| 959 OnHostLostWindowCapture(); |
| 960 } |
953 } | 961 } |
954 | 962 |
955 void DesktopWindowTreeHostX11::SetCursorNative(gfx::NativeCursor cursor) { | 963 void DesktopWindowTreeHostX11::SetCursorNative(gfx::NativeCursor cursor) { |
956 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); | 964 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); |
957 } | 965 } |
958 | 966 |
959 void DesktopWindowTreeHostX11::MoveCursorToNative(const gfx::Point& location) { | 967 void DesktopWindowTreeHostX11::MoveCursorToNative(const gfx::Point& location) { |
960 XWarpPointer(xdisplay_, None, x_root_window_, 0, 0, 0, 0, | 968 XWarpPointer(xdisplay_, None, x_root_window_, 0, 0, 0, 0, |
961 bounds_.x() + location.x(), bounds_.y() + location.y()); | 969 bounds_.x() + location.x(), bounds_.y() + location.y()); |
962 } | 970 } |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 return window_properties_.find(atom_cache_.GetAtom(property)) != | 1379 return window_properties_.find(atom_cache_.GetAtom(property)) != |
1372 window_properties_.end(); | 1380 window_properties_.end(); |
1373 } | 1381 } |
1374 | 1382 |
1375 void DesktopWindowTreeHostX11::SetUseNativeFrame(bool use_native_frame) { | 1383 void DesktopWindowTreeHostX11::SetUseNativeFrame(bool use_native_frame) { |
1376 use_native_frame_ = use_native_frame; | 1384 use_native_frame_ = use_native_frame; |
1377 ui::SetUseOSWindowFrame(xwindow_, use_native_frame); | 1385 ui::SetUseOSWindowFrame(xwindow_, use_native_frame); |
1378 ResetWindowRegion(); | 1386 ResetWindowRegion(); |
1379 } | 1387 } |
1380 | 1388 |
1381 void DesktopWindowTreeHostX11::OnCaptureReleased() { | |
1382 x11_capture_.reset(); | |
1383 g_current_capture = NULL; | |
1384 OnHostLostWindowCapture(); | |
1385 } | |
1386 | |
1387 void DesktopWindowTreeHostX11::DispatchMouseEvent(ui::MouseEvent* event) { | 1389 void DesktopWindowTreeHostX11::DispatchMouseEvent(ui::MouseEvent* event) { |
1388 // In Windows, the native events sent to chrome are separated into client | 1390 // In Windows, the native events sent to chrome are separated into client |
1389 // and non-client versions of events, which we record on our LocatedEvent | 1391 // and non-client versions of events, which we record on our LocatedEvent |
1390 // structures. On X11, we emulate the concept of non-client. Before we pass | 1392 // structures. On X11, we emulate the concept of non-client. Before we pass |
1391 // this event to the cross platform event handling framework, we need to | 1393 // this event to the cross platform event handling framework, we need to |
1392 // make sure it is appropriately marked as non-client if it's in the non | 1394 // make sure it is appropriately marked as non-client if it's in the non |
1393 // client area, or otherwise, we can get into a state where the a window is | 1395 // client area, or otherwise, we can get into a state where the a window is |
1394 // set as the |mouse_pressed_handler_| in window_event_dispatcher.cc | 1396 // set as the |mouse_pressed_handler_| in window_event_dispatcher.cc |
1395 // despite the mouse button being released. | 1397 // despite the mouse button being released. |
1396 // | 1398 // |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1905 if (linux_ui) { | 1907 if (linux_ui) { |
1906 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 1908 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
1907 if (native_theme) | 1909 if (native_theme) |
1908 return native_theme; | 1910 return native_theme; |
1909 } | 1911 } |
1910 | 1912 |
1911 return ui::NativeTheme::instance(); | 1913 return ui::NativeTheme::instance(); |
1912 } | 1914 } |
1913 | 1915 |
1914 } // namespace views | 1916 } // namespace views |
OLD | NEW |