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

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 9814015: Add new MouseCursor interface for setting the mouse cursor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \ 166 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \
167 == static_cast<int>(np_name), \ 167 == static_cast<int>(np_name), \
168 mismatching_enums) 168 mismatching_enums)
169 169
170 // <embed>/<object> attributes. 170 // <embed>/<object> attributes.
171 const char kWidth[] = "width"; 171 const char kWidth[] = "width";
172 const char kHeight[] = "height"; 172 const char kHeight[] = "height";
173 const char kBorder[] = "border"; // According to w3c, deprecated. 173 const char kBorder[] = "border"; // According to w3c, deprecated.
174 const char kStyle[] = "style"; 174 const char kStyle[] = "style";
175 175
176 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_CURSORTYPE_POINTER); 176 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_MOUSECURSOR_TYPE_POINTER);
177 COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_CURSORTYPE_CROSS); 177 COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_MOUSECURSOR_TYPE_CROSS);
178 COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_CURSORTYPE_HAND); 178 COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_MOUSECURSOR_TYPE_HAND);
179 COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, PP_CURSORTYPE_IBEAM); 179 COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, PP_MOUSECURSOR_TYPE_IBEAM);
180 COMPILE_ASSERT_MATCHING_ENUM(TypeWait, PP_CURSORTYPE_WAIT); 180 COMPILE_ASSERT_MATCHING_ENUM(TypeWait, PP_MOUSECURSOR_TYPE_WAIT);
181 COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, PP_CURSORTYPE_HELP); 181 COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, PP_MOUSECURSOR_TYPE_HELP);
182 COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, PP_CURSORTYPE_EASTRESIZE); 182 COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, PP_MOUSECURSOR_TYPE_EASTRESIZE);
183 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, PP_CURSORTYPE_NORTHRESIZE); 183 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, PP_MOUSECURSOR_TYPE_NORTHRESIZE);
184 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastResize, 184 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastResize,
185 PP_CURSORTYPE_NORTHEASTRESIZE); 185 PP_MOUSECURSOR_TYPE_NORTHEASTRESIZE);
186 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestResize, 186 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestResize,
187 PP_CURSORTYPE_NORTHWESTRESIZE); 187 PP_MOUSECURSOR_TYPE_NORTHWESTRESIZE);
188 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthResize, PP_CURSORTYPE_SOUTHRESIZE); 188 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthResize, PP_MOUSECURSOR_TYPE_SOUTHRESIZE);
189 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastResize, 189 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastResize,
190 PP_CURSORTYPE_SOUTHEASTRESIZE); 190 PP_MOUSECURSOR_TYPE_SOUTHEASTRESIZE);
191 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestResize, 191 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestResize,
192 PP_CURSORTYPE_SOUTHWESTRESIZE); 192 PP_MOUSECURSOR_TYPE_SOUTHWESTRESIZE);
193 COMPILE_ASSERT_MATCHING_ENUM(TypeWestResize, PP_CURSORTYPE_WESTRESIZE); 193 COMPILE_ASSERT_MATCHING_ENUM(TypeWestResize, PP_MOUSECURSOR_TYPE_WESTRESIZE);
194 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthSouthResize, 194 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthSouthResize,
195 PP_CURSORTYPE_NORTHSOUTHRESIZE); 195 PP_MOUSECURSOR_TYPE_NORTHSOUTHRESIZE);
196 COMPILE_ASSERT_MATCHING_ENUM(TypeEastWestResize, PP_CURSORTYPE_EASTWESTRESIZE); 196 COMPILE_ASSERT_MATCHING_ENUM(TypeEastWestResize,
197 PP_MOUSECURSOR_TYPE_EASTWESTRESIZE);
197 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastSouthWestResize, 198 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastSouthWestResize,
198 PP_CURSORTYPE_NORTHEASTSOUTHWESTRESIZE); 199 PP_MOUSECURSOR_TYPE_NORTHEASTSOUTHWESTRESIZE);
199 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestSouthEastResize, 200 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestSouthEastResize,
200 PP_CURSORTYPE_NORTHWESTSOUTHEASTRESIZE); 201 PP_MOUSECURSOR_TYPE_NORTHWESTSOUTHEASTRESIZE);
201 COMPILE_ASSERT_MATCHING_ENUM(TypeColumnResize, PP_CURSORTYPE_COLUMNRESIZE); 202 COMPILE_ASSERT_MATCHING_ENUM(TypeColumnResize,
202 COMPILE_ASSERT_MATCHING_ENUM(TypeRowResize, PP_CURSORTYPE_ROWRESIZE); 203 PP_MOUSECURSOR_TYPE_COLUMNRESIZE);
203 COMPILE_ASSERT_MATCHING_ENUM(TypeMiddlePanning, PP_CURSORTYPE_MIDDLEPANNING); 204 COMPILE_ASSERT_MATCHING_ENUM(TypeRowResize, PP_MOUSECURSOR_TYPE_ROWRESIZE);
204 COMPILE_ASSERT_MATCHING_ENUM(TypeEastPanning, PP_CURSORTYPE_EASTPANNING); 205 COMPILE_ASSERT_MATCHING_ENUM(TypeMiddlePanning,
205 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthPanning, PP_CURSORTYPE_NORTHPANNING); 206 PP_MOUSECURSOR_TYPE_MIDDLEPANNING);
207 COMPILE_ASSERT_MATCHING_ENUM(TypeEastPanning, PP_MOUSECURSOR_TYPE_EASTPANNING);
208 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthPanning,
209 PP_MOUSECURSOR_TYPE_NORTHPANNING);
206 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastPanning, 210 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastPanning,
207 PP_CURSORTYPE_NORTHEASTPANNING); 211 PP_MOUSECURSOR_TYPE_NORTHEASTPANNING);
208 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestPanning, 212 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestPanning,
209 PP_CURSORTYPE_NORTHWESTPANNING); 213 PP_MOUSECURSOR_TYPE_NORTHWESTPANNING);
210 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthPanning, PP_CURSORTYPE_SOUTHPANNING); 214 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthPanning,
215 PP_MOUSECURSOR_TYPE_SOUTHPANNING);
211 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastPanning, 216 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastPanning,
212 PP_CURSORTYPE_SOUTHEASTPANNING); 217 PP_MOUSECURSOR_TYPE_SOUTHEASTPANNING);
213 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestPanning, 218 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestPanning,
214 PP_CURSORTYPE_SOUTHWESTPANNING); 219 PP_MOUSECURSOR_TYPE_SOUTHWESTPANNING);
215 COMPILE_ASSERT_MATCHING_ENUM(TypeWestPanning, PP_CURSORTYPE_WESTPANNING); 220 COMPILE_ASSERT_MATCHING_ENUM(TypeWestPanning, PP_MOUSECURSOR_TYPE_WESTPANNING);
216 COMPILE_ASSERT_MATCHING_ENUM(TypeMove, PP_CURSORTYPE_MOVE); 221 COMPILE_ASSERT_MATCHING_ENUM(TypeMove, PP_MOUSECURSOR_TYPE_MOVE);
217 COMPILE_ASSERT_MATCHING_ENUM(TypeVerticalText, PP_CURSORTYPE_VERTICALTEXT); 222 COMPILE_ASSERT_MATCHING_ENUM(TypeVerticalText,
218 COMPILE_ASSERT_MATCHING_ENUM(TypeCell, PP_CURSORTYPE_CELL); 223 PP_MOUSECURSOR_TYPE_VERTICALTEXT);
219 COMPILE_ASSERT_MATCHING_ENUM(TypeContextMenu, PP_CURSORTYPE_CONTEXTMENU); 224 COMPILE_ASSERT_MATCHING_ENUM(TypeCell, PP_MOUSECURSOR_TYPE_CELL);
220 COMPILE_ASSERT_MATCHING_ENUM(TypeAlias, PP_CURSORTYPE_ALIAS); 225 COMPILE_ASSERT_MATCHING_ENUM(TypeContextMenu, PP_MOUSECURSOR_TYPE_CONTEXTMENU);
221 COMPILE_ASSERT_MATCHING_ENUM(TypeProgress, PP_CURSORTYPE_PROGRESS); 226 COMPILE_ASSERT_MATCHING_ENUM(TypeAlias, PP_MOUSECURSOR_TYPE_ALIAS);
222 COMPILE_ASSERT_MATCHING_ENUM(TypeNoDrop, PP_CURSORTYPE_NODROP); 227 COMPILE_ASSERT_MATCHING_ENUM(TypeProgress, PP_MOUSECURSOR_TYPE_PROGRESS);
223 COMPILE_ASSERT_MATCHING_ENUM(TypeCopy, PP_CURSORTYPE_COPY); 228 COMPILE_ASSERT_MATCHING_ENUM(TypeNoDrop, PP_MOUSECURSOR_TYPE_NODROP);
224 COMPILE_ASSERT_MATCHING_ENUM(TypeNone, PP_CURSORTYPE_NONE); 229 COMPILE_ASSERT_MATCHING_ENUM(TypeCopy, PP_MOUSECURSOR_TYPE_COPY);
225 COMPILE_ASSERT_MATCHING_ENUM(TypeNotAllowed, PP_CURSORTYPE_NOTALLOWED); 230 COMPILE_ASSERT_MATCHING_ENUM(TypeNone, PP_MOUSECURSOR_TYPE_NONE);
226 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomIn, PP_CURSORTYPE_ZOOMIN); 231 COMPILE_ASSERT_MATCHING_ENUM(TypeNotAllowed, PP_MOUSECURSOR_TYPE_NOTALLOWED);
227 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomOut, PP_CURSORTYPE_ZOOMOUT); 232 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomIn, PP_MOUSECURSOR_TYPE_ZOOMIN);
228 COMPILE_ASSERT_MATCHING_ENUM(TypeGrab, PP_CURSORTYPE_GRAB); 233 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomOut, PP_MOUSECURSOR_TYPE_ZOOMOUT);
229 COMPILE_ASSERT_MATCHING_ENUM(TypeGrabbing, PP_CURSORTYPE_GRABBING); 234 COMPILE_ASSERT_MATCHING_ENUM(TypeGrab, PP_MOUSECURSOR_TYPE_GRAB);
235 COMPILE_ASSERT_MATCHING_ENUM(TypeGrabbing, PP_MOUSECURSOR_TYPE_GRABBING);
230 // Do not assert WebCursorInfo::TypeCustom == PP_CURSORTYPE_CUSTOM; 236 // Do not assert WebCursorInfo::TypeCustom == PP_CURSORTYPE_CUSTOM;
231 // PP_CURSORTYPE_CUSTOM is pinned to allow new cursor types. 237 // PP_CURSORTYPE_CUSTOM is pinned to allow new cursor types.
232 238
233 // Sets |*security_origin| to be the WebKit security origin associated with the 239 // Sets |*security_origin| to be the WebKit security origin associated with the
234 // document containing the given plugin instance. On success, returns true. If 240 // document containing the given plugin instance. On success, returns true. If
235 // the instance is invalid, returns false and |*security_origin| will be 241 // the instance is invalid, returns false and |*security_origin| will be
236 // unchanged. 242 // unchanged.
237 bool SecurityOriginForInstance(PP_Instance instance_id, 243 bool SecurityOriginForInstance(PP_Instance instance_id,
238 WebKit::WebSecurityOrigin* security_origin) { 244 WebKit::WebSecurityOrigin* security_origin) {
239 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); 245 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 448
443 // Free any associated graphics. 449 // Free any associated graphics.
444 SetFullscreen(false); 450 SetFullscreen(false);
445 FlashSetFullscreen(false, false); 451 FlashSetFullscreen(false, false);
446 bound_graphics_ = NULL; 452 bound_graphics_ = NULL;
447 InvalidateRect(gfx::Rect()); 453 InvalidateRect(gfx::Rect());
448 454
449 delegate()->PluginCrashed(this); 455 delegate()->PluginCrashed(this);
450 } 456 }
451 457
452 bool PluginInstance::SetCursor(PP_CursorType_Dev type,
453 PP_Resource custom_image,
454 const PP_Point* hot_spot) {
455 if (type != PP_CURSORTYPE_CUSTOM) {
456 DoSetCursor(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type)));
457 return true;
458 }
459
460 if (!hot_spot)
461 return false;
462
463 EnterResourceNoLock<PPB_ImageData_API> enter(custom_image, true);
464 if (enter.failed())
465 return false;
466 PPB_ImageData_Impl* image_data =
467 static_cast<PPB_ImageData_Impl*>(enter.object());
468
469 if (image_data->format() != PPB_ImageData_Impl::GetNativeImageDataFormat()) {
470 // TODO(yzshen): Handle the case that the image format is different from the
471 // native format.
472 NOTIMPLEMENTED();
473 return false;
474 }
475
476 ImageDataAutoMapper auto_mapper(image_data);
477 if (!auto_mapper.is_valid())
478 return false;
479
480 scoped_ptr<WebCursorInfo> custom_cursor(
481 new WebCursorInfo(WebCursorInfo::TypeCustom));
482 custom_cursor->hotSpot.x = hot_spot->x;
483 custom_cursor->hotSpot.y = hot_spot->y;
484
485 #if WEBKIT_USING_SKIA
486 const SkBitmap* bitmap = image_data->GetMappedBitmap();
487 // Make a deep copy, so that the cursor remains valid even after the original
488 // image data gets freed.
489 if (!bitmap->copyTo(&custom_cursor->customImage.getSkBitmap(),
490 bitmap->config())) {
491 return false;
492 }
493 #elif WEBKIT_USING_CG
494 // TODO(yzshen): Implement it.
495 NOTIMPLEMENTED();
496 return false;
497 #endif
498
499 DoSetCursor(custom_cursor.release());
500 return true;
501 }
502
503 bool PluginInstance::Initialize(WebPluginContainer* container, 458 bool PluginInstance::Initialize(WebPluginContainer* container,
504 const std::vector<std::string>& arg_names, 459 const std::vector<std::string>& arg_names,
505 const std::vector<std::string>& arg_values, 460 const std::vector<std::string>& arg_values,
506 const GURL& plugin_url, 461 const GURL& plugin_url,
507 bool full_frame) { 462 bool full_frame) {
508 container_ = container; 463 container_ = container;
509 plugin_url_ = plugin_url; 464 plugin_url_ = plugin_url;
510 full_frame_ = full_frame; 465 full_frame_ = full_frame;
511 466
512 size_t argc = 0; 467 size_t argc = 0;
(...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 NOTREACHED(); 1972 NOTREACHED();
2018 return; 1973 return;
2019 } 1974 }
2020 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); 1975 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor);
2021 } 1976 }
2022 1977
2023 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) { 1978 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) {
2024 message_channel_->PostMessageToJavaScript(message); 1979 message_channel_->PostMessageToJavaScript(message);
2025 } 1980 }
2026 1981
1982 PP_Bool PluginInstance::SetCursor(PP_Instance instance,
1983 PP_MouseCursor_Type type,
1984 PP_Resource image,
1985 const PP_Point* hot_spot) {
1986 if (!ValidateSetCursorParams(type, image, hot_spot))
1987 return PP_FALSE;
1988
1989 if (type != PP_MOUSECURSOR_TYPE_CUSTOM) {
1990 DoSetCursor(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type)));
1991 return PP_TRUE;
1992 }
1993
1994 EnterResourceNoLock<PPB_ImageData_API> enter(image, true);
1995 if (enter.failed())
1996 return PP_FALSE;
1997 PPB_ImageData_Impl* image_data =
1998 static_cast<PPB_ImageData_Impl*>(enter.object());
1999
2000 ImageDataAutoMapper auto_mapper(image_data);
2001 if (!auto_mapper.is_valid())
2002 return PP_FALSE;
2003
2004 scoped_ptr<WebCursorInfo> custom_cursor(
2005 new WebCursorInfo(WebCursorInfo::TypeCustom));
2006 custom_cursor->hotSpot.x = hot_spot->x;
2007 custom_cursor->hotSpot.y = hot_spot->y;
2008
2009 #if WEBKIT_USING_SKIA
2010 const SkBitmap* bitmap = image_data->GetMappedBitmap();
2011 // Make a deep copy, so that the cursor remains valid even after the original
2012 // image data gets freed.
2013 if (!bitmap->copyTo(&custom_cursor->customImage.getSkBitmap(),
2014 bitmap->config())) {
2015 return PP_FALSE;
2016 }
2017 #elif WEBKIT_USING_CG
2018 // TODO(yzshen): Implement it.
2019 NOTIMPLEMENTED();
2020 return false;
2021 #endif
2022
2023 DoSetCursor(custom_cursor.release());
2024 return PP_TRUE;
2025 }
2026
2027 int32_t PluginInstance::LockMouse(PP_Instance instance, 2027 int32_t PluginInstance::LockMouse(PP_Instance instance,
2028 PP_CompletionCallback callback) { 2028 PP_CompletionCallback callback) {
2029 if (!callback.func) { 2029 if (!callback.func) {
2030 // Don't support synchronous call. 2030 // Don't support synchronous call.
2031 return PP_ERROR_BLOCKS_MAIN_THREAD; 2031 return PP_ERROR_BLOCKS_MAIN_THREAD;
2032 } 2032 }
2033 if (lock_mouse_callback_.func) // A lock is pending. 2033 if (lock_mouse_callback_.func) // A lock is pending.
2034 return PP_ERROR_INPROGRESS; 2034 return PP_ERROR_INPROGRESS;
2035 2035
2036 if (delegate()->IsMouseLocked(this)) 2036 if (delegate()->IsMouseLocked(this))
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2172 screen_size_for_fullscreen_ = gfx::Size(); 2172 screen_size_for_fullscreen_ = gfx::Size();
2173 WebElement element = container_->element(); 2173 WebElement element = container_->element();
2174 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2174 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2175 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2175 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2176 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2176 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2177 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2177 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2178 } 2178 }
2179 2179
2180 } // namespace ppapi 2180 } // namespace ppapi
2181 } // namespace webkit 2181 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | webkit/plugins/ppapi/ppb_cursor_control_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698