Changeset 60604 in webkit


Ignore:
Timestamp:
Jun 2, 2010 9:45:51 PM (14 years ago)
Author:
morrita@google.com
Message:

2010-06-02 MORITA Hajime <morrita@google.com>

Reviewed by Kent Tamura.

[Chromium] Support HTML5 <progress> element on Linux.
https://bugs.webkit.org/show_bug.cgi?id=37310

Implemented RenderThemeChromiumSkia::paintProgressBar(), extracing
determinateProgressValueRectFor() from RenderThemeChromiumWin to
RenderThemeChromiumSkia

No new tests. Expectations will come after ENABLE_PROGRESS_BAR get
enabled on chromium.

  • rendering/RenderThemeChromiumSkia.cpp: (WebCore::RenderThemeChromiumSkia::determinateProgressValueRectFor): (WebCore::RenderThemeChromiumSkia::indeterminateProgressValueRectFor): (WebCore::RenderThemeChromiumSkia::animationRepeatIntervalForProgressBar): (WebCore::RenderThemeChromiumSkia::animationDurationForProgressBar): (WebCore::RenderThemeChromiumSkia::paintProgressBar): (WebCore::RenderThemeChromiumSkia::progressValueRectFor):
  • rendering/RenderThemeChromiumSkia.h:
  • rendering/RenderThemeChromiumWin.cpp: (WebCore::RenderThemeChromiumWin::paintProgressBar):
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r60591 r60604  
     12010-06-02  MORITA Hajime  <morrita@google.com>
     2
     3        Reviewed by Kent Tamura.
     4
     5        [Chromium] Support HTML5 <progress> element on Linux.
     6        https://bugs.webkit.org/show_bug.cgi?id=37310
     7       
     8        Implemented RenderThemeChromiumSkia::paintProgressBar(), extracing
     9        determinateProgressValueRectFor() from RenderThemeChromiumWin to
     10        RenderThemeChromiumSkia
     11       
     12        No new tests. Expectations will come after ENABLE_PROGRESS_BAR get
     13        enabled on chromium.
     14
     15        * rendering/RenderThemeChromiumSkia.cpp:
     16        (WebCore::RenderThemeChromiumSkia::determinateProgressValueRectFor):
     17        (WebCore::RenderThemeChromiumSkia::indeterminateProgressValueRectFor):
     18        (WebCore::RenderThemeChromiumSkia::animationRepeatIntervalForProgressBar):
     19        (WebCore::RenderThemeChromiumSkia::animationDurationForProgressBar):
     20        (WebCore::RenderThemeChromiumSkia::paintProgressBar):
     21        (WebCore::RenderThemeChromiumSkia::progressValueRectFor):
     22        * rendering/RenderThemeChromiumSkia.h:
     23        * rendering/RenderThemeChromiumWin.cpp:
     24        (WebCore::RenderThemeChromiumWin::paintProgressBar):
     25
    1262010-06-02  Nico Weber  <thakis@chromium.org>
    227
  • trunk/WebCore/rendering/RenderThemeChromiumSkia.cpp

    r59956 r60604  
    2727#include "ChromiumBridge.h"
    2828#include "CSSValueKeywords.h"
     29#include "CurrentTime.h"
    2930#include "GraphicsContext.h"
    3031#include "HTMLMediaElement.h"
     
    3637#include "RenderMediaControlsChromium.h"
    3738#include "RenderObject.h"
     39#include "RenderProgress.h"
    3840#include "RenderSlider.h"
    3941#include "ScrollbarTheme.h"
     
    769771}
    770772
     773#if ENABLE(PROGRESS_TAG)
     774
     775//
     776// Following values are come from default of GTK+
     777//
     778static const int progressDeltaPixelsPerSecond = 100;
     779static const int progressActivityBlocks = 5;
     780static const int progressAnimationFrmaes = 10;
     781static const double progressAnimationInterval = 0.125;
     782
     783IntRect RenderThemeChromiumSkia::determinateProgressValueRectFor(RenderProgress* renderProgress, const IntRect& rect) const
     784{
     785    int dx = rect.width() * renderProgress->position();
     786    if (renderProgress->style()->direction() == RTL)
     787        return IntRect(rect.x() + rect.width() - dx, rect.y(), dx, rect.height());
     788    return IntRect(rect.x(), rect.y(), dx, rect.height());
     789}
     790
     791IntRect RenderThemeChromiumSkia::indeterminateProgressValueRectFor(RenderProgress* renderProgress, const IntRect& rect) const
     792{
     793
     794    int valueWidth = rect.width() / progressActivityBlocks;
     795    int movableWidth = rect.width() - valueWidth;
     796    if (movableWidth <= 0)
     797        return IntRect();
     798   
     799    double progress = renderProgress->animationProgress();
     800    if (progress < 0.5)
     801        return IntRect(rect.x() + progress * 2 * movableWidth, rect.y(), valueWidth, rect.height());
     802    return IntRect(rect.x() + (1.0 - progress) * 2 * movableWidth, rect.y(), valueWidth, rect.height());
     803}
     804
     805
     806double RenderThemeChromiumSkia::animationRepeatIntervalForProgressBar(RenderProgress*) const
     807{
     808    return progressAnimationInterval;
     809}
     810
     811double RenderThemeChromiumSkia::animationDurationForProgressBar(RenderProgress* renderProgress) const
     812{
     813    return progressAnimationInterval * progressAnimationFrmaes * 2; // "2" for back and forth
     814}
     815
     816bool RenderThemeChromiumSkia::paintProgressBar(RenderObject* renderObject, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
     817{
     818    static Image* barImage = Image::loadPlatformResource("linuxProgressBar").releaseRef();
     819    static Image* valueImage = Image::loadPlatformResource("linuxProgressValue").releaseRef();
     820    static Image* leftBorderImage = Image::loadPlatformResource("linuxProgressBorderLeft").releaseRef();
     821    static Image* rightBorderImage = Image::loadPlatformResource("linuxProgressBorderRight").releaseRef();
     822    ASSERT(barImage->height() == valueImage->height());
     823
     824
     825    RenderProgress* renderProgress = toRenderProgress(renderObject);
     826    double tileScale = static_cast<double>(rect.height()) / barImage->height();
     827    IntSize barTileSize(static_cast<int>(barImage->width() * tileScale), rect.height());
     828    ColorSpace colorSpace = renderObject->style()->colorSpace();
     829
     830    paintInfo.context->drawTiledImage(barImage, colorSpace, rect, IntPoint(0, 0), barTileSize);
     831
     832    IntRect valueRect = progressValueRectFor(renderProgress, rect);
     833    if (valueRect.width()) {
     834
     835        IntSize valueTileSize(static_cast<int>(valueImage->width() * tileScale), valueRect.height());
     836        int leftOffset = valueRect.x() - rect.x();
     837        int roundedLeftOffset= (leftOffset / valueTileSize.width()) * valueTileSize.width();
     838        int dstLeftValueWidth = roundedLeftOffset - leftOffset + (leftOffset % valueImage->width()) ? valueTileSize.width() : 0;
     839
     840        IntRect dstLeftValueRect(valueRect.x(), valueRect.y(), dstLeftValueWidth, valueRect.height());
     841        int srcLeftValueWidth = dstLeftValueWidth / tileScale;
     842        IntRect srcLeftValueRect(valueImage->width() - srcLeftValueWidth, 0, srcLeftValueWidth, valueImage->height());
     843        paintInfo.context->drawImage(valueImage, colorSpace, dstLeftValueRect, srcLeftValueRect);
     844
     845        int rightOffset = valueRect.right() - rect.x();
     846        int roundedRightOffset = (rightOffset / valueTileSize.width()) * valueTileSize.width();
     847        int dstRightValueWidth = rightOffset - roundedRightOffset;
     848        IntRect dstRightValueRect(rect.x() + roundedRightOffset, valueRect.y(), dstRightValueWidth, valueTileSize.height());
     849        int srcRightValueWidth = dstRightValueWidth / tileScale;
     850        IntRect srcRightValueRect(0, 0, srcRightValueWidth, valueImage->height());
     851        paintInfo.context->drawImage(valueImage, colorSpace, dstRightValueRect, srcRightValueRect);
     852       
     853        IntRect alignedValueRect(dstLeftValueRect.right(), dstLeftValueRect.y(),
     854                                 dstRightValueRect.x() - dstLeftValueRect.right(), dstLeftValueRect.height());
     855        paintInfo.context->drawTiledImage(valueImage, colorSpace, alignedValueRect, IntPoint(0, 0), valueTileSize);
     856    }
     857
     858    int dstLeftBorderWidth = leftBorderImage->width() * tileScale;
     859    IntRect dstLeftBorderRect(rect.x(), rect.y(), dstLeftBorderWidth, rect.height());
     860    paintInfo.context->drawImage(leftBorderImage, colorSpace, dstLeftBorderRect, leftBorderImage->rect());
     861
     862    int dstRightBorderWidth = rightBorderImage->width() * tileScale;
     863    IntRect dstRightBorderRect(rect.right() - dstRightBorderWidth, rect.y(), dstRightBorderWidth, rect.height());
     864    paintInfo.context->drawImage(rightBorderImage, colorSpace, dstRightBorderRect, rightBorderImage->rect());
     865
     866    return false;
     867}
     868
     869
     870IntRect RenderThemeChromiumSkia::progressValueRectFor(RenderProgress* renderProgress, const IntRect& rect) const
     871{
     872    return renderProgress->isDeterminate() ? determinateProgressValueRectFor(renderProgress, rect) : indeterminateProgressValueRectFor(renderProgress, rect);
     873}
     874
     875#endif
     876
    771877} // namespace WebCore
  • trunk/WebCore/rendering/RenderThemeChromiumSkia.h

    r55714 r60604  
    3232
    3333namespace WebCore {
     34
     35class RenderProgress;
    3436
    3537    class RenderThemeChromiumSkia : public RenderTheme {
     
    118120        virtual bool paintSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
    119121
     122#if ENABLE(PROGRESS_TAG)
     123        virtual double animationRepeatIntervalForProgressBar(RenderProgress*) const;
     124        virtual double animationDurationForProgressBar(RenderProgress*) const;
     125        virtual bool paintProgressBar(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
     126#endif
     127
    120128        // These methods define the padding for the MenuList's inner block.
    121129        virtual int popupInternalPaddingLeft(RenderStyle*) const;
     
    146154        virtual double caretBlinkIntervalInternal() const;
    147155
     156#if ENABLE(PROGRESS_TAG)
     157        IntRect determinateProgressValueRectFor(RenderProgress*, const IntRect&) const;
     158        IntRect indeterminateProgressValueRectFor(RenderProgress*, const IntRect&) const;
     159        IntRect progressValueRectFor(RenderProgress*, const IntRect&) const;
     160#endif
     161
    148162    private:
    149163        int menuListInternalPadding(RenderStyle*, int paddingType) const;
  • trunk/WebCore/rendering/RenderThemeChromiumWin.cpp

    r59959 r60604  
    681681{
    682682    RenderProgress* renderProgress = toRenderProgress(o);
    683 
    684     IntRect valueRect;
    685     if (renderProgress->isDeterminate()) {
    686         int dx = r.width() * renderProgress->position();
    687         if (renderProgress->style()->direction() == RTL)
    688             valueRect = IntRect(r.x() + r.width() - dx, r.y(), dx, r.height());
    689         else
    690             valueRect = IntRect(r.x(), r.y(), dx, r.height());
    691     } else {
    692         // For indeterminate bar, valueRect is ignored and it is computed by the theme engine
    693         // because the animation is a platform detail and WebKit doesn't need to know how.
    694         valueRect = IntRect(0, 0, 0, 0);
    695     }
    696 
     683    // For indeterminate bar, valueRect is ignored and it is computed by the theme engine
     684    // because the animation is a platform detail and WebKit doesn't need to know how.
     685    IntRect valueRect = renderProgress->isDeterminate() ? determianteProgressValueRectFor(renderProgress, r) : IntRect(0, 0, 0, 0);
    697686    double animatedSeconds = renderProgress->animationStartTime() ?  WTF::currentTime() - renderProgress->animationStartTime() : 0;
    698687    ThemePainter painter(i.context, r);
Note: See TracChangeset for help on using the changeset viewer.