summaryrefslogtreecommitdiffstats
path: root/ppapi/example/example.cc
diff options
context:
space:
mode:
authoryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-09 23:00:24 +0000
committeryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-09 23:00:24 +0000
commitb993705a0074ba28d880333d325c4e029a71a13b (patch)
tree375b2d90d64f1e1830a1380af50292b20d895cd6 /ppapi/example/example.cc
parent57f8c0cd95703e39aee6cb455edb6123f55b0537 (diff)
downloadchromium_src-b993705a0074ba28d880333d325c4e029a71a13b.zip
chromium_src-b993705a0074ba28d880333d325c4e029a71a13b.tar.gz
chromium_src-b993705a0074ba28d880333d325c4e029a71a13b.tar.bz2
Fix the issue that PPB_CursorControl_Dev.SetCursor doesn't take effect until the next input event.
BUG=94981 TEST= 1) run manual test in ppapi/example; 2) click on the plugin; 3) the cursor should change to a rectangle and keep changing its dimensions, even if you don't move/click the mouse. Review URL: http://codereview.chromium.org/8196003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104686 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/example/example.cc')
-rw-r--r--ppapi/example/example.cc31
1 files changed, 24 insertions, 7 deletions
diff --git a/ppapi/example/example.cc b/ppapi/example/example.cc
index 0caceff..34b39f2 100644
--- a/ppapi/example/example.cc
+++ b/ppapi/example/example.cc
@@ -170,7 +170,9 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient {
height_(0),
animation_counter_(0),
print_settings_valid_(false),
- showing_custom_cursor_(false) {
+ showing_custom_cursor_(false),
+ cursor_dimension_(50),
+ expanding_cursor_(false) {
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
}
@@ -379,6 +381,8 @@ int gettimeofday(struct timeval *tv, struct timezone*) {
UpdateFps();
animation_counter_++;
Paint();
+ if (showing_custom_cursor_)
+ SetCursor();
}
private:
@@ -426,6 +430,11 @@ int gettimeofday(struct timeval *tv, struct timezone*) {
}
void ToggleCursor() {
+ showing_custom_cursor_ = !showing_custom_cursor_;
+ SetCursor();
+ }
+
+ void SetCursor() {
const PPB_CursorControl_Dev* cursor_control =
reinterpret_cast<const PPB_CursorControl_Dev*>(
pp::Module::Get()->GetBrowserInterface(
@@ -433,20 +442,26 @@ int gettimeofday(struct timeval *tv, struct timezone*) {
if (!cursor_control)
return;
- if (showing_custom_cursor_) {
+ 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,
+ pp::Size(cursor_dimension_, cursor_dimension_),
+ false);
+ FillRect(&image_data, 0, 0, cursor_dimension_, cursor_dimension_,
image_data.format() == PP_IMAGEDATAFORMAT_BGRA_PREMUL ?
0x80800000 : 0x80000080);
- pp::Point hot_spot(0, 0);
+ pp::Point hot_spot(cursor_dimension_ / 2, cursor_dimension_ / 2);
cursor_control->SetCursor(pp_instance(), PP_CURSORTYPE_CUSTOM,
image_data.pp_resource(), &hot_spot.pp_point());
+ if (expanding_cursor_) {
+ if (++cursor_dimension_ >= 50)
+ expanding_cursor_ = false;
+ } else {
+ if (--cursor_dimension_ <= 5)
+ expanding_cursor_ = true;
+ }
}
-
- showing_custom_cursor_ = !showing_custom_cursor_;
}
pp::Var console_;
@@ -465,6 +480,8 @@ int gettimeofday(struct timeval *tv, struct timezone*) {
PP_PrintSettings_Dev print_settings_;
bool showing_custom_cursor_;
+ int cursor_dimension_;
+ bool expanding_cursor_;
};
void FlushCallback(void* data, int32_t result) {