• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
29 QT_BEGIN_NAMESPACE
30 class QLineEdit;
31 class QPainter;
32 class QWidget;
33 QT_END_NAMESPACE
34 
35 namespace WebCore {
36 
37 #if ENABLE(PROGRESS_TAG)
38 class RenderProgress;
39 #endif
40 class RenderStyle;
41 class HTMLMediaElement;
42 class ScrollbarThemeQt;
43 
44 class RenderThemeQt : public RenderTheme {
45 private:
46     RenderThemeQt(Page* page);
47     virtual ~RenderThemeQt();
48 
49 public:
50     static PassRefPtr<RenderTheme> create(Page*);
51 
52     String extraDefaultStyleSheet();
53 
54     virtual bool supportsHover(const RenderStyle*) const;
55     virtual bool supportsFocusRing(const RenderStyle* style) const;
56 
57     virtual int baselinePosition(const RenderObject* o) const;
58 
59     // A method asking if the control changes its tint when the window has focus or not.
60     virtual bool controlSupportsTints(const RenderObject*) const;
61 
62     // A general method asking if any control tinting is supported at all.
63     virtual bool supportsControlTints() const;
64 
65     virtual void adjustRepaintRect(const RenderObject* o, IntRect& r);
66 
67     // The platform selection color.
68     virtual Color platformActiveSelectionBackgroundColor() const;
69     virtual Color platformInactiveSelectionBackgroundColor() const;
70     virtual Color platformActiveSelectionForegroundColor() const;
71     virtual Color platformInactiveSelectionForegroundColor() const;
72 
73     virtual Color platformFocusRingColor() const;
74 
75     virtual void systemFont(int propId, FontDescription&) const;
76     virtual Color systemColor(int cssValueId) const;
77 
78     virtual int minimumMenuListSize(RenderStyle*) const;
79 
80     virtual void adjustSliderThumbSize(RenderObject*) const;
81 
82     virtual double caretBlinkInterval() const;
83 
84     virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
85 #if USE(QT_MOBILE_THEME)
86     virtual int popupInternalPaddingBottom(RenderStyle*) const;
87 #endif
88 
89 #if ENABLE(VIDEO)
90     virtual String extraMediaControlsStyleSheet();
91 #endif
92 
93     QStyle* qStyle() const;
94 
95 protected:
96     virtual bool paintCheckbox(RenderObject* o, const PaintInfo& i, const IntRect& r);
97     virtual void setCheckboxSize(RenderStyle*) const;
98 
99     virtual bool paintRadio(RenderObject* o, const PaintInfo& i, const IntRect& r);
100     virtual void setRadioSize(RenderStyle*) const;
101 
102     virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
103     virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&);
104     virtual void setButtonSize(RenderStyle*) const;
105 
106     virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&);
107     virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
108 
109     virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&);
110     virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
111 
112     virtual bool paintMenuList(RenderObject* o, const PaintInfo& i, const IntRect& r);
113     virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
114 
115     virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&);
116     virtual void adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
117 
118 #if ENABLE(PROGRESS_TAG)
119     virtual void adjustProgressBarStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
120     virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&);
121 #endif
122 
123     virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
124     virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
125 
126     virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
127     virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
128 
129     virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&);
130     virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
131 
132     virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
133     virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&);
134 
135     virtual void adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
136     virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&);
137 
138     virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
139     virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&);
140 
141 #if ENABLE(PROGRESS_TAG)
142     // Returns the repeat interval of the animation for the progress bar.
143     virtual double animationRepeatIntervalForProgressBar(RenderProgress* renderProgress) const;
144     // Returns the duration of the animation for the progress bar.
145     virtual double animationDurationForProgressBar(RenderProgress* renderProgress) const;
146 #endif
147 
148 #if ENABLE(VIDEO)
149     virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&);
150     virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&);
151     virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&);
152     virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&);
153     virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&);
154     virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
155     virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
156     virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&);
157     virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
158     virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
159     virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
160     virtual String formatMediaControlsRemainingTime(float currentTime, float duration) const;
hasOwnDisabledStateHandlingFor(ControlPart)161     virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const { return true; }
162 private:
163     void paintMediaBackground(QPainter* painter, const IntRect& r) const;
164     double mediaControlsBaselineOpacity() const;
165     QColor getMediaControlForegroundColor(RenderObject* o = 0) const;
166 #endif
167     void computeSizeBasedOnStyle(RenderStyle* renderStyle) const;
168 
169 private:
170     bool supportsFocus(ControlPart) const;
171 
172     ControlPart initializeCommonQStyleOptions(QStyleOption&, RenderObject*) const;
173 
174     void setButtonPadding(RenderStyle*) const;
175     void setPopupPadding(RenderStyle*) const;
176 
177     void setPaletteFromPageClientIfExists(QPalette&) const;
178 
179     int findFrameLineWidth(QStyle* style) const;
180 
181     QStyle* fallbackStyle() const;
182 
183     IntRect convertToPaintingRect(RenderObject* inputRenderer, const RenderObject* partRenderer, IntRect partRect, const IntRect& localOffset) const;
184 
185     Page* m_page;
186 
187 #ifdef Q_WS_MAC
188     int m_buttonFontPixelSize;
189 #endif
190     QString m_buttonFontFamily;
191 
192     QStyle* m_fallbackStyle;
193     mutable QLineEdit* m_lineEdit;
194 };
195 
196 class StylePainter {
197 public:
198     explicit StylePainter(RenderThemeQt*, const PaintInfo&);
199     explicit StylePainter(ScrollbarThemeQt*, GraphicsContext*);
200     ~StylePainter();
201 
isValid()202     bool isValid() const { return painter && style; }
203 
204     QPainter* painter;
205     QWidget* widget;
206     QStyle* style;
207 
drawPrimitive(QStyle::PrimitiveElement pe,const QStyleOption & opt)208     void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption& opt)
209     { style->drawPrimitive(pe, &opt, painter, widget); }
drawControl(QStyle::ControlElement ce,const QStyleOption & opt)210     void drawControl(QStyle::ControlElement ce, const QStyleOption& opt)
211     { style->drawControl(ce, &opt, painter, widget); }
drawComplexControl(QStyle::ComplexControl cc,const QStyleOptionComplex & opt)212     void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex& opt)
213     { style->drawComplexControl(cc, &opt, painter, widget); }
214 
215 private:
216     void init(GraphicsContext* context, QStyle*);
217 
218     QBrush oldBrush;
219     bool oldAntialiasing;
220 
221     Q_DISABLE_COPY(StylePainter)
222 };
223 
224 }
225 
226 #endif // RenderThemeQt_h
227