diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/aura.gyp | 1 | ||||
-rw-r--r-- | ui/aura/root_window.cc | 6 | ||||
-rw-r--r-- | ui/aura/root_window.h | 2 | ||||
-rw-r--r-- | ui/aura/root_window_host.h | 2 | ||||
-rw-r--r-- | ui/aura/root_window_host_linux.cc | 108 | ||||
-rw-r--r-- | ui/aura/root_window_host_win.cc | 96 | ||||
-rw-r--r-- | ui/base/cursor/cursor.cc | 40 | ||||
-rw-r--r-- | ui/base/cursor/cursor.h (renamed from ui/aura/cursor.h) | 75 | ||||
-rw-r--r-- | ui/base/cursor/cursor_win.cc | 17 | ||||
-rw-r--r-- | ui/base/cursor/cursor_x11.cc | 19 | ||||
-rw-r--r-- | ui/base/x/x11_util.cc | 110 | ||||
-rw-r--r-- | ui/base/x/x11_util.h | 16 | ||||
-rw-r--r-- | ui/gfx/native_widget_types.h | 9 | ||||
-rw-r--r-- | ui/ui.gyp | 10 | ||||
-rw-r--r-- | ui/views/controls/link.cc | 6 | ||||
-rw-r--r-- | ui/views/controls/resize_area.cc | 6 | ||||
-rw-r--r-- | ui/views/controls/single_split_view.cc | 6 | ||||
-rw-r--r-- | ui/views/controls/textfield/native_textfield_views.cc | 4 |
18 files changed, 396 insertions, 137 deletions
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; @@ -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); |