1/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "config.h"
32#if ENABLE(METER_ELEMENT)
33#include "MeterShadowElement.h"
34
35#include "CSSPropertyNames.h"
36#include "HTMLMeterElement.h"
37#include "HTMLNames.h"
38#include "RenderMeter.h"
39#include "RenderTheme.h"
40#include "ShadowRoot.h"
41#include "StyleProperties.h"
42
43namespace WebCore {
44
45using namespace HTMLNames;
46
47MeterShadowElement::MeterShadowElement(Document& document)
48    : HTMLDivElement(HTMLNames::divTag, document)
49{
50}
51
52HTMLMeterElement* MeterShadowElement::meterElement() const
53{
54    return toHTMLMeterElement(shadowHost());
55}
56
57bool MeterShadowElement::rendererIsNeeded(const RenderStyle& style)
58{
59    auto render = meterElement()->renderer();
60    return render && !render->theme().supportsMeter(render->style().appearance()) && HTMLDivElement::rendererIsNeeded(style);
61}
62
63MeterInnerElement::MeterInnerElement(Document& document)
64    : MeterShadowElement(document)
65{
66    DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-meter-inner-element", AtomicString::ConstructFromLiteral));
67    setPseudo(pseudoId);
68}
69
70bool MeterInnerElement::rendererIsNeeded(const RenderStyle& style)
71{
72    auto render = meterElement()->renderer();
73    return render && !render->theme().supportsMeter(render->style().appearance()) && HTMLDivElement::rendererIsNeeded(style);
74}
75
76RenderPtr<RenderElement> MeterInnerElement::createElementRenderer(PassRef<RenderStyle> style)
77{
78    return createRenderer<RenderMeter>(*this, WTF::move(style));
79}
80
81const AtomicString& MeterValueElement::valuePseudoId() const
82{
83    DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, optimumPseudoId, ("-webkit-meter-optimum-value", AtomicString::ConstructFromLiteral));
84    DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, suboptimumPseudoId, ("-webkit-meter-suboptimum-value", AtomicString::ConstructFromLiteral));
85    DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, evenLessGoodPseudoId, ("-webkit-meter-even-less-good-value", AtomicString::ConstructFromLiteral));
86
87    HTMLMeterElement* meter = meterElement();
88    if (!meter)
89        return optimumPseudoId;
90
91    switch (meter->gaugeRegion()) {
92    case HTMLMeterElement::GaugeRegionOptimum:
93        return optimumPseudoId;
94    case HTMLMeterElement::GaugeRegionSuboptimal:
95        return suboptimumPseudoId;
96    case HTMLMeterElement::GaugeRegionEvenLessGood:
97        return evenLessGoodPseudoId;
98    default:
99        ASSERT_NOT_REACHED();
100        return optimumPseudoId;
101    }
102}
103
104void MeterValueElement::setWidthPercentage(double width)
105{
106    setInlineStyleProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
107}
108
109}
110
111#endif
112
113