Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / RenderTheme.h
1 /*
2  * This file is part of the theme implementation for form controls in WebCore.
3  *
4  * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Computer, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22
23 #ifndef RenderTheme_h
24 #define RenderTheme_h
25
26 #if USE(NEW_THEME)
27 #include "Theme.h"
28 #else
29 #include "ThemeTypes.h"
30 #endif
31 #include "RenderObject.h"
32 #include "ScrollTypes.h"
33 #include <wtf/PassRefPtr.h>
34 #include <wtf/RefCounted.h>
35
36 namespace WebCore {
37
38 class Element;
39 class FileList;
40 class HTMLInputElement;
41 class PopupMenu;
42 class RenderMenuList;
43 #if ENABLE(METER_ELEMENT)
44 class RenderMeter;
45 #endif
46 #if ENABLE(PROGRESS_ELEMENT)
47 class RenderProgress;
48 #endif
49 class CSSStyleSheet;
50
51 class RenderTheme : public RefCounted<RenderTheme> {
52 protected:
53     RenderTheme();
54
55 public:
56     virtual ~RenderTheme() { }
57
58     // This function is to be implemented in your platform-specific theme implementation to hand back the
59     // appropriate platform theme. When the theme is needed in non-page dependent code, a default theme is
60     // used as fallback, which is returned for a nulled page, so the platform code needs to account for this.
61     static PassRefPtr<RenderTheme> themeForPage(Page* page);
62
63     // When the theme is needed in non-page dependent code, the defaultTheme() is used as fallback.
64     static inline PassRefPtr<RenderTheme> defaultTheme()
65     {
66         return themeForPage(0);
67     };
68
69     // This method is called whenever style has been computed for an element and the appearance
70     // property has been set to a value other than "none".  The theme should map in all of the appropriate
71     // metrics and defaults given the contents of the style.  This includes sophisticated operations like
72     // selection of control size based off the font, the disabling of appearance when certain other properties like
73     // "border" are set, or if the appearance is not supported by the theme.
74     void adjustStyle(StyleResolver*, RenderStyle*, Element*,  bool UAHasAppearance,
75                      const BorderData&, const FillLayer&, const Color& backgroundColor);
76
77     // This method is called to paint the widget as a background of the RenderObject.  A widget's foreground, e.g., the
78     // text of a button, is always rendered by the engine itself.  The boolean return value indicates
79     // whether the CSS border/background should also be painted.
80     bool paint(RenderObject*, const PaintInfo&, const IntRect&);
81     bool paintBorderOnly(RenderObject*, const PaintInfo&, const IntRect&);
82     bool paintDecorations(RenderObject*, const PaintInfo&, const IntRect&);
83
84     // The remaining methods should be implemented by the platform-specific portion of the theme, e.g.,
85     // RenderThemeMac.cpp for Mac OS X.
86
87     // These methods return the theme's extra style sheets rules, to let each platform
88     // adjust the default CSS rules in html.css, quirks.css, or mediaControls.css
89     virtual String extraDefaultStyleSheet() { return String(); }
90     virtual String extraQuirksStyleSheet() { return String(); }
91 #if ENABLE(VIDEO)
92     virtual String extraMediaControlsStyleSheet() { return String(); };
93 #endif
94 #if ENABLE(FULLSCREEN_API)
95 #if ENABLE(TIZEN_MEDIA_CONTROL_USER_AGENT_SHEET)
96     virtual String extraFullScreenHorizontalStyleSheet() { return String(); };
97     virtual String extraFullScreenVerticalStyleSheet() { return String(); };
98 #else
99     virtual String extraFullScreenStyleSheet() { return String(); };
100 #endif
101 #endif
102 #if ENABLE(CALENDAR_PICKER)
103     virtual CString extraCalendarPickerStyleSheet();
104 #endif
105
106     // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
107     // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
108     // controls that need to do this.
109     virtual LayoutUnit baselinePosition(const RenderObject*) const;
110
111     // A method for asking if a control is a container or not.  Leaf controls have to have some special behavior (like
112     // the baseline position API above).
113     bool isControlContainer(ControlPart) const;
114
115     // A method asking if the control changes its tint when the window has focus or not.
116     virtual bool controlSupportsTints(const RenderObject*) const { return false; }
117
118     // Whether or not the control has been styled enough by the author to disable the native appearance.
119     virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
120
121     // A general method asking if any control tinting is supported at all.
122     virtual bool supportsControlTints() const { return false; }
123
124     // Some controls may spill out of their containers (e.g., the check on an OS X checkbox).  When these controls repaint,
125     // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
126     virtual void adjustRepaintRect(const RenderObject*, IntRect&);
127
128     // This method is called whenever a relevant state changes on a particular themed object, e.g., the mouse becomes pressed
129     // or a control becomes disabled.
130     virtual bool stateChanged(RenderObject*, ControlState) const;
131
132     // This method is called whenever the theme changes on the system in order to flush cached resources from the
133     // old theme.
134     virtual void themeChanged() { }
135
136     // A method asking if the theme is able to draw the focus ring.
137     virtual bool supportsFocusRing(const RenderStyle*) const;
138
139     // A method asking if the theme's controls actually care about redrawing when hovered.
140     virtual bool supportsHover(const RenderStyle*) const { return false; }
141
142     // A method asking if the platform is able to show datalist suggestions for a given input type.
143     virtual bool supportsDataListUI(const AtomicString&) const { return false; }
144
145     // Text selection colors.
146     Color activeSelectionBackgroundColor() const;
147     Color inactiveSelectionBackgroundColor() const;
148     Color activeSelectionForegroundColor() const;
149     Color inactiveSelectionForegroundColor() const;
150
151     // List box selection colors
152     Color activeListBoxSelectionBackgroundColor() const;
153     Color activeListBoxSelectionForegroundColor() const;
154     Color inactiveListBoxSelectionBackgroundColor() const;
155     Color inactiveListBoxSelectionForegroundColor() const;
156
157     // Highlighting colors for TextMatches.
158     virtual Color platformActiveTextSearchHighlightColor() const;
159     virtual Color platformInactiveTextSearchHighlightColor() const;
160
161     virtual Color disabledTextColor(const Color& textColor, const Color& backgroundColor) const;
162
163     static Color focusRingColor();
164     virtual Color platformFocusRingColor() const { return Color(0, 0, 0); }
165     static void setCustomFocusRingColor(const Color&);
166 #if ENABLE(TOUCH_EVENTS)
167     static Color tapHighlightColor();
168     virtual Color platformTapHighlightColor() const { return RenderTheme::defaultTapHighlightColor; }
169 #endif
170     virtual void platformColorsDidChange();
171
172     virtual double caretBlinkInterval() const { return 0.5; }
173
174     // System fonts and colors for CSS.
175     virtual void systemFont(int cssValueId, FontDescription&) const = 0;
176     virtual Color systemColor(int cssValueId) const;
177
178     virtual int minimumMenuListSize(RenderStyle*) const { return 0; }
179
180     virtual void adjustSliderThumbSize(RenderStyle*, Element*) const;
181
182     virtual int popupInternalPaddingLeft(RenderStyle*) const { return 0; }
183     virtual int popupInternalPaddingRight(RenderStyle*) const { return 0; }
184     virtual int popupInternalPaddingTop(RenderStyle*) const { return 0; }
185     virtual int popupInternalPaddingBottom(RenderStyle*) const { return 0; }
186     virtual bool popupOptionSupportsTextIndent() const { return false; }
187
188     virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return RegularScrollbar; }
189
190     // Method for painting the caps lock indicator
191     virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&) { return 0; };
192
193 #if ENABLE(PROGRESS_ELEMENT)
194     // Returns the repeat interval of the animation for the progress bar.
195     virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
196     // Returns the duration of the animation for the progress bar.
197     virtual double animationDurationForProgressBar(RenderProgress*) const;
198 #endif
199
200 #if ENABLE(VIDEO)
201     // Media controls
202     virtual bool supportsClosedCaptioning() const { return false; }
203     virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const { return false; }
204     virtual bool usesMediaControlStatusDisplay() { return false; }
205     virtual bool usesMediaControlVolumeSlider() const { return true; }
206     virtual bool usesVerticalVolumeSlider() const { return true; }
207     virtual double mediaControlsFadeInDuration() { return 0.1; }
208     virtual double mediaControlsFadeOutDuration() { return 0.3; }
209     virtual String formatMediaControlsTime(float time) const;
210     virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
211     virtual String formatMediaControlsRemainingTime(float currentTime, float duration) const;
212     
213     // Returns the media volume slider container's offset from the mute button.
214     virtual IntPoint volumeSliderOffsetFromMuteButton(RenderBox*, const IntSize&) const;
215 #endif
216
217 #if ENABLE(METER_ELEMENT)
218     virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const;
219     virtual bool supportsMeter(ControlPart) const;
220 #endif
221
222 #if ENABLE(DATALIST_ELEMENT)
223     // Returns size of one slider tick mark for a horizontal track.
224     // For vertical tracks we rotate it and use it. i.e. Width is always length along the track.
225     virtual IntSize sliderTickSize() const = 0;
226     // Returns the distance of slider tick origin from the slider track center.
227     virtual int sliderTickOffsetFromTrackCenter() const = 0;
228     void paintSliderTicks(RenderObject*, const PaintInfo&, const IntRect&);
229 #endif
230
231     virtual bool shouldShowPlaceholderWhenFocused() const { return false; }
232     virtual bool shouldHaveSpinButton(HTMLInputElement*) const;
233
234     // Functions for <select> elements.
235     virtual bool delegatesMenuListRendering() const { return false; }
236     virtual bool popsMenuByArrowKeys() const { return false; }
237     virtual bool popsMenuBySpaceOrReturn() const { return false; }
238
239     virtual String fileListDefaultLabel(bool multipleFilesAllowed) const;
240     virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const;
241
242 protected:
243     // The platform selection color.
244     virtual Color platformActiveSelectionBackgroundColor() const;
245     virtual Color platformInactiveSelectionBackgroundColor() const;
246     virtual Color platformActiveSelectionForegroundColor() const;
247     virtual Color platformInactiveSelectionForegroundColor() const;
248
249     virtual Color platformActiveListBoxSelectionBackgroundColor() const;
250     virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
251     virtual Color platformActiveListBoxSelectionForegroundColor() const;
252     virtual Color platformInactiveListBoxSelectionForegroundColor() const;
253
254     virtual bool supportsSelectionForegroundColors() const { return true; }
255     virtual bool supportsListBoxSelectionForegroundColors() const { return true; }
256
257 #if !USE(NEW_THEME)
258     // Methods for each appearance value.
259     virtual void adjustCheckboxStyle(StyleResolver*, RenderStyle*, Element*) const;
260     virtual bool paintCheckbox(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
261     virtual void setCheckboxSize(RenderStyle*) const { }
262
263     virtual void adjustRadioStyle(StyleResolver*, RenderStyle*, Element*) const;
264     virtual bool paintRadio(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
265     virtual void setRadioSize(RenderStyle*) const { }
266
267     virtual void adjustButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
268     virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
269     virtual void setButtonSize(RenderStyle*) const { }
270
271     virtual void adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
272     virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
273 #endif
274
275     virtual void adjustTextFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
276     virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
277
278     virtual void adjustTextAreaStyle(StyleResolver*, RenderStyle*, Element*) const;
279     virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
280
281     virtual void adjustMenuListStyle(StyleResolver*, RenderStyle*, Element*) const;
282     virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
283
284     virtual void adjustMenuListButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
285     virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
286
287 #if ENABLE(METER_ELEMENT)
288     virtual void adjustMeterStyle(StyleResolver*, RenderStyle*, Element*) const;
289     virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&);
290 #endif
291
292 #if ENABLE(PROGRESS_ELEMENT)
293     virtual void adjustProgressBarStyle(StyleResolver*, RenderStyle*, Element*) const;
294     virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
295 #endif
296
297 #if ENABLE(INPUT_SPEECH)
298     virtual void adjustInputFieldSpeechButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
299     virtual bool paintInputFieldSpeechButton(RenderObject*, const PaintInfo&, const IntRect&);
300 #endif
301
302     virtual void adjustSliderTrackStyle(StyleResolver*, RenderStyle*, Element*) const;
303     virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
304
305     virtual void adjustSliderThumbStyle(StyleResolver*, RenderStyle*, Element*) const;
306     virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
307
308     virtual void adjustSearchFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
309     virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
310
311     virtual void adjustSearchFieldCancelButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
312     virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
313
314     virtual void adjustSearchFieldDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
315     virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
316
317     virtual void adjustSearchFieldResultsDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
318     virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
319
320     virtual void adjustSearchFieldResultsButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
321     virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
322
323     virtual void adjustMediaControlStyle(StyleResolver*, RenderStyle*, Element*) const;
324     virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
325     virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
326     virtual bool paintMediaOverlayPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
327     virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
328     virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
329     virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
330     virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
331     virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
332     virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
333     virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
334     virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
335     virtual bool paintMediaRewindButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
336     virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
337     virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
338     virtual bool paintMediaControlsBackground(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
339     virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
340     virtual bool paintMediaTimeRemaining(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
341     virtual bool paintMediaFullScreenVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
342     virtual bool paintMediaFullScreenVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
343
344 public:
345     // Methods for state querying
346     ControlStates controlStatesForRenderer(const RenderObject* o) const;
347     bool isActive(const RenderObject*) const;
348     bool isChecked(const RenderObject*) const;
349     bool isIndeterminate(const RenderObject*) const;
350     bool isEnabled(const RenderObject*) const;
351     bool isFocused(const RenderObject*) const;
352     bool isPressed(const RenderObject*) const;
353     bool isSpinUpButtonPartPressed(const RenderObject*) const;
354     bool isHovered(const RenderObject*) const;
355     bool isSpinUpButtonPartHovered(const RenderObject*) const;
356     bool isReadOnlyControl(const RenderObject*) const;
357     bool isDefault(const RenderObject*) const;
358
359 private:
360     mutable Color m_activeSelectionBackgroundColor;
361     mutable Color m_inactiveSelectionBackgroundColor;
362     mutable Color m_activeSelectionForegroundColor;
363     mutable Color m_inactiveSelectionForegroundColor;
364
365     mutable Color m_activeListBoxSelectionBackgroundColor;
366     mutable Color m_inactiveListBoxSelectionBackgroundColor;
367     mutable Color m_activeListBoxSelectionForegroundColor;
368     mutable Color m_inactiveListBoxSelectionForegroundColor;
369
370 #if ENABLE(TOUCH_EVENTS)
371     static const RGBA32 defaultTapHighlightColor = 0x33000000;
372 #endif
373
374 #if USE(NEW_THEME)
375     Theme* m_theme; // The platform-specific theme.
376 #endif
377 };
378
379 } // namespace WebCore
380
381 #endif // RenderTheme_h