initial import
[vuplus_webkit] / 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 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 HTMLInputElement;
40 class PopupMenu;
41 class RenderMenuList;
42 #if ENABLE(METER_TAG)
43 class RenderMeter;
44 #endif
45 #if ENABLE(PROGRESS_TAG)
46 class RenderProgress;
47 #endif
48 class CSSStyleSheet;
49
50 class RenderTheme : public RefCounted<RenderTheme> {
51 protected:
52     RenderTheme();
53
54 public:
55     virtual ~RenderTheme() { }
56
57     // This function is to be implemented in your platform-specific theme implementation to hand back the
58     // appropriate platform theme. When the theme is needed in non-page dependent code, a default theme is
59     // used as fallback, which is returned for a nulled page, so the platform code needs to account for this.
60     static PassRefPtr<RenderTheme> themeForPage(Page* page);
61
62     // When the theme is needed in non-page dependent code, the defaultTheme() is used as fallback.
63     static inline PassRefPtr<RenderTheme> defaultTheme()
64     {
65         return themeForPage(0);
66     };
67
68     // This method is called whenever style has been computed for an element and the appearance
69     // property has been set to a value other than "none".  The theme should map in all of the appropriate
70     // metrics and defaults given the contents of the style.  This includes sophisticated operations like
71     // selection of control size based off the font, the disabling of appearance when certain other properties like
72     // "border" are set, or if the appearance is not supported by the theme.
73     void adjustStyle(CSSStyleSelector*, RenderStyle*, Element*,  bool UAHasAppearance,
74                      const BorderData&, const FillLayer&, const Color& backgroundColor);
75
76     // This method is called to paint the widget as a background of the RenderObject.  A widget's foreground, e.g., the
77     // text of a button, is always rendered by the engine itself.  The boolean return value indicates
78     // whether the CSS border/background should also be painted.
79     bool paint(RenderObject*, const PaintInfo&, const LayoutRect&);
80     bool paintBorderOnly(RenderObject*, const PaintInfo&, const IntRect&);
81     bool paintDecorations(RenderObject*, const PaintInfo&, const IntRect&);
82
83     // The remaining methods should be implemented by the platform-specific portion of the theme, e.g.,
84     // RenderThemeMac.cpp for Mac OS X.
85
86     // These methods return the theme's extra style sheets rules, to let each platform
87     // adjust the default CSS rules in html.css, quirks.css, or mediaControls.css
88     virtual String extraDefaultStyleSheet() { return String(); }
89     virtual String extraQuirksStyleSheet() { return String(); }
90 #if ENABLE(VIDEO)
91     virtual String extraMediaControlsStyleSheet() { return String(); };
92 #endif
93 #if ENABLE(FULLSCREEN_API)
94     virtual String extraFullScreenStyleSheet() { return String(); };
95 #endif
96
97     // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
98     // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
99     // controls that need to do this.
100     virtual int baselinePosition(const RenderObject*) const;
101
102     // A method for asking if a control is a container or not.  Leaf controls have to have some special behavior (like
103     // the baseline position API above).
104     bool isControlContainer(ControlPart) const;
105
106     // A method asking if the control changes its tint when the window has focus or not.
107     virtual bool controlSupportsTints(const RenderObject*) const { return false; }
108
109     // Whether or not the control has been styled enough by the author to disable the native appearance.
110     virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
111
112     // A general method asking if any control tinting is supported at all.
113     virtual bool supportsControlTints() const { return false; }
114
115     // Some controls may spill out of their containers (e.g., the check on an OS X checkbox).  When these controls repaint,
116     // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
117     virtual void adjustRepaintRect(const RenderObject*, IntRect&);
118
119     // This method is called whenever a relevant state changes on a particular themed object, e.g., the mouse becomes pressed
120     // or a control becomes disabled.
121     virtual bool stateChanged(RenderObject*, ControlState) const;
122
123     // This method is called whenever the theme changes on the system in order to flush cached resources from the
124     // old theme.
125     virtual void themeChanged() { }
126
127     // A method asking if the theme is able to draw the focus ring.
128     virtual bool supportsFocusRing(const RenderStyle*) const;
129
130     // A method asking if the theme's controls actually care about redrawing when hovered.
131     virtual bool supportsHover(const RenderStyle*) const { return false; }
132
133     // Text selection colors.
134     Color activeSelectionBackgroundColor() const;
135     Color inactiveSelectionBackgroundColor() const;
136     Color activeSelectionForegroundColor() const;
137     Color inactiveSelectionForegroundColor() const;
138
139     // List box selection colors
140     Color activeListBoxSelectionBackgroundColor() const;
141     Color activeListBoxSelectionForegroundColor() const;
142     Color inactiveListBoxSelectionBackgroundColor() const;
143     Color inactiveListBoxSelectionForegroundColor() const;
144
145     // Highlighting colors for TextMatches.
146     virtual Color platformActiveTextSearchHighlightColor() const;
147     virtual Color platformInactiveTextSearchHighlightColor() const;
148
149     static Color focusRingColor();
150     virtual Color platformFocusRingColor() const { return Color(0, 0, 0); }
151     static void setCustomFocusRingColor(const Color&);
152
153     virtual void platformColorsDidChange();
154
155     virtual double caretBlinkInterval() const { return 0.5; }
156
157     // System fonts and colors for CSS.
158     virtual void systemFont(int cssValueId, FontDescription&) const = 0;
159     virtual Color systemColor(int cssValueId) const;
160
161     virtual int minimumMenuListSize(RenderStyle*) const { return 0; }
162
163     virtual void adjustSliderThumbSize(RenderStyle*) const;
164
165     virtual int popupInternalPaddingLeft(RenderStyle*) const { return 0; }
166     virtual int popupInternalPaddingRight(RenderStyle*) const { return 0; }
167     virtual int popupInternalPaddingTop(RenderStyle*) const { return 0; }
168     virtual int popupInternalPaddingBottom(RenderStyle*) const { return 0; }
169     virtual bool popupOptionSupportsTextIndent() const { return false; }
170
171     virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return RegularScrollbar; }
172
173     // Method for painting the caps lock indicator
174     virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&) { return 0; };
175
176 #if ENABLE(PROGRESS_TAG)
177     // Returns the repeat interval of the animation for the progress bar.
178     virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
179     // Returns the duration of the animation for the progress bar.
180     virtual double animationDurationForProgressBar(RenderProgress*) const;
181 #endif
182
183 #if ENABLE(VIDEO)
184     // Media controls
185     virtual bool supportsClosedCaptioning() const { return false; }
186     virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const { return false; }
187     virtual bool usesMediaControlStatusDisplay() { return false; }
188     virtual bool usesMediaControlVolumeSlider() const { return true; }
189     virtual double mediaControlsFadeInDuration() { return 0.1; }
190     virtual double mediaControlsFadeOutDuration() { return 0.3; }
191     virtual String formatMediaControlsTime(float time) const;
192     virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
193     virtual String formatMediaControlsRemainingTime(float currentTime, float duration) const;
194     
195     // Returns the media volume slider container's offset from the mute button.
196     virtual IntPoint volumeSliderOffsetFromMuteButton(RenderBox*, const IntSize&) const;
197 #endif
198
199 #if ENABLE(METER_TAG)
200     virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const;
201     virtual bool supportsMeter(ControlPart) const;
202 #endif
203     
204     virtual bool shouldShowPlaceholderWhenFocused() const { return false; }
205     virtual bool shouldHaveSpinButton(HTMLInputElement*) const;
206
207     virtual String fileListNameForWidth(const Vector<String>& filenames, const Font&, int width);
208
209 protected:
210     // The platform selection color.
211     virtual Color platformActiveSelectionBackgroundColor() const;
212     virtual Color platformInactiveSelectionBackgroundColor() const;
213     virtual Color platformActiveSelectionForegroundColor() const;
214     virtual Color platformInactiveSelectionForegroundColor() const;
215
216     virtual Color platformActiveListBoxSelectionBackgroundColor() const;
217     virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
218     virtual Color platformActiveListBoxSelectionForegroundColor() const;
219     virtual Color platformInactiveListBoxSelectionForegroundColor() const;
220
221     virtual bool supportsSelectionForegroundColors() const { return true; }
222     virtual bool supportsListBoxSelectionForegroundColors() const { return true; }
223
224 #if !USE(NEW_THEME)
225     // Methods for each appearance value.
226     virtual void adjustCheckboxStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
227     virtual bool paintCheckbox(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
228     virtual void setCheckboxSize(RenderStyle*) const { }
229
230     virtual void adjustRadioStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
231     virtual bool paintRadio(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
232     virtual void setRadioSize(RenderStyle*) const { }
233
234     virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
235     virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
236     virtual void setButtonSize(RenderStyle*) const { }
237
238     virtual void adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
239     virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
240 #endif
241
242     virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
243     virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
244
245     virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
246     virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
247
248     virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
249     virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
250
251     virtual void adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
252     virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
253
254 #if ENABLE(METER_TAG)
255     virtual void adjustMeterStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
256     virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&);
257 #endif
258
259 #if ENABLE(PROGRESS_TAG)
260     virtual void adjustProgressBarStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
261     virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
262 #endif
263
264 #if ENABLE(INPUT_SPEECH)
265     virtual void adjustInputFieldSpeechButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
266     virtual bool paintInputFieldSpeechButton(RenderObject*, const PaintInfo&, const IntRect&);
267 #endif
268
269     virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
270     virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
271
272     virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
273     virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
274
275     virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
276     virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
277
278     virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
279     virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
280
281     virtual void adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
282     virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
283
284     virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
285     virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
286
287     virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
288     virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
289
290     virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
291     virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
292     virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
293     virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
294     virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
295     virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
296     virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
297     virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
298     virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
299     virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
300     virtual bool paintMediaRewindButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
301     virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
302     virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
303     virtual bool paintMediaControlsBackground(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
304     virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
305     virtual bool paintMediaTimeRemaining(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
306
307 public:
308     // Methods for state querying
309     ControlStates controlStatesForRenderer(const RenderObject* o) const;
310     bool isActive(const RenderObject*) const;
311     bool isChecked(const RenderObject*) const;
312     bool isIndeterminate(const RenderObject*) const;
313     bool isEnabled(const RenderObject*) const;
314     bool isFocused(const RenderObject*) const;
315     bool isPressed(const RenderObject*) const;
316     bool isSpinUpButtonPartPressed(const RenderObject*) const;
317     bool isHovered(const RenderObject*) const;
318     bool isSpinUpButtonPartHovered(const RenderObject*) const;
319     bool isReadOnlyControl(const RenderObject*) const;
320     bool isDefault(const RenderObject*) const;
321
322 private:
323     mutable Color m_activeSelectionBackgroundColor;
324     mutable Color m_inactiveSelectionBackgroundColor;
325     mutable Color m_activeSelectionForegroundColor;
326     mutable Color m_inactiveSelectionForegroundColor;
327
328     mutable Color m_activeListBoxSelectionBackgroundColor;
329     mutable Color m_inactiveListBoxSelectionBackgroundColor;
330     mutable Color m_activeListBoxSelectionForegroundColor;
331     mutable Color m_inactiveListBoxSelectionForegroundColor;
332
333 #if USE(NEW_THEME)
334     Theme* m_theme; // The platform-specific theme.
335 #endif
336 };
337
338 } // namespace WebCore
339
340 #endif // RenderTheme_h