Chromium Code Reviews| 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/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 Loading... | |
| 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 Loading... | |
| 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 24 matching lines...) Expand all Loading... | |
| 310 black.red = black.green = black.blue = 0; | 313 black.red = black.green = black.blue = 0; |
| 311 Pixmap blank = XCreateBitmapFromData(xdisplay_, xwindow_, | 314 Pixmap blank = XCreateBitmapFromData(xdisplay_, xwindow_, |
| 312 nodata, 8, 8); | 315 nodata, 8, 8); |
| 313 invisible_cursor_ = XCreatePixmapCursor(xdisplay_, blank, blank, | 316 invisible_cursor_ = XCreatePixmapCursor(xdisplay_, blank, blank, |
| 314 &black, &black, 0, 0); | 317 &black, &black, 0, 0); |
| 315 if (RootWindow::hide_host_cursor()) | 318 if (RootWindow::hide_host_cursor()) |
| 316 XDefineCursor(xdisplay_, x_root_window_, invisible_cursor_); | 319 XDefineCursor(xdisplay_, x_root_window_, invisible_cursor_); |
| 317 } | 320 } |
| 318 | 321 |
| 319 RootWindowHostLinux::~RootWindowHostLinux() { | 322 RootWindowHostLinux::~RootWindowHostLinux() { |
| 323 if (custom_cursor_) { | |
| 324 ui::UnrefCustomXCursor(custom_cursor_); | |
| 325 custom_cursor_ = 0; | |
| 326 } | |
| 327 | |
| 320 XDestroyWindow(xdisplay_, xwindow_); | 328 XDestroyWindow(xdisplay_, xwindow_); |
| 321 | 329 |
| 322 // Clears XCursorCache. | 330 // Clears XCursorCache. |
| 323 ui::GetXCursor(ui::kCursorClearXCursorCache); | 331 ui::GetXCursor(ui::kCursorClearXCursorCache); |
| 324 | 332 |
| 325 XFreeCursor(xdisplay_, invisible_cursor_); | 333 XFreeCursor(xdisplay_, invisible_cursor_); |
| 326 | 334 |
| 327 MessageLoopForUI::current()->RemoveDestructionObserver(this); | 335 MessageLoopForUI::current()->RemoveDestructionObserver(this); |
| 328 base::MessagePumpX::SetDefaultDispatcher(NULL); | 336 base::MessagePumpX::SetDefaultDispatcher(NULL); |
| 329 } | 337 } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 } | 543 } |
| 536 | 544 |
| 537 void RootWindowHostLinux::ReleaseCapture() { | 545 void RootWindowHostLinux::ReleaseCapture() { |
| 538 } | 546 } |
| 539 | 547 |
| 540 void RootWindowHostLinux::SetCursor(gfx::NativeCursor cursor) { | 548 void RootWindowHostLinux::SetCursor(gfx::NativeCursor cursor) { |
| 541 if (cursor == current_cursor_) | 549 if (cursor == current_cursor_) |
| 542 return; | 550 return; |
| 543 current_cursor_ = cursor; | 551 current_cursor_ = cursor; |
| 544 | 552 |
| 545 // Custom web cursors are handled directly. | 553 if (custom_cursor_) { |
| 546 if (cursor == kCursorCustom) | 554 ui::UnrefCustomXCursor(custom_cursor_); |
| 547 return; | 555 custom_cursor_ = 0; |
| 556 } | |
| 548 | 557 |
| 549 if (cursor_shown_) | 558 if (cursor_shown_) |
| 550 SetCursorInternal(cursor); | 559 SetCursorInternal(cursor); |
| 551 } | 560 } |
| 552 | 561 |
| 562 void RootWindowHostLinux::SetCustomCursor(const gfx::PlatformCursor& cursor) { | |
| 563 if (custom_cursor_) | |
| 564 ui::UnrefCustomXCursor(custom_cursor_); | |
| 565 custom_cursor_ = cursor; | |
| 566 if (custom_cursor_) | |
|
Daniel Erat
2012/02/24 23:19:31
should this method CHECK(cursor)? i'm pretty sure
sadrul
2012/02/25 00:02:30
I just removed the if check here. The XCustomCurso
| |
| 567 ui::RefCustomXCursor(custom_cursor_); | |
| 568 current_cursor_ = kCursorCustom; | |
| 569 if (cursor_shown_) | |
| 570 SetCursorInternal(current_cursor_); | |
| 571 } | |
| 572 | |
| 553 void RootWindowHostLinux::ShowCursor(bool show) { | 573 void RootWindowHostLinux::ShowCursor(bool show) { |
| 554 if (show == cursor_shown_) | 574 if (show == cursor_shown_) |
| 555 return; | 575 return; |
| 556 cursor_shown_ = show; | 576 cursor_shown_ = show; |
| 557 SetCursorInternal(show ? current_cursor_ : kCursorNone); | 577 SetCursorInternal(show ? current_cursor_ : kCursorNone); |
| 558 } | 578 } |
| 559 | 579 |
| 560 gfx::Point RootWindowHostLinux::QueryMouseLocation() { | 580 gfx::Point RootWindowHostLinux::QueryMouseLocation() { |
| 561 ::Window root_return, child_return; | 581 ::Window root_return, child_return; |
| 562 int root_x_return, root_y_return, win_x_return, win_y_return; | 582 int root_x_return, root_y_return, win_x_return, win_y_return; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership | 658 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership |
| 639 // of WM_Sn selections (where n is a screen number). | 659 // of WM_Sn selections (where n is a screen number). |
| 640 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False); | 660 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False); |
| 641 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None; | 661 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None; |
| 642 } | 662 } |
| 643 | 663 |
| 644 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { | 664 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { |
| 645 ::Cursor xcursor = | 665 ::Cursor xcursor = |
| 646 cursor == kCursorNone ? | 666 cursor == kCursorNone ? |
| 647 invisible_cursor_ : | 667 invisible_cursor_ : |
| 668 cursor == kCursorCustom ? | |
| 669 custom_cursor_ : | |
| 648 ui::GetXCursor(CursorShapeFromNative(cursor)); | 670 ui::GetXCursor(CursorShapeFromNative(cursor)); |
| 649 XDefineCursor(xdisplay_, xwindow_, xcursor); | 671 XDefineCursor(xdisplay_, xwindow_, xcursor); |
| 650 } | 672 } |
| 651 | 673 |
| 652 // static | 674 // static |
| 653 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { | 675 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { |
| 654 return new RootWindowHostLinux(bounds); | 676 return new RootWindowHostLinux(bounds); |
| 655 } | 677 } |
| 656 | 678 |
| 657 // static | 679 // static |
| 658 gfx::Size RootWindowHost::GetNativeScreenSize() { | 680 gfx::Size RootWindowHost::GetNativeScreenSize() { |
| 659 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 681 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
| 660 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 682 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
| 661 } | 683 } |
| 662 | 684 |
| 663 } // namespace aura | 685 } // namespace aura |
| OLD | NEW |