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 "StylePropertySet.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 NodeRenderingContext& context) 58{ 59 RenderObject* render = meterElement()->renderer(); 60 return render && !render->theme()->supportsMeter(render->style()->appearance()) && HTMLDivElement::rendererIsNeeded(context); 61} 62 63MeterInnerElement::MeterInnerElement(Document* document) 64 : MeterShadowElement(document) 65{ 66 DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-meter-inner-element", AtomicString::ConstructFromLiteral)); 67 setPseudo(pseudoId); 68} 69 70bool MeterInnerElement::rendererIsNeeded(const NodeRenderingContext& context) 71{ 72 if (meterElement()->hasAuthorShadowRoot()) 73 return HTMLDivElement::rendererIsNeeded(context); 74 75 RenderObject* render = meterElement()->renderer(); 76 return render && !render->theme()->supportsMeter(render->style()->appearance()) && HTMLDivElement::rendererIsNeeded(context); 77} 78 79RenderObject* MeterInnerElement::createRenderer(RenderArena* arena, RenderStyle*) 80{ 81 return new (arena) RenderMeter(this); 82} 83 84const AtomicString& MeterValueElement::valuePseudoId() const 85{ 86 DEFINE_STATIC_LOCAL(AtomicString, optimumPseudoId, ("-webkit-meter-optimum-value", AtomicString::ConstructFromLiteral)); 87 DEFINE_STATIC_LOCAL(AtomicString, suboptimumPseudoId, ("-webkit-meter-suboptimum-value", AtomicString::ConstructFromLiteral)); 88 DEFINE_STATIC_LOCAL(AtomicString, evenLessGoodPseudoId, ("-webkit-meter-even-less-good-value", AtomicString::ConstructFromLiteral)); 89 90 HTMLMeterElement* meter = meterElement(); 91 if (!meter) 92 return optimumPseudoId; 93 94 switch (meter->gaugeRegion()) { 95 case HTMLMeterElement::GaugeRegionOptimum: 96 return optimumPseudoId; 97 case HTMLMeterElement::GaugeRegionSuboptimal: 98 return suboptimumPseudoId; 99 case HTMLMeterElement::GaugeRegionEvenLessGood: 100 return evenLessGoodPseudoId; 101 default: 102 ASSERT_NOT_REACHED(); 103 return optimumPseudoId; 104 } 105} 106 107void MeterValueElement::setWidthPercentage(double width) 108{ 109 setInlineStyleProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE); 110} 111 112} 113 114#endif 115 116