1/*
2 * This file is part of the theme implementation for form controls in WebCore.
3 *
4 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB.  If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22#ifndef RenderThemeQt_h
23#define RenderThemeQt_h
24
25#include "RenderTheme.h"
26
27#include <QStyle>
28
29QT_BEGIN_NAMESPACE
30class QPainter;
31class QWidget;
32QT_END_NAMESPACE
33
34namespace WebCore {
35
36class RenderStyle;
37class HTMLMediaElement;
38class ScrollbarThemeQt;
39
40class RenderThemeQt : public RenderTheme {
41private:
42    RenderThemeQt(Page* page);
43    virtual ~RenderThemeQt();
44
45public:
46    static PassRefPtr<RenderTheme> create(Page*);
47
48    virtual bool supportsHover(const RenderStyle*) const;
49    virtual bool supportsFocusRing(const RenderStyle* style) const;
50
51    virtual int baselinePosition(const RenderObject* o) const;
52
53    // A method asking if the control changes its tint when the window has focus or not.
54    virtual bool controlSupportsTints(const RenderObject*) const;
55
56    // A general method asking if any control tinting is supported at all.
57    virtual bool supportsControlTints() const;
58
59    virtual void adjustRepaintRect(const RenderObject* o, IntRect& r);
60
61    // The platform selection color.
62    virtual Color platformActiveSelectionBackgroundColor() const;
63    virtual Color platformInactiveSelectionBackgroundColor() const;
64    virtual Color platformActiveSelectionForegroundColor() const;
65    virtual Color platformInactiveSelectionForegroundColor() const;
66
67    virtual void systemFont(int propId, FontDescription&) const;
68
69    virtual int minimumMenuListSize(RenderStyle*) const;
70
71    virtual void adjustSliderThumbSize(RenderObject*) const;
72
73    virtual double caretBlinkInterval() const;
74
75#if ENABLE(VIDEO)
76    virtual String extraMediaControlsStyleSheet();
77#endif
78
79    QStyle* qStyle() const;
80
81protected:
82    virtual bool paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r);
83    virtual void setCheckboxSize(RenderStyle*) const;
84
85    virtual bool paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r);
86    virtual void setRadioSize(RenderStyle*) const;
87
88    virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
89    virtual bool paintButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
90    virtual void setButtonSize(RenderStyle*) const;
91
92    virtual bool paintTextField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
93    virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
94
95    virtual bool paintTextArea(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
96    virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
97
98    virtual bool paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r);
99    virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
100
101    virtual bool paintMenuListButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
102    virtual void adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
103
104    virtual bool paintSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
105    virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
106
107    virtual bool paintSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
108    virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
109
110    virtual bool paintSearchField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
111    virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
112
113    virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
114    virtual bool paintSearchFieldCancelButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
115
116    virtual void adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
117    virtual bool paintSearchFieldDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
118
119    virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
120    virtual bool paintSearchFieldResultsDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
121
122#if ENABLE(VIDEO)
123    virtual bool paintMediaFullscreenButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
124    virtual bool paintMediaPlayButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
125    virtual bool paintMediaMuteButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
126    virtual bool paintMediaSeekBackButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
127    virtual bool paintMediaSeekForwardButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
128    virtual bool paintMediaSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
129    virtual bool paintMediaSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
130
131private:
132    HTMLMediaElement* getMediaElementFromRenderObject(RenderObject* o) const;
133    void paintMediaBackground(QPainter* painter, const IntRect& r) const;
134    QColor getMediaControlForegroundColor(RenderObject* o = 0) const;
135#endif
136    void computeSizeBasedOnStyle(RenderStyle* renderStyle) const;
137
138private:
139    bool supportsFocus(ControlPart) const;
140
141    ControlPart initializeCommonQStyleOptions(QStyleOption&, RenderObject*) const;
142
143    void setButtonPadding(RenderStyle*) const;
144    void setPopupPadding(RenderStyle*) const;
145
146    void setPaletteFromPageClientIfExists(QPalette&) const;
147
148    QStyle* fallbackStyle() const;
149
150    Page* m_page;
151
152#ifdef Q_WS_MAC
153    int m_buttonFontPixelSize;
154#endif
155    QString m_buttonFontFamily;
156
157    QStyle* m_fallbackStyle;
158};
159
160class StylePainter {
161public:
162    explicit StylePainter(RenderThemeQt*, const RenderObject::PaintInfo&);
163    explicit StylePainter(ScrollbarThemeQt*, GraphicsContext*);
164    ~StylePainter();
165
166    bool isValid() const { return painter && style; }
167
168    QPainter* painter;
169    QWidget* widget;
170    QStyle* style;
171
172    void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption& opt)
173    { style->drawPrimitive(pe, &opt, painter, widget); }
174    void drawControl(QStyle::ControlElement ce, const QStyleOption& opt)
175    { style->drawControl(ce, &opt, painter, widget); }
176    void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex& opt)
177    { style->drawComplexControl(cc, &opt, painter, widget); }
178
179private:
180    void init(GraphicsContext* context, QStyle*);
181
182    QBrush oldBrush;
183    bool oldAntialiasing;
184
185    Q_DISABLE_COPY(StylePainter)
186};
187
188}
189
190#endif // RenderThemeQt_h
191