Changeset 56850 in webkit


Ignore:
Timestamp:
Mar 31, 2010 10:06:57 AM (14 years ago)
Author:
yael.aharon@nokia.com
Message:

Add animation to progress element
https://bugs.webkit.org/show_bug.cgi?id=36664

Reviewed by Antti Koivisto.

Add a timer to control the animation. The timer is started after painting
or a state change in the progress bar, to prevent animation from running
when the progress bar is not visible.

  • html/HTMLProgressElement.cpp:
  • platform/qt/RenderThemeQt.cpp:
  • platform/qt/RenderThemeQt.h:
  • rendering/RenderProgress.cpp:
  • rendering/RenderProgress.h:
  • rendering/RenderTheme.cpp:
  • rendering/RenderTheme.h:
Location:
trunk/WebCore
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56849 r56850  
     12010-03-31  Yael Aharon  <yael.aharon@nokia.com>
     2
     3        Reviewed by Antti Koivisto.
     4
     5        Add animation to progress element
     6        https://bugs.webkit.org/show_bug.cgi?id=36664
     7
     8        Add a timer to control the animation. The timer is started after painting
     9        or a state change in the progress bar, to prevent animation from running
     10        when the progress bar is not visible.
     11
     12        * html/HTMLProgressElement.cpp:
     13        (WebCore::HTMLProgressElement::createRenderer):
     14        * manual-tests/dom: Added.
     15        * manual-tests/dom/progressbar.html: Added.
     16        * platform/qt/RenderThemeQt.cpp:
     17        (WebCore::RenderThemeQt::animationRepeatIntervalForProgressBar):
     18        (WebCore::RenderThemeQt::animationDurationForProgressBar):
     19        (WebCore::RenderThemeQt::paintProgressBar):
     20        * platform/qt/RenderThemeQt.h:
     21        * rendering/RenderProgress.cpp:
     22        (WebCore::RenderProgress::RenderProgress):
     23        (WebCore::RenderProgress::layout):
     24        (WebCore::RenderProgress::updateFromElement):
     25        (WebCore::RenderProgress::animationProgress):
     26        (WebCore::RenderProgress::animationTimerFired):
     27        (WebCore::RenderProgress::paint):
     28        (WebCore::RenderProgress::updateAnimationState):
     29        * rendering/RenderProgress.h:
     30        * rendering/RenderTheme.cpp:
     31        (WebCore::RenderTheme::animationRepeatIntervalForProgressBar):
     32        (WebCore::RenderTheme::animationDurationForProgressBar):
     33        * rendering/RenderTheme.h:
     34
    1352010-03-31  Pavel Feldman  <pfeldman@chromium.org>
    236
  • trunk/WebCore/html/HTMLProgressElement.cpp

    r56126 r56850  
    4646}
    4747
    48 RenderObject* HTMLProgressElement::createRenderer(RenderArena* arena, RenderStyle* style)
     48RenderObject* HTMLProgressElement::createRenderer(RenderArena* arena, RenderStyle*)
    4949{
    5050    return new (arena) RenderProgress(this);
  • trunk/WebCore/platform/qt/RenderThemeQt.cpp

    r56629 r56850  
    654654
    655655#if ENABLE(PROGRESS_TAG)
    656 bool RenderThemeQt::getNumberOfPixelsForProgressPosition(double position, int& progressSize) const
    657 {
    658     progressSize = 65536 * position;
    659     return false;
     656double RenderThemeQt::animationRepeatIntervalForProgressBar(RenderProgress* renderProgress) const
     657{
     658    if (renderProgress->position() >= 0)
     659        return 0;
     660
     661    // FIXME: Use hard-coded value until http://bugreports.qt.nokia.com/browse/QTBUG-9171 is fixed.
     662    // Use the value from windows style which is 10 fps.
     663    return 0.1;
     664}
     665
     666double RenderThemeQt::animationDurationForProgressBar(RenderProgress* renderProgress) const
     667{
     668    if (renderProgress->position() >= 0)
     669        return 0;
     670
     671    QStyleOptionProgressBarV2 option;
     672    option.rect.setSize(renderProgress->size());
     673    // FIXME: Until http://bugreports.qt.nokia.com/browse/QTBUG-9171 is fixed,
     674    // we simulate one square animating across the progress bar.
     675    return (option.rect.width() / qStyle()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &option)) * animationRepeatIntervalForProgressBar(renderProgress);
    660676}
    661677
     
    687703    option.rect.setSize(r.size());
    688704
    689     p.drawControl(QStyle::CE_ProgressBar, option);
     705    if (option.progress < 0) {
     706        // FIXME: Until http://bugreports.qt.nokia.com/browse/QTBUG-9171 is fixed,
     707        // we simulate one square animating across the progress bar.
     708        p.drawControl(QStyle::CE_ProgressBarGroove, option);
     709        int chunkWidth = qStyle()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &option);
     710        QColor color = (option.palette.highlight() == option.palette.background()) ? option.palette.color(QPalette::Active, QPalette::Highlight) : option.palette.color(QPalette::Highlight);
     711        if (renderProgress->style()->direction() == RTL)
     712            p.painter->fillRect(option.rect.right() - chunkWidth  - renderProgress->animationProgress() * option.rect.width(), 0, chunkWidth, option.rect.height(), color);
     713        else
     714            p.painter->fillRect(renderProgress->animationProgress() * option.rect.width(), 0, chunkWidth, option.rect.height(), color);
     715    } else
     716        p.drawControl(QStyle::CE_ProgressBar, option);
     717
    690718    p.painter->translate(-topLeft);
    691719
  • trunk/WebCore/platform/qt/RenderThemeQt.h

    r56343 r56850  
    3535namespace WebCore {
    3636
     37#if ENABLE(PROGRESS_TAG)
     38class RenderProgress;
     39#endif
    3740class RenderStyle;
    3841class HTMLMediaElement;
     
    129132
    130133#if ENABLE(PROGRESS_TAG)
    131     // Helper method for optimizing the paint area of the progress bar.
    132     // If supported, it returns number of pixels needed to draw the progress bar up to the progress position.
    133     // progressSize is the value that is passed back to RenderTheme during drawing.
    134     virtual bool getNumberOfPixelsForProgressPosition(double position, int& progressSize) const;
     134    // Returns the repeat interval of the animation for the progress bar.
     135    virtual double animationRepeatIntervalForProgressBar(RenderProgress* renderProgress) const;
     136    // Returns the duration of the animation for the progress bar.
     137    virtual double animationDurationForProgressBar(RenderProgress* renderProgress) const;
    135138#endif
    136139
  • trunk/WebCore/rendering/RenderProgress.cpp

    r56629 r56850  
    3636    : RenderBlock(element)
    3737    , m_position(-1)
     38    , m_animationStartTime(0)
     39    , m_animationRepeatInterval(0)
     40    , m_animationDuration(0)
     41    , m_animating(false)
     42    , m_animationTimer(this, &RenderProgress::animationTimerFired)
    3843{
    3944}
     
    5055    m_overflow.clear();
    5156
     57    updateAnimationState();
     58
    5259    repainter.repaintAfterLayout();
    5360
     
    6269    m_position = element->position();
    6370
     71    updateAnimationState();
     72
    6473    repaint();
     74}
     75
     76double RenderProgress::animationProgress()
     77{
     78    return m_animating ? (fmod((currentTime() - m_animationStartTime), m_animationDuration) / m_animationDuration) : 0;
     79}
     80
     81void RenderProgress::animationTimerFired(Timer<RenderProgress>*)
     82{
     83    repaint();
     84}
     85
     86void RenderProgress::paint(PaintInfo& paintInfo, int tx, int ty)
     87{
     88    if (paintInfo.phase == PaintPhaseBlockBackground) {
     89        if (!m_animationTimer.isActive() && m_animating)
     90            m_animationTimer.startOneShot(m_animationRepeatInterval);
     91    }
     92
     93    RenderBlock::paint(paintInfo, tx, ty);
     94}
     95
     96void RenderProgress::updateAnimationState()
     97{
     98    m_animationDuration = theme()->animationDurationForProgressBar(this);
     99    m_animationRepeatInterval = theme()->animationRepeatIntervalForProgressBar(this);
     100
     101    bool animating = m_animationDuration > 0;
     102    if (animating == m_animating)
     103        return;
     104
     105    m_animating = animating;
     106    if (m_animating) {
     107        m_animationStartTime = currentTime();
     108        m_animationTimer.startOneShot(m_animationRepeatInterval);
     109    } else
     110        m_animationTimer.stop();
    65111}
    66112
  • trunk/WebCore/rendering/RenderProgress.h

    r56629 r56850  
    3333    RenderProgress(HTMLProgressElement*);
    3434    double position() { return m_position; }
     35    double animationProgress();
    3536
    3637private:
     
    3940    virtual void layout();
    4041    virtual void updateFromElement();
     42    virtual void paint(PaintInfo&, int tx, int ty);
     43
     44    void animationTimerFired(Timer<RenderProgress>*);
     45    void updateAnimationState();
     46
    4147    double m_position;
     48    double m_animationStartTime;
     49    double m_animationRepeatInterval;
     50    double m_animationDuration;
     51    bool m_animating;
     52    Timer<RenderProgress> m_animationTimer;
    4253};
    4354
  • trunk/WebCore/rendering/RenderTheme.cpp

    r56126 r56850  
    841841
    842842#if ENABLE(PROGRESS_TAG)
    843 bool RenderTheme::getNumberOfPixelsForProgressPosition(double , int& progressSize) const
    844 {
    845     progressSize = 0;
    846     return false;
     843double RenderTheme::animationRepeatIntervalForProgressBar(RenderProgress*) const
     844{
     845    return 0;
     846}
     847
     848double RenderTheme::animationDurationForProgressBar(RenderProgress*) const
     849{
     850    return 0;
    847851}
    848852
  • trunk/WebCore/rendering/RenderTheme.h

    r56126 r56850  
    4040class PopupMenu;
    4141class RenderMenuList;
     42#if ENABLE(PROGRESS_TAG)
     43class RenderProgress;
     44#endif
    4245class CSSStyleSheet;
    4346
     
    171174
    172175#if ENABLE(PROGRESS_TAG)
    173     // Helper method for optimizing the paint area of the progress bar.
    174     // If supported, it returns number of pixels needed to draw the progress bar up to the progress position.
    175     // progressSize is the value that is passed back to RenderTheme during drawing.
    176     virtual bool getNumberOfPixelsForProgressPosition(double position, int& progressSize) const;
     176    // Returns the repeat interval of the animation for the progress bar.
     177    virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
     178    // Returns the duration of the animation for the progress bar.
     179    virtual double animationDurationForProgressBar(RenderProgress*) const;
    177180#endif
    178181
Note: See TracChangeset for help on using the changeset viewer.