2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include "core/rendering/RenderProgress.h"
25 #include "core/html/HTMLProgressElement.h"
26 #include "core/rendering/RenderTheme.h"
27 #include "wtf/CurrentTime.h"
28 #include "wtf/RefPtr.h"
34 RenderProgress::RenderProgress(HTMLElement* element)
35 : RenderBlockFlow(element)
36 , m_position(HTMLProgressElement::InvalidPosition)
37 , m_animationStartTime(0)
38 , m_animationRepeatInterval(0)
39 , m_animationDuration(0)
41 , m_animationTimer(this, &RenderProgress::animationTimerFired)
45 RenderProgress::~RenderProgress()
49 void RenderProgress::updateFromElement()
51 HTMLProgressElement* element = progressElement();
52 if (m_position == element->position())
54 m_position = element->position();
56 updateAnimationState();
58 RenderBlockFlow::updateFromElement();
61 double RenderProgress::animationProgress() const
63 return m_animating ? (fmod((currentTime() - m_animationStartTime), m_animationDuration) / m_animationDuration) : 0;
66 bool RenderProgress::isDeterminate() const
68 return (HTMLProgressElement::IndeterminatePosition != position()
69 && HTMLProgressElement::InvalidPosition != position());
72 void RenderProgress::animationTimerFired(Timer<RenderProgress>*)
75 if (!m_animationTimer.isActive() && m_animating)
76 m_animationTimer.startOneShot(m_animationRepeatInterval);
79 void RenderProgress::updateAnimationState()
81 m_animationDuration = RenderTheme::theme().animationDurationForProgressBar(this);
82 m_animationRepeatInterval = RenderTheme::theme().animationRepeatIntervalForProgressBar(this);
84 bool animating = style()->hasAppearance() && m_animationDuration > 0;
85 if (animating == m_animating)
88 m_animating = animating;
90 m_animationStartTime = currentTime();
91 m_animationTimer.startOneShot(m_animationRepeatInterval);
93 m_animationTimer.stop();
96 HTMLProgressElement* RenderProgress::progressElement() const
101 if (node()->hasTagName(HTMLNames::progressTag))
102 return toHTMLProgressElement(node());
104 ASSERT(node()->shadowHost());
105 return toHTMLProgressElement(node()->shadowHost());
108 } // namespace WebCore