From 290fff915b8998caf56fc795c1d38422e41cc033 Mon Sep 17 00:00:00 2001 From: "cvshook%sicking.cc" Date: Thu, 2 Nov 2006 02:14:57 +0000 Subject: [PATCH] Bug 359121: Fix regression in editor from previous range checkins. nSDetach wasn't the same as Detach after all. r/sr=jst --- content/base/public/nsIRange.h | 12 ++++-------- content/base/src/nsRange.cpp | 18 ++++++++++++++++++ content/base/src/nsRange.h | 4 ++++ editor/libeditor/html/nsHTMLEditRules.cpp | 19 +++++++++++++++---- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/content/base/public/nsIRange.h b/content/base/public/nsIRange.h index 20e699bc8a9..2a739b5dece 100755 --- a/content/base/public/nsIRange.h +++ b/content/base/public/nsIRange.h @@ -40,7 +40,6 @@ #include "nsISupports.h" #include "nsCOMPtr.h" -#include "nsContentUtils.h" #include "nsINode.h" // IID for the nsIRange interface @@ -90,19 +89,16 @@ public: return mIsDetached; } - nsINode* GetCommonAncestor() - { - return mIsPositioned ? - nsContentUtils::GetCommonAncestor(mStartParent, mEndParent) : - nsnull; - } - PRBool Collapsed() { return mIsPositioned && mStartParent == mEndParent && mStartOffset == mEndOffset; } + virtual nsINode* GetCommonAncestor() = 0; + + virtual void Reset() = 0; + protected: nsCOMPtr mStartParent; nsCOMPtr mEndParent; diff --git a/content/base/src/nsRange.cpp b/content/base/src/nsRange.cpp index 6dcf7154c5d..f83e1ea170a 100644 --- a/content/base/src/nsRange.cpp +++ b/content/base/src/nsRange.cpp @@ -426,6 +426,24 @@ ContentOwnsRange(nsIRange* aRange, nsINode* aNode) return NS_OK; } +/****************************************************** + * nsIRange implementation + ******************************************************/ + +nsINode* +nsRange::GetCommonAncestor() +{ + return mIsPositioned ? + nsContentUtils::GetCommonAncestor(mStartParent, mEndParent) : + nsnull; +} + +void +nsRange::Reset() +{ + DoSetRange(nsnull, 0, nsnull, 0); +} + /****************************************************** * public functionality ******************************************************/ diff --git a/content/base/src/nsRange.h b/content/base/src/nsRange.h index 4aabc15cc2f..74a5d248bac 100644 --- a/content/base/src/nsRange.h +++ b/content/base/src/nsRange.h @@ -91,6 +91,10 @@ public: // nsIDOMNSRange interface NS_DECL_NSIDOMNSRANGE + // nsIRange interface + virtual nsINode* GetCommonAncestor(); + virtual void Reset(); + // nsRange interface extensions static NS_METHOD OwnerGone(nsIContent* aParentNode); diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index cbef42d006c..9faf669bf96 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -71,6 +71,7 @@ #include "nsIPrefBranch.h" #include "nsIPrefService.h" #include "nsIDOMNamedNodeMap.h" +#include "nsIRange.h" #include "nsEditorUtils.h" #include "nsWSRunObject.h" @@ -340,13 +341,15 @@ nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection) // clear out mDocChangeRange and mUtilRange if(mDocChangeRange) { - // Ignore failure code returned if the range is already detached - mDocChangeRange->Detach(); // clear out our accounting of what changed + // clear out our accounting of what changed + nsCOMPtr range = do_QueryInterface(mDocChangeRange); + range->Reset(); } if(mUtilRange) { - // Ignore failure code returned if the range is already detached - mUtilRange->Detach(); // ditto for mUtilRange. + // ditto for mUtilRange. + nsCOMPtr range = do_QueryInterface(mUtilRange); + range->Reset(); } // remember current inline styles for deletion and normal insertion operations @@ -8077,6 +8080,14 @@ nsHTMLEditRules::UpdateDocChangeRange(nsIDOMRange *aRange) // compare starts of ranges res = mDocChangeRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START, aRange, &result); + if (res == NS_ERROR_NOT_INITIALIZED) { + // This will happen is mDocChangeRange is non-null, but the range is + // uninitialized. In this case we'll set the start to aRange start. + // The same test won't be needed further down since after we've set + // the start the range will be collapsed to that point. + result = 1; + res = NS_OK; + } if (NS_FAILED(res)) return res; if (result > 0) // positive result means mDocChangeRange start is after aRange start {