From 470a41f1279581024ac56ce9b0ecc26645fe95cd Mon Sep 17 00:00:00 2001 From: "attinasi%netscape.com" Date: Sat, 26 May 2001 05:46:33 +0000 Subject: [PATCH] Fixed crash when mouse move event is handled by image frame and the baseURI is null (after traversing to the link'd document). b=81728 r=pavlov@netscape.com sr=hyatt2netscape.com a=asa@mozilla.org --- layout/generic/nsImageFrame.cpp | 46 +++++++++++++++------------ layout/html/base/src/nsImageFrame.cpp | 46 +++++++++++++++------------ 2 files changed, 52 insertions(+), 40 deletions(-) diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 7dd9bd2f83df..48ca63cec1e7 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1161,28 +1161,34 @@ nsImageFrame::HandleEvent(nsIPresContext* aPresContext, nsCOMPtr baseURL; GetBaseURI(getter_AddRefs(baseURL)); - // Server side image maps use the href in a containing anchor - // element to provide the basis for the destination url. - nsAutoString src; - if (GetAnchorHREFAndTarget(src, target)) { - NS_MakeAbsoluteURI(absURL, src, baseURL); + if (baseURL) { + // Server side image maps use the href in a containing anchor + // element to provide the basis for the destination url. + nsAutoString src; + if (GetAnchorHREFAndTarget(src, target)) { + NS_MakeAbsoluteURI(absURL, src, baseURL); - // XXX if the mouse is over/clicked in the border/padding area - // we should probably just pretend nothing happened. Nav4 - // keeps the x,y coordinates positive as we do; IE doesn't - // bother. Both of them send the click through even when the - // mouse is over the border. - if (p.x < 0) p.x = 0; - if (p.y < 0) p.y = 0; - char cbuf[50]; - PR_snprintf(cbuf, sizeof(cbuf), "?%d,%d", p.x, p.y); - absURL.AppendWithConversion(cbuf); - PRBool clicked = PR_FALSE; - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - *aEventStatus = nsEventStatus_eConsumeDoDefault; - clicked = PR_TRUE; + // XXX if the mouse is over/clicked in the border/padding area + // we should probably just pretend nothing happened. Nav4 + // keeps the x,y coordinates positive as we do; IE doesn't + // bother. Both of them send the click through even when the + // mouse is over the border. + if (p.x < 0) p.x = 0; + if (p.y < 0) p.y = 0; + char cbuf[50]; + PR_snprintf(cbuf, sizeof(cbuf), "?%d,%d", p.x, p.y); + absURL.AppendWithConversion(cbuf); + PRBool clicked = PR_FALSE; + if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { + *aEventStatus = nsEventStatus_eConsumeDoDefault; + clicked = PR_TRUE; + } + TriggerLink(aPresContext, absURL, target, clicked); } - TriggerLink(aPresContext, absURL, target, clicked); + } + else + { + NS_WARNING("baseURL is null for imageFrame - ignoring mouse event"); } } } diff --git a/layout/html/base/src/nsImageFrame.cpp b/layout/html/base/src/nsImageFrame.cpp index 7dd9bd2f83df..48ca63cec1e7 100644 --- a/layout/html/base/src/nsImageFrame.cpp +++ b/layout/html/base/src/nsImageFrame.cpp @@ -1161,28 +1161,34 @@ nsImageFrame::HandleEvent(nsIPresContext* aPresContext, nsCOMPtr baseURL; GetBaseURI(getter_AddRefs(baseURL)); - // Server side image maps use the href in a containing anchor - // element to provide the basis for the destination url. - nsAutoString src; - if (GetAnchorHREFAndTarget(src, target)) { - NS_MakeAbsoluteURI(absURL, src, baseURL); + if (baseURL) { + // Server side image maps use the href in a containing anchor + // element to provide the basis for the destination url. + nsAutoString src; + if (GetAnchorHREFAndTarget(src, target)) { + NS_MakeAbsoluteURI(absURL, src, baseURL); - // XXX if the mouse is over/clicked in the border/padding area - // we should probably just pretend nothing happened. Nav4 - // keeps the x,y coordinates positive as we do; IE doesn't - // bother. Both of them send the click through even when the - // mouse is over the border. - if (p.x < 0) p.x = 0; - if (p.y < 0) p.y = 0; - char cbuf[50]; - PR_snprintf(cbuf, sizeof(cbuf), "?%d,%d", p.x, p.y); - absURL.AppendWithConversion(cbuf); - PRBool clicked = PR_FALSE; - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - *aEventStatus = nsEventStatus_eConsumeDoDefault; - clicked = PR_TRUE; + // XXX if the mouse is over/clicked in the border/padding area + // we should probably just pretend nothing happened. Nav4 + // keeps the x,y coordinates positive as we do; IE doesn't + // bother. Both of them send the click through even when the + // mouse is over the border. + if (p.x < 0) p.x = 0; + if (p.y < 0) p.y = 0; + char cbuf[50]; + PR_snprintf(cbuf, sizeof(cbuf), "?%d,%d", p.x, p.y); + absURL.AppendWithConversion(cbuf); + PRBool clicked = PR_FALSE; + if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { + *aEventStatus = nsEventStatus_eConsumeDoDefault; + clicked = PR_TRUE; + } + TriggerLink(aPresContext, absURL, target, clicked); } - TriggerLink(aPresContext, absURL, target, clicked); + } + else + { + NS_WARNING("baseURL is null for imageFrame - ignoring mouse event"); } } }