From 43aec439d428b67499f87df006b7d3b0a2211968 Mon Sep 17 00:00:00 2001 From: "jfrancis%netscape.com" Date: Sun, 13 Aug 2000 23:53:34 +0000 Subject: [PATCH] fix for 45281, cannot insert a table caption. r=fm --- editor/base/nsHTMLEditRules.cpp | 28 +++++----- editor/base/nsHTMLEditUtils.cpp | 40 +++++++++++++++ editor/base/nsHTMLEditUtils.h | 2 + editor/base/nsHTMLEditor.cpp | 62 ++--------------------- editor/base/nsHTMLEditor.h | 3 -- editor/base/nsTableEditor.cpp | 2 +- editor/libeditor/html/nsHTMLEditRules.cpp | 28 +++++----- editor/libeditor/html/nsHTMLEditUtils.cpp | 40 +++++++++++++++ editor/libeditor/html/nsHTMLEditUtils.h | 2 + editor/libeditor/html/nsHTMLEditor.cpp | 62 ++--------------------- editor/libeditor/html/nsHTMLEditor.h | 3 -- editor/libeditor/html/nsTableEditor.cpp | 2 +- 12 files changed, 124 insertions(+), 150 deletions(-) diff --git a/editor/base/nsHTMLEditRules.cpp b/editor/base/nsHTMLEditRules.cpp index 07338e6adca..b5874f53585 100644 --- a/editor/base/nsHTMLEditRules.cpp +++ b/editor/base/nsHTMLEditRules.cpp @@ -1050,7 +1050,7 @@ nsHTMLEditRules::WillDeleteSelection(nsIDOMSelection *aSelection, return NS_OK; // bail to default // do not delete across table structures - if (mEditor->IsTableElement(leftParent) || mEditor->IsTableElement(rightParent)) + if (nsHTMLEditUtils::IsTableElement(leftParent) || nsHTMLEditUtils::IsTableElement(rightParent)) { *aCancel = PR_TRUE; return NS_OK; @@ -1159,7 +1159,7 @@ nsHTMLEditRules::WillDeleteSelection(nsIDOMSelection *aSelection, return NS_OK; // bail to default // do not delete across table structures - if (mEditor->IsTableElement(leftParent) || mEditor->IsTableElement(rightParent)) + if (nsHTMLEditUtils::IsTableElement(leftParent) || nsHTMLEditUtils::IsTableElement(rightParent)) { *aCancel = PR_TRUE; return NS_OK; @@ -1197,7 +1197,7 @@ nsHTMLEditRules::WillDeleteSelection(nsIDOMSelection *aSelection, // Note: do NOT delete table elements this way. PRBool bIsEmptyNode; res = mEditor->IsEmptyNode(node, &bIsEmptyNode, PR_TRUE, PR_FALSE); - if (bIsEmptyNode && !mEditor->IsTableElement(node)) + if (bIsEmptyNode && !nsHTMLEditUtils::IsTableElement(node)) nodeToDelete = node; else { @@ -1336,7 +1336,7 @@ nsHTMLEditRules::WillDeleteSelection(nsIDOMSelection *aSelection, rightParent = mEditor->GetBlockNodeParent(endNode); // do not delete across table structures - if (mEditor->IsTableElement(leftParent) || mEditor->IsTableElement(rightParent)) + if (nsHTMLEditUtils::IsTableElement(leftParent) || nsHTMLEditUtils::IsTableElement(rightParent)) { *aCancel = PR_TRUE; return NS_OK; @@ -2346,7 +2346,7 @@ nsHTMLEditRules::WillAlign(nsIDOMSelection *aSelection, // if it's a table element (but not a table), forget any "current" div, and // instead put divs inside any th's and td's inside the table element - if (mEditor->IsTableElement(curNode) && !mEditor->IsTable(curNode)) + if (nsHTMLEditUtils::IsTableElement(curNode) && !nsHTMLEditUtils::IsTable(curNode)) { res = AlignTableElement(curNode, alignType); if (NS_FAILED(res)) return res; @@ -2417,7 +2417,7 @@ nsHTMLEditRules::AlignTableElement(nsIDOMNode *aNode, const nsString *alignType) if (NS_FAILED(res)) return res; node = do_QueryInterface(content); if (!node) return NS_ERROR_FAILURE; - if (mEditor->IsTableCell(node)) + if (nsHTMLEditUtils::IsTableCell(node)) { isupports = do_QueryInterface(node); arrayOfNodes->AppendElement(isupports); @@ -2514,7 +2514,7 @@ nsHTMLEditRules::GetInnerContent(nsIDOMNode *aNode, nsISupportsArray *outArrayOf { if ( ( aList && (nsHTMLEditUtils::IsList(node) || nsHTMLEditUtils::IsListItem(node) ) ) - || ( aTbl && mEditor->IsTableElement(node) ) ) + || ( aTbl && nsHTMLEditUtils::IsTableElement(node) ) ) { res = GetInnerContent(node, outArrayOfNodes, aList, aTbl); if (NS_FAILED(res)) return res; @@ -3096,7 +3096,7 @@ nsHTMLEditRules::GetListActionNodes(nsCOMPtr *outArrayOfNodes, // scan for table elements. If we find table elements other than table, // replace it with a list of any editable non-table content. - if (mEditor->IsTableElement(testNode) && !mEditor->IsTable(testNode)) + if (nsHTMLEditUtils::IsTableElement(testNode) && !nsHTMLEditUtils::IsTable(testNode)) { (*outArrayOfNodes)->RemoveElementAt(i); res = GetInnerContent(testNode, *outArrayOfNodes, PR_FALSE); @@ -3166,7 +3166,7 @@ nsHTMLEditRules::GetParagraphFormatNodes(nsCOMPtr *outArrayOfN // scan for table elements. If we find table elements other than table, // replace it with a list of any editable non-table content. Ditto for list elements. - if (mEditor->IsTableElement(testNode) || + if (nsHTMLEditUtils::IsTableElement(testNode) || nsHTMLEditUtils::IsList(testNode) || nsHTMLEditUtils::IsListItem(testNode) ) { @@ -3709,7 +3709,7 @@ nsHTMLEditRules::ShouldMakeEmptyBlock(nsIDOMSelection *aSelection, if (NS_FAILED(res)) return res; // is selection point in the body? or a cell? - if (nsHTMLEditUtils::IsBody(parent) || mEditor->IsTableCell(parent)) + if (nsHTMLEditUtils::IsBody(parent) || nsHTMLEditUtils::IsTableCellOrCaption(parent)) { *outMakeEmpty = PR_TRUE; return res; @@ -3816,7 +3816,7 @@ nsHTMLEditRules::MakeBlockquote(nsISupportsArray *arrayOfNodes) if (NS_FAILED(res)) return res; // if the node is a table element or list item, dive inside - if ( (mEditor->IsTableElement(curNode) && !(mEditor->IsTable(curNode))) || + if ( (nsHTMLEditUtils::IsTableElement(curNode) && !(nsHTMLEditUtils::IsTable(curNode))) || nsHTMLEditUtils::IsListItem(curNode) ) { curBlock = 0; // forget any previous block @@ -4234,7 +4234,7 @@ nsHTMLEditRules::AdjustSpecialBreaks(PRBool aSafeToAskFrames) res = mEditor->IsEmptyNode(node, &bIsEmptyNode, PR_FALSE, PR_FALSE, aSafeToAskFrames); if (NS_FAILED(res)) return res; if (bIsEmptyNode - && (nsHTMLEditUtils::IsListItem(node) || mEditor->IsTableCell(node))) + && (nsHTMLEditUtils::IsListItem(node) || nsHTMLEditUtils::IsTableCellOrCaption(node))) { isupports = do_QueryInterface(node); arrayOfNodes->AppendElement(isupports); @@ -4541,7 +4541,7 @@ nsHTMLEditRules::InDifferentTableElements(nsIDOMNode *aNode1, nsIDOMNode *aNode2 nsCOMPtr tn1, tn2, node = aNode1, temp; - while (node && !mEditor->IsTableElement(node)) + while (node && !nsHTMLEditUtils::IsTableElement(node)) { node->GetParentNode(getter_AddRefs(temp)); node = temp; @@ -4549,7 +4549,7 @@ nsHTMLEditRules::InDifferentTableElements(nsIDOMNode *aNode1, nsIDOMNode *aNode2 tn1 = node; node = aNode2; - while (node && !mEditor->IsTableElement(node)) + while (node && !nsHTMLEditUtils::IsTableElement(node)) { node->GetParentNode(getter_AddRefs(temp)); node = temp; diff --git a/editor/base/nsHTMLEditUtils.cpp b/editor/base/nsHTMLEditUtils.cpp index 195ff4009ce..85532794557 100644 --- a/editor/base/nsHTMLEditUtils.cpp +++ b/editor/base/nsHTMLEditUtils.cpp @@ -233,6 +233,26 @@ nsHTMLEditUtils::IsListItem(nsIDOMNode *node) } +/////////////////////////////////////////////////////////////////////////// +// IsTableElement: true if node an html table, td, tr, ... +// +PRBool +nsHTMLEditUtils::IsTableElement(nsIDOMNode *node) +{ + NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTableElement"); + nsAutoString tagName; + nsEditor::GetTagString(node,tagName); + if (tagName.EqualsWithConversion("table") || tagName.EqualsWithConversion("tr") || + tagName.EqualsWithConversion("td") || tagName.EqualsWithConversion("th") || + tagName.EqualsWithConversion("thead") || tagName.EqualsWithConversion("tfoot") || + tagName.EqualsWithConversion("tbody") || tagName.EqualsWithConversion("caption")) + { + return PR_TRUE; + } + return PR_FALSE; +} + + /////////////////////////////////////////////////////////////////////////// // IsTable: true if node an html table // @@ -284,6 +304,26 @@ nsHTMLEditUtils::IsTableCell(nsIDOMNode *node) } +/////////////////////////////////////////////////////////////////////////// +// IsTableCell: true if node an html td or th +// +PRBool +nsHTMLEditUtils::IsTableCellOrCaption(nsIDOMNode *node) +{ + NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsTableCell"); + nsAutoString tag; + nsEditor::GetTagString(node,tag); + tag.ToLowerCase(); + if (tag.EqualsWithConversion("td") || + tag.EqualsWithConversion("th") || + tag.EqualsWithConversion("caption") ) + { + return PR_TRUE; + } + return PR_FALSE; +} + + /////////////////////////////////////////////////////////////////////////// // IsList: true if node an html list // diff --git a/editor/base/nsHTMLEditUtils.h b/editor/base/nsHTMLEditUtils.h index 2c96510cf81..b05ea6df602 100644 --- a/editor/base/nsHTMLEditUtils.h +++ b/editor/base/nsHTMLEditUtils.h @@ -46,7 +46,9 @@ public: static PRBool IsListItem(nsIDOMNode *aNode); static PRBool IsTable(nsIDOMNode *aNode); static PRBool IsTableRow(nsIDOMNode *aNode); + static PRBool IsTableElement(nsIDOMNode *aNode); static PRBool IsTableCell(nsIDOMNode *aNode); + static PRBool IsTableCellOrCaption(nsIDOMNode *aNode); static PRBool IsList(nsIDOMNode *aNode); static PRBool IsOrderedList(nsIDOMNode *aNode); static PRBool IsUnorderedList(nsIDOMNode *aNode); diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index df884bbb8ef..f1b8bb3a40b 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -730,7 +730,7 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent) { PRBool bHandled = PR_FALSE; - if (IsTableElement(blockParent)) + if (nsHTMLEditUtils::IsTableElement(blockParent)) res = TabInTable(isShift, &bHandled); else if (nsHTMLEditUtils::IsListItem(blockParent)) { @@ -845,7 +845,7 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled) res = iter->CurrentNode(getter_AddRefs(cNode)); if (NS_FAILED(res)) break; node = do_QueryInterface(cNode); - if (IsTableCell(node) && (GetEnclosingTable(node) == tbl)) + if (nsHTMLEditUtils::IsTableCell(node) && (GetEnclosingTable(node) == tbl)) { res = CollapseSelectionToDeepestNonTableFirstChild(nsnull, node); if (NS_FAILED(res)) return res; @@ -2262,7 +2262,7 @@ nsHTMLEditor::CollapseSelectionToDeepestNonTableFirstChild(nsIDOMSelection *aSel { // Stop if we find a table // don't want to go into nested tables - if (IsTable(child)) break; + if (nsHTMLEditUtils::IsTable(child)) break; // hey, it'g gotta be a container too! if (!IsContainer(child)) break; node = child; @@ -6237,58 +6237,6 @@ nsHTMLEditor::IsSubordinateBlock(nsString &aTag, PRBool &aIsTag) return NS_OK; } -/////////////////////////////////////////////////////////////////////////// -// IsTable: true if node an html table -// -PRBool -nsHTMLEditor::IsTable(nsIDOMNode *node) -{ - NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTable"); - nsAutoString tag; - nsEditor::GetTagString(node,tag); - if (tag.EqualsWithConversion("table")) - { - return PR_TRUE; - } - return PR_FALSE; -} - - -/////////////////////////////////////////////////////////////////////////// -// IsTableCell: true if node an html td -// -PRBool -nsHTMLEditor::IsTableCell(nsIDOMNode *node) -{ - NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTableCell"); - nsAutoString tag; - nsEditor::GetTagString(node,tag); - if (tag.EqualsWithConversion("td") || tag.EqualsWithConversion("th")) - { - return PR_TRUE; - } - return PR_FALSE; -} - - -/////////////////////////////////////////////////////////////////////////// -// IsTableElement: true if node an html table, td, tr, ... -// -PRBool -nsHTMLEditor::IsTableElement(nsIDOMNode *node) -{ - NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTableElement"); - nsAutoString tagName; - nsEditor::GetTagString(node,tagName); - if (tagName.EqualsWithConversion("table") || tagName.EqualsWithConversion("tr") || - tagName.EqualsWithConversion("td") || tagName.EqualsWithConversion("th") || - tagName.EqualsWithConversion("thead") || tagName.EqualsWithConversion("tfoot") || - tagName.EqualsWithConversion("tbody") || tagName.EqualsWithConversion("caption")) - { - return PR_TRUE; - } - return PR_FALSE; -} /////////////////////////////////////////////////////////////////////////// @@ -6304,7 +6252,7 @@ nsHTMLEditor::GetEnclosingTable(nsIDOMNode *aNode) { tmp = GetBlockNodeParent(node); if (!tmp) break; - if (IsTable(tmp)) tbl = tmp; + if (nsHTMLEditUtils::IsTable(tmp)) tbl = tmp; node = tmp; } return tbl; @@ -7249,7 +7197,7 @@ nsHTMLEditor::IsEmptyNode( nsIDOMNode *aNode, // cells empty if caller desires. if (!IsContainer(aNode) || nsHTMLEditUtils::IsAnchor(aNode) || (aListOrCellNotEmpty && nsHTMLEditUtils::IsListItem(aNode)) || - (aListOrCellNotEmpty && nsHTMLEditUtils::IsTableCell(aNode)) ) + (aListOrCellNotEmpty && nsHTMLEditUtils::nsHTMLEditUtils::IsTableCell(aNode)) ) { *outIsEmptyNode = PR_FALSE; return NS_OK; diff --git a/editor/base/nsHTMLEditor.h b/editor/base/nsHTMLEditor.h index dd24380ebc0..95f10f9edcf 100644 --- a/editor/base/nsHTMLEditor.h +++ b/editor/base/nsHTMLEditor.h @@ -442,9 +442,6 @@ protected: NS_IMETHOD IsSubordinateBlock(nsString &aTag, PRBool &aIsTag); - static PRBool IsTable(nsIDOMNode *aNode); - static PRBool IsTableCell(nsIDOMNode *aNode); - static PRBool IsTableElement(nsIDOMNode *aNode); static nsCOMPtr GetEnclosingTable(nsIDOMNode *aNode); /** content-based query returns PR_TRUE if effects aNode diff --git a/editor/base/nsTableEditor.cpp b/editor/base/nsTableEditor.cpp index f8d0753623d..3478566a57b 100644 --- a/editor/base/nsTableEditor.cpp +++ b/editor/base/nsTableEditor.cpp @@ -2786,7 +2786,7 @@ nsHTMLEditor::GetCellFromRange(nsIDOMRange *aRange, nsIDOMElement **aCell) // so tell caller the cell wasn't found if (startParent == endParent && endOffset == startOffset+1 && - IsTableCell(childNode)) + nsHTMLEditUtils::IsTableCell(childNode)) { // Should we also test if frame is selected? (Use GetCellDataAt()) // (Let's not for now -- more efficient) diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index 07338e6adca..b5874f53585 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -1050,7 +1050,7 @@ nsHTMLEditRules::WillDeleteSelection(nsIDOMSelection *aSelection, return NS_OK; // bail to default // do not delete across table structures - if (mEditor->IsTableElement(leftParent) || mEditor->IsTableElement(rightParent)) + if (nsHTMLEditUtils::IsTableElement(leftParent) || nsHTMLEditUtils::IsTableElement(rightParent)) { *aCancel = PR_TRUE; return NS_OK; @@ -1159,7 +1159,7 @@ nsHTMLEditRules::WillDeleteSelection(nsIDOMSelection *aSelection, return NS_OK; // bail to default // do not delete across table structures - if (mEditor->IsTableElement(leftParent) || mEditor->IsTableElement(rightParent)) + if (nsHTMLEditUtils::IsTableElement(leftParent) || nsHTMLEditUtils::IsTableElement(rightParent)) { *aCancel = PR_TRUE; return NS_OK; @@ -1197,7 +1197,7 @@ nsHTMLEditRules::WillDeleteSelection(nsIDOMSelection *aSelection, // Note: do NOT delete table elements this way. PRBool bIsEmptyNode; res = mEditor->IsEmptyNode(node, &bIsEmptyNode, PR_TRUE, PR_FALSE); - if (bIsEmptyNode && !mEditor->IsTableElement(node)) + if (bIsEmptyNode && !nsHTMLEditUtils::IsTableElement(node)) nodeToDelete = node; else { @@ -1336,7 +1336,7 @@ nsHTMLEditRules::WillDeleteSelection(nsIDOMSelection *aSelection, rightParent = mEditor->GetBlockNodeParent(endNode); // do not delete across table structures - if (mEditor->IsTableElement(leftParent) || mEditor->IsTableElement(rightParent)) + if (nsHTMLEditUtils::IsTableElement(leftParent) || nsHTMLEditUtils::IsTableElement(rightParent)) { *aCancel = PR_TRUE; return NS_OK; @@ -2346,7 +2346,7 @@ nsHTMLEditRules::WillAlign(nsIDOMSelection *aSelection, // if it's a table element (but not a table), forget any "current" div, and // instead put divs inside any th's and td's inside the table element - if (mEditor->IsTableElement(curNode) && !mEditor->IsTable(curNode)) + if (nsHTMLEditUtils::IsTableElement(curNode) && !nsHTMLEditUtils::IsTable(curNode)) { res = AlignTableElement(curNode, alignType); if (NS_FAILED(res)) return res; @@ -2417,7 +2417,7 @@ nsHTMLEditRules::AlignTableElement(nsIDOMNode *aNode, const nsString *alignType) if (NS_FAILED(res)) return res; node = do_QueryInterface(content); if (!node) return NS_ERROR_FAILURE; - if (mEditor->IsTableCell(node)) + if (nsHTMLEditUtils::IsTableCell(node)) { isupports = do_QueryInterface(node); arrayOfNodes->AppendElement(isupports); @@ -2514,7 +2514,7 @@ nsHTMLEditRules::GetInnerContent(nsIDOMNode *aNode, nsISupportsArray *outArrayOf { if ( ( aList && (nsHTMLEditUtils::IsList(node) || nsHTMLEditUtils::IsListItem(node) ) ) - || ( aTbl && mEditor->IsTableElement(node) ) ) + || ( aTbl && nsHTMLEditUtils::IsTableElement(node) ) ) { res = GetInnerContent(node, outArrayOfNodes, aList, aTbl); if (NS_FAILED(res)) return res; @@ -3096,7 +3096,7 @@ nsHTMLEditRules::GetListActionNodes(nsCOMPtr *outArrayOfNodes, // scan for table elements. If we find table elements other than table, // replace it with a list of any editable non-table content. - if (mEditor->IsTableElement(testNode) && !mEditor->IsTable(testNode)) + if (nsHTMLEditUtils::IsTableElement(testNode) && !nsHTMLEditUtils::IsTable(testNode)) { (*outArrayOfNodes)->RemoveElementAt(i); res = GetInnerContent(testNode, *outArrayOfNodes, PR_FALSE); @@ -3166,7 +3166,7 @@ nsHTMLEditRules::GetParagraphFormatNodes(nsCOMPtr *outArrayOfN // scan for table elements. If we find table elements other than table, // replace it with a list of any editable non-table content. Ditto for list elements. - if (mEditor->IsTableElement(testNode) || + if (nsHTMLEditUtils::IsTableElement(testNode) || nsHTMLEditUtils::IsList(testNode) || nsHTMLEditUtils::IsListItem(testNode) ) { @@ -3709,7 +3709,7 @@ nsHTMLEditRules::ShouldMakeEmptyBlock(nsIDOMSelection *aSelection, if (NS_FAILED(res)) return res; // is selection point in the body? or a cell? - if (nsHTMLEditUtils::IsBody(parent) || mEditor->IsTableCell(parent)) + if (nsHTMLEditUtils::IsBody(parent) || nsHTMLEditUtils::IsTableCellOrCaption(parent)) { *outMakeEmpty = PR_TRUE; return res; @@ -3816,7 +3816,7 @@ nsHTMLEditRules::MakeBlockquote(nsISupportsArray *arrayOfNodes) if (NS_FAILED(res)) return res; // if the node is a table element or list item, dive inside - if ( (mEditor->IsTableElement(curNode) && !(mEditor->IsTable(curNode))) || + if ( (nsHTMLEditUtils::IsTableElement(curNode) && !(nsHTMLEditUtils::IsTable(curNode))) || nsHTMLEditUtils::IsListItem(curNode) ) { curBlock = 0; // forget any previous block @@ -4234,7 +4234,7 @@ nsHTMLEditRules::AdjustSpecialBreaks(PRBool aSafeToAskFrames) res = mEditor->IsEmptyNode(node, &bIsEmptyNode, PR_FALSE, PR_FALSE, aSafeToAskFrames); if (NS_FAILED(res)) return res; if (bIsEmptyNode - && (nsHTMLEditUtils::IsListItem(node) || mEditor->IsTableCell(node))) + && (nsHTMLEditUtils::IsListItem(node) || nsHTMLEditUtils::IsTableCellOrCaption(node))) { isupports = do_QueryInterface(node); arrayOfNodes->AppendElement(isupports); @@ -4541,7 +4541,7 @@ nsHTMLEditRules::InDifferentTableElements(nsIDOMNode *aNode1, nsIDOMNode *aNode2 nsCOMPtr tn1, tn2, node = aNode1, temp; - while (node && !mEditor->IsTableElement(node)) + while (node && !nsHTMLEditUtils::IsTableElement(node)) { node->GetParentNode(getter_AddRefs(temp)); node = temp; @@ -4549,7 +4549,7 @@ nsHTMLEditRules::InDifferentTableElements(nsIDOMNode *aNode1, nsIDOMNode *aNode2 tn1 = node; node = aNode2; - while (node && !mEditor->IsTableElement(node)) + while (node && !nsHTMLEditUtils::IsTableElement(node)) { node->GetParentNode(getter_AddRefs(temp)); node = temp; diff --git a/editor/libeditor/html/nsHTMLEditUtils.cpp b/editor/libeditor/html/nsHTMLEditUtils.cpp index 195ff4009ce..85532794557 100644 --- a/editor/libeditor/html/nsHTMLEditUtils.cpp +++ b/editor/libeditor/html/nsHTMLEditUtils.cpp @@ -233,6 +233,26 @@ nsHTMLEditUtils::IsListItem(nsIDOMNode *node) } +/////////////////////////////////////////////////////////////////////////// +// IsTableElement: true if node an html table, td, tr, ... +// +PRBool +nsHTMLEditUtils::IsTableElement(nsIDOMNode *node) +{ + NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTableElement"); + nsAutoString tagName; + nsEditor::GetTagString(node,tagName); + if (tagName.EqualsWithConversion("table") || tagName.EqualsWithConversion("tr") || + tagName.EqualsWithConversion("td") || tagName.EqualsWithConversion("th") || + tagName.EqualsWithConversion("thead") || tagName.EqualsWithConversion("tfoot") || + tagName.EqualsWithConversion("tbody") || tagName.EqualsWithConversion("caption")) + { + return PR_TRUE; + } + return PR_FALSE; +} + + /////////////////////////////////////////////////////////////////////////// // IsTable: true if node an html table // @@ -284,6 +304,26 @@ nsHTMLEditUtils::IsTableCell(nsIDOMNode *node) } +/////////////////////////////////////////////////////////////////////////// +// IsTableCell: true if node an html td or th +// +PRBool +nsHTMLEditUtils::IsTableCellOrCaption(nsIDOMNode *node) +{ + NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsTableCell"); + nsAutoString tag; + nsEditor::GetTagString(node,tag); + tag.ToLowerCase(); + if (tag.EqualsWithConversion("td") || + tag.EqualsWithConversion("th") || + tag.EqualsWithConversion("caption") ) + { + return PR_TRUE; + } + return PR_FALSE; +} + + /////////////////////////////////////////////////////////////////////////// // IsList: true if node an html list // diff --git a/editor/libeditor/html/nsHTMLEditUtils.h b/editor/libeditor/html/nsHTMLEditUtils.h index 2c96510cf81..b05ea6df602 100644 --- a/editor/libeditor/html/nsHTMLEditUtils.h +++ b/editor/libeditor/html/nsHTMLEditUtils.h @@ -46,7 +46,9 @@ public: static PRBool IsListItem(nsIDOMNode *aNode); static PRBool IsTable(nsIDOMNode *aNode); static PRBool IsTableRow(nsIDOMNode *aNode); + static PRBool IsTableElement(nsIDOMNode *aNode); static PRBool IsTableCell(nsIDOMNode *aNode); + static PRBool IsTableCellOrCaption(nsIDOMNode *aNode); static PRBool IsList(nsIDOMNode *aNode); static PRBool IsOrderedList(nsIDOMNode *aNode); static PRBool IsUnorderedList(nsIDOMNode *aNode); diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index df884bbb8ef..f1b8bb3a40b 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -730,7 +730,7 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent) { PRBool bHandled = PR_FALSE; - if (IsTableElement(blockParent)) + if (nsHTMLEditUtils::IsTableElement(blockParent)) res = TabInTable(isShift, &bHandled); else if (nsHTMLEditUtils::IsListItem(blockParent)) { @@ -845,7 +845,7 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled) res = iter->CurrentNode(getter_AddRefs(cNode)); if (NS_FAILED(res)) break; node = do_QueryInterface(cNode); - if (IsTableCell(node) && (GetEnclosingTable(node) == tbl)) + if (nsHTMLEditUtils::IsTableCell(node) && (GetEnclosingTable(node) == tbl)) { res = CollapseSelectionToDeepestNonTableFirstChild(nsnull, node); if (NS_FAILED(res)) return res; @@ -2262,7 +2262,7 @@ nsHTMLEditor::CollapseSelectionToDeepestNonTableFirstChild(nsIDOMSelection *aSel { // Stop if we find a table // don't want to go into nested tables - if (IsTable(child)) break; + if (nsHTMLEditUtils::IsTable(child)) break; // hey, it'g gotta be a container too! if (!IsContainer(child)) break; node = child; @@ -6237,58 +6237,6 @@ nsHTMLEditor::IsSubordinateBlock(nsString &aTag, PRBool &aIsTag) return NS_OK; } -/////////////////////////////////////////////////////////////////////////// -// IsTable: true if node an html table -// -PRBool -nsHTMLEditor::IsTable(nsIDOMNode *node) -{ - NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTable"); - nsAutoString tag; - nsEditor::GetTagString(node,tag); - if (tag.EqualsWithConversion("table")) - { - return PR_TRUE; - } - return PR_FALSE; -} - - -/////////////////////////////////////////////////////////////////////////// -// IsTableCell: true if node an html td -// -PRBool -nsHTMLEditor::IsTableCell(nsIDOMNode *node) -{ - NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTableCell"); - nsAutoString tag; - nsEditor::GetTagString(node,tag); - if (tag.EqualsWithConversion("td") || tag.EqualsWithConversion("th")) - { - return PR_TRUE; - } - return PR_FALSE; -} - - -/////////////////////////////////////////////////////////////////////////// -// IsTableElement: true if node an html table, td, tr, ... -// -PRBool -nsHTMLEditor::IsTableElement(nsIDOMNode *node) -{ - NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTableElement"); - nsAutoString tagName; - nsEditor::GetTagString(node,tagName); - if (tagName.EqualsWithConversion("table") || tagName.EqualsWithConversion("tr") || - tagName.EqualsWithConversion("td") || tagName.EqualsWithConversion("th") || - tagName.EqualsWithConversion("thead") || tagName.EqualsWithConversion("tfoot") || - tagName.EqualsWithConversion("tbody") || tagName.EqualsWithConversion("caption")) - { - return PR_TRUE; - } - return PR_FALSE; -} /////////////////////////////////////////////////////////////////////////// @@ -6304,7 +6252,7 @@ nsHTMLEditor::GetEnclosingTable(nsIDOMNode *aNode) { tmp = GetBlockNodeParent(node); if (!tmp) break; - if (IsTable(tmp)) tbl = tmp; + if (nsHTMLEditUtils::IsTable(tmp)) tbl = tmp; node = tmp; } return tbl; @@ -7249,7 +7197,7 @@ nsHTMLEditor::IsEmptyNode( nsIDOMNode *aNode, // cells empty if caller desires. if (!IsContainer(aNode) || nsHTMLEditUtils::IsAnchor(aNode) || (aListOrCellNotEmpty && nsHTMLEditUtils::IsListItem(aNode)) || - (aListOrCellNotEmpty && nsHTMLEditUtils::IsTableCell(aNode)) ) + (aListOrCellNotEmpty && nsHTMLEditUtils::nsHTMLEditUtils::IsTableCell(aNode)) ) { *outIsEmptyNode = PR_FALSE; return NS_OK; diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index dd24380ebc0..95f10f9edcf 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -442,9 +442,6 @@ protected: NS_IMETHOD IsSubordinateBlock(nsString &aTag, PRBool &aIsTag); - static PRBool IsTable(nsIDOMNode *aNode); - static PRBool IsTableCell(nsIDOMNode *aNode); - static PRBool IsTableElement(nsIDOMNode *aNode); static nsCOMPtr GetEnclosingTable(nsIDOMNode *aNode); /** content-based query returns PR_TRUE if effects aNode diff --git a/editor/libeditor/html/nsTableEditor.cpp b/editor/libeditor/html/nsTableEditor.cpp index f8d0753623d..3478566a57b 100644 --- a/editor/libeditor/html/nsTableEditor.cpp +++ b/editor/libeditor/html/nsTableEditor.cpp @@ -2786,7 +2786,7 @@ nsHTMLEditor::GetCellFromRange(nsIDOMRange *aRange, nsIDOMElement **aCell) // so tell caller the cell wasn't found if (startParent == endParent && endOffset == startOffset+1 && - IsTableCell(childNode)) + nsHTMLEditUtils::IsTableCell(childNode)) { // Should we also test if frame is selected? (Use GetCellDataAt()) // (Let's not for now -- more efficient)