diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-23 19:55:45 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-23 19:55:45 +0000 |
commit | 030ea0b2e4c7a596c30ffa3825eaac83807b33aa (patch) | |
tree | 3c384600881abf47a1b1609f2b164ef86b80ac17 | |
parent | 6308cb72d0eebb3174c77161bdd8d5719c7f8978 (diff) | |
download | chromium_src-030ea0b2e4c7a596c30ffa3825eaac83807b33aa.zip chromium_src-030ea0b2e4c7a596c30ffa3825eaac83807b33aa.tar.gz chromium_src-030ea0b2e4c7a596c30ffa3825eaac83807b33aa.tar.bz2 |
PPB_CursorControl_Dev.SetCursor: Add support for custom cursor.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6720001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79168 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ppapi/example/example.cc | 33 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 49 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 6 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_cursor_control_impl.cc | 12 |
4 files changed, 81 insertions, 19 deletions
diff --git a/ppapi/example/example.cc b/ppapi/example/example.cc index 5529391..f9ae799 100644 --- a/ppapi/example/example.cc +++ b/ppapi/example/example.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -12,6 +12,7 @@ #include <algorithm> #include "ppapi/c/dev/ppb_console_dev.h" +#include "ppapi/c/dev/ppb_cursor_control_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_input_event.h" @@ -163,7 +164,8 @@ class MyInstance : public pp::Instance, public MyFetcherClient { width_(0), height_(0), animation_counter_(0), - print_settings_valid_(false) {} + print_settings_valid_(false), + showing_custom_cursor_(false) {} virtual ~MyInstance() { if (fetcher_) { @@ -194,6 +196,7 @@ class MyInstance : public pp::Instance, public MyFetcherClient { switch (event.type) { case PP_INPUTEVENT_TYPE_MOUSEDOWN: SayHello(); + ToggleCursor(); return true; case PP_INPUTEVENT_TYPE_MOUSEMOVE: return true; @@ -395,6 +398,30 @@ class MyInstance : public pp::Instance, public MyFetcherClient { fetcher_ = NULL; } + void ToggleCursor() { + const PPB_CursorControl_Dev* cursor_control = + reinterpret_cast<const PPB_CursorControl_Dev*>( + pp::Module::Get()->GetBrowserInterface( + PPB_CURSOR_CONTROL_DEV_INTERFACE)); + if (!cursor_control) + return; + + if (showing_custom_cursor_) { + cursor_control->SetCursor(pp_instance(), PP_CURSORTYPE_POINTER, 0, NULL); + } else { + pp::ImageData image_data(this, pp::ImageData::GetNativeImageDataFormat(), + pp::Size(50, 50), false); + FillRect(&image_data, 0, 0, 50, 50, + image_data.format() == PP_IMAGEDATAFORMAT_BGRA_PREMUL ? + 0x80800000 : 0x80000080); + pp::Point hot_spot(0, 0); + cursor_control->SetCursor(pp_instance(), PP_CURSORTYPE_CUSTOM, + image_data.pp_resource(), &hot_spot.pp_point()); + } + + showing_custom_cursor_ = !showing_custom_cursor_; + } + pp::Var console_; pp::Graphics2D device_context_; @@ -409,6 +436,8 @@ class MyInstance : public pp::Instance, public MyFetcherClient { int animation_counter_; bool print_settings_valid_; PP_PrintSettings_Dev print_settings_; + + bool showing_custom_cursor_; }; void FlushCallback(void* data, int32_t result) { diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 6360a8a..ecfcba7 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -555,14 +555,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; } diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index a8bba47..7cb6187 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -130,7 +130,11 @@ class PluginInstance : public base::RefCounted<PluginInstance> { PP_Var GetOwnerElementObject(); bool BindGraphics(PP_Resource graphics_id); bool full_frame() const { return full_frame_; } - bool SetCursor(PP_CursorType_Dev type); + // If |type| is not PP_CURSORTYPE_CUSTOM, |custom_image| and |hot_spot| are + // ignored. + bool SetCursor(PP_CursorType_Dev type, + PP_Resource custom_image, + const PP_Point* hot_spot); PP_Var ExecuteScript(PP_Var script, PP_Var* exception); // PPP_Instance pass-through. diff --git a/webkit/plugins/ppapi/ppb_cursor_control_impl.cc b/webkit/plugins/ppapi/ppb_cursor_control_impl.cc index 83c004d..fd0eb8b 100644 --- a/webkit/plugins/ppapi/ppb_cursor_control_impl.cc +++ b/webkit/plugins/ppapi/ppb_cursor_control_impl.cc @@ -28,16 +28,7 @@ PP_Bool SetCursor(PP_Instance instance_id, if (!instance) return PP_FALSE; - scoped_refptr<PPB_ImageData_Impl> custom_image( - Resource::GetAs<PPB_ImageData_Impl>(custom_image_id)); - if (custom_image.get()) { - // TODO(neb): implement custom cursors. - // (Remember that PP_CURSORTYPE_CUSTOM != WebCursorInfo::TypeCustom.) - NOTIMPLEMENTED(); - return PP_FALSE; - } - - return BoolToPPBool(instance->SetCursor(type)); + return BoolToPPBool(instance->SetCursor(type, custom_image_id, hot_spot)); } PP_Bool LockCursor(PP_Instance instance_id) { @@ -92,4 +83,3 @@ const PPB_CursorControl_Dev* GetCursorControlInterface() { } // namespace ppapi } // namespace webkit - |