Bug 581644 - Make nsHTMLDocument::GetImageMap return dom::Element; r=peterv
authorMs2ger <ms2ger@gmail.com>
Mon, 28 Mar 2011 12:51:59 -0400
changeset 64096 9df21e557f713c3d104d262f3be8418614f223fa
parent 64095 f8aa658b3d39e6247e616f2960b82d297216c37a
child 64097 d3721cc3e30574a48fded750155920d78c3f3c5e
push idunknown
push userunknown
push dateunknown
reviewerspeterv
bugs581644
milestone2.2a1pre
Bug 581644 - Make nsHTMLDocument::GetImageMap return dom::Element; r=peterv
accessible/src/base/nsAccessibilityService.cpp
content/html/content/src/nsImageMapUtils.cpp
content/html/document/src/nsHTMLDocument.cpp
content/html/document/src/nsHTMLDocument.h
content/html/document/src/nsIHTMLDocument.h
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -95,16 +95,17 @@
 #endif
 
 #ifndef DISABLE_XFORMS_HOOKS
 #include "nsXFormsFormControlsAccessible.h"
 #include "nsXFormsWidgetsAccessible.h"
 #endif
 
 #include "mozilla/FunctionTimer.h"
+#include "mozilla/dom/Element.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessibilityService
 ////////////////////////////////////////////////////////////////////////////////
 
 nsAccessibilityService *nsAccessibilityService::gAccessibilityService = nsnull;
 PRBool nsAccessibilityService::gIsShutdown = PR_TRUE;
 
@@ -270,17 +271,17 @@ nsAccessibilityService::CreateHTMLImageA
   if (htmlDoc) {
     nsAutoString mapElmName;
     aContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::usemap,
                       mapElmName);
 
     if (!mapElmName.IsEmpty()) {
       if (mapElmName.CharAt(0) == '#')
         mapElmName.Cut(0,1);
-      mapElm = htmlDoc->GetImageMap(mapElmName);
+      mapElm = do_QueryInterface(htmlDoc->GetImageMap(mapElmName));
     }
   }
 
   nsCOMPtr<nsIWeakReference> weakShell(do_GetWeakReference(aPresShell));
   nsAccessible* accessible = mapElm ?
     new nsHTMLImageMapAccessible(aContent, weakShell, mapElm) :
     new nsHTMLImageAccessibleWrap(aContent, weakShell);
   NS_IF_ADDREF(accessible);
--- a/content/html/content/src/nsImageMapUtils.cpp
+++ b/content/html/content/src/nsImageMapUtils.cpp
@@ -34,21 +34,23 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsCOMPtr.h"
 #include "nsIDocument.h"
-#include "nsIContent.h"
+#include "mozilla/dom/Element.h"
 #include "nsIHTMLDocument.h"
 #include "nsIDOMHTMLMapElement.h"
 #include "nsImageMapUtils.h"
 
+using namespace mozilla::dom;
+
 /*static*/
 already_AddRefed<nsIDOMHTMLMapElement>
 nsImageMapUtils::FindImageMap(nsIDocument *aDocument, 
                               const nsAString &aUsemap)
 {
   if (!aDocument)
     return nsnull;
 
@@ -74,27 +76,27 @@ nsImageMapUtils::FindImageMap(nsIDocumen
   } else {
     return nsnull;
   }
 
   const nsAString& usemap = Substring(start, end);
 
   nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(aDocument));
   if (htmlDoc) {
-    nsIDOMHTMLMapElement* map = htmlDoc->GetImageMap(usemap);
-    NS_IF_ADDREF(map);
-    return map;
+    nsCOMPtr<nsIDOMHTMLMapElement> map =
+      do_QueryInterface(htmlDoc->GetImageMap(usemap));
+    return map.forget();
   } 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().
-    nsIContent *element = aDocument->GetElementById(usemap);
+    Element* element = aDocument->GetElementById(usemap);
 
     if (element) {
       nsIDOMHTMLMapElement* map;
       CallQueryInterface(element, &map);
       return map;
     }
   }
   
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -1153,45 +1153,32 @@ nsHTMLDocument::EndLoad()
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::SetTitle(const nsAString& aTitle)
 {
   return nsDocument::SetTitle(aTitle);
 }
 
-nsIDOMHTMLMapElement *
+Element*
 nsHTMLDocument::GetImageMap(const nsAString& aMapName)
 {
   if (!mImageMaps) {
     mImageMaps = new nsContentList(this, kNameSpaceID_XHTML, nsGkAtoms::map, nsGkAtoms::map);
   }
 
   nsAutoString name;
   PRUint32 i, n = mImageMaps->Length(PR_TRUE);
   for (i = 0; i < n; ++i) {
-    nsCOMPtr<nsIDOMHTMLMapElement> map(
-      do_QueryInterface(mImageMaps->GetNodeAt(i)));
-
-    PRBool match;
-    nsresult rv;
-
-    rv = map->GetId(name);
-    NS_ENSURE_SUCCESS(rv, nsnull);
-
-    match = name.Equals(aMapName);
-    if (!match) {
-      rv = map->GetName(name);
-      NS_ENSURE_SUCCESS(rv, nsnull);
-
-      match = name.Equals(aMapName, nsCaseInsensitiveStringComparator());
-    }
-
-    if (match) {
-      return map;
+    nsIContent* map = mImageMaps->GetNodeAt(i);
+    if (map->AttrValueIs(kNameSpaceID_None, nsGkAtoms::id, aMapName,
+                         eCaseMatters) ||
+        map->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, aMapName,
+                         eIgnoreCase)) {
+      return map->AsElement();
     }
   }
 
   return NULL;
 }
 
 void
 nsHTMLDocument::SetCompatibilityMode(nsCompatibility aMode)
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -38,17 +38,16 @@
 #ifndef nsHTMLDocument_h___
 #define nsHTMLDocument_h___
 
 #include "nsDocument.h"
 #include "nsIHTMLDocument.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMNSHTMLDocument.h"
 #include "nsIDOMHTMLBodyElement.h"
-#include "nsIDOMHTMLMapElement.h"
 #include "nsIDOMHTMLCollection.h"
 #include "nsIScriptElement.h"
 #include "jsapi.h"
 #include "nsTArray.h"
 
 #include "pldhash.h"
 #include "nsIHttpChannel.h"
 #include "nsHTMLStyleSheet.h"
@@ -101,17 +100,17 @@ public:
                                      PRBool aReset = PR_TRUE,
                                      nsIContentSink* aSink = nsnull);
   virtual void StopDocumentLoad();
 
   virtual void BeginLoad();
 
   virtual void EndLoad();
 
-  virtual nsIDOMHTMLMapElement *GetImageMap(const nsAString& aMapName);
+  virtual mozilla::dom::Element* GetImageMap(const nsAString& aMapName);
 
   virtual void SetCompatibilityMode(nsCompatibility aMode);
 
   virtual PRBool IsWriting()
   {
     return mWriteLevel != PRUint32(0);
   }
 
--- a/content/html/document/src/nsIHTMLDocument.h
+++ b/content/html/document/src/nsIHTMLDocument.h
@@ -29,49 +29,50 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-#ifndef nsIHTMLDocument_h___
-#define nsIHTMLDocument_h___
+
+#ifndef nsIHTMLDocument_h
+#define nsIHTMLDocument_h
 
 #include "nsISupports.h"
 #include "nsCompatibility.h"
-#include "nsContentList.h"
 
-class nsIImageMap;
-class nsString;
-class nsIDOMNodeList;
-class nsIDOMHTMLCollection;
-class nsIDOMHTMLMapElement;
-class nsHTMLStyleSheet;
-class nsIStyleSheet;
+class nsIDOMHTMLFormElement;
 class nsIContent;
-class nsIDOMHTMLBodyElement;
 class nsIScriptElement;
 class nsIEditor;
+class nsContentList;
+class nsWrapperCache;
+
+namespace mozilla {
+namespace dom {
+class Element;
+} // namespace dom
+} // namespace mozilla
 
 #define NS_IHTMLDOCUMENT_IID \
-{ 0x840cacc9, 0x1956, 0x4987, \
-  { 0x80, 0x6e, 0xc6, 0xab, 0x19, 0x1b, 0x92, 0xd2 } }
+{ 0xe43a4bfd, 0xff5a, 0x40b0, \
+  { 0x8c, 0x31, 0x24, 0xac, 0xe8, 0x15, 0xda, 0xf2 } }
 
 
 /**
  * HTML document extensions to nsIDocument.
  */
 class nsIHTMLDocument : public nsISupports
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IHTMLDOCUMENT_IID)
 
-  virtual nsIDOMHTMLMapElement *GetImageMap(const nsAString& aMapName) = 0;
+  virtual mozilla::dom::Element* GetImageMap(const nsAString& aMapName) = 0;
 
   /**
    * Set compatibility mode for this document
    */
   virtual void SetCompatibilityMode(nsCompatibility aMode) = 0;
 
   virtual nsresult ResolveName(const nsAString& aName,
                                nsIDOMHTMLFormElement *aForm,
@@ -184,9 +185,9 @@ public:
 
   virtual void SetIsXHTML(PRBool aXHTML) = 0;
 
   virtual void SetDocWriteDisabled(PRBool aDisabled) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIHTMLDocument, NS_IHTMLDOCUMENT_IID)
 
-#endif /* nsIHTMLDocument_h___ */
+#endif /* nsIHTMLDocument_h */