Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Unified Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 6720001: PPB_CursorControl_Dev.SetCursor: Add support for custom cursor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix warning on Mac. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/plugins/ppapi/ppapi_plugin_instance.cc
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index b0fa47e9d7e9fb08e2e158b8a8342dc61ee1f7a6..13b545681e11424c0df0bbafdf9cc449cb190550 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -544,14 +544,53 @@ bool PluginInstance::BindGraphics(PP_Resource graphics_id) {
return true;
}
-bool PluginInstance::SetCursor(PP_CursorType_Dev type) {
- if (type == PP_CURSORTYPE_CUSTOM) {
- // TODO(neb): implement custom cursors.
- // (Remember that PP_CURSORTYPE_CUSTOM != WebCursorInfo::TypeCustom.)
+bool PluginInstance::SetCursor(PP_CursorType_Dev type,
+ PP_Resource custom_image,
+ const PP_Point* hot_spot) {
+ if (type != PP_CURSORTYPE_CUSTOM) {
+ cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type)));
+ return true;
+ }
+
+ if (!hot_spot)
+ return false;
+
+ scoped_refptr<PPB_ImageData_Impl> image_data(
+ Resource::GetAs<PPB_ImageData_Impl>(custom_image));
+ if (!image_data.get())
+ return false;
+
+ if (image_data->format() != PPB_ImageData_Impl::GetNativeImageDataFormat()) {
+ // TODO(yzshen): Handle the case that the image format is different from the
+ // native format.
NOTIMPLEMENTED();
return false;
}
- cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type)));
+
+ ImageDataAutoMapper auto_mapper(image_data);
+ if (!auto_mapper.is_valid())
+ return false;
+
+ scoped_ptr<WebCursorInfo> custom_cursor(
+ new WebCursorInfo(WebCursorInfo::TypeCustom));
+ custom_cursor->hotSpot.x = hot_spot->x;
+ custom_cursor->hotSpot.y = hot_spot->y;
+
+#if WEBKIT_USING_SKIA
+ const SkBitmap* bitmap = image_data->GetMappedBitmap();
+ // Make a deep copy, so that the cursor remains valid even after the original
+ // image data gets freed.
+ if (!bitmap->copyTo(&custom_cursor->customImage.getSkBitmap(),
+ bitmap->config())) {
+ return false;
+ }
+#elif WEBKIT_USING_CG
+ // TODO(yzshen): Implement it.
+ NOTIMPLEMENTED();
+ return false;
+#endif
+
+ cursor_.reset(custom_cursor.release());
return true;
}

Powered by Google App Engine
This is Rietveld 408576698