diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp index 30fba6613e4..f8c9a590097 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp @@ -948,9 +948,7 @@ nsHTMLEditRules::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent) { nsCOMPtr curNode = arrayOfNodes[i]; - if (nsHTMLEditUtils::IsList(curNode) || - nsHTMLEditUtils::IsListItem(curNode) || - nsHTMLEditUtils::IsBlockquote(curNode)) + if (nsHTMLEditUtils::IsNodeThatCanOutdent(curNode)) { *aCanOutdent = PR_TRUE; break; @@ -992,14 +990,12 @@ nsHTMLEditRules::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent) if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; - // test start parent heirachy + // test start parent hierarchy res = mHTMLEditor->GetStartNodeAndOffset(selection, address_of(parent), &selOffset); if (NS_FAILED(res)) return res; while (parent && (parent!=root)) { - if (nsHTMLEditUtils::IsList(parent) || - nsHTMLEditUtils::IsListItem(parent) || - nsHTMLEditUtils::IsBlockquote(parent)) + if (nsHTMLEditUtils::IsNodeThatCanOutdent(parent)) { *aCanOutdent = PR_TRUE; break; @@ -1008,14 +1004,12 @@ nsHTMLEditRules::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent) tmp->GetParentNode(getter_AddRefs(parent)); } - // test end parent heirachy + // test end parent hierarchy res = mHTMLEditor->GetEndNodeAndOffset(selection, address_of(parent), &selOffset); if (NS_FAILED(res)) return res; while (parent && (parent!=root)) { - if (nsHTMLEditUtils::IsList(parent) || - nsHTMLEditUtils::IsListItem(parent) || - nsHTMLEditUtils::IsBlockquote(parent)) + if (nsHTMLEditUtils::IsNodeThatCanOutdent(parent)) { *aCanOutdent = PR_TRUE; break; @@ -1056,7 +1050,7 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) nsCOMPtr curNode = arrayOfNodes[i]; nsAutoString format; // if it is a known format node we have it easy - if (IsBlockNode(curNode) && !IsFormatNode(curNode)) + if (IsBlockNode(curNode) && !nsHTMLEditUtils::IsFormatNode(curNode)) { // arrayOfNodes.RemoveObject(curNode); res = AppendInnerFormatNodes(arrayOfNodes, curNode); @@ -1093,7 +1087,7 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) nsCOMPtr curNode = arrayOfNodes[i]; nsAutoString format; // if it is a known format node we have it easy - if (IsFormatNode(curNode)) + if (nsHTMLEditUtils::IsFormatNode(curNode)) GetFormatString(curNode, format); else if (IsBlockNode(curNode)) { @@ -1114,7 +1108,7 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) format.Truncate(0); break; } - else if (IsFormatNode(node)) + else if (nsHTMLEditUtils::IsFormatNode(node)) { GetFormatString(node, format); break; @@ -1141,18 +1135,6 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) return res; } -PRBool -nsHTMLEditRules::IsFormatNode(nsIDOMNode *aNode) -{ - if (!aNode) return NS_ERROR_NULL_POINTER; - if (nsHTMLEditUtils::IsParagraph(aNode) || - nsHTMLEditUtils::IsPre(aNode) || - nsHTMLEditUtils::IsHeader(aNode) || - nsHTMLEditUtils::IsAddress(aNode) ) - return PR_TRUE; - return PR_FALSE; -} - nsresult nsHTMLEditRules::AppendInnerFormatNodes(nsCOMArray& aArray, nsIDOMNode *aNode) @@ -1176,7 +1158,7 @@ nsHTMLEditRules::AppendInnerFormatNodes(nsCOMArray& aArray, { childList->Item(j, getter_AddRefs(child)); PRBool isBlock = IsBlockNode(child); - PRBool isFormat = IsFormatNode(child); + PRBool isFormat = nsHTMLEditUtils::IsFormatNode(child); if (isBlock && !isFormat) // if it's a div, etc, recurse AppendInnerFormatNodes(aArray, child); else if (isFormat) @@ -1198,12 +1180,9 @@ nsHTMLEditRules::GetFormatString(nsIDOMNode *aNode, nsAString &outFormat) { if (!aNode) return NS_ERROR_NULL_POINTER; - nsCOMPtr atom = mHTMLEditor->GetTag(aNode); - if (nsEditProperty::p == atom || - nsEditProperty::address == atom || - nsEditProperty::pre == atom || - nsHTMLEditUtils::IsHeader(aNode)) + if (nsHTMLEditUtils::IsFormatNode(aNode)) { + nsCOMPtr atom = nsEditor::GetTag(aNode); atom->ToString(outFormat); } else @@ -2771,7 +2750,7 @@ nsHTMLEditRules::DeleteNonTableElements(nsIDOMNode *aNode) { if (!aNode) return NS_ERROR_NULL_POINTER; nsresult res = NS_OK; - if (nsHTMLEditUtils::IsTableElement(aNode) && !nsHTMLEditUtils::IsTable(aNode)) + if (nsHTMLEditUtils::IsTableElementButNotTable(aNode)) { nsCOMPtr children; aNode->GetChildNodes(getter_AddRefs(children)); @@ -3296,10 +3275,7 @@ nsHTMLEditRules::WillMakeBasicBlock(nsISelection *aSelection, nsCOMPtr curBlockPar; if (!curBlock) return NS_ERROR_NULL_POINTER; curBlock->GetParentNode(getter_AddRefs(curBlockPar)); - if (nsHTMLEditUtils::IsPre(curBlock) || - nsHTMLEditUtils::IsParagraph(curBlock) || - nsHTMLEditUtils::IsHeader(curBlock) || - nsHTMLEditUtils::IsAddress(curBlock)) + if (nsHTMLEditUtils::IsFormatNode(curBlock)) { // if the first editable node after selection is a br, consume it. Otherwise // it gets pushed into a following block after the split, which is visually bad. @@ -5629,7 +5605,7 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray& inArrayOfRanges, for (i=listCount-1; i>=0; i--) { nsCOMPtr node = outArrayOfNodes[i]; - if ( (nsHTMLEditUtils::IsTableElement(node) && !nsHTMLEditUtils::IsTable(node)) ) + if (nsHTMLEditUtils::IsTableElementButNotTable(node)) { PRInt32 j=i; outArrayOfNodes.RemoveObjectAt(i); @@ -5791,7 +5767,7 @@ nsHTMLEditRules::GetListActionNodes(nsCOMArray &outArrayOfNodes, // scan for table elements and divs. If we find table elements other than table, // replace it with a list of any editable non-table content. - if (nsHTMLEditUtils::IsTableElement(testNode) && !nsHTMLEditUtils::IsTable(testNode)) + if (nsHTMLEditUtils::IsTableElementButNotTable(testNode)) { PRInt32 j=i; outArrayOfNodes.RemoveObjectAt(i); @@ -6438,7 +6414,7 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection, // sanity check NS_PRECONDITION(PR_TRUE == nsHTMLEditUtils::IsListItem(aListItem), - "expected a list item and didnt get one"); + "expected a list item and didn't get one"); // if we are in an empty listitem, then we want to pop up out of the list PRBool isEmpty; @@ -6591,8 +6567,8 @@ nsHTMLEditRules::MakeBlockquote(nsCOMArray& arrayOfNodes) if (NS_FAILED(res)) return res; // if the node is a table element or list item, dive inside - if ( (nsHTMLEditUtils::IsTableElement(curNode) && !(nsHTMLEditUtils::IsTable(curNode))) || - nsHTMLEditUtils::IsListItem(curNode) ) + if (nsHTMLEditUtils::IsTableElementButNotTable(curNode) || + nsHTMLEditUtils::IsListItem(curNode)) { curBlock = 0; // forget any previous block // recursion time @@ -6670,10 +6646,7 @@ nsHTMLEditRules::RemoveBlockStyle(nsCOMArray& arrayOfNodes) ToLowerCase(curNodeTag); // if curNode is a address, p, header, address, or pre, remove it - if (nsHTMLEditUtils::IsPre(curNode) || - nsHTMLEditUtils::IsParagraph(curNode) || - nsHTMLEditUtils::IsHeader(curNode) || - nsHTMLEditUtils::IsAddress(curNode)) + if (nsHTMLEditUtils::IsFormatNode(curNode)) { // process any partial progress saved if (curBlock) @@ -6731,10 +6704,7 @@ nsHTMLEditRules::RemoveBlockStyle(nsCOMArray& arrayOfNodes) } } curBlock = mHTMLEditor->GetBlockNodeParent(curNode); - if (nsHTMLEditUtils::IsPre(curBlock) || - nsHTMLEditUtils::IsParagraph(curBlock) || - nsHTMLEditUtils::IsHeader(curBlock) || - nsHTMLEditUtils::IsAddress(curBlock)) + if (nsHTMLEditUtils::IsFormatNode(curBlock)) { firstNode = curNode; lastNode = curNode; @@ -6818,10 +6788,7 @@ nsHTMLEditRules::ApplyBlockStyle(nsCOMArray& arrayOfNodes, const nsA // it with a new block of correct type. // xxx floppy moose: pre cant hold everything the others can if (nsHTMLEditUtils::IsMozDiv(curNode) || - nsHTMLEditUtils::IsPre(curNode) || - nsHTMLEditUtils::IsParagraph(curNode) || - nsHTMLEditUtils::IsHeader(curNode) || - nsHTMLEditUtils::IsAddress(curNode)) + nsHTMLEditUtils::IsFormatNode(curNode)) { curBlock = 0; // forget any previous block used for previous inline nodes res = mHTMLEditor->ReplaceContainer(curNode, address_of(newBlock), *aBlockTag); @@ -7658,39 +7625,25 @@ nsHTMLEditRules::RemoveEmptyNodes() PRBool bIsCandidate = PR_FALSE; PRBool bIsEmptyNode = PR_FALSE; PRBool bIsMailCite = PR_FALSE; - - // dont delete the body + + // don't delete the body if (!nsTextEditUtils::IsBody(node)) { // only consider certain nodes to be empty for purposes of removal if ( (bIsMailCite = nsHTMLEditUtils::IsMailCite(node)) || nsEditor::NodeIsType(node, nsEditProperty::a) || - nsEditor::NodeIsType(node, nsEditProperty::b) || - nsEditor::NodeIsType(node, nsEditProperty::i) || - nsEditor::NodeIsType(node, nsEditProperty::u) || - nsEditor::NodeIsType(node, nsEditProperty::tt) || - nsEditor::NodeIsType(node, nsEditProperty::s) || - nsEditor::NodeIsType(node, nsEditProperty::strike) || - nsHTMLEditUtils::IsBig(node) || - nsHTMLEditUtils::IsSmall(node) || - nsEditor::NodeIsType(node, nsEditProperty::blink) || - nsEditor::NodeIsType(node, nsEditProperty::sub) || - nsEditor::NodeIsType(node, nsEditProperty::sup) || - nsEditor::NodeIsType(node, nsEditProperty::font) || + nsHTMLEditUtils::IsInlineStyle(node) || nsHTMLEditUtils::IsList(node) || nsHTMLEditUtils::IsDiv(node) ) { bIsCandidate = PR_TRUE; } // these node types are candidates if selection is not in them - else if (nsHTMLEditUtils::IsParagraph(node) || - nsHTMLEditUtils::IsHeader(node) || + else if (nsHTMLEditUtils::IsFormatNode(node) || nsHTMLEditUtils::IsListItem(node) || - nsHTMLEditUtils::IsBlockquote(node)|| - nsHTMLEditUtils::IsPre(node) || - nsHTMLEditUtils::IsAddress(node) ) + nsHTMLEditUtils::IsBlockquote(node) ) { - // if it is one of these, dont delete if sel inside. + // if it is one of these, don't delete if selection inside. // this is so we can create empty headings, etc, for the // user to type into. PRBool bIsSelInNode; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.h b/mozilla/editor/libeditor/html/nsHTMLEditRules.h index a9817ca5892..4dc459fec18 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditRules.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.h @@ -174,7 +174,6 @@ protected: nsresult DidAbsolutePosition(); nsresult AlignInnerBlocks(nsIDOMNode *aNode, const nsAString *alignType); nsresult AlignBlockContents(nsIDOMNode *aNode, const nsAString *alignType); - PRBool IsFormatNode(nsIDOMNode *aNode); nsresult AppendInnerFormatNodes(nsCOMArray& aArray, nsIDOMNode *aNode); nsresult GetFormatString(nsIDOMNode *aNode, nsAString &outFormat); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditUtils.cpp b/mozilla/editor/libeditor/html/nsHTMLEditUtils.cpp index 4d48711c168..931c1879302 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditUtils.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditUtils.cpp @@ -58,6 +58,64 @@ nsHTMLEditUtils::IsBig(nsIDOMNode *node) } +/////////////////////////////////////////////////////////////////////////// +// IsInlineStyle true if node is an inline style +// +PRBool +nsHTMLEditUtils::IsInlineStyle(nsIDOMNode *node) +{ + NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsInlineStyle"); + nsCOMPtr nodeAtom = nsEditor::GetTag(node); + return (nodeAtom == nsEditProperty::b) + || (nodeAtom == nsEditProperty::i) + || (nodeAtom == nsEditProperty::u) + || (nodeAtom == nsEditProperty::tt) + || (nodeAtom == nsEditProperty::s) + || (nodeAtom == nsEditProperty::strike) + || (nodeAtom == nsEditProperty::big) + || (nodeAtom == nsEditProperty::small) + || (nodeAtom == nsEditProperty::blink) + || (nodeAtom == nsEditProperty::sub) + || (nodeAtom == nsEditProperty::sup) + || (nodeAtom == nsEditProperty::font); +} + +/////////////////////////////////////////////////////////////////////////// +// IsFormatNode true if node is a format node +// +PRBool +nsHTMLEditUtils::IsFormatNode(nsIDOMNode *node) +{ + NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsFormatNode"); + nsCOMPtr nodeAtom = nsEditor::GetTag(node); + return (nodeAtom == nsEditProperty::p) + || (nodeAtom == nsEditProperty::pre) + || (nodeAtom == nsEditProperty::h1) + || (nodeAtom == nsEditProperty::h2) + || (nodeAtom == nsEditProperty::h3) + || (nodeAtom == nsEditProperty::h4) + || (nodeAtom == nsEditProperty::h5) + || (nodeAtom == nsEditProperty::h6) + || (nodeAtom == nsEditProperty::address); +} + +/////////////////////////////////////////////////////////////////////////// +// IsNodeThatCanOutdent true if node is a list, list item, or blockquote +// +PRBool +nsHTMLEditUtils::IsNodeThatCanOutdent(nsIDOMNode *node) +{ + NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsNodeThatCanOutdent"); + nsCOMPtr nodeAtom = nsEditor::GetTag(node); + return (nodeAtom == nsEditProperty::ul) + || (nodeAtom == nsEditProperty::ol) + || (nodeAtom == nsEditProperty::dl) + || (nodeAtom == nsEditProperty::li) + || (nodeAtom == nsEditProperty::dd) + || (nodeAtom == nsEditProperty::dt) + || (nodeAtom == nsEditProperty::blockquote); +} + /////////////////////////////////////////////////////////////////////////// // PRBool @@ -140,6 +198,22 @@ nsHTMLEditUtils::IsTableElement(nsIDOMNode *node) || (nodeAtom == nsEditProperty::caption); } +/////////////////////////////////////////////////////////////////////////// +// IsTableElementButNotTable: true if node an html td, tr, ... (doesn't include table) +// +PRBool +nsHTMLEditUtils::IsTableElementButNotTable(nsIDOMNode *node) +{ + NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTableElementButNotTable"); + nsCOMPtr nodeAtom = nsEditor::GetTag(node); + return (nodeAtom == nsEditProperty::tr) + || (nodeAtom == nsEditProperty::td) + || (nodeAtom == nsEditProperty::th) + || (nodeAtom == nsEditProperty::thead) + || (nodeAtom == nsEditProperty::tfoot) + || (nodeAtom == nsEditProperty::tbody) + || (nodeAtom == nsEditProperty::caption); +} /////////////////////////////////////////////////////////////////////////// // IsTable: true if node an html table diff --git a/mozilla/editor/libeditor/html/nsHTMLEditUtils.h b/mozilla/editor/libeditor/html/nsHTMLEditUtils.h index 52cc7dd0b92..ebb7713f9d8 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditUtils.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditUtils.h @@ -52,6 +52,9 @@ public: static PRBool IsSmall(nsIDOMNode *aNode); // from nsHTMLEditRules: + static PRBool IsInlineStyle(nsIDOMNode *aNode); + static PRBool IsFormatNode(nsIDOMNode *aNode); + static PRBool IsNodeThatCanOutdent(nsIDOMNode *aNode); static PRBool IsHeader(nsIDOMNode *aNode); static PRBool IsParagraph(nsIDOMNode *aNode); static PRBool IsHR(nsIDOMNode *aNode); @@ -59,6 +62,7 @@ public: static PRBool IsTable(nsIDOMNode *aNode); static PRBool IsTableRow(nsIDOMNode *aNode); static PRBool IsTableElement(nsIDOMNode *aNode); + static PRBool IsTableElementButNotTable(nsIDOMNode *aNode); static PRBool IsTableCell(nsIDOMNode *aNode); static PRBool IsTableCellOrCaption(nsIDOMNode *aNode); static PRBool IsList(nsIDOMNode *aNode); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 509a9f36a62..eb08ed00b58 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -5524,14 +5524,14 @@ nsHTMLEditor::IsEmptyNodeImpl( nsIDOMNode *aNode, if (isListItemOrCell) { if (nsHTMLEditUtils::IsList(node) || nsHTMLEditUtils::IsTable(node)) - { // break out if we find we aren't emtpy + { // break out if we find we aren't empty *outIsEmptyNode = PR_FALSE; return NS_OK; } } // is it a form widget? else if (nsHTMLEditUtils::IsFormWidget(aNode)) - { // break out if we find we aren't emtpy + { // break out if we find we aren't empty *outIsEmptyNode = PR_FALSE; return NS_OK; } @@ -5993,18 +5993,7 @@ nsHTMLEditor::CopyLastEditableChildStyles(nsIDOMNode * aPreviousBlock, nsIDOMNod } nsCOMPtr newStyles = nsnull, deepestStyle = nsnull; while (child && (child != aPreviousBlock)) { - if (nsEditor::NodeIsType(child, nsEditProperty::b) || - nsEditor::NodeIsType(child, nsEditProperty::i) || - nsEditor::NodeIsType(child, nsEditProperty::u) || - nsEditor::NodeIsType(child, nsEditProperty::tt) || - nsEditor::NodeIsType(child, nsEditProperty::s) || - nsEditor::NodeIsType(child, nsEditProperty::strike) || - nsHTMLEditUtils::IsBig(child) || - nsHTMLEditUtils::IsSmall(child) || - nsEditor::NodeIsType(child, nsEditProperty::blink) || - nsEditor::NodeIsType(child, nsEditProperty::sub) || - nsEditor::NodeIsType(child, nsEditProperty::sup) || - nsEditor::NodeIsType(child, nsEditProperty::font) || + if (nsHTMLEditUtils::IsInlineStyle(child) || nsEditor::NodeIsType(child, nsEditProperty::span)) { nsAutoString domTagName; child->GetNodeName(domTagName);