Changeset 196036 in webkit


Ignore:
Timestamp:
Feb 2, 2016 4:08:33 PM (8 years ago)
Author:
timothy_horton@apple.com
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.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r196033 r196036  
     12016-02-02  Tim Horton  <timothy_horton@apple.com>
     2
     3        <attachment> should attempt to guess the icon from the file extension if all else fails
     4        https://bugs.webkit.org/show_bug.cgi?id=153804
     5        <rdar://problem/24448146>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        * fast/attachment/attachment-icon-from-file-extension-expected.html: Added.
     10        * fast/attachment/attachment-icon-from-file-extension.html: Added.
     11
    1122016-02-02  Saam barati  <sbarati@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r196031 r196036  
     12016-02-02  Tim Horton  <timothy_horton@apple.com>
     2
     3        <attachment> should attempt to guess the icon from the file extension if all else fails
     4        https://bugs.webkit.org/show_bug.cgi?id=153804
     5        <rdar://problem/24448146>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        Test: fast/attachment/attachment-icon-from-file-extension.html
     10
     11        * platform/graphics/Icon.h:
     12        * platform/graphics/mac/IconMac.mm:
     13        (WebCore::Icon::createIconForFileExtension):
     14        * rendering/RenderThemeMac.mm:
     15        (WebCore::iconForAttachment):
     16        If we can't find an icon any other way, try assuming that the title is a filename,
     17        grab its extension, and have NSWorkspace try to work out an icon for it.
     18
    1192016-02-02  Antti Koivisto  <antti@apple.com>
    220
  • trunk/Source/WebCore/platform/graphics/Icon.h

    r195678 r196036  
    6464    static RefPtr<Icon> createIconForUTI(const String&);
    6565    static RefPtr<Icon> createIconForMIMEType(const String&);
     66    static RefPtr<Icon> createIconForFileExtension(const String&);
    6667#endif
    6768
  • trunk/Source/WebCore/platform/graphics/mac/IconMac.mm

    r195678 r196036  
    7474}
    7575
     76RefPtr<Icon> Icon::createIconForFileExtension(const String& fileExtension)
     77{
     78    NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:[@"." stringByAppendingString:fileExtension]];
     79    if (!image)
     80        return nullptr;
     81
     82    return adoptRef(new Icon(image));
     83}
     84
    7685RefPtr<Icon> Icon::createIconForUTI(const String& UTI)
    7786{
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r196028 r196036  
    23542354    }
    23552355
     2356    NSString *fileExtension = [static_cast<NSString *>(attachment.attachmentElement().attachmentTitle()) pathExtension];
     2357    if (fileExtension.length) {
     2358        if (auto icon = Icon::createIconForFileExtension(fileExtension))
     2359            return icon;
     2360    }
     2361
    23562362    return Icon::createIconForUTI("public.data");
    23572363}
Note: See TracChangeset for help on using the changeset viewer.