Title: [135842] trunk/Source/WebCore
Revision
135842
Author
[email protected]
Date
2012-11-27 03:15:38 -0800 (Tue, 27 Nov 2012)

Log Message

[Qt] Implement the mimetype icon methods
https://bugs.webkit.org/show_bug.cgi?id=103260

Reviewed by Simon Hausmann.

* platform/graphics/Icon.h:
(Icon):
* platform/graphics/qt/IconQt.cpp:
(WebCore::Icon::createIconForFiles):
(WebCore::Icon::paint):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (135841 => 135842)


--- trunk/Source/WebCore/ChangeLog	2012-11-27 11:03:23 UTC (rev 135841)
+++ trunk/Source/WebCore/ChangeLog	2012-11-27 11:15:38 UTC (rev 135842)
@@ -1,3 +1,16 @@
+2012-11-26  Allan Sandfeld Jensen  <[email protected]>
+
+        [Qt] Implement the mimetype icon methods
+        https://bugs.webkit.org/show_bug.cgi?id=103260
+
+        Reviewed by Simon Hausmann.
+
+        * platform/graphics/Icon.h:
+        (Icon):
+        * platform/graphics/qt/IconQt.cpp:
+        (WebCore::Icon::createIconForFiles):
+        (WebCore::Icon::paint):
+
 2012-09-17  Allan Sandfeld Jensen  <[email protected]>
 
         Incorrect rect-based hit-test result when hit-test region includes culled inlines

Modified: trunk/Source/WebCore/platform/graphics/Icon.h (135841 => 135842)


--- trunk/Source/WebCore/platform/graphics/Icon.h	2012-11-27 11:03:23 UTC (rev 135841)
+++ trunk/Source/WebCore/platform/graphics/Icon.h	2012-11-27 11:15:38 UTC (rev 135842)
@@ -32,7 +32,7 @@
 #elif PLATFORM(WIN)
 typedef struct HICON__* HICON;
 #elif PLATFORM(QT)
-#include <QImage>
+#include <QIcon>
 #elif PLATFORM(GTK)
 typedef struct _GdkPixbuf GdkPixbuf;
 #elif PLATFORM(EFL)
@@ -70,7 +70,7 @@
     HICON m_hIcon;
 #elif PLATFORM(QT)
     Icon();
-    QImage m_image;
+    QIcon m_icon;
 #elif PLATFORM(GTK)
     Icon();
     GdkPixbuf* m_icon;

Modified: trunk/Source/WebCore/platform/graphics/qt/IconQt.cpp (135841 => 135842)


--- trunk/Source/WebCore/platform/graphics/qt/IconQt.cpp	2012-11-27 11:03:23 UTC (rev 135841)
+++ trunk/Source/WebCore/platform/graphics/qt/IconQt.cpp	2012-11-27 11:15:38 UTC (rev 135842)
@@ -24,6 +24,7 @@
 #include "GraphicsContext.h"
 #include "IntRect.h"
 #include "NotImplemented.h"
+#include <QMimeDatabase>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -37,16 +38,49 @@
 }
 
 // FIXME: Move the code to ChromeClient::iconForFiles().
-PassRefPtr<Icon> Icon::createIconForFiles(const Vector<String>&)
+PassRefPtr<Icon> Icon::createIconForFiles(const Vector<String>& filenames)
 {
-    // FIXME: Should use QMimeType in Qt 5.
-    notImplemented();
-    return 0;
+    if (filenames.isEmpty())
+        return 0;
+
+    QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filenames[0], QMimeDatabase::MatchExtension);
+
+    QString iconName = mimeType.iconName();
+    QString genericIconName = mimeType.genericIconName();
+
+    // We try to match one of three cases:
+    // 1. All the files have the same type.
+    // 2. All the files are of the same generic type.
+    // 3. The files are not even of the same generic type.
+    const int count = filenames.size();
+    for (int i = 1; i < count; ++i) {
+        mimeType = QMimeDatabase().mimeTypeForFile(filenames[i], QMimeDatabase::MatchExtension);
+        if (iconName != mimeType.iconName())
+            iconName.clear();
+        if (genericIconName != mimeType.genericIconName()) {
+            genericIconName.clear();
+            break;
+        }
+    }
+
+    // FIXME: By default, only X11 will support themed icons.
+    RefPtr<Icon> icon = adoptRef(new Icon);
+    if (!iconName.isEmpty())
+        icon->m_icon = QIcon::fromTheme(iconName, QIcon::fromTheme(genericIconName));
+    else if (!genericIconName.isEmpty())
+        icon->m_icon = QIcon::fromTheme(genericIconName);
+
+    if (icon->m_icon.isNull())
+        return 0;
+    return icon.release();
 }
 
-void Icon::paint(GraphicsContext*, const IntRect&)
+void Icon::paint(GraphicsContext* context, const IntRect& rect)
 {
-    notImplemented();
+    if (m_icon.isNull())
+        return;
+
+    m_icon.paint(context->platformContext(), rect);
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to