[ilovegom commit] r74 - in trunk/gom: . idl include include/xpgom src/xpgom

0 views
Skip to first unread message

codesite...@google.com

unread,
Aug 16, 2008, 6:16:27 AM8/16/08
to gom-c...@googlegroups.com
Author: ja...@87k.net
Date: Sat Aug 16 03:15:47 2008
New Revision: 74

Added:
trunk/gom/idl/xgIGomContext.idl
trunk/gom/idl/xgIGomParser.idl
trunk/gom/include/xpgom/xgGomContext.hh
trunk/gom/include/xpgom/xgGomElementFactory.hh
trunk/gom/include/xpgom/xgGtkElement.hh
trunk/gom/include/xpgom/xgGtkElementFactory.hh
trunk/gom/src/xpgom/xgGomContext.cc
trunk/gom/src/xpgom/xgGomElementFactory.cc
trunk/gom/src/xpgom/xgGomParser.js
trunk/gom/src/xpgom/xgGtkElement.cc
trunk/gom/src/xpgom/xgGtkElementFactory.cc
Modified:
trunk/gom/ChangeLog
trunk/gom/Makefile.am
trunk/gom/configure.ac
trunk/gom/idl/ (props changed)
trunk/gom/include/gommacros.h
trunk/gom/src/xpgom/Makefile.inc
trunk/gom/src/xpgom/xgGomModule.cc
trunk/gom/src/xpgom/xpgom.js

Log:
2008-08-16 jacob berkman <ja...@ilovegom.org>

* src/xpgom/xgGomModule.cc (nsGomModuleConstructor):
initialize the gtk widget types here for now, instead of using
the defunct libgom

* src/xpgom/xgGomContext.cc: beginnings of the XTF-based
runtime

* src/xpgom/xgGtkElementFactory.cc (CreateElement): factory
for creating gtk elements

* src/xpgom/xgGomParser.js: load a url using the sax parser,
and give notice when the document is created

* src/xpgom/xgGomElementFactory.cc (CreateElement): stub for
handling non-gtk gom elements

* src/xpgom/xpgom.js: use our custom interface for loading
gom apps

* src/xpgom/xgGtkElement.cc: beginnings of an XTF-based gom
implementation

Modified: trunk/gom/ChangeLog
==============================================================================
--- trunk/gom/ChangeLog (original)
+++ trunk/gom/ChangeLog Sat Aug 16 03:15:47 2008
@@ -1,3 +1,27 @@
+2008-08-16 jacob berkman <ja...@ilovegom.org>
+
+ * src/xpgom/xgGomModule.cc (nsGomModuleConstructor):
+ initialize the gtk widget types here for now, instead of using
+ the defunct libgom
+
+ * src/xpgom/xgGomContext.cc: beginnings of the XTF-based
+ runtime
+
+ * src/xpgom/xgGtkElementFactory.cc (CreateElement): factory
+ for creating gtk elements
+
+ * src/xpgom/xgGomParser.js: load a url using the sax parser,
+ and give notice when the document is created
+
+ * src/xpgom/xgGomElementFactory.cc (CreateElement): stub for
+ handling non-gtk gom elements
+
+ * src/xpgom/xpgom.js: use our custom interface for loading
+ gom apps
+
+ * src/xpgom/xgGtkElement.cc: beginnings of an XTF-based gom
+ implementation
+
2008-08-13 jacob berkman <ja...@ilovegom.org>

* src/gom/gom.c (main): disable xpcom initialization

Modified: trunk/gom/Makefile.am
==============================================================================
--- trunk/gom/Makefile.am (original)
+++ trunk/gom/Makefile.am Sat Aug 16 03:15:47 2008
@@ -74,11 +74,11 @@

include examples/Makefile.inc
include idl/Makefile.inc
-include include/gom/Makefile.inc
-include include/gom/dom/Makefile.inc
+#include include/gom/Makefile.inc
+#include include/gom/dom/Makefile.inc
include include/xpgom/Makefile.inc
-include src/gom/Makefile.inc
-include src/libgom/Makefile.inc
+#include src/gom/Makefile.inc
+#include src/libgom/Makefile.inc
include src/schema/Makefile.inc
include src/xpgom/Makefile.inc
include tests/Makefile.inc
@@ -91,3 +91,6 @@

.idl.hh:
$(XPIDL) $(XPIDL_FLAGS) -m header -e $@ $<
+
+.idl.xpt:
+ $(XPIDL) $(XPIDL_FLAGS) -m typelib -e $@ $<

Modified: trunk/gom/configure.ac
==============================================================================
--- trunk/gom/configure.ac (original)
+++ trunk/gom/configure.ac Sat Aug 16 03:15:47 2008
@@ -77,10 +77,11 @@
])
GOM_CFLAGS="$GOM_CFLAGS $js_cppflags"

-xulrunner_cppflags="-I$xulrunnersdk/sdk/include -DMOZILLA_STRICT_API"
+xulrunner_cppflags="-I$xulrunnersdk/sdk/include
-I$xulrunnersdk/include/content -I$xulrunnersdk/include/xpcom
-DMOZILLA_STRICT_API"
CPPFLAGS="$CPPFLAGS_save $xulrunner_cppflags"
+CXXFLAGS="$CXXFLAGS -fshort-wchar"
AC_LANG_PUSH([C++])
-AC_CHECK_HEADERS([nsXPCOM.h nsIIOService.h],[],[
+AC_CHECK_HEADERS([nsXPCOM.h nsIIOService.h nsIXTFElementFactory.h
nsIAtom.h],[],[
AC_MSG_ERROR([$xulrunnersdk is missing XPCOM headers.])
])
AC_LANG_POP([C++])

Added: trunk/gom/idl/xgIGomContext.idl
==============================================================================
--- (empty file)
+++ trunk/gom/idl/xgIGomContext.idl Sat Aug 16 03:15:47 2008
@@ -0,0 +1,12 @@
+#include "nsISupports.idl"
+
+interface nsIDOMDocument;
+
+[scriptable, uuid(B6A5927E-44A3-4626-A71E-08575B367349)]
+interface xgIGomContext : nsISupports
+{
+ readonly attribute nsIDOMDocument document;
+
+ void init (in string uri);
+ void run ();
+};
\ No newline at end of file

Added: trunk/gom/idl/xgIGomParser.idl
==============================================================================
--- (empty file)
+++ trunk/gom/idl/xgIGomParser.idl Sat Aug 16 03:15:47 2008
@@ -0,0 +1,15 @@
+#include "nsISupports.idl"
+
+interface nsIDOMDocument;
+
+[scriptable, uuid(194C04B0-62FD-4594-822D-1CDB3596BB7C)]
+interface xgIGomParserListener : nsISupports
+{
+ void documentCreated (in nsIDOMDocument document);
+};
+
+[scriptable, uuid(5B251DFE-C380-4298-B547-11A006AB4784)]
+interface xgIGomParser : nsISupports
+{
+ nsIDOMDocument parseURI (in string uri, in xgIGomParserListener
listener);
+};

Modified: trunk/gom/include/gommacros.h
==============================================================================
--- trunk/gom/include/gommacros.h (original)
+++ trunk/gom/include/gommacros.h Sat Aug 16 03:15:47 2008
@@ -190,6 +190,12 @@
NS_UTF16ToCString (_aString, NS_CSTRING_ENCODING_UTF8,
_aCString##String); \
const char *_aCString = _aCString##String.get();

+#define GOM_ATOM_TO_GSTRING_RETURN(_aCString, _aAtom, _errval) \
+ const char *_aCString; \
+ if (NS_FAILED (_aAtom->GetUTF8String (&_aCString))) { \
+ return _errval; \
+ }
+
#define GOM_GSTRING_TO_ASTRING_RETURN(_aString, _aCString, _errval) \
G_STMT_START { \
nsCAutoString _aCString##String (_aCString); \

Added: trunk/gom/include/xpgom/xgGomContext.hh
==============================================================================
--- (empty file)
+++ trunk/gom/include/xpgom/xgGomContext.hh Sat Aug 16 03:15:47 2008
@@ -0,0 +1,57 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#ifndef XG_GOM_CONTEXT_HH
+#define XG_GOM_CONTEXT_HH
+
+#include "xgIGomContext.hh"
+
+#include <nsCOMPtr.h>
+
+class nsIDOMDocument;
+
+#define XG_GOMCONTEXT_CID_STR "C47A034A-600D-43CF-96A0-769642753BA0"
+#define XG_GOMCONTEXT_CID \
+ { 0xC47A034A, 0x600D, 0x43CF, { 0x96, 0xA0, 0x76, 0x96, 0x42, 0x75,
0x3B, 0xA0 } }
+#define XG_GOMCONTEXT_CONTRACTID "@ilovegom.org/context;1"
+
+class xgGomContext : public xgIGomContext
+{
+ friend class xgGomContextParserListener;
+
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_XGIGOMCONTEXT
+
+ xgGomContext();
+
+private:
+ ~xgGomContext();
+
+ nsCOMPtr<nsIDOMDocument> mDocument;
+
+protected:
+ void SetDocument (nsIDOMDocument *aDocument);
+};
+
+#endif /* XG_GOM_CONTEXT_HH */

Added: trunk/gom/include/xpgom/xgGomElementFactory.hh
==============================================================================
--- (empty file)
+++ trunk/gom/include/xpgom/xgGomElementFactory.hh Sat Aug 16 03:15:47 2008
@@ -0,0 +1,52 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#ifndef XG_GOM_ELEMENT_FACTORY_HH
+#define XG_GOM_ELEMENT_FACTORY_HH
+
+#include <nsIXTFElementFactory.h>
+
+#define XG_NAMESPACE_GOM "http://ilovegom.org/Gom"
+
+#define XG_GOMELEMENTFACTORY_CID_STR "DAD332E0-0067-4F10-B1F5-DFFB6F1188BA"
+#define XG_GOMELEMENTFACTORY_CID \
+ { 0xDAD332E0, 0x0067, 0x4F10, { 0xB1, 0xF5, 0xDF, 0xFB, 0x6F, 0x11,
0x88, 0xBA } }
+#define XG_GOMELEMENTFACTORY_CONTRACTID
NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX XG_NAMESPACE_GOM
+
+class xgGomElementFactory : public nsIXTFElementFactory
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXTFELEMENTFACTORY
+
+ xgGomElementFactory();
+
+private:
+ ~xgGomElementFactory();
+
+protected:
+ /* additional members */
+};
+
+#endif /* XG_GOM_ELEMENT_FACTORY_HH */
+

Added: trunk/gom/include/xpgom/xgGtkElement.hh
==============================================================================
--- (empty file)
+++ trunk/gom/include/xpgom/xgGtkElement.hh Sat Aug 16 03:15:47 2008
@@ -0,0 +1,59 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#ifndef XG_GTK_ELEMENT_HH
+#define XG_GTK_ELEMENT_HH
+
+#include "xgPIWrapped.hh"
+
+#include <nsIXTFElement.h>
+#include <nsIXTFElementWrapper.h>
+#include <nsIXTFAttributeHandler.h>
+#include <nsCOMPtr.h>
+
+#include <glib-object.h>
+
+class xgGtkElement : public nsIXTFElement,
+ public nsIXTFAttributeHandler,
+ public xgPIWrapped
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXTFELEMENT
+ NS_DECL_NSIXTFATTRIBUTEHANDLER
+ NS_DECL_XGPIWRAPPED
+
+ xgGtkElement();
+ nsresult Init(GType type);
+
+private:
+ ~xgGtkElement();
+
+protected:
+ GType mType;
+ GObject *mObject;
+ nsCOMPtr<nsIXTFElementWrapper> mWrapper;
+ GHashTable *mAttrs;
+};
+
+#endif /* XG_GTK_ELEMENT_HH */

Added: trunk/gom/include/xpgom/xgGtkElementFactory.hh
==============================================================================
--- (empty file)
+++ trunk/gom/include/xpgom/xgGtkElementFactory.hh Sat Aug 16 03:15:47 2008
@@ -0,0 +1,52 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#ifndef XG_GTK_ELEMENT_FACTORY_HH
+#define XG_GTK_ELEMENT_FACTORY_HH
+
+#include <nsIXTFElementFactory.h>
+
+#define XG_NAMESPACE_GTK "http://ilovegom.org/Gtk"
+
+#define XG_GTKELEMENTFACTORY_CID_STR "D950C1C6-BEE4-44D1-AF0A-5323C09048A3"
+#define XG_GTKELEMENTFACTORY_CID \
+ { 0xD950C1C6, 0xBEE4, 0x44D1, { 0xAF, 0x0A, 0x53, 0x23, 0xC0, 0x90,
0x48, 0xA3 } }
+#define XG_GTKELEMENTFACTORY_CONTRACTID
NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX XG_NAMESPACE_GTK
+
+class xgGtkElementFactory : public nsIXTFElementFactory
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXTFELEMENTFACTORY
+
+ xgGtkElementFactory();
+
+private:
+ ~xgGtkElementFactory();
+
+protected:
+ /* additional members */
+};
+
+#endif /* XG_GTK_ELEMENT_FACTORY_HH */
+

Modified: trunk/gom/src/xpgom/Makefile.inc
==============================================================================
--- trunk/gom/src/xpgom/Makefile.inc (original)
+++ trunk/gom/src/xpgom/Makefile.inc Sat Aug 16 03:15:47 2008
@@ -3,25 +3,28 @@
lib_LTLIBRARIES += libxpgom.la

libxpgom_la_SOURCES :=
-libxpgom_la_SOURCES += src/xpgom/gomwrapped.cc
-libxpgom_la_SOURCES += src/xpgom/gomwrappedattr.cc
-libxpgom_la_SOURCES += src/xpgom/gomwrappeddocument.cc
-libxpgom_la_SOURCES += src/xpgom/gomwrappeddomimplementation.cc
-libxpgom_la_SOURCES += src/xpgom/gomwrappedelement.cc
-libxpgom_la_SOURCES += src/xpgom/gomwrappednamednodemap.cc
-libxpgom_la_SOURCES += src/xpgom/gomwrappednode.cc
-libxpgom_la_SOURCES += src/xpgom/xgDocument.cc
-libxpgom_la_SOURCES += src/xpgom/xgDOMImplementation.cc
-libxpgom_la_SOURCES += src/xpgom/xgElement.cc
+#libxpgom_la_SOURCES += src/xpgom/gomwrapped.cc
+#libxpgom_la_SOURCES += src/xpgom/gomwrappedattr.cc
+#libxpgom_la_SOURCES += src/xpgom/gomwrappeddocument.cc
+#libxpgom_la_SOURCES += src/xpgom/gomwrappeddomimplementation.cc
+#libxpgom_la_SOURCES += src/xpgom/gomwrappedelement.cc
+#libxpgom_la_SOURCES += src/xpgom/gomwrappednamednodemap.cc
+#libxpgom_la_SOURCES += src/xpgom/gomwrappednode.cc
+#libxpgom_la_SOURCES += src/xpgom/xgDocument.cc
+#libxpgom_la_SOURCES += src/xpgom/xgDOMImplementation.cc
+#libxpgom_la_SOURCES += src/xpgom/xgElement.cc
+libxpgom_la_SOURCES += src/xpgom/xgGomContext.cc
+libxpgom_la_SOURCES += src/xpgom/xgGomElementFactory.cc
+libxpgom_la_SOURCES += src/xpgom/xgGtkElement.cc
+libxpgom_la_SOURCES += src/xpgom/xgGtkElementFactory.cc
libxpgom_la_SOURCES += src/xpgom/xgGomModule.cc
-libxpgom_la_SOURCES += src/xpgom/xgNode.cc
-libxpgom_la_SOURCES += src/xpgom/xgWrapped.cc
+#libxpgom_la_SOURCES += src/xpgom/xgNode.cc
+#libxpgom_la_SOURCES += src/xpgom/xgWrapped.cc

-src/xpgom/xgWrapped.cc: idl/xgPIWrapped.hh
+#$(libxpgom_la_SOURCES): idl/xgPIWrapped.hh idl/xgIGomContext.hh
idl/xgIGomParser.hh

libxpgom_la_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
-I$(top_builddir)/idl $(XPGOM_CFLAGS)
-libxpgom_la_CXXFLAGS = -fshort-wchar
libxpgom_la_LIBDADD :=
-libxpgom_la_LDFLAGS := -avoid-version -export-dynamic libgom.a
$(XPGOM_LIBS)
+libxpgom_la_LDFLAGS := -avoid-version -export-dynamic -no-undefined
$(XPGOM_LIBS)

-libxpgom_la_DEPENDENCIES := libgom.a
+# libxpgom_la_DEPENDENCIES := libgom.a

Added: trunk/gom/src/xpgom/xgGomContext.cc
==============================================================================
--- (empty file)
+++ trunk/gom/src/xpgom/xgGomContext.cc Sat Aug 16 03:15:47 2008
@@ -0,0 +1,134 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#include "config.h"
+
+#include "xpgom/xgGomContext.hh"
+#include "xgIGomParser.hh"
+
+#include <nsCOMPtr.h>
+#include <nsComponentManagerUtils.h>
+#include <nsIClassInfoImpl.h>
+#include <nsIDOMDocument.h>
+#include <nsMemory.h>
+
+#include <gtk/gtkmain.h>
+
+class xgGomContextParserListener : public xgIGomParserListener
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_XGIGOMPARSERLISTENER
+
+ xgGomContextParserListener ();
+
+ nsresult Init (xgGomContext *context);
+
+private:
+ ~xgGomContextParserListener();
+
+protected:
+ xgGomContext *mContext;
+};
+
+xgGomContext::xgGomContext()
+{
+}
+
+xgGomContext::~xgGomContext()
+{
+}
+
+
+NS_IMPL_ISUPPORTS1_CI(xgGomContext, xgIGomContext)
+
+/* readonly attribute nsIDOMDocument document; */
+NS_IMETHODIMP
+xgGomContext::GetDocument (nsIDOMDocument **aDocument)
+{
+ *aDocument = mDocument;
+ NS_IF_ADDREF (*aDocument);
+ return NS_OK;
+}
+
+/* void init (in string uri); */
+NS_IMETHODIMP
+xgGomContext::Init (const char *uri)
+{
+ nsresult rv;
+ xgGomContextParserListener *listener = new xgGomContextParserListener
();
+
+ NS_ADDREF (listener);
+ rv = listener->Init (this);
+ if (NS_FAILED (rv)) {
+ NS_RELEASE (listener);
+ return rv;
+ }
+
+ nsCOMPtr<xgIGomParserListener> iListener (do_QueryInterface
(listener));
+ NS_RELEASE (listener);
+
+ nsCOMPtr<xgIGomParser> parser (do_CreateInstance
("@ilovegom.org/parser;1", &rv));
+ if (NS_FAILED (rv)) {
+ return rv;
+ }
+
+ nsCOMPtr<nsIDOMDocument> document;
+ return parser->ParseURI (uri, iListener, getter_AddRefs (document));
+}
+
+/* void run (); */
+NS_IMETHODIMP
+xgGomContext::Run()
+{
+ gtk_main ();
+ return NS_OK;
+}
+
+xgGomContextParserListener::xgGomContextParserListener()
+ : mContext (NULL)
+{
+}
+
+xgGomContextParserListener::~xgGomContextParserListener()
+{
+ mContext = NULL;
+}
+
+NS_IMPL_ISUPPORTS1(xgGomContextParserListener, xgIGomParserListener)
+
+nsresult
+xgGomContextParserListener::Init (xgGomContext *context)
+{
+ mContext = context;
+ return NS_OK;
+}
+
+
+/* void documentCreated (in nsIDOMDocument document); */
+NS_IMETHODIMP
+xgGomContextParserListener::DocumentCreated (nsIDOMDocument *document)
+{
+ mContext->mDocument = document;
+ return NS_OK;
+}

Added: trunk/gom/src/xpgom/xgGomElementFactory.cc
==============================================================================
--- (empty file)
+++ trunk/gom/src/xpgom/xgGomElementFactory.cc Sat Aug 16 03:15:47 2008
@@ -0,0 +1,46 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#include "config.h"
+
+#include "xpgom/xgGomElementFactory.hh"
+
+/* Implementation file */
+NS_IMPL_ISUPPORTS1(xgGomElementFactory, nsIXTFElementFactory)
+
+xgGomElementFactory::xgGomElementFactory()
+{
+ /* member initializers and constructor code */
+}
+
+xgGomElementFactory::~xgGomElementFactory()
+{
+ /* destructor code */
+}
+
+/* nsIXTFElement createElement (in AString tagName); */
+NS_IMETHODIMP
+xgGomElementFactory::CreateElement (const nsAString &tagName,
nsIXTFElement **_retval)
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}

Modified: trunk/gom/src/xpgom/xgGomModule.cc
==============================================================================
--- trunk/gom/src/xpgom/xgGomModule.cc (original)
+++ trunk/gom/src/xpgom/xgGomModule.cc Sat Aug 16 03:15:47 2008
@@ -23,35 +23,70 @@
*/
#include "config.h"

+#include <glib/gmacros.h>
+
+#if 0
#include "xpgom/xgDOMImplementation.hh"
#include "xpgom/gomwrappeddomimplementation.hh"
#include "xpgom/gomwrappeddocument.hh"
#include "xpgom/gomwrappedelement.hh"
#include "xpgom/gomwrappednamednodemap.hh"
#include "xpgom/gomwrappedattr.hh"
+#endif
+
+#include "xpgom/xgGomContext.hh"
+#include "xpgom/xgGomElementFactory.hh"
+#include "xpgom/xgGtkElementFactory.hh"

#include "gom/gomwidget.h"

-#include <gtk/gtkmain.h>
+#include <gtk/gtk.h>

-#include <nsIGenericFactory.h>
#include <nsIClassInfoImpl.h>
#include <nsIFile.h>
+#include <nsIGenericFactory.h>
+#include <nsIXTFElementFactory.h>
#include <nsStringAPI.h>

-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(xgDOMImplementation, Init);
+NS_GENERIC_FACTORY_CONSTRUCTOR(xgGomElementFactory);
+NS_GENERIC_FACTORY_CONSTRUCTOR(xgGtkElementFactory);
+//NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(xgDOMImplementation, Init);
+NS_GENERIC_FACTORY_CONSTRUCTOR (xgGomContext);

-NS_DECL_CLASSINFO(xgDOMImplementation)
+//NS_DECL_CLASSINFO(xgDOMImplementation)
+NS_DECL_CLASSINFO (xgGomContext)

static const nsModuleComponentInfo components[] = {
{
- "DOM Implementation",
+ "Gom Core Element Factory",
+ XG_GOMELEMENTFACTORY_CID, XG_GOMELEMENTFACTORY_CONTRACTID,
+ xgGomElementFactoryConstructor
+ },
+ {
+ "Gom Gtk Element Factory",
+ XG_GTKELEMENTFACTORY_CID, XG_GTKELEMENTFACTORY_CONTRACTID,
+ xgGtkElementFactoryConstructor
+ },
+ {
+ "Gom Application Context",
+ XG_GOMCONTEXT_CID, XG_GOMCONTEXT_CONTRACTID,
+ xgGomContextConstructor,
+ NULL, NULL, NULL,
+ NS_CI_INTERFACE_GETTER_NAME (xgGomContext),
+ NULL,
+ &NS_CLASSINFO_NAME (xgGomContext)
+
+#if 0
+ },
+ {
+ "Gom DOM Implementation",
XG_DOMIMPLEMENTATION_CID, XG_DOMIMPLEMENTATION_CONTRACTID,
xgDOMImplementationConstructor,
/* xgGomRegistrationProc */ NULL, NULL, NULL,
NS_CI_INTERFACE_GETTER_NAME (xgDOMImplementation),
NULL,
&NS_CLASSINFO_NAME(xgDOMImplementation)
+#endif
}
};

@@ -62,12 +97,19 @@
g_warning ("Could not initialize Gtk; Gom module unavailable.");
return NS_ERROR_NOT_AVAILABLE;
}
+
+#define WIDGET(w) g_type_qname (w);
+#include "gomwidgets.c"
+#undef WIDGET
+
+#if 0
gom_widget_init ();
g_type_class_ref (GOM_TYPE_WRAPPED_DOM_IMPLEMENTATION);
g_type_class_ref (GOM_TYPE_WRAPPED_NAMED_NODE_MAP);
g_type_class_ref (GOM_TYPE_WRAPPED_ATTR);
g_type_class_ref (GOM_TYPE_WRAPPED_ELEMENT);
g_type_class_ref (GOM_TYPE_WRAPPED_DOCUMENT);
+#endif
return NS_OK;
}


Added: trunk/gom/src/xpgom/xgGomParser.js
==============================================================================
--- (empty file)
+++ trunk/gom/src/xpgom/xgGomParser.js Sat Aug 16 03:15:47 2008
@@ -0,0 +1,125 @@
+var xgGomParserModule = { };
+function NSGetModule (aCompMgr, aFileSpec) { return xgGomParserModule; }
+
+(function () {
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+
+const CLASS_ID = Components.ID("{E643FF76-1F9C-452A-A0A6-421B1AA1AFE5}");
+const CLASS_NAME = "An XML Parser for Gom";
+const CONTRACT_ID = "@ilovegom.org/parser;1";
+
+function xgGomParser() {
+ this.wrappedJSObject = this;
+};
+
+function getDOMImplementation() {
+ // return
Cc['@ilovegom.org/dom-implementation;1'].createInstance(Ci.nsIDOMDOMImplementation);
+ var parser = Cc['@mozilla.org/xmlextras/domparser;1'].createInstance
(Ci.nsIDOMParser);
+ var document = parser.parseFromString('', "text/xml");
+ return document.implementation;
+};
+
+xgGomParser.prototype = {
+ // xgIGomParser
+ parseURI: function (uri, listener) {
+ var io = Cc['@mozilla.org/network/io-service;1'].getService
(Ci.nsIIOService);
+ var uri = io.newURI (uri, null, null);
+
+ var chan = io.newChannelFromURI (uri);
+ var stream = chan.open();
+
+ var reader = Cc['@mozilla.org/saxparser/xmlreader;1'].createInstance
(Ci.nsISAXXMLReader);
+ var document = null;
+ reader.contentHandler = {
+ elem: null,
+
+ // nsISAXContentHandler
+ startDocument: function () { },
+ endDocument: function () { },
+
+ startElement: function (nsUri, localName, qName, /*nsISAXAttributes*/
attributes) {
+ var elem;
+ if (document) {
+ elem = document.createElementNS (nsUri, qName);
+ } else {
+ document = getDOMImplementation ().createDocument (nsUri, qName,
null);
+ if (listener) {
+ listener.documentCreated (document);
+ }
+ elem = document.documentElement;
+ }
+ for(var i = 0; i < attributes.length; i++) {
+ elem.setAttribute (attributes.getLocalName (i),
+ attributes.getValue (i));
+ }
+ this.elem = this.elem ? this.elem.appendChild (elem) : elem;
+ },
+
+ endElement: function(uri, localName, qName) {
+ this.elem = this.elem.parentNode;
+ },
+
+ characters: function(value) { },
+ processingInstruction: function(target, data) { },
+ ignorableWhitespace: function(whitespace) { },
+ startPrefixMapping: function(prefix, uri) { },
+ endPrefixMapping: function(prefix) { },
+
+ // nsISupports
+ QueryInterface: function(iid) {
+ if(!iid.equals(Ci.nsISupports) &&
+ !iid.equals(Ci.nsISAXContentHandler))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ return this;
+ }
+ };
+ reader.parseFromStream (stream, 'UTF-8', 'text/xml');
+ return document;
+ },
+ // nsISupports
+ QueryInterface: function (aIID) {
+ if (!aIID.equals(Ci.xgIGomParser) &&
+ !aIID.equals(Ci.nsISupports))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ return this;
+ }
+};
+
+var xgGomParserFactory = {
+ createInstance: function (aOuter, aIID) {
+ if (aOuter != null) {
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+ }
+ return (new xgGomParser).QueryInterface (aIID);
+ }
+};
+
+xgGomParserModule.registerSelf = function(aCompMgr, aFileSpec, aLocation,
aType)
+{
+ aCompMgr = aCompMgr.QueryInterface
(Components.interfaces.nsIComponentRegistrar);
+ aCompMgr.registerFactoryLocation (CLASS_ID, CLASS_NAME, CONTRACT_ID,
+ aFileSpec, aLocation, aType);
+};
+
+xgGomParserModule.unregisterSelf = function (aCompMgr, aLocation, aType)
+{
+ aCompMgr = aCompMgr.QueryInterface
(Components.interfaces.nsIComponentRegistrar);
+ aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
+};
+
+xgGomParserModule.getClassObject = function(aCompMgr, aCID, aIID)
+{
+ if (!aIID.equals(Ci.nsIFactory)) {
+ throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+ }
+ if (aCID.equals(CLASS_ID))
+ return xgGomParserFactory;
+
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+};
+
+xgGomParserModule.canUnload = function(aCompMgr) { return true; }
+
+})();

Added: trunk/gom/src/xpgom/xgGtkElement.cc
==============================================================================
--- (empty file)
+++ trunk/gom/src/xpgom/xgGtkElement.cc Sat Aug 16 03:15:47 2008
@@ -0,0 +1,455 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#include "config.h"
+
+#include "xpgom/xgGtkElement.hh"
+
+#include "xpgom/xgObjectUtils.hh"
+
+#include <nsIAtom.h>
+#include <nsIDOMNode.h>
+#include <nsIDOMElement.h>
+#include <nsMemory.h>
+
+#include <gtk/gtk.h>
+
+#include "gommacros.h"
+
+xgGtkElement::xgGtkElement ()
+ : mType (0),
+ mObject (NULL),
+ mAttrs (NULL)
+{
+}
+
+xgGtkElement::~xgGtkElement()
+{
+ if (mAttrs) {
+ g_hash_table_destroy (mAttrs);
+ mAttrs = NULL;
+ }
+ if (mObject) {
+ g_object_unref (mObject);
+ mObject = NULL;
+ }
+}
+
+NS_IMPL_ISUPPORTS3 (xgGtkElement, nsIXTFElement, nsIXTFAttributeHandler,
xgPIWrapped)
+
+extern "C" static void
+free_value (gpointer data)
+{
+ GValue *value = (GValue *)data;
+ g_value_unset (value);
+ g_free (value);
+}
+
+nsresult
+xgGtkElement::Init (GType type)
+{
+ mAttrs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
free_value);
+ if (!mAttrs) {
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+ mType = type;
+ return NS_OK;
+}
+
+/* xgNativeGObject getWrappedGObject (); */
+NS_IMETHODIMP
+xgGtkElement::GetWrappedGObject (GObject **_retval)
+{
+ *_retval = mObject ? G_OBJECT (g_object_ref (mObject)) : NULL;
+ return NS_OK;
+}
+
+#if 0
+/* xgNativeGtkElement getGtkElement (); */
+NS_IMETHODIMP
+xgGtkElement::GetGtkElement (xgGtkElement **_retval)
+{
+ *_retval = this;
+ return NS_OK;
+}
+#endif
+
+/* void onCreated (in nsIXTFElementWrapper wrapper); */
+NS_IMETHODIMP
+xgGtkElement::OnCreated (nsIXTFElementWrapper *wrapper)
+{
+ if (!mType) {
+ return NS_ERROR_FAILURE;
+ }
+ g_print (GOM_LOC ("Creating new <%s>...\n"), g_type_name (mType));
+ mObject = (GObject *)g_object_new (mType, NULL);
+ gtk_widget_show (GTK_WIDGET (mObject));
+ mWrapper = wrapper;
+ mWrapper->SetNotificationMask (NOTIFY_PARENT_CHANGED |
+ NOTIFY_WILL_INSERT_CHILD |
+ NOTIFY_WILL_APPEND_CHILD |
+ NOTIFY_CHILD_REMOVED);
+ return NS_OK;
+}
+
+/* void onDestroyed (); */
+NS_IMETHODIMP
+xgGtkElement::OnDestroyed ()
+{
+ mWrapper = NULL;
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* readonly attribute boolean isAttributeHandler; */
+NS_IMETHODIMP
+xgGtkElement::GetIsAttributeHandler (PRBool *aIsAttributeHandler)
+{
+ *aIsAttributeHandler = PR_TRUE;
+ return NS_OK;
+}
+
+/* void getScriptingInterfaces (out unsigned long count, [array, size_is
(count), retval] out nsIIDPtr array); */
+NS_IMETHODIMP
+xgGtkElement::GetScriptingInterfaces (PRUint32 *count, nsIID ***array)
+{
+ *array = (nsIID **)nsMemory::Alloc (sizeof (nsIID *));
+ if (!array) {
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+
+ const nsIID wrappedIID = XGPIWRAPPED_IID;
+ (*array)[0] = (nsIID *)nsMemory::Clone (&wrappedIID, sizeof (nsIID));
+ if (!(*array)[0]) {
+ nsMemory::Free (*array);
+ *array = NULL;
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+
+ *count = 1;
+ return NS_OK;
+}
+
+/* void willChangeDocument (in nsIDOMDocument newDoc); */
+NS_IMETHODIMP
+xgGtkElement::WillChangeDocument (nsIDOMDocument *newDoc)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void documentChanged (in nsIDOMDocument newDoc); */
+NS_IMETHODIMP
+xgGtkElement::DocumentChanged (nsIDOMDocument *newDoc)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void willChangeParent (in nsIDOMElement newParent); */
+NS_IMETHODIMP
+xgGtkElement::WillChangeParent (nsIDOMElement *newParent)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+extern "C" static void
+append_child_attrs_foreach (gpointer key, gpointer value, gpointer
user_data)
+{
+ GParamSpec *spec;
+ GError *error = NULL;
+ GValue gval = { 0 };
+
+ GtkWidget *child = GTK_WIDGET (user_data);
+ GtkWidget *parent = gtk_widget_get_parent (child);
+
+ spec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS
(parent), (char *)key);
+ if (!spec ||
+ G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (spec)) ==
G_TYPE_OBJECT) {
+ return;
+ }
+#if 1
+ g_print ("found child property %s.%s on %s\n",
+ g_type_name (G_TYPE_FROM_INSTANCE (parent)),
+ spec->name,
+ g_type_name (G_TYPE_FROM_INSTANCE (child)));
+#endif
+ if (gtk_builder_value_from_string (NULL, spec,
+ g_value_get_string ((const GValue *)value),
+ &gval, &error)) {
+ gtk_container_child_set_property (GTK_CONTAINER (parent), child,
+ spec->name, &gval);
+ g_value_unset (&gval);
+ } else {
+ g_print ("Error getting value_from_string: %s\n",
+ error->message);
+ g_error_free (error);
+ }
+}
+
+/* void parentChanged (in nsIDOMElement newParent); */
+NS_IMETHODIMP
+xgGtkElement::ParentChanged (nsIDOMElement *newParent)
+{
+ /* no need for this rigamarole... */
+ if (GTK_IS_WINDOW (mObject)) {
+ return NS_OK;
+ }
+
+ /* just as a sanity check */
+ nsCOMPtr<xgPIWrapped> wrappedParent (do_QueryInterface (newParent));
+ GObject *parent = NULL;
+ if (!wrappedParent || NS_FAILED (wrappedParent->GetWrappedGObject
(&parent)) ||
+ !GTK_IS_CONTAINER (parent)) {
+ g_warning (GOM_LOC ("Could not get parent widget for node: <%s>"),
+ G_OBJECT_TYPE_NAME (mObject));
+ return NS_ERROR_FAILURE;
+ }
+ g_assert ((GtkWidget *)parent == gtk_widget_get_parent (GTK_WIDGET
(mObject)));
+ g_object_unref (parent);
+
+ g_hash_table_foreach (mAttrs, append_child_attrs_foreach, mObject);
+
+ return NS_OK;
+}
+
+/* void willInsertChild (in nsIDOMNode child, in unsigned long index); */
+NS_IMETHODIMP
+xgGtkElement::WillInsertChild (nsIDOMNode *child, PRUint32 index)
+{
+ return WillAppendChild (child);
+}
+
+/* void childInserted (in nsIDOMNode child, in unsigned long index); */
+NS_IMETHODIMP
+xgGtkElement::ChildInserted (nsIDOMNode *child, PRUint32 index)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void willAppendChild (in nsIDOMNode child); */
+NS_IMETHODIMP
+xgGtkElement::WillAppendChild (nsIDOMNode *child)
+{
+ if (!GTK_IS_CONTAINER (mObject)) {
+ return NS_ERROR_FAILURE;
+ }
+
+ nsCOMPtr<xgPIWrapped> wrappedChild (do_QueryInterface (child));
+ GObject *widget = NULL;
+ if (!wrappedChild || NS_FAILED (wrappedChild->GetWrappedGObject
(&widget)) ||
+ !GTK_IS_WIDGET (widget)) {
+ if (widget) {
+ g_object_unref (widget);
+ }
+ return NS_ERROR_FAILURE;
+ }
+
+ gtk_container_add (GTK_CONTAINER (mObject), GTK_WIDGET (widget));
+ return NS_OK;
+}
+
+/* void childAppended (in nsIDOMNode child); */
+NS_IMETHODIMP
+xgGtkElement::ChildAppended (nsIDOMNode *child)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void willRemoveChild (in unsigned long index); */
+NS_IMETHODIMP
+xgGtkElement::WillRemoveChild (PRUint32 index)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void childRemoved (in unsigned long index); */
+NS_IMETHODIMP
+xgGtkElement::ChildRemoved (PRUint32 index)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void willSetAttribute (in nsIAtom name, in AString newValue); */
+NS_IMETHODIMP
+xgGtkElement::WillSetAttribute (nsIAtom *name, const nsAString & newValue)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void attributeSet (in nsIAtom name, in AString newValue); */
+NS_IMETHODIMP
+xgGtkElement::AttributeSet (nsIAtom *name, const nsAString & newValue)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void willRemoveAttribute (in nsIAtom name); */
+NS_IMETHODIMP
+xgGtkElement::WillRemoveAttribute (nsIAtom *name)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void attributeRemoved (in nsIAtom name); */
+NS_IMETHODIMP
+xgGtkElement::AttributeRemoved (nsIAtom *name)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void beginAddingChildren (); */
+NS_IMETHODIMP
+xgGtkElement::BeginAddingChildren ()
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void doneAddingChildren (); */
+NS_IMETHODIMP
+xgGtkElement::DoneAddingChildren ()
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* boolean handleDefault (in nsIDOMEvent aEvent); */
+NS_IMETHODIMP
+xgGtkElement::HandleDefault (nsIDOMEvent *aEvent, PRBool *_retval)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void cloneState (in nsIDOMElement aElement); */
+NS_IMETHODIMP
+xgGtkElement::CloneState (nsIDOMElement *aElement)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* readonly attribute nsIDOMAttr accesskeyNode; */
+NS_IMETHODIMP
+xgGtkElement::GetAccesskeyNode (nsIDOMAttr **aAccesskeyNode)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void performAccesskey (); */
+NS_IMETHODIMP
+xgGtkElement::PerformAccesskey ()
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* boolean handlesAttribute (in nsIAtom name); */
+NS_IMETHODIMP
+xgGtkElement::HandlesAttribute (nsIAtom *name, PRBool *_retval)
+{
+ *_retval = PR_TRUE;
+ return NS_OK;
+}
+
+/* void setAttribute (in nsIAtom name, in AString newValue); */
+NS_IMETHODIMP
+xgGtkElement::SetAttribute (nsIAtom *name, const nsAString &newValue)
+{
+ GOM_ATOM_TO_GSTRING_RETURN (prop, name, NS_ERROR_INVALID_ARG);
+ GOM_ASTRING_TO_GSTRING_RETURN (value, newValue, NS_ERROR_INVALID_ARG);
+
+ GParamSpec *spec = g_object_class_find_property (G_OBJECT_GET_CLASS
(mObject), prop);
+ if (spec) {
+ GError *error = NULL;
+ GValue gval = { 0 };
+ if (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (spec)) ==
G_TYPE_OBJECT) {
+ g_warning (GOM_LOC ("Attribute %s.%s is a %s, which a string
cannot be converted to"),
+ g_type_name (mType), prop,
+ g_type_name (G_PARAM_SPEC_VALUE_TYPE (spec)));
+ return NS_ERROR_FAILURE;
+ } else if (gtk_builder_value_from_string (NULL, spec, value,
&gval, &error)) {
+ g_object_set_property (mObject, prop, &gval);
+ g_value_unset (&gval);
+ } else {
+ g_warning (GOM_LOC ("Could not get value from string: '%s'"), value);
+ return NS_ERROR_FAILURE;
+ }
+ } else {
+ GValue *newval = g_new0 (GValue, 1);
+ g_value_init (newval, G_TYPE_STRING);
+ g_value_set_string (newval, value);
+ g_hash_table_insert (mAttrs, g_strdup (prop), newval);
+ }
+ return NS_OK;
+}
+
+/* void removeAttribute (in nsIAtom name); */
+NS_IMETHODIMP
+xgGtkElement::RemoveAttribute (nsIAtom *name)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* AString getAttribute (in nsIAtom name); */
+NS_IMETHODIMP
+xgGtkElement::GetAttribute (nsIAtom *name, nsAString &_retval)
+{
+ GOM_ATOM_TO_GSTRING_RETURN (prop, name, NS_ERROR_INVALID_ARG);
+
+ GParamSpec *spec = g_object_class_find_property (G_OBJECT_GET_CLASS
(mObject), prop);
+ if (spec) {
+ GValue gval = { 0 };
+ g_value_init (&gval, G_TYPE_STRING);
+ g_object_get_property (G_OBJECT (mObject), prop, &gval);
+ if (G_VALUE_HOLDS (&gval, G_TYPE_STRING)) {
+ nsCAutoString rval (g_value_get_string (&gval));
+ g_value_unset (&gval);
+ return NS_CStringToUTF16 (rval, NS_CSTRING_ENCODING_UTF8, _retval);
+ }
+ g_value_unset (&gval);
+ } else {
+ const GValue *gvalp = (const GValue *)g_hash_table_lookup (mAttrs,
prop);
+ if (gvalp) {
+ if (G_VALUE_HOLDS_STRING (gvalp)) {
+ nsCAutoString rval (g_value_get_string (gvalp));
+ return NS_CStringToUTF16 (rval, NS_CSTRING_ENCODING_UTF8, _retval);
+ }
+ }
+ }
+ return NS_ERROR_FAILURE;
+}
+
+/* boolean hasAttribute (in nsIAtom name); */
+NS_IMETHODIMP
+xgGtkElement::HasAttribute (nsIAtom *name, PRBool *_retval)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* unsigned long getAttributeCount (); */
+NS_IMETHODIMP
+xgGtkElement::GetAttributeCount (PRUint32 *_retval)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* nsIAtom getAttributeNameAt (in unsigned long index); */
+NS_IMETHODIMP
+xgGtkElement::GetAttributeNameAt (PRUint32 index, nsIAtom **_retval)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}

Added: trunk/gom/src/xpgom/xgGtkElementFactory.cc
==============================================================================
--- (empty file)
+++ trunk/gom/src/xpgom/xgGtkElementFactory.cc Sat Aug 16 03:15:47 2008
@@ -0,0 +1,71 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#include "config.h"
+
+#include "xpgom/xgGtkElement.hh"
+#include "xpgom/xgGtkElementFactory.hh"
+
+#include <nsCOMPtr.h>
+#include <nsStringAPI.h>
+
+#include <gtk/gtkwidget.h>
+
+#include "gommacros.h"
+
+/* Implementation file */
+NS_IMPL_ISUPPORTS1 (xgGtkElementFactory, nsIXTFElementFactory)
+
+xgGtkElementFactory::xgGtkElementFactory()
+{
+ /* member initializers and constructor code */
+}
+
+xgGtkElementFactory::~xgGtkElementFactory()
+{
+ /* destructor code */
+}
+
+/* nsIXTFElement createElement (in AString tagName); */
+NS_IMETHODIMP
+xgGtkElementFactory::CreateElement (const nsAString &tagName,
+ nsIXTFElement **_retval)
+{
+ GOM_ASTRING_TO_GSTRING_RETURN (tag_name, tagName,
NS_ERROR_INVALID_ARG);
+ GType gtype = g_type_from_name (tag_name);
+ if (!gtype || !g_type_is_a (gtype, GTK_TYPE_WIDGET)) {
+ return NS_ERROR_FAILURE;
+ }
+ xgGtkElement *elem = new xgGtkElement ();
+ if (!elem) {
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+ *_retval = elem;
+ NS_ADDREF (*_retval);
+ nsresult rv = elem->Init (gtype);
+ if (!NS_SUCCEEDED (rv)) {
+ NS_RELEASE (*_retval);
+ *_retval = NULL;
+ }
+ return rv;
+}

Modified: trunk/gom/src/xpgom/xpgom.js
==============================================================================
--- trunk/gom/src/xpgom/xpgom.js (original)
+++ trunk/gom/src/xpgom/xpgom.js Sat Aug 16 03:15:47 2008
@@ -1,5 +1,5 @@
//(function (args) {
-args = arguments;
+var args = arguments;
if (args.length == 0) {
print ('Usage: xpgom.js <url>');
quit (1);
@@ -8,91 +8,12 @@
var Cc = Components.classes;
var Ci = Components.interfaces;

-var io = Cc['@mozilla.org/network/io-service;1'].getService
(Ci.nsIIOService);
-var uri;
-try {
- uri = io.newURI (args[0], null, null);
-} catch (e) {
- print ('could not create uri: ' + e);
- quit (1);
-}
-
-var chan = io.newChannelFromURI (uri);
-var stream = chan.open();
-
-var reader = Cc['@mozilla.org/saxparser/xmlreader;1'].createInstance
(Ci.nsISAXXMLReader);
-var doc = null;
-reader.contentHandler = {
- elem: null,
-
- // nsISAXContentHandler
- startDocument: function () {
- print ("startDocument");
- },
-
- endDocument: function () {
- print ("endDocument");
- },
-
- startElement: function (nsUri, localName, qName, /*nsISAXAttributes*/
attributes) {
- var elem;
- if (doc) {
- elem = doc.createElementNS (nsUri, qName);
- } else {
- var dom =
Cc['@ilovegom.org/dom-implementation;1'].createInstance(Ci.nsIDOMDOMImplementation);
- doc = dom.createDocument (nsUri, qName, null);
- elem = doc.documentElement;
- }
- for(var i = 0; i < attributes.length; i++) {
- elem.setAttribute (attributes.getLocalName (i),
- attributes.getValue (i));
- }
- this.elem = this.elem ? this.elem.appendChild (elem) : elem;
- },
-
- endElement: function(uri, localName, qName) {
- this.elem = this.elem.parentNode;
- print("endElement: namespace='" + uri + "', localName='" +
- localName + "', qName='" + qName + "'");
- },
-
- characters: function(value) {
- print("characters: " + value);
- },
-
- processingInstruction: function(target, data) {
- print("processingInstruction: target='" + target + "', data='" +
- data + "'");
- },
-
- ignorableWhitespace: function(whitespace) {
- // don't care
- },
-
- startPrefixMapping: function(prefix, uri) {
- // don't care
- },
-
- endPrefixMapping: function(prefix) {
- // don't care
- },
-
- // nsISupports
- QueryInterface: function(iid) {
- if(!iid.equals(Ci.nsISupports) &&
- !iid.equals(Ci.nsISAXContentHandler))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- }
-};
-reader.parseFromStream (stream, 'UTF-8', 'text/xml');
-
-var parser = Cc['@mozilla.org/xmlextras/domparser;1'].createInstance
(Ci.nsIDOMParser);
-
-var nsdoc = parser.parseFromString ('<?xml
version="1.0"?>\n<a/>', 'text/xml')
-nsdoc.replaceChild (nsdoc.documentElement, nsdoc.importNode
(doc.documentElement, true));
+var gom = Cc['@ilovegom.org/context;1'].createInstance (Ci.xgIGomContext);
+gom.init (args[0]);

var serializer =
Cc['@mozilla.org/xmlextras/xmlserializer;1'].createInstance(Ci.nsIDOMSerializer);
-print (serializer.serializeToString (nsdoc));
+print (serializer.serializeToString (gom.document));
+
+gom.run ();

//})(arguments);

Reply all
Reply to author
Forward
0 new messages