diff --git a/mozilla/content/html/content/src/nsImageMapUtils.cpp b/mozilla/content/html/content/src/nsImageMapUtils.cpp
index 4fdddfdc7ed..6aa6c1bcf7d 100644
--- a/mozilla/content/html/content/src/nsImageMapUtils.cpp
+++ b/mozilla/content/html/content/src/nsImageMapUtils.cpp
@@ -56,56 +56,44 @@ nsresult nsImageMapUtils::FindImageMap(nsIDocument *aDocument,
NS_ENSURE_ARG_POINTER(aMap);
*aMap = nsnull;
- /* we used to strip the whitespace from the usemap value as a Quirk, but it was too quirky and
- didn't really work correctly - see bug 87050
- */
+ // We used to strip the whitespace from the usemap value as a Quirk,
+ // but it was too quirky and didn't really work correctly - see bug
+ // 87050
if (aUsemap.IsEmpty())
return NS_OK;
- PRInt32 hash = aUsemap.FindChar('#');
nsAString::const_iterator start, end;
+ aUsemap.BeginReading(start);
+ aUsemap.EndReading(end);
+
+ PRInt32 hash = aUsemap.FindChar('#');
if (hash > -1) {
- aUsemap.BeginReading(start);
- aUsemap.EndReading(end);
+ // aUsemap contains a '#', set start to point right after the '#'
start.advance(hash + 1);
- if (start == end)
+
+ if (start == end) {
return NS_OK; // aUsemap == "#"
+ }
}
- // At this point, if hash < 0, then there was no '#'
- // so aUsemap IS the ref. Otherwise the ref starts
- // from 'start'
-
- // NOTE!
- // I'd really like to do this, but it won't compile, and casting
- // Substring return to (const nsAString&) will cause a runtime crash.
- // Therefore, to avoid doing needless work, this pattern is replicated
- // below where we actually call functions with 'usemap' values.
- //const nsAString &usemap = (hash < 0) ? aUsemap : Substring(start, end);
+ const nsAString& usemap(Substring(start, end));
nsCOMPtr htmlDoc(do_QueryInterface(aDocument));
if (htmlDoc) {
- // See above NOTE
- if (hash < 0) {
- htmlDoc->GetImageMap(aUsemap, aMap);
- } else {
- htmlDoc->GetImageMap(Substring(start, end), aMap);
- }
+ htmlDoc->GetImageMap(usemap, aMap);
} else {
- // XHTML requires that where a name attribute was used in HTML 4.01,
- // the ID attribute must be used in XHTML. name is officially deprecated.
- // This simplifies our life becase we can simply get the map with
+ // For XHTML elements embedded in non-XHTML documents we get the
+ // map by id since XHTML requires that where a "name" attribute
+ // was used in HTML 4.01, the "id" attribute must be used in
+ // XHTML. The attribute "name" is officially deprecated. This
+ // simplifies our life becase we can simply get the map with
// getElementById().
nsCOMPtr domDoc(do_QueryInterface(aDocument));
if (domDoc) {
nsCOMPtr element;
- // See above NOTE
- if (hash < 0) {
- domDoc->GetElementById(aUsemap, getter_AddRefs(element));
- } else {
- domDoc->GetElementById(Substring(start, end), getter_AddRefs(element));
- }
+ domDoc->GetElementById(usemap, getter_AddRefs(element));
+
if (element) {
CallQueryInterface(element, aMap);
}
diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp
index ddc56680e71..04f7db6956f 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.cpp
+++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp
@@ -1138,29 +1138,38 @@ nsHTMLDocument::GetImageMap(const nsAString& aMapName,
return NS_ERROR_NULL_POINTER;
}
+ *aResult = nsnull;
+
nsAutoString name;
PRUint32 i, n = mImageMaps.Count();
for (i = 0; i < n; i++) {
nsCOMPtr map = mImageMaps[i];
- if (map && NS_SUCCEEDED(map->GetName(name))) {
- PRBool match;
+ NS_ASSERTION(map, "Null map in map list!");
- if (IsXHTML()) {
- match = name.Equals(aMapName);
- } else {
- match = name.Equals(aMapName, nsCaseInsensitiveStringComparator());
- }
+ PRBool match;
+ nsresult rv;
- if (match) {
- *aResult = map;
- NS_ADDREF(*aResult);
- return NS_OK;
- }
+ if (IsXHTML()) {
+ rv = map->GetId(name);
+
+ match = name.Equals(aMapName);
+ } else {
+ rv = map->GetName(name);
+
+ match = name.Equals(aMapName, nsCaseInsensitiveStringComparator());
+ }
+
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ if (match) {
+ *aResult = map;
+ NS_ADDREF(*aResult);
+ return NS_OK;
}
}
- return NS_ERROR_FAILURE;
+ return NS_OK;
}
NS_IMETHODIMP
diff --git a/mozilla/content/shared/src/nsImageMapUtils.cpp b/mozilla/content/shared/src/nsImageMapUtils.cpp
index 4fdddfdc7ed..6aa6c1bcf7d 100644
--- a/mozilla/content/shared/src/nsImageMapUtils.cpp
+++ b/mozilla/content/shared/src/nsImageMapUtils.cpp
@@ -56,56 +56,44 @@ nsresult nsImageMapUtils::FindImageMap(nsIDocument *aDocument,
NS_ENSURE_ARG_POINTER(aMap);
*aMap = nsnull;
- /* we used to strip the whitespace from the usemap value as a Quirk, but it was too quirky and
- didn't really work correctly - see bug 87050
- */
+ // We used to strip the whitespace from the usemap value as a Quirk,
+ // but it was too quirky and didn't really work correctly - see bug
+ // 87050
if (aUsemap.IsEmpty())
return NS_OK;
- PRInt32 hash = aUsemap.FindChar('#');
nsAString::const_iterator start, end;
+ aUsemap.BeginReading(start);
+ aUsemap.EndReading(end);
+
+ PRInt32 hash = aUsemap.FindChar('#');
if (hash > -1) {
- aUsemap.BeginReading(start);
- aUsemap.EndReading(end);
+ // aUsemap contains a '#', set start to point right after the '#'
start.advance(hash + 1);
- if (start == end)
+
+ if (start == end) {
return NS_OK; // aUsemap == "#"
+ }
}
- // At this point, if hash < 0, then there was no '#'
- // so aUsemap IS the ref. Otherwise the ref starts
- // from 'start'
-
- // NOTE!
- // I'd really like to do this, but it won't compile, and casting
- // Substring return to (const nsAString&) will cause a runtime crash.
- // Therefore, to avoid doing needless work, this pattern is replicated
- // below where we actually call functions with 'usemap' values.
- //const nsAString &usemap = (hash < 0) ? aUsemap : Substring(start, end);
+ const nsAString& usemap(Substring(start, end));
nsCOMPtr htmlDoc(do_QueryInterface(aDocument));
if (htmlDoc) {
- // See above NOTE
- if (hash < 0) {
- htmlDoc->GetImageMap(aUsemap, aMap);
- } else {
- htmlDoc->GetImageMap(Substring(start, end), aMap);
- }
+ htmlDoc->GetImageMap(usemap, aMap);
} else {
- // XHTML requires that where a name attribute was used in HTML 4.01,
- // the ID attribute must be used in XHTML. name is officially deprecated.
- // This simplifies our life becase we can simply get the map with
+ // For XHTML elements embedded in non-XHTML documents we get the
+ // map by id since XHTML requires that where a "name" attribute
+ // was used in HTML 4.01, the "id" attribute must be used in
+ // XHTML. The attribute "name" is officially deprecated. This
+ // simplifies our life becase we can simply get the map with
// getElementById().
nsCOMPtr domDoc(do_QueryInterface(aDocument));
if (domDoc) {
nsCOMPtr element;
- // See above NOTE
- if (hash < 0) {
- domDoc->GetElementById(aUsemap, getter_AddRefs(element));
- } else {
- domDoc->GetElementById(Substring(start, end), getter_AddRefs(element));
- }
+ domDoc->GetElementById(usemap, getter_AddRefs(element));
+
if (element) {
CallQueryInterface(element, aMap);
}