From 3f918b6ada7e9401b166d2e4650edf6e5ed235ed Mon Sep 17 00:00:00 2001 From: Uri Bernstein Date: Mon, 13 Oct 2008 00:11:51 +0200 Subject: [PATCH] Bug 459588: Kill OLD_SELECTION code. r+sr=roc. --- layout/generic/nsSelection.cpp | 449 ++++----------------------------- 1 file changed, 50 insertions(+), 399 deletions(-) diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index f267b30e3322..ba847f95b603 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -117,10 +117,6 @@ static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID); static NS_DEFINE_IID(kCContentIteratorCID, NS_CONTENTITERATOR_CID); static NS_DEFINE_IID(kCSubtreeIteratorCID, NS_SUBTREEITERATOR_CID); -#undef OLD_SELECTION -#undef OLD_TABLE_SELECTION - - //PROTOTYPES class nsSelectionIterator; class nsFrameSelection; @@ -309,10 +305,6 @@ private: nsresult getTableCellLocationFromRange(nsIDOMRange *aRange, PRInt32 *aSelectionType, PRInt32 *aRow, PRInt32 *aCol); nsresult addTableCellRange(nsIDOMRange *aRange, PRBool *aDidAddRange, PRInt32 *aOutIndex); -#ifdef OLD_SELECTION - NS_IMETHOD FixupSelectionPoints(nsIDOMRange *aRange, nsDirection *aDir, PRBool *aFixupState); -#endif //OLD_SELECTION - // These are the ranges inside this selection. They are kept sorted in order // of DOM position of start and end, respectively (both of these arrays // should have the same contents, but possibly in different orders). @@ -377,7 +369,6 @@ private: nsDirection mDirection; SelectionType mType; PRPackedBool mTrueDirection; - PRPackedBool mFixupState; }; // Stack-class to turn on/off selection batching for table selection @@ -3548,7 +3539,6 @@ nsTypedSelection::nsTypedSelection() , mDirection(eDirNext) , mType(nsISelectionController::SELECTION_NORMAL) , mTrueDirection(PR_FALSE) - , mFixupState(PR_FALSE) { } @@ -3558,7 +3548,6 @@ nsTypedSelection::nsTypedSelection(nsFrameSelection *aList) , mDirection(eDirNext) , mType(nsISelectionController::SELECTION_NORMAL) , mTrueDirection(PR_FALSE) - , mFixupState(PR_FALSE) { } @@ -4611,7 +4600,6 @@ nsTypedSelection::selectFrames(nsPresContext* aPresContext, { //NOTE: eSpreadDown is now IGNORED. Selected state is set only for given frame frame->SetSelected(aPresContext, nsnull, aFlags, eSpreadDown, mType); -#ifndef OLD_TABLE_SELECTION if (mFrameSelection->GetTableCellSelection()) { nsITableCellLayout *tcl = nsnull; @@ -4621,7 +4609,6 @@ nsTypedSelection::selectFrames(nsPresContext* aPresContext, return NS_OK; } } -#endif //OLD_TABLE_SELECTION } // Now iterated through the child frames and set them while (!aInnerIter->IsDone()) @@ -5653,242 +5640,6 @@ nsTypedSelection::GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn) return NS_OK; } -#ifdef OLD_SELECTION - -//may change parameters may not. -//return NS_ERROR_FAILURE if invalid new selection between anchor and passed in parameters -NS_IMETHODIMP -nsTypedSelection::FixupSelectionPoints(nsIDOMRange *aRange , nsDirection *aDir, PRBool *aFixupState) -{ - if (!aRange || !aFixupState) - return NS_ERROR_NULL_POINTER; - *aFixupState = PR_FALSE; - nsresult res; - - //startNode is the beginning or "anchor" of the range - //end Node is the end or "focus of the range - nsCOMPtr startNode; - nsCOMPtr endNode; - PRInt32 startOffset; - PRInt32 endOffset; - nsresult result; - if (*aDir == eDirNext) - { - if (NS_FAILED(GetOriginalAnchorPoint(getter_AddRefs(startNode), &startOffset))) - { - aRange->GetStartParent(getter_AddRefs(startNode)); - aRange->GetStartOffset(&startOffset); - } - aRange->GetEndParent(getter_AddRefs(endNode)); - aRange->GetEndOffset(&endOffset); - } - else - { - if (NS_FAILED(GetOriginalAnchorPoint(getter_AddRefs(startNode), &startOffset))) - { - aRange->GetEndParent(getter_AddRefs(startNode)); - aRange->GetEndOffset(&startOffset); - } - aRange->GetStartParent(getter_AddRefs(endNode)); - aRange->GetStartOffset(&endOffset); - } - if (!startNode || !endNode) - return NS_ERROR_FAILURE; - - // if end node is a tbody then all bets are off we cannot select "rows" - nsIAtom *atom = GetTag(endNode); - if (atom == nsGkAtoms::tbody) - return NS_ERROR_FAILURE; //cannot select INTO row node ony cells - - //get common parent - nsCOMPtr parent; - nsCOMPtr subRange; - NS_NewRange(getter_AddRefs(subRange)); - if (!subRange) return NS_ERROR_OUT_OF_MEMORY - - result = subRange->SetStart(startNode,startOffset); - if (NS_FAILED(result)) - return result; - result = subRange->SetEnd(endNode,endOffset); - if (NS_FAILED(result)) - { - result = subRange->SetEnd(startNode,startOffset); - if (NS_FAILED(result)) - return result; - result = subRange->SetStart(endNode,endOffset); - if (NS_FAILED(result)) - return result; - } - - res = subRange->GetCommonParent(getter_AddRefs(parent)); - if (NS_FAILED(res) || !parent) - return res; - - //look for dest. if you see a cell you are in "cell mode" - //if you see a table you select "whole" table - - //src first - nsCOMPtr tempNode; - nsCOMPtr tempNode2; - PRBool cellMode = PR_FALSE; - PRBool dirtystart = PR_FALSE; - PRBool dirtyend = PR_FALSE; - if (startNode != endNode) - { - if (parent != startNode) - { - result = startNode->GetParentNode(getter_AddRefs(tempNode)); - if (NS_FAILED(result) || !tempNode) - return NS_ERROR_FAILURE; - while (tempNode != parent) - { - atom = GetTag(tempNode); - if (atom == nsGkAtoms::table) //select whole table if in cell mode, wait for cell - { - result = ParentOffset(tempNode, getter_AddRefs(startNode), &startOffset); - if (NS_FAILED(result)) - return NS_ERROR_FAILURE; - if (*aDir == eDirPrevious) //select after - startOffset++; - dirtystart = PR_TRUE; - cellMode = PR_FALSE; - } - else if (atom == nsGkAtoms::td || - atom == nsGkAtoms::th) //you are in "cell" mode put selection to end of cell - { - cellMode = PR_TRUE; - result = ParentOffset(tempNode, getter_AddRefs(startNode), &startOffset); - if (NS_FAILED(result)) - return result; - if (*aDir == eDirPrevious) //select after - startOffset++; - dirtystart = PR_TRUE; - } - result = tempNode->GetParentNode(getter_AddRefs(tempNode2)); - if (NS_FAILED(result) || !tempNode2) - return NS_ERROR_FAILURE; - tempNode = tempNode2; - } - } - - //now for dest node - if (parent != endNode) - { - result = endNode->GetParentNode(getter_AddRefs(tempNode)); - PRBool found = !cellMode; - if (NS_FAILED(result) || !tempNode) - return NS_ERROR_FAILURE; - while (tempNode != parent) - { - atom = GetTag(tempNode); - if (atom == nsGkAtoms::table) //select whole table if in cell mode, wait for cell - { - if (!cellMode) - { - result = ParentOffset(tempNode, getter_AddRefs(endNode), &endOffset); - if (NS_FAILED(result)) - return result; - if (*aDir == eDirNext) //select after - endOffset++; - dirtyend = PR_TRUE; - } - else - found = PR_FALSE; //didn't find the right cell yet - } - else if (atom == nsGkAtoms::td || - atom == nsGkAtoms::th) //you are in "cell" mode put selection to end of cell - { - result = ParentOffset(tempNode, getter_AddRefs(endNode), &endOffset); - if (NS_FAILED(result)) - return result; - if (*aDir == eDirNext) //select after - endOffset++; - found = PR_TRUE; - dirtyend = PR_TRUE; - } - result = tempNode->GetParentNode(getter_AddRefs(tempNode2)); - if (NS_FAILED(result) || !tempNode2) - return NS_ERROR_FAILURE; - tempNode = tempNode2; - } - if (!found) - return NS_ERROR_FAILURE; - } - } - if (*aDir == eDirNext) - { - if (FetchAnchorNode() == startNode.get() && FetchFocusNode() == endNode.get() && - FetchAnchorOffset() == startOffset && FetchFocusOffset() == endOffset) - { - *aFixupState = PR_FALSE; - return NS_ERROR_FAILURE;//nothing to do - } - } - else - { - if (FetchAnchorNode() == endNode.get() && FetchFocusNode() == startNode.get() && - FetchAnchorOffset() == endOffset && FetchFocusOffset() == startOffset) - { - *aFixupState = PR_FALSE; - return NS_ERROR_FAILURE;//nothing to do - } - } - if (mFixupState && !dirtyend && !dirtystart)//no mor fixup! all bets off - { - dirtystart = PR_TRUE;//force a reset of anchor positions - dirtystart = PR_TRUE; - *aFixupState = PR_TRUE;//redraw all selection here - mFixupState = PR_FALSE;//no more fixup for next time - } - else - if ((dirtystart || dirtyend) && *aDir != mDirection) //fixup took place but new direction all bets are off - { - *aFixupState = PR_TRUE; - //mFixupState = PR_FALSE; - } - else - if (dirtystart && (FetchAnchorNode() != startNode.get() || FetchAnchorOffset() != startOffset)) - { - *aFixupState = PR_TRUE; - mFixupState = PR_TRUE; - } - else - if (dirtyend && (FetchFocusNode() != endNode.get() || FetchFocusOffset() != endOffset)) - { - *aFixupState = PR_TRUE; - mFixupState = PR_TRUE; - } - else - { - mFixupState = dirtystart || dirtyend; - *aFixupState = PR_FALSE; - } - if (dirtystart || dirtyend){ - if (*aDir == eDirNext) - { - if (NS_FAILED(aRange->SetStart(startNode,startOffset)) || NS_FAILED(aRange->SetEnd(endNode, endOffset))) - { - *aDir = eDirPrevious; - aRange->SetStart(endNode, endOffset); - aRange->SetEnd(startNode, startOffset); - } - } - else - { - if (NS_FAILED(aRange->SetStart(endNode,endOffset)) || NS_FAILED(aRange->SetEnd(startNode, startOffset))) - { - *aDir = eDirNext; - aRange->SetStart(startNode, startOffset); - aRange->SetEnd(endNode, endOffset); - } - } - } - return NS_OK; -} -#endif //OLD_SELECTION - - - NS_IMETHODIMP nsTypedSelection::SetOriginalAnchorPoint(nsIDOMNode *aNode, PRInt32 aOffset) @@ -5914,7 +5665,6 @@ nsTypedSelection::SetOriginalAnchorPoint(nsIDOMNode *aNode, PRInt32 aOffset) } - NS_IMETHODIMP nsTypedSelection::GetOriginalAnchorPoint(nsIDOMNode **aNode, PRInt32 *aOffset) { @@ -6010,6 +5760,8 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) return NS_ERROR_FAILURE;//same node nothing to do! res = mAnchorFocusRange->CloneRange(getter_AddRefs(range)); + if (NS_FAILED(res)) + return res; //range = mAnchorFocusRange; nsCOMPtr startNode; @@ -6022,11 +5774,7 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) range->GetStartOffset(&startOffset); range->GetEndOffset(&endOffset); - nsDirection dir = GetDirection(); - PRBool fixupState = PR_FALSE; //if there was a previous fixup the optimal drawing erasing will NOT work - if (NS_FAILED(res)) - return res; NS_NewRange(getter_AddRefs(difRange)); //compare anchor to old cursor. @@ -6061,21 +5809,7 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res |= difRange->SetStart(FetchFocusNode(), FetchFocusOffset()); if (NS_FAILED(res)) return res; -#ifdef OLD_SELECTION - res = FixupSelectionPoints(range, &dir, &fixupState); -#endif - if (NS_FAILED(res)) - return res; - if (fixupState) - { -#ifdef OLD_SELECTION - selectFrames(mAnchorFocusRange, PR_FALSE); - selectFrames(range, PR_TRUE); -#endif - } - else{ - selectFrames(presContext, difRange , PR_TRUE); - } + selectFrames(presContext, difRange , PR_TRUE); res = CopyRangeToAnchorFocus(range); if (NS_FAILED(res)) return res; @@ -6086,18 +5820,7 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res = range->SetStart(aParentNode,aOffset); if (NS_FAILED(res)) return res; -#ifdef OLD_SELECTION - res = FixupSelectionPoints(range, &dir, &fixupState); - if (NS_FAILED(res)) - return res; - if (fixupState) //unselect previous and select new state has changed to not fixed up - { - selectFrames(mAnchorFocusRange, PR_FALSE); - selectFrames(range, PR_TRUE); - } - else -#endif - selectFrames(presContext, range, PR_TRUE); + selectFrames(presContext, range, PR_TRUE); res = CopyRangeToAnchorFocus(range); if (NS_FAILED(res)) return res; @@ -6112,30 +5835,14 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res = range->SetEnd(aParentNode,aOffset); if (NS_FAILED(res)) return res; -#ifdef OLD_SELECTION - dir = eDirNext; - res = FixupSelectionPoints(range, &dir, &fixupState); -#endif + res = CopyRangeToAnchorFocus(range); if (NS_FAILED(res)) return res; - if (fixupState) //unselect previous and select new state has changed to not fixed up - { -#ifdef OLD_SELECTION - selectFrames(mAnchorFocusRange, PR_FALSE); - selectFrames(range, PR_TRUE); -#endif - } - else - { - res = CopyRangeToAnchorFocus(range); - if (NS_FAILED(res)) - return res; - RemoveItem(mAnchorFocusRange); - selectFrames(presContext, difRange, PR_FALSE);//deselect now if fixup succeeded - AddItem(mAnchorFocusRange); - difRange->SetEnd(FetchEndParent(range),FetchEndOffset(range)); - selectFrames(presContext, difRange, PR_TRUE);//must reselect last node maybe more if fixup did something - } + RemoveItem(mAnchorFocusRange); + selectFrames(presContext, difRange, PR_FALSE); // deselect now + AddItem(mAnchorFocusRange); + difRange->SetEnd(FetchEndParent(range),FetchEndOffset(range)); + selectFrames(presContext, difRange, PR_TRUE); // must reselect last node maybe more } else if (result1 >= 0 && result3 <= 0) {//1,a,2 or 1a,2 or 1,a2 or 1a2 if (GetDirection() == eDirPrevious){ @@ -6147,41 +5854,27 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res = range->SetEnd(aParentNode,aOffset); if (NS_FAILED(res)) return res; -#ifdef OLD_SELECTION - res = FixupSelectionPoints(range, &dir, &fixupState); - if (NS_FAILED(res)) - return res; - - if (fixupState) //unselect previous and select new state has changed to not fixed up - { - selectFrames(mAnchorFocusRange, PR_FALSE); - selectFrames(range, PR_TRUE); + if (FetchFocusNode() != FetchAnchorNode() || FetchFocusOffset() != FetchAnchorOffset() ){//if collapsed diff dont do anything + res = difRange->SetStart(FetchFocusNode(), FetchFocusOffset()); + res |= difRange->SetEnd(FetchAnchorNode(), FetchAnchorOffset()); + if (NS_FAILED(res)) + return res; + res = CopyRangeToAnchorFocus(range); + if (NS_FAILED(res)) + return res; + //deselect from 1 to a + RemoveItem(mAnchorFocusRange); + selectFrames(presContext, difRange , PR_FALSE); + AddItem(mAnchorFocusRange); } - else -#endif + else { - if (FetchFocusNode() != FetchAnchorNode() || FetchFocusOffset() != FetchAnchorOffset() ){//if collapsed diff dont do anything - res = difRange->SetStart(FetchFocusNode(), FetchFocusOffset()); - res |= difRange->SetEnd(FetchAnchorNode(), FetchAnchorOffset()); - if (NS_FAILED(res)) - return res; - res = CopyRangeToAnchorFocus(range); - if (NS_FAILED(res)) - return res; - //deselect from 1 to a - RemoveItem(mAnchorFocusRange); - selectFrames(presContext, difRange , PR_FALSE); - AddItem(mAnchorFocusRange); - } - else - { - res = CopyRangeToAnchorFocus(range); - if (NS_FAILED(res)) - return res; - } - //select from a to 2 - selectFrames(presContext, range , PR_TRUE); + res = CopyRangeToAnchorFocus(range); + if (NS_FAILED(res)) + return res; } + //select from a to 2 + selectFrames(presContext, range , PR_TRUE); } else if (result2 <= 0 && result3 >= 0) {//1,2,a or 12,a or 1,2a or 12a //deselect from 1 to 2 @@ -6194,29 +5887,14 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) if (NS_FAILED(res)) return res; -#ifdef OLD_SELECTION - res = FixupSelectionPoints(range, &dir, &fixupState); -#endif + res = CopyRangeToAnchorFocus(range); if (NS_FAILED(res)) return res; - if (fixupState) //unselect previous and select new state has changed to not fixed up - { -#ifdef OLD_SELECTION - selectFrames(mAnchorFocusRange, PR_FALSE); - selectFrames(range, PR_TRUE); -#endif - } - else - { - res = CopyRangeToAnchorFocus(range); - if (NS_FAILED(res)) - return res; - RemoveItem(mAnchorFocusRange); - selectFrames(presContext, difRange , PR_FALSE); - AddItem(mAnchorFocusRange); - difRange->SetStart(FetchStartParent(range),FetchStartOffset(range)); - selectFrames(presContext, difRange, PR_TRUE);//must reselect last node - } + RemoveItem(mAnchorFocusRange); + selectFrames(presContext, difRange , PR_FALSE); + AddItem(mAnchorFocusRange); + difRange->SetStart(FetchStartParent(range),FetchStartOffset(range)); + selectFrames(presContext, difRange, PR_TRUE);//must reselect last node } else if (result3 >= 0 && result1 <= 0) {//2,a,1 or 2a,1 or 2,a1 or 2a1 if (GetDirection() == eDirNext){ @@ -6226,38 +5904,25 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) res = range->SetStart(aParentNode,aOffset); if (NS_FAILED(res)) return res; -#ifdef OLD_SELECTION - res = FixupSelectionPoints(range, &dir, &fixupState); - if (NS_FAILED(res)) - return res; - if (fixupState) //unselect previous and select new state has changed to not fixed up - { - selectFrames(mAnchorFocusRange, PR_FALSE); - selectFrames(range, PR_TRUE); + //deselect from a to 1 + if (FetchFocusNode() != FetchAnchorNode() || FetchFocusOffset() != FetchAnchorOffset() ){//if collapsed diff dont do anything + res = difRange->SetStart(FetchAnchorNode(), FetchAnchorOffset()); + res |= difRange->SetEnd(FetchFocusNode(), FetchFocusOffset()); + res |= CopyRangeToAnchorFocus(range); + if (NS_FAILED(res)) + return res; + RemoveItem(mAnchorFocusRange); + selectFrames(presContext, difRange, 0); + AddItem(mAnchorFocusRange); } else -#endif { - //deselect from a to 1 - if (FetchFocusNode() != FetchAnchorNode() || FetchFocusOffset() != FetchAnchorOffset() ){//if collapsed diff dont do anything - res = difRange->SetStart(FetchAnchorNode(), FetchAnchorOffset()); - res |= difRange->SetEnd(FetchFocusNode(), FetchFocusOffset()); - res = CopyRangeToAnchorFocus(range); - if (NS_FAILED(res)) - return res; - RemoveItem(mAnchorFocusRange); - selectFrames(presContext, difRange, 0); - AddItem(mAnchorFocusRange); - } - else - { - res = CopyRangeToAnchorFocus(range); - if (NS_FAILED(res)) - return res; - } - //select from 2 to a - selectFrames(presContext, range , PR_TRUE); + res = CopyRangeToAnchorFocus(range); + if (NS_FAILED(res)) + return res; } + //select from 2 to a + selectFrames(presContext, range , PR_TRUE); } else if (result2 >= 0 && result1 >= 0) {//2,1,a or 21,a or 2,1a or 21a //select from 2 to 1 @@ -6270,21 +5935,7 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) if (NS_FAILED(res)) return res; -#ifdef OLD_SELECTION - res = FixupSelectionPoints(range, &dir, &fixupState); -#endif - if (NS_FAILED(res)) - return res; - if (fixupState) //unselect previous and select new state has changed to not fixed up - { -#ifdef OLD_SELECTION - selectFrames(mAnchorFocusRange, PR_FALSE); - selectFrames(range, PR_TRUE); -#endif - } - else { - selectFrames(presContext, difRange, PR_TRUE); - } + selectFrames(presContext, difRange, PR_TRUE); res = CopyRangeToAnchorFocus(range); if (NS_FAILED(res)) return res;