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

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

Issue 9463003: aura-x11: Add custom web cursor support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: x custom cursor cache Created 8 years, 10 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
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/cursorfont.h> 7 #include <X11/cursorfont.h>
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 case aura::kCursorAlias: 145 case aura::kCursorAlias:
146 case aura::kCursorProgress: 146 case aura::kCursorProgress:
147 case aura::kCursorNoDrop: 147 case aura::kCursorNoDrop:
148 case aura::kCursorCopy: 148 case aura::kCursorCopy:
149 case aura::kCursorNone: 149 case aura::kCursorNone:
150 case aura::kCursorNotAllowed: 150 case aura::kCursorNotAllowed:
151 case aura::kCursorZoomIn: 151 case aura::kCursorZoomIn:
152 case aura::kCursorZoomOut: 152 case aura::kCursorZoomOut:
153 case aura::kCursorGrab: 153 case aura::kCursorGrab:
154 case aura::kCursorGrabbing: 154 case aura::kCursorGrabbing:
155 // TODO(jamescook): Need cursors for these. crbug.com/111650
156 return XC_left_ptr;
155 case aura::kCursorCustom: 157 case aura::kCursorCustom:
156 // TODO(jamescook): Need cursors for these. crbug.com/111650 158 NOTREACHED();
157 return XC_left_ptr; 159 return XC_left_ptr;
158 } 160 }
159 NOTREACHED(); 161 NOTREACHED();
160 return XC_left_ptr; 162 return XC_left_ptr;
161 } 163 }
162 164
163 // Coalesce all pending motion events that are at the top of the queue, and 165 // Coalesce all pending motion events that are at the top of the queue, and
164 // return the number eliminated, storing the last one in |last_event|. 166 // return the number eliminated, storing the last one in |last_event|.
165 int CoalescePendingXIMotionEvents(const XEvent* xev, XEvent* last_event) { 167 int CoalescePendingXIMotionEvents(const XEvent* xev, XEvent* last_event) {
166 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); 168 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 268 }
267 269
268 } // namespace 270 } // namespace
269 271
270 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) 272 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
271 : root_window_(NULL), 273 : root_window_(NULL),
272 xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), 274 xdisplay_(base::MessagePumpX::GetDefaultXDisplay()),
273 xwindow_(0), 275 xwindow_(0),
274 x_root_window_(DefaultRootWindow(xdisplay_)), 276 x_root_window_(DefaultRootWindow(xdisplay_)),
275 current_cursor_(aura::kCursorNull), 277 current_cursor_(aura::kCursorNull),
278 custom_cursor_(0),
276 cursor_shown_(true), 279 cursor_shown_(true),
277 bounds_(bounds) { 280 bounds_(bounds) {
278 XSetWindowAttributes swa; 281 XSetWindowAttributes swa;
279 memset(&swa, 0, sizeof(swa)); 282 memset(&swa, 0, sizeof(swa));
280 swa.background_pixmap = None; 283 swa.background_pixmap = None;
281 xwindow_ = XCreateWindow( 284 xwindow_ = XCreateWindow(
282 xdisplay_, x_root_window_, 285 xdisplay_, x_root_window_,
283 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), 286 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(),
284 0, // border width 287 0, // border width
285 CopyFromParent, // depth 288 CopyFromParent, // depth
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 current_cursor_ = cursor; 546 current_cursor_ = cursor;
544 547
545 // Custom web cursors are handled directly. 548 // Custom web cursors are handled directly.
546 if (cursor == kCursorCustom) 549 if (cursor == kCursorCustom)
547 return; 550 return;
548 551
549 if (cursor_shown_) 552 if (cursor_shown_)
550 SetCursorInternal(cursor); 553 SetCursorInternal(cursor);
551 } 554 }
552 555
556 void RootWindowHostLinux::SetCustomCursor(const gfx::PlatformCursor& cursor) {
557 if (custom_cursor_)
558 ui::UnrefCustomXCursor(custom_cursor_);
Daniel Erat 2012/02/24 21:04:36 put this in the d'tor too
sadrul 2012/02/24 22:48:49 Ah, good catch. Done.
559 custom_cursor_ = cursor;
560 if (custom_cursor_)
561 ui::RefCustomXCursor(custom_cursor_);
562 if (cursor_shown_)
563 XDefineCursor(xdisplay_, xwindow_, cursor);
Daniel Erat 2012/02/24 21:04:36 i think that you need to make ShowCursor() handle
sadrul 2012/02/24 22:48:49 Very nice. Done! One exception: I am not CHECK()i
Daniel Erat 2012/02/24 23:19:31 Hmm, I see. Will the current unsetting/unref-ing
sadrul 2012/02/25 00:02:30 I have changed the code in SetCursor to unset cust
Daniel Erat 2012/02/25 00:38:56 So just to make sure that I understand correctly,
564 }
565
553 void RootWindowHostLinux::ShowCursor(bool show) { 566 void RootWindowHostLinux::ShowCursor(bool show) {
554 if (show == cursor_shown_) 567 if (show == cursor_shown_)
555 return; 568 return;
556 cursor_shown_ = show; 569 cursor_shown_ = show;
557 SetCursorInternal(show ? current_cursor_ : kCursorNone); 570 SetCursorInternal(show ? current_cursor_ : kCursorNone);
558 } 571 }
559 572
560 gfx::Point RootWindowHostLinux::QueryMouseLocation() { 573 gfx::Point RootWindowHostLinux::QueryMouseLocation() {
561 ::Window root_return, child_return; 574 ::Window root_return, child_return;
562 int root_x_return, root_y_return, win_x_return, win_y_return; 575 int root_x_return, root_y_return, win_x_return, win_y_return;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False); 653 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False);
641 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None; 654 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None;
642 } 655 }
643 656
644 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { 657 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) {
645 ::Cursor xcursor = 658 ::Cursor xcursor =
646 cursor == kCursorNone ? 659 cursor == kCursorNone ?
647 invisible_cursor_ : 660 invisible_cursor_ :
648 ui::GetXCursor(CursorShapeFromNative(cursor)); 661 ui::GetXCursor(CursorShapeFromNative(cursor));
649 XDefineCursor(xdisplay_, xwindow_, xcursor); 662 XDefineCursor(xdisplay_, xwindow_, xcursor);
663 if (custom_cursor_) {
664 ui::UnrefCustomXCursor(custom_cursor_);
665 custom_cursor_ = 0;
666 }
650 } 667 }
651 668
652 // static 669 // static
653 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { 670 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) {
654 return new RootWindowHostLinux(bounds); 671 return new RootWindowHostLinux(bounds);
655 } 672 }
656 673
657 // static 674 // static
658 gfx::Size RootWindowHost::GetNativeScreenSize() { 675 gfx::Size RootWindowHost::GetNativeScreenSize() {
659 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); 676 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay();
660 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); 677 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0));
661 } 678 }
662 679
663 } // namespace aura 680 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698