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*) 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 double mediaControlsFadeInDuration() { return 0.1; }
202 virtual double mediaControlsFadeOutDuration() { return 0.3; }
203 virtual String formatMediaControlsTime(float time) const;
204 virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
205 virtual String formatMediaControlsRemainingTime(float currentTime, float duration) const;
207 // Returns the media volume slider container's offset from the mute button.
208 virtual IntPoint volumeSliderOffsetFromMuteButton(RenderBox*, const IntSize&) const;
211 #if ENABLE(METER_TAG)
212 virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const;
213 virtual bool supportsMeter(ControlPart) const;
216 virtual bool shouldShowPlaceholderWhenFocused() const { return false; }
217 virtual bool shouldHaveSpinButton(HTMLInputElement*) const;
219 // Functions for <select> elements.
220 virtual bool delegatesMenuListRendering() const { return false; }
221 virtual bool popsMenuByArrowKeys() const { return false; }
222 virtual bool popsMenuBySpaceOrReturn() const { return false; }
224 virtual String fileListDefaultLabel(bool multipleFilesAllowed) const;
225 virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const;
228 // The platform selection color.
229 virtual Color platformActiveSelectionBackgroundColor() const;
230 virtual Color platformInactiveSelectionBackgroundColor() const;
231 virtual Color platformActiveSelectionForegroundColor() const;
232 virtual Color platformInactiveSelectionForegroundColor() const;
234 virtual Color platformActiveListBoxSelectionBackgroundColor() const;
235 virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
236 virtual Color platformActiveListBoxSelectionForegroundColor() const;
237 virtual Color platformInactiveListBoxSelectionForegroundColor() const;
239 virtual bool supportsSelectionForegroundColors() const { return true; }
240 virtual bool supportsListBoxSelectionForegroundColors() const { return true; }
243 // Methods for each appearance value.
244 virtual void adjustCheckboxStyle(StyleResolver*, RenderStyle*, Element*) const;
245 virtual bool paintCheckbox(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
246 virtual void setCheckboxSize(RenderStyle*) const { }
248 virtual void adjustRadioStyle(StyleResolver*, RenderStyle*, Element*) const;
249 virtual bool paintRadio(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
250 virtual void setRadioSize(RenderStyle*) const { }
252 virtual void adjustButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
253 virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
254 virtual void setButtonSize(RenderStyle*) const { }
256 virtual void adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
257 virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
260 virtual void adjustTextFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
261 virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
263 virtual void adjustTextAreaStyle(StyleResolver*, RenderStyle*, Element*) const;
264 virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
266 virtual void adjustMenuListStyle(StyleResolver*, RenderStyle*, Element*) const;
267 virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
269 virtual void adjustMenuListButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
270 virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
272 #if ENABLE(METER_TAG)
273 virtual void adjustMeterStyle(StyleResolver*, RenderStyle*, Element*) const;
274 virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&);
277 #if ENABLE(PROGRESS_TAG)
278 virtual void adjustProgressBarStyle(StyleResolver*, RenderStyle*, Element*) const;
279 virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
282 #if ENABLE(INPUT_SPEECH)
283 virtual void adjustInputFieldSpeechButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
284 virtual bool paintInputFieldSpeechButton(RenderObject*, const PaintInfo&, const IntRect&);
287 virtual void adjustSliderTrackStyle(StyleResolver*, RenderStyle*, Element*) const;
288 virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
290 virtual void adjustSliderThumbStyle(StyleResolver*, RenderStyle*, Element*) const;
291 virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
293 virtual void adjustSearchFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
294 virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
296 virtual void adjustSearchFieldCancelButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
297 virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
299 virtual void adjustSearchFieldDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
300 virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
302 virtual void adjustSearchFieldResultsDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
303 virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
305 virtual void adjustSearchFieldResultsButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
306 virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
308 virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
309 virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
310 virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
311 virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
312 virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
313 virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
314 virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
315 virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
316 virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
317 virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
318 virtual bool paintMediaRewindButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
319 virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
320 virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
321 virtual bool paintMediaControlsBackground(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
322 virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
323 virtual bool paintMediaTimeRemaining(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
324 virtual bool paintMediaFullScreenVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
325 virtual bool paintMediaFullScreenVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
328 // Methods for state querying
329 ControlStates controlStatesForRenderer(const RenderObject* o) const;
330 bool isActive(const RenderObject*) const;
331 bool isChecked(const RenderObject*) const;
332 bool isIndeterminate(const RenderObject*) const;
333 bool isEnabled(const RenderObject*) const;
334 bool isFocused(const RenderObject*) const;
335 bool isPressed(const RenderObject*) const;
336 bool isSpinUpButtonPartPressed(const RenderObject*) const;
337 bool isHovered(const RenderObject*) const;
338 bool isSpinUpButtonPartHovered(const RenderObject*) const;
339 bool isReadOnlyControl(const RenderObject*) const;
340 bool isDefault(const RenderObject*) const;
343 mutable Color m_activeSelectionBackgroundColor;
344 mutable Color m_inactiveSelectionBackgroundColor;
345 mutable Color m_activeSelectionForegroundColor;
346 mutable Color m_inactiveSelectionForegroundColor;
348 mutable Color m_activeListBoxSelectionBackgroundColor;
349 mutable Color m_inactiveListBoxSelectionBackgroundColor;
350 mutable Color m_activeListBoxSelectionForegroundColor;
351 mutable Color m_inactiveListBoxSelectionForegroundColor;
353 #if ENABLE(TOUCH_EVENTS)
354 static const RGBA32 defaultTapHighlightColor = 0x33000000;
358 Theme* m_theme; // The platform-specific theme.
362 } // namespace WebCore
364 #endif // RenderTheme_h