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;
43 #if ENABLE(METER_ELEMENT)
46 #if ENABLE(PROGRESS_ELEMENT)
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 #if ENABLE(TIZEN_MEDIA_CONTROL_USER_AGENT_SHEET)
96 virtual String extraFullScreenHorizontalStyleSheet() { return String(); };
97 virtual String extraFullScreenVerticalStyleSheet() { return String(); };
99 virtual String extraFullScreenStyleSheet() { return String(); };
102 #if ENABLE(CALENDAR_PICKER)
103 virtual CString extraCalendarPickerStyleSheet();
106 // A method to obtain the baseline position for a "leaf" control. This will only be used if a baseline
107 // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
108 // controls that need to do this.
109 virtual LayoutUnit baselinePosition(const RenderObject*) const;
111 // A method for asking if a control is a container or not. Leaf controls have to have some special behavior (like
112 // the baseline position API above).
113 bool isControlContainer(ControlPart) const;
115 // A method asking if the control changes its tint when the window has focus or not.
116 virtual bool controlSupportsTints(const RenderObject*) const { return false; }
118 // Whether or not the control has been styled enough by the author to disable the native appearance.
119 virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
121 // A general method asking if any control tinting is supported at all.
122 virtual bool supportsControlTints() const { return false; }
124 // Some controls may spill out of their containers (e.g., the check on an OS X checkbox). When these controls repaint,
125 // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
126 virtual void adjustRepaintRect(const RenderObject*, IntRect&);
128 // This method is called whenever a relevant state changes on a particular themed object, e.g., the mouse becomes pressed
129 // or a control becomes disabled.
130 virtual bool stateChanged(RenderObject*, ControlState) const;
132 // This method is called whenever the theme changes on the system in order to flush cached resources from the
134 virtual void themeChanged() { }
136 // A method asking if the theme is able to draw the focus ring.
137 virtual bool supportsFocusRing(const RenderStyle*) const;
139 // A method asking if the theme's controls actually care about redrawing when hovered.
140 virtual bool supportsHover(const RenderStyle*) const { return false; }
142 // A method asking if the platform is able to show datalist suggestions for a given input type.
143 virtual bool supportsDataListUI(const AtomicString&) const { return false; }
145 // Text selection colors.
146 Color activeSelectionBackgroundColor() const;
147 Color inactiveSelectionBackgroundColor() const;
148 Color activeSelectionForegroundColor() const;
149 Color inactiveSelectionForegroundColor() const;
151 // List box selection colors
152 Color activeListBoxSelectionBackgroundColor() const;
153 Color activeListBoxSelectionForegroundColor() const;
154 Color inactiveListBoxSelectionBackgroundColor() const;
155 Color inactiveListBoxSelectionForegroundColor() const;
157 // Highlighting colors for TextMatches.
158 virtual Color platformActiveTextSearchHighlightColor() const;
159 virtual Color platformInactiveTextSearchHighlightColor() const;
161 virtual Color disabledTextColor(const Color& textColor, const Color& backgroundColor) const;
163 static Color focusRingColor();
164 virtual Color platformFocusRingColor() const { return Color(0, 0, 0); }
165 static void setCustomFocusRingColor(const Color&);
166 #if ENABLE(TOUCH_EVENTS)
167 static Color tapHighlightColor();
168 virtual Color platformTapHighlightColor() const { return RenderTheme::defaultTapHighlightColor; }
170 virtual void platformColorsDidChange();
172 virtual double caretBlinkInterval() const { return 0.5; }
174 // System fonts and colors for CSS.
175 virtual void systemFont(int cssValueId, FontDescription&) const = 0;
176 virtual Color systemColor(int cssValueId) const;
178 virtual int minimumMenuListSize(RenderStyle*) const { return 0; }
180 virtual void adjustSliderThumbSize(RenderStyle*, Element*) const;
182 virtual int popupInternalPaddingLeft(RenderStyle*) const { return 0; }
183 virtual int popupInternalPaddingRight(RenderStyle*) const { return 0; }
184 virtual int popupInternalPaddingTop(RenderStyle*) const { return 0; }
185 virtual int popupInternalPaddingBottom(RenderStyle*) const { return 0; }
186 virtual bool popupOptionSupportsTextIndent() const { return false; }
188 virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return RegularScrollbar; }
190 // Method for painting the caps lock indicator
191 virtual bool paintCapsLockIndicator(RenderObject*, const PaintInfo&, const IntRect&) { return 0; };
193 #if ENABLE(PROGRESS_ELEMENT)
194 // Returns the repeat interval of the animation for the progress bar.
195 virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
196 // Returns the duration of the animation for the progress bar.
197 virtual double animationDurationForProgressBar(RenderProgress*) const;
202 virtual bool supportsClosedCaptioning() const { return false; }
203 virtual bool hasOwnDisabledStateHandlingFor(ControlPart) const { return false; }
204 virtual bool usesMediaControlStatusDisplay() { return false; }
205 virtual bool usesMediaControlVolumeSlider() const { return true; }
206 virtual bool usesVerticalVolumeSlider() const { return true; }
207 virtual double mediaControlsFadeInDuration() { return 0.1; }
208 virtual double mediaControlsFadeOutDuration() { return 0.3; }
209 virtual String formatMediaControlsTime(float time) const;
210 virtual String formatMediaControlsCurrentTime(float currentTime, float duration) const;
211 virtual String formatMediaControlsRemainingTime(float currentTime, float duration) const;
213 // Returns the media volume slider container's offset from the mute button.
214 virtual IntPoint volumeSliderOffsetFromMuteButton(RenderBox*, const IntSize&) const;
217 #if ENABLE(METER_ELEMENT)
218 virtual IntSize meterSizeForBounds(const RenderMeter*, const IntRect&) const;
219 virtual bool supportsMeter(ControlPart) const;
222 #if ENABLE(DATALIST_ELEMENT)
223 // Returns size of one slider tick mark for a horizontal track.
224 // For vertical tracks we rotate it and use it. i.e. Width is always length along the track.
225 virtual IntSize sliderTickSize() const = 0;
226 // Returns the distance of slider tick origin from the slider track center.
227 virtual int sliderTickOffsetFromTrackCenter() const = 0;
228 void paintSliderTicks(RenderObject*, const PaintInfo&, const IntRect&);
231 virtual bool shouldShowPlaceholderWhenFocused() const { return false; }
232 virtual bool shouldHaveSpinButton(HTMLInputElement*) const;
234 // Functions for <select> elements.
235 virtual bool delegatesMenuListRendering() const { return false; }
236 virtual bool popsMenuByArrowKeys() const { return false; }
237 virtual bool popsMenuBySpaceOrReturn() const { return false; }
239 virtual String fileListDefaultLabel(bool multipleFilesAllowed) const;
240 virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const;
243 // The platform selection color.
244 virtual Color platformActiveSelectionBackgroundColor() const;
245 virtual Color platformInactiveSelectionBackgroundColor() const;
246 virtual Color platformActiveSelectionForegroundColor() const;
247 virtual Color platformInactiveSelectionForegroundColor() const;
249 virtual Color platformActiveListBoxSelectionBackgroundColor() const;
250 virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
251 virtual Color platformActiveListBoxSelectionForegroundColor() const;
252 virtual Color platformInactiveListBoxSelectionForegroundColor() const;
254 virtual bool supportsSelectionForegroundColors() const { return true; }
255 virtual bool supportsListBoxSelectionForegroundColors() const { return true; }
258 // Methods for each appearance value.
259 virtual void adjustCheckboxStyle(StyleResolver*, RenderStyle*, Element*) const;
260 virtual bool paintCheckbox(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
261 virtual void setCheckboxSize(RenderStyle*) const { }
263 virtual void adjustRadioStyle(StyleResolver*, RenderStyle*, Element*) const;
264 virtual bool paintRadio(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
265 virtual void setRadioSize(RenderStyle*) const { }
267 virtual void adjustButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
268 virtual bool paintButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
269 virtual void setButtonSize(RenderStyle*) const { }
271 virtual void adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
272 virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
275 virtual void adjustTextFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
276 virtual bool paintTextField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
278 virtual void adjustTextAreaStyle(StyleResolver*, RenderStyle*, Element*) const;
279 virtual bool paintTextArea(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
281 virtual void adjustMenuListStyle(StyleResolver*, RenderStyle*, Element*) const;
282 virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
284 virtual void adjustMenuListButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
285 virtual bool paintMenuListButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
287 #if ENABLE(METER_ELEMENT)
288 virtual void adjustMeterStyle(StyleResolver*, RenderStyle*, Element*) const;
289 virtual bool paintMeter(RenderObject*, const PaintInfo&, const IntRect&);
292 #if ENABLE(PROGRESS_ELEMENT)
293 virtual void adjustProgressBarStyle(StyleResolver*, RenderStyle*, Element*) const;
294 virtual bool paintProgressBar(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
297 #if ENABLE(INPUT_SPEECH)
298 virtual void adjustInputFieldSpeechButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
299 virtual bool paintInputFieldSpeechButton(RenderObject*, const PaintInfo&, const IntRect&);
302 virtual void adjustSliderTrackStyle(StyleResolver*, RenderStyle*, Element*) const;
303 virtual bool paintSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
305 virtual void adjustSliderThumbStyle(StyleResolver*, RenderStyle*, Element*) const;
306 virtual bool paintSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
308 virtual void adjustSearchFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
309 virtual bool paintSearchField(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
311 virtual void adjustSearchFieldCancelButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
312 virtual bool paintSearchFieldCancelButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
314 virtual void adjustSearchFieldDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
315 virtual bool paintSearchFieldDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
317 virtual void adjustSearchFieldResultsDecorationStyle(StyleResolver*, RenderStyle*, Element*) const;
318 virtual bool paintSearchFieldResultsDecoration(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
320 virtual void adjustSearchFieldResultsButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
321 virtual bool paintSearchFieldResultsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
323 virtual void adjustMediaControlStyle(StyleResolver*, RenderStyle*, Element*) const;
324 virtual bool paintMediaFullscreenButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
325 virtual bool paintMediaPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
326 virtual bool paintMediaOverlayPlayButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
327 virtual bool paintMediaMuteButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
328 virtual bool paintMediaSeekBackButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
329 virtual bool paintMediaSeekForwardButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
330 virtual bool paintMediaSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
331 virtual bool paintMediaSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
332 virtual bool paintMediaVolumeSliderContainer(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
333 virtual bool paintMediaVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
334 virtual bool paintMediaVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
335 virtual bool paintMediaRewindButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
336 virtual bool paintMediaReturnToRealtimeButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
337 virtual bool paintMediaToggleClosedCaptionsButton(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
338 virtual bool paintMediaControlsBackground(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
339 virtual bool paintMediaCurrentTime(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
340 virtual bool paintMediaTimeRemaining(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
341 virtual bool paintMediaFullScreenVolumeSliderTrack(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
342 virtual bool paintMediaFullScreenVolumeSliderThumb(RenderObject*, const PaintInfo&, const IntRect&) { return true; }
345 // Methods for state querying
346 ControlStates controlStatesForRenderer(const RenderObject* o) const;
347 bool isActive(const RenderObject*) const;
348 bool isChecked(const RenderObject*) const;
349 bool isIndeterminate(const RenderObject*) const;
350 bool isEnabled(const RenderObject*) const;
351 bool isFocused(const RenderObject*) const;
352 bool isPressed(const RenderObject*) const;
353 bool isSpinUpButtonPartPressed(const RenderObject*) const;
354 bool isHovered(const RenderObject*) const;
355 bool isSpinUpButtonPartHovered(const RenderObject*) const;
356 bool isReadOnlyControl(const RenderObject*) const;
357 bool isDefault(const RenderObject*) const;
360 mutable Color m_activeSelectionBackgroundColor;
361 mutable Color m_inactiveSelectionBackgroundColor;
362 mutable Color m_activeSelectionForegroundColor;
363 mutable Color m_inactiveSelectionForegroundColor;
365 mutable Color m_activeListBoxSelectionBackgroundColor;
366 mutable Color m_inactiveListBoxSelectionBackgroundColor;
367 mutable Color m_activeListBoxSelectionForegroundColor;
368 mutable Color m_inactiveListBoxSelectionForegroundColor;
370 #if ENABLE(TOUCH_EVENTS)
371 static const RGBA32 defaultTapHighlightColor = 0x33000000;
375 Theme* m_theme; // The platform-specific theme.
379 } // namespace WebCore
381 #endif // RenderTheme_h