From 822d2a28ff4c437e23043dc03adbb00ddde36e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Rameau?= Date: Thu, 2 Jun 2005 20:50:28 +0000 Subject: Add code to handle area tags. Fix bug #152482 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2005-06-02 Jean-François Rameau * embed/mozilla/EventContext.cpp: (EventContext::GetEventContext): Add code to handle area tags. Fix bug #152482 --- embed/mozilla/EventContext.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'embed') diff --git a/embed/mozilla/EventContext.cpp b/embed/mozilla/EventContext.cpp index 1ac345b5b..6211b36a8 100644 --- a/embed/mozilla/EventContext.cpp +++ b/embed/mozilla/EventContext.cpp @@ -43,9 +43,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -198,6 +200,7 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, nsresult rv; const PRUnichar hrefLiteral[] = {'h', 'r', 'e', 'f', '\0'}; + const PRUnichar imgLiteral[] = {'i', 'm', 'g', '\0'}; const PRUnichar typeLiteral[] = {'t', 'y', 'p', 'e', '\0'}; const PRUnichar xlinknsLiteral[] = {'h', 't', 't', 'p', ':', '/', '/','w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', @@ -284,6 +287,66 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, if (NS_FAILED(rv)) return NS_ERROR_FAILURE; SetStringProperty ("image", img); } + else if (g_ascii_strcasecmp (tag.get(), "area") == 0) + { + nsCOMPtr area = + do_QueryInterface(node, &rv); + if (NS_FAILED(rv) || !area) return NS_ERROR_FAILURE; + + // Parent node is the map itself + nsCOMPtr parentNode; + node->GetParentNode (getter_AddRefs(parentNode)); + + nsCOMPtr map = + do_QueryInterface(parentNode, &rv); + if (NS_FAILED(rv) || !area) return NS_ERROR_FAILURE; + + nsEmbedString mapName; + rv = map->GetName (mapName); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + // Now we are searching for all the images with a usemap attribute + nsCOMPtr imgs; + rv = mDOMDocument->GetElementsByTagName (nsEmbedString(imgLiteral), + getter_AddRefs (imgs)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + PRUint32 imgs_count; + rv = imgs->GetLength (&imgs_count); + if (NS_FAILED (rv)) return NS_ERROR_FAILURE; + + for (PRUint32 i = 0; i < imgs_count; i++) + { + nsCOMPtr aNode; + rv = imgs->Item (i, getter_AddRefs (aNode)); + if (NS_FAILED (rv)) continue; + + nsCOMPtr img = + do_QueryInterface(aNode, &rv); + if (NS_FAILED(rv) || !img) continue; + + nsEmbedString imgMapName; + rv = img->GetUseMap (imgMapName); + if (NS_FAILED (rv)) continue; + + // usemap always starts with # + imgMapName.Cut (0,1); + + // Check if the current image is attached to the map we are looking for + if (EphyUtils::StringEquals(imgMapName, mapName)) + { + nsEmbedString imgSrc; + rv = img->GetSrc (imgSrc); + if (NS_FAILED(rv)) continue; + + info->context |= EPHY_EMBED_CONTEXT_IMAGE; + + SetStringProperty ("image", imgSrc); + + break; + } + } + } else if (g_ascii_strcasecmp (tag.get(), "input") == 0) { CheckInput (node); -- cgit v1.2.3