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/aura/root_window_host_linux.h" | 5 #include "ui/aura/root_window_host_linux.h" |
6 | 6 |
7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
8 #include <X11/Xcursor/Xcursor.h> | |
9 #include <X11/cursorfont.h> | 8 #include <X11/cursorfont.h> |
10 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
11 #include <X11/extensions/Xfixes.h> | 10 #include <X11/extensions/Xfixes.h> |
12 #include <X11/extensions/Xrandr.h> | 11 #include <X11/extensions/Xrandr.h> |
13 #include <algorithm> | 12 #include <algorithm> |
14 | 13 |
15 #include "base/message_pump_x.h" | 14 #include "base/message_pump_x.h" |
16 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
17 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
18 #include "grit/ui_resources_standard.h" | |
19 #include "third_party/skia/include/core/SkBitmap.h" | |
20 #include "ui/aura/client/user_gesture_client.h" | 17 #include "ui/aura/client/user_gesture_client.h" |
21 #include "ui/aura/dispatcher_linux.h" | 18 #include "ui/aura/dispatcher_linux.h" |
22 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
23 #include "ui/aura/event.h" | 20 #include "ui/aura/event.h" |
24 #include "ui/aura/root_window.h" | 21 #include "ui/aura/root_window.h" |
25 #include "ui/base/cursor/cursor.h" | 22 #include "ui/base/cursor/cursor.h" |
26 #include "ui/base/keycodes/keyboard_codes.h" | 23 #include "ui/base/keycodes/keyboard_codes.h" |
27 #include "ui/base/resource/resource_bundle.h" | |
28 #include "ui/base/touch/touch_factory.h" | 24 #include "ui/base/touch/touch_factory.h" |
29 #include "ui/base/view_prop.h" | 25 #include "ui/base/view_prop.h" |
30 #include "ui/base/x/x11_util.h" | 26 #include "ui/base/x/x11_util.h" |
31 #include "ui/compositor/layer.h" | 27 #include "ui/compositor/layer.h" |
32 #include "ui/gfx/image/image.h" | |
33 | 28 |
34 using std::max; | 29 using std::max; |
35 using std::min; | 30 using std::min; |
36 | 31 |
37 namespace aura { | 32 namespace aura { |
38 | 33 |
39 namespace { | 34 namespace { |
40 | 35 |
41 // Standard Linux mouse buttons for going back and forward. | 36 // Standard Linux mouse buttons for going back and forward. |
42 const int kBackMouseButton = 8; | 37 const int kBackMouseButton = 8; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 // X11 server. Must be kept in sync with RootWindowHostLinux::AtomList | 285 // X11 server. Must be kept in sync with RootWindowHostLinux::AtomList |
291 const char* kAtomList[] = { | 286 const char* kAtomList[] = { |
292 "WM_DELETE_WINDOW", | 287 "WM_DELETE_WINDOW", |
293 "_NET_WM_PING", | 288 "_NET_WM_PING", |
294 "_NET_WM_PID", | 289 "_NET_WM_PID", |
295 "WM_S0" | 290 "WM_S0" |
296 }; | 291 }; |
297 | 292 |
298 } // namespace | 293 } // namespace |
299 | 294 |
300 // A utility class that provides X Cursor for NativeCursors for which we have | |
301 // image resources. | |
302 class RootWindowHostLinux::ImageCursors { | |
303 public: | |
304 ImageCursors() { | |
305 LoadImageCursor(ui::kCursorNoDrop, IDR_AURA_CURSOR_NO_DROP); | |
306 LoadImageCursor(ui::kCursorCopy, IDR_AURA_CURSOR_COPY); | |
307 // TODO (varunjain): add more cursors once we have assets. | |
308 } | |
309 | |
310 ~ImageCursors() { | |
311 std::map<int, Cursor>::const_iterator it; | |
312 for (it = cursors_.begin(); it != cursors_.end(); ++it) | |
313 ui::UnrefCustomXCursor(it->second); | |
314 } | |
315 | |
316 // Returns true if we have an image resource loaded for the |native_cursor|. | |
317 bool IsImageCursor(gfx::NativeCursor native_cursor) { | |
318 return cursors_.find(native_cursor.native_type()) != cursors_.end(); | |
319 } | |
320 | |
321 // Gets the X Cursor corresponding to the |native_cursor|. | |
322 ::Cursor ImageCursorFromNative(gfx::NativeCursor native_cursor) { | |
323 DCHECK(cursors_.find(native_cursor.native_type()) != cursors_.end()); | |
324 return cursors_[native_cursor.native_type()]; | |
325 } | |
326 | |
327 private: | |
328 // Creates an X Cursor from an image resource and puts it in the cursor map. | |
329 void LoadImageCursor(int id, int resource_id) { | |
330 const SkBitmap* bitmap = | |
331 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
332 resource_id).ToSkBitmap(); | |
333 | |
334 XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap, gfx::Point(0, 0)); | |
335 cursors_[id] = ui::CreateReffedCustomXCursor(image); | |
336 // |bitmap| is owned by the resource bundle. So we do not need to free it. | |
337 } | |
338 | |
339 // A map to hold all image cursors. It maps the cursor ID to the X Cursor. | |
340 std::map<int, Cursor> cursors_; | |
341 | |
342 DISALLOW_COPY_AND_ASSIGN(ImageCursors); | |
343 }; | |
344 | |
345 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) | 295 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) |
346 : root_window_(NULL), | 296 : root_window_(NULL), |
347 xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), | 297 xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), |
348 xwindow_(0), | 298 xwindow_(0), |
349 x_root_window_(DefaultRootWindow(xdisplay_)), | 299 x_root_window_(DefaultRootWindow(xdisplay_)), |
350 current_cursor_(ui::kCursorNull), | 300 current_cursor_(ui::kCursorNull), |
351 cursor_shown_(true), | 301 cursor_shown_(true), |
352 bounds_(bounds), | 302 bounds_(bounds), |
353 focus_when_shown_(false), | 303 focus_when_shown_(false), |
354 pointer_barriers_(NULL), | 304 pointer_barriers_(NULL) { |
355 image_cursors_(new ImageCursors) { | |
356 XSetWindowAttributes swa; | 305 XSetWindowAttributes swa; |
357 memset(&swa, 0, sizeof(swa)); | 306 memset(&swa, 0, sizeof(swa)); |
358 swa.background_pixmap = None; | 307 swa.background_pixmap = None; |
359 xwindow_ = XCreateWindow( | 308 xwindow_ = XCreateWindow( |
360 xdisplay_, x_root_window_, | 309 xdisplay_, x_root_window_, |
361 bounds.x(), bounds.y(), bounds.width(), bounds.height(), | 310 bounds.x(), bounds.y(), bounds.width(), bounds.height(), |
362 0, // border width | 311 0, // border width |
363 CopyFromParent, // depth | 312 CopyFromParent, // depth |
364 InputOutput, | 313 InputOutput, |
365 CopyFromParent, // visual | 314 CopyFromParent, // visual |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 } | 787 } |
839 | 788 |
840 bool RootWindowHostLinux::IsWindowManagerPresent() { | 789 bool RootWindowHostLinux::IsWindowManagerPresent() { |
841 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership | 790 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership |
842 // of WM_Sn selections (where n is a screen number). | 791 // of WM_Sn selections (where n is a screen number). |
843 return XGetSelectionOwner(xdisplay_, cached_atoms_[ATOM_WM_S0]) != None; | 792 return XGetSelectionOwner(xdisplay_, cached_atoms_[ATOM_WM_S0]) != None; |
844 } | 793 } |
845 | 794 |
846 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { | 795 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { |
847 ::Cursor xcursor = | 796 ::Cursor xcursor = |
848 image_cursors_->IsImageCursor(cursor) ? | |
849 image_cursors_->ImageCursorFromNative(cursor) : | |
850 cursor == ui::kCursorNone ? | 797 cursor == ui::kCursorNone ? |
851 invisible_cursor_ : | 798 invisible_cursor_ : |
852 cursor == ui::kCursorCustom ? | 799 cursor == ui::kCursorCustom ? |
853 cursor.platform() : | 800 cursor.platform() : |
854 ui::GetXCursor(CursorShapeFromNative(cursor)); | 801 ui::GetXCursor(CursorShapeFromNative(cursor)); |
855 XDefineCursor(xdisplay_, xwindow_, xcursor); | 802 XDefineCursor(xdisplay_, xwindow_, xcursor); |
856 } | 803 } |
857 | 804 |
858 // static | 805 // static |
859 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { | 806 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { |
860 return new RootWindowHostLinux(bounds); | 807 return new RootWindowHostLinux(bounds); |
861 } | 808 } |
862 | 809 |
863 // static | 810 // static |
864 RootWindowHost* RootWindowHost::GetForAcceleratedWidget( | 811 RootWindowHost* RootWindowHost::GetForAcceleratedWidget( |
865 gfx::AcceleratedWidget accelerated_widget) { | 812 gfx::AcceleratedWidget accelerated_widget) { |
866 return reinterpret_cast<RootWindowHost*>( | 813 return reinterpret_cast<RootWindowHost*>( |
867 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); | 814 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); |
868 } | 815 } |
869 | 816 |
870 // static | 817 // static |
871 gfx::Size RootWindowHost::GetNativeScreenSize() { | 818 gfx::Size RootWindowHost::GetNativeScreenSize() { |
872 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 819 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
873 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 820 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
874 } | 821 } |
875 | 822 |
876 } // namespace aura | 823 } // namespace aura |
OLD | NEW |