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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 if (!graphics_3d->BindToInstance(true)) 537 if (!graphics_3d->BindToInstance(true))
538 return false; 538 return false;
539 539
540 setBackingTextureId(graphics_3d->GetBackingTextureId()); 540 setBackingTextureId(graphics_3d->GetBackingTextureId());
541 bound_graphics_ = graphics_3d; 541 bound_graphics_ = graphics_3d;
542 } 542 }
543 543
544 return true; 544 return true;
545 } 545 }
546 546
547 bool PluginInstance::SetCursor(PP_CursorType_Dev type) { 547 bool PluginInstance::SetCursor(PP_CursorType_Dev type,
548 if (type == PP_CURSORTYPE_CUSTOM) { 548 PP_Resource custom_image,
549 // TODO(neb): implement custom cursors. 549 const PP_Point* hot_spot) {
550 // (Remember that PP_CURSORTYPE_CUSTOM != WebCursorInfo::TypeCustom.) 550 if (type != PP_CURSORTYPE_CUSTOM) {
551 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type)));
552 return true;
553 }
554
555 if (!hot_spot)
556 return false;
557
558 scoped_refptr<PPB_ImageData_Impl> image_data(
559 Resource::GetAs<PPB_ImageData_Impl>(custom_image));
560 if (!image_data.get())
561 return false;
562
563 if (image_data->format() != PPB_ImageData_Impl::GetNativeImageDataFormat()) {
564 // TODO(yzshen): Handle the case that the image format is different from the
565 // native format.
551 NOTIMPLEMENTED(); 566 NOTIMPLEMENTED();
552 return false; 567 return false;
553 } 568 }
554 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); 569
570 ImageDataAutoMapper auto_mapper(image_data);
571 if (!auto_mapper.is_valid())
572 return false;
573
574 scoped_ptr<WebCursorInfo> custom_cursor(
575 new WebCursorInfo(WebCursorInfo::TypeCustom));
576 custom_cursor->hotSpot.x = hot_spot->x;
577 custom_cursor->hotSpot.y = hot_spot->y;
578
579 #if WEBKIT_USING_SKIA
580 const SkBitmap* bitmap = image_data->GetMappedBitmap();
581 // Make a deep copy, so that the cursor remains valid even after the original
582 // image data gets freed.
583 if (!bitmap->copyTo(&custom_cursor->customImage.getSkBitmap(),
584 bitmap->config())) {
585 return false;
586 }
587 #elif WEBKIT_USING_CG
588 // TODO(yzshen): Implement it.
589 NOTIMPLEMENTED();
590 return false;
591 #endif
592
593 cursor_.reset(custom_cursor.release());
555 return true; 594 return true;
556 } 595 }
557 596
558 PP_Var PluginInstance::ExecuteScript(PP_Var script, PP_Var* exception) { 597 PP_Var PluginInstance::ExecuteScript(PP_Var script, PP_Var* exception) {
559 TryCatch try_catch(module(), exception); 598 TryCatch try_catch(module(), exception);
560 if (try_catch.has_exception()) 599 if (try_catch.has_exception())
561 return PP_MakeUndefined(); 600 return PP_MakeUndefined();
562 601
563 // Convert the script into an inconvenient NPString object. 602 // Convert the script into an inconvenient NPString object.
564 scoped_refptr<StringVar> script_string(StringVar::FromPPVar(script)); 603 scoped_refptr<StringVar> script_string(StringVar::FromPPVar(script));
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 return found->second; 1394 return found->second;
1356 } 1395 }
1357 1396
1358 bool PluginInstance::IsFullPagePlugin() const { 1397 bool PluginInstance::IsFullPagePlugin() const {
1359 WebFrame* frame = container()->element().document().frame(); 1398 WebFrame* frame = container()->element().document().frame();
1360 return frame->view()->mainFrame()->document().isPluginDocument(); 1399 return frame->view()->mainFrame()->document().isPluginDocument();
1361 } 1400 }
1362 1401
1363 } // namespace ppapi 1402 } // namespace ppapi
1364 } // namespace webkit 1403 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698