Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Private Member Functions
nsImageMapUtils Class Reference

#include <nsImageMapUtils.h>

List of all members.

Static Public Member Functions

static already_AddRefed
< nsIDOMHTMLMapElement
FindImageMap (nsIDocument *aDocument, const nsAString &aUsemap)
 FindImageMap tries to find a map element from a document.

Private Member Functions

 nsImageMapUtils ()
 ~nsImageMapUtils ()

Detailed Description

Definition at line 50 of file nsImageMapUtils.h.

Constructor & Destructor Documentation

Member Function Documentation

already_AddRefed< nsIDOMHTMLMapElement > nsImageMapUtils::FindImageMap ( nsIDocument aDocument,
const nsAString &  aUsemap 
) [static]

FindImageMap tries to find a map element from a document.

aDocument[in] The document to be searched.
aUsemap[in] The value of the usemap attribute.
The first found (if any) map element, addrefed.

Definition at line 51 of file nsImageMapUtils.cpp.

  if (!aDocument)
    return 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

  if (aUsemap.IsEmpty())
    return nsnull;

  nsAString::const_iterator start, end;

  PRInt32 hash = aUsemap.FindChar('#');
  if (hash > -1) {
    // aUsemap contains a '#', set start to point right after the '#'
    start.advance(hash + 1);

    if (start == end) {
      return nsnull; // aUsemap == "#"

  const nsAString& usemap = Substring(start, end);

  nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(aDocument));
  if (htmlDoc) {
    nsIDOMHTMLMapElement* map = htmlDoc->GetImageMap(usemap);
    return map;
  } else {
    // 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;
      domDoc->GetElementById(usemap, getter_AddRefs(element));

      if (element) {
        nsIDOMHTMLMapElement* map;
        CallQueryInterface(element, &map);
        return map;
  return nsnull;

Here is the call graph for this function:

Here is the caller graph for this function:

The documentation for this class was generated from the following files: