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_root_window_host_x11.h" | 5 #include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h" |
6 | 6 |
7 #include <X11/extensions/XInput2.h> | 7 #include <X11/extensions/XInput2.h> |
8 #include <X11/Xatom.h> | 8 #include <X11/Xatom.h> |
9 #include <X11/Xutil.h> | 9 #include <X11/Xutil.h> |
10 | 10 |
11 #include "base/message_pump_aurax11.h" | 11 #include "base/message_pump_aurax11.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "ui/aura/client/screen_position_client.h" | 14 #include "ui/aura/client/screen_position_client.h" |
15 #include "ui/aura/client/user_action_client.h" | 15 #include "ui/aura/client/user_action_client.h" |
16 #include "ui/aura/focus_manager.h" | 16 #include "ui/aura/focus_manager.h" |
17 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
18 #include "ui/aura/window_property.h" | 18 #include "ui/aura/window_property.h" |
| 19 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" |
19 #include "ui/base/events/event_utils.h" | 20 #include "ui/base/events/event_utils.h" |
20 #include "ui/base/touch/touch_factory_x11.h" | 21 #include "ui/base/touch/touch_factory_x11.h" |
21 #include "ui/base/x/x11_util.h" | 22 #include "ui/base/x/x11_util.h" |
22 #include "ui/gfx/insets.h" | 23 #include "ui/gfx/insets.h" |
23 #include "ui/linux_ui/linux_ui.h" | 24 #include "ui/linux_ui/linux_ui.h" |
24 #include "ui/native_theme/native_theme.h" | 25 #include "ui/native_theme/native_theme.h" |
25 #include "ui/views/corewm/compound_event_filter.h" | 26 #include "ui/views/corewm/compound_event_filter.h" |
26 #include "ui/views/corewm/corewm_switches.h" | 27 #include "ui/views/corewm/corewm_switches.h" |
27 #include "ui/views/corewm/cursor_manager.h" | 28 #include "ui/views/corewm/cursor_manager.h" |
28 #include "ui/views/corewm/focus_controller.h" | 29 #include "ui/views/corewm/focus_controller.h" |
29 #include "ui/views/ime/input_method.h" | 30 #include "ui/views/ime/input_method.h" |
30 #include "ui/views/widget/desktop_aura/desktop_activation_client.h" | 31 #include "ui/views/widget/desktop_aura/desktop_activation_client.h" |
31 #include "ui/views/widget/desktop_aura/desktop_capture_client.h" | 32 #include "ui/views/widget/desktop_aura/desktop_capture_client.h" |
32 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater_aurax11.h" | 33 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater_aurax11.h" |
33 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h" | 34 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h" |
| 35 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" |
34 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h" | 36 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h" |
35 #include "ui/views/widget/desktop_aura/desktop_layout_manager.h" | 37 #include "ui/views/widget/desktop_aura/desktop_layout_manager.h" |
36 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" | 38 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" |
37 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 39 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
38 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h" | 40 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h" |
39 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" | 41 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" |
40 #include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h" | 42 #include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h" |
41 #include "ui/views/widget/desktop_aura/x11_window_event_filter.h" | 43 #include "ui/views/widget/desktop_aura/x11_window_event_filter.h" |
42 | 44 |
43 namespace views { | 45 namespace views { |
(...skipping 12 matching lines...) Expand all Loading... |
56 // Standard Linux mouse buttons for going back and forward. | 58 // Standard Linux mouse buttons for going back and forward. |
57 const int kBackMouseButton = 8; | 59 const int kBackMouseButton = 8; |
58 const int kForwardMouseButton = 9; | 60 const int kForwardMouseButton = 9; |
59 | 61 |
60 // Constants that are part of EWMH. | 62 // Constants that are part of EWMH. |
61 const int k_NET_WM_STATE_ADD = 1; | 63 const int k_NET_WM_STATE_ADD = 1; |
62 const int k_NET_WM_STATE_REMOVE = 0; | 64 const int k_NET_WM_STATE_REMOVE = 0; |
63 | 65 |
64 const char* kAtomsToCache[] = { | 66 const char* kAtomsToCache[] = { |
65 "WM_DELETE_WINDOW", | 67 "WM_DELETE_WINDOW", |
| 68 "WM_PROTOCOLS", |
66 "WM_S0", | 69 "WM_S0", |
67 "_NET_WM_PID", | 70 "_NET_WM_PID", |
68 "_NET_WM_PING", | 71 "_NET_WM_PING", |
69 "_NET_WM_STATE", | 72 "_NET_WM_STATE", |
70 "_NET_WM_STATE_FULLSCREEN", | 73 "_NET_WM_STATE_FULLSCREEN", |
71 "_NET_WM_STATE_HIDDEN", | 74 "_NET_WM_STATE_HIDDEN", |
72 "_NET_WM_STATE_MAXIMIZED_HORZ", | 75 "_NET_WM_STATE_MAXIMIZED_HORZ", |
73 "_NET_WM_STATE_MAXIMIZED_VERT", | 76 "_NET_WM_STATE_MAXIMIZED_VERT", |
| 77 "XdndActionAsk", |
| 78 "XdndActionCopy" |
| 79 "XdndActionLink", |
| 80 "XdndActionList", |
| 81 "XdndActionMove", |
| 82 "XdndActionPrivate", |
| 83 "XdndAware", |
| 84 "XdndDrop", |
| 85 "XdndEnter", |
| 86 "XdndFinished", |
| 87 "XdndLeave", |
| 88 "XdndPosition", |
| 89 "XdndProxy", // Proxy windows? |
| 90 "XdndSelection", |
| 91 "XdndStatus", |
| 92 "XdndTypeList", |
74 NULL | 93 NULL |
75 }; | 94 }; |
76 | 95 |
77 } // namespace | 96 } // namespace |
78 | 97 |
79 //////////////////////////////////////////////////////////////////////////////// | 98 //////////////////////////////////////////////////////////////////////////////// |
80 // DesktopRootWindowHostX11, public: | 99 // DesktopRootWindowHostX11, public: |
81 | 100 |
82 DesktopRootWindowHostX11::DesktopRootWindowHostX11( | 101 DesktopRootWindowHostX11::DesktopRootWindowHostX11( |
83 internal::NativeWidgetDelegate* native_widget_delegate, | 102 internal::NativeWidgetDelegate* native_widget_delegate, |
84 DesktopNativeWidgetAura* desktop_native_widget_aura, | 103 DesktopNativeWidgetAura* desktop_native_widget_aura, |
85 const gfx::Rect& initial_bounds) | 104 const gfx::Rect& initial_bounds) |
86 : close_widget_factory_(this), | 105 : close_widget_factory_(this), |
87 xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), | 106 xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), |
88 xwindow_(0), | 107 xwindow_(0), |
89 x_root_window_(DefaultRootWindow(xdisplay_)), | 108 x_root_window_(DefaultRootWindow(xdisplay_)), |
90 atom_cache_(xdisplay_, kAtomsToCache), | 109 atom_cache_(xdisplay_, kAtomsToCache), |
91 window_mapped_(false), | 110 window_mapped_(false), |
92 focus_when_shown_(false), | 111 focus_when_shown_(false), |
93 current_cursor_(ui::kCursorNull), | 112 current_cursor_(ui::kCursorNull), |
94 native_widget_delegate_(native_widget_delegate), | 113 native_widget_delegate_(native_widget_delegate), |
95 desktop_native_widget_aura_(desktop_native_widget_aura) { | 114 desktop_native_widget_aura_(desktop_native_widget_aura), |
| 115 drop_handler_(NULL) { |
96 } | 116 } |
97 | 117 |
98 DesktopRootWindowHostX11::~DesktopRootWindowHostX11() { | 118 DesktopRootWindowHostX11::~DesktopRootWindowHostX11() { |
99 root_window_->ClearProperty(kHostForRootWindow); | 119 root_window_->ClearProperty(kHostForRootWindow); |
100 if (corewm::UseFocusControllerOnDesktop()) { | 120 if (corewm::UseFocusControllerOnDesktop()) { |
101 aura::client::SetFocusClient(root_window_, NULL); | 121 aura::client::SetFocusClient(root_window_, NULL); |
102 aura::client::SetActivationClient(root_window_, NULL); | 122 aura::client::SetActivationClient(root_window_, NULL); |
103 } | 123 } |
104 } | 124 } |
105 | 125 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 new DesktopCursorLoaderUpdaterAuraX11))))); | 275 new DesktopCursorLoaderUpdaterAuraX11))))); |
256 aura::client::SetCursorClient(root_window_, | 276 aura::client::SetCursorClient(root_window_, |
257 cursor_client_.get()); | 277 cursor_client_.get()); |
258 | 278 |
259 position_client_.reset(new DesktopScreenPositionClient); | 279 position_client_.reset(new DesktopScreenPositionClient); |
260 aura::client::SetScreenPositionClient(root_window_, | 280 aura::client::SetScreenPositionClient(root_window_, |
261 position_client_.get()); | 281 position_client_.get()); |
262 | 282 |
263 desktop_native_widget_aura_->InstallInputMethodEventFilter(root_window_); | 283 desktop_native_widget_aura_->InstallInputMethodEventFilter(root_window_); |
264 | 284 |
| 285 drag_drop_client_.reset(new DesktopDragDropClientAuraX11( |
| 286 this, root_window_, xdisplay_, xwindow_)); |
| 287 aura::client::SetDragDropClient(root_window_, drag_drop_client_.get()); |
| 288 |
265 // TODO(erg): Unify this code once the other consumer goes away. | 289 // TODO(erg): Unify this code once the other consumer goes away. |
266 x11_window_event_filter_.reset( | 290 x11_window_event_filter_.reset( |
267 new X11WindowEventFilter(root_window_, activation_client_.get())); | 291 new X11WindowEventFilter(root_window_, activation_client_.get())); |
268 x11_window_event_filter_->SetUseHostWindowBorders(false); | 292 x11_window_event_filter_->SetUseHostWindowBorders(false); |
269 desktop_native_widget_aura_->root_window_event_filter()->AddHandler( | 293 desktop_native_widget_aura_->root_window_event_filter()->AddHandler( |
270 x11_window_event_filter_.get()); | 294 x11_window_event_filter_.get()); |
271 | 295 |
272 x11_window_move_client_.reset(new X11DesktopWindowMoveClient); | 296 x11_window_move_client_.reset(new X11DesktopWindowMoveClient); |
273 aura::client::SetWindowMoveClient(root_window_, | 297 aura::client::SetWindowMoveClient(root_window_, |
274 x11_window_move_client_.get()); | 298 x11_window_move_client_.get()); |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 } | 902 } |
879 | 903 |
880 void DesktopRootWindowHostX11::OnDeviceScaleFactorChanged( | 904 void DesktopRootWindowHostX11::OnDeviceScaleFactorChanged( |
881 float device_scale_factor) { | 905 float device_scale_factor) { |
882 } | 906 } |
883 | 907 |
884 void DesktopRootWindowHostX11::PrepareForShutdown() { | 908 void DesktopRootWindowHostX11::PrepareForShutdown() { |
885 } | 909 } |
886 | 910 |
887 //////////////////////////////////////////////////////////////////////////////// | 911 //////////////////////////////////////////////////////////////////////////////// |
| 912 // DesktopRootWindowHostX11, ui::DesktopSelectionProviderAuraX11 implementation: |
| 913 |
| 914 void DesktopRootWindowHostX11::SetDropHandler( |
| 915 ui::OSExchangeDataProviderAuraX11* handler) { |
| 916 if (handler) { |
| 917 DCHECK(!drop_handler_); |
| 918 drop_handler_ = handler; |
| 919 } else { |
| 920 DCHECK(drop_handler_); |
| 921 drop_handler_ = NULL; |
| 922 } |
| 923 } |
| 924 |
| 925 //////////////////////////////////////////////////////////////////////////////// |
888 // DesktopRootWindowHostX11, MessageLoop::Dispatcher implementation: | 926 // DesktopRootWindowHostX11, MessageLoop::Dispatcher implementation: |
889 | 927 |
890 bool DesktopRootWindowHostX11::Dispatch(const base::NativeEvent& event) { | 928 bool DesktopRootWindowHostX11::Dispatch(const base::NativeEvent& event) { |
891 XEvent* xev = event; | 929 XEvent* xev = event; |
892 | 930 |
893 // May want to factor CheckXEventForConsistency(xev); into a common location | 931 // May want to factor CheckXEventForConsistency(xev); into a common location |
894 // since it is called here. | 932 // since it is called here. |
895 switch (xev->type) { | 933 switch (xev->type) { |
896 case Expose: { | 934 case Expose: { |
897 gfx::Rect damage_rect(xev->xexpose.x, xev->xexpose.y, | 935 gfx::Rect damage_rect(xev->xexpose.x, xev->xexpose.y, |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 break; | 1079 break; |
1042 } | 1080 } |
1043 case MapNotify: { | 1081 case MapNotify: { |
1044 // If there's no window manager running, we need to assign the X input | 1082 // If there's no window manager running, we need to assign the X input |
1045 // focus to our host window. | 1083 // focus to our host window. |
1046 if (!IsWindowManagerPresent() && focus_when_shown_) | 1084 if (!IsWindowManagerPresent() && focus_when_shown_) |
1047 XSetInputFocus(xdisplay_, xwindow_, RevertToNone, CurrentTime); | 1085 XSetInputFocus(xdisplay_, xwindow_, RevertToNone, CurrentTime); |
1048 break; | 1086 break; |
1049 } | 1087 } |
1050 case ClientMessage: { | 1088 case ClientMessage: { |
1051 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); | 1089 Atom message_type = xev->xclient.message_type; |
1052 if (message_type == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { | 1090 if (message_type == atom_cache_.GetAtom("WM_PROTOCOLS")) { |
1053 // We have received a close message from the window manager. | 1091 Atom protocol = static_cast<Atom>(xev->xclient.data.l[0]); |
1054 root_window_->OnRootWindowHostCloseRequested(); | 1092 if (protocol == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { |
1055 } else if (message_type == atom_cache_.GetAtom("_NET_WM_PING")) { | 1093 // We have received a close message from the window manager. |
1056 XEvent reply_event = *xev; | 1094 root_window_->OnRootWindowHostCloseRequested(); |
1057 reply_event.xclient.window = x_root_window_; | 1095 } else if (protocol == atom_cache_.GetAtom("_NET_WM_PING")) { |
| 1096 XEvent reply_event = *xev; |
| 1097 reply_event.xclient.window = x_root_window_; |
1058 | 1098 |
1059 XSendEvent(xdisplay_, | 1099 XSendEvent(xdisplay_, |
1060 reply_event.xclient.window, | 1100 reply_event.xclient.window, |
1061 False, | 1101 False, |
1062 SubstructureRedirectMask | SubstructureNotifyMask, | 1102 SubstructureRedirectMask | SubstructureNotifyMask, |
1063 &reply_event); | 1103 &reply_event); |
| 1104 } |
| 1105 } else if (message_type == atom_cache_.GetAtom("XdndEnter")) { |
| 1106 drag_drop_client_->OnXdndEnter(xev->xclient); |
| 1107 } else if (message_type == atom_cache_.GetAtom("XdndLeave")) { |
| 1108 drag_drop_client_->OnXdndLeave(xev->xclient); |
| 1109 } else if (message_type == atom_cache_.GetAtom("XdndPosition")) { |
| 1110 drag_drop_client_->OnXdndPosition(xev->xclient); |
| 1111 } else if (message_type == atom_cache_.GetAtom("XdndStatus")) { |
| 1112 drag_drop_client_->OnXdndStatus(xev->xclient); |
| 1113 } else if (message_type == atom_cache_.GetAtom("XdndFinished")) { |
| 1114 drag_drop_client_->OnXdndFinished(xev->xclient); |
| 1115 } else if (message_type == atom_cache_.GetAtom("XdndDrop")) { |
| 1116 drag_drop_client_->OnXdndDrop(xev->xclient); |
1064 } | 1117 } |
1065 break; | 1118 break; |
1066 } | 1119 } |
1067 case MappingNotify: { | 1120 case MappingNotify: { |
1068 switch (xev->xmapping.request) { | 1121 switch (xev->xmapping.request) { |
1069 case MappingModifier: | 1122 case MappingModifier: |
1070 case MappingKeyboard: | 1123 case MappingKeyboard: |
1071 XRefreshKeyboardMapping(&xev->xmapping); | 1124 XRefreshKeyboardMapping(&xev->xmapping); |
1072 root_window_->OnKeyboardMappingChanged(); | 1125 root_window_->OnKeyboardMappingChanged(); |
1073 break; | 1126 break; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 // fullscreen state. Unsure what to do about that. | 1177 // fullscreen state. Unsure what to do about that. |
1125 Widget* widget = native_widget_delegate_->AsWidget(); | 1178 Widget* widget = native_widget_delegate_->AsWidget(); |
1126 NonClientView* non_client_view = widget->non_client_view(); | 1179 NonClientView* non_client_view = widget->non_client_view(); |
1127 // non_client_view may be NULL, especially during creation. | 1180 // non_client_view may be NULL, especially during creation. |
1128 if (non_client_view) { | 1181 if (non_client_view) { |
1129 non_client_view->client_view()->InvalidateLayout(); | 1182 non_client_view->client_view()->InvalidateLayout(); |
1130 non_client_view->InvalidateLayout(); | 1183 non_client_view->InvalidateLayout(); |
1131 } | 1184 } |
1132 widget->GetRootView()->Layout(); | 1185 widget->GetRootView()->Layout(); |
1133 } | 1186 } |
| 1187 break; |
| 1188 } |
| 1189 case SelectionNotify: { |
| 1190 if (drop_handler_) |
| 1191 drop_handler_->OnSelectionNotify(xev->xselection); |
| 1192 break; |
1134 } | 1193 } |
1135 } | 1194 } |
1136 return true; | 1195 return true; |
1137 } | 1196 } |
1138 | 1197 |
1139 //////////////////////////////////////////////////////////////////////////////// | 1198 //////////////////////////////////////////////////////////////////////////////// |
1140 // DesktopRootWindowHost, public: | 1199 // DesktopRootWindowHost, public: |
1141 | 1200 |
1142 // static | 1201 // static |
1143 DesktopRootWindowHost* DesktopRootWindowHost::Create( | 1202 DesktopRootWindowHost* DesktopRootWindowHost::Create( |
1144 internal::NativeWidgetDelegate* native_widget_delegate, | 1203 internal::NativeWidgetDelegate* native_widget_delegate, |
1145 DesktopNativeWidgetAura* desktop_native_widget_aura, | 1204 DesktopNativeWidgetAura* desktop_native_widget_aura, |
1146 const gfx::Rect& initial_bounds) { | 1205 const gfx::Rect& initial_bounds) { |
1147 return new DesktopRootWindowHostX11(native_widget_delegate, | 1206 return new DesktopRootWindowHostX11(native_widget_delegate, |
1148 desktop_native_widget_aura, | 1207 desktop_native_widget_aura, |
1149 initial_bounds); | 1208 initial_bounds); |
1150 } | 1209 } |
1151 | 1210 |
1152 } // namespace views | 1211 } // namespace views |
OLD | NEW |