From 09384ee7f30037bdbcc6fb706632cd8a589fa752 Mon Sep 17 00:00:00 2001 From: "cvshook%sicking.cc" Date: Wed, 25 Oct 2006 21:53:03 +0000 Subject: [PATCH] bug 358073: Kill useless/redundant functions on nsIDOMNSRange. r/sr=jst git-svn-id: svn://10.0.0.236/trunk@214136 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsIRangeUtils.h | 2 - mozilla/content/base/src/nsRange.cpp | 173 ++---------------- mozilla/content/base/src/nsRange.h | 20 +- .../dom/public/idl/range/nsIDOMNSRange.idl | 15 +- .../editor/libeditor/html/nsHTMLEditRules.cpp | 13 +- 5 files changed, 27 insertions(+), 196 deletions(-) diff --git a/mozilla/content/base/public/nsIRangeUtils.h b/mozilla/content/base/public/nsIRangeUtils.h index 381c86fe8f2..4c6d70118df 100644 --- a/mozilla/content/base/public/nsIRangeUtils.h +++ b/mozilla/content/base/public/nsIRangeUtils.h @@ -60,8 +60,6 @@ public: NS_IMETHOD_(PRInt32) ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1, nsIDOMNode* aParent2, PRInt32 aOffset2) = 0; - NS_IMETHOD_(PRBool) IsNodeIntersectsRange(nsIContent* aNode, nsIDOMRange* aRange) = 0; - NS_IMETHOD CompareNodeToRange(nsIContent* aNode, nsIDOMRange* aRange, PRBool *outNodeBefore, diff --git a/mozilla/content/base/src/nsRange.cpp b/mozilla/content/base/src/nsRange.cpp index a717e1831da..6dcf7154c5d 100644 --- a/mozilla/content/base/src/nsRange.cpp +++ b/mozilla/content/base/src/nsRange.cpp @@ -79,58 +79,8 @@ nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aInstancePtrResult); } \ PR_END_MACRO -// Utility routine to create a pair of dom points to represent -// the start and end locations of a single node. Return false -// if we dont' succeed. -// NOTE! This does NOT follow XPCOM rules in that it doesn't -// addref |outParent| -static PRBool -GetNodeBracketPoints(nsIContent* aNode, - nsINode** outParent, - PRInt32* outStartOffset, - PRInt32* outEndOffset); - static nsresult ContentOwnsRange(nsIRange* aRange, nsINode* aNode); -// Utility routine to detect if a content node intersects a range -/* static */ -PRBool -nsRange::IsNodeIntersectsRange(nsIContent* aNode, nsIDOMRange* aRange) -{ - // create a pair of dom points that expresses location of node: - // NODE(start), NODE(end) - // Let incoming range be: - // {RANGE(start), RANGE(end)} - // if (RANGE(start) < NODE(end)) and (RANGE(end) > NODE(start)) - // then the Node intersect the Range. - - nsCOMPtr range = do_QueryInterface(aRange); - NS_ENSURE_TRUE(range, PR_FALSE); - - nsINode *parent, *rangeStartParent, *rangeEndParent; - PRInt32 nodeStart, nodeEnd, rangeStartOffset, rangeEndOffset; - - // gather up the dom point info - if (!GetNodeBracketPoints(aNode, &parent, &nodeStart, &nodeEnd)) - return PR_FALSE; - - rangeStartParent = range->GetStartParent(); - rangeEndParent = range->GetEndParent(); - - if (!rangeStartParent || !rangeEndParent) { - return PR_FALSE; - } - - rangeStartOffset = range->StartOffset(); - rangeEndOffset = range->EndOffset(); - - // False if range start is after node end or range end is before node start - return nsContentUtils::ComparePoints(rangeStartParent, rangeStartOffset, - parent, nodeEnd) < 0 && - nsContentUtils::ComparePoints(parent, nodeStart, - rangeEndParent, rangeEndOffset) > 0; -} - // Utility routine to detect if a content node is completely contained in a range // If outNodeBefore is returned true, then the node starts before the range does. // If outNodeAfter is returned true, then the node ends after the range does. @@ -157,22 +107,29 @@ nsRange::CompareNodeToRange(nsIContent* aNode, nsIDOMRange* aRange, if (!range->IsPositioned()) return NS_ERROR_UNEXPECTED; - nsINode *parent, *rangeStartParent, *rangeEndParent; - PRInt32 nodeStart, nodeEnd, rangeStartOffset, rangeEndOffset; - // gather up the dom point info - if (!GetNodeBracketPoints(aNode, &parent, &nodeStart, &nodeEnd)) - return NS_ERROR_FAILURE; - - rangeStartParent = range->GetStartParent(); - rangeEndParent = range->GetEndParent(); - - if (!rangeStartParent || !rangeEndParent) { - return NS_ERROR_FAILURE; + PRInt32 nodeStart, nodeEnd; + nsINode* parent = aNode->GetNodeParent(); + if (!parent) { + // can't make a parent/offset pair to represent start or + // end of the root node, becasue it has no parent. + // so instead represent it by (node,0) and (node,numChildren) + parent = aNode; + nodeStart = 0; + nodeEnd = aNode->GetChildCount(); + if (!nodeEnd) { + return NS_ERROR_FAILURE; + } + } + else { + nodeStart = parent->IndexOf(aNode); + nodeEnd = nodeStart + 1; } - rangeStartOffset = range->StartOffset(); - rangeEndOffset = range->EndOffset(); + nsINode* rangeStartParent = range->GetStartParent(); + nsINode* rangeEndParent = range->GetEndParent(); + PRInt32 rangeStartOffset = range->StartOffset(); + PRInt32 rangeEndOffset = range->EndOffset(); // is RANGE(start) <= NODE(start) ? *outNodeBefore = nsContentUtils::ComparePoints(rangeStartParent, @@ -186,37 +143,6 @@ nsRange::CompareNodeToRange(nsIContent* aNode, nsIDOMRange* aRange, return NS_OK; } -// Utility routine to create a pair of dom points to represent -// the start and end locations of a single node. Return false -// if we dont' succeed. -// NOTE! This does NOT follow XPCOM rules in that it doesn't -// addref |outParent| -static PRBool -GetNodeBracketPoints(nsIContent* aNode, - nsINode** outParent, - PRInt32* outStartOffset, - PRInt32* outEndOffset) -{ - nsINode* parent = aNode->GetNodeParent(); - - if (!parent) { - // can't make a parent/offset pair to represent start or - // end of the root node, becasue it has no parent. - // so instead represent it by (node,0) and (node,numChildren) - *outParent = aNode; - *outStartOffset = 0; - *outEndOffset = aNode->GetChildCount(); - if (!*outEndOffset) - return PR_FALSE; - } - else { - *outParent = parent; - *outStartOffset = parent->IndexOf(aNode); - *outEndOffset = *outStartOffset + 1; - } - return PR_TRUE; -} - /****************************************************** * non members ******************************************************/ @@ -255,12 +181,6 @@ nsRangeUtils::ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1, return nsContentUtils::ComparePoints(parent1, aOffset1, parent2, aOffset2); } -NS_IMETHODIMP_(PRBool) -nsRangeUtils::IsNodeIntersectsRange(nsIContent* aNode, nsIDOMRange* aRange) -{ - return nsRange::IsNodeIntersectsRange( aNode, aRange); -} - NS_IMETHODIMP nsRangeUtils::CompareNodeToRange(nsIContent* aNode, nsIDOMRange* aRange, PRBool *outNodeBefore, PRBool *outNodeAfter) @@ -354,59 +274,6 @@ nsRange::ComparePoint(nsIDOMNode* aParent, PRInt32 aOffset, PRInt16* aResult) return NS_OK; } -NS_IMETHODIMP -nsRange::IntersectsNode(nsIDOMNode* aNode, PRBool* aReturn) -{ - nsCOMPtr cont = do_QueryInterface(aNode); - if (!cont) { - *aReturn = PR_FALSE; - return NS_ERROR_UNEXPECTED; - } - - *aReturn = IsNodeIntersectsRange(cont, this); - - return NS_OK; -} - -// HOW does the node intersect the range? -NS_IMETHODIMP -nsRange::CompareNode(nsIDOMNode* aNode, PRUint16* aReturn) -{ - *aReturn = 0; - - PRBool nodeBefore, nodeAfter; - nsCOMPtr content = do_QueryInterface(aNode); - NS_ENSURE_TRUE(content, NS_ERROR_UNEXPECTED); - - nsresult rv = CompareNodeToRange(content, this, &nodeBefore, &nodeAfter); - NS_ENSURE_SUCCESS(rv, rv); - - // nodeBefore -> range start after node start, i.e. node starts before range. - // nodeAfter -> range end before node end, i.e. node ends after range. - // But I know that I get nodeBefore && !nodeAfter when the node is - // entirely inside the selection! This doesn't make sense. - if (nodeBefore && !nodeAfter) - *aReturn = nsIDOMNSRange::NODE_BEFORE; // May or may not intersect - else if (!nodeBefore && nodeAfter) - *aReturn = nsIDOMNSRange::NODE_AFTER; // May or may not intersect - else if (nodeBefore && nodeAfter) - *aReturn = nsIDOMNSRange::NODE_BEFORE_AND_AFTER; // definitely intersects - else - *aReturn = nsIDOMNSRange::NODE_INSIDE; // definitely intersects - - return NS_OK; -} - -nsresult -nsRange::NSDetach() -{ - DoSetRange(nsnull, 0, nsnull, 0); - - return NS_OK; -} - - - /****************************************************** * Private helper routines ******************************************************/ diff --git a/mozilla/content/base/src/nsRange.h b/mozilla/content/base/src/nsRange.h index 89ddea7a33a..4aabc15cc2f 100644 --- a/mozilla/content/base/src/nsRange.h +++ b/mozilla/content/base/src/nsRange.h @@ -65,8 +65,6 @@ public: NS_IMETHOD_(PRInt32) ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1, nsIDOMNode* aParent2, PRInt32 aOffset2); - NS_IMETHOD_(PRBool) IsNodeIntersectsRange(nsIContent* aNode, nsIDOMRange* aRange); - NS_IMETHOD CompareNodeToRange(nsIContent* aNode, nsIDOMRange* aRange, PRBool *outNodeBefore, @@ -90,17 +88,8 @@ public: // nsIDOMRange interface NS_DECL_NSIDOMRANGE -/*BEGIN nsIDOMNSRange interface implementations*/ - NS_IMETHOD CreateContextualFragment(const nsAString& aFragment, - nsIDOMDocumentFragment** aReturn); - NS_IMETHOD IsPointInRange(nsIDOMNode* aParent, PRInt32 aOffset, - PRBool* aResult); - NS_IMETHOD ComparePoint(nsIDOMNode* aParent, PRInt32 aOffset, - PRInt16* aResult); - NS_IMETHOD IntersectsNode(nsIDOMNode* aNode, PRBool* aReturn); - NS_IMETHOD CompareNode(nsIDOMNode* aNode, PRUint16* aReturn); - NS_IMETHOD NSDetach(); -/*END nsIDOMNSRange interface implementations*/ + // nsIDOMNSRange interface + NS_DECL_NSIDOMNSRANGE // nsRange interface extensions @@ -122,11 +111,6 @@ private: nsRange& operator=(const nsRange&); public: - /** - * Utility routine to detect if a content node intersects a range - */ - static PRBool IsNodeIntersectsRange(nsIContent* aNode, nsIDOMRange* aRange); - /****************************************************************************** * Utility routine to detect if a content node starts before a range and/or * ends after a range. If neither it is contained inside the range. diff --git a/mozilla/dom/public/idl/range/nsIDOMNSRange.idl b/mozilla/dom/public/idl/range/nsIDOMNSRange.idl index b30e6a3cc50..ac735aecd48 100644 --- a/mozilla/dom/public/idl/range/nsIDOMNSRange.idl +++ b/mozilla/dom/public/idl/range/nsIDOMNSRange.idl @@ -39,7 +39,7 @@ #include "domstubs.idl" -[scriptable, uuid(a6cf90f2-15b3-11d2-932e-00805f8add32)] +[scriptable, uuid(59188642-23b4-41d6-bde1-302c3906d1f0)] interface nsIDOMNSRange : nsISupports { nsIDOMDocumentFragment createContextualFragment(in DOMString fragment); @@ -54,17 +54,4 @@ interface nsIDOMNSRange : nsISupports // 1 if point is after range // Sort of a strcmp for ranges. short comparePoint(in nsIDOMNode parent, in long offset); - - // Does the node intersect the range? - boolean intersectsNode(in nsIDOMNode n); - - // HOW does the node intersect the range? Four possible values: - const unsigned short NODE_BEFORE = 0; - const unsigned short NODE_AFTER = 1; - const unsigned short NODE_BEFORE_AND_AFTER = 2; - const unsigned short NODE_INSIDE = 3; - unsigned short compareNode(in nsIDOMNode n); - - // now what the %&*!@ is this? - void nSDetach(); }; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp index 833c8171c61..146268df264 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp @@ -338,20 +338,15 @@ nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection) mDidDeleteSelection = PR_FALSE; // clear out mDocChangeRange and mUtilRange - nsCOMPtr nsrange; if(mDocChangeRange) { - nsrange = do_QueryInterface(mDocChangeRange); - if (!nsrange) - return NS_ERROR_FAILURE; - nsrange->NSDetach(); // clear out our accounting of what changed + // Ignore failure code returned if the range is already detached + mDocChangeRange->Detach(); // clear out our accounting of what changed } if(mUtilRange) { - nsrange = do_QueryInterface(mUtilRange); - if (!nsrange) - return NS_ERROR_FAILURE; - nsrange->NSDetach(); // ditto for mUtilRange. + // Ignore failure code returned if the range is already detached + mUtilRange->Detach(); // ditto for mUtilRange. } // remember current inline styles for deletion and normal insertion operations