diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | ui/aura/root_window.cc | 4 | ||||
-rw-r--r-- | ui/aura/root_window.h | 3 | ||||
-rw-r--r-- | ui/aura/root_window_host.h | 7 | ||||
-rw-r--r-- | ui/aura/root_window_host_linux.cc | 35 | ||||
-rw-r--r-- | ui/aura/root_window_host_win.cc | 4 | ||||
-rw-r--r-- | ui/aura/root_window_host_win.h | 1 | ||||
-rw-r--r-- | ui/aura_shell/root_window_event_filter.cc | 18 | ||||
-rw-r--r-- | ui/aura_shell/root_window_event_filter.h | 6 |
9 files changed, 76 insertions, 3 deletions
@@ -150,3 +150,4 @@ Halton Huo <halton.huo@gmail.com> Shiliu Wang <aofdwsl@gmail.com> Gao Chun <gaochun.dev@gmail.com> Devlin Cronin <rdevlin.cronin@gmail.com> +Junmin Zhu <junmin.zhu@intel.com> diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index 62db782..ef4e0a1 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -111,6 +111,10 @@ void RootWindow::SetCursor(gfx::NativeCursor cursor) { host_->SetCursor(cursor); } +void RootWindow::ShowCursor(bool show) { + host_->ShowCursor(show); +} + void RootWindow::Run() { ShowRootWindow(); MessageLoopForUI::current()->Run(); diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h index f7b0862..0af56b2 100644 --- a/ui/aura/root_window.h +++ b/ui/aura/root_window.h @@ -71,6 +71,9 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, // Shows the specified cursor. void SetCursor(gfx::NativeCursor cursor); + // Sets current cursor visibility to |show|. + void ShowCursor(bool show); + // Shows the root window host and runs an event loop for it. void Run(); diff --git a/ui/aura/root_window_host.h b/ui/aura/root_window_host.h index c88097d..1c77565 100644 --- a/ui/aura/root_window_host.h +++ b/ui/aura/root_window_host.h @@ -54,9 +54,14 @@ class RootWindowHost : public MessageLoop::Dispatcher { // Returns the location of the RootWindow on native screen. virtual gfx::Point GetLocationOnNativeScreen() const = 0; - // Sets the currently displayed cursor. + // Sets the currently displayed cursor. Shows the cursor by default. + // If you want to update hidden cursor, should call ShowCursor(false) + // after this function. virtual void SetCursor(gfx::NativeCursor cursor) = 0; + // Sets current cursor visibility to |show|. + virtual void ShowCursor(bool show) = 0; + // Queries the mouse's current position relative to the host window. // The position is constrained within the host window. // You should probably call RootWindow::last_mouse_location() instead; this diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc index 6ed655b..0857a9f 100644 --- a/ui/aura/root_window_host_linux.cc +++ b/ui/aura/root_window_host_linux.cc @@ -293,6 +293,7 @@ class RootWindowHostLinux : public RootWindowHost, virtual void SetSize(const gfx::Size& size) OVERRIDE; virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE; + virtual void ShowCursor(bool show) OVERRIDE; virtual gfx::Point QueryMouseLocation() OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; @@ -316,6 +317,13 @@ class RootWindowHostLinux : public RootWindowHost, // Current Aura cursor. gfx::NativeCursor current_cursor_; + // The default cursor is showed after startup, and hidden when touch pressed. + // Once mouse moved, the cursor is immediately displayed. + bool is_cursor_visible_; + + // The invisible cursor. + ::Cursor invisible_cursor_; + // The bounds of |xwindow_|. gfx::Rect bounds_; @@ -328,6 +336,7 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) xwindow_(0), x_root_window_(DefaultRootWindow(xdisplay_)), current_cursor_(aura::kCursorNull), + is_cursor_visible_(true), bounds_(bounds) { xwindow_ = XCreateSimpleWindow(xdisplay_, x_root_window_, bounds.x(), bounds.y(), @@ -349,6 +358,15 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) base::MessagePumpX::SetDefaultDispatcher(this); MessageLoopForUI::current()->AddDestructionObserver(this); + + // Initializes invisiable cursor. + char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + XColor black; + black.red = black.green = black.blue = 0; + Pixmap blank = XCreateBitmapFromData(xdisplay_, xwindow_, + nodata, 8, 8); + invisible_cursor_ = XCreatePixmapCursor(xdisplay_, blank, blank, + &black, &black, 0, 0); } RootWindowHostLinux::~RootWindowHostLinux() { @@ -357,6 +375,8 @@ RootWindowHostLinux::~RootWindowHostLinux() { // Clears XCursorCache. ui::GetXCursor(ui::kCursorClearXCursorCache); + XFreeCursor(xdisplay_, invisible_cursor_); + MessageLoopForUI::current()->RemoveDestructionObserver(this); base::MessagePumpX::SetDefaultDispatcher(NULL); } @@ -575,6 +595,21 @@ void RootWindowHostLinux::SetCursor(gfx::NativeCursor cursor) { XDefineCursor(xdisplay_, xwindow_, xcursor); } +void RootWindowHostLinux::ShowCursor(bool show) { + if (show == is_cursor_visible_) + return; + + is_cursor_visible_ = show; + + if (show) { + int cursor_shape = CursorShapeFromNative(current_cursor_); + ::Cursor xcursor = ui::GetXCursor(cursor_shape); + XDefineCursor(xdisplay_, xwindow_, xcursor); + } else { + XDefineCursor(xdisplay_, xwindow_, invisible_cursor_); + } +} + gfx::Point RootWindowHostLinux::QueryMouseLocation() { ::Window root_return, child_return; int root_x_return, root_y_return, win_x_return, win_y_return; diff --git a/ui/aura/root_window_host_win.cc b/ui/aura/root_window_host_win.cc index 577f5d0..443da6b 100644 --- a/ui/aura/root_window_host_win.cc +++ b/ui/aura/root_window_host_win.cc @@ -223,6 +223,10 @@ void RootWindowHostWin::SetCursor(gfx::NativeCursor native_cursor) { ::SetCursor(LoadCursor(NULL, cursor_id)); } +void RootWindowHostWin::ShowCursor(bool show) { + NOTIMPLEMENTED(); +} + gfx::Point RootWindowHostWin::QueryMouseLocation() { POINT pt; GetCursorPos(&pt); diff --git a/ui/aura/root_window_host_win.h b/ui/aura/root_window_host_win.h index 29ca65f..ad9547f 100644 --- a/ui/aura/root_window_host_win.h +++ b/ui/aura/root_window_host_win.h @@ -29,6 +29,7 @@ class RootWindowHostWin : public RootWindowHost, public ui::WindowImpl { virtual void SetSize(const gfx::Size& size) OVERRIDE; virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; + virtual void ShowCursor(bool show) OVERRIDE; virtual gfx::Point QueryMouseLocation() OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE; diff --git a/ui/aura_shell/root_window_event_filter.cc b/ui/aura_shell/root_window_event_filter.cc index b627341..4279f30 100644 --- a/ui/aura_shell/root_window_event_filter.cc +++ b/ui/aura_shell/root_window_event_filter.cc @@ -73,8 +73,12 @@ bool RootWindowEventFilter::PreHandleMouseEvent(aura::Window* target, aura::MouseEvent* event) { // We must always update the cursor, otherwise the cursor can get stuck if an // event filter registered with us consumes the event. - if (event->type() == ui::ET_MOUSE_MOVED) + if (event->type() == ui::ET_MOUSE_MOVED) { + // Shows the cursor when mouse moved. + SetCursorVisible(target, event, true); + UpdateCursor(target, event); + } if (FilterMouseEvent(target, event)) return true; @@ -92,8 +96,12 @@ ui::TouchStatus RootWindowEventFilter::PreHandleTouchEvent( if (status != ui::TOUCH_STATUS_UNKNOWN) return status; - if (event->type() == ui::ET_TOUCH_PRESSED) + if (event->type() == ui::ET_TOUCH_PRESSED) { + // Hides the cursor when touch pressed. + SetCursorVisible(target, event, false); + target->GetFocusManager()->SetFocusedWindow(target); + } return ui::TOUCH_STATUS_UNKNOWN; } @@ -111,6 +119,12 @@ void RootWindowEventFilter::UpdateCursor(aura::Window* target, aura::RootWindow::GetInstance()->SetCursor(cursor); } +void RootWindowEventFilter::SetCursorVisible(aura::Window* target, + aura::LocatedEvent* event, + bool show) { + aura::RootWindow::GetInstance()->ShowCursor(show); +} + bool RootWindowEventFilter::FilterKeyEvent(aura::Window* target, aura::KeyEvent* event) { bool handled = false; diff --git a/ui/aura_shell/root_window_event_filter.h b/ui/aura_shell/root_window_event_filter.h index 8392aa4..9c0e61b 100644 --- a/ui/aura_shell/root_window_event_filter.h +++ b/ui/aura_shell/root_window_event_filter.h @@ -8,6 +8,7 @@ #include "base/compiler_specific.h" #include "base/observer_list.h" +#include "ui/aura/event.h" #include "ui/aura/event_filter.h" #include "ui/aura_shell/aura_shell_export.h" @@ -44,6 +45,11 @@ class AURA_SHELL_EXPORT RootWindowEventFilter : public aura::EventFilter { // default resize cursors for window edges. void UpdateCursor(aura::Window* target, aura::MouseEvent* event); + // Sets the cursor invisible when the target receives touch press event. + void SetCursorVisible(aura::Window* target, + aura::LocatedEvent* event, + bool show); + // Dispatches event to additional filters. Returns false or // ui::TOUCH_STATUS_UNKNOWN if event is consumed. bool FilterKeyEvent(aura::Window* target, aura::KeyEvent* event); |