2 * This file is part of the theme implementation for form controls in WebCore.
4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Computer, Inc.
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.
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.
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.
29 #include "ThemeTypes.h"
31 #include "RenderObject.h"
32 #include "ScrollTypes.h"
33 #include <wtf/PassRefPtr.h>
34 #include <wtf/RefCounted.h>
40 class HTMLInputElement;
46 #if ENABLE(PROGRESS_TAG)
51 class RenderTheme : public RefCounted<RenderTheme> {
56 virtual ~RenderTheme() { }
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);
63 // When the theme is needed in non-page dependent code, the defaultTheme() is used as fallback.
64 static inline PassRefPtr<RenderTheme> defaultTheme()
66 return themeForPage(0);
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);
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&);
84 // The remaining methods should be implemented by the platform-specific portion of the theme, e.g.,
85 // RenderThemeMac.cpp for Mac OS X.
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(); }
92 virtual String extraMediaControlsStyleSheet() { return String(); };
94 #if ENABLE(FULLSCREEN_API)
95 virtual String extraFullScreenStyleSheet() { return String(); };
97 #if ENABLE(CALENDAR_PICKER)
98 virtual CString extraCalendarPickerStyleSheet();
101 // A method to obtain the baseline position for a "leaf" control. This will only be used if a baseline
102 // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
103 // controls that need to do this.
104 virtual LayoutUnit baselinePosition(const RenderObject*) const;
106 // A method for asking if a control is a container or not. Leaf controls have to have some special behavior (like
107 // the baseline position API above).
108 bool isControlContainer(ControlPart) const;
110 // A method asking if the control changes its tint when the window has focus or not.
111 virtual bool controlSupportsTints(const RenderObject*) const { return false; }
113 // Whether or not the control has been styled enough by the author to disable the native appearance.
114 virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
116 // A general method asking if any control tinting is supported at all.
117 virtual bool supportsControlTints() const { return false; }
119 // Some controls may spill out of their containers (e.g., the check on an OS X checkbox). When these controls repaint,
120 // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
121 virtual void adjustRepaintRect(const RenderObject*, IntRect&);
123 // This method is called whenever a relevant state changes on a particular themed object, e.g., the mouse becomes pressed
124 // or a control becomes disabled.
125 virtual bool stateChanged(RenderObject*, ControlState) const;
127 // This method is called whenever the theme changes on the system in order to flush cached resources from the
129 virtual void themeChanged() { }
131 // A method asking if the theme is able to draw the focus ring.
132 virtual bool supportsFocusRing(const RenderStyle*) const;
134 // A method asking if the theme's controls actually care about redrawing when hovered.
135 virtual bool supportsHover(const RenderStyle*) const { return false; }
137 // A method asking if the platform is able to show datalist suggestions for a given input type.
138 virtual bool supportsDataListUI(const AtomicString&) const { return false; }
140 // Text selection colors.
141 Color activeSelectionBackgroundColor() const;
142 Color inactiveSelectionBackgroundColor() const;
143 Color activeSelectionForegroundColor() const;
144 Color inactiveSelectionForegroundColor() const;
146 // List box selection colors
147 Color activeListBoxSelectionBackgroundColor() const;
148 Color activeListBoxSelectionForegroundColor() const;
149 Color inactiveListBoxSelectionBackgroundColor() const;
150 Color inactiveListBoxSelectionForegroundColor() const;
152 // Highlighting colors for TextMatches.
153 virtual Color platformActiveTextSearchHighlightColor() const;
154 virtual Color platformInactiveTextSearchHighlightColor() const;
156 virtual Color disabledTextColor(const Color& textColor, const Color& backgroundColor) const;
158 static Color focusRingColor();
159 virtual Color platformFocusRingColor() const { return Color(0, 0, 0); }
160 static void setCustomFocusRingColor(const Color&);
161 #if ENABLE(TOUCH_EVENTS)
162 static Color tapHighlightColor();
163 virtual Color platformTapHighlightColor() const { return RenderTheme::defaultTapHighlightColor; }
165 virtual void platformColorsDidChange();
167 virtual double caretBlinkInterval() const { return 0.5; }
169 // System fonts and colors for CSS.
170 virtual void systemFont(int cssValueId, FontDescription&) const = 0;
171 virtual Color systemColor(int cssValueId) const;
173 virtual int minimumMenuListSize(RenderStyle*) const { return 0; }
175 virtual void adjustSliderThumbSize(RenderStyle*, Element*) const;
177 virtual int popupInternalPaddingLeft(RenderStyle*) const { return 0; }
178 virtual int popupInternalPaddingRight(RenderStyle*) const { return 0; }
179 virtual int popupInternalPaddingTop(RenderStyle*) const { return 0; }
180 virtual int popupInternalPaddingBottom(RenderStyle*) const { return 0; }
181 virtual bool popupOptionSupportsTextIndent() const { return false; }
183 virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return RegularScrollbar; }
185 // Method for painting the caps lock indicator
186 virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&) { return 0; };
188 #if ENABLE(PROGRESS_TAG)
189 // Returns the repeat interval of the animation for the progress bar.
190 virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
191 // Returns the duration of the animation for the progress bar.
192 virtual double animationDurationForProgressBar(RenderProgress*) const;
197 virtual bool supportsClosedCaptioning() const { return false; }
198 virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const { return false; }
199 virtual bool usesMediaControlStatusDisplay() { return false; }
200 virtual bool usesMediaControlVolumeSlider() const { return true; }
201 virtual bool usesVerticalVolumeSlider() const { return true; }
202 virtual double mediaControlsFadeInDuration() { return 0.1; }
203 virtual double mediaControlsFadeOutDuration() { return 0.3; }
204 virtual String formatMediaControlsTime(float time) const;
205 virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
206 virtual String formatMediaControlsRemainingTime(float currentTime, float duration) const;
208 // Returns the media volume slider container's offset from the mute button.
209 virtual IntPoint volumeSliderOffsetFromMuteButton(RenderBox*, const IntSize&) const;
212 #if ENABLE(METER_TAG)
213 virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const;
214 virtual bool supportsMeter(ControlPart) const;
217 virtual bool shouldShowPlaceholderWhenFocused() const { return false; }
218 virtual bool shouldHaveSpinButton(HTMLInputElement*) const;
220 // Functions for <select> elements.
221 virtual bool delegatesMenuListRendering() const { return false; }
222 virtual bool popsMenuByArrowKeys() const { return false; }
223 virtual bool popsMenuBySpaceOrReturn() const { return false; }
225 virtual String fileListDefaultLabel(bool multipleFilesAllowed) const;
226 virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const;
229 // The platform selection color.
230 virtual Color platformActiveSelectionBackgroundColor() const;
231 virtual Color platformInactiveSelectionBackgroundColor() const;
232 virtual Color platformActiveSelectionForegroundColor() const;
233 virtual Color platformInactiveSelectionForegroundColor() const;
235 virtual Color platformActiveListBoxSelectionBackgroundColor() const;
236 virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
237 virtual Color platformActiveListBoxSelectionForegroundColor() const;
238 virtual Color platformInactiveListBoxSelectionForegroundColor() const;
240 virtual bool supportsSelectionForegroundColors() const { return true; }
241 virtual bool supportsListBoxSelectionForegroundColors() const { return true; }
244 // Methods for each appearance value.
245 virtual void adjustCheckboxStyle(StyleResolver*, RenderStyle*, Element*) const;
246 virtual bool paintCheckbox(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
247 virtual void setCheckboxSize(RenderStyle*) const { }
249 virtual void adjustRadioStyle(StyleResolver*, RenderStyle*, Element*) const;
250 virtual bool paintRadio(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
251 virtual void setRadioSize(RenderStyle*) const { }
253 virtual void adjustButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
254 virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
255 virtual void setButtonSize(RenderStyle*) const { }
257 virtual void adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
258 virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
261 virtual void adjustTextFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
262 virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
264 virtual void adjustTextAreaStyle(StyleResolver*, RenderStyle*, Element*) const;
265 virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
267 virtual void adjustMenuListStyle(StyleResolver*, RenderStyle*, Element*) const;
268 virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
270 virtual void adjustMenuListButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
271 virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
273 #if ENABLE(METER_TAG)
274 virtual void adjustMeterStyle(StyleResolver*, RenderStyle*, Element*) const;
275 virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&);
278 #if ENABLE(PROGRESS_TAG)
279 virtual void adjustProgressBarStyle(StyleResolver*, RenderStyle*, Element*) const;
280 virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
283 #if ENABLE(INPUT_SPEECH)
284 virtual void adjustInputFieldSpeechButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
285 virtual bool paintInputFieldSpeechButton(RenderObject*, const PaintInfo&, const IntRect&);
288 virtual void adjustSliderTrackStyle(StyleResolver*, RenderStyle*, Element*) const;
289 virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
291 virtual void adjustSliderThumbStyle(StyleResolver*, RenderStyle*, Element*) const;
292 virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
294 virtual void adjustSearchFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
295 virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
297 virtual void adjustSearchFieldCancelButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
298 virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
300 virtual void adjustSearchFieldDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
301 virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
303 virtual void adjustSearchFieldResultsDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
304 virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
306 virtual void adjustSearchFieldResultsButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
307 virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
309 virtual void adjustMediaControlStyle(StyleResolver*, RenderStyle*, Element*) const;
310 virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
311 virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
312 virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
313 virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
314 virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
315 virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
316 virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
317 virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
318 virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
319 virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
320 virtual bool paintMediaRewindButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
321 virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
322 virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
323 virtual bool paintMediaControlsBackground(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
324 virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
325 virtual bool paintMediaTimeRemaining(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
326 virtual bool paintMediaFullScreenVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
327 virtual bool paintMediaFullScreenVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
330 // Methods for state querying
331 ControlStates controlStatesForRenderer(const RenderObject* o) const;
332 bool isActive(const RenderObject*) const;
333 bool isChecked(const RenderObject*) const;
334 bool isIndeterminate(const RenderObject*) const;
335 bool isEnabled(const RenderObject*) const;
336 bool isFocused(const RenderObject*) const;
337 bool isPressed(const RenderObject*) const;
338 bool isSpinUpButtonPartPressed(const RenderObject*) const;
339 bool isHovered(const RenderObject*) const;
340 bool isSpinUpButtonPartHovered(const RenderObject*) const;
341 bool isReadOnlyControl(const RenderObject*) const;
342 bool isDefault(const RenderObject*) const;
345 mutable Color m_activeSelectionBackgroundColor;
346 mutable Color m_inactiveSelectionBackgroundColor;
347 mutable Color m_activeSelectionForegroundColor;
348 mutable Color m_inactiveSelectionForegroundColor;
350 mutable Color m_activeListBoxSelectionBackgroundColor;
351 mutable Color m_inactiveListBoxSelectionBackgroundColor;
352 mutable Color m_activeListBoxSelectionForegroundColor;
353 mutable Color m_inactiveListBoxSelectionForegroundColor;
355 #if ENABLE(TOUCH_EVENTS)
356 static const RGBA32 defaultTapHighlightColor = 0x33000000;
360 Theme* m_theme; // The platform-specific theme.
364 } // namespace WebCore
366 #endif // RenderTheme_h