1998-06-07 07:55:55 +00:00
|
|
|
/* -*- 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsDOMEvent.h"
|
1998-06-23 21:53:02 +00:00
|
|
|
#include "nsIDOMNode.h"
|
1998-06-07 07:55:55 +00:00
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
1998-06-07 07:55:55 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
|
|
|
|
static NS_DEFINE_IID(kINSEventIID, NS_INSEVENT_IID);
|
|
|
|
|
|
|
|
nsDOMEvent::nsDOMEvent() {
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMEvent::~nsDOMEvent() {
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsDOMEvent)
|
|
|
|
NS_IMPL_RELEASE(nsDOMEvent)
|
|
|
|
|
|
|
|
nsresult nsDOMEvent::QueryInterface(const nsIID& aIID,
|
|
|
|
void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMEventIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIDOMEvent*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kINSEventIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsINSEvent*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMEventInterface
|
|
|
|
NS_METHOD nsDOMEvent::GetType(nsString& aType)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
|
1998-06-07 07:55:55 +00:00
|
|
|
{
|
1998-06-23 21:53:02 +00:00
|
|
|
return kTarget->QueryInterface(kIDOMNodeIID, (void**)aTarget);
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetScreenX(PRInt32& aX)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetScreenY(PRInt32& aY)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetClientX(PRInt32& aX)
|
|
|
|
{
|
1998-06-23 21:53:02 +00:00
|
|
|
//XXX these are not client coords yet
|
|
|
|
aX = kEvent->point.x;
|
|
|
|
return NS_OK;
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetClientY(PRInt32& aY)
|
|
|
|
{
|
1998-06-23 21:53:02 +00:00
|
|
|
//XXX these are not client coords yet
|
|
|
|
aY = kEvent->point.y;
|
|
|
|
return NS_OK;
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetAltKey(PRBool& aIsDown)
|
|
|
|
{
|
1998-06-23 21:53:02 +00:00
|
|
|
aIsDown = ((nsInputEvent*)kEvent)->isAlt;
|
|
|
|
return NS_OK;
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetCtrlKey(PRBool& aIsDown)
|
|
|
|
{
|
1998-06-23 21:53:02 +00:00
|
|
|
aIsDown = ((nsInputEvent*)kEvent)->isControl;
|
|
|
|
return NS_OK;
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetShiftKey(PRBool& aIsDown)
|
|
|
|
{
|
1998-06-23 21:53:02 +00:00
|
|
|
aIsDown = ((nsInputEvent*)kEvent)->isShift;
|
1998-06-07 07:55:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetMetaKey(PRBool& aIsDown)
|
|
|
|
{
|
1998-06-23 21:53:02 +00:00
|
|
|
return NS_OK;
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode)
|
|
|
|
{
|
1998-06-23 21:53:02 +00:00
|
|
|
switch (kEvent->message) {
|
|
|
|
case NS_KEY_UP:
|
|
|
|
case NS_KEY_DOWN:
|
|
|
|
aKeyCode = ((nsKeyEvent*)kEvent)->keyCode;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1998-06-07 07:55:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton)
|
|
|
|
{
|
1998-06-23 21:53:02 +00:00
|
|
|
switch (kEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
|
|
|
case NS_MOUSE_LEFT_DOUBLECLICK:
|
|
|
|
aButton = 1;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
|
|
|
aButton = 2;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_UP:
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_DOWN:
|
|
|
|
case NS_MOUSE_RIGHT_DOUBLECLICK:
|
|
|
|
aButton = 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsINSEventInterface
|
|
|
|
NS_METHOD nsDOMEvent::GetLayerX(PRInt32& aX)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::GetLayerY(PRInt32& aY)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
NS_METHOD nsDOMEvent::SetGUIEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
|
|
|
kEvent = aEvent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsDOMEvent::SetEventTarget(nsISupports *aTarget)
|
|
|
|
{
|
|
|
|
kTarget = aTarget;
|
|
|
|
return NS_OK;
|
|
|
|
}
|