2 * This file is part of the theme implementation for form controls in WebCore.
4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Computer, Inc.
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.
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.
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.
23 #include "RenderTheme.h"
25 #include "CSSValueKeywords.h"
28 #include "FileSystem.h"
29 #include "FloatConversion.h"
30 #include "FocusController.h"
31 #include "FontSelector.h"
33 #include "FrameSelection.h"
34 #include "GraphicsContext.h"
35 #include "HTMLInputElement.h"
36 #include "HTMLNames.h"
37 #include "LocalizedStrings.h"
38 #include "MediaControlElements.h"
40 #include "PaintInfo.h"
41 #include "RenderStyle.h"
42 #include "RenderView.h"
44 #include "StringTruncator.h"
45 #include "TextControlInnerElements.h"
47 #if ENABLE(METER_ELEMENT)
48 #include "HTMLMeterElement.h"
49 #include "RenderMeter.h"
52 #if ENABLE(INPUT_SPEECH)
53 #include "RenderInputSpeech.h"
56 #if ENABLE(DATALIST_ELEMENT)
57 #include "ElementShadow.h"
58 #include "HTMLCollection.h"
59 #include "HTMLDataListElement.h"
60 #include "HTMLOptionElement.h"
61 #include "HTMLParserIdioms.h"
64 // The methods in this file are shared by all themes on every platform.
68 using namespace HTMLNames;
70 static Color& customFocusRingColor()
72 DEFINE_STATIC_LOCAL(Color, color, ());
76 RenderTheme::RenderTheme()
78 : m_theme(platformTheme())
83 void RenderTheme::adjustStyle(StyleResolver* styleResolver, RenderStyle* style, Element* e,
84 bool UAHasAppearance, const BorderData& border, const FillLayer& background, const Color& backgroundColor)
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() == RUN_IN || style->display() == LIST_ITEM || style->display() == TABLE)
94 style->setDisplay(BLOCK);
96 if (UAHasAppearance && isControlStyled(style, border, background, backgroundColor)) {
97 if (part == MenulistPart) {
98 style->setAppearance(MenulistButtonPart);
99 part = MenulistButtonPart;
101 style->setAppearance(NoControlPart);
104 if (!style->hasAppearance())
107 // Never support box-shadow on native controls.
108 style->setBoxShadow(nullptr);
113 case InnerSpinButtonPart:
116 case SquareButtonPart:
117 case DefaultButtonPart:
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());
126 style->resetBorderTop();
128 if (borderBox.right().value() != static_cast<int>(style->borderRightWidth())) {
129 if (borderBox.right().value())
130 style->setBorderRightWidth(borderBox.right().value());
132 style->resetBorderRight();
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());
139 style->resetBorderBottom();
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());
146 style->resetBorderLeft();
150 LengthBox paddingBox = m_theme->controlPadding(part, style->font(), style->paddingBox(), style->effectiveZoom());
151 if (paddingBox != style->paddingBox())
152 style->setPaddingBox(paddingBox);
155 if (m_theme->controlRequiresPreWhiteSpace(part))
156 style->setWhiteSpace(PRE);
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());
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());
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());
180 // Now update our font.
181 if (style->setFontDescription(controlFont))
182 style->font().update(0);
190 // Call the appropriate style adjustment method based off the appearance value.
191 switch (style->appearance()) {
194 return adjustCheckboxStyle(styleResolver, style, e);
196 return adjustRadioStyle(styleResolver, style, e);
198 case SquareButtonPart:
199 case DefaultButtonPart:
201 return adjustButtonStyle(styleResolver, style, e);
202 case InnerSpinButtonPart:
203 return adjustInnerSpinButtonStyle(styleResolver, style, e);
206 return adjustTextFieldStyle(styleResolver, style, e);
208 return adjustTextAreaStyle(styleResolver, style, e);
210 return adjustMenuListStyle(styleResolver, style, e);
211 case MenulistButtonPart:
212 return adjustMenuListButtonStyle(styleResolver, style, e);
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, e);
221 case MediaSliderPart:
222 case MediaVolumeSliderPart:
223 case MediaFullScreenVolumeSliderPart:
224 case SliderHorizontalPart:
225 case SliderVerticalPart:
226 return adjustSliderTrackStyle(styleResolver, style, e);
227 case SliderThumbHorizontalPart:
228 case SliderThumbVerticalPart:
229 return adjustSliderThumbStyle(styleResolver, style, e);
230 case SearchFieldPart:
231 return adjustSearchFieldStyle(styleResolver, style, e);
232 case SearchFieldCancelButtonPart:
233 return adjustSearchFieldCancelButtonStyle(styleResolver, style, e);
234 case SearchFieldDecorationPart:
235 return adjustSearchFieldDecorationStyle(styleResolver, style, e);
236 case SearchFieldResultsDecorationPart:
237 return adjustSearchFieldResultsDecorationStyle(styleResolver, style, e);
238 case SearchFieldResultsButtonPart:
239 return adjustSearchFieldResultsButtonStyle(styleResolver, style, e);
240 #if ENABLE(PROGRESS_ELEMENT)
241 case ProgressBarPart:
242 return adjustProgressBarStyle(styleResolver, style, e);
244 #if ENABLE(METER_ELEMENT)
246 case RelevancyLevelIndicatorPart:
247 case ContinuousCapacityLevelIndicatorPart:
248 case DiscreteCapacityLevelIndicatorPart:
249 case RatingLevelIndicatorPart:
250 return adjustMeterStyle(styleResolver, style, e);
252 #if ENABLE(INPUT_SPEECH)
253 case InputSpeechButtonPart:
254 return adjustInputFieldSpeechButtonStyle(styleResolver, style, e);
261 bool RenderTheme::paint(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
263 // If painting is disabled, but we aren't updating control tints, then just bail.
264 // If we are updating control tints, just schedule a repaint if the theme supports tinting
266 if (paintInfo.context->updatingControlTints()) {
267 if (controlSupportsTints(o))
271 if (paintInfo.context->paintingDisabled())
274 ControlPart part = o->style()->appearance();
281 case SquareButtonPart:
282 case DefaultButtonPart:
284 case InnerSpinButtonPart:
285 m_theme->paint(part, controlStatesForRenderer(o), const_cast<GraphicsContext*>(paintInfo.context), r, o->style()->effectiveZoom(), o->view()->frameView());
292 // Call the appropriate paint method based off the appearance value.
296 return paintCheckbox(o, paintInfo, r);
298 return paintRadio(o, paintInfo, r);
300 case SquareButtonPart:
301 case DefaultButtonPart:
303 return paintButton(o, paintInfo, r);
304 case InnerSpinButtonPart:
305 return paintInnerSpinButton(o, paintInfo, r);
308 return paintMenuList(o, paintInfo, r);
309 #if ENABLE(METER_ELEMENT)
311 case RelevancyLevelIndicatorPart:
312 case ContinuousCapacityLevelIndicatorPart:
313 case DiscreteCapacityLevelIndicatorPart:
314 case RatingLevelIndicatorPart:
315 return paintMeter(o, paintInfo, r);
317 #if ENABLE(PROGRESS_ELEMENT)
318 case ProgressBarPart:
319 return paintProgressBar(o, paintInfo, r);
321 case SliderHorizontalPart:
322 case SliderVerticalPart:
323 return paintSliderTrack(o, paintInfo, r);
324 case SliderThumbHorizontalPart:
325 case SliderThumbVerticalPart:
326 return paintSliderThumb(o, paintInfo, r);
327 case MediaEnterFullscreenButtonPart:
328 case MediaExitFullscreenButtonPart:
329 return paintMediaFullscreenButton(o, paintInfo, r);
330 case MediaPlayButtonPart:
331 return paintMediaPlayButton(o, paintInfo, r);
332 case MediaOverlayPlayButtonPart:
333 return paintMediaOverlayPlayButton(o, paintInfo, r);
334 case MediaMuteButtonPart:
335 return paintMediaMuteButton(o, paintInfo, r);
336 case MediaSeekBackButtonPart:
337 return paintMediaSeekBackButton(o, paintInfo, r);
338 case MediaSeekForwardButtonPart:
339 return paintMediaSeekForwardButton(o, paintInfo, r);
340 case MediaRewindButtonPart:
341 return paintMediaRewindButton(o, paintInfo, r);
342 case MediaReturnToRealtimeButtonPart:
343 return paintMediaReturnToRealtimeButton(o, paintInfo, r);
344 case MediaToggleClosedCaptionsButtonPart:
345 return paintMediaToggleClosedCaptionsButton(o, paintInfo, r);
346 case MediaSliderPart:
347 return paintMediaSliderTrack(o, paintInfo, r);
348 case MediaSliderThumbPart:
349 return paintMediaSliderThumb(o, paintInfo, r);
350 case MediaVolumeSliderMuteButtonPart:
351 return paintMediaMuteButton(o, paintInfo, r);
352 case MediaVolumeSliderContainerPart:
353 return paintMediaVolumeSliderContainer(o, paintInfo, r);
354 case MediaVolumeSliderPart:
355 return paintMediaVolumeSliderTrack(o, paintInfo, r);
356 case MediaVolumeSliderThumbPart:
357 return paintMediaVolumeSliderThumb(o, paintInfo, r);
358 case MediaFullScreenVolumeSliderPart:
359 return paintMediaFullScreenVolumeSliderTrack(o, paintInfo, r);
360 case MediaFullScreenVolumeSliderThumbPart:
361 return paintMediaFullScreenVolumeSliderThumb(o, paintInfo, r);
362 case MediaTimeRemainingPart:
363 return paintMediaTimeRemaining(o, paintInfo, r);
364 case MediaCurrentTimePart:
365 return paintMediaCurrentTime(o, paintInfo, r);
366 case MediaControlsBackgroundPart:
367 return paintMediaControlsBackground(o, paintInfo, r);
368 case MenulistButtonPart:
373 case SearchFieldPart:
374 return paintSearchField(o, paintInfo, r);
375 case SearchFieldCancelButtonPart:
376 return paintSearchFieldCancelButton(o, paintInfo, r);
377 case SearchFieldDecorationPart:
378 return paintSearchFieldDecoration(o, paintInfo, r);
379 case SearchFieldResultsDecorationPart:
380 return paintSearchFieldResultsDecoration(o, paintInfo, r);
381 case SearchFieldResultsButtonPart:
382 return paintSearchFieldResultsButton(o, paintInfo, r);
383 #if ENABLE(INPUT_SPEECH)
384 case InputSpeechButtonPart:
385 return paintInputFieldSpeechButton(o, paintInfo, r);
391 return true; // We don't support the appearance, so let the normal background/border paint.
394 bool RenderTheme::paintBorderOnly(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
396 if (paintInfo.context->paintingDisabled())
399 // Call the appropriate paint method based off the appearance value.
400 switch (o->style()->appearance()) {
402 return paintTextField(o, paintInfo, r);
405 return paintTextArea(o, paintInfo, r);
406 case MenulistButtonPart:
407 case SearchFieldPart:
412 case SquareButtonPart:
413 case DefaultButtonPart:
416 #if ENABLE(METER_ELEMENT)
418 case RelevancyLevelIndicatorPart:
419 case ContinuousCapacityLevelIndicatorPart:
420 case DiscreteCapacityLevelIndicatorPart:
421 case RatingLevelIndicatorPart:
423 #if ENABLE(PROGRESS_ELEMENT)
424 case ProgressBarPart:
426 case SliderHorizontalPart:
427 case SliderVerticalPart:
428 case SliderThumbHorizontalPart:
429 case SliderThumbVerticalPart:
430 case SearchFieldCancelButtonPart:
431 case SearchFieldDecorationPart:
432 case SearchFieldResultsDecorationPart:
433 case SearchFieldResultsButtonPart:
434 #if ENABLE(INPUT_SPEECH)
435 case InputSpeechButtonPart:
444 bool RenderTheme::paintDecorations(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
446 if (paintInfo.context->paintingDisabled())
449 // Call the appropriate paint method based off the appearance value.
450 switch (o->style()->appearance()) {
451 case MenulistButtonPart:
452 return paintMenuListButton(o, paintInfo, r);
459 case SquareButtonPart:
460 case DefaultButtonPart:
463 #if ENABLE(METER_ELEMENT)
465 case RelevancyLevelIndicatorPart:
466 case ContinuousCapacityLevelIndicatorPart:
467 case DiscreteCapacityLevelIndicatorPart:
468 case RatingLevelIndicatorPart:
470 #if ENABLE(PROGRESS_ELEMENT)
471 case ProgressBarPart:
473 case SliderHorizontalPart:
474 case SliderVerticalPart:
475 case SliderThumbHorizontalPart:
476 case SliderThumbVerticalPart:
477 case SearchFieldPart:
478 case SearchFieldCancelButtonPart:
479 case SearchFieldDecorationPart:
480 case SearchFieldResultsDecorationPart:
481 case SearchFieldResultsButtonPart:
482 #if ENABLE(INPUT_SPEECH)
483 case InputSpeechButtonPart:
494 String RenderTheme::formatMediaControlsTime(float time) const
498 int seconds = (int)fabsf(time);
499 int hours = seconds / (60 * 60);
500 int minutes = (seconds / 60) % 60;
504 return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
506 return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
509 return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
512 String RenderTheme::formatMediaControlsCurrentTime(float currentTime, float /*duration*/) const
514 return formatMediaControlsTime(currentTime);
517 String RenderTheme::formatMediaControlsRemainingTime(float currentTime, float duration) const
519 return formatMediaControlsTime(currentTime - duration);
522 IntPoint RenderTheme::volumeSliderOffsetFromMuteButton(RenderBox* muteButtonBox, const IntSize& size) const
524 int y = -size.height();
525 FloatPoint absPoint = muteButtonBox->localToAbsolute(FloatPoint(muteButtonBox->pixelSnappedOffsetLeft(), y), true, true);
526 if (absPoint.y() < 0)
527 y = muteButtonBox->height();
528 return IntPoint(0, y);
533 Color RenderTheme::activeSelectionBackgroundColor() const
535 if (!m_activeSelectionBackgroundColor.isValid())
536 m_activeSelectionBackgroundColor = platformActiveSelectionBackgroundColor().blendWithWhite();
537 return m_activeSelectionBackgroundColor;
540 Color RenderTheme::inactiveSelectionBackgroundColor() const
542 if (!m_inactiveSelectionBackgroundColor.isValid())
543 m_inactiveSelectionBackgroundColor = platformInactiveSelectionBackgroundColor().blendWithWhite();
544 return m_inactiveSelectionBackgroundColor;
547 Color RenderTheme::activeSelectionForegroundColor() const
549 if (!m_activeSelectionForegroundColor.isValid() && supportsSelectionForegroundColors())
550 m_activeSelectionForegroundColor = platformActiveSelectionForegroundColor();
551 return m_activeSelectionForegroundColor;
554 Color RenderTheme::inactiveSelectionForegroundColor() const
556 if (!m_inactiveSelectionForegroundColor.isValid() && supportsSelectionForegroundColors())
557 m_inactiveSelectionForegroundColor = platformInactiveSelectionForegroundColor();
558 return m_inactiveSelectionForegroundColor;
561 Color RenderTheme::activeListBoxSelectionBackgroundColor() const
563 if (!m_activeListBoxSelectionBackgroundColor.isValid())
564 m_activeListBoxSelectionBackgroundColor = platformActiveListBoxSelectionBackgroundColor();
565 return m_activeListBoxSelectionBackgroundColor;
568 Color RenderTheme::inactiveListBoxSelectionBackgroundColor() const
570 if (!m_inactiveListBoxSelectionBackgroundColor.isValid())
571 m_inactiveListBoxSelectionBackgroundColor = platformInactiveListBoxSelectionBackgroundColor();
572 return m_inactiveListBoxSelectionBackgroundColor;
575 Color RenderTheme::activeListBoxSelectionForegroundColor() const
577 if (!m_activeListBoxSelectionForegroundColor.isValid() && supportsListBoxSelectionForegroundColors())
578 m_activeListBoxSelectionForegroundColor = platformActiveListBoxSelectionForegroundColor();
579 return m_activeListBoxSelectionForegroundColor;
582 Color RenderTheme::inactiveListBoxSelectionForegroundColor() const
584 if (!m_inactiveListBoxSelectionForegroundColor.isValid() && supportsListBoxSelectionForegroundColors())
585 m_inactiveListBoxSelectionForegroundColor = platformInactiveListBoxSelectionForegroundColor();
586 return m_inactiveListBoxSelectionForegroundColor;
589 Color RenderTheme::platformActiveSelectionBackgroundColor() const
591 // Use a blue color by default if the platform theme doesn't define anything.
592 return Color(0, 0, 255);
595 Color RenderTheme::platformActiveSelectionForegroundColor() const
597 // Use a white color by default if the platform theme doesn't define anything.
601 Color RenderTheme::platformInactiveSelectionBackgroundColor() const
603 // Use a grey color by default if the platform theme doesn't define anything.
604 // This color matches Firefox's inactive color.
605 return Color(176, 176, 176);
608 Color RenderTheme::platformInactiveSelectionForegroundColor() const
610 // Use a black color by default.
614 Color RenderTheme::platformActiveListBoxSelectionBackgroundColor() const
616 return platformActiveSelectionBackgroundColor();
619 Color RenderTheme::platformActiveListBoxSelectionForegroundColor() const
621 return platformActiveSelectionForegroundColor();
624 Color RenderTheme::platformInactiveListBoxSelectionBackgroundColor() const
626 return platformInactiveSelectionBackgroundColor();
629 Color RenderTheme::platformInactiveListBoxSelectionForegroundColor() const
631 return platformInactiveSelectionForegroundColor();
634 #if ENABLE(CALENDAR_PICKER)
635 CString RenderTheme::extraCalendarPickerStyleSheet()
641 LayoutUnit RenderTheme::baselinePosition(const RenderObject* o) const
646 const RenderBox* box = toRenderBox(o);
649 return box->height() + box->marginTop() + m_theme->baselinePositionAdjustment(o->style()->appearance()) * o->style()->effectiveZoom();
651 return box->height() + box->marginTop();
655 bool RenderTheme::isControlContainer(ControlPart appearance) const
657 // There are more leaves than this, but we'll patch this function as we add support for
659 return appearance != CheckboxPart && appearance != RadioPart;
662 bool RenderTheme::isControlStyled(const RenderStyle* style, const BorderData& border, const FillLayer& background,
663 const Color& backgroundColor) const
665 switch (style->appearance()) {
667 case SquareButtonPart:
668 case DefaultButtonPart:
672 case ProgressBarPart:
674 case RelevancyLevelIndicatorPart:
675 case ContinuousCapacityLevelIndicatorPart:
676 case DiscreteCapacityLevelIndicatorPart:
677 case RatingLevelIndicatorPart:
678 #if ENABLE(TIZEN_SEARCH_FIELD_STYLE)
679 case SearchFieldPart:
681 // FIXME: Uncomment this when making search fields style-able.
682 // case SearchFieldPart:
686 // Test the style to see if the UA border and background match.
687 return (style->border() != border ||
688 *style->backgroundLayers() != background ||
689 style->visitedDependentColor(CSSPropertyBackgroundColor) != backgroundColor);
695 void RenderTheme::adjustRepaintRect(const RenderObject* o, IntRect& r)
698 m_theme->inflateControlPaintRect(o->style()->appearance(), controlStatesForRenderer(o), r, o->style()->effectiveZoom());
702 bool RenderTheme::supportsFocusRing(const RenderStyle* style) const
704 return (style->hasAppearance() && style->appearance() != TextFieldPart && style->appearance() != TextAreaPart && style->appearance() != MenulistButtonPart && style->appearance() != ListboxPart);
707 bool RenderTheme::stateChanged(RenderObject* o, ControlState state) const
709 // Default implementation assumes the controls don't respond to changes in :hover state
710 if (state == HoverState && !supportsHover(o->style()))
713 // Assume pressed state is only responded to if the control is enabled.
714 if (state == PressedState && !isEnabled(o))
717 // Repaint the control.
722 ControlStates RenderTheme::controlStatesForRenderer(const RenderObject* o) const
724 ControlStates result = 0;
726 result |= HoverState;
727 if (isSpinUpButtonPartHovered(o))
728 result |= SpinUpState;
731 result |= PressedState;
732 if (isSpinUpButtonPartPressed(o))
733 result |= SpinUpState;
735 if (isFocused(o) && o->style()->outlineStyleIsAuto())
736 result |= FocusState;
738 result |= EnabledState;
740 result |= CheckedState;
741 if (isReadOnlyControl(o))
742 result |= ReadOnlyState;
744 result |= DefaultState;
746 result |= WindowInactiveState;
747 if (isIndeterminate(o))
748 result |= IndeterminateState;
752 bool RenderTheme::isActive(const RenderObject* o) const
754 Node* node = o->node();
758 Frame* frame = node->document()->frame();
762 Page* page = frame->page();
766 return page->focusController()->isActive();
769 bool RenderTheme::isChecked(const RenderObject* o) const
774 HTMLInputElement* inputElement = o->node()->toInputElement();
778 return inputElement->shouldAppearChecked();
781 bool RenderTheme::isIndeterminate(const RenderObject* o) const
786 HTMLInputElement* inputElement = o->node()->toInputElement();
790 return inputElement->isIndeterminate();
793 bool RenderTheme::isEnabled(const RenderObject* o) const
795 Node* node = o->node();
796 if (!node || !node->isElementNode())
798 return static_cast<Element*>(node)->isEnabledFormControl();
801 bool RenderTheme::isFocused(const RenderObject* o) const
803 Node* node = o->node();
807 node = node->focusDelegate();
808 Document* document = node->document();
809 Frame* frame = document->frame();
810 return node == document->focusedNode() && frame && frame->selection()->isFocusedAndActive();
813 bool RenderTheme::isPressed(const RenderObject* o) const
817 return o->node()->active();
820 bool RenderTheme::isSpinUpButtonPartPressed(const RenderObject* o) const
822 Node* node = o->node();
823 if (!node || !node->active() || !node->isElementNode()
824 || !static_cast<Element*>(node)->isSpinButtonElement())
826 SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
827 return element->upDownState() == SpinButtonElement::Up;
830 bool RenderTheme::isReadOnlyControl(const RenderObject* o) const
832 Node* node = o->node();
833 if (!node || !node->isElementNode())
835 return static_cast<Element*>(node)->isReadOnlyFormControl();
838 bool RenderTheme::isHovered(const RenderObject* o) const
840 Node* node = o->node();
843 if (!node->isElementNode() || !static_cast<Element*>(node)->isSpinButtonElement())
844 return node->hovered();
845 SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
846 return element->hovered() && element->upDownState() != SpinButtonElement::Indeterminate;
849 bool RenderTheme::isSpinUpButtonPartHovered(const RenderObject* o) const
851 Node* node = o->node();
852 if (!node || !node->isElementNode() || !static_cast<Element*>(node)->isSpinButtonElement())
854 SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
855 return element->upDownState() == SpinButtonElement::Up;
858 bool RenderTheme::isDefault(const RenderObject* o) const
860 // A button should only have the default appearance if the page is active
867 Settings* settings = o->document()->settings();
868 if (!settings || !settings->inApplicationChromeMode())
871 return o->style()->appearance() == DefaultButtonPart;
876 void RenderTheme::adjustCheckboxStyle(StyleResolver*, RenderStyle* style, Element*) const
878 // A summary of the rules for checkbox designed to match WinIE:
879 // width/height - honored (WinIE actually scales its control for small widths, but lets it overflow for small heights.)
880 // font-size - not honored (control has no text), but we use it to decide which control size to use.
881 setCheckboxSize(style);
883 // padding - not honored by WinIE, needs to be removed.
884 style->resetPadding();
886 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
887 // for now, we will not honor it.
888 style->resetBorder();
890 style->setBoxShadow(nullptr);
893 void RenderTheme::adjustRadioStyle(StyleResolver*, RenderStyle* style, Element*) const
895 // A summary of the rules for checkbox designed to match WinIE:
896 // width/height - honored (WinIE actually scales its control for small widths, but lets it overflow for small heights.)
897 // font-size - not honored (control has no text), but we use it to decide which control size to use.
900 // padding - not honored by WinIE, needs to be removed.
901 style->resetPadding();
903 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
904 // for now, we will not honor it.
905 style->resetBorder();
907 style->setBoxShadow(nullptr);
910 void RenderTheme::adjustButtonStyle(StyleResolver*, RenderStyle* style, Element*) const
912 // Most platforms will completely honor all CSS, and so we have no need to adjust the style
913 // at all by default. We will still allow the theme a crack at setting up a desired vertical size.
914 setButtonSize(style);
917 void RenderTheme::adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle*, Element*) const
922 void RenderTheme::adjustTextFieldStyle(StyleResolver*, RenderStyle*, Element*) const
926 void RenderTheme::adjustTextAreaStyle(StyleResolver*, RenderStyle*, Element*) const
930 void RenderTheme::adjustMenuListStyle(StyleResolver*, RenderStyle*, Element*) const
934 #if ENABLE(INPUT_SPEECH)
935 void RenderTheme::adjustInputFieldSpeechButtonStyle(StyleResolver* styleResolver, RenderStyle* style, Element* element) const
937 RenderInputSpeech::adjustInputFieldSpeechButtonStyle(styleResolver, style, element);
940 bool RenderTheme::paintInputFieldSpeechButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
942 return RenderInputSpeech::paintInputFieldSpeechButton(object, paintInfo, rect);
946 #if ENABLE(METER_ELEMENT)
947 void RenderTheme::adjustMeterStyle(StyleResolver*, RenderStyle* style, Element*) const
949 style->setBoxShadow(nullptr);
952 IntSize RenderTheme::meterSizeForBounds(const RenderMeter*, const IntRect& bounds) const
954 return bounds.size();
957 bool RenderTheme::supportsMeter(ControlPart) const
962 bool RenderTheme::paintMeter(RenderObject*, const PaintInfo&, const IntRect&)
969 #if ENABLE(DATALIST_ELEMENT)
970 void RenderTheme::paintSliderTicks(RenderObject* o, const PaintInfo& paintInfo, const IntRect& rect)
972 Node* node = o->node();
976 HTMLInputElement* input = node->toInputElement();
980 HTMLDataListElement* dataList = static_cast<HTMLDataListElement*>(input->list());
984 double min = input->minimum();
985 double max = input->maximum();
986 ControlPart part = o->style()->appearance();
987 // We don't support ticks on alternate sliders like MediaVolumeSliders.
988 if (part != SliderHorizontalPart && part != SliderVerticalPart)
990 bool isHorizontal = part == SliderHorizontalPart;
993 RenderObject* thumbRenderer = input->sliderThumbElement()->renderer();
995 RenderStyle* thumbStyle = thumbRenderer->style();
996 int thumbWidth = thumbStyle->width().intValue();
997 int thumbHeight = thumbStyle->height().intValue();
998 thumbSize.setWidth(isHorizontal ? thumbWidth : thumbHeight);
999 thumbSize.setHeight(isHorizontal ? thumbHeight : thumbWidth);
1002 IntSize tickSize = sliderTickSize();
1003 float zoomFactor = o->style()->effectiveZoom();
1005 int tickRegionMargin = (thumbSize.width() - tickSize.width()) / 2.0;
1006 int tickRegionSideMargin = 0;
1007 int tickRegionWidth = 0;
1009 tickRect.setWidth(floor(tickSize.width() * zoomFactor));
1010 tickRect.setHeight(floor(tickSize.height() * zoomFactor));
1011 tickRect.setY(floor(rect.y() + rect.height() / 2.0 + sliderTickOffsetFromTrackCenter() * zoomFactor));
1012 tickRegionSideMargin = rect.x() + tickRegionMargin;
1013 tickRegionWidth = rect.width() - tickRegionMargin * 2 - tickSize.width() * zoomFactor;
1015 tickRect.setWidth(floor(tickSize.height() * zoomFactor));
1016 tickRect.setHeight(floor(tickSize.width() * zoomFactor));
1017 tickRect.setX(floor(rect.x() + rect.width() / 2.0 + sliderTickOffsetFromTrackCenter() * zoomFactor));
1018 tickRegionSideMargin = rect.y() + tickRegionMargin;
1019 tickRegionWidth = rect.height() - tickRegionMargin * 2 - tickSize.width() * zoomFactor;
1021 RefPtr<HTMLCollection> options = dataList->options();
1022 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1023 paintInfo.context->setFillColor(o->style()->visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB);
1024 for (unsigned i = 0; Node* node = options->item(i); i++) {
1025 ASSERT(node->hasTagName(optionTag));
1026 HTMLOptionElement* optionElement = static_cast<HTMLOptionElement*>(node);
1027 String value = optionElement->value();
1028 if (!input->isValidValue(value))
1030 double parsedValue = parseToDoubleForNumberType(input->sanitizeValue(value));
1031 double tickPosition = (parsedValue - min) / (max - min);
1032 if (!o->style()->isLeftToRightDirection())
1033 tickPosition = 1.0 - tickPosition;
1035 tickRect.setX(floor(tickRegionSideMargin + tickRegionWidth * tickPosition));
1037 tickRect.setY(floor(tickRegionSideMargin + tickRegionWidth * tickPosition));
1038 paintInfo.context->fillRect(tickRect);
1043 #if ENABLE(PROGRESS_ELEMENT)
1044 double RenderTheme::animationRepeatIntervalForProgressBar(RenderProgress*) const
1049 double RenderTheme::animationDurationForProgressBar(RenderProgress*) const
1054 void RenderTheme::adjustProgressBarStyle(StyleResolver*, RenderStyle*, Element*) const
1059 bool RenderTheme::shouldHaveSpinButton(HTMLInputElement* inputElement) const
1061 return inputElement->isSteppable() && !inputElement->isRangeControl();
1064 void RenderTheme::adjustMenuListButtonStyle(StyleResolver*, RenderStyle*, Element*) const
1068 void RenderTheme::adjustMediaControlStyle(StyleResolver*, RenderStyle*, Element*) const
1072 void RenderTheme::adjustSliderTrackStyle(StyleResolver*, RenderStyle*, Element*) const
1076 void RenderTheme::adjustSliderThumbStyle(StyleResolver*, RenderStyle* style, Element* element) const
1078 adjustSliderThumbSize(style, element);
1081 void RenderTheme::adjustSliderThumbSize(RenderStyle*, Element*) const
1085 void RenderTheme::adjustSearchFieldStyle(StyleResolver*, RenderStyle*, Element*) const
1089 void RenderTheme::adjustSearchFieldCancelButtonStyle(StyleResolver*, RenderStyle*, Element*) const
1093 void RenderTheme::adjustSearchFieldDecorationStyle(StyleResolver*, RenderStyle*, Element*) const
1097 void RenderTheme::adjustSearchFieldResultsDecorationStyle(StyleResolver*, RenderStyle*, Element*) const
1101 void RenderTheme::adjustSearchFieldResultsButtonStyle(StyleResolver*, RenderStyle*, Element*) const
1105 void RenderTheme::platformColorsDidChange()
1107 m_activeSelectionForegroundColor = Color();
1108 m_inactiveSelectionForegroundColor = Color();
1109 m_activeSelectionBackgroundColor = Color();
1110 m_inactiveSelectionBackgroundColor = Color();
1112 m_activeListBoxSelectionForegroundColor = Color();
1113 m_inactiveListBoxSelectionForegroundColor = Color();
1114 m_activeListBoxSelectionBackgroundColor = Color();
1115 m_inactiveListBoxSelectionForegroundColor = Color();
1117 Page::scheduleForcedStyleRecalcForAllPages();
1120 Color RenderTheme::systemColor(int cssValueId) const
1122 switch (cssValueId) {
1123 case CSSValueActiveborder:
1125 case CSSValueActivecaption:
1127 case CSSValueAppworkspace:
1129 case CSSValueBackground:
1131 case CSSValueButtonface:
1133 case CSSValueButtonhighlight:
1135 case CSSValueButtonshadow:
1137 case CSSValueButtontext:
1139 case CSSValueCaptiontext:
1141 case CSSValueGraytext:
1143 case CSSValueHighlight:
1145 case CSSValueHighlighttext:
1147 case CSSValueInactiveborder:
1149 case CSSValueInactivecaption:
1151 case CSSValueInactivecaptiontext:
1153 case CSSValueInfobackground:
1155 case CSSValueInfotext:
1159 case CSSValueMenutext:
1161 case CSSValueScrollbar:
1165 case CSSValueThreeddarkshadow:
1167 case CSSValueThreedface:
1169 case CSSValueThreedhighlight:
1171 case CSSValueThreedlightshadow:
1173 case CSSValueThreedshadow:
1175 case CSSValueWindow:
1177 case CSSValueWindowframe:
1179 case CSSValueWindowtext:
1185 Color RenderTheme::platformActiveTextSearchHighlightColor() const
1187 return Color(255, 150, 50); // Orange.
1190 Color RenderTheme::platformInactiveTextSearchHighlightColor() const
1192 return Color(255, 255, 0); // Yellow.
1195 #if ENABLE(TOUCH_EVENTS)
1196 Color RenderTheme::tapHighlightColor()
1198 return defaultTheme()->platformTapHighlightColor();
1202 // Value chosen by observation. This can be tweaked.
1203 static const int minColorContrastValue = 1300;
1204 // For transparent or translucent background color, use lightening.
1205 static const int minDisabledColorAlphaValue = 128;
1207 Color RenderTheme::disabledTextColor(const Color& textColor, const Color& backgroundColor) const
1209 // The explicit check for black is an optimization for the 99% case (black on white).
1210 // This also means that black on black will turn into grey on black when disabled.
1211 Color disabledColor;
1212 if (textColor.rgb() == Color::black || backgroundColor.alpha() < minDisabledColorAlphaValue || differenceSquared(textColor, Color::white) > differenceSquared(backgroundColor, Color::white))
1213 disabledColor = textColor.light();
1215 disabledColor = textColor.dark();
1217 // If there's not very much contrast between the disabled color and the background color,
1218 // just leave the text color alone. We don't want to change a good contrast color scheme so that it has really bad contrast.
1219 // If the the contrast was already poor, then it doesn't do any good to change it to a different poor contrast color scheme.
1220 if (differenceSquared(disabledColor, backgroundColor) < minColorContrastValue)
1223 return disabledColor;
1226 void RenderTheme::setCustomFocusRingColor(const Color& c)
1228 customFocusRingColor() = c;
1231 Color RenderTheme::focusRingColor()
1233 return customFocusRingColor().isValid() ? customFocusRingColor() : defaultTheme()->platformFocusRingColor();
1236 String RenderTheme::fileListDefaultLabel(bool multipleFilesAllowed) const
1238 if (multipleFilesAllowed)
1239 return fileButtonNoFilesSelectedLabel();
1240 return fileButtonNoFileSelectedLabel();
1243 String RenderTheme::fileListNameForWidth(const FileList* fileList, const Font& font, int width, bool multipleFilesAllowed) const
1249 if (fileList->isEmpty())
1250 string = fileListDefaultLabel(multipleFilesAllowed);
1251 else if (fileList->length() == 1)
1252 string = fileList->item(0)->name();
1254 return StringTruncator::rightTruncate(multipleFileUploadText(fileList->length()), width, font, StringTruncator::EnableRoundingHacks);
1256 return StringTruncator::centerTruncate(string, width, font, StringTruncator::EnableRoundingHacks);
1259 } // namespace WebCore