Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / RenderThemeChromiumLinux.cpp
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 "PlatformSupport.h"
32 #include "RenderObject.h"
33 #include "RenderProgress.h"
34 #include "RenderSlider.h"
35 #include "ScrollbarTheme.h"
36 #include "UserAgentStyleSheets.h"
37
38 namespace WebCore {
39
40 unsigned RenderThemeChromiumLinux::m_activeSelectionBackgroundColor =
41     0xff1e90ff;
42 unsigned RenderThemeChromiumLinux::m_activeSelectionForegroundColor =
43     Color::black;
44 unsigned RenderThemeChromiumLinux::m_inactiveSelectionBackgroundColor =
45     0xffc8c8c8;
46 unsigned RenderThemeChromiumLinux::m_inactiveSelectionForegroundColor =
47     0xff323232;
48
49 double RenderThemeChromiumLinux::m_caretBlinkInterval;
50
51 static const unsigned defaultButtonBackgroundColor = 0xffdddddd;
52
53 static PlatformSupport::ThemePaintState getWebThemeState(const RenderTheme* theme, const RenderObject* o)
54 {
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;
61
62     return PlatformSupport::StateNormal;
63 }
64
65
66 PassRefPtr<RenderTheme> RenderThemeChromiumLinux::create()
67 {
68     return adoptRef(new RenderThemeChromiumLinux());
69 }
70
71 // RenderTheme::themeForPage for Android is defined in RenderThemeChromiumAndroid.cpp.
72 #if !OS(ANDROID)
73 PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page* page)
74 {
75     static RenderTheme* rt = RenderThemeChromiumLinux::create().leakRef();
76     return rt;
77 }
78 #endif
79
80 RenderThemeChromiumLinux::RenderThemeChromiumLinux()
81 {
82     m_caretBlinkInterval = RenderTheme::caretBlinkInterval();
83 }
84
85 RenderThemeChromiumLinux::~RenderThemeChromiumLinux()
86 {
87 }
88
89 Color RenderThemeChromiumLinux::systemColor(int cssValueId) const
90 {
91     static const Color linuxButtonGrayColor(0xffdddddd);
92
93     if (cssValueId == CSSValueButtonface)
94         return linuxButtonGrayColor;
95     return RenderTheme::systemColor(cssValueId);
96 }
97
98 String RenderThemeChromiumLinux::extraDefaultStyleSheet()
99 {
100     return RenderThemeChromiumSkia::extraDefaultStyleSheet() +
101            String(themeChromiumLinuxUserAgentStyleSheet, sizeof(themeChromiumLinuxUserAgentStyleSheet));
102 }
103
104 bool RenderThemeChromiumLinux::controlSupportsTints(const RenderObject* o) const
105 {
106     return isEnabled(o);
107 }
108
109 Color RenderThemeChromiumLinux::activeListBoxSelectionBackgroundColor() const
110 {
111     return Color(0x28, 0x28, 0x28);
112 }
113
114 Color RenderThemeChromiumLinux::activeListBoxSelectionForegroundColor() const
115 {
116     return Color::black;
117 }
118
119 Color RenderThemeChromiumLinux::inactiveListBoxSelectionBackgroundColor() const
120 {
121     return Color(0xc8, 0xc8, 0xc8);
122 }
123
124 Color RenderThemeChromiumLinux::inactiveListBoxSelectionForegroundColor() const
125 {
126     return Color(0x32, 0x32, 0x32);
127 }
128
129 Color RenderThemeChromiumLinux::platformActiveSelectionBackgroundColor() const
130 {
131     return m_activeSelectionBackgroundColor;
132 }
133
134 Color RenderThemeChromiumLinux::platformInactiveSelectionBackgroundColor() const
135 {
136     return m_inactiveSelectionBackgroundColor;
137 }
138
139 Color RenderThemeChromiumLinux::platformActiveSelectionForegroundColor() const
140 {
141     return m_activeSelectionForegroundColor;
142 }
143
144 Color RenderThemeChromiumLinux::platformInactiveSelectionForegroundColor() const
145 {
146     return m_inactiveSelectionForegroundColor;
147 }
148
149 #if ENABLE(DATALIST_ELEMENT)
150 IntSize RenderThemeChromiumLinux::sliderTickSize() const
151 {
152     return IntSize(1, 6);
153 }
154
155 int RenderThemeChromiumLinux::sliderTickOffsetFromTrackCenter() const
156 {
157     return -16;
158 }
159 #endif
160
161 void RenderThemeChromiumLinux::adjustSliderThumbSize(RenderStyle* style, Element* element) const
162 {
163     IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartSliderThumb);
164
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));
171     } else
172         RenderThemeChromiumSkia::adjustSliderThumbSize(style, element);
173 }
174
175 bool RenderThemeChromiumLinux::supportsControlTints() const
176 {
177     return true;
178 }
179
180 void RenderThemeChromiumLinux::setCaretBlinkInterval(double interval)
181 {
182     m_caretBlinkInterval = interval;
183 }
184
185 double RenderThemeChromiumLinux::caretBlinkIntervalInternal() const
186 {
187     return m_caretBlinkInterval;
188 }
189
190 void RenderThemeChromiumLinux::setSelectionColors(
191     unsigned activeBackgroundColor,
192     unsigned activeForegroundColor,
193     unsigned inactiveBackgroundColor,
194     unsigned inactiveForegroundColor)
195 {
196     m_activeSelectionBackgroundColor = activeBackgroundColor;
197     m_activeSelectionForegroundColor = activeForegroundColor;
198     m_inactiveSelectionBackgroundColor = inactiveBackgroundColor;
199     m_inactiveSelectionForegroundColor = inactiveForegroundColor;
200 }
201
202 bool RenderThemeChromiumLinux::paintCheckbox(RenderObject* o, const PaintInfo& i, const IntRect& rect)
203 {
204     PlatformSupport::ThemePaintExtraParams extraParams;
205     extraParams.button.checked = isChecked(o);
206     extraParams.button.indeterminate = isIndeterminate(o);
207
208     PlatformSupport::paintThemePart(i.context, PlatformSupport::PartCheckbox, getWebThemeState(this, o), rect, &extraParams);
209     return false;
210 }
211
212 void RenderThemeChromiumLinux::setCheckboxSize(RenderStyle* style) const
213 {
214     // If the width and height are both specified, then we have nothing to do.
215     if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
216         return;
217
218     IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartCheckbox);
219     setSizeIfAuto(style, size);
220 }
221
222 bool RenderThemeChromiumLinux::paintRadio(RenderObject* o, const PaintInfo& i, const IntRect& rect)
223 {
224     PlatformSupport::ThemePaintExtraParams extraParams;
225     extraParams.button.checked = isChecked(o);
226
227     PlatformSupport::paintThemePart(i.context, PlatformSupport::PartRadio, getWebThemeState(this, o), rect, &extraParams);
228     return false;
229 }
230
231 void RenderThemeChromiumLinux::setRadioSize(RenderStyle* style) const
232 {
233     // If the width and height are both specified, then we have nothing to do.
234     if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
235         return;
236
237     IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartRadio);
238     setSizeIfAuto(style, size);
239 }
240
241 bool RenderThemeChromiumLinux::paintButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
242 {
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();
249
250     PlatformSupport::paintThemePart(i.context, PlatformSupport::PartButton, getWebThemeState(this, o), rect, &extraParams);
251     return false;
252 }
253
254 bool RenderThemeChromiumLinux::paintTextField(RenderObject* o, const PaintInfo& i, const IntRect& rect)
255 {
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())
259         return true;
260
261     ControlPart part = o->style()->appearance();
262
263     PlatformSupport::ThemePaintExtraParams extraParams;
264     extraParams.textField.isTextArea = part == TextAreaPart;
265     extraParams.textField.isListbox = part == ListboxPart;
266
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();
272
273     PlatformSupport::paintThemePart(i.context, PlatformSupport::PartTextField, getWebThemeState(this, o), rect, &extraParams);
274     return false;
275 }
276
277 bool RenderThemeChromiumLinux::paintMenuList(RenderObject* o, const PaintInfo& i, const IntRect& rect)
278 {
279     if (!o->isBox())
280         return false;
281
282     const int right = rect.x() + rect.width();
283     const int middle = rect.y() + rect.height() / 2;
284
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();
296
297     PlatformSupport::paintThemePart(i.context, PlatformSupport::PartMenuList, getWebThemeState(this, o), rect, &extraParams);
298     return false;
299 }
300
301 bool RenderThemeChromiumLinux::paintSliderTrack(RenderObject* o, const PaintInfo& i, const IntRect& rect)
302 {
303     PlatformSupport::ThemePaintExtraParams extraParams;
304     extraParams.slider.vertical = o->style()->appearance() == SliderVerticalPart;
305
306     PlatformSupport::paintThemePart(i.context, PlatformSupport::PartSliderTrack, getWebThemeState(this, o), rect, &extraParams);
307
308 #if ENABLE(DATALIST_ELEMENT)
309     paintSliderTicks(o, i, rect);
310 #endif
311
312     return false;
313 }
314
315 bool RenderThemeChromiumLinux::paintSliderThumb(RenderObject* o, const PaintInfo& i, const IntRect& rect)
316 {
317     PlatformSupport::ThemePaintExtraParams extraParams;
318     extraParams.slider.vertical = o->style()->appearance() == SliderThumbVerticalPart;
319     extraParams.slider.inDrag = isPressed(o);
320
321     PlatformSupport::paintThemePart(i.context, PlatformSupport::PartSliderThumb, getWebThemeState(this, o), rect, &extraParams);
322     return false;
323 }
324
325 void RenderThemeChromiumLinux::adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle* style, Element*) const
326 {
327     IntSize size = PlatformSupport::getThemePartSize(PlatformSupport::PartInnerSpinButton);
328
329     style->setWidth(Length(size.width(), Fixed));
330     style->setMinWidth(Length(size.width(), Fixed));
331 }
332
333 bool RenderThemeChromiumLinux::paintInnerSpinButton(RenderObject* o, const PaintInfo& i, const IntRect& rect)
334 {
335     PlatformSupport::ThemePaintExtraParams extraParams;
336     extraParams.innerSpin.spinUp = (controlStatesForRenderer(o) & SpinUpState);
337     extraParams.innerSpin.readOnly = isReadOnlyControl(o);
338
339     PlatformSupport::paintThemePart(i.context, PlatformSupport::PartInnerSpinButton, getWebThemeState(this, o), rect, &extraParams);
340     return false;
341 }
342
343 #if ENABLE(PROGRESS_ELEMENT)
344
345 bool RenderThemeChromiumLinux::paintProgressBar(RenderObject* o, const PaintInfo& i, const IntRect& rect)
346 {
347     if (!o->isProgress())
348         return true;
349
350     RenderProgress* renderProgress = toRenderProgress(o);
351     IntRect valueRect = progressValueRectFor(renderProgress, rect);
352
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();
359
360     DirectionFlippingScope scope(o, i, rect);
361     PlatformSupport::paintThemePart(i.context, PlatformSupport::PartProgressBar, getWebThemeState(this, o), rect, &extraParams);
362     return false;
363 }
364
365 #endif
366
367 } // namespace WebCore