Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / 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 "platform/Theme.h"
28 #else
29 #include "platform/ThemeTypes.h"
30 #endif
31 #include "core/rendering/RenderObject.h"
32 #include "core/rendering/style/CachedUAStyle.h"
33 #include "platform/scroll/ScrollTypes.h"
34 #include "wtf/PassRefPtr.h"
35 #include "wtf/RefCounted.h"
36 #include "wtf/text/WTFString.h"
37
38 namespace WebCore {
39
40 class CSSStyleSheet;
41 class Element;
42 class FileList;
43 class HTMLInputElement;
44 class PopupMenu;
45 class RenderMenuList;
46 class RenderMeter;
47 class RenderProgress;
48
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.
59     static RenderTheme& theme();
60
61     static void setSizeIfAuto(RenderStyle*, const IntSize&);
62
63     // This method is called whenever style has been computed for an element and the appearance
64     // property has been set to a value other than "none".  The theme should map in all of the appropriate
65     // metrics and defaults given the contents of the style.  This includes sophisticated operations like
66     // selection of control size based off the font, the disabling of appearance when certain other properties like
67     // "border" are set, or if the appearance is not supported by the theme.
68     void adjustStyle(RenderStyle*, Element*,  const CachedUAStyle&);
69
70     // This method is called to paint the widget as a background of the RenderObject.  A widget's foreground, e.g., the
71     // text of a button, is always rendered by the engine itself.  The boolean return value indicates
72     // whether the CSS border/background should also be painted.
73     bool paint(RenderObject*, const PaintInfo&, const IntRect&);
74     bool paintBorderOnly(RenderObject*, const PaintInfo&, const IntRect&);
75     bool paintDecorations(RenderObject*, const PaintInfo&, const IntRect&);
76
77     // The remaining methods should be implemented by the platform-specific portion of the theme, e.g.,
78     // RenderThemeMac.cpp for Mac OS X.
79
80     // These methods return the theme's extra style sheets rules, to let each platform
81     // adjust the default CSS rules in html.css, quirks.css or mediaControls.css.
82     virtual String extraDefaultStyleSheet();
83     virtual String extraQuirksStyleSheet() { return String(); }
84     virtual String extraMediaControlsStyleSheet() { return String(); }
85     virtual String extraFullScreenStyleSheet() { return String(); }
86
87     // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
88     // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
89     // controls that need to do this.
90     virtual int baselinePosition(const RenderObject*) const;
91
92     // A method for asking if a control is a container or not.  Leaf controls have to have some special behavior (like
93     // the baseline position API above).
94     bool isControlContainer(ControlPart) const;
95
96     // A method asking if the control changes its tint when the window has focus or not.
97     virtual bool controlSupportsTints(const RenderObject*) const { return false; }
98
99     // Whether or not the control has been styled enough by the author to disable the native appearance.
100     virtual bool isControlStyled(const RenderStyle*, const CachedUAStyle&) const;
101
102     // A general method asking if any control tinting is supported at all.
103     virtual bool supportsControlTints() const { return false; }
104
105     // Some controls may spill out of their containers (e.g., the check on an OS X checkbox).  When these controls repaint,
106     // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
107     virtual void adjustRepaintRect(const RenderObject*, IntRect&);
108
109     // This method is called whenever a relevant state changes on a particular themed object, e.g., the mouse becomes pressed
110     // or a control becomes disabled.
111     virtual bool stateChanged(RenderObject*, ControlState) const;
112
113     bool shouldDrawDefaultFocusRing(RenderObject*) const;
114
115     // A method asking if the theme's controls actually care about redrawing when hovered.
116     virtual bool supportsHover(const RenderStyle*) const { return false; }
117
118 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
119     // A method asking if the platform is able to show a calendar picker for a given input type.
120     virtual bool supportsCalendarPicker(const AtomicString&) const;
121 #endif
122
123     // Text selection colors.
124     Color activeSelectionBackgroundColor() const;
125     Color inactiveSelectionBackgroundColor() const;
126     Color activeSelectionForegroundColor() const;
127     Color inactiveSelectionForegroundColor() const;
128
129     // List box selection colors
130     Color activeListBoxSelectionBackgroundColor() const;
131     Color activeListBoxSelectionForegroundColor() const;
132     Color inactiveListBoxSelectionBackgroundColor() const;
133     Color inactiveListBoxSelectionForegroundColor() const;
134
135     // Highlighting colors for TextMatches.
136     virtual Color platformActiveTextSearchHighlightColor() const;
137     virtual Color platformInactiveTextSearchHighlightColor() const;
138
139     Color focusRingColor() const;
140     virtual Color platformFocusRingColor() const { return Color(0, 0, 0); }
141     void setCustomFocusRingColor(const Color&);
142     static Color tapHighlightColor();
143     virtual Color platformTapHighlightColor() const { return RenderTheme::defaultTapHighlightColor; }
144     virtual void platformColorsDidChange();
145
146     virtual double caretBlinkInterval() const { return 0.5; }
147
148     // System fonts and colors for CSS.
149     virtual void systemFont(CSSValueID, FontDescription&) const = 0;
150     virtual Color systemColor(CSSValueID) const;
151
152     virtual int minimumMenuListSize(RenderStyle*) const { return 0; }
153
154     virtual void adjustSliderThumbSize(RenderStyle*, Element*) const;
155
156     virtual int popupInternalPaddingLeft(RenderStyle*) const { return 0; }
157     virtual int popupInternalPaddingRight(RenderStyle*) const { return 0; }
158     virtual int popupInternalPaddingTop(RenderStyle*) const { return 0; }
159     virtual int popupInternalPaddingBottom(RenderStyle*) const { return 0; }
160     virtual bool popupOptionSupportsTextIndent() const { return false; }
161
162     virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return RegularScrollbar; }
163
164     // Method for painting the caps lock indicator
165     virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&) { return 0; };
166
167     // Returns the repeat interval of the animation for the progress bar.
168     virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
169     // Returns the duration of the animation for the progress bar.
170     virtual double animationDurationForProgressBar(RenderProgress*) const;
171
172     // Media controls
173     virtual String formatMediaControlsTime(float time) const;
174     virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
175
176     virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const;
177     virtual bool supportsMeter(ControlPart) const;
178
179     // Returns size of one slider tick mark for a horizontal track.
180     // For vertical tracks we rotate it and use it. i.e. Width is always length along the track.
181     virtual IntSize sliderTickSize() const = 0;
182     // Returns the distance of slider tick origin from the slider track center.
183     virtual int sliderTickOffsetFromTrackCenter() const = 0;
184     void paintSliderTicks(RenderObject*, const PaintInfo&, const IntRect&);
185
186     virtual bool shouldShowPlaceholderWhenFocused() const { return false; }
187     virtual bool shouldHaveSpinButton(HTMLInputElement*) const;
188
189     // Functions for <select> elements.
190     virtual bool delegatesMenuListRendering() const { return false; }
191     virtual bool popsMenuByArrowKeys() const { return false; }
192     virtual bool popsMenuBySpaceOrReturn() const { return false; }
193
194     virtual String fileListNameForWidth(Locale&, const FileList*, const Font&, int width) const;
195
196     virtual bool shouldOpenPickerWithF4Key() const;
197
198     virtual bool supportsSelectionForegroundColors() const { return true; }
199
200 protected:
201     // The platform selection color.
202     virtual Color platformActiveSelectionBackgroundColor() const;
203     virtual Color platformInactiveSelectionBackgroundColor() const;
204     virtual Color platformActiveSelectionForegroundColor() const;
205     virtual Color platformInactiveSelectionForegroundColor() const;
206
207     virtual Color platformActiveListBoxSelectionBackgroundColor() const;
208     virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
209     virtual Color platformActiveListBoxSelectionForegroundColor() const;
210     virtual Color platformInactiveListBoxSelectionForegroundColor() const;
211
212     // A method asking if the theme is able to draw the focus ring.
213     virtual bool supportsFocusRing(const RenderStyle*) const;
214
215 #if !USE(NEW_THEME)
216     // Methods for each appearance value.
217     virtual void adjustCheckboxStyle(RenderStyle*, Element*) const;
218     virtual bool paintCheckbox(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
219     virtual void setCheckboxSize(RenderStyle*) const { }
220
221     virtual void adjustRadioStyle(RenderStyle*, Element*) const;
222     virtual bool paintRadio(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
223     virtual void setRadioSize(RenderStyle*) const { }
224
225     virtual void adjustButtonStyle(RenderStyle*, Element*) const;
226     virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
227
228     virtual void adjustInnerSpinButtonStyle(RenderStyle*, Element*) const;
229     virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
230 #endif
231
232     virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
233
234     virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
235
236     virtual void adjustMenuListStyle(RenderStyle*, Element*) const;
237     virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
238
239     virtual void adjustMenuListButtonStyle(RenderStyle*, Element*) const;
240     virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
241
242     virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&);
243
244     virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
245
246     virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
247
248     virtual void adjustSliderThumbStyle(RenderStyle*, Element*) const;
249     virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
250
251     virtual void adjustSearchFieldStyle(RenderStyle*, Element*) const;
252     virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
253
254     virtual void adjustSearchFieldCancelButtonStyle(RenderStyle*, Element*) const;
255     virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
256
257     virtual void adjustSearchFieldDecorationStyle(RenderStyle*, Element*) const;
258     virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
259
260     virtual void adjustSearchFieldResultsDecorationStyle(RenderStyle*, Element*) const;
261     virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
262
263     virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
264     virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
265     virtual bool paintMediaOverlayPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
266     virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
267     virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
268     virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
269     virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
270     virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
271     virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
272     virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
273     virtual bool paintMediaControlsBackground(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
274     virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
275     virtual bool paintMediaTimeRemaining(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
276     virtual bool paintMediaFullScreenVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
277     virtual bool paintMediaFullScreenVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
278
279     virtual bool shouldUseFallbackTheme(RenderStyle*) const;
280     void adjustStyleUsingFallbackTheme(RenderStyle*, Element*);
281     bool paintUsingFallbackTheme(RenderObject*, const PaintInfo&, const IntRect&);
282     void adjustCheckboxStyleUsingFallbackTheme(RenderStyle*, Element*) const;
283     bool paintCheckboxUsingFallbackTheme(RenderObject*, const PaintInfo&, const IntRect&);
284     void adjustRadioStyleUsingFallbackTheme(RenderStyle*, Element*) const;
285     bool paintRadioUsingFallbackTheme(RenderObject*, const PaintInfo&, const IntRect&);
286
287 public:
288     // Methods for state querying
289     ControlStates controlStatesForRenderer(const RenderObject* o) const;
290     bool isActive(const RenderObject*) const;
291     bool isChecked(const RenderObject*) const;
292     bool isIndeterminate(const RenderObject*) const;
293     bool isEnabled(const RenderObject*) const;
294     bool isFocused(const RenderObject*) const;
295     bool isPressed(const RenderObject*) const;
296     bool isSpinUpButtonPartPressed(const RenderObject*) const;
297     bool isHovered(const RenderObject*) const;
298     bool isSpinUpButtonPartHovered(const RenderObject*) const;
299     bool isReadOnlyControl(const RenderObject*) const;
300
301 private:
302     Color m_customFocusRingColor;
303     bool m_hasCustomFocusRingColor;
304
305     // This color is expected to be drawn on a semi-transparent overlay,
306     // making it more transparent than its alpha value indicates.
307     static const RGBA32 defaultTapHighlightColor = 0x66000000;
308
309 #if USE(NEW_THEME)
310     Theme* m_platformTheme; // The platform-specific theme.
311 #endif
312 };
313
314 } // namespace WebCore
315
316 #endif // RenderTheme_h