• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
33 #include "core/html/shadow/MeterShadowElement.h"
34 
35 #include "CSSPropertyNames.h"
36 #include "HTMLNames.h"
37 #include "core/html/HTMLMeterElement.h"
38 #include "core/rendering/RenderMeter.h"
39 #include "core/rendering/RenderTheme.h"
40 
41 namespace WebCore {
42 
43 using namespace HTMLNames;
44 
MeterShadowElement(Document & document)45 inline MeterShadowElement::MeterShadowElement(Document& document)
46     : HTMLDivElement(document)
47 {
48 }
49 
meterElement() const50 HTMLMeterElement* MeterShadowElement::meterElement() const
51 {
52     return toHTMLMeterElement(shadowHost());
53 }
54 
rendererIsNeeded(const RenderStyle & style)55 bool MeterShadowElement::rendererIsNeeded(const RenderStyle& style)
56 {
57     RenderObject* renderer = meterElement()->renderer();
58     return renderer && !RenderTheme::theme().supportsMeter(renderer->style()->appearance()) && HTMLDivElement::rendererIsNeeded(style);
59 }
60 
MeterInnerElement(Document & document)61 inline MeterInnerElement::MeterInnerElement(Document& document)
62     : MeterShadowElement(document)
63 {
64 }
65 
create(Document & document)66 PassRefPtr<MeterInnerElement> MeterInnerElement::create(Document& document)
67 {
68     RefPtr<MeterInnerElement> element = adoptRef(new MeterInnerElement(document));
69     element->setPseudo(AtomicString("-webkit-meter-inner-element", AtomicString::ConstructFromLiteral));
70     return element.release();
71 }
72 
rendererIsNeeded(const RenderStyle & style)73 bool MeterInnerElement::rendererIsNeeded(const RenderStyle& style)
74 {
75     if (meterElement()->hasAuthorShadowRoot())
76         return HTMLDivElement::rendererIsNeeded(style);
77 
78     RenderObject* renderer = meterElement()->renderer();
79     return renderer && !RenderTheme::theme().supportsMeter(renderer->style()->appearance()) && HTMLDivElement::rendererIsNeeded(style);
80 }
81 
createRenderer(RenderStyle *)82 RenderObject* MeterInnerElement::createRenderer(RenderStyle*)
83 {
84     return new RenderMeter(this);
85 }
86 
MeterBarElement(Document & document)87 inline MeterBarElement::MeterBarElement(Document& document)
88     : MeterShadowElement(document)
89 {
90 }
91 
create(Document & document)92 PassRefPtr<MeterBarElement> MeterBarElement::create(Document& document)
93 {
94     RefPtr<MeterBarElement> element = adoptRef(new MeterBarElement(document));
95     element->setPseudo(AtomicString("-webkit-meter-bar", AtomicString::ConstructFromLiteral));
96     return element.release();
97 }
98 
MeterValueElement(Document & document)99 inline MeterValueElement::MeterValueElement(Document& document)
100     : MeterShadowElement(document)
101 {
102 }
103 
create(Document & document)104 PassRefPtr<MeterValueElement> MeterValueElement::create(Document& document)
105 {
106     RefPtr<MeterValueElement> element = adoptRef(new MeterValueElement(document));
107     element->updatePseudo();
108     return element.release();
109 }
110 
valuePseudoId() const111 const AtomicString& MeterValueElement::valuePseudoId() const
112 {
113     DEFINE_STATIC_LOCAL(AtomicString, optimumPseudoId, ("-webkit-meter-optimum-value", AtomicString::ConstructFromLiteral));
114     DEFINE_STATIC_LOCAL(AtomicString, suboptimumPseudoId, ("-webkit-meter-suboptimum-value", AtomicString::ConstructFromLiteral));
115     DEFINE_STATIC_LOCAL(AtomicString, evenLessGoodPseudoId, ("-webkit-meter-even-less-good-value", AtomicString::ConstructFromLiteral));
116 
117     HTMLMeterElement* meter = meterElement();
118     if (!meter)
119         return optimumPseudoId;
120 
121     switch (meter->gaugeRegion()) {
122     case HTMLMeterElement::GaugeRegionOptimum:
123         return optimumPseudoId;
124     case HTMLMeterElement::GaugeRegionSuboptimal:
125         return suboptimumPseudoId;
126     case HTMLMeterElement::GaugeRegionEvenLessGood:
127         return evenLessGoodPseudoId;
128     default:
129         ASSERT_NOT_REACHED();
130         return optimumPseudoId;
131     }
132 }
133 
setWidthPercentage(double width)134 void MeterValueElement::setWidthPercentage(double width)
135 {
136     setInlineStyleProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
137 }
138 
139 }
140