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> |
11 #include <X11/Xutil.h> | 11 #include <X11/Xutil.h> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
15 #include "base/message_loop/message_pump_x11.h" | 15 #include "base/message_loop/message_pump_x11.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "third_party/skia/include/core/SkPath.h" | 18 #include "third_party/skia/include/core/SkPath.h" |
19 #include "ui/aura/client/cursor_client.h" | 19 #include "ui/aura/client/cursor_client.h" |
20 #include "ui/aura/client/focus_client.h" | 20 #include "ui/aura/client/focus_client.h" |
21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
22 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
23 #include "ui/aura/window_property.h" | 23 #include "ui/aura/window_property.h" |
24 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" | 24 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" |
25 #include "ui/base/hit_test.h" | 25 #include "ui/base/hit_test.h" |
26 #include "ui/base/x/x11_util.h" | 26 #include "ui/base/x/x11_util.h" |
27 #include "ui/events/event_utils.h" | 27 #include "ui/events/event_utils.h" |
| 28 #include "ui/events/platform/platform_event_source.h" |
| 29 #include "ui/events/platform/x11/x11_event_source.h" |
28 #include "ui/events/x/device_data_manager.h" | 30 #include "ui/events/x/device_data_manager.h" |
29 #include "ui/events/x/device_list_cache_x.h" | 31 #include "ui/events/x/device_list_cache_x.h" |
30 #include "ui/events/x/touch_factory_x11.h" | 32 #include "ui/events/x/touch_factory_x11.h" |
31 #include "ui/gfx/image/image_skia.h" | 33 #include "ui/gfx/image/image_skia.h" |
32 #include "ui/gfx/image/image_skia_rep.h" | 34 #include "ui/gfx/image/image_skia_rep.h" |
33 #include "ui/gfx/insets.h" | 35 #include "ui/gfx/insets.h" |
34 #include "ui/gfx/path.h" | 36 #include "ui/gfx/path.h" |
35 #include "ui/gfx/path_x11.h" | 37 #include "ui/gfx/path_x11.h" |
36 #include "ui/native_theme/native_theme.h" | 38 #include "ui/native_theme/native_theme.h" |
37 #include "ui/views/corewm/tooltip_aura.h" | 39 #include "ui/views/corewm/tooltip_aura.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 desktop_native_widget_aura_->root_window_event_filter()->RemoveHandler( | 306 desktop_native_widget_aura_->root_window_event_filter()->RemoveHandler( |
305 x11_window_event_filter_.get()); | 307 x11_window_event_filter_.get()); |
306 | 308 |
307 // Destroy the compositor before destroying the |xwindow_| since shutdown | 309 // Destroy the compositor before destroying the |xwindow_| since shutdown |
308 // may try to swap, and the swap without a window causes an X error, which | 310 // may try to swap, and the swap without a window causes an X error, which |
309 // causes a crash with in-process renderer. | 311 // causes a crash with in-process renderer. |
310 DestroyCompositor(); | 312 DestroyCompositor(); |
311 | 313 |
312 open_windows().remove(xwindow_); | 314 open_windows().remove(xwindow_); |
313 // Actually free our native resources. | 315 // Actually free our native resources. |
314 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); | 316 if (ui::PlatformEventSource::GetInstance()) |
| 317 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
315 XDestroyWindow(xdisplay_, xwindow_); | 318 XDestroyWindow(xdisplay_, xwindow_); |
316 xwindow_ = None; | 319 xwindow_ = None; |
317 | 320 |
318 desktop_native_widget_aura_->OnHostClosed(); | 321 desktop_native_widget_aura_->OnHostClosed(); |
319 } | 322 } |
320 | 323 |
321 aura::WindowTreeHost* DesktopWindowTreeHostX11::AsWindowTreeHost() { | 324 aura::WindowTreeHost* DesktopWindowTreeHostX11::AsWindowTreeHost() { |
322 return this; | 325 return this; |
323 } | 326 } |
324 | 327 |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 xwindow_ = XCreateWindow( | 970 xwindow_ = XCreateWindow( |
968 xdisplay_, x_root_window_, | 971 xdisplay_, x_root_window_, |
969 bounds_.x(), bounds_.y(), | 972 bounds_.x(), bounds_.y(), |
970 bounds_.width(), bounds_.height(), | 973 bounds_.width(), bounds_.height(), |
971 0, // border width | 974 0, // border width |
972 CopyFromParent, // depth | 975 CopyFromParent, // depth |
973 InputOutput, | 976 InputOutput, |
974 CopyFromParent, // visual | 977 CopyFromParent, // visual |
975 attribute_mask, | 978 attribute_mask, |
976 &swa); | 979 &swa); |
977 base::MessagePumpX11::Current()->AddDispatcherForWindow(this, xwindow_); | 980 if (ui::PlatformEventSource::GetInstance()) |
| 981 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
978 open_windows().push_back(xwindow_); | 982 open_windows().push_back(xwindow_); |
979 | 983 |
980 // TODO(erg): Maybe need to set a ViewProp here like in RWHL::RWHL(). | 984 // TODO(erg): Maybe need to set a ViewProp here like in RWHL::RWHL(). |
981 | 985 |
982 long event_mask = ButtonPressMask | ButtonReleaseMask | FocusChangeMask | | 986 long event_mask = ButtonPressMask | ButtonReleaseMask | FocusChangeMask | |
983 KeyPressMask | KeyReleaseMask | | 987 KeyPressMask | KeyReleaseMask | |
984 EnterWindowMask | LeaveWindowMask | | 988 EnterWindowMask | LeaveWindowMask | |
985 ExposureMask | VisibilityChangeMask | | 989 ExposureMask | VisibilityChangeMask | |
986 StructureNotifyMask | PropertyChangeMask | | 990 StructureNotifyMask | PropertyChangeMask | |
987 PointerMotionMask; | 991 PointerMotionMask; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 // https://crbug.com/355667 | 1297 // https://crbug.com/355667 |
1294 XDeleteProperty( | 1298 XDeleteProperty( |
1295 xdisplay_, xwindow_, atom_cache_.GetAtom("_NET_WM_USER_TIME")); | 1299 xdisplay_, xwindow_, atom_cache_.GetAtom("_NET_WM_USER_TIME")); |
1296 } | 1300 } |
1297 | 1301 |
1298 XMapWindow(xdisplay_, xwindow_); | 1302 XMapWindow(xdisplay_, xwindow_); |
1299 | 1303 |
1300 // We now block until our window is mapped. Some X11 APIs will crash and | 1304 // We now block until our window is mapped. Some X11 APIs will crash and |
1301 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is | 1305 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is |
1302 // asynchronous. | 1306 // asynchronous. |
1303 base::MessagePumpX11::Current()->BlockUntilWindowMapped(xwindow_); | 1307 if (ui::X11EventSource::GetInstance()) |
| 1308 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(xwindow_); |
1304 window_mapped_ = true; | 1309 window_mapped_ = true; |
1305 } | 1310 } |
1306 | 1311 |
1307 //////////////////////////////////////////////////////////////////////////////// | 1312 //////////////////////////////////////////////////////////////////////////////// |
1308 // DesktopWindowTreeHostX11, MessagePumpDispatcher implementation: | 1313 // DesktopWindowTreeHostX11, ui::PlatformEventDispatcher implementation: |
1309 | 1314 |
1310 uint32_t DesktopWindowTreeHostX11::Dispatch(const base::NativeEvent& event) { | 1315 bool DesktopWindowTreeHostX11::CanDispatchEvent( |
| 1316 const ui::PlatformEvent& event) { |
| 1317 return event->xany.window == xwindow_ || |
| 1318 (event->type == GenericEvent && |
| 1319 static_cast<XIDeviceEvent*>(event->xcookie.data)->event == xwindow_); |
| 1320 } |
| 1321 |
| 1322 uint32_t DesktopWindowTreeHostX11::DispatchEvent( |
| 1323 const ui::PlatformEvent& event) { |
1311 XEvent* xev = event; | 1324 XEvent* xev = event; |
1312 | 1325 |
1313 TRACE_EVENT1("views", "DesktopWindowTreeHostX11::Dispatch", | 1326 TRACE_EVENT1("views", "DesktopWindowTreeHostX11::Dispatch", |
1314 "event->type", event->type); | 1327 "event->type", event->type); |
1315 | 1328 |
1316 // May want to factor CheckXEventForConsistency(xev); into a common location | 1329 // May want to factor CheckXEventForConsistency(xev); into a common location |
1317 // since it is called here. | 1330 // since it is called here. |
1318 switch (xev->type) { | 1331 switch (xev->type) { |
1319 case EnterNotify: | 1332 case EnterNotify: |
1320 case LeaveNotify: { | 1333 case LeaveNotify: { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 // changed the window's maximization state. | 1603 // changed the window's maximization state. |
1591 ResetWindowRegion(); | 1604 ResetWindowRegion(); |
1592 } | 1605 } |
1593 break; | 1606 break; |
1594 } | 1607 } |
1595 case SelectionNotify: { | 1608 case SelectionNotify: { |
1596 drag_drop_client_->OnSelectionNotify(xev->xselection); | 1609 drag_drop_client_->OnSelectionNotify(xev->xselection); |
1597 break; | 1610 break; |
1598 } | 1611 } |
1599 } | 1612 } |
1600 return POST_DISPATCH_NONE; | 1613 return ui::POST_DISPATCH_STOP_PROPAGATION; |
1601 } | 1614 } |
1602 | 1615 |
1603 //////////////////////////////////////////////////////////////////////////////// | 1616 //////////////////////////////////////////////////////////////////////////////// |
1604 // DesktopWindowTreeHost, public: | 1617 // DesktopWindowTreeHost, public: |
1605 | 1618 |
1606 // static | 1619 // static |
1607 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( | 1620 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( |
1608 internal::NativeWidgetDelegate* native_widget_delegate, | 1621 internal::NativeWidgetDelegate* native_widget_delegate, |
1609 DesktopNativeWidgetAura* desktop_native_widget_aura) { | 1622 DesktopNativeWidgetAura* desktop_native_widget_aura) { |
1610 return new DesktopWindowTreeHostX11(native_widget_delegate, | 1623 return new DesktopWindowTreeHostX11(native_widget_delegate, |
1611 desktop_native_widget_aura); | 1624 desktop_native_widget_aura); |
1612 } | 1625 } |
1613 | 1626 |
1614 // static | 1627 // static |
1615 ui::NativeTheme* DesktopWindowTreeHost::GetNativeTheme(aura::Window* window) { | 1628 ui::NativeTheme* DesktopWindowTreeHost::GetNativeTheme(aura::Window* window) { |
1616 const views::LinuxUI* linux_ui = views::LinuxUI::instance(); | 1629 const views::LinuxUI* linux_ui = views::LinuxUI::instance(); |
1617 if (linux_ui) { | 1630 if (linux_ui) { |
1618 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(); | 1631 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(); |
1619 if (native_theme) | 1632 if (native_theme) |
1620 return native_theme; | 1633 return native_theme; |
1621 } | 1634 } |
1622 | 1635 |
1623 return ui::NativeTheme::instance(); | 1636 return ui::NativeTheme::instance(); |
1624 } | 1637 } |
1625 | 1638 |
1626 } // namespace views | 1639 } // namespace views |
OLD | NEW |