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