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/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" | 45 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" |
46 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 46 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
47 #include "ui/views/widget/desktop_aura/desktop_root_window_host_observer_x11.h" | 47 #include "ui/views/widget/desktop_aura/desktop_root_window_host_observer_x11.h" |
48 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" | 48 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" |
49 #include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h" | 49 #include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h" |
50 #include "ui/views/widget/desktop_aura/x11_scoped_capture.h" | 50 #include "ui/views/widget/desktop_aura/x11_scoped_capture.h" |
51 #include "ui/views/widget/desktop_aura/x11_window_event_filter.h" | 51 #include "ui/views/widget/desktop_aura/x11_window_event_filter.h" |
52 | 52 |
53 namespace views { | 53 namespace views { |
54 | 54 |
55 DesktopRootWindowHostX11* DesktopRootWindowHostX11::g_current_capture = | 55 DesktopWindowTreeHostX11* DesktopWindowTreeHostX11::g_current_capture = |
56 NULL; | 56 NULL; |
57 std::list<XID>* DesktopRootWindowHostX11::open_windows_ = NULL; | 57 std::list<XID>* DesktopWindowTreeHostX11::open_windows_ = NULL; |
58 | 58 |
59 DEFINE_WINDOW_PROPERTY_KEY( | 59 DEFINE_WINDOW_PROPERTY_KEY( |
60 aura::Window*, kViewsWindowForRootWindow, NULL); | 60 aura::Window*, kViewsWindowForRootWindow, NULL); |
61 | 61 |
62 DEFINE_WINDOW_PROPERTY_KEY( | 62 DEFINE_WINDOW_PROPERTY_KEY( |
63 DesktopRootWindowHostX11*, kHostForRootWindow, NULL); | 63 DesktopWindowTreeHostX11*, kHostForRootWindow, NULL); |
64 | 64 |
65 namespace { | 65 namespace { |
66 | 66 |
67 // Standard Linux mouse buttons for going back and forward. | 67 // Standard Linux mouse buttons for going back and forward. |
68 const int kBackMouseButton = 8; | 68 const int kBackMouseButton = 8; |
69 const int kForwardMouseButton = 9; | 69 const int kForwardMouseButton = 9; |
70 | 70 |
71 // Constants that are part of EWMH. | 71 // Constants that are part of EWMH. |
72 const int k_NET_WM_STATE_ADD = 1; | 72 const int k_NET_WM_STATE_ADD = 1; |
73 const int k_NET_WM_STATE_REMOVE = 0; | 73 const int k_NET_WM_STATE_REMOVE = 0; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 "XdndProxy", // Proxy windows? | 110 "XdndProxy", // Proxy windows? |
111 "XdndSelection", | 111 "XdndSelection", |
112 "XdndStatus", | 112 "XdndStatus", |
113 "XdndTypeList", | 113 "XdndTypeList", |
114 NULL | 114 NULL |
115 }; | 115 }; |
116 | 116 |
117 } // namespace | 117 } // namespace |
118 | 118 |
119 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
120 // DesktopRootWindowHostX11, public: | 120 // DesktopWindowTreeHostX11, public: |
121 | 121 |
122 DesktopRootWindowHostX11::DesktopRootWindowHostX11( | 122 DesktopWindowTreeHostX11::DesktopWindowTreeHostX11( |
123 internal::NativeWidgetDelegate* native_widget_delegate, | 123 internal::NativeWidgetDelegate* native_widget_delegate, |
124 DesktopNativeWidgetAura* desktop_native_widget_aura) | 124 DesktopNativeWidgetAura* desktop_native_widget_aura) |
125 : close_widget_factory_(this), | 125 : close_widget_factory_(this), |
126 xdisplay_(gfx::GetXDisplay()), | 126 xdisplay_(gfx::GetXDisplay()), |
127 xwindow_(0), | 127 xwindow_(0), |
128 x_root_window_(DefaultRootWindow(xdisplay_)), | 128 x_root_window_(DefaultRootWindow(xdisplay_)), |
129 atom_cache_(xdisplay_, kAtomsToCache), | 129 atom_cache_(xdisplay_, kAtomsToCache), |
130 window_mapped_(false), | 130 window_mapped_(false), |
131 is_fullscreen_(false), | 131 is_fullscreen_(false), |
132 is_always_on_top_(false), | 132 is_always_on_top_(false), |
133 root_window_(NULL), | 133 root_window_(NULL), |
134 drag_drop_client_(NULL), | 134 drag_drop_client_(NULL), |
135 current_cursor_(ui::kCursorNull), | 135 current_cursor_(ui::kCursorNull), |
136 native_widget_delegate_(native_widget_delegate), | 136 native_widget_delegate_(native_widget_delegate), |
137 desktop_native_widget_aura_(desktop_native_widget_aura), | 137 desktop_native_widget_aura_(desktop_native_widget_aura), |
138 content_window_(NULL), | 138 content_window_(NULL), |
139 window_parent_(NULL), | 139 window_parent_(NULL), |
140 custom_window_shape_(NULL) { | 140 custom_window_shape_(NULL) { |
141 } | 141 } |
142 | 142 |
143 DesktopRootWindowHostX11::~DesktopRootWindowHostX11() { | 143 DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() { |
144 root_window_->window()->ClearProperty(kHostForRootWindow); | 144 root_window_->window()->ClearProperty(kHostForRootWindow); |
145 aura::client::SetWindowMoveClient(root_window_->window(), NULL); | 145 aura::client::SetWindowMoveClient(root_window_->window(), NULL); |
146 desktop_native_widget_aura_->OnDesktopRootWindowHostDestroyed(root_window_); | 146 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(root_window_); |
147 if (custom_window_shape_) | 147 if (custom_window_shape_) |
148 XDestroyRegion(custom_window_shape_); | 148 XDestroyRegion(custom_window_shape_); |
149 } | 149 } |
150 | 150 |
151 // static | 151 // static |
152 aura::Window* DesktopRootWindowHostX11::GetContentWindowForXID(XID xid) { | 152 aura::Window* DesktopWindowTreeHostX11::GetContentWindowForXID(XID xid) { |
153 aura::RootWindow* root = aura::RootWindow::GetForAcceleratedWidget(xid); | 153 aura::RootWindow* root = aura::RootWindow::GetForAcceleratedWidget(xid); |
154 return root ? root->window()->GetProperty(kViewsWindowForRootWindow) : NULL; | 154 return root ? root->window()->GetProperty(kViewsWindowForRootWindow) : NULL; |
155 } | 155 } |
156 | 156 |
157 // static | 157 // static |
158 DesktopRootWindowHostX11* DesktopRootWindowHostX11::GetHostForXID(XID xid) { | 158 DesktopWindowTreeHostX11* DesktopWindowTreeHostX11::GetHostForXID(XID xid) { |
159 aura::RootWindow* root = aura::RootWindow::GetForAcceleratedWidget(xid); | 159 aura::RootWindow* root = aura::RootWindow::GetForAcceleratedWidget(xid); |
160 return root ? root->window()->GetProperty(kHostForRootWindow) : NULL; | 160 return root ? root->window()->GetProperty(kHostForRootWindow) : NULL; |
161 } | 161 } |
162 | 162 |
163 // static | 163 // static |
164 std::vector<aura::Window*> DesktopRootWindowHostX11::GetAllOpenWindows() { | 164 std::vector<aura::Window*> DesktopWindowTreeHostX11::GetAllOpenWindows() { |
165 std::vector<aura::Window*> windows(open_windows().size()); | 165 std::vector<aura::Window*> windows(open_windows().size()); |
166 std::transform(open_windows().begin(), | 166 std::transform(open_windows().begin(), |
167 open_windows().end(), | 167 open_windows().end(), |
168 windows.begin(), | 168 windows.begin(), |
169 GetContentWindowForXID); | 169 GetContentWindowForXID); |
170 return windows; | 170 return windows; |
171 } | 171 } |
172 | 172 |
173 gfx::Rect DesktopRootWindowHostX11::GetX11RootWindowBounds() const { | 173 gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowBounds() const { |
174 return bounds_; | 174 return bounds_; |
175 } | 175 } |
176 | 176 |
177 void DesktopRootWindowHostX11::HandleNativeWidgetActivationChanged( | 177 void DesktopWindowTreeHostX11::HandleNativeWidgetActivationChanged( |
178 bool active) { | 178 bool active) { |
179 if (active) { | 179 if (active) { |
180 delegate_->OnHostActivated(); | 180 delegate_->OnHostActivated(); |
181 open_windows().remove(xwindow_); | 181 open_windows().remove(xwindow_); |
182 open_windows().insert(open_windows().begin(), xwindow_); | 182 open_windows().insert(open_windows().begin(), xwindow_); |
183 } | 183 } |
184 | 184 |
185 desktop_native_widget_aura_->HandleActivationChanged(active); | 185 desktop_native_widget_aura_->HandleActivationChanged(active); |
186 | 186 |
187 native_widget_delegate_->AsWidget()->GetRootView()->SchedulePaint(); | 187 native_widget_delegate_->AsWidget()->GetRootView()->SchedulePaint(); |
188 } | 188 } |
189 | 189 |
190 void DesktopRootWindowHostX11::AddObserver( | 190 void DesktopWindowTreeHostX11::AddObserver( |
191 views::DesktopRootWindowHostObserverX11* observer) { | 191 views::DesktopWindowTreeHostObserverX11* observer) { |
192 observer_list_.AddObserver(observer); | 192 observer_list_.AddObserver(observer); |
193 } | 193 } |
194 | 194 |
195 void DesktopRootWindowHostX11::RemoveObserver( | 195 void DesktopWindowTreeHostX11::RemoveObserver( |
196 views::DesktopRootWindowHostObserverX11* observer) { | 196 views::DesktopWindowTreeHostObserverX11* observer) { |
197 observer_list_.RemoveObserver(observer); | 197 observer_list_.RemoveObserver(observer); |
198 } | 198 } |
199 | 199 |
200 void DesktopRootWindowHostX11::CleanUpWindowList() { | 200 void DesktopWindowTreeHostX11::CleanUpWindowList() { |
201 delete open_windows_; | 201 delete open_windows_; |
202 open_windows_ = NULL; | 202 open_windows_ = NULL; |
203 } | 203 } |
204 | 204 |
205 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
206 // DesktopRootWindowHostX11, DesktopRootWindowHost implementation: | 206 // DesktopWindowTreeHostX11, DesktopWindowTreeHost implementation: |
207 | 207 |
208 void DesktopRootWindowHostX11::Init( | 208 void DesktopWindowTreeHostX11::Init( |
209 aura::Window* content_window, | 209 aura::Window* content_window, |
210 const Widget::InitParams& params, | 210 const Widget::InitParams& params, |
211 aura::RootWindow::CreateParams* rw_create_params) { | 211 aura::RootWindow::CreateParams* rw_create_params) { |
212 content_window_ = content_window; | 212 content_window_ = content_window; |
213 | 213 |
214 // TODO(erg): Check whether we *should* be building a RootWindowHost here, or | 214 // TODO(erg): Check whether we *should* be building a WindowTreeHost here, or |
215 // whether we should be proxying requests to another DRWHL. | 215 // whether we should be proxying requests to another DRWHL. |
216 | 216 |
217 // In some situations, views tries to make a zero sized window, and that | 217 // In some situations, views tries to make a zero sized window, and that |
218 // makes us crash. Make sure we have valid sizes. | 218 // makes us crash. Make sure we have valid sizes. |
219 Widget::InitParams sanitized_params = params; | 219 Widget::InitParams sanitized_params = params; |
220 if (sanitized_params.bounds.width() == 0) | 220 if (sanitized_params.bounds.width() == 0) |
221 sanitized_params.bounds.set_width(100); | 221 sanitized_params.bounds.set_width(100); |
222 if (sanitized_params.bounds.height() == 0) | 222 if (sanitized_params.bounds.height() == 0) |
223 sanitized_params.bounds.set_height(100); | 223 sanitized_params.bounds.set_height(100); |
224 | 224 |
225 InitX11Window(sanitized_params); | 225 InitX11Window(sanitized_params); |
226 | 226 |
227 rw_create_params->initial_bounds = bounds_; | 227 rw_create_params->initial_bounds = bounds_; |
228 rw_create_params->host = this; | 228 rw_create_params->host = this; |
229 } | 229 } |
230 | 230 |
231 void DesktopRootWindowHostX11::OnRootWindowCreated( | 231 void DesktopWindowTreeHostX11::OnRootWindowCreated( |
232 aura::RootWindow* root, | 232 aura::RootWindow* root, |
233 const Widget::InitParams& params) { | 233 const Widget::InitParams& params) { |
234 root_window_ = root; | 234 root_window_ = root; |
235 | 235 |
236 root_window_->window()->SetProperty(kViewsWindowForRootWindow, | 236 root_window_->window()->SetProperty(kViewsWindowForRootWindow, |
237 content_window_); | 237 content_window_); |
238 root_window_->window()->SetProperty(kHostForRootWindow, this); | 238 root_window_->window()->SetProperty(kHostForRootWindow, this); |
239 delegate_ = root_window_; | 239 delegate_ = root_window_; |
240 | 240 |
241 // If we're given a parent, we need to mark ourselves as transient to another | 241 // If we're given a parent, we need to mark ourselves as transient to another |
(...skipping 12 matching lines...) Expand all Loading... |
254 desktop_native_widget_aura_->root_window_event_filter()->AddHandler( | 254 desktop_native_widget_aura_->root_window_event_filter()->AddHandler( |
255 x11_window_event_filter_.get()); | 255 x11_window_event_filter_.get()); |
256 | 256 |
257 x11_window_move_client_.reset(new X11DesktopWindowMoveClient); | 257 x11_window_move_client_.reset(new X11DesktopWindowMoveClient); |
258 aura::client::SetWindowMoveClient(root_window_->window(), | 258 aura::client::SetWindowMoveClient(root_window_->window(), |
259 x11_window_move_client_.get()); | 259 x11_window_move_client_.get()); |
260 | 260 |
261 native_widget_delegate_->OnNativeWidgetCreated(true); | 261 native_widget_delegate_->OnNativeWidgetCreated(true); |
262 } | 262 } |
263 | 263 |
264 scoped_ptr<corewm::Tooltip> DesktopRootWindowHostX11::CreateTooltip() { | 264 scoped_ptr<corewm::Tooltip> DesktopWindowTreeHostX11::CreateTooltip() { |
265 return scoped_ptr<corewm::Tooltip>( | 265 return scoped_ptr<corewm::Tooltip>( |
266 new corewm::TooltipAura(gfx::SCREEN_TYPE_NATIVE)); | 266 new corewm::TooltipAura(gfx::SCREEN_TYPE_NATIVE)); |
267 } | 267 } |
268 | 268 |
269 scoped_ptr<aura::client::DragDropClient> | 269 scoped_ptr<aura::client::DragDropClient> |
270 DesktopRootWindowHostX11::CreateDragDropClient( | 270 DesktopWindowTreeHostX11::CreateDragDropClient( |
271 DesktopNativeCursorManager* cursor_manager) { | 271 DesktopNativeCursorManager* cursor_manager) { |
272 drag_drop_client_ = new DesktopDragDropClientAuraX11( | 272 drag_drop_client_ = new DesktopDragDropClientAuraX11( |
273 root_window_->window(), cursor_manager, xdisplay_, xwindow_); | 273 root_window_->window(), cursor_manager, xdisplay_, xwindow_); |
274 return scoped_ptr<aura::client::DragDropClient>(drag_drop_client_).Pass(); | 274 return scoped_ptr<aura::client::DragDropClient>(drag_drop_client_).Pass(); |
275 } | 275 } |
276 | 276 |
277 void DesktopRootWindowHostX11::Close() { | 277 void DesktopWindowTreeHostX11::Close() { |
278 // TODO(erg): Might need to do additional hiding tasks here. | 278 // TODO(erg): Might need to do additional hiding tasks here. |
279 | 279 |
280 if (!close_widget_factory_.HasWeakPtrs()) { | 280 if (!close_widget_factory_.HasWeakPtrs()) { |
281 // And we delay the close so that if we are called from an ATL callback, | 281 // And we delay the close so that if we are called from an ATL callback, |
282 // we don't destroy the window before the callback returned (as the caller | 282 // we don't destroy the window before the callback returned (as the caller |
283 // may delete ourselves on destroy and the ATL callback would still | 283 // may delete ourselves on destroy and the ATL callback would still |
284 // dereference us when the callback returns). | 284 // dereference us when the callback returns). |
285 base::MessageLoop::current()->PostTask( | 285 base::MessageLoop::current()->PostTask( |
286 FROM_HERE, | 286 FROM_HERE, |
287 base::Bind(&DesktopRootWindowHostX11::CloseNow, | 287 base::Bind(&DesktopWindowTreeHostX11::CloseNow, |
288 close_widget_factory_.GetWeakPtr())); | 288 close_widget_factory_.GetWeakPtr())); |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 void DesktopRootWindowHostX11::CloseNow() { | 292 void DesktopWindowTreeHostX11::CloseNow() { |
293 if (xwindow_ == None) | 293 if (xwindow_ == None) |
294 return; | 294 return; |
295 | 295 |
296 x11_capture_.reset(); | 296 x11_capture_.reset(); |
297 native_widget_delegate_->OnNativeWidgetDestroying(); | 297 native_widget_delegate_->OnNativeWidgetDestroying(); |
298 | 298 |
299 // If we have children, close them. Use a copy for iteration because they'll | 299 // If we have children, close them. Use a copy for iteration because they'll |
300 // remove themselves. | 300 // remove themselves. |
301 std::set<DesktopRootWindowHostX11*> window_children_copy = window_children_; | 301 std::set<DesktopWindowTreeHostX11*> window_children_copy = window_children_; |
302 for (std::set<DesktopRootWindowHostX11*>::iterator it = | 302 for (std::set<DesktopWindowTreeHostX11*>::iterator it = |
303 window_children_copy.begin(); it != window_children_copy.end(); | 303 window_children_copy.begin(); it != window_children_copy.end(); |
304 ++it) { | 304 ++it) { |
305 (*it)->CloseNow(); | 305 (*it)->CloseNow(); |
306 } | 306 } |
307 DCHECK(window_children_.empty()); | 307 DCHECK(window_children_.empty()); |
308 | 308 |
309 // If we have a parent, remove ourselves from its children list. | 309 // If we have a parent, remove ourselves from its children list. |
310 if (window_parent_) { | 310 if (window_parent_) { |
311 window_parent_->window_children_.erase(this); | 311 window_parent_->window_children_.erase(this); |
312 window_parent_ = NULL; | 312 window_parent_ = NULL; |
313 } | 313 } |
314 | 314 |
315 // Remove the event listeners we've installed. We need to remove these | 315 // Remove the event listeners we've installed. We need to remove these |
316 // because otherwise we get assert during ~RootWindow(). | 316 // because otherwise we get assert during ~RootWindow(). |
317 desktop_native_widget_aura_->root_window_event_filter()->RemoveHandler( | 317 desktop_native_widget_aura_->root_window_event_filter()->RemoveHandler( |
318 x11_window_event_filter_.get()); | 318 x11_window_event_filter_.get()); |
319 | 319 |
320 open_windows().remove(xwindow_); | 320 open_windows().remove(xwindow_); |
321 // Actually free our native resources. | 321 // Actually free our native resources. |
322 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); | 322 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); |
323 XDestroyWindow(xdisplay_, xwindow_); | 323 XDestroyWindow(xdisplay_, xwindow_); |
324 xwindow_ = None; | 324 xwindow_ = None; |
325 | 325 |
326 desktop_native_widget_aura_->OnHostClosed(); | 326 desktop_native_widget_aura_->OnHostClosed(); |
327 } | 327 } |
328 | 328 |
329 aura::RootWindowHost* DesktopRootWindowHostX11::AsRootWindowHost() { | 329 aura::WindowTreeHost* DesktopWindowTreeHostX11::AsWindowTreeHost() { |
330 return this; | 330 return this; |
331 } | 331 } |
332 | 332 |
333 void DesktopRootWindowHostX11::ShowWindowWithState( | 333 void DesktopWindowTreeHostX11::ShowWindowWithState( |
334 ui::WindowShowState show_state) { | 334 ui::WindowShowState show_state) { |
335 if (show_state != ui::SHOW_STATE_DEFAULT && | 335 if (show_state != ui::SHOW_STATE_DEFAULT && |
336 show_state != ui::SHOW_STATE_NORMAL) { | 336 show_state != ui::SHOW_STATE_NORMAL) { |
337 // Only forwarding to Show(). | 337 // Only forwarding to Show(). |
338 NOTIMPLEMENTED(); | 338 NOTIMPLEMENTED(); |
339 } | 339 } |
340 | 340 |
341 Show(); | 341 Show(); |
342 } | 342 } |
343 | 343 |
344 void DesktopRootWindowHostX11::ShowMaximizedWithBounds( | 344 void DesktopWindowTreeHostX11::ShowMaximizedWithBounds( |
345 const gfx::Rect& restored_bounds) { | 345 const gfx::Rect& restored_bounds) { |
346 restored_bounds_ = restored_bounds; | 346 restored_bounds_ = restored_bounds; |
347 Maximize(); | 347 Maximize(); |
348 Show(); | 348 Show(); |
349 } | 349 } |
350 | 350 |
351 bool DesktopRootWindowHostX11::IsVisible() const { | 351 bool DesktopWindowTreeHostX11::IsVisible() const { |
352 return window_mapped_; | 352 return window_mapped_; |
353 } | 353 } |
354 | 354 |
355 void DesktopRootWindowHostX11::SetSize(const gfx::Size& size) { | 355 void DesktopWindowTreeHostX11::SetSize(const gfx::Size& size) { |
356 // TODO(erg): | 356 // TODO(erg): |
357 NOTIMPLEMENTED(); | 357 NOTIMPLEMENTED(); |
358 } | 358 } |
359 | 359 |
360 void DesktopRootWindowHostX11::StackAtTop() { | 360 void DesktopWindowTreeHostX11::StackAtTop() { |
361 XRaiseWindow(xdisplay_, xwindow_); | 361 XRaiseWindow(xdisplay_, xwindow_); |
362 } | 362 } |
363 | 363 |
364 void DesktopRootWindowHostX11::CenterWindow(const gfx::Size& size) { | 364 void DesktopWindowTreeHostX11::CenterWindow(const gfx::Size& size) { |
365 gfx::Rect parent_bounds = GetWorkAreaBoundsInScreen(); | 365 gfx::Rect parent_bounds = GetWorkAreaBoundsInScreen(); |
366 | 366 |
367 // If |window_|'s transient parent bounds are big enough to contain |size|, | 367 // If |window_|'s transient parent bounds are big enough to contain |size|, |
368 // use them instead. | 368 // use them instead. |
369 if (content_window_->transient_parent()) { | 369 if (content_window_->transient_parent()) { |
370 gfx::Rect transient_parent_rect = | 370 gfx::Rect transient_parent_rect = |
371 content_window_->transient_parent()->GetBoundsInScreen(); | 371 content_window_->transient_parent()->GetBoundsInScreen(); |
372 if (transient_parent_rect.height() >= size.height() && | 372 if (transient_parent_rect.height() >= size.height() && |
373 transient_parent_rect.width() >= size.width()) { | 373 transient_parent_rect.width() >= size.width()) { |
374 parent_bounds = transient_parent_rect; | 374 parent_bounds = transient_parent_rect; |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 gfx::Rect window_bounds( | 378 gfx::Rect window_bounds( |
379 parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, | 379 parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, |
380 parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, | 380 parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, |
381 size.width(), | 381 size.width(), |
382 size.height()); | 382 size.height()); |
383 // Don't size the window bigger than the parent, otherwise the user may not be | 383 // Don't size the window bigger than the parent, otherwise the user may not be |
384 // able to close or move it. | 384 // able to close or move it. |
385 window_bounds.AdjustToFit(parent_bounds); | 385 window_bounds.AdjustToFit(parent_bounds); |
386 | 386 |
387 SetBounds(window_bounds); | 387 SetBounds(window_bounds); |
388 } | 388 } |
389 | 389 |
390 void DesktopRootWindowHostX11::GetWindowPlacement( | 390 void DesktopWindowTreeHostX11::GetWindowPlacement( |
391 gfx::Rect* bounds, | 391 gfx::Rect* bounds, |
392 ui::WindowShowState* show_state) const { | 392 ui::WindowShowState* show_state) const { |
393 *bounds = bounds_; | 393 *bounds = bounds_; |
394 | 394 |
395 if (IsFullscreen()) { | 395 if (IsFullscreen()) { |
396 *show_state = ui::SHOW_STATE_FULLSCREEN; | 396 *show_state = ui::SHOW_STATE_FULLSCREEN; |
397 } else if (IsMinimized()) { | 397 } else if (IsMinimized()) { |
398 *show_state = ui::SHOW_STATE_MINIMIZED; | 398 *show_state = ui::SHOW_STATE_MINIMIZED; |
399 } else if (IsMaximized()) { | 399 } else if (IsMaximized()) { |
400 *show_state = ui::SHOW_STATE_MAXIMIZED; | 400 *show_state = ui::SHOW_STATE_MAXIMIZED; |
401 } else if (!IsActive()) { | 401 } else if (!IsActive()) { |
402 *show_state = ui::SHOW_STATE_INACTIVE; | 402 *show_state = ui::SHOW_STATE_INACTIVE; |
403 } else { | 403 } else { |
404 *show_state = ui::SHOW_STATE_NORMAL; | 404 *show_state = ui::SHOW_STATE_NORMAL; |
405 } | 405 } |
406 } | 406 } |
407 | 407 |
408 gfx::Rect DesktopRootWindowHostX11::GetWindowBoundsInScreen() const { | 408 gfx::Rect DesktopWindowTreeHostX11::GetWindowBoundsInScreen() const { |
409 return bounds_; | 409 return bounds_; |
410 } | 410 } |
411 | 411 |
412 gfx::Rect DesktopRootWindowHostX11::GetClientAreaBoundsInScreen() const { | 412 gfx::Rect DesktopWindowTreeHostX11::GetClientAreaBoundsInScreen() const { |
413 // TODO(erg): The NativeWidgetAura version returns |bounds_|, claiming its | 413 // TODO(erg): The NativeWidgetAura version returns |bounds_|, claiming its |
414 // needed for View::ConvertPointToScreen() to work | 414 // needed for View::ConvertPointToScreen() to work |
415 // correctly. DesktopRootWindowHostWin::GetClientAreaBoundsInScreen() just | 415 // correctly. DesktopWindowTreeHostWin::GetClientAreaBoundsInScreen() just |
416 // asks windows what it thinks the client rect is. | 416 // asks windows what it thinks the client rect is. |
417 // | 417 // |
418 // Attempts to calculate the rect by asking the NonClientFrameView what it | 418 // Attempts to calculate the rect by asking the NonClientFrameView what it |
419 // thought its GetBoundsForClientView() were broke combobox drop down | 419 // thought its GetBoundsForClientView() were broke combobox drop down |
420 // placement. | 420 // placement. |
421 return bounds_; | 421 return bounds_; |
422 } | 422 } |
423 | 423 |
424 gfx::Rect DesktopRootWindowHostX11::GetRestoredBounds() const { | 424 gfx::Rect DesktopWindowTreeHostX11::GetRestoredBounds() const { |
425 // We can't reliably track the restored bounds of a window, but we can get | 425 // We can't reliably track the restored bounds of a window, but we can get |
426 // the 90% case down. When *chrome* is the process that requests maximizing | 426 // the 90% case down. When *chrome* is the process that requests maximizing |
427 // or restoring bounds, we can record the current bounds before we request | 427 // or restoring bounds, we can record the current bounds before we request |
428 // maximization, and clear it when we detect a state change. | 428 // maximization, and clear it when we detect a state change. |
429 if (!restored_bounds_.IsEmpty()) | 429 if (!restored_bounds_.IsEmpty()) |
430 return restored_bounds_; | 430 return restored_bounds_; |
431 | 431 |
432 return GetWindowBoundsInScreen(); | 432 return GetWindowBoundsInScreen(); |
433 } | 433 } |
434 | 434 |
435 gfx::Rect DesktopRootWindowHostX11::GetWorkAreaBoundsInScreen() const { | 435 gfx::Rect DesktopWindowTreeHostX11::GetWorkAreaBoundsInScreen() const { |
436 std::vector<int> value; | 436 std::vector<int> value; |
437 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && | 437 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && |
438 value.size() >= 4) { | 438 value.size() >= 4) { |
439 return gfx::Rect(value[0], value[1], value[2], value[3]); | 439 return gfx::Rect(value[0], value[1], value[2], value[3]); |
440 } | 440 } |
441 | 441 |
442 // Fetch the geometry of the root window. | 442 // Fetch the geometry of the root window. |
443 Window root; | 443 Window root; |
444 int x, y; | 444 int x, y; |
445 unsigned int width, height; | 445 unsigned int width, height; |
446 unsigned int border_width, depth; | 446 unsigned int border_width, depth; |
447 if (!XGetGeometry(xdisplay_, x_root_window_, &root, &x, &y, | 447 if (!XGetGeometry(xdisplay_, x_root_window_, &root, &x, &y, |
448 &width, &height, &border_width, &depth)) { | 448 &width, &height, &border_width, &depth)) { |
449 NOTIMPLEMENTED(); | 449 NOTIMPLEMENTED(); |
450 return gfx::Rect(0, 0, 10, 10); | 450 return gfx::Rect(0, 0, 10, 10); |
451 } | 451 } |
452 | 452 |
453 return gfx::Rect(x, y, width, height); | 453 return gfx::Rect(x, y, width, height); |
454 } | 454 } |
455 | 455 |
456 void DesktopRootWindowHostX11::SetShape(gfx::NativeRegion native_region) { | 456 void DesktopWindowTreeHostX11::SetShape(gfx::NativeRegion native_region) { |
457 if (custom_window_shape_) | 457 if (custom_window_shape_) |
458 XDestroyRegion(custom_window_shape_); | 458 XDestroyRegion(custom_window_shape_); |
459 custom_window_shape_ = gfx::CreateRegionFromSkRegion(*native_region); | 459 custom_window_shape_ = gfx::CreateRegionFromSkRegion(*native_region); |
460 ResetWindowRegion(); | 460 ResetWindowRegion(); |
461 delete native_region; | 461 delete native_region; |
462 } | 462 } |
463 | 463 |
464 void DesktopRootWindowHostX11::Activate() { | 464 void DesktopWindowTreeHostX11::Activate() { |
465 X11DesktopHandler::get()->ActivateWindow(xwindow_); | 465 X11DesktopHandler::get()->ActivateWindow(xwindow_); |
466 native_widget_delegate_->AsWidget()->SetInitialFocus(); | 466 native_widget_delegate_->AsWidget()->SetInitialFocus(); |
467 } | 467 } |
468 | 468 |
469 void DesktopRootWindowHostX11::Deactivate() { | 469 void DesktopWindowTreeHostX11::Deactivate() { |
470 // Deactivating a window means activating nothing. | 470 // Deactivating a window means activating nothing. |
471 x11_capture_.reset(); | 471 x11_capture_.reset(); |
472 X11DesktopHandler::get()->ActivateWindow(None); | 472 X11DesktopHandler::get()->ActivateWindow(None); |
473 } | 473 } |
474 | 474 |
475 bool DesktopRootWindowHostX11::IsActive() const { | 475 bool DesktopWindowTreeHostX11::IsActive() const { |
476 return X11DesktopHandler::get()->IsActiveWindow(xwindow_); | 476 return X11DesktopHandler::get()->IsActiveWindow(xwindow_); |
477 } | 477 } |
478 | 478 |
479 void DesktopRootWindowHostX11::Maximize() { | 479 void DesktopWindowTreeHostX11::Maximize() { |
480 // When we're the process requesting the maximizing, we can accurately keep | 480 // When we're the process requesting the maximizing, we can accurately keep |
481 // track of our restored bounds instead of relying on the heuristics that are | 481 // track of our restored bounds instead of relying on the heuristics that are |
482 // in the PropertyNotify and ConfigureNotify handlers. | 482 // in the PropertyNotify and ConfigureNotify handlers. |
483 restored_bounds_ = bounds_; | 483 restored_bounds_ = bounds_; |
484 | 484 |
485 SetWMSpecState(true, | 485 SetWMSpecState(true, |
486 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"), | 486 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"), |
487 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")); | 487 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")); |
488 } | 488 } |
489 | 489 |
490 void DesktopRootWindowHostX11::Minimize() { | 490 void DesktopWindowTreeHostX11::Minimize() { |
491 x11_capture_.reset(); | 491 x11_capture_.reset(); |
492 XIconifyWindow(xdisplay_, xwindow_, 0); | 492 XIconifyWindow(xdisplay_, xwindow_, 0); |
493 } | 493 } |
494 | 494 |
495 void DesktopRootWindowHostX11::Restore() { | 495 void DesktopWindowTreeHostX11::Restore() { |
496 SetWMSpecState(false, | 496 SetWMSpecState(false, |
497 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"), | 497 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"), |
498 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")); | 498 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")); |
499 } | 499 } |
500 | 500 |
501 bool DesktopRootWindowHostX11::IsMaximized() const { | 501 bool DesktopWindowTreeHostX11::IsMaximized() const { |
502 return (HasWMSpecProperty("_NET_WM_STATE_MAXIMIZED_VERT") && | 502 return (HasWMSpecProperty("_NET_WM_STATE_MAXIMIZED_VERT") && |
503 HasWMSpecProperty("_NET_WM_STATE_MAXIMIZED_HORZ")); | 503 HasWMSpecProperty("_NET_WM_STATE_MAXIMIZED_HORZ")); |
504 } | 504 } |
505 | 505 |
506 bool DesktopRootWindowHostX11::IsMinimized() const { | 506 bool DesktopWindowTreeHostX11::IsMinimized() const { |
507 return HasWMSpecProperty("_NET_WM_STATE_HIDDEN"); | 507 return HasWMSpecProperty("_NET_WM_STATE_HIDDEN"); |
508 } | 508 } |
509 | 509 |
510 | 510 |
511 bool DesktopRootWindowHostX11::HasCapture() const { | 511 bool DesktopWindowTreeHostX11::HasCapture() const { |
512 return g_current_capture == this; | 512 return g_current_capture == this; |
513 } | 513 } |
514 | 514 |
515 void DesktopRootWindowHostX11::SetAlwaysOnTop(bool always_on_top) { | 515 void DesktopWindowTreeHostX11::SetAlwaysOnTop(bool always_on_top) { |
516 is_always_on_top_ = always_on_top; | 516 is_always_on_top_ = always_on_top; |
517 SetWMSpecState(always_on_top, | 517 SetWMSpecState(always_on_top, |
518 atom_cache_.GetAtom("_NET_WM_STATE_ABOVE"), | 518 atom_cache_.GetAtom("_NET_WM_STATE_ABOVE"), |
519 None); | 519 None); |
520 } | 520 } |
521 | 521 |
522 bool DesktopRootWindowHostX11::IsAlwaysOnTop() const { | 522 bool DesktopWindowTreeHostX11::IsAlwaysOnTop() const { |
523 return is_always_on_top_; | 523 return is_always_on_top_; |
524 } | 524 } |
525 | 525 |
526 bool DesktopRootWindowHostX11::SetWindowTitle(const base::string16& title) { | 526 bool DesktopWindowTreeHostX11::SetWindowTitle(const base::string16& title) { |
527 if (window_title_ == title) | 527 if (window_title_ == title) |
528 return false; | 528 return false; |
529 window_title_ = title; | 529 window_title_ = title; |
530 std::string utf8str = UTF16ToUTF8(title); | 530 std::string utf8str = UTF16ToUTF8(title); |
531 XChangeProperty(xdisplay_, | 531 XChangeProperty(xdisplay_, |
532 xwindow_, | 532 xwindow_, |
533 atom_cache_.GetAtom("_NET_WM_NAME"), | 533 atom_cache_.GetAtom("_NET_WM_NAME"), |
534 atom_cache_.GetAtom("UTF8_STRING"), | 534 atom_cache_.GetAtom("UTF8_STRING"), |
535 8, | 535 8, |
536 PropModeReplace, | 536 PropModeReplace, |
537 reinterpret_cast<const unsigned char*>(utf8str.c_str()), | 537 reinterpret_cast<const unsigned char*>(utf8str.c_str()), |
538 utf8str.size()); | 538 utf8str.size()); |
539 // TODO(erg): This is technically wrong. So XStoreName and friends expect | 539 // TODO(erg): This is technically wrong. So XStoreName and friends expect |
540 // this in Host Portable Character Encoding instead of UTF-8, which I believe | 540 // this in Host Portable Character Encoding instead of UTF-8, which I believe |
541 // is Compound Text. This shouldn't matter 90% of the time since this is the | 541 // is Compound Text. This shouldn't matter 90% of the time since this is the |
542 // fallback to the UTF8 property above. | 542 // fallback to the UTF8 property above. |
543 XStoreName(xdisplay_, xwindow_, utf8str.c_str()); | 543 XStoreName(xdisplay_, xwindow_, utf8str.c_str()); |
544 return true; | 544 return true; |
545 } | 545 } |
546 | 546 |
547 void DesktopRootWindowHostX11::ClearNativeFocus() { | 547 void DesktopWindowTreeHostX11::ClearNativeFocus() { |
548 // This method is weird and misnamed. Instead of clearing the native focus, | 548 // This method is weird and misnamed. Instead of clearing the native focus, |
549 // it sets the focus to our |content_window_|, which will trigger a cascade | 549 // it sets the focus to our |content_window_|, which will trigger a cascade |
550 // of focus changes into views. | 550 // of focus changes into views. |
551 if (content_window_ && aura::client::GetFocusClient(content_window_) && | 551 if (content_window_ && aura::client::GetFocusClient(content_window_) && |
552 content_window_->Contains( | 552 content_window_->Contains( |
553 aura::client::GetFocusClient(content_window_)->GetFocusedWindow())) { | 553 aura::client::GetFocusClient(content_window_)->GetFocusedWindow())) { |
554 aura::client::GetFocusClient(content_window_)->FocusWindow(content_window_); | 554 aura::client::GetFocusClient(content_window_)->FocusWindow(content_window_); |
555 } | 555 } |
556 } | 556 } |
557 | 557 |
558 Widget::MoveLoopResult DesktopRootWindowHostX11::RunMoveLoop( | 558 Widget::MoveLoopResult DesktopWindowTreeHostX11::RunMoveLoop( |
559 const gfx::Vector2d& drag_offset, | 559 const gfx::Vector2d& drag_offset, |
560 Widget::MoveLoopSource source, | 560 Widget::MoveLoopSource source, |
561 Widget::MoveLoopEscapeBehavior escape_behavior) { | 561 Widget::MoveLoopEscapeBehavior escape_behavior) { |
562 aura::client::WindowMoveSource window_move_source = | 562 aura::client::WindowMoveSource window_move_source = |
563 source == Widget::MOVE_LOOP_SOURCE_MOUSE ? | 563 source == Widget::MOVE_LOOP_SOURCE_MOUSE ? |
564 aura::client::WINDOW_MOVE_SOURCE_MOUSE : | 564 aura::client::WINDOW_MOVE_SOURCE_MOUSE : |
565 aura::client::WINDOW_MOVE_SOURCE_TOUCH; | 565 aura::client::WINDOW_MOVE_SOURCE_TOUCH; |
566 if (x11_window_move_client_->RunMoveLoop(content_window_, drag_offset, | 566 if (x11_window_move_client_->RunMoveLoop(content_window_, drag_offset, |
567 window_move_source) == aura::client::MOVE_SUCCESSFUL) | 567 window_move_source) == aura::client::MOVE_SUCCESSFUL) |
568 return Widget::MOVE_LOOP_SUCCESSFUL; | 568 return Widget::MOVE_LOOP_SUCCESSFUL; |
569 | 569 |
570 return Widget::MOVE_LOOP_CANCELED; | 570 return Widget::MOVE_LOOP_CANCELED; |
571 } | 571 } |
572 | 572 |
573 void DesktopRootWindowHostX11::EndMoveLoop() { | 573 void DesktopWindowTreeHostX11::EndMoveLoop() { |
574 x11_window_move_client_->EndMoveLoop(); | 574 x11_window_move_client_->EndMoveLoop(); |
575 } | 575 } |
576 | 576 |
577 void DesktopRootWindowHostX11::SetVisibilityChangedAnimationsEnabled( | 577 void DesktopWindowTreeHostX11::SetVisibilityChangedAnimationsEnabled( |
578 bool value) { | 578 bool value) { |
579 // Much like the previous NativeWidgetGtk, we don't have anything to do here. | 579 // Much like the previous NativeWidgetGtk, we don't have anything to do here. |
580 } | 580 } |
581 | 581 |
582 bool DesktopRootWindowHostX11::ShouldUseNativeFrame() { | 582 bool DesktopWindowTreeHostX11::ShouldUseNativeFrame() { |
583 return false; | 583 return false; |
584 } | 584 } |
585 | 585 |
586 void DesktopRootWindowHostX11::FrameTypeChanged() { | 586 void DesktopWindowTreeHostX11::FrameTypeChanged() { |
587 // Replace the frame and layout the contents. Even though we don't have a | 587 // Replace the frame and layout the contents. Even though we don't have a |
588 // swapable glass frame like on Windows, we still replace the frame because | 588 // swapable glass frame like on Windows, we still replace the frame because |
589 // the button assets don't update otherwise. | 589 // the button assets don't update otherwise. |
590 native_widget_delegate_->AsWidget()->non_client_view()->UpdateFrame(); | 590 native_widget_delegate_->AsWidget()->non_client_view()->UpdateFrame(); |
591 } | 591 } |
592 | 592 |
593 NonClientFrameView* DesktopRootWindowHostX11::CreateNonClientFrameView() { | 593 NonClientFrameView* DesktopWindowTreeHostX11::CreateNonClientFrameView() { |
594 return NULL; | 594 return NULL; |
595 } | 595 } |
596 | 596 |
597 void DesktopRootWindowHostX11::SetFullscreen(bool fullscreen) { | 597 void DesktopWindowTreeHostX11::SetFullscreen(bool fullscreen) { |
598 is_fullscreen_ = fullscreen; | 598 is_fullscreen_ = fullscreen; |
599 SetWMSpecState(fullscreen, | 599 SetWMSpecState(fullscreen, |
600 atom_cache_.GetAtom("_NET_WM_STATE_FULLSCREEN"), | 600 atom_cache_.GetAtom("_NET_WM_STATE_FULLSCREEN"), |
601 None); | 601 None); |
602 } | 602 } |
603 | 603 |
604 bool DesktopRootWindowHostX11::IsFullscreen() const { | 604 bool DesktopWindowTreeHostX11::IsFullscreen() const { |
605 return is_fullscreen_; | 605 return is_fullscreen_; |
606 } | 606 } |
607 | 607 |
608 void DesktopRootWindowHostX11::SetOpacity(unsigned char opacity) { | 608 void DesktopWindowTreeHostX11::SetOpacity(unsigned char opacity) { |
609 // X server opacity is in terms of 32 bit unsigned int space, and counts from | 609 // X server opacity is in terms of 32 bit unsigned int space, and counts from |
610 // the opposite direction. | 610 // the opposite direction. |
611 // XChangeProperty() expects "cardinality" to be long. | 611 // XChangeProperty() expects "cardinality" to be long. |
612 unsigned long cardinality = opacity * 0x1010101; | 612 unsigned long cardinality = opacity * 0x1010101; |
613 | 613 |
614 if (cardinality == 0xffffffff) { | 614 if (cardinality == 0xffffffff) { |
615 XDeleteProperty(xdisplay_, xwindow_, | 615 XDeleteProperty(xdisplay_, xwindow_, |
616 atom_cache_.GetAtom("_NET_WM_WINDOW_OPACITY")); | 616 atom_cache_.GetAtom("_NET_WM_WINDOW_OPACITY")); |
617 } else { | 617 } else { |
618 XChangeProperty(xdisplay_, xwindow_, | 618 XChangeProperty(xdisplay_, xwindow_, |
619 atom_cache_.GetAtom("_NET_WM_WINDOW_OPACITY"), | 619 atom_cache_.GetAtom("_NET_WM_WINDOW_OPACITY"), |
620 XA_CARDINAL, 32, | 620 XA_CARDINAL, 32, |
621 PropModeReplace, | 621 PropModeReplace, |
622 reinterpret_cast<unsigned char*>(&cardinality), 1); | 622 reinterpret_cast<unsigned char*>(&cardinality), 1); |
623 } | 623 } |
624 } | 624 } |
625 | 625 |
626 void DesktopRootWindowHostX11::SetWindowIcons( | 626 void DesktopWindowTreeHostX11::SetWindowIcons( |
627 const gfx::ImageSkia& window_icon, const gfx::ImageSkia& app_icon) { | 627 const gfx::ImageSkia& window_icon, const gfx::ImageSkia& app_icon) { |
628 // TODO(erg): The way we handle icons across different versions of chrome | 628 // TODO(erg): The way we handle icons across different versions of chrome |
629 // could be substantially improved. The Windows version does its own thing | 629 // could be substantially improved. The Windows version does its own thing |
630 // and only sometimes comes down this code path. The icon stuff in | 630 // and only sometimes comes down this code path. The icon stuff in |
631 // ChromeViewsDelegate is hard coded to use HICONs. Likewise, we're hard | 631 // ChromeViewsDelegate is hard coded to use HICONs. Likewise, we're hard |
632 // coded to be given two images instead of an arbitrary collection of images | 632 // coded to be given two images instead of an arbitrary collection of images |
633 // so that we can pass to the WM. | 633 // so that we can pass to the WM. |
634 // | 634 // |
635 // All of this could be made much, much better. | 635 // All of this could be made much, much better. |
636 std::vector<unsigned long> data; | 636 std::vector<unsigned long> data; |
637 | 637 |
638 if (window_icon.HasRepresentation(1.0f)) | 638 if (window_icon.HasRepresentation(1.0f)) |
639 SerializeImageRepresentation(window_icon.GetRepresentation(1.0f), &data); | 639 SerializeImageRepresentation(window_icon.GetRepresentation(1.0f), &data); |
640 | 640 |
641 if (app_icon.HasRepresentation(1.0f)) | 641 if (app_icon.HasRepresentation(1.0f)) |
642 SerializeImageRepresentation(app_icon.GetRepresentation(1.0f), &data); | 642 SerializeImageRepresentation(app_icon.GetRepresentation(1.0f), &data); |
643 | 643 |
644 if (data.empty()) | 644 if (data.empty()) |
645 XDeleteProperty(xdisplay_, xwindow_, atom_cache_.GetAtom("_NET_WM_ICON")); | 645 XDeleteProperty(xdisplay_, xwindow_, atom_cache_.GetAtom("_NET_WM_ICON")); |
646 else | 646 else |
647 ui::SetAtomArrayProperty(xwindow_, "_NET_WM_ICON", "CARDINAL", data); | 647 ui::SetAtomArrayProperty(xwindow_, "_NET_WM_ICON", "CARDINAL", data); |
648 } | 648 } |
649 | 649 |
650 void DesktopRootWindowHostX11::InitModalType(ui::ModalType modal_type) { | 650 void DesktopWindowTreeHostX11::InitModalType(ui::ModalType modal_type) { |
651 switch (modal_type) { | 651 switch (modal_type) { |
652 case ui::MODAL_TYPE_NONE: | 652 case ui::MODAL_TYPE_NONE: |
653 break; | 653 break; |
654 default: | 654 default: |
655 // TODO(erg): Figure out under what situations |modal_type| isn't | 655 // TODO(erg): Figure out under what situations |modal_type| isn't |
656 // none. The comment in desktop_native_widget_aura.cc suggests that this | 656 // none. The comment in desktop_native_widget_aura.cc suggests that this |
657 // is rare. | 657 // is rare. |
658 NOTIMPLEMENTED(); | 658 NOTIMPLEMENTED(); |
659 } | 659 } |
660 } | 660 } |
661 | 661 |
662 void DesktopRootWindowHostX11::FlashFrame(bool flash_frame) { | 662 void DesktopWindowTreeHostX11::FlashFrame(bool flash_frame) { |
663 // TODO(erg): | 663 // TODO(erg): |
664 NOTIMPLEMENTED(); | 664 NOTIMPLEMENTED(); |
665 } | 665 } |
666 | 666 |
667 void DesktopRootWindowHostX11::OnRootViewLayout() const { | 667 void DesktopWindowTreeHostX11::OnRootViewLayout() const { |
668 if (!window_mapped_) | 668 if (!window_mapped_) |
669 return; | 669 return; |
670 | 670 |
671 XSizeHints hints; | 671 XSizeHints hints; |
672 long supplied_return; | 672 long supplied_return; |
673 XGetWMNormalHints(xdisplay_, xwindow_, &hints, &supplied_return); | 673 XGetWMNormalHints(xdisplay_, xwindow_, &hints, &supplied_return); |
674 | 674 |
675 gfx::Size minimum = native_widget_delegate_->GetMinimumSize(); | 675 gfx::Size minimum = native_widget_delegate_->GetMinimumSize(); |
676 if (minimum.IsEmpty()) { | 676 if (minimum.IsEmpty()) { |
677 hints.flags &= ~PMinSize; | 677 hints.flags &= ~PMinSize; |
678 } else { | 678 } else { |
679 hints.flags |= PMinSize; | 679 hints.flags |= PMinSize; |
680 hints.min_width = minimum.width(); | 680 hints.min_width = minimum.width(); |
681 hints.min_height = minimum.height(); | 681 hints.min_height = minimum.height(); |
682 } | 682 } |
683 | 683 |
684 gfx::Size maximum = native_widget_delegate_->GetMaximumSize(); | 684 gfx::Size maximum = native_widget_delegate_->GetMaximumSize(); |
685 if (maximum.IsEmpty()) { | 685 if (maximum.IsEmpty()) { |
686 hints.flags &= ~PMaxSize; | 686 hints.flags &= ~PMaxSize; |
687 } else { | 687 } else { |
688 hints.flags |= PMaxSize; | 688 hints.flags |= PMaxSize; |
689 hints.max_width = maximum.width(); | 689 hints.max_width = maximum.width(); |
690 hints.max_height = maximum.height(); | 690 hints.max_height = maximum.height(); |
691 } | 691 } |
692 | 692 |
693 XSetWMNormalHints(xdisplay_, xwindow_, &hints); | 693 XSetWMNormalHints(xdisplay_, xwindow_, &hints); |
694 } | 694 } |
695 | 695 |
696 void DesktopRootWindowHostX11::OnNativeWidgetFocus() { | 696 void DesktopWindowTreeHostX11::OnNativeWidgetFocus() { |
697 native_widget_delegate_->AsWidget()->GetInputMethod()->OnFocus(); | 697 native_widget_delegate_->AsWidget()->GetInputMethod()->OnFocus(); |
698 } | 698 } |
699 | 699 |
700 void DesktopRootWindowHostX11::OnNativeWidgetBlur() { | 700 void DesktopWindowTreeHostX11::OnNativeWidgetBlur() { |
701 if (xwindow_) { | 701 if (xwindow_) { |
702 x11_capture_.reset(); | 702 x11_capture_.reset(); |
703 native_widget_delegate_->AsWidget()->GetInputMethod()->OnBlur(); | 703 native_widget_delegate_->AsWidget()->GetInputMethod()->OnBlur(); |
704 } | 704 } |
705 } | 705 } |
706 | 706 |
707 bool DesktopRootWindowHostX11::IsAnimatingClosed() const { | 707 bool DesktopWindowTreeHostX11::IsAnimatingClosed() const { |
708 return false; | 708 return false; |
709 } | 709 } |
710 | 710 |
711 //////////////////////////////////////////////////////////////////////////////// | 711 //////////////////////////////////////////////////////////////////////////////// |
712 // DesktopRootWindowHostX11, aura::RootWindowHost implementation: | 712 // DesktopWindowTreeHostX11, aura::WindowTreeHost implementation: |
713 | 713 |
714 aura::RootWindow* DesktopRootWindowHostX11::GetRootWindow() { | 714 aura::RootWindow* DesktopWindowTreeHostX11::GetRootWindow() { |
715 return root_window_; | 715 return root_window_; |
716 } | 716 } |
717 | 717 |
718 gfx::AcceleratedWidget DesktopRootWindowHostX11::GetAcceleratedWidget() { | 718 gfx::AcceleratedWidget DesktopWindowTreeHostX11::GetAcceleratedWidget() { |
719 return xwindow_; | 719 return xwindow_; |
720 } | 720 } |
721 | 721 |
722 void DesktopRootWindowHostX11::Show() { | 722 void DesktopWindowTreeHostX11::Show() { |
723 if (!window_mapped_) { | 723 if (!window_mapped_) { |
724 // Before we map the window, set size hints. Otherwise, some window managers | 724 // Before we map the window, set size hints. Otherwise, some window managers |
725 // will ignore toplevel XMoveWindow commands. | 725 // will ignore toplevel XMoveWindow commands. |
726 XSizeHints size_hints; | 726 XSizeHints size_hints; |
727 size_hints.flags = PPosition; | 727 size_hints.flags = PPosition; |
728 size_hints.x = bounds_.x(); | 728 size_hints.x = bounds_.x(); |
729 size_hints.y = bounds_.y(); | 729 size_hints.y = bounds_.y(); |
730 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); | 730 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); |
731 | 731 |
732 XMapWindow(xdisplay_, xwindow_); | 732 XMapWindow(xdisplay_, xwindow_); |
733 | 733 |
734 // We now block until our window is mapped. Some X11 APIs will crash and | 734 // We now block until our window is mapped. Some X11 APIs will crash and |
735 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is | 735 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is |
736 // asynchronous. | 736 // asynchronous. |
737 base::MessagePumpX11::Current()->BlockUntilWindowMapped(xwindow_); | 737 base::MessagePumpX11::Current()->BlockUntilWindowMapped(xwindow_); |
738 window_mapped_ = true; | 738 window_mapped_ = true; |
739 } | 739 } |
740 | 740 |
741 native_widget_delegate_->AsWidget()->SetInitialFocus(); | 741 native_widget_delegate_->AsWidget()->SetInitialFocus(); |
742 } | 742 } |
743 | 743 |
744 void DesktopRootWindowHostX11::Hide() { | 744 void DesktopWindowTreeHostX11::Hide() { |
745 if (window_mapped_) { | 745 if (window_mapped_) { |
746 XWithdrawWindow(xdisplay_, xwindow_, 0); | 746 XWithdrawWindow(xdisplay_, xwindow_, 0); |
747 window_mapped_ = false; | 747 window_mapped_ = false; |
748 } | 748 } |
749 } | 749 } |
750 | 750 |
751 void DesktopRootWindowHostX11::ToggleFullScreen() { | 751 void DesktopWindowTreeHostX11::ToggleFullScreen() { |
752 NOTIMPLEMENTED(); | 752 NOTIMPLEMENTED(); |
753 } | 753 } |
754 | 754 |
755 gfx::Rect DesktopRootWindowHostX11::GetBounds() const { | 755 gfx::Rect DesktopWindowTreeHostX11::GetBounds() const { |
756 return bounds_; | 756 return bounds_; |
757 } | 757 } |
758 | 758 |
759 void DesktopRootWindowHostX11::SetBounds(const gfx::Rect& bounds) { | 759 void DesktopWindowTreeHostX11::SetBounds(const gfx::Rect& bounds) { |
760 bool origin_changed = bounds_.origin() != bounds.origin(); | 760 bool origin_changed = bounds_.origin() != bounds.origin(); |
761 bool size_changed = bounds_.size() != bounds.size(); | 761 bool size_changed = bounds_.size() != bounds.size(); |
762 XWindowChanges changes = {0}; | 762 XWindowChanges changes = {0}; |
763 unsigned value_mask = 0; | 763 unsigned value_mask = 0; |
764 | 764 |
765 if (size_changed) { | 765 if (size_changed) { |
766 // X11 will send an XError at our process if have a 0 sized window. | 766 // X11 will send an XError at our process if have a 0 sized window. |
767 DCHECK_GT(bounds.width(), 0); | 767 DCHECK_GT(bounds.width(), 0); |
768 DCHECK_GT(bounds.height(), 0); | 768 DCHECK_GT(bounds.height(), 0); |
769 | 769 |
(...skipping 18 matching lines...) Expand all Loading... |
788 bounds_ = bounds; | 788 bounds_ = bounds; |
789 | 789 |
790 if (origin_changed) | 790 if (origin_changed) |
791 native_widget_delegate_->AsWidget()->OnNativeWidgetMove(); | 791 native_widget_delegate_->AsWidget()->OnNativeWidgetMove(); |
792 if (size_changed) | 792 if (size_changed) |
793 NotifyHostResized(bounds.size()); | 793 NotifyHostResized(bounds.size()); |
794 else | 794 else |
795 compositor()->ScheduleRedrawRect(gfx::Rect(bounds.size())); | 795 compositor()->ScheduleRedrawRect(gfx::Rect(bounds.size())); |
796 } | 796 } |
797 | 797 |
798 gfx::Insets DesktopRootWindowHostX11::GetInsets() const { | 798 gfx::Insets DesktopWindowTreeHostX11::GetInsets() const { |
799 return gfx::Insets(); | 799 return gfx::Insets(); |
800 } | 800 } |
801 | 801 |
802 void DesktopRootWindowHostX11::SetInsets(const gfx::Insets& insets) { | 802 void DesktopWindowTreeHostX11::SetInsets(const gfx::Insets& insets) { |
803 } | 803 } |
804 | 804 |
805 gfx::Point DesktopRootWindowHostX11::GetLocationOnNativeScreen() const { | 805 gfx::Point DesktopWindowTreeHostX11::GetLocationOnNativeScreen() const { |
806 return bounds_.origin(); | 806 return bounds_.origin(); |
807 } | 807 } |
808 | 808 |
809 void DesktopRootWindowHostX11::SetCapture() { | 809 void DesktopWindowTreeHostX11::SetCapture() { |
810 // This is vaguely based on the old NativeWidgetGtk implementation. | 810 // This is vaguely based on the old NativeWidgetGtk implementation. |
811 // | 811 // |
812 // X11's XPointerGrab() shouldn't be used for everything; it doesn't map | 812 // X11's XPointerGrab() shouldn't be used for everything; it doesn't map |
813 // cleanly to Windows' SetCapture(). GTK only provides a separate concept of | 813 // cleanly to Windows' SetCapture(). GTK only provides a separate concept of |
814 // a grab that wasn't the X11 pointer grab, but was instead a manual | 814 // a grab that wasn't the X11 pointer grab, but was instead a manual |
815 // redirection of the event. (You need to drop into GDK if you want to | 815 // redirection of the event. (You need to drop into GDK if you want to |
816 // perform a raw X11 grab). | 816 // perform a raw X11 grab). |
817 | 817 |
818 if (g_current_capture) | 818 if (g_current_capture) |
819 g_current_capture->OnCaptureReleased(); | 819 g_current_capture->OnCaptureReleased(); |
820 | 820 |
821 g_current_capture = this; | 821 g_current_capture = this; |
822 x11_capture_.reset(new X11ScopedCapture(xwindow_)); | 822 x11_capture_.reset(new X11ScopedCapture(xwindow_)); |
823 } | 823 } |
824 | 824 |
825 void DesktopRootWindowHostX11::ReleaseCapture() { | 825 void DesktopWindowTreeHostX11::ReleaseCapture() { |
826 if (g_current_capture == this) | 826 if (g_current_capture == this) |
827 g_current_capture->OnCaptureReleased(); | 827 g_current_capture->OnCaptureReleased(); |
828 } | 828 } |
829 | 829 |
830 void DesktopRootWindowHostX11::SetCursor(gfx::NativeCursor cursor) { | 830 void DesktopWindowTreeHostX11::SetCursor(gfx::NativeCursor cursor) { |
831 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); | 831 XDefineCursor(xdisplay_, xwindow_, cursor.platform()); |
832 } | 832 } |
833 | 833 |
834 bool DesktopRootWindowHostX11::QueryMouseLocation( | 834 bool DesktopWindowTreeHostX11::QueryMouseLocation( |
835 gfx::Point* location_return) { | 835 gfx::Point* location_return) { |
836 aura::client::CursorClient* cursor_client = | 836 aura::client::CursorClient* cursor_client = |
837 aura::client::GetCursorClient(GetRootWindow()->window()); | 837 aura::client::GetCursorClient(GetRootWindow()->window()); |
838 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { | 838 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { |
839 *location_return = gfx::Point(0, 0); | 839 *location_return = gfx::Point(0, 0); |
840 return false; | 840 return false; |
841 } | 841 } |
842 | 842 |
843 ::Window root_return, child_return; | 843 ::Window root_return, child_return; |
844 int root_x_return, root_y_return, win_x_return, win_y_return; | 844 int root_x_return, root_y_return, win_x_return, win_y_return; |
845 unsigned int mask_return; | 845 unsigned int mask_return; |
846 XQueryPointer(xdisplay_, | 846 XQueryPointer(xdisplay_, |
847 xwindow_, | 847 xwindow_, |
848 &root_return, | 848 &root_return, |
849 &child_return, | 849 &child_return, |
850 &root_x_return, &root_y_return, | 850 &root_x_return, &root_y_return, |
851 &win_x_return, &win_y_return, | 851 &win_x_return, &win_y_return, |
852 &mask_return); | 852 &mask_return); |
853 *location_return = gfx::Point( | 853 *location_return = gfx::Point( |
854 std::max(0, std::min(bounds_.width(), win_x_return)), | 854 std::max(0, std::min(bounds_.width(), win_x_return)), |
855 std::max(0, std::min(bounds_.height(), win_y_return))); | 855 std::max(0, std::min(bounds_.height(), win_y_return))); |
856 return (win_x_return >= 0 && win_x_return < bounds_.width() && | 856 return (win_x_return >= 0 && win_x_return < bounds_.width() && |
857 win_y_return >= 0 && win_y_return < bounds_.height()); | 857 win_y_return >= 0 && win_y_return < bounds_.height()); |
858 } | 858 } |
859 | 859 |
860 bool DesktopRootWindowHostX11::ConfineCursorToRootWindow() { | 860 bool DesktopWindowTreeHostX11::ConfineCursorToRootWindow() { |
861 NOTIMPLEMENTED(); | 861 NOTIMPLEMENTED(); |
862 return false; | 862 return false; |
863 } | 863 } |
864 | 864 |
865 void DesktopRootWindowHostX11::UnConfineCursor() { | 865 void DesktopWindowTreeHostX11::UnConfineCursor() { |
866 NOTIMPLEMENTED(); | 866 NOTIMPLEMENTED(); |
867 } | 867 } |
868 | 868 |
869 void DesktopRootWindowHostX11::OnCursorVisibilityChanged(bool show) { | 869 void DesktopWindowTreeHostX11::OnCursorVisibilityChanged(bool show) { |
870 // TODO(erg): Conditional on us enabling touch on desktop linux builds, do | 870 // TODO(erg): Conditional on us enabling touch on desktop linux builds, do |
871 // the same tap-to-click disabling here that chromeos does. | 871 // the same tap-to-click disabling here that chromeos does. |
872 } | 872 } |
873 | 873 |
874 void DesktopRootWindowHostX11::MoveCursorTo(const gfx::Point& location) { | 874 void DesktopWindowTreeHostX11::MoveCursorTo(const gfx::Point& location) { |
875 XWarpPointer(xdisplay_, None, x_root_window_, 0, 0, 0, 0, | 875 XWarpPointer(xdisplay_, None, x_root_window_, 0, 0, 0, 0, |
876 bounds_.x() + location.x(), bounds_.y() + location.y()); | 876 bounds_.x() + location.x(), bounds_.y() + location.y()); |
877 } | 877 } |
878 | 878 |
879 void DesktopRootWindowHostX11::PostNativeEvent( | 879 void DesktopWindowTreeHostX11::PostNativeEvent( |
880 const base::NativeEvent& native_event) { | 880 const base::NativeEvent& native_event) { |
881 DCHECK(xwindow_); | 881 DCHECK(xwindow_); |
882 DCHECK(xdisplay_); | 882 DCHECK(xdisplay_); |
883 XEvent xevent = *native_event; | 883 XEvent xevent = *native_event; |
884 xevent.xany.display = xdisplay_; | 884 xevent.xany.display = xdisplay_; |
885 xevent.xany.window = xwindow_; | 885 xevent.xany.window = xwindow_; |
886 | 886 |
887 switch (xevent.type) { | 887 switch (xevent.type) { |
888 case EnterNotify: | 888 case EnterNotify: |
889 case LeaveNotify: | 889 case LeaveNotify: |
(...skipping 12 matching lines...) Expand all Loading... |
902 ConvertPointToNativeScreen(&point); | 902 ConvertPointToNativeScreen(&point); |
903 xevent.xmotion.x_root = point.x(); | 903 xevent.xmotion.x_root = point.x(); |
904 xevent.xmotion.y_root = point.y(); | 904 xevent.xmotion.y_root = point.y(); |
905 } | 905 } |
906 default: | 906 default: |
907 break; | 907 break; |
908 } | 908 } |
909 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); | 909 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); |
910 } | 910 } |
911 | 911 |
912 void DesktopRootWindowHostX11::OnDeviceScaleFactorChanged( | 912 void DesktopWindowTreeHostX11::OnDeviceScaleFactorChanged( |
913 float device_scale_factor) { | 913 float device_scale_factor) { |
914 } | 914 } |
915 | 915 |
916 void DesktopRootWindowHostX11::PrepareForShutdown() { | 916 void DesktopWindowTreeHostX11::PrepareForShutdown() { |
917 } | 917 } |
918 | 918 |
919 //////////////////////////////////////////////////////////////////////////////// | 919 //////////////////////////////////////////////////////////////////////////////// |
920 // DesktopRootWindowHostX11, private: | 920 // DesktopWindowTreeHostX11, private: |
921 | 921 |
922 void DesktopRootWindowHostX11::InitX11Window( | 922 void DesktopWindowTreeHostX11::InitX11Window( |
923 const Widget::InitParams& params) { | 923 const Widget::InitParams& params) { |
924 unsigned long attribute_mask = CWBackPixmap; | 924 unsigned long attribute_mask = CWBackPixmap; |
925 XSetWindowAttributes swa; | 925 XSetWindowAttributes swa; |
926 memset(&swa, 0, sizeof(swa)); | 926 memset(&swa, 0, sizeof(swa)); |
927 swa.background_pixmap = None; | 927 swa.background_pixmap = None; |
928 | 928 |
929 ::Atom window_type; | 929 ::Atom window_type; |
930 switch (params.type) { | 930 switch (params.type) { |
931 case Widget::InitParams::TYPE_MENU: | 931 case Widget::InitParams::TYPE_MENU: |
932 swa.override_redirect = True; | 932 swa.override_redirect = True; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 // If we have a delegate which is providing a default window icon, use that | 1062 // If we have a delegate which is providing a default window icon, use that |
1063 // icon. | 1063 // icon. |
1064 gfx::ImageSkia* window_icon = ViewsDelegate::views_delegate ? | 1064 gfx::ImageSkia* window_icon = ViewsDelegate::views_delegate ? |
1065 ViewsDelegate::views_delegate->GetDefaultWindowIcon() : NULL; | 1065 ViewsDelegate::views_delegate->GetDefaultWindowIcon() : NULL; |
1066 if (window_icon) { | 1066 if (window_icon) { |
1067 SetWindowIcons(gfx::ImageSkia(), *window_icon); | 1067 SetWindowIcons(gfx::ImageSkia(), *window_icon); |
1068 } | 1068 } |
1069 CreateCompositor(GetAcceleratedWidget()); | 1069 CreateCompositor(GetAcceleratedWidget()); |
1070 } | 1070 } |
1071 | 1071 |
1072 bool DesktopRootWindowHostX11::IsWindowManagerPresent() { | 1072 bool DesktopWindowTreeHostX11::IsWindowManagerPresent() { |
1073 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership | 1073 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership |
1074 // of WM_Sn selections (where n is a screen number). | 1074 // of WM_Sn selections (where n is a screen number). |
1075 return XGetSelectionOwner( | 1075 return XGetSelectionOwner( |
1076 xdisplay_, atom_cache_.GetAtom("WM_S0")) != None; | 1076 xdisplay_, atom_cache_.GetAtom("WM_S0")) != None; |
1077 } | 1077 } |
1078 | 1078 |
1079 void DesktopRootWindowHostX11::SetWMSpecState(bool enabled, | 1079 void DesktopWindowTreeHostX11::SetWMSpecState(bool enabled, |
1080 ::Atom state1, | 1080 ::Atom state1, |
1081 ::Atom state2) { | 1081 ::Atom state2) { |
1082 XEvent xclient; | 1082 XEvent xclient; |
1083 memset(&xclient, 0, sizeof(xclient)); | 1083 memset(&xclient, 0, sizeof(xclient)); |
1084 xclient.type = ClientMessage; | 1084 xclient.type = ClientMessage; |
1085 xclient.xclient.window = xwindow_; | 1085 xclient.xclient.window = xwindow_; |
1086 xclient.xclient.message_type = atom_cache_.GetAtom("_NET_WM_STATE"); | 1086 xclient.xclient.message_type = atom_cache_.GetAtom("_NET_WM_STATE"); |
1087 xclient.xclient.format = 32; | 1087 xclient.xclient.format = 32; |
1088 xclient.xclient.data.l[0] = | 1088 xclient.xclient.data.l[0] = |
1089 enabled ? k_NET_WM_STATE_ADD : k_NET_WM_STATE_REMOVE; | 1089 enabled ? k_NET_WM_STATE_ADD : k_NET_WM_STATE_REMOVE; |
1090 xclient.xclient.data.l[1] = state1; | 1090 xclient.xclient.data.l[1] = state1; |
1091 xclient.xclient.data.l[2] = state2; | 1091 xclient.xclient.data.l[2] = state2; |
1092 xclient.xclient.data.l[3] = 1; | 1092 xclient.xclient.data.l[3] = 1; |
1093 xclient.xclient.data.l[4] = 0; | 1093 xclient.xclient.data.l[4] = 0; |
1094 | 1094 |
1095 XSendEvent(xdisplay_, x_root_window_, False, | 1095 XSendEvent(xdisplay_, x_root_window_, False, |
1096 SubstructureRedirectMask | SubstructureNotifyMask, | 1096 SubstructureRedirectMask | SubstructureNotifyMask, |
1097 &xclient); | 1097 &xclient); |
1098 } | 1098 } |
1099 | 1099 |
1100 bool DesktopRootWindowHostX11::HasWMSpecProperty(const char* property) const { | 1100 bool DesktopWindowTreeHostX11::HasWMSpecProperty(const char* property) const { |
1101 return window_properties_.find(atom_cache_.GetAtom(property)) != | 1101 return window_properties_.find(atom_cache_.GetAtom(property)) != |
1102 window_properties_.end(); | 1102 window_properties_.end(); |
1103 } | 1103 } |
1104 | 1104 |
1105 void DesktopRootWindowHostX11::OnCaptureReleased() { | 1105 void DesktopWindowTreeHostX11::OnCaptureReleased() { |
1106 x11_capture_.reset(); | 1106 x11_capture_.reset(); |
1107 g_current_capture = NULL; | 1107 g_current_capture = NULL; |
1108 delegate_->OnHostLostWindowCapture(); | 1108 delegate_->OnHostLostWindowCapture(); |
1109 native_widget_delegate_->OnMouseCaptureLost(); | 1109 native_widget_delegate_->OnMouseCaptureLost(); |
1110 } | 1110 } |
1111 | 1111 |
1112 void DesktopRootWindowHostX11::DispatchMouseEvent(ui::MouseEvent* event) { | 1112 void DesktopWindowTreeHostX11::DispatchMouseEvent(ui::MouseEvent* event) { |
1113 if (!g_current_capture || g_current_capture == this) { | 1113 if (!g_current_capture || g_current_capture == this) { |
1114 delegate_->OnHostMouseEvent(event); | 1114 delegate_->OnHostMouseEvent(event); |
1115 } else { | 1115 } else { |
1116 // Another DesktopRootWindowHostX11 has installed itself as | 1116 // Another DesktopWindowTreeHostX11 has installed itself as |
1117 // capture. Translate the event's location and dispatch to the other. | 1117 // capture. Translate the event's location and dispatch to the other. |
1118 event->ConvertLocationToTarget(root_window_->window(), | 1118 event->ConvertLocationToTarget(root_window_->window(), |
1119 g_current_capture->root_window_->window()); | 1119 g_current_capture->root_window_->window()); |
1120 g_current_capture->delegate_->OnHostMouseEvent(event); | 1120 g_current_capture->delegate_->OnHostMouseEvent(event); |
1121 } | 1121 } |
1122 } | 1122 } |
1123 | 1123 |
1124 void DesktopRootWindowHostX11::DispatchTouchEvent(ui::TouchEvent* event) { | 1124 void DesktopWindowTreeHostX11::DispatchTouchEvent(ui::TouchEvent* event) { |
1125 if (g_current_capture && g_current_capture != this && | 1125 if (g_current_capture && g_current_capture != this && |
1126 event->type() == ui::ET_TOUCH_PRESSED) { | 1126 event->type() == ui::ET_TOUCH_PRESSED) { |
1127 event->ConvertLocationToTarget(root_window_->window(), | 1127 event->ConvertLocationToTarget(root_window_->window(), |
1128 g_current_capture->root_window_->window()); | 1128 g_current_capture->root_window_->window()); |
1129 g_current_capture->delegate_->OnHostTouchEvent(event); | 1129 g_current_capture->delegate_->OnHostTouchEvent(event); |
1130 } else { | 1130 } else { |
1131 delegate_->OnHostTouchEvent(event); | 1131 delegate_->OnHostTouchEvent(event); |
1132 } | 1132 } |
1133 } | 1133 } |
1134 | 1134 |
1135 void DesktopRootWindowHostX11::ResetWindowRegion() { | 1135 void DesktopWindowTreeHostX11::ResetWindowRegion() { |
1136 // If a custom window shape was supplied then apply it. | 1136 // If a custom window shape was supplied then apply it. |
1137 if (custom_window_shape_) { | 1137 if (custom_window_shape_) { |
1138 XShapeCombineRegion( | 1138 XShapeCombineRegion( |
1139 xdisplay_, xwindow_, ShapeBounding, 0, 0, custom_window_shape_, false); | 1139 xdisplay_, xwindow_, ShapeBounding, 0, 0, custom_window_shape_, false); |
1140 return; | 1140 return; |
1141 } | 1141 } |
1142 | 1142 |
1143 if (!IsMaximized()) { | 1143 if (!IsMaximized()) { |
1144 gfx::Path window_mask; | 1144 gfx::Path window_mask; |
1145 views::Widget* widget = native_widget_delegate_->AsWidget(); | 1145 views::Widget* widget = native_widget_delegate_->AsWidget(); |
(...skipping 12 matching lines...) Expand all Loading... |
1158 } | 1158 } |
1159 | 1159 |
1160 // If we didn't set the shape for any reason, reset the shaping information | 1160 // If we didn't set the shape for any reason, reset the shaping information |
1161 // by ShapeSet-ing with our bounds rect. | 1161 // by ShapeSet-ing with our bounds rect. |
1162 XRectangle r = { 0, 0, static_cast<unsigned short>(bounds_.width()), | 1162 XRectangle r = { 0, 0, static_cast<unsigned short>(bounds_.width()), |
1163 static_cast<unsigned short>(bounds_.height()) }; | 1163 static_cast<unsigned short>(bounds_.height()) }; |
1164 XShapeCombineRectangles(xdisplay_, xwindow_, ShapeBounding, | 1164 XShapeCombineRectangles(xdisplay_, xwindow_, ShapeBounding, |
1165 0, 0, &r, 1, ShapeSet, YXBanded); | 1165 0, 0, &r, 1, ShapeSet, YXBanded); |
1166 } | 1166 } |
1167 | 1167 |
1168 void DesktopRootWindowHostX11::SerializeImageRepresentation( | 1168 void DesktopWindowTreeHostX11::SerializeImageRepresentation( |
1169 const gfx::ImageSkiaRep& rep, | 1169 const gfx::ImageSkiaRep& rep, |
1170 std::vector<unsigned long>* data) { | 1170 std::vector<unsigned long>* data) { |
1171 int width = rep.GetWidth(); | 1171 int width = rep.GetWidth(); |
1172 data->push_back(width); | 1172 data->push_back(width); |
1173 | 1173 |
1174 int height = rep.GetHeight(); | 1174 int height = rep.GetHeight(); |
1175 data->push_back(height); | 1175 data->push_back(height); |
1176 | 1176 |
1177 const SkBitmap& bitmap = rep.sk_bitmap(); | 1177 const SkBitmap& bitmap = rep.sk_bitmap(); |
1178 SkAutoLockPixels locker(bitmap); | 1178 SkAutoLockPixels locker(bitmap); |
1179 | 1179 |
1180 for (int y = 0; y < height; ++y) | 1180 for (int y = 0; y < height; ++y) |
1181 for (int x = 0; x < width; ++x) | 1181 for (int x = 0; x < width; ++x) |
1182 data->push_back(bitmap.getColor(x, y)); | 1182 data->push_back(bitmap.getColor(x, y)); |
1183 } | 1183 } |
1184 | 1184 |
1185 std::list<XID>& DesktopRootWindowHostX11::open_windows() { | 1185 std::list<XID>& DesktopWindowTreeHostX11::open_windows() { |
1186 if (!open_windows_) | 1186 if (!open_windows_) |
1187 open_windows_ = new std::list<XID>(); | 1187 open_windows_ = new std::list<XID>(); |
1188 return *open_windows_; | 1188 return *open_windows_; |
1189 } | 1189 } |
1190 | 1190 |
1191 //////////////////////////////////////////////////////////////////////////////// | 1191 //////////////////////////////////////////////////////////////////////////////// |
1192 // DesktopRootWindowHostX11, MessageLoop::Dispatcher implementation: | 1192 // DesktopWindowTreeHostX11, MessageLoop::Dispatcher implementation: |
1193 | 1193 |
1194 bool DesktopRootWindowHostX11::Dispatch(const base::NativeEvent& event) { | 1194 bool DesktopWindowTreeHostX11::Dispatch(const base::NativeEvent& event) { |
1195 XEvent* xev = event; | 1195 XEvent* xev = event; |
1196 | 1196 |
1197 TRACE_EVENT1("views", "DesktopRootWindowHostX11::Dispatch", | 1197 TRACE_EVENT1("views", "DesktopWindowTreeHostX11::Dispatch", |
1198 "event->type", event->type); | 1198 "event->type", event->type); |
1199 | 1199 |
1200 // May want to factor CheckXEventForConsistency(xev); into a common location | 1200 // May want to factor CheckXEventForConsistency(xev); into a common location |
1201 // since it is called here. | 1201 // since it is called here. |
1202 switch (xev->type) { | 1202 switch (xev->type) { |
1203 case EnterNotify: | 1203 case EnterNotify: |
1204 case LeaveNotify: { | 1204 case LeaveNotify: { |
1205 if (!g_current_capture) | 1205 if (!g_current_capture) |
1206 X11DesktopHandler::get()->ProcessXEvent(xev); | 1206 X11DesktopHandler::get()->ProcessXEvent(xev); |
1207 ui::MouseEvent mouse_event(xev); | 1207 ui::MouseEvent mouse_event(xev); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 default: | 1377 default: |
1378 NOTREACHED(); | 1378 NOTREACHED(); |
1379 } | 1379 } |
1380 | 1380 |
1381 // If we coalesced an event we need to free its cookie. | 1381 // If we coalesced an event we need to free its cookie. |
1382 if (num_coalesced > 0) | 1382 if (num_coalesced > 0) |
1383 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); | 1383 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); |
1384 break; | 1384 break; |
1385 } | 1385 } |
1386 case MapNotify: { | 1386 case MapNotify: { |
1387 FOR_EACH_OBSERVER(DesktopRootWindowHostObserverX11, | 1387 FOR_EACH_OBSERVER(DesktopWindowTreeHostObserverX11, |
1388 observer_list_, | 1388 observer_list_, |
1389 OnWindowMapped(xwindow_)); | 1389 OnWindowMapped(xwindow_)); |
1390 break; | 1390 break; |
1391 } | 1391 } |
1392 case UnmapNotify: { | 1392 case UnmapNotify: { |
1393 FOR_EACH_OBSERVER(DesktopRootWindowHostObserverX11, | 1393 FOR_EACH_OBSERVER(DesktopWindowTreeHostObserverX11, |
1394 observer_list_, | 1394 observer_list_, |
1395 OnWindowUnmapped(xwindow_)); | 1395 OnWindowUnmapped(xwindow_)); |
1396 break; | 1396 break; |
1397 } | 1397 } |
1398 case ClientMessage: { | 1398 case ClientMessage: { |
1399 Atom message_type = xev->xclient.message_type; | 1399 Atom message_type = xev->xclient.message_type; |
1400 if (message_type == atom_cache_.GetAtom("WM_PROTOCOLS")) { | 1400 if (message_type == atom_cache_.GetAtom("WM_PROTOCOLS")) { |
1401 Atom protocol = static_cast<Atom>(xev->xclient.data.l[0]); | 1401 Atom protocol = static_cast<Atom>(xev->xclient.data.l[0]); |
1402 if (protocol == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { | 1402 if (protocol == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { |
1403 // We have received a close message from the window manager. | 1403 // We have received a close message from the window manager. |
1404 root_window_->OnRootWindowHostCloseRequested(); | 1404 root_window_->OnWindowTreeHostCloseRequested(); |
1405 } else if (protocol == atom_cache_.GetAtom("_NET_WM_PING")) { | 1405 } else if (protocol == atom_cache_.GetAtom("_NET_WM_PING")) { |
1406 XEvent reply_event = *xev; | 1406 XEvent reply_event = *xev; |
1407 reply_event.xclient.window = x_root_window_; | 1407 reply_event.xclient.window = x_root_window_; |
1408 | 1408 |
1409 XSendEvent(xdisplay_, | 1409 XSendEvent(xdisplay_, |
1410 reply_event.xclient.window, | 1410 reply_event.xclient.window, |
1411 False, | 1411 False, |
1412 SubstructureRedirectMask | SubstructureNotifyMask, | 1412 SubstructureRedirectMask | SubstructureNotifyMask, |
1413 &reply_event); | 1413 &reply_event); |
1414 } | 1414 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 } | 1517 } |
1518 case SelectionNotify: { | 1518 case SelectionNotify: { |
1519 drag_drop_client_->OnSelectionNotify(xev->xselection); | 1519 drag_drop_client_->OnSelectionNotify(xev->xselection); |
1520 break; | 1520 break; |
1521 } | 1521 } |
1522 } | 1522 } |
1523 return true; | 1523 return true; |
1524 } | 1524 } |
1525 | 1525 |
1526 //////////////////////////////////////////////////////////////////////////////// | 1526 //////////////////////////////////////////////////////////////////////////////// |
1527 // DesktopRootWindowHost, public: | 1527 // DesktopWindowTreeHost, public: |
1528 | 1528 |
1529 // static | 1529 // static |
1530 DesktopRootWindowHost* DesktopRootWindowHost::Create( | 1530 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( |
1531 internal::NativeWidgetDelegate* native_widget_delegate, | 1531 internal::NativeWidgetDelegate* native_widget_delegate, |
1532 DesktopNativeWidgetAura* desktop_native_widget_aura) { | 1532 DesktopNativeWidgetAura* desktop_native_widget_aura) { |
1533 return new DesktopRootWindowHostX11(native_widget_delegate, | 1533 return new DesktopWindowTreeHostX11(native_widget_delegate, |
1534 desktop_native_widget_aura); | 1534 desktop_native_widget_aura); |
1535 } | 1535 } |
1536 | 1536 |
1537 // static | 1537 // static |
1538 ui::NativeTheme* DesktopRootWindowHost::GetNativeTheme(aura::Window* window) { | 1538 ui::NativeTheme* DesktopWindowTreeHost::GetNativeTheme(aura::Window* window) { |
1539 const views::LinuxUI* linux_ui = views::LinuxUI::instance(); | 1539 const views::LinuxUI* linux_ui = views::LinuxUI::instance(); |
1540 if (linux_ui) { | 1540 if (linux_ui) { |
1541 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(); | 1541 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(); |
1542 if (native_theme) | 1542 if (native_theme) |
1543 return native_theme; | 1543 return native_theme; |
1544 } | 1544 } |
1545 | 1545 |
1546 return ui::NativeTheme::instance(); | 1546 return ui::NativeTheme::instance(); |
1547 } | 1547 } |
1548 | 1548 |
1549 } // namespace views | 1549 } // namespace views |
OLD | NEW |