OLD | NEW |
| (Empty) |
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 | |
32 #include "core/html/shadow/MeterShadowElement.h" | |
33 | |
34 #include "core/CSSPropertyNames.h" | |
35 #include "core/HTMLNames.h" | |
36 #include "core/html/HTMLMeterElement.h" | |
37 #include "core/layout/LayoutMeter.h" | |
38 #include "core/layout/LayoutTheme.h" | |
39 | |
40 namespace blink { | |
41 | |
42 using namespace HTMLNames; | |
43 | |
44 inline MeterShadowElement::MeterShadowElement(Document& document) | |
45 : HTMLDivElement(document) | |
46 { | |
47 } | |
48 | |
49 HTMLMeterElement* MeterShadowElement::meterElement() const | |
50 { | |
51 return toHTMLMeterElement(shadowHost()); | |
52 } | |
53 | |
54 bool MeterShadowElement::layoutObjectIsNeeded(const ComputedStyle& style) | |
55 { | |
56 LayoutObject* layoutObject = meterElement()->layoutObject(); | |
57 return layoutObject && !LayoutTheme::theme().supportsMeter(layoutObject->sty
le()->appearance()) && HTMLDivElement::layoutObjectIsNeeded(style); | |
58 } | |
59 | |
60 inline MeterInnerElement::MeterInnerElement(Document& document) | |
61 : MeterShadowElement(document) | |
62 { | |
63 } | |
64 | |
65 PassRefPtrWillBeRawPtr<MeterInnerElement> MeterInnerElement::create(Document& do
cument) | |
66 { | |
67 RefPtrWillBeRawPtr<MeterInnerElement> element = adoptRefWillBeNoop(new Meter
InnerElement(document)); | |
68 element->setShadowPseudoId(AtomicString("-webkit-meter-inner-element", Atomi
cString::ConstructFromLiteral)); | |
69 return element.release(); | |
70 } | |
71 | |
72 bool MeterInnerElement::layoutObjectIsNeeded(const ComputedStyle& style) | |
73 { | |
74 if (meterElement()->openShadowRoot()) | |
75 return HTMLDivElement::layoutObjectIsNeeded(style); | |
76 | |
77 LayoutObject* layoutObject = meterElement()->layoutObject(); | |
78 return layoutObject && !LayoutTheme::theme().supportsMeter(layoutObject->sty
le()->appearance()) && HTMLDivElement::layoutObjectIsNeeded(style); | |
79 } | |
80 | |
81 LayoutObject* MeterInnerElement::createLayoutObject(const ComputedStyle&) | |
82 { | |
83 return new LayoutMeter(this); | |
84 } | |
85 | |
86 inline MeterBarElement::MeterBarElement(Document& document) | |
87 : MeterShadowElement(document) | |
88 { | |
89 } | |
90 | |
91 PassRefPtrWillBeRawPtr<MeterBarElement> MeterBarElement::create(Document& docume
nt) | |
92 { | |
93 RefPtrWillBeRawPtr<MeterBarElement> element = adoptRefWillBeNoop(new MeterBa
rElement(document)); | |
94 element->setShadowPseudoId(AtomicString("-webkit-meter-bar", AtomicString::C
onstructFromLiteral)); | |
95 return element.release(); | |
96 } | |
97 | |
98 inline MeterValueElement::MeterValueElement(Document& document) | |
99 : MeterShadowElement(document) | |
100 { | |
101 } | |
102 | |
103 PassRefPtrWillBeRawPtr<MeterValueElement> MeterValueElement::create(Document& do
cument) | |
104 { | |
105 RefPtrWillBeRawPtr<MeterValueElement> element = adoptRefWillBeNoop(new Meter
ValueElement(document)); | |
106 element->updatePseudo(); | |
107 return element.release(); | |
108 } | |
109 | |
110 const AtomicString& MeterValueElement::valuePseudoId() const | |
111 { | |
112 DEFINE_STATIC_LOCAL(AtomicString, optimumPseudoId, ("-webkit-meter-optimum-v
alue", AtomicString::ConstructFromLiteral)); | |
113 DEFINE_STATIC_LOCAL(AtomicString, suboptimumPseudoId, ("-webkit-meter-subopt
imum-value", AtomicString::ConstructFromLiteral)); | |
114 DEFINE_STATIC_LOCAL(AtomicString, evenLessGoodPseudoId, ("-webkit-meter-even
-less-good-value", AtomicString::ConstructFromLiteral)); | |
115 | |
116 HTMLMeterElement* meter = meterElement(); | |
117 if (!meter) | |
118 return optimumPseudoId; | |
119 | |
120 switch (meter->gaugeRegion()) { | |
121 case HTMLMeterElement::GaugeRegionOptimum: | |
122 return optimumPseudoId; | |
123 case HTMLMeterElement::GaugeRegionSuboptimal: | |
124 return suboptimumPseudoId; | |
125 case HTMLMeterElement::GaugeRegionEvenLessGood: | |
126 return evenLessGoodPseudoId; | |
127 default: | |
128 ASSERT_NOT_REACHED(); | |
129 return optimumPseudoId; | |
130 } | |
131 } | |
132 | |
133 void MeterValueElement::setWidthPercentage(double width) | |
134 { | |
135 setInlineStyleProperty(CSSPropertyWidth, width, CSSPrimitiveValue::UnitType:
:Percentage); | |
136 } | |
137 | |
138 } // namespace blink | |
OLD | NEW |