Nix Upstream: Updating WebCore files
[WebKit-https.git] / Source / WebCore / platform / nix / RenderThemeNix.cpp
index dfb5681..edb37b9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 20122013 Nokia Corporation and/or its subsidiary(-ies).
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "config.h"
 #include "RenderThemeNix.h"
 
+#include "HTMLMediaElement.h"
 #include "InputTypeNames.h"
 #include "PaintInfo.h"
 #include "PlatformContextCairo.h"
+#include "UserAgentStyleSheets.h"
+#include "public/Canvas.h"
 #include "public/Platform.h"
-#include "public/WebCanvas.h"
-#include "public/WebRect.h"
-#include "public/WebThemeEngine.h"
+#include "public/Rect.h"
+#include "public/ThemeEngine.h"
 #if ENABLE(PROGRESS_ELEMENT)
 #include "RenderProgress.h"
 #endif
@@ -43,8 +45,6 @@
 
 namespace WebCore {
 
-static const unsigned defaultButtonBackgroundColor = 0xffdddddd;
-
 static void setSizeIfAuto(RenderStyle* style, const IntSize& size)
 {
     if (style->width().isIntrinsicOrAuto())
@@ -53,19 +53,24 @@ static void setSizeIfAuto(RenderStyle* style, const IntSize& size)
         style->setHeight(Length(size.height(), Fixed));
 }
 
-Color toColor(const WebKit::WebColor& color)
+static Nix::ThemeEngine* themeEngine()
 {
-    return WebCore::Color(RGBA32(color));
+    return Nix::Platform::current()->themeEngine();
 }
 
-static WebKit::WebThemeEngine* themeEngine()
+static Nix::Canvas* webCanvas(const PaintInfo& info)
 {
-    return WebKit::Platform::current()->themeEngine();
+    return info.context->platformContext()->cr();
 }
 
-static WebKit::WebCanvas* webCanvas(const PaintInfo& info)
+static IntSize toIntSize(const Nix::Size& size)
 {
-    return info.context->platformContext()->cr();
+    return IntSize(size.width, size.height);
+}
+
+static Nix::Rect toNixRect(const IntRect& rect)
+{
+    return Nix::Rect(rect.x(), rect.y(), rect.width(), rect.height());
 }
 
 PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page*)
@@ -105,63 +110,63 @@ String RenderThemeNix::extraPlugInsStyleSheet()
 
 Color RenderThemeNix::platformActiveSelectionBackgroundColor() const
 {
-    return toColor(themeEngine()->activeSelectionBackgroundColor());
+    return themeEngine()->activeSelectionBackgroundColor().argb32();
 }
 
 Color RenderThemeNix::platformInactiveSelectionBackgroundColor() const
 {
-    return toColor(themeEngine()->inactiveSelectionBackgroundColor());
+    return themeEngine()->inactiveSelectionBackgroundColor().argb32();
 }
 
 Color RenderThemeNix::platformActiveSelectionForegroundColor() const
 {
-    return toColor(themeEngine()->activeSelectionForegroundColor());
+    return themeEngine()->activeSelectionForegroundColor().argb32();
 }
 
 Color RenderThemeNix::platformInactiveSelectionForegroundColor() const
 {
-    return toColor(themeEngine()->inactiveSelectionForegroundColor());
+    return themeEngine()->inactiveSelectionForegroundColor().argb32();
 }
 
 Color RenderThemeNix::platformActiveListBoxSelectionBackgroundColor() const
 {
-    return toColor(themeEngine()->activeListBoxSelectionBackgroundColor());
+    return themeEngine()->activeListBoxSelectionBackgroundColor().argb32();
 }
 
 Color RenderThemeNix::platformInactiveListBoxSelectionBackgroundColor() const
 {
-    return toColor(themeEngine()->inactiveListBoxSelectionBackgroundColor());
+    return themeEngine()->inactiveListBoxSelectionBackgroundColor().argb32();
 }
 
 Color RenderThemeNix::platformActiveListBoxSelectionForegroundColor() const
 {
-    return toColor(themeEngine()->activeListBoxSelectionForegroundColor());
+    return themeEngine()->activeListBoxSelectionForegroundColor().argb32();
 }
 
 Color RenderThemeNix::platformInactiveListBoxSelectionForegroundColor() const
 {
-    return toColor(themeEngine()->inactiveListBoxSelectionForegroundColor());
+    return themeEngine()->inactiveListBoxSelectionForegroundColor().argb32();
 }
 
 Color RenderThemeNix::platformActiveTextSearchHighlightColor() const
 {
-    return toColor(themeEngine()->activeTextSearchHighlightColor());
+    return themeEngine()->activeTextSearchHighlightColor().argb32();
 }
 
 Color RenderThemeNix::platformInactiveTextSearchHighlightColor() const
 {
-    return toColor(themeEngine()->inactiveTextSearchHighlightColor());
+    return themeEngine()->inactiveTextSearchHighlightColor().argb32();
 }
 
 Color RenderThemeNix::platformFocusRingColor() const
 {
-    return toColor(themeEngine()->focusRingColor());
+    return themeEngine()->focusRingColor().argb32();
 }
 
 #if ENABLE(TOUCH_EVENTS)
 Color RenderThemeNix::platformTapHighlightColor() const
 {
-    return toColor(themeEngine()->tapHighlightColor());
+    return themeEngine()->tapHighlightColor().argb32();
 }
 #endif
 
@@ -169,28 +174,24 @@ void RenderThemeNix::systemFont(WebCore::CSSValueID, FontDescription&) const
 {
 }
 
-static WebKit::WebThemeEngine::State getWebThemeState(const RenderTheme* theme, const RenderObject* o)
+static Nix::ThemeEngine::State getWebThemeState(const RenderTheme* theme, const RenderObject* o)
 {
     if (!theme->isEnabled(o))
-        return WebKit::WebThemeEngine::StateDisabled;
+        return Nix::ThemeEngine::StateDisabled;
     if (theme->isPressed(o))
-        return WebKit::WebThemeEngine::StatePressed;
+        return Nix::ThemeEngine::StatePressed;
     if (theme->isHovered(o))
-        return WebKit::WebThemeEngine::StateHover;
+        return Nix::ThemeEngine::StateHover;
 
-    return WebKit::WebThemeEngine::StateNormal;
+    return Nix::ThemeEngine::StateNormal;
 }
 
 bool RenderThemeNix::paintButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
-    WebKit::WebThemeEngine::ButtonExtraParams extraParams;
+    Nix::ThemeEngine::ButtonExtraParams extraParams;
     extraParams.isDefault = isDefault(o);
     extraParams.hasBorder = true;
-    extraParams.backgroundColor = defaultButtonBackgroundColor;
-    if (o->hasBackground())
-        extraParams.backgroundColor = o->style()->visitedDependentColor(CSSPropertyBackgroundColor).rgb();
-
-    themeEngine()->paintButton(webCanvas(i), getWebThemeState(this, o), WebKit::WebRect(rect), extraParams);
+    themeEngine()->paintButton(webCanvas(i), getWebThemeState(this, o), toNixRect(rect), extraParams);
     return false;
 }
 
@@ -198,10 +199,10 @@ bool RenderThemeNix::paintTextField(RenderObject* o, const PaintInfo& i, const I
 {
     // WebThemeEngine does not handle border rounded corner and background image
     // so return true to draw CSS border and background.
-    if (o->style()->hasBorderRadius() || o->style()->hasBackgroundImage())
+    if (o->style().hasBorderRadius() || o->style().hasBackgroundImage())
         return true;
 
-    themeEngine()->paintTextField(webCanvas(i), getWebThemeState(this, o), WebKit::WebRect(rect));
+    themeEngine()->paintTextField(webCanvas(i), getWebThemeState(this, o), toNixRect(rect));
     return false;
 }
 
@@ -212,11 +213,11 @@ bool RenderThemeNix::paintTextArea(RenderObject* o, const PaintInfo& i, const In
 
 bool RenderThemeNix::paintCheckbox(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
-    WebKit::WebThemeEngine::ButtonExtraParams extraParams;
+    Nix::ThemeEngine::ButtonExtraParams extraParams;
     extraParams.checked = isChecked(o);
     extraParams.indeterminate = isIndeterminate(o);
 
-    themeEngine()->paintCheckbox(webCanvas(i), getWebThemeState(this, o), WebKit::WebRect(rect), extraParams);
+    themeEngine()->paintCheckbox(webCanvas(i), getWebThemeState(this, o), toNixRect(rect), extraParams);
     return false;
 }
 
@@ -226,17 +227,17 @@ void RenderThemeNix::setCheckboxSize(RenderStyle* style) const
     if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
         return;
 
-    IntSize size = themeEngine()->getCheckboxSize();
+    IntSize size = toIntSize(themeEngine()->getCheckboxSize());
     setSizeIfAuto(style, size);
 }
 
 bool RenderThemeNix::paintRadio(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
-    WebKit::WebThemeEngine::ButtonExtraParams extraParams;
+    Nix::ThemeEngine::ButtonExtraParams extraParams;
     extraParams.checked = isChecked(o);
     extraParams.indeterminate = isIndeterminate(o);
 
-    themeEngine()->paintRadio(webCanvas(i), getWebThemeState(this, o), WebKit::WebRect(rect), extraParams);
+    themeEngine()->paintRadio(webCanvas(i), getWebThemeState(this, o), toNixRect(rect), extraParams);
     return false;
 }
 
@@ -246,13 +247,13 @@ void RenderThemeNix::setRadioSize(RenderStyle* style) const
     if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
         return;
 
-    IntSize size = themeEngine()->getRadioSize();
+    IntSize size = toIntSize(themeEngine()->getRadioSize());
     setSizeIfAuto(style, size);
 }
 
 bool RenderThemeNix::paintMenuList(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
-    themeEngine()->paintMenuList(webCanvas(i), getWebThemeState(this, o), WebKit::WebRect(rect));
+    themeEngine()->paintMenuList(webCanvas(i), getWebThemeState(this, o), toNixRect(rect));
     return false;
 }
 
@@ -281,12 +282,12 @@ void RenderThemeNix::adjustProgressBarStyle(StyleResolver*, RenderStyle* style,
 bool RenderThemeNix::paintProgressBar(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
     RenderProgress* renderProgress = toRenderProgress(o);
-    WebKit::WebThemeEngine::ProgressBarExtraParams extraParams;
+    Nix::ThemeEngine::ProgressBarExtraParams extraParams;
     extraParams.isDeterminate = renderProgress->isDeterminate();
     extraParams.position = renderProgress->position();
     extraParams.animationProgress = renderProgress->animationProgress();
     extraParams.animationStartTime = renderProgress->animationStartTime();
-    themeEngine()->paintProgressBar(webCanvas(i), getWebThemeState(this, o), WebKit::WebRect(rect), extraParams);
+    themeEngine()->paintProgressBar(webCanvas(i), getWebThemeState(this, o), toNixRect(rect), extraParams);
 
     return false;
 }
@@ -304,7 +305,7 @@ double RenderThemeNix::animationDurationForProgressBar(RenderProgress*) const
 
 bool RenderThemeNix::paintSliderTrack(RenderObject* object, const PaintInfo& info, const IntRect& rect)
 {
-    themeEngine()->paintSliderTrack(webCanvas(info), getWebThemeState(this, object), rect);
+    themeEngine()->paintSliderTrack(webCanvas(info), getWebThemeState(this, object), toNixRect(rect));
 #if ENABLE(DATALIST_ELEMENT)
     paintSliderTicks(object, info, rect);
 #endif
@@ -318,7 +319,7 @@ void RenderThemeNix::adjustSliderTrackStyle(StyleResolver*, RenderStyle* style,
 
 bool RenderThemeNix::paintSliderThumb(RenderObject* object, const PaintInfo& info, const IntRect& rect)
 {
-    themeEngine()->paintSliderThumb(webCanvas(info), getWebThemeState(this, object), rect);
+    themeEngine()->paintSliderThumb(webCanvas(info), getWebThemeState(this, object), toNixRect(rect));
 
     return false;
 }
@@ -384,11 +385,11 @@ void RenderThemeNix::adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle* sty
 
 bool RenderThemeNix::paintInnerSpinButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
 {
-    WebKit::WebThemeEngine::InnerSpinButtonExtraParams extraParams;
+    Nix::ThemeEngine::InnerSpinButtonExtraParams extraParams;
     extraParams.spinUp = isSpinUpButtonPartPressed(o);
     extraParams.readOnly = isReadOnlyControl(o);
 
-    themeEngine()->paintInnerSpinButton(webCanvas(i), getWebThemeState(this, o), WebKit::WebRect(rect), extraParams);
+    themeEngine()->paintInnerSpinButton(webCanvas(i), getWebThemeState(this, o), toNixRect(rect), extraParams);
     return false;
 }
 
@@ -424,7 +425,7 @@ bool RenderThemeNix::paintMeter(RenderObject* o, const PaintInfo& i, const IntRe
 
     RenderMeter* renderMeter = toRenderMeter(o);
     HTMLMeterElement* e = renderMeter->meterElement();
-    WebKit::WebThemeEngine::MeterExtraParams extraParams;
+    Nix::ThemeEngine::MeterExtraParams extraParams;
     extraParams.min = e->min();
     extraParams.max = e->max();
     extraParams.value = e->value();
@@ -432,10 +433,65 @@ bool RenderThemeNix::paintMeter(RenderObject* o, const PaintInfo& i, const IntRe
     extraParams.high = e->high();
     extraParams.optimum = e->optimum();
 
-    themeEngine()->paintMeter(webCanvas(i), getWebThemeState(this, o), rect, extraParams);
+    themeEngine()->paintMeter(webCanvas(i), getWebThemeState(this, o), toNixRect(rect), extraParams);
 
     return false;
 }
 #endif
 
+#if ENABLE(VIDEO)
+String RenderThemeNix::extraMediaControlsStyleSheet()
+{
+    return String(mediaControlsNixUserAgentStyleSheet, sizeof(mediaControlsNixUserAgentStyleSheet));
+}
+
+bool RenderThemeNix::paintMediaPlayButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
+{
+    auto state = toHTMLMediaElement(o->node()->shadowHost())->canPlay() ? Nix::ThemeEngine::StatePaused : Nix::ThemeEngine::StatePlaying;
+    themeEngine()->paintMediaPlayButton(webCanvas(i), state, toNixRect(rect));
+    return false;
+}
+
+bool RenderThemeNix::paintMediaMuteButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
+{
+    auto state = toHTMLMediaElement(o->node()->shadowHost())->muted() ? Nix::ThemeEngine::StateMuted : Nix::ThemeEngine::StateNotMuted;
+    themeEngine()->paintMediaMuteButton(webCanvas(i), state, toNixRect(rect));
+    return false;
+}
+
+bool RenderThemeNix::paintMediaSeekBackButton(RenderObject*, const PaintInfo& i, const IntRect& rect)
+{
+    themeEngine()->paintMediaSeekBackButton(webCanvas(i), toNixRect(rect));
+    return false;
+}
+
+bool RenderThemeNix::paintMediaSeekForwardButton(RenderObject*, const PaintInfo& i, const IntRect& rect)
+{
+    themeEngine()->paintMediaSeekForwardButton(webCanvas(i), toNixRect(rect));
+    return false;
+}
+
+bool RenderThemeNix::paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&)
+{
+    return false;
+}
+
+bool RenderThemeNix::paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&)
+{
+    return false;
 }
+
+bool RenderThemeNix::paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&)
+{
+    return false;
+}
+
+bool RenderThemeNix::paintMediaRewindButton(RenderObject*, const PaintInfo& i, const IntRect& rect)
+{
+    themeEngine()->paintMediaRewindButton(webCanvas(i), toNixRect(rect));
+    return false;
+}
+#endif // ENABLE(VIDEO)
+
+} // namespace WebCore
+