RenderThemeGtk.h revision ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb
1/*
2 * This file is part of the WebKit project.
3 *
4 * Copyright (C) 2006 Apple Computer, Inc.
5 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
6 * Copyright (C) 2007 Holger Hans Peter Freyther
7 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
8 * Copyright (C) 2010 Igalia S.L.
9 * All rights reserved.
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB.  If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
25 *
26 */
27
28#ifndef RenderThemeGtk_h
29#define RenderThemeGtk_h
30
31#include "GRefPtr.h"
32#include "RenderTheme.h"
33
34#ifdef GTK_API_VERSION_2
35#include "gtkdrawing.h"
36#endif
37
38typedef gulong GType;
39
40namespace WebCore {
41
42class RenderThemeGtk : public RenderTheme {
43private:
44    RenderThemeGtk();
45    virtual ~RenderThemeGtk();
46
47public:
48    static PassRefPtr<RenderTheme> create();
49
50    // A method asking if the theme's controls actually care about redrawing when hovered.
51    virtual bool supportsHover(const RenderStyle* style) const { return true; }
52
53    // A method asking if the theme is able to draw the focus ring.
54    virtual bool supportsFocusRing(const RenderStyle*) const;
55
56    // A method asking if the control changes its tint when the window has focus or not.
57    virtual bool controlSupportsTints(const RenderObject*) const;
58
59    // A general method asking if any control tinting is supported at all.
60    virtual bool supportsControlTints() const { return true; }
61
62    virtual void adjustRepaintRect(const RenderObject*, IntRect&);
63
64    // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
65    // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
66    // controls that need to do this.
67    virtual int baselinePosition(const RenderObject*) const;
68
69    // The platform selection color.
70    virtual Color platformActiveSelectionBackgroundColor() const;
71    virtual Color platformInactiveSelectionBackgroundColor() const;
72    virtual Color platformActiveSelectionForegroundColor() const;
73    virtual Color platformInactiveSelectionForegroundColor() const;
74
75    // List Box selection color
76    virtual Color activeListBoxSelectionBackgroundColor() const;
77    virtual Color activeListBoxSelectionForegroundColor() const;
78    virtual Color inactiveListBoxSelectionBackgroundColor() const;
79    virtual Color inactiveListBoxSelectionForegroundColor() const;
80
81    virtual double caretBlinkInterval() const;
82
83    virtual void platformColorsDidChange();
84
85    // System fonts and colors.
86    virtual void systemFont(int propId, FontDescription&) const;
87    virtual Color systemColor(int cssValueId) const;
88
89#if ENABLE(VIDEO)
90    virtual String extraMediaControlsStyleSheet();
91    virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
92#endif
93
94#ifdef GTK_API_VERSION_2
95    GtkWidget* gtkScrollbar();
96    static void getIndicatorMetrics(ControlPart, int& indicatorSize, int& indicatorSpacing);
97#else
98    GtkStyleContext* gtkScrollbarStyle();
99#endif
100
101protected:
102    virtual bool paintCheckbox(RenderObject* o, const PaintInfo& i, const IntRect& r);
103    virtual void setCheckboxSize(RenderStyle* style) const;
104
105    virtual bool paintRadio(RenderObject* o, const PaintInfo& i, const IntRect& r);
106    virtual void setRadioSize(RenderStyle* style) const;
107
108    virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
109    virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&);
110
111    virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&);
112    virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&);
113
114    int popupInternalPaddingLeft(RenderStyle*) const;
115    int popupInternalPaddingRight(RenderStyle*) const;
116    int popupInternalPaddingTop(RenderStyle*) const;
117    int popupInternalPaddingBottom(RenderStyle*) const;
118
119    // The Mac port differentiates between the "menu list" and the "menu list button."
120    // The former is used when a menu list button has been styled. This is used to ensure
121    // Aqua themed controls whenever possible. We always want to use GTK+ theming, so
122    // we don't maintain this differentiation.
123    virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
124    virtual void adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element* e) const;
125    virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&);
126    virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&);
127
128    virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
129    virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&);
130
131    virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
132    virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&);
133
134    virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
135    virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&);
136
137    virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
138    virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&);
139
140    virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
141    virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
142
143    virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
144    virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
145
146    virtual void adjustSliderThumbSize(RenderObject* object) const;
147
148#if ENABLE(VIDEO)
149    void initMediaColors();
150    void initMediaButtons();
151    void adjustMediaSliderThumbSize(RenderObject*) const;
152    virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&);
153    virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&);
154    virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&);
155    virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&);
156    virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&);
157    virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
158    virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
159    virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&);
160    virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
161    virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
162    virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&);
163#endif
164
165#if ENABLE(PROGRESS_TAG)
166    virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
167    virtual double animationDurationForProgressBar(RenderProgress*) const;
168    virtual void adjustProgressBarStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
169    virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&);
170#endif
171
172    virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&);
173
174private:
175    void platformInit();
176    static void setTextInputBorders(RenderStyle*);
177    GRefPtr<GdkPixbuf> getStockIcon(GType, const char* iconName, gint direction, gint state, gint iconSize);
178    static double getScreenDPI();
179
180#if ENABLE(VIDEO)
181    bool paintMediaButton(RenderObject*, GraphicsContext*, const IntRect&, const char* iconName);
182#endif
183
184#if ENABLE(PROGRESS_TAG)
185    static IntRect calculateProgressRect(RenderObject*, const IntRect&);
186#endif
187
188    mutable Color m_panelColor;
189    mutable Color m_sliderColor;
190    mutable Color m_sliderThumbColor;
191    const int m_mediaIconSize;
192    const int m_mediaSliderHeight;
193    const int m_mediaSliderThumbWidth;
194    const int m_mediaSliderThumbHeight;
195
196#ifdef GTK_API_VERSION_2
197    void setupWidgetAndAddToContainer(GtkWidget*, GtkWidget*) const;
198    bool paintRenderObject(GtkThemeWidgetType, RenderObject*, GraphicsContext*, const IntRect&, int flags = 0);
199    void refreshComboBoxChildren() const;
200    void getComboBoxPadding(RenderStyle*, int& left, int& top, int& right, int& bottom) const;
201    int getComboBoxSeparatorWidth() const;
202    int comboBoxArrowSize(RenderStyle*) const;
203    GtkThemeParts m_themeParts;
204
205    GtkWidget* gtkButton() const;
206    GtkWidget* gtkEntry() const;
207    GtkWidget* gtkTreeView() const;
208    GtkWidget* gtkVScale() const;
209    GtkWidget* gtkHScale() const;
210    GtkWidget* gtkContainer() const;
211    GtkWidget* gtkRadioButton() const;
212    GtkWidget* gtkCheckButton() const;
213    GtkWidget* gtkProgressBar() const;
214    GtkWidget* gtkComboBox() const;
215    GtkWidget* gtkComboBoxButton() const;
216    GtkWidget* gtkComboBoxArrow() const;
217    GtkWidget* gtkComboBoxSeparator() const;
218
219    mutable GtkWidget* m_gtkWindow;
220    mutable GtkWidget* m_gtkContainer;
221    mutable GtkWidget* m_gtkButton;
222    mutable GtkWidget* m_gtkEntry;
223    mutable GtkWidget* m_gtkTreeView;
224    mutable GtkWidget* m_gtkVScale;
225    mutable GtkWidget* m_gtkHScale;
226    mutable GtkWidget* m_gtkRadioButton;
227    mutable GtkWidget* m_gtkCheckButton;
228    mutable GtkWidget* m_gtkProgressBar;
229    mutable GtkWidget* m_gtkComboBox;
230    mutable GtkWidget* m_gtkComboBoxButton;
231    mutable GtkWidget* m_gtkComboBoxArrow;
232    mutable GtkWidget* m_gtkComboBoxSeparator;
233    bool m_themePartsHaveRGBAColormap;
234    friend class WidgetRenderingContext;
235#endif
236};
237
238}
239
240#endif // RenderThemeGtk_h
241