mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Adding window.opener, window.focus, window.blur, event.cancelBubble, and modifying window.open
This commit is contained in:
parent
ddd65d40ed
commit
61e4e69ecc
@ -176,6 +176,9 @@ public:
|
||||
NS_IMETHOD GetMetaKey(PRBool* aMetaKey)=0;
|
||||
NS_IMETHOD SetMetaKey(PRBool aMetaKey)=0;
|
||||
|
||||
NS_IMETHOD GetCancelBubble(PRBool* aCancelBubble)=0;
|
||||
NS_IMETHOD SetCancelBubble(PRBool aCancelBubble)=0;
|
||||
|
||||
NS_IMETHOD GetCharCode(PRUint32* aCharCode)=0;
|
||||
NS_IMETHOD SetCharCode(PRUint32 aCharCode)=0;
|
||||
|
||||
@ -208,6 +211,8 @@ public:
|
||||
NS_IMETHOD SetShiftKey(PRBool aShiftKey); \
|
||||
NS_IMETHOD GetMetaKey(PRBool* aMetaKey); \
|
||||
NS_IMETHOD SetMetaKey(PRBool aMetaKey); \
|
||||
NS_IMETHOD GetCancelBubble(PRBool* aCancelBubble); \
|
||||
NS_IMETHOD SetCancelBubble(PRBool aCancelBubble); \
|
||||
NS_IMETHOD GetCharCode(PRUint32* aCharCode); \
|
||||
NS_IMETHOD SetCharCode(PRUint32 aCharCode); \
|
||||
NS_IMETHOD GetKeyCode(PRUint32* aKeyCode); \
|
||||
@ -238,6 +243,8 @@ public:
|
||||
NS_IMETHOD SetShiftKey(PRBool aShiftKey) { return _to##SetShiftKey(aShiftKey); } \
|
||||
NS_IMETHOD GetMetaKey(PRBool* aMetaKey) { return _to##GetMetaKey(aMetaKey); } \
|
||||
NS_IMETHOD SetMetaKey(PRBool aMetaKey) { return _to##SetMetaKey(aMetaKey); } \
|
||||
NS_IMETHOD GetCancelBubble(PRBool* aCancelBubble) { return _to##GetCancelBubble(aCancelBubble); } \
|
||||
NS_IMETHOD SetCancelBubble(PRBool aCancelBubble) { return _to##SetCancelBubble(aCancelBubble); } \
|
||||
NS_IMETHOD GetCharCode(PRUint32* aCharCode) { return _to##GetCharCode(aCharCode); } \
|
||||
NS_IMETHOD SetCharCode(PRUint32 aCharCode) { return _to##SetCharCode(aCharCode); } \
|
||||
NS_IMETHOD GetKeyCode(PRUint32* aKeyCode) { return _to##GetKeyCode(aKeyCode); } \
|
||||
|
@ -3,21 +3,23 @@
|
||||
readonly attribute Window self;
|
||||
readonly attribute Document document;
|
||||
readonly attribute Navigator navigator;
|
||||
readonly attribute Window opener;
|
||||
readonly attribute Window parent;
|
||||
readonly attribute Window top;
|
||||
readonly attribute boolean closed;
|
||||
readonly attribute WindowCollection frames;
|
||||
attribute Window opener;
|
||||
attribute wstring status;
|
||||
attribute wstring defaultStatus;
|
||||
attribute wstring name;
|
||||
void dump(in wstring str);
|
||||
void alert(in wstring str);
|
||||
void focus();
|
||||
void blur();
|
||||
|
||||
void clearTimeout(in long timerID);
|
||||
void clearInterval(in long timerID);
|
||||
long setTimeout(/* ... */);
|
||||
long setInterval(/* ... */);
|
||||
long open(/* ... */);
|
||||
Window open(/* ... */);
|
||||
};
|
||||
|
||||
|
@ -110,7 +110,7 @@
|
||||
const int VK_NUM_LOCK = 0x90;
|
||||
const int VK_SCROLL_LOCK = 0x91;
|
||||
|
||||
const int VK_COMMA = 0xBC;
|
||||
const int VK_COMMA = 0xBC;
|
||||
const int VK_PERIOD = 0xBE;
|
||||
const int VK_SLASH = 0xBF;
|
||||
const int VK_BACK_QUOTE = 0xC0;
|
||||
@ -133,6 +133,8 @@
|
||||
attribute boolean shiftKey;
|
||||
attribute boolean metaKey;
|
||||
|
||||
attribute boolean cancelBubble;
|
||||
|
||||
attribute unsigned long charCode;
|
||||
attribute unsigned long keyCode;
|
||||
attribute unsigned long button;
|
||||
|
@ -45,8 +45,6 @@ public:
|
||||
|
||||
NS_IMETHOD GetNavigator(nsIDOMNavigator** aNavigator)=0;
|
||||
|
||||
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener)=0;
|
||||
|
||||
NS_IMETHOD GetParent(nsIDOMWindow** aParent)=0;
|
||||
|
||||
NS_IMETHOD GetTop(nsIDOMWindow** aTop)=0;
|
||||
@ -55,6 +53,9 @@ public:
|
||||
|
||||
NS_IMETHOD GetFrames(nsIDOMWindowCollection** aFrames)=0;
|
||||
|
||||
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener)=0;
|
||||
NS_IMETHOD SetOpener(nsIDOMWindow* aOpener)=0;
|
||||
|
||||
NS_IMETHOD GetStatus(nsString& aStatus)=0;
|
||||
NS_IMETHOD SetStatus(const nsString& aStatus)=0;
|
||||
|
||||
@ -68,6 +69,10 @@ public:
|
||||
|
||||
NS_IMETHOD Alert(const nsString& aStr)=0;
|
||||
|
||||
NS_IMETHOD Focus()=0;
|
||||
|
||||
NS_IMETHOD Blur()=0;
|
||||
|
||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID)=0;
|
||||
|
||||
NS_IMETHOD ClearInterval(PRInt32 aTimerID)=0;
|
||||
@ -76,7 +81,7 @@ public:
|
||||
|
||||
NS_IMETHOD SetInterval(JSContext *cx, jsval *argv, PRUint32 argc, PRInt32* aReturn)=0;
|
||||
|
||||
NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc, nsIDOMWindow** aReturn)=0;
|
||||
};
|
||||
|
||||
|
||||
@ -85,11 +90,12 @@ public:
|
||||
NS_IMETHOD GetSelf(nsIDOMWindow** aSelf); \
|
||||
NS_IMETHOD GetDocument(nsIDOMDocument** aDocument); \
|
||||
NS_IMETHOD GetNavigator(nsIDOMNavigator** aNavigator); \
|
||||
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener); \
|
||||
NS_IMETHOD GetParent(nsIDOMWindow** aParent); \
|
||||
NS_IMETHOD GetTop(nsIDOMWindow** aTop); \
|
||||
NS_IMETHOD GetClosed(PRBool* aClosed); \
|
||||
NS_IMETHOD GetFrames(nsIDOMWindowCollection** aFrames); \
|
||||
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener); \
|
||||
NS_IMETHOD SetOpener(nsIDOMWindow* aOpener); \
|
||||
NS_IMETHOD GetStatus(nsString& aStatus); \
|
||||
NS_IMETHOD SetStatus(const nsString& aStatus); \
|
||||
NS_IMETHOD GetDefaultStatus(nsString& aDefaultStatus); \
|
||||
@ -98,11 +104,13 @@ public:
|
||||
NS_IMETHOD SetName(const nsString& aName); \
|
||||
NS_IMETHOD Dump(const nsString& aStr); \
|
||||
NS_IMETHOD Alert(const nsString& aStr); \
|
||||
NS_IMETHOD Focus(); \
|
||||
NS_IMETHOD Blur(); \
|
||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID); \
|
||||
NS_IMETHOD ClearInterval(PRInt32 aTimerID); \
|
||||
NS_IMETHOD SetTimeout(JSContext *cx, jsval *argv, PRUint32 argc, PRInt32* aReturn); \
|
||||
NS_IMETHOD SetInterval(JSContext *cx, jsval *argv, PRUint32 argc, PRInt32* aReturn); \
|
||||
NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc, PRInt32* aReturn); \
|
||||
NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc, nsIDOMWindow** aReturn); \
|
||||
|
||||
|
||||
|
||||
@ -111,11 +119,12 @@ public:
|
||||
NS_IMETHOD GetSelf(nsIDOMWindow** aSelf) { return _to##GetSelf(aSelf); } \
|
||||
NS_IMETHOD GetDocument(nsIDOMDocument** aDocument) { return _to##GetDocument(aDocument); } \
|
||||
NS_IMETHOD GetNavigator(nsIDOMNavigator** aNavigator) { return _to##GetNavigator(aNavigator); } \
|
||||
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener) { return _to##GetOpener(aOpener); } \
|
||||
NS_IMETHOD GetParent(nsIDOMWindow** aParent) { return _to##GetParent(aParent); } \
|
||||
NS_IMETHOD GetTop(nsIDOMWindow** aTop) { return _to##GetTop(aTop); } \
|
||||
NS_IMETHOD GetClosed(PRBool* aClosed) { return _to##GetClosed(aClosed); } \
|
||||
NS_IMETHOD GetFrames(nsIDOMWindowCollection** aFrames) { return _to##GetFrames(aFrames); } \
|
||||
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener) { return _to##GetOpener(aOpener); } \
|
||||
NS_IMETHOD SetOpener(nsIDOMWindow* aOpener) { return _to##SetOpener(aOpener); } \
|
||||
NS_IMETHOD GetStatus(nsString& aStatus) { return _to##GetStatus(aStatus); } \
|
||||
NS_IMETHOD SetStatus(const nsString& aStatus) { return _to##SetStatus(aStatus); } \
|
||||
NS_IMETHOD GetDefaultStatus(nsString& aDefaultStatus) { return _to##GetDefaultStatus(aDefaultStatus); } \
|
||||
@ -124,11 +133,13 @@ public:
|
||||
NS_IMETHOD SetName(const nsString& aName) { return _to##SetName(aName); } \
|
||||
NS_IMETHOD Dump(const nsString& aStr) { return _to##Dump(aStr); } \
|
||||
NS_IMETHOD Alert(const nsString& aStr) { return _to##Alert(aStr); } \
|
||||
NS_IMETHOD Focus() { return _to##Focus(); } \
|
||||
NS_IMETHOD Blur() { return _to##Blur(); } \
|
||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID) { return _to##ClearTimeout(aTimerID); } \
|
||||
NS_IMETHOD ClearInterval(PRInt32 aTimerID) { return _to##ClearInterval(aTimerID); } \
|
||||
NS_IMETHOD SetTimeout(JSContext *cx, jsval *argv, PRUint32 argc, PRInt32* aReturn) { return _to##SetTimeout(cx, argv, argc, aReturn); } \
|
||||
NS_IMETHOD SetInterval(JSContext *cx, jsval *argv, PRUint32 argc, PRInt32* aReturn) { return _to##SetInterval(cx, argv, argc, aReturn); } \
|
||||
NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc, PRInt32* aReturn) { return _to##Open(cx, argv, argc, aReturn); } \
|
||||
NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc, nsIDOMWindow** aReturn) { return _to##Open(cx, argv, argc, aReturn); } \
|
||||
|
||||
|
||||
extern nsresult NS_InitWindowClass(nsIScriptContext *aContext, nsIScriptGlobalObject *aGlobal);
|
||||
|
@ -28,6 +28,7 @@ class nsIDOMDocument;
|
||||
class nsIDOMEvent;
|
||||
class nsIPresContext;
|
||||
class nsIWebShell;
|
||||
class nsIDOMWindow;
|
||||
|
||||
#define NS_ISCRIPTGLOBALOBJECT_IID \
|
||||
{ 0x2b16fc80, 0xfa41, 0x11d1, \
|
||||
@ -43,6 +44,7 @@ public:
|
||||
NS_IMETHOD_(void) SetContext(nsIScriptContext *aContext)=0;
|
||||
NS_IMETHOD_(void) SetNewDocument(nsIDOMDocument *aDocument)=0;
|
||||
NS_IMETHOD_(void) SetWebShell(nsIWebShell *aWebShell)=0;
|
||||
NS_IMETHOD_(void) SetOpenerWindow(nsIDOMWindow *aOpener)=0;
|
||||
|
||||
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
|
@ -44,6 +44,8 @@
|
||||
#include "nsIBrowserWindow.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIScriptContextOwner.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
@ -68,6 +70,7 @@ static NS_DEFINE_IID(kIDOMEventCapturerIID, NS_IDOMEVENTCAPTURER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
||||
static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
|
||||
static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
||||
|
||||
GlobalWindowImpl::GlobalWindowImpl()
|
||||
{
|
||||
@ -78,6 +81,7 @@ GlobalWindowImpl::GlobalWindowImpl()
|
||||
mNavigator = nsnull;
|
||||
mLocation = nsnull;
|
||||
mFrames = nsnull;
|
||||
mOpener = nsnull;
|
||||
|
||||
mTimeouts = nsnull;
|
||||
mTimeoutInsertionPoint = nsnull;
|
||||
@ -93,17 +97,12 @@ GlobalWindowImpl::~GlobalWindowImpl()
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
if (nsnull != mContext) {
|
||||
NS_RELEASE(mContext);
|
||||
}
|
||||
|
||||
if (nsnull != mDocument) {
|
||||
NS_RELEASE(mDocument);
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mContext);
|
||||
NS_IF_RELEASE(mDocument);
|
||||
NS_IF_RELEASE(mNavigator);
|
||||
NS_IF_RELEASE(mLocation);
|
||||
NS_IF_RELEASE(mFrames);
|
||||
NS_IF_RELEASE(mOpener);
|
||||
NS_IF_RELEASE(mListenerManager);
|
||||
}
|
||||
|
||||
@ -196,7 +195,7 @@ GlobalWindowImpl::SetNewDocument(nsIDOMDocument *aDocument)
|
||||
if (nsnull != mDocument) {
|
||||
ClearAllTimeouts();
|
||||
|
||||
if (nsnull != mScriptObject) {
|
||||
if (nsnull != mScriptObject && nsnull != mContext) {
|
||||
JS_ClearScope((JSContext *)mContext->GetNativeContext(),
|
||||
(JSObject *)mScriptObject);
|
||||
}
|
||||
@ -231,6 +230,14 @@ GlobalWindowImpl::SetWebShell(nsIWebShell *aWebShell)
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
GlobalWindowImpl::SetOpenerWindow(nsIDOMWindow *aOpener)
|
||||
{
|
||||
NS_IF_RELEASE(mOpener);
|
||||
mOpener = aOpener;
|
||||
NS_IF_ADDREF(mOpener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::GetWindow(nsIDOMWindow** aWindow)
|
||||
{
|
||||
@ -275,12 +282,22 @@ GlobalWindowImpl::GetNavigator(nsIDOMNavigator** aNavigator)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::GetOpener(nsIDOMWindow** aOpener)
|
||||
{
|
||||
*aOpener = nsnull;
|
||||
*aOpener = mOpener;
|
||||
NS_IF_ADDREF(*aOpener);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SetOpener(nsIDOMWindow* aOpener)
|
||||
{
|
||||
if (nsnull == aOpener) {
|
||||
NS_IF_RELEASE(mOpener);
|
||||
mOpener = nsnull;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::GetParent(nsIDOMWindow** aParent)
|
||||
{
|
||||
@ -449,6 +466,18 @@ GlobalWindowImpl::Alert(const nsString& aStr)
|
||||
return Dump(aStr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::Focus()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::Blur()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GlobalWindowImpl::ClearTimeoutOrInterval(PRInt32 aTimerID)
|
||||
{
|
||||
@ -875,21 +904,36 @@ NS_IMETHODIMP
|
||||
GlobalWindowImpl::Open(JSContext *cx,
|
||||
jsval *argv,
|
||||
PRUint32 argc,
|
||||
PRInt32* aReturn)
|
||||
nsIDOMWindow** aReturn)
|
||||
{
|
||||
PRUint32 mChrome = 0;
|
||||
PRInt32 mWidth, mHeight;
|
||||
PRInt32 mLeft, mTop;
|
||||
nsString mURL, mName;
|
||||
nsString mName;
|
||||
nsAutoString mAbsURL;
|
||||
JSString* str;
|
||||
*aReturn = JSVAL_NULL;
|
||||
*aReturn = nsnull;
|
||||
|
||||
if (argc > 0) {
|
||||
JSString *mJSStrURL = JS_ValueToString(cx, argv[0]);
|
||||
if (nsnull == mJSStrURL) {
|
||||
if (nsnull == mJSStrURL || nsnull == mDocument) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsAutoString mURL, mEmpty;
|
||||
nsIURL* mDocURL;
|
||||
nsIDocument* mDoc;
|
||||
|
||||
mURL.SetString(JS_GetStringChars(mJSStrURL));
|
||||
|
||||
if (NS_OK == mDocument->QueryInterface(kIDocumentIID, (void**)&mDoc)) {
|
||||
mDocURL = mDoc->GetDocumentURL();
|
||||
NS_RELEASE(mDoc);
|
||||
}
|
||||
|
||||
if (NS_OK != NS_MakeAbsoluteURL(mDocURL, mEmpty, mURL, mAbsURL)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Sanity-check the optional window_name argument. */
|
||||
@ -966,14 +1010,14 @@ GlobalWindowImpl::Open(JSContext *cx,
|
||||
}
|
||||
|
||||
nsIBrowserWindow *mNewWindow, *mBrowser;
|
||||
void *mNewScriptObject = nsnull;
|
||||
nsIScriptGlobalObject *mNewGlobalObject = nsnull;
|
||||
|
||||
/* XXX check for existing window of same name. If exists, set url and
|
||||
* update chrome */
|
||||
|
||||
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
||||
mBrowser->OpenWindow(mChrome, mNewWindow);
|
||||
mNewWindow->LoadURL(mURL);
|
||||
mNewWindow->LoadURL(mAbsURL);
|
||||
//How should we do default size/pos
|
||||
mNewWindow->SizeTo(mWidth ? mWidth : 620, mHeight ? mHeight : 400);
|
||||
mNewWindow->MoveTo(mLeft, mTop);
|
||||
@ -981,56 +1025,34 @@ GlobalWindowImpl::Open(JSContext *cx,
|
||||
|
||||
NS_RELEASE(mBrowser);
|
||||
|
||||
/*XXX Get win obj */
|
||||
nsIWebShell *mNewWebShell;
|
||||
nsIScriptGlobalObject *mNewGlobalObject;
|
||||
nsIScriptContextOwner *mNewContextOwner;
|
||||
/* Get win obj */
|
||||
nsIWebShell *mNewWebShell = nsnull;
|
||||
nsIScriptContextOwner *mNewContextOwner = nsnull;
|
||||
|
||||
if (NS_OK != mNewWindow->GetWebShell(mNewWebShell)) {
|
||||
NS_RELEASE(mNewWindow);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (NS_OK != mNewWebShell->QueryInterface(kIScriptContextOwnerIID, (void**)&mNewContextOwner)) {
|
||||
NS_RELEASE(mNewWebShell);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (NS_OK != mNewWindow->GetWebShell(mNewWebShell) ||
|
||||
NS_OK != mNewWebShell->QueryInterface(kIScriptContextOwnerIID, (void**)&mNewContextOwner) ||
|
||||
NS_OK != mNewContextOwner->GetScriptGlobalObject(&mNewGlobalObject)) {
|
||||
|
||||
if (NS_OK != mNewContextOwner->GetScriptGlobalObject(&mNewGlobalObject)) {
|
||||
NS_RELEASE(mNewContextOwner);
|
||||
NS_IF_RELEASE(mNewWindow);
|
||||
NS_IF_RELEASE(mNewWebShell);
|
||||
NS_IF_RELEASE(mNewContextOwner);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_RELEASE(mNewWindow);
|
||||
NS_RELEASE(mNewWebShell);
|
||||
|
||||
nsIScriptContext *mNewContext;
|
||||
if (NS_OK != mNewContextOwner->GetScriptContext(&mNewContext)) {
|
||||
NS_RELEASE(mNewContextOwner);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsIScriptObjectOwner *mNewObjectOwner;
|
||||
if (NS_OK == mNewGlobalObject->QueryInterface(kIScriptObjectOwnerIID, (void**)&mNewObjectOwner)) {
|
||||
mNewObjectOwner->GetScriptObject(mNewContext, &mNewScriptObject);
|
||||
}
|
||||
|
||||
NS_RELEASE(mNewGlobalObject);
|
||||
NS_RELEASE(mNewObjectOwner);
|
||||
NS_RELEASE(mNewContextOwner);
|
||||
|
||||
/* Set opener in private data, too? */
|
||||
/*Need the tiny id
|
||||
if (!JS_DefinePropertyWithTinyId(cx, (JSObject*)mNewScriptObject,
|
||||
"opener", WIN_OPENER,
|
||||
OBJECT_TO_JSVAL(mScriptObject),
|
||||
nsnull, nsnull, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
*aReturn = OBJECT_TO_JSVAL((JSObject*)mNewScriptObject);
|
||||
nsIDOMWindow *mNewDOMWindow;
|
||||
if (nsnull != mNewGlobalObject && NS_OK == mNewGlobalObject->QueryInterface(kIDOMWindowIID, (void**)&mNewDOMWindow)) {
|
||||
*aReturn = mNewDOMWindow;
|
||||
}
|
||||
|
||||
/* Set opener */
|
||||
mNewGlobalObject->SetOpenerWindow(mNewDOMWindow);
|
||||
|
||||
NS_IF_RELEASE(mNewGlobalObject);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -62,18 +62,21 @@ public:
|
||||
NS_IMETHOD_(void) SetContext(nsIScriptContext *aContext);
|
||||
NS_IMETHOD_(void) SetNewDocument(nsIDOMDocument *aDocument);
|
||||
NS_IMETHOD_(void) SetWebShell(nsIWebShell *aWebShell);
|
||||
NS_IMETHOD_(void) SetOpenerWindow(nsIDOMWindow *aOpener);
|
||||
|
||||
NS_IMETHOD GetWindow(nsIDOMWindow** aWindow);
|
||||
NS_IMETHOD GetSelf(nsIDOMWindow** aSelf);
|
||||
NS_IMETHOD GetDocument(nsIDOMDocument** aDocument);
|
||||
NS_IMETHOD GetNavigator(nsIDOMNavigator** aNavigator);
|
||||
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener);
|
||||
NS_IMETHOD GetLocation(nsIDOMLocation** aLocation);
|
||||
NS_IMETHOD GetParent(nsIDOMWindow** aOpener);
|
||||
NS_IMETHOD GetTop(nsIDOMWindow** aTop);
|
||||
NS_IMETHOD GetClosed(PRBool* aClosed);
|
||||
NS_IMETHOD GetFrames(nsIDOMWindowCollection** aFrames);
|
||||
|
||||
NS_IMETHOD GetOpener(nsIDOMWindow** aOpener);
|
||||
NS_IMETHOD SetOpener(nsIDOMWindow* aOpener);
|
||||
|
||||
NS_IMETHOD GetStatus(nsString& aStatus);
|
||||
NS_IMETHOD SetStatus(const nsString& aStatus);
|
||||
|
||||
@ -85,6 +88,8 @@ public:
|
||||
|
||||
NS_IMETHOD Dump(const nsString& aStr);
|
||||
NS_IMETHOD Alert(const nsString& aStr);
|
||||
NS_IMETHOD Focus();
|
||||
NS_IMETHOD Blur();
|
||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID);
|
||||
NS_IMETHOD ClearInterval(PRInt32 aTimerID);
|
||||
NS_IMETHOD SetTimeout(JSContext *cx, jsval *argv, PRUint32 argc,
|
||||
@ -92,7 +97,7 @@ public:
|
||||
NS_IMETHOD SetInterval(JSContext *cx, jsval *argv, PRUint32 argc,
|
||||
PRInt32* aReturn);
|
||||
NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc,
|
||||
PRInt32* aReturn);
|
||||
nsIDOMWindow** aReturn);
|
||||
|
||||
// nsIDOMEventCapturer interface
|
||||
NS_IMETHOD CaptureEvent(nsIDOMEventListener *aListener);
|
||||
@ -142,6 +147,7 @@ protected:
|
||||
NavigatorImpl *mNavigator;
|
||||
LocationImpl *mLocation;
|
||||
nsIWebShell *mWebShell;
|
||||
nsIDOMWindow *mOpener;
|
||||
|
||||
nsTimeoutImpl *mTimeouts;
|
||||
nsTimeoutImpl **mTimeoutInsertionPoint;
|
||||
|
@ -52,11 +52,11 @@ enum Window_slots {
|
||||
WINDOW_SELF = -12,
|
||||
WINDOW_DOCUMENT = -13,
|
||||
WINDOW_NAVIGATOR = -14,
|
||||
WINDOW_OPENER = -15,
|
||||
WINDOW_PARENT = -16,
|
||||
WINDOW_TOP = -17,
|
||||
WINDOW_CLOSED = -18,
|
||||
WINDOW_FRAMES = -19,
|
||||
WINDOW_PARENT = -15,
|
||||
WINDOW_TOP = -16,
|
||||
WINDOW_CLOSED = -17,
|
||||
WINDOW_FRAMES = -18,
|
||||
WINDOW_OPENER = -19,
|
||||
WINDOW_STATUS = -110,
|
||||
WINDOW_DEFAULTSTATUS = -111,
|
||||
WINDOW_NAME = -112
|
||||
@ -186,33 +186,6 @@ GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WINDOW_OPENER:
|
||||
{
|
||||
nsIDOMWindow* prop;
|
||||
if (NS_OK == a->GetOpener(&prop)) {
|
||||
// get the js object
|
||||
if (prop != nsnull) {
|
||||
nsIScriptObjectOwner *owner = nsnull;
|
||||
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
|
||||
JSObject *object = nsnull;
|
||||
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
|
||||
// set the return value
|
||||
*vp = OBJECT_TO_JSVAL(object);
|
||||
}
|
||||
NS_RELEASE(owner);
|
||||
}
|
||||
NS_RELEASE(prop);
|
||||
}
|
||||
else {
|
||||
*vp = JSVAL_NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WINDOW_PARENT:
|
||||
{
|
||||
nsIDOMWindow* prop;
|
||||
@ -305,6 +278,33 @@ GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WINDOW_OPENER:
|
||||
{
|
||||
nsIDOMWindow* prop;
|
||||
if (NS_OK == a->GetOpener(&prop)) {
|
||||
// get the js object
|
||||
if (prop != nsnull) {
|
||||
nsIScriptObjectOwner *owner = nsnull;
|
||||
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
|
||||
JSObject *object = nsnull;
|
||||
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
|
||||
// set the return value
|
||||
*vp = OBJECT_TO_JSVAL(object);
|
||||
}
|
||||
NS_RELEASE(owner);
|
||||
}
|
||||
NS_RELEASE(prop);
|
||||
}
|
||||
else {
|
||||
*vp = JSVAL_NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WINDOW_STATUS:
|
||||
{
|
||||
nsAutoString prop;
|
||||
@ -385,6 +385,29 @@ SetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case WINDOW_OPENER:
|
||||
{
|
||||
nsIDOMWindow* prop;
|
||||
if (JSVAL_IS_NULL(*vp)) {
|
||||
prop = nsnull;
|
||||
}
|
||||
else if (JSVAL_IS_OBJECT(*vp)) {
|
||||
JSObject *jsobj = JSVAL_TO_OBJECT(*vp);
|
||||
nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj);
|
||||
if (NS_OK != supports->QueryInterface(kIWindowIID, (void **)&prop)) {
|
||||
JS_ReportError(cx, "Parameter must be of type Window");
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Parameter must be an object");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
a->SetOpener(prop);
|
||||
if (prop) NS_RELEASE(prop);
|
||||
break;
|
||||
}
|
||||
case WINDOW_STATUS:
|
||||
{
|
||||
nsAutoString prop;
|
||||
@ -589,6 +612,72 @@ WindowAlert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Focus
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowFocus(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 0) {
|
||||
|
||||
if (NS_OK != nativeThis->Focus()) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function focus requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Blur
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowBlur(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 0) {
|
||||
|
||||
if (NS_OK != nativeThis->Blur()) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function blur requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method ClearTimeout
|
||||
//
|
||||
@ -743,7 +832,7 @@ WindowOpen(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
PRInt32 nativeRet;
|
||||
nsIDOMWindow* nativeRet;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
@ -758,7 +847,22 @@ WindowOpen(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = INT_TO_JSVAL(nativeRet);
|
||||
if (nativeRet != nsnull) {
|
||||
nsIScriptObjectOwner *owner = nsnull;
|
||||
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
|
||||
JSObject *object = nsnull;
|
||||
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
|
||||
// set the return value
|
||||
*rval = OBJECT_TO_JSVAL(object);
|
||||
}
|
||||
NS_RELEASE(owner);
|
||||
}
|
||||
NS_RELEASE(nativeRet);
|
||||
}
|
||||
else {
|
||||
*rval = JSVAL_NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function open requires 0 parameters");
|
||||
@ -796,11 +900,11 @@ static JSPropertySpec WindowProperties[] =
|
||||
{"self", WINDOW_SELF, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"document", WINDOW_DOCUMENT, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"navigator", WINDOW_NAVIGATOR, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"opener", WINDOW_OPENER, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"parent", WINDOW_PARENT, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"top", WINDOW_TOP, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"closed", WINDOW_CLOSED, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"frames", WINDOW_FRAMES, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"opener", WINDOW_OPENER, JSPROP_ENUMERATE},
|
||||
{"status", WINDOW_STATUS, JSPROP_ENUMERATE},
|
||||
{"defaultStatus", WINDOW_DEFAULTSTATUS, JSPROP_ENUMERATE},
|
||||
{"name", WINDOW_NAME, JSPROP_ENUMERATE},
|
||||
@ -815,6 +919,8 @@ static JSFunctionSpec WindowMethods[] =
|
||||
{
|
||||
{"dump", WindowDump, 1},
|
||||
{"alert", WindowAlert, 1},
|
||||
{"focus", WindowFocus, 0},
|
||||
{"blur", WindowBlur, 0},
|
||||
{"clearTimeout", WindowClearTimeout, 1},
|
||||
{"clearInterval", WindowClearInterval, 1},
|
||||
{"setTimeout", WindowSetTimeout, 0},
|
||||
@ -873,6 +979,9 @@ extern "C" NS_DOM nsresult NS_NewScriptWindow(nsIScriptContext *aContext, nsIDOM
|
||||
// assign "this" to the js object, don't AddRef
|
||||
::JS_SetPrivate(jscontext, global, aSupports);
|
||||
|
||||
JS_DefineProperties(jscontext, global, WindowProperties);
|
||||
JS_DefineFunctions(jscontext, global, WindowMethods);
|
||||
|
||||
*aReturn = (void*)global;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -55,9 +55,10 @@ enum Event_slots {
|
||||
EVENT_CTRLKEY = -18,
|
||||
EVENT_SHIFTKEY = -19,
|
||||
EVENT_METAKEY = -110,
|
||||
EVENT_CHARCODE = -111,
|
||||
EVENT_KEYCODE = -112,
|
||||
EVENT_BUTTON = -113,
|
||||
EVENT_CANCELBUBBLE = -111,
|
||||
EVENT_CHARCODE = -112,
|
||||
EVENT_KEYCODE = -113,
|
||||
EVENT_BUTTON = -114,
|
||||
NSEVENT_LAYERX = -21,
|
||||
NSEVENT_LAYERY = -22
|
||||
};
|
||||
@ -206,6 +207,17 @@ GetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EVENT_CANCELBUBBLE:
|
||||
{
|
||||
PRBool prop;
|
||||
if (NS_OK == a->GetCancelBubble(&prop)) {
|
||||
*vp = BOOLEAN_TO_JSVAL(prop);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EVENT_CHARCODE:
|
||||
{
|
||||
PRUint32 prop;
|
||||
@ -486,6 +498,22 @@ SetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
break;
|
||||
}
|
||||
case EVENT_CANCELBUBBLE:
|
||||
{
|
||||
PRBool prop;
|
||||
JSBool temp;
|
||||
if (JSVAL_IS_BOOLEAN(*vp) && JS_ValueToBoolean(cx, *vp, &temp)) {
|
||||
prop = (PRBool)temp;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Parameter must be a boolean");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
a->SetCancelBubble(prop);
|
||||
|
||||
break;
|
||||
}
|
||||
case EVENT_CHARCODE:
|
||||
{
|
||||
PRUint32 prop;
|
||||
@ -704,6 +732,7 @@ static JSPropertySpec EventProperties[] =
|
||||
{"ctrlKey", EVENT_CTRLKEY, JSPROP_ENUMERATE},
|
||||
{"shiftKey", EVENT_SHIFTKEY, JSPROP_ENUMERATE},
|
||||
{"metaKey", EVENT_METAKEY, JSPROP_ENUMERATE},
|
||||
{"cancelBubble", EVENT_CANCELBUBBLE, JSPROP_ENUMERATE},
|
||||
{"charCode", EVENT_CHARCODE, JSPROP_ENUMERATE},
|
||||
{"keyCode", EVENT_KEYCODE, JSPROP_ENUMERATE},
|
||||
{"button", EVENT_BUTTON, JSPROP_ENUMERATE},
|
||||
|
@ -1501,6 +1501,9 @@ static const char *kNewGlobalJSObjectStr =
|
||||
" // assign \"this\" to the js object, don't AddRef\n"
|
||||
" ::JS_SetPrivate(jscontext, global, aSupports);\n"
|
||||
"\n"
|
||||
" JS_DefineProperties(jscontext, global, %sProperties);\n"
|
||||
" JS_DefineFunctions(jscontext, global, %sMethods);\n"
|
||||
"\n"
|
||||
" *aReturn = (void*)global;\n"
|
||||
" return NS_OK;\n"
|
||||
" }\n"
|
||||
@ -1510,7 +1513,7 @@ static const char *kNewGlobalJSObjectStr =
|
||||
|
||||
#define JSGEN_GENERATE_NEWGLOBALJSOBJECT(buffer, className) \
|
||||
sprintf(buffer, kNewGlobalJSObjectStr, className, className, \
|
||||
className, className)
|
||||
className, className, className, className)
|
||||
|
||||
static const char *kNewJSObjectStr =
|
||||
"\n\n//\n"
|
||||
|
Loading…
Reference in New Issue
Block a user