- Revision
- 195678
- Author
- [email protected]
- Date
- 2016-01-27 11:11:22 -0800 (Wed, 27 Jan 2016)
Log Message
Need to be able to specify MIME type for <attachment> without filename or handle
https://bugs.webkit.org/show_bug.cgi?id=153552
<rdar://problem/20145857>
Reviewed by Anders Carlsson.
Tests: fast/attachment/attachment-default-icon.html
fast/attachment/attachment-type-attribute.html
* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::parseAttribute):
Invalidate attachment when 'type' attribute changes.
(WebCore::HTMLAttachmentElement::attachmentType):
* html/HTMLAttachmentElement.h:
* platform/graphics/Icon.h:
* platform/graphics/mac/IconMac.mm:
(WebCore::Icon::createIconForUTI):
(WebCore::Icon::createIconForMIMEType):
Add Icon class methods to retrieve an icon given a UTI or MIME type.
* rendering/RenderThemeMac.mm:
(WebCore::paintAttachmentIcon):
Use the 'type' attribute (a MIME type) if we have one. Otherwise,
use the filename. Lastly fall back to a plain file icon (using the root
file UTI, public.data).
* fast/attachment/attachment-default-icon-expected.html: Added.
* fast/attachment/attachment-default-icon.html: Added.
* fast/attachment/attachment-type-attribute-expected.html: Added.
* fast/attachment/attachment-type-attribute.html: Added.
Add some tests.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (195677 => 195678)
--- trunk/LayoutTests/ChangeLog 2016-01-27 18:38:22 UTC (rev 195677)
+++ trunk/LayoutTests/ChangeLog 2016-01-27 19:11:22 UTC (rev 195678)
@@ -1,3 +1,17 @@
+2016-01-27 Tim Horton <[email protected]>
+
+ Need to be able to specify MIME type for <attachment> without filename or handle
+ https://bugs.webkit.org/show_bug.cgi?id=153552
+ <rdar://problem/20145857>
+
+ Reviewed by Anders Carlsson.
+
+ * fast/attachment/attachment-default-icon-expected.html: Added.
+ * fast/attachment/attachment-default-icon.html: Added.
+ * fast/attachment/attachment-type-attribute-expected.html: Added.
+ * fast/attachment/attachment-type-attribute.html: Added.
+ Add some tests.
+
2016-01-27 Xabier Rodriguez Calvar <[email protected]> and Youenn Fablet <[email protected]>
[GTK] Problem running promises code in workers
Added: trunk/LayoutTests/fast/attachment/attachment-default-icon-expected.html (0 => 195678)
--- trunk/LayoutTests/fast/attachment/attachment-default-icon-expected.html (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-default-icon-expected.html 2016-01-27 19:11:22 UTC (rev 195678)
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<body>
+<attachment id="attachment" title=" "></attachment>
+<script>
+var file;
+if (window.internals)
+ file = window.internals.createFile("resources/test-file.dat");
+
+document.getElementById("attachment").file = file;
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/fast/attachment/attachment-default-icon.html (0 => 195678)
--- trunk/LayoutTests/fast/attachment/attachment-default-icon.html (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-default-icon.html 2016-01-27 19:11:22 UTC (rev 195678)
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+<body>
+<attachment></attachment>
+</body>
+</html>
Added: trunk/LayoutTests/fast/attachment/attachment-type-attribute-expected.html (0 => 195678)
--- trunk/LayoutTests/fast/attachment/attachment-type-attribute-expected.html (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-type-attribute-expected.html 2016-01-27 19:11:22 UTC (rev 195678)
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<body>
+<attachment id="attachment" title=" "></attachment>
+<script>
+var file;
+if (window.internals)
+ file = window.internals.createFile("resources/test-file.txt");
+
+document.getElementById("attachment").file = file;
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/fast/attachment/attachment-type-attribute.html (0 => 195678)
--- trunk/LayoutTests/fast/attachment/attachment-type-attribute.html (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-type-attribute.html 2016-01-27 19:11:22 UTC (rev 195678)
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+<body>
+<attachment type="text/plain"></attachment>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (195677 => 195678)
--- trunk/Source/WebCore/ChangeLog 2016-01-27 18:38:22 UTC (rev 195677)
+++ trunk/Source/WebCore/ChangeLog 2016-01-27 19:11:22 UTC (rev 195678)
@@ -1,3 +1,32 @@
+2016-01-27 Tim Horton <[email protected]>
+
+ Need to be able to specify MIME type for <attachment> without filename or handle
+ https://bugs.webkit.org/show_bug.cgi?id=153552
+ <rdar://problem/20145857>
+
+ Reviewed by Anders Carlsson.
+
+ Tests: fast/attachment/attachment-default-icon.html
+ fast/attachment/attachment-type-attribute.html
+
+ * html/HTMLAttachmentElement.cpp:
+ (WebCore::HTMLAttachmentElement::parseAttribute):
+ Invalidate attachment when 'type' attribute changes.
+
+ (WebCore::HTMLAttachmentElement::attachmentType):
+ * html/HTMLAttachmentElement.h:
+ * platform/graphics/Icon.h:
+ * platform/graphics/mac/IconMac.mm:
+ (WebCore::Icon::createIconForUTI):
+ (WebCore::Icon::createIconForMIMEType):
+ Add Icon class methods to retrieve an icon given a UTI or MIME type.
+
+ * rendering/RenderThemeMac.mm:
+ (WebCore::paintAttachmentIcon):
+ Use the 'type' attribute (a MIME type) if we have one. Otherwise,
+ use the filename. Lastly fall back to a plain file icon (using the root
+ file UTI, public.data).
+
2016-01-27 Alexey Proskuryakov <[email protected]>
Remove ENABLE_CURRENTSRC
Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.cpp (195677 => 195678)
--- trunk/Source/WebCore/html/HTMLAttachmentElement.cpp 2016-01-27 18:38:22 UTC (rev 195677)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.cpp 2016-01-27 19:11:22 UTC (rev 195678)
@@ -74,7 +74,7 @@
void HTMLAttachmentElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
- if ((name == progressAttr || name == titleAttr || name == subtitleAttr) && is<RenderAttachment>(renderer())) {
+ if ((name == progressAttr || name == titleAttr || name == subtitleAttr || name == typeAttr) && is<RenderAttachment>(renderer())) {
downcast<RenderAttachment>(*renderer()).invalidate();
return;
}
@@ -90,6 +90,11 @@
return m_file ? m_file->name() : String();
}
+String HTMLAttachmentElement::attachmentType() const
+{
+ return fastGetAttribute(typeAttr);
+}
+
} // namespace WebCore
#endif // ENABLE(ATTACHMENT_ELEMENT)
Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.h (195677 => 195678)
--- trunk/Source/WebCore/html/HTMLAttachmentElement.h 2016-01-27 18:38:22 UTC (rev 195677)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.h 2016-01-27 19:11:22 UTC (rev 195678)
@@ -41,6 +41,7 @@
void setFile(File*);
String attachmentTitle() const;
+ String attachmentType() const;
private:
HTMLAttachmentElement(const QualifiedName&, Document&);
Modified: trunk/Source/WebCore/platform/graphics/Icon.h (195677 => 195678)
--- trunk/Source/WebCore/platform/graphics/Icon.h 2016-01-27 18:38:22 UTC (rev 195677)
+++ trunk/Source/WebCore/platform/graphics/Icon.h 2016-01-27 19:11:22 UTC (rev 195678)
@@ -60,6 +60,11 @@
WEBCORE_EXPORT static PassRefPtr<Icon> createIconForImage(NativeImagePtr);
#endif
+#if PLATFORM(MAC)
+ static RefPtr<Icon> createIconForUTI(const String&);
+ static RefPtr<Icon> createIconForMIMEType(const String&);
+#endif
+
private:
#if PLATFORM(IOS)
Icon(CGImageRef);
Modified: trunk/Source/WebCore/platform/graphics/mac/IconMac.mm (195677 => 195678)
--- trunk/Source/WebCore/platform/graphics/mac/IconMac.mm 2016-01-27 18:38:22 UTC (rev 195677)
+++ trunk/Source/WebCore/platform/graphics/mac/IconMac.mm 2016-01-27 19:11:22 UTC (rev 195678)
@@ -26,6 +26,7 @@
#import "GraphicsContext.h"
#import "IntRect.h"
#import "LocalCurrentGraphicsContext.h"
+#import "UTIUtilities.h"
#import <wtf/PassRefPtr.h>
#include <wtf/text/WTFString.h>
@@ -72,6 +73,20 @@
return adoptRef(new Icon(image));
}
+RefPtr<Icon> Icon::createIconForUTI(const String& UTI)
+{
+ NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:UTI];
+ if (!image)
+ return nullptr;
+
+ return adoptRef(new Icon(image));
+}
+
+RefPtr<Icon> Icon::createIconForMIMEType(const String& MIMEType)
+{
+ return createIconForUTI(UTIFromMIMEType(MIMEType.createCFString().get()).get());
+}
+
void Icon::paint(GraphicsContext& context, const FloatRect& rect)
{
if (context.paintingDisabled())
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (195677 => 195678)
--- trunk/Source/WebCore/rendering/RenderThemeMac.mm 2016-01-27 18:38:22 UTC (rev 195677)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm 2016-01-27 19:11:22 UTC (rev 195678)
@@ -2339,11 +2339,21 @@
static void paintAttachmentIcon(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
{
- Vector<String> filenames;
- if (File* file = attachment.attachmentElement().file())
- filenames.append(file->path());
- RefPtr<Icon> icon = Icon::createIconForFiles(filenames);
+ RefPtr<Icon> icon;
+ String type = attachment.attachmentElement().attachmentType();
+ if (!type.isEmpty())
+ icon = Icon::createIconForMIMEType(type);
+ else {
+ Vector<String> filenames;
+ if (File* file = attachment.attachmentElement().file())
+ filenames.append(file->path());
+ icon = Icon::createIconForFiles(filenames);
+ }
+
if (!icon)
+ icon = Icon::createIconForUTI("public.data");
+
+ if (!icon)
return;
icon->paint(context, layout.iconRect);
}