Index: WebCore/rendering/RenderMeter.cpp |
=================================================================== |
--- WebCore/rendering/RenderMeter.cpp (revision 73789) |
+++ WebCore/rendering/RenderMeter.cpp (working copy) |
@@ -35,6 +35,61 @@ |
using namespace HTMLNames; |
+class MeterPartElement : public ShadowBlockElement { |
+public: |
+ static PassRefPtr<MeterPartElement> createForPart(HTMLElement*, PseudoId); |
+ |
+ void hide(); |
+ void restoreVisibility(); |
+ |
+ virtual void updateStyleForPart(PseudoId); |
+ |
+private: |
+ MeterPartElement(HTMLElement*); |
+ void saveVisibility(); |
+ |
+ EVisibility m_originalVisibility; |
+}; |
+ |
+MeterPartElement::MeterPartElement(HTMLElement* shadowParent) |
+ : ShadowBlockElement(shadowParent) |
+{ |
+} |
+ |
+PassRefPtr<MeterPartElement> MeterPartElement::createForPart(HTMLElement* shadowParent, PseudoId pseudoId) |
+{ |
+ RefPtr<MeterPartElement> ret = adoptRef(new MeterPartElement(shadowParent)); |
+ ret->initAsPart(pseudoId); |
+ ret->saveVisibility(); |
+ return ret; |
+} |
+ |
+void MeterPartElement::hide() |
+{ |
+ if (renderer()) |
+ renderer()->style()->setVisibility(HIDDEN); |
+} |
+ |
+void MeterPartElement::restoreVisibility() |
+{ |
+ if (renderer()) |
+ renderer()->style()->setVisibility(m_originalVisibility); |
+} |
+ |
+void MeterPartElement::updateStyleForPart(PseudoId pseudoId) |
+{ |
+ if (renderer()->style()->styleType() == pseudoId) |
+ return; |
+ |
+ ShadowBlockElement::updateStyleForPart(pseudoId); |
+ saveVisibility(); |
+} |
+ |
+void MeterPartElement::saveVisibility() |
+{ |
+ m_originalVisibility = renderer()->style()->visibility(); |
+} |
+ |
RenderMeter::RenderMeter(HTMLMeterElement* element) |
: RenderIndicator(element) |
{ |
@@ -42,12 +97,38 @@ |
RenderMeter::~RenderMeter() |
{ |
- if (m_valuePart) |
- m_valuePart->detach(); |
- if (m_barPart) |
- m_barPart->detach(); |
+ if (shadowAttached()) { |
+ m_verticalValuePart->detach(); |
+ m_verticalBarPart->detach(); |
+ m_horizontalValuePart->detach(); |
+ m_horizontalBarPart->detach(); |
+ } |
} |
+PassRefPtr<MeterPartElement> RenderMeter::createPart(PseudoId pseudoId) |
+{ |
+ RefPtr<MeterPartElement> element = MeterPartElement::createForPart(static_cast<HTMLElement*>(node()), pseudoId); |
+ if (element->renderer()) |
+ addChild(element->renderer()); |
+ return element; |
+} |
+ |
+void RenderMeter::updateFromElement() |
+{ |
+ if (!shadowAttached()) { |
+ m_horizontalBarPart = createPart(barPseudoId(HORIZONTAL)); |
+ m_horizontalValuePart = createPart(valuePseudoId(HORIZONTAL)); |
+ m_verticalBarPart = createPart(barPseudoId(VERTICAL)); |
+ m_verticalValuePart = createPart(valuePseudoId(VERTICAL)); |
+ } |
+ |
+ m_horizontalBarPart->updateStyleForPart(barPseudoId(HORIZONTAL)); |
+ m_horizontalValuePart->updateStyleForPart(valuePseudoId(HORIZONTAL)); |
+ m_verticalBarPart->updateStyleForPart(barPseudoId(VERTICAL)); |
+ m_verticalValuePart->updateStyleForPart(valuePseudoId(VERTICAL)); |
+ RenderIndicator::updateFromElement(); |
+} |
+ |
void RenderMeter::computeLogicalWidth() |
{ |
RenderBox::computeLogicalWidth(); |
@@ -62,21 +143,38 @@ |
void RenderMeter::layoutParts() |
{ |
- // We refresh shadow node here because the state can depend |
- // on the frame size of this render object. |
- updatePartsState(); |
- if (m_valuePart) |
- m_valuePart->layoutAsPart(valuePartRect()); |
- if (m_barPart) |
- m_barPart->layoutAsPart(barPartRect()); |
+ m_horizontalBarPart->layoutAsPart(barPartRect()); |
+ m_horizontalValuePart->layoutAsPart(valuePartRect(HORIZONTAL)); |
+ m_verticalBarPart->layoutAsPart(barPartRect()); |
+ m_verticalValuePart->layoutAsPart(valuePartRect(VERTICAL)); |
+ |
+ if (shouldHaveParts()) { |
+ if (HORIZONTAL == orientation()) { |
+ m_verticalBarPart->hide(); |
+ m_verticalValuePart->hide(); |
+ m_horizontalBarPart->restoreVisibility(); |
+ m_horizontalValuePart->restoreVisibility(); |
+ } else { |
+ m_verticalBarPart->restoreVisibility(); |
+ m_verticalValuePart->restoreVisibility(); |
+ m_horizontalBarPart->hide(); |
+ m_horizontalValuePart->hide(); |
+ } |
+ } else { |
+ m_verticalBarPart->hide(); |
+ m_verticalValuePart->hide(); |
+ m_horizontalBarPart->hide(); |
+ m_horizontalValuePart->hide(); |
+ } |
} |
bool RenderMeter::shouldHaveParts() const |
{ |
- bool hasTheme = theme()->supportsMeter(style()->appearance(), isHorizontal()); |
+ EBoxOrient currentOrientation = orientation(); |
+ bool hasTheme = theme()->supportsMeter(style()->appearance(), HORIZONTAL == currentOrientation); |
if (!hasTheme) |
return true; |
- bool shadowsHaveStyle = ShadowBlockElement::partShouldHaveStyle(this, barPseudoId()) || ShadowBlockElement::partShouldHaveStyle(this, valuePseudoId()); |
+ bool shadowsHaveStyle = ShadowBlockElement::partShouldHaveStyle(this, barPseudoId(currentOrientation)) || ShadowBlockElement::partShouldHaveStyle(this, valuePseudoId(currentOrientation)); |
if (shadowsHaveStyle) |
return true; |
return false; |
@@ -99,11 +197,11 @@ |
return IntRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), lround(width() - borderLeft() - paddingLeft() - borderRight() - paddingRight()), height() - borderTop() - paddingTop() - borderBottom() - paddingBottom()); |
} |
-IntRect RenderMeter::valuePartRect() const |
+IntRect RenderMeter::valuePartRect(EBoxOrient asOrientation) const |
{ |
IntRect rect = barPartRect(); |
- if (rect.height() <= rect.width()) { |
+ if (HORIZONTAL == asOrientation) { |
int width = static_cast<int>(rect.width()*valueRatio()); |
if (!style()->isLeftToRightDirection()) { |
rect.setX(rect.x() + (rect.width() - width)); |
@@ -119,17 +217,17 @@ |
return rect; |
} |
-bool RenderMeter::isHorizontal() const |
+EBoxOrient RenderMeter::orientation() const |
{ |
IntRect rect = barPartRect(); |
- return rect.height() <= rect.width(); |
+ return rect.height() <= rect.width() ? HORIZONTAL : VERTICAL; |
} |
-PseudoId RenderMeter::valuePseudoId() const |
+PseudoId RenderMeter::valuePseudoId(EBoxOrient asOrientation) const |
{ |
HTMLMeterElement* element = static_cast<HTMLMeterElement*>(node()); |
- if (isHorizontal()) { |
+ if (HORIZONTAL == asOrientation) { |
switch (element->gaugeRegion()) { |
case HTMLMeterElement::GaugeRegionOptimum: |
return METER_HORIZONTAL_OPTIMUM; |
@@ -153,34 +251,11 @@ |
return NOPSEUDO; |
} |
-PseudoId RenderMeter::barPseudoId() const |
+PseudoId RenderMeter::barPseudoId(EBoxOrient asOrientation) const |
{ |
- return isHorizontal() ? METER_HORIZONTAL_BAR : METER_VERTICAL_BAR; |
+ return HORIZONTAL == asOrientation ? METER_HORIZONTAL_BAR : METER_VERTICAL_BAR; |
} |
-void RenderMeter::updatePartsState() |
-{ |
- if (shouldHaveParts() && !m_barPart) { |
- ASSERT(!m_valuePart); |
- m_barPart = ShadowBlockElement::createForPart(static_cast<HTMLElement*>(node()), barPseudoId()); |
- addChild(m_barPart->renderer()); |
- m_valuePart = ShadowBlockElement::createForPart(static_cast<HTMLElement*>(node()), valuePseudoId()); |
- addChild(m_valuePart->renderer()); |
- } else if (!shouldHaveParts() && m_barPart) { |
- ASSERT(m_valuePart); |
- m_barPart->detach(); |
- m_barPart = 0; |
- m_valuePart->detach(); |
- m_valuePart = 0; |
- } |
- |
- if (m_barPart) { |
- ASSERT(m_valuePart); |
- m_barPart->updateStyleForPart(barPseudoId()); |
- m_valuePart->updateStyleForPart(valuePseudoId()); |
- } |
-} |
- |
} // namespace WebCore |
#endif |