Bug 611182 - Part 2: Correct the definition of EndOfDocument for the HTML editor in order to fix some tests which have been relying on the bogus node existing in non-empty editable documents; r=bzbarsky a=blocking-beta8+
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 11 Nov 2010 16:40:55 -0500
changeset 57480 a9f682f84cab0340bf96ca0f04003fa8531586c2
parent 57479 ff35e522f880a6bb6c08b7b9e36747c157e7fcce
child 57481 54d00e3411ab46ca27d20bfe9528aebcc10bcb32
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersbzbarsky, blocking-beta8
bugs611182
milestone2.0b8pre
Bug 611182 - Part 2: Correct the definition of EndOfDocument for the HTML editor in order to fix some tests which have been relying on the bogus node existing in non-empty editable documents; r=bzbarsky a=blocking-beta8+
docshell/test/navigation/test_bug386782.html
editor/libeditor/base/nsEditor.cpp
editor/libeditor/html/nsHTMLEditor.h
--- a/docshell/test/navigation/test_bug386782.html
+++ b/docshell/test/navigation/test_bug386782.html
@@ -28,17 +28,17 @@ https://bugzilla.mozilla.org/show_bug.cg
         expectedBodyBeforeEdit: '<p>designModeDocument</p>',
         expectedBodyAfterEdit:  '<p>EDITED designModeDocument</p>',
         expectedBodyAfterSecondEdit: '<p>EDITED TWICE designModeDocument</p>',
       },
       {
         // <html><body contentEditable="true"><p>contentEditable</p></body></html>
         url: 'data:text/html;charset=utf-8,<html><body contentEditable="true"><p>contentEditable</p></body></html>',
         name: 'contentEditableNavigate',
-        expectedBodyBeforeEdit: '<br><p>contentEditable</p>',
+        expectedBodyBeforeEdit: '<p>contentEditable</p>',
         expectedBodyAfterEdit:  'EDITED <br><p>contentEditable</p>',
         expectedBodyAfterSecondEdit: 'EDITED TWICE <br><p>contentEditable</p>',
       }
     ];
     
     var gTestNum = -1;
     var gTest = null;
     
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -1071,23 +1071,37 @@ nsEditor::EndOfDocument()
   res = GetSelection(getter_AddRefs(selection)); 
   NS_ENSURE_SUCCESS(res, res); 
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); 
   
   // get the root element 
   nsIDOMElement *rootElement = GetRoot(); 
   NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER); 
 
-  // get the length of the rot element 
-  PRUint32 len; 
-  res = GetLengthOfDOMNode(rootElement, len); 
+  nsCOMPtr<nsIDOMNode> node = do_QueryInterface(rootElement);
+  nsCOMPtr<nsIDOMNode> child;
+  NS_ASSERTION(node, "Invalid root element");
+
+  do {
+    node->GetLastChild(getter_AddRefs(child));
+
+    if (child) {
+      if (IsContainer(child)) {
+        node = child;
+      } else {
+        break;
+      }
+    }
+  } while (child);
+
+  PRUint32 length = 0;
+  res = GetLengthOfDOMNode(node, length);
   NS_ENSURE_SUCCESS(res, res);
 
-  // set the selection to after the last child of the root element 
-  return selection->Collapse(rootElement, (PRInt32)len); 
+  return selection->Collapse(node, (PRInt32)length);
 } 
   
 NS_IMETHODIMP
 nsEditor::GetDocumentModified(PRBool *outDocModified)
 {
   NS_ENSURE_TRUE(outDocModified, NS_ERROR_NULL_POINTER);
 
   PRInt32  modCount = 0;
--- a/editor/libeditor/html/nsHTMLEditor.h
+++ b/editor/libeditor/html/nsHTMLEditor.h
@@ -143,17 +143,17 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
 
 
            nsHTMLEditor();
   virtual  ~nsHTMLEditor();
 
   /* ------------ nsPlaintextEditor overrides -------------- */
   NS_IMETHOD GetIsDocumentEditable(PRBool *aIsDocumentEditable);
-  NS_IMETHODIMP BeginningOfDocument();
+  NS_IMETHOD BeginningOfDocument();
   virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
   virtual already_AddRefed<nsIContent> GetFocusedContent();
   virtual PRBool IsActiveInDOMWindow();
   virtual already_AddRefed<nsPIDOMEventTarget> GetPIDOMEventTarget();
   virtual already_AddRefed<nsIContent> FindSelectionRoot(nsINode *aNode);
   virtual PRBool IsAcceptableInputEvent(nsIDOMEvent* aEvent);
 
   /* ------------ nsStubMutationObserver overrides --------- */