From 835a8e5d69eb75a4910e0a08f78e8a8d5318f6be Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Thu, 8 Jul 1999 19:44:42 +0000 Subject: [PATCH] Only pass on url to server side image map when we end up with a valid url --- layout/generic/nsImageFrame.cpp | 76 +++++++++++++++------------ layout/generic/nsImageFrame.h | 2 +- layout/html/base/src/nsImageFrame.cpp | 76 +++++++++++++++------------ layout/html/base/src/nsImageFrame.h | 2 +- 4 files changed, 84 insertions(+), 72 deletions(-) diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 8508503faf4..ebc2ce53f7c 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -632,9 +632,10 @@ nsImageFrame::TranslateEventCoords(nsIPresContext& aPresContext, aResult.y = NSTwipsToIntPixels(y, t2p); } -void +PRBool nsImageFrame::GetAnchorHREF(nsString& aResult) { + PRBool status = PR_FALSE; aResult.Truncate(); // Walk up the content tree, looking for an nsIDOMAnchorElement @@ -644,12 +645,16 @@ nsImageFrame::GetAnchorHREF(nsString& aResult) nsCOMPtr anchor(do_QueryInterface(content)); if (anchor) { anchor->GetHref(aResult); + if (aResult.Length() > 0) { + status = PR_TRUE; + } break; } nsCOMPtr parent; content->GetParent(*getter_AddRefs(parent)); content = parent; } + return status; } // XXX what should clicks on transparent pixels do? @@ -715,47 +720,48 @@ nsImageFrame::HandleEvent(nsIPresContext& aPresContext, // Server side image maps use the href in a containing anchor // element to provide the basis for the destination url. nsAutoString src; - GetAnchorHREF(src); + if (GetAnchorHREF(src)) { #ifndef NECKO - nsString empty; - NS_MakeAbsoluteURL(baseURL, empty, src, absURL); + nsString empty; + NS_MakeAbsoluteURL(baseURL, empty, src, absURL); #else - // XXX Should be a component local subroutine.... - nsresult rv; - NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + // XXX Should be a component local subroutine.... + nsresult rv; + NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv); + if (NS_FAILED(rv)) return rv; - nsIURI *baseUri = nsnull; - rv = baseURL->QueryInterface(nsIURI::GetIID(), (void**)&baseUri); - if (NS_FAILED(rv)) return rv; + nsIURI *baseUri = nsnull; + rv = baseURL->QueryInterface(nsIURI::GetIID(), (void**)&baseUri); + if (NS_FAILED(rv)) return rv; - char *absUrlStr = nsnull; - char *baseSpec = src.ToNewCString(); - if (!baseSpec) return NS_ERROR_OUT_OF_MEMORY; - rv = service->MakeAbsolute(baseSpec, baseUri, &absUrlStr); - NS_RELEASE(baseUri); - absURL = absUrlStr; - nsCRT::free(baseSpec); - delete [] absUrlStr; + char *absUrlStr = nsnull; + char *baseSpec = src.ToNewCString(); + if (!baseSpec) return NS_ERROR_OUT_OF_MEMORY; + rv = service->MakeAbsolute(baseSpec, baseUri, &absUrlStr); + NS_RELEASE(baseUri); + absURL = absUrlStr; + nsCRT::free(baseSpec); + delete [] absUrlStr; #endif // NECKO - NS_IF_RELEASE(baseURL); + NS_IF_RELEASE(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.Append(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.Append(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); } break; } diff --git a/layout/generic/nsImageFrame.h b/layout/generic/nsImageFrame.h index a2eef83ff0c..c980e5b9cc5 100644 --- a/layout/generic/nsImageFrame.h +++ b/layout/generic/nsImageFrame.h @@ -82,7 +82,7 @@ protected: const nsPoint& aPoint, nsPoint& aResult); - void GetAnchorHREF(nsString& aResult); + PRBool GetAnchorHREF(nsString& aResult); PRIntn GetSuppress(); diff --git a/layout/html/base/src/nsImageFrame.cpp b/layout/html/base/src/nsImageFrame.cpp index 8508503faf4..ebc2ce53f7c 100644 --- a/layout/html/base/src/nsImageFrame.cpp +++ b/layout/html/base/src/nsImageFrame.cpp @@ -632,9 +632,10 @@ nsImageFrame::TranslateEventCoords(nsIPresContext& aPresContext, aResult.y = NSTwipsToIntPixels(y, t2p); } -void +PRBool nsImageFrame::GetAnchorHREF(nsString& aResult) { + PRBool status = PR_FALSE; aResult.Truncate(); // Walk up the content tree, looking for an nsIDOMAnchorElement @@ -644,12 +645,16 @@ nsImageFrame::GetAnchorHREF(nsString& aResult) nsCOMPtr anchor(do_QueryInterface(content)); if (anchor) { anchor->GetHref(aResult); + if (aResult.Length() > 0) { + status = PR_TRUE; + } break; } nsCOMPtr parent; content->GetParent(*getter_AddRefs(parent)); content = parent; } + return status; } // XXX what should clicks on transparent pixels do? @@ -715,47 +720,48 @@ nsImageFrame::HandleEvent(nsIPresContext& aPresContext, // Server side image maps use the href in a containing anchor // element to provide the basis for the destination url. nsAutoString src; - GetAnchorHREF(src); + if (GetAnchorHREF(src)) { #ifndef NECKO - nsString empty; - NS_MakeAbsoluteURL(baseURL, empty, src, absURL); + nsString empty; + NS_MakeAbsoluteURL(baseURL, empty, src, absURL); #else - // XXX Should be a component local subroutine.... - nsresult rv; - NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + // XXX Should be a component local subroutine.... + nsresult rv; + NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv); + if (NS_FAILED(rv)) return rv; - nsIURI *baseUri = nsnull; - rv = baseURL->QueryInterface(nsIURI::GetIID(), (void**)&baseUri); - if (NS_FAILED(rv)) return rv; + nsIURI *baseUri = nsnull; + rv = baseURL->QueryInterface(nsIURI::GetIID(), (void**)&baseUri); + if (NS_FAILED(rv)) return rv; - char *absUrlStr = nsnull; - char *baseSpec = src.ToNewCString(); - if (!baseSpec) return NS_ERROR_OUT_OF_MEMORY; - rv = service->MakeAbsolute(baseSpec, baseUri, &absUrlStr); - NS_RELEASE(baseUri); - absURL = absUrlStr; - nsCRT::free(baseSpec); - delete [] absUrlStr; + char *absUrlStr = nsnull; + char *baseSpec = src.ToNewCString(); + if (!baseSpec) return NS_ERROR_OUT_OF_MEMORY; + rv = service->MakeAbsolute(baseSpec, baseUri, &absUrlStr); + NS_RELEASE(baseUri); + absURL = absUrlStr; + nsCRT::free(baseSpec); + delete [] absUrlStr; #endif // NECKO - NS_IF_RELEASE(baseURL); + NS_IF_RELEASE(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.Append(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.Append(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); } break; } diff --git a/layout/html/base/src/nsImageFrame.h b/layout/html/base/src/nsImageFrame.h index a2eef83ff0c..c980e5b9cc5 100644 --- a/layout/html/base/src/nsImageFrame.h +++ b/layout/html/base/src/nsImageFrame.h @@ -82,7 +82,7 @@ protected: const nsPoint& aPoint, nsPoint& aResult); - void GetAnchorHREF(nsString& aResult); + PRBool GetAnchorHREF(nsString& aResult); PRIntn GetSuppress();