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) 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#if ENABLE(VIDEO)
34#include "MediaControlElements.h"
35#endif
36#include "RenderTheme.h"
37
38#include <cairo.h>
39
40typedef struct _Ecore_Evas Ecore_Evas;
41typedef struct _Evas_Object Evas_Object;
42
43namespace WebCore {
44
45enum FormType { // KEEP IN SYNC WITH edjeGroupFromFormType()
46    Button,
47    RadioButton,
48    TextField,
49    CheckBox,
50    ComboBox,
51#if ENABLE(PROGRESS_TAG)
52    ProgressBar,
53#endif
54    SearchField,
55    SearchFieldDecoration,
56    SearchFieldResultsButton,
57    SearchFieldResultsDecoration,
58    SearchFieldCancelButton,
59    SliderVertical,
60    SliderHorizontal,
61#if ENABLE(VIDEO)
62    PlayPauseButton,
63    MuteUnMuteButton,
64    SeekForwardButton,
65    SeekBackwardButton,
66#endif
67    FormTypeLast
68};
69
70class RenderThemeEfl : public RenderTheme {
71private:
72    RenderThemeEfl(Page*);
73    ~RenderThemeEfl();
74
75public:
76    static PassRefPtr<RenderTheme> create(Page*);
77
78    // A method asking if the theme's controls actually care about redrawing when hovered.
79    virtual bool supportsHover(const RenderStyle*) const { return true; }
80
81    // A method asking if the theme is able to draw the focus ring.
82    virtual bool supportsFocusRing(const RenderStyle*) const;
83
84    // A method asking if the control changes its tint when the window has focus or not.
85    virtual bool controlSupportsTints(const RenderObject*) const;
86
87    // A general method asking if any control tinting is supported at all.
88    virtual bool supportsControlTints() const { return true; }
89
90    // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
91    // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
92    // controls that need to do this.
93    virtual int baselinePosition(const RenderObject*) const;
94
95    virtual Color platformActiveSelectionBackgroundColor() const { return m_activeSelectionBackgroundColor; }
96    virtual Color platformInactiveSelectionBackgroundColor() const { return m_inactiveSelectionBackgroundColor; }
97    virtual Color platformActiveSelectionForegroundColor() const { return m_activeSelectionForegroundColor; }
98    virtual Color platformInactiveSelectionForegroundColor() const { return m_inactiveSelectionForegroundColor; }
99    virtual Color platformFocusRingColor() const { return m_focusRingColor; }
100
101    virtual void themeChanged();
102
103    // Set platform colors and notify they changed
104    void setActiveSelectionColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA);
105    void setInactiveSelectionColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA);
106    void setFocusRingColor(int r, int g, int b, int a);
107
108    void setButtonTextColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA);
109    void setComboTextColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA);
110    void setEntryTextColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA);
111    void setSearchTextColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA);
112
113    void adjustSizeConstraints(RenderStyle*, FormType) const;
114
115
116    // System fonts.
117    virtual void systemFont(int propId, FontDescription&) const;
118
119    virtual void adjustCheckboxStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
120    virtual bool paintCheckbox(RenderObject*, const PaintInfo&, const IntRect&);
121
122    virtual void adjustRadioStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
123    virtual bool paintRadio(RenderObject*, const PaintInfo&, const IntRect&);
124
125    virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
126    virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&);
127
128    virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
129    virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&);
130
131    virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
132    virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&);
133
134    virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
135    virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&);
136
137    virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
138    virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&);
139
140    virtual void adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
141    virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&);
142
143    virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
144    virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&);
145
146    virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
147    virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&);
148
149    virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
150    virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&);
151
152    virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
153    virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
154
155    virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
156    virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
157
158    static void setDefaultFontSize(int fontsize);
159
160#if ENABLE(PROGRESS_TAG)
161    virtual void adjustProgressBarStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
162    virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&);
163#endif
164
165#if ENABLE(VIDEO)
166    virtual String extraMediaControlsStyleSheet();
167    virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
168
169    virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&);
170    virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&);
171    virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&);
172    virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&);
173    virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&);
174    virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
175    virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
176    virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&);
177    virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&);
178    virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&);
179    virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&);
180#endif
181
182protected:
183    static float defaultFontSize;
184
185private:
186    void createCanvas();
187    void createEdje();
188    void applyEdjeColors();
189    void applyPartDescriptions();
190    const char* edjeGroupFromFormType(FormType) const;
191    void applyEdjeStateFromForm(Evas_Object*, ControlStates);
192    bool paintThemePart(RenderObject*, FormType, const PaintInfo&, const IntRect&);
193
194#if ENABLE(VIDEO)
195    bool emitMediaButtonSignal(FormType, MediaControlElementType, const IntRect&);
196#endif
197
198    Page* m_page;
199    Color m_activeSelectionBackgroundColor;
200    Color m_activeSelectionForegroundColor;
201    Color m_inactiveSelectionBackgroundColor;
202    Color m_inactiveSelectionForegroundColor;
203    Color m_focusRingColor;
204    Color m_buttonTextBackgroundColor;
205    Color m_buttonTextForegroundColor;
206    Color m_comboTextBackgroundColor;
207    Color m_comboTextForegroundColor;
208    Color m_entryTextBackgroundColor;
209    Color m_entryTextForegroundColor;
210    Color m_searchTextBackgroundColor;
211    Color m_searchTextForegroundColor;
212    Ecore_Evas* m_canvas;
213    Evas_Object* m_edje;
214
215    struct ThemePartDesc {
216        FormType type;
217        LengthSize min;
218        LengthSize max;
219        LengthBox padding;
220    };
221    void applyPartDescriptionFallback(struct ThemePartDesc*);
222    void applyPartDescription(Evas_Object*, struct ThemePartDesc*);
223
224    struct ThemePartCacheEntry {
225        FormType type;
226        IntSize size;
227        Ecore_Evas* ee;
228        Evas_Object* o;
229        cairo_surface_t* surface;
230    };
231
232    struct ThemePartDesc m_partDescs[FormTypeLast];
233
234    // this should be small and not so frequently used,
235    // so use a vector and do linear searches
236    Vector<struct ThemePartCacheEntry *> m_partCache;
237
238    // get (use, create or replace) entry from cache
239    struct ThemePartCacheEntry* cacheThemePartGet(FormType, const IntSize&);
240    // flush cache, deleting all entries
241    void cacheThemePartFlush();
242
243    // internal, used by cacheThemePartGet()
244    bool themePartCacheEntryReset(struct ThemePartCacheEntry*, FormType);
245    bool themePartCacheEntrySurfaceCreate(struct ThemePartCacheEntry*);
246    struct ThemePartCacheEntry* cacheThemePartNew(FormType, const IntSize&);
247    struct ThemePartCacheEntry* cacheThemePartReset(FormType, struct ThemePartCacheEntry*);
248    struct ThemePartCacheEntry* cacheThemePartResizeAndReset(FormType, const IntSize&, struct ThemePartCacheEntry*);
249
250};
251}
252
253#endif // RenderThemeEfl_h
254