Bug 761997 - Cleanup nsHTMLEditRules::GetListItemState / nsHTMLEditRules::GetDefinitionListItemTypes; r=ehsan

This commit is contained in:
Ms2ger 2012-06-17 10:11:16 +02:00
parent a8f93dcf4b
commit 5d70833a3d
2 changed files with 31 additions and 36 deletions

View File

@ -703,41 +703,34 @@ nsHTMLEditRules::GetListItemState(bool *aMixed, bool *aLI, bool *aDT, bool *aDD)
// examine list type for nodes in selection // examine list type for nodes in selection
PRInt32 listCount = arrayOfNodes.Count(); PRInt32 listCount = arrayOfNodes.Count();
PRInt32 i; for (PRInt32 i = listCount - 1; i >= 0; --i) {
for (i = listCount-1; i>=0; i--)
{
nsIDOMNode* curNode = arrayOfNodes[i]; nsIDOMNode* curNode = arrayOfNodes[i];
nsCOMPtr<dom::Element> element = do_QueryInterface(curNode);
if (nsHTMLEditUtils::IsUnorderedList(curNode) || if (!element) {
nsHTMLEditUtils::IsOrderedList(curNode) || bNonList = true;
nsEditor::NodeIsType(curNode, nsEditProperty::li) ) } else if (element->IsHTML(nsGkAtoms::ul) ||
{ element->IsHTML(nsGkAtoms::ol) ||
element->IsHTML(nsGkAtoms::li)) {
*aLI = true; *aLI = true;
} } else if (element->IsHTML(nsGkAtoms::dt)) {
else if (nsEditor::NodeIsType(curNode, nsEditProperty::dt))
{
*aDT = true; *aDT = true;
} } else if (element->IsHTML(nsGkAtoms::dd)) {
else if (nsEditor::NodeIsType(curNode, nsEditProperty::dd))
{
*aDD = true; *aDD = true;
} } else if (element->IsHTML(nsGkAtoms::dl)) {
else if (nsEditor::NodeIsType(curNode, nsEditProperty::dl))
{
// need to look inside dl and see which types of items it has // need to look inside dl and see which types of items it has
bool bDT, bDD; bool bDT, bDD;
res = GetDefinitionListItemTypes(curNode, bDT, bDD); GetDefinitionListItemTypes(element, &bDT, &bDD);
NS_ENSURE_SUCCESS(res, res);
*aDT |= bDT; *aDT |= bDT;
*aDD |= bDD; *aDD |= bDD;
} else {
bNonList = true;
} }
else bNonList = true;
} }
// hokey arithmetic with booleans // hokey arithmetic with booleans
if ( (*aDT + *aDD + bNonList) > 1) *aMixed = true; if ( (*aDT + *aDD + bNonList) > 1) *aMixed = true;
return res; return NS_OK;
} }
nsresult nsresult
@ -5959,22 +5952,24 @@ nsHTMLEditRules::LookInsideDivBQandList(nsCOMArray<nsIDOMNode>& aNodeArray)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// GetDefinitionListItemTypes: // GetDefinitionListItemTypes:
// //
nsresult void
nsHTMLEditRules::GetDefinitionListItemTypes(nsIDOMNode *aNode, bool &aDT, bool &aDD) nsHTMLEditRules::GetDefinitionListItemTypes(dom::Element* aElement, bool* aDT, bool* aDD)
{ {
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); MOZ_ASSERT(aElement);
aDT = aDD = false; MOZ_ASSERT(aElement->IsHTML(nsGkAtoms::dl));
nsresult res = NS_OK; MOZ_ASSERT(aDT);
nsCOMPtr<nsIDOMNode> child, temp; MOZ_ASSERT(aDD);
res = aNode->GetFirstChild(getter_AddRefs(child));
while (child && NS_SUCCEEDED(res)) *aDT = *aDD = false;
{ for (nsIContent* child = aElement->GetFirstChild();
if (nsEditor::NodeIsType(child, nsEditProperty::dt)) aDT = true; child;
else if (nsEditor::NodeIsType(child, nsEditProperty::dd)) aDD = true; child = child->GetNextSibling()) {
res = child->GetNextSibling(getter_AddRefs(temp)); if (child->IsHTML(nsGkAtoms::dt)) {
child = temp; *aDT = true;
} else if (child->IsHTML(nsGkAtoms::dd)) {
*aDD = true;
}
} }
return res;
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

View File

@ -234,7 +234,7 @@ protected:
nsCOMArray<nsIDOMNode>& arrayOfNodes, nsCOMArray<nsIDOMNode>& arrayOfNodes,
bool aDontTouchContent=false); bool aDontTouchContent=false);
nsresult GetListActionNodes(nsCOMArray<nsIDOMNode> &outArrayOfNodes, bool aEntireList, bool aDontTouchContent=false); nsresult GetListActionNodes(nsCOMArray<nsIDOMNode> &outArrayOfNodes, bool aEntireList, bool aDontTouchContent=false);
nsresult GetDefinitionListItemTypes(nsIDOMNode *aNode, bool &aDT, bool &aDD); void GetDefinitionListItemTypes(mozilla::dom::Element* aElement, bool* aDT, bool* aDD);
nsresult GetParagraphFormatNodes(nsCOMArray<nsIDOMNode>& outArrayOfNodes, bool aDontTouchContent=false); nsresult GetParagraphFormatNodes(nsCOMArray<nsIDOMNode>& outArrayOfNodes, bool aDontTouchContent=false);
nsresult LookInsideDivBQandList(nsCOMArray<nsIDOMNode>& aNodeArray); nsresult LookInsideDivBQandList(nsCOMArray<nsIDOMNode>& aNodeArray);
nsresult BustUpInlinesAtRangeEndpoints(nsRangeStore &inRange); nsresult BustUpInlinesAtRangeEndpoints(nsRangeStore &inRange);