Fixing bug 203345. Making image maps work correctly in XHTML documents. r=heikki@netscape.com, sr=bzbarsky@mit.edu
git-svn-id: svn://10.0.0.236/trunk@143012 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -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<nsIHTMLDocument> 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<nsIDOMDocument> domDoc(do_QueryInterface(aDocument));
|
||||
if (domDoc) {
|
||||
nsCOMPtr<nsIDOMElement> 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);
|
||||
}
|
||||
|
||||
@@ -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<nsIDOMHTMLMapElement> 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
|
||||
|
||||
@@ -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<nsIHTMLDocument> 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<nsIDOMDocument> domDoc(do_QueryInterface(aDocument));
|
||||
if (domDoc) {
|
||||
nsCOMPtr<nsIDOMElement> 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user