RenderThemeChromiumLinux.cpp revision ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb
1/*
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
7 *
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.
12 *
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.
17 *
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.
22 *
23 */
24
25#include "config.h"
26#include "RenderThemeChromiumLinux.h"
27
28#include "CSSValueKeywords.h"
29#include "Color.h"
30#include "PaintInfo.h"
31#include "PlatformBridge.h"
32#include "RenderObject.h"
33#include "RenderProgress.h"
34#include "RenderSlider.h"
35#include "ScrollbarTheme.h"
36#include "UserAgentStyleSheets.h"
37
38namespace WebCore {
39
40unsigned RenderThemeChromiumLinux::m_activeSelectionBackgroundColor =
41    0xff1e90ff;
42unsigned RenderThemeChromiumLinux::m_activeSelectionForegroundColor =
43    Color::black;
44unsigned RenderThemeChromiumLinux::m_inactiveSelectionBackgroundColor =
45    0xffc8c8c8;
46unsigned RenderThemeChromiumLinux::m_inactiveSelectionForegroundColor =
47    0xff323232;
48
49double RenderThemeChromiumLinux::m_caretBlinkInterval;
50
51static const unsigned defaultButtonBackgroundColor = 0xffdddddd;
52
53static PlatformBridge::ThemePaintState getWebThemeState(const RenderTheme* theme, const RenderObject* o)
54{
55    if (!theme->isEnabled(o))
56        return PlatformBridge::StateDisabled;
57    if (theme->isPressed(o))
58        return PlatformBridge::StatePressed;
59    if (theme->isHovered(o))
60        return PlatformBridge::StateHover;
61
62    return PlatformBridge::StateNormal;
63}
64
65
66PassRefPtr<RenderTheme> RenderThemeChromiumLinux::create()
67{
68    return adoptRef(new RenderThemeChromiumLinux());
69}
70
71PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page* page)
72{
73    static RenderTheme* rt = RenderThemeChromiumLinux::create().releaseRef();
74    return rt;
75}
76
77RenderThemeChromiumLinux::RenderThemeChromiumLinux()
78{
79    m_caretBlinkInterval = RenderTheme::caretBlinkInterval();
80}
81
82RenderThemeChromiumLinux::~RenderThemeChromiumLinux()
83{
84}
85
86Color RenderThemeChromiumLinux::systemColor(int cssValueId) const
87{
88    static const Color linuxButtonGrayColor(0xffdddddd);
89
90    if (cssValueId == CSSValueButtonface)
91        return linuxButtonGrayColor;
92    return RenderTheme::systemColor(cssValueId);
93}
94
95String RenderThemeChromiumLinux::extraDefaultStyleSheet()
96{
97    return RenderThemeChromiumSkia::extraDefaultStyleSheet() +
98           String(themeChromiumLinuxUserAgentStyleSheet, sizeof(themeChromiumLinuxUserAgentStyleSheet));
99}
100
101bool RenderThemeChromiumLinux::controlSupportsTints(const RenderObject* o) const
102{
103    return isEnabled(o);
104}
105
106Color RenderThemeChromiumLinux::activeListBoxSelectionBackgroundColor() const
107{
108    return Color(0x28, 0x28, 0x28);
109}
110
111Color RenderThemeChromiumLinux::activeListBoxSelectionForegroundColor() const
112{
113    return Color::black;
114}
115
116Color RenderThemeChromiumLinux::inactiveListBoxSelectionBackgroundColor() const
117{
118    return Color(0xc8, 0xc8, 0xc8);
119}
120
121Color RenderThemeChromiumLinux::inactiveListBoxSelectionForegroundColor() const
122{
123    return Color(0x32, 0x32, 0x32);
124}
125
126Color RenderThemeChromiumLinux::platformActiveSelectionBackgroundColor() const
127{
128    return m_activeSelectionBackgroundColor;
129}
130
131Color RenderThemeChromiumLinux::platformInactiveSelectionBackgroundColor() const
132{
133    return m_inactiveSelectionBackgroundColor;
134}
135
136Color RenderThemeChromiumLinux::platformActiveSelectionForegroundColor() const
137{
138    return m_activeSelectionForegroundColor;
139}
140
141Color RenderThemeChromiumLinux::platformInactiveSelectionForegroundColor() const
142{
143    return m_inactiveSelectionForegroundColor;
144}
145
146void RenderThemeChromiumLinux::adjustSliderThumbSize(RenderObject* o) const
147{
148    IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartSliderThumb);
149
150    if (o->style()->appearance() == SliderThumbHorizontalPart) {
151        o->style()->setWidth(Length(size.width(), Fixed));
152        o->style()->setHeight(Length(size.height(), Fixed));
153    } else if (o->style()->appearance() == SliderThumbVerticalPart) {
154        o->style()->setWidth(Length(size.height(), Fixed));
155        o->style()->setHeight(Length(size.width(), Fixed));
156    } else
157        RenderThemeChromiumSkia::adjustSliderThumbSize(o);
158}
159
160bool RenderThemeChromiumLinux::supportsControlTints() const
161{
162    return true;
163}
164
165void RenderThemeChromiumLinux::setCaretBlinkInterval(double interval)
166{
167    m_caretBlinkInterval = interval;
168}
169
170double RenderThemeChromiumLinux::caretBlinkIntervalInternal() const
171{
172    return m_caretBlinkInterval;
173}
174
175void RenderThemeChromiumLinux::setSelectionColors(
176    unsigned activeBackgroundColor,
177    unsigned activeForegroundColor,
178    unsigned inactiveBackgroundColor,
179    unsigned inactiveForegroundColor)
180{
181    m_activeSelectionBackgroundColor = activeBackgroundColor;
182    m_activeSelectionForegroundColor = activeForegroundColor;
183    m_inactiveSelectionBackgroundColor = inactiveBackgroundColor;
184    m_inactiveSelectionForegroundColor = inactiveForegroundColor;
185}
186
187bool RenderThemeChromiumLinux::paintCheckbox(RenderObject* o, const PaintInfo& i, const IntRect& rect)
188{
189    PlatformBridge::ThemePaintExtraParams extraParams;
190    extraParams.button.checked = isChecked(o);
191    extraParams.button.indeterminate = isIndeterminate(o);
192
193    PlatformBridge::paintThemePart(i.context, PlatformBridge::PartCheckbox, getWebThemeState(this, o), rect, &extraParams);
194    return false;
195}
196
197void RenderThemeChromiumLinux::setCheckboxSize(RenderStyle* style) const
198{
199    // If the width and height are both specified, then we have nothing to do.
200    if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
201        return;
202
203    IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartCheckbox);
204    setSizeIfAuto(style, size);
205}
206
207bool RenderThemeChromiumLinux::paintRadio(RenderObject* o, const PaintInfo& i, const IntRect& rect)
208{
209    PlatformBridge::ThemePaintExtraParams extraParams;
210    extraParams.button.checked = isChecked(o);
211
212    PlatformBridge::paintThemePart(i.context, PlatformBridge::PartRadio, getWebThemeState(this, o), rect, &extraParams);
213    return false;
214}
215
216void RenderThemeChromiumLinux::setRadioSize(RenderStyle* style) const
217{
218    // If the width and height are both specified, then we have nothing to do.
219    if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
220        return;
221
222    IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartRadio);
223    setSizeIfAuto(style, size);
224}
225
226bool RenderThemeChromiumLinux::paintButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
227{
228    PlatformBridge::ThemePaintExtraParams extraParams;
229    extraParams.button.isDefault = isDefault(o);
230    extraParams.button.backgroundColor = defaultButtonBackgroundColor;
231    if (o->hasBackground())
232        extraParams.button.backgroundColor = o->style()->visitedDependentColor(CSSPropertyBackgroundColor).rgb();
233
234    PlatformBridge::paintThemePart(i.context, PlatformBridge::PartButton, getWebThemeState(this, o), rect, &extraParams);
235    return false;
236}
237
238bool RenderThemeChromiumLinux::paintTextField(RenderObject* o, const PaintInfo& i, const IntRect& rect)
239{
240    // WebThemeEngine does not handle border rounded corner and background image
241    // so return true to draw CSS border and background.
242    if (o->style()->hasBorderRadius() || o->style()->hasBackgroundImage())
243        return true;
244
245    ControlPart part = o->style()->appearance();
246
247    PlatformBridge::ThemePaintExtraParams extraParams;
248    extraParams.textField.isTextArea = part == TextAreaPart;
249    extraParams.textField.isListbox = part == ListboxPart;
250
251    // Fallback to white if the specified color object is invalid.
252    Color backgroundColor(Color::white);
253    if (o->style()->visitedDependentColor(CSSPropertyBackgroundColor).isValid())
254        backgroundColor = o->style()->visitedDependentColor(CSSPropertyBackgroundColor);
255    extraParams.textField.backgroundColor = backgroundColor.rgb();
256
257    PlatformBridge::paintThemePart(i.context, PlatformBridge::PartTextField, getWebThemeState(this, o), rect, &extraParams);
258    return false;
259}
260
261bool RenderThemeChromiumLinux::paintMenuList(RenderObject* o, const PaintInfo& i, const IntRect& rect)
262{
263    const int right = rect.x() + rect.width();
264    const int middle = rect.y() + rect.height() / 2;
265
266    PlatformBridge::ThemePaintExtraParams extraParams;
267    extraParams.menuList.arrowX = (o->style()->direction() == RTL) ? rect.x() + 7 : right - 13;
268    extraParams.menuList.arrowY = middle;
269    extraParams.menuList.backgroundColor = SkColorSetRGB(0xdd, 0xdd, 0xdd);
270    if (o->hasBackground())
271        extraParams.menuList.backgroundColor = o->style()->visitedDependentColor(CSSPropertyBackgroundColor).rgb();
272
273    PlatformBridge::paintThemePart(i.context, PlatformBridge::PartMenuList, getWebThemeState(this, o), rect, &extraParams);
274    return false;
275}
276
277bool RenderThemeChromiumLinux::paintSliderTrack(RenderObject* o, const PaintInfo& i, const IntRect& rect)
278{
279    PlatformBridge::ThemePaintExtraParams extraParams;
280    extraParams.slider.vertical = o->style()->appearance() == SliderVerticalPart;
281
282    PlatformBridge::paintThemePart(i.context, PlatformBridge::PartSliderTrack, getWebThemeState(this, o), rect, &extraParams);
283    return false;
284}
285
286bool RenderThemeChromiumLinux::paintSliderThumb(RenderObject* o, const PaintInfo& i, const IntRect& rect)
287{
288    PlatformBridge::ThemePaintExtraParams extraParams;
289    extraParams.slider.vertical = o->style()->appearance() == SliderThumbVerticalPart;
290    extraParams.slider.inDrag = toRenderSlider(o->parent())->inDragMode();
291
292    PlatformBridge::paintThemePart(i.context, PlatformBridge::PartSliderThumb, getWebThemeState(this, o), rect, &extraParams);
293    return false;
294}
295
296void RenderThemeChromiumLinux::adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
297{
298    IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartInnerSpinButton);
299
300    style->setWidth(Length(size.width(), Fixed));
301    style->setMinWidth(Length(size.width(), Fixed));
302}
303
304bool RenderThemeChromiumLinux::paintInnerSpinButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
305{
306    PlatformBridge::ThemePaintExtraParams extraParams;
307    extraParams.innerSpin.spinUp = (controlStatesForRenderer(o) & SpinUpState);
308    extraParams.innerSpin.readOnly = isReadOnlyControl(o);
309
310    PlatformBridge::paintThemePart(i.context, PlatformBridge::PartInnerSpinButton, getWebThemeState(this, o), rect, &extraParams);
311    return false;
312}
313
314#if ENABLE(PROGRESS_TAG)
315
316bool RenderThemeChromiumLinux::paintProgressBar(RenderObject* o, const PaintInfo& i, const IntRect& rect)
317{
318    if (!o->isProgress())
319        return true;
320
321    RenderProgress* renderProgress = toRenderProgress(o);
322    IntRect valueRect = progressValueRectFor(renderProgress, rect);
323
324    PlatformBridge::ThemePaintExtraParams extraParams;
325    extraParams.progressBar.determinate = renderProgress->isDeterminate();
326    extraParams.progressBar.valueRectX = valueRect.x();
327    extraParams.progressBar.valueRectY = valueRect.y();
328    extraParams.progressBar.valueRectWidth = valueRect.width();
329    extraParams.progressBar.valueRectHeight = valueRect.height();
330
331    PlatformBridge::paintThemePart(i.context, PlatformBridge::PartProgressBar, getWebThemeState(this, o), rect, &extraParams);
332    return false;
333}
334
335#endif
336
337} // namespace WebCore
338