117418: warnings in nsWSRunObject.cpp
98286: splitting paragraphs broken
101041: block transformations could grab too much beyon selection
82813: whitespace handling code needs to do right thing with preformatted text
99545 &
103677: new blocks not always pre-populated with br
41336: better handling of mailcites when splitting or deleting them or portions of them

partial fix for:
46474: creating new blocks kills style settings

r=fm, sr=kin
This commit is contained in:
jfrancis%netscape.com 2002-02-19 11:52:50 +00:00
Родитель ae0b7240a9
Коммит f9413bd619
4 изменённых файлов: 56 добавлений и 13 удалений

Просмотреть файл

@ -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<nsISupportsArray> nodeList;
res = CreateListOfNodesToPaste(fragmentAsNode, address_of(nodeList), rangeStartHint, rangeEndHint);
@ -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)
{

Просмотреть файл

@ -154,6 +154,11 @@ protected:
nsCOMPtr<nsIDOMNode> 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<nsIDOMNode> *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<nsIDOMNode> *outNode, PRInt32 *outOffset);
nsresult GetPromotedRanges(nsISelection *inSelection,

Просмотреть файл

@ -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<nsIDOMNode> 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<nsIDOMNode> 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<nsIDOMNode> 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<nsIDOMNode> startNode, endNode;
PRInt32 startOffset, endOffset;
PRInt32 startOffset=0, endOffset=0;
nsresult res = NS_OK;

Просмотреть файл

@ -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<nsIDOMNode> mStartNode; // node/offet where ws starts
PRInt32 mStartOffset; // ...
PRInt16 mStartReason; // reason why ws starts (eText, eOtherBlock, etc)
nsCOMPtr<nsIDOMNode> mStartReasonNode;// the node that implicated by start reason
nsCOMPtr<nsIDOMNode> mEndNode; // node/offet where ws ends
PRInt32 mEndOffset; // ...
PRInt16 mEndReason; // reason why ws ends (eText, eOtherBlock, etc)
nsCOMPtr<nsIDOMNode> mEndReasonNode; // the node that implicated by end reason
nsCOMPtr<nsIDOMNode> 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