summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-04 14:45:07 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-04 14:45:07 +0000
commit0207c92d4fec87764ea65bc8f5fd3c8bd2d0754d (patch)
tree26cdc0f0149812893fa7cc22d086387285db6562
parent1d887b27477d3b8af67ff392d704b430fa9a4c08 (diff)
downloadchromium_src-0207c92d4fec87764ea65bc8f5fd3c8bd2d0754d.zip
chromium_src-0207c92d4fec87764ea65bc8f5fd3c8bd2d0754d.tar.gz
chromium_src-0207c92d4fec87764ea65bc8f5fd3c8bd2d0754d.tar.bz2
Fixes the cursor to update reliably when moving from window to window.
http://crbug.com/98337 TEST=none Review URL: http://codereview.chromium.org/8122008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103882 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/aura/demo/demo_main.cc3
-rw-r--r--ui/aura/desktop.cc4
-rw-r--r--ui/aura/desktop.h2
-rw-r--r--ui/aura/desktop_host.h2
-rw-r--r--ui/aura/desktop_host_linux.cc4
-rw-r--r--ui/aura/desktop_host_win.cc24
-rw-r--r--ui/aura/desktop_host_win.h2
-rw-r--r--ui/aura/event_filter.cc11
-rw-r--r--ui/aura/toplevel_window_event_filter.cc16
-rw-r--r--ui/aura/window.cc4
-rw-r--r--ui/aura/window.h4
-rw-r--r--ui/aura/window_delegate.h6
-rw-r--r--ui/aura/window_unittest.cc3
-rw-r--r--ui/aura_shell/toplevel_frame_view.cc25
-rw-r--r--ui/aura_shell/toplevel_frame_view.h1
-rw-r--r--ui/gfx/compositor/compositor.h2
-rw-r--r--views/aura_desktop/aura_desktop_main.cc3
-rw-r--r--views/widget/native_widget_aura.cc11
-rw-r--r--views/widget/native_widget_aura.h3
19 files changed, 83 insertions, 47 deletions
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc
index 67f8730..acd7a78 100644
--- a/ui/aura/demo/demo_main.cc
+++ b/ui/aura/demo/demo_main.cc
@@ -37,6 +37,9 @@ class DemoWindowDelegate : public aura::WindowDelegate {
virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE {
return false;
}
+ virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
+ return NULL;
+ }
virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
return HTCAPTION;
}
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc
index 4315a4c..43d76ba 100644
--- a/ui/aura/desktop.cc
+++ b/ui/aura/desktop.cc
@@ -70,8 +70,8 @@ void Desktop::SetSize(const gfx::Size& size) {
host_->SetSize(size);
}
-void Desktop::SetCursor(CursorType cursor_type) {
- host_->SetCursor(cursor_type);
+void Desktop::SetCursor(gfx::NativeCursor cursor) {
+ host_->SetCursor(cursor);
}
void Desktop::Run() {
diff --git a/ui/aura/desktop.h b/ui/aura/desktop.h
index 85cd4dc..1af4b8f 100644
--- a/ui/aura/desktop.h
+++ b/ui/aura/desktop.h
@@ -43,7 +43,7 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate {
void SetSize(const gfx::Size& size);
// Shows the specified cursor.
- void SetCursor(CursorType cursor_type);
+ void SetCursor(gfx::NativeCursor cursor);
// Shows the desktop host and runs an event loop for it.
void Run();
diff --git a/ui/aura/desktop_host.h b/ui/aura/desktop_host.h
index e9e134a..bc2232e 100644
--- a/ui/aura/desktop_host.h
+++ b/ui/aura/desktop_host.h
@@ -43,7 +43,7 @@ class DesktopHost : public MessageLoop::Dispatcher {
virtual void SetSize(const gfx::Size& size) = 0;
// Sets the currently displayed cursor.
- virtual void SetCursor(CursorType cursor_type) = 0;
+ virtual void SetCursor(gfx::NativeCursor cursor) = 0;
};
} // namespace aura
diff --git a/ui/aura/desktop_host_linux.cc b/ui/aura/desktop_host_linux.cc
index e602451..b61bf56 100644
--- a/ui/aura/desktop_host_linux.cc
+++ b/ui/aura/desktop_host_linux.cc
@@ -30,7 +30,7 @@ class DesktopHostLinux : public DesktopHost {
virtual void Show() OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
- virtual void SetCursor(CursorType cursor_type) OVERRIDE;
+ virtual void UpdateCursor(gfx::NativeCursor cursor_type) OVERRIDE;
Desktop* desktop_;
@@ -127,7 +127,7 @@ void DesktopHostLinux::SetSize(const gfx::Size& size) {
XResizeWindow(xdisplay_, xwindow_, size.width(), size.height());
}
-void DesktopHostLinux::SetCursor(CursorType cursor_type) {
+void DesktopHostLinux::SetCursor(gfx::NativeCursor cursor_type) {
NOTIMPLEMENTED();
}
diff --git a/ui/aura/desktop_host_win.cc b/ui/aura/desktop_host_win.cc
index e078c7d..9f3fef2 100644
--- a/ui/aura/desktop_host_win.cc
+++ b/ui/aura/desktop_host_win.cc
@@ -58,26 +58,10 @@ void DesktopHostWin::SetSize(const gfx::Size& size) {
SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION);
}
-void DesktopHostWin::SetCursor(CursorType cursor_type) {
- switch (cursor_type) {
- case CURSOR_POINTER:
- ::SetCursor(LoadCursor(NULL, IDC_ARROW));
- break;
- case CURSOR_LINK:
- ::SetCursor(LoadCursor(NULL, IDC_HAND));
- break;
- case CURSOR_WAIT:
- ::SetCursor(LoadCursor(NULL, IDC_WAIT));
- break;
- case CURSOR_SIZE_HORIZONTAL:
- ::SetCursor(LoadCursor(NULL, IDC_SIZEWE));
- break;
- case CURSOR_SIZE_VERTICAL:
- ::SetCursor(LoadCursor(NULL, IDC_SIZENS));
- break;
- default:
- break;
- }
+void DesktopHostWin::SetCursor(gfx::NativeCursor cursor) {
+ if (!cursor)
+ cursor = LoadCursor(NULL, IDC_ARROW);
+ ::SetCursor(cursor);
}
void DesktopHostWin::OnClose() {
diff --git a/ui/aura/desktop_host_win.h b/ui/aura/desktop_host_win.h
index 45bdaf3..7d91768 100644
--- a/ui/aura/desktop_host_win.h
+++ b/ui/aura/desktop_host_win.h
@@ -26,7 +26,7 @@ class DesktopHostWin : public DesktopHost, public ui::WindowImpl {
virtual void Show() OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
- virtual void SetCursor(CursorType cursor_type) OVERRIDE;
+ virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
private:
BEGIN_MSG_MAP_EX(DesktopHostWin)
diff --git a/ui/aura/event_filter.cc b/ui/aura/event_filter.cc
index 2ece9ab..b6d7289 100644
--- a/ui/aura/event_filter.cc
+++ b/ui/aura/event_filter.cc
@@ -19,8 +19,15 @@ EventFilter::~EventFilter() {
}
bool EventFilter::OnMouseEvent(Window* target, MouseEvent* event) {
- if (event->type() == ui::ET_MOUSE_PRESSED) {
- ActivateIfNecessary(target, event);
+ switch (event->type()) {
+ case ui::ET_MOUSE_PRESSED:
+ ActivateIfNecessary(target, event);
+ break;
+ case ui::ET_MOUSE_MOVED:
+ Desktop::GetInstance()->SetCursor(target->GetCursor(event->location()));
+ break;
+ default:
+ break;
}
return false;
}
diff --git a/ui/aura/toplevel_window_event_filter.cc b/ui/aura/toplevel_window_event_filter.cc
index 90b61c6..9eb1e2c 100644
--- a/ui/aura/toplevel_window_event_filter.cc
+++ b/ui/aura/toplevel_window_event_filter.cc
@@ -34,7 +34,6 @@ bool ToplevelWindowEventFilter::OnMouseEvent(Window* target,
case ui::ET_MOUSE_MOVED:
window_component_ =
target->delegate()->GetNonClientComponent(event->location());
- UpdateCursorForWindowComponent();
break;
case ui::ET_MOUSE_PRESSED:
mouse_down_offset_ = event->location();
@@ -71,19 +70,4 @@ void ToplevelWindowEventFilter::MoveWindowToFront(Window* target) {
}
}
-void ToplevelWindowEventFilter::UpdateCursorForWindowComponent() {
- switch (window_component_) {
- case HTLEFT:
- case HTRIGHT:
- Desktop::GetInstance()->SetCursor(CURSOR_SIZE_HORIZONTAL);
- break;
- case HTBOTTOM:
- Desktop::GetInstance()->SetCursor(CURSOR_SIZE_VERTICAL);
- break;
- default:
- Desktop::GetInstance()->SetCursor(CURSOR_POINTER);
- break;
- }
-}
-
} // namespace aura
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index 7df20a5..c1e41de 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -174,6 +174,10 @@ void Window::ConvertPointToWindow(Window* source,
ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point);
}
+gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const {
+ return delegate_ ? delegate_->GetCursor(point) : NULL;
+}
+
void Window::SetEventFilter(EventFilter* event_filter) {
event_filter_.reset(event_filter);
}
diff --git a/ui/aura/window.h b/ui/aura/window.h
index d41b204b..4e42c13 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -13,6 +13,7 @@
#include "base/string16.h"
#include "ui/aura/aura_export.h"
#include "ui/gfx/compositor/layer_delegate.h"
+#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/rect.h"
class SkCanvas;
@@ -105,6 +106,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
Window* target,
gfx::Point* point);
+ // Returns the cursor for the specified point, in window coordinates.
+ gfx::NativeCursor GetCursor(const gfx::Point& point) const;
+
// Window takes ownership of the EventFilter.
void SetEventFilter(EventFilter* event_filter);
diff --git a/ui/aura/window_delegate.h b/ui/aura/window_delegate.h
index f02a113..03d562b 100644
--- a/ui/aura/window_delegate.h
+++ b/ui/aura/window_delegate.h
@@ -6,6 +6,8 @@
#define UI_AURA_WINDOW_DELEGATE_H_
#pragma once
+#include "ui/gfx/native_widget_types.h"
+
namespace gfx {
class Canvas;
class Point;
@@ -30,6 +32,10 @@ class WindowDelegate {
virtual bool OnKeyEvent(KeyEvent* event) = 0;
+ // Returns the native cursor for the specified point, in window coordinates,
+ // or NULL for the default cursor.
+ virtual gfx::NativeCursor GetCursor(const gfx::Point& point) = 0;
+
// Returns the non-client component (see hit_test.h) containing |point|, in
// window coordinates.
virtual int GetNonClientComponent(const gfx::Point& point) const = 0;
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 9c489e6..48834c5 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -38,6 +38,9 @@ class WindowDelegateImpl : public WindowDelegate {
virtual bool OnKeyEvent(KeyEvent* event) OVERRIDE {
return false;
}
+ virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
+ return NULL;
+ }
virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
return HTCLIENT;
}
diff --git a/ui/aura_shell/toplevel_frame_view.cc b/ui/aura_shell/toplevel_frame_view.cc
index 11590c7..cdbc4b4 100644
--- a/ui/aura_shell/toplevel_frame_view.cc
+++ b/ui/aura_shell/toplevel_frame_view.cc
@@ -471,5 +471,30 @@ views::View* ToplevelFrameView::GetEventHandlerForPoint(
return View::GetEventHandlerForPoint(point);
}
+gfx::NativeCursor ToplevelFrameView::GetCursor(const views::MouseEvent& event) {
+#if defined(OS_WIN)
+ switch (current_hittest_code_) {
+ case HTTOPLEFT:
+ case HTBOTTOMRIGHT:
+ return LoadCursor(NULL, IDC_SIZENWSE);
+ case HTTOP:
+ case HTBOTTOM:
+ return LoadCursor(NULL, IDC_SIZENS);
+ case HTTOPRIGHT:
+ case HTBOTTOMLEFT:
+ return LoadCursor(NULL, IDC_SIZENESW);
+ case HTRIGHT:
+ case HTLEFT:
+ return LoadCursor(NULL, IDC_SIZEWE);
+ default:
+ break;
+ }
+ return NULL;
+#elif defined(OS_LINUX)
+ NOTIMPLEMENTED();
+ return NULL;
+#endif
+}
+
} // namespace internal
} // namespace aura_shell
diff --git a/ui/aura_shell/toplevel_frame_view.h b/ui/aura_shell/toplevel_frame_view.h
index 10772dc..46d20fb 100644
--- a/ui/aura_shell/toplevel_frame_view.h
+++ b/ui/aura_shell/toplevel_frame_view.h
@@ -66,6 +66,7 @@ class AURA_SHELL_EXPORT ToplevelFrameView : public views::NonClientFrameView {
virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
virtual views::View* GetEventHandlerForPoint(
const gfx::Point& point) OVERRIDE;
+ virtual gfx::NativeCursor GetCursor(const views::MouseEvent& event) OVERRIDE;
gfx::Rect client_view_bounds_;
diff --git a/ui/gfx/compositor/compositor.h b/ui/gfx/compositor/compositor.h
index 3f912bd..5c45cc9 100644
--- a/ui/gfx/compositor/compositor.h
+++ b/ui/gfx/compositor/compositor.h
@@ -124,6 +124,8 @@ class COMPOSITOR_EXPORT Compositor : public base::RefCounted<Compositor> {
// Notifies the compositor that the size of the widget that it is
// drawing to has changed.
void WidgetSizeChanged(const gfx::Size& size) {
+ if (size.IsEmpty())
+ return;
size_ = size;
OnWidgetSizeChanged();
}
diff --git a/views/aura_desktop/aura_desktop_main.cc b/views/aura_desktop/aura_desktop_main.cc
index 0f8bc56..2cd2bc6 100644
--- a/views/aura_desktop/aura_desktop_main.cc
+++ b/views/aura_desktop/aura_desktop_main.cc
@@ -40,6 +40,9 @@ class DemoWindowDelegate : public aura::WindowDelegate {
virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE {
return false;
}
+ virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
+ return NULL;
+ }
virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
return HTCLIENT;
}
diff --git a/views/widget/native_widget_aura.cc b/views/widget/native_widget_aura.cc
index 033527d..d3dc4a9 100644
--- a/views/widget/native_widget_aura.cc
+++ b/views/widget/native_widget_aura.cc
@@ -4,6 +4,7 @@
#include "views/widget/native_widget_aura.h"
+#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
#include "ui/aura/window.h"
#include "ui/gfx/canvas.h"
@@ -28,7 +29,8 @@ NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate)
ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
- can_activate_(true) {
+ can_activate_(true),
+ cursor_(NULL) {
}
NativeWidgetAura::~NativeWidgetAura() {
@@ -358,7 +360,8 @@ void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) {
}
void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) {
- //NOTIMPLEMENTED();
+ cursor_ = cursor;
+ aura::Desktop::GetInstance()->SetCursor(cursor);
}
void NativeWidgetAura::ClearNativeFocus() {
@@ -407,6 +410,10 @@ bool NativeWidgetAura::OnKeyEvent(aura::KeyEvent* event) {
return delegate_->OnKeyEvent(KeyEvent(event));
}
+gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) {
+ return cursor_;
+}
+
int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const {
return delegate_->GetNonClientComponent(point);
}
diff --git a/views/widget/native_widget_aura.h b/views/widget/native_widget_aura.h
index 2066679..5458241 100644
--- a/views/widget/native_widget_aura.h
+++ b/views/widget/native_widget_aura.h
@@ -123,6 +123,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
virtual void OnFocus() OVERRIDE;
virtual void OnBlur() OVERRIDE;
virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE;
+ virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE;
virtual bool ShouldActivate(aura::MouseEvent* event) OVERRIDE;
@@ -152,6 +153,8 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
// Map used by Set/GetNativeWindowProperty.
PropsMap props_map_;
+ gfx::NativeCursor cursor_;
+
DISALLOW_COPY_AND_ASSIGN(NativeWidgetAura);
};