Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / RenderProgress.cpp
1 /*
2  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
3  *
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.
8  *
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.
13  *
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.
18  *
19  */
20
21 #include "config.h"
22 #include "RenderProgress.h"
23
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>
31
32 using namespace std;
33
34 namespace WebCore {
35
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)
42     , m_animating(false)
43     , m_animationTimer(this, &RenderProgress::animationTimerFired)
44 {
45 }
46
47 RenderProgress::~RenderProgress()
48 {
49 }
50
51 void RenderProgress::updateFromElement()
52 {
53     HTMLProgressElement* element = progressElement();
54     if (m_position == element->position())
55         return;
56     m_position = element->position();
57
58     updateAnimationState();
59     RenderBlock::updateFromElement();
60 }
61
62 double RenderProgress::animationProgress() const
63 {
64     return m_animating ? (fmod((currentTime() - m_animationStartTime), m_animationDuration) / m_animationDuration) : 0;
65 }
66
67 bool RenderProgress::isDeterminate() const
68 {
69     return (HTMLProgressElement::IndeterminatePosition != position()
70             && HTMLProgressElement::InvalidPosition != position());
71 }
72
73 void RenderProgress::animationTimerFired(Timer<RenderProgress>*)
74 {
75     repaint();
76     if (!m_animationTimer.isActive() && m_animating)
77         m_animationTimer.startOneShot(m_animationRepeatInterval);
78 }
79
80 void RenderProgress::updateAnimationState()
81 {
82     m_animationDuration = theme()->animationDurationForProgressBar(this);
83     m_animationRepeatInterval = theme()->animationRepeatIntervalForProgressBar(this);
84
85     bool animating = style()->hasAppearance() && m_animationDuration > 0;
86     if (animating == m_animating)
87         return;
88
89     repaint();
90     m_animating = animating;
91     if (m_animating) {
92         m_animationStartTime = currentTime();
93         m_animationTimer.startOneShot(m_animationRepeatInterval);
94     } else
95         m_animationTimer.stop();
96 }
97
98 HTMLProgressElement* RenderProgress::progressElement() const
99 {
100     return static_cast<HTMLProgressElement*>(node());
101 }    
102
103 } // namespace WebCore
104
105 #endif