Re-add. Wasn't meant to be deleted yet.
git-svn-id: svn://10.0.0.236/trunk@41230 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
8fed7652f8
commit
ba3808369f
54
mozilla/content/xul/content/src/nsXULTreeElement.cpp
Normal file
54
mozilla/content/xul/content/src/nsXULTreeElement.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsXULTreeElement.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsXULTreeElement, nsXULElement, nsIDOMXULTreeElement);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULTreeElement::GetDatabase(nsIRDFCompositeDataSource** aDatabase)
|
||||
{
|
||||
NS_PRECONDITION(aDatabase != nsnull, "null ptr");
|
||||
if (! aDatabase)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aDatabase = mDatabase;
|
||||
NS_IF_ADDREF(*aDatabase);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULTreeElement::SetDatabase(nsIRDFCompositeDataSource* aDatabase)
|
||||
{
|
||||
// XXX maybe someday you'll be allowed to change it.
|
||||
NS_PRECONDITION(mDatabase == nsnull, "already initialized");
|
||||
if (mDatabase)
|
||||
return NS_ERROR_ALREADY_INITIALIZED;
|
||||
|
||||
mDatabase = aDatabase;
|
||||
|
||||
// XXX reconstruct the entire tree now!
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
55
mozilla/content/xul/content/src/nsXULTreeElement.h
Normal file
55
mozilla/content/xul/content/src/nsXULTreeElement.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsXULTreeElement_h__
|
||||
#define nsXULTreeElement_h__
|
||||
|
||||
#include "nsXULElement.h"
|
||||
#include "nsIDOMXULTreeElement.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
|
||||
class nsXULTreeElement : public nsXULElement,
|
||||
public nsIDOMXULTreeElement
|
||||
{
|
||||
private:
|
||||
nsCOMPtr<nsIRDFCompositeDataSource> mDatabase;
|
||||
|
||||
public:
|
||||
nsXULTreeElement(nsIDOMXULElement* aOuter)
|
||||
: nsXULElement(aOuter)
|
||||
{
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNode interface
|
||||
NS_FORWARD_IDOMNODE(mOuter->);
|
||||
|
||||
// nsIDOMElement interface
|
||||
NS_FORWARD_IDOMELEMENT(mOuter->);
|
||||
|
||||
// nsIDOMXULElement interface
|
||||
NS_FORWARD_IDOMXULELEMENT(mOuter->);
|
||||
|
||||
// nsIDOMXULTreeElement interface
|
||||
NS_DECL_IDOMXULTREEELEMENT
|
||||
};
|
||||
|
||||
|
||||
#endif // nsXULTreeElement_h__
|
||||
58
mozilla/dom/public/xul/nsIDOMXULTreeElement.h
Normal file
58
mozilla/dom/public/xul/nsIDOMXULTreeElement.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
/* AUTO-GENERATED. DO NOT EDIT!!! */
|
||||
|
||||
#ifndef nsIDOMXULTreeElement_h__
|
||||
#define nsIDOMXULTreeElement_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIDOMXULElement.h"
|
||||
|
||||
class nsIRDFCompositeDataSource;
|
||||
|
||||
#define NS_IDOMXULTREEELEMENT_IID \
|
||||
{ 0xa6cf90ec, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
class nsIDOMXULTreeElement : public nsIDOMXULElement {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULTREEELEMENT_IID; return iid; }
|
||||
|
||||
NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase)=0;
|
||||
NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase)=0;
|
||||
};
|
||||
|
||||
|
||||
#define NS_DECL_IDOMXULTREEELEMENT \
|
||||
NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase); \
|
||||
NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMXULTREEELEMENT(_to) \
|
||||
NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase) { return _to GetDatabase(aDatabase); } \
|
||||
NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase) { return _to SetDatabase(aDatabase); } \
|
||||
|
||||
|
||||
extern "C" NS_DOM nsresult NS_InitXULTreeElementClass(nsIScriptContext *aContext, void **aPrototype);
|
||||
|
||||
extern "C" NS_DOM nsresult NS_NewScriptXULTreeElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
|
||||
|
||||
#endif // nsIDOMXULTreeElement_h__
|
||||
328
mozilla/dom/src/xul/nsJSXULTreeElement.cpp
Normal file
328
mozilla/dom/src/xul/nsJSXULTreeElement.cpp
Normal file
@ -0,0 +1,328 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
/* AUTO-GENERATED. DO NOT EDIT!!! */
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIJSScriptObject.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIDOMXULTreeElement.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIRDFCompositeDataSourceIID, NS_IRDFCOMPOSITEDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIXULTreeElementIID, NS_IDOMXULTREEELEMENT_IID);
|
||||
|
||||
NS_DEF_PTR(nsIRDFCompositeDataSource);
|
||||
NS_DEF_PTR(nsIDOMXULTreeElement);
|
||||
|
||||
//
|
||||
// XULTreeElement property ids
|
||||
//
|
||||
enum XULTreeElement_slots {
|
||||
XULTREEELEMENT_DATABASE = -1
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// XULTreeElement Properties Getter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMXULTreeElement *a = (nsIDOMXULTreeElement*)JS_GetPrivate(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
PRBool ok;
|
||||
if (NS_OK != scriptCX->GetSecurityManager(&secMan)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case XULTREEELEMENT_DATABASE:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.database", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (NS_OK == a->GetDatabase(&prop)) {
|
||||
// get the js object; n.b., this will do a release on 'prop'
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// XULTreeElement Properties Setter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
SetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMXULTreeElement *a = (nsIDOMXULTreeElement*)JS_GetPrivate(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
PRBool ok;
|
||||
if (NS_OK != scriptCX->GetSecurityManager(&secMan)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case XULTREEELEMENT_DATABASE:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.database", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop,
|
||||
kIRDFCompositeDataSourceIID, cx, *vp)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
a->SetDatabase(prop);
|
||||
NS_IF_RELEASE(prop);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement finalizer
|
||||
//
|
||||
PR_STATIC_CALLBACK(void)
|
||||
FinalizeXULTreeElement(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
nsJSUtils::nsGenericFinalize(cx, obj);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement enumerate
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
EnumerateXULTreeElement(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
return nsJSUtils::nsGenericEnumerate(cx, obj);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement resolve
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
ResolveXULTreeElement(JSContext *cx, JSObject *obj, jsval id)
|
||||
{
|
||||
return nsJSUtils::nsGenericResolve(cx, obj, id);
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// class for XULTreeElement
|
||||
//
|
||||
JSClass XULTreeElementClass = {
|
||||
"XULTreeElement",
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetXULTreeElementProperty,
|
||||
SetXULTreeElementProperty,
|
||||
EnumerateXULTreeElement,
|
||||
ResolveXULTreeElement,
|
||||
JS_ConvertStub,
|
||||
FinalizeXULTreeElement
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement class properties
|
||||
//
|
||||
static JSPropertySpec XULTreeElementProperties[] =
|
||||
{
|
||||
{"database", XULTREEELEMENT_DATABASE, JSPROP_ENUMERATE},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement class methods
|
||||
//
|
||||
static JSFunctionSpec XULTreeElementMethods[] =
|
||||
{
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement constructor
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
XULTreeElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement class initialization
|
||||
//
|
||||
extern "C" NS_DOM nsresult NS_InitXULTreeElementClass(nsIScriptContext *aContext, void **aPrototype)
|
||||
{
|
||||
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
|
||||
JSObject *proto = nsnull;
|
||||
JSObject *constructor = nsnull;
|
||||
JSObject *parent_proto = nsnull;
|
||||
JSObject *global = JS_GetGlobalObject(jscontext);
|
||||
jsval vp;
|
||||
|
||||
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "XULTreeElement", &vp)) ||
|
||||
!JSVAL_IS_OBJECT(vp) ||
|
||||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
|
||||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
|
||||
!JSVAL_IS_OBJECT(vp)) {
|
||||
|
||||
if (NS_OK != NS_InitXULElementClass(aContext, (void **)&parent_proto)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
proto = JS_InitClass(jscontext, // context
|
||||
global, // global object
|
||||
parent_proto, // parent proto
|
||||
&XULTreeElementClass, // JSClass
|
||||
XULTreeElement, // JSNative ctor
|
||||
0, // ctor args
|
||||
XULTreeElementProperties, // proto props
|
||||
XULTreeElementMethods, // proto funcs
|
||||
nsnull, // ctor props (static)
|
||||
nsnull); // ctor funcs (static)
|
||||
if (nsnull == proto) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
|
||||
proto = JSVAL_TO_OBJECT(vp);
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (aPrototype) {
|
||||
*aPrototype = proto;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Method for creating a new XULTreeElement JavaScript object
|
||||
//
|
||||
extern "C" NS_DOM nsresult NS_NewScriptXULTreeElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptXULTreeElement");
|
||||
JSObject *proto;
|
||||
JSObject *parent;
|
||||
nsIScriptObjectOwner *owner;
|
||||
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
|
||||
nsresult result = NS_OK;
|
||||
nsIDOMXULTreeElement *aXULTreeElement;
|
||||
|
||||
if (nsnull == aParent) {
|
||||
parent = nsnull;
|
||||
}
|
||||
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
|
||||
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
|
||||
NS_RELEASE(owner);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
NS_RELEASE(owner);
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (NS_OK != NS_InitXULTreeElementClass(aContext, (void **)&proto)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
result = aSupports->QueryInterface(kIXULTreeElementIID, (void **)&aXULTreeElement);
|
||||
if (NS_OK != result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// create a js object for this class
|
||||
*aReturn = JS_NewObject(jscontext, &XULTreeElementClass, proto, parent);
|
||||
if (nsnull != *aReturn) {
|
||||
// connect the native object to the js object
|
||||
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aXULTreeElement);
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(aXULTreeElement);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
58
mozilla/rdf/content/public/nsIDOMXULTreeElement.h
Normal file
58
mozilla/rdf/content/public/nsIDOMXULTreeElement.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
/* AUTO-GENERATED. DO NOT EDIT!!! */
|
||||
|
||||
#ifndef nsIDOMXULTreeElement_h__
|
||||
#define nsIDOMXULTreeElement_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIDOMXULElement.h"
|
||||
|
||||
class nsIRDFCompositeDataSource;
|
||||
|
||||
#define NS_IDOMXULTREEELEMENT_IID \
|
||||
{ 0xa6cf90ec, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
class nsIDOMXULTreeElement : public nsIDOMXULElement {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULTREEELEMENT_IID; return iid; }
|
||||
|
||||
NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase)=0;
|
||||
NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase)=0;
|
||||
};
|
||||
|
||||
|
||||
#define NS_DECL_IDOMXULTREEELEMENT \
|
||||
NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase); \
|
||||
NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMXULTREEELEMENT(_to) \
|
||||
NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase) { return _to GetDatabase(aDatabase); } \
|
||||
NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase) { return _to SetDatabase(aDatabase); } \
|
||||
|
||||
|
||||
extern "C" NS_DOM nsresult NS_InitXULTreeElementClass(nsIScriptContext *aContext, void **aPrototype);
|
||||
|
||||
extern "C" NS_DOM nsresult NS_NewScriptXULTreeElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
|
||||
|
||||
#endif // nsIDOMXULTreeElement_h__
|
||||
328
mozilla/rdf/content/src/nsJSXULTreeElement.cpp
Normal file
328
mozilla/rdf/content/src/nsJSXULTreeElement.cpp
Normal file
@ -0,0 +1,328 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
/* AUTO-GENERATED. DO NOT EDIT!!! */
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIJSScriptObject.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIDOMXULTreeElement.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIRDFCompositeDataSourceIID, NS_IRDFCOMPOSITEDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIXULTreeElementIID, NS_IDOMXULTREEELEMENT_IID);
|
||||
|
||||
NS_DEF_PTR(nsIRDFCompositeDataSource);
|
||||
NS_DEF_PTR(nsIDOMXULTreeElement);
|
||||
|
||||
//
|
||||
// XULTreeElement property ids
|
||||
//
|
||||
enum XULTreeElement_slots {
|
||||
XULTREEELEMENT_DATABASE = -1
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// XULTreeElement Properties Getter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMXULTreeElement *a = (nsIDOMXULTreeElement*)JS_GetPrivate(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
PRBool ok;
|
||||
if (NS_OK != scriptCX->GetSecurityManager(&secMan)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case XULTREEELEMENT_DATABASE:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.database", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (NS_OK == a->GetDatabase(&prop)) {
|
||||
// get the js object; n.b., this will do a release on 'prop'
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// XULTreeElement Properties Setter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
SetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMXULTreeElement *a = (nsIDOMXULTreeElement*)JS_GetPrivate(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
PRBool ok;
|
||||
if (NS_OK != scriptCX->GetSecurityManager(&secMan)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case XULTREEELEMENT_DATABASE:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.database", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop,
|
||||
kIRDFCompositeDataSourceIID, cx, *vp)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
a->SetDatabase(prop);
|
||||
NS_IF_RELEASE(prop);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement finalizer
|
||||
//
|
||||
PR_STATIC_CALLBACK(void)
|
||||
FinalizeXULTreeElement(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
nsJSUtils::nsGenericFinalize(cx, obj);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement enumerate
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
EnumerateXULTreeElement(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
return nsJSUtils::nsGenericEnumerate(cx, obj);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement resolve
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
ResolveXULTreeElement(JSContext *cx, JSObject *obj, jsval id)
|
||||
{
|
||||
return nsJSUtils::nsGenericResolve(cx, obj, id);
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// class for XULTreeElement
|
||||
//
|
||||
JSClass XULTreeElementClass = {
|
||||
"XULTreeElement",
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetXULTreeElementProperty,
|
||||
SetXULTreeElementProperty,
|
||||
EnumerateXULTreeElement,
|
||||
ResolveXULTreeElement,
|
||||
JS_ConvertStub,
|
||||
FinalizeXULTreeElement
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement class properties
|
||||
//
|
||||
static JSPropertySpec XULTreeElementProperties[] =
|
||||
{
|
||||
{"database", XULTREEELEMENT_DATABASE, JSPROP_ENUMERATE},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement class methods
|
||||
//
|
||||
static JSFunctionSpec XULTreeElementMethods[] =
|
||||
{
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement constructor
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
XULTreeElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// XULTreeElement class initialization
|
||||
//
|
||||
extern "C" NS_DOM nsresult NS_InitXULTreeElementClass(nsIScriptContext *aContext, void **aPrototype)
|
||||
{
|
||||
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
|
||||
JSObject *proto = nsnull;
|
||||
JSObject *constructor = nsnull;
|
||||
JSObject *parent_proto = nsnull;
|
||||
JSObject *global = JS_GetGlobalObject(jscontext);
|
||||
jsval vp;
|
||||
|
||||
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "XULTreeElement", &vp)) ||
|
||||
!JSVAL_IS_OBJECT(vp) ||
|
||||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
|
||||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
|
||||
!JSVAL_IS_OBJECT(vp)) {
|
||||
|
||||
if (NS_OK != NS_InitXULElementClass(aContext, (void **)&parent_proto)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
proto = JS_InitClass(jscontext, // context
|
||||
global, // global object
|
||||
parent_proto, // parent proto
|
||||
&XULTreeElementClass, // JSClass
|
||||
XULTreeElement, // JSNative ctor
|
||||
0, // ctor args
|
||||
XULTreeElementProperties, // proto props
|
||||
XULTreeElementMethods, // proto funcs
|
||||
nsnull, // ctor props (static)
|
||||
nsnull); // ctor funcs (static)
|
||||
if (nsnull == proto) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
|
||||
proto = JSVAL_TO_OBJECT(vp);
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (aPrototype) {
|
||||
*aPrototype = proto;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Method for creating a new XULTreeElement JavaScript object
|
||||
//
|
||||
extern "C" NS_DOM nsresult NS_NewScriptXULTreeElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptXULTreeElement");
|
||||
JSObject *proto;
|
||||
JSObject *parent;
|
||||
nsIScriptObjectOwner *owner;
|
||||
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
|
||||
nsresult result = NS_OK;
|
||||
nsIDOMXULTreeElement *aXULTreeElement;
|
||||
|
||||
if (nsnull == aParent) {
|
||||
parent = nsnull;
|
||||
}
|
||||
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
|
||||
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
|
||||
NS_RELEASE(owner);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
NS_RELEASE(owner);
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (NS_OK != NS_InitXULTreeElementClass(aContext, (void **)&proto)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
result = aSupports->QueryInterface(kIXULTreeElementIID, (void **)&aXULTreeElement);
|
||||
if (NS_OK != result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// create a js object for this class
|
||||
*aReturn = JS_NewObject(jscontext, &XULTreeElementClass, proto, parent);
|
||||
if (nsnull != *aReturn) {
|
||||
// connect the native object to the js object
|
||||
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aXULTreeElement);
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(aXULTreeElement);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
447
mozilla/rdf/content/src/nsRDFMenuBuilder.cpp
Normal file
447
mozilla/rdf/content/src/nsRDFMenuBuilder.cpp
Normal file
@ -0,0 +1,447 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMElementObserver.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMNodeObserver.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFObserver.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsRDFContentUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "rdf.h"
|
||||
#include "rdfutil.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#include "nsRDFGenericBuilder.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
||||
static NS_DEFINE_IID(kIRDFContentModelBuilderIID, NS_IRDFCONTENTMODELBUILDER_IID);
|
||||
static NS_DEFINE_IID(kIRDFObserverIID, NS_IRDFOBSERVER_IID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class RDFMenuBuilderImpl : public RDFGenericBuilderImpl
|
||||
{
|
||||
public:
|
||||
RDFMenuBuilderImpl();
|
||||
virtual ~RDFMenuBuilderImpl();
|
||||
|
||||
// Implementation methods
|
||||
nsresult
|
||||
AddWidgetItem(nsIContent* aMenuItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFResource* aValue, PRInt32 aNaturalOrderPos);
|
||||
|
||||
nsresult
|
||||
RemoveWidgetItem(nsIContent* aMenuItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFResource* aValue);
|
||||
|
||||
nsresult
|
||||
SetWidgetAttribute(nsIContent* aMenuItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aValue);
|
||||
|
||||
nsresult
|
||||
UnsetWidgetAttribute(nsIContent* aMenuItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aValue);
|
||||
|
||||
nsresult
|
||||
GetRootWidgetAtom(nsIAtom** aResult) {
|
||||
NS_ADDREF(kMenuAtom);
|
||||
*aResult = kMenuAtom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetWidgetItemAtom(nsIAtom** aResult) {
|
||||
NS_ADDREF(kMenuItemAtom);
|
||||
*aResult = kMenuItemAtom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetWidgetFolderAtom(nsIAtom** aResult) {
|
||||
NS_ADDREF(kMenuAtom);
|
||||
*aResult = kMenuAtom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetInsertionRootAtom(nsIAtom** aResult) {
|
||||
NS_ADDREF(kMenuAtom);
|
||||
*aResult = kMenuAtom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetItemAtomThatContainsTheChildren(nsIAtom** aResult) {
|
||||
NS_ADDREF(kMenuAtom);
|
||||
*aResult = kMenuAtom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
Notify(nsITimer *timer);
|
||||
|
||||
// pseudo-constants
|
||||
static nsrefcnt gRefCnt;
|
||||
|
||||
static nsIAtom* kMenuBarAtom;
|
||||
static nsIAtom* kMenuAtom;
|
||||
static nsIAtom* kMenuItemAtom;
|
||||
static nsIAtom* kNameAtom;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsrefcnt RDFMenuBuilderImpl::gRefCnt = 0;
|
||||
|
||||
nsIAtom* RDFMenuBuilderImpl::kMenuAtom;
|
||||
nsIAtom* RDFMenuBuilderImpl::kMenuItemAtom;
|
||||
nsIAtom* RDFMenuBuilderImpl::kMenuBarAtom;
|
||||
nsIAtom* RDFMenuBuilderImpl::kNameAtom;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewRDFMenuBuilder(nsIRDFContentModelBuilder** result)
|
||||
{
|
||||
NS_PRECONDITION(result != nsnull, "null ptr");
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
RDFMenuBuilderImpl* builder = new RDFMenuBuilderImpl();
|
||||
if (! builder)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(builder);
|
||||
*result = builder;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDFMenuBuilderImpl::RDFMenuBuilderImpl(void)
|
||||
: RDFGenericBuilderImpl()
|
||||
{
|
||||
if (gRefCnt == 0) {
|
||||
kMenuAtom = NS_NewAtom("menu");
|
||||
kMenuItemAtom = NS_NewAtom("menuitem");
|
||||
kMenuBarAtom = NS_NewAtom("menubar");
|
||||
kNameAtom = NS_NewAtom("name");
|
||||
}
|
||||
|
||||
++gRefCnt;
|
||||
}
|
||||
|
||||
RDFMenuBuilderImpl::~RDFMenuBuilderImpl(void)
|
||||
{
|
||||
--gRefCnt;
|
||||
if (gRefCnt == 0) {
|
||||
NS_RELEASE(kMenuAtom);
|
||||
NS_RELEASE(kMenuItemAtom);
|
||||
NS_RELEASE(kMenuBarAtom);
|
||||
NS_RELEASE(kNameAtom);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RDFMenuBuilderImpl::Notify(nsITimer *timer)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Implementation methods
|
||||
|
||||
nsresult
|
||||
RDFMenuBuilderImpl::AddWidgetItem(nsIContent* aElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFResource* aValue,
|
||||
PRInt32 naturalOrderPos)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIContent> menuParent;
|
||||
menuParent = dont_QueryInterface(aElement);
|
||||
if (!IsItemOrFolder(aElement) && !IsWidgetInsertionRootElement(aElement))
|
||||
{
|
||||
NS_ERROR("Can't add something here!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// Find out if we're a container or not.
|
||||
PRBool markAsContainer = IsContainer(aElement, aValue) && !IsEmpty(aElement, aValue);
|
||||
nsCOMPtr<nsIAtom> itemAtom;
|
||||
|
||||
// Figure out what atom to use based on whether or not we're a container
|
||||
// or leaf
|
||||
if (markAsContainer)
|
||||
{
|
||||
// We're a menu element
|
||||
GetWidgetFolderAtom(getter_AddRefs(itemAtom));
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're a menuitem element
|
||||
GetWidgetItemAtom(getter_AddRefs(itemAtom));
|
||||
}
|
||||
|
||||
// Create the <xul:menuitem> element
|
||||
nsCOMPtr<nsIContent> menuItem;
|
||||
if (NS_FAILED(rv = CreateElement(kNameSpaceID_XUL,
|
||||
itemAtom,
|
||||
aValue,
|
||||
getter_AddRefs(menuItem))))
|
||||
return rv;
|
||||
|
||||
// Add the new menu item to the <xul:menu> element.
|
||||
menuParent->AppendChildTo(menuItem, PR_TRUE);
|
||||
|
||||
// Add miscellaneous attributes by iterating _all_ of the
|
||||
// properties out of the resource.
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
PRBool hasMore;
|
||||
rv = arcs->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = arcs->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// Ignore properties that are used to indicate containment
|
||||
if (IsContainmentProperty(aElement, property))
|
||||
continue;
|
||||
|
||||
// Ignore properties that we have been explicitly _asked_ to
|
||||
// ignore.
|
||||
if (IsIgnoredProperty(aElement, property))
|
||||
continue;
|
||||
|
||||
PRInt32 nameSpaceID;
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)))) {
|
||||
NS_ERROR("unable to split property");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFNode> value;
|
||||
if (NS_FAILED(rv = mDB->GetTarget(aValue, property, PR_TRUE, getter_AddRefs(value)))) {
|
||||
NS_ERROR("unable to get target");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// ArcsLabelsOut is allowed to be promiscuous, giving back
|
||||
// potential arc labels that may not currently have a value.
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
continue;
|
||||
|
||||
nsAutoString s;
|
||||
rv = nsRDFContentUtils::GetTextForNode(value, s);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = menuItem->SetAttribute(nameSpaceID, tag, s, PR_FALSE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// XXX This should go away and just be determined dynamically;
|
||||
// e.g., by setting an attribute on the "xul:menu" tag
|
||||
nsAutoString tagStr;
|
||||
tag->ToString(tagStr);
|
||||
if (tagStr.EqualsIgnoreCase("name")) {
|
||||
// Hack to ensure that we add in a lowercase name attribute also.
|
||||
menuItem->SetAttribute(kNameSpaceID_None, kNameAtom, s, PR_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: This is a hack until the menu folks get their act together.
|
||||
menuItem->SetAttribute(kNameSpaceID_None, kOpenAtom, "true", PR_FALSE);
|
||||
|
||||
// Finally, mark this as a "container" so that we know to
|
||||
// recursively generate kids if they're asked for.
|
||||
if (markAsContainer == PR_TRUE)
|
||||
{
|
||||
// Finally, mark this as a "container" so that we know to
|
||||
// recursively generate kids if they're asked for.
|
||||
if (NS_FAILED(rv = menuItem->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE)))
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
RDFMenuBuilderImpl::RemoveWidgetItem(nsIContent* aMenuItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFResource* aValue)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Find the doomed kid and blow it away.
|
||||
PRInt32 count;
|
||||
if (NS_FAILED(rv = aMenuItemElement->ChildCount(count)))
|
||||
return rv;
|
||||
|
||||
for (PRInt32 i = 0; i < count; ++i) {
|
||||
nsCOMPtr<nsIContent> kid;
|
||||
rv = aMenuItemElement->ChildAt(i, *getter_AddRefs(kid));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Make sure it's a <xul:menu> or <xul:menuitem>
|
||||
PRInt32 nameSpaceID;
|
||||
rv = kid->GetNameSpaceID(nameSpaceID);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (nameSpaceID != kNameSpaceID_XUL)
|
||||
continue; // wrong namespace
|
||||
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
rv = kid->GetTag(*getter_AddRefs(tag));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if ((tag.get() != kMenuItemAtom) &&
|
||||
(tag.get() != kMenuAtom))
|
||||
continue; // wrong tag
|
||||
|
||||
// Now get the resource ID from the RDF:ID attribute. We do it
|
||||
// via the content model, because you're never sure who
|
||||
// might've added this stuff in...
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
rv = nsRDFContentUtils::GetElementRefResource(kid, getter_AddRefs(resource));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving resource");
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
|
||||
if (resource.get() != aValue)
|
||||
continue; // not the resource we want
|
||||
|
||||
// Fount it! Now kill it.
|
||||
rv = aMenuItemElement->RemoveChildAt(i, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove xul:menu[item] from xul:menu");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX make this a warning
|
||||
NS_WARNING("unable to find child to remove");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
RDFMenuBuilderImpl::SetWidgetAttribute(nsIContent* aMenuItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aValue)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 nameSpaceID;
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
rv = mDocument->SplitProperty(aProperty, &nameSpaceID, getter_AddRefs(tag));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString value;
|
||||
rv = nsRDFContentUtils::GetTextForNode(aValue, value);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aMenuItemElement->SetAttribute(nameSpaceID, tag, value, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// XXX This should go away and just be determined dynamically;
|
||||
// e.g., by setting an attribute on the "xul:menu" tag.
|
||||
nsAutoString tagStr;
|
||||
tag->ToString(tagStr);
|
||||
if (tagStr.EqualsIgnoreCase("name")) {
|
||||
// Hack to ensure that we add in a lowercase name attribute also.
|
||||
aMenuItemElement->SetAttribute(kNameSpaceID_None, kNameAtom, value, PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
RDFMenuBuilderImpl::UnsetWidgetAttribute(nsIContent* aMenuItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aValue)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 nameSpaceID;
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
rv = mDocument->SplitProperty(aProperty, &nameSpaceID, getter_AddRefs(tag));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aMenuItemElement->UnsetAttribute(nameSpaceID, tag, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// XXX This should go away and just be determined dynamically;
|
||||
// e.g., by setting an attribute on the "xul:menu" tag.
|
||||
nsAutoString tagStr;
|
||||
tag->ToString(tagStr);
|
||||
if (tagStr.EqualsIgnoreCase("name")) {
|
||||
// Hack to ensure that we add in a lowercase name attribute also.
|
||||
aMenuItemElement->UnsetAttribute(kNameSpaceID_None, kNameAtom, PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
441
mozilla/rdf/content/src/nsRDFToolbarBuilder.cpp
Normal file
441
mozilla/rdf/content/src/nsRDFToolbarBuilder.cpp
Normal file
@ -0,0 +1,441 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
/* XXX: Teach this how to make toolboxes as well as toolbars. */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMElementObserver.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMNodeObserver.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFObserver.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsRDFContentUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "rdf.h"
|
||||
#include "rdfutil.h"
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#include "nsRDFGenericBuilder.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
||||
static NS_DEFINE_IID(kIRDFContentModelBuilderIID, NS_IRDFCONTENTMODELBUILDER_IID);
|
||||
static NS_DEFINE_IID(kIRDFObserverIID, NS_IRDFOBSERVER_IID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class RDFToolbarBuilderImpl : public RDFGenericBuilderImpl
|
||||
{
|
||||
public:
|
||||
RDFToolbarBuilderImpl();
|
||||
virtual ~RDFToolbarBuilderImpl();
|
||||
|
||||
// Implementation methods
|
||||
nsresult
|
||||
AddWidgetItem(nsIContent* aToolbarItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFResource* aValue, PRInt32 aNaturalOrderPos);
|
||||
|
||||
nsresult
|
||||
RemoveWidgetItem(nsIContent* aTreeItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFResource* aValue);
|
||||
|
||||
nsresult
|
||||
SetWidgetAttribute(nsIContent* aToolbarItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aValue);
|
||||
|
||||
nsresult
|
||||
UnsetWidgetAttribute(nsIContent* aToolbarItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aValue);
|
||||
|
||||
nsresult
|
||||
GetRootWidgetAtom(nsIAtom** aResult) {
|
||||
NS_ADDREF(kToolbarAtom);
|
||||
*aResult = kToolbarAtom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetWidgetItemAtom(nsIAtom** aResult) {
|
||||
NS_ADDREF(kTitledButtonAtom);
|
||||
*aResult = kTitledButtonAtom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetWidgetFolderAtom(nsIAtom** aResult) {
|
||||
NS_ADDREF(kTitledButtonAtom);
|
||||
*aResult = kTitledButtonAtom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetInsertionRootAtom(nsIAtom** aResult) {
|
||||
NS_ADDREF(kToolbarAtom);
|
||||
*aResult = kToolbarAtom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetItemAtomThatContainsTheChildren(nsIAtom** aResult) {
|
||||
NS_ADDREF(kTitledButtonAtom);
|
||||
*aResult = kTitledButtonAtom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
Notify(nsITimer *timer);
|
||||
|
||||
// pseudo-constants
|
||||
static nsrefcnt gRefCnt;
|
||||
|
||||
static nsIAtom* kToolbarAtom;
|
||||
static nsIAtom* kTitledButtonAtom;
|
||||
static nsIAtom* kAlignAtom;
|
||||
static nsIAtom* kSrcAtom;
|
||||
static nsIAtom* kValueAtom;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsrefcnt RDFToolbarBuilderImpl::gRefCnt = 0;
|
||||
|
||||
nsIAtom* RDFToolbarBuilderImpl::kToolbarAtom;
|
||||
nsIAtom* RDFToolbarBuilderImpl::kTitledButtonAtom;
|
||||
nsIAtom* RDFToolbarBuilderImpl::kAlignAtom;
|
||||
nsIAtom* RDFToolbarBuilderImpl::kSrcAtom;
|
||||
nsIAtom* RDFToolbarBuilderImpl::kValueAtom;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewRDFToolbarBuilder(nsIRDFContentModelBuilder** result)
|
||||
{
|
||||
NS_PRECONDITION(result != nsnull, "null ptr");
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
RDFToolbarBuilderImpl* builder = new RDFToolbarBuilderImpl();
|
||||
if (! builder)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(builder);
|
||||
*result = builder;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDFToolbarBuilderImpl::RDFToolbarBuilderImpl(void)
|
||||
: RDFGenericBuilderImpl()
|
||||
{
|
||||
if (gRefCnt == 0) {
|
||||
kToolbarAtom = NS_NewAtom("toolbar");
|
||||
kTitledButtonAtom = NS_NewAtom("titledbutton");
|
||||
kAlignAtom = NS_NewAtom("align");
|
||||
kSrcAtom = NS_NewAtom("src");
|
||||
kValueAtom = NS_NewAtom("value");
|
||||
}
|
||||
|
||||
++gRefCnt;
|
||||
}
|
||||
|
||||
RDFToolbarBuilderImpl::~RDFToolbarBuilderImpl(void)
|
||||
{
|
||||
--gRefCnt;
|
||||
if (gRefCnt == 0) {
|
||||
|
||||
NS_RELEASE(kToolbarAtom);
|
||||
NS_RELEASE(kTitledButtonAtom);
|
||||
NS_RELEASE(kAlignAtom);
|
||||
NS_RELEASE(kSrcAtom);
|
||||
NS_RELEASE(kValueAtom);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RDFToolbarBuilderImpl::Notify(nsITimer *timer)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Implementation methods
|
||||
|
||||
nsresult
|
||||
RDFToolbarBuilderImpl::AddWidgetItem(nsIContent* aElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFResource* aValue,
|
||||
PRInt32 naturalOrderPos)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIContent> toolbarParent;
|
||||
toolbarParent = dont_QueryInterface(aElement);
|
||||
if (!IsItemOrFolder(aElement) && !IsWidgetInsertionRootElement(aElement))
|
||||
{
|
||||
NS_ERROR("Can't add something here!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
PRBool markAsContainer = IsContainer(aElement, aValue);
|
||||
|
||||
// Create the <xul:titledbutton> element
|
||||
nsCOMPtr<nsIContent> toolbarItem;
|
||||
if (NS_FAILED(rv = CreateElement(kNameSpaceID_XUL,
|
||||
kTitledButtonAtom,
|
||||
aValue,
|
||||
getter_AddRefs(toolbarItem))))
|
||||
return rv;
|
||||
|
||||
// Add the <xul:titledbutton> to the <xul:toolbar> element.
|
||||
toolbarParent->AppendChildTo(toolbarItem, PR_TRUE);
|
||||
|
||||
// Add miscellaneous attributes by iterating _all_ of the
|
||||
// properties out of the resource.
|
||||
|
||||
// XXX Per Bug 3367, this'll have to be fixed.
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
PRBool hasMore;
|
||||
rv = arcs->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = arcs->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// Ignore properties that are used to indicate containment
|
||||
if (IsContainmentProperty(aElement, property))
|
||||
continue;
|
||||
|
||||
// Ignore properties that we have been explicitly _asked_ to
|
||||
// ignore.
|
||||
if (IsIgnoredProperty(aElement, property))
|
||||
continue;
|
||||
|
||||
PRInt32 nameSpaceID;
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)))) {
|
||||
NS_ERROR("unable to split property");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFNode> value;
|
||||
if (NS_FAILED(rv = mDB->GetTarget(aValue, property, PR_TRUE, getter_AddRefs(value)))) {
|
||||
NS_ERROR("unable to get target");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// ArcsLabelsOut is allowed to be promiscuous, giving back
|
||||
// potential arc labels that may not currently have a value.
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
continue;
|
||||
|
||||
nsAutoString s;
|
||||
rv = nsRDFContentUtils::GetTextForNode(value, s);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
toolbarItem->SetAttribute(nameSpaceID, tag, s, PR_FALSE);
|
||||
|
||||
nsString tagStr;
|
||||
tag->ToString(tagStr);
|
||||
if (tagStr.EqualsIgnoreCase("name")) {
|
||||
// Hack to ensure that we add in a lowercase value attribute also.
|
||||
toolbarItem->SetAttribute(kNameSpaceID_None, kValueAtom, s, PR_FALSE);
|
||||
}
|
||||
|
||||
// XXX (Dave) I want these to go away. Style sheets should be used for these.
|
||||
toolbarItem->SetAttribute(kNameSpaceID_None, kAlignAtom, "right", PR_FALSE);
|
||||
toolbarItem->SetAttribute(kNameSpaceID_None, kSrcAtom, "resource:/res/toolbar/TB_Location.gif", PR_FALSE);
|
||||
}
|
||||
|
||||
// Finally, mark this as a "container" so that we know to
|
||||
// recursively generate kids if they're asked for.
|
||||
if (markAsContainer == PR_TRUE)
|
||||
{
|
||||
// Finally, mark this as a "container" so that we know to
|
||||
// recursively generate kids if they're asked for.
|
||||
if (NS_FAILED(rv = toolbarItem->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE)))
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
RDFToolbarBuilderImpl::RemoveWidgetItem(nsIContent* aToolbarItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFResource* aValue)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Find the doomed kid and blow it away.
|
||||
PRInt32 count;
|
||||
if (NS_FAILED(rv = aToolbarItemElement->ChildCount(count)))
|
||||
return rv;
|
||||
|
||||
for (PRInt32 i = 0; i < count; ++i) {
|
||||
nsCOMPtr<nsIContent> kid;
|
||||
rv = aToolbarItemElement->ChildAt(i, *getter_AddRefs(kid));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Make sure it's a <xul:toolbar> or <xul:titledbutton>
|
||||
PRInt32 nameSpaceID;
|
||||
rv = kid->GetNameSpaceID(nameSpaceID);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (nameSpaceID != kNameSpaceID_XUL)
|
||||
continue; // wrong namespace
|
||||
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
rv = kid->GetTag(*getter_AddRefs(tag));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if ((tag.get() != kTitledButtonAtom) &&
|
||||
(tag.get() != kToolbarAtom))
|
||||
continue; // wrong tag
|
||||
|
||||
// Now get the resource ID from the RDF:ID attribute. We do it
|
||||
// via the content model, because you're never sure who
|
||||
// might've added this stuff in...
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
rv = nsRDFContentUtils::GetElementRefResource(kid, getter_AddRefs(resource));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving resource");
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
|
||||
if (resource.get() != aValue)
|
||||
continue; // not the resource we want
|
||||
|
||||
// Fount it! Now kill it.
|
||||
rv = aToolbarItemElement->RemoveChildAt(i, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove xul:toolbar/titledbutton from xul:toolbar");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX make this a warning
|
||||
NS_WARNING("unable to find child to remove");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
RDFToolbarBuilderImpl::SetWidgetAttribute(nsIContent* aToolbarItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aValue)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 nameSpaceID;
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
rv = mDocument->SplitProperty(aProperty, &nameSpaceID, getter_AddRefs(tag));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString value;
|
||||
rv = nsRDFContentUtils::GetTextForNode(aValue, value);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aToolbarItemElement->SetAttribute(nameSpaceID, tag, value, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// XXX This should go away and just be determined dynamically;
|
||||
// e.g., by setting an attribute on the "xul:menu" tag.
|
||||
nsAutoString tagStr;
|
||||
tag->ToString(tagStr);
|
||||
if (tagStr.EqualsIgnoreCase("name")) {
|
||||
// Hack to ensure that we add in a lowercase name attribute also.
|
||||
aToolbarItemElement->SetAttribute(kNameSpaceID_None, kValueAtom, value, PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
RDFToolbarBuilderImpl::UnsetWidgetAttribute(nsIContent* aToolbarItemElement,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aValue)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 nameSpaceID;
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
rv = mDocument->SplitProperty(aProperty, &nameSpaceID, getter_AddRefs(tag));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aToolbarItemElement->UnsetAttribute(nameSpaceID, tag, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// XXX This should go away and just be determined dynamically;
|
||||
// e.g., by setting an attribute on the "xul:menu" tag.
|
||||
nsAutoString tagStr;
|
||||
tag->ToString(tagStr);
|
||||
if (tagStr.EqualsIgnoreCase("name")) {
|
||||
// Hack to ensure that we add in a lowercase name attribute also.
|
||||
aToolbarItemElement->UnsetAttribute(kNameSpaceID_None, kValueAtom, PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
1796
mozilla/rdf/content/src/nsRDFTreeBuilder.cpp
Normal file
1796
mozilla/rdf/content/src/nsRDFTreeBuilder.cpp
Normal file
File diff suppressed because it is too large
Load Diff
54
mozilla/rdf/content/src/nsXULTreeElement.cpp
Normal file
54
mozilla/rdf/content/src/nsXULTreeElement.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsXULTreeElement.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsXULTreeElement, nsXULElement, nsIDOMXULTreeElement);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULTreeElement::GetDatabase(nsIRDFCompositeDataSource** aDatabase)
|
||||
{
|
||||
NS_PRECONDITION(aDatabase != nsnull, "null ptr");
|
||||
if (! aDatabase)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aDatabase = mDatabase;
|
||||
NS_IF_ADDREF(*aDatabase);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULTreeElement::SetDatabase(nsIRDFCompositeDataSource* aDatabase)
|
||||
{
|
||||
// XXX maybe someday you'll be allowed to change it.
|
||||
NS_PRECONDITION(mDatabase == nsnull, "already initialized");
|
||||
if (mDatabase)
|
||||
return NS_ERROR_ALREADY_INITIALIZED;
|
||||
|
||||
mDatabase = aDatabase;
|
||||
|
||||
// XXX reconstruct the entire tree now!
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
55
mozilla/rdf/content/src/nsXULTreeElement.h
Normal file
55
mozilla/rdf/content/src/nsXULTreeElement.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsXULTreeElement_h__
|
||||
#define nsXULTreeElement_h__
|
||||
|
||||
#include "nsXULElement.h"
|
||||
#include "nsIDOMXULTreeElement.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
|
||||
class nsXULTreeElement : public nsXULElement,
|
||||
public nsIDOMXULTreeElement
|
||||
{
|
||||
private:
|
||||
nsCOMPtr<nsIRDFCompositeDataSource> mDatabase;
|
||||
|
||||
public:
|
||||
nsXULTreeElement(nsIDOMXULElement* aOuter)
|
||||
: nsXULElement(aOuter)
|
||||
{
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNode interface
|
||||
NS_FORWARD_IDOMNODE(mOuter->);
|
||||
|
||||
// nsIDOMElement interface
|
||||
NS_FORWARD_IDOMELEMENT(mOuter->);
|
||||
|
||||
// nsIDOMXULElement interface
|
||||
NS_FORWARD_IDOMXULELEMENT(mOuter->);
|
||||
|
||||
// nsIDOMXULTreeElement interface
|
||||
NS_DECL_IDOMXULTREEELEMENT
|
||||
};
|
||||
|
||||
|
||||
#endif // nsXULTreeElement_h__
|
||||
Loading…
x
Reference in New Issue
Block a user