Bug 751547 - Unify action enums in editor/; r=ehsan

This commit is contained in:
Aryeh Gregor 2012-05-05 21:52:29 +03:00
parent 4386c22bf1
commit cb28d967ce
15 changed files with 230 additions and 243 deletions

View File

@ -54,10 +54,10 @@ class nsRulesInfo
{
public:
nsRulesInfo(int aAction) : action(aAction) {}
nsRulesInfo(nsEditor::OperationID aAction) : action(aAction) {}
virtual ~nsRulesInfo() {}
int action;
nsEditor::OperationID action;
};
/***************************************************************************
@ -74,8 +74,10 @@ public:
NS_IMETHOD Init(nsPlaintextEditor *aEditor)=0;
NS_IMETHOD DetachEditor()=0;
NS_IMETHOD BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)=0;
NS_IMETHOD AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection)=0;
NS_IMETHOD BeforeEdit(nsEditor::OperationID action,
nsIEditor::EDirection aDirection) = 0;
NS_IMETHOD AfterEdit(nsEditor::OperationID action,
nsIEditor::EDirection aDirection) = 0;
NS_IMETHOD WillDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, bool *aCancel, bool *aHandled)=0;
NS_IMETHOD DidDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, nsresult aResult)=0;
NS_IMETHOD DocumentIsEmpty(bool *aDocumentIsEmpty)=0;

View File

@ -154,7 +154,7 @@ nsEditor::nsEditor()
, mFlags(0)
, mUpdateCount(0)
, mPlaceHolderBatch(0)
, mAction(nsnull)
, mAction(kOpNone)
, mHandlingActionCount(0)
, mIMETextOffset(0)
, mIMEBufferLength(0)
@ -2157,7 +2157,7 @@ nsEditor::GetRootElement(nsIDOMElement **aRootElement)
/** All editor operations which alter the doc should be prefaced
* with a call to StartOperation, naming the action and direction */
NS_IMETHODIMP
nsEditor::StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection)
nsEditor::StartOperation(OperationID opID, nsIEditor::EDirection aDirection)
{
mAction = opID;
mDirection = aDirection;
@ -2170,7 +2170,7 @@ nsEditor::StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection)
NS_IMETHODIMP
nsEditor::EndOperation()
{
mAction = nsnull;
mAction = kOpNone;
mDirection = eNone;
return NS_OK;
}
@ -5129,7 +5129,7 @@ nsEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
}
nsresult
nsEditor::HandleInlineSpellCheck(PRInt32 action,
nsEditor::HandleInlineSpellCheck(OperationID action,
nsISelection *aSelection,
nsIDOMNode *previousSelectedNode,
PRInt32 previousSelectedOffset,

View File

@ -129,12 +129,34 @@ public:
kOpDeleteNode,
kOpSplitNode,
kOpJoinNode,
kOpDeleteSelection,
kOpDeleteText = 1003,
// text commands
kOpInsertBreak = 1000,
kOpInsertText = 1001,
kOpInsertIMEText = 1002,
kOpDeleteText = 1003
kOpInsertText = 2000,
kOpInsertIMEText = 2001,
kOpDeleteSelection = 2002,
kOpSetTextProperty = 2003,
kOpRemoveTextProperty = 2004,
kOpOutputText = 2005,
// html only action
kOpInsertBreak = 3000,
kOpMakeList = 3001,
kOpIndent = 3002,
kOpOutdent = 3003,
kOpAlign = 3004,
kOpMakeBasicBlock = 3005,
kOpRemoveList = 3006,
kOpMakeDefListItem = 3007,
kOpInsertElement = 3008,
kOpInsertQuotation = 3009,
kOpHTMLPaste = 3012,
kOpLoadHTML = 3013,
kOpResetTextProperties = 3014,
kOpSetAbsolutePosition = 3015,
kOpRemoveAbsolutePosition = 3016,
kOpDecreaseZIndex = 3017,
kOpIncreaseZIndex = 3018
};
/** The default constructor. This should suffice. the setting of the interfaces is done
@ -384,7 +406,8 @@ public:
/** All editor operations which alter the doc should be prefaced
* with a call to StartOperation, naming the action and direction */
NS_IMETHOD StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection);
NS_IMETHOD StartOperation(OperationID opID,
nsIEditor::EDirection aDirection);
/** All editor operations which alter the doc should be followed
* with a call to EndOperation */
@ -635,7 +658,7 @@ public:
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
nsresult HandleInlineSpellCheck(PRInt32 action,
nsresult HandleInlineSpellCheck(OperationID action,
nsISelection *aSelection,
nsIDOMNode *previousSelectedNode,
PRInt32 previousSelectedOffset,
@ -846,7 +869,7 @@ protected:
PRInt32 mUpdateCount;
PRInt32 mPlaceHolderBatch; // nesting count for batching
PRInt32 mAction; // the current editor action
OperationID mAction; // the current editor action
PRUint32 mHandlingActionCount;
PRUint32 mIMETextOffset; // offset in text node where IME comp string begins

View File

@ -106,7 +106,8 @@ class NS_STACK_CLASS nsAutoRules
{
public:
nsAutoRules(nsEditor *ed, PRInt32 action, nsIEditor::EDirection aDirection) :
nsAutoRules(nsEditor *ed, nsEditor::OperationID action,
nsIEditor::EDirection aDirection) :
mEd(ed), mDoNothing(false)
{
if (mEd && !mEd->mAction) // mAction will already be set if this is nested call

View File

@ -84,9 +84,8 @@ nsHTMLEditor::AbsolutePositionSelection(bool aEnabled)
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
nsTextRulesInfo ruleInfo(aEnabled ?
nsTextEditRules::kSetAbsolutePosition :
nsTextEditRules::kRemoveAbsolutePosition);
nsTextRulesInfo ruleInfo(aEnabled ? kOpSetAbsolutePosition :
kOpRemoveAbsolutePosition);
bool cancel, handled;
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (NS_FAILED(res) || cancel)
@ -199,8 +198,8 @@ nsHTMLEditor::RelativeChangeZIndex(PRInt32 aChange)
nsresult res = GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
nsTextRulesInfo ruleInfo((aChange < 0) ? nsTextEditRules::kDecreaseZIndex:
nsTextEditRules::kIncreaseZIndex);
nsTextRulesInfo ruleInfo(aChange < 0 ? kOpDecreaseZIndex :
kOpIncreaseZIndex);
bool cancel, handled;
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (cancel || NS_FAILED(res))

View File

@ -189,7 +189,7 @@ NS_IMETHODIMP nsHTMLEditor::LoadHTML(const nsAString & aInputString)
nsresult rv = GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(rv, rv);
nsTextRulesInfo ruleInfo(nsTextEditRules::kLoadHTML);
nsTextRulesInfo ruleInfo(kOpLoadHTML);
bool cancel, handled;
rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(rv, rv);
@ -420,7 +420,7 @@ nsHTMLEditor::DoInsertHTMLWithContext(const nsAString & aInputString,
}
// give rules a chance to handle or cancel
nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement);
nsTextRulesInfo ruleInfo(kOpInsertElement);
bool cancel, handled;
rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(rv, rv);
@ -1764,7 +1764,7 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsAString & aCitation,
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
// give rules a chance to handle or cancel
nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement);
nsTextRulesInfo ruleInfo(kOpInsertElement);
bool cancel, handled;
rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(rv, rv);
@ -1966,7 +1966,7 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAString & aQuotedText,
nsAutoRules beginRulesSniffing(this, kOpInsertQuotation, nsIEditor::eNext);
// give rules a chance to handle or cancel
nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement);
nsTextRulesInfo ruleInfo(kOpInsertElement);
bool cancel, handled;
rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(rv, rv);
@ -2060,7 +2060,7 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsAString & aQuotedText,
nsAutoRules beginRulesSniffing(this, kOpInsertQuotation, nsIEditor::eNext);
// give rules a chance to handle or cancel
nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement);
nsTextRulesInfo ruleInfo(kOpInsertElement);
bool cancel, handled;
rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -282,7 +282,8 @@ nsHTMLEditRules::DetachEditor()
}
NS_IMETHODIMP
nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)
nsHTMLEditRules::BeforeEdit(nsEditor::OperationID action,
nsIEditor::EDirection aDirection)
{
if (mLockRulesSniffing) return NS_OK;
@ -366,7 +367,8 @@ nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)
NS_IMETHODIMP
nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection)
nsHTMLEditRules::AfterEdit(nsEditor::OperationID action,
nsIEditor::EDirection aDirection)
{
if (mLockRulesSniffing) return NS_OK;
@ -400,7 +402,8 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection)
nsresult
nsHTMLEditRules::AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection)
nsHTMLEditRules::AfterEditInner(nsEditor::OperationID action,
nsIEditor::EDirection aDirection)
{
ConfirmSelectionInBody();
if (action == nsEditor::kOpIgnore) return NS_OK;
@ -552,10 +555,9 @@ nsHTMLEditRules::WillDoAction(nsISelection *aSelection,
// Deal with actions for which we don't need to check whether the selection is
// editable.
if (info->action == kOutputText ||
info->action == kUndo ||
info->action == kRedo)
{
if (info->action == nsEditor::kOpOutputText ||
info->action == nsEditor::kOpUndo ||
info->action == nsEditor::kOpRedo) {
return nsTextEditRules::WillDoAction(aSelection, aInfo, aCancel, aHandled);
}
@ -600,8 +602,8 @@ nsHTMLEditRules::WillDoAction(nsISelection *aSelection,
switch (info->action)
{
case kInsertText:
case kInsertTextIME:
case nsEditor::kOpInsertText:
case nsEditor::kOpInsertIMEText:
return WillInsertText(info->action,
aSelection,
aCancel,
@ -609,38 +611,39 @@ nsHTMLEditRules::WillDoAction(nsISelection *aSelection,
info->inString,
info->outString,
info->maxLength);
case kLoadHTML:
case nsEditor::kOpLoadHTML:
return WillLoadHTML(aSelection, aCancel);
case kInsertBreak:
case nsEditor::kOpInsertBreak:
return WillInsertBreak(aSelection, aCancel, aHandled);
case kDeleteSelection:
case nsEditor::kOpDeleteSelection:
return WillDeleteSelection(aSelection, info->collapsedAction, aCancel, aHandled);
case kMakeList:
case nsEditor::kOpMakeList:
return WillMakeList(aSelection, info->blockType, info->entireList, info->bulletType, aCancel, aHandled);
case kIndent:
case nsEditor::kOpIndent:
return WillIndent(aSelection, aCancel, aHandled);
case kOutdent:
case nsEditor::kOpOutdent:
return WillOutdent(aSelection, aCancel, aHandled);
case kSetAbsolutePosition:
case nsEditor::kOpSetAbsolutePosition:
return WillAbsolutePosition(aSelection, aCancel, aHandled);
case kRemoveAbsolutePosition:
case nsEditor::kOpRemoveAbsolutePosition:
return WillRemoveAbsolutePosition(aSelection, aCancel, aHandled);
case kAlign:
case nsEditor::kOpAlign:
return WillAlign(aSelection, info->alignType, aCancel, aHandled);
case kMakeBasicBlock:
case nsEditor::kOpMakeBasicBlock:
return WillMakeBasicBlock(aSelection, info->blockType, aCancel, aHandled);
case kRemoveList:
case nsEditor::kOpRemoveList:
return WillRemoveList(aSelection, info->bOrdered, aCancel, aHandled);
case kMakeDefListItem:
case nsEditor::kOpMakeDefListItem:
return WillMakeDefListItem(aSelection, info->blockType, info->entireList, aCancel, aHandled);
case kInsertElement:
case nsEditor::kOpInsertElement:
return WillInsert(aSelection, aCancel);
case kDecreaseZIndex:
case nsEditor::kOpDecreaseZIndex:
return WillRelativeChangeZIndex(aSelection, -1, aCancel, aHandled);
case kIncreaseZIndex:
case nsEditor::kOpIncreaseZIndex:
return WillRelativeChangeZIndex(aSelection, 1, aCancel, aHandled);
default:
return nsTextEditRules::WillDoAction(aSelection, aInfo, aCancel, aHandled);
}
return nsTextEditRules::WillDoAction(aSelection, aInfo, aCancel, aHandled);
}
@ -651,24 +654,24 @@ nsHTMLEditRules::DidDoAction(nsISelection *aSelection,
nsTextRulesInfo *info = static_cast<nsTextRulesInfo*>(aInfo);
switch (info->action)
{
case kInsertBreak:
case nsEditor::kOpInsertBreak:
return DidInsertBreak(aSelection, aResult);
case kDeleteSelection:
case nsEditor::kOpDeleteSelection:
return DidDeleteSelection(aSelection, info->collapsedAction, aResult);
case kMakeBasicBlock:
case kIndent:
case kOutdent:
case kAlign:
case nsEditor::kOpMakeBasicBlock:
case nsEditor::kOpIndent:
case nsEditor::kOpOutdent:
case nsEditor::kOpAlign:
return DidMakeBasicBlock(aSelection, aInfo, aResult);
case kSetAbsolutePosition: {
case nsEditor::kOpSetAbsolutePosition: {
nsresult rv = DidMakeBasicBlock(aSelection, aInfo, aResult);
NS_ENSURE_SUCCESS(rv, rv);
return DidAbsolutePosition();
}
}
default:
// pass thru to nsTextEditRules
return nsTextEditRules::DidDoAction(aSelection, aInfo, aResult);
}
// default: pass thru to nsTextEditRules
return nsTextEditRules::DidDoAction(aSelection, aInfo, aResult);
}
nsresult
@ -833,12 +836,13 @@ nsHTMLEditRules::GetAlignment(bool *aMixed, nsIHTMLEditor::EAlignment *aAlign)
else
{
nsCOMArray<nsIDOMRange> arrayOfRanges;
res = GetPromotedRanges(selection, arrayOfRanges, kAlign);
res = GetPromotedRanges(selection, arrayOfRanges, nsEditor::kOpAlign);
NS_ENSURE_SUCCESS(res, res);
// use these ranges to construct a list of nodes to act on.
nsCOMArray<nsIDOMNode> arrayOfNodes;
res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, kAlign, true);
res = GetNodesForOperation(arrayOfRanges, arrayOfNodes,
nsEditor::kOpAlign, true);
NS_ENSURE_SUCCESS(res, res);
nodeToExamine = arrayOfNodes.SafeObjectAt(0);
}
@ -957,7 +961,8 @@ nsHTMLEditRules::GetIndentState(bool *aCanIndent, bool *aCanOutdent)
// contruct a list of nodes to act on.
nsCOMArray<nsIDOMNode> arrayOfNodes;
res = GetNodesFromSelection(selection, kIndent, arrayOfNodes, true);
res = GetNodesFromSelection(selection, nsEditor::kOpIndent,
arrayOfNodes, true);
NS_ENSURE_SUCCESS(res, res);
// examine nodes in selection for blockquotes or list elements;
@ -1275,7 +1280,7 @@ nsHTMLEditRules::DidInsert(nsISelection *aSelection, nsresult aResult)
#endif
nsresult
nsHTMLEditRules::WillInsertText(PRInt32 aAction,
nsHTMLEditRules::WillInsertText(nsEditor::OperationID aAction,
nsISelection *aSelection,
bool *aCancel,
bool *aHandled,
@ -1285,10 +1290,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
{
if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
if (inString->IsEmpty() && (aAction != kInsertTextIME))
{
if (inString->IsEmpty() && aAction != nsEditor::kOpInsertIMEText) {
// HACK: this is a fix for bug 19395
// I can't outlaw all empty insertions
// because IME transaction depend on them
@ -1336,8 +1338,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
nsCOMPtr<nsIDOMDocument> doc = mHTMLEditor->GetDOMDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
if (aAction == kInsertTextIME)
{
if (aAction == nsEditor::kOpInsertIMEText) {
// Right now the nsWSRunObject code bails on empty strings, but IME needs
// the InsertTextImpl() call to still happen since empty strings are meaningful there.
if (inString->IsEmpty())
@ -2781,7 +2782,8 @@ nsHTMLEditRules::MoveBlock(nsIDOMNode *aLeftBlock, nsIDOMNode *aRightBlock, PRIn
nsCOMArray<nsIDOMNode> arrayOfNodes;
nsCOMPtr<nsISupports> isupports;
// GetNodesFromPoint is the workhorse that figures out what we wnat to move.
nsresult res = GetNodesFromPoint(DOMPoint(aRightBlock,aRightOffset), kMakeList, arrayOfNodes, true);
nsresult res = GetNodesFromPoint(DOMPoint(aRightBlock,aRightOffset),
nsEditor::kOpMakeList, arrayOfNodes, true);
NS_ENSURE_SUCCESS(res, res);
PRInt32 listCount = arrayOfNodes.Count();
PRInt32 i;
@ -3277,7 +3279,7 @@ nsHTMLEditRules::WillRemoveList(nsISelection *aSelection,
nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor);
nsCOMArray<nsIDOMRange> arrayOfRanges;
res = GetPromotedRanges(aSelection, arrayOfRanges, kMakeList);
res = GetPromotedRanges(aSelection, arrayOfRanges, nsEditor::kOpMakeList);
NS_ENSURE_SUCCESS(res, res);
// use these ranges to contruct a list of nodes to act on.
@ -3366,7 +3368,8 @@ nsHTMLEditRules::WillMakeBasicBlock(nsISelection *aSelection,
// contruct a list of nodes to act on.
nsCOMArray<nsIDOMNode> arrayOfNodes;
res = GetNodesFromSelection(aSelection, kMakeBasicBlock, arrayOfNodes);
res = GetNodesFromSelection(aSelection, nsEditor::kOpMakeBasicBlock,
arrayOfNodes);
NS_ENSURE_SUCCESS(res, res);
// Remove all non-editable nodes. Leave them be.
@ -3563,7 +3566,7 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, bool *aCancel, bool * a
// this basically just expands the range to include the immediate
// block parent, and then further expands to include any ancestors
// whose children are all in the range
res = GetNodesFromSelection(aSelection, kIndent, arrayOfNodes);
res = GetNodesFromSelection(aSelection, nsEditor::kOpIndent, arrayOfNodes);
NS_ENSURE_SUCCESS(res, res);
}
@ -3746,12 +3749,12 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, bool *aCancel, bool *
// whose children are all in the range
nsCOMArray<nsIDOMRange> arrayOfRanges;
res = GetPromotedRanges(aSelection, arrayOfRanges, kIndent);
res = GetPromotedRanges(aSelection, arrayOfRanges, nsEditor::kOpIndent);
NS_ENSURE_SUCCESS(res, res);
// use these ranges to contruct a list of nodes to act on.
nsCOMArray<nsIDOMNode> arrayOfNodes;
res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, kIndent);
res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, nsEditor::kOpIndent);
NS_ENSURE_SUCCESS(res, res);
NS_NAMED_LITERAL_STRING(quoteType, "blockquote");
@ -3976,7 +3979,8 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, bool *aCancel, bool *aHan
// block parent, and then further expands to include any ancestors
// whose children are all in the range
nsCOMArray<nsIDOMNode> arrayOfNodes;
res = GetNodesFromSelection(aSelection, kOutdent, arrayOfNodes);
res = GetNodesFromSelection(aSelection, nsEditor::kOpOutdent,
arrayOfNodes);
NS_ENSURE_SUCCESS(res, res);
// Ok, now go through all the nodes and remove a level of blockquoting,
@ -4599,7 +4603,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection,
// whose children are all in the range
*aHandled = true;
nsCOMArray<nsIDOMNode> arrayOfNodes;
res = GetNodesFromSelection(aSelection, kAlign, arrayOfNodes);
res = GetNodesFromSelection(aSelection, nsEditor::kOpAlign, arrayOfNodes);
NS_ENSURE_SUCCESS(res, res);
// if we don't have any nodes, or we have only a single br, then we are
@ -5475,8 +5479,11 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection)
// GetPromotedPoint: figure out where a start or end point for a block
// operation really is
nsresult
nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt32 aOffset,
PRInt32 actionID, nsCOMPtr<nsIDOMNode> *outNode, PRInt32 *outOffset)
nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode,
PRInt32 aOffset,
nsEditor::OperationID actionID,
nsCOMPtr<nsIDOMNode> *outNode,
PRInt32 *outOffset)
{
nsresult res = NS_OK;
nsCOMPtr<nsIDOMNode> nearNode, node = aNode;
@ -5672,7 +5679,7 @@ nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt
nsresult
nsHTMLEditRules::GetPromotedRanges(nsISelection *inSelection,
nsCOMArray<nsIDOMRange> &outArrayOfRanges,
PRInt32 inOperationType)
nsEditor::OperationID inOperationType)
{
NS_ENSURE_TRUE(inSelection, NS_ERROR_NULL_POINTER);
@ -5713,7 +5720,7 @@ nsHTMLEditRules::GetPromotedRanges(nsISelection *inSelection,
//
nsresult
nsHTMLEditRules::PromoteRange(nsIDOMRange *inRange,
PRInt32 inOperationType)
nsEditor::OperationID inOperationType)
{
NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
nsresult res;
@ -5813,7 +5820,7 @@ private:
nsresult
nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges,
nsCOMArray<nsIDOMNode>& outArrayOfNodes,
PRInt32 inOperationType,
nsEditor::OperationID inOperationType,
bool aDontTouchContent)
{
PRInt32 rangeCount = inArrayOfRanges.Count();
@ -5896,8 +5903,7 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges,
// certain operations should not act on li's and td's, but rather inside
// them. alter the list as needed
if (inOperationType == kMakeBasicBlock)
{
if (inOperationType == nsEditor::kOpMakeBasicBlock) {
PRInt32 listCount = outArrayOfNodes.Count();
for (i=listCount-1; i>=0; i--)
{
@ -5913,10 +5919,9 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges,
}
// indent/outdent already do something special for list items, but
// we still need to make sure we don't act on table elements
else if ( (inOperationType == kOutdent) ||
(inOperationType == kIndent) ||
(inOperationType == kSetAbsolutePosition))
{
else if (inOperationType == nsEditor::kOpOutdent ||
inOperationType == nsEditor::kOpIndent ||
inOperationType == nsEditor::kOpSetAbsolutePosition) {
PRInt32 listCount = outArrayOfNodes.Count();
for (i=listCount-1; i>=0; i--)
{
@ -5931,8 +5936,8 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges,
}
}
// outdent should look inside of divs.
if (inOperationType == kOutdent && !mHTMLEditor->IsCSSEnabled())
{
if (inOperationType == nsEditor::kOpOutdent &&
!mHTMLEditor->IsCSSEnabled()) {
PRInt32 listCount = outArrayOfNodes.Count();
for (i=listCount-1; i>=0; i--)
{
@ -5950,13 +5955,12 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges,
// post process the list to break up inline containers that contain br's.
// but only for operations that might care, like making lists or para's...
if ( (inOperationType == kMakeBasicBlock) ||
(inOperationType == kMakeList) ||
(inOperationType == kAlign) ||
(inOperationType == kSetAbsolutePosition) ||
(inOperationType == kIndent) ||
(inOperationType == kOutdent) )
{
if (inOperationType == nsEditor::kOpMakeBasicBlock ||
inOperationType == nsEditor::kOpMakeList ||
inOperationType == nsEditor::kOpAlign ||
inOperationType == nsEditor::kOpSetAbsolutePosition ||
inOperationType == nsEditor::kOpIndent ||
inOperationType == nsEditor::kOpOutdent) {
PRInt32 listCount = outArrayOfNodes.Count();
for (i=listCount-1; i>=0; i--)
{
@ -6068,7 +6072,8 @@ nsHTMLEditRules::GetListActionNodes(nsCOMArray<nsIDOMNode> &outArrayOfNodes,
nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor);
// contruct a list of nodes to act on.
res = GetNodesFromSelection(selection, kMakeList, outArrayOfNodes, aDontTouchContent);
res = GetNodesFromSelection(selection, nsEditor::kOpMakeList,
outArrayOfNodes, aDontTouchContent);
NS_ENSURE_SUCCESS(res, res);
}
@ -6191,7 +6196,8 @@ nsHTMLEditRules::GetParagraphFormatNodes(nsCOMArray<nsIDOMNode>& outArrayOfNodes
NS_ENSURE_SUCCESS(res, res);
// contruct a list of nodes to act on.
res = GetNodesFromSelection(selection, kMakeBasicBlock, outArrayOfNodes, aDontTouchContent);
res = GetNodesFromSelection(selection, nsEditor::kOpMakeBasicBlock,
outArrayOfNodes, aDontTouchContent);
NS_ENSURE_SUCCESS(res, res);
// pre process our list of nodes...
@ -6364,7 +6370,7 @@ nsHTMLEditRules::GetHighestInlineParent(nsIDOMNode* aNode)
//
nsresult
nsHTMLEditRules::GetNodesFromPoint(DOMPoint point,
PRInt32 operation,
nsEditor::OperationID operation,
nsCOMArray<nsIDOMNode> &arrayOfNodes,
bool dontTouchContent)
{
@ -6405,7 +6411,7 @@ nsHTMLEditRules::GetNodesFromPoint(DOMPoint point,
//
nsresult
nsHTMLEditRules::GetNodesFromSelection(nsISelection *selection,
PRInt32 operation,
nsEditor::OperationID operation,
nsCOMArray<nsIDOMNode>& arrayOfNodes,
bool dontTouchContent)
{
@ -8931,12 +8937,14 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, bool *aCancel, b
// whose children are all in the range
nsCOMArray<nsIDOMRange> arrayOfRanges;
res = GetPromotedRanges(aSelection, arrayOfRanges, kSetAbsolutePosition);
res = GetPromotedRanges(aSelection, arrayOfRanges,
nsEditor::kOpSetAbsolutePosition);
NS_ENSURE_SUCCESS(res, res);
// use these ranges to contruct a list of nodes to act on.
nsCOMArray<nsIDOMNode> arrayOfNodes;
res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, kSetAbsolutePosition);
res = GetNodesForOperation(arrayOfRanges, arrayOfNodes,
nsEditor::kOpSetAbsolutePosition);
NS_ENSURE_SUCCESS(res, res);
NS_NAMED_LITERAL_STRING(divType, "div");

View File

@ -90,8 +90,10 @@ public:
// nsIEditRules methods
NS_IMETHOD Init(nsPlaintextEditor *aEditor);
NS_IMETHOD DetachEditor();
NS_IMETHOD BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection);
NS_IMETHOD AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection);
NS_IMETHOD BeforeEdit(nsEditor::OperationID action,
nsIEditor::EDirection aDirection);
NS_IMETHOD AfterEdit(nsEditor::OperationID action,
nsIEditor::EDirection aDirection);
NS_IMETHOD WillDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, bool *aCancel, bool *aHandled);
NS_IMETHOD DidDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
NS_IMETHOD DocumentModified();
@ -141,7 +143,7 @@ protected:
#ifdef XXX_DEAD_CODE
nsresult DidInsert(nsISelection *aSelection, nsresult aResult);
#endif
nsresult WillInsertText( PRInt32 aAction,
nsresult WillInsertText( nsEditor::OperationID aAction,
nsISelection *aSelection,
bool *aCancel,
bool *aHandled,
@ -196,7 +198,8 @@ protected:
nsCOMPtr<nsIDOMNode> *aSelNode,
PRInt32 *aOffset);
nsresult ReturnInListItem(nsISelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, PRInt32 aOffset);
nsresult AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection);
nsresult AfterEditInner(nsEditor::OperationID action,
nsIEditor::EDirection aDirection);
nsresult RemovePartOfBlock(nsIDOMNode *aBlock,
nsIDOMNode *aStartChild,
nsIDOMNode *aEndChild,
@ -234,24 +237,26 @@ protected:
bool 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 GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode,
PRInt32 aOffset, nsEditor::OperationID actionID,
nsCOMPtr<nsIDOMNode> *outNode, PRInt32 *outOffset);
nsresult GetPromotedRanges(nsISelection *inSelection,
nsCOMArray<nsIDOMRange> &outArrayOfRanges,
PRInt32 inOperationType);
nsresult PromoteRange(nsIDOMRange *inRange, PRInt32 inOperationType);
nsEditor::OperationID inOperationType);
nsresult PromoteRange(nsIDOMRange *inRange,
nsEditor::OperationID inOperationType);
nsresult GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges,
nsCOMArray<nsIDOMNode>& outArrayOfNodes,
PRInt32 inOperationType,
nsEditor::OperationID inOperationType,
bool aDontTouchContent=false);
nsresult GetChildNodesForOperation(nsIDOMNode *inNode,
nsCOMArray<nsIDOMNode>& outArrayOfNodes);
nsresult GetNodesFromPoint(DOMPoint point,
PRInt32 operation,
nsEditor::OperationID operation,
nsCOMArray<nsIDOMNode>& arrayOfNodes,
bool dontTouchContent);
nsresult GetNodesFromSelection(nsISelection *selection,
PRInt32 operation,
nsEditor::OperationID operation,
nsCOMArray<nsIDOMNode>& arrayOfNodes,
bool aDontTouchContent=false);
nsresult GetListActionNodes(nsCOMArray<nsIDOMNode> &outArrayOfNodes, bool aEntireList, bool aDontTouchContent=false);

View File

@ -1742,7 +1742,7 @@ nsHTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement, bool aDeleteSele
// hand off to the rules system, see if it has anything to say about this
bool cancel, handled;
nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement);
nsTextRulesInfo ruleInfo(kOpInsertElement);
ruleInfo.insertElement = aElement;
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (cancel || (NS_FAILED(res))) return res;
@ -2222,7 +2222,7 @@ nsHTMLEditor::MakeOrChangeList(const nsAString& aListType, bool entireList, cons
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
nsTextRulesInfo ruleInfo(nsTextEditRules::kMakeList);
nsTextRulesInfo ruleInfo(kOpMakeList);
ruleInfo.blockType = &aListType;
ruleInfo.entireList = entireList;
ruleInfo.bulletType = &aBulletType;
@ -2303,7 +2303,7 @@ nsHTMLEditor::RemoveList(const nsAString& aListType)
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
nsTextRulesInfo ruleInfo(nsTextEditRules::kRemoveList);
nsTextRulesInfo ruleInfo(kOpRemoveList);
if (aListType.LowerCaseEqualsLiteral("ol"))
ruleInfo.bOrdered = true;
else ruleInfo.bOrdered = false;
@ -2335,7 +2335,7 @@ nsHTMLEditor::MakeDefinitionItem(const nsAString& aItemType)
res = GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
nsTextRulesInfo ruleInfo(nsTextEditRules::kMakeDefListItem);
nsTextRulesInfo ruleInfo(kOpMakeDefListItem);
ruleInfo.blockType = &aItemType;
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (cancel || (NS_FAILED(res))) return res;
@ -2368,7 +2368,7 @@ nsHTMLEditor::InsertBasicBlock(const nsAString& aBlockType)
res = GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
nsTextRulesInfo ruleInfo(nsTextEditRules::kMakeBasicBlock);
nsTextRulesInfo ruleInfo(kOpMakeBasicBlock);
ruleInfo.blockType = &aBlockType;
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (cancel || (NS_FAILED(res))) return res;
@ -2434,11 +2434,9 @@ nsHTMLEditor::Indent(const nsAString& aIndent)
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
bool cancel, handled;
PRInt32 theAction = nsTextEditRules::kIndent;
PRInt32 opID = kOpIndent;
OperationID opID = kOpIndent;
if (aIndent.LowerCaseEqualsLiteral("outdent"))
{
theAction = nsTextEditRules::kOutdent;
opID = kOpOutdent;
}
nsAutoEditBatch beginBatching(this);
@ -2450,7 +2448,7 @@ nsHTMLEditor::Indent(const nsAString& aIndent)
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
nsTextRulesInfo ruleInfo(theAction);
nsTextRulesInfo ruleInfo(opID);
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (cancel || (NS_FAILED(res))) return res;
@ -2530,7 +2528,7 @@ nsHTMLEditor::Align(const nsAString& aAlignType)
nsresult res = GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
nsTextRulesInfo ruleInfo(nsTextEditRules::kAlign);
nsTextRulesInfo ruleInfo(kOpAlign);
ruleInfo.alignType = &aAlignType;
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (cancel || NS_FAILED(res))
@ -3750,7 +3748,8 @@ nsHTMLEditor::StyleSheetLoaded(nsCSSStyleSheet* aSheet, bool aWasAlternate,
/** All editor operations which alter the doc should be prefaced
* with a call to StartOperation, naming the action and direction */
NS_IMETHODIMP
nsHTMLEditor::StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection)
nsHTMLEditor::StartOperation(OperationID opID,
nsIEditor::EDirection aDirection)
{
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
@ -4939,7 +4938,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor)
nsAutoTxnsConserveSelection dontSpazMySelection(this);
bool cancel, handled;
nsTextRulesInfo ruleInfo(nsTextEditRules::kSetTextProperty);
nsTextRulesInfo ruleInfo(kOpSetTextProperty);
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(res, res);
if (!cancel && !handled)

View File

@ -109,29 +109,6 @@ class nsHTMLEditor : public nsPlaintextEditor,
public:
enum OperationID
{
kOpInsertBreak = 3000,
kOpMakeList = 3001,
kOpIndent = 3002,
kOpOutdent = 3003,
kOpAlign = 3004,
kOpMakeBasicBlock = 3005,
kOpRemoveList = 3006,
kOpMakeDefListItem = 3007,
kOpInsertElement = 3008,
kOpInsertQuotation = 3009,
kOpSetTextProperty = 3010,
kOpRemoveTextProperty = 3011,
kOpHTMLPaste = 3012,
kOpLoadHTML = 3013,
kOpResetTextProperties = 3014,
kOpSetAbsolutePosition = 3015,
kOpRemoveAbsolutePosition = 3016,
kOpDecreaseZIndex = 3017,
kOpIncreaseZIndex = 3018
};
enum ResizingRequestID
{
kX = 0,
@ -317,7 +294,8 @@ public:
/** All editor operations which alter the doc should be prefaced
* with a call to StartOperation, naming the action and direction */
NS_IMETHOD StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection);
NS_IMETHOD StartOperation(OperationID opID,
nsIEditor::EDirection aDirection);
/** All editor operations which alter the doc should be followed
* with a call to EndOperation */

View File

@ -143,7 +143,7 @@ nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty,
nsAutoTxnsConserveSelection dontSpazMySelection(this);
bool cancel, handled;
nsTextRulesInfo ruleInfo(nsTextEditRules::kSetTextProperty);
nsTextRulesInfo ruleInfo(kOpSetTextProperty);
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(res, res);
if (!cancel && !handled) {
@ -1285,7 +1285,7 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr
nsAutoTxnsConserveSelection dontSpazMySelection(this);
bool cancel, handled;
nsTextRulesInfo ruleInfo(nsTextEditRules::kRemoveTextProperty);
nsTextRulesInfo ruleInfo(kOpRemoveTextProperty);
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(res, res);
if (!cancel && !handled)

View File

@ -783,7 +783,7 @@ NS_IMETHODIMP nsPlaintextEditor::DeleteSelection(nsIEditor::EDirection aAction)
}
}
nsTextRulesInfo ruleInfo(nsTextEditRules::kDeleteSelection);
nsTextRulesInfo ruleInfo(kOpDeleteSelection);
ruleInfo.collapsedAction = aAction;
bool cancel, handled;
result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
@ -808,11 +808,9 @@ NS_IMETHODIMP nsPlaintextEditor::InsertText(const nsAString &aStringToInsert)
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
PRInt32 theAction = nsTextEditRules::kInsertText;
PRInt32 opID = kOpInsertText;
OperationID opID = kOpInsertText;
if (mInIMEMode)
{
theAction = nsTextEditRules::kInsertTextIME;
opID = kOpInsertIMEText;
}
nsAutoPlaceHolderBatch batch(this, nsnull);
@ -827,7 +825,7 @@ NS_IMETHODIMP nsPlaintextEditor::InsertText(const nsAString &aStringToInsert)
// XXX can we trust instring to outlive ruleInfo,
// XXX and ruleInfo not to refer to instring in its dtor?
//nsAutoString instring(aStringToInsert);
nsTextRulesInfo ruleInfo(theAction);
nsTextRulesInfo ruleInfo(opID);
ruleInfo.inString = &aStringToInsert;
ruleInfo.outString = &resultString;
ruleInfo.maxLength = mMaxTextLength;
@ -870,7 +868,7 @@ NS_IMETHODIMP nsPlaintextEditor::InsertLineBreak()
NS_ENSURE_TRUE(shell, NS_ERROR_NOT_INITIALIZED);
shell->MaybeInvalidateCaretPosition();
nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertBreak);
nsTextRulesInfo ruleInfo(kOpInsertBreak);
ruleInfo.maxLength = mMaxTextLength;
bool cancel, handled;
res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
@ -1209,7 +1207,7 @@ nsPlaintextEditor::Undo(PRUint32 aCount)
nsAutoRules beginRulesSniffing(this, kOpUndo, nsIEditor::eNone);
nsTextRulesInfo ruleInfo(nsTextEditRules::kUndo);
nsTextRulesInfo ruleInfo(kOpUndo);
nsCOMPtr<nsISelection> selection;
GetSelection(getter_AddRefs(selection));
bool cancel, handled;
@ -1239,7 +1237,7 @@ nsPlaintextEditor::Redo(PRUint32 aCount)
nsAutoRules beginRulesSniffing(this, kOpRedo, nsIEditor::eNone);
nsTextRulesInfo ruleInfo(nsTextEditRules::kRedo);
nsTextRulesInfo ruleInfo(kOpRedo);
nsCOMPtr<nsISelection> selection;
GetSelection(getter_AddRefs(selection));
bool cancel, handled;
@ -1385,7 +1383,7 @@ nsPlaintextEditor::OutputToString(const nsAString& aFormatType,
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
nsString resultString;
nsTextRulesInfo ruleInfo(nsTextEditRules::kOutputText);
nsTextRulesInfo ruleInfo(kOpOutputText);
ruleInfo.outString = &resultString;
// XXX Struct should store a nsAReadable*
nsAutoString str(aFormatType);
@ -1526,7 +1524,7 @@ nsPlaintextEditor::InsertAsQuotation(const nsAString& aQuotedText,
nsAutoRules beginRulesSniffing(this, kOpInsertText, nsIEditor::eNext);
// give rules a chance to handle or cancel
nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement);
nsTextRulesInfo ruleInfo(kOpInsertElement);
bool cancel, handled;
rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(rv, rv);
@ -1652,7 +1650,8 @@ nsPlaintextEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList)
/** All editor operations which alter the doc should be prefaced
* with a call to StartOperation, naming the action and direction */
NS_IMETHODIMP
nsPlaintextEditor::StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection)
nsPlaintextEditor::StartOperation(OperationID opID,
nsIEditor::EDirection aDirection)
{
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);

View File

@ -130,7 +130,8 @@ public:
/** All editor operations which alter the doc should be prefaced
* with a call to StartOperation, naming the action and direction */
NS_IMETHOD StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection);
NS_IMETHOD StartOperation(OperationID opID,
nsIEditor::EDirection aDirection);
/** All editor operations which alter the doc should be followed
* with a call to EndOperation */

View File

@ -91,7 +91,7 @@ nsTextEditRules::nsTextEditRules()
, mActionNesting(0)
, mLockRulesSniffing(false)
, mDidExplicitlySetInterline(false)
, mTheAction(0)
, mTheAction(nsEditor::kOpNone)
, mLastStart(0)
, mLastLength(0)
{
@ -173,7 +173,8 @@ nsTextEditRules::DetachEditor()
}
NS_IMETHODIMP
nsTextEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)
nsTextEditRules::BeforeEdit(nsEditor::OperationID action,
nsIEditor::EDirection aDirection)
{
if (mLockRulesSniffing) return NS_OK;
@ -199,7 +200,8 @@ nsTextEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)
NS_IMETHODIMP
nsTextEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection)
nsTextEditRules::AfterEdit(nsEditor::OperationID action,
nsIEditor::EDirection aDirection)
{
if (mLockRulesSniffing) return NS_OK;
@ -258,10 +260,10 @@ nsTextEditRules::WillDoAction(nsISelection *aSelection,
switch (info->action)
{
case kInsertBreak:
case nsEditor::kOpInsertBreak:
return WillInsertBreak(aSelection, aCancel, aHandled, info->maxLength);
case kInsertText:
case kInsertTextIME:
case nsEditor::kOpInsertText:
case nsEditor::kOpInsertIMEText:
return WillInsertText(info->action,
aSelection,
aCancel,
@ -269,27 +271,29 @@ nsTextEditRules::WillDoAction(nsISelection *aSelection,
info->inString,
info->outString,
info->maxLength);
case kDeleteSelection:
case nsEditor::kOpDeleteSelection:
return WillDeleteSelection(aSelection, info->collapsedAction, aCancel, aHandled);
case kUndo:
case nsEditor::kOpUndo:
return WillUndo(aSelection, aCancel, aHandled);
case kRedo:
case nsEditor::kOpRedo:
return WillRedo(aSelection, aCancel, aHandled);
case kSetTextProperty:
case nsEditor::kOpSetTextProperty:
return WillSetTextProperty(aSelection, aCancel, aHandled);
case kRemoveTextProperty:
case nsEditor::kOpRemoveTextProperty:
return WillRemoveTextProperty(aSelection, aCancel, aHandled);
case kOutputText:
case nsEditor::kOpOutputText:
return WillOutputText(aSelection,
info->outputFormat,
info->outString,
aCancel,
aHandled);
case kInsertElement: // i had thought this would be html rules only. but we put pre elements
// into plaintext mail when doing quoting for reply! doh!
case nsEditor::kOpInsertElement:
// i had thought this would be html rules only. but we put pre elements
// into plaintext mail when doing quoting for reply! doh!
return WillInsert(aSelection, aCancel);
default:
return NS_ERROR_FAILURE;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
@ -307,26 +311,27 @@ nsTextEditRules::DidDoAction(nsISelection *aSelection,
switch (info->action)
{
case kInsertBreak:
return DidInsertBreak(aSelection, aResult);
case kInsertText:
case kInsertTextIME:
case nsEditor::kOpInsertBreak:
return DidInsertBreak(aSelection, aResult);
case nsEditor::kOpInsertText:
case nsEditor::kOpInsertIMEText:
return DidInsertText(aSelection, aResult);
case kDeleteSelection:
case nsEditor::kOpDeleteSelection:
return DidDeleteSelection(aSelection, info->collapsedAction, aResult);
case kUndo:
case nsEditor::kOpUndo:
return DidUndo(aSelection, aResult);
case kRedo:
case nsEditor::kOpRedo:
return DidRedo(aSelection, aResult);
case kSetTextProperty:
case nsEditor::kOpSetTextProperty:
return DidSetTextProperty(aSelection, aResult);
case kRemoveTextProperty:
case nsEditor::kOpRemoveTextProperty:
return DidRemoveTextProperty(aSelection, aResult);
case kOutputText:
case nsEditor::kOpOutputText:
return DidOutputText(aSelection, aResult);
default:
// Don't fail on transactions we don't handle here!
return NS_OK;
}
// Don't fail on transactions we don't handle here!
return NS_OK;
}
@ -577,7 +582,7 @@ nsTextEditRules::HandleNewLines(nsString &aString,
}
nsresult
nsTextEditRules::WillInsertText(PRInt32 aAction,
nsTextEditRules::WillInsertText(nsEditor::OperationID aAction,
nsISelection *aSelection,
bool *aCancel,
bool *aHandled,
@ -587,8 +592,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
{
if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
if (inString->IsEmpty() && (aAction != kInsertTextIME))
{
if (inString->IsEmpty() && aAction != nsEditor::kOpInsertIMEText) {
// HACK: this is a fix for bug 19395
// I can't outlaw all empty insertions
// because IME transaction depend on them
@ -611,7 +615,8 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
NS_ENSURE_SUCCESS(res, res);
// If we're exceeding the maxlength when composing IME, we need to clean up
// the composing text, so we shouldn't return early.
if (truncated && outString->IsEmpty() && aAction != kInsertTextIME) {
if (truncated && outString->IsEmpty() &&
aAction != nsEditor::kOpInsertIMEText) {
*aCancel = true;
return NS_OK;
}
@ -648,7 +653,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
// to the replacement character
if (IsPasswordEditor())
{
if (aAction == kInsertTextIME) {
if (aAction == nsEditor::kOpInsertIMEText) {
res = RemoveIMETextFromPWBuf(start, outString);
NS_ENSURE_SUCCESS(res, res);
}
@ -716,14 +721,11 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
nsCOMPtr<nsIDOMDocument> doc = mEditor->GetDOMDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
if (aAction == kInsertTextIME)
{
if (aAction == nsEditor::kOpInsertIMEText) {
res = mEditor->InsertTextImpl(*outString, address_of(selNode), &selOffset, doc);
NS_ENSURE_SUCCESS(res, res);
}
else // aAction == kInsertText
{
// find where we are
} else {
// aAction == nsEditor::kOpInsertText; find where we are
nsCOMPtr<nsIDOMNode> curNode = selNode;
PRInt32 curOffset = selOffset;

View File

@ -70,45 +70,15 @@ public:
// nsIEditRules methods
NS_IMETHOD Init(nsPlaintextEditor *aEditor);
NS_IMETHOD DetachEditor();
NS_IMETHOD BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection);
NS_IMETHOD AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection);
NS_IMETHOD BeforeEdit(nsEditor::OperationID action,
nsIEditor::EDirection aDirection);
NS_IMETHOD AfterEdit(nsEditor::OperationID action,
nsIEditor::EDirection aDirection);
NS_IMETHOD WillDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, bool *aCancel, bool *aHandled);
NS_IMETHOD DidDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
NS_IMETHOD DocumentIsEmpty(bool *aDocumentIsEmpty);
NS_IMETHOD DocumentModified();
// nsTextEditRules action id's
enum
{
kDefault = 0,
// any editor that has a txn mgr
kUndo = 1000,
kRedo = 1001,
// text actions
kInsertText = 2000,
kInsertTextIME = 2001,
kDeleteSelection = 2002,
kSetTextProperty = 2003,
kRemoveTextProperty = 2004,
kOutputText = 2005,
// html only action
kInsertBreak = 3000,
kMakeList = 3001,
kIndent = 3002,
kOutdent = 3003,
kAlign = 3004,
kMakeBasicBlock = 3005,
kRemoveList = 3006,
kMakeDefListItem = 3007,
kInsertElement = 3008,
kLoadHTML = 3013,
kSetAbsolutePosition = 3015,
kRemoveAbsolutePosition = 3016,
kDecreaseZIndex = 3017,
kIncreaseZIndex = 3018
};
public:
nsresult ResetIMETextPWBuf();
@ -151,7 +121,7 @@ public:
protected:
// nsTextEditRules implementation methods
nsresult WillInsertText( PRInt32 aAction,
nsresult WillInsertText( nsEditor::OperationID aAction,
nsISelection *aSelection,
bool *aCancel,
bool *aHandled,
@ -283,7 +253,7 @@ protected:
// characters not visually
// adjacent to the caret without
// moving the caret first.
PRInt32 mTheAction; // the top level editor action
nsEditor::OperationID mTheAction; // the top level editor action
nsCOMPtr<nsITimer> mTimer;
PRUint32 mLastStart, mLastLength;
@ -298,7 +268,7 @@ class nsTextRulesInfo : public nsRulesInfo
{
public:
nsTextRulesInfo(int aAction) :
nsTextRulesInfo(nsEditor::OperationID aAction) :
nsRulesInfo(aAction),
inString(0),
outString(0),