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.
22 #include "RenderProgress.h"
24 #if ENABLE(PROGRESS_ELEMENT)
25 #include "HTMLNames.h"
26 #include "HTMLProgressElement.h"
27 #include "PaintInfo.h"
28 #include "RenderTheme.h"
29 #include <wtf/CurrentTime.h>
30 #include <wtf/RefPtr.h>
36 RenderProgress::RenderProgress(HTMLProgressElement* element)
37 : RenderBlock(element)
38 , m_position(HTMLProgressElement::InvalidPosition)
39 , m_animationStartTime(0)
40 , m_animationRepeatInterval(0)
41 , m_animationDuration(0)
43 , m_animationTimer(this, &RenderProgress::animationTimerFired)
47 RenderProgress::~RenderProgress()
51 void RenderProgress::updateFromElement()
53 HTMLProgressElement* element = progressElement();
54 if (m_position == element->position())
56 m_position = element->position();
58 updateAnimationState();
59 RenderBlock::updateFromElement();
62 double RenderProgress::animationProgress() const
64 return m_animating ? (fmod((currentTime() - m_animationStartTime), m_animationDuration) / m_animationDuration) : 0;
67 bool RenderProgress::isDeterminate() const
69 return (HTMLProgressElement::IndeterminatePosition != position()
70 && HTMLProgressElement::InvalidPosition != position());
73 void RenderProgress::animationTimerFired(Timer<RenderProgress>*)
76 if (!m_animationTimer.isActive() && m_animating)
77 m_animationTimer.startOneShot(m_animationRepeatInterval);
80 void RenderProgress::updateAnimationState()
82 m_animationDuration = theme()->animationDurationForProgressBar(this);
83 m_animationRepeatInterval = theme()->animationRepeatIntervalForProgressBar(this);
85 bool animating = style()->hasAppearance() && m_animationDuration > 0;
86 if (animating == m_animating)
90 m_animating = animating;
92 m_animationStartTime = currentTime();
93 m_animationTimer.startOneShot(m_animationRepeatInterval);
95 m_animationTimer.stop();
98 HTMLProgressElement* RenderProgress::progressElement() const
100 return static_cast<HTMLProgressElement*>(node());
103 } // namespace WebCore