summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-03 21:14:36 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-03 21:14:36 +0000
commitc78395583ae96c6ad4287cc1af8ec2ba1cd038c8 (patch)
tree7d3190a78c9c6b243ab5ea6a1c12090835edc3f4
parent741a46a76bd8f09547a3ea8967f380ccde31ae65 (diff)
downloadchromium_src-c78395583ae96c6ad4287cc1af8ec2ba1cd038c8.zip
chromium_src-c78395583ae96c6ad4287cc1af8ec2ba1cd038c8.tar.gz
chromium_src-c78395583ae96c6ad4287cc1af8ec2ba1cd038c8.tar.bz2
aura-x11: Add custom web cursor support.
BUG=102562 TEST=manually (using sites that use custom cursor, e.g.: http://beradrian.users.sourceforge.net/articles/cursor.html) Review URL: https://chromiumcodereview.appspot.com/9463003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130456 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/drag_drop/drag_drop_controller.cc6
-rw-r--r--ash/shell.cc10
-rw-r--r--ash/wm/panel_frame_view.cc6
-rw-r--r--ash/wm/panel_window_event_filter.cc2
-rw-r--r--ash/wm/partial_screenshot_view.cc4
-rw-r--r--ash/wm/root_window_event_filter.cc18
-rw-r--r--ash/wm/root_window_event_filter_unittest.cc26
-rw-r--r--ash/wm/toplevel_window_event_filter.cc4
-rw-r--r--chrome/browser/ui/views/content_setting_bubble_contents.cc4
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura.cc6
-rw-r--r--ui/aura/aura.gyp1
-rw-r--r--ui/aura/root_window.cc6
-rw-r--r--ui/aura/root_window.h2
-rw-r--r--ui/aura/root_window_host.h2
-rw-r--r--ui/aura/root_window_host_linux.cc108
-rw-r--r--ui/aura/root_window_host_win.cc96
-rw-r--r--ui/base/cursor/cursor.cc40
-rw-r--r--ui/base/cursor/cursor.h (renamed from ui/aura/cursor.h)75
-rw-r--r--ui/base/cursor/cursor_win.cc17
-rw-r--r--ui/base/cursor/cursor_x11.cc19
-rw-r--r--ui/base/x/x11_util.cc110
-rw-r--r--ui/base/x/x11_util.h16
-rw-r--r--ui/gfx/native_widget_types.h9
-rw-r--r--ui/ui.gyp10
-rw-r--r--ui/views/controls/link.cc6
-rw-r--r--ui/views/controls/resize_area.cc6
-rw-r--r--ui/views/controls/single_split_view.cc6
-rw-r--r--ui/views/controls/textfield/native_textfield_views.cc4
-rw-r--r--webkit/glue/webcursor.h9
-rw-r--r--webkit/glue/webcursor_aura.cc116
-rw-r--r--webkit/glue/webcursor_aurawin.cc35
-rw-r--r--webkit/glue/webcursor_aurax11.cc83
-rw-r--r--webkit/glue/webkit_glue.gypi7
33 files changed, 622 insertions, 247 deletions
diff --git a/ash/drag_drop/drag_drop_controller.cc b/ash/drag_drop/drag_drop_controller.cc
index 5510081..dd52f82 100644
--- a/ash/drag_drop/drag_drop_controller.cc
+++ b/ash/drag_drop/drag_drop_controller.cc
@@ -114,7 +114,7 @@ void DragDropController::DragUpdate(aura::Window* target,
drag_operation_);
int op = delegate->OnDragUpdated(e);
gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)?
- aura::kCursorMove : aura::kCursorHand;
+ ui::kCursorMove : ui::kCursorHand;
Shell::GetRootWindow()->SetCursor(cursor);
}
}
@@ -128,7 +128,7 @@ void DragDropController::DragUpdate(aura::Window* target,
void DragDropController::Drop(aura::Window* target,
const aura::LocatedEvent& event) {
- Shell::GetRootWindow()->SetCursor(aura::kCursorPointer);
+ Shell::GetRootWindow()->SetCursor(ui::kCursorPointer);
aura::client::DragDropDelegate* delegate = NULL;
// |drag_window_| can be NULL if we have just started the drag and have not
@@ -153,7 +153,7 @@ void DragDropController::Drop(aura::Window* target,
}
void DragDropController::DragCancel() {
- Shell::GetRootWindow()->SetCursor(aura::kCursorPointer);
+ Shell::GetRootWindow()->SetCursor(ui::kCursorPointer);
aura::client::DragDropDelegate* delegate = NULL;
if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) {
delegate->OnDragExited();
diff --git a/ash/shell.cc b/ash/shell.cc
index 21af31b..e06d5e1 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -15,8 +15,8 @@
#include "ash/focus_cycler.h"
#include "ash/ime/input_method_event_filter.h"
#include "ash/launcher/launcher.h"
-#include "ash/monitor/multi_monitor_manager.h"
#include "ash/monitor/monitor_controller.h"
+#include "ash/monitor/multi_monitor_manager.h"
#include "ash/screen_ash.h"
#include "ash/shell_delegate.h"
#include "ash/shell_factory.h"
@@ -31,8 +31,8 @@
#include "ash/system/power/power_supply_status.h"
#include "ash/system/power/tray_power.h"
#include "ash/system/settings/tray_settings.h"
-#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray.h"
+#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_empty.h"
#include "ash/system/tray_accessibility.h"
#include "ash/system/tray_caps_lock.h"
@@ -45,8 +45,8 @@
#include "ash/wm/dialog_frame_view.h"
#include "ash/wm/event_client_impl.h"
#include "ash/wm/key_rewriter_event_filter.h"
-#include "ash/wm/panel_window_event_filter.h"
#include "ash/wm/panel_layout_manager.h"
+#include "ash/wm/panel_window_event_filter.h"
#include "ash/wm/partial_screenshot_event_filter.h"
#include "ash/wm/power_button_controller.h"
#include "ash/wm/resize_shadow_controller.h"
@@ -64,10 +64,10 @@
#include "ash/wm/window_modality_controller.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace/always_on_top_layout_manager.h"
-#include "ash/wm/workspace_controller.h"
#include "ash/wm/workspace/workspace_event_filter.h"
#include "ash/wm/workspace/workspace_layout_manager.h"
#include "ash/wm/workspace/workspace_manager.h"
+#include "ash/wm/workspace_controller.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "grit/ui_resources.h"
@@ -647,7 +647,7 @@ void Shell::Init() {
input_method_filter_.reset(new internal::InputMethodEventFilter);
AddRootWindowEventFilter(input_method_filter_.get());
- root_window->SetCursor(aura::kCursorPointer);
+ root_window->SetCursor(ui::kCursorPointer);
if (initially_hide_cursor_)
root_window->ShowCursor(false);
diff --git a/ash/wm/panel_frame_view.cc b/ash/wm/panel_frame_view.cc
index 4ed23b5..dfbce25 100644
--- a/ash/wm/panel_frame_view.cc
+++ b/ash/wm/panel_frame_view.cc
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ash/wm/panel_frame_view.h"
#include "ash/wm/frame_painter.h"
+#include "ash/wm/panel_frame_view.h"
#include "grit/ui_resources.h"
#include "grit/ui_strings.h" // Accessibility names
#include "third_party/skia/include/core/SkPaint.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/aura/cursor.h"
#include "ui/base/animation/throb_animation.h"
+#include "ui/base/cursor/cursor.h"
#include "ui/base/hit_test.h"
+#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font.h"
diff --git a/ash/wm/panel_window_event_filter.cc b/ash/wm/panel_window_event_filter.cc
index 8eca9d4..c4bf829 100644
--- a/ash/wm/panel_window_event_filter.cc
+++ b/ash/wm/panel_window_event_filter.cc
@@ -7,11 +7,11 @@
#include "ash/wm/window_util.h"
#include "base/message_loop.h"
#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/cursor.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
+#include "ui/base/cursor/cursor.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/compositor/scoped_layer_animation_settings.h"
diff --git a/ash/wm/partial_screenshot_view.cc b/ash/wm/partial_screenshot_view.cc
index 9cb29df..42ae2503 100644
--- a/ash/wm/partial_screenshot_view.cc
+++ b/ash/wm/partial_screenshot_view.cc
@@ -8,9 +8,9 @@
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/partial_screenshot_event_filter.h"
-#include "ui/aura/cursor.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
+#include "ui/base/cursor/cursor.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/rect.h"
#include "ui/views/view.h"
@@ -71,7 +71,7 @@ void PartialScreenshotView::Cancel() {
gfx::NativeCursor PartialScreenshotView::GetCursor(
const views::MouseEvent& event) {
// Always use "crosshair" cursor.
- return aura::kCursorCross;
+ return ui::kCursorCross;
}
void PartialScreenshotView::OnPaint(gfx::Canvas* canvas) {
diff --git a/ash/wm/root_window_event_filter.cc b/ash/wm/root_window_event_filter.cc
index 4c52320..822dfe6 100644
--- a/ash/wm/root_window_event_filter.cc
+++ b/ash/wm/root_window_event_filter.cc
@@ -46,23 +46,23 @@ gfx::NativeCursor RootWindowEventFilter::CursorForWindowComponent(
int window_component) {
switch (window_component) {
case HTBOTTOM:
- return aura::kCursorSouthResize;
+ return ui::kCursorSouthResize;
case HTBOTTOMLEFT:
- return aura::kCursorSouthWestResize;
+ return ui::kCursorSouthWestResize;
case HTBOTTOMRIGHT:
- return aura::kCursorSouthEastResize;
+ return ui::kCursorSouthEastResize;
case HTLEFT:
- return aura::kCursorWestResize;
+ return ui::kCursorWestResize;
case HTRIGHT:
- return aura::kCursorEastResize;
+ return ui::kCursorEastResize;
case HTTOP:
- return aura::kCursorNorthResize;
+ return ui::kCursorNorthResize;
case HTTOPLEFT:
- return aura::kCursorNorthWestResize;
+ return ui::kCursorNorthWestResize;
case HTTOPRIGHT:
- return aura::kCursorNorthEastResize;
+ return ui::kCursorNorthEastResize;
default:
- return aura::kCursorNull;
+ return ui::kCursorNull;
}
}
diff --git a/ash/wm/root_window_event_filter_unittest.cc b/ash/wm/root_window_event_filter_unittest.cc
index 6266839..c2c3cda 100644
--- a/ash/wm/root_window_event_filter_unittest.cc
+++ b/ash/wm/root_window_event_filter_unittest.cc
@@ -13,7 +13,6 @@
#include "ash/wm/window_util.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/activation_delegate.h"
-#include "ui/aura/cursor.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/aura_test_base.h"
@@ -21,6 +20,7 @@
#include "ui/aura/test/test_event_filter.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
+#include "ui/base/cursor/cursor.h"
#include "ui/base/hit_test.h"
#include "ui/gfx/screen.h"
@@ -375,45 +375,49 @@ TEST_F(RootWindowEventFilterTest, MouseEventCursors) {
aura::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0);
// Cursor starts as a pointer (set during Shell::Init()).
- EXPECT_EQ(aura::kCursorPointer, root_window->last_cursor());
+ EXPECT_EQ(ui::kCursorPointer, root_window->last_cursor().native_type());
// Resize edges and corners show proper cursors.
window_delegate.set_hittest_code(HTBOTTOM);
root_window->DispatchMouseEvent(&move1);
- EXPECT_EQ(aura::kCursorSouthResize, root_window->last_cursor());
+ EXPECT_EQ(ui::kCursorSouthResize, root_window->last_cursor().native_type());
window_delegate.set_hittest_code(HTBOTTOMLEFT);
root_window->DispatchMouseEvent(&move2);
- EXPECT_EQ(aura::kCursorSouthWestResize, root_window->last_cursor());
+ EXPECT_EQ(ui::kCursorSouthWestResize,
+ root_window->last_cursor().native_type());
window_delegate.set_hittest_code(HTBOTTOMRIGHT);
root_window->DispatchMouseEvent(&move1);
- EXPECT_EQ(aura::kCursorSouthEastResize, root_window->last_cursor());
+ EXPECT_EQ(ui::kCursorSouthEastResize,
+ root_window->last_cursor().native_type());
window_delegate.set_hittest_code(HTLEFT);
root_window->DispatchMouseEvent(&move2);
- EXPECT_EQ(aura::kCursorWestResize, root_window->last_cursor());
+ EXPECT_EQ(ui::kCursorWestResize, root_window->last_cursor().native_type());
window_delegate.set_hittest_code(HTRIGHT);
root_window->DispatchMouseEvent(&move1);
- EXPECT_EQ(aura::kCursorEastResize, root_window->last_cursor());
+ EXPECT_EQ(ui::kCursorEastResize, root_window->last_cursor().native_type());
window_delegate.set_hittest_code(HTTOP);
root_window->DispatchMouseEvent(&move2);
- EXPECT_EQ(aura::kCursorNorthResize, root_window->last_cursor());
+ EXPECT_EQ(ui::kCursorNorthResize, root_window->last_cursor().native_type());
window_delegate.set_hittest_code(HTTOPLEFT);
root_window->DispatchMouseEvent(&move1);
- EXPECT_EQ(aura::kCursorNorthWestResize, root_window->last_cursor());
+ EXPECT_EQ(ui::kCursorNorthWestResize,
+ root_window->last_cursor().native_type());
window_delegate.set_hittest_code(HTTOPRIGHT);
root_window->DispatchMouseEvent(&move2);
- EXPECT_EQ(aura::kCursorNorthEastResize, root_window->last_cursor());
+ EXPECT_EQ(ui::kCursorNorthEastResize,
+ root_window->last_cursor().native_type());
// Client area uses null cursor.
window_delegate.set_hittest_code(HTCLIENT);
root_window->DispatchMouseEvent(&move1);
- EXPECT_EQ(aura::kCursorNull, root_window->last_cursor());
+ EXPECT_EQ(ui::kCursorNull, root_window->last_cursor().native_type());
}
#if defined(OS_MACOSX)
diff --git a/ash/wm/toplevel_window_event_filter.cc b/ash/wm/toplevel_window_event_filter.cc
index 3de5075..962698ff 100644
--- a/ash/wm/toplevel_window_event_filter.cc
+++ b/ash/wm/toplevel_window_event_filter.cc
@@ -12,12 +12,12 @@
#include "ash/wm/window_util.h"
#include "base/message_loop.h"
#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/cursor.h"
#include "ui/aura/env.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
+#include "ui/base/cursor/cursor.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/screen.h"
@@ -163,7 +163,7 @@ void ToplevelWindowEventFilter::RunMoveLoop(aura::Window* source) {
root_window, source->parent(), &parent_mouse_location);
window_resizer_.reset(
CreateWindowResizer(source, parent_mouse_location, HTCAPTION));
- source->GetRootWindow()->SetCursor(aura::kCursorPointer);
+ source->GetRootWindow()->SetCursor(ui::kCursorPointer);
#if !defined(OS_MACOSX)
MessageLoopForUI* loop = MessageLoopForUI::current();
MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
diff --git a/chrome/browser/ui/views/content_setting_bubble_contents.cc b/chrome/browser/ui/views/content_setting_bubble_contents.cc
index 4817b2f..57e496a 100644
--- a/chrome/browser/ui/views/content_setting_bubble_contents.cc
+++ b/chrome/browser/ui/views/content_setting_bubble_contents.cc
@@ -29,7 +29,7 @@
#include "ui/views/layout/layout_constants.h"
#if defined(USE_AURA)
-#include "ui/aura/cursor.h"
+#include "ui/base/cursor/cursor.h"
#endif
// If we don't clamp the maximum width, then very long URLs and titles can make
@@ -88,7 +88,7 @@ void ContentSettingBubbleContents::Favicon::OnMouseReleased(
gfx::NativeCursor ContentSettingBubbleContents::Favicon::GetCursor(
const views::MouseEvent& event) {
#if defined(USE_AURA)
- return aura::kCursorHand;
+ return ui::kCursorHand;
#elif defined(OS_WIN)
static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND);
return g_hand_cursor;
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
index d851114..8962d028 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
@@ -921,7 +921,7 @@ bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) {
gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
if (mouse_locked_)
- return aura::kCursorNone;
+ return ui::kCursorNone;
return current_cursor_.GetNativeCursor();
}
@@ -1130,8 +1130,8 @@ void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() {
return;
gfx::NativeCursor cursor = current_cursor_.GetNativeCursor();
- if (is_loading_ && cursor == aura::kCursorPointer)
- cursor = aura::kCursorProgress;
+ if (is_loading_ && cursor == ui::kCursorPointer)
+ cursor = ui::kCursorProgress;
root_window->SetCursor(cursor);
}
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index b862a70..0c6d218 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -49,7 +49,6 @@
'client/window_move_client.cc',
'client/window_move_client.h',
'client/window_types.h',
- 'cursor.h',
'desktop/desktop_activation_client.cc',
'desktop/desktop_activation_client.h',
'desktop/desktop_dispatcher_client.cc',
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 3657af3..99e1ad0 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -15,14 +15,14 @@
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/event_client.h"
#include "ui/aura/env.h"
-#include "ui/aura/root_window_host.h"
-#include "ui/aura/root_window_observer.h"
#include "ui/aura/event.h"
#include "ui/aura/event_filter.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/gestures/gesture_recognizer.h"
#include "ui/aura/monitor.h"
#include "ui/aura/monitor_manager.h"
+#include "ui/aura/root_window_host.h"
+#include "ui/aura/root_window_observer.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/hit_test.h"
@@ -89,7 +89,7 @@ RootWindow::RootWindow(const gfx::Rect& initial_bounds)
ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)),
mouse_button_flags_(0),
- last_cursor_(kCursorNull),
+ last_cursor_(ui::kCursorNull),
cursor_shown_(true),
capture_window_(NULL),
mouse_pressed_handler_(NULL),
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 4cb605d..896af44 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -12,10 +12,10 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "ui/aura/aura_export.h"
-#include "ui/aura/cursor.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/gestures/gesture_recognizer.h"
#include "ui/aura/window.h"
+#include "ui/base/cursor/cursor.h"
#include "ui/base/events.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/compositor_observer.h"
diff --git a/ui/aura/root_window_host.h b/ui/aura/root_window_host.h
index 4ab1830..5c089fb 100644
--- a/ui/aura/root_window_host.h
+++ b/ui/aura/root_window_host.h
@@ -7,7 +7,7 @@
#pragma once
#include "base/message_loop.h"
-#include "ui/aura/cursor.h"
+#include "ui/base/cursor/cursor.h"
#include "ui/gfx/native_widget_types.h"
namespace gfx {
diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc
index 9c0d898..cd2597b 100644
--- a/ui/aura/root_window_host_linux.cc
+++ b/ui/aura/root_window_host_linux.cc
@@ -13,13 +13,13 @@
#include "base/message_pump_x.h"
#include "base/stl_util.h"
#include "base/stringprintf.h"
-#include "ui/aura/cursor.h"
#include "ui/aura/dispatcher_linux.h"
#include "ui/aura/env.h"
#include "ui/aura/event.h"
#include "ui/aura/monitor.h"
#include "ui/aura/monitor_manager.h"
#include "ui/aura/root_window.h"
+#include "ui/base/cursor/cursor.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/touch/touch_factory.h"
#include "ui/base/x/x11_util.h"
@@ -83,85 +83,87 @@ void CheckXEventForConsistency(XEvent* xevent) {
// Returns X font cursor shape from an Aura cursor.
int CursorShapeFromNative(gfx::NativeCursor native_cursor) {
- switch (native_cursor) {
- case aura::kCursorNull:
+ switch (native_cursor.native_type()) {
+ case ui::kCursorNull:
return XC_left_ptr;
- case aura::kCursorPointer:
+ case ui::kCursorPointer:
return XC_left_ptr;
- case aura::kCursorCross:
+ case ui::kCursorCross:
return XC_crosshair;
- case aura::kCursorHand:
+ case ui::kCursorHand:
return XC_hand2;
- case aura::kCursorIBeam:
+ case ui::kCursorIBeam:
return XC_xterm;
- case aura::kCursorWait:
+ case ui::kCursorWait:
return XC_watch;
- case aura::kCursorHelp:
+ case ui::kCursorHelp:
return XC_question_arrow;
- case aura::kCursorEastResize:
+ case ui::kCursorEastResize:
return XC_right_side;
- case aura::kCursorNorthResize:
+ case ui::kCursorNorthResize:
return XC_top_side;
- case aura::kCursorNorthEastResize:
+ case ui::kCursorNorthEastResize:
return XC_top_right_corner;
- case aura::kCursorNorthWestResize:
+ case ui::kCursorNorthWestResize:
return XC_top_left_corner;
- case aura::kCursorSouthResize:
+ case ui::kCursorSouthResize:
return XC_bottom_side;
- case aura::kCursorSouthEastResize:
+ case ui::kCursorSouthEastResize:
return XC_bottom_right_corner;
- case aura::kCursorSouthWestResize:
+ case ui::kCursorSouthWestResize:
return XC_bottom_left_corner;
- case aura::kCursorWestResize:
+ case ui::kCursorWestResize:
return XC_left_side;
- case aura::kCursorNorthSouthResize:
+ case ui::kCursorNorthSouthResize:
return XC_sb_v_double_arrow;
- case aura::kCursorEastWestResize:
+ case ui::kCursorEastWestResize:
return XC_sb_h_double_arrow;
- case aura::kCursorNorthEastSouthWestResize:
- case aura::kCursorNorthWestSouthEastResize:
+ case ui::kCursorNorthEastSouthWestResize:
+ case ui::kCursorNorthWestSouthEastResize:
// There isn't really a useful cursor available for these.
return XC_left_ptr;
- case aura::kCursorColumnResize:
+ case ui::kCursorColumnResize:
return XC_sb_h_double_arrow;
- case aura::kCursorRowResize:
+ case ui::kCursorRowResize:
return XC_sb_v_double_arrow;
- case aura::kCursorMiddlePanning:
+ case ui::kCursorMiddlePanning:
return XC_fleur;
- case aura::kCursorEastPanning:
+ case ui::kCursorEastPanning:
return XC_sb_right_arrow;
- case aura::kCursorNorthPanning:
+ case ui::kCursorNorthPanning:
return XC_sb_up_arrow;
- case aura::kCursorNorthEastPanning:
+ case ui::kCursorNorthEastPanning:
return XC_top_right_corner;
- case aura::kCursorNorthWestPanning:
+ case ui::kCursorNorthWestPanning:
return XC_top_left_corner;
- case aura::kCursorSouthPanning:
+ case ui::kCursorSouthPanning:
return XC_sb_down_arrow;
- case aura::kCursorSouthEastPanning:
+ case ui::kCursorSouthEastPanning:
return XC_bottom_right_corner;
- case aura::kCursorSouthWestPanning:
+ case ui::kCursorSouthWestPanning:
return XC_bottom_left_corner;
- case aura::kCursorWestPanning:
+ case ui::kCursorWestPanning:
return XC_sb_left_arrow;
- case aura::kCursorMove:
+ case ui::kCursorMove:
return XC_fleur;
- case aura::kCursorVerticalText:
- case aura::kCursorCell:
- case aura::kCursorContextMenu:
- case aura::kCursorAlias:
- case aura::kCursorProgress:
- case aura::kCursorNoDrop:
- case aura::kCursorCopy:
- case aura::kCursorNone:
- case aura::kCursorNotAllowed:
- case aura::kCursorZoomIn:
- case aura::kCursorZoomOut:
- case aura::kCursorGrab:
- case aura::kCursorGrabbing:
- case aura::kCursorCustom:
+ case ui::kCursorVerticalText:
+ case ui::kCursorCell:
+ case ui::kCursorContextMenu:
+ case ui::kCursorAlias:
+ case ui::kCursorProgress:
+ case ui::kCursorNoDrop:
+ case ui::kCursorCopy:
+ case ui::kCursorNone:
+ case ui::kCursorNotAllowed:
+ case ui::kCursorZoomIn:
+ case ui::kCursorZoomOut:
+ case ui::kCursorGrab:
+ case ui::kCursorGrabbing:
// TODO(jamescook): Need cursors for these. crbug.com/111650
return XC_left_ptr;
+ case ui::kCursorCustom:
+ NOTREACHED();
+ return XC_left_ptr;
}
NOTREACHED();
return XC_left_ptr;
@@ -279,7 +281,7 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
xdisplay_(base::MessagePumpX::GetDefaultXDisplay()),
xwindow_(0),
x_root_window_(DefaultRootWindow(xdisplay_)),
- current_cursor_(aura::kCursorNull),
+ current_cursor_(ui::kCursorNull),
cursor_shown_(true),
bounds_(bounds),
focus_when_shown_(false),
@@ -563,10 +565,6 @@ void RootWindowHostLinux::SetCursor(gfx::NativeCursor cursor) {
return;
current_cursor_ = cursor;
- // Custom web cursors are handled directly.
- if (cursor == kCursorCustom)
- return;
-
if (cursor_shown_)
SetCursorInternal(cursor);
}
@@ -575,7 +573,7 @@ void RootWindowHostLinux::ShowCursor(bool show) {
if (show == cursor_shown_)
return;
cursor_shown_ = show;
- SetCursorInternal(show ? current_cursor_ : kCursorNone);
+ SetCursorInternal(show ? current_cursor_ : ui::kCursorNone);
}
gfx::Point RootWindowHostLinux::QueryMouseLocation() {
@@ -698,8 +696,10 @@ bool RootWindowHostLinux::IsWindowManagerPresent() {
void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) {
::Cursor xcursor =
- cursor == kCursorNone ?
+ cursor == ui::kCursorNone ?
invisible_cursor_ :
+ cursor == ui::kCursorCustom ?
+ cursor.platform() :
ui::GetXCursor(CursorShapeFromNative(cursor));
XDefineCursor(xdisplay_, xwindow_, xcursor);
}
diff --git a/ui/aura/root_window_host_win.cc b/ui/aura/root_window_host_win.cc
index 2e90ba4..a5176fc 100644
--- a/ui/aura/root_window_host_win.cc
+++ b/ui/aura/root_window_host_win.cc
@@ -9,9 +9,9 @@
#include <algorithm>
#include "base/message_loop.h"
-#include "ui/aura/root_window.h"
#include "ui/aura/env.h"
#include "ui/aura/event.h"
+#include "ui/aura/root_window.h"
using std::max;
using std::min;
@@ -21,75 +21,75 @@ namespace aura {
namespace {
const wchar_t* GetCursorId(gfx::NativeCursor native_cursor) {
- switch (native_cursor) {
- case kCursorNull:
+ switch (native_cursor.native_type()) {
+ case ui::kCursorNull:
return IDC_ARROW;
- case kCursorPointer:
+ case ui::kCursorPointer:
return IDC_ARROW;
- case kCursorCross:
+ case ui::kCursorCross:
return IDC_CROSS;
- case kCursorHand:
+ case ui::kCursorHand:
return IDC_HAND;
- case kCursorIBeam:
+ case ui::kCursorIBeam:
return IDC_IBEAM;
- case kCursorWait:
+ case ui::kCursorWait:
return IDC_WAIT;
- case kCursorHelp:
+ case ui::kCursorHelp:
return IDC_HELP;
- case kCursorEastResize:
+ case ui::kCursorEastResize:
return IDC_SIZEWE;
- case kCursorNorthResize:
+ case ui::kCursorNorthResize:
return IDC_SIZENS;
- case kCursorNorthEastResize:
+ case ui::kCursorNorthEastResize:
return IDC_SIZENESW;
- case kCursorNorthWestResize:
+ case ui::kCursorNorthWestResize:
return IDC_SIZENWSE;
- case kCursorSouthResize:
+ case ui::kCursorSouthResize:
return IDC_SIZENS;
- case kCursorSouthEastResize:
+ case ui::kCursorSouthEastResize:
return IDC_SIZENWSE;
- case kCursorSouthWestResize:
+ case ui::kCursorSouthWestResize:
return IDC_SIZENESW;
- case kCursorWestResize:
+ case ui::kCursorWestResize:
return IDC_SIZEWE;
- case kCursorNorthSouthResize:
+ case ui::kCursorNorthSouthResize:
return IDC_SIZENS;
- case kCursorEastWestResize:
+ case ui::kCursorEastWestResize:
return IDC_SIZEWE;
- case kCursorNorthEastSouthWestResize:
+ case ui::kCursorNorthEastSouthWestResize:
return IDC_SIZENESW;
- case kCursorNorthWestSouthEastResize:
+ case ui::kCursorNorthWestSouthEastResize:
return IDC_SIZENWSE;
- case kCursorMove:
+ case ui::kCursorMove:
return IDC_SIZEALL;
- case kCursorProgress:
+ case ui::kCursorProgress:
return IDC_APPSTARTING;
- case kCursorNoDrop:
+ case ui::kCursorNoDrop:
return IDC_NO;
- case kCursorNotAllowed:
+ case ui::kCursorNotAllowed:
return IDC_NO;
- case kCursorColumnResize:
- case kCursorRowResize:
- case kCursorMiddlePanning:
- case kCursorEastPanning:
- case kCursorNorthPanning:
- case kCursorNorthEastPanning:
- case kCursorNorthWestPanning:
- case kCursorSouthPanning:
- case kCursorSouthEastPanning:
- case kCursorSouthWestPanning:
- case kCursorWestPanning:
- case kCursorVerticalText:
- case kCursorCell:
- case kCursorContextMenu:
- case kCursorAlias:
- case kCursorCopy:
- case kCursorNone:
- case kCursorZoomIn:
- case kCursorZoomOut:
- case kCursorGrab:
- case kCursorGrabbing:
- case kCursorCustom:
+ case ui::kCursorColumnResize:
+ case ui::kCursorRowResize:
+ case ui::kCursorMiddlePanning:
+ case ui::kCursorEastPanning:
+ case ui::kCursorNorthPanning:
+ case ui::kCursorNorthEastPanning:
+ case ui::kCursorNorthWestPanning:
+ case ui::kCursorSouthPanning:
+ case ui::kCursorSouthEastPanning:
+ case ui::kCursorSouthWestPanning:
+ case ui::kCursorWestPanning:
+ case ui::kCursorVerticalText:
+ case ui::kCursorCell:
+ case ui::kCursorContextMenu:
+ case ui::kCursorAlias:
+ case ui::kCursorCopy:
+ case ui::kCursorNone:
+ case ui::kCursorZoomIn:
+ case ui::kCursorZoomOut:
+ case ui::kCursorGrab:
+ case ui::kCursorGrabbing:
+ case ui::kCursorCustom:
// TODO(jamescook): Should we use WebKit glue resources for these?
// Or migrate those resources to someplace ui/aura can share?
NOTIMPLEMENTED();
@@ -211,7 +211,7 @@ gfx::Point RootWindowHostWin::GetLocationOnNativeScreen() const {
void RootWindowHostWin::SetCursor(gfx::NativeCursor native_cursor) {
// Custom web cursors are handled directly.
- if (native_cursor == kCursorCustom)
+ if (native_cursor == ui::kCursorCustom)
return;
const wchar_t* cursor_id = GetCursorId(native_cursor);
// TODO(jamescook): Support for non-system cursors will require finding
diff --git a/ui/base/cursor/cursor.cc b/ui/base/cursor/cursor.cc
new file mode 100644
index 0000000..b9f66fe
--- /dev/null
+++ b/ui/base/cursor/cursor.cc
@@ -0,0 +1,40 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/cursor/cursor.h"
+
+namespace ui {
+
+Cursor::Cursor()
+ : native_type_(0),
+ platform_cursor_(0) {
+}
+
+Cursor::Cursor(int type)
+ : native_type_(type),
+ platform_cursor_(0) {
+}
+
+Cursor::Cursor(const Cursor& cursor)
+ : native_type_(cursor.native_type_),
+ platform_cursor_(cursor.platform_cursor_) {
+ if (native_type_ == kCursorCustom)
+ RefCustomCursor();
+}
+
+Cursor::~Cursor() {
+ if (native_type_ == kCursorCustom)
+ UnrefCustomCursor();
+}
+
+void Cursor::SetPlatformCursor(const PlatformCursor& platform) {
+ if (platform_cursor_)
+ UnrefCustomCursor();
+ native_type_ = kCursorCustom;
+ platform_cursor_ = platform;
+ RefCustomCursor();
+}
+
+
+} // namespace ui
diff --git a/ui/aura/cursor.h b/ui/base/cursor/cursor.h
index 33664e8..09076e9 100644
--- a/ui/aura/cursor.h
+++ b/ui/base/cursor/cursor.h
@@ -1,12 +1,34 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef UI_AURA_CURSOR_H_
-#define UI_AURA_CURSOR_H_
+#ifndef UI_BASE_CURSOR_CURSOR_H_
+#define UI_BASE_CURSOR_CURSOR_H_
#pragma once
-namespace aura {
+#include "build/build_config.h"
+#include "ui/base/ui_export.h"
+
+namespace gfx {
+class Point;
+class Size;
+}
+
+#if defined(OS_WIN)
+typedef struct HINSTANCE__* HINSTANCE;
+typedef struct HICON__* HICON;
+typedef HICON HCURSOR;
+#endif
+
+namespace ui {
+
+#if defined(OS_WIN)
+typedef ::HCURSOR PlatformCursor;
+#elif defined(USE_X11)
+typedef unsigned long PlatformCursor;
+#else
+typedef void* PlatformCursor;
+#endif
// TODO(jamescook): Once we're on C++0x we could change these constants
// to an enum and forward declare it in native_widget_types.h.
@@ -14,7 +36,7 @@ namespace aura {
// Equivalent to a NULL HCURSOR on Windows.
const int kCursorNull = 0;
-// Aura cursors mirror WebKit cursors from WebCursorInfo, but are replicated
+// These cursors mirror WebKit cursors from WebCursorInfo, but are replicated
// here so we don't introduce a WebKit dependency.
const int kCursorPointer = 1;
const int kCursorCross = 2;
@@ -61,6 +83,45 @@ const int kCursorGrab = 42;
const int kCursorGrabbing = 43;
const int kCursorCustom = 44;
-} // namespace aura
+// Ref-counted cursor that supports both default and custom cursors.
+class UI_EXPORT Cursor {
+ public:
+ Cursor();
+
+ // Implicit constructor.
+ Cursor(int type);
+
+ // Allow copy.
+ Cursor(const Cursor& cursor);
+
+ ~Cursor();
+
+ void SetPlatformCursor(const PlatformCursor& platform);
+
+ void RefCustomCursor();
+ void UnrefCustomCursor();
+
+ int native_type() const { return native_type_; }
+ PlatformCursor platform() const { return platform_cursor_; }
+
+ bool operator==(int type) const { return native_type_ == type; }
+ bool operator==(const Cursor& cursor) const {
+ return native_type_ == cursor.native_type_ &&
+ platform_cursor_ == cursor.platform_cursor_;
+ }
+ bool operator!=(int type) const { return native_type_ != type; }
+ bool operator!=(const Cursor& cursor) const {
+ return native_type_ != cursor.native_type_ ||
+ platform_cursor_ != cursor.platform_cursor_;
+ }
+
+ private:
+ // See definitions above.
+ int native_type_;
+
+ PlatformCursor platform_cursor_;
+};
+
+} // namespace ui
-#endif // UI_AURA_CURSOR_H_
+#endif // UI_BASE_CURSOR_CURSOR_H_
diff --git a/ui/base/cursor/cursor_win.cc b/ui/base/cursor/cursor_win.cc
new file mode 100644
index 0000000..2d4aafea
--- /dev/null
+++ b/ui/base/cursor/cursor_win.cc
@@ -0,0 +1,17 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/cursor/cursor.h"
+
+namespace ui {
+
+void Cursor::RefCustomCursor() {
+ // TODO(winguru):
+}
+
+void Cursor::UnrefCustomCursor() {
+ // TODO(winguru):
+}
+
+} // namespace ui
diff --git a/ui/base/cursor/cursor_x11.cc b/ui/base/cursor/cursor_x11.cc
new file mode 100644
index 0000000..b74d03c
--- /dev/null
+++ b/ui/base/cursor/cursor_x11.cc
@@ -0,0 +1,19 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/cursor/cursor.h"
+
+#include "ui/base/x/x11_util.h"
+
+namespace ui {
+
+void Cursor::RefCustomCursor() {
+ ui::RefCustomXCursor(platform_cursor_);
+}
+
+void Cursor::UnrefCustomCursor() {
+ ui::UnrefCustomXCursor(platform_cursor_);
+}
+
+} // namespace ui
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
index 2883448..01d55c5 100644
--- a/ui/base/x/x11_util.cc
+++ b/ui/base/x/x11_util.cc
@@ -31,16 +31,20 @@
#include "ui/gfx/size.h"
#if defined(OS_FREEBSD)
-#include <sys/types.h>
#include <sys/sysctl.h>
+#include <sys/types.h>
+#endif
+
+#if defined(USE_AURA)
+#include <X11/Xcursor/Xcursor.h>
#endif
#if defined(TOOLKIT_USES_GTK)
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
-#include "ui/base/gtk/gtk_compat.h"
#include "ui/base/gtk/gdk_x_compat.h"
+#include "ui/base/gtk/gtk_compat.h"
#else
// TODO(sad): Use the new way of handling X errors when
// http://codereview.chromium.org/7889040/ lands.
@@ -160,10 +164,10 @@ class XCursorCache {
Clear();
}
- Cursor GetCursor(int cursor_shape) {
+ ::Cursor GetCursor(int cursor_shape) {
// Lookup cursor by attempting to insert a null value, which avoids
// a second pass through the map after a cache miss.
- std::pair<std::map<int, Cursor>::iterator, bool> it = cache_.insert(
+ std::pair<std::map<int, ::Cursor>::iterator, bool> it = cache_.insert(
std::make_pair(cursor_shape, 0));
if (it.second) {
Display* display = base::MessagePumpForUI::GetDefaultXDisplay();
@@ -174,7 +178,7 @@ class XCursorCache {
void Clear() {
Display* display = base::MessagePumpForUI::GetDefaultXDisplay();
- for (std::map<int, Cursor>::iterator it =
+ for (std::map<int, ::Cursor>::iterator it =
cache_.begin(); it != cache_.end(); ++it) {
XFreeCursor(display, it->second);
}
@@ -183,11 +187,89 @@ class XCursorCache {
private:
// Maps X11 font cursor shapes to Cursor IDs.
- std::map<int, Cursor> cache_;
+ std::map<int, ::Cursor> cache_;
DISALLOW_COPY_AND_ASSIGN(XCursorCache);
};
+#if defined(USE_AURA)
+// A process wide singleton cache for custom X cursors.
+class XCustomCursorCache {
+ public:
+ static XCustomCursorCache* GetInstance() {
+ return Singleton<XCustomCursorCache>::get();
+ }
+
+ ::Cursor InstallCustomCursor(XcursorImage* image) {
+ XCustomCursor* custom_cursor = new XCustomCursor(image);
+ ::Cursor xcursor = custom_cursor->cursor();
+ cache_[xcursor] = custom_cursor;
+ return xcursor;
+ }
+
+ void Ref(::Cursor cursor) {
+ cache_[cursor]->Ref();
+ }
+
+ void Unref(::Cursor cursor) {
+ if (cache_[cursor]->Unref())
+ cache_.erase(cursor);
+ }
+
+ void Clear() {
+ cache_.clear();
+ }
+
+ private:
+ friend struct DefaultSingletonTraits<XCustomCursorCache>;
+
+ class XCustomCursor {
+ public:
+ // This takes ownership of the image.
+ XCustomCursor(XcursorImage* image)
+ : image_(image),
+ ref_(1) {
+ cursor_ = XcursorImageLoadCursor(GetXDisplay(), image);
+ }
+
+ ~XCustomCursor() {
+ XcursorImageDestroy(image_);
+ XFreeCursor(GetXDisplay(), cursor_);
+ }
+
+ ::Cursor cursor() const { return cursor_; }
+
+ void Ref() {
+ ++ref_;
+ }
+
+ // Returns true if the cursor was destroyed because of the unref.
+ bool Unref() {
+ if (--ref_ == 0) {
+ delete this;
+ return true;
+ }
+ return false;
+ }
+
+ private:
+ XcursorImage* image_;
+ int ref_;
+ ::Cursor cursor_;
+
+ DISALLOW_COPY_AND_ASSIGN(XCustomCursor);
+ };
+
+ XCustomCursorCache() {}
+ ~XCustomCursorCache() {
+ Clear();
+ }
+
+ std::map< ::Cursor, XCustomCursor*> cache_;
+ DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache);
+};
+#endif // defined(USE_AURA)
+
// A singleton object that remembers remappings of mouse buttons.
class XButtonMap {
public:
@@ -306,7 +388,7 @@ int GetDefaultScreen(Display* display) {
return XDefaultScreen(display);
}
-Cursor GetXCursor(int cursor_shape) {
+::Cursor GetXCursor(int cursor_shape) {
CR_DEFINE_STATIC_LOCAL(XCursorCache, cache, ());
if (cursor_shape == kCursorClearXCursorCache) {
@@ -317,6 +399,20 @@ Cursor GetXCursor(int cursor_shape) {
return cache.GetCursor(cursor_shape);
}
+#if defined(USE_AURA)
+::Cursor CreateReffedCustomXCursor(XcursorImage* image) {
+ return XCustomCursorCache::GetInstance()->InstallCustomCursor(image);
+}
+
+void RefCustomXCursor(::Cursor cursor) {
+ XCustomCursorCache::GetInstance()->Ref(cursor);
+}
+
+void UnrefCustomXCursor(::Cursor cursor) {
+ XCustomCursorCache::GetInstance()->Unref(cursor);
+}
+#endif
+
XID GetX11RootWindow() {
return DefaultRootWindow(GetXDisplay());
}
diff --git a/ui/base/x/x11_util.h b/ui/base/x/x11_util.h
index 86955bf..64e7d64 100644
--- a/ui/base/x/x11_util.h
+++ b/ui/base/x/x11_util.h
@@ -24,6 +24,7 @@ typedef unsigned long XID;
typedef unsigned long XSharedMemoryId; // ShmSeg in the X headers.
typedef struct _XDisplay Display;
typedef unsigned long Cursor;
+typedef struct _XcursorImage XcursorImage;
#if defined(TOOLKIT_USES_GTK)
typedef struct _GdkDrawable GdkWindow;
@@ -75,7 +76,20 @@ const int kCursorClearXCursorCache = -1;
// Returns an X11 Cursor, sharable across the process.
// |cursor_shape| is an X font cursor shape, see XCreateFontCursor().
-UI_EXPORT Cursor GetXCursor(int cursor_shape);
+UI_EXPORT ::Cursor GetXCursor(int cursor_shape);
+
+#if defined(USE_AURA)
+// Creates a custom X cursor from the image. This takes ownership of image. The
+// caller must not free/modify the image. The refcount of the newly created
+// cursor is set to 1.
+UI_EXPORT ::Cursor CreateReffedCustomXCursor(XcursorImage* image);
+
+// Increases the refcount of the custom cursor.
+UI_EXPORT void RefCustomXCursor(::Cursor cursor);
+
+// Decreases the refcount of the custom cursor, and destroys it if it reaches 0.
+UI_EXPORT void UnrefCustomXCursor(::Cursor cursor);
+#endif
// These functions do not cache their results --------------------------
diff --git a/ui/gfx/native_widget_types.h b/ui/gfx/native_widget_types.h
index 1b39ea0..7d25743 100644
--- a/ui/gfx/native_widget_types.h
+++ b/ui/gfx/native_widget_types.h
@@ -43,6 +43,8 @@
// 'views'.
#if defined(USE_AURA)
+#include "ui/base/cursor/cursor.h"
+
class SkRegion;
namespace aura {
class Event;
@@ -102,8 +104,7 @@ class SkBitmap;
namespace gfx {
#if defined(USE_AURA)
-// See ui/aura/cursor.h for values.
-typedef int NativeCursor;
+typedef ui::Cursor NativeCursor;
typedef aura::Window* NativeView;
typedef aura::Window* NativeWindow;
typedef SkRegion* NativeRegion;
@@ -180,7 +181,11 @@ typedef void* NativeViewAccessible;
#endif
// A constant value to indicate that gfx::NativeCursor refers to no cursor.
+#if defined(USE_AURA)
+const int kNullCursor = 0;
+#else
const gfx::NativeCursor kNullCursor = static_cast<gfx::NativeCursor>(NULL);
+#endif
#if defined(OS_MACOSX)
typedef NSImage NativeImageType;
diff --git a/ui/ui.gyp b/ui/ui.gyp
index e8abe9ec..5afa51a 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -99,6 +99,10 @@
'base/cocoa/fullscreen_window_manager.mm',
'base/cocoa/underlay_opengl_hosting_window.h',
'base/cocoa/underlay_opengl_hosting_window.mm',
+ 'base/cursor/cursor.cc',
+ 'base/cursor/cursor.h',
+ 'base/cursor/cursor_win.cc',
+ 'base/cursor/cursor_x11.cc',
'base/dragdrop/cocoa_dnd_util.h',
'base/dragdrop/cocoa_dnd_util.mm',
'base/dragdrop/drag_drop_types_gtk.cc',
@@ -417,6 +421,10 @@
'sources!': [
'gfx/native_theme_aura.cc',
'gfx/native_theme_aura.h',
+ 'base/cursor/cursor.cc',
+ 'base/cursor/cursor.h',
+ 'base/cursor/cursor_win.cc',
+ 'base/cursor/cursor_x11.cc',
]
}],
['use_aura==1 and OS=="win"', {
@@ -604,7 +612,7 @@
],
'link_settings': {
'libraries': [
- '-lX11',
+ '-lX11 -lXcursor',
],
},
},
diff --git a/ui/views/controls/link.cc b/ui/views/controls/link.cc
index 49a9d838..20c17d8 100644
--- a/ui/views/controls/link.cc
+++ b/ui/views/controls/link.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,7 +16,7 @@
#include "ui/views/events/event.h"
#if defined(USE_AURA)
-#include "ui/aura/cursor.h"
+#include "ui/base/cursor/cursor.h"
#endif
namespace views {
@@ -47,7 +47,7 @@ gfx::NativeCursor Link::GetCursor(const MouseEvent& event) {
if (!enabled())
return gfx::kNullCursor;
#if defined(USE_AURA)
- return aura::kCursorHand;
+ return ui::kCursorHand;
#elif defined(OS_WIN)
static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND);
return g_hand_cursor;
diff --git a/ui/views/controls/resize_area.cc b/ui/views/controls/resize_area.cc
index c19361c..fe4bc60 100644
--- a/ui/views/controls/resize_area.cc
+++ b/ui/views/controls/resize_area.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,7 +10,7 @@
#include "ui/views/controls/resize_area_delegate.h"
#if defined(USE_AURA)
-#include "ui/aura/cursor.h"
+#include "ui/base/cursor/cursor.h"
#endif
namespace views {
@@ -36,7 +36,7 @@ gfx::NativeCursor ResizeArea::GetCursor(const MouseEvent& event) {
if (!enabled())
return gfx::kNullCursor;
#if defined(USE_AURA)
- return aura::kCursorEastWestResize;
+ return ui::kCursorEastWestResize;
#elif defined(OS_WIN)
static HCURSOR g_resize_cursor = LoadCursor(NULL, IDC_SIZEWE);
return g_resize_cursor;
diff --git a/ui/views/controls/single_split_view.cc b/ui/views/controls/single_split_view.cc
index 3b4453d..7744aa6 100644
--- a/ui/views/controls/single_split_view.cc
+++ b/ui/views/controls/single_split_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,7 +11,7 @@
#include "ui/views/controls/single_split_view_listener.h"
#if defined(USE_AURA)
-#include "ui/aura/cursor.h"
+#include "ui/base/cursor/cursor.h"
#endif
namespace views {
@@ -95,7 +95,7 @@ gfx::NativeCursor SingleSplitView::GetCursor(const MouseEvent& event) {
return gfx::kNullCursor;
#if defined(USE_AURA)
return is_horizontal_ ?
- aura::kCursorEastWestResize : aura::kCursorNorthSouthResize;
+ ui::kCursorEastWestResize : ui::kCursorNorthSouthResize;
#elif defined(OS_WIN)
static HCURSOR we_resize_cursor = LoadCursor(NULL, IDC_SIZEWE);
static HCURSOR ns_resize_cursor = LoadCursor(NULL, IDC_SIZENS);
diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc
index 298b9ff..299d5a7 100644
--- a/ui/views/controls/textfield/native_textfield_views.cc
+++ b/ui/views/controls/textfield/native_textfield_views.cc
@@ -39,7 +39,7 @@
#include "ui/views/widget/widget.h"
#if defined(USE_AURA)
-#include "ui/aura/cursor.h"
+#include "ui/base/cursor/cursor.h"
#endif
namespace {
@@ -265,7 +265,7 @@ gfx::NativeCursor NativeTextfieldViews::GetCursor(const MouseEvent& event) {
bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED;
bool text_cursor = !initiating_drag_ && (drag_event || !in_selection);
#if defined(USE_AURA)
- return text_cursor ? aura::kCursorIBeam : aura::kCursorNull;
+ return text_cursor ? ui::kCursorIBeam : ui::kCursorNull;
#elif defined(OS_WIN)
static HCURSOR ibeam = LoadCursor(NULL, IDC_IBEAM);
static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW);
diff --git a/webkit/glue/webcursor.h b/webkit/glue/webcursor.h
index 0dfddcf..23d55fe 100644
--- a/webkit/glue/webcursor.h
+++ b/webkit/glue/webcursor.h
@@ -71,7 +71,9 @@ class WEBKIT_GLUE_EXPORT WebCursor {
// Returns a native cursor representing the current WebCursor instance.
gfx::NativeCursor GetNativeCursor();
-#if defined(OS_WIN) && !defined(USE_AURA)
+#if defined(USE_AURA)
+ const ui::PlatformCursor GetPlatformCursor();
+#elif defined(OS_WIN)
// Returns a HCURSOR representing the current WebCursor instance.
// The ownership of the HCURSOR (does not apply to external cursors) remains
// with the WebCursor instance.
@@ -143,7 +145,10 @@ class WEBKIT_GLUE_EXPORT WebCursor {
gfx::Size custom_size_;
std::vector<char> custom_data_;
-#if defined(OS_WIN)
+#if defined(USE_AURA) && defined(USE_X11)
+ // Only used for custom cursors.
+ ui::PlatformCursor platform_cursor_;
+#elif defined(OS_WIN)
// An externally generated HCURSOR. We assume that it remains valid, i.e we
// don't attempt to copy the HCURSOR.
HCURSOR external_cursor_;
diff --git a/webkit/glue/webcursor_aura.cc b/webkit/glue/webcursor_aura.cc
index 08719c1..2642c47 100644
--- a/webkit/glue/webcursor_aura.cc
+++ b/webkit/glue/webcursor_aura.cc
@@ -6,123 +6,105 @@
#include "base/logging.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
-#include "ui/aura/cursor.h"
+#include "ui/base/cursor/cursor.h"
using WebKit::WebCursorInfo;
gfx::NativeCursor WebCursor::GetNativeCursor() {
switch (type_) {
case WebCursorInfo::TypePointer:
- return aura::kCursorPointer;
+ return ui::kCursorPointer;
case WebCursorInfo::TypeCross:
- return aura::kCursorCross;
+ return ui::kCursorCross;
case WebCursorInfo::TypeHand:
- return aura::kCursorHand;
+ return ui::kCursorHand;
case WebCursorInfo::TypeIBeam:
- return aura::kCursorIBeam;
+ return ui::kCursorIBeam;
case WebCursorInfo::TypeWait:
- return aura::kCursorWait;
+ return ui::kCursorWait;
case WebCursorInfo::TypeHelp:
- return aura::kCursorHelp;
+ return ui::kCursorHelp;
case WebCursorInfo::TypeEastResize:
- return aura::kCursorEastResize;
+ return ui::kCursorEastResize;
case WebCursorInfo::TypeNorthResize:
- return aura::kCursorNorthResize;
+ return ui::kCursorNorthResize;
case WebCursorInfo::TypeNorthEastResize:
- return aura::kCursorNorthEastResize;
+ return ui::kCursorNorthEastResize;
case WebCursorInfo::TypeNorthWestResize:
- return aura::kCursorNorthWestResize;
+ return ui::kCursorNorthWestResize;
case WebCursorInfo::TypeSouthResize:
- return aura::kCursorSouthResize;
+ return ui::kCursorSouthResize;
case WebCursorInfo::TypeSouthEastResize:
- return aura::kCursorSouthEastResize;
+ return ui::kCursorSouthEastResize;
case WebCursorInfo::TypeSouthWestResize:
- return aura::kCursorSouthWestResize;
+ return ui::kCursorSouthWestResize;
case WebCursorInfo::TypeWestResize:
- return aura::kCursorWestResize;
+ return ui::kCursorWestResize;
case WebCursorInfo::TypeNorthSouthResize:
- return aura::kCursorNorthSouthResize;
+ return ui::kCursorNorthSouthResize;
case WebCursorInfo::TypeEastWestResize:
- return aura::kCursorEastWestResize;
+ return ui::kCursorEastWestResize;
case WebCursorInfo::TypeNorthEastSouthWestResize:
- return aura::kCursorNorthEastSouthWestResize;
+ return ui::kCursorNorthEastSouthWestResize;
case WebCursorInfo::TypeNorthWestSouthEastResize:
- return aura::kCursorNorthWestSouthEastResize;
+ return ui::kCursorNorthWestSouthEastResize;
case WebCursorInfo::TypeColumnResize:
- return aura::kCursorColumnResize;
+ return ui::kCursorColumnResize;
case WebCursorInfo::TypeRowResize:
- return aura::kCursorRowResize;
+ return ui::kCursorRowResize;
case WebCursorInfo::TypeMiddlePanning:
- return aura::kCursorMiddlePanning;
+ return ui::kCursorMiddlePanning;
case WebCursorInfo::TypeEastPanning:
- return aura::kCursorEastPanning;
+ return ui::kCursorEastPanning;
case WebCursorInfo::TypeNorthPanning:
- return aura::kCursorNorthPanning;
+ return ui::kCursorNorthPanning;
case WebCursorInfo::TypeNorthEastPanning:
- return aura::kCursorNorthEastPanning;
+ return ui::kCursorNorthEastPanning;
case WebCursorInfo::TypeNorthWestPanning:
- return aura::kCursorNorthWestPanning;
+ return ui::kCursorNorthWestPanning;
case WebCursorInfo::TypeSouthPanning:
- return aura::kCursorSouthPanning;
+ return ui::kCursorSouthPanning;
case WebCursorInfo::TypeSouthEastPanning:
- return aura::kCursorSouthEastPanning;
+ return ui::kCursorSouthEastPanning;
case WebCursorInfo::TypeSouthWestPanning:
- return aura::kCursorSouthWestPanning;
+ return ui::kCursorSouthWestPanning;
case WebCursorInfo::TypeWestPanning:
- return aura::kCursorWestPanning;
+ return ui::kCursorWestPanning;
case WebCursorInfo::TypeMove:
- return aura::kCursorMove;
+ return ui::kCursorMove;
case WebCursorInfo::TypeVerticalText:
- return aura::kCursorVerticalText;
+ return ui::kCursorVerticalText;
case WebCursorInfo::TypeCell:
- return aura::kCursorCell;
+ return ui::kCursorCell;
case WebCursorInfo::TypeContextMenu:
- return aura::kCursorContextMenu;
+ return ui::kCursorContextMenu;
case WebCursorInfo::TypeAlias:
- return aura::kCursorAlias;
+ return ui::kCursorAlias;
case WebCursorInfo::TypeProgress:
- return aura::kCursorProgress;
+ return ui::kCursorProgress;
case WebCursorInfo::TypeNoDrop:
- return aura::kCursorNoDrop;
+ return ui::kCursorNoDrop;
case WebCursorInfo::TypeCopy:
- return aura::kCursorCopy;
+ return ui::kCursorCopy;
case WebCursorInfo::TypeNone:
- return aura::kCursorNone;
+ return ui::kCursorNone;
case WebCursorInfo::TypeNotAllowed:
- return aura::kCursorNotAllowed;
+ return ui::kCursorNotAllowed;
case WebCursorInfo::TypeZoomIn:
- return aura::kCursorZoomIn;
+ return ui::kCursorZoomIn;
case WebCursorInfo::TypeZoomOut:
- return aura::kCursorZoomOut;
+ return ui::kCursorZoomOut;
case WebCursorInfo::TypeGrab:
- return aura::kCursorGrab;
+ return ui::kCursorGrab;
case WebCursorInfo::TypeGrabbing:
- return aura::kCursorGrabbing;
- case WebCursorInfo::TypeCustom:
- return aura::kCursorCustom;
+ return ui::kCursorGrabbing;
+ case WebCursorInfo::TypeCustom: {
+ ui::Cursor cursor;
+ cursor.SetPlatformCursor(GetPlatformCursor());
+ return cursor;
+ }
default:
NOTREACHED();
return gfx::kNullCursor;
}
}
-
-void WebCursor::InitPlatformData() {
-}
-
-bool WebCursor::SerializePlatformData(Pickle* pickle) const {
- return true;
-}
-
-bool WebCursor::DeserializePlatformData(PickleIterator* iter) {
- return true;
-}
-
-bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const {
- return true;
-}
-
-void WebCursor::CleanupPlatformData() {
-}
-
-void WebCursor::CopyPlatformData(const WebCursor& other) {
-}
diff --git a/webkit/glue/webcursor_aurawin.cc b/webkit/glue/webcursor_aurawin.cc
new file mode 100644
index 0000000..b47ba51
--- /dev/null
+++ b/webkit/glue/webcursor_aurawin.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/glue/webcursor.h"
+
+#include <windows.h>
+
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
+
+const ui::PlatformCursor WebCursor::GetPlatformCursor() {
+ // TODO(winguru):
+ return LoadCursor(NULL, IDC_ARROW);
+}
+
+void WebCursor::InitPlatformData() {
+}
+
+bool WebCursor::SerializePlatformData(Pickle* pickle) const {
+ return true;
+}
+
+bool WebCursor::DeserializePlatformData(PickleIterator* iter) {
+ return true;
+}
+
+bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const {
+ return true;
+}
+
+void WebCursor::CleanupPlatformData() {
+}
+
+void WebCursor::CopyPlatformData(const WebCursor& other) {
+}
diff --git a/webkit/glue/webcursor_aurax11.cc b/webkit/glue/webcursor_aurax11.cc
new file mode 100644
index 0000000..fe221e2
--- /dev/null
+++ b/webkit/glue/webcursor_aurax11.cc
@@ -0,0 +1,83 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/glue/webcursor.h"
+
+#include <X11/Xcursor/Xcursor.h>
+#include <X11/Xlib.h>
+#include <X11/cursorfont.h>
+
+#include "base/logging.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
+#include "third_party/skia/include/core/SkUnPreMultiply.h"
+#include "ui/base/cursor/cursor.h"
+#include "ui/base/x/x11_util.h"
+
+const ui::PlatformCursor WebCursor::GetPlatformCursor() {
+ if (platform_cursor_)
+ return platform_cursor_;
+
+ XcursorImage* image =
+ XcursorImageCreate(custom_size_.width(), custom_size_.height());
+ image->xhot = hotspot_.x();
+ image->yhot = hotspot_.y();
+ uint32* pixels = image->pixels;
+
+ if (custom_size_.width() && custom_size_.height()) {
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config,
+ custom_size_.width(), custom_size_.height());
+ bitmap.allocPixels();
+ memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size());
+
+ bitmap.lockPixels();
+ int height = bitmap.height(), width = bitmap.width();
+ for (int y = 0, i = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ uint32 pixel = bitmap.getAddr32(0, y)[x];
+ int alpha = SkColorGetA(pixel);
+ if (alpha != 0 && alpha != 255)
+ pixels[i] = SkUnPreMultiply::PMColorToColor(pixel);
+ else
+ pixels[i] = pixel;
+ ++i;
+ }
+ }
+ bitmap.unlockPixels();
+ }
+
+ platform_cursor_ = ui::CreateReffedCustomXCursor(image);
+ return platform_cursor_;
+}
+
+void WebCursor::InitPlatformData() {
+ platform_cursor_ = 0;
+}
+
+bool WebCursor::SerializePlatformData(Pickle* pickle) const {
+ return true;
+}
+
+bool WebCursor::DeserializePlatformData(PickleIterator* iter) {
+ return true;
+}
+
+bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const {
+ return true;
+}
+
+void WebCursor::CleanupPlatformData() {
+ if (platform_cursor_) {
+ ui::UnrefCustomXCursor(platform_cursor_);
+ platform_cursor_ = 0;
+ }
+}
+
+void WebCursor::CopyPlatformData(const WebCursor& other) {
+ if (platform_cursor_)
+ ui::UnrefCustomXCursor(platform_cursor_);
+ platform_cursor_ = other.platform_cursor_;
+ if (platform_cursor_)
+ ui::RefCustomXCursor(platform_cursor_);
+}
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 987eb2c..8bebf2a 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -401,6 +401,8 @@
'webcursor.h',
'webcursor_android.cc',
'webcursor_aura.cc',
+ 'webcursor_aurawin.cc',
+ 'webcursor_aurax11.cc',
'webcursor_gtk.cc',
'webcursor_gtk_data.h',
'webcursor_mac.mm',
@@ -499,6 +501,11 @@
'webcursor_win.cc',
],
}],
+ ['use_aura==1 and use_x11==1', {
+ 'link_settings': {
+ 'libraries': [ '-lXcursor', ],
+ },
+ }],
['OS!="mac"', {
'sources/': [['exclude', '_mac\\.(cc|mm)$']],
'sources!': [