summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kolb <kolby@google.com>2012-01-24 11:37:16 -0800
committerMichael Kolb <kolby@google.com>2012-01-24 15:11:05 -0800
commit4d6b8874f0e7c59190e219d2eb362498ae440a81 (patch)
tree37926eaf86b375b11992dd60839f9100470ba185
parentbf7bb6a8af0b5752b8a10f52c1962cc7a38e388c (diff)
downloadexternal_webkit-4d6b8874f0e7c59190e219d2eb362498ae440a81.zip
external_webkit-4d6b8874f0e7c59190e219d2eb362498ae440a81.tar.gz
external_webkit-4d6b8874f0e7c59190e219d2eb362498ae440a81.tar.bz2
Fix form button layout
Bug: 5822424 Fixed by removing all padding adjustments and rendering buttons natively as draw commands Change-Id: I6adcdfbd75b3c586414b5e6e60aeca01f5d05b9d
-rw-r--r--Source/WebCore/platform/android/RenderThemeAndroid.cpp91
-rw-r--r--Source/WebCore/platform/android/RenderThemeAndroid.h1
-rw-r--r--Source/WebCore/platform/graphics/android/PlatformGraphicsContext.h1
-rw-r--r--Source/WebKit/Android.mk1
-rw-r--r--Source/WebKit/android/RenderSkinAndroid.cpp3
-rw-r--r--Source/WebKit/android/RenderSkinAndroid.h4
-rw-r--r--Source/WebKit/android/RenderSkinButton.cpp105
-rw-r--r--Source/WebKit/android/RenderSkinButton.h55
-rw-r--r--Source/WebKit/android/nav/WebView.cpp3
9 files changed, 60 insertions, 204 deletions
diff --git a/Source/WebCore/platform/android/RenderThemeAndroid.cpp b/Source/WebCore/platform/android/RenderThemeAndroid.cpp
index 843068a..5f40ede 100644
--- a/Source/WebCore/platform/android/RenderThemeAndroid.cpp
+++ b/Source/WebCore/platform/android/RenderThemeAndroid.cpp
@@ -38,10 +38,10 @@
#include "RenderMediaControls.h"
#endif
#include "RenderSkinAndroid.h"
-#include "RenderSkinButton.h"
#include "RenderSkinCombo.h"
#include "RenderSkinMediaButton.h"
#include "RenderSkinRadio.h"
+#include "RoundedIntRect.h"
#include "SkCanvas.h"
#include "UserAgentStyleSheets.h"
#include "WebCoreFrameBridge.h"
@@ -63,6 +63,20 @@ const int listboxPadding = 5;
const RGBA32 selectionColor = makeRGB(181, 224, 136);
+// Colors copied from the holo resources
+const RGBA32 defaultBgColor = makeRGBA(204, 204, 204, 197);
+const RGBA32 defaultBgBright = makeRGBA(213, 213, 213, 221);
+const RGBA32 defaultBgDark = makeRGBA(92, 92, 92, 160);
+const RGBA32 defaultFgColor = makeRGBA(101, 101, 101, 225);
+
+const RGBA32 disabledBgColor = makeRGBA(205, 205, 205, 107);
+const RGBA32 disabledBgBright = makeRGBA(213, 213, 213, 133);
+const RGBA32 disabledBgDark = makeRGBA(92, 92, 92, 96);
+const RGBA32 disabledFgColor = makeRGBA(148, 148, 148, 137);
+
+const int paddingButton = 2;
+const int cornerButton = 2;
+
static SkCanvas* getCanvasFromInfo(const PaintInfo& info)
{
return info.context->platformContext()->mCanvas;
@@ -174,10 +188,10 @@ void RenderThemeAndroid::addIntrinsicMargins(RenderStyle* style) const
// Cut out the intrinsic margins completely if we end up using a small font size
if (style->fontSize() < 11)
return;
-
+
// Intrinsic margin value.
const int m = 2;
-
+
// FIXME: Using width/height alone and not also dealing with min-width/max-width is flawed.
if (style->width().isIntrinsicOrAuto()) {
if (style->marginLeft().quirk())
@@ -210,17 +224,6 @@ bool RenderThemeAndroid::supportsFocus(ControlPart appearance)
void RenderThemeAndroid::adjustButtonStyle(CSSStyleSelector*, RenderStyle* style, WebCore::Element*) const
{
- // Code is taken from RenderThemeSafari.cpp
- // It makes sure we have enough space for the button text.
- const int paddingHoriz = 12;
- const int paddingVert = 8;
- style->setPaddingLeft(Length(paddingHoriz, Fixed));
- style->setPaddingRight(Length(paddingHoriz, Fixed));
- style->setPaddingTop(Length(paddingVert, Fixed));
- style->setPaddingBottom(Length(paddingVert, Fixed));
-
- // Set a min-height so that we can't get smaller than the mini button.
- style->setMinHeight(Length(15, Fixed));
}
bool RenderThemeAndroid::paintCheckbox(RenderObject* obj, const PaintInfo& info, const IntRect& rect)
@@ -237,16 +240,42 @@ bool RenderThemeAndroid::paintButton(RenderObject* obj, const PaintInfo& info, c
if (formControlElement) {
android::WebFrame* webFrame = getWebFrame(node);
if (webFrame) {
- RenderSkinAndroid* skins = webFrame->renderSkins();
- if (skins) {
- RenderSkinAndroid::State state = RenderSkinAndroid::kNormal;
- if (!formControlElement->isEnabledFormControl())
- state = RenderSkinAndroid::kDisabled;
- skins->renderSkinButton()->draw(getCanvasFromInfo(info), rect, state);
+ GraphicsContext *context = info.context;
+ IntRect innerrect = IntRect(rect.x() + paddingButton, rect.y() + paddingButton,
+ rect.width() - 2 * paddingButton, rect.height() - 2 * paddingButton);
+ IntSize cornerrect = IntSize(cornerButton, cornerButton);
+ Color bg, bright, dark;
+ if (formControlElement->isEnabledFormControl()) {
+ bg = Color(defaultBgColor);
+ bright = Color(defaultBgBright);
+ dark = Color(defaultBgDark);
+ } else {
+ bg = Color(disabledBgColor);
+ bright = Color(disabledBgBright);
+ dark = Color(disabledBgDark);
}
+ context->save();
+ context->clip(
+ IntRect(innerrect.x(), innerrect.y(), innerrect.width(), 1));
+ context->fillRoundedRect(innerrect, cornerrect, cornerrect,
+ cornerrect, cornerrect, bright, context->fillColorSpace());
+ context->restore();
+ context->save();
+ context->clip(IntRect(innerrect.x(), innerrect.y() + innerrect.height() - 1,
+ innerrect.width(), 1));
+ context->fillRoundedRect(innerrect, cornerrect, cornerrect,
+ cornerrect, cornerrect, dark, context->fillColorSpace());
+ context->restore();
+ context->save();
+ context->clip(IntRect(innerrect.x(), innerrect.y() + 1, innerrect.width(),
+ innerrect.height() - 2));
+ context->fillRoundedRect(innerrect, cornerrect, cornerrect,
+ cornerrect, cornerrect, bg, context->fillColorSpace());
+ context->restore();
}
}
+
// We always return false so we do not request to be redrawn.
return false;
}
@@ -400,7 +429,7 @@ void RenderThemeAndroid::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* st
bool RenderThemeAndroid::paintTextField(RenderObject*, const PaintInfo&, const IntRect&)
{
- return true;
+ return true;
}
void RenderThemeAndroid::adjustTextAreaStyle(CSSStyleSelector*, RenderStyle* style, WebCore::Element*) const
@@ -422,7 +451,7 @@ void RenderThemeAndroid::adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*
bool RenderThemeAndroid::paintSearchField(RenderObject*, const PaintInfo&, const IntRect&)
{
- return true;
+ return true;
}
static void adjustMenuListStyleCommon(RenderStyle* style)
@@ -453,8 +482,8 @@ bool RenderThemeAndroid::paintCombo(RenderObject* obj, const PaintInfo& info, c
return RenderSkinCombo::Draw(getCanvasFromInfo(info), obj->node(), rect.x(), rect.y(), rect.width(), rect.height());
}
-bool RenderThemeAndroid::paintMenuList(RenderObject* obj, const PaintInfo& info, const IntRect& rect)
-{
+bool RenderThemeAndroid::paintMenuList(RenderObject* obj, const PaintInfo& info, const IntRect& rect)
+{
return paintCombo(obj, info, rect);
}
@@ -465,13 +494,13 @@ void RenderThemeAndroid::adjustMenuListButtonStyle(CSSStyleSelector*,
const float baseFontSize = 11.0f;
const int baseBorderRadius = 5;
float fontScale = style->fontSize() / baseFontSize;
-
+
style->resetPadding();
style->setBorderRadius(IntSize(int(baseBorderRadius + fontScale - 1), int(baseBorderRadius + fontScale - 1))); // FIXME: Round up?
const int minHeight = 15;
style->setMinHeight(Length(minHeight, Fixed));
-
+
style->setLineHeight(RenderStyle::initialLineHeight());
// Found these padding numbers by trial and error.
const int padding = 4;
@@ -480,7 +509,7 @@ void RenderThemeAndroid::adjustMenuListButtonStyle(CSSStyleSelector*,
adjustMenuListStyleCommon(style);
}
-bool RenderThemeAndroid::paintMenuListButton(RenderObject* obj, const PaintInfo& info, const IntRect& rect)
+bool RenderThemeAndroid::paintMenuListButton(RenderObject* obj, const PaintInfo& info, const IntRect& rect)
{
return paintCombo(obj, info, rect);
}
@@ -488,10 +517,10 @@ bool RenderThemeAndroid::paintMenuListButton(RenderObject* obj, const PaintInfo&
bool RenderThemeAndroid::supportsFocusRing(const RenderStyle* style) const
{
return style->opacity() > 0
- && style->hasAppearance()
- && style->appearance() != TextFieldPart
- && style->appearance() != SearchFieldPart
- && style->appearance() != TextAreaPart
+ && style->hasAppearance()
+ && style->appearance() != TextFieldPart
+ && style->appearance() != SearchFieldPart
+ && style->appearance() != TextAreaPart
&& style->appearance() != CheckboxPart
&& style->appearance() != RadioPart
&& style->appearance() != PushButtonPart
diff --git a/Source/WebCore/platform/android/RenderThemeAndroid.h b/Source/WebCore/platform/android/RenderThemeAndroid.h
index e3922a1..7ac372d 100644
--- a/Source/WebCore/platform/android/RenderThemeAndroid.h
+++ b/Source/WebCore/platform/android/RenderThemeAndroid.h
@@ -31,7 +31,6 @@
namespace WebCore {
-class RenderSkinButton;
class RenderSkinRadio;
class RenderSkinCombo;
diff --git a/Source/WebCore/platform/graphics/android/PlatformGraphicsContext.h b/Source/WebCore/platform/graphics/android/PlatformGraphicsContext.h
index d22dbd8..80ea5d6 100644
--- a/Source/WebCore/platform/graphics/android/PlatformGraphicsContext.h
+++ b/Source/WebCore/platform/graphics/android/PlatformGraphicsContext.h
@@ -28,7 +28,6 @@
#include "IntRect.h"
#include "RenderSkinAndroid.h"
-#include "RenderSkinButton.h"
#include "SkCanvas.h"
#include "SkPicture.h"
#include "SkTDArray.h"
diff --git a/Source/WebKit/Android.mk b/Source/WebKit/Android.mk
index f581111..6f9d8eb 100644
--- a/Source/WebKit/Android.mk
+++ b/Source/WebKit/Android.mk
@@ -49,7 +49,6 @@ endif # HTTP_STACK == chrome
LOCAL_SRC_FILES += \
android/RenderSkinAndroid.cpp \
- android/RenderSkinButton.cpp \
android/RenderSkinCombo.cpp \
android/RenderSkinMediaButton.cpp \
android/RenderSkinNinePatch.cpp \
diff --git a/Source/WebKit/android/RenderSkinAndroid.cpp b/Source/WebKit/android/RenderSkinAndroid.cpp
index e6fb67b..0662bbe 100644
--- a/Source/WebKit/android/RenderSkinAndroid.cpp
+++ b/Source/WebKit/android/RenderSkinAndroid.cpp
@@ -27,7 +27,6 @@
#include "config.h"
#include "RenderSkinAndroid.h"
-#include "RenderSkinButton.h"
#include "RenderSkinCombo.h"
#include "RenderSkinMediaButton.h"
#include "RenderSkinRadio.h"
@@ -43,7 +42,6 @@ RenderSkinAndroid::Resolution RenderSkinAndroid::s_drawableResolution = RenderSk
RenderSkinAndroid::~RenderSkinAndroid()
{
- delete m_button;
}
RenderSkinAndroid::RenderSkinAndroid(String drawableDirectory)
{
@@ -56,7 +54,6 @@ RenderSkinAndroid::RenderSkinAndroid(String drawableDirectory)
s_drawableDirectory = drawableDirectory;
}
- m_button = new RenderSkinButton(drawableDirectory);
}
bool RenderSkinAndroid::DecodeBitmap(android::AssetManager* am, const char* fileName, SkBitmap* bitmap)
diff --git a/Source/WebKit/android/RenderSkinAndroid.h b/Source/WebKit/android/RenderSkinAndroid.h
index bbc327d..1d3820d 100644
--- a/Source/WebKit/android/RenderSkinAndroid.h
+++ b/Source/WebKit/android/RenderSkinAndroid.h
@@ -36,7 +36,6 @@ class SkBitmap;
namespace WebCore {
class Node;
-class RenderSkinButton;
class RenderSkinAndroid
{
@@ -69,12 +68,9 @@ public:
static String DrawableDirectory() { return s_drawableDirectory; }
static Resolution DrawableResolution() { return s_drawableResolution; }
- RenderSkinButton* renderSkinButton() const { return m_button; }
-
private:
static String s_drawableDirectory;
static Resolution s_drawableResolution;
- RenderSkinButton* m_button;
};
} // WebCore
diff --git a/Source/WebKit/android/RenderSkinButton.cpp b/Source/WebKit/android/RenderSkinButton.cpp
deleted file mode 100644
index 7ab50aa..0000000
--- a/Source/WebKit/android/RenderSkinButton.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2006, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#define LOG_TAG "WebCore"
-
-#include "config.h"
-#include "android_graphics.h"
-#include "Document.h"
-#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>
-
-extern android::AssetManager* globalAssetManager();
-
-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"
- };
-
-namespace WebCore {
-
-RenderSkinButton::RenderSkinButton(String drawableDirectory)
- : m_decoded(false)
- , m_decodingAttempted(false)
- , m_drawableDirectory(drawableDirectory)
-{
- // Ensure our enums properly line up with our arrays.
- android::CompileTimeAssert<(RenderSkinAndroid::kDisabled == 0)> a1;
- android::CompileTimeAssert<(RenderSkinAndroid::kNormal == 1)> a2;
- android::CompileTimeAssert<(RenderSkinAndroid::kFocused == 2)> a3;
- android::CompileTimeAssert<(RenderSkinAndroid::kPressed == 3)> a4;
-}
-
-void RenderSkinButton::decode()
-{
- m_decodingAttempted = true;
-
- android::AssetManager* am = globalAssetManager();
-
- for (size_t i = 0; i < 4; i++) {
- String path = m_drawableDirectory;
- path.append(String(gFiles[i]));
- if (!RenderSkinNinePatch::decodeAsset(am, path.utf8().data(), &m_buttons[i])) {
- m_decoded = false;
- ALOGE("RenderSkinButton::decode: button assets failed to decode\n\tWebView buttons will not draw");
- return;
- }
- }
- m_decoded = true;
-}
-
-void RenderSkinButton::draw(SkCanvas* canvas, const IntRect& r,
- RenderSkinAndroid::State newState)
-{
- if (!m_decodingAttempted)
- decode();
-
- // 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 (!m_decoded) {
- return;
- }
-
- // Ensure that the state is within the valid range of our array.
- SkASSERT(static_cast<unsigned>(newState) <
- static_cast<unsigned>(RenderSkinAndroid::kNumStates));
-
- RenderSkinNinePatch::DrawNinePatch(canvas, SkRect(r), m_buttons[newState]);
-}
-
-} //WebCore
diff --git a/Source/WebKit/android/RenderSkinButton.h b/Source/WebKit/android/RenderSkinButton.h
deleted file mode 100644
index 83c57dd..0000000
--- a/Source/WebKit/android/RenderSkinButton.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2006, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef RenderSkinButton_h
-#define RenderSkinButton_h
-
-#include "RenderSkinAndroid.h"
-#include "RenderSkinNinePatch.h"
-
-class SkCanvas;
-
-namespace WebCore {
-class IntRect;
-
-class RenderSkinButton {
-public:
- RenderSkinButton(String drawableDirectory);
- /**
- * Draw the skin to the canvas, using the rectangle for its bounds and the
- * State to determine which skin to use, i.e. focused or not focused.
- */
- void draw(SkCanvas* , const IntRect& , RenderSkinAndroid::State);
-
- void decode();
-private:
- bool m_decoded;
- bool m_decodingAttempted;
- NinePatch m_buttons[4];
- String m_drawableDirectory;
-};
-
-} // WebCore
-#endif
diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp
index b1ca2ac..78881a9 100644
--- a/Source/WebKit/android/nav/WebView.cpp
+++ b/Source/WebKit/android/nav/WebView.cpp
@@ -199,7 +199,6 @@ WebView(JNIEnv* env, jobject javaWebView, int viewImpl, WTF::String drawableDir,
m_baseLayer = 0;
m_glDrawFunctor = 0;
m_isDrawingPaused = false;
- m_buttonSkin = drawableDir.isEmpty() ? 0 : new RenderSkinButton(drawableDir);
#if USE(ACCELERATED_COMPOSITING)
m_glWebViewState = 0;
m_pageSwapCallbackRegistered = false;
@@ -223,7 +222,6 @@ WebView(JNIEnv* env, jobject javaWebView, int viewImpl, WTF::String drawableDir,
delete m_frameCacheUI;
SkSafeUnref(m_baseLayer);
delete m_glDrawFunctor;
- delete m_buttonSkin;
}
void stopGL()
@@ -1536,7 +1534,6 @@ private: // local state for WebView
GLWebViewState* m_glWebViewState;
bool m_pageSwapCallbackRegistered;
#endif
- RenderSkinButton* m_buttonSkin;
SkRect m_visibleRect;
bool m_isHighEndGfx;
}; // end of WebView class