2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
33 #include "MeterShadowElement.h"
35 #include "CSSMutableStyleDeclaration.h"
36 #include "CSSPropertyNames.h"
37 #include "HTMLMeterElement.h"
38 #include "HTMLNames.h"
39 #include "RenderMeter.h"
40 #include "RenderTheme.h"
44 using namespace HTMLNames;
46 MeterShadowElement::MeterShadowElement(Document* document)
47 : HTMLDivElement(HTMLNames::divTag, document)
51 HTMLMeterElement* MeterShadowElement::meterElement() const
53 Node* node = const_cast<MeterShadowElement*>(this)->shadowAncestorNode();
54 ASSERT(!node || meterTag == toElement(node)->tagQName());
55 return static_cast<HTMLMeterElement*>(node);
58 bool MeterShadowElement::rendererIsNeeded(const NodeRenderingContext& context)
60 RenderMeter* meterRenderer = toRenderMeter(meterElement()->renderer());
61 return meterRenderer && !meterRenderer->theme()->supportsMeter(meterRenderer->style()->appearance()) && HTMLDivElement::rendererIsNeeded(context);
64 const AtomicString& MeterBarElement::shadowPseudoId() const
66 DEFINE_STATIC_LOCAL(AtomicString, pseudId, ("-webkit-meter-bar"));
71 const AtomicString& MeterValueElement::shadowPseudoId() const
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"));
77 HTMLMeterElement* meter = meterElement();
79 return optimumPseudId;
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;
90 return optimumPseudId;
94 void MeterValueElement::setWidthPercentage(double width)
96 getInlineStyleDecl()->setProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);