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 23 #if ENABLE(PROGRESS_TAG) 24 25 #include "RenderProgress.h" 26 27 #include "HTMLNames.h" 28 #include "HTMLProgressElement.h" 29 #include "PaintInfo.h" 30 #include "RenderTheme.h" 31 #include "ShadowElement.h" 32 #include <wtf/CurrentTime.h> 33 #include <wtf/RefPtr.h> 34 35 using namespace std; 36 37 namespace WebCore { 38 39 RenderProgress::RenderProgress(HTMLProgressElement* element) 40 : RenderBlock(element) 41 , m_position(HTMLProgressElement::InvalidPosition) 42 , m_animationStartTime(0) 43 , m_animationRepeatInterval(0) 44 , m_animationDuration(0) 45 , m_animating(false) 46 , m_animationTimer(this, &RenderProgress::animationTimerFired) 47 { 48 } 49 50 RenderProgress::~RenderProgress() 51 { 52 } 53 54 void RenderProgress::updateFromElement() 55 { 56 HTMLProgressElement* element = progressElement(); 57 if (m_position == element->position()) 58 return; 59 m_position = element->position(); 60 61 updateAnimationState(); 62 RenderBlock::updateFromElement(); 63 } 64 65 double RenderProgress::animationProgress() const 66 { 67 return m_animating ? (fmod((currentTime() - m_animationStartTime), m_animationDuration) / m_animationDuration) : 0; 68 } 69 70 bool RenderProgress::isDeterminate() const 71 { 72 return (HTMLProgressElement::IndeterminatePosition != position() 73 && HTMLProgressElement::InvalidPosition != position()); 74 } 75 76 void RenderProgress::animationTimerFired(Timer<RenderProgress>*) 77 { 78 repaint(); 79 if (!m_animationTimer.isActive() && m_animating) 80 m_animationTimer.startOneShot(m_animationRepeatInterval); 81 } 82 83 void RenderProgress::updateAnimationState() 84 { 85 m_animationDuration = theme()->animationDurationForProgressBar(this); 86 m_animationRepeatInterval = theme()->animationRepeatIntervalForProgressBar(this); 87 88 bool animating = style()->hasAppearance() && m_animationDuration > 0; 89 if (animating == m_animating) 90 return; 91 92 m_animating = animating; 93 if (m_animating) { 94 m_animationStartTime = currentTime(); 95 m_animationTimer.startOneShot(m_animationRepeatInterval); 96 } else 97 m_animationTimer.stop(); 98 } 99 100 HTMLProgressElement* RenderProgress::progressElement() const 101 { 102 return static_cast<HTMLProgressElement*>(node()); 103 } 104 105 } // namespace WebCore 106 107 #endif 108