diff --git a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp index 812be18b3c5..5e862c3df94 100644 --- a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp @@ -319,7 +319,6 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString & &rangeStartHint, &rangeEndHint); NS_ENSURE_SUCCESS(res, res); - // make a list of what nodes in docFrag we need to move nsCOMPtr nodeList; res = CreateListOfNodesToPaste(fragmentAsNode, address_of(nodeList), rangeStartHint, rangeEndHint); @@ -1107,7 +1106,7 @@ NS_IMETHODIMP nsHTMLEditor::DoDrag(nsIDOMEvent *aDragEvent) nsCOMPtr domdoc; rv = GetDocument(getter_AddRefs(domdoc)); if (NS_FAILED(rv)) return rv; - + nsCOMPtr doc = do_QueryInterface(domdoc); if (doc) { @@ -1721,8 +1720,6 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *aNSRange, res = aNSRange->CreateContextualFragment(aInputString, getter_AddRefs(docfrag)); NS_ENSURE_SUCCESS(res, res); *outFragNode = do_QueryInterface(docfrag); - res = StripFormattingNodes(*outFragNode); - NS_ENSURE_SUCCESS(res, res); if (contextfrag) { diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.h b/mozilla/editor/libeditor/html/nsHTMLEditRules.h index 1a1942ac631..ce407a1a8fa 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditRules.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.h @@ -154,6 +154,11 @@ protected: nsCOMPtr IsInListItem(nsIDOMNode *aNode); nsresult ReturnInHeader(nsISelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset); nsresult ReturnInParagraph(nsISelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset, PRBool *aCancel, PRBool *aHandled); + nsresult SplitParagraph(nsIDOMNode *aPara, + nsIDOMNode *aBRNode, + nsISelection *aSelection, + nsCOMPtr *aSelNode, + PRInt32 *aOffset); nsresult ReturnInListItem(nsISelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset); nsresult AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection); nsresult RemovePartOfBlock(nsIDOMNode *aBlock, @@ -183,6 +188,7 @@ protected: PRBool AtStartOfBlock(nsIDOMNode *aNode, PRInt32 aOffset, nsIDOMNode *aBlock); PRBool AtEndOfBlock(nsIDOMNode *aNode, PRInt32 aOffset, nsIDOMNode *aBlock); #endif + nsresult NormalizeSelection(nsISelection *inSelection); nsresult GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt32 aOffset, PRInt32 actionID, nsCOMPtr *outNode, PRInt32 *outOffset); nsresult GetPromotedRanges(nsISelection *inSelection, diff --git a/mozilla/editor/libeditor/html/nsWSRunObject.cpp b/mozilla/editor/libeditor/html/nsWSRunObject.cpp index 246c46f47dd..5b86138162f 100644 --- a/mozilla/editor/libeditor/html/nsWSRunObject.cpp +++ b/mozilla/editor/libeditor/html/nsWSRunObject.cpp @@ -76,12 +76,15 @@ static PRBool IsInlineNode(nsIDOMNode* node) nsWSRunObject::nsWSRunObject(nsHTMLEditor *aEd, nsIDOMNode *aNode, PRInt32 aOffset) : mNode(aNode) ,mOffset(aOffset) +,mPRE(PR_FALSE) ,mStartNode() ,mStartOffset(0) ,mStartReason(0) +,mStartReasonNode() ,mEndNode() ,mEndOffset(0) ,mEndReason(0) +,mEndReasonNode() ,mFirstNBSPNode() ,mFirstNBSPOffset(0) ,mLastNBSPNode() @@ -456,6 +459,17 @@ nsWSRunObject::DeleteWSBackward() NS_ENSURE_SUCCESS(res, res); if (!point.mTextNode) return NS_OK; // nothing to delete + if (mPRE) // easy case, preformatted ws + { + if (nsCRT::IsAsciiSpace(point.mChar) || (point.mChar == nbsp)) + { + nsCOMPtr node(do_QueryInterface(point.mTextNode)); + PRInt32 startOffset = point.mOffset; + PRInt32 endOffset = point.mOffset+1; + return DeleteChars(node, startOffset, node, endOffset); + } + } + // callers job to insure that previous char is really ws. // If it is normal ws, we need to delete the whole run if (nsCRT::IsAsciiSpace(point.mChar)) @@ -500,6 +514,17 @@ nsWSRunObject::DeleteWSForward() NS_ENSURE_SUCCESS(res, res); if (!point.mTextNode) return NS_OK; // nothing to delete + if (mPRE) // easy case, preformatted ws + { + if (nsCRT::IsAsciiSpace(point.mChar) || (point.mChar == nbsp)) + { + nsCOMPtr node(do_QueryInterface(point.mTextNode)); + PRInt32 startOffset = point.mOffset; + PRInt32 endOffset = point.mOffset+1; + return DeleteChars(node, startOffset, node, endOffset); + } + } + // callers job to insure that next char is really ws. // If it is normal ws, we need to delete the whole run if (nsCRT::IsAsciiSpace(point.mChar)) @@ -547,6 +572,7 @@ nsWSRunObject::PriorVisibleNode(nsIDOMNode *aNode, if (!aNode || !outVisNode || !outVisOffset || !outType) return NS_ERROR_NULL_POINTER; + *outType = eNone; WSFragment *run; nsresult res = FindRun(aNode, aOffset, &run, PR_FALSE); @@ -707,6 +733,7 @@ nsWSRunObject::GetWSNodes() mStartNode = mNode; mStartOffset = pos+1; mStartReason = eText; + mStartReasonNode = mNode; break; } // as we look backwards update our earliest found nbsp @@ -736,6 +763,7 @@ nsWSRunObject::GetWSNodes() { start.GetPoint(mStartNode, mStartOffset); mStartReason = eOtherBlock; + mStartReasonNode = priorNode; } else if (mHTMLEditor->IsTextNode(priorNode)) { @@ -768,6 +796,7 @@ nsWSRunObject::GetWSNodes() mStartNode = priorNode; mStartOffset = pos+1; mStartReason = eText; + mStartReasonNode = priorNode; break; } // as we look backwards update our earliest found nbsp @@ -793,6 +822,7 @@ nsWSRunObject::GetWSNodes() mStartReason = eBreak; else mStartReason = eSpecial; + mStartReasonNode = priorNode; } } else @@ -800,6 +830,7 @@ nsWSRunObject::GetWSNodes() // no prior node means we exhausted blockParent start.GetPoint(mStartNode, mStartOffset); mStartReason = eThisBlock; + mStartReasonNode = blockParent; } } @@ -826,6 +857,7 @@ nsWSRunObject::GetWSNodes() mEndNode = mNode; mEndOffset = pos; mEndReason = eText; + mEndReasonNode = mNode; break; } // as we look forwards update our latest found nbsp @@ -856,6 +888,7 @@ nsWSRunObject::GetWSNodes() // we encountered a new block. therefore no more ws. end.GetPoint(mEndNode, mEndOffset); mEndReason = eOtherBlock; + mEndReasonNode = nextNode; } else if (mHTMLEditor->IsTextNode(nextNode)) { @@ -889,6 +922,7 @@ nsWSRunObject::GetWSNodes() mEndNode = nextNode; mEndOffset = pos; mEndReason = eText; + mEndReasonNode = nextNode; break; } // as we look forwards update our latest found nbsp @@ -912,9 +946,10 @@ nsWSRunObject::GetWSNodes() // serves as a terminator to ws runs. end.GetPoint(mEndNode, mEndOffset); if (nsTextEditUtils::IsBreak(nextNode)) - mStartReason = eBreak; + mEndReason = eBreak; else - mStartReason = eSpecial; + mEndReason = eSpecial; + mEndReasonNode = nextNode; } } else @@ -922,6 +957,7 @@ nsWSRunObject::GetWSNodes() // no next node means we exhausted blockParent end.GetPoint(mEndNode, mEndOffset); mEndReason = eThisBlock; + mEndReasonNode = blockParent; } } @@ -934,11 +970,11 @@ nsWSRunObject::GetRuns() ClearRuns(); // handle some easy cases first - - // if we are surrounded by text or special, it's all one + mHTMLEditor->IsPreformatted(mNode, &mPRE); + // if it's preformatedd, or if we are surrounded by text or special, it's all one // big normal ws run - if ( ((mStartReason == eText) || (mStartReason == eSpecial)) && - ((mEndReason == eText) || (mEndReason == eSpecial) || (mEndReason == eBreak)) ) + if ( mPRE || (((mStartReason == eText) || (mStartReason == eSpecial)) && + ((mEndReason == eText) || (mEndReason == eSpecial) || (mEndReason == eBreak))) ) { return MakeSingleWSRun(eNormalWS); } @@ -1611,7 +1647,6 @@ nsWSRunObject::GetCharAfter(WSPoint &aPoint, WSPoint *outPoint) if (aPoint.mOffset < len) { *outPoint = aPoint; - outPoint->mOffset; outPoint->mChar = GetCharAt(aPoint.mTextNode, aPoint.mOffset); } else if (idx < (PRInt32)(numNodes-1)) @@ -1684,7 +1719,7 @@ nsWSRunObject::ConvertToNBSP(WSPoint aPoint) // next, find range of ws it will replace nsCOMPtr startNode, endNode; - PRInt32 startOffset, endOffset; + PRInt32 startOffset=0, endOffset=0; res = GetAsciiWSBounds(eAfter, node, aPoint.mOffset+1, address_of(startNode), &startOffset, address_of(endNode), &endOffset); @@ -1708,7 +1743,7 @@ nsWSRunObject::GetAsciiWSBounds(PRInt16 aDir, nsIDOMNode *aNode, PRInt32 aOffset return NS_ERROR_NULL_POINTER; nsCOMPtr startNode, endNode; - PRInt32 startOffset, endOffset; + PRInt32 startOffset=0, endOffset=0; nsresult res = NS_OK; diff --git a/mozilla/editor/libeditor/html/nsWSRunObject.h b/mozilla/editor/libeditor/html/nsWSRunObject.h index 9c1db3cb799..394a1aab1a5 100644 --- a/mozilla/editor/libeditor/html/nsWSRunObject.h +++ b/mozilla/editor/libeditor/html/nsWSRunObject.h @@ -320,13 +320,16 @@ class nsWSRunObject PRInt32 mOffset; // the offset passed to our contructor // together, the above represent the point at which we are building up ws info. + PRBool mPRE; // true if we are in preformatted whitespace context nsCOMPtr mStartNode; // node/offet where ws starts PRInt32 mStartOffset; // ... PRInt16 mStartReason; // reason why ws starts (eText, eOtherBlock, etc) + nsCOMPtr mStartReasonNode;// the node that implicated by start reason nsCOMPtr mEndNode; // node/offet where ws ends PRInt32 mEndOffset; // ... PRInt16 mEndReason; // reason why ws ends (eText, eOtherBlock, etc) + nsCOMPtr mEndReasonNode; // the node that implicated by end reason nsCOMPtr mFirstNBSPNode; // location of first nbsp in ws run, if any PRInt32 mFirstNBSPOffset; // ... @@ -340,6 +343,8 @@ class nsWSRunObject WSFragment *mEndRun; // the last WSFragment in the run, may be same as first nsHTMLEditor *mHTMLEditor; // non-owning. + + friend class nsHTMLEditRules; // opening this class up for pillaging }; #endif