• 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 #if ENABLE(METER_TAG)
33 #include "MeterShadowElement.h"
34 
35 #include "CSSMutableStyleDeclaration.h"
36 #include "CSSPropertyNames.h"
37 #include "HTMLMeterElement.h"
38 #include "HTMLNames.h"
39 #include "RenderMeter.h"
40 #include "RenderTheme.h"
41 
42 namespace WebCore {
43 
44 using namespace HTMLNames;
45 
MeterShadowElement(Document * document)46 MeterShadowElement::MeterShadowElement(Document* document)
47     : HTMLDivElement(HTMLNames::divTag, document)
48 {
49 }
50 
meterElement() const51 HTMLMeterElement* MeterShadowElement::meterElement() const
52 {
53     Node* node = const_cast<MeterShadowElement*>(this)->shadowAncestorNode();
54     ASSERT(!node || meterTag == toElement(node)->tagQName());
55     return static_cast<HTMLMeterElement*>(node);
56 }
57 
rendererIsNeeded(RenderStyle * style)58 bool MeterShadowElement::rendererIsNeeded(RenderStyle* style)
59 {
60     RenderMeter* meterRenderer = toRenderMeter(meterElement()->renderer());
61     return meterRenderer && !meterRenderer->theme()->supportsMeter(meterRenderer->style()->appearance()) && HTMLDivElement::rendererIsNeeded(style);
62 }
63 
shadowPseudoId() const64 const AtomicString& MeterBarElement::shadowPseudoId() const
65 {
66     DEFINE_STATIC_LOCAL(AtomicString, pseudId, ("-webkit-meter-bar"));
67     return pseudId;
68 }
69 
70 
shadowPseudoId() const71 const AtomicString& MeterValueElement::shadowPseudoId() const
72 {
73     DEFINE_STATIC_LOCAL(AtomicString, optimumPseudId, ("-webkit-meter-optimum-value"));
74     DEFINE_STATIC_LOCAL(AtomicString, suboptimumPseudId, ("-webkit-meter-suboptimum-value"));
75     DEFINE_STATIC_LOCAL(AtomicString, evenLessGoodPseudId, ("-webkit-meter-even-less-good-value"));
76 
77     HTMLMeterElement* meter = meterElement();
78     if (!meter)
79         return optimumPseudId;
80 
81     switch (meter->gaugeRegion()) {
82     case HTMLMeterElement::GaugeRegionOptimum:
83         return optimumPseudId;
84     case HTMLMeterElement::GaugeRegionSuboptimal:
85         return suboptimumPseudId;
86     case HTMLMeterElement::GaugeRegionEvenLessGood:
87         return evenLessGoodPseudId;
88     default:
89         ASSERT_NOT_REACHED();
90         return optimumPseudId;
91     }
92 }
93 
setWidthPercentage(double width)94 void MeterValueElement::setWidthPercentage(double width)
95 {
96     getInlineStyleDecl()->setProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
97 }
98 
99 
100 }
101 
102 #endif
103 
104