diff options
-rw-r--r-- | base/gfx/native_widget_types.h | 3 | ||||
-rw-r--r-- | views/controls/button/image_button.cc | 4 | ||||
-rw-r--r-- | views/controls/link.cc | 16 | ||||
-rw-r--r-- | views/controls/link.h | 5 | ||||
-rw-r--r-- | views/controls/single_split_view.cc | 13 | ||||
-rw-r--r-- | views/controls/single_split_view.h | 2 | ||||
-rw-r--r-- | views/view.cc | 5 | ||||
-rw-r--r-- | views/view.h | 14 | ||||
-rw-r--r-- | views/view_win.cc | 4 | ||||
-rw-r--r-- | views/widget/root_view.cc | 40 | ||||
-rw-r--r-- | views/widget/root_view.h | 7 |
11 files changed, 67 insertions, 46 deletions
diff --git a/base/gfx/native_widget_types.h b/base/gfx/native_widget_types.h index d43db5c..4c9f000 100644 --- a/base/gfx/native_widget_types.h +++ b/base/gfx/native_widget_types.h @@ -47,6 +47,7 @@ class NSWindow; class NSTextField; #endif // __OBJC__ #elif defined(OS_LINUX) +typedef struct _GdkCursor GdkCursor; typedef struct _GtkWidget GtkWidget; typedef struct _GtkWindow GtkWindow; typedef struct _cairo_surface cairo_surface_t; @@ -59,6 +60,7 @@ typedef HWND NativeView; typedef HWND NativeWindow; typedef HWND NativeEditView; typedef HDC NativeDrawingContext; +typedef HCURSOR NativeCursor; #elif defined(OS_MACOSX) typedef NSView* NativeView; typedef NSWindow* NativeWindow; @@ -69,6 +71,7 @@ typedef GtkWidget* NativeView; typedef GtkWindow* NativeWindow; typedef GtkWidget* NativeEditView; typedef cairo_surface_t* NativeDrawingContext; +typedef GdkCursor* NativeCursor; #endif // Note: for test_shell we're packing a pointer into the NativeViewId. So, if diff --git a/views/controls/button/image_button.cc b/views/controls/button/image_button.cc index a4f9123..85f5f4e 100644 --- a/views/controls/button/image_button.cc +++ b/views/controls/button/image_button.cc @@ -18,9 +18,9 @@ static const int kDefaultHeight = 14; // Default button height if no theme. ImageButton::ImageButton(ButtonListener* listener) : CustomButton(listener), + background_image_(NULL), h_alignment_(ALIGN_LEFT), - v_alignment_(ALIGN_TOP), - background_image_(NULL) { + v_alignment_(ALIGN_TOP) { // By default, we request that the gfx::Canvas passed to our View::Paint() // implementation is flipped horizontally so that the button's bitmaps are // mirrored when the UI directionality is right-to-left. diff --git a/views/controls/link.cc b/views/controls/link.cc index 14bc112..34a9e46 100644 --- a/views/controls/link.cc +++ b/views/controls/link.cc @@ -4,6 +4,10 @@ #include "views/controls/link.h" +#if defined(OS_LINUX) +#include <gdk/gdk.h> +#endif + #include "app/gfx/font.h" #include "base/logging.h" #include "views/event.h" @@ -184,17 +188,19 @@ void Link::SetEnabled(bool f) { } } -#if defined(OS_WIN) -HCURSOR Link::GetCursorForPoint(Event::EventType event_type, int x, int y) { +gfx::NativeCursor Link::GetCursorForPoint(Event::EventType event_type, int x, + int y) { if (enabled_) { - if (!g_hand_cursor) { +#if defined(OS_WIN) + if (!g_hand_cursor) g_hand_cursor = LoadCursor(NULL, IDC_HAND); - } return g_hand_cursor; +#elif defined(OS_LINUX) + return gdk_cursor_new(GDK_HAND2); +#endif } else { return NULL; } } -#endif } // namespace views diff --git a/views/controls/link.h b/views/controls/link.h index 91e77ad..c574b6e 100644 --- a/views/controls/link.h +++ b/views/controls/link.h @@ -54,9 +54,8 @@ class Link : public Label { // Set whether the link is enabled. virtual void SetEnabled(bool f); -#if defined(OS_WIN) - virtual HCURSOR GetCursorForPoint(Event::EventType event_type, int x, int y); -#endif + virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type, + int x, int y); virtual std::string GetClassName() const; diff --git a/views/controls/single_split_view.cc b/views/controls/single_split_view.cc index b40fca2..c741233 100644 --- a/views/controls/single_split_view.cc +++ b/views/controls/single_split_view.cc @@ -4,6 +4,10 @@ #include "views/controls/single_split_view.h" +#if defined(OS_LINUX) +#include <gdk/gdk.h> +#endif + #include "app/gfx/canvas.h" #include "skia/ext/skia_utils_win.h" #include "views/background.h" @@ -55,12 +59,15 @@ gfx::Size SingleSplitView::GetPreferredSize() { return gfx::Size(width, height); } -HCURSOR SingleSplitView::GetCursorForPoint(Event::EventType event_type, - int x, - int y) { +gfx::NativeCursor SingleSplitView::GetCursorForPoint(Event::EventType event_type, + int x, int y) { if (IsPointInDivider(x)) { +#if defined(OS_WIN) static HCURSOR resize_cursor = LoadCursor(NULL, IDC_SIZEWE); return resize_cursor; +#elif defined(OS_LINUX) + return gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW); +#endif } return NULL; } diff --git a/views/controls/single_split_view.h b/views/controls/single_split_view.h index a531800..9d25918 100644 --- a/views/controls/single_split_view.h +++ b/views/controls/single_split_view.h @@ -22,7 +22,7 @@ class SingleSplitView : public views::View { virtual gfx::Size GetPreferredSize(); // Overriden to return a resize cursor when over the divider. - virtual HCURSOR GetCursorForPoint(Event::EventType event_type, int x, int y); + virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type, int x, int y); void set_divider_x(int divider_x) { divider_x_ = divider_x; } int divider_x() { return divider_x_; } diff --git a/views/view.cc b/views/view.cc index b93c3c8..f817f1c 100644 --- a/views/view.cc +++ b/views/view.cc @@ -397,6 +397,11 @@ gfx::Insets View::GetInsets() const { return insets; } +gfx::NativeCursor View::GetCursorForPoint(Event::EventType event_type, int x, + int y) { + return NULL; +} + void View::SetContextMenuController(ContextMenuController* menu_controller) { context_menu_controller_ = menu_controller; } diff --git a/views/view.h b/views/view.h index 63fd56d..03291c6 100644 --- a/views/view.h +++ b/views/view.h @@ -12,6 +12,7 @@ #include <string> #include <vector> +#include "base/gfx/native_widget_types.h" #include "base/gfx/rect.h" #include "base/scoped_ptr.h" #include "views/accelerator.h" @@ -811,14 +812,15 @@ class View : public AcceleratorTarget { // insets is returned. virtual gfx::Insets GetInsets() const; -#if defined(OS_WIN) - // TODO(port): Make GetCursorForPoint portable. - // Return the cursor that should be used for this view or NULL if // the default cursor should be used. The provided point is in the - // receiver's coordinate system. - virtual HCURSOR GetCursorForPoint(Event::EventType event_type, int x, int y); -#endif // defined(OS_WIN) + // receiver's coordinate system. The caller is responsible for managing the + // lifetime of the returned object, though that lifetime may vary from + // platform to platform. On Windows, the cursor is a shared resource but in + // Gtk, the framework destroys the returned cursor after setting it. + virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type, + int x, + int y); // Convenience to test whether a point is within this view's bounds virtual bool HitTest(const gfx::Point& l) const; diff --git a/views/view_win.cc b/views/view_win.cc index 92a6396..cff8e53 100644 --- a/views/view_win.cc +++ b/views/view_win.cc @@ -66,10 +66,6 @@ bool View::HitTest(const gfx::Point& l) const { return false; } -HCURSOR View::GetCursorForPoint(Event::EventType event_type, int x, int y) { - return NULL; -} - void View::Focus() { // Set the native focus to the root view window so it receives the keyboard // messages. diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index fb64756..fd42412 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -467,29 +467,13 @@ void RootView::OnMouseMoved(const MouseEvent& e) { 0); mouse_move_handler_->OnMouseMoved(moved_event); -#if defined(OS_WIN) - HCURSOR cursor = mouse_move_handler_->GetCursorForPoint( + gfx::NativeCursor cursor = mouse_move_handler_->GetCursorForPoint( moved_event.GetType(), moved_event.x(), moved_event.y()); - if (cursor) { - previous_cursor_ = ::SetCursor(cursor); - } else if (previous_cursor_) { - ::SetCursor(previous_cursor_); - previous_cursor_ = NULL; - } -#else - NOTIMPLEMENTED(); -#endif + SetActiveCursor(cursor); } else if (mouse_move_handler_ != NULL) { MouseEvent exited_event(Event::ET_MOUSE_EXITED, 0, 0, 0); mouse_move_handler_->OnMouseExited(exited_event); -#if defined(OS_WIN) - if (previous_cursor_) { - ::SetCursor(previous_cursor_); - previous_cursor_ = NULL; - } -#else - NOTIMPLEMENTED(); -#endif + SetActiveCursor(NULL); } } @@ -922,4 +906,22 @@ View* RootView::GetDragView() { return drag_view_; } +void RootView::SetActiveCursor(gfx::NativeCursor cursor) { +#if defined(OS_WIN) + if (cursor) { + previous_cursor_ = ::SetCursor(cursor); + } else if (previous_cursor_) { + ::SetCursor(previous_cursor_); + previous_cursor_ = NULL; + } +#elif defined(OS_LINUX) + if (cursor) { + gdk_window_set_cursor(GetWidget()->GetNativeView()->window, cursor); + gdk_cursor_destroy(cursor); + } else { + gdk_window_set_cursor(GetWidget()->GetNativeView()->window, NULL); + } +#endif +} + } // namespace views diff --git a/views/widget/root_view.h b/views/widget/root_view.h index ae73eef..8f0df1f 100644 --- a/views/widget/root_view.h +++ b/views/widget/root_view.h @@ -269,6 +269,9 @@ class RootView : public View, // If a view is dragging, this returns it. Otherwise returns NULL. View* GetDragView(); + // Sets the current cursor, or resets it to the last one if NULL is provided. + void SetActiveCursor(gfx::NativeCursor cursor); + // The view currently handing down - drag - up View* mouse_pressed_handler_; @@ -299,10 +302,8 @@ class RootView : public View, // true if mouse_handler_ has been explicitly set bool explicit_mouse_handler_; -#if defined(OS_WIN) // Previous cursor - HCURSOR previous_cursor_; -#endif + gfx::NativeCursor previous_cursor_; // Default keyboard handler View* default_keyboard_handler_; |