Subpixel rendering: Make <select> element's decoration subpixel aware.
[WebKit-https.git] / Source / WebCore / rendering / RenderTheme.cpp
1 /**
2  * This file is part of the theme implementation for form controls in WebCore.
3  *
4  * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple 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 #include "config.h"
23 #include "RenderTheme.h"
24
25 #include "CSSValueKeywords.h"
26 #include "ControlStates.h"
27 #include "Document.h"
28 #include "FileList.h"
29 #include "FileSystem.h"
30 #include "FloatConversion.h"
31 #include "FocusController.h"
32 #include "FontSelector.h"
33 #include "Frame.h"
34 #include "FrameSelection.h"
35 #include "GraphicsContext.h"
36 #include "HTMLInputElement.h"
37 #include "HTMLNames.h"
38 #include "LocalizedStrings.h"
39 #include "MediaControlElements.h"
40 #include "Page.h"
41 #include "PaintInfo.h"
42 #include "RenderStyle.h"
43 #include "RenderView.h"
44 #include "Settings.h"
45 #include "SpinButtonElement.h"
46 #include "StringTruncator.h"
47 #include "TextControlInnerElements.h"
48
49 #if ENABLE(METER_ELEMENT)
50 #include "HTMLMeterElement.h"
51 #include "RenderMeter.h"
52 #endif
53
54 #if ENABLE(INPUT_SPEECH)
55 #include "RenderInputSpeech.h"
56 #endif
57
58 #if ENABLE(DATALIST_ELEMENT)
59 #include "HTMLCollection.h"
60 #include "HTMLDataListElement.h"
61 #include "HTMLOptionElement.h"
62 #include "HTMLParserIdioms.h"
63 #endif
64
65 // The methods in this file are shared by all themes on every platform.
66
67 namespace WebCore {
68
69 using namespace HTMLNames;
70
71 static Color& customFocusRingColor()
72 {
73     DEPRECATED_DEFINE_STATIC_LOCAL(Color, color, ());
74     return color;
75 }
76
77 RenderTheme::RenderTheme()
78 #if USE(NEW_THEME)
79     : m_theme(platformTheme())
80 #endif
81 {
82 }
83
84 void RenderTheme::adjustStyle(StyleResolver& styleResolver, RenderStyle& style, Element* e, bool UAHasAppearance, const BorderData& border, const FillLayer& background, const Color& backgroundColor)
85 {
86     // Force inline and table display styles to be inline-block (except for table- which is block)
87     ControlPart part = style.appearance();
88     if (style.display() == INLINE || style.display() == INLINE_TABLE || style.display() == TABLE_ROW_GROUP
89         || style.display() == TABLE_HEADER_GROUP || style.display() == TABLE_FOOTER_GROUP
90         || style.display() == TABLE_ROW || style.display() == TABLE_COLUMN_GROUP || style.display() == TABLE_COLUMN
91         || style.display() == TABLE_CELL || style.display() == TABLE_CAPTION)
92         style.setDisplay(INLINE_BLOCK);
93     else if (style.display() == COMPACT || style.display() == LIST_ITEM || style.display() == TABLE)
94         style.setDisplay(BLOCK);
95
96     if (UAHasAppearance && isControlStyled(&style, border, background, backgroundColor)) {
97         if (part == MenulistPart) {
98             style.setAppearance(MenulistButtonPart);
99             part = MenulistButtonPart;
100         } else
101             style.setAppearance(NoControlPart);
102     }
103
104     if (!style.hasAppearance())
105         return;
106
107     // Never support box-shadow on native controls.
108     style.setBoxShadow(nullptr);
109     
110 #if USE(NEW_THEME)
111     switch (part) {
112     case CheckboxPart:
113     case InnerSpinButtonPart:
114     case RadioPart:
115     case PushButtonPart:
116     case SquareButtonPart:
117     case DefaultButtonPart:
118     case ButtonPart: {
119         // Border
120         LengthBox borderBox(style.borderTopWidth(), style.borderRightWidth(), style.borderBottomWidth(), style.borderLeftWidth());
121         borderBox = m_theme->controlBorder(part, style.font(), borderBox, style.effectiveZoom());
122         if (borderBox.top().value() != static_cast<int>(style.borderTopWidth())) {
123             if (borderBox.top().value())
124                 style.setBorderTopWidth(borderBox.top().value());
125             else
126                 style.resetBorderTop();
127         }
128         if (borderBox.right().value() != static_cast<int>(style.borderRightWidth())) {
129             if (borderBox.right().value())
130                 style.setBorderRightWidth(borderBox.right().value());
131             else
132                 style.resetBorderRight();
133         }
134         if (borderBox.bottom().value() != static_cast<int>(style.borderBottomWidth())) {
135             style.setBorderBottomWidth(borderBox.bottom().value());
136             if (borderBox.bottom().value())
137                 style.setBorderBottomWidth(borderBox.bottom().value());
138             else
139                 style.resetBorderBottom();
140         }
141         if (borderBox.left().value() != static_cast<int>(style.borderLeftWidth())) {
142             style.setBorderLeftWidth(borderBox.left().value());
143             if (borderBox.left().value())
144                 style.setBorderLeftWidth(borderBox.left().value());
145             else
146                 style.resetBorderLeft();
147         }
148
149         // Padding
150         LengthBox paddingBox = m_theme->controlPadding(part, style.font(), style.paddingBox(), style.effectiveZoom());
151         if (paddingBox != style.paddingBox())
152             style.setPaddingBox(paddingBox);
153
154         // Whitespace
155         if (m_theme->controlRequiresPreWhiteSpace(part))
156             style.setWhiteSpace(PRE);
157             
158         // Width / Height
159         // The width and height here are affected by the zoom.
160         // FIXME: Check is flawed, since it doesn't take min-width/max-width into account.
161         LengthSize controlSize = m_theme->controlSize(part, style.font(), LengthSize(style.width(), style.height()), style.effectiveZoom());
162         if (controlSize.width() != style.width())
163             style.setWidth(controlSize.width());
164         if (controlSize.height() != style.height())
165             style.setHeight(controlSize.height());
166                 
167         // Min-Width / Min-Height
168         LengthSize minControlSize = m_theme->minimumControlSize(part, style.font(), style.effectiveZoom());
169         if (minControlSize.width() != style.minWidth())
170             style.setMinWidth(minControlSize.width());
171         if (minControlSize.height() != style.minHeight())
172             style.setMinHeight(minControlSize.height());
173                 
174         // Font
175         FontDescription controlFont = m_theme->controlFont(part, style.font(), style.effectiveZoom());
176         if (controlFont != style.font().fontDescription()) {
177             // Reset our line-height
178             style.setLineHeight(RenderStyle::initialLineHeight());
179
180             // Now update our font.
181             if (style.setFontDescription(controlFont))
182                 style.font().update(0);
183         }
184     }
185     break;
186     default:
187         break;
188     }
189 #endif
190
191     // Call the appropriate style adjustment method based off the appearance value.
192     switch (style.appearance()) {
193 #if !USE(NEW_THEME)
194     case CheckboxPart:
195         return adjustCheckboxStyle(&styleResolver, &style, e);
196     case RadioPart:
197         return adjustRadioStyle(&styleResolver, &style, e);
198     case PushButtonPart:
199     case SquareButtonPart:
200     case DefaultButtonPart:
201     case ButtonPart:
202         return adjustButtonStyle(&styleResolver, &style, e);
203     case InnerSpinButtonPart:
204         return adjustInnerSpinButtonStyle(&styleResolver, &style, e);
205 #endif
206     case TextFieldPart:
207         return adjustTextFieldStyle(&styleResolver, &style, e);
208     case TextAreaPart:
209         return adjustTextAreaStyle(&styleResolver, &style, e);
210     case MenulistPart:
211         return adjustMenuListStyle(&styleResolver, &style, e);
212     case MenulistButtonPart:
213         return adjustMenuListButtonStyle(&styleResolver, &style, e);
214     case MediaPlayButtonPart:
215     case MediaCurrentTimePart:
216     case MediaTimeRemainingPart:
217     case MediaEnterFullscreenButtonPart:
218     case MediaExitFullscreenButtonPart:
219     case MediaMuteButtonPart:
220     case MediaVolumeSliderContainerPart:
221         return adjustMediaControlStyle(&styleResolver, &style, e);
222     case MediaSliderPart:
223     case MediaVolumeSliderPart:
224     case MediaFullScreenVolumeSliderPart:
225     case SliderHorizontalPart:
226     case SliderVerticalPart:
227         return adjustSliderTrackStyle(&styleResolver, &style, e);
228     case SliderThumbHorizontalPart:
229     case SliderThumbVerticalPart:
230         return adjustSliderThumbStyle(&styleResolver, &style, e);
231     case SearchFieldPart:
232         return adjustSearchFieldStyle(&styleResolver, &style, e);
233     case SearchFieldCancelButtonPart:
234         return adjustSearchFieldCancelButtonStyle(&styleResolver, &style, e);
235     case SearchFieldDecorationPart:
236         return adjustSearchFieldDecorationPartStyle(&styleResolver, &style, e);
237     case SearchFieldResultsDecorationPart:
238         return adjustSearchFieldResultsDecorationPartStyle(&styleResolver, &style, e);
239     case SearchFieldResultsButtonPart:
240         return adjustSearchFieldResultsButtonStyle(&styleResolver, &style, e);
241 #if ENABLE(PROGRESS_ELEMENT)
242     case ProgressBarPart:
243         return adjustProgressBarStyle(&styleResolver, &style, e);
244 #endif
245 #if ENABLE(METER_ELEMENT)
246     case MeterPart:
247     case RelevancyLevelIndicatorPart:
248     case ContinuousCapacityLevelIndicatorPart:
249     case DiscreteCapacityLevelIndicatorPart:
250     case RatingLevelIndicatorPart:
251         return adjustMeterStyle(&styleResolver, &style, e);
252 #endif
253 #if ENABLE(INPUT_SPEECH)
254     case InputSpeechButtonPart:
255         return adjustInputFieldSpeechButtonStyle(&styleResolver, &style, e);
256 #endif
257 #if ENABLE(SERVICE_CONTROLS)
258     case ImageControlsButtonPart:
259         break;
260 #endif
261     default:
262         break;
263     }
264 }
265
266 bool RenderTheme::paint(const RenderObject& o, ControlStates* controlStates, const PaintInfo& paintInfo, const LayoutRect& r)
267 {
268     // If painting is disabled, but we aren't updating control tints, then just bail.
269     // If we are updating control tints, just schedule a repaint if the theme supports tinting
270     // for that control.
271     if (paintInfo.context->updatingControlTints()) {
272         if (controlSupportsTints(o))
273             o.repaint();
274         return false;
275     }
276     if (paintInfo.context->paintingDisabled())
277         return false;
278
279     ControlPart part = o.style().appearance();
280     IntRect integralSnappedRect = pixelSnappedIntRect(r);
281     FloatRect devicePixelSnappedRect = pixelSnappedForPainting(r, o.document().deviceScaleFactor());
282
283 #if USE(NEW_THEME)
284     switch (part) {
285     case CheckboxPart:
286     case RadioPart:
287     case PushButtonPart:
288     case SquareButtonPart:
289     case DefaultButtonPart:
290     case ButtonPart:
291     case InnerSpinButtonPart:
292         updateControlStatesForRenderer(o, controlStates);
293         m_theme->paint(part, controlStates, const_cast<GraphicsContext*>(paintInfo.context), integralSnappedRect, o.style().effectiveZoom(), &o.view().frameView());
294         return false;
295     default:
296         break;
297     }
298 #else
299     UNUSED_PARAM(controlStates);
300 #endif
301
302     // Call the appropriate paint method based off the appearance value.
303     switch (part) {
304 #if !USE(NEW_THEME)
305     case CheckboxPart:
306         return paintCheckbox(o, paintInfo, integralSnappedRect);
307     case RadioPart:
308         return paintRadio(o, paintInfo, integralSnappedRect);
309     case PushButtonPart:
310     case SquareButtonPart:
311     case DefaultButtonPart:
312     case ButtonPart:
313         return paintButton(o, paintInfo, integralSnappedRect);
314     case InnerSpinButtonPart:
315         return paintInnerSpinButton(o, paintInfo, integralSnappedRect);
316 #endif
317     case MenulistPart:
318         return paintMenuList(o, paintInfo, devicePixelSnappedRect);
319 #if ENABLE(METER_ELEMENT)
320     case MeterPart:
321     case RelevancyLevelIndicatorPart:
322     case ContinuousCapacityLevelIndicatorPart:
323     case DiscreteCapacityLevelIndicatorPart:
324     case RatingLevelIndicatorPart:
325         return paintMeter(o, paintInfo, integralSnappedRect);
326 #endif
327 #if ENABLE(PROGRESS_ELEMENT)
328     case ProgressBarPart:
329         return paintProgressBar(o, paintInfo, integralSnappedRect);
330 #endif
331     case SliderHorizontalPart:
332     case SliderVerticalPart:
333         return paintSliderTrack(o, paintInfo, integralSnappedRect);
334     case SliderThumbHorizontalPart:
335     case SliderThumbVerticalPart:
336         return paintSliderThumb(o, paintInfo, integralSnappedRect);
337     case MediaEnterFullscreenButtonPart:
338     case MediaExitFullscreenButtonPart:
339         return paintMediaFullscreenButton(o, paintInfo, integralSnappedRect);
340     case MediaPlayButtonPart:
341         return paintMediaPlayButton(o, paintInfo, integralSnappedRect);
342     case MediaOverlayPlayButtonPart:
343         return paintMediaOverlayPlayButton(o, paintInfo, integralSnappedRect);
344     case MediaMuteButtonPart:
345         return paintMediaMuteButton(o, paintInfo, integralSnappedRect);
346     case MediaSeekBackButtonPart:
347         return paintMediaSeekBackButton(o, paintInfo, integralSnappedRect);
348     case MediaSeekForwardButtonPart:
349         return paintMediaSeekForwardButton(o, paintInfo, integralSnappedRect);
350     case MediaRewindButtonPart:
351         return paintMediaRewindButton(o, paintInfo, integralSnappedRect);
352     case MediaReturnToRealtimeButtonPart:
353         return paintMediaReturnToRealtimeButton(o, paintInfo, integralSnappedRect);
354     case MediaToggleClosedCaptionsButtonPart:
355         return paintMediaToggleClosedCaptionsButton(o, paintInfo, integralSnappedRect);
356     case MediaSliderPart:
357         return paintMediaSliderTrack(o, paintInfo, integralSnappedRect);
358     case MediaSliderThumbPart:
359         return paintMediaSliderThumb(o, paintInfo, integralSnappedRect);
360     case MediaVolumeSliderMuteButtonPart:
361         return paintMediaMuteButton(o, paintInfo, integralSnappedRect);
362     case MediaVolumeSliderContainerPart:
363         return paintMediaVolumeSliderContainer(o, paintInfo, integralSnappedRect);
364     case MediaVolumeSliderPart:
365         return paintMediaVolumeSliderTrack(o, paintInfo, integralSnappedRect);
366     case MediaVolumeSliderThumbPart:
367         return paintMediaVolumeSliderThumb(o, paintInfo, integralSnappedRect);
368     case MediaFullScreenVolumeSliderPart:
369         return paintMediaFullScreenVolumeSliderTrack(o, paintInfo, integralSnappedRect);
370     case MediaFullScreenVolumeSliderThumbPart:
371         return paintMediaFullScreenVolumeSliderThumb(o, paintInfo, integralSnappedRect);
372     case MediaTimeRemainingPart:
373         return paintMediaTimeRemaining(o, paintInfo, integralSnappedRect);
374     case MediaCurrentTimePart:
375         return paintMediaCurrentTime(o, paintInfo, integralSnappedRect);
376     case MediaControlsBackgroundPart:
377         return paintMediaControlsBackground(o, paintInfo, integralSnappedRect);
378     case MenulistButtonPart:
379     case TextFieldPart:
380     case TextAreaPart:
381     case ListboxPart:
382         return true;
383     case SearchFieldPart:
384         return paintSearchField(o, paintInfo, integralSnappedRect);
385     case SearchFieldCancelButtonPart:
386         return paintSearchFieldCancelButton(o, paintInfo, integralSnappedRect);
387     case SearchFieldDecorationPart:
388         return paintSearchFieldDecorationPart(o, paintInfo, integralSnappedRect);
389     case SearchFieldResultsDecorationPart:
390         return paintSearchFieldResultsDecorationPart(o, paintInfo, integralSnappedRect);
391     case SearchFieldResultsButtonPart:
392         return paintSearchFieldResultsButton(o, paintInfo, integralSnappedRect);
393     case SnapshottedPluginOverlayPart:
394         return paintSnapshottedPluginOverlay(o, paintInfo, integralSnappedRect);
395 #if ENABLE(INPUT_SPEECH)
396     case InputSpeechButtonPart:
397         return paintInputFieldSpeechButton(o, paintInfo, integralSnappedRect);
398 #endif
399 #if ENABLE(SERVICE_CONTROLS)
400     case ImageControlsButtonPart:
401         return paintImageControlsButton(o, paintInfo, integralSnappedRect);
402 #endif
403     default:
404         break;
405     }
406
407     return true; // We don't support the appearance, so let the normal background/border paint.
408 }
409
410 bool RenderTheme::paintBorderOnly(const RenderObject& o, const PaintInfo& paintInfo, const LayoutRect& r)
411 {
412     if (paintInfo.context->paintingDisabled())
413         return false;
414
415 #if PLATFORM(IOS)
416     UNUSED_PARAM(r);
417     return o.style().appearance() != NoControlPart;
418 #else
419     FloatRect devicePixelSnappedRect = pixelSnappedForPainting(r, o.document().deviceScaleFactor());
420     // Call the appropriate paint method based off the appearance value.
421     switch (o.style().appearance()) {
422     case TextFieldPart:
423         return paintTextField(o, paintInfo, devicePixelSnappedRect);
424     case ListboxPart:
425     case TextAreaPart:
426         return paintTextArea(o, paintInfo, devicePixelSnappedRect);
427     case MenulistButtonPart:
428     case SearchFieldPart:
429         return true;
430     case CheckboxPart:
431     case RadioPart:
432     case PushButtonPart:
433     case SquareButtonPart:
434     case DefaultButtonPart:
435     case ButtonPart:
436     case MenulistPart:
437 #if ENABLE(METER_ELEMENT)
438     case MeterPart:
439     case RelevancyLevelIndicatorPart:
440     case ContinuousCapacityLevelIndicatorPart:
441     case DiscreteCapacityLevelIndicatorPart:
442     case RatingLevelIndicatorPart:
443 #endif
444 #if ENABLE(PROGRESS_ELEMENT)
445     case ProgressBarPart:
446 #endif
447     case SliderHorizontalPart:
448     case SliderVerticalPart:
449     case SliderThumbHorizontalPart:
450     case SliderThumbVerticalPart:
451     case SearchFieldCancelButtonPart:
452     case SearchFieldDecorationPart:
453     case SearchFieldResultsDecorationPart:
454     case SearchFieldResultsButtonPart:
455 #if ENABLE(INPUT_SPEECH)
456     case InputSpeechButtonPart:
457 #endif
458 #if ENABLE(SERVICE_CONTROLS)
459     case ImageControlsButtonPart:
460 #endif
461     default:
462         break;
463     }
464
465     return false;
466 #endif
467 }
468
469 bool RenderTheme::paintDecorations(const RenderObject& renderer, const PaintInfo& paintInfo, const LayoutRect& rect)
470 {
471     if (paintInfo.context->paintingDisabled())
472         return false;
473
474     IntRect integralSnappedRect = pixelSnappedIntRect(rect);
475     FloatRect devicePixelSnappedRect = pixelSnappedForPainting(rect, renderer.document().deviceScaleFactor());
476
477     // Call the appropriate paint method based off the appearance value.
478     switch (renderer.style().appearance()) {
479     case MenulistButtonPart:
480         return paintMenuListButtonDecorations(renderer, paintInfo, devicePixelSnappedRect);
481     case TextFieldPart:
482         return paintTextFieldDecorations(renderer, paintInfo, devicePixelSnappedRect);
483     case TextAreaPart:
484         return paintTextAreaDecorations(renderer, paintInfo, devicePixelSnappedRect);
485     case CheckboxPart:
486         return paintCheckboxDecorations(renderer, paintInfo, integralSnappedRect);
487     case RadioPart:
488         return paintRadioDecorations(renderer, paintInfo, integralSnappedRect);
489     case PushButtonPart:
490         return paintPushButtonDecorations(renderer, paintInfo, integralSnappedRect);
491     case SquareButtonPart:
492         return paintSquareButtonDecorations(renderer, paintInfo, integralSnappedRect);
493     case ButtonPart:
494         return paintButtonDecorations(renderer, paintInfo, integralSnappedRect);
495     case MenulistPart:
496         return paintMenuListDecorations(renderer, paintInfo, integralSnappedRect);
497     case SliderThumbHorizontalPart:
498     case SliderThumbVerticalPart:
499         return paintSliderThumbDecorations(renderer, paintInfo, integralSnappedRect);
500     case SearchFieldPart:
501         return paintSearchFieldDecorations(renderer, paintInfo, integralSnappedRect);
502 #if ENABLE(METER_ELEMENT)
503     case MeterPart:
504     case RelevancyLevelIndicatorPart:
505     case ContinuousCapacityLevelIndicatorPart:
506     case DiscreteCapacityLevelIndicatorPart:
507     case RatingLevelIndicatorPart:
508 #endif
509 #if ENABLE(PROGRESS_ELEMENT)
510     case ProgressBarPart:
511 #endif
512     case SliderHorizontalPart:
513     case SliderVerticalPart:
514     case ListboxPart:
515     case DefaultButtonPart:
516     case SearchFieldCancelButtonPart:
517     case SearchFieldDecorationPart:
518     case SearchFieldResultsDecorationPart:
519     case SearchFieldResultsButtonPart:
520 #if ENABLE(INPUT_SPEECH)
521     case InputSpeechButtonPart:
522 #endif
523 #if ENABLE(SERVICE_CONTROLS)
524     case ImageControlsButtonPart:
525 #endif
526     default:
527         break;
528     }
529
530     return false;
531 }
532
533 #if ENABLE(VIDEO)
534
535 String RenderTheme::formatMediaControlsTime(float time) const
536 {
537     if (!std::isfinite(time))
538         time = 0;
539     int seconds = (int)fabsf(time);
540     int hours = seconds / (60 * 60);
541     int minutes = (seconds / 60) % 60;
542     seconds %= 60;
543     if (hours) {
544         if (hours > 9)
545             return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
546
547         return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
548     }
549
550     return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
551 }
552
553 String RenderTheme::formatMediaControlsCurrentTime(float currentTime, float /*duration*/) const
554 {
555     return formatMediaControlsTime(currentTime);
556 }
557
558 String RenderTheme::formatMediaControlsRemainingTime(float currentTime, float duration) const
559 {
560     return formatMediaControlsTime(currentTime - duration);
561 }
562
563 IntPoint RenderTheme::volumeSliderOffsetFromMuteButton(RenderBox* muteButtonBox, const IntSize& size) const
564 {
565     int y = -size.height();
566     FloatPoint absPoint = muteButtonBox->localToAbsolute(FloatPoint(muteButtonBox->pixelSnappedOffsetLeft(), y), IsFixed | UseTransforms);
567     if (absPoint.y() < 0)
568         y = muteButtonBox->height();
569     return IntPoint(0, y);
570 }
571
572 #endif
573
574 Color RenderTheme::activeSelectionBackgroundColor() const
575 {
576     if (!m_activeSelectionBackgroundColor.isValid())
577         m_activeSelectionBackgroundColor = platformActiveSelectionBackgroundColor().blendWithWhite();
578     return m_activeSelectionBackgroundColor;
579 }
580
581 Color RenderTheme::inactiveSelectionBackgroundColor() const
582 {
583     if (!m_inactiveSelectionBackgroundColor.isValid())
584         m_inactiveSelectionBackgroundColor = platformInactiveSelectionBackgroundColor().blendWithWhite();
585     return m_inactiveSelectionBackgroundColor;
586 }
587
588 Color RenderTheme::activeSelectionForegroundColor() const
589 {
590     if (!m_activeSelectionForegroundColor.isValid() && supportsSelectionForegroundColors())
591         m_activeSelectionForegroundColor = platformActiveSelectionForegroundColor();
592     return m_activeSelectionForegroundColor;
593 }
594
595 Color RenderTheme::inactiveSelectionForegroundColor() const
596 {
597     if (!m_inactiveSelectionForegroundColor.isValid() && supportsSelectionForegroundColors())
598         m_inactiveSelectionForegroundColor = platformInactiveSelectionForegroundColor();
599     return m_inactiveSelectionForegroundColor;
600 }
601
602 Color RenderTheme::activeListBoxSelectionBackgroundColor() const
603 {
604     if (!m_activeListBoxSelectionBackgroundColor.isValid())
605         m_activeListBoxSelectionBackgroundColor = platformActiveListBoxSelectionBackgroundColor();
606     return m_activeListBoxSelectionBackgroundColor;
607 }
608
609 Color RenderTheme::inactiveListBoxSelectionBackgroundColor() const
610 {
611     if (!m_inactiveListBoxSelectionBackgroundColor.isValid())
612         m_inactiveListBoxSelectionBackgroundColor = platformInactiveListBoxSelectionBackgroundColor();
613     return m_inactiveListBoxSelectionBackgroundColor;
614 }
615
616 Color RenderTheme::activeListBoxSelectionForegroundColor() const
617 {
618     if (!m_activeListBoxSelectionForegroundColor.isValid() && supportsListBoxSelectionForegroundColors())
619         m_activeListBoxSelectionForegroundColor = platformActiveListBoxSelectionForegroundColor();
620     return m_activeListBoxSelectionForegroundColor;
621 }
622
623 Color RenderTheme::inactiveListBoxSelectionForegroundColor() const
624 {
625     if (!m_inactiveListBoxSelectionForegroundColor.isValid() && supportsListBoxSelectionForegroundColors())
626         m_inactiveListBoxSelectionForegroundColor = platformInactiveListBoxSelectionForegroundColor();
627     return m_inactiveListBoxSelectionForegroundColor;
628 }
629
630 Color RenderTheme::platformActiveSelectionBackgroundColor() const
631 {
632     // Use a blue color by default if the platform theme doesn't define anything.
633     return Color(0, 0, 255);
634 }
635
636 Color RenderTheme::platformActiveSelectionForegroundColor() const
637 {
638     // Use a white color by default if the platform theme doesn't define anything.
639     return Color::white;
640 }
641
642 Color RenderTheme::platformInactiveSelectionBackgroundColor() const
643 {
644     // Use a grey color by default if the platform theme doesn't define anything.
645     // This color matches Firefox's inactive color.
646     return Color(176, 176, 176);
647 }
648
649 Color RenderTheme::platformInactiveSelectionForegroundColor() const
650 {
651     // Use a black color by default.
652     return Color::black;
653 }
654
655 Color RenderTheme::platformActiveListBoxSelectionBackgroundColor() const
656 {
657     return platformActiveSelectionBackgroundColor();
658 }
659
660 Color RenderTheme::platformActiveListBoxSelectionForegroundColor() const
661 {
662     return platformActiveSelectionForegroundColor();
663 }
664
665 Color RenderTheme::platformInactiveListBoxSelectionBackgroundColor() const
666 {
667     return platformInactiveSelectionBackgroundColor();
668 }
669
670 Color RenderTheme::platformInactiveListBoxSelectionForegroundColor() const
671 {
672     return platformInactiveSelectionForegroundColor();
673 }
674
675 int RenderTheme::baselinePosition(const RenderObject& o) const
676 {
677     if (!o.isBox())
678         return 0;
679
680     const RenderBox& box = *toRenderBox(&o);
681
682 #if USE(NEW_THEME)
683     return box.height() + box.marginTop() + m_theme->baselinePositionAdjustment(o.style().appearance()) * o.style().effectiveZoom();
684 #else
685     return box.height() + box.marginTop();
686 #endif
687 }
688
689 bool RenderTheme::isControlContainer(ControlPart appearance) const
690 {
691     // There are more leaves than this, but we'll patch this function as we add support for
692     // more controls.
693     return appearance != CheckboxPart && appearance != RadioPart;
694 }
695
696 bool RenderTheme::isControlStyled(const RenderStyle* style, const BorderData& border, const FillLayer& background, const Color& backgroundColor) const
697 {
698     switch (style->appearance()) {
699     case PushButtonPart:
700     case SquareButtonPart:
701     case DefaultButtonPart:
702     case ButtonPart:
703     case ListboxPart:
704     case MenulistPart:
705     case ProgressBarPart:
706     case MeterPart:
707     case RelevancyLevelIndicatorPart:
708     case ContinuousCapacityLevelIndicatorPart:
709     case DiscreteCapacityLevelIndicatorPart:
710     case RatingLevelIndicatorPart:
711     // FIXME: SearchFieldPart should be included here when making search fields style-able.
712     case TextFieldPart:
713     case TextAreaPart:
714         // Test the style to see if the UA border and background match.
715         return (style->border() != border
716             || *style->backgroundLayers() != background
717             || style->visitedDependentColor(CSSPropertyBackgroundColor) != backgroundColor);
718     default:
719         return false;
720     }
721 }
722
723 void RenderTheme::adjustRepaintRect(const RenderObject& o, IntRect& r)
724 {
725 #if USE(NEW_THEME)
726     ControlStates states(extractControlStatesForRenderer(o));
727     m_theme->inflateControlPaintRect(o.style().appearance(), &states, r, o.style().effectiveZoom());
728 #else
729     UNUSED_PARAM(o);
730     UNUSED_PARAM(r);
731 #endif
732 }
733
734 bool RenderTheme::supportsFocusRing(const RenderStyle* style) const
735 {
736     return (style->hasAppearance() && style->appearance() != TextFieldPart && style->appearance() != TextAreaPart && style->appearance() != MenulistButtonPart && style->appearance() != ListboxPart);
737 }
738
739 bool RenderTheme::stateChanged(const RenderObject& o, ControlStates::States state) const
740 {
741     // Default implementation assumes the controls don't respond to changes in :hover state
742     if (state == ControlStates::HoverState && !supportsHover(&o.style()))
743         return false;
744
745     // Assume pressed state is only responded to if the control is enabled.
746     if (state == ControlStates::PressedState && !isEnabled(o))
747         return false;
748
749     // Repaint the control.
750     o.repaint();
751     return true;
752 }
753
754 void RenderTheme::updateControlStatesForRenderer(const RenderObject& o, ControlStates* controlStates) const
755 {
756     ControlStates newStates = extractControlStatesForRenderer(o);
757     controlStates->setStates(newStates.states());
758     if (isFocused(o))
759         controlStates->setTimeSinceControlWasFocused(o.document().page()->focusController().timeSinceFocusWasSet());
760 }
761
762 ControlStates::States RenderTheme::extractControlStatesForRenderer(const RenderObject& o) const
763 {
764     ControlStates::States states = 0;
765     if (isHovered(o)) {
766         states |= ControlStates::HoverState;
767         if (isSpinUpButtonPartHovered(o))
768             states |= ControlStates::SpinUpState;
769     }
770     if (isPressed(o)) {
771         states |= ControlStates::PressedState;
772         if (isSpinUpButtonPartPressed(o))
773             states |= ControlStates::SpinUpState;
774     }
775     if (isFocused(o) && o.style().outlineStyleIsAuto())
776         states |= ControlStates::FocusState;
777     if (isEnabled(o))
778         states |= ControlStates::EnabledState;
779     if (isChecked(o))
780         states |= ControlStates::CheckedState;
781     if (isReadOnlyControl(o))
782         states |= ControlStates::ReadOnlyState;
783     if (isDefault(o))
784         states |= ControlStates::DefaultState;
785     if (!isActive(o))
786         states |= ControlStates::WindowInactiveState;
787     if (isIndeterminate(o))
788         states |= ControlStates::IndeterminateState;
789     return states;
790 }
791
792 bool RenderTheme::isActive(const RenderObject& o) const
793 {
794     Node* node = o.node();
795     if (!node)
796         return false;
797
798     Frame* frame = node->document().frame();
799     if (!frame)
800         return false;
801
802     Page* page = frame->page();
803     if (!page)
804         return false;
805
806     return page->focusController().isActive();
807 }
808
809 bool RenderTheme::isChecked(const RenderObject& o) const
810 {
811     if (!o.node())
812         return false;
813
814     HTMLInputElement* inputElement = o.node()->toInputElement();
815     if (!inputElement)
816         return false;
817
818     return inputElement->shouldAppearChecked();
819 }
820
821 bool RenderTheme::isIndeterminate(const RenderObject& o) const
822 {
823     if (!o.node())
824         return false;
825
826     HTMLInputElement* inputElement = o.node()->toInputElement();
827     if (!inputElement)
828         return false;
829
830     return inputElement->shouldAppearIndeterminate();
831 }
832
833 bool RenderTheme::isEnabled(const RenderObject& o) const
834 {
835     Node* node = o.node();
836     if (!node || !node->isElementNode())
837         return true;
838     return !toElement(node)->isDisabledFormControl();
839 }
840
841 bool RenderTheme::isFocused(const RenderObject& o) const
842 {
843     Node* node = o.node();
844     if (!node || !node->isElementNode())
845         return false;
846
847     Element* focusDelegate = toElement(node)->focusDelegate();
848     Document& document = focusDelegate->document();
849     Frame* frame = document.frame();
850     return focusDelegate == document.focusedElement() && frame && frame->selection().isFocusedAndActive();
851 }
852
853 bool RenderTheme::isPressed(const RenderObject& o) const
854 {
855     if (!o.node() || !o.node()->isElementNode())
856         return false;
857     return toElement(o.node())->active();
858 }
859
860 bool RenderTheme::isSpinUpButtonPartPressed(const RenderObject& o) const
861 {
862     Node* node = o.node();
863     if (!node || !node->isElementNode())
864         return false;
865     Element* element = toElement(node);
866     if (!element->active() || !element->isSpinButtonElement())
867         return false;
868     return static_cast<SpinButtonElement*>(element)->upDownState() == SpinButtonElement::Up;
869 }
870
871 bool RenderTheme::isReadOnlyControl(const RenderObject& o) const
872 {
873     Node* node = o.node();
874     if (!node || !node->isElementNode())
875         return false;
876     return toElement(node)->matchesReadOnlyPseudoClass();
877 }
878
879 bool RenderTheme::isHovered(const RenderObject& o) const
880 {
881     Node* node = o.node();
882     if (!node || !node->isElementNode())
883         return false;
884     if (!toElement(node)->isSpinButtonElement())
885         return toElement(node)->hovered();
886     SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
887     return element->hovered() && element->upDownState() != SpinButtonElement::Indeterminate;
888 }
889
890 bool RenderTheme::isSpinUpButtonPartHovered(const RenderObject& o) const
891 {
892     Node* node = o.node();
893     if (!node || !node->isElementNode() || !toElement(node)->isSpinButtonElement())
894         return false;
895     SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
896     return element->upDownState() == SpinButtonElement::Up;
897 }
898
899 bool RenderTheme::isDefault(const RenderObject& o) const
900 {
901     // A button should only have the default appearance if the page is active
902     if (!isActive(o))
903         return false;
904
905     if (!o.frame().settings().applicationChromeMode())
906         return false;
907     
908     return o.style().appearance() == DefaultButtonPart;
909 }
910
911 #if !USE(NEW_THEME)
912
913 void RenderTheme::adjustCheckboxStyle(StyleResolver*, RenderStyle* style, Element*) const
914 {
915     // A summary of the rules for checkbox designed to match WinIE:
916     // width/height - honored (WinIE actually scales its control for small widths, but lets it overflow for small heights.)
917     // font-size - not honored (control has no text), but we use it to decide which control size to use.
918     setCheckboxSize(style);
919
920     // padding - not honored by WinIE, needs to be removed.
921     style->resetPadding();
922
923     // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
924     // for now, we will not honor it.
925     style->resetBorder();
926
927     style->setBoxShadow(nullptr);
928 }
929
930 void RenderTheme::adjustRadioStyle(StyleResolver*, RenderStyle* style, Element*) const
931 {
932     // A summary of the rules for checkbox designed to match WinIE:
933     // width/height - honored (WinIE actually scales its control for small widths, but lets it overflow for small heights.)
934     // font-size - not honored (control has no text), but we use it to decide which control size to use.
935     setRadioSize(style);
936
937     // padding - not honored by WinIE, needs to be removed.
938     style->resetPadding();
939
940     // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
941     // for now, we will not honor it.
942     style->resetBorder();
943
944     style->setBoxShadow(nullptr);
945 }
946
947 void RenderTheme::adjustButtonStyle(StyleResolver*, RenderStyle* style, Element*) const
948 {
949     // Most platforms will completely honor all CSS, and so we have no need to
950     // adjust the style at all by default. We will still allow the theme a crack
951     // at setting up a desired vertical size.
952     setButtonSize(style);
953 }
954
955 void RenderTheme::adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle*, Element*) const
956 {
957 }
958 #endif
959
960 void RenderTheme::adjustTextFieldStyle(StyleResolver*, RenderStyle*, Element*) const
961 {
962 }
963
964 void RenderTheme::adjustTextAreaStyle(StyleResolver*, RenderStyle*, Element*) const
965 {
966 }
967
968 void RenderTheme::adjustMenuListStyle(StyleResolver*, RenderStyle*, Element*) const
969 {
970 }
971
972 #if ENABLE(INPUT_SPEECH)
973 void RenderTheme::adjustInputFieldSpeechButtonStyle(StyleResolver* styleResolver, RenderStyle* style, Element* element) const
974 {
975     RenderInputSpeech::adjustInputFieldSpeechButtonStyle(styleResolver, style, element);
976 }
977
978 bool RenderTheme::paintInputFieldSpeechButton(const RenderObject& object, const PaintInfo& paintInfo, const IntRect& rect)
979 {
980     return RenderInputSpeech::paintInputFieldSpeechButton(object, paintInfo, rect);
981 }
982 #endif
983
984 #if ENABLE(METER_ELEMENT)
985 void RenderTheme::adjustMeterStyle(StyleResolver*, RenderStyle* style, Element*) const
986 {
987     style->setBoxShadow(nullptr);
988 }
989
990 IntSize RenderTheme::meterSizeForBounds(const RenderMeter*, const IntRect& bounds) const
991 {
992     return bounds.size();
993 }
994
995 bool RenderTheme::supportsMeter(ControlPart) const
996 {
997     return false;
998 }
999
1000 bool RenderTheme::paintMeter(const RenderObject&, const PaintInfo&, const IntRect&)
1001 {
1002     return true;
1003 }
1004
1005 #endif
1006
1007 #if ENABLE(DATALIST_ELEMENT)
1008 LayoutUnit RenderTheme::sliderTickSnappingThreshold() const
1009 {
1010     return 0;
1011 }
1012
1013 void RenderTheme::paintSliderTicks(const RenderObject& o, const PaintInfo& paintInfo, const IntRect& rect)
1014 {
1015     Node* node = o.node();
1016     if (!node)
1017         return;
1018
1019     HTMLInputElement* input = node->toInputElement();
1020     if (!input)
1021         return;
1022
1023     HTMLDataListElement* dataList = toHTMLDataListElement(input->list());
1024     if (!dataList)
1025         return;
1026
1027     double min = input->minimum();
1028     double max = input->maximum();
1029     ControlPart part = o.style().appearance();
1030     // We don't support ticks on alternate sliders like MediaVolumeSliders.
1031     if (part !=  SliderHorizontalPart && part != SliderVerticalPart)
1032         return;
1033     bool isHorizontal = part ==  SliderHorizontalPart;
1034
1035     IntSize thumbSize;
1036     const RenderObject* thumbRenderer = input->sliderThumbElement()->renderer();
1037     if (thumbRenderer) {
1038         const RenderStyle& thumbStyle = thumbRenderer->style();
1039         int thumbWidth = thumbStyle.width().intValue();
1040         int thumbHeight = thumbStyle.height().intValue();
1041         thumbSize.setWidth(isHorizontal ? thumbWidth : thumbHeight);
1042         thumbSize.setHeight(isHorizontal ? thumbHeight : thumbWidth);
1043     }
1044
1045     IntSize tickSize = sliderTickSize();
1046     float zoomFactor = o.style().effectiveZoom();
1047     FloatRect tickRect;
1048     int tickRegionSideMargin = 0;
1049     int tickRegionWidth = 0;
1050     IntRect trackBounds;
1051     RenderObject* trackRenderer = input->sliderTrackElement()->renderer();
1052     // We can ignoring transforms because transform is handled by the graphics context.
1053     if (trackRenderer)
1054         trackBounds = trackRenderer->absoluteBoundingBoxRectIgnoringTransforms();
1055     IntRect sliderBounds = o.absoluteBoundingBoxRectIgnoringTransforms();
1056
1057     // Make position relative to the transformed ancestor element.
1058     trackBounds.setX(trackBounds.x() - sliderBounds.x() + rect.x());
1059     trackBounds.setY(trackBounds.y() - sliderBounds.y() + rect.y());
1060
1061     if (isHorizontal) {
1062         tickRect.setWidth(floor(tickSize.width() * zoomFactor));
1063         tickRect.setHeight(floor(tickSize.height() * zoomFactor));
1064         tickRect.setY(floor(rect.y() + rect.height() / 2.0 + sliderTickOffsetFromTrackCenter() * zoomFactor));
1065         tickRegionSideMargin = trackBounds.x() + (thumbSize.width() - tickSize.width() * zoomFactor) / 2.0;
1066         tickRegionWidth = trackBounds.width() - thumbSize.width();
1067     } else {
1068         tickRect.setWidth(floor(tickSize.height() * zoomFactor));
1069         tickRect.setHeight(floor(tickSize.width() * zoomFactor));
1070         tickRect.setX(floor(rect.x() + rect.width() / 2.0 + sliderTickOffsetFromTrackCenter() * zoomFactor));
1071         tickRegionSideMargin = trackBounds.y() + (thumbSize.width() - tickSize.width() * zoomFactor) / 2.0;
1072         tickRegionWidth = trackBounds.height() - thumbSize.width();
1073     }
1074     RefPtr<HTMLCollection> options = dataList->options();
1075     GraphicsContextStateSaver stateSaver(*paintInfo.context);
1076     paintInfo.context->setFillColor(o.style().visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB);
1077     for (unsigned i = 0; Node* node = options->item(i); i++) {
1078         ASSERT(isHTMLOptionElement(node));
1079         HTMLOptionElement* optionElement = toHTMLOptionElement(node);
1080         String value = optionElement->value();
1081         if (!input->isValidValue(value))
1082             continue;
1083         double parsedValue = parseToDoubleForNumberType(input->sanitizeValue(value));
1084         double tickFraction = (parsedValue - min) / (max - min);
1085         double tickRatio = isHorizontal && o.style().isLeftToRightDirection() ? tickFraction : 1.0 - tickFraction;
1086         double tickPosition = round(tickRegionSideMargin + tickRegionWidth * tickRatio);
1087         if (isHorizontal)
1088             tickRect.setX(tickPosition);
1089         else
1090             tickRect.setY(tickPosition);
1091         paintInfo.context->fillRect(tickRect);
1092     }
1093 }
1094 #endif
1095
1096 #if ENABLE(PROGRESS_ELEMENT)
1097 double RenderTheme::animationRepeatIntervalForProgressBar(RenderProgress*) const
1098 {
1099     return 0;
1100 }
1101
1102 double RenderTheme::animationDurationForProgressBar(RenderProgress*) const
1103 {
1104     return 0;
1105 }
1106
1107 void RenderTheme::adjustProgressBarStyle(StyleResolver*, RenderStyle*, Element*) const
1108 {
1109 }
1110
1111 IntRect RenderTheme::progressBarRectForBounds(const RenderObject&, const IntRect& bounds) const
1112 {
1113     return bounds;
1114 }
1115 #endif
1116
1117 bool RenderTheme::shouldHaveSpinButton(HTMLInputElement* inputElement) const
1118 {
1119     return inputElement->isSteppable() && !inputElement->isRangeControl();
1120 }
1121
1122 void RenderTheme::adjustMenuListButtonStyle(StyleResolver*, RenderStyle*, Element*) const
1123 {
1124 }
1125
1126 void RenderTheme::adjustMediaControlStyle(StyleResolver*, RenderStyle*, Element*) const
1127 {
1128 }
1129
1130 void RenderTheme::adjustSliderTrackStyle(StyleResolver*, RenderStyle*, Element*) const
1131 {
1132 }
1133
1134 void RenderTheme::adjustSliderThumbStyle(StyleResolver*, RenderStyle* style, Element* element) const
1135 {
1136     adjustSliderThumbSize(style, element);
1137 }
1138
1139 void RenderTheme::adjustSliderThumbSize(RenderStyle*, Element*) const
1140 {
1141 }
1142
1143 void RenderTheme::adjustSearchFieldStyle(StyleResolver*, RenderStyle*, Element*) const
1144 {
1145 }
1146
1147 void RenderTheme::adjustSearchFieldCancelButtonStyle(StyleResolver*, RenderStyle*, Element*) const
1148 {
1149 }
1150
1151 void RenderTheme::adjustSearchFieldDecorationPartStyle(StyleResolver*, RenderStyle*, Element*) const
1152 {
1153 }
1154
1155 void RenderTheme::adjustSearchFieldResultsDecorationPartStyle(StyleResolver*, RenderStyle*, Element*) const
1156 {
1157 }
1158
1159 void RenderTheme::adjustSearchFieldResultsButtonStyle(StyleResolver*, RenderStyle*, Element*) const
1160 {
1161 }
1162
1163 void RenderTheme::platformColorsDidChange()
1164 {
1165     m_activeSelectionForegroundColor = Color();
1166     m_inactiveSelectionForegroundColor = Color();
1167     m_activeSelectionBackgroundColor = Color();
1168     m_inactiveSelectionBackgroundColor = Color();
1169
1170     m_activeListBoxSelectionForegroundColor = Color();
1171     m_inactiveListBoxSelectionForegroundColor = Color();
1172     m_activeListBoxSelectionBackgroundColor = Color();
1173     m_inactiveListBoxSelectionForegroundColor = Color();
1174
1175     Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment();
1176 }
1177
1178 Color RenderTheme::systemColor(CSSValueID cssValueId) const
1179 {
1180     switch (cssValueId) {
1181     case CSSValueActiveborder:
1182         return 0xFFFFFFFF;
1183     case CSSValueActivecaption:
1184         return 0xFFCCCCCC;
1185     case CSSValueAppworkspace:
1186         return 0xFFFFFFFF;
1187     case CSSValueBackground:
1188         return 0xFF6363CE;
1189     case CSSValueButtonface:
1190         return 0xFFC0C0C0;
1191     case CSSValueButtonhighlight:
1192         return 0xFFDDDDDD;
1193     case CSSValueButtonshadow:
1194         return 0xFF888888;
1195     case CSSValueButtontext:
1196         return 0xFF000000;
1197     case CSSValueCaptiontext:
1198         return 0xFF000000;
1199     case CSSValueGraytext:
1200         return 0xFF808080;
1201     case CSSValueHighlight:
1202         return 0xFFB5D5FF;
1203     case CSSValueHighlighttext:
1204         return 0xFF000000;
1205     case CSSValueInactiveborder:
1206         return 0xFFFFFFFF;
1207     case CSSValueInactivecaption:
1208         return 0xFFFFFFFF;
1209     case CSSValueInactivecaptiontext:
1210         return 0xFF7F7F7F;
1211     case CSSValueInfobackground:
1212         return 0xFFFBFCC5;
1213     case CSSValueInfotext:
1214         return 0xFF000000;
1215     case CSSValueMenu:
1216         return 0xFFC0C0C0;
1217     case CSSValueMenutext:
1218         return 0xFF000000;
1219     case CSSValueScrollbar:
1220         return 0xFFFFFFFF;
1221     case CSSValueText:
1222         return 0xFF000000;
1223     case CSSValueThreeddarkshadow:
1224         return 0xFF666666;
1225     case CSSValueThreedface:
1226         return 0xFFC0C0C0;
1227     case CSSValueThreedhighlight:
1228         return 0xFFDDDDDD;
1229     case CSSValueThreedlightshadow:
1230         return 0xFFC0C0C0;
1231     case CSSValueThreedshadow:
1232         return 0xFF888888;
1233     case CSSValueWindow:
1234         return 0xFFFFFFFF;
1235     case CSSValueWindowframe:
1236         return 0xFFCCCCCC;
1237     case CSSValueWindowtext:
1238         return 0xFF000000;
1239     default:
1240         break;
1241     }
1242     return Color();
1243 }
1244
1245 Color RenderTheme::platformActiveTextSearchHighlightColor() const
1246 {
1247     return Color(255, 150, 50); // Orange.
1248 }
1249
1250 Color RenderTheme::platformInactiveTextSearchHighlightColor() const
1251 {
1252     return Color(255, 255, 0); // Yellow.
1253 }
1254
1255 #if ENABLE(TOUCH_EVENTS)
1256 Color RenderTheme::tapHighlightColor()
1257 {
1258     return defaultTheme()->platformTapHighlightColor();
1259 }
1260 #endif
1261
1262 // Value chosen by observation. This can be tweaked.
1263 static const int minColorContrastValue = 1300;
1264 // For transparent or translucent background color, use lightening.
1265 static const int minDisabledColorAlphaValue = 128;
1266
1267 Color RenderTheme::disabledTextColor(const Color& textColor, const Color& backgroundColor) const
1268 {
1269     // The explicit check for black is an optimization for the 99% case (black on white).
1270     // This also means that black on black will turn into grey on black when disabled.
1271     Color disabledColor;
1272     if (textColor.rgb() == Color::black || backgroundColor.alpha() < minDisabledColorAlphaValue || differenceSquared(textColor, Color::white) > differenceSquared(backgroundColor, Color::white))
1273         disabledColor = textColor.light();
1274     else
1275         disabledColor = textColor.dark();
1276     
1277     // If there's not very much contrast between the disabled color and the background color,
1278     // just leave the text color alone. We don't want to change a good contrast color scheme so that it has really bad contrast.
1279     // If the the contrast was already poor, then it doesn't do any good to change it to a different poor contrast color scheme.
1280     if (differenceSquared(disabledColor, backgroundColor) < minColorContrastValue)
1281         return textColor;
1282     
1283     return disabledColor;
1284 }
1285
1286 void RenderTheme::setCustomFocusRingColor(const Color& c)
1287 {
1288     customFocusRingColor() = c;
1289 }
1290
1291 Color RenderTheme::focusRingColor()
1292 {
1293     return customFocusRingColor().isValid() ? customFocusRingColor() : defaultTheme()->platformFocusRingColor();
1294 }
1295
1296 String RenderTheme::fileListDefaultLabel(bool multipleFilesAllowed) const
1297 {
1298     if (multipleFilesAllowed)
1299         return fileButtonNoFilesSelectedLabel();
1300     return fileButtonNoFileSelectedLabel();
1301 }
1302
1303 String RenderTheme::fileListNameForWidth(const FileList* fileList, const Font& font, int width, bool multipleFilesAllowed) const
1304 {
1305     if (width <= 0)
1306         return String();
1307
1308     String string;
1309     if (fileList->isEmpty())
1310         string = fileListDefaultLabel(multipleFilesAllowed);
1311     else if (fileList->length() == 1)
1312         string = fileList->item(0)->name();
1313     else
1314         return StringTruncator::rightTruncate(multipleFileUploadText(fileList->length()), width, font, StringTruncator::EnableRoundingHacks);
1315
1316     return StringTruncator::centerTruncate(string, width, font, StringTruncator::EnableRoundingHacks);
1317 }
1318
1319 } // namespace WebCore