diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-19 01:46:41 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-19 01:46:41 +0000 |
commit | c21fcc5b17f1a7234d7649dbc4d24c3b9918605f (patch) | |
tree | b1be7bd835ee5535117f92e02b9126d172b9753a | |
parent | 4f644da31f9f8d03b02dcfd9176d6fbf48bef578 (diff) | |
download | chromium_src-c21fcc5b17f1a7234d7649dbc4d24c3b9918605f.zip chromium_src-c21fcc5b17f1a7234d7649dbc4d24c3b9918605f.tar.gz chromium_src-c21fcc5b17f1a7234d7649dbc4d24c3b9918605f.tar.bz2 |
Support loading non system cursors in Chrome AURA/ASH windows.
This is mostly intended to support special cursors passed by Webkit like the middle scroll panning cursor, etc.
On Windows AURA the code to load the platform cursor is implemented in CursorLoaderWin, which attempts to
load the cursor via the LoadCursor API always passing NULL as the module handle. This would not work for non
system cursors.
To enable support for the same added support to pass the cursor module name in the Cursor interfaces for AURA.
These include the following:-
1. CursorClient
2. CursorLoader
3. NativeCursorManager
Added a method SetCursorResourceModule to these interfaces. The NativeCursorManager is registered as the cursor client
in AURA/ASH. It forwards calls to the CursorClient which then forwards the calls over to the CursorLoader.
For ASH, I added a SetCursorResourceModule method to the ImageCursor class used by ASH.
We pass the resource dll name from RenderWidgetHostViewAura::UpdateCursorIfOverSelf method.
Added code in the CursorLoaderWin::SetPlatformCursor function to use the platform cursor from the passed in cursor if
available, as the resource dll name may not be available to all cursor clients.
BUG=176079
Review URL: https://codereview.chromium.org/12903002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188911 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/ash.gyp | 3 | ||||
-rw-r--r-- | ash/wm/ash_native_cursor_manager.cc | 6 | ||||
-rw-r--r-- | ash/wm/ash_native_cursor_manager.h | 2 | ||||
-rw-r--r-- | ash/wm/ash_native_cursor_manager_unittest.cc | 8 | ||||
-rw-r--r-- | ash/wm/image_cursors.cc | 5 | ||||
-rw-r--r-- | ash/wm/image_cursors.h | 4 | ||||
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_aura.cc | 11 | ||||
-rw-r--r-- | ui/DEPS | 1 | ||||
-rw-r--r-- | ui/aura/client/cursor_client.h | 5 | ||||
-rw-r--r-- | ui/base/cursor/cursor_loader.h | 5 | ||||
-rw-r--r-- | ui/base/cursor/cursor_loader_win.cc | 50 | ||||
-rw-r--r-- | ui/base/cursor/cursor_loader_win.h | 4 | ||||
-rw-r--r-- | ui/base/cursor/cursor_loader_x11.h | 2 | ||||
-rw-r--r-- | ui/views/corewm/compound_event_filter_unittest.cc | 3 | ||||
-rw-r--r-- | ui/views/corewm/cursor_manager.cc | 4 | ||||
-rw-r--r-- | ui/views/corewm/cursor_manager.h | 1 | ||||
-rw-r--r-- | ui/views/corewm/cursor_manager_unittest.cc | 3 | ||||
-rw-r--r-- | ui/views/corewm/native_cursor_manager.h | 5 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_native_cursor_manager.cc | 5 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_native_cursor_manager.h | 1 |
20 files changed, 114 insertions, 14 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index ee03219..af44301 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -691,6 +691,9 @@ ['exclude', 'magnifier/magnification_controller_unittest.cc'], ['exclude', 'wm/workspace/workspace_window_resizer_unittest.cc'], ], + 'sources': [ + '<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_unscaled_resources.rc', + ], # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. 'msvs_disabled_warnings': [ 4267, ], }], diff --git a/ash/wm/ash_native_cursor_manager.cc b/ash/wm/ash_native_cursor_manager.cc index b02cf6a..885f95b 100644 --- a/ash/wm/ash_native_cursor_manager.cc +++ b/ash/wm/ash_native_cursor_manager.cc @@ -107,4 +107,10 @@ void AshNativeCursorManager::SetMouseEventsEnabled( NotifyMouseEventsEnableStateChange(enabled); } +void AshNativeCursorManager::SetCursorResourceModule( + const string16& module_name) { + image_cursors_->SetCursorResourceModule(module_name); +} + + } // namespace ash diff --git a/ash/wm/ash_native_cursor_manager.h b/ash/wm/ash_native_cursor_manager.h index 07a7168..506d381 100644 --- a/ash/wm/ash_native_cursor_manager.h +++ b/ash/wm/ash_native_cursor_manager.h @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" +#include "base/string16.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/point.h" #include "ui/views/corewm/native_cursor_manager.h" @@ -48,6 +49,7 @@ class ASH_EXPORT AshNativeCursorManager virtual void SetMouseEventsEnabled( bool enabled, views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE; + virtual void SetCursorResourceModule(const string16& module_name) OVERRIDE; // The cursor location where the cursor was disabled. gfx::Point disabled_cursor_location_; diff --git a/ash/wm/ash_native_cursor_manager_unittest.cc b/ash/wm/ash_native_cursor_manager_unittest.cc index 7697621..ca0597d 100644 --- a/ash/wm/ash_native_cursor_manager_unittest.cc +++ b/ash/wm/ash_native_cursor_manager_unittest.cc @@ -49,7 +49,9 @@ TEST_F(AshNativeCursorManagerTest, LockCursor) { CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); CursorManagerTestApi test_api(cursor_manager); gfx::Display display(0); - +#if defined(OS_WIN) + cursor_manager->SetCursorResourceModule(L"ash_unittests.exe"); +#endif cursor_manager->SetCursor(ui::kCursorCopy); EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); display.set_device_scale_factor(2.0f); @@ -85,7 +87,9 @@ TEST_F(AshNativeCursorManagerTest, LockCursor) { TEST_F(AshNativeCursorManagerTest, SetCursor) { CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); CursorManagerTestApi test_api(cursor_manager); - +#if defined(OS_WIN) + cursor_manager->SetCursorResourceModule(L"ash_unittests.exe"); +#endif cursor_manager->SetCursor(ui::kCursorCopy); EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); EXPECT_TRUE(test_api.GetCurrentCursor().platform()); diff --git a/ash/wm/image_cursors.cc b/ash/wm/image_cursors.cc index 74bf358..1792c6c 100644 --- a/ash/wm/image_cursors.cc +++ b/ash/wm/image_cursors.cc @@ -5,6 +5,7 @@ #include "ash/wm/image_cursors.h" #include "base/logging.h" +#include "base/string16.h" #include "ui/base/cursor/cursor_loader.h" #include "ui/base/cursor/cursor.h" #include "ui/gfx/display.h" @@ -134,4 +135,8 @@ void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { cursor_loader_->SetPlatformCursor(cursor); } +void ImageCursors::SetCursorResourceModule(const string16& module_name) { + cursor_loader_->SetCursorResourceModule(module_name); +} + } // namespace ash diff --git a/ash/wm/image_cursors.h b/ash/wm/image_cursors.h index 59c7b82..3f1e609 100644 --- a/ash/wm/image_cursors.h +++ b/ash/wm/image_cursors.h @@ -7,6 +7,7 @@ #include "ash/ash_export.h" #include "base/memory/scoped_ptr.h" +#include "base/string16.h" #include "ui/gfx/native_widget_types.h" namespace gfx { @@ -39,6 +40,9 @@ class ASH_EXPORT ImageCursors { // Sets the platform cursor based on the native type of |cursor|. void SetPlatformCursor(gfx::NativeCursor* cursor); + // Sets the cursor resource module name for non system cursors. + void SetCursorResourceModule(const string16& module_name); + private: scoped_ptr<ui::CursorLoader> cursor_loader_; 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 88cd26a..85c3ffc 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -28,6 +28,7 @@ #include "content/port/browser/render_widget_host_view_port.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/content_browser_client.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/user_metrics.h" @@ -2449,8 +2450,16 @@ void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() { aura::client::CursorClient* cursor_client = aura::client::GetCursorClient(root_window); - if (cursor_client) + if (cursor_client) { +#if defined(OS_WIN) + if (GetContentClient() && GetContentClient()->browser() && + GetContentClient()->browser()->GetResourceDllName()) { + cursor_client->SetCursorResourceModule( + GetContentClient()->browser()->GetResourceDllName()); + } +#endif cursor_client->SetCursor(cursor); + } } ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() const { @@ -3,6 +3,7 @@ include_rules = [ "+grit/native_theme_resources.h", "+grit/ui_resources.h", "+grit/ui_strings.h", + "+grit/ui_unscaled_resources.h", "+jni", "+net", "+skia", diff --git a/ui/aura/client/cursor_client.h b/ui/aura/client/cursor_client.h index 8f48430..fb2dde2 100644 --- a/ui/aura/client/cursor_client.h +++ b/ui/aura/client/cursor_client.h @@ -5,6 +5,7 @@ #ifndef UI_AURA_CLIENT_CURSOR_CLIENT_H_ #define UI_AURA_CLIENT_CURSOR_CLIENT_H_ +#include "base/string16.h" #include "ui/aura/aura_export.h" #include "ui/gfx/native_widget_types.h" @@ -55,6 +56,10 @@ class AURA_EXPORT CursorClient { // EnableMouseEvents/DisableMouseEvents. virtual void UnlockCursor() = 0; + // Used to pass the cursor resource module name to the cursor loader. This is + // typically used to load non system cursors. + virtual void SetCursorResourceModule(const string16& module_name) = 0; + protected: virtual ~CursorClient() {} }; diff --git a/ui/base/cursor/cursor_loader.h b/ui/base/cursor/cursor_loader.h index 661ab08..945a926 100644 --- a/ui/base/cursor/cursor_loader.h +++ b/ui/base/cursor/cursor_loader.h @@ -6,6 +6,7 @@ #define UI_BASE_CURSOR_CURSOR_LOADER_H_ #include "base/logging.h" +#include "base/string16.h" #include "ui/base/ui_export.h" #include "ui/gfx/display.h" #include "ui/gfx/native_widget_types.h" @@ -49,6 +50,10 @@ class UI_EXPORT CursorLoader { // Sets the platform cursor based on the native type of |cursor|. virtual void SetPlatformCursor(gfx::NativeCursor* cursor) = 0; + // Used to pass the cursor resource module name to the cursor loader. This is + // typically used to load non system cursors. + virtual void SetCursorResourceModule(const string16& module_name) = 0; + // Creates a CursorLoader. static CursorLoader* Create(); diff --git a/ui/base/cursor/cursor_loader_win.cc b/ui/base/cursor/cursor_loader_win.cc index 272a298..ba3ade9 100644 --- a/ui/base/cursor/cursor_loader_win.cc +++ b/ui/base/cursor/cursor_loader_win.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "ui/base/cursor/cursor_loader_win.h" +#include "grit/ui_unscaled_resources.h" namespace ui { @@ -59,29 +60,46 @@ const wchar_t* GetCursorId(gfx::NativeCursor native_cursor) { case kCursorNotAllowed: return IDC_NO; case kCursorColumnResize: + return MAKEINTRESOURCE(IDC_COLRESIZE); case kCursorRowResize: + return MAKEINTRESOURCE(IDC_ROWRESIZE); case kCursorMiddlePanning: + return MAKEINTRESOURCE(IDC_PAN_MIDDLE); case kCursorEastPanning: + return MAKEINTRESOURCE(IDC_PAN_EAST); case kCursorNorthPanning: + return MAKEINTRESOURCE(IDC_PAN_NORTH); case kCursorNorthEastPanning: + return MAKEINTRESOURCE(IDC_PAN_NORTH_EAST); case kCursorNorthWestPanning: + return MAKEINTRESOURCE(IDC_PAN_NORTH_WEST); case kCursorSouthPanning: + return MAKEINTRESOURCE(IDC_PAN_SOUTH); case kCursorSouthEastPanning: + return MAKEINTRESOURCE(IDC_PAN_SOUTH_EAST); case kCursorSouthWestPanning: + return MAKEINTRESOURCE(IDC_PAN_SOUTH_WEST); case kCursorWestPanning: + return MAKEINTRESOURCE(IDC_PAN_WEST); case kCursorVerticalText: + return MAKEINTRESOURCE(IDC_VERTICALTEXT); case kCursorCell: - case kCursorContextMenu: - case kCursorAlias: - case kCursorCopy: - case kCursorNone: + return MAKEINTRESOURCE(IDC_CELL); case kCursorZoomIn: + return MAKEINTRESOURCE(IDC_ZOOMIN); case kCursorZoomOut: + return MAKEINTRESOURCE(IDC_ZOOMOUT); case kCursorGrab: + return MAKEINTRESOURCE(IDC_HAND_GRAB); case kCursorGrabbing: + return MAKEINTRESOURCE(IDC_HAND_GRABBING); + case kCursorCopy: + return MAKEINTRESOURCE(IDC_COPYCUR); + case kCursorAlias: + return MAKEINTRESOURCE(IDC_ALIAS); + case kCursorContextMenu: + case kCursorNone: case kCursorCustom: - // TODO(jamescook): Should we use WebKit glue resources for these? - // Or migrate those resources to someplace ui/aura can share? NOTIMPLEMENTED(); return IDC_ARROW; default: @@ -124,13 +142,23 @@ void CursorLoaderWin::UnloadAll() { void CursorLoaderWin::SetPlatformCursor(gfx::NativeCursor* cursor) { #if defined(USE_AURA) if (cursor->native_type() != kCursorCustom) { - const wchar_t* cursor_id = GetCursorId(*cursor); - - // TODO(jamescook): Support for non-system cursors will require finding - // the appropriate module to pass to LoadCursor(). - cursor->SetPlatformCursor(LoadCursor(NULL, cursor_id)); + if (cursor->platform()) { + cursor->SetPlatformCursor(cursor->platform()); + } else { + const wchar_t* cursor_id = GetCursorId(*cursor); + PlatformCursor platform_cursor = LoadCursor(NULL, cursor_id); + if (!platform_cursor && !cursor_resource_module_name_.empty()) { + platform_cursor = LoadCursor( + GetModuleHandle(cursor_resource_module_name_.c_str()), cursor_id); + } + cursor->SetPlatformCursor(platform_cursor); + } } #endif } +void CursorLoaderWin::SetCursorResourceModule(const string16& module_name) { + cursor_resource_module_name_ = module_name; +} + } // namespace ui diff --git a/ui/base/cursor/cursor_loader_win.h b/ui/base/cursor/cursor_loader_win.h index d4539d9..9448f85 100644 --- a/ui/base/cursor/cursor_loader_win.h +++ b/ui/base/cursor/cursor_loader_win.h @@ -6,6 +6,7 @@ #define UI_BASE_CURSOR_CURSOR_LOADER_WIN_H_ #include "base/compiler_specific.h" +#include "base/string16.h" #include "ui/base/cursor/cursor_loader.h" namespace ui { @@ -25,8 +26,11 @@ class UI_EXPORT CursorLoaderWin : public CursorLoader { int frame_delay_ms) OVERRIDE; virtual void UnloadAll() OVERRIDE; virtual void SetPlatformCursor(gfx::NativeCursor* cursor) OVERRIDE; + virtual void SetCursorResourceModule(const string16& module_name) OVERRIDE; private: + string16 cursor_resource_module_name_; + DISALLOW_COPY_AND_ASSIGN(CursorLoaderWin); }; diff --git a/ui/base/cursor/cursor_loader_x11.h b/ui/base/cursor/cursor_loader_x11.h index 4947ca0..2b740f8 100644 --- a/ui/base/cursor/cursor_loader_x11.h +++ b/ui/base/cursor/cursor_loader_x11.h @@ -31,6 +31,8 @@ class UI_EXPORT CursorLoaderX11 : public CursorLoader { int frame_delay_ms) OVERRIDE; virtual void UnloadAll() OVERRIDE; virtual void SetPlatformCursor(gfx::NativeCursor* cursor) OVERRIDE; + virtual void SetCursorResourceModule(const string16& module_name) OVERRIDE { + } private: // Returns true if we have an image resource loaded for the |native_cursor|. diff --git a/ui/views/corewm/compound_event_filter_unittest.cc b/ui/views/corewm/compound_event_filter_unittest.cc index 1dd743f..d3c32ee 100644 --- a/ui/views/corewm/compound_event_filter_unittest.cc +++ b/ui/views/corewm/compound_event_filter_unittest.cc @@ -62,6 +62,9 @@ class TestCursorClient : public aura::client::CursorClient { virtual void UnlockCursor() OVERRIDE { } + virtual void SetCursorResourceModule(const string16& module_name) OVERRIDE { + } + private: bool visible_; bool mouse_events_enabled_; diff --git a/ui/views/corewm/cursor_manager.cc b/ui/views/corewm/cursor_manager.cc index 39b7ee9..24abfe2 100644 --- a/ui/views/corewm/cursor_manager.cc +++ b/ui/views/corewm/cursor_manager.cc @@ -150,6 +150,10 @@ void CursorManager::UnlockCursor() { } } +void CursorManager::SetCursorResourceModule(const string16& module_name) { + delegate_->SetCursorResourceModule(module_name); +} + gfx::NativeCursor CursorManager::GetCurrentCursor() const { return current_state_->cursor(); } diff --git a/ui/views/corewm/cursor_manager.h b/ui/views/corewm/cursor_manager.h index d7784b3..7197995 100644 --- a/ui/views/corewm/cursor_manager.h +++ b/ui/views/corewm/cursor_manager.h @@ -50,6 +50,7 @@ class VIEWS_EXPORT CursorManager : public aura::client::CursorClient, virtual void SetDisplay(const gfx::Display& display) OVERRIDE; virtual void LockCursor() OVERRIDE; virtual void UnlockCursor() OVERRIDE; + virtual void SetCursorResourceModule(const string16& module_name) OVERRIDE; private: // Overridden from NativeCursorManagerDelegate: diff --git a/ui/views/corewm/cursor_manager_unittest.cc b/ui/views/corewm/cursor_manager_unittest.cc index f1e24a5..3f53370 100644 --- a/ui/views/corewm/cursor_manager_unittest.cc +++ b/ui/views/corewm/cursor_manager_unittest.cc @@ -37,6 +37,9 @@ class TestingCursorManager : public views::corewm::NativeCursorManager { delegate->CommitMouseEventsEnabled(enabled); } + virtual void SetCursorResourceModule(const string16& module_name) OVERRIDE { + } + private: gfx::NativeCursor cursor_; }; diff --git a/ui/views/corewm/native_cursor_manager.h b/ui/views/corewm/native_cursor_manager.h index bb28b01..880621a 100644 --- a/ui/views/corewm/native_cursor_manager.h +++ b/ui/views/corewm/native_cursor_manager.h @@ -5,6 +5,7 @@ #ifndef UI_VIEWS_COREWM_NATIVE_CURSOR_MANAGER_H_ #define UI_VIEWS_COREWM_NATIVE_CURSOR_MANAGER_H_ +#include "base/string16.h" #include "ui/views/corewm/native_cursor_manager_delegate.h" #include "ui/views/views_export.h" @@ -48,6 +49,10 @@ class VIEWS_EXPORT NativeCursorManager { virtual void SetMouseEventsEnabled( bool enabled, views::corewm::NativeCursorManagerDelegate* delegate) = 0; + + // Used to pass the cursor resource module name to the cursor loader. This is + // typically used to load non system cursors. + virtual void SetCursorResourceModule(const string16& module_name) = 0; }; } // namespace corewm diff --git a/ui/views/widget/desktop_aura/desktop_native_cursor_manager.cc b/ui/views/widget/desktop_aura/desktop_native_cursor_manager.cc index 9ce2da9..0334d52 100644 --- a/ui/views/widget/desktop_aura/desktop_native_cursor_manager.cc +++ b/ui/views/widget/desktop_aura/desktop_native_cursor_manager.cc @@ -66,4 +66,9 @@ void DesktopNativeCursorManager::SetMouseEventsEnabled( root_window_->OnMouseEventsEnableStateChanged(enabled); } +void DesktopNativeCursorManager::SetCursorResourceModule( + const string16& module_name) { + cursor_loader_->SetCursorResourceModule(module_name); +} + } // namespace views diff --git a/ui/views/widget/desktop_aura/desktop_native_cursor_manager.h b/ui/views/widget/desktop_aura/desktop_native_cursor_manager.h index cbb73a1..1f4f79a 100644 --- a/ui/views/widget/desktop_aura/desktop_native_cursor_manager.h +++ b/ui/views/widget/desktop_aura/desktop_native_cursor_manager.h @@ -46,6 +46,7 @@ class VIEWS_EXPORT DesktopNativeCursorManager virtual void SetMouseEventsEnabled( bool enabled, views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE; + virtual void SetCursorResourceModule(const string16& module_name) OVERRIDE; aura::RootWindow* root_window_; scoped_ptr<ui::CursorLoader> cursor_loader_; |