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