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