2 * Copyright (C) 2007 Apple Inc.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4 * Copyright (C) 2008 Collabora Ltd.
5 * Copyright (C) 2008, 2009 Google Inc.
6 * Copyright (C) 2009 Kenneth Rohde Christiansen
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
26 #include "RenderThemeChromiumLinux.h"
28 #include "CSSValueKeywords.h"
30 #include "PaintInfo.h"
31 #include "PlatformSupport.h"
32 #include "RenderObject.h"
33 #include "RenderProgress.h"
34 #include "RenderSlider.h"
35 #include "ScrollbarTheme.h"
36 #include "UserAgentStyleSheets.h"
40 unsigned RenderThemeChromiumLinux::m_activeSelectionBackgroundColor =
42 unsigned RenderThemeChromiumLinux::m_activeSelectionForegroundColor =
44 unsigned RenderThemeChromiumLinux::m_inactiveSelectionBackgroundColor =
46 unsigned RenderThemeChromiumLinux::m_inactiveSelectionForegroundColor =
49 double RenderThemeChromiumLinux::m_caretBlinkInterval;
51 static const unsigned defaultButtonBackgroundColor = 0xffdddddd;
53 static PlatformSupport::ThemePaintState getWebThemeState(const RenderTheme* theme, const RenderObject* o)
55 if (!theme->isEnabled(o))
56 return PlatformSupport::StateDisabled;
57 if (theme->isPressed(o))
58 return PlatformSupport::StatePressed;
59 if (theme->isHovered(o))
60 return PlatformSupport::StateHover;
62 return PlatformSupport::StateNormal;
66 PassRefPtr<RenderTheme> RenderThemeChromiumLinux::create()
68 return adoptRef(new RenderThemeChromiumLinux());
71 // RenderTheme::themeForPage for Android is defined in RenderThemeChromiumAndroid.cpp.
73 PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page* page)
75 static RenderTheme* rt = RenderThemeChromiumLinux::create().leakRef();
80 RenderThemeChromiumLinux::RenderThemeChromiumLinux()
82 m_caretBlinkInterval = RenderTheme::caretBlinkInterval();
85 RenderThemeChromiumLinux::~RenderThemeChromiumLinux()
89 Color RenderThemeChromiumLinux::systemColor(int cssValueId) const
91 static const Color linuxButtonGrayColor(0xffdddddd);
93 if (cssValueId == CSSValueButtonface)
94 return linuxButtonGrayColor;
95 return RenderTheme::systemColor(cssValueId);
98 String RenderThemeChromiumLinux::extraDefaultStyleSheet()
100 return RenderThemeChromiumSkia::extraDefaultStyleSheet() +
101 String(themeChromiumLinuxUserAgentStyleSheet, sizeof(themeChromiumLinuxUserAgentStyleSheet));
104 bool RenderThemeChromiumLinux::controlSupportsTints(const RenderObject* o) const
109 Color RenderThemeChromiumLinux::activeListBoxSelectionBackgroundColor() const
111 return Color(0x28, 0x28, 0x28);
114 Color RenderThemeChromiumLinux::activeListBoxSelectionForegroundColor() const
119 Color RenderThemeChromiumLinux::inactiveListBoxSelectionBackgroundColor() const
121 return Color(0xc8, 0xc8, 0xc8);
124 Color RenderThemeChromiumLinux::inactiveListBoxSelectionForegroundColor() const
126 return Color(0x32, 0x32, 0x32);
129 Color RenderThemeChromiumLinux::platformActiveSelectionBackgroundColor() const
131 return m_activeSelectionBackgroundColor;
134 Color RenderThemeChromiumLinux::platformInactiveSelectionBackgroundColor() const
136 return m_inactiveSelectionBackgroundColor;
139 Color RenderThemeChromiumLinux::platformActiveSelectionForegroundColor() const
141 return m_activeSelectionForegroundColor;
144 Color RenderThemeChromiumLinux::platformInactiveSelectionForegroundColor() const
146 return m_inactiveSelectionForegroundColor;
149 #if ENABLE(DATALIST_ELEMENT)
150 IntSize RenderThemeChromiumLinux::sliderTickSize() const
152 return IntSize(1, 6);
155 int RenderThemeChromiumLinux::sliderTickOffsetFromTrackCenter() const
161 void RenderThemeChromiumLinux::adjustSliderThumbSize(RenderStyle* style, Element* element) const
163 IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartSliderThumb);
165 if (style->appearance() == SliderThumbHorizontalPart) {
166 style->setWidth(Length(size.width(), Fixed));
167 style->setHeight(Length(size.height(), Fixed));
168 } else if (style->appearance() == SliderThumbVerticalPart) {
169 style->setWidth(Length(size.height(), Fixed));
170 style->setHeight(Length(size.width(), Fixed));
172 RenderThemeChromiumSkia::adjustSliderThumbSize(style, element);
175 bool RenderThemeChromiumLinux::supportsControlTints() const
180 void RenderThemeChromiumLinux::setCaretBlinkInterval(double interval)
182 m_caretBlinkInterval = interval;
185 double RenderThemeChromiumLinux::caretBlinkIntervalInternal() const
187 return m_caretBlinkInterval;
190 void RenderThemeChromiumLinux::setSelectionColors(
191 unsigned activeBackgroundColor,
192 unsigned activeForegroundColor,
193 unsigned inactiveBackgroundColor,
194 unsigned inactiveForegroundColor)
196 m_activeSelectionBackgroundColor = activeBackgroundColor;
197 m_activeSelectionForegroundColor = activeForegroundColor;
198 m_inactiveSelectionBackgroundColor = inactiveBackgroundColor;
199 m_inactiveSelectionForegroundColor = inactiveForegroundColor;
202 bool RenderThemeChromiumLinux::paintCheckbox(RenderObject* o, const PaintInfo& i, const IntRect& rect)
204 PlatformSupport::ThemePaintExtraParams extraParams;
205 extraParams.button.checked = isChecked(o);
206 extraParams.button.indeterminate = isIndeterminate(o);
208 PlatformSupport::paintThemePart(i.context, PlatformSupport::PartCheckbox, getWebThemeState(this, o), rect, &extraParams);
212 void RenderThemeChromiumLinux::setCheckboxSize(RenderStyle* style) const
214 // If the width and height are both specified, then we have nothing to do.
215 if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
218 IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartCheckbox);
219 setSizeIfAuto(style, size);
222 bool RenderThemeChromiumLinux::paintRadio(RenderObject* o, const PaintInfo& i, const IntRect& rect)
224 PlatformSupport::ThemePaintExtraParams extraParams;
225 extraParams.button.checked = isChecked(o);
227 PlatformSupport::paintThemePart(i.context, PlatformSupport::PartRadio, getWebThemeState(this, o), rect, &extraParams);
231 void RenderThemeChromiumLinux::setRadioSize(RenderStyle* style) const
233 // If the width and height are both specified, then we have nothing to do.
234 if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
237 IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartRadio);
238 setSizeIfAuto(style, size);
241 bool RenderThemeChromiumLinux::paintButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
243 PlatformSupport::ThemePaintExtraParams extraParams;
244 extraParams.button.isDefault = isDefault(o);
245 extraParams.button.hasBorder = true;
246 extraParams.button.backgroundColor = defaultButtonBackgroundColor;
247 if (o->hasBackground())
248 extraParams.button.backgroundColor = o->style()->visitedDependentColor(CSSPropertyBackgroundColor).rgb();
250 PlatformSupport::paintThemePart(i.context, PlatformSupport::PartButton, getWebThemeState(this, o), rect, &extraParams);
254 bool RenderThemeChromiumLinux::paintTextField(RenderObject* o, const PaintInfo& i, const IntRect& rect)
256 // WebThemeEngine does not handle border rounded corner and background image
257 // so return true to draw CSS border and background.
258 if (o->style()->hasBorderRadius() || o->style()->hasBackgroundImage())
261 ControlPart part = o->style()->appearance();
263 PlatformSupport::ThemePaintExtraParams extraParams;
264 extraParams.textField.isTextArea = part == TextAreaPart;
265 extraParams.textField.isListbox = part == ListboxPart;
267 // Fallback to white if the specified color object is invalid.
268 Color backgroundColor(Color::white);
269 if (o->style()->visitedDependentColor(CSSPropertyBackgroundColor).isValid())
270 backgroundColor = o->style()->visitedDependentColor(CSSPropertyBackgroundColor);
271 extraParams.textField.backgroundColor = backgroundColor.rgb();
273 PlatformSupport::paintThemePart(i.context, PlatformSupport::PartTextField, getWebThemeState(this, o), rect, &extraParams);
277 bool RenderThemeChromiumLinux::paintMenuList(RenderObject* o, const PaintInfo& i, const IntRect& rect)
282 const int right = rect.x() + rect.width();
283 const int middle = rect.y() + rect.height() / 2;
285 PlatformSupport::ThemePaintExtraParams extraParams;
286 extraParams.menuList.arrowX = (o->style()->direction() == RTL) ? rect.x() + 7 : right - 13;
287 extraParams.menuList.arrowY = middle;
288 const RenderBox* box = toRenderBox(o);
289 // Match Chromium Win behaviour of showing all borders if any are shown.
290 extraParams.menuList.hasBorder = box->borderRight() || box->borderLeft() || box->borderTop() || box->borderBottom();
291 extraParams.menuList.hasBorderRadius = o->style()->hasBorderRadius();
292 // Fallback to transparent if the specified color object is invalid.
293 extraParams.menuList.backgroundColor = Color::transparent;
294 if (o->hasBackground())
295 extraParams.menuList.backgroundColor = o->style()->visitedDependentColor(CSSPropertyBackgroundColor).rgb();
297 PlatformSupport::paintThemePart(i.context, PlatformSupport::PartMenuList, getWebThemeState(this, o), rect, &extraParams);
301 bool RenderThemeChromiumLinux::paintSliderTrack(RenderObject* o, const PaintInfo& i, const IntRect& rect)
303 PlatformSupport::ThemePaintExtraParams extraParams;
304 extraParams.slider.vertical = o->style()->appearance() == SliderVerticalPart;
306 PlatformSupport::paintThemePart(i.context, PlatformSupport::PartSliderTrack, getWebThemeState(this, o), rect, &extraParams);
308 #if ENABLE(DATALIST_ELEMENT)
309 paintSliderTicks(o, i, rect);
315 bool RenderThemeChromiumLinux::paintSliderThumb(RenderObject* o, const PaintInfo& i, const IntRect& rect)
317 PlatformSupport::ThemePaintExtraParams extraParams;
318 extraParams.slider.vertical = o->style()->appearance() == SliderThumbVerticalPart;
319 extraParams.slider.inDrag = isPressed(o);
321 PlatformSupport::paintThemePart(i.context, PlatformSupport::PartSliderThumb, getWebThemeState(this, o), rect, &extraParams);
325 void RenderThemeChromiumLinux::adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle* style, Element*) const
327 IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartInnerSpinButton);
329 style->setWidth(Length(size.width(), Fixed));
330 style->setMinWidth(Length(size.width(), Fixed));
333 bool RenderThemeChromiumLinux::paintInnerSpinButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
335 PlatformSupport::ThemePaintExtraParams extraParams;
336 extraParams.innerSpin.spinUp = (controlStatesForRenderer(o) & SpinUpState);
337 extraParams.innerSpin.readOnly = isReadOnlyControl(o);
339 PlatformSupport::paintThemePart(i.context, PlatformSupport::PartInnerSpinButton, getWebThemeState(this, o), rect, &extraParams);
343 #if ENABLE(PROGRESS_ELEMENT)
345 bool RenderThemeChromiumLinux::paintProgressBar(RenderObject* o, const PaintInfo& i, const IntRect& rect)
347 if (!o->isProgress())
350 RenderProgress* renderProgress = toRenderProgress(o);
351 IntRect valueRect = progressValueRectFor(renderProgress, rect);
353 PlatformSupport::ThemePaintExtraParams extraParams;
354 extraParams.progressBar.determinate = renderProgress->isDeterminate();
355 extraParams.progressBar.valueRectX = valueRect.x();
356 extraParams.progressBar.valueRectY = valueRect.y();
357 extraParams.progressBar.valueRectWidth = valueRect.width();
358 extraParams.progressBar.valueRectHeight = valueRect.height();
360 DirectionFlippingScope scope(o, i, rect);
361 PlatformSupport::paintThemePart(i.context, PlatformSupport::PartProgressBar, getWebThemeState(this, o), rect, &extraParams);
367 } // namespace WebCore