diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-08 23:59:51 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-08 23:59:51 +0000 |
commit | 86fd1a61b1715209da8482369d5667fcb1f0236f (patch) | |
tree | e61f323be8fd740fed3e992de387864fef4f5a6e /chrome/renderer/webplugin_delegate_pepper.cc | |
parent | d09f7b8c6658dce22559f9264cea1218f1d507c8 (diff) | |
download | chromium_src-86fd1a61b1715209da8482369d5667fcb1f0236f.zip chromium_src-86fd1a61b1715209da8482369d5667fcb1f0236f.tar.gz chromium_src-86fd1a61b1715209da8482369d5667fcb1f0236f.tar.bz2 |
Add theming API to Pepper. For now, this only handles scrollbars.
Review URL: http://codereview.chromium.org/660158
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40969 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/webplugin_delegate_pepper.cc')
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.cc | 214 |
1 files changed, 208 insertions, 6 deletions
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; |