diff options
-rw-r--r-- | chrome/renderer/pepper_devices.h | 1 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.cc | 214 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.h | 5 | ||||
-rw-r--r-- | third_party/npapi/bindings/npapi_extensions.h | 52 | ||||
-rw-r--r-- | webkit/glue/plugins/npapi_extension_thunk.cc | 32 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_2d_device_delegate.h | 9 |
6 files changed, 307 insertions, 6 deletions
diff --git a/chrome/renderer/pepper_devices.h b/chrome/renderer/pepper_devices.h index 3c9f98c..cf14133 100644 --- a/chrome/renderer/pepper_devices.h +++ b/chrome/renderer/pepper_devices.h @@ -42,6 +42,7 @@ class Graphics2DDeviceContext { void RenderViewFlushedPaint(); TransportDIB* transport_dib() { return transport_dib_.get(); } + skia::PlatformCanvas* canvas() { return canvas_.get(); } private: struct FlushCallbackData { diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc index 4c62381..086699d 100644 --- a/chrome/renderer/webplugin_delegate_pepper.cc +++ b/chrome/renderer/webplugin_delegate_pepper.cc @@ -4,12 +4,20 @@ #define PEPPER_APIS_ENABLED 1 +#include "build/build_config.h" +#if defined(OS_WIN) +#include <vsstyle.h> +#endif + #include "chrome/renderer/webplugin_delegate_pepper.h" #include <string> #include <vector> #include "app/gfx/blit.h" +#if defined(OS_WIN) +#include "app/gfx/native_theme_win.h" +#endif #include "base/file_util.h" #include "base/md5.h" #include "base/message_loop.h" @@ -17,6 +25,9 @@ #include "base/scoped_ptr.h" #include "base/stats_counters.h" #include "base/string_util.h" +#if defined(OS_WIN) +#include "base/win_util.h" +#endif #include "chrome/common/render_messages.h" #include "chrome/renderer/render_thread.h" #include "chrome/renderer/webplugin_delegate_proxy.h" @@ -44,6 +55,8 @@ using WebKit::WebInputEvent; using WebKit::WebMouseEvent; using WebKit::WebMouseWheelEvent; +namespace { + // Implementation artifacts for a context struct Device2DImpl { TransportDIB* dib; @@ -53,6 +66,57 @@ struct Device3DImpl { gpu::CommandBuffer* command_buffer; }; +#if defined(OS_WIN) +struct ScrollbarThemeMapping { + NPThemeItem item; + NPThemeState state; + int state_id; // Used by uxtheme. +}; +static const ScrollbarThemeMapping scrollbar_mappings[] = { + { NPThemeItemScrollbarDownArrow, NPThemeStateDisabled, ABS_DOWNDISABLED}, + { NPThemeItemScrollbarDownArrow, NPThemeStateHot, ABS_DOWNHOT}, + { NPThemeItemScrollbarDownArrow, NPThemeStateHover, ABS_DOWNHOVER}, + { NPThemeItemScrollbarDownArrow, NPThemeStateNormal, ABS_DOWNNORMAL}, + { NPThemeItemScrollbarDownArrow, NPThemeStatePressed, ABS_DOWNPRESSED}, + { NPThemeItemScrollbarLeftArrow, NPThemeStateDisabled, ABS_LEFTDISABLED}, + { NPThemeItemScrollbarLeftArrow, NPThemeStateHot, ABS_LEFTHOT}, + { NPThemeItemScrollbarLeftArrow, NPThemeStateHover, ABS_LEFTHOVER}, + { NPThemeItemScrollbarLeftArrow, NPThemeStateNormal, ABS_LEFTNORMAL}, + { NPThemeItemScrollbarLeftArrow, NPThemeStatePressed, ABS_LEFTPRESSED}, + { NPThemeItemScrollbarRightArrow, NPThemeStateDisabled, ABS_RIGHTDISABLED}, + { NPThemeItemScrollbarRightArrow, NPThemeStateHot, ABS_RIGHTHOT}, + { NPThemeItemScrollbarRightArrow, NPThemeStateHover, ABS_RIGHTHOVER}, + { NPThemeItemScrollbarRightArrow, NPThemeStateNormal, ABS_RIGHTNORMAL}, + { NPThemeItemScrollbarRightArrow, NPThemeStatePressed, ABS_RIGHTPRESSED}, + { NPThemeItemScrollbarUpArrow, NPThemeStateDisabled, ABS_UPDISABLED}, + { NPThemeItemScrollbarUpArrow, NPThemeStateHot, ABS_UPHOT}, + { NPThemeItemScrollbarUpArrow, NPThemeStateHover, ABS_UPHOVER}, + { NPThemeItemScrollbarUpArrow, NPThemeStateNormal, ABS_UPNORMAL}, + { NPThemeItemScrollbarUpArrow, NPThemeStatePressed, ABS_UPPRESSED}, +}; + +int GetStateIdFromNPState(int state) { + switch (state) { + case NPThemeStateDisabled: + return SCRBS_DISABLED; + case NPThemeStateHot: + return SCRBS_HOT; + case NPThemeStateHover: + return SCRBS_HOVER; + case NPThemeStateNormal: + return SCRBS_NORMAL; + case NPThemeStatePressed: + return SCRBS_PRESSED; + default: + return -1; + }; +} +#else + // TODO(port) +#endif + +} // namespace + WebPluginDelegatePepper* WebPluginDelegatePepper::Create( const FilePath& filename, const std::string& mime_type, @@ -153,7 +217,7 @@ void WebPluginDelegatePepper::UpdateGeometry( // needs to repaint? SkBitmap new_committed; new_committed.setConfig(SkBitmap::kARGB_8888_Config, - window_rect_.width(), window_rect.height()); + window_rect_.width(), window_rect_.height()); new_committed.allocPixels(); committed_bitmap_ = new_committed; @@ -328,16 +392,14 @@ NPError WebPluginDelegatePepper::Device2DFlushContext( NPDeviceContext2D* context, NPDeviceFlushContextCallbackPtr callback, void* user_data) { - - if (!context) { + if (!context) return NPERR_INVALID_PARAM; - } Graphics2DDeviceContext* ctx = graphic2d_contexts_.Lookup( reinterpret_cast<intptr_t>(context->reserved)); - if (!ctx) { + if (!ctx) return NPERR_INVALID_PARAM; // TODO(brettw) call callback. - } + return ctx->Flush(&committed_bitmap_, context, callback, id, user_data); } @@ -353,6 +415,146 @@ NPError WebPluginDelegatePepper::Device2DDestroyContext( return NPERR_NO_ERROR; } +NPError WebPluginDelegatePepper::Device2DThemeGetSize(NPThemeItem item, + int* width, + int* height) { +#if defined(OS_WIN) + switch (item) { + case NPThemeItemScrollbarDownArrow: + case NPThemeItemScrollbarUpArrow: + *width = GetSystemMetrics(SM_CXVSCROLL); + *height = GetSystemMetrics(SM_CYVSCROLL); + break; + case NPThemeItemScrollbarLeftArrow: + case NPThemeItemScrollbarRightArrow: + *width = GetSystemMetrics(SM_CXHSCROLL); + *height = GetSystemMetrics(SM_CYHSCROLL); + break; + case NPThemeItemScrollbarHorizontalThumb: + *width = GetSystemMetrics(SM_CXHTHUMB); + *height = *width; // Make the min size a square. + break; + case NPThemeItemScrollbarVerticalThumb: + *height = GetSystemMetrics(SM_CYVTHUMB); + *width = *height; // Make the min size a square. + break; + case NPThemeItemScrollbarHoriztonalTrack: + *height = GetSystemMetrics(SM_CYHSCROLL); + *width = 0; + break; + case NPThemeItemScrollbarVerticalTrack: + *width = GetSystemMetrics(SM_CXVSCROLL); + *height = 0; + break; + default: + return NPERR_GENERIC_ERROR; + } + return NPERR_NO_ERROR; +#else + NOTIMPLEMENTED(); + return NPERR_GENERIC_ERROR; +#endif +} + +NPError WebPluginDelegatePepper::Device2DThemePaint(NPDeviceContext2D* context, + NPThemeParams* params) { + if (!context) + return NPERR_INVALID_PARAM; + + Graphics2DDeviceContext* ctx = graphic2d_contexts_.Lookup( + reinterpret_cast<intptr_t>(context->reserved)); + if (!ctx) + return NPERR_INVALID_PARAM; + + NPError rv; + gfx::Rect rect(params->location.left, + params->location.top, + params->location.right - params->location.left, + params->location.bottom - params->location.top); + skia::PlatformCanvas* canvas = ctx->canvas(); + +#if defined(OS_WIN) + int state = -1; + int part = -1; + int classic_state = 0; + skia::PlatformDevice::PlatformSurface surface = canvas->beginPlatformPaint(); +#endif + + switch (params->item) { + case NPThemeItemScrollbarDownArrow: + case NPThemeItemScrollbarLeftArrow: + case NPThemeItemScrollbarRightArrow: + case NPThemeItemScrollbarUpArrow: { + int state_to_use = params->state; + if (state_to_use == NPThemeStateHover +#if defined(OS_WIN) + && win_util::GetWinVersion() < win_util::WINVERSION_VISTA +#endif + ) { + state_to_use = NPThemeStateHover; + } + +#if defined(OS_WIN) + for (size_t i = 0; i < arraysize(scrollbar_mappings); ++i) { + if (scrollbar_mappings[i].item == params->item && + scrollbar_mappings[i].state == state_to_use) { + state = scrollbar_mappings[i].state_id; + gfx::NativeTheme::instance()->PaintScrollbarArrow( + surface, state, classic_state, &rect.ToRECT()); + rv = NPERR_NO_ERROR; + break; + } + } +#else + // TODO(port) +#endif + break; + } + case NPThemeItemScrollbarHorizontalThumb: + case NPThemeItemScrollbarVerticalThumb: +#if defined(OS_WIN) + // First draw the thumb, then the gripper. + part = params->item == NPThemeItemScrollbarHorizontalThumb ? + SBP_THUMBBTNHORZ : SBP_THUMBBTNVERT; + state = GetStateIdFromNPState(params->state); + gfx::NativeTheme::instance()->PaintScrollbarThumb( + surface, part, state, classic_state, &rect.ToRECT()); + + part = params->item == NPThemeItemScrollbarHorizontalThumb ? + SBP_GRIPPERHORZ : SBP_GRIPPERVERT; + gfx::NativeTheme::instance()->PaintScrollbarThumb( + surface, part, state, classic_state, &rect.ToRECT()); + rv = NPERR_NO_ERROR; +#else + // TODO(port) +#endif + break; + case NPThemeItemScrollbarHoriztonalTrack: + case NPThemeItemScrollbarVerticalTrack: { +#if defined(OS_WIN) + part = params->item == NPThemeItemScrollbarHoriztonalTrack ? + SBP_LOWERTRACKHORZ : SBP_LOWERTRACKVERT; + state = GetStateIdFromNPState(params->state); + RECT align; + align.left = align.right = params->align.x; + align.top = align.bottom = params->align.y; + gfx::NativeTheme::instance()->PaintScrollbarTrack( + surface, part, state, classic_state, &rect.ToRECT(), &align, canvas); + rv = NPERR_NO_ERROR; +#else + // TODO(port) + NOTIMPLEMENTED(); +#endif + break; + } + default: + NOTREACHED(); + } + + canvas->endPlatformPaint(); + return rv; +} + NPError WebPluginDelegatePepper::Device3DQueryCapability(int32 capability, int32* value) { return NPERR_GENERIC_ERROR; diff --git a/chrome/renderer/webplugin_delegate_pepper.h b/chrome/renderer/webplugin_delegate_pepper.h index 0bcbc06..789c6712 100644 --- a/chrome/renderer/webplugin_delegate_pepper.h +++ b/chrome/renderer/webplugin_delegate_pepper.h @@ -93,6 +93,11 @@ class WebPluginDelegatePepper : public webkit_glue::WebPluginDelegate { NPDeviceFlushContextCallbackPtr callback, void* user_data); virtual NPError Device2DDestroyContext(NPDeviceContext2D* context); + virtual NPError Device2DThemeGetSize(NPThemeItem item, + int* width, + int* height); + virtual NPError Device2DThemePaint(NPDeviceContext2D* context, + NPThemeParams* params); // WebPlugin3DDeviceDelegate implementation. virtual NPError Device3DQueryCapability(int32 capability, int32* value); diff --git a/third_party/npapi/bindings/npapi_extensions.h b/third_party/npapi/bindings/npapi_extensions.h index 2e18a6a..05526d1 100644 --- a/third_party/npapi/bindings/npapi_extensions.h +++ b/third_party/npapi/bindings/npapi_extensions.h @@ -21,6 +21,42 @@ typedef void NPUserData; /* unique id for each device interface */ typedef int32 NPDeviceID; +typedef struct _NPPoint { + uint16 x; + uint16 y; +} NPPoint; + +typedef enum { + NPThemeItemScrollbarDownArrow = 0, + NPThemeItemScrollbarLeftArrow = 1, + NPThemeItemScrollbarRightArrow = 2, + NPThemeItemScrollbarUpArrow = 3, + NPThemeItemScrollbarHorizontalThumb = 4, + NPThemeItemScrollbarVerticalThumb = 5, + NPThemeItemScrollbarHoriztonalTrack = 6, + NPThemeItemScrollbarVerticalTrack = 7, +} NPThemeItem; + +typedef enum { + NPThemeStateDisabled = 0, + // Mouse is over this item. + NPThemeStateHot = 1, + // Mouse is over another part of this component. This is only used on Windows + // Vista and above. The plugin should pass it in, and the host will convert + // it to NPThemeStateNormal if on other platforms or on Windows XP. + NPThemeStateHover = 2, + NPThemeStateNormal = 3, + NPThemeStatePressed = 4, +} NPThemeState; + +typedef struct _NPThemeParams { + NPThemeItem item; + NPThemeState state; + NPRect location; + // Used for scroll bar tracks, needed for classic theme in Windows which draws + // a checkered pattern. + NPPoint align; +} NPThemeParams; typedef struct _NPDeviceBuffer { void* ptr; @@ -92,6 +128,20 @@ typedef NPError (*NPDeviceMapBufferPtr)( NPDeviceContext* context, int32 id, NPDeviceBuffer* buffer); +/* Gets the size of the given theme component. For variable sized items like */ +/* vertical scrollbar tracks, the width will be the required width of the */ +/* track while the height will be the minimum height. */ +typedef NPError (*NPDeviceThemeGetSize)( + NPP instance, + NPThemeItem item, + int* width, + int* height); +/* Draw a themed item (i.e. scrollbar arrow). */ +typedef NPError (*NPDeviceThemePaint)( + NPP instance, + NPDeviceContext* context, + NPThemeParams* params); + /* forward decl typdef structs */ typedef struct NPDevice NPDevice; @@ -109,6 +159,8 @@ struct NPDevice { NPDeviceCreateBufferPtr createBuffer; NPDeviceDestroyBufferPtr destroyBuffer; NPDeviceMapBufferPtr mapBuffer; + NPDeviceThemeGetSize themeGetSize; + NPDeviceThemePaint themePaint; }; /* returns NULL if deviceID unavailable / unrecognized */ diff --git a/webkit/glue/plugins/npapi_extension_thunk.cc b/webkit/glue/plugins/npapi_extension_thunk.cc index ab5b852..1ffecfc 100644 --- a/webkit/glue/plugins/npapi_extension_thunk.cc +++ b/webkit/glue/plugins/npapi_extension_thunk.cc @@ -137,6 +137,29 @@ static NPError Device2DMapBuffer(NPP id, return NPERR_GENERIC_ERROR; } +static NPError Device2DThemeGetSize(NPP id, + NPThemeItem item, + int* width, + int* height) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->webplugin()->delegate()->Device2DThemeGetSize( + item, width, height); + } + return NPERR_GENERIC_ERROR; +} + +static NPError Device2DThemePaint(NPP id, + NPDeviceContext* context, + NPThemeParams* params) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->webplugin()->delegate()->Device2DThemePaint( + static_cast<NPDeviceContext2D*>(context), params); + } + return NPERR_GENERIC_ERROR; +} + // 3D device API --------------------------------------------------------------- static NPError Device3DQueryCapability(NPP id, int32 capability, int32* value) { @@ -342,6 +365,8 @@ static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) { Device2DCreateBuffer, Device2DDestroyBuffer, Device2DMapBuffer, + Device2DThemeGetSize, + Device2DThemePaint, }; static NPDevice device_3d = { Device3DQueryCapability, @@ -354,6 +379,8 @@ static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) { Device3DCreateBuffer, Device3DDestroyBuffer, Device3DMapBuffer, + NULL, + NULL, }; static NPDevice device_audio = { DeviceAudioQueryCapability, @@ -363,6 +390,11 @@ static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) { DeviceAudioGetStateContext, DeviceAudioFlushContext, DeviceAudioDestroyContext, + NULL, + NULL, + NULL, + NULL, + NULL, }; switch (device_id) { diff --git a/webkit/glue/plugins/webplugin_2d_device_delegate.h b/webkit/glue/plugins/webplugin_2d_device_delegate.h index 69bd53a..b622d20 100644 --- a/webkit/glue/plugins/webplugin_2d_device_delegate.h +++ b/webkit/glue/plugins/webplugin_2d_device_delegate.h @@ -46,6 +46,15 @@ class WebPlugin2DDeviceDelegate { virtual NPError Device2DDestroyContext(NPDeviceContext2D* context) { return NPERR_GENERIC_ERROR; } + virtual NPError Device2DThemeGetSize(NPThemeItem item, + int* width, + int* height) { + return NPERR_GENERIC_ERROR; + } + virtual NPError Device2DThemePaint(NPDeviceContext2D* context, + NPThemeParams* params) { + return NPERR_GENERIC_ERROR; + } protected: WebPlugin2DDeviceDelegate() {} |