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 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.
26 #include "ControlStates.h"
30 #include "ThemeTypes.h"
32 #include "PopupMenuStyle.h"
33 #include "RenderObject.h"
34 #include "ScrollTypes.h"
35 #include <wtf/PassRefPtr.h>
36 #include <wtf/RefCounted.h>
43 class HTMLInputElement;
47 #if ENABLE(METER_ELEMENT)
51 class RenderSnapshottedPlugIn;
53 class RenderTheme : public RefCounted<RenderTheme> {
58 virtual ~RenderTheme() { }
60 // This function is to be implemented in your platform-specific theme implementation to hand back the
61 // appropriate platform theme. When the theme is needed in non-page dependent code, a default theme is
62 // used as fallback, which is returned for a nulled page, so the platform code needs to account for this.
63 static PassRefPtr<RenderTheme> themeForPage(Page* page);
65 // When the theme is needed in non-page dependent code, the defaultTheme() is used as fallback.
66 static inline PassRefPtr<RenderTheme> defaultTheme()
68 return themeForPage(0);
71 // This method is called whenever style has been computed for an element and the appearance
72 // property has been set to a value other than "none". The theme should map in all of the appropriate
73 // metrics and defaults given the contents of the style. This includes sophisticated operations like
74 // selection of control size based off the font, the disabling of appearance when certain other properties like
75 // "border" are set, or if the appearance is not supported by the theme.
76 void adjustStyle(StyleResolver&, RenderStyle&, Element*, bool UAHasAppearance, const BorderData&, const FillLayer&, const Color& backgroundColor);
78 // This method is called to paint the widget as a background of the RenderObject. A widget's foreground, e.g., the
79 // text of a button, is always rendered by the engine itself. The boolean return value indicates
80 // whether the CSS border/background should also be painted.
81 bool paint(const RenderObject&, ControlStates*, const PaintInfo&, const LayoutRect&);
82 bool paintBorderOnly(const RenderObject&, const PaintInfo&, const LayoutRect&);
83 bool paintDecorations(const RenderObject&, const PaintInfo&, const LayoutRect&);
85 // The remaining methods should be implemented by the platform-specific portion of the theme, e.g.,
86 // RenderThemeMac.cpp for Mac OS X.
88 // These methods return the theme's extra style sheets rules, to let each platform
89 // adjust the default CSS rules in html.css, quirks.css, mediaControls.css, or plugIns.css
90 virtual String extraDefaultStyleSheet() { return String(); }
91 virtual String extraQuirksStyleSheet() { return String(); }
92 virtual String extraPlugInsStyleSheet() { return String(); }
94 virtual String mediaControlsStyleSheet() { return String(); }
95 virtual String extraMediaControlsStyleSheet() { return String(); }
96 virtual String mediaControlsScript() { return String(); }
98 #if ENABLE(FULLSCREEN_API)
99 virtual String extraFullScreenStyleSheet() { return String(); }
101 #if ENABLE(SERVICE_CONTROLS)
102 virtual String imageControlsStyleSheet() const { return String(); }
105 // A method to obtain the baseline position for a "leaf" control. This will only be used if a baseline
106 // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
107 // controls that need to do this.
108 virtual int baselinePosition(const RenderObject&) const;
110 // A method for asking if a control is a container or not. Leaf controls have to have some special behavior (like
111 // the baseline position API above).
112 bool isControlContainer(ControlPart) const;
114 // A method asking if the control changes its tint when the window has focus or not.
115 virtual bool controlSupportsTints(const RenderObject&) const { return false; }
117 // Whether or not the control has been styled enough by the author to disable the native appearance.
118 virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
120 // A general method asking if any control tinting is supported at all.
121 virtual bool supportsControlTints() const { return false; }
123 // Some controls may spill out of their containers (e.g., the check on an OS X checkbox). When these controls repaint,
124 // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
125 virtual void adjustRepaintRect(const RenderObject&, FloatRect&);
127 // This method is called whenever a relevant state changes on a particular themed object, e.g., the mouse becomes pressed
128 // or a control becomes disabled.
129 virtual bool stateChanged(const RenderObject&, ControlStates::States) const;
131 // This method is called whenever the theme changes on the system in order to flush cached resources from the
133 virtual void themeChanged() { }
135 // A method asking if the theme is able to draw the focus ring.
136 virtual bool supportsFocusRing(const RenderStyle*) const;
138 // A method asking if the theme's controls actually care about redrawing when hovered.
139 virtual bool supportsHover(const RenderStyle*) const { return false; }
141 // A method asking if the platform is able to show datalist suggestions for a given input type.
142 virtual bool supportsDataListUI(const AtomicString&) const { return false; }
144 // Text selection colors.
145 Color activeSelectionBackgroundColor() const;
146 Color inactiveSelectionBackgroundColor() const;
147 Color activeSelectionForegroundColor() const;
148 Color inactiveSelectionForegroundColor() const;
150 // List box selection colors
151 Color activeListBoxSelectionBackgroundColor() const;
152 Color activeListBoxSelectionForegroundColor() const;
153 Color inactiveListBoxSelectionBackgroundColor() const;
154 Color inactiveListBoxSelectionForegroundColor() const;
156 // Highlighting colors for TextMatches.
157 virtual Color platformActiveTextSearchHighlightColor() const;
158 virtual Color platformInactiveTextSearchHighlightColor() const;
160 virtual Color disabledTextColor(const Color& textColor, const Color& backgroundColor) const;
162 static Color focusRingColor();
163 virtual Color platformFocusRingColor() const { return Color(0, 0, 0); }
164 static void setCustomFocusRingColor(const Color&);
165 virtual int platformFocusRingMaxWidth() const { return 3; }
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(CSSValueID, FontDescription&) const = 0;
176 virtual Color systemColor(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; }
187 virtual PopupMenuStyle::PopupMenuSize popupMenuSize(const RenderStyle*, IntRect&) const { return PopupMenuStyle::PopupMenuSizeNormal; }
189 virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) { return RegularScrollbar; }
191 // Method for painting the caps lock indicator
192 virtual bool paintCapsLockIndicator(const RenderObject&, const PaintInfo&, const IntRect&) { return 0; };
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;
198 virtual IntRect progressBarRectForBounds(const RenderObject&, const IntRect&) 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 the threshold distance for snapping to a slider tick mark.
224 virtual LayoutUnit sliderTickSnappingThreshold() const;
225 // Returns size of one slider tick mark for a horizontal track.
226 // For vertical tracks we rotate it and use it. i.e. Width is always length along the track.
227 virtual IntSize sliderTickSize() const = 0;
228 // Returns the distance of slider tick origin from the slider track center.
229 virtual int sliderTickOffsetFromTrackCenter() const = 0;
230 void paintSliderTicks(const RenderObject&, const PaintInfo&, const IntRect&);
233 virtual bool shouldShowPlaceholderWhenFocused() const { return false; }
234 virtual bool shouldHaveSpinButton(HTMLInputElement*) const;
236 // Functions for <select> elements.
237 virtual bool delegatesMenuListRendering() const { return false; }
238 virtual bool popsMenuByArrowKeys() const { return false; }
239 virtual bool popsMenuBySpaceOrReturn() const { return false; }
241 virtual String fileListDefaultLabel(bool multipleFilesAllowed) const;
242 virtual String fileListNameForWidth(const FileList*, const Font&, int width, bool multipleFilesAllowed) const;
244 enum FileUploadDecorations { SingleFile, MultipleFiles };
245 virtual bool paintFileUploadIconDecorations(const RenderObject& /*inputRenderer*/, const RenderObject& /*buttonRenderer*/, const PaintInfo&, const IntRect&, Icon*, FileUploadDecorations) { return true; }
247 #if ENABLE(SERVICE_CONTROLS)
248 virtual IntSize imageControlsButtonSize(const RenderObject&) const { return IntSize(); }
249 virtual IntSize imageControlsButtonPositionOffset() const { return IntSize(); }
253 // The platform selection color.
254 virtual Color platformActiveSelectionBackgroundColor() const;
255 virtual Color platformInactiveSelectionBackgroundColor() const;
256 virtual Color platformActiveSelectionForegroundColor() const;
257 virtual Color platformInactiveSelectionForegroundColor() const;
259 virtual Color platformActiveListBoxSelectionBackgroundColor() const;
260 virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
261 virtual Color platformActiveListBoxSelectionForegroundColor() const;
262 virtual Color platformInactiveListBoxSelectionForegroundColor() const;
264 virtual bool supportsSelectionForegroundColors() const { return true; }
265 virtual bool supportsListBoxSelectionForegroundColors() const { return true; }
268 // Methods for each appearance value.
269 virtual void adjustCheckboxStyle(StyleResolver*, RenderStyle*, Element*) const;
270 virtual bool paintCheckbox(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
271 virtual void setCheckboxSize(RenderStyle*) const { }
273 virtual void adjustRadioStyle(StyleResolver*, RenderStyle*, Element*) const;
274 virtual bool paintRadio(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
275 virtual void setRadioSize(RenderStyle*) const { }
277 virtual void adjustButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
278 virtual bool paintButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
279 virtual void setButtonSize(RenderStyle*) const { }
281 virtual void adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
282 virtual bool paintInnerSpinButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
285 virtual bool paintCheckboxDecorations(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
286 virtual bool paintRadioDecorations(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
287 virtual bool paintButtonDecorations(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
289 virtual void adjustTextFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
290 virtual bool paintTextField(const RenderObject&, const PaintInfo&, const FloatRect&) { return true; }
291 virtual bool paintTextFieldDecorations(const RenderObject&, const PaintInfo&, const FloatRect&) { return true; }
293 virtual void adjustTextAreaStyle(StyleResolver*, RenderStyle*, Element*) const;
294 virtual bool paintTextArea(const RenderObject&, const PaintInfo&, const FloatRect&) { return true; }
295 virtual bool paintTextAreaDecorations(const RenderObject&, const PaintInfo&, const FloatRect&) { return true; }
297 virtual void adjustMenuListStyle(StyleResolver*, RenderStyle*, Element*) const;
298 virtual bool paintMenuList(const RenderObject&, const PaintInfo&, const FloatRect&) { return true; }
299 virtual bool paintMenuListDecorations(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
301 virtual void adjustMenuListButtonStyle(StyleResolver&, RenderStyle&, Element&) const;
302 virtual bool paintMenuListButtonDecorations(const RenderObject&, const PaintInfo&, const FloatRect&) { return true; }
304 virtual bool paintPushButtonDecorations(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
305 virtual bool paintSquareButtonDecorations(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
307 #if ENABLE(METER_ELEMENT)
308 virtual void adjustMeterStyle(StyleResolver*, RenderStyle*, Element*) const;
309 virtual bool paintMeter(const RenderObject&, const PaintInfo&, const IntRect&);
312 virtual void adjustProgressBarStyle(StyleResolver*, RenderStyle*, Element*) const;
313 virtual bool paintProgressBar(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
315 #if ENABLE(INPUT_SPEECH)
316 virtual void adjustInputFieldSpeechButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
317 virtual bool paintInputFieldSpeechButton(const RenderObject&, const PaintInfo&, const IntRect&);
320 virtual void adjustSliderTrackStyle(StyleResolver*, RenderStyle*, Element*) const;
321 virtual bool paintSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
323 virtual void adjustSliderThumbStyle(StyleResolver*, RenderStyle*, Element*) const;
324 virtual bool paintSliderThumb(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
325 virtual bool paintSliderThumbDecorations(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
327 virtual void adjustSearchFieldStyle(StyleResolver*, RenderStyle*, Element*) const;
328 virtual bool paintSearchField(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
329 virtual bool paintSearchFieldDecorations(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
331 virtual void adjustSearchFieldCancelButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
332 virtual bool paintSearchFieldCancelButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
334 virtual void adjustSearchFieldDecorationPartStyle(StyleResolver*, RenderStyle*, Element*) const;
335 virtual bool paintSearchFieldDecorationPart(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
337 virtual void adjustSearchFieldResultsDecorationPartStyle(StyleResolver*, RenderStyle*, Element*) const;
338 virtual bool paintSearchFieldResultsDecorationPart(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
340 virtual void adjustSearchFieldResultsButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
341 virtual bool paintSearchFieldResultsButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
343 virtual void adjustMediaControlStyle(StyleResolver*, RenderStyle*, Element*) const;
344 virtual bool paintMediaFullscreenButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
345 virtual bool paintMediaPlayButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
346 virtual bool paintMediaOverlayPlayButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
347 virtual bool paintMediaMuteButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
348 virtual bool paintMediaSeekBackButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
349 virtual bool paintMediaSeekForwardButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
350 virtual bool paintMediaSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
351 virtual bool paintMediaSliderThumb(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
352 virtual bool paintMediaVolumeSliderContainer(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
353 virtual bool paintMediaVolumeSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
354 virtual bool paintMediaVolumeSliderThumb(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
355 virtual bool paintMediaRewindButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
356 virtual bool paintMediaReturnToRealtimeButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
357 virtual bool paintMediaToggleClosedCaptionsButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
358 virtual bool paintMediaControlsBackground(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
359 virtual bool paintMediaCurrentTime(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
360 virtual bool paintMediaTimeRemaining(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
361 virtual bool paintMediaFullScreenVolumeSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
362 virtual bool paintMediaFullScreenVolumeSliderThumb(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
364 virtual bool paintSnapshottedPluginOverlay(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
366 #if ENABLE(SERVICE_CONTROLS)
367 virtual bool paintImageControlsButton(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
371 void updateControlStatesForRenderer(const RenderObject&, ControlStates*) const;
372 ControlStates::States extractControlStatesForRenderer(const RenderObject&) const;
373 bool isActive(const RenderObject&) const;
374 bool isChecked(const RenderObject&) const;
375 bool isIndeterminate(const RenderObject&) const;
376 bool isEnabled(const RenderObject&) const;
377 bool isFocused(const RenderObject&) const;
378 bool isPressed(const RenderObject&) const;
379 bool isSpinUpButtonPartPressed(const RenderObject&) const;
380 bool isHovered(const RenderObject&) const;
381 bool isSpinUpButtonPartHovered(const RenderObject&) const;
382 bool isReadOnlyControl(const RenderObject&) const;
383 bool isDefault(const RenderObject&) const;
386 mutable Color m_activeSelectionBackgroundColor;
387 mutable Color m_inactiveSelectionBackgroundColor;
388 mutable Color m_activeSelectionForegroundColor;
389 mutable Color m_inactiveSelectionForegroundColor;
391 mutable Color m_activeListBoxSelectionBackgroundColor;
392 mutable Color m_inactiveListBoxSelectionBackgroundColor;
393 mutable Color m_activeListBoxSelectionForegroundColor;
394 mutable Color m_inactiveListBoxSelectionForegroundColor;
396 #if ENABLE(TOUCH_EVENTS)
397 // This color is expected to be drawn on a semi-transparent overlay,
398 // making it more transparent than its alpha value indicates.
399 static const RGBA32 defaultTapHighlightColor = 0x66000000;
403 Theme* m_theme; // The platform-specific theme.
407 } // namespace WebCore
409 #endif // RenderTheme_h