]> git.saurik.com Git - iphone-api.git/blob - WebCore/RenderTheme.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / RenderTheme.h
1 /*
2 * This file is part of the theme implementation for form controls in WebCore.
3 *
4 * Copyright (C) 2005, 2006, 2007, 2008 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 #include "RenderObject.h"
27 #if USE(NEW_THEME)
28 #include "Theme.h"
29 #else
30 #include "ThemeTypes.h"
31 #endif
32
33 namespace WebCore {
34
35 class Element;
36 class PopupMenu;
37 class RenderMenuList;
38 class CSSStyleSheet;
39
40 class RenderTheme {
41 public:
42 RenderTheme();
43 virtual ~RenderTheme() { }
44
45 // This method is called whenever style has been computed for an element and the appearance
46 // property has been set to a value other than "none". The theme should map in all of the appropriate
47 // metrics and defaults given the contents of the style. This includes sophisticated operations like
48 // selection of control size based off the font, the disabling of appearance when certain other properties like
49 // "border" are set, or if the appearance is not supported by the theme.
50 void adjustStyle(CSSStyleSelector*, RenderStyle*, Element*, bool UAHasAppearance,
51 const BorderData&, const FillLayer&, const Color& backgroundColor);
52
53 // This method is called to paint the widget as a background of the RenderObject. A widget's foreground, e.g., the
54 // text of a button, is always rendered by the engine itself. The boolean return value indicates
55 // whether the CSS border/background should also be painted.
56 bool paint(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
57 bool paintBorderOnly(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
58 bool paintDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
59
60 // The remaining methods should be implemented by the platform-specific portion of the theme, e.g.,
61 // RenderThemeMac.cpp for Mac OS X.
62
63 // These methods return the theme's extra style sheets rules, to let each platform
64 // adjust the default CSS rules in html4.css, quirks.css, or mediaControls.css
65 virtual String extraDefaultStyleSheet() { return String(); }
66 virtual String extraQuirksStyleSheet() { return String(); }
67 #if ENABLE(VIDEO)
68 virtual String extraMediaControlsStyleSheet() { return String(); };
69 #endif
70
71 // A method to obtain the baseline position for a "leaf" control. This will only be used if a baseline
72 // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
73 // controls that need to do this.
74 virtual int baselinePosition(const RenderObject*) const;
75
76 // A method for asking if a control is a container or not. Leaf controls have to have some special behavior (like
77 // the baseline position API above).
78 bool isControlContainer(ControlPart) const;
79
80 // A method asking if the control changes its tint when the window has focus or not.
81 virtual bool controlSupportsTints(const RenderObject*) const { return false; }
82
83 // Whether or not the control has been styled enough by the author to disable the native appearance.
84 virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
85
86 // A general method asking if any control tinting is supported at all.
87 virtual bool supportsControlTints() const { return false; }
88
89 // Some controls may spill out of their containers (e.g., the check on an OS X checkbox). When these controls repaint,
90 // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
91 virtual void adjustRepaintRect(const RenderObject*, IntRect&);
92
93 // This method is called whenever a relevant state changes on a particular themed object, e.g., the mouse becomes pressed
94 // or a control becomes disabled.
95 virtual bool stateChanged(RenderObject*, ControlState) const;
96
97 // This method is called whenever the theme changes on the system in order to flush cached resources from the
98 // old theme.
99 virtual void themeChanged() { }
100
101 // A method asking if the theme is able to draw the focus ring.
102 virtual bool supportsFocusRing(const RenderStyle*) const;
103
104 // A method asking if the theme's controls actually care about redrawing when hovered.
105 virtual bool supportsHover(const RenderStyle*) const { return false; }
106
107 // Text selection colors.
108 Color activeSelectionBackgroundColor() const;
109 Color inactiveSelectionBackgroundColor() const;
110 Color activeSelectionForegroundColor() const;
111 Color inactiveSelectionForegroundColor() const;
112
113 // List box selection colors
114 Color activeListBoxSelectionBackgroundColor() const;
115 Color activeListBoxSelectionForegroundColor() const;
116 Color inactiveListBoxSelectionBackgroundColor() const;
117 Color inactiveListBoxSelectionForegroundColor() const;
118
119 virtual Color platformTextSearchHighlightColor() const;
120
121 virtual void platformColorsDidChange();
122
123 virtual double caretBlinkInterval() const { return 0.5; }
124
125 // System fonts and colors for CSS.
126 virtual Color systemColor(int cssValueId) const;
127
128 virtual int minimumMenuListSize(RenderStyle*) const { return 0; }
129
130 virtual void adjustButtonInnerStyle(RenderStyle*) const;
131 virtual void adjustSliderThumbSize(RenderObject*) const;
132
133 virtual int popupInternalPaddingLeft(RenderStyle*) const { return 0; }
134 virtual int popupInternalPaddingRight(RenderStyle*) const { return 0; }
135 virtual int popupInternalPaddingTop(RenderStyle*) const { return 0; }
136 virtual int popupInternalPaddingBottom(RenderStyle*) const { return 0; }
137
138 // Method for painting the caps lock indicator
139 virtual bool paintCapsLockIndicator(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return 0; };
140
141 virtual bool paintCheckboxDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
142 virtual bool paintRadioDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
143 virtual bool paintButtonDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
144 virtual bool paintPushButtonDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
145 virtual bool paintSquareButtonDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
146 virtual bool paintTextFieldDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
147 virtual bool paintTextAreaDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
148 virtual bool paintMenuListDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
149 virtual bool paintMenuListButtonDecorations(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
150
151 #if ENABLE(VIDEO)
152 // Media controls
153 virtual bool hitTestMediaControlPart(RenderObject*, const IntPoint& absPoint);
154 #endif
155
156 protected:
157 // The platform selection color.
158 virtual Color platformActiveSelectionBackgroundColor() const;
159 virtual Color platformInactiveSelectionBackgroundColor() const;
160 virtual Color platformActiveSelectionForegroundColor() const;
161 virtual Color platformInactiveSelectionForegroundColor() const;
162
163 virtual Color platformActiveListBoxSelectionBackgroundColor() const;
164 virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
165 virtual Color platformActiveListBoxSelectionForegroundColor() const;
166 virtual Color platformInactiveListBoxSelectionForegroundColor() const;
167
168 virtual bool supportsSelectionForegroundColors() const { return true; }
169 virtual bool supportsListBoxSelectionForegroundColors() const { return true; }
170
171 #if !USE(NEW_THEME)
172 // Methods for each appearance value.
173 virtual void adjustCheckboxStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
174 virtual bool paintCheckbox(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
175 virtual void setCheckboxSize(RenderStyle*) const { }
176
177 virtual void adjustRadioStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
178 virtual bool paintRadio(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
179 virtual void setRadioSize(RenderStyle*) const { }
180
181 virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
182 virtual bool paintButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
183 virtual void setButtonSize(RenderStyle*) const { }
184 #endif
185
186 virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
187 virtual bool paintTextField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
188
189 virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
190 virtual bool paintTextArea(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
191
192 virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
193 virtual bool paintMenuList(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
194
195 virtual void adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
196 virtual bool paintMenuListButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
197
198 virtual void adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
199 virtual bool paintSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
200
201 virtual void adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
202 virtual bool paintSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
203
204 virtual void adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
205 virtual bool paintSearchField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
206
207 virtual void adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
208 virtual bool paintSearchFieldCancelButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
209
210 virtual void adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
211 virtual bool paintSearchFieldDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
212
213 virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
214 virtual bool paintSearchFieldResultsDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
215
216 virtual void adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
217 virtual bool paintSearchFieldResultsButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
218
219 virtual bool paintMediaFullscreenButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
220 virtual bool paintMediaPlayButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
221 virtual bool paintMediaMuteButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
222 virtual bool paintMediaSeekBackButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
223 virtual bool paintMediaSeekForwardButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
224 virtual bool paintMediaSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
225 virtual bool paintMediaSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
226 virtual bool paintMediaTimelineContainer(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
227 virtual bool paintMediaCurrentTime(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
228 virtual bool paintMediaTimeRemaining(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { return true; }
229
230 public:
231 // Methods for state querying
232 ControlStates controlStatesForRenderer(const RenderObject* o) const;
233 bool isActive(const RenderObject*) const;
234 bool isChecked(const RenderObject*) const;
235 bool isIndeterminate(const RenderObject*) const;
236 bool isEnabled(const RenderObject*) const;
237 bool isFocused(const RenderObject*) const;
238 bool isPressed(const RenderObject*) const;
239 bool isHovered(const RenderObject*) const;
240 bool isReadOnlyControl(const RenderObject*) const;
241 bool isDefault(const RenderObject*) const;
242
243 private:
244 mutable Color m_activeSelectionBackgroundColor;
245 mutable Color m_inactiveSelectionBackgroundColor;
246 mutable Color m_activeSelectionForegroundColor;
247 mutable Color m_inactiveSelectionForegroundColor;
248
249 mutable Color m_activeListBoxSelectionBackgroundColor;
250 mutable Color m_inactiveListBoxSelectionBackgroundColor;
251 mutable Color m_activeListBoxSelectionForegroundColor;
252 mutable Color m_inactiveListBoxSelectionForegroundColor;
253
254 #if USE(NEW_THEME)
255 Theme* m_theme; // The platform-specific theme.
256 #endif
257 };
258
259 // Function to obtain the theme. This is implemented in your platform-specific theme implementation to hand
260 // back the appropriate platform theme.
261 RenderTheme* theme();
262
263 } // namespace WebCore
264
265 #endif // RenderTheme_h