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

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: sort headers. Created 8 years, 9 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 <X11/extensions/Xfixes.h> 9 #include <X11/extensions/Xfixes.h>
10 #include <X11/extensions/Xrandr.h> 10 #include <X11/extensions/Xrandr.h>
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #include "base/message_pump_x.h" 13 #include "base/message_pump_x.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "ui/aura/cursor.h"
16 #include "ui/aura/dispatcher_linux.h" 15 #include "ui/aura/dispatcher_linux.h"
17 #include "ui/aura/env.h" 16 #include "ui/aura/env.h"
18 #include "ui/aura/event.h" 17 #include "ui/aura/event.h"
19 #include "ui/aura/monitor.h" 18 #include "ui/aura/monitor.h"
20 #include "ui/aura/monitor_manager.h" 19 #include "ui/aura/monitor_manager.h"
21 #include "ui/aura/root_window.h" 20 #include "ui/aura/root_window.h"
21 #include "ui/base/cursor/cursor.h"
22 #include "ui/base/keycodes/keyboard_codes.h" 22 #include "ui/base/keycodes/keyboard_codes.h"
23 #include "ui/base/touch/touch_factory.h" 23 #include "ui/base/touch/touch_factory.h"
24 #include "ui/base/x/x11_util.h" 24 #include "ui/base/x/x11_util.h"
25 #include "ui/gfx/compositor/layer.h" 25 #include "ui/gfx/compositor/layer.h"
26 26
27 using std::max; 27 using std::max;
28 using std::min; 28 using std::min;
29 29
30 namespace aura { 30 namespace aura {
31 31
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 CHECK_EQ(slave_event.valuators.mask_len, xievent->valuators.mask_len); 75 CHECK_EQ(slave_event.valuators.mask_len, xievent->valuators.mask_len);
76 CHECK_EQ(slave_event.mods.base, xievent->mods.base); 76 CHECK_EQ(slave_event.mods.base, xievent->mods.base);
77 CHECK_EQ(slave_event.mods.latched, xievent->mods.latched); 77 CHECK_EQ(slave_event.mods.latched, xievent->mods.latched);
78 CHECK_EQ(slave_event.mods.locked, xievent->mods.locked); 78 CHECK_EQ(slave_event.mods.locked, xievent->mods.locked);
79 CHECK_EQ(slave_event.mods.effective, xievent->mods.effective); 79 CHECK_EQ(slave_event.mods.effective, xievent->mods.effective);
80 } 80 }
81 } 81 }
82 82
83 // Returns X font cursor shape from an Aura cursor. 83 // Returns X font cursor shape from an Aura cursor.
84 int CursorShapeFromNative(gfx::NativeCursor native_cursor) { 84 int CursorShapeFromNative(gfx::NativeCursor native_cursor) {
85 switch (native_cursor) { 85 switch (native_cursor.native_type()) {
86 case aura::kCursorNull: 86 case ui::kCursorNull:
87 return XC_left_ptr; 87 return XC_left_ptr;
88 case aura::kCursorPointer: 88 case ui::kCursorPointer:
89 return XC_left_ptr; 89 return XC_left_ptr;
90 case aura::kCursorCross: 90 case ui::kCursorCross:
91 return XC_crosshair; 91 return XC_crosshair;
92 case aura::kCursorHand: 92 case ui::kCursorHand:
93 return XC_hand2; 93 return XC_hand2;
94 case aura::kCursorIBeam: 94 case ui::kCursorIBeam:
95 return XC_xterm; 95 return XC_xterm;
96 case aura::kCursorWait: 96 case ui::kCursorWait:
97 return XC_watch; 97 return XC_watch;
98 case aura::kCursorHelp: 98 case ui::kCursorHelp:
99 return XC_question_arrow; 99 return XC_question_arrow;
100 case aura::kCursorEastResize: 100 case ui::kCursorEastResize:
101 return XC_right_side; 101 return XC_right_side;
102 case aura::kCursorNorthResize: 102 case ui::kCursorNorthResize:
103 return XC_top_side; 103 return XC_top_side;
104 case aura::kCursorNorthEastResize: 104 case ui::kCursorNorthEastResize:
105 return XC_top_right_corner; 105 return XC_top_right_corner;
106 case aura::kCursorNorthWestResize: 106 case ui::kCursorNorthWestResize:
107 return XC_top_left_corner; 107 return XC_top_left_corner;
108 case aura::kCursorSouthResize: 108 case ui::kCursorSouthResize:
109 return XC_bottom_side; 109 return XC_bottom_side;
110 case aura::kCursorSouthEastResize: 110 case ui::kCursorSouthEastResize:
111 return XC_bottom_right_corner; 111 return XC_bottom_right_corner;
112 case aura::kCursorSouthWestResize: 112 case ui::kCursorSouthWestResize:
113 return XC_bottom_left_corner; 113 return XC_bottom_left_corner;
114 case aura::kCursorWestResize: 114 case ui::kCursorWestResize:
115 return XC_left_side; 115 return XC_left_side;
116 case aura::kCursorNorthSouthResize: 116 case ui::kCursorNorthSouthResize:
117 return XC_sb_v_double_arrow; 117 return XC_sb_v_double_arrow;
118 case aura::kCursorEastWestResize: 118 case ui::kCursorEastWestResize:
119 return XC_sb_h_double_arrow; 119 return XC_sb_h_double_arrow;
120 case aura::kCursorNorthEastSouthWestResize: 120 case ui::kCursorNorthEastSouthWestResize:
121 case aura::kCursorNorthWestSouthEastResize: 121 case ui::kCursorNorthWestSouthEastResize:
122 // There isn't really a useful cursor available for these. 122 // There isn't really a useful cursor available for these.
123 return XC_left_ptr; 123 return XC_left_ptr;
124 case aura::kCursorColumnResize: 124 case ui::kCursorColumnResize:
125 return XC_sb_h_double_arrow; 125 return XC_sb_h_double_arrow;
126 case aura::kCursorRowResize: 126 case ui::kCursorRowResize:
127 return XC_sb_v_double_arrow; 127 return XC_sb_v_double_arrow;
128 case aura::kCursorMiddlePanning: 128 case ui::kCursorMiddlePanning:
129 return XC_fleur; 129 return XC_fleur;
130 case aura::kCursorEastPanning: 130 case ui::kCursorEastPanning:
131 return XC_sb_right_arrow; 131 return XC_sb_right_arrow;
132 case aura::kCursorNorthPanning: 132 case ui::kCursorNorthPanning:
133 return XC_sb_up_arrow; 133 return XC_sb_up_arrow;
134 case aura::kCursorNorthEastPanning: 134 case ui::kCursorNorthEastPanning:
135 return XC_top_right_corner; 135 return XC_top_right_corner;
136 case aura::kCursorNorthWestPanning: 136 case ui::kCursorNorthWestPanning:
137 return XC_top_left_corner; 137 return XC_top_left_corner;
138 case aura::kCursorSouthPanning: 138 case ui::kCursorSouthPanning:
139 return XC_sb_down_arrow; 139 return XC_sb_down_arrow;
140 case aura::kCursorSouthEastPanning: 140 case ui::kCursorSouthEastPanning:
141 return XC_bottom_right_corner; 141 return XC_bottom_right_corner;
142 case aura::kCursorSouthWestPanning: 142 case ui::kCursorSouthWestPanning:
143 return XC_bottom_left_corner; 143 return XC_bottom_left_corner;
144 case aura::kCursorWestPanning: 144 case ui::kCursorWestPanning:
145 return XC_sb_left_arrow; 145 return XC_sb_left_arrow;
146 case aura::kCursorMove: 146 case ui::kCursorMove:
147 return XC_fleur; 147 return XC_fleur;
148 case aura::kCursorVerticalText: 148 case ui::kCursorVerticalText:
149 case aura::kCursorCell: 149 case ui::kCursorCell:
150 case aura::kCursorContextMenu: 150 case ui::kCursorContextMenu:
151 case aura::kCursorAlias: 151 case ui::kCursorAlias:
152 case aura::kCursorProgress: 152 case ui::kCursorProgress:
153 case aura::kCursorNoDrop: 153 case ui::kCursorNoDrop:
154 case aura::kCursorCopy: 154 case ui::kCursorCopy:
155 case aura::kCursorNone: 155 case ui::kCursorNone:
156 case aura::kCursorNotAllowed: 156 case ui::kCursorNotAllowed:
157 case aura::kCursorZoomIn: 157 case ui::kCursorZoomIn:
158 case aura::kCursorZoomOut: 158 case ui::kCursorZoomOut:
159 case aura::kCursorGrab: 159 case ui::kCursorGrab:
160 case aura::kCursorGrabbing: 160 case ui::kCursorGrabbing:
161 case aura::kCursorCustom:
162 // TODO(jamescook): Need cursors for these. crbug.com/111650 161 // TODO(jamescook): Need cursors for these. crbug.com/111650
163 return XC_left_ptr; 162 return XC_left_ptr;
163 case ui::kCursorCustom:
164 NOTREACHED();
165 return XC_left_ptr;
164 } 166 }
165 NOTREACHED(); 167 NOTREACHED();
166 return XC_left_ptr; 168 return XC_left_ptr;
167 } 169 }
168 170
169 // Coalesce all pending motion events that are at the top of the queue, and 171 // Coalesce all pending motion events that are at the top of the queue, and
170 // return the number eliminated, storing the last one in |last_event|. 172 // return the number eliminated, storing the last one in |last_event|.
171 int CoalescePendingXIMotionEvents(const XEvent* xev, XEvent* last_event) { 173 int CoalescePendingXIMotionEvents(const XEvent* xev, XEvent* last_event) {
172 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); 174 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
173 int num_coalesed = 0; 175 int num_coalesed = 0;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 273 }
272 } 274 }
273 275
274 } // namespace 276 } // namespace
275 277
276 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) 278 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
277 : root_window_(NULL), 279 : root_window_(NULL),
278 xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), 280 xdisplay_(base::MessagePumpX::GetDefaultXDisplay()),
279 xwindow_(0), 281 xwindow_(0),
280 x_root_window_(DefaultRootWindow(xdisplay_)), 282 x_root_window_(DefaultRootWindow(xdisplay_)),
281 current_cursor_(aura::kCursorNull), 283 current_cursor_(ui::kCursorNull),
282 cursor_shown_(true), 284 cursor_shown_(true),
283 bounds_(bounds), 285 bounds_(bounds),
284 focus_when_shown_(false), 286 focus_when_shown_(false),
285 pointer_barriers_(NULL) { 287 pointer_barriers_(NULL) {
286 XSetWindowAttributes swa; 288 XSetWindowAttributes swa;
287 memset(&swa, 0, sizeof(swa)); 289 memset(&swa, 0, sizeof(swa));
288 swa.background_pixmap = None; 290 swa.background_pixmap = None;
289 xwindow_ = XCreateWindow( 291 xwindow_ = XCreateWindow(
290 xdisplay_, x_root_window_, 292 xdisplay_, x_root_window_,
291 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), 293 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(),
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 547 }
546 548
547 void RootWindowHostLinux::ReleaseCapture() { 549 void RootWindowHostLinux::ReleaseCapture() {
548 } 550 }
549 551
550 void RootWindowHostLinux::SetCursor(gfx::NativeCursor cursor) { 552 void RootWindowHostLinux::SetCursor(gfx::NativeCursor cursor) {
551 if (cursor == current_cursor_) 553 if (cursor == current_cursor_)
552 return; 554 return;
553 current_cursor_ = cursor; 555 current_cursor_ = cursor;
554 556
555 // Custom web cursors are handled directly.
556 if (cursor == kCursorCustom)
557 return;
558
559 if (cursor_shown_) 557 if (cursor_shown_)
560 SetCursorInternal(cursor); 558 SetCursorInternal(cursor);
561 } 559 }
562 560
563 void RootWindowHostLinux::ShowCursor(bool show) { 561 void RootWindowHostLinux::ShowCursor(bool show) {
564 if (show == cursor_shown_) 562 if (show == cursor_shown_)
565 return; 563 return;
566 cursor_shown_ = show; 564 cursor_shown_ = show;
567 SetCursorInternal(show ? current_cursor_ : kCursorNone); 565 SetCursorInternal(show ? current_cursor_ : ui::kCursorNone);
568 } 566 }
569 567
570 gfx::Point RootWindowHostLinux::QueryMouseLocation() { 568 gfx::Point RootWindowHostLinux::QueryMouseLocation() {
571 ::Window root_return, child_return; 569 ::Window root_return, child_return;
572 int root_x_return, root_y_return, win_x_return, win_y_return; 570 int root_x_return, root_y_return, win_x_return, win_y_return;
573 unsigned int mask_return; 571 unsigned int mask_return;
574 XQueryPointer(xdisplay_, 572 XQueryPointer(xdisplay_,
575 xwindow_, 573 xwindow_,
576 &root_return, 574 &root_return,
577 &child_return, 575 &child_return,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 678
681 bool RootWindowHostLinux::IsWindowManagerPresent() { 679 bool RootWindowHostLinux::IsWindowManagerPresent() {
682 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership 680 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership
683 // of WM_Sn selections (where n is a screen number). 681 // of WM_Sn selections (where n is a screen number).
684 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False); 682 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False);
685 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None; 683 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None;
686 } 684 }
687 685
688 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { 686 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) {
689 ::Cursor xcursor = 687 ::Cursor xcursor =
690 cursor == kCursorNone ? 688 cursor == ui::kCursorNone ?
691 invisible_cursor_ : 689 invisible_cursor_ :
690 cursor == ui::kCursorCustom ?
691 cursor.platform() :
692 ui::GetXCursor(CursorShapeFromNative(cursor)); 692 ui::GetXCursor(CursorShapeFromNative(cursor));
693 XDefineCursor(xdisplay_, xwindow_, xcursor); 693 XDefineCursor(xdisplay_, xwindow_, xcursor);
694 } 694 }
695 695
696 // static 696 // static
697 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { 697 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) {
698 return new RootWindowHostLinux(bounds); 698 return new RootWindowHostLinux(bounds);
699 } 699 }
700 700
701 // static 701 // static
702 gfx::Size RootWindowHost::GetNativeScreenSize() { 702 gfx::Size RootWindowHost::GetNativeScreenSize() {
703 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); 703 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay();
704 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); 704 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0));
705 } 705 }
706 706
707 } // namespace aura 707 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698