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