Title: [196036] trunk
- Revision
- 196036
- Author
- timothy_hor...@apple.com
- Date
- 2016-02-02 16:08:33 -0800 (Tue, 02 Feb 2016)
Log Message
<attachment> should attempt to guess the icon from the file extension if all else fails
https://bugs.webkit.org/show_bug.cgi?id=153804
<rdar://problem/24448146>
Reviewed by Anders Carlsson.
Source/WebCore:
Test: fast/attachment/attachment-icon-from-file-extension.html
* platform/graphics/Icon.h:
* platform/graphics/mac/IconMac.mm:
(WebCore::Icon::createIconForFileExtension):
* rendering/RenderThemeMac.mm:
(WebCore::iconForAttachment):
If we can't find an icon any other way, try assuming that the title is a filename,
grab its extension, and have NSWorkspace try to work out an icon for it.
LayoutTests:
* fast/attachment/attachment-icon-from-file-extension-expected.html: Added.
* fast/attachment/attachment-icon-from-file-extension.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (196035 => 196036)
--- trunk/LayoutTests/ChangeLog 2016-02-02 23:46:52 UTC (rev 196035)
+++ trunk/LayoutTests/ChangeLog 2016-02-03 00:08:33 UTC (rev 196036)
@@ -1,3 +1,14 @@
+2016-02-02 Tim Horton <timothy_hor...@apple.com>
+
+ <attachment> should attempt to guess the icon from the file extension if all else fails
+ https://bugs.webkit.org/show_bug.cgi?id=153804
+ <rdar://problem/24448146>
+
+ Reviewed by Anders Carlsson.
+
+ * fast/attachment/attachment-icon-from-file-extension-expected.html: Added.
+ * fast/attachment/attachment-icon-from-file-extension.html: Added.
+
2016-02-02 Saam barati <sbar...@apple.com>
[ES6] bound functions .name property should be "bound " + the target function's name
Added: trunk/LayoutTests/fast/attachment/attachment-icon-from-file-extension-expected.html (0 => 196036)
--- trunk/LayoutTests/fast/attachment/attachment-icon-from-file-extension-expected.html (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-icon-from-file-extension-expected.html 2016-02-03 00:08:33 UTC (rev 196036)
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<body>
+<attachment></attachment>
+<script>
+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>
Added: trunk/LayoutTests/fast/attachment/attachment-icon-from-file-extension.html (0 => 196036)
--- trunk/LayoutTests/fast/attachment/attachment-icon-from-file-extension.html (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-icon-from-file-extension.html 2016-02-03 00:08:33 UTC (rev 196036)
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+<body>
+<attachment title="test-file.txt"></attachment>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (196035 => 196036)
--- trunk/Source/WebCore/ChangeLog 2016-02-02 23:46:52 UTC (rev 196035)
+++ trunk/Source/WebCore/ChangeLog 2016-02-03 00:08:33 UTC (rev 196036)
@@ -1,3 +1,21 @@
+2016-02-02 Tim Horton <timothy_hor...@apple.com>
+
+ <attachment> should attempt to guess the icon from the file extension if all else fails
+ https://bugs.webkit.org/show_bug.cgi?id=153804
+ <rdar://problem/24448146>
+
+ Reviewed by Anders Carlsson.
+
+ Test: fast/attachment/attachment-icon-from-file-extension.html
+
+ * platform/graphics/Icon.h:
+ * platform/graphics/mac/IconMac.mm:
+ (WebCore::Icon::createIconForFileExtension):
+ * rendering/RenderThemeMac.mm:
+ (WebCore::iconForAttachment):
+ If we can't find an icon any other way, try assuming that the title is a filename,
+ grab its extension, and have NSWorkspace try to work out an icon for it.
+
2016-02-02 Antti Koivisto <an...@apple.com>
Factor style sharing code out of StyleResolver
Modified: trunk/Source/WebCore/platform/graphics/Icon.h (196035 => 196036)
--- trunk/Source/WebCore/platform/graphics/Icon.h 2016-02-02 23:46:52 UTC (rev 196035)
+++ trunk/Source/WebCore/platform/graphics/Icon.h 2016-02-03 00:08:33 UTC (rev 196036)
@@ -63,6 +63,7 @@
#if PLATFORM(MAC)
static RefPtr<Icon> createIconForUTI(const String&);
static RefPtr<Icon> createIconForMIMEType(const String&);
+ static RefPtr<Icon> createIconForFileExtension(const String&);
#endif
private:
Modified: trunk/Source/WebCore/platform/graphics/mac/IconMac.mm (196035 => 196036)
--- trunk/Source/WebCore/platform/graphics/mac/IconMac.mm 2016-02-02 23:46:52 UTC (rev 196035)
+++ trunk/Source/WebCore/platform/graphics/mac/IconMac.mm 2016-02-03 00:08:33 UTC (rev 196036)
@@ -73,6 +73,15 @@
return adoptRef(new Icon(image));
}
+RefPtr<Icon> Icon::createIconForFileExtension(const String& fileExtension)
+{
+ NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:[@"." stringByAppendingString:fileExtension]];
+ if (!image)
+ return nullptr;
+
+ return adoptRef(new Icon(image));
+}
+
RefPtr<Icon> Icon::createIconForUTI(const String& UTI)
{
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:UTI];
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (196035 => 196036)
--- trunk/Source/WebCore/rendering/RenderThemeMac.mm 2016-02-02 23:46:52 UTC (rev 196035)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm 2016-02-03 00:08:33 UTC (rev 196036)
@@ -2353,6 +2353,12 @@
return icon;
}
+ NSString *fileExtension = [static_cast<NSString *>(attachment.attachmentElement().attachmentTitle()) pathExtension];
+ if (fileExtension.length) {
+ if (auto icon = Icon::createIconForFileExtension(fileExtension))
+ return icon;
+ }
+
return Icon::createIconForUTI("public.data");
}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes