<attachment> should support indication of download progress
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Mar 2015 00:34:25 +0000 (00:34 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Mar 2015 00:34:25 +0000 (00:34 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181114 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/attachment/attachment-progress.html [new file with mode: 0644]
LayoutTests/platform/mac-mavericks/fast/attachment/attachment-progress-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/attachment/attachment-progress-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/attachment/attachment-progress-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/attachment/attachment-rendering-expected.png
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLAttachmentElement.cpp
Source/WebCore/platform/graphics/FloatRoundedRect.h
Source/WebCore/rendering/RenderThemeMac.mm

index 8042932..57c5887 100644 (file)
@@ -1,3 +1,22 @@
+2015-03-05  Timothy Horton  <timothy_horton@apple.com>
+
+        <attachment> should support indication of download progress
+        https://bugs.webkit.org/show_bug.cgi?id=142336
+        <rdar://problem/19982504>
+
+        Reviewed by Anders Carlsson.
+
+        * 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.
+
 2015-03-05  Benjamin Poulain  <bpoulain@apple.com>
 
         Add basic support for character sets to the URL Filter parser
diff --git a/LayoutTests/fast/attachment/attachment-progress.html b/LayoutTests/fast/attachment/attachment-progress.html
new file mode 100644 (file)
index 0000000..da3270c
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<body>
+<attachment progress="-1.5"></attachment>
+<attachment progress="0"></attachment>
+<attachment progress="0.2"></attachment>
+<attachment progress="0.4"></attachment>
+<attachment progress="0.6"></attachment>
+<attachment progress="0.8"></attachment>
+<attachment progress="1"></attachment>
+<attachment progress="1.5"></attachment>
+<script>
+var file;
+if (window.internals)
+    file = window.internals.createFile("resources/test-file.txt");
+
+var attachments = document.getElementsByTagName("attachment");
+for (var i = 0; i < attachments.length; i++)
+    attachments[i].file = file;
+</script>
+</body>
+</html>
diff --git a/LayoutTests/platform/mac-mavericks/fast/attachment/attachment-progress-expected.txt b/LayoutTests/platform/mac-mavericks/fast/attachment/attachment-progress-expected.txt
new file mode 100644 (file)
index 0000000..cabd038
--- /dev/null
@@ -0,0 +1,29 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x93
+  RenderBlock {HTML} at (0,0) size 800x93
+    RenderBody {BODY} at (8,8) size 784x77
+      RenderAttachment {ATTACHMENT} at (0,0) size 78x77
+      RenderText {#text} at (78,54) size 4x18
+        text run at (78,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (82,0) size 78x77
+      RenderText {#text} at (160,54) size 4x18
+        text run at (160,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (164,0) size 78x77
+      RenderText {#text} at (242,54) size 4x18
+        text run at (242,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (246,0) size 78x77
+      RenderText {#text} at (324,54) size 4x18
+        text run at (324,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (328,0) size 78x77
+      RenderText {#text} at (406,54) size 4x18
+        text run at (406,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (410,0) size 78x77
+      RenderText {#text} at (488,54) size 4x18
+        text run at (488,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (492,0) size 78x77
+      RenderText {#text} at (570,54) size 4x18
+        text run at (570,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (574,0) size 78x77
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/platform/mac/fast/attachment/attachment-progress-expected.png b/LayoutTests/platform/mac/fast/attachment/attachment-progress-expected.png
new file mode 100644 (file)
index 0000000..a354748
Binary files /dev/null and b/LayoutTests/platform/mac/fast/attachment/attachment-progress-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/attachment/attachment-progress-expected.txt b/LayoutTests/platform/mac/fast/attachment/attachment-progress-expected.txt
new file mode 100644 (file)
index 0000000..922b907
--- /dev/null
@@ -0,0 +1,29 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x93
+  RenderBlock {HTML} at (0,0) size 800x93
+    RenderBody {BODY} at (8,8) size 784x77
+      RenderAttachment {ATTACHMENT} at (0,0) size 74x77
+      RenderText {#text} at (74,54) size 4x18
+        text run at (74,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (78,0) size 74x77
+      RenderText {#text} at (152,54) size 4x18
+        text run at (152,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (156,0) size 74x77
+      RenderText {#text} at (230,54) size 4x18
+        text run at (230,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (234,0) size 74x77
+      RenderText {#text} at (308,54) size 4x18
+        text run at (308,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (312,0) size 74x77
+      RenderText {#text} at (386,54) size 4x18
+        text run at (386,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (390,0) size 74x77
+      RenderText {#text} at (464,54) size 4x18
+        text run at (464,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (468,0) size 74x77
+      RenderText {#text} at (542,54) size 4x18
+        text run at (542,54) width 4: " "
+      RenderAttachment {ATTACHMENT} at (546,0) size 74x77
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0
index 1266df7..990b0f8 100644 (file)
Binary files a/LayoutTests/platform/mac/fast/attachment/attachment-rendering-expected.png and b/LayoutTests/platform/mac/fast/attachment/attachment-rendering-expected.png differ
index 6ec9030..4b287ad 100644 (file)
@@ -1,3 +1,34 @@
+2015-03-05  Timothy Horton  <timothy_horton@apple.com>
+
+        <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.
+
 2015-03-05  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r180846.
index 610156f..53b52f9 100644 (file)
@@ -74,7 +74,7 @@ void HTMLAttachmentElement::setFile(File* file)
 
 void HTMLAttachmentElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
 {
-    if (name == subtitleAttr && is<RenderAttachment>(renderer())) {
+    if ((name == progressAttr || name == subtitleAttr) && is<RenderAttachment>(renderer())) {
         downcast<RenderAttachment>(*renderer()).invalidate();
         return;
     }
index 6c655be..fd2fc1b 100644 (file)
@@ -57,6 +57,14 @@ public:
         {
         }
 
+        explicit Radii(float uniformRadius)
+            : m_topLeft(uniformRadius, uniformRadius)
+            , m_topRight(uniformRadius, uniformRadius)
+            , m_bottomLeft(uniformRadius, uniformRadius)
+            , m_bottomRight(uniformRadius, uniformRadius)
+        {
+        }
+
         void setTopLeft(const FloatSize& size) { m_topLeft = size; }
         void setTopRight(const FloatSize& size) { m_topRight = size; }
         void setBottomLeft(const FloatSize& size) { m_bottomLeft = size; }
index a6e104f..6c069dd 100644 (file)
@@ -2094,6 +2094,14 @@ static Color attachmentTitleInactiveTextColor() { return Color(100, 100, 100, 25
 const CGFloat attachmentSubtitleFontSize = 10;
 static Color attachmentSubtitleTextColor() { return Color(82, 145, 214, 255); }
 
+const CGFloat attachmentProgressBarWidth = 30;
+const CGFloat attachmentProgressBarHeight = 5;
+const CGFloat attachmentProgressBarOffset = -9;
+const CGFloat attachmentProgressBarBorderWidth = 1;
+static Color attachmentProgressBarBackgroundColor() { return Color(0, 0, 0, 89); }
+static Color attachmentProgressBarFillColor() { return Color(Color::white); }
+static Color attachmentProgressBarBorderColor() { return Color(0, 0, 0, 128); }
+
 const CGFloat attachmentMargin = 3;
 
 struct AttachmentLayout {
@@ -2300,17 +2308,13 @@ static void paintAttachmentIconBackground(const RenderAttachment&, GraphicsConte
     if (paintBorder)
         backgroundRect.inflate(-attachmentIconSelectionBorderThickness);
 
-    FloatSize iconBackgroundRadiusSize(attachmentIconBackgroundRadius, attachmentIconBackgroundRadius);
-
-    Path backgroundPath;
-    backgroundPath.addRoundedRect(backgroundRect, iconBackgroundRadiusSize);
-    context.setFillColor(attachmentIconBackgroundColor(), ColorSpaceDeviceRGB);
-    context.fillPath(backgroundPath);
+    context.fillRoundedRect(FloatRoundedRect(backgroundRect, FloatRoundedRect::Radii(attachmentIconBackgroundRadius)), attachmentIconBackgroundColor(), ColorSpaceDeviceRGB);
 
     if (paintBorder) {
         FloatRect borderRect = layout.iconBackgroundRect;
         borderRect.inflate(-attachmentIconSelectionBorderThickness / 2);
 
+        FloatSize iconBackgroundRadiusSize(attachmentIconBackgroundRadius, attachmentIconBackgroundRadius);
         Path borderPath;
         borderPath.addRoundedRect(borderRect, iconBackgroundRadiusSize);
         context.setStrokeColor(attachmentIconBorderColor(), ColorSpaceDeviceRGB);
@@ -2494,6 +2498,47 @@ static void paintAttachmentSubtitle(const RenderAttachment&, GraphicsContext& co
     CTLineDraw(layout.subtitleLine.get(), context.platformContext());
 }
 
+static void paintAttachmentProgress(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
+{
+    String progressString = attachment.attachmentElement().fastGetAttribute(progressAttr);
+    if (progressString.isEmpty())
+        return;
+    bool validProgress;
+    float progress = progressString.toFloat(&validProgress);
+    if (!validProgress)
+        return;
+
+    GraphicsContextStateSaver saver(context);
+
+    FloatRect progressBounds((attachmentIconBackgroundSize - attachmentProgressBarWidth) / 2, layout.iconBackgroundRect.maxY() + attachmentProgressBarOffset - attachmentProgressBarHeight, attachmentProgressBarWidth, attachmentProgressBarHeight);
+
+    FloatRect borderRect = progressBounds;
+    borderRect.inflate(-0.5);
+    FloatRect backgroundRect = borderRect;
+    backgroundRect.inflate(-attachmentProgressBarBorderWidth / 2);
+
+    FloatRoundedRect backgroundRoundedRect(backgroundRect, FloatRoundedRect::Radii(backgroundRect.height() / 2));
+    context.fillRoundedRect(backgroundRoundedRect, attachmentProgressBarBackgroundColor(), ColorSpaceDeviceRGB);
+
+    {
+        GraphicsContextStateSaver clipSaver(context);
+        context.clipRoundedRect(backgroundRoundedRect);
+
+        FloatRect progressRect = progressBounds;
+        progressRect.setWidth(progressRect.width() * progress);
+        progressRect = encloseRectToDevicePixels(progressRect, attachment.document().deviceScaleFactor());
+
+        context.fillRect(progressRect, attachmentProgressBarFillColor(), ColorSpaceDeviceRGB);
+    }
+
+    Path borderPath;
+    float borderRadius = borderRect.height() / 2;
+    borderPath.addRoundedRect(borderRect, FloatSize(borderRadius, borderRadius));
+    context.setStrokeColor(attachmentProgressBarBorderColor(), ColorSpaceDeviceRGB);
+    context.setStrokeThickness(attachmentProgressBarBorderWidth);
+    context.strokePath(borderPath);
+}
+
 bool RenderThemeMac::paintAttachment(const RenderObject& renderer, const PaintInfo& paintInfo, const IntRect& paintRect)
 {
     if (!is<RenderAttachment>(renderer))
@@ -2519,6 +2564,7 @@ bool RenderThemeMac::paintAttachment(const RenderObject& renderer, const PaintIn
         paintAttachmentTitleBackground(attachment, context, layout);
     paintAttachmentTitle(attachment, context, layout);
     paintAttachmentSubtitle(attachment, context, layout);
+    paintAttachmentProgress(attachment, context, layout);
 
     return true;
 }