Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc

Issue 31043006: Moves creation of various clients to DesktopNativeWidgetAura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: resolve merge Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_root_window_host_x11.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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/message_loop/message_pump_x11.h" 14 #include "base/message_loop/message_pump_x11.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "third_party/skia/include/core/SkPath.h" 17 #include "third_party/skia/include/core/SkPath.h"
18 #include "ui/aura/client/screen_position_client.h" 18 #include "ui/aura/client/cursor_client.h"
19 #include "ui/aura/client/focus_client.h"
19 #include "ui/aura/client/user_action_client.h" 20 #include "ui/aura/client/user_action_client.h"
20 #include "ui/aura/root_window.h" 21 #include "ui/aura/root_window.h"
21 #include "ui/aura/window_property.h" 22 #include "ui/aura/window_property.h"
22 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" 23 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h"
23 #include "ui/base/x/x11_util.h" 24 #include "ui/base/x/x11_util.h"
24 #include "ui/events/event_utils.h" 25 #include "ui/events/event_utils.h"
25 #include "ui/events/x/device_data_manager.h" 26 #include "ui/events/x/device_data_manager.h"
26 #include "ui/events/x/touch_factory_x11.h" 27 #include "ui/events/x/touch_factory_x11.h"
27 #include "ui/gfx/insets.h" 28 #include "ui/gfx/insets.h"
28 #include "ui/gfx/path.h" 29 #include "ui/gfx/path.h"
29 #include "ui/gfx/path_x11.h" 30 #include "ui/gfx/path_x11.h"
30 #include "ui/native_theme/native_theme.h" 31 #include "ui/native_theme/native_theme.h"
31 #include "ui/views/corewm/compound_event_filter.h" 32 #include "ui/views/corewm/compound_event_filter.h"
32 #include "ui/views/corewm/corewm_switches.h" 33 #include "ui/views/corewm/corewm_switches.h"
33 #include "ui/views/corewm/cursor_manager.h"
34 #include "ui/views/corewm/focus_controller.h"
35 #include "ui/views/corewm/tooltip_aura.h" 34 #include "ui/views/corewm/tooltip_aura.h"
36 #include "ui/views/ime/input_method.h" 35 #include "ui/views/ime/input_method.h"
37 #include "ui/views/linux_ui/linux_ui.h" 36 #include "ui/views/linux_ui/linux_ui.h"
38 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater_aurax11.h"
39 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h" 37 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h"
40 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" 38 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h"
41 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h"
42 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" 39 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
43 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 40 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
44 #include "ui/views/widget/desktop_aura/desktop_root_window_host_observer_x11.h" 41 #include "ui/views/widget/desktop_aura/desktop_root_window_host_observer_x11.h"
45 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h"
46 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" 42 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h"
47 #include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h" 43 #include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h"
48 #include "ui/views/widget/desktop_aura/x11_window_event_filter.h" 44 #include "ui/views/widget/desktop_aura/x11_window_event_filter.h"
49 45
50 namespace views { 46 namespace views {
51 47
52 DesktopRootWindowHostX11* DesktopRootWindowHostX11::g_current_capture = 48 DesktopRootWindowHostX11* DesktopRootWindowHostX11::g_current_capture =
53 NULL; 49 NULL;
54 std::list<XID>* DesktopRootWindowHostX11::open_windows_ = NULL; 50 std::list<XID>* DesktopRootWindowHostX11::open_windows_ = NULL;
55 51
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 NULL 102 NULL
107 }; 103 };
108 104
109 } // namespace 105 } // namespace
110 106
111 //////////////////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////////////////
112 // DesktopRootWindowHostX11, public: 108 // DesktopRootWindowHostX11, public:
113 109
114 DesktopRootWindowHostX11::DesktopRootWindowHostX11( 110 DesktopRootWindowHostX11::DesktopRootWindowHostX11(
115 internal::NativeWidgetDelegate* native_widget_delegate, 111 internal::NativeWidgetDelegate* native_widget_delegate,
116 DesktopNativeWidgetAura* desktop_native_widget_aura, 112 DesktopNativeWidgetAura* desktop_native_widget_aura)
117 const gfx::Rect& initial_bounds)
118 : close_widget_factory_(this), 113 : close_widget_factory_(this),
119 xdisplay_(gfx::GetXDisplay()), 114 xdisplay_(gfx::GetXDisplay()),
120 xwindow_(0), 115 xwindow_(0),
121 x_root_window_(DefaultRootWindow(xdisplay_)), 116 x_root_window_(DefaultRootWindow(xdisplay_)),
122 atom_cache_(xdisplay_, kAtomsToCache), 117 atom_cache_(xdisplay_, kAtomsToCache),
123 window_mapped_(false), 118 window_mapped_(false),
124 focus_when_shown_(false), 119 focus_when_shown_(false),
125 is_fullscreen_(false), 120 is_fullscreen_(false),
126 is_always_on_top_(false), 121 is_always_on_top_(false),
122 root_window_(NULL),
123 drag_drop_client_(NULL),
127 current_cursor_(ui::kCursorNull), 124 current_cursor_(ui::kCursorNull),
128 native_widget_delegate_(native_widget_delegate), 125 native_widget_delegate_(native_widget_delegate),
129 desktop_native_widget_aura_(desktop_native_widget_aura) { 126 desktop_native_widget_aura_(desktop_native_widget_aura) {
130 } 127 }
131 128
132 DesktopRootWindowHostX11::~DesktopRootWindowHostX11() { 129 DesktopRootWindowHostX11::~DesktopRootWindowHostX11() {
133 root_window_->ClearProperty(kHostForRootWindow); 130 root_window_->ClearProperty(kHostForRootWindow);
134 aura::client::SetFocusClient(root_window_, NULL);
135 aura::client::SetActivationClient(root_window_, NULL);
136 aura::client::SetScreenPositionClient(root_window_, NULL);
137 aura::client::SetDispatcherClient(root_window_, NULL);
138 aura::client::SetCursorClient(root_window_, NULL);
139 aura::client::SetDragDropClient(root_window_, NULL);
140 aura::client::SetWindowMoveClient(root_window_, NULL); 131 aura::client::SetWindowMoveClient(root_window_, NULL);
132 desktop_native_widget_aura_->OnDesktopRootWindowHostDestroyed(root_window_);
141 } 133 }
142 134
143 // static 135 // static
144 aura::Window* DesktopRootWindowHostX11::GetContentWindowForXID(XID xid) { 136 aura::Window* DesktopRootWindowHostX11::GetContentWindowForXID(XID xid) {
145 aura::RootWindow* root = aura::RootWindow::GetForAcceleratedWidget(xid); 137 aura::RootWindow* root = aura::RootWindow::GetForAcceleratedWidget(xid);
146 return root ? root->GetProperty(kViewsWindowForRootWindow) : NULL; 138 return root ? root->GetProperty(kViewsWindowForRootWindow) : NULL;
147 } 139 }
148 140
149 // static 141 // static
150 DesktopRootWindowHostX11* DesktopRootWindowHostX11::GetHostForXID(XID xid) { 142 DesktopRootWindowHostX11* DesktopRootWindowHostX11::GetHostForXID(XID xid) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 179 }
188 180
189 void DesktopRootWindowHostX11::CleanUpWindowList() { 181 void DesktopRootWindowHostX11::CleanUpWindowList() {
190 delete open_windows_; 182 delete open_windows_;
191 open_windows_ = NULL; 183 open_windows_ = NULL;
192 } 184 }
193 185
194 //////////////////////////////////////////////////////////////////////////////// 186 ////////////////////////////////////////////////////////////////////////////////
195 // DesktopRootWindowHostX11, DesktopRootWindowHost implementation: 187 // DesktopRootWindowHostX11, DesktopRootWindowHost implementation:
196 188
197 aura::RootWindow* DesktopRootWindowHostX11::Init( 189 void DesktopRootWindowHostX11::Init(
198 aura::Window* content_window, 190 aura::Window* content_window,
199 const Widget::InitParams& params) { 191 const Widget::InitParams& params,
192 aura::RootWindow::CreateParams* rw_create_params) {
200 content_window_ = content_window; 193 content_window_ = content_window;
201 194
202 // TODO(erg): Check whether we *should* be building a RootWindowHost here, or 195 // TODO(erg): Check whether we *should* be building a RootWindowHost here, or
203 // whether we should be proxying requests to another DRWHL. 196 // whether we should be proxying requests to another DRWHL.
204 197
205 // In some situations, views tries to make a zero sized window, and that 198 // In some situations, views tries to make a zero sized window, and that
206 // makes us crash. Make sure we have valid sizes. 199 // makes us crash. Make sure we have valid sizes.
207 Widget::InitParams sanitized_params = params; 200 Widget::InitParams sanitized_params = params;
208 if (sanitized_params.bounds.width() == 0) 201 if (sanitized_params.bounds.width() == 0)
209 sanitized_params.bounds.set_width(100); 202 sanitized_params.bounds.set_width(100);
210 if (sanitized_params.bounds.height() == 0) 203 if (sanitized_params.bounds.height() == 0)
211 sanitized_params.bounds.set_height(100); 204 sanitized_params.bounds.set_height(100);
212 205
213 InitX11Window(sanitized_params); 206 InitX11Window(sanitized_params);
214 return InitRootWindow(sanitized_params); 207
208 rw_create_params->initial_bounds = bounds_;
209 rw_create_params->host = this;
210 }
211
212 void DesktopRootWindowHostX11::OnRootWindowCreated(
213 aura::RootWindow* root,
214 const Widget::InitParams& params) {
215 root_window_ = root;
216
217 root_window_->SetProperty(kViewsWindowForRootWindow, content_window_);
218 root_window_->SetProperty(kHostForRootWindow, this);
219 root_window_host_delegate_ = root_window_;
220
221 // If we're given a parent, we need to mark ourselves as transient to another
222 // window. Otherwise activation gets screwy.
223 gfx::NativeView parent = params.parent;
224 if (!params.child && params.parent)
225 parent->AddTransientChild(content_window_);
226
227 // Ensure that the X11DesktopHandler exists so that it dispatches activation
228 // messages to us.
229 X11DesktopHandler::get();
230
231 // TODO(erg): Unify this code once the other consumer goes away.
232 x11_window_event_filter_.reset(new X11WindowEventFilter(root_window_));
233 x11_window_event_filter_->SetUseHostWindowBorders(false);
234 desktop_native_widget_aura_->root_window_event_filter()->AddHandler(
235 x11_window_event_filter_.get());
236
237 x11_window_move_client_.reset(new X11DesktopWindowMoveClient);
238 aura::client::SetWindowMoveClient(root_window_,
239 x11_window_move_client_.get());
215 } 240 }
216 241
217 scoped_ptr<corewm::Tooltip> DesktopRootWindowHostX11::CreateTooltip() { 242 scoped_ptr<corewm::Tooltip> DesktopRootWindowHostX11::CreateTooltip() {
218 return scoped_ptr<corewm::Tooltip>( 243 return scoped_ptr<corewm::Tooltip>(
219 new corewm::TooltipAura(gfx::SCREEN_TYPE_NATIVE)); 244 new corewm::TooltipAura(gfx::SCREEN_TYPE_NATIVE));
220 } 245 }
221 246
247 scoped_ptr<aura::client::DragDropClient>
248 DesktopRootWindowHostX11::CreateDragDropClient(
249 DesktopNativeCursorManager* cursor_manager) {
250 drag_drop_client_ = new DesktopDragDropClientAuraX11(
251 root_window_, cursor_manager, xdisplay_, xwindow_);
252 return scoped_ptr<aura::client::DragDropClient>(drag_drop_client_).Pass();
253 }
254
222 void DesktopRootWindowHostX11::Close() { 255 void DesktopRootWindowHostX11::Close() {
223 // TODO(erg): Might need to do additional hiding tasks here. 256 // TODO(erg): Might need to do additional hiding tasks here.
224 257
225 if (!close_widget_factory_.HasWeakPtrs()) { 258 if (!close_widget_factory_.HasWeakPtrs()) {
226 // And we delay the close so that if we are called from an ATL callback, 259 // And we delay the close so that if we are called from an ATL callback,
227 // we don't destroy the window before the callback returned (as the caller 260 // we don't destroy the window before the callback returned (as the caller
228 // may delete ourselves on destroy and the ATL callback would still 261 // may delete ourselves on destroy and the ATL callback would still
229 // dereference us when the callback returns). 262 // dereference us when the callback returns).
230 base::MessageLoop::current()->PostTask( 263 base::MessageLoop::current()->PostTask(
231 FROM_HERE, 264 FROM_HERE,
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 "ATOM", 966 "ATOM",
934 state_atom_list); 967 state_atom_list);
935 } 968 }
936 969
937 if (!params.wm_class_name.empty() || !params.wm_class_class.empty()) { 970 if (!params.wm_class_name.empty() || !params.wm_class_class.empty()) {
938 ui::SetWindowClassHint( 971 ui::SetWindowClassHint(
939 xdisplay_, xwindow_, params.wm_class_name, params.wm_class_class); 972 xdisplay_, xwindow_, params.wm_class_name, params.wm_class_class);
940 } 973 }
941 } 974 }
942 975
943 aura::RootWindow* DesktopRootWindowHostX11::InitRootWindow(
944 const Widget::InitParams& params) {
945 aura::RootWindow::CreateParams rw_params(bounds_);
946 rw_params.host = this;
947 root_window_ = new aura::RootWindow(rw_params);
948 root_window_->Init();
949 root_window_->AddChild(content_window_);
950 root_window_->SetProperty(kViewsWindowForRootWindow, content_window_);
951 root_window_->SetProperty(kHostForRootWindow, this);
952 root_window_host_delegate_ = root_window_;
953
954 // If we're given a parent, we need to mark ourselves as transient to another
955 // window. Otherwise activation gets screwy.
956 gfx::NativeView parent = params.parent;
957 if (!params.child && params.parent)
958 parent->AddTransientChild(content_window_);
959
960 native_widget_delegate_->OnNativeWidgetCreated(true);
961
962 desktop_native_widget_aura_->InstallWindowModalityController(root_window_);
963 desktop_native_widget_aura_->CreateCaptureClient(root_window_);
964
965 // Ensure that the X11DesktopHandler exists so that it dispatches activation
966 // messages to us.
967 X11DesktopHandler::get();
968
969 corewm::FocusController* focus_controller =
970 new corewm::FocusController(new DesktopFocusRules(content_window_));
971 focus_client_.reset(focus_controller);
972 aura::client::SetFocusClient(root_window_, focus_controller);
973 aura::client::SetActivationClient(root_window_, focus_controller);
974 root_window_->AddPreTargetHandler(focus_controller);
975
976 dispatcher_client_.reset(new DesktopDispatcherClient);
977 aura::client::SetDispatcherClient(root_window_,
978 dispatcher_client_.get());
979
980 views::DesktopNativeCursorManager* desktop_native_cursor_manager =
981 new views::DesktopNativeCursorManager(
982 root_window_,
983 scoped_ptr<DesktopCursorLoaderUpdater>(
984 new DesktopCursorLoaderUpdaterAuraX11));
985 cursor_client_.reset(
986 new views::corewm::CursorManager(
987 scoped_ptr<corewm::NativeCursorManager>(
988 desktop_native_cursor_manager)));
989 aura::client::SetCursorClient(root_window_,
990 cursor_client_.get());
991
992 position_client_.reset(new DesktopScreenPositionClient);
993 aura::client::SetScreenPositionClient(root_window_,
994 position_client_.get());
995
996 desktop_native_widget_aura_->InstallInputMethodEventFilter(root_window_);
997
998 drag_drop_client_.reset(new DesktopDragDropClientAuraX11(
999 root_window_, desktop_native_cursor_manager, xdisplay_, xwindow_));
1000 aura::client::SetDragDropClient(root_window_, drag_drop_client_.get());
1001
1002 // TODO(erg): Unify this code once the other consumer goes away.
1003 x11_window_event_filter_.reset(new X11WindowEventFilter(root_window_));
1004 x11_window_event_filter_->SetUseHostWindowBorders(false);
1005 desktop_native_widget_aura_->root_window_event_filter()->AddHandler(
1006 x11_window_event_filter_.get());
1007
1008 x11_window_move_client_.reset(new X11DesktopWindowMoveClient);
1009 aura::client::SetWindowMoveClient(root_window_,
1010 x11_window_move_client_.get());
1011 return root_window_;
1012 }
1013
1014 bool DesktopRootWindowHostX11::IsWindowManagerPresent() { 976 bool DesktopRootWindowHostX11::IsWindowManagerPresent() {
1015 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership 977 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership
1016 // of WM_Sn selections (where n is a screen number). 978 // of WM_Sn selections (where n is a screen number).
1017 return XGetSelectionOwner( 979 return XGetSelectionOwner(
1018 xdisplay_, atom_cache_.GetAtom("WM_S0")) != None; 980 xdisplay_, atom_cache_.GetAtom("WM_S0")) != None;
1019 } 981 }
1020 982
1021 void DesktopRootWindowHostX11::SetWMSpecState(bool enabled, 983 void DesktopRootWindowHostX11::SetWMSpecState(bool enabled,
1022 ::Atom state1, 984 ::Atom state1,
1023 ::Atom state2) { 985 ::Atom state2) {
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 } 1370 }
1409 return true; 1371 return true;
1410 } 1372 }
1411 1373
1412 //////////////////////////////////////////////////////////////////////////////// 1374 ////////////////////////////////////////////////////////////////////////////////
1413 // DesktopRootWindowHost, public: 1375 // DesktopRootWindowHost, public:
1414 1376
1415 // static 1377 // static
1416 DesktopRootWindowHost* DesktopRootWindowHost::Create( 1378 DesktopRootWindowHost* DesktopRootWindowHost::Create(
1417 internal::NativeWidgetDelegate* native_widget_delegate, 1379 internal::NativeWidgetDelegate* native_widget_delegate,
1418 DesktopNativeWidgetAura* desktop_native_widget_aura, 1380 DesktopNativeWidgetAura* desktop_native_widget_aura) {
1419 const gfx::Rect& initial_bounds) {
1420 return new DesktopRootWindowHostX11(native_widget_delegate, 1381 return new DesktopRootWindowHostX11(native_widget_delegate,
1421 desktop_native_widget_aura, 1382 desktop_native_widget_aura);
1422 initial_bounds);
1423 } 1383 }
1424 1384
1425 // static 1385 // static
1426 ui::NativeTheme* DesktopRootWindowHost::GetNativeTheme(aura::Window* window) { 1386 ui::NativeTheme* DesktopRootWindowHost::GetNativeTheme(aura::Window* window) {
1427 const views::LinuxUI* linux_ui = views::LinuxUI::instance(); 1387 const views::LinuxUI* linux_ui = views::LinuxUI::instance();
1428 if (linux_ui) { 1388 if (linux_ui) {
1429 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(); 1389 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme();
1430 if (native_theme) 1390 if (native_theme)
1431 return native_theme; 1391 return native_theme;
1432 } 1392 }
1433 1393
1434 return ui::NativeTheme::instance(); 1394 return ui::NativeTheme::instance();
1435 } 1395 }
1436 1396
1437 } // namespace views 1397 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_root_window_host_x11.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698