summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/qt/RenderThemeQt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/qt/RenderThemeQt.cpp')
-rw-r--r--WebCore/platform/qt/RenderThemeQt.cpp203
1 files changed, 139 insertions, 64 deletions
diff --git a/WebCore/platform/qt/RenderThemeQt.cpp b/WebCore/platform/qt/RenderThemeQt.cpp
index 501a28b..83e3746 100644
--- a/WebCore/platform/qt/RenderThemeQt.cpp
+++ b/WebCore/platform/qt/RenderThemeQt.cpp
@@ -32,6 +32,7 @@
#include "CSSStyleSelector.h"
#include "CSSStyleSheet.h"
+#include "Chrome.h"
#include "ChromeClientQt.h"
#include "Color.h"
#include "Document.h"
@@ -42,10 +43,12 @@
#include "HTMLNames.h"
#include "NotImplemented.h"
#include "Page.h"
+#include "QWebPageClient.h"
#include "RenderBox.h"
+#include "RenderSlider.h"
#include "RenderTheme.h"
+#include "ScrollbarThemeQt.h"
#include "UserAgentStyleSheets.h"
-#include "QWebPageClient.h"
#include "qwebpage.h"
#include <QApplication>
@@ -58,6 +61,7 @@
#include <QStyleFactory>
#include <QStyleOptionButton>
#include <QStyleOptionFrameV2>
+#include <QStyleOptionSlider>
#include <QWidget>
@@ -66,17 +70,17 @@ namespace WebCore {
using namespace HTMLNames;
-StylePainter::StylePainter(const RenderObject::PaintInfo& paintInfo)
+StylePainter::StylePainter(RenderThemeQt* theme, const RenderObject::PaintInfo& paintInfo)
{
- init(paintInfo.context ? paintInfo.context : 0);
+ init(paintInfo.context ? paintInfo.context : 0, theme->qStyle());
}
-StylePainter::StylePainter(GraphicsContext* context)
+StylePainter::StylePainter(ScrollbarThemeQt* theme, GraphicsContext* context)
{
- init(context);
+ init(context, theme->style());
}
-void StylePainter::init(GraphicsContext* context)
+void StylePainter::init(GraphicsContext* context, QStyle* themeStyle)
{
painter = static_cast<QPainter*>(context->platformContext());
widget = 0;
@@ -85,7 +89,7 @@ void StylePainter::init(GraphicsContext* context)
dev = painter->device();
if (dev && dev->devType() == QInternal::Widget)
widget = static_cast<QWidget*>(dev);
- style = (widget ? widget->style() : QApplication::style());
+ style = themeStyle;
if (painter) {
// the styles often assume being called with a pristine painter where no brush is set,
@@ -157,13 +161,10 @@ QStyle* RenderThemeQt::fallbackStyle()
QStyle* RenderThemeQt::qStyle() const
{
if (m_page) {
- ChromeClientQt* client = static_cast<ChromeClientQt*>(m_page->chrome()->client());
-
- if (!client->m_webPage)
- return QApplication::style();
+ QWebPageClient* pageClient = m_page->chrome()->client()->platformPageClient();
- if (QWidget* view = client->m_webPage->view())
- return view->style();
+ if (pageClient)
+ return pageClient->style();
}
return QApplication::style();
@@ -394,8 +395,13 @@ void RenderThemeQt::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* s
// Ditch the border.
style->resetBorder();
- // Height is locked to auto.
- style->setHeight(Length(Auto));
+#ifdef Q_WS_MAC
+ if (style->appearance() == PushButtonPart) {
+ // The Mac ports ignore the specified height for <input type="button"> elements
+ // unless a border and/or background CSS property is also specified.
+ style->setHeight(Length(Auto));
+ }
+#endif
// White-space is locked to pre
style->setWhiteSpace(PRE);
@@ -465,7 +471,7 @@ void RenderThemeQt::setButtonPadding(RenderStyle* style) const
bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
- StylePainter p(i);
+ StylePainter p(this, i);
if (!p.isValid())
return true;
@@ -476,7 +482,7 @@ bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo&
option.rect = r;
option.state |= QStyle::State_Small;
- ControlPart appearance = applyTheme(option, o);
+ ControlPart appearance = initializeCommonQStyleOptions(option, o);
if (appearance == PushButtonPart || appearance == ButtonPart) {
option.rect = inflateButtonRect(option.rect, qStyle());
p.drawControl(QStyle::CE_PushButton, option);
@@ -498,7 +504,7 @@ void RenderThemeQt::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style,
bool RenderThemeQt::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
- StylePainter p(i);
+ StylePainter p(this, i);
if (!p.isValid())
return true;
@@ -512,7 +518,7 @@ bool RenderThemeQt::paintTextField(RenderObject* o, const RenderObject::PaintInf
panel.features = QStyleOptionFrameV2::None;
// Get the correct theme data for a text field
- ControlPart appearance = applyTheme(panel, o);
+ ControlPart appearance = initializeCommonQStyleOptions(panel, o);
if (appearance != TextFieldPart
&& appearance != SearchFieldPart
&& appearance != TextAreaPart
@@ -567,14 +573,14 @@ void RenderThemeQt::setPopupPadding(RenderStyle* style) const
bool RenderThemeQt::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
- StylePainter p(i);
+ StylePainter p(this, i);
if (!p.isValid())
return true;
QStyleOptionComboBox opt;
if (p.widget)
opt.initFrom(p.widget);
- applyTheme(opt, o);
+ initializeCommonQStyleOptions(opt, o);
const QPoint topLeft = r.topLeft();
p.painter->translate(topLeft);
@@ -607,14 +613,14 @@ void RenderThemeQt::adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle* st
bool RenderThemeQt::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i,
const IntRect& r)
{
- StylePainter p(i);
+ StylePainter p(this, i);
if (!p.isValid())
return true;
QStyleOptionComboBox option;
if (p.widget)
option.initFrom(p.widget);
- applyTheme(option, o);
+ initializeCommonQStyleOptions(option, o);
option.rect = r;
// for drawing the combo box arrow, rely only on the fallback style
@@ -628,22 +634,73 @@ bool RenderThemeQt::paintMenuListButton(RenderObject* o, const RenderObject::Pai
bool RenderThemeQt::paintSliderTrack(RenderObject* o, const RenderObject::PaintInfo& pi,
const IntRect& r)
{
- notImplemented();
- return RenderTheme::paintSliderTrack(o, pi, r);
+ StylePainter p(this, pi);
+ if (!p.isValid())
+ return true;
+
+ QStyleOptionSlider option;
+ if (p.widget)
+ option.initFrom(p.widget);
+ ControlPart appearance = initializeCommonQStyleOptions(option, o);
+
+ RenderSlider* renderSlider = toRenderSlider(o);
+ IntRect thumbRect = renderSlider->thumbRect();
+
+ option.rect = r;
+
+ int value;
+ if (appearance == SliderVerticalPart) {
+ option.maximum = r.height() - thumbRect.height();
+ value = thumbRect.y();
+ } else {
+ option.maximum = r.width() - thumbRect.width();
+ value = thumbRect.x();
+ }
+
+ value = QStyle::sliderValueFromPosition(0, option.maximum, value, option.maximum);
+
+ option.sliderValue = value;
+ option.sliderPosition = value;
+ if (appearance == SliderVerticalPart)
+ option.orientation = Qt::Vertical;
+
+ if (renderSlider->inDragMode()) {
+ option.activeSubControls = QStyle::SC_SliderHandle;
+ option.state |= QStyle::State_Sunken;
+ }
+
+ const QPoint topLeft = r.topLeft();
+ p.painter->translate(topLeft);
+ option.rect.moveTo(QPoint(0, 0));
+ option.rect.setSize(r.size());
+
+ p.drawComplexControl(QStyle::CC_Slider, option);
+ p.painter->translate(-topLeft);
+
+ return false;
+}
+
+void RenderThemeQt::adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
+{
+ style->setBoxShadow(0);
}
bool RenderThemeQt::paintSliderThumb(RenderObject* o, const RenderObject::PaintInfo& pi,
const IntRect& r)
{
- notImplemented();
- return RenderTheme::paintSliderThumb(o, pi, r);
+ // We've already painted it in paintSliderTrack(), no need to do anything here.
+ return false;
+}
+
+void RenderThemeQt::adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
+{
+ style->setBoxShadow(0);
}
bool RenderThemeQt::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& pi,
const IntRect& r)
{
- paintTextField(o, pi, r);
- return false;
+ return true;
}
void RenderThemeQt::adjustSearchFieldStyle(CSSStyleSelector* selector, RenderStyle* style,
@@ -706,13 +763,32 @@ bool RenderThemeQt::supportsFocus(ControlPart appearance) const
case MenulistPart:
case RadioPart:
case CheckboxPart:
+ case SliderHorizontalPart:
+ case SliderVerticalPart:
return true;
default: // No for all others...
return false;
}
}
-ControlPart RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) const
+void RenderThemeQt::setPaletteFromPageClientIfExists(QPalette& palette) const
+{
+ // If the webview has a custom palette, use it
+ if (!m_page)
+ return;
+ Chrome* chrome = m_page->chrome();
+ if (!chrome)
+ return;
+ ChromeClient* chromeClient = chrome->client();
+ if (!chromeClient)
+ return;
+ QWebPageClient* pageClient = chromeClient->platformPageClient();
+ if (!pageClient)
+ return;
+ palette = pageClient->palette();
+}
+
+ControlPart RenderThemeQt::initializeCommonQStyleOptions(QStyleOption& option, RenderObject* o) const
{
// Default bits: no focus, no mouse over
option.state &= ~(QStyle::State_HasFocus | QStyle::State_MouseOver);
@@ -724,19 +800,24 @@ ControlPart RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) con
// Readonly is supported on textfields.
option.state |= QStyle::State_ReadOnly;
- if (supportsFocus(o->style()->appearance()) && isFocused(o)) {
- option.state |= QStyle::State_HasFocus;
- option.state |= QStyle::State_KeyboardFocusChange;
- }
+ option.direction = Qt::LeftToRight;
if (isHovered(o))
option.state |= QStyle::State_MouseOver;
- option.direction = Qt::LeftToRight;
- if (o->style() && o->style()->direction() == WebCore::RTL)
- option.direction = Qt::RightToLeft;
+ setPaletteFromPageClientIfExists(option.palette);
+ RenderStyle* style = o->style();
+ if (!style)
+ return NoControlPart;
- ControlPart result = o->style()->appearance();
+ ControlPart result = style->appearance();
+ if (supportsFocus(result) && isFocused(o)) {
+ option.state |= QStyle::State_HasFocus;
+ option.state |= QStyle::State_KeyboardFocusChange;
+ }
+
+ if (style->direction() == WebCore::RTL)
+ option.direction = Qt::RightToLeft;
switch (result) {
case PushButtonPart:
@@ -753,18 +834,9 @@ ControlPart RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) con
option.state |= QStyle::State_Raised;
break;
}
- }
-
- if (result == RadioPart || result == CheckboxPart)
+ case RadioPart:
+ case CheckboxPart:
option.state |= (isChecked(o) ? QStyle::State_On : QStyle::State_Off);
-
- // If the owner widget has a custom palette, use it
- Page* page = o->document()->page();
- if (page) {
- ChromeClient* client = page->chrome()->client();
- QWebPageClient* pageClient = client->platformPageClient();
- if (pageClient)
- option.palette = pageClient->palette();
}
return result;
@@ -833,7 +905,7 @@ bool RenderThemeQt::paintMediaMuteButton(RenderObject* o, const RenderObject::Pa
if (!mediaElement)
return false;
- StylePainter p(paintInfo);
+ StylePainter p(this, paintInfo);
if (!p.isValid())
return true;
@@ -862,7 +934,7 @@ bool RenderThemeQt::paintMediaPlayButton(RenderObject* o, const RenderObject::Pa
if (!mediaElement)
return false;
- StylePainter p(paintInfo);
+ StylePainter p(this, paintInfo);
if (!p.isValid())
return true;
@@ -901,7 +973,7 @@ bool RenderThemeQt::paintMediaSliderTrack(RenderObject* o, const RenderObject::P
if (!mediaElement)
return false;
- StylePainter p(paintInfo);
+ StylePainter p(this, paintInfo);
if (!p.isValid())
return true;
@@ -909,16 +981,6 @@ bool RenderThemeQt::paintMediaSliderTrack(RenderObject* o, const RenderObject::P
paintMediaBackground(p.painter, r);
- if (MediaPlayer* player = mediaElement->player()) {
- if (player->totalBytesKnown()) {
- float percentLoaded = static_cast<float>(player->bytesLoaded()) / player->totalBytes();
-
- WorldMatrixTransformer transformer(p.painter, o, r);
- p.painter->setBrush(getMediaControlForegroundColor());
- p.painter->drawRect(0, 37, 100 * percentLoaded, 26);
- }
- }
-
return false;
}
@@ -928,7 +990,7 @@ bool RenderThemeQt::paintMediaSliderThumb(RenderObject* o, const RenderObject::P
if (!mediaElement)
return false;
- StylePainter p(paintInfo);
+ StylePainter p(this, paintInfo);
if (!p.isValid())
return true;
@@ -944,13 +1006,26 @@ bool RenderThemeQt::paintMediaSliderThumb(RenderObject* o, const RenderObject::P
void RenderThemeQt::adjustSliderThumbSize(RenderObject* o) const
{
- if (o->style()->appearance() == MediaSliderThumbPart) {
+ ControlPart part = o->style()->appearance();
+
+ if (part == MediaSliderThumbPart) {
RenderStyle* parentStyle = o->parent()->style();
Q_ASSERT(parentStyle);
int parentHeight = parentStyle->height().value();
o->style()->setWidth(Length(parentHeight / 3, Fixed));
o->style()->setHeight(Length(parentHeight, Fixed));
+ } else if (part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart) {
+ QStyleOptionSlider option;
+ if (part == SliderThumbVerticalPart)
+ option.orientation = Qt::Vertical;
+
+ QStyle* style = qStyle();
+
+ int width = style->pixelMetric(QStyle::PM_SliderLength, &option);
+ int height = style->pixelMetric(QStyle::PM_SliderThickness, &option);
+ o->style()->setWidth(Length(width, Fixed));
+ o->style()->setHeight(Length(height, Fixed));
}
}