зеркало из https://github.com/mozilla/pjs.git
Added support for document.popup, so that event handlers in popup content
can refer to the popup's originating element.
This commit is contained in:
Родитель
19df6b9fc3
Коммит
e79a5b7f9e
|
@ -222,6 +222,8 @@ XULPopupListenerImpl::LaunchPopup(nsIDOMEvent* anEvent)
|
|||
nsString popupAlignment("topleft");
|
||||
element->GetAttribute("popupalign", popupAlignment);
|
||||
|
||||
// Set the popup in the document for the duration of this call.
|
||||
xulDocument->SetPopup(element);
|
||||
if (anchorAlignment == "") {
|
||||
// We aren't anchored. Create on the point.
|
||||
// Retrieve our x and y position.
|
||||
|
@ -239,6 +241,7 @@ XULPopupListenerImpl::LaunchPopup(nsIDOMEvent* anEvent)
|
|||
domWindow->CreateAnchoredPopup(element, popupContent,
|
||||
anchorAlignment, type, popupAlignment);
|
||||
}
|
||||
xulDocument->SetPopup(nsnull);
|
||||
}
|
||||
NS_RELEASE(global);
|
||||
}
|
||||
|
|
|
@ -746,6 +746,7 @@ protected:
|
|||
nsString mCommand;
|
||||
nsIRDFResource* mFragmentRoot; // [OWNER]
|
||||
nsVoidArray mSubDocuments; // [OWNER] of subelements
|
||||
nsIDOMElement* mPopup; // [OWNER] of this popup element in the doc
|
||||
};
|
||||
|
||||
PRInt32 XULDocumentImpl::gRefCnt = 0;
|
||||
|
@ -781,7 +782,8 @@ XULDocumentImpl::XULDocumentImpl(void)
|
|||
mContentViewerContainer(nsnull),
|
||||
mCommand(""),
|
||||
mFragmentRoot(nsnull),
|
||||
mListenerManager(nsnull)
|
||||
mListenerManager(nsnull),
|
||||
mPopup(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
|
@ -827,6 +829,8 @@ XULDocumentImpl::~XULDocumentImpl()
|
|||
|
||||
NS_IF_RELEASE(mListenerManager);
|
||||
|
||||
NS_IF_RELEASE(mPopup);
|
||||
|
||||
// mParentDocument is never refcounted
|
||||
// Delete references to sub-documents
|
||||
PRInt32 index = mSubDocuments.Count();
|
||||
|
@ -2684,6 +2688,23 @@ XULDocumentImpl::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIDOMXULDocument interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::GetPopup(nsIDOMElement** anElement)
|
||||
{
|
||||
*anElement = mPopup;
|
||||
NS_IF_ADDREF(mPopup);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::SetPopup(nsIDOMElement* anElement)
|
||||
{
|
||||
NS_IF_RELEASE(mPopup);
|
||||
NS_IF_ADDREF(anElement);
|
||||
mPopup = anElement;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,8 @@ interface XULDocument : Document {
|
|||
/* IID: { 0x17ddd8c0, 0xc5f8, 0x11d2, \
|
||||
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */
|
||||
|
||||
Element getElementById(in DOMString id);
|
||||
attribute Element popup;
|
||||
|
||||
Element getElementById(in DOMString id);
|
||||
NodeList getElementsByAttribute(in DOMString name, in DOMString value);
|
||||
};
|
||||
|
|
|
@ -36,6 +36,9 @@ class nsIDOMXULDocument : public nsIDOMDocument {
|
|||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULDOCUMENT_IID; return iid; }
|
||||
|
||||
NS_IMETHOD GetPopup(nsIDOMElement** aPopup)=0;
|
||||
NS_IMETHOD SetPopup(nsIDOMElement* aPopup)=0;
|
||||
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn)=0;
|
||||
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn)=0;
|
||||
|
@ -43,12 +46,16 @@ public:
|
|||
|
||||
|
||||
#define NS_DECL_IDOMXULDOCUMENT \
|
||||
NS_IMETHOD GetPopup(nsIDOMElement** aPopup); \
|
||||
NS_IMETHOD SetPopup(nsIDOMElement* aPopup); \
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn); \
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMXULDOCUMENT(_to) \
|
||||
NS_IMETHOD GetPopup(nsIDOMElement** aPopup) { return _to GetPopup(aPopup); } \
|
||||
NS_IMETHOD SetPopup(nsIDOMElement* aPopup) { return _to SetPopup(aPopup); } \
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn) { return _to GetElementById(aId, aReturn); } \
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn) { return _to GetElementsByAttribute(aName, aValue, aReturn); } \
|
||||
|
||||
|
|
|
@ -42,6 +42,12 @@ NS_DEF_PTR(nsIDOMElement);
|
|||
NS_DEF_PTR(nsIDOMXULDocument);
|
||||
NS_DEF_PTR(nsIDOMNodeList);
|
||||
|
||||
//
|
||||
// XULDocument property ids
|
||||
//
|
||||
enum XULDocument_slots {
|
||||
XULDOCUMENT_POPUP = -1
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
|
@ -59,7 +65,18 @@ GetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case 0:
|
||||
case XULDOCUMENT_POPUP:
|
||||
{
|
||||
nsIDOMElement* prop;
|
||||
if (NS_OK == a->GetPopup(&prop)) {
|
||||
// get the js object
|
||||
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||
}
|
||||
|
@ -87,7 +104,19 @@ SetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case 0:
|
||||
case XULDOCUMENT_POPUP:
|
||||
{
|
||||
nsIDOMElement* prop;
|
||||
if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop,
|
||||
kIElementIID, "Element",
|
||||
cx, *vp)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
a->SetPopup(prop);
|
||||
NS_IF_RELEASE(prop);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
|
||||
}
|
||||
|
@ -213,7 +242,7 @@ XULDocumentGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsva
|
|||
//
|
||||
JSClass XULDocumentClass = {
|
||||
"XULDocument",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetXULDocumentProperty,
|
||||
|
@ -230,6 +259,7 @@ JSClass XULDocumentClass = {
|
|||
//
|
||||
static JSPropertySpec XULDocumentProperties[] =
|
||||
{
|
||||
{"popup", XULDOCUMENT_POPUP, JSPROP_ENUMERATE},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
@ -319,7 +319,7 @@ XULElementGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval
|
|||
//
|
||||
JSClass XULElementClass = {
|
||||
"XULElement",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetXULElementProperty,
|
||||
|
|
|
@ -161,7 +161,7 @@ ResolveXULTreeElement(JSContext *cx, JSObject *obj, jsval id)
|
|||
//
|
||||
JSClass XULTreeElementClass = {
|
||||
"XULTreeElement",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetXULTreeElementProperty,
|
||||
|
|
|
@ -3,7 +3,8 @@ interface XULDocument : Document {
|
|||
/* IID: { 0x17ddd8c0, 0xc5f8, 0x11d2, \
|
||||
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */
|
||||
|
||||
Element getElementById(in DOMString id);
|
||||
attribute Element popup;
|
||||
|
||||
Element getElementById(in DOMString id);
|
||||
NodeList getElementsByAttribute(in DOMString name, in DOMString value);
|
||||
};
|
||||
|
|
|
@ -36,6 +36,9 @@ class nsIDOMXULDocument : public nsIDOMDocument {
|
|||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULDOCUMENT_IID; return iid; }
|
||||
|
||||
NS_IMETHOD GetPopup(nsIDOMElement** aPopup)=0;
|
||||
NS_IMETHOD SetPopup(nsIDOMElement* aPopup)=0;
|
||||
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn)=0;
|
||||
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn)=0;
|
||||
|
@ -43,12 +46,16 @@ public:
|
|||
|
||||
|
||||
#define NS_DECL_IDOMXULDOCUMENT \
|
||||
NS_IMETHOD GetPopup(nsIDOMElement** aPopup); \
|
||||
NS_IMETHOD SetPopup(nsIDOMElement* aPopup); \
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn); \
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMXULDOCUMENT(_to) \
|
||||
NS_IMETHOD GetPopup(nsIDOMElement** aPopup) { return _to GetPopup(aPopup); } \
|
||||
NS_IMETHOD SetPopup(nsIDOMElement* aPopup) { return _to SetPopup(aPopup); } \
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn) { return _to GetElementById(aId, aReturn); } \
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn) { return _to GetElementsByAttribute(aName, aValue, aReturn); } \
|
||||
|
||||
|
|
|
@ -331,7 +331,7 @@ ElementObserverOnRemoveAttributeNode(JSContext *cx, JSObject *obj, uintN argc, j
|
|||
//
|
||||
JSClass ElementObserverClass = {
|
||||
"ElementObserver",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetElementObserverProperty,
|
||||
|
|
|
@ -400,7 +400,7 @@ NodeObserverOnAppendChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
//
|
||||
JSClass NodeObserverClass = {
|
||||
"NodeObserver",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetNodeObserverProperty,
|
||||
|
|
|
@ -42,6 +42,12 @@ NS_DEF_PTR(nsIDOMElement);
|
|||
NS_DEF_PTR(nsIDOMXULDocument);
|
||||
NS_DEF_PTR(nsIDOMNodeList);
|
||||
|
||||
//
|
||||
// XULDocument property ids
|
||||
//
|
||||
enum XULDocument_slots {
|
||||
XULDOCUMENT_POPUP = -1
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
|
@ -59,7 +65,18 @@ GetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case 0:
|
||||
case XULDOCUMENT_POPUP:
|
||||
{
|
||||
nsIDOMElement* prop;
|
||||
if (NS_OK == a->GetPopup(&prop)) {
|
||||
// get the js object
|
||||
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||
}
|
||||
|
@ -87,7 +104,19 @@ SetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case 0:
|
||||
case XULDOCUMENT_POPUP:
|
||||
{
|
||||
nsIDOMElement* prop;
|
||||
if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop,
|
||||
kIElementIID, "Element",
|
||||
cx, *vp)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
a->SetPopup(prop);
|
||||
NS_IF_RELEASE(prop);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
|
||||
}
|
||||
|
@ -213,7 +242,7 @@ XULDocumentGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsva
|
|||
//
|
||||
JSClass XULDocumentClass = {
|
||||
"XULDocument",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetXULDocumentProperty,
|
||||
|
@ -230,6 +259,7 @@ JSClass XULDocumentClass = {
|
|||
//
|
||||
static JSPropertySpec XULDocumentProperties[] =
|
||||
{
|
||||
{"popup", XULDOCUMENT_POPUP, JSPROP_ENUMERATE},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
@ -319,7 +319,7 @@ XULElementGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval
|
|||
//
|
||||
JSClass XULElementClass = {
|
||||
"XULElement",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetXULElementProperty,
|
||||
|
|
|
@ -161,7 +161,7 @@ ResolveXULTreeElement(JSContext *cx, JSObject *obj, jsval id)
|
|||
//
|
||||
JSClass XULTreeElementClass = {
|
||||
"XULTreeElement",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetXULTreeElementProperty,
|
||||
|
|
|
@ -746,6 +746,7 @@ protected:
|
|||
nsString mCommand;
|
||||
nsIRDFResource* mFragmentRoot; // [OWNER]
|
||||
nsVoidArray mSubDocuments; // [OWNER] of subelements
|
||||
nsIDOMElement* mPopup; // [OWNER] of this popup element in the doc
|
||||
};
|
||||
|
||||
PRInt32 XULDocumentImpl::gRefCnt = 0;
|
||||
|
@ -781,7 +782,8 @@ XULDocumentImpl::XULDocumentImpl(void)
|
|||
mContentViewerContainer(nsnull),
|
||||
mCommand(""),
|
||||
mFragmentRoot(nsnull),
|
||||
mListenerManager(nsnull)
|
||||
mListenerManager(nsnull),
|
||||
mPopup(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
|
@ -827,6 +829,8 @@ XULDocumentImpl::~XULDocumentImpl()
|
|||
|
||||
NS_IF_RELEASE(mListenerManager);
|
||||
|
||||
NS_IF_RELEASE(mPopup);
|
||||
|
||||
// mParentDocument is never refcounted
|
||||
// Delete references to sub-documents
|
||||
PRInt32 index = mSubDocuments.Count();
|
||||
|
@ -2684,6 +2688,23 @@ XULDocumentImpl::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIDOMXULDocument interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::GetPopup(nsIDOMElement** anElement)
|
||||
{
|
||||
*anElement = mPopup;
|
||||
NS_IF_ADDREF(mPopup);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::SetPopup(nsIDOMElement* anElement)
|
||||
{
|
||||
NS_IF_RELEASE(mPopup);
|
||||
NS_IF_ADDREF(anElement);
|
||||
mPopup = anElement;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn)
|
||||
{
|
||||
|
|
|
@ -222,6 +222,8 @@ XULPopupListenerImpl::LaunchPopup(nsIDOMEvent* anEvent)
|
|||
nsString popupAlignment("topleft");
|
||||
element->GetAttribute("popupalign", popupAlignment);
|
||||
|
||||
// Set the popup in the document for the duration of this call.
|
||||
xulDocument->SetPopup(element);
|
||||
if (anchorAlignment == "") {
|
||||
// We aren't anchored. Create on the point.
|
||||
// Retrieve our x and y position.
|
||||
|
@ -239,6 +241,7 @@ XULPopupListenerImpl::LaunchPopup(nsIDOMEvent* anEvent)
|
|||
domWindow->CreateAnchoredPopup(element, popupContent,
|
||||
anchorAlignment, type, popupAlignment);
|
||||
}
|
||||
xulDocument->SetPopup(nsnull);
|
||||
}
|
||||
NS_RELEASE(global);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче