summaryrefslogtreecommitdiffstats
path: root/WebCore/rendering/RenderThemeChromiumLinux.cpp
diff options
context:
space:
mode:
authorFeng Qian <fqian@google.com>2009-06-17 12:12:20 -0700
committerFeng Qian <fqian@google.com>2009-06-17 12:12:20 -0700
commit5f1ab04193ad0130ca8204aadaceae083aca9881 (patch)
tree5a92cd389e2cfe7fb67197ce14b38469462379f8 /WebCore/rendering/RenderThemeChromiumLinux.cpp
parent194315e5a908cc8ed67d597010544803eef1ac59 (diff)
downloadexternal_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.zip
external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.gz
external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.bz2
Get WebKit r44544.
Diffstat (limited to 'WebCore/rendering/RenderThemeChromiumLinux.cpp')
-rw-r--r--WebCore/rendering/RenderThemeChromiumLinux.cpp266
1 files changed, 241 insertions, 25 deletions
diff --git a/WebCore/rendering/RenderThemeChromiumLinux.cpp b/WebCore/rendering/RenderThemeChromiumLinux.cpp
index 8c6874d..8049403 100644
--- a/WebCore/rendering/RenderThemeChromiumLinux.cpp
+++ b/WebCore/rendering/RenderThemeChromiumLinux.cpp
@@ -27,9 +27,12 @@
#include "ChromiumBridge.h"
#include "CSSValueKeywords.h"
#include "GraphicsContext.h"
+#include "HTMLMediaElement.h"
+#include "HTMLNames.h"
#include "Image.h"
-#include "NotImplemented.h"
+#include "MediaControlElements.h"
#include "PlatformContextSkia.h"
+#include "RenderBox.h"
#include "RenderObject.h"
#include "ScrollbarTheme.h"
#include "TransformationMatrix.h"
@@ -52,7 +55,21 @@ static const int styledMenuListInternalPadding[4] = { 1, 4, 1, 4 };
// The default variable-width font size. We use this as the default font
// size for the "system font", and as a base size (which we then shrink) for
// form control fonts.
-static const float DefaultFontSize = 16.0;
+static const float defaultFontSize = 16.0;
+
+// The background for the media player controls should be a 60% opaque black rectangle. This
+// matches the UI mockups for the default UI theme.
+static const float defaultMediaControlOpacity = 0.6f;
+
+// These values all match Safari/Win.
+static const float defaultControlFontPixelSize = 13;
+static const float defaultCancelButtonSize = 9;
+static const float minCancelButtonSize = 5;
+static const float maxCancelButtonSize = 21;
+static const float defaultSearchFieldResultsDecorationSize = 13;
+static const float minSearchFieldResultsDecorationSize = 9;
+static const float maxSearchFieldResultsDecorationSize = 30;
+static const float defaultSearchFieldResultsButtonWidth = 18;
static bool supportsFocus(ControlPart appearance)
{
@@ -77,11 +94,25 @@ static void setSizeIfAuto(RenderStyle* style, const IntSize& size)
// FIXME: The only case where we know we don't match IE is for ANSI encodings.
// IE uses MS Shell Dlg there, which we render incorrectly at certain pixel
// sizes (e.g. 15px). So, for now we just use Arial.
-static const char* defaultGUIFont(Document* document)
+static const char* defaultGUIFont()
{
return "Arial";
}
+#if ENABLE(VIDEO)
+// Attempt to retrieve a HTMLMediaElement from a Node. Returns NULL if one cannot be found.
+static HTMLMediaElement* mediaElementParent(Node* node)
+{
+ if (!node)
+ return 0;
+ Node* mediaNode = node->shadowAncestorNode();
+ if (!mediaNode || (!mediaNode->hasTagName(HTMLNames::videoTag) && !mediaNode->hasTagName(HTMLNames::audioTag)))
+ return 0;
+
+ return static_cast<HTMLMediaElement*>(mediaNode);
+}
+#endif
+
RenderTheme* theme()
{
static RenderThemeChromiumLinux theme;
@@ -92,10 +123,20 @@ RenderThemeChromiumLinux::RenderThemeChromiumLinux()
{
}
+Color RenderThemeChromiumLinux::systemColor(int cssValueId) const
+{
+ static const Color linuxButtonGrayColor(0xffdddddd);
+
+ if (cssValueId == CSSValueButtonface)
+ return linuxButtonGrayColor;
+ return RenderTheme::systemColor(cssValueId);
+}
+
// Use the Windows style sheets to match their metrics.
String RenderThemeChromiumLinux::extraDefaultStyleSheet()
{
- return String(themeChromiumWinUserAgentStyleSheet, sizeof(themeChromiumWinUserAgentStyleSheet));
+ return String(themeWinUserAgentStyleSheet, sizeof(themeWinUserAgentStyleSheet)) +
+ String(themeChromiumLinuxUserAgentStyleSheet, sizeof(themeChromiumLinuxUserAgentStyleSheet));
}
String RenderThemeChromiumLinux::extraQuirksStyleSheet()
@@ -103,6 +144,13 @@ String RenderThemeChromiumLinux::extraQuirksStyleSheet()
return String(themeWinQuirksUserAgentStyleSheet, sizeof(themeWinQuirksUserAgentStyleSheet));
}
+#if ENABLE(VIDEO)
+String RenderThemeChromiumLinux::extraMediaControlsStyleSheet()
+{
+ return String(mediaControlsChromiumUserAgentStyleSheet, sizeof(mediaControlsChromiumUserAgentStyleSheet));
+}
+#endif
+
bool RenderThemeChromiumLinux::supportsFocusRing(const RenderStyle* style) const
{
return supportsFocus(style->appearance());
@@ -120,7 +168,7 @@ Color RenderThemeChromiumLinux::platformInactiveSelectionBackgroundColor() const
Color RenderThemeChromiumLinux::platformActiveSelectionForegroundColor() const
{
- return Color(0, 0, 0);
+ return Color::black;
}
Color RenderThemeChromiumLinux::platformInactiveSelectionForegroundColor() const
@@ -144,9 +192,9 @@ double RenderThemeChromiumLinux::caretBlinkInterval() const
return 0.5;
}
-void RenderThemeChromiumLinux::systemFont(int propId, Document* document, FontDescription& fontDescription) const
+void RenderThemeChromiumLinux::systemFont(int propId, FontDescription& fontDescription) const
{
- float fontSize = DefaultFontSize;
+ float fontSize = defaultFontSize;
switch (propId) {
case CSSValueWebkitMiniControl:
@@ -161,7 +209,7 @@ void RenderThemeChromiumLinux::systemFont(int propId, Document* document, FontDe
break;
}
- fontDescription.firstFamily().setFamily(defaultGUIFont(NULL));
+ fontDescription.firstFamily().setFamily(defaultGUIFont());
fontDescription.setSpecifiedSize(fontSize);
fontDescription.setIsAbsoluteSize(true);
fontDescription.setGenericFamily(FontDescription::NoFamily);
@@ -215,16 +263,36 @@ void RenderThemeChromiumLinux::setRadioSize(RenderStyle* style) const
setCheckboxSize(style);
}
-static void paintButtonLike(RenderTheme* theme, RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect) {
+static SkColor brightenColor(double h, double s, double l, float brightenAmount)
+{
+ l += brightenAmount;
+ if (l > 1.0)
+ l = 1.0;
+ if (l < 0.0)
+ l = 0.0;
+
+ return makeRGBAFromHSLA(h, s, l, 1.0);
+}
+
+static void paintButtonLike(RenderTheme* theme, RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+{
SkCanvas* const canvas = i.context->platformContext()->canvas();
SkPaint paint;
SkRect skrect;
const int right = rect.x() + rect.width();
const int bottom = rect.y() + rect.height();
+ SkColor baseColor = SkColorSetARGB(0xff, 0xdd, 0xdd, 0xdd);
+ if (o->style()->hasBackground())
+ baseColor = o->style()->backgroundColor().rgb();
+ double h, s, l;
+ Color(baseColor).getHSL(h, s, l);
+ // Our standard gradient is from 0xdd to 0xf8. This is the amount of
+ // increased luminance between those values.
+ SkColor lightColor(brightenColor(h, s, l, 0.105));
// If the button is too small, fallback to drawing a single, solid color
if (rect.width() < 5 || rect.height() < 5) {
- paint.setARGB(0xff, 0xe9, 0xe9, 0xe9);
+ paint.setColor(baseColor);
skrect.set(rect.x(), rect.y(), right, bottom);
canvas->drawRect(skrect, paint);
return;
@@ -244,20 +312,20 @@ static void paintButtonLike(RenderTheme* theme, RenderObject* o, const RenderObj
p[lightEnd].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y()));
p[darkEnd].set(SkIntToScalar(rect.x()), SkIntToScalar(bottom - 1));
SkColor colors[2];
- colors[0] = SkColorSetARGB(0xff, 0xf8, 0xf8, 0xf8);
- colors[1] = SkColorSetARGB(0xff, 0xdd, 0xdd, 0xdd);
+ colors[0] = lightColor;
+ colors[1] = baseColor;
- SkShader* s = SkGradientShader::CreateLinear(
+ SkShader* shader = SkGradientShader::CreateLinear(
p, colors, NULL, 2, SkShader::kClamp_TileMode, NULL);
paint.setStyle(SkPaint::kFill_Style);
- paint.setShader(s);
- s->unref();
+ paint.setShader(shader);
+ shader->unref();
skrect.set(rect.x() + 1, rect.y() + 1, right - 1, bottom - 1);
canvas->drawRect(skrect, paint);
paint.setShader(NULL);
- paint.setARGB(0xff, 0xce, 0xce, 0xce);
+ paint.setColor(brightenColor(h, s, l, -0.0588));
canvas->drawPoint(rect.x() + 1, rect.y() + 1, paint);
canvas->drawPoint(right - 2, rect.y() + 1, paint);
canvas->drawPoint(rect.x() + 1, bottom - 2, paint);
@@ -275,24 +343,172 @@ bool RenderThemeChromiumLinux::paintTextField(RenderObject* o, const RenderObjec
return true;
}
-bool RenderThemeChromiumLinux::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+void RenderThemeChromiumLinux::adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
{
- return true;
+ // Scale the button size based on the font size
+ float fontScale = style->fontSize() / defaultControlFontPixelSize;
+ int cancelButtonSize = lroundf(std::min(std::max(minCancelButtonSize, defaultCancelButtonSize * fontScale), maxCancelButtonSize));
+ style->setWidth(Length(cancelButtonSize, Fixed));
+ style->setHeight(Length(cancelButtonSize, Fixed));
}
-bool RenderThemeChromiumLinux::paintSearchFieldResultsDecoration(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+bool RenderThemeChromiumLinux::paintSearchFieldCancelButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
- return true;
+ IntRect bounds = r;
+ ASSERT(o->parent());
+ if (!o->parent() || !o->parent()->isBox())
+ return false;
+
+ RenderBox* parentRenderBox = toRenderBox(o->parent());
+
+ IntRect parentBox = parentRenderBox->absoluteContentBox();
+
+ // Make sure the scaled button stays square and will fit in its parent's box
+ bounds.setHeight(std::min(parentBox.width(), std::min(parentBox.height(), bounds.height())));
+ bounds.setWidth(bounds.height());
+
+ // Center the button vertically. Round up though, so if it has to be one pixel off-center, it will
+ // be one pixel closer to the bottom of the field. This tends to look better with the text.
+ bounds.setY(parentBox.y() + (parentBox.height() - bounds.height() + 1) / 2);
+
+ static Image* cancelImage = Image::loadPlatformResource("searchCancel").releaseRef();
+ static Image* cancelPressedImage = Image::loadPlatformResource("searchCancelPressed").releaseRef();
+ i.context->drawImage(isPressed(o) ? cancelPressedImage : cancelImage, bounds);
+ return false;
}
-bool RenderThemeChromiumLinux::paintSearchFieldResultsButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+void RenderThemeChromiumLinux::adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
{
- return true;
+ IntSize emptySize(1, 11);
+ style->setWidth(Length(emptySize.width(), Fixed));
+ style->setHeight(Length(emptySize.height(), Fixed));
}
-bool RenderThemeChromiumLinux::paintSearchFieldCancelButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect)
+void RenderThemeChromiumLinux::adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
{
- return true;
+ // Scale the decoration size based on the font size
+ float fontScale = style->fontSize() / defaultControlFontPixelSize;
+ int magnifierSize = lroundf(std::min(std::max(minSearchFieldResultsDecorationSize, defaultSearchFieldResultsDecorationSize * fontScale),
+ maxSearchFieldResultsDecorationSize));
+ style->setWidth(Length(magnifierSize, Fixed));
+ style->setHeight(Length(magnifierSize, Fixed));
+}
+
+bool RenderThemeChromiumLinux::paintSearchFieldResultsDecoration(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
+{
+ IntRect bounds = r;
+ ASSERT(o->parent());
+ if (!o->parent() || !o->parent()->isBox())
+ return false;
+
+ RenderBox* parentRenderBox = toRenderBox(o->parent());
+ IntRect parentBox = parentRenderBox->absoluteContentBox();
+
+ // Make sure the scaled decoration stays square and will fit in its parent's box
+ bounds.setHeight(std::min(parentBox.width(), std::min(parentBox.height(), bounds.height())));
+ bounds.setWidth(bounds.height());
+
+ // Center the decoration vertically. Round up though, so if it has to be one pixel off-center, it will
+ // be one pixel closer to the bottom of the field. This tends to look better with the text.
+ bounds.setY(parentBox.y() + (parentBox.height() - bounds.height() + 1) / 2);
+
+ static Image* magnifierImage = Image::loadPlatformResource("searchMagnifier").releaseRef();
+ i.context->drawImage(magnifierImage, bounds);
+ return false;
+}
+
+void RenderThemeChromiumLinux::adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
+{
+ // Scale the button size based on the font size
+ float fontScale = style->fontSize() / defaultControlFontPixelSize;
+ int magnifierHeight = lroundf(std::min(std::max(minSearchFieldResultsDecorationSize, defaultSearchFieldResultsDecorationSize * fontScale),
+ maxSearchFieldResultsDecorationSize));
+ int magnifierWidth = lroundf(magnifierHeight * defaultSearchFieldResultsButtonWidth / defaultSearchFieldResultsDecorationSize);
+ style->setWidth(Length(magnifierWidth, Fixed));
+ style->setHeight(Length(magnifierHeight, Fixed));
+}
+
+bool RenderThemeChromiumLinux::paintSearchFieldResultsButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
+{
+ IntRect bounds = r;
+ ASSERT(o->parent());
+ if (!o->parent())
+ return false;
+ if (!o->parent() || !o->parent()->isBox())
+ return false;
+
+ RenderBox* parentRenderBox = toRenderBox(o->parent());
+ IntRect parentBox = parentRenderBox->absoluteContentBox();
+
+ // Make sure the scaled decoration will fit in its parent's box
+ bounds.setHeight(std::min(parentBox.height(), bounds.height()));
+ bounds.setWidth(std::min(parentBox.width(), static_cast<int>(bounds.height() * defaultSearchFieldResultsButtonWidth / defaultSearchFieldResultsDecorationSize)));
+
+ // Center the button vertically. Round up though, so if it has to be one pixel off-center, it will
+ // be one pixel closer to the bottom of the field. This tends to look better with the text.
+ bounds.setY(parentBox.y() + (parentBox.height() - bounds.height() + 1) / 2);
+
+ static Image* magnifierImage = Image::loadPlatformResource("searchMagnifierResults").releaseRef();
+ i.context->drawImage(magnifierImage, bounds);
+ return false;
+}
+
+bool RenderThemeChromiumLinux::paintMediaButtonInternal(GraphicsContext* context, const IntRect& rect, Image* image)
+{
+ context->beginTransparencyLayer(defaultMediaControlOpacity);
+
+ // Draw background.
+ Color oldFill = context->fillColor();
+ Color oldStroke = context->strokeColor();
+
+ context->setFillColor(Color::black);
+ context->setStrokeColor(Color::black);
+ context->drawRect(rect);
+
+ context->setFillColor(oldFill);
+ context->setStrokeColor(oldStroke);
+
+ // Create a destination rectangle for the image that is centered in the drawing rectangle, rounded left, and down.
+ IntRect imageRect = image->rect();
+ imageRect.setY(rect.y() + (rect.height() - image->height() + 1) / 2);
+ imageRect.setX(rect.x() + (rect.width() - image->width() + 1) / 2);
+
+ context->drawImage(image, imageRect, CompositeSourceAtop);
+ context->endTransparencyLayer();
+
+ return false;
+}
+
+bool RenderThemeChromiumLinux::paintMediaPlayButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
+{
+#if ENABLE(VIDEO)
+ HTMLMediaElement* mediaElement = mediaElementParent(o->node());
+ if (!mediaElement)
+ return false;
+
+ static Image* mediaPlay = Image::loadPlatformResource("mediaPlay").releaseRef();
+ static Image* mediaPause = Image::loadPlatformResource("mediaPause").releaseRef();
+
+ return paintMediaButtonInternal(paintInfo.context, rect, mediaElement->paused() ? mediaPlay : mediaPause);
+#else
+ return false;
+#endif
+}
+
+bool RenderThemeChromiumLinux::paintMediaMuteButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
+{
+#if ENABLE(VIDEO)
+ HTMLMediaElement* mediaElement = mediaElementParent(o->node());
+ if (!mediaElement)
+ return false;
+
+ static Image* soundFull = Image::loadPlatformResource("mediaSoundFull").releaseRef();
+ static Image* soundNone = Image::loadPlatformResource("mediaSoundNone").releaseRef();
+
+ return paintMediaButtonInternal(paintInfo.context, rect, mediaElement->muted() ? soundNone: soundFull);
+#else
+ return false;
+#endif
}
void RenderThemeChromiumLinux::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, WebCore::Element* e) const
@@ -387,7 +603,7 @@ Color RenderThemeChromiumLinux::activeListBoxSelectionBackgroundColor() const
Color RenderThemeChromiumLinux::activeListBoxSelectionForegroundColor() const
{
- return Color(0, 0, 0);
+ return Color::black;
}
Color RenderThemeChromiumLinux::inactiveListBoxSelectionBackgroundColor() const