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) 2008 INdT - Instituto Nokia de Tecnologia
9 * Copyright (C) 2009-2010 ProFUSION embedded systems
10 * Copyright (C) 2009-2010 Samsung Electronics
11 * All rights reserved.
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Library General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 * Library General Public License for more details.
22 *
23 * You should have received a copy of the GNU Library General Public License
24 * along with this library; see the file COPYING.LIB.  If not, write to
25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 * Boston, MA 02110-1301, USA.
27 *
28 */
29
30#ifndef RenderThemeEfl_h
31#define RenderThemeEfl_h
32
33#include "RenderTheme.h"
34
35#include <Eina.h>
36#include <cairo.h>
37#include <wtf/efl/UniquePtrEfl.h>
38
39namespace WebCore {
40
41enum FormType { // KEEP IN SYNC WITH edjeGroupFromFormType()
42    Button,
43    RadioButton,
44    TextField,
45    CheckBox,
46    ComboBox,
47    ProgressBar,
48    SearchField,
49    SearchFieldResultsButton,
50    SearchFieldResultsDecoration,
51    SearchFieldCancelButton,
52    SliderVertical,
53    SliderHorizontal,
54    SliderThumbVertical,
55    SliderThumbHorizontal,
56    Spinner,
57    FormTypeLast
58};
59
60class RenderThemeEfl final : public RenderTheme {
61private:
62    explicit RenderThemeEfl(Page*);
63    virtual ~RenderThemeEfl();
64
65public:
66    static PassRefPtr<RenderTheme> create(Page*);
67
68    // A method asking if the theme's controls actually care about redrawing when hovered.
69    virtual bool supportsHover(const RenderStyle&) const override { return true; }
70
71    // A method Returning whether the control is styled by css or not e.g specifying background-color.
72    virtual bool isControlStyled(const RenderStyle&, const BorderData&, const FillLayer&, const Color& backgroundColor) const override;
73
74    // A method asking if the theme is able to draw the focus ring.
75    virtual bool supportsFocusRing(const RenderStyle&) const override;
76
77    // A method asking if the control changes its tint when the window has focus or not.
78    virtual bool controlSupportsTints(const RenderObject&) const override;
79
80    // A general method asking if any control tinting is supported at all.
81    virtual bool supportsControlTints() const override { return true; }
82
83    // A general method asking if foreground colors of selection are supported.
84    virtual bool supportsSelectionForegroundColors() const override;
85
86    // A method to obtain the baseline position for a "leaf" control. This will only be used if a baseline
87    // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
88    // controls that need to do this.
89    virtual int baselinePosition(const RenderObject&) const override;
90
91    virtual Color platformActiveSelectionBackgroundColor() const override;
92    virtual Color platformInactiveSelectionBackgroundColor() const override;
93    virtual Color platformActiveSelectionForegroundColor() const override;
94    virtual Color platformInactiveSelectionForegroundColor() const override;
95    virtual Color platformFocusRingColor() const override;
96
97    // Set platform colors; remember to call platformColorDidChange after.
98    void setColorFromThemeClass(const char* colorClass);
99
100    void setButtonTextColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA);
101    void setComboTextColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA);
102    void setEntryTextColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA);
103    void setSearchTextColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA);
104
105    void adjustSizeConstraints(RenderStyle&, FormType) const;
106
107    // System fonts.
108    virtual void systemFont(CSSValueID, FontDescription&) const override;
109
110    virtual void adjustCheckboxStyle(StyleResolver&, RenderStyle&, Element&) const override;
111    virtual bool paintCheckbox(const RenderObject&, const PaintInfo&, const IntRect&) override;
112
113    virtual void adjustRadioStyle(StyleResolver&, RenderStyle&, Element&) const override;
114    virtual bool paintRadio(const RenderObject&, const PaintInfo&, const IntRect&) override;
115
116    virtual void adjustButtonStyle(StyleResolver&, RenderStyle&, Element&) const override;
117    virtual bool paintButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
118
119    virtual void adjustTextFieldStyle(StyleResolver&, RenderStyle&, Element&) const override;
120    virtual bool paintTextField(const RenderObject&, const PaintInfo&, const FloatRect&) override;
121
122    virtual void adjustTextAreaStyle(StyleResolver&, RenderStyle&, Element&) const override;
123    virtual bool paintTextArea(const RenderObject&, const PaintInfo&, const FloatRect&) override;
124
125    virtual void adjustMenuListStyle(StyleResolver&, RenderStyle&, Element&) const override;
126    virtual bool paintMenuList(const RenderObject&, const PaintInfo&, const FloatRect&) override;
127
128    virtual void adjustMenuListButtonStyle(StyleResolver&, RenderStyle&, Element&) const override;
129    virtual bool paintMenuListButtonDecorations(const RenderObject&, const PaintInfo&, const FloatRect&) override;
130
131    virtual void adjustSearchFieldResultsDecorationPartStyle(StyleResolver&, RenderStyle&, Element&) const override;
132    virtual bool paintSearchFieldResultsDecorationPart(const RenderObject&, const PaintInfo&, const IntRect&) override;
133
134    virtual void adjustSearchFieldStyle(StyleResolver&, RenderStyle&, Element&) const override;
135    virtual bool paintSearchField(const RenderObject&, const PaintInfo&, const IntRect&) override;
136
137    virtual void adjustSearchFieldResultsButtonStyle(StyleResolver&, RenderStyle&, Element&) const override;
138    virtual bool paintSearchFieldResultsButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
139
140    virtual void adjustSearchFieldCancelButtonStyle(StyleResolver&, RenderStyle&, Element&) const override;
141    virtual bool paintSearchFieldCancelButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
142
143    virtual void adjustSliderTrackStyle(StyleResolver&, RenderStyle&, Element&) const override;
144    virtual bool paintSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) override;
145
146    virtual void adjustSliderThumbStyle(StyleResolver&, RenderStyle&, Element&) const override;
147
148    virtual void adjustSliderThumbSize(RenderStyle&, Element&) const override;
149
150#if ENABLE(DATALIST_ELEMENT)
151    virtual IntSize sliderTickSize() const override;
152    virtual int sliderTickOffsetFromTrackCenter() const override;
153    virtual LayoutUnit sliderTickSnappingThreshold() const override;
154#endif
155
156    virtual bool supportsDataListUI(const AtomicString&) const override;
157
158    virtual bool paintSliderThumb(const RenderObject&, const PaintInfo&, const IntRect&) override;
159
160    virtual void adjustInnerSpinButtonStyle(StyleResolver&, RenderStyle&, Element&) const override;
161    virtual bool paintInnerSpinButton(const RenderObject&, const PaintInfo&, const IntRect&) override;
162
163    static void setDefaultFontSize(int fontsize);
164
165    virtual void adjustProgressBarStyle(StyleResolver&, RenderStyle&, Element&) const override;
166    virtual bool paintProgressBar(const RenderObject&, const PaintInfo&, const IntRect&) override;
167    virtual double animationRepeatIntervalForProgressBar(RenderProgress&) const override;
168    virtual double animationDurationForProgressBar(RenderProgress&) const override;
169
170#if ENABLE(VIDEO)
171    virtual String mediaControlsStyleSheet() override;
172    virtual String mediaControlsScript() override;
173#endif
174#if ENABLE(VIDEO_TRACK)
175    virtual bool supportsClosedCaptioning() const override { return true; }
176#endif
177    virtual bool shouldShowPlaceholderWhenFocused() const override { return true; }
178
179    void setThemePath(const String&);
180    String themePath() const;
181
182protected:
183    static float defaultFontSize;
184
185private:
186    bool loadTheme();
187    ALWAYS_INLINE bool loadThemeIfNeeded() const
188    {
189        return m_edje || (!m_themePath.isEmpty() && const_cast<RenderThemeEfl*>(this)->loadTheme());
190    }
191
192    ALWAYS_INLINE Ecore_Evas* canvas() const { return m_canvas.get(); }
193    ALWAYS_INLINE Evas_Object* edje() const { return m_edje.get(); }
194
195    void applyPartDescriptionsFrom(const String& themePath);
196
197    void applyEdjeStateFromForm(Evas_Object*, const ControlStates*, bool);
198    void applyEdjeRTLState(Evas_Object*, const RenderObject&, FormType, const IntRect&);
199    bool paintThemePart(const RenderObject&, FormType, const PaintInfo&, const IntRect&);
200
201    Page* m_page;
202    Color m_activeSelectionBackgroundColor;
203    Color m_activeSelectionForegroundColor;
204    Color m_inactiveSelectionBackgroundColor;
205    Color m_inactiveSelectionForegroundColor;
206    Color m_focusRingColor;
207    Color m_sliderThumbColor;
208
209    String m_themePath;
210    // Order so that the canvas gets destroyed at last.
211    EflUniquePtr<Ecore_Evas> m_canvas;
212    EflUniquePtr<Evas_Object> m_edje;
213
214    bool m_supportsSelectionForegroundColor;
215
216    struct ThemePartDesc {
217        FormType type;
218        LengthSize min;
219        LengthSize max;
220        LengthBox padding;
221    };
222    void applyPartDescriptionFallback(struct ThemePartDesc*);
223    void applyPartDescription(Evas_Object*, struct ThemePartDesc*);
224
225    struct ThemePartCacheEntry {
226        static PassOwnPtr<RenderThemeEfl::ThemePartCacheEntry> create(const String& themePath, FormType, const IntSize&);
227        void reuse(const String& themePath, FormType, const IntSize&);
228
229        ALWAYS_INLINE Ecore_Evas* canvas() { return m_canvas.get(); }
230        ALWAYS_INLINE Evas_Object* edje() { return m_edje.get(); }
231        ALWAYS_INLINE cairo_surface_t* surface() { return m_surface.get(); }
232
233        FormType type;
234        IntSize size;
235
236    private:
237        // Order so that the canvas gets destroyed at last.
238        EflUniquePtr<Ecore_Evas> m_canvas;
239        EflUniquePtr<Evas_Object> m_edje;
240        RefPtr<cairo_surface_t> m_surface;
241    };
242
243    struct ThemePartDesc m_partDescs[FormTypeLast];
244
245    // List of ThemePartCacheEntry* sorted so that the most recently
246    // used entries come first. We use a list for efficient moving
247    // of items within the container.
248    Eina_List* m_partCache;
249
250    ThemePartCacheEntry* getThemePartFromCache(FormType, const IntSize&);
251    void clearThemePartCache();
252};
253}
254
255#endif // RenderThemeEfl_h
256