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
34typedef gulong GType;
35typedef struct _GdkColormap GdkColormap;
36
37namespace WebCore {
38
39class RenderThemeGtk : public RenderTheme {
40private:
41    RenderThemeGtk();
42    virtual ~RenderThemeGtk();
43
44public:
45    static PassRefPtr<RenderTheme> create();
46
47    // A method asking if the theme's controls actually care about redrawing when hovered.
48    virtual bool supportsHover(const RenderStyle* style) const { return true; }
49
50    // A method asking if the theme is able to draw the focus ring.
51    virtual bool supportsFocusRing(const RenderStyle*) 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 { return true; }
58
59    virtual void adjustRepaintRect(const RenderObject*, IntRect&);
60
61    // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
62    // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
63    // controls that need to do this.
64    virtual int baselinePosition(const RenderObject*) const;
65
66    // The platform selection color.
67    virtual Color platformActiveSelectionBackgroundColor() const;
68    virtual Color platformInactiveSelectionBackgroundColor() const;
69    virtual Color platformActiveSelectionForegroundColor() const;
70    virtual Color platformInactiveSelectionForegroundColor() const;
71
72    // List Box selection color
73    virtual Color activeListBoxSelectionBackgroundColor() const;
74    virtual Color activeListBoxSelectionForegroundColor() const;
75    virtual Color inactiveListBoxSelectionBackgroundColor() const;
76    virtual Color inactiveListBoxSelectionForegroundColor() const;
77
78    virtual double caretBlinkInterval() const;
79
80    virtual void platformColorsDidChange();
81
82    // System fonts and colors.
83    virtual void systemFont(int propId, FontDescription&) const;
84    virtual Color systemColor(int cssValueId) const;
85
86#if ENABLE(VIDEO)
87    virtual String extraMediaControlsStyleSheet();
88    virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
89#endif
90
91#ifdef GTK_API_VERSION_2
92    GtkWidget* gtkVScrollbar() const;
93    GtkWidget* gtkHScrollbar() const;
94    static void getIndicatorMetrics(ControlPart, int& indicatorSize, int& indicatorSpacing);
95#else
96    GtkStyleContext* gtkScrollbarStyle();
97#endif
98
99protected:
100    virtual bool paintCheckbox(RenderObject* o, const PaintInfo& i, const IntRect& r);
101    virtual void setCheckboxSize(RenderStyle* style) const;
102
103    virtual bool paintRadio(RenderObject* o, const PaintInfo& i, const IntRect& r);
104    virtual void setRadioSize(RenderStyle* style) const;
105
106    virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
107    virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&);
108
109    virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&);
110    virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&);
111
112    int popupInternalPaddingLeft(RenderStyle*) const;
113    int popupInternalPaddingRight(RenderStyle*) const;
114    int popupInternalPaddingTop(RenderStyle*) const;
115    int popupInternalPaddingBottom(RenderStyle*) const;
116
117    // The Mac port differentiates between the "menu list" and the "menu list button."
118    // The former is used when a menu list button has been styled. This is used to ensure
119    // Aqua themed controls whenever possible. We always want to use GTK+ theming, so
120    // we don't maintain this differentiation.
121    virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
122    virtual void adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element* e) const;
123    virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&);
124    virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&);
125
126    virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
127    virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&);
128
129    virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
130    virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&);
131
132    virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
133    virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&);
134
135    virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
136    virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&);
137
138    virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
139    virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
140
141    virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
142    virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
143
144    virtual void adjustSliderThumbSize(RenderObject* object) const;
145
146#if ENABLE(VIDEO)
147    void initMediaColors();
148    void initMediaButtons();
149    void adjustMediaSliderThumbSize(RenderObject*) const;
150    virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const { return true; }
151    virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&);
152    virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&);
153    virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&);
154    virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&);
155    virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&);
156    virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
157    virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
158    virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&);
159    virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
160    virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
161    virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&);
162#endif
163
164#if ENABLE(PROGRESS_TAG)
165    virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
166    virtual double animationDurationForProgressBar(RenderProgress*) const;
167    virtual void adjustProgressBarStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
168    virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&);
169#endif
170
171    virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&);
172
173    virtual void adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
174    virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&);
175
176private:
177    void platformInit();
178    static void setTextInputBorders(RenderStyle*);
179    GRefPtr<GdkPixbuf> getStockIcon(GType, const char* iconName, gint direction, gint state, gint iconSize);
180    static double getScreenDPI();
181
182#if ENABLE(VIDEO)
183    bool paintMediaButton(RenderObject*, GraphicsContext*, const IntRect&, const char* iconName);
184#endif
185
186#if ENABLE(PROGRESS_TAG)
187    static IntRect calculateProgressRect(RenderObject*, const IntRect&);
188#endif
189
190    mutable Color m_panelColor;
191    mutable Color m_sliderColor;
192    mutable Color m_sliderThumbColor;
193    const int m_mediaIconSize;
194    const int m_mediaSliderHeight;
195    const int m_mediaSliderThumbWidth;
196    const int m_mediaSliderThumbHeight;
197
198#ifdef GTK_API_VERSION_2
199    void setupWidgetAndAddToContainer(GtkWidget*, GtkWidget*) const;
200    void refreshComboBoxChildren() const;
201    void getComboBoxPadding(RenderStyle*, int& left, int& top, int& right, int& bottom) const;
202    int getComboBoxSeparatorWidth() const;
203    int comboBoxArrowSize(RenderStyle*) const;
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    GtkWidget* gtkSpinButton() const;
219
220    GdkColormap* m_colormap;
221    mutable GtkWidget* m_gtkWindow;
222    mutable GtkWidget* m_gtkContainer;
223    mutable GtkWidget* m_gtkButton;
224    mutable GtkWidget* m_gtkEntry;
225    mutable GtkWidget* m_gtkTreeView;
226    mutable GtkWidget* m_gtkVScale;
227    mutable GtkWidget* m_gtkHScale;
228    mutable GtkWidget* m_gtkRadioButton;
229    mutable GtkWidget* m_gtkCheckButton;
230    mutable GtkWidget* m_gtkProgressBar;
231    mutable GtkWidget* m_gtkComboBox;
232    mutable GtkWidget* m_gtkComboBoxButton;
233    mutable GtkWidget* m_gtkComboBoxArrow;
234    mutable GtkWidget* m_gtkComboBoxSeparator;
235    mutable GtkWidget* m_gtkVScrollbar;
236    mutable GtkWidget* m_gtkHScrollbar;
237    mutable GtkWidget* m_gtkSpinButton;
238    bool m_themePartsHaveRGBAColormap;
239    friend class WidgetRenderingContext;
240#endif
241};
242
243}
244
245#endif // RenderThemeGtk_h
246