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

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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 442
443 // Free any associated graphics. 443 // Free any associated graphics.
444 SetFullscreen(false); 444 SetFullscreen(false);
445 FlashSetFullscreen(false, false); 445 FlashSetFullscreen(false, false);
446 bound_graphics_ = NULL; 446 bound_graphics_ = NULL;
447 InvalidateRect(gfx::Rect()); 447 InvalidateRect(gfx::Rect());
448 448
449 delegate()->PluginCrashed(this); 449 delegate()->PluginCrashed(this);
450 } 450 }
451 451
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, 452 bool PluginInstance::Initialize(WebPluginContainer* container,
504 const std::vector<std::string>& arg_names, 453 const std::vector<std::string>& arg_names,
505 const std::vector<std::string>& arg_values, 454 const std::vector<std::string>& arg_values,
506 const GURL& plugin_url, 455 const GURL& plugin_url,
507 bool full_frame) { 456 bool full_frame) {
508 container_ = container; 457 container_ = container;
509 plugin_url_ = plugin_url; 458 plugin_url_ = plugin_url;
510 full_frame_ = full_frame; 459 full_frame_ = full_frame;
511 460
512 size_t argc = 0; 461 size_t argc = 0;
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 NOTREACHED(); 1962 NOTREACHED();
2014 return; 1963 return;
2015 } 1964 }
2016 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); 1965 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor);
2017 } 1966 }
2018 1967
2019 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) { 1968 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) {
2020 message_channel_->PostMessageToJavaScript(message); 1969 message_channel_->PostMessageToJavaScript(message);
2021 } 1970 }
2022 1971
1972 PP_Bool PluginInstance::SetCursor(PP_Instance instance,
1973 PP_MouseCursor_Type type,
1974 PP_Resource image,
1975 const PP_Point* hot_spot) {
1976 if (!ValidateSetCursorParams(type, image, hot_spot))
1977 return PP_FALSE;
1978
1979 if (type != PP_CURSORTYPE_CUSTOM) {
1980 DoSetCursor(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type)));
dmichael (off chromium) 2012/03/26 17:43:17 Would it be possible to have a test or something t
brettw 2012/03/27 05:17:19 There were already compiler asserts for this in pp
1981 return PP_TRUE;
1982 }
1983
1984 EnterResourceNoLock<PPB_ImageData_API> enter(image, true);
1985 if (enter.failed())
1986 return PP_FALSE;
1987 PPB_ImageData_Impl* image_data =
1988 static_cast<PPB_ImageData_Impl*>(enter.object());
1989
1990 ImageDataAutoMapper auto_mapper(image_data);
1991 if (!auto_mapper.is_valid())
1992 return PP_FALSE;
1993
1994 scoped_ptr<WebCursorInfo> custom_cursor(
1995 new WebCursorInfo(WebCursorInfo::TypeCustom));
1996 custom_cursor->hotSpot.x = hot_spot->x;
1997 custom_cursor->hotSpot.y = hot_spot->y;
1998
1999 #if WEBKIT_USING_SKIA
2000 const SkBitmap* bitmap = image_data->GetMappedBitmap();
2001 // Make a deep copy, so that the cursor remains valid even after the original
2002 // image data gets freed.
2003 if (!bitmap->copyTo(&custom_cursor->customImage.getSkBitmap(),
2004 bitmap->config())) {
2005 return PP_FALSE;
2006 }
2007 #elif WEBKIT_USING_CG
2008 // TODO(yzshen): Implement it.
2009 NOTIMPLEMENTED();
2010 return false;
2011 #endif
2012
2013 DoSetCursor(custom_cursor.release());
2014 return PP_TRUE;
2015 }
2016
2023 int32_t PluginInstance::LockMouse(PP_Instance instance, 2017 int32_t PluginInstance::LockMouse(PP_Instance instance,
2024 PP_CompletionCallback callback) { 2018 PP_CompletionCallback callback) {
2025 if (!callback.func) { 2019 if (!callback.func) {
2026 // Don't support synchronous call. 2020 // Don't support synchronous call.
2027 return PP_ERROR_BLOCKS_MAIN_THREAD; 2021 return PP_ERROR_BLOCKS_MAIN_THREAD;
2028 } 2022 }
2029 if (lock_mouse_callback_.func) // A lock is pending. 2023 if (lock_mouse_callback_.func) // A lock is pending.
2030 return PP_ERROR_INPROGRESS; 2024 return PP_ERROR_INPROGRESS;
2031 2025
2032 if (delegate()->IsMouseLocked(this)) 2026 if (delegate()->IsMouseLocked(this))
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2168 screen_size_for_fullscreen_ = gfx::Size(); 2162 screen_size_for_fullscreen_ = gfx::Size();
2169 WebElement element = container_->element(); 2163 WebElement element = container_->element();
2170 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2164 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2171 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2165 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2172 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2166 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2173 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2167 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2174 } 2168 }
2175 2169
2176 } // namespace ppapi 2170 } // namespace ppapi
2177 } // namespace webkit 2171 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698