2 * This file is part of the theme implementation for form controls in WebCore.
4 * Copyright (C) 2005 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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include "RenderTheme.h"
26 #include "GraphicsContext.h"
27 #include "HTMLInputElement.h"
28 #include "HTMLNames.h"
29 #include "render_style.h"
30 #include "RenderPopupMenu.h"
32 // The methods in this file are shared by all themes on every platform.
36 using namespace HTMLNames;
38 void RenderTheme::adjustStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e)
40 // Force inline and table display styles to be inline-block (except for table- which is block)
41 if (style->display() == INLINE || style->display() == INLINE_TABLE || style->display() == TABLE_ROW_GROUP ||
42 style->display() == TABLE_HEADER_GROUP || style->display() == TABLE_FOOTER_GROUP ||
43 style->display() == TABLE_ROW || style->display() == TABLE_COLUMN_GROUP || style->display() == TABLE_COLUMN ||
44 style->display() == TABLE_CELL || style->display() == TABLE_CAPTION)
45 style->setDisplay(INLINE_BLOCK);
46 else if (style->display() == COMPACT || style->display() == RUN_IN || style->display() == LIST_ITEM || style->display() == TABLE)
47 style->setDisplay(BLOCK);
49 // Call the appropriate style adjustment method based off the appearance value.
50 switch (style->appearance()) {
51 case CheckboxAppearance:
52 return adjustCheckboxStyle(selector, style, e);
54 return adjustRadioStyle(selector, style, e);
55 case PushButtonAppearance:
56 case SquareButtonAppearance:
57 case ButtonAppearance:
58 return adjustButtonStyle(selector, style, e);
59 case TextFieldAppearance:
60 return adjustTextFieldStyle(selector, style, e);
61 case TextAreaAppearance:
62 return adjustTextAreaStyle(selector, style, e);
63 case MenulistAppearance:
64 return adjustMenuListStyle(selector, style, e);
70 bool RenderTheme::paint(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
72 // If painting is disabled, but we aren't updating control tints, then just bail.
73 // If we are updating control tints, just schedule a repaint if the theme supports tinting
75 if (i.p->updatingControlTints()) {
76 if (controlSupportsTints(o))
80 if (i.p->paintingDisabled())
83 // Call the appropriate paint method based off the appearance value.
84 switch (o->style()->appearance()) {
85 case CheckboxAppearance:
86 return paintCheckbox(o, i, r);
88 return paintRadio(o, i, r);
89 case PushButtonAppearance:
90 case SquareButtonAppearance:
91 case ButtonAppearance:
92 return paintButton(o, i, r);
93 case MenulistAppearance:
94 return paintMenuList(o, i, r);
95 case TextFieldAppearance:
96 case TextAreaAppearance:
102 return true; // We don't support the appearance, so let the normal background/border paint.
105 bool RenderTheme::paintBorderOnly(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
107 if (i.p->paintingDisabled())
110 // Call the appropriate paint method based off the appearance value.
111 switch (o->style()->appearance()) {
112 case TextFieldAppearance:
113 return paintTextField(o, i, r);
114 case TextAreaAppearance:
115 return paintTextArea(o, i, r);
116 case CheckboxAppearance:
117 case RadioAppearance:
118 case PushButtonAppearance:
119 case SquareButtonAppearance:
120 case ButtonAppearance:
121 case MenulistAppearance:
129 Color RenderTheme::activeSelectionBackgroundColor() const
131 static Color activeSelectionColor;
132 if (!activeSelectionColor.isValid())
133 activeSelectionColor = platformActiveSelectionBackgroundColor().blendWithWhite();
134 return activeSelectionColor;
137 Color RenderTheme::inactiveSelectionBackgroundColor() const
139 static Color inactiveSelectionColor;
140 if (!inactiveSelectionColor.isValid())
141 inactiveSelectionColor = platformInactiveSelectionBackgroundColor().blendWithWhite();
142 return inactiveSelectionColor;
145 Color RenderTheme::platformActiveSelectionBackgroundColor() const
147 // Use a blue color by default if the platform theme doesn't define anything.
148 return Color(0, 0, 255);
151 Color RenderTheme::platformInactiveSelectionBackgroundColor() const
153 // Use a grey color by default if the platform theme doesn't define anything.
154 return Color(128, 128, 128);
157 Color RenderTheme::platformActiveSelectionForegroundColor() const
162 Color RenderTheme::platformInactiveSelectionForegroundColor() const
167 short RenderTheme::baselinePosition(const RenderObject* o) const
169 return o->height() + o->marginTop();
172 bool RenderTheme::isControlContainer(EAppearance appearance) const
174 // There are more leaves than this, but we'll patch this function as we add support for
176 return appearance != CheckboxAppearance && appearance != RadioAppearance;
179 bool RenderTheme::isControlStyled(const RenderStyle* style, const BorderData& border, const BackgroundLayer& background,
180 const Color& backgroundColor) const
182 switch (style->appearance()) {
183 case PushButtonAppearance:
184 case SquareButtonAppearance:
185 case ButtonAppearance:
186 case MenulistAppearance:
187 case TextFieldAppearance:
188 case TextAreaAppearance: {
189 // Test the style to see if the UA border and background match.
190 return (style->border() != border ||
191 *style->backgroundLayers() != background ||
192 style->backgroundColor() != backgroundColor);
201 bool RenderTheme::supportsFocusRing(const RenderStyle* style) const
203 return (style->hasAppearance() && style->appearance() != TextFieldAppearance && style->appearance() != TextAreaAppearance);
206 bool RenderTheme::stateChanged(RenderObject* o, ControlState state) const
208 // Default implementation assumes the controls dont respond to changes in :hover state
209 if (state == HoverState && !supportsHover(o->style()))
212 // Assume pressed state is only responded to if the control is enabled.
213 if (state == PressedState && !isEnabled(o))
216 // Repaint the control.
221 bool RenderTheme::isChecked(const RenderObject* o) const
225 return o->element()->isChecked();
228 bool RenderTheme::isIndeterminate(const RenderObject* o) const
232 return o->element()->isIndeterminate();
235 bool RenderTheme::isEnabled(const RenderObject* o) const
239 return o->element()->isEnabled();
242 bool RenderTheme::isFocused(const RenderObject* o) const
246 return o->element() == o->element()->document()->focusNode();
249 bool RenderTheme::isPressed(const RenderObject* o) const
253 return o->element()->active();
256 bool RenderTheme::isReadOnlyControl(const RenderObject* o) const
260 return o->element()->isReadOnlyControl();
263 bool RenderTheme::isHovered(const RenderObject* o) const
267 return o->element()->hovered();
270 void RenderTheme::adjustCheckboxStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
272 // A summary of the rules for checkbox designed to match WinIE:
273 // width/height - honored (WinIE actually scales its control for small widths, but lets it overflow for small heights.)
274 // font-size - not honored (control has no text), but we use it to decide which control size to use.
275 setCheckboxSize(style);
277 // padding - not honored by WinIE, needs to be removed.
278 style->resetPadding();
280 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
281 // for now, we will not honor it.
282 style->resetBorder();
285 void RenderTheme::adjustRadioStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
287 // A summary of the rules for checkbox designed to match WinIE:
288 // width/height - honored (WinIE actually scales its control for small widths, but lets it overflow for small heights.)
289 // font-size - not honored (control has no text), but we use it to decide which control size to use.
292 // padding - not honored by WinIE, needs to be removed.
293 style->resetPadding();
295 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
296 // for now, we will not honor it.
297 style->resetBorder();
300 void RenderTheme::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
302 // Most platforms will completely honor all CSS, and so we have no need to adjust the style
303 // at all by default. We will still allow the theme a crack at setting up a desired vertical size.
304 setButtonSize(style);
307 void RenderTheme::adjustTextFieldStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
311 void RenderTheme::adjustTextAreaStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
315 void RenderTheme::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const