[kazehakase-svn] [3390] * module/embed/gecko/kz-mozwrapper.cpp,
svnnotify at sourceforge.jp
svnnotify at sourceforge.jp
Revision: 3390
http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=3390
Author: kous
Date: 2008-02-23 00:36:56 +0900 (Sat, 23 Feb 2008)
Log Message:
-----------
* module/embed/gecko/kz-mozwrapper.cpp,
module/embed/gecko/kz-mozthumbnailer.{cpp,h},
module/embed/gecko/gtkmozembed/MozillaPrivate.{cpp,h}:
re-supported thumbnail.
Modified Paths:
--------------
kazehakase/trunk/ChangeLog
kazehakase/trunk/module/embed/gecko/Makefile.am
kazehakase/trunk/module/embed/gecko/gtkmozembed/MozillaPrivate.cpp
kazehakase/trunk/module/embed/gecko/gtkmozembed/MozillaPrivate.h
kazehakase/trunk/module/embed/gecko/kz-mozwrapper.cpp
Added Paths:
-----------
kazehakase/trunk/module/embed/gecko/kz-mozthumbnailer.cpp
kazehakase/trunk/module/embed/gecko/kz-mozthumbnailer.h
Modified: kazehakase/trunk/ChangeLog
===================================================================
--- kazehakase/trunk/ChangeLog 2008-02-22 04:21:35 UTC (rev 3389)
+++ kazehakase/trunk/ChangeLog 2008-02-22 15:36:56 UTC (rev 3390)
@@ -1,3 +1,10 @@
+2008-02-23 Kouhei Sutou <kou at cozmixng.org>
+
+ * module/embed/gecko/kz-mozwrapper.cpp,
+ module/embed/gecko/kz-mozthumbnailer.{cpp,h},
+ module/embed/gecko/gtkmozembed/MozillaPrivate.{cpp,h}:
+ re-supported thumbnail.
+
2008-02-22 Hiroyuki Ikezoe <poincare at ikezoe.net>
* module/embed/webkit-gtk/kz-webkit-gtk.c: more functional.
Modified: kazehakase/trunk/module/embed/gecko/Makefile.am
===================================================================
--- kazehakase/trunk/module/embed/gecko/Makefile.am 2008-02-22 04:21:35 UTC (rev 3389)
+++ kazehakase/trunk/module/embed/gecko/Makefile.am 2008-02-22 15:36:56 UTC (rev 3390)
@@ -83,6 +83,7 @@
kz-mozprogresslistener.cpp kz-mozprogresslistener.h \
kz-mozutils.cpp kz-mozutils.h \
kz-mozwrapper.cpp kz-mozwrapper.h \
+ kz-mozthumbnailer.cpp kz-mozthumbnailer.h \
kz-mozhistorysearch.cpp kz-mozhistorysearch.h
if HAVE_NSIBADCERTLISTENER_H
Modified: kazehakase/trunk/module/embed/gecko/gtkmozembed/MozillaPrivate.cpp
===================================================================
--- kazehakase/trunk/module/embed/gecko/gtkmozembed/MozillaPrivate.cpp 2008-02-22 04:21:35 UTC (rev 3389)
+++ kazehakase/trunk/module/embed/gecko/gtkmozembed/MozillaPrivate.cpp 2008-02-22 15:36:56 UTC (rev 3390)
@@ -39,10 +39,6 @@
#include <nsPromiseFlatString.h>
#include <nsEscape.h>
#include <nsIDocument.h>
-#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_
-#include <nsICanvasRenderingContextInternal.h>
-#include <nsIDOMCanvasRenderingContext2D.h>
-#endif
#undef MOZILLA_INTERNAL_API
#include <nsISimpleEnumerator.h>
#include <nsISupportsPrimitives.h>
@@ -160,88 +156,3 @@
return TRUE;
}
-
-#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_
-#define KZ_CANVAS_WIDTH 1024
-#define KZ_CANVAS_HEIGHT 800
-gboolean
-MozillaPrivate::CreateThumbnail(nsIDOMWindow *domWindow, const gchar *uri,
- guint last_modified, EggPixbufThumbSize size)
-{
- nsresult rv;
- nsCOMPtr<nsIDOMDocument> domDoc;
- domWindow->GetDocument(getter_AddRefs(domDoc));
-
- nsCOMPtr<nsICanvasRenderingContextInternal> context;
-
- nsCString ctxString("@mozilla.org/content/canvas-rendering-context;1?id=2d");
- context = do_CreateInstance(nsPromiseFlatCString(ctxString).get(), &rv);
-
- if (NS_FAILED(rv) || !context) return FALSE;
-
- context->SetDimensions(size, KZ_THUMB_HEIGHT);
- context->SetCanvasElement(nsnull);
-
- nsCOMPtr<nsIDOMCanvasRenderingContext2D> domCanvas = do_QueryInterface(context, &rv);
- if (NS_FAILED(rv) || !domCanvas) return FALSE;
-
- float sx, sy;
- sx = (float) size / KZ_CANVAS_WIDTH;
- sy = (float) KZ_THUMB_HEIGHT / KZ_CANVAS_HEIGHT;
- domCanvas->Scale(sx, sy);
-
- rv = domCanvas->DrawWindow(domWindow, 0, 0, KZ_CANVAS_WIDTH, KZ_CANVAS_HEIGHT, NS_LITERAL_STRING("rgb(0,0,0)"));
- if (NS_FAILED(rv)) return FALSE;
-
- nsCOMPtr<nsIInputStream> imgStream;
- rv = context->GetInputStream(NS_LITERAL_CSTRING("image/png"), EmptyString(), getter_AddRefs(imgStream));
- if (NS_FAILED(rv) || !imgStream) return FALSE;
-
- // this code wa picked from content/html/content/src/nsHTMLCanvasElement.cpp in firefox-2.0b.
- PRUint32 bufSize;
- rv = imgStream->Available(&bufSize);
- if (NS_FAILED(rv)) return FALSE;
-
- bufSize += 16;
- PRUint32 imgSize = 0;
- char* imgData = (char*)g_malloc((gulong)bufSize);
- if (!imgData) return FALSE;
-
- PRUint32 numReadThisTime = 0;
- while ((rv = imgStream->Read(&imgData[imgSize], bufSize - imgSize,
- &numReadThisTime)) == NS_OK && numReadThisTime > 0)
- {
- imgSize += numReadThisTime;
- if (imgSize == bufSize)
- {
- // need a bigger buffer, just double
- bufSize *= 2;
- char* newImgData = (char*)g_realloc(imgData, (gulong)bufSize);
- if (!newImgData)
- {
- g_free(imgData);
- return FALSE;
- }
- imgData = newImgData;
- }
- }
-
- GdkPixbufLoader *loader = gdk_pixbuf_loader_new_with_mime_type("image/png", NULL);
- if (!loader)
- return FALSE;
- gdk_pixbuf_loader_write(loader, (const guchar *)imgData, (gsize)imgSize, NULL);
- GdkPixbuf *thumbnail = gdk_pixbuf_loader_get_pixbuf(loader);
- gdk_pixbuf_loader_close(loader, NULL);
-
- if (!thumbnail)
- return FALSE;
-
- KZ_CREATE_THUMBNAIL(thumbnail, uri, last_modified, size);
-
- g_object_unref(thumbnail);
-
- g_free(imgData);
-
- return TRUE;
-}
-#endif
Modified: kazehakase/trunk/module/embed/gecko/gtkmozembed/MozillaPrivate.h
===================================================================
--- kazehakase/trunk/module/embed/gecko/gtkmozembed/MozillaPrivate.h 2008-02-22 04:21:35 UTC (rev 3389)
+++ kazehakase/trunk/module/embed/gecko/gtkmozembed/MozillaPrivate.h 2008-02-22 15:36:56 UTC (rev 3390)
@@ -48,11 +48,5 @@
gboolean CreatePrintSettings (nsIPrintSettings **options);
GdkWindow *GetGdkWindow (nsIBaseWindow *window);
gboolean GetEventReceiver (nsIDOMWindow *domWindow, nsIDOMEventReceiver **receiver);
-#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_
- gboolean CreateThumbnail (nsIDOMWindow *domWindow,
- const gchar *uri,
- guint last_modified,
- EggPixbufThumbSize size);
-#endif
}
#endif /* __MOZILLA_PRIVATE_H__ */
Added: kazehakase/trunk/module/embed/gecko/kz-mozthumbnailer.cpp
===================================================================
--- kazehakase/trunk/module/embed/gecko/kz-mozthumbnailer.cpp 2008-02-22 04:21:35 UTC (rev 3389)
+++ kazehakase/trunk/module/embed/gecko/kz-mozthumbnailer.cpp 2008-02-22 15:36:56 UTC (rev 3390)
@@ -0,0 +1,119 @@
+// -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+//
+// Copyright (C) 2008 Kouhei Sutou
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include "kazehakase.h"
+
+#include "kz-mozthumbnailer.h"
+
+#define MOZILLA_INTERNAL_API
+#include <nsIComponentManager.h>
+#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_
+# include <nsICanvasRenderingContextInternal.h>
+# include <nsIDOMCanvasRenderingContext2D.h>
+#endif
+#undef MOZILLA_INTERNAL_API
+
+#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_
+#define KZ_CANVAS_WIDTH 1024
+#define KZ_CANVAS_HEIGHT 800
+gboolean
+KzMozThumbnailer::CreateThumbnail(nsIDOMWindow *domWindow, const gchar *uri,
+ guint last_modified, EggPixbufThumbSize size)
+{
+ nsresult rv;
+ nsCOMPtr<nsIDOMDocument> domDoc;
+ domWindow->GetDocument(getter_AddRefs(domDoc));
+
+ nsCOMPtr<nsICanvasRenderingContextInternal> context;
+
+ nsCString ctxString("@mozilla.org/content/canvas-rendering-context;1?id=2d");
+ context = do_CreateInstance(nsPromiseFlatCString(ctxString).get(), &rv);
+
+ if (NS_FAILED(rv) || !context) return FALSE;
+
+ context->SetDimensions(size, KZ_THUMB_HEIGHT);
+ context->SetCanvasElement(nsnull);
+
+ nsCOMPtr<nsIDOMCanvasRenderingContext2D> domCanvas = do_QueryInterface(context, &rv);
+ if (NS_FAILED(rv) || !domCanvas) return FALSE;
+
+ float sx, sy;
+ sx = (float) size / KZ_CANVAS_WIDTH;
+ sy = (float) KZ_THUMB_HEIGHT / KZ_CANVAS_HEIGHT;
+ domCanvas->Scale(sx, sy);
+
+ rv = domCanvas->DrawWindow(domWindow, 0, 0, KZ_CANVAS_WIDTH, KZ_CANVAS_HEIGHT, NS_LITERAL_STRING("rgb(0,0,0)"));
+ if (NS_FAILED(rv)) return FALSE;
+
+ nsCOMPtr<nsIInputStream> imgStream;
+ rv = context->GetInputStream(NS_LITERAL_CSTRING("image/png"), EmptyString(), getter_AddRefs(imgStream));
+ if (NS_FAILED(rv) || !imgStream) return FALSE;
+
+ // this code wa picked from content/html/content/src/nsHTMLCanvasElement.cpp in firefox-2.0b.
+ PRUint32 bufSize;
+ rv = imgStream->Available(&bufSize);
+ if (NS_FAILED(rv)) return FALSE;
+
+ bufSize += 16;
+ PRUint32 imgSize = 0;
+ char* imgData = (char*)g_malloc((gulong)bufSize);
+ if (!imgData) return FALSE;
+
+ PRUint32 numReadThisTime = 0;
+ while ((rv = imgStream->Read(&imgData[imgSize], bufSize - imgSize,
+ &numReadThisTime)) == NS_OK && numReadThisTime > 0)
+ {
+ imgSize += numReadThisTime;
+ if (imgSize == bufSize)
+ {
+ // need a bigger buffer, just double
+ bufSize *= 2;
+ char* newImgData = (char*)g_realloc(imgData, (gulong)bufSize);
+ if (!newImgData)
+ {
+ g_free(imgData);
+ return FALSE;
+ }
+ imgData = newImgData;
+ }
+ }
+
+ GdkPixbufLoader *loader = gdk_pixbuf_loader_new_with_mime_type("image/png", NULL);
+ if (!loader)
+ return FALSE;
+ gdk_pixbuf_loader_write(loader, (const guchar *)imgData, (gsize)imgSize, NULL);
+ GdkPixbuf *thumbnail = gdk_pixbuf_loader_get_pixbuf(loader);
+ gdk_pixbuf_loader_close(loader, NULL);
+
+ if (!thumbnail)
+ return FALSE;
+
+ KZ_CREATE_THUMBNAIL(thumbnail, uri, last_modified, size);
+
+ g_object_unref(thumbnail);
+
+ g_free(imgData);
+
+ return TRUE;
+}
+#endif
Property changes on: kazehakase/trunk/module/embed/gecko/kz-mozthumbnailer.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Added: kazehakase/trunk/module/embed/gecko/kz-mozthumbnailer.h
===================================================================
--- kazehakase/trunk/module/embed/gecko/kz-mozthumbnailer.h 2008-02-22 04:21:35 UTC (rev 3389)
+++ kazehakase/trunk/module/embed/gecko/kz-mozthumbnailer.h 2008-02-22 15:36:56 UTC (rev 3390)
@@ -0,0 +1,40 @@
+// -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+
+//
+// Copyright (C) 2008 Kouhei Sutou
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+
+#ifndef __KZ_MOZTHUMBNAILER_H__
+#define __KZ_MOZTHUMBNAILER_H__
+
+#include <nsIDOMWindow.h>
+#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_
+#include "egg-pixbuf-thumbnail.h"
+#endif
+
+namespace KzMozThumbnailer
+{
+#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_
+ gboolean CreateThumbnail (nsIDOMWindow *domWindow,
+ const gchar *uri,
+ guint last_modified,
+ EggPixbufThumbSize size);
+#endif
+};
+
+#endif
Property changes on: kazehakase/trunk/module/embed/gecko/kz-mozthumbnailer.h
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: kazehakase/trunk/module/embed/gecko/kz-mozwrapper.cpp
===================================================================
--- kazehakase/trunk/module/embed/gecko/kz-mozwrapper.cpp 2008-02-22 04:21:35 UTC (rev 3389)
+++ kazehakase/trunk/module/embed/gecko/kz-mozwrapper.cpp 2008-02-22 15:36:56 UTC (rev 3390)
@@ -93,6 +93,7 @@
#include <nsIDOM3Document.h>
#include <nsIDocCharset.h>
+
#ifdef HAVE_NSIPRESCONTEXT_H
# include <nsIPresContext.h>
#else
@@ -109,6 +110,7 @@
#include "kz-mozutils.h"
#include "utils.h"
#include "kz-bookmark.h"
+#include "kz-mozthumbnailer.h"
# include <nsISSLStatus.h>
# include <nsISSLStatusProvider.h>
@@ -2091,8 +2093,8 @@
nsCOMPtr<nsIDOMWindow> domWindow;
GetDOMWindow(getter_AddRefs(domWindow));
-// if (!MozillaPrivate::CreateThumbnail(domWindow, uri,
-// last_modified, size))
+ if (!KzMozThumbnailer::CreateThumbnail(domWindow, uri,
+ last_modified, size))
return NS_ERROR_FAILURE;
return NS_OK;
More information about the Kazehakase-cvs mailing list |