Changeset 181114 in webkit


Ignore:
Timestamp:
Mar 5, 2015 4:34:25 PM (9 years ago)
Author:
timothy_horton@apple.com
Message:

<attachment> should support indication of download progress
https://bugs.webkit.org/show_bug.cgi?id=142336
<rdar://problem/19982504>

Reviewed by Anders Carlsson.

  • html/HTMLAttachmentElement.cpp:

(WebCore::HTMLAttachmentElement::parseAttribute):
Invalidate the attachment if the progress attribute changes.

  • platform/graphics/FloatRoundedRect.h:

(WebCore::FloatRoundedRect::Radii::Radii):
Add a Radii constructor that takes a single argument that is used
as the radius for all corners, for convenience.

  • rendering/RenderThemeMac.mm:

(WebCore::attachmentProgressBarBackgroundColor):
(WebCore::attachmentProgressBarFillColor):
(WebCore::attachmentProgressBarBorderColor):
Add a bunch of constants for the progress bar.

(WebCore::paintAttachmentIconBackground):
Make use of fillRoundedRect instead of creating a path.

(WebCore::paintAttachmentProgress):
(WebCore::RenderThemeMac::paintAttachment):
Paint a progress bar if the progress attribute exists and
is a valid floating point number.

  • fast/attachment/attachment-progress.html: Added.
  • platform/mac/fast/attachment/attachment-progress-expected.png: Added.
  • platform/mac/fast/attachment/attachment-progress-expected.txt: Added.
  • platform/mac-mavericks/fast/attachment/attachment-progress-expected.txt: Added.

Add a test for the <attachment> progress attribute.

  • platform/mac/fast/attachment/attachment-rendering-expected.png:

Rebaseline a test that changed in r181058 (and will change again!), but
which didn't start failing because the pixel test tolerance is such that
it only fails the hash check and not the test itself.

Location:
trunk
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181107 r181114  
     12015-03-05  Timothy Horton  <timothy_horton@apple.com>
     2
     3        <attachment> should support indication of download progress
     4        https://bugs.webkit.org/show_bug.cgi?id=142336
     5        <rdar://problem/19982504>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        * fast/attachment/attachment-progress.html: Added.
     10        * platform/mac/fast/attachment/attachment-progress-expected.png: Added.
     11        * platform/mac/fast/attachment/attachment-progress-expected.txt: Added.
     12        * platform/mac-mavericks/fast/attachment/attachment-progress-expected.txt: Added.
     13        Add a test for the <attachment> progress attribute.
     14
     15        * platform/mac/fast/attachment/attachment-rendering-expected.png:
     16        Rebaseline a test that changed in r181058 (and will change again!), but
     17        which didn't start failing because the pixel test tolerance is such that
     18        it only fails the hash check and not the test itself.
     19
    1202015-03-05  Benjamin Poulain  <bpoulain@apple.com>
    221
  • trunk/Source/WebCore/ChangeLog

    r181111 r181114  
     12015-03-05  Timothy Horton  <timothy_horton@apple.com>
     2
     3        <attachment> should support indication of download progress
     4        https://bugs.webkit.org/show_bug.cgi?id=142336
     5        <rdar://problem/19982504>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        * html/HTMLAttachmentElement.cpp:
     10        (WebCore::HTMLAttachmentElement::parseAttribute):
     11        Invalidate the attachment if the progress attribute changes.
     12
     13        * platform/graphics/FloatRoundedRect.h:
     14        (WebCore::FloatRoundedRect::Radii::Radii):
     15        Add a Radii constructor that takes a single argument that is used
     16        as the radius for all corners, for convenience.
     17
     18        * rendering/RenderThemeMac.mm:
     19        (WebCore::attachmentProgressBarBackgroundColor):
     20        (WebCore::attachmentProgressBarFillColor):
     21        (WebCore::attachmentProgressBarBorderColor):
     22        Add a bunch of constants for the progress bar.
     23
     24        (WebCore::paintAttachmentIconBackground):
     25        Make use of fillRoundedRect instead of creating a path.
     26
     27        (WebCore::paintAttachmentProgress):
     28        (WebCore::RenderThemeMac::paintAttachment):
     29        Paint a progress bar if the progress attribute exists and
     30        is a valid floating point number.
     31
    1322015-03-05  Commit Queue  <commit-queue@webkit.org>
    233
  • trunk/Source/WebCore/html/HTMLAttachmentElement.cpp

    r181056 r181114  
    7575void HTMLAttachmentElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
    7676{
    77     if (name == subtitleAttr && is<RenderAttachment>(renderer())) {
     77    if ((name == progressAttr || name == subtitleAttr) && is<RenderAttachment>(renderer())) {
    7878        downcast<RenderAttachment>(*renderer()).invalidate();
    7979        return;
  • trunk/Source/WebCore/platform/graphics/FloatRoundedRect.h

    r177739 r181114  
    5555            , m_bottomLeft(intRadii.bottomLeft())
    5656            , m_bottomRight(intRadii.bottomRight())
     57        {
     58        }
     59
     60        explicit Radii(float uniformRadius)
     61            : m_topLeft(uniformRadius, uniformRadius)
     62            , m_topRight(uniformRadius, uniformRadius)
     63            , m_bottomLeft(uniformRadius, uniformRadius)
     64            , m_bottomRight(uniformRadius, uniformRadius)
    5765        {
    5866        }
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r181058 r181114  
    20952095static Color attachmentSubtitleTextColor() { return Color(82, 145, 214, 255); }
    20962096
     2097const CGFloat attachmentProgressBarWidth = 30;
     2098const CGFloat attachmentProgressBarHeight = 5;
     2099const CGFloat attachmentProgressBarOffset = -9;
     2100const CGFloat attachmentProgressBarBorderWidth = 1;
     2101static Color attachmentProgressBarBackgroundColor() { return Color(0, 0, 0, 89); }
     2102static Color attachmentProgressBarFillColor() { return Color(Color::white); }
     2103static Color attachmentProgressBarBorderColor() { return Color(0, 0, 0, 128); }
     2104
    20972105const CGFloat attachmentMargin = 3;
    20982106
     
    23012309        backgroundRect.inflate(-attachmentIconSelectionBorderThickness);
    23022310
    2303     FloatSize iconBackgroundRadiusSize(attachmentIconBackgroundRadius, attachmentIconBackgroundRadius);
    2304 
    2305     Path backgroundPath;
    2306     backgroundPath.addRoundedRect(backgroundRect, iconBackgroundRadiusSize);
    2307     context.setFillColor(attachmentIconBackgroundColor(), ColorSpaceDeviceRGB);
    2308     context.fillPath(backgroundPath);
     2311    context.fillRoundedRect(FloatRoundedRect(backgroundRect, FloatRoundedRect::Radii(attachmentIconBackgroundRadius)), attachmentIconBackgroundColor(), ColorSpaceDeviceRGB);
    23092312
    23102313    if (paintBorder) {
     
    23122315        borderRect.inflate(-attachmentIconSelectionBorderThickness / 2);
    23132316
     2317        FloatSize iconBackgroundRadiusSize(attachmentIconBackgroundRadius, attachmentIconBackgroundRadius);
    23142318        Path borderPath;
    23152319        borderPath.addRoundedRect(borderRect, iconBackgroundRadiusSize);
     
    24952499}
    24962500
     2501static void paintAttachmentProgress(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
     2502{
     2503    String progressString = attachment.attachmentElement().fastGetAttribute(progressAttr);
     2504    if (progressString.isEmpty())
     2505        return;
     2506    bool validProgress;
     2507    float progress = progressString.toFloat(&validProgress);
     2508    if (!validProgress)
     2509        return;
     2510
     2511    GraphicsContextStateSaver saver(context);
     2512
     2513    FloatRect progressBounds((attachmentIconBackgroundSize - attachmentProgressBarWidth) / 2, layout.iconBackgroundRect.maxY() + attachmentProgressBarOffset - attachmentProgressBarHeight, attachmentProgressBarWidth, attachmentProgressBarHeight);
     2514
     2515    FloatRect borderRect = progressBounds;
     2516    borderRect.inflate(-0.5);
     2517    FloatRect backgroundRect = borderRect;
     2518    backgroundRect.inflate(-attachmentProgressBarBorderWidth / 2);
     2519
     2520    FloatRoundedRect backgroundRoundedRect(backgroundRect, FloatRoundedRect::Radii(backgroundRect.height() / 2));
     2521    context.fillRoundedRect(backgroundRoundedRect, attachmentProgressBarBackgroundColor(), ColorSpaceDeviceRGB);
     2522
     2523    {
     2524        GraphicsContextStateSaver clipSaver(context);
     2525        context.clipRoundedRect(backgroundRoundedRect);
     2526
     2527        FloatRect progressRect = progressBounds;
     2528        progressRect.setWidth(progressRect.width() * progress);
     2529        progressRect = encloseRectToDevicePixels(progressRect, attachment.document().deviceScaleFactor());
     2530
     2531        context.fillRect(progressRect, attachmentProgressBarFillColor(), ColorSpaceDeviceRGB);
     2532    }
     2533
     2534    Path borderPath;
     2535    float borderRadius = borderRect.height() / 2;
     2536    borderPath.addRoundedRect(borderRect, FloatSize(borderRadius, borderRadius));
     2537    context.setStrokeColor(attachmentProgressBarBorderColor(), ColorSpaceDeviceRGB);
     2538    context.setStrokeThickness(attachmentProgressBarBorderWidth);
     2539    context.strokePath(borderPath);
     2540}
     2541
    24972542bool RenderThemeMac::paintAttachment(const RenderObject& renderer, const PaintInfo& paintInfo, const IntRect& paintRect)
    24982543{
     
    25202565    paintAttachmentTitle(attachment, context, layout);
    25212566    paintAttachmentSubtitle(attachment, context, layout);
     2567    paintAttachmentProgress(attachment, context, layout);
    25222568
    25232569    return true;
Note: See TracChangeset for help on using the changeset viewer.