Modified:
trunk/gom/ChangeLog
trunk/gom/xulapp/components/gom/src/xgGtkElement.cpp
trunk/gom/xulapp/components/gom/src/xgGtkElement.h
Log:
2008-08-27 jacob <ja...@ilovegom.org>
* xulapp/components/gom/src/xgGtkElement.cpp (xgGtkElement::SetAttribute):
add the attribute to our hash table whether it is handled as a
property or not, so that attribute lookups work as they should
(xgGtkElement::HasAttribute, xgGtkElement::GetAttributeCount)
(xgGtkElement::GetAttributeNameAt): implement
Modified: trunk/gom/ChangeLog
==============================================================================
--- trunk/gom/ChangeLog (original)
+++ trunk/gom/ChangeLog Wed Aug 27 00:33:09 2008
@@ -1,3 +1,11 @@
+2008-08-27 jacob <ja...@ilovegom.org>
+
+ * xulapp/components/gom/src/xgGtkElement.cpp (xgGtkElement::SetAttribute):
+ add the attribute to our hash table whether it is handled as a
+ property or not, so that attribute lookups work as they should
+ (xgGtkElement::HasAttribute, xgGtkElement::GetAttributeCount)
+ (xgGtkElement::GetAttributeNameAt): implement
+
2008-08-24 jacob <ja...@ilovegom.org>
* xulapp/various: continue to fixup 'make dist', and enable 'make
Modified: trunk/gom/xulapp/components/gom/src/xgGtkElement.cpp
==============================================================================
--- trunk/gom/xulapp/components/gom/src/xgGtkElement.cpp (original)
+++ trunk/gom/xulapp/components/gom/src/xgGtkElement.cpp Wed Aug 27
00:33:09 2008
@@ -32,18 +32,25 @@
#include "gommacros.h"
#include <nsIAtom.h>
+#include <nsIAtomService.h>
#include <nsIDOMNode.h>
#include <nsIDOMElement.h>
+#include <nsServiceManagerUtils.h>
xgGtkElement::xgGtkElement ()
: mType (0),
mObject (NULL),
- mAttrs (NULL)
+ mAttrs (NULL),
+ mKeys (NULL)
{
}
xgGtkElement::~xgGtkElement()
{
+ if (mKeys) {
+ g_list_free (mKeys);
+ mKeys = NULL;
+ }
if (mAttrs) {
g_hash_table_destroy (mAttrs);
mAttrs = NULL;
@@ -56,6 +63,23 @@
NS_IMPL_ISUPPORTS3 (xgGtkElement, nsIXTFElement, nsIXTFAttributeHandler,
xgIGObjectWrapper)
+void
+xgGtkElement::AttrsModified ()
+{
+ if (mKeys) {
+ g_list_free (mKeys);
+ mKeys = NULL;
+ }
+}
+
+void
+xgGtkElement::EnsureKeys ()
+{
+ if (!mKeys) {
+ mKeys = g_hash_table_get_keys (mAttrs);
+ }
+}
+
static void
free_value (gpointer data)
{
@@ -158,6 +182,10 @@
static void
append_child_attrs_foreach (gpointer key, gpointer value, gpointer
user_data)
{
+ if (!value) {
+ return;
+ }
+
GParamSpec *spec;
GError *error = NULL;
GValue gval = { 0 };
@@ -358,6 +386,7 @@
GOM_ASTRING_TO_GSTRING_RETURN (value, newValue, NS_ERROR_INVALID_ARG);
GParamSpec *spec = g_object_class_find_property (G_OBJECT_GET_CLASS
(mObject), prop);
+ GValue *newval = NULL;
if (spec) {
GError *error = NULL;
GValue gval = { 0 };
@@ -374,11 +403,12 @@
return NS_ERROR_FAILURE;
}
} else {
- GValue *newval = g_new0 (GValue, 1);
+ 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);
}
+ g_hash_table_insert (mAttrs, g_strdup (prop), newval);
+ AttrsModified();
return NS_OK;
}
@@ -422,19 +452,37 @@
NS_IMETHODIMP
xgGtkElement::HasAttribute (nsIAtom *name, PRBool *_retval)
{
- XG_RETURN_NOT_IMPLEMENTED;
+ GOM_ATOM_TO_GSTRING_RETURN (prop, name, NS_ERROR_INVALID_ARG);
+
+ GParamSpec *spec = g_object_class_find_property (G_OBJECT_GET_CLASS
(mObject), prop);
+ const GValue *gvalp = (const GValue *)g_hash_table_lookup (mAttrs,
prop);
+
+ *_retval = spec || gvalp;
+ return NS_OK;
}
/* unsigned long getAttributeCount (); */
NS_IMETHODIMP
xgGtkElement::GetAttributeCount (PRUint32 *_retval)
{
- XG_RETURN_NOT_IMPLEMENTED;
+ EnsureKeys ();
+ *_retval = g_list_length (mKeys);
+ return NS_OK;
}
/* nsIAtom getAttributeNameAt (in unsigned long index); */
NS_IMETHODIMP
xgGtkElement::GetAttributeNameAt (PRUint32 index, nsIAtom **_retval)
{
- XG_RETURN_NOT_IMPLEMENTED;
+ EnsureKeys ();
+ const char *key = (const char *)g_list_nth_data (mKeys, index);
+ if (!key) {
+ return NS_ERROR_INVALID_ARG;
+ }
+
+ nsresult rv;
+ nsCOMPtr<nsIAtomService> as (do_GetService (NS_ATOMSERVICE_CONTRACTID,
&rv));
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ return as->GetAtomUTF8 (key, _retval);
}
Modified: trunk/gom/xulapp/components/gom/src/xgGtkElement.h
==============================================================================
--- trunk/gom/xulapp/components/gom/src/xgGtkElement.h (original)
+++ trunk/gom/xulapp/components/gom/src/xgGtkElement.h Wed Aug 27 00:33:09
2008
@@ -50,10 +50,14 @@
~xgGtkElement();
protected:
+ void AttrsModified ();
+ void EnsureKeys ();
+
GType mType;
GObject *mObject;
nsCOMPtr<nsIXTFElementWrapper> mWrapper;
GHashTable *mAttrs;
+ GList *mKeys;
};
#endif // XG_GTK_ELEMENT_H