2 * This file is part of the theme implementation for form controls in WebCore.
4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 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"
27 #include "FileSystem.h"
28 #include "FloatConversion.h"
29 #include "FocusController.h"
30 #include "FontSelector.h"
32 #include "FrameSelection.h"
33 #include "GraphicsContext.h"
34 #include "HTMLInputElement.h"
35 #include "HTMLNames.h"
36 #include "LocalizedStrings.h"
37 #include "MediaControlElements.h"
39 #include "PaintInfo.h"
40 #include "RenderStyle.h"
41 #include "RenderView.h"
43 #include "StringTruncator.h"
44 #include "TextControlInnerElements.h"
47 #include "HTMLMeterElement.h"
48 #include "RenderMeter.h"
51 #if ENABLE(INPUT_SPEECH)
52 #include "RenderInputSpeech.h"
55 // The methods in this file are shared by all themes on every platform.
59 using namespace HTMLNames;
61 static Color& customFocusRingColor()
63 DEFINE_STATIC_LOCAL(Color, color, ());
67 RenderTheme::RenderTheme()
69 : m_theme(platformTheme())
74 void RenderTheme::adjustStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e,
75 bool UAHasAppearance, const BorderData& border, const FillLayer& background, const Color& backgroundColor)
77 // Force inline and table display styles to be inline-block (except for table- which is block)
78 ControlPart part = style->appearance();
79 if (style->display() == INLINE || style->display() == INLINE_TABLE || style->display() == TABLE_ROW_GROUP ||
80 style->display() == TABLE_HEADER_GROUP || style->display() == TABLE_FOOTER_GROUP ||
81 style->display() == TABLE_ROW || style->display() == TABLE_COLUMN_GROUP || style->display() == TABLE_COLUMN ||
82 style->display() == TABLE_CELL || style->display() == TABLE_CAPTION)
83 style->setDisplay(INLINE_BLOCK);
84 else if (style->display() == COMPACT || style->display() == RUN_IN || style->display() == LIST_ITEM || style->display() == TABLE)
85 style->setDisplay(BLOCK);
87 if (UAHasAppearance && isControlStyled(style, border, background, backgroundColor)) {
88 if (part == MenulistPart) {
89 style->setAppearance(MenulistButtonPart);
90 part = MenulistButtonPart;
92 style->setAppearance(NoControlPart);
95 if (!style->hasAppearance())
98 // Never support box-shadow on native controls.
99 style->setBoxShadow(nullptr);
105 case InnerSpinButtonPart:
108 case SquareButtonPart:
109 case DefaultButtonPart:
112 LengthBox borderBox(style->borderTopWidth(), style->borderRightWidth(), style->borderBottomWidth(), style->borderLeftWidth());
113 borderBox = m_theme->controlBorder(part, style->font(), borderBox, style->effectiveZoom());
114 if (borderBox.top().value() != style->borderTopWidth()) {
115 if (borderBox.top().value())
116 style->setBorderTopWidth(borderBox.top().value());
118 style->resetBorderTop();
120 if (borderBox.right().value() != style->borderRightWidth()) {
121 if (borderBox.right().value())
122 style->setBorderRightWidth(borderBox.right().value());
124 style->resetBorderRight();
126 if (borderBox.bottom().value() != style->borderBottomWidth()) {
127 style->setBorderBottomWidth(borderBox.bottom().value());
128 if (borderBox.bottom().value())
129 style->setBorderBottomWidth(borderBox.bottom().value());
131 style->resetBorderBottom();
133 if (borderBox.left().value() != style->borderLeftWidth()) {
134 style->setBorderLeftWidth(borderBox.left().value());
135 if (borderBox.left().value())
136 style->setBorderLeftWidth(borderBox.left().value());
138 style->resetBorderLeft();
142 LengthBox paddingBox = m_theme->controlPadding(part, style->font(), style->paddingBox(), style->effectiveZoom());
143 if (paddingBox != style->paddingBox())
144 style->setPaddingBox(paddingBox);
147 if (m_theme->controlRequiresPreWhiteSpace(part))
148 style->setWhiteSpace(PRE);
151 // The width and height here are affected by the zoom.
152 // FIXME: Check is flawed, since it doesn't take min-width/max-width into account.
153 LengthSize controlSize = m_theme->controlSize(part, style->font(), LengthSize(style->width(), style->height()), style->effectiveZoom());
154 if (controlSize.width() != style->width())
155 style->setWidth(controlSize.width());
156 if (controlSize.height() != style->height())
157 style->setHeight(controlSize.height());
159 // Min-Width / Min-Height
160 LengthSize minControlSize = m_theme->minimumControlSize(part, style->font(), style->effectiveZoom());
161 if (minControlSize.width() != style->minWidth())
162 style->setMinWidth(minControlSize.width());
163 if (minControlSize.height() != style->minHeight())
164 style->setMinHeight(minControlSize.height());
167 FontDescription controlFont = m_theme->controlFont(part, style->font(), style->effectiveZoom());
168 if (controlFont != style->font().fontDescription()) {
169 // Reset our line-height
170 style->setLineHeight(RenderStyle::initialLineHeight());
172 // Now update our font.
173 if (style->setFontDescription(controlFont))
174 style->font().update(0);
182 // Call the appropriate style adjustment method based off the appearance value.
183 switch (style->appearance()) {
186 return adjustCheckboxStyle(selector, style, e);
188 return adjustRadioStyle(selector, style, e);
190 case SquareButtonPart:
192 case DefaultButtonPart:
194 return adjustButtonStyle(selector, style, e);
195 case InnerSpinButtonPart:
196 return adjustInnerSpinButtonStyle(selector, style, e);
199 return adjustTextFieldStyle(selector, style, e);
200 #if ENABLE(TIZEN_INPUT_TAG_DATE)
202 return adjustDateFieldStyle(selector, style, e);
205 return adjustTextAreaStyle(selector, style, e);
207 return adjustMenuListStyle(selector, style, e);
208 case MenulistButtonPart:
209 return adjustMenuListButtonStyle(selector, style, e);
210 case MediaSliderPart:
211 case MediaVolumeSliderPart:
212 case SliderHorizontalPart:
213 case SliderVerticalPart:
214 return adjustSliderTrackStyle(selector, style, e);
215 case SliderThumbHorizontalPart:
216 case SliderThumbVerticalPart:
217 return adjustSliderThumbStyle(selector, style, e);
218 case SearchFieldPart:
219 return adjustSearchFieldStyle(selector, style, e);
220 case SearchFieldCancelButtonPart:
221 return adjustSearchFieldCancelButtonStyle(selector, style, e);
222 case SearchFieldDecorationPart:
223 return adjustSearchFieldDecorationStyle(selector, style, e);
224 case SearchFieldResultsDecorationPart:
225 return adjustSearchFieldResultsDecorationStyle(selector, style, e);
226 case SearchFieldResultsButtonPart:
227 return adjustSearchFieldResultsButtonStyle(selector, style, e);
228 #if ENABLE(PROGRESS_TAG)
229 case ProgressBarPart:
230 return adjustProgressBarStyle(selector, style, e);
232 #if ENABLE(METER_TAG)
234 case RelevancyLevelIndicatorPart:
235 case ContinuousCapacityLevelIndicatorPart:
236 case DiscreteCapacityLevelIndicatorPart:
237 case RatingLevelIndicatorPart:
238 return adjustMeterStyle(selector, style, e);
240 #if ENABLE(INPUT_SPEECH)
241 case InputSpeechButtonPart:
242 return adjustInputFieldSpeechButtonStyle(selector, style, e);
249 bool RenderTheme::paint(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
251 // If painting is disabled, but we aren't updating control tints, then just bail.
252 // If we are updating control tints, just schedule a repaint if the theme supports tinting
254 if (paintInfo.context->updatingControlTints()) {
255 if (controlSupportsTints(o))
259 if (paintInfo.context->paintingDisabled())
262 ControlPart part = o->style()->appearance();
269 case SquareButtonPart:
271 case DefaultButtonPart:
273 case InnerSpinButtonPart:
274 m_theme->paint(part, controlStatesForRenderer(o), const_cast<GraphicsContext*>(paintInfo.context), r, o->style()->effectiveZoom(), o->view()->frameView());
281 // Call the appropriate paint method based off the appearance value.
285 return paintCheckbox(o, paintInfo, r);
287 return paintRadio(o, paintInfo, r);
289 case SquareButtonPart:
291 case DefaultButtonPart:
293 return paintButton(o, paintInfo, r);
294 case InnerSpinButtonPart:
295 return paintInnerSpinButton(o, paintInfo, r);
298 return paintMenuList(o, paintInfo, r);
299 #if ENABLE(METER_TAG)
301 case RelevancyLevelIndicatorPart:
302 case ContinuousCapacityLevelIndicatorPart:
303 case DiscreteCapacityLevelIndicatorPart:
304 case RatingLevelIndicatorPart:
305 return paintMeter(o, paintInfo, r);
307 #if ENABLE(PROGRESS_TAG)
308 case ProgressBarPart:
309 return paintProgressBar(o, paintInfo, r);
311 case SliderHorizontalPart:
312 case SliderVerticalPart:
313 return paintSliderTrack(o, paintInfo, r);
314 case SliderThumbHorizontalPart:
315 case SliderThumbVerticalPart:
316 return paintSliderThumb(o, paintInfo, r);
317 case MediaFullscreenButtonPart:
318 return paintMediaFullscreenButton(o, paintInfo, r);
319 case MediaPlayButtonPart:
320 return paintMediaPlayButton(o, paintInfo, r);
321 case MediaMuteButtonPart:
322 return paintMediaMuteButton(o, paintInfo, r);
323 case MediaSeekBackButtonPart:
324 return paintMediaSeekBackButton(o, paintInfo, r);
325 case MediaSeekForwardButtonPart:
326 return paintMediaSeekForwardButton(o, paintInfo, r);
327 case MediaRewindButtonPart:
328 return paintMediaRewindButton(o, paintInfo, r);
329 case MediaReturnToRealtimeButtonPart:
330 return paintMediaReturnToRealtimeButton(o, paintInfo, r);
331 case MediaToggleClosedCaptionsButtonPart:
332 return paintMediaToggleClosedCaptionsButton(o, paintInfo, r);
333 case MediaSliderPart:
334 return paintMediaSliderTrack(o, paintInfo, r);
335 case MediaSliderThumbPart:
336 return paintMediaSliderThumb(o, paintInfo, r);
337 case MediaVolumeSliderMuteButtonPart:
338 return paintMediaMuteButton(o, paintInfo, r);
339 case MediaVolumeSliderContainerPart:
340 return paintMediaVolumeSliderContainer(o, paintInfo, r);
341 case MediaVolumeSliderPart:
342 return paintMediaVolumeSliderTrack(o, paintInfo, r);
343 case MediaVolumeSliderThumbPart:
344 return paintMediaVolumeSliderThumb(o, paintInfo, r);
345 case MediaTimeRemainingPart:
346 return paintMediaTimeRemaining(o, paintInfo, r);
347 case MediaCurrentTimePart:
348 return paintMediaCurrentTime(o, paintInfo, r);
349 case MediaControlsBackgroundPart:
350 return paintMediaControlsBackground(o, paintInfo, r);
351 case MenulistButtonPart:
353 #if ENABLE(TIZEN_INPUT_TAG_DATE)
359 case SearchFieldPart:
360 return paintSearchField(o, paintInfo, r);
361 case SearchFieldCancelButtonPart:
362 return paintSearchFieldCancelButton(o, paintInfo, r);
363 case SearchFieldDecorationPart:
364 return paintSearchFieldDecoration(o, paintInfo, r);
365 case SearchFieldResultsDecorationPart:
366 return paintSearchFieldResultsDecoration(o, paintInfo, r);
367 case SearchFieldResultsButtonPart:
368 return paintSearchFieldResultsButton(o, paintInfo, r);
369 #if ENABLE(INPUT_SPEECH)
370 case InputSpeechButtonPart:
371 return paintInputFieldSpeechButton(o, paintInfo, r);
377 return true; // We don't support the appearance, so let the normal background/border paint.
380 bool RenderTheme::paintBorderOnly(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
382 if (paintInfo.context->paintingDisabled())
385 // Call the appropriate paint method based off the appearance value.
386 switch (o->style()->appearance()) {
388 return paintTextField(o, paintInfo, r);
389 #if ENABLE(TIZEN_INPUT_TAG_DATE)
391 return paintDateField(o, paintInfo, r);
395 return paintTextArea(o, paintInfo, r);
396 case MenulistButtonPart:
397 case SearchFieldPart:
402 case SquareButtonPart:
404 case DefaultButtonPart:
407 #if ENABLE(METER_TAG)
409 case RelevancyLevelIndicatorPart:
410 case ContinuousCapacityLevelIndicatorPart:
411 case DiscreteCapacityLevelIndicatorPart:
412 case RatingLevelIndicatorPart:
414 #if ENABLE(PROGRESS_TAG)
415 case ProgressBarPart:
417 case SliderHorizontalPart:
418 case SliderVerticalPart:
419 case SliderThumbHorizontalPart:
420 case SliderThumbVerticalPart:
421 case SearchFieldCancelButtonPart:
422 case SearchFieldDecorationPart:
423 case SearchFieldResultsDecorationPart:
424 case SearchFieldResultsButtonPart:
425 #if ENABLE(INPUT_SPEECH)
426 case InputSpeechButtonPart:
435 bool RenderTheme::paintDecorations(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
437 if (paintInfo.context->paintingDisabled())
440 // Call the appropriate paint method based off the appearance value.
441 switch (o->style()->appearance()) {
442 case MenulistButtonPart:
443 return paintMenuListButton(o, paintInfo, r);
445 #if ENABLE(TIZEN_INPUT_TAG_DATE)
453 case SquareButtonPart:
455 case DefaultButtonPart:
458 #if ENABLE(METER_TAG)
460 case RelevancyLevelIndicatorPart:
461 case ContinuousCapacityLevelIndicatorPart:
462 case DiscreteCapacityLevelIndicatorPart:
463 case RatingLevelIndicatorPart:
465 #if ENABLE(PROGRESS_TAG)
466 case ProgressBarPart:
468 case SliderHorizontalPart:
469 case SliderVerticalPart:
470 case SliderThumbHorizontalPart:
471 case SliderThumbVerticalPart:
472 case SearchFieldPart:
473 case SearchFieldCancelButtonPart:
474 case SearchFieldDecorationPart:
475 case SearchFieldResultsDecorationPart:
476 case SearchFieldResultsButtonPart:
477 #if ENABLE(INPUT_SPEECH)
478 case InputSpeechButtonPart:
489 String RenderTheme::formatMediaControlsTime(float time) const
493 int seconds = (int)fabsf(time);
494 int hours = seconds / (60 * 60);
495 int minutes = (seconds / 60) % 60;
499 return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
501 return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
504 return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
507 String RenderTheme::formatMediaControlsCurrentTime(float currentTime, float /*duration*/) const
509 return formatMediaControlsTime(currentTime);
512 String RenderTheme::formatMediaControlsRemainingTime(float currentTime, float duration) const
514 return formatMediaControlsTime(currentTime - duration);
517 IntPoint RenderTheme::volumeSliderOffsetFromMuteButton(RenderBox* muteButtonBox, const IntSize& size) const
519 int y = -size.height();
520 FloatPoint absPoint = muteButtonBox->localToAbsolute(FloatPoint(muteButtonBox->offsetLeft(), y), true, true);
521 if (absPoint.y() < 0)
522 y = muteButtonBox->height();
523 return IntPoint(0, y);
528 Color RenderTheme::activeSelectionBackgroundColor() const
530 if (!m_activeSelectionBackgroundColor.isValid())
531 m_activeSelectionBackgroundColor = platformActiveSelectionBackgroundColor().blendWithWhite();
532 return m_activeSelectionBackgroundColor;
535 Color RenderTheme::inactiveSelectionBackgroundColor() const
537 if (!m_inactiveSelectionBackgroundColor.isValid())
538 m_inactiveSelectionBackgroundColor = platformInactiveSelectionBackgroundColor().blendWithWhite();
539 return m_inactiveSelectionBackgroundColor;
542 Color RenderTheme::activeSelectionForegroundColor() const
544 if (!m_activeSelectionForegroundColor.isValid() && supportsSelectionForegroundColors())
545 m_activeSelectionForegroundColor = platformActiveSelectionForegroundColor();
546 return m_activeSelectionForegroundColor;
549 Color RenderTheme::inactiveSelectionForegroundColor() const
551 if (!m_inactiveSelectionForegroundColor.isValid() && supportsSelectionForegroundColors())
552 m_inactiveSelectionForegroundColor = platformInactiveSelectionForegroundColor();
553 return m_inactiveSelectionForegroundColor;
556 Color RenderTheme::activeListBoxSelectionBackgroundColor() const
558 if (!m_activeListBoxSelectionBackgroundColor.isValid())
559 m_activeListBoxSelectionBackgroundColor = platformActiveListBoxSelectionBackgroundColor();
560 return m_activeListBoxSelectionBackgroundColor;
563 Color RenderTheme::inactiveListBoxSelectionBackgroundColor() const
565 if (!m_inactiveListBoxSelectionBackgroundColor.isValid())
566 m_inactiveListBoxSelectionBackgroundColor = platformInactiveListBoxSelectionBackgroundColor();
567 return m_inactiveListBoxSelectionBackgroundColor;
570 Color RenderTheme::activeListBoxSelectionForegroundColor() const
572 if (!m_activeListBoxSelectionForegroundColor.isValid() && supportsListBoxSelectionForegroundColors())
573 m_activeListBoxSelectionForegroundColor = platformActiveListBoxSelectionForegroundColor();
574 return m_activeListBoxSelectionForegroundColor;
577 Color RenderTheme::inactiveListBoxSelectionForegroundColor() const
579 if (!m_inactiveListBoxSelectionForegroundColor.isValid() && supportsListBoxSelectionForegroundColors())
580 m_inactiveListBoxSelectionForegroundColor = platformInactiveListBoxSelectionForegroundColor();
581 return m_inactiveListBoxSelectionForegroundColor;
584 Color RenderTheme::platformActiveSelectionBackgroundColor() const
586 // Use a blue color by default if the platform theme doesn't define anything.
587 return Color(0, 0, 255);
590 Color RenderTheme::platformActiveSelectionForegroundColor() const
592 // Use a white color by default if the platform theme doesn't define anything.
596 Color RenderTheme::platformInactiveSelectionBackgroundColor() const
598 // Use a grey color by default if the platform theme doesn't define anything.
599 // This color matches Firefox's inactive color.
600 return Color(176, 176, 176);
603 Color RenderTheme::platformInactiveSelectionForegroundColor() const
605 // Use a black color by default.
609 Color RenderTheme::platformActiveListBoxSelectionBackgroundColor() const
611 return platformActiveSelectionBackgroundColor();
614 Color RenderTheme::platformActiveListBoxSelectionForegroundColor() const
616 return platformActiveSelectionForegroundColor();
619 Color RenderTheme::platformInactiveListBoxSelectionBackgroundColor() const
621 return platformInactiveSelectionBackgroundColor();
624 Color RenderTheme::platformInactiveListBoxSelectionForegroundColor() const
626 return platformInactiveSelectionForegroundColor();
629 int RenderTheme::baselinePosition(const RenderObject* o) const
634 const RenderBox* box = toRenderBox(o);
637 return box->height() + box->marginTop() + m_theme->baselinePositionAdjustment(o->style()->appearance()) * o->style()->effectiveZoom();
639 return box->height() + box->marginTop();
643 bool RenderTheme::isControlContainer(ControlPart appearance) const
645 // There are more leaves than this, but we'll patch this function as we add support for
647 return appearance != CheckboxPart && appearance != RadioPart;
650 bool RenderTheme::isControlStyled(const RenderStyle* style, const BorderData& border, const FillLayer& background,
651 const Color& backgroundColor) const
653 switch (style->appearance()) {
655 case SquareButtonPart:
656 case DefaultButtonPart:
660 case ProgressBarPart:
662 case RelevancyLevelIndicatorPart:
663 case ContinuousCapacityLevelIndicatorPart:
664 case DiscreteCapacityLevelIndicatorPart:
665 case RatingLevelIndicatorPart:
666 #if ENABLE(TIZEN_SEARCH_FIELD_STYLE)
667 case SearchFieldPart:
669 // FIXME: Uncomment this when making search fields style-able.
670 // case SearchFieldPart:
673 #if ENABLE(TIZEN_INPUT_TAG_DATE)
677 // Test the style to see if the UA border and background match.
678 return (style->border() != border ||
679 *style->backgroundLayers() != background ||
680 style->visitedDependentColor(CSSPropertyBackgroundColor) != backgroundColor);
686 void RenderTheme::adjustRepaintRect(const RenderObject* o, IntRect& r)
689 m_theme->inflateControlPaintRect(o->style()->appearance(), controlStatesForRenderer(o), r, o->style()->effectiveZoom());
693 bool RenderTheme::supportsFocusRing(const RenderStyle* style) const
695 #if ENABLE(TIZEN_INPUT_TAG_DATE)
696 return (style->hasAppearance() && style->appearance() != TextFieldPart && style->appearance() != DateFieldPart && style->appearance() != TextAreaPart && style->appearance() != MenulistButtonPart && style->appearance() != ListboxPart);
698 return (style->hasAppearance() && style->appearance() != TextFieldPart && style->appearance() != TextAreaPart && style->appearance() != MenulistButtonPart && style->appearance() != ListboxPart);
702 bool RenderTheme::stateChanged(RenderObject* o, ControlState state) const
704 // Default implementation assumes the controls don't respond to changes in :hover state
705 if (state == HoverState && !supportsHover(o->style()))
708 // Assume pressed state is only responded to if the control is enabled.
709 if (state == PressedState && !isEnabled(o))
712 #if ENABLE(TIZEN_EXPEDIA_CALENDAR_FIX)
713 if (state == PressedState && isEnabled(o)) {
714 Node* node = o->node();
716 Frame* frame = node->document()->frame();
718 Page* page = frame->page();
720 if (page->settings()->frameFlatteningEnabled())
721 frame->document()->styleSelectorChanged(DeferRecalcStyle);
727 // Repaint the control.
732 ControlStates RenderTheme::controlStatesForRenderer(const RenderObject* o) const
734 ControlStates result = 0;
736 result |= HoverState;
737 if (isSpinUpButtonPartHovered(o))
738 result |= SpinUpState;
741 result |= PressedState;
742 if (isSpinUpButtonPartPressed(o))
743 result |= SpinUpState;
745 if (isFocused(o) && o->style()->outlineStyleIsAuto())
746 result |= FocusState;
748 result |= EnabledState;
750 result |= CheckedState;
751 if (isReadOnlyControl(o))
752 result |= ReadOnlyState;
754 result |= DefaultState;
756 result |= WindowInactiveState;
757 if (isIndeterminate(o))
758 result |= IndeterminateState;
762 bool RenderTheme::isActive(const RenderObject* o) const
764 Node* node = o->node();
768 Frame* frame = node->document()->frame();
772 Page* page = frame->page();
776 return page->focusController()->isActive();
779 bool RenderTheme::isChecked(const RenderObject* o) const
784 HTMLInputElement* inputElement = o->node()->toInputElement();
788 return inputElement->shouldAppearChecked();
791 bool RenderTheme::isIndeterminate(const RenderObject* o) const
796 HTMLInputElement* inputElement = o->node()->toInputElement();
800 return inputElement->isIndeterminate();
803 bool RenderTheme::isEnabled(const RenderObject* o) const
805 Node* node = o->node();
806 if (!node || !node->isElementNode())
808 return static_cast<Element*>(node)->isEnabledFormControl();
811 bool RenderTheme::isFocused(const RenderObject* o) const
813 Node* node = o->node();
817 node = node->focusDelegate();
818 Document* document = node->document();
819 Frame* frame = document->frame();
820 return node == document->focusedNode() && frame && frame->selection()->isFocusedAndActive();
823 bool RenderTheme::isPressed(const RenderObject* o) const
827 return o->node()->active();
830 bool RenderTheme::isSpinUpButtonPartPressed(const RenderObject* o) const
832 Node* node = o->node();
833 if (!node || !node->active() || !node->isElementNode()
834 || !static_cast<Element*>(node)->isSpinButtonElement())
836 SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
837 return element->upDownState() == SpinButtonElement::Up;
840 bool RenderTheme::isReadOnlyControl(const RenderObject* o) const
842 Node* node = o->node();
843 if (!node || !node->isElementNode())
845 return static_cast<Element*>(node)->isReadOnlyFormControl();
848 bool RenderTheme::isHovered(const RenderObject* o) const
850 Node* node = o->node();
853 if (!node->isElementNode() || !static_cast<Element*>(node)->isSpinButtonElement())
854 return node->hovered();
855 SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
856 return element->hovered() && element->upDownState() != SpinButtonElement::Indeterminate;
859 bool RenderTheme::isSpinUpButtonPartHovered(const RenderObject* o) const
861 Node* node = o->node();
862 if (!node || !node->isElementNode() || !static_cast<Element*>(node)->isSpinButtonElement())
864 SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
865 return element->upDownState() == SpinButtonElement::Up;
868 bool RenderTheme::isDefault(const RenderObject* o) const
870 // A button should only have the default appearance if the page is active
877 Settings* settings = o->document()->settings();
878 if (!settings || !settings->inApplicationChromeMode())
881 return o->style()->appearance() == DefaultButtonPart;
886 void RenderTheme::adjustCheckboxStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
888 // A summary of the rules for checkbox designed to match WinIE:
889 // width/height - honored (WinIE actually scales its control for small widths, but lets it overflow for small heights.)
890 // font-size - not honored (control has no text), but we use it to decide which control size to use.
891 setCheckboxSize(style);
893 // padding - not honored by WinIE, needs to be removed.
894 style->resetPadding();
896 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
897 // for now, we will not honor it.
898 style->resetBorder();
900 style->setBoxShadow(nullptr);
903 void RenderTheme::adjustRadioStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
905 // A summary of the rules for checkbox designed to match WinIE:
906 // width/height - honored (WinIE actually scales its control for small widths, but lets it overflow for small heights.)
907 // font-size - not honored (control has no text), but we use it to decide which control size to use.
910 // padding - not honored by WinIE, needs to be removed.
911 style->resetPadding();
913 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
914 // for now, we will not honor it.
915 style->resetBorder();
917 style->setBoxShadow(nullptr);
920 void RenderTheme::adjustButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
922 // Most platforms will completely honor all CSS, and so we have no need to adjust the style
923 // at all by default. We will still allow the theme a crack at setting up a desired vertical size.
924 setButtonSize(style);
927 void RenderTheme::adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const
932 void RenderTheme::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const
936 #if ENABLE(TIZEN_INPUT_TAG_DATE)
937 void RenderTheme::adjustDateFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const
942 void RenderTheme::adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const
946 void RenderTheme::adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const
950 #if ENABLE(INPUT_SPEECH)
951 void RenderTheme::adjustInputFieldSpeechButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* element) const
953 RenderInputSpeech::adjustInputFieldSpeechButtonStyle(selector, style, element);
956 bool RenderTheme::paintInputFieldSpeechButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
958 return RenderInputSpeech::paintInputFieldSpeechButton(object, paintInfo, rect);
962 #if ENABLE(METER_TAG)
963 void RenderTheme::adjustMeterStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
965 style->setBoxShadow(nullptr);
968 IntSize RenderTheme::meterSizeForBounds(const RenderMeter*, const IntRect& bounds) const
970 return bounds.size();
973 bool RenderTheme::supportsMeter(ControlPart) const
978 bool RenderTheme::paintMeter(RenderObject*, const PaintInfo&, const IntRect&)
985 #if ENABLE(PROGRESS_TAG)
986 double RenderTheme::animationRepeatIntervalForProgressBar(RenderProgress*) const
991 double RenderTheme::animationDurationForProgressBar(RenderProgress*) const
996 void RenderTheme::adjustProgressBarStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1001 bool RenderTheme::shouldHaveSpinButton(HTMLInputElement* inputElement) const
1003 return inputElement->isSteppable() && !inputElement->isRangeControl();
1006 void RenderTheme::adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1010 void RenderTheme::adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1014 void RenderTheme::adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
1016 adjustSliderThumbSize(style);
1019 void RenderTheme::adjustSliderThumbSize(RenderStyle*) const
1023 void RenderTheme::adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1027 void RenderTheme::adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1031 void RenderTheme::adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1035 void RenderTheme::adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1039 void RenderTheme::adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1043 void RenderTheme::platformColorsDidChange()
1045 m_activeSelectionForegroundColor = Color();
1046 m_inactiveSelectionForegroundColor = Color();
1047 m_activeSelectionBackgroundColor = Color();
1048 m_inactiveSelectionBackgroundColor = Color();
1050 m_activeListBoxSelectionForegroundColor = Color();
1051 m_inactiveListBoxSelectionForegroundColor = Color();
1052 m_activeListBoxSelectionBackgroundColor = Color();
1053 m_inactiveListBoxSelectionForegroundColor = Color();
1055 Page::scheduleForcedStyleRecalcForAllPages();
1058 Color RenderTheme::systemColor(int cssValueId) const
1060 switch (cssValueId) {
1061 case CSSValueActiveborder:
1063 case CSSValueActivecaption:
1065 case CSSValueAppworkspace:
1067 case CSSValueBackground:
1069 case CSSValueButtonface:
1071 case CSSValueButtonhighlight:
1073 case CSSValueButtonshadow:
1075 case CSSValueButtontext:
1077 case CSSValueCaptiontext:
1079 case CSSValueGraytext:
1081 case CSSValueHighlight:
1083 case CSSValueHighlighttext:
1085 case CSSValueInactiveborder:
1087 case CSSValueInactivecaption:
1089 case CSSValueInactivecaptiontext:
1091 case CSSValueInfobackground:
1093 case CSSValueInfotext:
1097 case CSSValueMenutext:
1099 case CSSValueScrollbar:
1103 case CSSValueThreeddarkshadow:
1105 case CSSValueThreedface:
1107 case CSSValueThreedhighlight:
1109 case CSSValueThreedlightshadow:
1111 case CSSValueThreedshadow:
1113 case CSSValueWindow:
1115 case CSSValueWindowframe:
1117 case CSSValueWindowtext:
1123 Color RenderTheme::platformActiveTextSearchHighlightColor() const
1125 return Color(255, 150, 50); // Orange.
1128 Color RenderTheme::platformInactiveTextSearchHighlightColor() const
1130 return Color(255, 255, 0); // Yellow.
1133 #if ENABLE(TOUCH_EVENTS)
1134 Color RenderTheme::tapHighlightColor()
1136 return defaultTheme()->platformTapHighlightColor();
1140 void RenderTheme::setCustomFocusRingColor(const Color& c)
1142 customFocusRingColor() = c;
1145 Color RenderTheme::focusRingColor()
1147 return customFocusRingColor().isValid() ? customFocusRingColor() : defaultTheme()->platformFocusRingColor();
1150 String RenderTheme::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed)
1156 if (filenames.isEmpty()) {
1157 if (multipleFilesAllowed)
1158 string = fileButtonNoFilesSelectedLabel();
1160 string = fileButtonNoFileSelectedLabel();
1162 else if (filenames.size() == 1)
1163 string = pathGetFileName(filenames[0]);
1165 return StringTruncator::rightTruncate(multipleFileUploadText(filenames.size()), width, font, StringTruncator::EnableRoundingHacks);
1167 return StringTruncator::centerTruncate(string, width, font, StringTruncator::EnableRoundingHacks);
1170 } // namespace WebCore