diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-08 02:48:13 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-08 02:48:13 +0000 |
commit | d53d0aaae59bac04b4c800611ccdaff5ac1825a8 (patch) | |
tree | a70a78e79955d58bbcc76e1a0e5b7d0a4103f574 /webkit | |
parent | 5c820ad84320c9a07dd81844b1eefa7d73f19501 (diff) | |
download | chromium_src-d53d0aaae59bac04b4c800611ccdaff5ac1825a8.zip chromium_src-d53d0aaae59bac04b4c800611ccdaff5ac1825a8.tar.gz chromium_src-d53d0aaae59bac04b4c800611ccdaff5ac1825a8.tar.bz2 |
Chrome side of Pepper v2 scrollbar widget.
Review URL: http://codereview.chromium.org/2884016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51818 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/plugins/pepper_event_conversion.cc | 235 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_event_conversion.h | 26 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_instance.cc | 110 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.cc | 8 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_resource.h | 6 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_scrollbar.cc | 228 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_scrollbar.h | 64 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_widget.cc | 90 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_widget.h | 53 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 6 |
10 files changed, 726 insertions, 100 deletions
diff --git a/webkit/glue/plugins/pepper_event_conversion.cc b/webkit/glue/plugins/pepper_event_conversion.cc new file mode 100644 index 0000000..8ffa5e0 --- /dev/null +++ b/webkit/glue/plugins/pepper_event_conversion.cc @@ -0,0 +1,235 @@ +// Copyright (c) 2010 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. + +#include "webkit/glue/plugins/pepper_event_conversion.h" + +#include "base/logging.h" +#include "base/scoped_ptr.h" +#include "third_party/ppapi/c/pp_event.h" +#include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" + +using WebKit::WebInputEvent; +using WebKit::WebKeyboardEvent; +using WebKit::WebMouseEvent; +using WebKit::WebMouseWheelEvent; + +namespace { +// Anonymous namespace for functions converting WebInputEvent to PP_Event and +// back. +PP_Event_Type ConvertEventTypes(WebInputEvent::Type wetype) { + switch (wetype) { + case WebInputEvent::MouseDown: + return PP_Event_Type_MouseDown; + case WebInputEvent::MouseUp: + return PP_Event_Type_MouseUp; + case WebInputEvent::MouseMove: + return PP_Event_Type_MouseMove; + case WebInputEvent::MouseEnter: + return PP_Event_Type_MouseEnter; + case WebInputEvent::MouseLeave: + return PP_Event_Type_MouseLeave; + case WebInputEvent::MouseWheel: + return PP_Event_Type_MouseWheel; + case WebInputEvent::RawKeyDown: + return PP_Event_Type_RawKeyDown; + case WebInputEvent::KeyDown: + return PP_Event_Type_KeyDown; + case WebInputEvent::KeyUp: + return PP_Event_Type_KeyUp; + case WebInputEvent::Char: + return PP_Event_Type_Char; + case WebInputEvent::Undefined: + default: + return PP_Event_Type_Undefined; + } +} + +void BuildKeyEvent(const WebInputEvent* event, PP_Event* pp_event) { + const WebKeyboardEvent* key_event = + reinterpret_cast<const WebKeyboardEvent*>(event); + pp_event->u.key.modifier = key_event->modifiers; + pp_event->u.key.normalizedKeyCode = key_event->windowsKeyCode; +} + +void BuildCharEvent(const WebInputEvent* event, PP_Event* pp_event) { + const WebKeyboardEvent* key_event = + reinterpret_cast<const WebKeyboardEvent*>(event); + pp_event->u.character.modifier = key_event->modifiers; + // For consistency, check that the sizes of the texts agree. + DCHECK(sizeof(pp_event->u.character.text) == sizeof(key_event->text)); + DCHECK(sizeof(pp_event->u.character.unmodifiedText) == + sizeof(key_event->unmodifiedText)); + for (size_t i = 0; i < WebKeyboardEvent::textLengthCap; ++i) { + pp_event->u.character.text[i] = key_event->text[i]; + pp_event->u.character.unmodifiedText[i] = key_event->unmodifiedText[i]; + } +} + +void BuildMouseEvent(const WebInputEvent* event, PP_Event* pp_event) { + const WebMouseEvent* mouse_event = + reinterpret_cast<const WebMouseEvent*>(event); + pp_event->u.mouse.modifier = mouse_event->modifiers; + pp_event->u.mouse.button = mouse_event->button; + pp_event->u.mouse.x = mouse_event->x; + pp_event->u.mouse.y = mouse_event->y; + pp_event->u.mouse.clickCount = mouse_event->clickCount; +} + +void BuildMouseWheelEvent(const WebInputEvent* event, PP_Event* pp_event) { + const WebMouseWheelEvent* mouse_wheel_event = + reinterpret_cast<const WebMouseWheelEvent*>(event); + pp_event->u.wheel.modifier = mouse_wheel_event->modifiers; + pp_event->u.wheel.deltaX = mouse_wheel_event->deltaX; + pp_event->u.wheel.deltaY = mouse_wheel_event->deltaY; + pp_event->u.wheel.wheelTicksX = mouse_wheel_event->wheelTicksX; + pp_event->u.wheel.wheelTicksY = mouse_wheel_event->wheelTicksY; + pp_event->u.wheel.scrollByPage = mouse_wheel_event->scrollByPage; +} + + +WebKeyboardEvent* BuildKeyEvent(const PP_Event& event) { + WebKeyboardEvent* key_event = new WebKeyboardEvent(); + switch (event.type) { + case PP_Event_Type_RawKeyDown: + key_event->type = WebInputEvent::RawKeyDown; + break; + case PP_Event_Type_KeyDown: + key_event->type = WebInputEvent::KeyDown; + break; + case PP_Event_Type_KeyUp: + key_event->type = WebInputEvent::KeyUp; + break; + } + key_event->timeStampSeconds = event.time_stamp_seconds; + key_event->modifiers = event.u.key.modifier; + key_event->windowsKeyCode = event.u.key.normalizedKeyCode; + return key_event; +} + +WebKeyboardEvent* BuildCharEvent(const PP_Event& event) { + WebKeyboardEvent* key_event = new WebKeyboardEvent(); + key_event->type = WebInputEvent::Char; + key_event->timeStampSeconds = event.time_stamp_seconds; + key_event->modifiers = event.u.character.modifier; + // For consistency, check that the sizes of the texts agree. + DCHECK(sizeof(event.u.character.text) == sizeof(key_event->text)); + DCHECK(sizeof(event.u.character.unmodifiedText) == + sizeof(key_event->unmodifiedText)); + for (size_t i = 0; i < WebKeyboardEvent::textLengthCap; ++i) { + key_event->text[i] = event.u.character.text[i]; + key_event->unmodifiedText[i] = event.u.character.unmodifiedText[i]; + } + return key_event; +} + +WebMouseEvent* BuildMouseEvent(const PP_Event& event) { + WebMouseEvent* mouse_event = new WebMouseEvent(); + switch (event.type) { + case PP_Event_Type_MouseDown: + mouse_event->type = WebInputEvent::MouseDown; + break; + case PP_Event_Type_MouseUp: + mouse_event->type = WebInputEvent::MouseUp; + break; + case PP_Event_Type_MouseMove: + mouse_event->type = WebInputEvent::MouseMove; + break; + case PP_Event_Type_MouseEnter: + mouse_event->type = WebInputEvent::MouseEnter; + break; + case PP_Event_Type_MouseLeave: + mouse_event->type = WebInputEvent::MouseLeave; + break; + } + mouse_event->timeStampSeconds = event.time_stamp_seconds; + mouse_event->modifiers = event.u.mouse.modifier; + mouse_event->button = + static_cast<WebMouseEvent::Button>(event.u.mouse.button); + mouse_event->x = event.u.mouse.x; + mouse_event->y = event.u.mouse.y; + mouse_event->clickCount = event.u.mouse.clickCount; + return mouse_event; +} + +WebMouseWheelEvent* BuildMouseWheelEvent(const PP_Event& event) { + WebMouseWheelEvent* mouse_wheel_event = new WebMouseWheelEvent(); + mouse_wheel_event->type = WebInputEvent::MouseWheel; + mouse_wheel_event->timeStampSeconds = event.time_stamp_seconds; + mouse_wheel_event->modifiers = event.u.wheel.modifier; + mouse_wheel_event->deltaX = event.u.wheel.deltaX; + mouse_wheel_event->deltaY = event.u.wheel.deltaY; + mouse_wheel_event->wheelTicksX = event.u.wheel.wheelTicksX; + mouse_wheel_event->wheelTicksY = event.u.wheel.wheelTicksY; + mouse_wheel_event->scrollByPage = event.u.wheel.scrollByPage; + return mouse_wheel_event; +} + +} // namespace + +namespace pepper { + +PP_Event* CreatePP_Event(const WebInputEvent& event) { + scoped_ptr<PP_Event> pp_event(new PP_Event); + + pp_event->type = ConvertEventTypes(event.type); + pp_event->size = sizeof(pp_event); + pp_event->time_stamp_seconds = event.timeStampSeconds; + switch (pp_event->type) { + case PP_Event_Type_Undefined: + return NULL; + case PP_Event_Type_MouseDown: + case PP_Event_Type_MouseUp: + case PP_Event_Type_MouseMove: + case PP_Event_Type_MouseEnter: + case PP_Event_Type_MouseLeave: + BuildMouseEvent(&event, pp_event.get()); + break; + case PP_Event_Type_MouseWheel: + BuildMouseWheelEvent(&event, pp_event.get()); + break; + case PP_Event_Type_RawKeyDown: + case PP_Event_Type_KeyDown: + case PP_Event_Type_KeyUp: + BuildKeyEvent(&event, pp_event.get()); + break; + case PP_Event_Type_Char: + BuildCharEvent(&event, pp_event.get()); + break; + } + + return pp_event.release(); +} + +WebInputEvent* CreateWebInputEvent(const PP_Event& event) { + scoped_ptr<WebInputEvent> web_input_event; + switch (event.type) { + case PP_Event_Type_Undefined: + return NULL; + case PP_Event_Type_MouseDown: + case PP_Event_Type_MouseUp: + case PP_Event_Type_MouseMove: + case PP_Event_Type_MouseEnter: + case PP_Event_Type_MouseLeave: + web_input_event.reset(BuildMouseEvent(event)); + break; + case PP_Event_Type_MouseWheel: + web_input_event.reset(BuildMouseWheelEvent(event)); + break; + case PP_Event_Type_RawKeyDown: + case PP_Event_Type_KeyDown: + case PP_Event_Type_KeyUp: + web_input_event.reset(BuildKeyEvent(event)); + break; + case PP_Event_Type_Char: + web_input_event.reset(BuildCharEvent(event)); + break; + case PP_Event_Type_Focus: + // NOTIMPLEMENTED(); + return NULL; + } + + return web_input_event.release(); +} + +} // namespace pepper diff --git a/webkit/glue/plugins/pepper_event_conversion.h b/webkit/glue/plugins/pepper_event_conversion.h new file mode 100644 index 0000000..2d699cd --- /dev/null +++ b/webkit/glue/plugins/pepper_event_conversion.h @@ -0,0 +1,26 @@ +// Copyright (c) 2010 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. + +#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_EVENT_H_ +#define WEBKIT_GLUE_PLUGINS_PEPPER_EVENT_H_ + +typedef struct _pp_Event PP_Event; + +namespace WebKit { +class WebInputEvent; +} + +namespace pepper { + +// Creates a PP_Event from the given WebInputEvent. If it fails, returns NULL. +// The caller owns the created object on success. +PP_Event* CreatePP_Event(const WebKit::WebInputEvent& event); + +// Creates a WebInputEvent from the given PP_Event. If it fails, returns NULL. +// The caller owns the created object on success. +WebKit::WebInputEvent* CreateWebInputEvent(const PP_Event& event); + +} // namespace pepper + +#endif // WEBKIT_GLUE_PLUGINS_PEPPER_EVENT_H_ diff --git a/webkit/glue/plugins/pepper_plugin_instance.cc b/webkit/glue/plugins/pepper_plugin_instance.cc index 5f054ee..65863f1 100644 --- a/webkit/glue/plugins/pepper_plugin_instance.cc +++ b/webkit/glue/plugins/pepper_plugin_instance.cc @@ -21,11 +21,14 @@ #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" #include "webkit/glue/plugins/pepper_device_context_2d.h" +#include "webkit/glue/plugins/pepper_event_conversion.h" #include "webkit/glue/plugins/pepper_plugin_delegate.h" #include "webkit/glue/plugins/pepper_plugin_module.h" #include "webkit/glue/plugins/pepper_url_loader.h" #include "webkit/glue/plugins/pepper_var.h" +using WebKit::WebCanvas; +using WebKit::WebCursorInfo; using WebKit::WebFrame; using WebKit::WebInputEvent; using WebKit::WebPluginContainer; @@ -39,76 +42,6 @@ void RectToPPRect(const gfx::Rect& input, PP_Rect* output) { input.width(), input.height()); } -PP_Event_Type ConvertEventTypes(WebInputEvent::Type wetype) { - switch (wetype) { - case WebInputEvent::MouseDown: - return PP_Event_Type_MouseDown; - case WebInputEvent::MouseUp: - return PP_Event_Type_MouseUp; - case WebInputEvent::MouseMove: - return PP_Event_Type_MouseMove; - case WebInputEvent::MouseEnter: - return PP_Event_Type_MouseEnter; - case WebInputEvent::MouseLeave: - return PP_Event_Type_MouseLeave; - case WebInputEvent::MouseWheel: - return PP_Event_Type_MouseWheel; - case WebInputEvent::RawKeyDown: - return PP_Event_Type_RawKeyDown; - case WebInputEvent::KeyDown: - return PP_Event_Type_KeyDown; - case WebInputEvent::KeyUp: - return PP_Event_Type_KeyUp; - case WebInputEvent::Char: - return PP_Event_Type_Char; - case WebInputEvent::Undefined: - default: - return PP_Event_Type_Undefined; - } -} - -void BuildKeyEvent(const WebInputEvent* event, PP_Event* pp_event) { - const WebKit::WebKeyboardEvent* key_event = - reinterpret_cast<const WebKit::WebKeyboardEvent*>(event); - pp_event->u.key.modifier = key_event->modifiers; - pp_event->u.key.normalizedKeyCode = key_event->windowsKeyCode; -} - -void BuildCharEvent(const WebInputEvent* event, PP_Event* pp_event) { - const WebKit::WebKeyboardEvent* key_event = - reinterpret_cast<const WebKit::WebKeyboardEvent*>(event); - pp_event->u.character.modifier = key_event->modifiers; - // For consistency, check that the sizes of the texts agree. - DCHECK(sizeof(pp_event->u.character.text) == sizeof(key_event->text)); - DCHECK(sizeof(pp_event->u.character.unmodifiedText) == - sizeof(key_event->unmodifiedText)); - for (size_t i = 0; i < WebKit::WebKeyboardEvent::textLengthCap; ++i) { - pp_event->u.character.text[i] = key_event->text[i]; - pp_event->u.character.unmodifiedText[i] = key_event->unmodifiedText[i]; - } -} - -void BuildMouseEvent(const WebInputEvent* event, PP_Event* pp_event) { - const WebKit::WebMouseEvent* mouse_event = - reinterpret_cast<const WebKit::WebMouseEvent*>(event); - pp_event->u.mouse.modifier = mouse_event->modifiers; - pp_event->u.mouse.button = mouse_event->button; - pp_event->u.mouse.x = mouse_event->x; - pp_event->u.mouse.y = mouse_event->y; - pp_event->u.mouse.clickCount = mouse_event->clickCount; -} - -void BuildMouseWheelEvent(const WebInputEvent* event, PP_Event* pp_event) { - const WebKit::WebMouseWheelEvent* mouse_wheel_event = - reinterpret_cast<const WebKit::WebMouseWheelEvent*>(event); - pp_event->u.wheel.modifier = mouse_wheel_event->modifiers; - pp_event->u.wheel.deltaX = mouse_wheel_event->deltaX; - pp_event->u.wheel.deltaY = mouse_wheel_event->deltaY; - pp_event->u.wheel.wheelTicksX = mouse_wheel_event->wheelTicksX; - pp_event->u.wheel.wheelTicksY = mouse_wheel_event->wheelTicksY; - pp_event->u.wheel.scrollByPage = mouse_wheel_event->scrollByPage; -} - PP_Var GetWindowObject(PP_Instance instance_id) { PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); if (!instance) @@ -178,7 +111,7 @@ PP_Instance PluginInstance::GetPPInstance() { return reinterpret_cast<intptr_t>(this); } -void PluginInstance::Paint(WebKit::WebCanvas* canvas, +void PluginInstance::Paint(WebCanvas* canvas, const gfx::Rect& plugin_rect, const gfx::Rect& paint_rect) { if (device_context_2d_) @@ -271,35 +204,12 @@ bool PluginInstance::HandleDocumentLoad(URLLoader* loader) { } bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, - WebKit::WebCursorInfo* cursor_info) { - PP_Event pp_event; - - pp_event.type = ConvertEventTypes(event.type); - pp_event.size = sizeof(pp_event); - pp_event.time_stamp_seconds = event.timeStampSeconds; - switch (pp_event.type) { - case PP_Event_Type_Undefined: - return false; - case PP_Event_Type_MouseDown: - case PP_Event_Type_MouseUp: - case PP_Event_Type_MouseMove: - case PP_Event_Type_MouseEnter: - case PP_Event_Type_MouseLeave: - BuildMouseEvent(&event, &pp_event); - break; - case PP_Event_Type_MouseWheel: - BuildMouseWheelEvent(&event, &pp_event); - break; - case PP_Event_Type_RawKeyDown: - case PP_Event_Type_KeyDown: - case PP_Event_Type_KeyUp: - BuildKeyEvent(&event, &pp_event); - break; - case PP_Event_Type_Char: - BuildCharEvent(&event, &pp_event); - break; - } - return instance_interface_->HandleEvent(GetPPInstance(), &pp_event); + WebCursorInfo* cursor_info) { + scoped_ptr<PP_Event> pp_event(CreatePP_Event(event)); + if (!pp_event.get()) + return false; + + return instance_interface_->HandleEvent(GetPPInstance(), pp_event.get()); } PP_Var PluginInstance::GetInstanceObject() { diff --git a/webkit/glue/plugins/pepper_plugin_module.cc b/webkit/glue/plugins/pepper_plugin_module.cc index 3a63384..7eecfb6 100644 --- a/webkit/glue/plugins/pepper_plugin_module.cc +++ b/webkit/glue/plugins/pepper_plugin_module.cc @@ -20,11 +20,13 @@ #include "third_party/ppapi/c/ppb_file_system.h" #include "third_party/ppapi/c/ppb_image_data.h" #include "third_party/ppapi/c/ppb_instance.h" +#include "third_party/ppapi/c/ppb_scrollbar.h" #include "third_party/ppapi/c/ppb_testing.h" #include "third_party/ppapi/c/ppb_url_loader.h" #include "third_party/ppapi/c/ppb_url_request_info.h" #include "third_party/ppapi/c/ppb_url_response_info.h" #include "third_party/ppapi/c/ppb_var.h" +#include "third_party/ppapi/c/ppb_widget.h" #include "third_party/ppapi/c/ppp.h" #include "third_party/ppapi/c/ppp_instance.h" #include "third_party/ppapi/c/pp_module.h" @@ -39,10 +41,12 @@ #include "webkit/glue/plugins/pepper_image_data.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" #include "webkit/glue/plugins/pepper_resource_tracker.h" +#include "webkit/glue/plugins/pepper_scrollbar.h" #include "webkit/glue/plugins/pepper_url_loader.h" #include "webkit/glue/plugins/pepper_url_request_info.h" #include "webkit/glue/plugins/pepper_url_response_info.h" #include "webkit/glue/plugins/pepper_var.h" +#include "webkit/glue/plugins/pepper_widget.h" namespace pepper { @@ -173,6 +177,10 @@ const void* GetInterface(const char* name) { return FileSystem::GetInterface(); if (strcmp(name, PPB_DIRECTORYREADER_INTERFACE) == 0) return DirectoryReader::GetInterface(); + if (strcmp(name, PPB_WIDGET_INTERFACE) == 0) + return Widget::GetInterface(); + if (strcmp(name, PPB_SCROLLBAR_INTERFACE) == 0) + return Scrollbar::GetInterface(); // Only support the testing interface when the command line switch is // specified. This allows us to prevent people from (ab)using this interface diff --git a/webkit/glue/plugins/pepper_resource.h b/webkit/glue/plugins/pepper_resource.h index fdb9d01..d8cf837 100644 --- a/webkit/glue/plugins/pepper_resource.h +++ b/webkit/glue/plugins/pepper_resource.h @@ -20,9 +20,11 @@ class FileIO; class FileRef; class ImageData; class PluginModule; +class Scrollbar; class URLLoader; class URLRequestInfo; class URLResponseInfo; +class Widget; class Resource : public base::RefCountedThreadSafe<Resource> { public: @@ -56,9 +58,11 @@ class Resource : public base::RefCountedThreadSafe<Resource> { virtual FileIO* AsFileIO() { return NULL; } virtual FileRef* AsFileRef() { return NULL; } virtual ImageData* AsImageData() { return NULL; } + virtual Scrollbar* AsScrollbar() { return NULL; } virtual URLLoader* AsURLLoader() { return NULL; } virtual URLRequestInfo* AsURLRequestInfo() { return NULL; } virtual URLResponseInfo* AsURLResponseInfo() { return NULL; } + virtual Widget* AsWidget() { return NULL; } PluginModule* module_; // Non-owning pointer to our module. @@ -78,9 +82,11 @@ DEFINE_RESOURCE_CAST(FileChooser) DEFINE_RESOURCE_CAST(FileIO) DEFINE_RESOURCE_CAST(FileRef) DEFINE_RESOURCE_CAST(ImageData) +DEFINE_RESOURCE_CAST(Scrollbar) DEFINE_RESOURCE_CAST(URLLoader) DEFINE_RESOURCE_CAST(URLRequestInfo) DEFINE_RESOURCE_CAST(URLResponseInfo) +DEFINE_RESOURCE_CAST(Widget) #undef DEFINE_RESOURCE_CAST } // namespace pepper diff --git a/webkit/glue/plugins/pepper_scrollbar.cc b/webkit/glue/plugins/pepper_scrollbar.cc new file mode 100644 index 0000000..07e3d4d --- /dev/null +++ b/webkit/glue/plugins/pepper_scrollbar.cc @@ -0,0 +1,228 @@ +// Copyright (c) 2010 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. + +#include "webkit/glue/plugins/pepper_scrollbar.h" + +#include "base/logging.h" +#include "base/message_loop.h" +#include "third_party/ppapi/c/ppp_scrollbar.h" +#include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" +#include "third_party/WebKit/WebKit/chromium/public/WebRect.h" +#include "third_party/WebKit/WebKit/chromium/public/WebScrollbar.h" +#include "third_party/WebKit/WebKit/chromium/public/WebVector.h" +#include "webkit/glue/plugins/pepper_event_conversion.h" +#include "webkit/glue/plugins/pepper_image_data.h" +#include "webkit/glue/plugins/pepper_plugin_instance.h" +#include "webkit/glue/plugins/pepper_plugin_module.h" +#include "webkit/glue/webkit_glue.h" + +using WebKit::WebInputEvent; +using WebKit::WebRect; +using WebKit::WebScrollbar; + +namespace pepper { + +namespace { + +PP_Resource Create(PP_Instance instance_id, bool vertical) { + PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); + if (!instance) + return NULL; + + scoped_refptr<Scrollbar> scrollbar(new Scrollbar(instance, vertical)); + scrollbar->AddRef(); // AddRef for the caller. + + return scrollbar->GetResource(); +} + +bool IsScrollbar(PP_Resource resource) { + return !!Resource::GetAs<Scrollbar>(resource).get(); +} + +uint32_t GetThickness() { + return WebScrollbar::defaultThickness(); +} + +uint32_t GetValue(PP_Resource resource) { + scoped_refptr<Scrollbar> scrollbar(Resource::GetAs<Scrollbar>(resource)); + if (!scrollbar.get()) + return 0; + return scrollbar->GetValue(); +} + +void SetValue(PP_Resource resource, uint32_t value) { + scoped_refptr<Scrollbar> scrollbar(Resource::GetAs<Scrollbar>(resource)); + if (scrollbar.get()) + scrollbar->SetValue(value); +} + +void SetDocumentSize(PP_Resource resource, uint32_t size) { + scoped_refptr<Scrollbar> scrollbar(Resource::GetAs<Scrollbar>(resource)); + if (scrollbar.get()) + scrollbar->SetDocumentSize(size); +} + +void SetTickMarks(PP_Resource resource, + const PP_Rect* tick_marks, + uint32_t count) { + scoped_refptr<Scrollbar> scrollbar(Resource::GetAs<Scrollbar>(resource)); + if (scrollbar.get()) + scrollbar->SetTickMarks(tick_marks, count); +} + +void ScrollBy(PP_Resource resource, + PP_ScrollBy unit, + int32_t multiplier) { + scoped_refptr<Scrollbar> scrollbar(Resource::GetAs<Scrollbar>(resource)); + if (scrollbar.get()) + scrollbar->ScrollBy(unit, multiplier); +} + +const PPB_Scrollbar ppb_scrollbar = { + &Create, + &IsScrollbar, + &GetThickness, + &GetValue, + &SetValue, + &SetDocumentSize, + &SetTickMarks, + &ScrollBy +}; + +} // namespace + +Scrollbar::Scrollbar(PluginInstance* instance, bool vertical) + : Widget(instance) { + scrollbar_.reset(WebScrollbar::create( + static_cast<WebKit::WebScrollbarClient*>(this), + vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal)); +} + +Scrollbar::~Scrollbar() { +} + +// static +const PPB_Scrollbar* Scrollbar::GetInterface() { + return &ppb_scrollbar; +} + +uint32_t Scrollbar::GetValue() { + return scrollbar_->value(); +} + +void Scrollbar::SetValue(uint32_t value) { + scrollbar_->setValue(value); +} + +void Scrollbar::SetDocumentSize(uint32_t size) { + scrollbar_->setDocumentSize(size); +} + +void Scrollbar::SetTickMarks(const PP_Rect* tick_marks, uint32_t count) { + tickmarks_.resize(count); + for (uint32 i = 0; i < count; ++i) { + tickmarks_[i] = WebRect(tick_marks[i].point.x, + tick_marks[i].point.y, + tick_marks[i].size.width, + tick_marks[i].size.height);; + } + Invalidate(&location()); +} + +void Scrollbar::ScrollBy(PP_ScrollBy unit, int32_t multiplier) { + WebScrollbar::ScrollDirection direction = multiplier >= 0 ? + WebScrollbar::ScrollForward : WebScrollbar::ScrollBackward; + float fmultiplier = 1.0; + + WebScrollbar::ScrollGranularity granularity; + if (unit == PP_WIDGET_SCROLL_BY_LINE) { + granularity = WebScrollbar::ScrollByLine; + } else if (unit == PP_WIDGET_SCROLL_BY_PAGE) { + granularity = WebScrollbar::ScrollByPage; + } else if (unit == PP_WIDGET_SCROLL_BY_DOCUMENT) { + granularity = WebScrollbar::ScrollByDocument; + } else { + granularity = WebScrollbar::ScrollByPixel; + fmultiplier = static_cast<float>(multiplier); + if (fmultiplier < 0) + fmultiplier *= -1; + } + scrollbar_->scroll(direction, granularity, fmultiplier); +} + +bool Scrollbar::Paint(const PP_Rect* rect, ImageData* image) { + gfx::Rect gfx_rect(rect->point.x, + rect->point.y, + rect->size.width, + rect->size.height); + skia::PlatformCanvas* canvas = image->mapped_canvas(); + if (!canvas) + return false; + scrollbar_->paint(webkit_glue::ToWebCanvas(canvas), gfx_rect); + return true; +} + +bool Scrollbar::HandleEvent(const PP_Event* event) { + scoped_ptr<WebInputEvent> web_input_event(CreateWebInputEvent(*event)); + if (!web_input_event.get()) + return false; + + return scrollbar_->handleInputEvent(*web_input_event.get()); +} + +void Scrollbar::SetLocationInternal(const PP_Rect* location) { + scrollbar_->setLocation(WebRect(location->point.x, + location->point.y, + location->size.width, + location->size.height)); +} + +void Scrollbar::valueChanged(WebKit::WebScrollbar* scrollbar) { + const PPP_Scrollbar* ppp_scrollbar = static_cast<const PPP_Scrollbar*>( + module()->GetPluginInterface(PPP_SCROLLBAR_INTERFACE)); + if (!ppp_scrollbar) + return; + ppp_scrollbar->ValueChanged( + instance()->GetPPInstance(), GetResource(), scrollbar_->value()); +} + +void Scrollbar::invalidateScrollbarRect(WebKit::WebScrollbar* scrollbar, + const WebKit::WebRect& rect) { + gfx::Rect gfx_rect(rect.x, + rect.y, + rect.width, + rect.height); + dirty_ = dirty_.Union(gfx_rect); + // Can't call into the client to tell them about the invalidate right away, + // since the Scrollbar code is still in the middle of updating its internal + // state. + MessageLoop::current()->PostTask( + FROM_HERE, + NewRunnableMethod(this, &Scrollbar::NotifyInvalidate)); +} + +void Scrollbar::getTickmarks( + WebKit::WebScrollbar* scrollbar, + WebKit::WebVector<WebKit::WebRect>* tick_marks) const { + if (tickmarks_.empty()) { + WebRect* rects = NULL; + tick_marks->assign(rects, 0); + } else { + tick_marks->assign(&tickmarks_[0], tickmarks_.size()); + } +} + +void Scrollbar::NotifyInvalidate() { + if (dirty_.IsEmpty()) + return; + PP_Rect pp_rect; + pp_rect.point.x = dirty_.x(); + pp_rect.point.y = dirty_.y(); + pp_rect.size.width = dirty_.width(); + pp_rect.size.height = dirty_.height(); + dirty_ = gfx::Rect(); + Invalidate(&pp_rect); +} + +} // namespace pepper diff --git a/webkit/glue/plugins/pepper_scrollbar.h b/webkit/glue/plugins/pepper_scrollbar.h new file mode 100644 index 0000000..bf25136 --- /dev/null +++ b/webkit/glue/plugins/pepper_scrollbar.h @@ -0,0 +1,64 @@ +// Copyright (c) 2010 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. + +#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_SCROLLBAR_H_ +#define WEBKIT_GLUE_PLUGINS_PEPPER_SCROLLBAR_H_ + +#include <vector> + +#include "gfx/rect.h" +#include "third_party/ppapi/c/ppb_scrollbar.h" +#include "third_party/WebKit/WebKit/chromium/public/WebRect.h" +#include "third_party/WebKit/WebKit/chromium/public/WebScrollbarClient.h" +#include "webkit/glue/plugins/pepper_widget.h" + +typedef struct _ppb_Scrollbar PPB_Scrollbar; + +namespace pepper { + +class PluginInstance; + +class Scrollbar : public Widget, public WebKit::WebScrollbarClient { + public: + Scrollbar(PluginInstance* instance, bool vertical); + virtual ~Scrollbar(); + + // Returns a pointer to the interface implementing PPB_Scrollbar that is + // exposed to the plugin. + static const PPB_Scrollbar* GetInterface(); + + // Resource overrides. + Scrollbar* AsScrollbar() { return this; } + + // PPB_Scrollbar implementation. + uint32_t GetValue(); + void SetValue(uint32_t value); + void SetDocumentSize(uint32_t size); + void SetTickMarks(const PP_Rect* tick_marks, uint32_t count); + void ScrollBy(PP_ScrollBy unit, int32_t multiplier); + + // PPB_Widget implementation. + virtual bool Paint(const PP_Rect* rect, ImageData* image); + virtual bool HandleEvent(const PP_Event* event); + virtual void SetLocationInternal(const PP_Rect* location); + + private: + // WebKit::WebScrollbarClient implementation. + virtual void valueChanged(WebKit::WebScrollbar* scrollbar); + virtual void invalidateScrollbarRect(WebKit::WebScrollbar* scrollbar, + const WebKit::WebRect& rect); + virtual void getTickmarks( + WebKit::WebScrollbar* scrollbar, + WebKit::WebVector<WebKit::WebRect>* tick_marks) const; + + void NotifyInvalidate(); + + gfx::Rect dirty_; + std::vector<WebKit::WebRect> tickmarks_; + scoped_ptr<WebKit::WebScrollbar> scrollbar_; +}; + +} // namespace pepper + +#endif // WEBKIT_GLUE_PLUGINS_PEPPER_SCROLLBAR_H_ diff --git a/webkit/glue/plugins/pepper_widget.cc b/webkit/glue/plugins/pepper_widget.cc new file mode 100644 index 0000000..9d345274 --- /dev/null +++ b/webkit/glue/plugins/pepper_widget.cc @@ -0,0 +1,90 @@ +// Copyright (c) 2010 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. + +#include "webkit/glue/plugins/pepper_widget.h" + +#include "base/logging.h" +#include "third_party/ppapi/c/pp_completion_callback.h" +#include "third_party/ppapi/c/pp_errors.h" +#include "third_party/ppapi/c/ppb_widget.h" +#include "third_party/ppapi/c/ppp_widget.h" +#include "webkit/glue/plugins/pepper_image_data.h" +#include "webkit/glue/plugins/pepper_plugin_instance.h" +#include "webkit/glue/plugins/pepper_plugin_module.h" + +namespace pepper { + +namespace { + +bool IsWidget(PP_Resource resource) { + return !!Resource::GetAs<Widget>(resource).get(); +} + +bool Paint(PP_Resource resource, const PP_Rect* rect, PP_Resource image_id) { + scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); + if (!widget.get()) + return false; + + scoped_refptr<ImageData> image(Resource::GetAs<ImageData>(image_id)); + return widget.get() && widget->Paint(rect, image); +} + +bool HandleEvent(PP_Resource resource, const PP_Event* event) { + scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); + return widget.get() && widget->HandleEvent(event); +} + +bool GetLocation(PP_Resource resource, PP_Rect* location) { + scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); + return widget.get() && widget->GetLocation(location); +} + +void SetLocation(PP_Resource resource, const PP_Rect* location) { + scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); + if (widget.get()) + widget->SetLocation(location); +} + +const PPB_Widget ppb_widget = { + &IsWidget, + &Paint, + &HandleEvent, + &GetLocation, + &SetLocation, +}; + +} // namespace + +Widget::Widget(PluginInstance* instance) + : Resource(instance->module()), + instance_(instance) { +} + +Widget::~Widget() { +} + +// static +const PPB_Widget* Widget::GetInterface() { + return &ppb_widget; +} + +bool Widget::GetLocation(PP_Rect* location) { + *location = location_; + return true; +} + +void Widget::SetLocation(const PP_Rect* location) { + location_ = *location; + SetLocationInternal(location); +} + +void Widget::Invalidate(const PP_Rect* dirty) { + const PPP_Widget* widget = static_cast<const PPP_Widget*>( + module()->GetPluginInterface(PPP_WIDGET_INTERFACE)); + if (!widget) + return; + widget->Invalidate(instance_->GetPPInstance(), GetResource(), dirty); +} + +} // namespace pepper diff --git a/webkit/glue/plugins/pepper_widget.h b/webkit/glue/plugins/pepper_widget.h new file mode 100644 index 0000000..048a718 --- /dev/null +++ b/webkit/glue/plugins/pepper_widget.h @@ -0,0 +1,53 @@ +// Copyright (c) 2010 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. + +#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_WIDGET_H_ +#define WEBKIT_GLUE_PLUGINS_PEPPER_WIDGET_H_ + +#include "base/scoped_ptr.h" +#include "third_party/ppapi/c/pp_rect.h" +#include "webkit/glue/plugins/pepper_resource.h" + +typedef struct _ppb_Widget PPB_Widget; +typedef struct _pp_Event PP_Event; + +namespace pepper { + +class ImageData; +class PluginInstance; + +class Widget : public Resource { + public: + explicit Widget(PluginInstance* instance); + virtual ~Widget(); + + // Returns a pointer to the interface implementing PPB_Widget that is + // exposed to the plugin. + static const PPB_Widget* GetInterface(); + + // Resource overrides. + Widget* AsWidget() { return this; } + + // PPB_Widget implementation. + virtual bool Paint(const PP_Rect* rect, ImageData* image) = 0; + virtual bool HandleEvent(const PP_Event* event) = 0; + bool GetLocation(PP_Rect* location); + void SetLocation(const PP_Rect* location); + + // Notifies the plugin instance that the given rect needs to be repainted. + void Invalidate(const PP_Rect* dirty); + PluginInstance* instance() { return instance_; } + + protected: + virtual void SetLocationInternal(const PP_Rect* location) = 0; + PP_Rect location() const { return location_; } + + private: + scoped_refptr<PluginInstance> instance_; + PP_Rect location_; +}; + +} // namespace pepper + +#endif // WEBKIT_GLUE_PLUGINS_PEPPER_WIDGET_H_ diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index cf97f76..9bdebd7 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -169,6 +169,8 @@ 'plugins/pepper_device_context_2d.h', 'plugins/pepper_directory_reader.cc', 'plugins/pepper_directory_reader.h', + 'plugins/pepper_event_conversion.cc', + 'plugins/pepper_event_conversion.h', 'plugins/pepper_file_chooser.cc', 'plugins/pepper_file_chooser.h', 'plugins/pepper_file_io.cc', @@ -188,6 +190,8 @@ 'plugins/pepper_resource_tracker.h', 'plugins/pepper_resource.cc', 'plugins/pepper_resource.h', + 'plugins/pepper_scrollbar.cc', + 'plugins/pepper_scrollbar.h', 'plugins/pepper_url_loader.cc', 'plugins/pepper_url_loader.h', 'plugins/pepper_url_request_info.cc', @@ -198,6 +202,8 @@ 'plugins/pepper_var.h', 'plugins/pepper_webplugin_impl.cc', 'plugins/pepper_webplugin_impl.h', + 'plugins/pepper_widget.cc', + 'plugins/pepper_widget.h', 'plugins/plugin_constants_win.h', 'plugins/plugin_host.cc', 'plugins/plugin_host.h', |