bool RenderTheme::paintMeter(RenderObject* renderObject, const RenderObject::PaintInfo& paintInfo, const IntRect& rect) { // Some platforms do not have a native gauge widget, so we draw here a default implementation. RenderMeter* renderMeter = toRenderMeter(renderObject); RenderStyle* style = renderObject->style(); int left = style->borderLeft().width() + style->paddingLeft().value(); int top = style->borderTop().width() + style->paddingTop().value(); int right = style->borderRight().width() + style->paddingRight().value(); int bottom = style->borderBottom().width() + style->paddingBottom().value(); FloatRect innerRect(rect.x() + left, rect.y() + top, rect.width() - left - right, rect.height() - top - bottom); HTMLMeterElement* element = static_cast<HTMLMeterElement*>(renderMeter->node()); double min = element->min(); double max = element->max(); double value = element->value(); if (min >= max) { paintInfo.context->fillRect(innerRect, Color::black, style->colorSpace()); return false; } // Paint the background first paintInfo.context->fillRect(innerRect, Color::lightGray, style->colorSpace()); FloatRect valueRect; if (rect.width() < rect.height()) { // Vertical gauge double scale = innerRect.height() / (max - min); valueRect.setLocation(FloatPoint(innerRect.x(), innerRect.y() + narrowPrecisionToFloat((max - value) * scale))); valueRect.setSize(FloatSize(innerRect.width(), narrowPrecisionToFloat((value - min) * scale))); } else if (renderMeter->style()->direction() == RTL) { // right to left horizontal gauge double scale = innerRect.width() / (max - min); valueRect.setLocation(FloatPoint(innerRect.x() + narrowPrecisionToFloat((max - value) * scale), innerRect.y())); valueRect.setSize(FloatSize(narrowPrecisionToFloat((value - min) * scale), innerRect.height())); } else { // left to right horizontal gauge double scale = innerRect.width() / (max - min); valueRect.setLocation(innerRect.location()); valueRect.setSize(FloatSize(narrowPrecisionToFloat((value - min)) * scale, innerRect.height())); } if (!valueRect.isEmpty()) paintInfo.context->fillRect(valueRect, Color::black, style->colorSpace()); return false; }
bool MeterShadowElement::rendererIsNeeded(const NodeRenderingContext& context) { RenderMeter* meterRenderer = toRenderMeter(meterElement()->renderer()); return meterRenderer && !meterRenderer->theme()->supportsMeter(meterRenderer->style()->appearance()) && HTMLDivElement::rendererIsNeeded(context); }