This commit is contained in:
jfrancis%netscape.com 2000-06-29 09:23:41 +00:00
Родитель 48d82867a9
Коммит 6669bb643d
12 изменённых файлов: 170 добавлений и 68 удалений

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

@ -2178,20 +2178,8 @@ NS_IMETHODIMP nsEditor::OutputToStream(nsIOutputStream* aOutputStream,
NS_IMETHODIMP NS_IMETHODIMP
nsEditor::DumpContentTree() nsEditor::DumpContentTree()
{ {
nsCOMPtr<nsIDocument> thedoc; nsCOMPtr<nsIContent> root = do_QueryInterface(mBodyElement);
nsCOMPtr<nsIPresShell> presShell; if (root) root->List(stdout);
if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))))
{
presShell->GetDocument(getter_AddRefs(thedoc));
if (thedoc) {
nsIContent* root = thedoc->GetRootContent();
if (nsnull != root) {
root->List(stdout);
NS_RELEASE(root);
}
}
}
return NS_OK; return NS_OK;
} }

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

@ -605,7 +605,7 @@ public:
/** returns PR_TRUE if aParent can contain a child of type aTag */ /** returns PR_TRUE if aParent can contain a child of type aTag */
PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag); PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag);
PRBool TagCanContain(const nsString &aParentTag, nsIDOMNode* aChild); PRBool TagCanContain(const nsString &aParentTag, nsIDOMNode* aChild);
PRBool TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag); virtual PRBool TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag);
/** returns PR_TRUE if aNode is a descendant of our root node */ /** returns PR_TRUE if aNode is a descendant of our root node */
PRBool IsDescendantOfBody(nsIDOMNode *inNode); PRBool IsDescendantOfBody(nsIDOMNode *inNode);

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

@ -520,7 +520,34 @@ nsHTMLEditRules::GetParagraphState(PRBool &aMixed, nsString &outFormat)
nsCOMPtr<nsIAtom> atom = mEditor->GetTag(curNode); nsCOMPtr<nsIAtom> atom = mEditor->GetTag(curNode);
if (mEditor->IsInlineNode(curNode)) if (mEditor->IsInlineNode(curNode))
{
nsCOMPtr<nsIDOMNode> block = mEditor->GetBlockNodeParent(curNode);
if (block)
{
nsCOMPtr<nsIAtom> blockAtom = mEditor->GetTag(block);
if ( nsIEditProperty::p == blockAtom.get() ||
nsIEditProperty::blockquote == blockAtom.get() ||
nsIEditProperty::address == blockAtom.get() ||
nsIEditProperty::pre == blockAtom.get() )
{
blockAtom->ToString(format);
}
else if (nsHTMLEditUtils::IsHeader(block))
{
nsAutoString tag;
nsEditor::GetTagString(block,tag);
format = tag;
}
else
{
format.AssignWithConversion(""); format.AssignWithConversion("");
}
}
else
{
format.AssignWithConversion("");
}
}
else if (nsHTMLEditUtils::IsHeader(curNode)) else if (nsHTMLEditUtils::IsHeader(curNode))
{ {
nsAutoString tag; nsAutoString tag;
@ -530,9 +557,7 @@ nsHTMLEditRules::GetParagraphState(PRBool &aMixed, nsString &outFormat)
else if (nsIEditProperty::p == atom.get() || else if (nsIEditProperty::p == atom.get() ||
nsIEditProperty::blockquote == atom.get() || nsIEditProperty::blockquote == atom.get() ||
nsIEditProperty::address == atom.get() || nsIEditProperty::address == atom.get() ||
nsIEditProperty::pre == atom.get() || nsIEditProperty::pre == atom.get() )
nsIEditProperty::dt == atom.get() ||
nsIEditProperty::dd == atom.get() )
{ {
atom->ToString(format); atom->ToString(format);
} }
@ -2224,12 +2249,29 @@ nsHTMLEditRules::WillAlign(nsIDOMSelection *aSelection,
if (outMakeEmpty) if (outMakeEmpty)
{ {
PRInt32 offset; PRInt32 offset;
nsCOMPtr<nsIDOMNode> brNode, parent, theDiv; nsCOMPtr<nsIDOMNode> brNode, parent, theDiv, sib;
nsAutoString divType; divType.AssignWithConversion("div"); nsAutoString divType; divType.AssignWithConversion("div");
res = mEditor->GetStartNodeAndOffset(aSelection, &parent, &offset); res = mEditor->GetStartNodeAndOffset(aSelection, &parent, &offset);
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
res = SplitAsNeeded(&divType, &parent, &offset); res = SplitAsNeeded(&divType, &parent, &offset);
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
// consume a trailing br, if any. This is to keep an alignment from
// creating extra lines, if possible.
res = mEditor->GetNextHTMLNode(parent, offset, &brNode);
if (NS_FAILED(res)) return res;
if (nsHTMLEditUtils::IsBreak(brNode))
{
// making use of html structure... if next node after where
// we are putting our div is not a block, then the br we
// found is in same block we are, so its safe to consume it.
res = mEditor->GetNextHTMLSibling(parent, offset, &sib);
if (NS_FAILED(res)) return res;
if (!nsEditor::IsBlockNode(sib))
{
res = mEditor->DeleteNode(brNode);
if (NS_FAILED(res)) return res;
}
}
res = mEditor->CreateNode(divType, parent, offset, getter_AddRefs(theDiv)); res = mEditor->CreateNode(divType, parent, offset, getter_AddRefs(theDiv));
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
// set up the alignment on the div // set up the alignment on the div
@ -3662,8 +3704,8 @@ nsHTMLEditRules::ShouldMakeEmptyBlock(nsIDOMSelection *aSelection,
res = nsEditor::GetStartNodeAndOffset(aSelection, &parent, &offset); res = nsEditor::GetStartNodeAndOffset(aSelection, &parent, &offset);
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
// is selection point in the body? // is selection point in the body? or a cell?
if (nsHTMLEditUtils::IsBody(parent)) if (nsHTMLEditUtils::IsBody(parent) || mEditor->IsTableCell(parent))
{ {
*outMakeEmpty = PR_TRUE; *outMakeEmpty = PR_TRUE;
return res; return res;

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

@ -5794,19 +5794,39 @@ nsHTMLEditor::EndOperation(PRInt32 opID, nsIEditor::EDirection aDirection)
PRBool PRBool
nsHTMLEditor::CanContainTag(nsIDOMNode* aParent, const nsString &aTag) nsHTMLEditor::TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag)
{ {
// CNavDTD gives some unwanted results. We override them here. // CNavDTD gives some unwanted results. We override them here.
if ( aParentTag.EqualsWithConversion("ol") ||
aParentTag.EqualsWithConversion("ul") )
{
// if parent is a list and tag is text, say "no". // if parent is a list and tag is text, say "no".
if (IsListNode(aParent) && (aTag.EqualsWithConversion("__moz_text"))) if (aChildTag.EqualsWithConversion("__moz_text"))
return PR_FALSE; return PR_FALSE;
// if both are lists, return true // if both are lists, return true
if (IsListNode(aParent) && if (aChildTag.EqualsWithConversion("ol") ||
( aTag.EqualsWithConversion("ol") || aChildTag.EqualsWithConversion("ul") )
aTag.EqualsWithConversion("ul") ) )
return PR_TRUE; return PR_TRUE;
}
// if parent is a pre, and child is not inline, say "no"
if ( aParentTag.EqualsWithConversion("pre") )
{
if (aChildTag.EqualsWithConversion("__moz_text"))
return PR_TRUE;
PRInt32 childTagEnum, parentTagEnum;
nsAutoString non_const_childTag(aChildTag);
nsAutoString non_const_parentTag(aParentTag);
nsresult res = mDTD->StringTagToIntTag(non_const_childTag,&childTagEnum);
if (NS_FAILED(res)) return PR_FALSE;
res = mDTD->StringTagToIntTag(non_const_parentTag,&parentTagEnum);
if (NS_FAILED(res)) return PR_FALSE;
if (!mDTD->IsInlineElement(childTagEnum,parentTagEnum))
return PR_FALSE;
}
// else fall thru // else fall thru
return nsEditor::CanContainTag(aParent, aTag); return nsEditor::TagCanContainTag(aParentTag, aChildTag);
} }

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

@ -286,8 +286,8 @@ public:
* with a call to EndOperation, naming the action and direction */ * with a call to EndOperation, naming the action and direction */
NS_IMETHOD EndOperation(PRInt32 opID, nsIEditor::EDirection aDirection); NS_IMETHOD EndOperation(PRInt32 opID, nsIEditor::EDirection aDirection);
/** returns PR_TRUE if aParent can contain a child of type aTag */ /** returns PR_TRUE if aParentTag can contain a child of type aChildTag */
PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag); virtual PRBool TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag);
/** make the given selection span the entire document */ /** make the given selection span the entire document */
NS_IMETHOD SelectEntireDocument(nsIDOMSelection *aSelection); NS_IMETHOD SelectEntireDocument(nsIDOMSelection *aSelection);

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

@ -555,6 +555,7 @@ nsTextEditRules::DidInsertBreak(nsIDOMSelection *aSelection, nsresult aResult)
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
} }
} }
// mEditor->DumpContentTree();
return res; return res;
} }

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

@ -2178,20 +2178,8 @@ NS_IMETHODIMP nsEditor::OutputToStream(nsIOutputStream* aOutputStream,
NS_IMETHODIMP NS_IMETHODIMP
nsEditor::DumpContentTree() nsEditor::DumpContentTree()
{ {
nsCOMPtr<nsIDocument> thedoc; nsCOMPtr<nsIContent> root = do_QueryInterface(mBodyElement);
nsCOMPtr<nsIPresShell> presShell; if (root) root->List(stdout);
if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))))
{
presShell->GetDocument(getter_AddRefs(thedoc));
if (thedoc) {
nsIContent* root = thedoc->GetRootContent();
if (nsnull != root) {
root->List(stdout);
NS_RELEASE(root);
}
}
}
return NS_OK; return NS_OK;
} }

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

@ -605,7 +605,7 @@ public:
/** returns PR_TRUE if aParent can contain a child of type aTag */ /** returns PR_TRUE if aParent can contain a child of type aTag */
PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag); PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag);
PRBool TagCanContain(const nsString &aParentTag, nsIDOMNode* aChild); PRBool TagCanContain(const nsString &aParentTag, nsIDOMNode* aChild);
PRBool TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag); virtual PRBool TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag);
/** returns PR_TRUE if aNode is a descendant of our root node */ /** returns PR_TRUE if aNode is a descendant of our root node */
PRBool IsDescendantOfBody(nsIDOMNode *inNode); PRBool IsDescendantOfBody(nsIDOMNode *inNode);

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

@ -520,7 +520,34 @@ nsHTMLEditRules::GetParagraphState(PRBool &aMixed, nsString &outFormat)
nsCOMPtr<nsIAtom> atom = mEditor->GetTag(curNode); nsCOMPtr<nsIAtom> atom = mEditor->GetTag(curNode);
if (mEditor->IsInlineNode(curNode)) if (mEditor->IsInlineNode(curNode))
{
nsCOMPtr<nsIDOMNode> block = mEditor->GetBlockNodeParent(curNode);
if (block)
{
nsCOMPtr<nsIAtom> blockAtom = mEditor->GetTag(block);
if ( nsIEditProperty::p == blockAtom.get() ||
nsIEditProperty::blockquote == blockAtom.get() ||
nsIEditProperty::address == blockAtom.get() ||
nsIEditProperty::pre == blockAtom.get() )
{
blockAtom->ToString(format);
}
else if (nsHTMLEditUtils::IsHeader(block))
{
nsAutoString tag;
nsEditor::GetTagString(block,tag);
format = tag;
}
else
{
format.AssignWithConversion(""); format.AssignWithConversion("");
}
}
else
{
format.AssignWithConversion("");
}
}
else if (nsHTMLEditUtils::IsHeader(curNode)) else if (nsHTMLEditUtils::IsHeader(curNode))
{ {
nsAutoString tag; nsAutoString tag;
@ -530,9 +557,7 @@ nsHTMLEditRules::GetParagraphState(PRBool &aMixed, nsString &outFormat)
else if (nsIEditProperty::p == atom.get() || else if (nsIEditProperty::p == atom.get() ||
nsIEditProperty::blockquote == atom.get() || nsIEditProperty::blockquote == atom.get() ||
nsIEditProperty::address == atom.get() || nsIEditProperty::address == atom.get() ||
nsIEditProperty::pre == atom.get() || nsIEditProperty::pre == atom.get() )
nsIEditProperty::dt == atom.get() ||
nsIEditProperty::dd == atom.get() )
{ {
atom->ToString(format); atom->ToString(format);
} }
@ -2224,12 +2249,29 @@ nsHTMLEditRules::WillAlign(nsIDOMSelection *aSelection,
if (outMakeEmpty) if (outMakeEmpty)
{ {
PRInt32 offset; PRInt32 offset;
nsCOMPtr<nsIDOMNode> brNode, parent, theDiv; nsCOMPtr<nsIDOMNode> brNode, parent, theDiv, sib;
nsAutoString divType; divType.AssignWithConversion("div"); nsAutoString divType; divType.AssignWithConversion("div");
res = mEditor->GetStartNodeAndOffset(aSelection, &parent, &offset); res = mEditor->GetStartNodeAndOffset(aSelection, &parent, &offset);
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
res = SplitAsNeeded(&divType, &parent, &offset); res = SplitAsNeeded(&divType, &parent, &offset);
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
// consume a trailing br, if any. This is to keep an alignment from
// creating extra lines, if possible.
res = mEditor->GetNextHTMLNode(parent, offset, &brNode);
if (NS_FAILED(res)) return res;
if (nsHTMLEditUtils::IsBreak(brNode))
{
// making use of html structure... if next node after where
// we are putting our div is not a block, then the br we
// found is in same block we are, so its safe to consume it.
res = mEditor->GetNextHTMLSibling(parent, offset, &sib);
if (NS_FAILED(res)) return res;
if (!nsEditor::IsBlockNode(sib))
{
res = mEditor->DeleteNode(brNode);
if (NS_FAILED(res)) return res;
}
}
res = mEditor->CreateNode(divType, parent, offset, getter_AddRefs(theDiv)); res = mEditor->CreateNode(divType, parent, offset, getter_AddRefs(theDiv));
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
// set up the alignment on the div // set up the alignment on the div
@ -3662,8 +3704,8 @@ nsHTMLEditRules::ShouldMakeEmptyBlock(nsIDOMSelection *aSelection,
res = nsEditor::GetStartNodeAndOffset(aSelection, &parent, &offset); res = nsEditor::GetStartNodeAndOffset(aSelection, &parent, &offset);
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
// is selection point in the body? // is selection point in the body? or a cell?
if (nsHTMLEditUtils::IsBody(parent)) if (nsHTMLEditUtils::IsBody(parent) || mEditor->IsTableCell(parent))
{ {
*outMakeEmpty = PR_TRUE; *outMakeEmpty = PR_TRUE;
return res; return res;

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

@ -5794,19 +5794,39 @@ nsHTMLEditor::EndOperation(PRInt32 opID, nsIEditor::EDirection aDirection)
PRBool PRBool
nsHTMLEditor::CanContainTag(nsIDOMNode* aParent, const nsString &aTag) nsHTMLEditor::TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag)
{ {
// CNavDTD gives some unwanted results. We override them here. // CNavDTD gives some unwanted results. We override them here.
if ( aParentTag.EqualsWithConversion("ol") ||
aParentTag.EqualsWithConversion("ul") )
{
// if parent is a list and tag is text, say "no". // if parent is a list and tag is text, say "no".
if (IsListNode(aParent) && (aTag.EqualsWithConversion("__moz_text"))) if (aChildTag.EqualsWithConversion("__moz_text"))
return PR_FALSE; return PR_FALSE;
// if both are lists, return true // if both are lists, return true
if (IsListNode(aParent) && if (aChildTag.EqualsWithConversion("ol") ||
( aTag.EqualsWithConversion("ol") || aChildTag.EqualsWithConversion("ul") )
aTag.EqualsWithConversion("ul") ) )
return PR_TRUE; return PR_TRUE;
}
// if parent is a pre, and child is not inline, say "no"
if ( aParentTag.EqualsWithConversion("pre") )
{
if (aChildTag.EqualsWithConversion("__moz_text"))
return PR_TRUE;
PRInt32 childTagEnum, parentTagEnum;
nsAutoString non_const_childTag(aChildTag);
nsAutoString non_const_parentTag(aParentTag);
nsresult res = mDTD->StringTagToIntTag(non_const_childTag,&childTagEnum);
if (NS_FAILED(res)) return PR_FALSE;
res = mDTD->StringTagToIntTag(non_const_parentTag,&parentTagEnum);
if (NS_FAILED(res)) return PR_FALSE;
if (!mDTD->IsInlineElement(childTagEnum,parentTagEnum))
return PR_FALSE;
}
// else fall thru // else fall thru
return nsEditor::CanContainTag(aParent, aTag); return nsEditor::TagCanContainTag(aParentTag, aChildTag);
} }

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

@ -286,8 +286,8 @@ public:
* with a call to EndOperation, naming the action and direction */ * with a call to EndOperation, naming the action and direction */
NS_IMETHOD EndOperation(PRInt32 opID, nsIEditor::EDirection aDirection); NS_IMETHOD EndOperation(PRInt32 opID, nsIEditor::EDirection aDirection);
/** returns PR_TRUE if aParent can contain a child of type aTag */ /** returns PR_TRUE if aParentTag can contain a child of type aChildTag */
PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag); virtual PRBool TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag);
/** make the given selection span the entire document */ /** make the given selection span the entire document */
NS_IMETHOD SelectEntireDocument(nsIDOMSelection *aSelection); NS_IMETHOD SelectEntireDocument(nsIDOMSelection *aSelection);

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

@ -555,6 +555,7 @@ nsTextEditRules::DidInsertBreak(nsIDOMSelection *aSelection, nsresult aResult)
if (NS_FAILED(res)) return res; if (NS_FAILED(res)) return res;
} }
} }
// mEditor->DumpContentTree();
return res; return res;
} }