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 "core/rendering/RenderTheme.h"
25 #include "core/CSSValueKeywords.h"
26 #include "core/HTMLNames.h"
27 #include "core/InputTypeNames.h"
28 #include "core/dom/Document.h"
29 #include "core/dom/shadow/ElementShadow.h"
30 #include "core/editing/FrameSelection.h"
31 #include "core/fileapi/FileList.h"
32 #include "core/frame/LocalFrame.h"
33 #include "core/html/HTMLCollection.h"
34 #include "core/html/HTMLDataListElement.h"
35 #include "core/html/HTMLFormControlElement.h"
36 #include "core/html/HTMLInputElement.h"
37 #include "core/html/HTMLMeterElement.h"
38 #include "core/html/HTMLOptionElement.h"
39 #include "core/html/parser/HTMLParserIdioms.h"
40 #include "core/html/shadow/MediaControlElements.h"
41 #include "core/html/shadow/ShadowElementNames.h"
42 #include "core/html/shadow/SpinButtonElement.h"
43 #include "core/html/shadow/TextControlInnerElements.h"
44 #include "core/page/FocusController.h"
45 #include "core/page/Page.h"
46 #include "core/frame/Settings.h"
47 #include "core/rendering/PaintInfo.h"
48 #include "core/rendering/RenderMeter.h"
49 #include "core/rendering/RenderView.h"
50 #include "core/rendering/style/RenderStyle.h"
51 #include "platform/FileMetadata.h"
52 #include "platform/FloatConversion.h"
53 #include "platform/RuntimeEnabledFeatures.h"
54 #include "platform/fonts/FontSelector.h"
55 #include "platform/graphics/GraphicsContextStateSaver.h"
56 #include "platform/text/PlatformLocale.h"
57 #include "platform/text/StringTruncator.h"
58 #include "public/platform/Platform.h"
59 #include "public/platform/WebFallbackThemeEngine.h"
60 #include "public/platform/WebRect.h"
61 #include "wtf/text/StringBuilder.h"
63 // The methods in this file are shared by all themes on every platform.
67 using namespace HTMLNames;
69 static WebFallbackThemeEngine::State getWebFallbackThemeState(const RenderTheme* theme, const RenderObject* o)
71 if (!theme->isEnabled(o))
72 return WebFallbackThemeEngine::StateDisabled;
73 if (theme->isPressed(o))
74 return WebFallbackThemeEngine::StatePressed;
75 if (theme->isHovered(o))
76 return WebFallbackThemeEngine::StateHover;
78 return WebFallbackThemeEngine::StateNormal;
81 RenderTheme::RenderTheme()
82 : m_hasCustomFocusRingColor(false)
84 , m_platformTheme(platformTheme())
89 void RenderTheme::adjustStyle(RenderStyle* style, Element* e, const CachedUAStyle* uaStyle)
91 // Force inline and table display styles to be inline-block (except for table- which is block)
92 ControlPart part = style->appearance();
93 if (style->display() == INLINE || style->display() == INLINE_TABLE || style->display() == TABLE_ROW_GROUP
94 || style->display() == TABLE_HEADER_GROUP || style->display() == TABLE_FOOTER_GROUP
95 || style->display() == TABLE_ROW || style->display() == TABLE_COLUMN_GROUP || style->display() == TABLE_COLUMN
96 || style->display() == TABLE_CELL || style->display() == TABLE_CAPTION)
97 style->setDisplay(INLINE_BLOCK);
98 else if (style->display() == LIST_ITEM || style->display() == TABLE)
99 style->setDisplay(BLOCK);
101 if (uaStyle && uaStyle->hasAppearance && isControlStyled(style, uaStyle)) {
102 if (part == MenulistPart) {
103 style->setAppearance(MenulistButtonPart);
104 part = MenulistButtonPart;
106 style->setAppearance(NoControlPart);
109 if (!style->hasAppearance())
112 if (shouldUseFallbackTheme(style)) {
113 adjustStyleUsingFallbackTheme(style, e);
120 case InnerSpinButtonPart:
123 case SquareButtonPart:
126 LengthBox borderBox(style->borderTopWidth(), style->borderRightWidth(), style->borderBottomWidth(), style->borderLeftWidth());
127 borderBox = m_platformTheme->controlBorder(part, style->font().fontDescription(), borderBox, style->effectiveZoom());
128 if (borderBox.top().value() != static_cast<int>(style->borderTopWidth())) {
129 if (borderBox.top().value())
130 style->setBorderTopWidth(borderBox.top().value());
132 style->resetBorderTop();
134 if (borderBox.right().value() != static_cast<int>(style->borderRightWidth())) {
135 if (borderBox.right().value())
136 style->setBorderRightWidth(borderBox.right().value());
138 style->resetBorderRight();
140 if (borderBox.bottom().value() != static_cast<int>(style->borderBottomWidth())) {
141 style->setBorderBottomWidth(borderBox.bottom().value());
142 if (borderBox.bottom().value())
143 style->setBorderBottomWidth(borderBox.bottom().value());
145 style->resetBorderBottom();
147 if (borderBox.left().value() != static_cast<int>(style->borderLeftWidth())) {
148 style->setBorderLeftWidth(borderBox.left().value());
149 if (borderBox.left().value())
150 style->setBorderLeftWidth(borderBox.left().value());
152 style->resetBorderLeft();
156 LengthBox paddingBox = m_platformTheme->controlPadding(part, style->font().fontDescription(), style->paddingBox(), style->effectiveZoom());
157 if (paddingBox != style->paddingBox())
158 style->setPaddingBox(paddingBox);
161 if (m_platformTheme->controlRequiresPreWhiteSpace(part))
162 style->setWhiteSpace(PRE);
165 // The width and height here are affected by the zoom.
166 // FIXME: Check is flawed, since it doesn't take min-width/max-width into account.
167 LengthSize controlSize = m_platformTheme->controlSize(part, style->font().fontDescription(), LengthSize(style->width(), style->height()), style->effectiveZoom());
168 if (controlSize.width() != style->width())
169 style->setWidth(controlSize.width());
170 if (controlSize.height() != style->height())
171 style->setHeight(controlSize.height());
173 // Min-Width / Min-Height
174 LengthSize minControlSize = m_platformTheme->minimumControlSize(part, style->font().fontDescription(), style->effectiveZoom());
175 if (minControlSize.width() != style->minWidth())
176 style->setMinWidth(minControlSize.width());
177 if (minControlSize.height() != style->minHeight())
178 style->setMinHeight(minControlSize.height());
181 FontDescription controlFont = m_platformTheme->controlFont(part, style->font().fontDescription(), style->effectiveZoom());
182 if (controlFont != style->font().fontDescription()) {
183 // Reset our line-height
184 style->setLineHeight(RenderStyle::initialLineHeight());
186 // Now update our font.
187 if (style->setFontDescription(controlFont))
188 style->font().update(nullptr);
196 // Call the appropriate style adjustment method based off the appearance value.
197 switch (style->appearance()) {
200 return adjustCheckboxStyle(style, e);
202 return adjustRadioStyle(style, e);
204 case SquareButtonPart:
206 return adjustButtonStyle(style, e);
207 case InnerSpinButtonPart:
208 return adjustInnerSpinButtonStyle(style, e);
211 return adjustMenuListStyle(style, e);
212 case MenulistButtonPart:
213 return adjustMenuListButtonStyle(style, e);
214 case SliderThumbHorizontalPart:
215 case SliderThumbVerticalPart:
216 return adjustSliderThumbStyle(style, e);
217 case SearchFieldPart:
218 return adjustSearchFieldStyle(style, e);
219 case SearchFieldCancelButtonPart:
220 return adjustSearchFieldCancelButtonStyle(style, e);
221 case SearchFieldDecorationPart:
222 return adjustSearchFieldDecorationStyle(style, e);
223 case SearchFieldResultsDecorationPart:
224 return adjustSearchFieldResultsDecorationStyle(style, e);
230 bool RenderTheme::paint(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
232 ControlPart part = o->style()->appearance();
234 if (shouldUseFallbackTheme(o->style()))
235 return paintUsingFallbackTheme(o, paintInfo, r);
242 case SquareButtonPart:
244 case InnerSpinButtonPart:
245 m_platformTheme->paint(part, controlStatesForRenderer(o), const_cast<GraphicsContext*>(paintInfo.context), r, o->style()->effectiveZoom(), o->view()->frameView());
252 // Call the appropriate paint method based off the appearance value.
256 return paintCheckbox(o, paintInfo, r);
258 return paintRadio(o, paintInfo, r);
260 case SquareButtonPart:
262 return paintButton(o, paintInfo, r);
263 case InnerSpinButtonPart:
264 return paintInnerSpinButton(o, paintInfo, r);
267 return paintMenuList(o, paintInfo, r);
269 case RelevancyLevelIndicatorPart:
270 case ContinuousCapacityLevelIndicatorPart:
271 case DiscreteCapacityLevelIndicatorPart:
272 case RatingLevelIndicatorPart:
273 return paintMeter(o, paintInfo, r);
274 case ProgressBarPart:
275 return paintProgressBar(o, paintInfo, r);
276 case SliderHorizontalPart:
277 case SliderVerticalPart:
278 return paintSliderTrack(o, paintInfo, r);
279 case SliderThumbHorizontalPart:
280 case SliderThumbVerticalPart:
281 return paintSliderThumb(o, paintInfo, r);
282 case MediaEnterFullscreenButtonPart:
283 case MediaExitFullscreenButtonPart:
284 return paintMediaFullscreenButton(o, paintInfo, r);
285 case MediaPlayButtonPart:
286 return paintMediaPlayButton(o, paintInfo, r);
287 case MediaOverlayPlayButtonPart:
288 return paintMediaOverlayPlayButton(o, paintInfo, r);
289 case MediaMuteButtonPart:
290 return paintMediaMuteButton(o, paintInfo, r);
291 case MediaToggleClosedCaptionsButtonPart:
292 return paintMediaToggleClosedCaptionsButton(o, paintInfo, r);
293 case MediaSliderPart:
294 return paintMediaSliderTrack(o, paintInfo, r);
295 case MediaSliderThumbPart:
296 return paintMediaSliderThumb(o, paintInfo, r);
297 case MediaVolumeSliderContainerPart:
298 return paintMediaVolumeSliderContainer(o, paintInfo, r);
299 case MediaVolumeSliderPart:
300 return paintMediaVolumeSliderTrack(o, paintInfo, r);
301 case MediaVolumeSliderThumbPart:
302 return paintMediaVolumeSliderThumb(o, paintInfo, r);
303 case MediaFullScreenVolumeSliderPart:
304 return paintMediaFullScreenVolumeSliderTrack(o, paintInfo, r);
305 case MediaFullScreenVolumeSliderThumbPart:
306 return paintMediaFullScreenVolumeSliderThumb(o, paintInfo, r);
307 case MediaTimeRemainingPart:
308 return paintMediaTimeRemaining(o, paintInfo, r);
309 case MediaCurrentTimePart:
310 return paintMediaCurrentTime(o, paintInfo, r);
311 case MediaControlsBackgroundPart:
312 return paintMediaControlsBackground(o, paintInfo, r);
313 case MenulistButtonPart:
317 case SearchFieldPart:
318 return paintSearchField(o, paintInfo, r);
319 case SearchFieldCancelButtonPart:
320 return paintSearchFieldCancelButton(o, paintInfo, r);
321 case SearchFieldDecorationPart:
322 return paintSearchFieldDecoration(o, paintInfo, r);
323 case SearchFieldResultsDecorationPart:
324 return paintSearchFieldResultsDecoration(o, paintInfo, r);
329 return true; // We don't support the appearance, so let the normal background/border paint.
332 bool RenderTheme::paintBorderOnly(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
334 // Call the appropriate paint method based off the appearance value.
335 switch (o->style()->appearance()) {
337 return paintTextField(o, paintInfo, r);
339 return paintTextArea(o, paintInfo, r);
340 case MenulistButtonPart:
341 case SearchFieldPart:
347 case SquareButtonPart:
351 case RelevancyLevelIndicatorPart:
352 case ContinuousCapacityLevelIndicatorPart:
353 case DiscreteCapacityLevelIndicatorPart:
354 case RatingLevelIndicatorPart:
355 case ProgressBarPart:
356 case SliderHorizontalPart:
357 case SliderVerticalPart:
358 case SliderThumbHorizontalPart:
359 case SliderThumbVerticalPart:
360 case SearchFieldCancelButtonPart:
361 case SearchFieldDecorationPart:
362 case SearchFieldResultsDecorationPart:
370 bool RenderTheme::paintDecorations(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
372 // Call the appropriate paint method based off the appearance value.
373 switch (o->style()->appearance()) {
374 case MenulistButtonPart:
375 return paintMenuListButton(o, paintInfo, r);
381 case SquareButtonPart:
385 case RelevancyLevelIndicatorPart:
386 case ContinuousCapacityLevelIndicatorPart:
387 case DiscreteCapacityLevelIndicatorPart:
388 case RatingLevelIndicatorPart:
389 case ProgressBarPart:
390 case SliderHorizontalPart:
391 case SliderVerticalPart:
392 case SliderThumbHorizontalPart:
393 case SliderThumbVerticalPart:
394 case SearchFieldPart:
395 case SearchFieldCancelButtonPart:
396 case SearchFieldDecorationPart:
397 case SearchFieldResultsDecorationPart:
405 String RenderTheme::extraDefaultStyleSheet()
407 StringBuilder runtimeCSS;
408 if (RuntimeEnabledFeatures::dialogElementEnabled()) {
409 runtimeCSS.appendLiteral("dialog:not([open]) { display: none; }");
410 runtimeCSS.appendLiteral("dialog { position: absolute; left: 0; right: 0; width: -webkit-fit-content; height: -webkit-fit-content; margin: auto; border: solid; padding: 1em; background: white; color: black;}");
411 runtimeCSS.appendLiteral("dialog::backdrop { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,0.1); }");
414 if (RuntimeEnabledFeatures::contextMenuEnabled()) {
415 runtimeCSS.appendLiteral("menu[type=\"popup\" i] { display: none; }");
418 return runtimeCSS.toString();
421 String RenderTheme::formatMediaControlsTime(float time) const
423 if (!std::isfinite(time))
425 int seconds = (int)fabsf(time);
426 int hours = seconds / (60 * 60);
427 int minutes = (seconds / 60) % 60;
431 return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
433 return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
436 return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
439 String RenderTheme::formatMediaControlsCurrentTime(float currentTime, float /*duration*/) const
441 return formatMediaControlsTime(currentTime);
444 Color RenderTheme::activeSelectionBackgroundColor() const
446 return platformActiveSelectionBackgroundColor().blendWithWhite();
449 Color RenderTheme::inactiveSelectionBackgroundColor() const
451 return platformInactiveSelectionBackgroundColor().blendWithWhite();
454 Color RenderTheme::activeSelectionForegroundColor() const
456 return platformActiveSelectionForegroundColor();
459 Color RenderTheme::inactiveSelectionForegroundColor() const
461 return platformInactiveSelectionForegroundColor();
464 Color RenderTheme::activeListBoxSelectionBackgroundColor() const
466 return platformActiveListBoxSelectionBackgroundColor();
469 Color RenderTheme::inactiveListBoxSelectionBackgroundColor() const
471 return platformInactiveListBoxSelectionBackgroundColor();
474 Color RenderTheme::activeListBoxSelectionForegroundColor() const
476 return platformActiveListBoxSelectionForegroundColor();
479 Color RenderTheme::inactiveListBoxSelectionForegroundColor() const
481 return platformInactiveListBoxSelectionForegroundColor();
484 Color RenderTheme::platformActiveSelectionBackgroundColor() const
486 // Use a blue color by default if the platform theme doesn't define anything.
487 return Color(0, 0, 255);
490 Color RenderTheme::platformActiveSelectionForegroundColor() const
492 // Use a white color by default if the platform theme doesn't define anything.
496 Color RenderTheme::platformInactiveSelectionBackgroundColor() const
498 // Use a grey color by default if the platform theme doesn't define anything.
499 // This color matches Firefox's inactive color.
500 return Color(176, 176, 176);
503 Color RenderTheme::platformInactiveSelectionForegroundColor() const
505 // Use a black color by default.
509 Color RenderTheme::platformActiveListBoxSelectionBackgroundColor() const
511 return platformActiveSelectionBackgroundColor();
514 Color RenderTheme::platformActiveListBoxSelectionForegroundColor() const
516 return platformActiveSelectionForegroundColor();
519 Color RenderTheme::platformInactiveListBoxSelectionBackgroundColor() const
521 return platformInactiveSelectionBackgroundColor();
524 Color RenderTheme::platformInactiveListBoxSelectionForegroundColor() const
526 return platformInactiveSelectionForegroundColor();
529 int RenderTheme::baselinePosition(const RenderObject* o) const
534 const RenderBox* box = toRenderBox(o);
537 return box->height() + box->marginTop() + m_platformTheme->baselinePositionAdjustment(o->style()->appearance()) * o->style()->effectiveZoom();
539 return box->height() + box->marginTop();
543 bool RenderTheme::isControlContainer(ControlPart appearance) const
545 // There are more leaves than this, but we'll patch this function as we add support for
547 return appearance != CheckboxPart && appearance != RadioPart;
550 static bool isBackgroundOrBorderStyled(const RenderStyle& style, const CachedUAStyle& uaStyle)
552 // Code below excludes the background-repeat from comparison by resetting it
553 FillLayer backgroundCopy = uaStyle.backgroundLayers;
554 FillLayer backgroundLayersCopy = style.backgroundLayers();
555 backgroundCopy.setRepeatX(NoRepeatFill);
556 backgroundCopy.setRepeatY(NoRepeatFill);
557 backgroundLayersCopy.setRepeatX(NoRepeatFill);
558 backgroundLayersCopy.setRepeatY(NoRepeatFill);
559 // Test the style to see if the UA border and background match.
560 return style.border() != uaStyle.border
561 || backgroundLayersCopy != backgroundCopy
562 || style.visitedDependentColor(CSSPropertyBackgroundColor) != uaStyle.backgroundColor;
565 bool RenderTheme::isControlStyled(const RenderStyle* style, const CachedUAStyle* uaStyle) const
569 switch (style->appearance()) {
571 case SquareButtonPart:
573 case ProgressBarPart:
575 case RelevancyLevelIndicatorPart:
576 case ContinuousCapacityLevelIndicatorPart:
577 case DiscreteCapacityLevelIndicatorPart:
578 case RatingLevelIndicatorPart:
579 return isBackgroundOrBorderStyled(*style, *uaStyle);
582 case SearchFieldPart:
585 return isBackgroundOrBorderStyled(*style, *uaStyle) || style->boxShadow();
587 case SliderHorizontalPart:
588 case SliderVerticalPart:
589 return style->boxShadow();
596 void RenderTheme::adjustRepaintRect(const RenderObject* o, IntRect& r)
599 m_platformTheme->inflateControlPaintRect(o->style()->appearance(), controlStatesForRenderer(o), r, o->style()->effectiveZoom());
603 bool RenderTheme::shouldDrawDefaultFocusRing(RenderObject* renderer) const
605 if (supportsFocusRing(renderer->style()))
607 if (!renderer->style()->hasAppearance())
609 Node* node = renderer->node();
612 // We can't use RenderTheme::isFocused because outline:auto might be
613 // specified to non-:focus rulesets.
614 if (node->focused() && !node->shouldHaveFocusAppearance())
619 bool RenderTheme::supportsFocusRing(const RenderStyle* style) const
621 return (style->hasAppearance() && style->appearance() != TextFieldPart && style->appearance() != TextAreaPart && style->appearance() != MenulistButtonPart && style->appearance() != ListboxPart);
624 bool RenderTheme::stateChanged(RenderObject* o, ControlState state) const
626 // Default implementation assumes the controls don't respond to changes in :hover state
627 if (state == HoverControlState && !supportsHover(o->style()))
630 // Assume pressed state is only responded to if the control is enabled.
631 if (state == PressedControlState && !isEnabled(o))
634 // Repaint the control.
635 o->paintInvalidationForWholeRenderer();
639 ControlStates RenderTheme::controlStatesForRenderer(const RenderObject* o) const
641 ControlStates result = 0;
643 result |= HoverControlState;
644 if (isSpinUpButtonPartHovered(o))
645 result |= SpinUpControlState;
648 result |= PressedControlState;
649 if (isSpinUpButtonPartPressed(o))
650 result |= SpinUpControlState;
652 if (isFocused(o) && o->style()->outlineStyleIsAuto())
653 result |= FocusControlState;
655 result |= EnabledControlState;
657 result |= CheckedControlState;
658 if (isReadOnlyControl(o))
659 result |= ReadOnlyControlState;
661 result |= WindowInactiveControlState;
662 if (isIndeterminate(o))
663 result |= IndeterminateControlState;
667 bool RenderTheme::isActive(const RenderObject* o) const
669 Node* node = o->node();
673 Page* page = node->document().page();
677 return page->focusController().isActive();
680 bool RenderTheme::isChecked(const RenderObject* o) const
682 if (!isHTMLInputElement(o->node()))
684 return toHTMLInputElement(o->node())->shouldAppearChecked();
687 bool RenderTheme::isIndeterminate(const RenderObject* o) const
689 if (!isHTMLInputElement(o->node()))
691 return toHTMLInputElement(o->node())->shouldAppearIndeterminate();
694 bool RenderTheme::isEnabled(const RenderObject* o) const
696 Node* node = o->node();
697 if (!node || !node->isElementNode())
699 return !toElement(node)->isDisabledFormControl();
702 bool RenderTheme::isFocused(const RenderObject* o) const
704 Node* node = o->node();
708 node = node->focusDelegate();
709 Document& document = node->document();
710 LocalFrame* frame = document.frame();
711 return node == document.focusedElement() && node->focused() && node->shouldHaveFocusAppearance() && frame && frame->selection().isFocusedAndActive();
714 bool RenderTheme::isPressed(const RenderObject* o) const
718 return o->node()->active();
721 bool RenderTheme::isSpinUpButtonPartPressed(const RenderObject* o) const
723 Node* node = o->node();
724 if (!node || !node->active() || !node->isElementNode()
725 || !toElement(node)->isSpinButtonElement())
727 SpinButtonElement* element = toSpinButtonElement(node);
728 return element->upDownState() == SpinButtonElement::Up;
731 bool RenderTheme::isReadOnlyControl(const RenderObject* o) const
733 Node* node = o->node();
734 if (!node || !node->isElementNode() || !toElement(node)->isFormControlElement())
736 HTMLFormControlElement* element = toHTMLFormControlElement(node);
737 return element->isReadOnly();
740 bool RenderTheme::isHovered(const RenderObject* o) const
742 Node* node = o->node();
745 if (!node->isElementNode() || !toElement(node)->isSpinButtonElement())
746 return node->hovered();
747 SpinButtonElement* element = toSpinButtonElement(node);
748 return element->hovered() && element->upDownState() != SpinButtonElement::Indeterminate;
751 bool RenderTheme::isSpinUpButtonPartHovered(const RenderObject* o) const
753 Node* node = o->node();
754 if (!node || !node->isElementNode() || !toElement(node)->isSpinButtonElement())
756 SpinButtonElement* element = toSpinButtonElement(node);
757 return element->upDownState() == SpinButtonElement::Up;
762 void RenderTheme::adjustCheckboxStyle(RenderStyle* style, Element*) const
764 // A summary of the rules for checkbox designed to match WinIE:
765 // width/height - honored (WinIE actually scales its control for small widths, but lets it overflow for small heights.)
766 // font-size - not honored (control has no text), but we use it to decide which control size to use.
767 setCheckboxSize(style);
769 // padding - not honored by WinIE, needs to be removed.
770 style->resetPadding();
772 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
773 // for now, we will not honor it.
774 style->resetBorder();
777 void RenderTheme::adjustRadioStyle(RenderStyle* style, Element*) const
779 // A summary of the rules for checkbox designed to match WinIE:
780 // width/height - honored (WinIE actually scales its control for small widths, but lets it overflow for small heights.)
781 // font-size - not honored (control has no text), but we use it to decide which control size to use.
784 // padding - not honored by WinIE, needs to be removed.
785 style->resetPadding();
787 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
788 // for now, we will not honor it.
789 style->resetBorder();
792 void RenderTheme::adjustButtonStyle(RenderStyle* style, Element*) const
796 void RenderTheme::adjustInnerSpinButtonStyle(RenderStyle*, Element*) const
801 void RenderTheme::adjustMenuListStyle(RenderStyle*, Element*) const
805 IntSize RenderTheme::meterSizeForBounds(const RenderMeter*, const IntRect& bounds) const
807 return bounds.size();
810 bool RenderTheme::supportsMeter(ControlPart) const
815 bool RenderTheme::paintMeter(RenderObject*, const PaintInfo&, const IntRect&)
820 void RenderTheme::paintSliderTicks(RenderObject* o, const PaintInfo& paintInfo, const IntRect& rect)
822 Node* node = o->node();
823 if (!isHTMLInputElement(node))
826 HTMLInputElement* input = toHTMLInputElement(node);
827 if (!input->isRangeControl())
830 HTMLDataListElement* dataList = input->dataList();
834 double min = input->minimum();
835 double max = input->maximum();
836 ControlPart part = o->style()->appearance();
837 // We don't support ticks on alternate sliders like MediaVolumeSliders.
838 if (part != SliderHorizontalPart && part != SliderVerticalPart)
840 bool isHorizontal = part == SliderHorizontalPart;
843 RenderObject* thumbRenderer = input->userAgentShadowRoot()->getElementById(ShadowElementNames::sliderThumb())->renderer();
845 RenderStyle* thumbStyle = thumbRenderer->style();
846 int thumbWidth = thumbStyle->width().intValue();
847 int thumbHeight = thumbStyle->height().intValue();
848 thumbSize.setWidth(isHorizontal ? thumbWidth : thumbHeight);
849 thumbSize.setHeight(isHorizontal ? thumbHeight : thumbWidth);
852 IntSize tickSize = sliderTickSize();
853 float zoomFactor = o->style()->effectiveZoom();
855 int tickRegionSideMargin = 0;
856 int tickRegionWidth = 0;
858 RenderObject* trackRenderer = input->userAgentShadowRoot()->getElementById(ShadowElementNames::sliderTrack())->renderer();
859 // We can ignoring transforms because transform is handled by the graphics context.
861 trackBounds = trackRenderer->absoluteBoundingBoxRectIgnoringTransforms();
862 IntRect sliderBounds = o->absoluteBoundingBoxRectIgnoringTransforms();
864 // Make position relative to the transformed ancestor element.
865 trackBounds.setX(trackBounds.x() - sliderBounds.x() + rect.x());
866 trackBounds.setY(trackBounds.y() - sliderBounds.y() + rect.y());
869 tickRect.setWidth(floor(tickSize.width() * zoomFactor));
870 tickRect.setHeight(floor(tickSize.height() * zoomFactor));
871 tickRect.setY(floor(rect.y() + rect.height() / 2.0 + sliderTickOffsetFromTrackCenter() * zoomFactor));
872 tickRegionSideMargin = trackBounds.x() + (thumbSize.width() - tickSize.width() * zoomFactor) / 2.0;
873 tickRegionWidth = trackBounds.width() - thumbSize.width();
875 tickRect.setWidth(floor(tickSize.height() * zoomFactor));
876 tickRect.setHeight(floor(tickSize.width() * zoomFactor));
877 tickRect.setX(floor(rect.x() + rect.width() / 2.0 + sliderTickOffsetFromTrackCenter() * zoomFactor));
878 tickRegionSideMargin = trackBounds.y() + (thumbSize.width() - tickSize.width() * zoomFactor) / 2.0;
879 tickRegionWidth = trackBounds.height() - thumbSize.width();
881 RefPtrWillBeRawPtr<HTMLCollection> options = dataList->options();
882 GraphicsContextStateSaver stateSaver(*paintInfo.context);
883 paintInfo.context->setFillColor(o->resolveColor(CSSPropertyColor));
884 for (unsigned i = 0; Element* element = options->item(i); i++) {
885 ASSERT(isHTMLOptionElement(*element));
886 HTMLOptionElement& optionElement = toHTMLOptionElement(*element);
887 String value = optionElement.value();
888 if (!input->isValidValue(value))
890 double parsedValue = parseToDoubleForNumberType(input->sanitizeValue(value));
891 double tickFraction = (parsedValue - min) / (max - min);
892 double tickRatio = isHorizontal && o->style()->isLeftToRightDirection() ? tickFraction : 1.0 - tickFraction;
893 double tickPosition = round(tickRegionSideMargin + tickRegionWidth * tickRatio);
895 tickRect.setX(tickPosition);
897 tickRect.setY(tickPosition);
898 paintInfo.context->fillRect(tickRect);
902 double RenderTheme::animationRepeatIntervalForProgressBar(RenderProgress*) const
907 double RenderTheme::animationDurationForProgressBar(RenderProgress*) const
912 bool RenderTheme::shouldHaveSpinButton(HTMLInputElement* inputElement) const
914 return inputElement->isSteppable() && !inputElement->isRangeControl();
917 void RenderTheme::adjustMenuListButtonStyle(RenderStyle*, Element*) const
921 void RenderTheme::adjustSliderThumbStyle(RenderStyle* style, Element* element) const
923 adjustSliderThumbSize(style, element);
926 void RenderTheme::adjustSliderThumbSize(RenderStyle*, Element*) const
930 void RenderTheme::adjustSearchFieldStyle(RenderStyle*, Element*) const
934 void RenderTheme::adjustSearchFieldCancelButtonStyle(RenderStyle*, Element*) const
938 void RenderTheme::adjustSearchFieldDecorationStyle(RenderStyle*, Element*) const
942 void RenderTheme::adjustSearchFieldResultsDecorationStyle(RenderStyle*, Element*) const
946 void RenderTheme::platformColorsDidChange()
948 Page::scheduleForcedStyleRecalcForAllPages();
951 Color RenderTheme::systemColor(CSSValueID cssValueId) const
953 switch (cssValueId) {
954 case CSSValueActiveborder:
956 case CSSValueActivecaption:
958 case CSSValueAppworkspace:
960 case CSSValueBackground:
962 case CSSValueButtonface:
964 case CSSValueButtonhighlight:
966 case CSSValueButtonshadow:
968 case CSSValueButtontext:
970 case CSSValueCaptiontext:
972 case CSSValueGraytext:
974 case CSSValueHighlight:
976 case CSSValueHighlighttext:
978 case CSSValueInactiveborder:
980 case CSSValueInactivecaption:
982 case CSSValueInactivecaptiontext:
984 case CSSValueInfobackground:
986 case CSSValueInfotext:
990 case CSSValueMenutext:
992 case CSSValueScrollbar:
996 case CSSValueThreeddarkshadow:
998 case CSSValueThreedface:
1000 case CSSValueThreedhighlight:
1002 case CSSValueThreedlightshadow:
1004 case CSSValueThreedshadow:
1006 case CSSValueWindow:
1008 case CSSValueWindowframe:
1010 case CSSValueWindowtext:
1012 case CSSValueInternalActiveListBoxSelection:
1013 return activeListBoxSelectionBackgroundColor();
1015 case CSSValueInternalActiveListBoxSelectionText:
1016 return activeListBoxSelectionForegroundColor();
1018 case CSSValueInternalInactiveListBoxSelection:
1019 return inactiveListBoxSelectionBackgroundColor();
1021 case CSSValueInternalInactiveListBoxSelectionText:
1022 return inactiveListBoxSelectionForegroundColor();
1027 ASSERT_NOT_REACHED();
1031 Color RenderTheme::platformActiveTextSearchHighlightColor() const
1033 return Color(255, 150, 50); // Orange.
1036 Color RenderTheme::platformInactiveTextSearchHighlightColor() const
1038 return Color(255, 255, 0); // Yellow.
1041 Color RenderTheme::tapHighlightColor()
1043 return theme().platformTapHighlightColor();
1046 void RenderTheme::setCustomFocusRingColor(const Color& c)
1048 m_customFocusRingColor = c;
1049 m_hasCustomFocusRingColor = true;
1052 Color RenderTheme::focusRingColor() const
1054 return m_hasCustomFocusRingColor ? m_customFocusRingColor : theme().platformFocusRingColor();
1057 String RenderTheme::fileListNameForWidth(Locale& locale, const FileList* fileList, const Font& font, int width) const
1063 if (fileList->isEmpty()) {
1064 string = locale.queryString(WebLocalizedString::FileButtonNoFileSelectedLabel);
1065 } else if (fileList->length() == 1) {
1066 string = fileList->item(0)->name();
1068 // FIXME: Localization of fileList->length().
1069 return StringTruncator::rightTruncate(locale.queryString(WebLocalizedString::MultipleFileUploadText, String::number(fileList->length())), width, font);
1072 return StringTruncator::centerTruncate(string, width, font);
1075 bool RenderTheme::shouldOpenPickerWithF4Key() const
1080 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
1081 bool RenderTheme::supportsCalendarPicker(const AtomicString& type) const
1083 return type == InputTypeNames::date
1084 || type == InputTypeNames::datetime
1085 || type == InputTypeNames::datetime_local
1086 || type == InputTypeNames::month
1087 || type == InputTypeNames::week;
1091 bool RenderTheme::shouldUseFallbackTheme(RenderStyle*) const
1096 void RenderTheme::adjustStyleUsingFallbackTheme(RenderStyle* style, Element* e)
1098 ControlPart part = style->appearance();
1101 return adjustCheckboxStyleUsingFallbackTheme(style, e);
1103 return adjustRadioStyleUsingFallbackTheme(style, e);
1109 bool RenderTheme::paintUsingFallbackTheme(RenderObject* o, const PaintInfo& i, const IntRect& r)
1111 ControlPart part = o->style()->appearance();
1114 return paintCheckboxUsingFallbackTheme(o, i, r);
1116 return paintRadioUsingFallbackTheme(o, i, r);
1124 void RenderTheme::setSizeIfAuto(RenderStyle* style, const IntSize& size)
1126 if (style->width().isIntrinsicOrAuto())
1127 style->setWidth(Length(size.width(), Fixed));
1128 if (style->height().isAuto())
1129 style->setHeight(Length(size.height(), Fixed));
1132 bool RenderTheme::paintCheckboxUsingFallbackTheme(RenderObject* o, const PaintInfo& i, const IntRect& r)
1134 WebFallbackThemeEngine::ExtraParams extraParams;
1135 WebCanvas* canvas = i.context->canvas();
1136 extraParams.button.checked = isChecked(o);
1137 extraParams.button.indeterminate = isIndeterminate(o);
1139 float zoomLevel = o->style()->effectiveZoom();
1140 GraphicsContextStateSaver stateSaver(*i.context);
1141 IntRect unzoomedRect = r;
1142 if (zoomLevel != 1) {
1143 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1144 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1145 i.context->translate(unzoomedRect.x(), unzoomedRect.y());
1146 i.context->scale(zoomLevel, zoomLevel);
1147 i.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1150 Platform::current()->fallbackThemeEngine()->paint(canvas, WebFallbackThemeEngine::PartCheckbox, getWebFallbackThemeState(this, o), WebRect(unzoomedRect), &extraParams);
1154 void RenderTheme::adjustCheckboxStyleUsingFallbackTheme(RenderStyle* style, Element*) const
1156 // If the width and height are both specified, then we have nothing to do.
1157 if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
1160 IntSize size = Platform::current()->fallbackThemeEngine()->getSize(WebFallbackThemeEngine::PartCheckbox);
1161 float zoomLevel = style->effectiveZoom();
1162 size.setWidth(size.width() * zoomLevel);
1163 size.setHeight(size.height() * zoomLevel);
1164 setSizeIfAuto(style, size);
1166 // padding - not honored by WinIE, needs to be removed.
1167 style->resetPadding();
1169 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
1170 // for now, we will not honor it.
1171 style->resetBorder();
1174 bool RenderTheme::paintRadioUsingFallbackTheme(RenderObject* o, const PaintInfo& i, const IntRect& r)
1176 WebFallbackThemeEngine::ExtraParams extraParams;
1177 WebCanvas* canvas = i.context->canvas();
1178 extraParams.button.checked = isChecked(o);
1179 extraParams.button.indeterminate = isIndeterminate(o);
1181 float zoomLevel = o->style()->effectiveZoom();
1182 GraphicsContextStateSaver stateSaver(*i.context);
1183 IntRect unzoomedRect = r;
1184 if (zoomLevel != 1) {
1185 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1186 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1187 i.context->translate(unzoomedRect.x(), unzoomedRect.y());
1188 i.context->scale(zoomLevel, zoomLevel);
1189 i.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1192 Platform::current()->fallbackThemeEngine()->paint(canvas, WebFallbackThemeEngine::PartRadio, getWebFallbackThemeState(this, o), WebRect(unzoomedRect), &extraParams);
1196 void RenderTheme::adjustRadioStyleUsingFallbackTheme(RenderStyle* style, Element*) const
1198 // If the width and height are both specified, then we have nothing to do.
1199 if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
1202 IntSize size = Platform::current()->fallbackThemeEngine()->getSize(WebFallbackThemeEngine::PartRadio);
1203 float zoomLevel = style->effectiveZoom();
1204 size.setWidth(size.width() * zoomLevel);
1205 size.setHeight(size.height() * zoomLevel);
1206 setSizeIfAuto(style, size);
1208 // padding - not honored by WinIE, needs to be removed.
1209 style->resetPadding();
1211 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
1212 // for now, we will not honor it.
1213 style->resetBorder();
1216 } // namespace blink