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

Side by Side Diff: ui/aura/root_window_host_linux.cc

Issue 10382016: Revert 135378 - Aura: Adds custom cursors for drag and drop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 months 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/aura/root_window_host_linux.h ('k') | ui/base/x/x11_util.h » ('j') | 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/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/x/x11_util.h" 25 #include "ui/base/x/x11_util.h"
30 #include "ui/base/view_prop.h" 26 #include "ui/base/view_prop.h"
31 #include "ui/gfx/compositor/layer.h" 27 #include "ui/gfx/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
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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 } 788 }
840 789
841 bool RootWindowHostLinux::IsWindowManagerPresent() { 790 bool RootWindowHostLinux::IsWindowManagerPresent() {
842 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership 791 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership
843 // of WM_Sn selections (where n is a screen number). 792 // of WM_Sn selections (where n is a screen number).
844 return XGetSelectionOwner(xdisplay_, cached_atoms_[ATOM_WM_S0]) != None; 793 return XGetSelectionOwner(xdisplay_, cached_atoms_[ATOM_WM_S0]) != None;
845 } 794 }
846 795
847 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { 796 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) {
848 ::Cursor xcursor = 797 ::Cursor xcursor =
849 image_cursors_->IsImageCursor(cursor) ?
850 image_cursors_->ImageCursorFromNative(cursor) :
851 cursor == ui::kCursorNone ? 798 cursor == ui::kCursorNone ?
852 invisible_cursor_ : 799 invisible_cursor_ :
853 cursor == ui::kCursorCustom ? 800 cursor == ui::kCursorCustom ?
854 cursor.platform() : 801 cursor.platform() :
855 ui::GetXCursor(CursorShapeFromNative(cursor)); 802 ui::GetXCursor(CursorShapeFromNative(cursor));
856 XDefineCursor(xdisplay_, xwindow_, xcursor); 803 XDefineCursor(xdisplay_, xwindow_, xcursor);
857 } 804 }
858 805
859 // static 806 // static
860 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { 807 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) {
861 return new RootWindowHostLinux(bounds); 808 return new RootWindowHostLinux(bounds);
862 } 809 }
863 810
864 // static 811 // static
865 RootWindowHost* RootWindowHost::GetForAcceleratedWidget( 812 RootWindowHost* RootWindowHost::GetForAcceleratedWidget(
866 gfx::AcceleratedWidget accelerated_widget) { 813 gfx::AcceleratedWidget accelerated_widget) {
867 return reinterpret_cast<RootWindowHost*>( 814 return reinterpret_cast<RootWindowHost*>(
868 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); 815 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey));
869 } 816 }
870 817
871 // static 818 // static
872 gfx::Size RootWindowHost::GetNativeScreenSize() { 819 gfx::Size RootWindowHost::GetNativeScreenSize() {
873 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); 820 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay();
874 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); 821 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0));
875 } 822 }
876 823
877 } // namespace aura 824 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window_host_linux.h ('k') | ui/base/x/x11_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698