diff options
Diffstat (limited to 'WebKit/android/RenderSkinButton.cpp')
-rw-r--r-- | WebKit/android/RenderSkinButton.cpp | 73 |
1 files changed, 22 insertions, 51 deletions
diff --git a/WebKit/android/RenderSkinButton.cpp b/WebKit/android/RenderSkinButton.cpp index 1dc6560..6a0ae54 100644 --- a/WebKit/android/RenderSkinButton.cpp +++ b/WebKit/android/RenderSkinButton.cpp @@ -31,47 +31,36 @@ #include "IntRect.h" #include "Node.h" #include "RenderSkinButton.h" +#include "RenderSkinNinePatch.h" #include "SkCanvas.h" #include "SkNinePatch.h" #include "SkRect.h" +#include <utils/Asset.h> +#include <utils/AssetManager.h> #include <utils/Debug.h> #include <utils/Log.h> +#include <utils/ResourceTypes.h> #include <wtf/text/CString.h> -struct PatchData { - const char* name; - int8_t outset, margin; -}; - -static const PatchData gFiles[] = - { - { "btn_default_disabled_holo.9.png", 2, 7 }, - { "btn_default_normal_holo.9.png", 2, 7 }, - { "btn_default_focused_holo.9.png", 2, 7 }, - { "btn_default_pressed_holo.9.png", 2, 7 } +static const char* gFiles[] = { + "btn_default_disabled_holo.9.png", + "btn_default_normal_holo.9.png", + "btn_default_focused_holo.9.png", + "btn_default_pressed_holo.9.png" }; -static SkBitmap gButton[sizeof(gFiles)/sizeof(gFiles[0])]; -static bool gDecoded; -static bool gHighRes; - namespace WebCore { -void RenderSkinButton::Init(android::AssetManager* am, String drawableDirectory) +RenderSkinButton::RenderSkinButton(android::AssetManager* am, String drawableDirectory) { - static bool gInited; - if (gInited) - return; - - gInited = true; - gDecoded = true; - gHighRes = drawableDirectory[drawableDirectory.length() - 5] == 'h'; - for (size_t i = 0; i < sizeof(gFiles)/sizeof(gFiles[0]); i++) { - String path = drawableDirectory + gFiles[i].name; - if (!RenderSkinAndroid::DecodeBitmap(am, path.utf8().data(), &gButton[i])) { - gDecoded = false; - LOGD("RenderSkinButton::Init: button assets failed to decode\n\tBrowser buttons will not draw"); - break; + m_decoded = true; + for (size_t i = 0; i < 4; i++) { + String path = String(drawableDirectory.impl()); + path.append(String(gFiles[i])); + if (!RenderSkinNinePatch::decodeAsset(am, path.utf8().data(), &m_buttons[i])) { + m_decoded = false; + LOGE("RenderSkinButton::Init: button assets failed to decode\n\tBrowser buttons will not draw"); + return; } } @@ -82,11 +71,12 @@ void RenderSkinButton::Init(android::AssetManager* am, String drawableDirectory) android::CompileTimeAssert<(RenderSkinAndroid::kPressed == 3)> a4; } -void RenderSkinButton::Draw(SkCanvas* canvas, const IntRect& r, RenderSkinAndroid::State newState) +void RenderSkinButton::draw(SkCanvas* canvas, const IntRect& r, + RenderSkinAndroid::State newState) const { // If we failed to decode, do nothing. This way the browser still works, // and webkit will still draw the label and layout space for us. - if (!gDecoded) { + if (!m_decoded) { return; } @@ -94,26 +84,7 @@ void RenderSkinButton::Draw(SkCanvas* canvas, const IntRect& r, RenderSkinAndroi SkASSERT(static_cast<unsigned>(newState) < static_cast<unsigned>(RenderSkinAndroid::kNumStates)); - // Set up the ninepatch information for drawing. - SkRect bounds(r); - const PatchData& pd = gFiles[newState]; - int marginValue = pd.margin + pd.outset; - - SkIRect margin; - - margin.set(marginValue, marginValue, marginValue, marginValue); - if (gHighRes) { - /* FIXME: it shoudn't be necessary to offset the button here, - but gives the right results. */ - bounds.offset(0, SK_Scalar1 * 2); - /* FIXME: This temporarily gets around the fact that the margin values and - positioning were created for a low res asset, which was used on - g1-like devices. A better fix would be to read the offset information - out of the png. */ - margin.set(10, 9, 10, 14); - } - // Draw to the canvas. - SkNinePatch::DrawNine(canvas, bounds, gButton[newState], margin); + RenderSkinNinePatch::DrawNinePatch(canvas, SkRect(r), m_buttons[newState]); } } //WebCore |