зеркало из https://github.com/mozilla/pjs.git
fixes for:
This commit is contained in:
Родитель
4d3809d8fb
Коммит
1ff627fe07
|
@ -186,6 +186,7 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection, PRB
|
|||
// add in any needed <br>s, and remove any unneeded ones.
|
||||
res = AdjustSpecialBreaks();
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
// adjust whitespace for insert text and delete actions
|
||||
if ((action == nsEditor::kOpInsertText) ||
|
||||
(action == nsEditor::kOpInsertIMEText) ||
|
||||
|
@ -194,6 +195,7 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection, PRB
|
|||
res = AdjustWhitespace(selection);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
||||
// replace newlines that are preformatted
|
||||
if ((action == nsEditor::kOpInsertText) ||
|
||||
(action == nsEditor::kOpInsertIMEText) ||
|
||||
|
@ -201,14 +203,35 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection, PRB
|
|||
{
|
||||
res = ReplaceNewlines(mDocChangeRange);
|
||||
}
|
||||
|
||||
// clean up any empty nodes in the selection
|
||||
res = RemoveEmptyNodes();
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
/* I'll move to this code in M15. For now being very conservative with changes
|
||||
|
||||
// adjust selection for insert text and delete actions
|
||||
if ((action == nsEditor::kOpInsertText) ||
|
||||
(action == nsEditor::kOpInsertIMEText) ||
|
||||
(action == nsEditor::kOpDeleteSelection))
|
||||
{
|
||||
res = AdjustSelection(selection, aDirection);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// adjust selection unless it was an inline style manipulation
|
||||
// see above commented out code: we're just being safe for now
|
||||
// with the minimal change to fix selection problem when removing
|
||||
// link property
|
||||
if ((action != nsEditor::kOpSetTextProperty) &&
|
||||
(action != nsEditor::kOpRemoveTextProperty))
|
||||
{
|
||||
res = AdjustSelection(selection, aDirection);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
||||
// adjust selection
|
||||
res = AdjustSelection(selection, aDirection);
|
||||
if (NS_FAILED(res)) return res;
|
||||
// detect empty doc
|
||||
res = CreateBogusNodeIfNeeded(selection);
|
||||
|
||||
|
@ -381,36 +404,6 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
|||
else
|
||||
blockParent = mEditor->GetBlockNodeParent(selNode);
|
||||
if (!blockParent) return NS_ERROR_FAILURE;
|
||||
|
||||
// are we not in a textnode?
|
||||
if (!mEditor->IsTextNode(selNode))
|
||||
{
|
||||
// find a nearby text node if possible
|
||||
nsCOMPtr<nsIDOMNode> priorNode, nextNode;
|
||||
res = GetPriorHTMLNode(selNode, selOffset, &priorNode);
|
||||
if (NS_SUCCEEDED(res) && priorNode && mEditor->IsTextNode(priorNode)
|
||||
&& (blockParent == mEditor->GetBlockNodeParent(priorNode)))
|
||||
{
|
||||
// put selection at end of prior node
|
||||
PRUint32 strLength;
|
||||
nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(priorNode);
|
||||
res = textNode->GetLength(&strLength);
|
||||
if (NS_FAILED(res)) return res;
|
||||
res = aSelection->Collapse(priorNode, strLength);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = GetNextHTMLNode(selNode, selOffset, &nextNode);
|
||||
if (NS_SUCCEEDED(res) && nextNode && mEditor->IsTextNode(nextNode)
|
||||
&& (blockParent == mEditor->GetBlockNodeParent(nextNode)))
|
||||
{
|
||||
// put selection at begining of next node
|
||||
res = aSelection->Collapse(nextNode, 0);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PRBool bCancel;
|
||||
nsString theString(*inString); // copy instring for now
|
||||
|
@ -3288,7 +3281,7 @@ nsHTMLEditRules::AdjustSelection(nsIDOMSelection *aSelection, nsIEditor::EDirect
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// we aren't in a textnode: are we adjacent to a break or an image?
|
||||
res = GetPriorHTMLSibling(selNode, selOffset, &nearNode);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
@ -3325,6 +3318,7 @@ nsHTMLEditRules::AdjustSelection(nsIDOMSelection *aSelection, nsIEditor::EDirect
|
|||
if (aAction == nsIEditor::ePrevious) selOffset++; // want to be beyond it if we backed up to it
|
||||
res = aSelection->Collapse(selNode, selOffset);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -224,6 +224,7 @@ nsHTMLEditor::nsHTMLEditor()
|
|||
mItalicAtom = getter_AddRefs(NS_NewAtom("i"));
|
||||
mUnderlineAtom = getter_AddRefs(NS_NewAtom("u"));
|
||||
mFontAtom = getter_AddRefs(NS_NewAtom("font"));
|
||||
mLinkAtom = getter_AddRefs(NS_NewAtom("a"));
|
||||
|
||||
if (!gTypingTxnName)
|
||||
gTypingTxnName = NS_NewAtom("Typing");
|
||||
|
@ -1248,7 +1249,38 @@ NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsStr
|
|||
if (PR_TRUE==isCollapsed)
|
||||
{
|
||||
// manipulating text attributes on a collapsed selection only sets state for the next text insertion
|
||||
SetTypeInStateForProperty(*mTypeInState, aProperty, aAttribute, nsnull);
|
||||
// But only if it's a property for which we have TypeInState!
|
||||
if ( (aProperty == mBoldAtom.get()) ||
|
||||
(aProperty == mItalicAtom.get()) ||
|
||||
(aProperty == mUnderlineAtom.get()) )
|
||||
{
|
||||
SetTypeInStateForProperty(*mTypeInState, aProperty, aAttribute, nsnull);
|
||||
}
|
||||
else if (aProperty == mLinkAtom.get())
|
||||
{
|
||||
// a hack for links. The user is trying to kill the link "style" where
|
||||
// they are typing. We need to split up through any link elements above the
|
||||
// collapsed insertion point.
|
||||
nsCOMPtr<nsIDOMNode> selNode, tmpNode, parent;
|
||||
PRInt32 selOffset, outOffset;
|
||||
result = GetStartNodeAndOffset(selection, &selNode, &selOffset);
|
||||
if (NS_FAILED(result)) return result;
|
||||
tmpNode = selNode;
|
||||
while (tmpNode)
|
||||
{
|
||||
if (nsHTMLEditUtils::IsBody(tmpNode)) break;
|
||||
if (IsLinkNode(tmpNode))
|
||||
{
|
||||
result = SplitNodeDeep(tmpNode, selNode, selOffset, &outOffset);
|
||||
if (NS_FAILED(result)) return result;
|
||||
tmpNode->GetParentNode(getter_AddRefs(parent));
|
||||
selection->Collapse(parent, outOffset);
|
||||
break;
|
||||
}
|
||||
tmpNode->GetParentNode(getter_AddRefs(parent));
|
||||
tmpNode = parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -593,6 +593,7 @@ protected:
|
|||
nsCOMPtr<nsIAtom> mItalicAtom;
|
||||
nsCOMPtr<nsIAtom> mUnderlineAtom;
|
||||
nsCOMPtr<nsIAtom> mFontAtom;
|
||||
nsCOMPtr<nsIAtom> mLinkAtom;
|
||||
nsCOMPtr<nsIDOMNode> mCachedNode;
|
||||
|
||||
PRBool mCachedBoldStyle;
|
||||
|
|
|
@ -1430,9 +1430,6 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
|||
if (!bodyElement) return NS_ERROR_NULL_POINTER;
|
||||
nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> bogusNodeParent (bodyNode);
|
||||
PRInt32 bogusNodeOffset = 0;
|
||||
|
||||
// now we've got the body tag.
|
||||
// iterate the body tag, looking for editable content
|
||||
// if no editable content is found, insert the bogus node
|
||||
|
@ -1450,38 +1447,11 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
|||
bodyChild->GetNextSibling(getter_AddRefs(temp));
|
||||
bodyChild = do_QueryInterface(temp);
|
||||
}
|
||||
|
||||
// Also, if we just inserted a non-text node, and if there's
|
||||
// no editable content after the newly inserted node, then
|
||||
// we need a bogus node at the end of the document:
|
||||
if (!needsBogusContent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> focusParent;
|
||||
aSelection->GetFocusNode(getter_AddRefs(focusParent));
|
||||
if (focusParent && !mEditor->IsTextNode(focusParent))
|
||||
{
|
||||
PRInt32 focusOffset;
|
||||
if (NS_SUCCEEDED(aSelection->GetFocusOffset(&focusOffset)))
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> child = mEditor->GetChildAt(focusParent,
|
||||
focusOffset+1);
|
||||
|
||||
if (!child || !mEditor->IsEditable(child))
|
||||
{
|
||||
needsBogusContent = PR_TRUE;
|
||||
bogusNodeParent = focusParent;
|
||||
bogusNodeOffset = focusOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (needsBogusContent)
|
||||
{
|
||||
// set mBogusNode to be the newly created <br>
|
||||
res = mEditor->CreateNode(nsAutoString("br"),
|
||||
bogusNodeParent, bogusNodeOffset,
|
||||
getter_AddRefs(mBogusNode));
|
||||
res = mEditor->CreateNode(nsAutoString("br"), bodyNode, 0,
|
||||
getter_AddRefs(mBogusNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (!mBogusNode) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
|
@ -1496,7 +1466,7 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
|||
}
|
||||
|
||||
// set selection
|
||||
aSelection->Collapse(bogusNodeParent, bogusNodeOffset);
|
||||
aSelection->Collapse(bodyNode,0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -186,6 +186,7 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection, PRB
|
|||
// add in any needed <br>s, and remove any unneeded ones.
|
||||
res = AdjustSpecialBreaks();
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
// adjust whitespace for insert text and delete actions
|
||||
if ((action == nsEditor::kOpInsertText) ||
|
||||
(action == nsEditor::kOpInsertIMEText) ||
|
||||
|
@ -194,6 +195,7 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection, PRB
|
|||
res = AdjustWhitespace(selection);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
||||
// replace newlines that are preformatted
|
||||
if ((action == nsEditor::kOpInsertText) ||
|
||||
(action == nsEditor::kOpInsertIMEText) ||
|
||||
|
@ -201,14 +203,35 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection, PRB
|
|||
{
|
||||
res = ReplaceNewlines(mDocChangeRange);
|
||||
}
|
||||
|
||||
// clean up any empty nodes in the selection
|
||||
res = RemoveEmptyNodes();
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
/* I'll move to this code in M15. For now being very conservative with changes
|
||||
|
||||
// adjust selection for insert text and delete actions
|
||||
if ((action == nsEditor::kOpInsertText) ||
|
||||
(action == nsEditor::kOpInsertIMEText) ||
|
||||
(action == nsEditor::kOpDeleteSelection))
|
||||
{
|
||||
res = AdjustSelection(selection, aDirection);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// adjust selection unless it was an inline style manipulation
|
||||
// see above commented out code: we're just being safe for now
|
||||
// with the minimal change to fix selection problem when removing
|
||||
// link property
|
||||
if ((action != nsEditor::kOpSetTextProperty) &&
|
||||
(action != nsEditor::kOpRemoveTextProperty))
|
||||
{
|
||||
res = AdjustSelection(selection, aDirection);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
||||
// adjust selection
|
||||
res = AdjustSelection(selection, aDirection);
|
||||
if (NS_FAILED(res)) return res;
|
||||
// detect empty doc
|
||||
res = CreateBogusNodeIfNeeded(selection);
|
||||
|
||||
|
@ -381,36 +404,6 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
|||
else
|
||||
blockParent = mEditor->GetBlockNodeParent(selNode);
|
||||
if (!blockParent) return NS_ERROR_FAILURE;
|
||||
|
||||
// are we not in a textnode?
|
||||
if (!mEditor->IsTextNode(selNode))
|
||||
{
|
||||
// find a nearby text node if possible
|
||||
nsCOMPtr<nsIDOMNode> priorNode, nextNode;
|
||||
res = GetPriorHTMLNode(selNode, selOffset, &priorNode);
|
||||
if (NS_SUCCEEDED(res) && priorNode && mEditor->IsTextNode(priorNode)
|
||||
&& (blockParent == mEditor->GetBlockNodeParent(priorNode)))
|
||||
{
|
||||
// put selection at end of prior node
|
||||
PRUint32 strLength;
|
||||
nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(priorNode);
|
||||
res = textNode->GetLength(&strLength);
|
||||
if (NS_FAILED(res)) return res;
|
||||
res = aSelection->Collapse(priorNode, strLength);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = GetNextHTMLNode(selNode, selOffset, &nextNode);
|
||||
if (NS_SUCCEEDED(res) && nextNode && mEditor->IsTextNode(nextNode)
|
||||
&& (blockParent == mEditor->GetBlockNodeParent(nextNode)))
|
||||
{
|
||||
// put selection at begining of next node
|
||||
res = aSelection->Collapse(nextNode, 0);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PRBool bCancel;
|
||||
nsString theString(*inString); // copy instring for now
|
||||
|
@ -3288,7 +3281,7 @@ nsHTMLEditRules::AdjustSelection(nsIDOMSelection *aSelection, nsIEditor::EDirect
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// we aren't in a textnode: are we adjacent to a break or an image?
|
||||
res = GetPriorHTMLSibling(selNode, selOffset, &nearNode);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
@ -3325,6 +3318,7 @@ nsHTMLEditRules::AdjustSelection(nsIDOMSelection *aSelection, nsIEditor::EDirect
|
|||
if (aAction == nsIEditor::ePrevious) selOffset++; // want to be beyond it if we backed up to it
|
||||
res = aSelection->Collapse(selNode, selOffset);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -224,6 +224,7 @@ nsHTMLEditor::nsHTMLEditor()
|
|||
mItalicAtom = getter_AddRefs(NS_NewAtom("i"));
|
||||
mUnderlineAtom = getter_AddRefs(NS_NewAtom("u"));
|
||||
mFontAtom = getter_AddRefs(NS_NewAtom("font"));
|
||||
mLinkAtom = getter_AddRefs(NS_NewAtom("a"));
|
||||
|
||||
if (!gTypingTxnName)
|
||||
gTypingTxnName = NS_NewAtom("Typing");
|
||||
|
@ -1248,7 +1249,38 @@ NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsStr
|
|||
if (PR_TRUE==isCollapsed)
|
||||
{
|
||||
// manipulating text attributes on a collapsed selection only sets state for the next text insertion
|
||||
SetTypeInStateForProperty(*mTypeInState, aProperty, aAttribute, nsnull);
|
||||
// But only if it's a property for which we have TypeInState!
|
||||
if ( (aProperty == mBoldAtom.get()) ||
|
||||
(aProperty == mItalicAtom.get()) ||
|
||||
(aProperty == mUnderlineAtom.get()) )
|
||||
{
|
||||
SetTypeInStateForProperty(*mTypeInState, aProperty, aAttribute, nsnull);
|
||||
}
|
||||
else if (aProperty == mLinkAtom.get())
|
||||
{
|
||||
// a hack for links. The user is trying to kill the link "style" where
|
||||
// they are typing. We need to split up through any link elements above the
|
||||
// collapsed insertion point.
|
||||
nsCOMPtr<nsIDOMNode> selNode, tmpNode, parent;
|
||||
PRInt32 selOffset, outOffset;
|
||||
result = GetStartNodeAndOffset(selection, &selNode, &selOffset);
|
||||
if (NS_FAILED(result)) return result;
|
||||
tmpNode = selNode;
|
||||
while (tmpNode)
|
||||
{
|
||||
if (nsHTMLEditUtils::IsBody(tmpNode)) break;
|
||||
if (IsLinkNode(tmpNode))
|
||||
{
|
||||
result = SplitNodeDeep(tmpNode, selNode, selOffset, &outOffset);
|
||||
if (NS_FAILED(result)) return result;
|
||||
tmpNode->GetParentNode(getter_AddRefs(parent));
|
||||
selection->Collapse(parent, outOffset);
|
||||
break;
|
||||
}
|
||||
tmpNode->GetParentNode(getter_AddRefs(parent));
|
||||
tmpNode = parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -593,6 +593,7 @@ protected:
|
|||
nsCOMPtr<nsIAtom> mItalicAtom;
|
||||
nsCOMPtr<nsIAtom> mUnderlineAtom;
|
||||
nsCOMPtr<nsIAtom> mFontAtom;
|
||||
nsCOMPtr<nsIAtom> mLinkAtom;
|
||||
nsCOMPtr<nsIDOMNode> mCachedNode;
|
||||
|
||||
PRBool mCachedBoldStyle;
|
||||
|
|
|
@ -1430,9 +1430,6 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
|||
if (!bodyElement) return NS_ERROR_NULL_POINTER;
|
||||
nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> bogusNodeParent (bodyNode);
|
||||
PRInt32 bogusNodeOffset = 0;
|
||||
|
||||
// now we've got the body tag.
|
||||
// iterate the body tag, looking for editable content
|
||||
// if no editable content is found, insert the bogus node
|
||||
|
@ -1450,38 +1447,11 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
|||
bodyChild->GetNextSibling(getter_AddRefs(temp));
|
||||
bodyChild = do_QueryInterface(temp);
|
||||
}
|
||||
|
||||
// Also, if we just inserted a non-text node, and if there's
|
||||
// no editable content after the newly inserted node, then
|
||||
// we need a bogus node at the end of the document:
|
||||
if (!needsBogusContent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> focusParent;
|
||||
aSelection->GetFocusNode(getter_AddRefs(focusParent));
|
||||
if (focusParent && !mEditor->IsTextNode(focusParent))
|
||||
{
|
||||
PRInt32 focusOffset;
|
||||
if (NS_SUCCEEDED(aSelection->GetFocusOffset(&focusOffset)))
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> child = mEditor->GetChildAt(focusParent,
|
||||
focusOffset+1);
|
||||
|
||||
if (!child || !mEditor->IsEditable(child))
|
||||
{
|
||||
needsBogusContent = PR_TRUE;
|
||||
bogusNodeParent = focusParent;
|
||||
bogusNodeOffset = focusOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (needsBogusContent)
|
||||
{
|
||||
// set mBogusNode to be the newly created <br>
|
||||
res = mEditor->CreateNode(nsAutoString("br"),
|
||||
bogusNodeParent, bogusNodeOffset,
|
||||
getter_AddRefs(mBogusNode));
|
||||
res = mEditor->CreateNode(nsAutoString("br"), bodyNode, 0,
|
||||
getter_AddRefs(mBogusNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (!mBogusNode) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
|
@ -1496,7 +1466,7 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsIDOMSelection *aSelection)
|
|||
}
|
||||
|
||||
// set selection
|
||||
aSelection->Collapse(bogusNodeParent, bogusNodeOffset);
|
||||
aSelection->Collapse(bodyNode,0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче