Fixing event coordinates to give screen based info. Also fixing direct reference to frames via their names.

This commit is contained in:
joki%netscape.com 1999-06-09 07:38:26 +00:00
Родитель c7f0ebfe8d
Коммит 25aab9fee5
8 изменённых файлов: 127 добавлений и 19 удалений

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsIContent.h"
#include "nsIRenderingContext.h"
#include "nsIDOMRenderingContext.h"
#include "nsIWidget.h"
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID);
@ -195,13 +196,43 @@ NS_METHOD nsDOMEvent::SetCommitText(PRBool aCommitText)
NS_METHOD nsDOMEvent::GetScreenX(PRInt32* aScreenX)
{
*aScreenX = 0;
nsRect bounds, offset;
offset.x = 0;
nsIWidget* parent = ((nsGUIEvent*)mEvent)->widget;
//Add extra since loop will free one.
NS_ADDREF(parent);
nsIWidget* tmp;
while (nsnull != prent) {
parent->GetBoundsa(bounds);
offset.x += bounds.x;
tmp = parent;
parent = tmp->GetParent();
NS_RELEASE(tmp);
}
*aScreenX = mEvent->refPoint.x + offset.x;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetScreenY(PRInt32* aScreenY)
{
*aScreenY = 0;
nsRect bounds, offset;
offset.y = 0;
nsIWidget* parent = ((nsGUIEvent*)mEvent)->widget;
//Add extra since loop will free one.
NS_ADDREF(parent);
nsIWidget* tmp;
while (nsnull != parent) {
parent->GetBounds(bounds);
offset.y += bounds.y;
tmp = parent;
parent = tmp->GetParent();
NS_RELEASE(tmp);
}
*aScreenY = mEvent->refPoint.y + offset.y;
return NS_OK;
}
@ -318,14 +349,12 @@ NS_METHOD nsDOMEvent::GetLayerY(PRInt32* aLayerY)
NS_METHOD nsDOMEvent::GetPageX(PRInt32* aPageX)
{
*aPageX = 0;
return NS_OK;
return GetClientX(aPageX);
}
NS_METHOD nsDOMEvent::GetPageY(PRInt32* aPageY)
{
*aPageY = 0;
return NS_OK;
return GetClientY(aPageY);
}
NS_METHOD nsDOMEvent::GetWhich(PRUint32* aWhich)

Просмотреть файл

@ -586,9 +586,11 @@ nsEventStateManager::CheckForAndDispatchClick(nsIPresContext& aPresContext,
if (fireClick) {
//fire click
event.eventStructType = NS_MOUSE_EVENT;
event.widget = nsnull;
event.widget = aEvent->widget;
event.point.x = aEvent->point.x;
event.point.y = aEvent->point.y;
event.refPoint.x = aEvent->refPoint.x;
event.refPoint.y = aEvent->refPoint.y;
if (nsnull != mouseContent) {
ret = mouseContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, aStatus);

Просмотреть файл

@ -1979,10 +1979,49 @@ GlobalWindowImpl::EnumerateProperty(JSContext *aContext)
PRBool
GlobalWindowImpl::Resolve(JSContext *aContext, jsval aID)
{
if (JSVAL_IS_STRING(aID) &&
PL_strcmp("location", JS_GetStringBytes(JS_ValueToString(aContext, aID))) == 0) {
::JS_DefineProperty(aContext, (JSObject *)mScriptObject, "location",
JSVAL_NULL, nsnull, nsnull, 0);
if (JSVAL_IS_STRING(aID)) {
if (PL_strcmp("location", JS_GetStringBytes(JS_ValueToString(aContext, aID))) == 0) {
::JS_DefineProperty(aContext, (JSObject *)mScriptObject, "location",
JSVAL_NULL, nsnull, nsnull, 0);
}
else {
PRInt32 count;
if (NS_SUCCEEDED(mWebShell->GetChildCount(count)) && count) {
nsIWebShell *child = nsnull;
nsAutoString name(JS_GetStringBytes(JS_ValueToString(aContext, aID)));
if (NS_SUCCEEDED(mWebShell->FindChildWithName(name.GetUnicode(), child))) {
if (child) {
JSObject *childObj;
//We found a subframe of the right name. The rest of this is to get its script object.
nsIScriptContextOwner *contextOwner;
if (NS_SUCCEEDED(child->QueryInterface(kIScriptContextOwnerIID, (void**)&contextOwner))) {
nsIScriptGlobalObject *childGlobalObj;
if (NS_SUCCEEDED(contextOwner->GetScriptGlobalObject(&childGlobalObj))) {
nsIScriptObjectOwner *objOwner;
if (NS_SUCCEEDED(childGlobalObj->QueryInterface(kIScriptObjectOwnerIID, (void**)&objOwner))) {
nsIScriptContext *scriptContext;
childGlobalObj->GetContext(&scriptContext);
if (scriptContext) {
objOwner->GetScriptObject(scriptContext, (void**)&childObj);
NS_RELEASE(scriptContext);
}
NS_RELEASE(objOwner);
}
NS_RELEASE(childGlobalObj);
}
NS_RELEASE(contextOwner);
}
//Okay, if we now have a childObj, we can define it and proceed.
if (childObj) {
::JS_DefineProperty(aContext, (JSObject *)mScriptObject,
JS_GetStringBytes(JS_ValueToString(aContext, aID)),
OBJECT_TO_JSVAL(childObj), nsnull, nsnull, 0);
}
NS_RELEASE(child);
}
}
}
}
}
return PR_TRUE;

Просмотреть файл

@ -183,6 +183,7 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
nsIScriptObjectOwner *owner;
JSObject *global;
nsresult res = aGlobalObject->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
mIsInitialized = PR_FALSE;
if (NS_OK == res) {
res = owner->GetScriptObject(this, (void **)&global);

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsIContent.h"
#include "nsIRenderingContext.h"
#include "nsIDOMRenderingContext.h"
#include "nsIWidget.h"
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID);
@ -195,13 +196,43 @@ NS_METHOD nsDOMEvent::SetCommitText(PRBool aCommitText)
NS_METHOD nsDOMEvent::GetScreenX(PRInt32* aScreenX)
{
*aScreenX = 0;
nsRect bounds, offset;
offset.x = 0;
nsIWidget* parent = ((nsGUIEvent*)mEvent)->widget;
//Add extra since loop will free one.
NS_ADDREF(parent);
nsIWidget* tmp;
while (nsnull != prent) {
parent->GetBoundsa(bounds);
offset.x += bounds.x;
tmp = parent;
parent = tmp->GetParent();
NS_RELEASE(tmp);
}
*aScreenX = mEvent->refPoint.x + offset.x;
return NS_OK;
}
NS_METHOD nsDOMEvent::GetScreenY(PRInt32* aScreenY)
{
*aScreenY = 0;
nsRect bounds, offset;
offset.y = 0;
nsIWidget* parent = ((nsGUIEvent*)mEvent)->widget;
//Add extra since loop will free one.
NS_ADDREF(parent);
nsIWidget* tmp;
while (nsnull != parent) {
parent->GetBounds(bounds);
offset.y += bounds.y;
tmp = parent;
parent = tmp->GetParent();
NS_RELEASE(tmp);
}
*aScreenY = mEvent->refPoint.y + offset.y;
return NS_OK;
}
@ -318,14 +349,12 @@ NS_METHOD nsDOMEvent::GetLayerY(PRInt32* aLayerY)
NS_METHOD nsDOMEvent::GetPageX(PRInt32* aPageX)
{
*aPageX = 0;
return NS_OK;
return GetClientX(aPageX);
}
NS_METHOD nsDOMEvent::GetPageY(PRInt32* aPageY)
{
*aPageY = 0;
return NS_OK;
return GetClientY(aPageY);
}
NS_METHOD nsDOMEvent::GetWhich(PRUint32* aWhich)

Просмотреть файл

@ -586,9 +586,11 @@ nsEventStateManager::CheckForAndDispatchClick(nsIPresContext& aPresContext,
if (fireClick) {
//fire click
event.eventStructType = NS_MOUSE_EVENT;
event.widget = nsnull;
event.widget = aEvent->widget;
event.point.x = aEvent->point.x;
event.point.y = aEvent->point.y;
event.refPoint.x = aEvent->refPoint.x;
event.refPoint.y = aEvent->refPoint.y;
if (nsnull != mouseContent) {
ret = mouseContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, aStatus);

Просмотреть файл

@ -1721,6 +1721,10 @@ NS_IMETHODIMP nsViewManager :: DispatchEvent(nsGUIEvent *aEvent, nsEventStatus &
mContext->GetDevUnitsToAppUnits(p2t);
mContext->GetAppUnitsToDevUnits(t2p);
//Before we start mucking with coords, make sure we know our baseline
aEvent->refPoint.x = aEvent->point.x;
aEvent->refPoint.y = aEvent->point.y;
aEvent->point.x = NSIntPixelsToTwips(aEvent->point.x, p2t);
aEvent->point.y = NSIntPixelsToTwips(aEvent->point.y, p2t);

Просмотреть файл

@ -48,8 +48,10 @@ struct nsEvent {
PRUint8 eventStructType;
/// See GUI MESSAGES,
PRUint32 message;
/// in widget relative coordinates
/// in widget relative coordinates, modified to be relative to current view in layout.
nsPoint point;
// in widget relative coordinates, not modified by layout code.
nsPoint refPoint;
/// elapsed time, in milliseconds, from the time the system was started to the time the message was created
PRUint32 time;
};