1/*
2 * This file is part of the WebKit project.
3 *
4 * Copyright (C) 2006 Apple 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 <wtf/gobject/GRefPtr.h>
32#include "RenderTheme.h"
33
34typedef struct _GdkColormap GdkColormap;
35
36namespace WebCore {
37
38class RenderThemeGtk final : public RenderTheme {
39private:
40    RenderThemeGtk();
41    virtual ~RenderThemeGtk();
42
43public:
44    static PassRefPtr<RenderTheme> create();
45
46    // A method asking if the theme's controls actually care about redrawing when hovered.
47    virtual bool supportsHover(const RenderStyle&) const override { return true; }
48
49    // A method asking if the theme is able to draw the focus ring.
50    virtual bool supportsFocusRing(const RenderStyle&) const override;
51
52    // A method asking if the control changes its tint when the window has focus or not.
53    virtual bool controlSupportsTints(const RenderObject&) const override;
54
55    // A general method asking if any control tinting is supported at all.
56    virtual bool supportsControlTints() const override { return true; }
57
58    virtual void adjustRepaintRect(const RenderObject&, FloatRect&) override;
59
60    // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
61    // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
62    // controls that need to do this.
63    virtual int baselinePosition(const RenderObject&) const override;
64
65    // The platform selection color.
66    virtual Color platformActiveSelectionBackgroundColor() const override;
67    virtual Color platformInactiveSelectionBackgroundColor() const override;
68    virtual Color platformActiveSelectionForegroundColor() const override;
69    virtual Color platformInactiveSelectionForegroundColor() const override;
70
71    // List Box selection color
72    virtual Color platformActiveListBoxSelectionBackgroundColor() const override;
73    virtual Color platformActiveListBoxSelectionForegroundColor() const override;
74    virtual Color platformInactiveListBoxSelectionBackgroundColor() const override;
75    virtual Color platformInactiveListBoxSelectionForegroundColor() const override;
76
77    virtual double caretBlinkInterval() const override;
78
79    virtual void platformColorsDidChange() override;
80
81    // System fonts and colors.
82    virtual void systemFont(CSSValueID, FontDescription&) const override;
83    virtual Color systemColor(CSSValueID) const override;
84
85    virtual bool popsMenuBySpaceOrReturn() const override { return true; }
86
87#if ENABLE(VIDEO)
88    virtual String extraMediaControlsStyleSheet() override;
89    virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const override;
90    virtual bool supportsClosedCaptioning() const override { return true; }
91    virtual String mediaControlsScript() override;
92
93#if ENABLE(FULLSCREEN_API)
94    virtual String extraFullScreenStyleSheet() override;
95#endif
96#endif
97
98#if ENABLE(DATALIST_ELEMENT)
99    // Returns size of one slider tick mark for a horizontal track.
100    // For vertical tracks we rotate it and use it. i.e. Width is always length along the track.
101    virtual IntSize sliderTickSize() const override;
102    // Returns the distance of slider tick origin from the slider track center.
103    virtual int sliderTickOffsetFromTrackCenter() const override;
104#endif
105
106#ifdef GTK_API_VERSION_2
107    GtkWidget* gtkContainer() const;
108    GtkWidget* gtkEntry() const;
109    GtkWidget* gtkVScrollbar() const;
110    GtkWidget* gtkHScrollbar() const;
111    static void getIndicatorMetrics(ControlPart, int& indicatorSize, int& indicatorSpacing);
112#else
113    GtkStyleContext* gtkScrollbarStyle();
114#endif
115
116private:
117    virtual bool paintCheckbox(const RenderObject&, const PaintInfo&, const IntRect&) override;
118    virtual void setCheckboxSize(RenderStyle&) const override;
119
120    virtual bool paintRadio(const RenderObject&, const PaintInfo&, const IntRect&) override;
121    virtual void setRadioSize(RenderStyle&) const override;
122
123    virtual void adjustButtonStyle(StyleResolver&, RenderStyle&, Element&) const override;
124    virtual bool paintButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
125
126    virtual bool paintTextField(const RenderObject&, const PaintInfo&, const FloatRect&) override;
127    virtual bool paintTextArea(const RenderObject&, const PaintInfo&, const FloatRect&) override;
128
129    int popupInternalPaddingLeft(RenderStyle&) const override;
130    int popupInternalPaddingRight(RenderStyle&) const override;
131    int popupInternalPaddingTop(RenderStyle&) const override;
132    int popupInternalPaddingBottom(RenderStyle&) const override;
133
134    // The Mac port differentiates between the "menu list" and the "menu list button."
135    // The former is used when a menu list button has been styled. This is used to ensure
136    // Aqua themed controls whenever possible. We always want to use GTK+ theming, so
137    // we don't maintain this differentiation.
138    virtual void adjustMenuListStyle(StyleResolver&, RenderStyle&, Element&) const override;
139    virtual void adjustMenuListButtonStyle(StyleResolver&, RenderStyle&, Element&) const override;
140    virtual bool paintMenuList(const RenderObject&, const PaintInfo&, const FloatRect&) override;
141    virtual bool paintMenuListButtonDecorations(const RenderObject&, const PaintInfo&, const FloatRect&) override;
142
143    virtual void adjustSearchFieldResultsDecorationPartStyle(StyleResolver&, RenderStyle&, Element&) const override;
144    virtual bool paintSearchFieldResultsDecorationPart(const RenderObject&, const PaintInfo&, const IntRect&) override;
145
146    virtual void adjustSearchFieldStyle(StyleResolver&, RenderStyle&, Element&) const override;
147    virtual bool paintSearchField(const RenderObject&, const PaintInfo&, const IntRect&) override;
148
149    virtual void adjustSearchFieldResultsButtonStyle(StyleResolver&, RenderStyle&, Element&) const override;
150    virtual bool paintSearchFieldResultsButton(const RenderObject&, const PaintInfo&, const IntRect&);
151
152    virtual void adjustSearchFieldCancelButtonStyle(StyleResolver&, RenderStyle&, Element&) const override;
153    virtual bool paintSearchFieldCancelButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
154
155    virtual bool paintSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) override;
156    virtual void adjustSliderTrackStyle(StyleResolver&, RenderStyle&, Element&) const override;
157
158    virtual bool paintSliderThumb(const RenderObject&, const PaintInfo&, const IntRect&) override;
159    virtual void adjustSliderThumbStyle(StyleResolver&, RenderStyle&, Element&) const override;
160
161    virtual void adjustSliderThumbSize(RenderStyle&, Element&) const override;
162
163#if ENABLE(VIDEO)
164    void initMediaColors();
165    void initMediaButtons();
166    virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const override;
167    virtual bool paintMediaFullscreenButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
168    virtual bool paintMediaPlayButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
169    virtual bool paintMediaMuteButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
170    virtual bool paintMediaSeekBackButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
171    virtual bool paintMediaSeekForwardButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
172    virtual bool paintMediaSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) override;
173    virtual bool paintMediaSliderThumb(const RenderObject&, const PaintInfo&, const IntRect&) override;
174    virtual bool paintMediaVolumeSliderContainer(const RenderObject&, const PaintInfo&, const IntRect&) override;
175    virtual bool paintMediaVolumeSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) override;
176    virtual bool paintMediaVolumeSliderThumb(const RenderObject&, const PaintInfo&, const IntRect&) override;
177    virtual bool paintMediaCurrentTime(const RenderObject&, const PaintInfo&, const IntRect&) override;
178#if ENABLE(VIDEO_TRACK)
179    virtual bool paintMediaToggleClosedCaptionsButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
180#endif
181#endif
182
183    virtual double animationRepeatIntervalForProgressBar(RenderProgress&) const override;
184    virtual double animationDurationForProgressBar(RenderProgress&) const override;
185    virtual void adjustProgressBarStyle(StyleResolver&, RenderStyle&, Element&) const override;
186    virtual bool paintProgressBar(const RenderObject&, const PaintInfo&, const IntRect&) override;
187
188    virtual bool paintCapsLockIndicator(const RenderObject&, const PaintInfo&, const IntRect&) override;
189
190    virtual void adjustInnerSpinButtonStyle(StyleResolver&, RenderStyle&, Element&) const override;
191    virtual bool paintInnerSpinButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
192
193    virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const override;
194
195    void platformInit();
196    static void setTextInputBorders(RenderStyle&);
197    static double getScreenDPI();
198
199#if ENABLE(VIDEO)
200    bool paintMediaButton(const RenderObject&, GraphicsContext*, const IntRect&, const char* symbolicIconName, const char* fallbackStockIconName);
201#endif
202
203    static IntRect calculateProgressRect(const RenderObject&, const IntRect&);
204
205    mutable Color m_panelColor;
206    mutable Color m_sliderColor;
207    mutable Color m_sliderThumbColor;
208    const int m_mediaIconSize;
209    const int m_mediaSliderHeight;
210
211#ifdef GTK_API_VERSION_2
212    void setupWidgetAndAddToContainer(GtkWidget*, GtkWidget*) const;
213    void refreshComboBoxChildren() const;
214    void getComboBoxPadding(RenderStyle&, int& left, int& top, int& right, int& bottom) const;
215    int getComboBoxSeparatorWidth() const;
216    int comboBoxArrowSize(RenderStyle&) const;
217
218    GtkWidget* gtkButton() const;
219    GtkWidget* gtkTreeView() const;
220    GtkWidget* gtkVScale() const;
221    GtkWidget* gtkHScale() const;
222    GtkWidget* gtkRadioButton() const;
223    GtkWidget* gtkCheckButton() const;
224    GtkWidget* gtkProgressBar() const;
225    GtkWidget* gtkComboBox() const;
226    GtkWidget* gtkComboBoxButton() const;
227    GtkWidget* gtkComboBoxArrow() const;
228    GtkWidget* gtkComboBoxSeparator() const;
229    GtkWidget* gtkSpinButton() const;
230
231    GdkColormap* m_colormap;
232    mutable GtkWidget* m_gtkWindow;
233    mutable GtkWidget* m_gtkContainer;
234    mutable GtkWidget* m_gtkButton;
235    mutable GtkWidget* m_gtkEntry;
236    mutable GtkWidget* m_gtkTreeView;
237    mutable GtkWidget* m_gtkVScale;
238    mutable GtkWidget* m_gtkHScale;
239    mutable GtkWidget* m_gtkRadioButton;
240    mutable GtkWidget* m_gtkCheckButton;
241    mutable GtkWidget* m_gtkProgressBar;
242    mutable GtkWidget* m_gtkComboBox;
243    mutable GtkWidget* m_gtkComboBoxButton;
244    mutable GtkWidget* m_gtkComboBoxArrow;
245    mutable GtkWidget* m_gtkComboBoxSeparator;
246    mutable GtkWidget* m_gtkVScrollbar;
247    mutable GtkWidget* m_gtkHScrollbar;
248    mutable GtkWidget* m_gtkSpinButton;
249    bool m_themePartsHaveRGBAColormap;
250    friend class WidgetRenderingContext;
251#endif
252};
253
254}
255
256#endif // RenderThemeGtk_h
257