tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / rendering / RenderTheme.cpp
1 /**
2  * This file is part of the theme implementation for form controls in WebCore.
3  *
4  * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Computer, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #include "config.h"
23 #include "RenderTheme.h"
24
25 #include "CSSValueKeywords.h"
26 #include "Document.h"
27 #include "FileSystem.h"
28 #include "FloatConversion.h"
29 #include "FocusController.h"
30 #include "FontSelector.h"
31 #include "Frame.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"
38 #include "Page.h"
39 #include "PaintInfo.h"
40 #include "RenderStyle.h"
41 #include "RenderView.h"
42 #include "Settings.h"
43 #include "StringTruncator.h"
44 #include "TextControlInnerElements.h"
45
46 #if ENABLE(METER_TAG)
47 #include "HTMLMeterElement.h"
48 #include "RenderMeter.h"
49 #endif
50
51 #if ENABLE(INPUT_SPEECH)
52 #include "RenderInputSpeech.h"
53 #endif
54
55 // The methods in this file are shared by all themes on every platform.
56
57 namespace WebCore {
58
59 using namespace HTMLNames;
60
61 static Color& customFocusRingColor()
62 {
63     DEFINE_STATIC_LOCAL(Color, color, ());
64     return color;
65 }
66
67 RenderTheme::RenderTheme()
68 #if USE(NEW_THEME)
69     : m_theme(platformTheme())
70 #endif
71 {
72 }
73
74 void RenderTheme::adjustStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e,
75                               bool UAHasAppearance, const BorderData& border, const FillLayer& background, const Color& backgroundColor)
76 {
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);
86
87     if (UAHasAppearance && isControlStyled(style, border, background, backgroundColor)) {
88         if (part == MenulistPart) {
89             style->setAppearance(MenulistButtonPart);
90             part = MenulistButtonPart;
91         } else
92             style->setAppearance(NoControlPart);
93     }
94
95     if (!style->hasAppearance())
96         return;
97
98     // Never support box-shadow on native controls.
99     style->setBoxShadow(nullptr);
100     
101 #if USE(NEW_THEME)
102     switch (part) {
103         case ListButtonPart:
104         case CheckboxPart:
105         case InnerSpinButtonPart:
106         case RadioPart:
107         case PushButtonPart:
108         case SquareButtonPart:
109         case DefaultButtonPart:
110         case ButtonPart: {
111             // Border
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());
117                 else
118                     style->resetBorderTop();
119             }
120             if (borderBox.right().value() != style->borderRightWidth()) {
121                 if (borderBox.right().value())
122                     style->setBorderRightWidth(borderBox.right().value());
123                 else
124                     style->resetBorderRight();
125             }
126             if (borderBox.bottom().value() != style->borderBottomWidth()) {
127                 style->setBorderBottomWidth(borderBox.bottom().value());
128                 if (borderBox.bottom().value())
129                     style->setBorderBottomWidth(borderBox.bottom().value());
130                 else
131                     style->resetBorderBottom();
132             }
133             if (borderBox.left().value() != style->borderLeftWidth()) {
134                 style->setBorderLeftWidth(borderBox.left().value());
135                 if (borderBox.left().value())
136                     style->setBorderLeftWidth(borderBox.left().value());
137                 else
138                     style->resetBorderLeft();
139             }
140
141             // Padding
142             LengthBox paddingBox = m_theme->controlPadding(part, style->font(), style->paddingBox(), style->effectiveZoom());
143             if (paddingBox != style->paddingBox())
144                 style->setPaddingBox(paddingBox);
145
146             // Whitespace
147             if (m_theme->controlRequiresPreWhiteSpace(part))
148                 style->setWhiteSpace(PRE);
149             
150             // Width / Height
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());
158                 
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());
165                 
166             // Font
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());
171                 
172                 // Now update our font.
173                 if (style->setFontDescription(controlFont))
174                     style->font().update(0);
175             }
176         }
177         default:
178             break;
179     }
180 #endif
181
182     // Call the appropriate style adjustment method based off the appearance value.
183     switch (style->appearance()) {
184 #if !USE(NEW_THEME)
185         case CheckboxPart:
186             return adjustCheckboxStyle(selector, style, e);
187         case RadioPart:
188             return adjustRadioStyle(selector, style, e);
189         case PushButtonPart:
190         case SquareButtonPart:
191         case ListButtonPart:
192         case DefaultButtonPart:
193         case ButtonPart:
194             return adjustButtonStyle(selector, style, e);
195         case InnerSpinButtonPart:
196             return adjustInnerSpinButtonStyle(selector, style, e);
197 #endif
198         case TextFieldPart:
199             return adjustTextFieldStyle(selector, style, e);
200 #if ENABLE(TIZEN_INPUT_TAG_DATE)
201         case DateFieldPart:
202             return adjustDateFieldStyle(selector, style, e);
203 #endif
204         case TextAreaPart:
205             return adjustTextAreaStyle(selector, style, e);
206         case MenulistPart:
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);
231 #endif
232 #if ENABLE(METER_TAG)
233         case MeterPart:
234         case RelevancyLevelIndicatorPart:
235         case ContinuousCapacityLevelIndicatorPart:
236         case DiscreteCapacityLevelIndicatorPart:
237         case RatingLevelIndicatorPart:
238             return adjustMeterStyle(selector, style, e);
239 #endif
240 #if ENABLE(INPUT_SPEECH)
241         case InputSpeechButtonPart:
242             return adjustInputFieldSpeechButtonStyle(selector, style, e);
243 #endif
244         default:
245             break;
246     }
247 }
248
249 bool RenderTheme::paint(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
250 {
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
253     // for that control.
254     if (paintInfo.context->updatingControlTints()) {
255         if (controlSupportsTints(o))
256             o->repaint();
257         return false;
258     }
259     if (paintInfo.context->paintingDisabled())
260         return false;
261
262     ControlPart part = o->style()->appearance();
263
264 #if USE(NEW_THEME)
265     switch (part) {
266         case CheckboxPart:
267         case RadioPart:
268         case PushButtonPart:
269         case SquareButtonPart:
270         case ListButtonPart:
271         case DefaultButtonPart:
272         case ButtonPart:
273         case InnerSpinButtonPart:
274             m_theme->paint(part, controlStatesForRenderer(o), const_cast<GraphicsContext*>(paintInfo.context), r, o->style()->effectiveZoom(), o->view()->frameView());
275             return false;
276         default:
277             break;
278     }
279 #endif
280
281     // Call the appropriate paint method based off the appearance value.
282     switch (part) {
283 #if !USE(NEW_THEME)
284         case CheckboxPart:
285             return paintCheckbox(o, paintInfo, r);
286         case RadioPart:
287             return paintRadio(o, paintInfo, r);
288         case PushButtonPart:
289         case SquareButtonPart:
290         case ListButtonPart:
291         case DefaultButtonPart:
292         case ButtonPart:
293             return paintButton(o, paintInfo, r);
294         case InnerSpinButtonPart:
295             return paintInnerSpinButton(o, paintInfo, r);
296 #endif
297         case MenulistPart:
298             return paintMenuList(o, paintInfo, r);
299 #if ENABLE(METER_TAG)
300         case MeterPart:
301         case RelevancyLevelIndicatorPart:
302         case ContinuousCapacityLevelIndicatorPart:
303         case DiscreteCapacityLevelIndicatorPart:
304         case RatingLevelIndicatorPart:
305             return paintMeter(o, paintInfo, r);
306 #endif
307 #if ENABLE(PROGRESS_TAG)
308         case ProgressBarPart:
309             return paintProgressBar(o, paintInfo, r);
310 #endif
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:
352         case TextFieldPart:
353 #if ENABLE(TIZEN_INPUT_TAG_DATE)
354         case DateFieldPart:
355 #endif
356         case TextAreaPart:
357         case ListboxPart:
358             return true;
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);
372 #endif
373         default:
374             break;
375     }
376
377     return true; // We don't support the appearance, so let the normal background/border paint.
378 }
379
380 bool RenderTheme::paintBorderOnly(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
381 {
382     if (paintInfo.context->paintingDisabled())
383         return false;
384
385     // Call the appropriate paint method based off the appearance value.
386     switch (o->style()->appearance()) {
387         case TextFieldPart:
388             return paintTextField(o, paintInfo, r);
389 #if ENABLE(TIZEN_INPUT_TAG_DATE)
390         case DateFieldPart:
391             return paintDateField(o, paintInfo, r);
392 #endif
393         case ListboxPart:
394         case TextAreaPart:
395             return paintTextArea(o, paintInfo, r);
396         case MenulistButtonPart:
397         case SearchFieldPart:
398             return true;
399         case CheckboxPart:
400         case RadioPart:
401         case PushButtonPart:
402         case SquareButtonPart:
403         case ListButtonPart:
404         case DefaultButtonPart:
405         case ButtonPart:
406         case MenulistPart:
407 #if ENABLE(METER_TAG)
408         case MeterPart:
409         case RelevancyLevelIndicatorPart:
410         case ContinuousCapacityLevelIndicatorPart:
411         case DiscreteCapacityLevelIndicatorPart:
412         case RatingLevelIndicatorPart:
413 #endif
414 #if ENABLE(PROGRESS_TAG)
415         case ProgressBarPart:
416 #endif
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:
427 #endif
428         default:
429             break;
430     }
431
432     return false;
433 }
434
435 bool RenderTheme::paintDecorations(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
436 {
437     if (paintInfo.context->paintingDisabled())
438         return false;
439
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);
444         case TextFieldPart:
445 #if ENABLE(TIZEN_INPUT_TAG_DATE)
446         case DateFieldPart:
447 #endif
448         case TextAreaPart:
449         case ListboxPart:
450         case CheckboxPart:
451         case RadioPart:
452         case PushButtonPart:
453         case SquareButtonPart:
454         case ListButtonPart:
455         case DefaultButtonPart:
456         case ButtonPart:
457         case MenulistPart:
458 #if ENABLE(METER_TAG)
459         case MeterPart:
460         case RelevancyLevelIndicatorPart:
461         case ContinuousCapacityLevelIndicatorPart:
462         case DiscreteCapacityLevelIndicatorPart:
463         case RatingLevelIndicatorPart:
464 #endif
465 #if ENABLE(PROGRESS_TAG)
466         case ProgressBarPart:
467 #endif
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:
479 #endif
480         default:
481             break;
482     }
483
484     return false;
485 }
486
487 #if ENABLE(VIDEO)
488
489 String RenderTheme::formatMediaControlsTime(float time) const
490 {
491     if (!isfinite(time))
492         time = 0;
493     int seconds = (int)fabsf(time);
494     int hours = seconds / (60 * 60);
495     int minutes = (seconds / 60) % 60;
496     seconds %= 60;
497     if (hours) {
498         if (hours > 9)
499             return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
500
501         return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
502     }
503
504     return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds);
505 }
506
507 String RenderTheme::formatMediaControlsCurrentTime(float currentTime, float /*duration*/) const
508 {
509     return formatMediaControlsTime(currentTime);
510 }
511
512 String RenderTheme::formatMediaControlsRemainingTime(float currentTime, float duration) const
513 {
514     return formatMediaControlsTime(currentTime - duration);
515 }
516
517 IntPoint RenderTheme::volumeSliderOffsetFromMuteButton(RenderBox* muteButtonBox, const IntSize& size) const
518 {
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);
524 }
525
526 #endif
527
528 Color RenderTheme::activeSelectionBackgroundColor() const
529 {
530     if (!m_activeSelectionBackgroundColor.isValid())
531         m_activeSelectionBackgroundColor = platformActiveSelectionBackgroundColor().blendWithWhite();
532     return m_activeSelectionBackgroundColor;
533 }
534
535 Color RenderTheme::inactiveSelectionBackgroundColor() const
536 {
537     if (!m_inactiveSelectionBackgroundColor.isValid())
538         m_inactiveSelectionBackgroundColor = platformInactiveSelectionBackgroundColor().blendWithWhite();
539     return m_inactiveSelectionBackgroundColor;
540 }
541
542 Color RenderTheme::activeSelectionForegroundColor() const
543 {
544     if (!m_activeSelectionForegroundColor.isValid() && supportsSelectionForegroundColors())
545         m_activeSelectionForegroundColor = platformActiveSelectionForegroundColor();
546     return m_activeSelectionForegroundColor;
547 }
548
549 Color RenderTheme::inactiveSelectionForegroundColor() const
550 {
551     if (!m_inactiveSelectionForegroundColor.isValid() && supportsSelectionForegroundColors())
552         m_inactiveSelectionForegroundColor = platformInactiveSelectionForegroundColor();
553     return m_inactiveSelectionForegroundColor;
554 }
555
556 Color RenderTheme::activeListBoxSelectionBackgroundColor() const
557 {
558     if (!m_activeListBoxSelectionBackgroundColor.isValid())
559         m_activeListBoxSelectionBackgroundColor = platformActiveListBoxSelectionBackgroundColor();
560     return m_activeListBoxSelectionBackgroundColor;
561 }
562
563 Color RenderTheme::inactiveListBoxSelectionBackgroundColor() const
564 {
565     if (!m_inactiveListBoxSelectionBackgroundColor.isValid())
566         m_inactiveListBoxSelectionBackgroundColor = platformInactiveListBoxSelectionBackgroundColor();
567     return m_inactiveListBoxSelectionBackgroundColor;
568 }
569
570 Color RenderTheme::activeListBoxSelectionForegroundColor() const
571 {
572     if (!m_activeListBoxSelectionForegroundColor.isValid() && supportsListBoxSelectionForegroundColors())
573         m_activeListBoxSelectionForegroundColor = platformActiveListBoxSelectionForegroundColor();
574     return m_activeListBoxSelectionForegroundColor;
575 }
576
577 Color RenderTheme::inactiveListBoxSelectionForegroundColor() const
578 {
579     if (!m_inactiveListBoxSelectionForegroundColor.isValid() && supportsListBoxSelectionForegroundColors())
580         m_inactiveListBoxSelectionForegroundColor = platformInactiveListBoxSelectionForegroundColor();
581     return m_inactiveListBoxSelectionForegroundColor;
582 }
583
584 Color RenderTheme::platformActiveSelectionBackgroundColor() const
585 {
586     // Use a blue color by default if the platform theme doesn't define anything.
587     return Color(0, 0, 255);
588 }
589
590 Color RenderTheme::platformActiveSelectionForegroundColor() const
591 {
592     // Use a white color by default if the platform theme doesn't define anything.
593     return Color::white;
594 }
595
596 Color RenderTheme::platformInactiveSelectionBackgroundColor() const
597 {
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);
601 }
602
603 Color RenderTheme::platformInactiveSelectionForegroundColor() const
604 {
605     // Use a black color by default.
606     return Color::black;
607 }
608
609 Color RenderTheme::platformActiveListBoxSelectionBackgroundColor() const
610 {
611     return platformActiveSelectionBackgroundColor();
612 }
613
614 Color RenderTheme::platformActiveListBoxSelectionForegroundColor() const
615 {
616     return platformActiveSelectionForegroundColor();
617 }
618
619 Color RenderTheme::platformInactiveListBoxSelectionBackgroundColor() const
620 {
621     return platformInactiveSelectionBackgroundColor();
622 }
623
624 Color RenderTheme::platformInactiveListBoxSelectionForegroundColor() const
625 {
626     return platformInactiveSelectionForegroundColor();
627 }
628
629 int RenderTheme::baselinePosition(const RenderObject* o) const
630 {
631     if (!o->isBox())
632         return 0;
633
634     const RenderBox* box = toRenderBox(o);
635
636 #if USE(NEW_THEME)
637     return box->height() + box->marginTop() + m_theme->baselinePositionAdjustment(o->style()->appearance()) * o->style()->effectiveZoom();
638 #else
639     return box->height() + box->marginTop();
640 #endif
641 }
642
643 bool RenderTheme::isControlContainer(ControlPart appearance) const
644 {
645     // There are more leaves than this, but we'll patch this function as we add support for
646     // more controls.
647     return appearance != CheckboxPart && appearance != RadioPart;
648 }
649
650 bool RenderTheme::isControlStyled(const RenderStyle* style, const BorderData& border, const FillLayer& background,
651                                   const Color& backgroundColor) const
652 {
653     switch (style->appearance()) {
654         case PushButtonPart:
655         case SquareButtonPart:
656         case DefaultButtonPart:
657         case ButtonPart:
658         case ListboxPart:
659         case MenulistPart:
660         case ProgressBarPart:
661         case MeterPart:
662         case RelevancyLevelIndicatorPart:
663         case ContinuousCapacityLevelIndicatorPart:
664         case DiscreteCapacityLevelIndicatorPart:
665         case RatingLevelIndicatorPart:
666 #if ENABLE(TIZEN_SEARCH_FIELD_STYLE)
667         case SearchFieldPart:
668 #else
669         // FIXME: Uncomment this when making search fields style-able.
670         // case SearchFieldPart:
671 #endif
672         case TextFieldPart:
673 #if ENABLE(TIZEN_INPUT_TAG_DATE)
674         case DateFieldPart:
675 #endif
676         case TextAreaPart:
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);
681         default:
682             return false;
683     }
684 }
685
686 void RenderTheme::adjustRepaintRect(const RenderObject* o, IntRect& r)
687 {
688 #if USE(NEW_THEME)
689     m_theme->inflateControlPaintRect(o->style()->appearance(), controlStatesForRenderer(o), r, o->style()->effectiveZoom());
690 #endif
691 }
692
693 bool RenderTheme::supportsFocusRing(const RenderStyle* style) const
694 {
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);
697 #else
698     return (style->hasAppearance() && style->appearance() != TextFieldPart && style->appearance() != TextAreaPart && style->appearance() != MenulistButtonPart && style->appearance() != ListboxPart);
699 #endif
700 }
701
702 bool RenderTheme::stateChanged(RenderObject* o, ControlState state) const
703 {
704     // Default implementation assumes the controls don't respond to changes in :hover state
705     if (state == HoverState && !supportsHover(o->style()))
706         return false;
707
708     // Assume pressed state is only responded to if the control is enabled.
709     if (state == PressedState && !isEnabled(o))
710         return false;
711
712 #if ENABLE(TIZEN_EXPEDIA_CALENDAR_FIX)
713     if (state == PressedState && isEnabled(o)) {
714         Node* node = o->node();
715         if (node) {
716             Frame* frame = node->document()->frame();
717             if (frame) {
718                 Page* page = frame->page();
719                 if (page)
720                     if (page->settings()->frameFlatteningEnabled())
721                         frame->document()->styleSelectorChanged(DeferRecalcStyle);
722             }
723         }
724     }
725 #endif
726
727     // Repaint the control.
728     o->repaint();
729     return true;
730 }
731
732 ControlStates RenderTheme::controlStatesForRenderer(const RenderObject* o) const
733 {
734     ControlStates result = 0;
735     if (isHovered(o)) {
736         result |= HoverState;
737         if (isSpinUpButtonPartHovered(o))
738             result |= SpinUpState;
739     }
740     if (isPressed(o)) {
741         result |= PressedState;
742         if (isSpinUpButtonPartPressed(o))
743             result |= SpinUpState;
744     }
745     if (isFocused(o) && o->style()->outlineStyleIsAuto())
746         result |= FocusState;
747     if (isEnabled(o))
748         result |= EnabledState;
749     if (isChecked(o))
750         result |= CheckedState;
751     if (isReadOnlyControl(o))
752         result |= ReadOnlyState;
753     if (isDefault(o))
754         result |= DefaultState;
755     if (!isActive(o))
756         result |= WindowInactiveState;
757     if (isIndeterminate(o))
758         result |= IndeterminateState;
759     return result;
760 }
761
762 bool RenderTheme::isActive(const RenderObject* o) const
763 {
764     Node* node = o->node();
765     if (!node)
766         return false;
767
768     Frame* frame = node->document()->frame();
769     if (!frame)
770         return false;
771
772     Page* page = frame->page();
773     if (!page)
774         return false;
775
776     return page->focusController()->isActive();
777 }
778
779 bool RenderTheme::isChecked(const RenderObject* o) const
780 {
781     if (!o->node())
782         return false;
783
784     HTMLInputElement* inputElement = o->node()->toInputElement();
785     if (!inputElement)
786         return false;
787
788     return inputElement->shouldAppearChecked();
789 }
790
791 bool RenderTheme::isIndeterminate(const RenderObject* o) const
792 {
793     if (!o->node())
794         return false;
795
796     HTMLInputElement* inputElement = o->node()->toInputElement();
797     if (!inputElement)
798         return false;
799
800     return inputElement->isIndeterminate();
801 }
802
803 bool RenderTheme::isEnabled(const RenderObject* o) const
804 {
805     Node* node = o->node();
806     if (!node || !node->isElementNode())
807         return true;
808     return static_cast<Element*>(node)->isEnabledFormControl();
809 }
810
811 bool RenderTheme::isFocused(const RenderObject* o) const
812 {
813     Node* node = o->node();
814     if (!node)
815         return false;
816
817     node = node->focusDelegate();
818     Document* document = node->document();
819     Frame* frame = document->frame();
820     return node == document->focusedNode() && frame && frame->selection()->isFocusedAndActive();
821 }
822
823 bool RenderTheme::isPressed(const RenderObject* o) const
824 {
825     if (!o->node())
826         return false;
827     return o->node()->active();
828 }
829
830 bool RenderTheme::isSpinUpButtonPartPressed(const RenderObject* o) const
831 {
832     Node* node = o->node();
833     if (!node || !node->active() || !node->isElementNode()
834         || !static_cast<Element*>(node)->isSpinButtonElement())
835         return false;
836     SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
837     return element->upDownState() == SpinButtonElement::Up;
838 }
839
840 bool RenderTheme::isReadOnlyControl(const RenderObject* o) const
841 {
842     Node* node = o->node();
843     if (!node || !node->isElementNode())
844         return false;
845     return static_cast<Element*>(node)->isReadOnlyFormControl();
846 }
847
848 bool RenderTheme::isHovered(const RenderObject* o) const
849 {
850     Node* node = o->node();
851     if (!node)
852         return false;
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;
857 }
858
859 bool RenderTheme::isSpinUpButtonPartHovered(const RenderObject* o) const
860 {
861     Node* node = o->node();
862     if (!node || !node->isElementNode() || !static_cast<Element*>(node)->isSpinButtonElement())
863         return false;
864     SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
865     return element->upDownState() == SpinButtonElement::Up;
866 }
867
868 bool RenderTheme::isDefault(const RenderObject* o) const
869 {
870     // A button should only have the default appearance if the page is active
871     if (!isActive(o))
872         return false;
873
874     if (!o->document())
875         return false;
876
877     Settings* settings = o->document()->settings();
878     if (!settings || !settings->inApplicationChromeMode())
879         return false;
880     
881     return o->style()->appearance() == DefaultButtonPart;
882 }
883
884 #if !USE(NEW_THEME)
885
886 void RenderTheme::adjustCheckboxStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
887 {
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);
892
893     // padding - not honored by WinIE, needs to be removed.
894     style->resetPadding();
895
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();
899
900     style->setBoxShadow(nullptr);
901 }
902
903 void RenderTheme::adjustRadioStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
904 {
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.
908     setRadioSize(style);
909
910     // padding - not honored by WinIE, needs to be removed.
911     style->resetPadding();
912
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();
916
917     style->setBoxShadow(nullptr);
918 }
919
920 void RenderTheme::adjustButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
921 {
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);
925 }
926
927 void RenderTheme::adjustInnerSpinButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const
928 {
929 }
930 #endif
931
932 void RenderTheme::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const
933 {
934 }
935
936 #if ENABLE(TIZEN_INPUT_TAG_DATE)
937 void RenderTheme::adjustDateFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const
938 {
939 }
940 #endif
941
942 void RenderTheme::adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const
943 {
944 }
945
946 void RenderTheme::adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const
947 {
948 }
949
950 #if ENABLE(INPUT_SPEECH)
951 void RenderTheme::adjustInputFieldSpeechButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* element) const
952 {
953     RenderInputSpeech::adjustInputFieldSpeechButtonStyle(selector, style, element);
954 }
955
956 bool RenderTheme::paintInputFieldSpeechButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
957 {
958     return RenderInputSpeech::paintInputFieldSpeechButton(object, paintInfo, rect);
959 }
960 #endif
961
962 #if ENABLE(METER_TAG)
963 void RenderTheme::adjustMeterStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
964 {
965     style->setBoxShadow(nullptr);
966 }
967
968 IntSize RenderTheme::meterSizeForBounds(const RenderMeter*, const IntRect& bounds) const
969 {
970     return bounds.size();
971 }
972
973 bool RenderTheme::supportsMeter(ControlPart) const
974 {
975     return false;
976 }
977
978 bool RenderTheme::paintMeter(RenderObject*, const PaintInfo&, const IntRect&)
979 {
980     return true;
981 }
982
983 #endif
984
985 #if ENABLE(PROGRESS_TAG)
986 double RenderTheme::animationRepeatIntervalForProgressBar(RenderProgress*) const
987 {
988     return 0;
989 }
990
991 double RenderTheme::animationDurationForProgressBar(RenderProgress*) const
992 {
993     return 0;
994 }
995
996 void RenderTheme::adjustProgressBarStyle(CSSStyleSelector*, RenderStyle*, Element*) const
997 {
998 }
999 #endif
1000
1001 bool RenderTheme::shouldHaveSpinButton(HTMLInputElement* inputElement) const
1002 {
1003     return inputElement->isSteppable() && !inputElement->isRangeControl();
1004 }
1005
1006 void RenderTheme::adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1007 {
1008 }
1009
1010 void RenderTheme::adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1011 {
1012 }
1013
1014 void RenderTheme::adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
1015 {
1016     adjustSliderThumbSize(style);
1017 }
1018
1019 void RenderTheme::adjustSliderThumbSize(RenderStyle*) const
1020 {
1021 }
1022
1023 void RenderTheme::adjustSearchFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1024 {
1025 }
1026
1027 void RenderTheme::adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1028 {
1029 }
1030
1031 void RenderTheme::adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1032 {
1033 }
1034
1035 void RenderTheme::adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1036 {
1037 }
1038
1039 void RenderTheme::adjustSearchFieldResultsButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const
1040 {
1041 }
1042
1043 void RenderTheme::platformColorsDidChange()
1044 {
1045     m_activeSelectionForegroundColor = Color();
1046     m_inactiveSelectionForegroundColor = Color();
1047     m_activeSelectionBackgroundColor = Color();
1048     m_inactiveSelectionBackgroundColor = Color();
1049
1050     m_activeListBoxSelectionForegroundColor = Color();
1051     m_inactiveListBoxSelectionForegroundColor = Color();
1052     m_activeListBoxSelectionBackgroundColor = Color();
1053     m_inactiveListBoxSelectionForegroundColor = Color();
1054
1055     Page::scheduleForcedStyleRecalcForAllPages();
1056 }
1057
1058 Color RenderTheme::systemColor(int cssValueId) const
1059 {
1060     switch (cssValueId) {
1061         case CSSValueActiveborder:
1062             return 0xFFFFFFFF;
1063         case CSSValueActivecaption:
1064             return 0xFFCCCCCC;
1065         case CSSValueAppworkspace:
1066             return 0xFFFFFFFF;
1067         case CSSValueBackground:
1068             return 0xFF6363CE;
1069         case CSSValueButtonface:
1070             return 0xFFC0C0C0;
1071         case CSSValueButtonhighlight:
1072             return 0xFFDDDDDD;
1073         case CSSValueButtonshadow:
1074             return 0xFF888888;
1075         case CSSValueButtontext:
1076             return 0xFF000000;
1077         case CSSValueCaptiontext:
1078             return 0xFF000000;
1079         case CSSValueGraytext:
1080             return 0xFF808080;
1081         case CSSValueHighlight:
1082             return 0xFFB5D5FF;
1083         case CSSValueHighlighttext:
1084             return 0xFF000000;
1085         case CSSValueInactiveborder:
1086             return 0xFFFFFFFF;
1087         case CSSValueInactivecaption:
1088             return 0xFFFFFFFF;
1089         case CSSValueInactivecaptiontext:
1090             return 0xFF7F7F7F;
1091         case CSSValueInfobackground:
1092             return 0xFFFBFCC5;
1093         case CSSValueInfotext:
1094             return 0xFF000000;
1095         case CSSValueMenu:
1096             return 0xFFC0C0C0;
1097         case CSSValueMenutext:
1098             return 0xFF000000;
1099         case CSSValueScrollbar:
1100             return 0xFFFFFFFF;
1101         case CSSValueText:
1102             return 0xFF000000;
1103         case CSSValueThreeddarkshadow:
1104             return 0xFF666666;
1105         case CSSValueThreedface:
1106             return 0xFFC0C0C0;
1107         case CSSValueThreedhighlight:
1108             return 0xFFDDDDDD;
1109         case CSSValueThreedlightshadow:
1110             return 0xFFC0C0C0;
1111         case CSSValueThreedshadow:
1112             return 0xFF888888;
1113         case CSSValueWindow:
1114             return 0xFFFFFFFF;
1115         case CSSValueWindowframe:
1116             return 0xFFCCCCCC;
1117         case CSSValueWindowtext:
1118             return 0xFF000000;
1119     }
1120     return Color();
1121 }
1122
1123 Color RenderTheme::platformActiveTextSearchHighlightColor() const
1124 {
1125     return Color(255, 150, 50); // Orange.
1126 }
1127
1128 Color RenderTheme::platformInactiveTextSearchHighlightColor() const
1129 {
1130     return Color(255, 255, 0); // Yellow.
1131 }
1132
1133 #if ENABLE(TOUCH_EVENTS)
1134 Color RenderTheme::tapHighlightColor()
1135 {
1136     return defaultTheme()->platformTapHighlightColor();
1137 }
1138 #endif
1139
1140 void RenderTheme::setCustomFocusRingColor(const Color& c)
1141 {
1142     customFocusRingColor() = c;
1143 }
1144
1145 Color RenderTheme::focusRingColor()
1146 {
1147     return customFocusRingColor().isValid() ? customFocusRingColor() : defaultTheme()->platformFocusRingColor();
1148 }
1149
1150 String RenderTheme::fileListNameForWidth(const Vector<String>& filenames, const Font& font, int width, bool multipleFilesAllowed)
1151 {
1152     if (width <= 0)
1153         return String();
1154
1155     String string;
1156     if (filenames.isEmpty()) {
1157         if (multipleFilesAllowed)
1158             string = fileButtonNoFilesSelectedLabel();
1159         else
1160             string = fileButtonNoFileSelectedLabel();
1161     }
1162     else if (filenames.size() == 1)
1163         string = pathGetFileName(filenames[0]);
1164     else
1165         return StringTruncator::rightTruncate(multipleFileUploadText(filenames.size()), width, font, StringTruncator::EnableRoundingHacks);
1166
1167     return StringTruncator::centerTruncate(string, width, font, StringTruncator::EnableRoundingHacks);
1168 }
1169
1170 } // namespace WebCore