Bug 688547 - Use Element* for nsIDocument::{SetSubDocumentFor,FindContentForSubDocument}; r=peterv
authorMs2ger <ms2ger@gmail.com>
Sat, 29 Oct 2011 22:22:19 +0200
changeset 80763 df4b49fffc78e660b42d78cab43ff866a0307c84
parent 80762 82469275d2fe348f5fdd7d11be33682ca9d88b0b
child 80781 945f64763a706a8c02e9cb84ef6483f06548d367
child 80790 91c2f92fcca1d5809dd8ab025c9eca6da65cd4eb
push id434
push userclegnitto@mozilla.com
push dateWed, 21 Dec 2011 12:10:54 +0000
treeherdermozilla-beta@bddb6ed8dd47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs688547
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 688547 - Use Element* for nsIDocument::{SetSubDocumentFor,FindContentForSubDocument}; r=peterv
content/base/public/nsIDocument.h
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
layout/base/nsDocumentViewer.cpp
layout/printing/nsPrintPreviewListener.cpp
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -121,18 +121,18 @@ class Loader;
 
 namespace dom {
 class Link;
 class Element;
 } // namespace dom
 } // namespace mozilla
 
 #define NS_IDOCUMENT_IID \
-{ 0x6f88f88d, 0xbd36, 0x4406, \
-  { 0xb9, 0xc6, 0xb4, 0xd2, 0x22, 0x90, 0x4b, 0x28 } }
+{ 0x3d24831e, 0x2a2b, 0x42f4, \
+  { 0x9d, 0x98, 0x17, 0x60, 0x18, 0xab, 0x6e, 0xfb } }
 
 // Flag for AddStyleSheet().
 #define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
 
 // Document states
 
 // RTL locale: specific to the XUL localedir attribute
 #define NS_DOCUMENT_STATE_RTL_LOCALE              NS_DEFINE_EVENT_STATE_MACRO(0)
@@ -506,28 +506,28 @@ public:
   void SetParentDocument(nsIDocument* aParent)
   {
     mParentDocument = aParent;
   }
 
   /**
    * Set the sub document for aContent to aSubDoc.
    */
-  virtual nsresult SetSubDocumentFor(nsIContent *aContent,
+  virtual nsresult SetSubDocumentFor(Element* aContent,
                                      nsIDocument* aSubDoc) = 0;
 
   /**
    * Get the sub document for aContent
    */
   virtual nsIDocument *GetSubDocumentFor(nsIContent *aContent) const = 0;
 
   /**
    * Find the content node for which aDocument is a sub document.
    */
-  virtual nsIContent *FindContentForSubDocument(nsIDocument *aDocument) const = 0;
+  virtual Element* FindContentForSubDocument(nsIDocument* aDocument) const = 0;
 
   /**
    * Return the root element for this document.
    */
   Element *GetRootElement() const;
 
 protected:
   virtual Element *GetRootElementInternal() const = 0;
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -445,29 +445,29 @@ nsIdentifierMapEntry::RemoveNameElement(
 }
 
 // Helper structs for the content->subdoc map
 
 class SubDocMapEntry : public PLDHashEntryHdr
 {
 public:
   // Both of these are strong references
-  nsIContent *mKey; // must be first, to look like PLDHashEntryStub
+  Element *mKey; // must be first, to look like PLDHashEntryStub
   nsIDocument *mSubDocument;
 };
 
 struct FindContentData
 {
   FindContentData(nsIDocument *aSubDoc)
     : mSubDocument(aSubDoc), mResult(nsnull)
   {
   }
 
   nsISupports *mSubDocument;
-  nsIContent *mResult;
+  Element *mResult;
 };
 
 
 /**
  * A struct that holds all the information about a radio group.
  */
 struct nsRadioGroupStruct
 {
@@ -3253,37 +3253,36 @@ SubDocClearEntry(PLDHashTable *table, PL
 
 static bool
 SubDocInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry, const void *key)
 {
   SubDocMapEntry *e =
     const_cast<SubDocMapEntry *>
               (static_cast<const SubDocMapEntry *>(entry));
 
-  e->mKey = const_cast<nsIContent *>
-                      (static_cast<const nsIContent *>(key));
+  e->mKey = const_cast<Element*>(static_cast<const Element*>(key));
   NS_ADDREF(e->mKey);
 
   e->mSubDocument = nsnull;
   return true;
 }
 
 nsresult
-nsDocument::SetSubDocumentFor(nsIContent *aContent, nsIDocument* aSubDoc)
-{
-  NS_ENSURE_TRUE(aContent, NS_ERROR_UNEXPECTED);
+nsDocument::SetSubDocumentFor(Element* aElement, nsIDocument* aSubDoc)
+{
+  NS_ENSURE_TRUE(aElement, NS_ERROR_UNEXPECTED);
 
   if (!aSubDoc) {
     // aSubDoc is nsnull, remove the mapping
 
     if (mSubDocuments) {
       SubDocMapEntry *entry =
         static_cast<SubDocMapEntry*>
-                   (PL_DHashTableOperate(mSubDocuments, aContent,
-                                            PL_DHASH_LOOKUP));
+                   (PL_DHashTableOperate(mSubDocuments, aElement,
+                                         PL_DHASH_LOOKUP));
 
       if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
         PL_DHashTableRawRemove(mSubDocuments, entry);
       }
     }
   } else {
     if (!mSubDocuments) {
       // Create a new hashtable
@@ -3305,18 +3304,18 @@ nsDocument::SetSubDocumentFor(nsIContent
       if (!mSubDocuments) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
     }
 
     // Add a mapping to the hash table
     SubDocMapEntry *entry =
       static_cast<SubDocMapEntry*>
-                 (PL_DHashTableOperate(mSubDocuments, aContent,
-                                          PL_DHASH_ADD));
+                 (PL_DHashTableOperate(mSubDocuments, aElement,
+                                       PL_DHASH_ADD));
 
     if (!entry) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     if (entry->mSubDocument) {
       entry->mSubDocument->SetParentDocument(nsnull);
 
@@ -3331,21 +3330,21 @@ nsDocument::SetSubDocumentFor(nsIContent
   }
 
   return NS_OK;
 }
 
 nsIDocument*
 nsDocument::GetSubDocumentFor(nsIContent *aContent) const
 {
-  if (mSubDocuments) {
+  if (mSubDocuments && aContent->IsElement()) {
     SubDocMapEntry *entry =
       static_cast<SubDocMapEntry*>
-                 (PL_DHashTableOperate(mSubDocuments, aContent,
-                                          PL_DHASH_LOOKUP));
+                 (PL_DHashTableOperate(mSubDocuments, aContent->AsElement(),
+                                       PL_DHASH_LOOKUP));
 
     if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
       return entry->mSubDocument;
     }
   }
 
   return nsnull;
 }
@@ -3361,17 +3360,17 @@ FindContentEnumerator(PLDHashTable *tabl
     data->mResult = entry->mKey;
 
     return PL_DHASH_STOP;
   }
 
   return PL_DHASH_NEXT;
 }
 
-nsIContent*
+Element*
 nsDocument::FindContentForSubDocument(nsIDocument *aDocument) const
 {
   NS_ENSURE_TRUE(aDocument, nsnull);
 
   if (!mSubDocuments) {
     return nsnull;
   }
 
@@ -8503,18 +8502,17 @@ nsDocument::RequestFullScreen(Element* a
     // is not visible there.
     mFullScreenElement = aElement;
     // Set the full-screen state on the element, so the css-pseudo class
     // applies to the element.
     nsEventStateManager::SetFullScreenState(mFullScreenElement, true);
     nsIDocument* child = this;
     nsIDocument* parent;
     while (parent = child->GetParentDocument()) {
-      nsIContent* content = parent->FindContentForSubDocument(child);
-      nsCOMPtr<Element> element(do_QueryInterface(content));
+      Element* element = parent->FindContentForSubDocument(child);
       // Containing frames also need the css-pseudo class applied.
       nsEventStateManager::SetFullScreenState(element, true);
       static_cast<nsDocument*>(parent)->mFullScreenElement = element;
       child = parent;
     }
   }
 
   // Set all documents in hierarchy to full-screen mode.
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -583,20 +583,20 @@ public:
    * shared among multiple presentation shell's).
    */
   virtual nsresult CreateShell(nsPresContext* aContext,
                                nsIViewManager* aViewManager,
                                nsStyleSet* aStyleSet,
                                nsIPresShell** aInstancePtrResult);
   virtual void DeleteShell();
 
-  virtual nsresult SetSubDocumentFor(nsIContent *aContent,
+  virtual nsresult SetSubDocumentFor(Element* aContent,
                                      nsIDocument* aSubDoc);
-  virtual nsIDocument* GetSubDocumentFor(nsIContent *aContent) const;
-  virtual nsIContent* FindContentForSubDocument(nsIDocument *aDocument) const;
+  virtual nsIDocument* GetSubDocumentFor(nsIContent* aContent) const;
+  virtual Element* FindContentForSubDocument(nsIDocument *aDocument) const;
   virtual Element* GetRootElementInternal() const;
 
   /**
    * Get the style sheets owned by this document.
    * These are ordered, highest priority last
    */
   virtual PRInt32 GetNumberOfStyleSheets() const;
   virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex) const;
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -652,20 +652,21 @@ DocumentViewerImpl::SyncParentSubDocMap(
 
     if (parent_win) {
       nsCOMPtr<nsIDOMDocument> dom_doc;
       parent_win->GetDocument(getter_AddRefs(dom_doc));
 
       nsCOMPtr<nsIDocument> parent_doc(do_QueryInterface(dom_doc));
 
       if (parent_doc) {
-        if (mDocument && parent_doc->GetSubDocumentFor(content) != mDocument) {
+        if (mDocument &&
+            parent_doc->GetSubDocumentFor(content) != mDocument) {
           mDocument->SuppressEventHandling(parent_doc->EventHandlingSuppressed());
         }
-        return parent_doc->SetSubDocumentFor(content, mDocument);
+        return parent_doc->SetSubDocumentFor(content->AsElement(), mDocument);
       }
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/layout/printing/nsPrintPreviewListener.cpp
+++ b/layout/printing/nsPrintPreviewListener.cpp
@@ -33,28 +33,31 @@
  * 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 ***** */
 
 #include "nsPrintPreviewListener.h"
-#include "nsIContent.h"
+
+#include "mozilla/dom/Element.h"
 #include "nsIDOMWindow.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMKeyEvent.h"
 #include "nsIDOMNSEvent.h"
 #include "nsIDocument.h"
 #include "nsIDocShell.h"
 #include "nsPresContext.h"
 #include "nsFocusManager.h"
 #include "nsLiteralString.h"
 
+using namespace mozilla;
+
 NS_IMPL_ISUPPORTS1(nsPrintPreviewListener, nsIDOMEventListener)
 
 
 //
 // nsPrintPreviewListener ctor
 //
 nsPrintPreviewListener::nsPrintPreviewListener (nsIDOMEventTarget* aTarget)
   : mEventTarget(aTarget)
@@ -189,18 +192,18 @@ nsPrintPreviewListener::HandleEvent(nsID
 
           nsIDocument* parentDoc = doc->GetParentDocument();
           NS_ASSERTION(parentDoc, "no parent document");
 
           nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(parentDoc->GetWindow());
 
           nsIFocusManager* fm = nsFocusManager::GetFocusManager();
           if (fm && win) {
-            nsIContent* fromContent = parentDoc->FindContentForSubDocument(doc);
-            nsCOMPtr<nsIDOMElement> from = do_QueryInterface(fromContent);
+            dom::Element* fromElement = parentDoc->FindContentForSubDocument(doc);
+            nsCOMPtr<nsIDOMElement> from = do_QueryInterface(fromElement);
 
             bool forward = (action == eEventAction_Tab);
             nsCOMPtr<nsIDOMElement> result;
             fm->MoveFocus(win, from,
                           forward ? nsIFocusManager::MOVEFOCUS_FORWARD :
                                     nsIFocusManager::MOVEFOCUS_BACKWARD,
                           nsIFocusManager::FLAG_BYKEY, getter_AddRefs(result));
           }