Bug 1154701 part 6 - Clean up nsHTMLEditor::SetInlinePropertyOnNodeImpl; r=ehsan

This commit is contained in:
Aryeh Gregor 2015-04-24 14:27:35 +03:00
parent edc5f268b3
commit 9aea14124a
2 changed files with 42 additions and 46 deletions

View File

@ -960,10 +960,10 @@ private:
nsIAtom* aProperty,
const nsAString* aAttribute,
const nsAString* aValue);
nsresult SetInlinePropertyOnNodeImpl(nsIContent* aNode,
nsIAtom* aProperty,
nsresult SetInlinePropertyOnNodeImpl(nsIContent& aNode,
nsIAtom& aProperty,
const nsAString* aAttribute,
const nsAString* aValue);
const nsAString& aValue);
typedef enum { eInserted, eAppended } InsertedOrAppended;
void DoContentInserted(nsIDocument* aDocument, nsIContent* aContainer,
nsIContent* aChild, int32_t aIndexInContainer,

View File

@ -381,36 +381,32 @@ nsHTMLEditor::SetInlinePropertyOnTextNode(Text& aText,
nsresult
nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent* aNode,
nsIAtom* aProperty,
nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent& aNode,
nsIAtom& aProperty,
const nsAString* aAttribute,
const nsAString* aValue)
const nsAString& aValue)
{
MOZ_ASSERT(aNode && aProperty);
MOZ_ASSERT(aValue);
nsCOMPtr<nsIAtom> attrAtom = aAttribute ? do_GetAtom(*aAttribute) : nullptr;
// If this is an element that can't be contained in a span, we have to
// recurse to its children.
if (!TagCanContain(*nsGkAtoms::span, *aNode)) {
if (aNode->HasChildren()) {
nsCOMArray<nsIContent> arrayOfNodes;
if (!TagCanContain(*nsGkAtoms::span, aNode)) {
if (aNode.HasChildren()) {
nsTArray<OwningNonNull<nsIContent>> arrayOfNodes;
// Populate the list.
for (nsIContent* child = aNode->GetFirstChild();
for (nsCOMPtr<nsIContent> child = aNode.GetFirstChild();
child;
child = child->GetNextSibling()) {
if (IsEditable(child) && !IsEmptyTextNode(this, child)) {
arrayOfNodes.AppendObject(child);
arrayOfNodes.AppendElement(*child);
}
}
// Then loop through the list, set the property on each node.
int32_t listCount = arrayOfNodes.Count();
for (int32_t j = 0; j < listCount; ++j) {
nsresult rv = SetInlinePropertyOnNode(arrayOfNodes[j], aProperty,
aAttribute, aValue);
for (auto& node : arrayOfNodes) {
nsresult rv = SetInlinePropertyOnNode(node, &aProperty, aAttribute,
&aValue);
NS_ENSURE_SUCCESS(rv, rv);
}
}
@ -419,36 +415,36 @@ nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent* aNode,
// First check if there's an adjacent sibling we can put our node into.
nsresult res;
nsCOMPtr<nsIContent> previousSibling = GetPriorHTMLSibling(aNode);
nsCOMPtr<nsIContent> nextSibling = GetNextHTMLSibling(aNode);
if (IsSimpleModifiableNode(previousSibling, aProperty, aAttribute, aValue)) {
res = MoveNode(aNode, previousSibling, -1);
nsCOMPtr<nsIContent> previousSibling = GetPriorHTMLSibling(&aNode);
nsCOMPtr<nsIContent> nextSibling = GetNextHTMLSibling(&aNode);
if (IsSimpleModifiableNode(previousSibling, &aProperty, aAttribute, &aValue)) {
res = MoveNode(&aNode, previousSibling, -1);
NS_ENSURE_SUCCESS(res, res);
if (IsSimpleModifiableNode(nextSibling, aProperty, aAttribute, aValue)) {
if (IsSimpleModifiableNode(nextSibling, &aProperty, aAttribute, &aValue)) {
res = JoinNodes(*previousSibling, *nextSibling);
NS_ENSURE_SUCCESS(res, res);
}
return NS_OK;
}
if (IsSimpleModifiableNode(nextSibling, aProperty, aAttribute, aValue)) {
res = MoveNode(aNode, nextSibling, 0);
if (IsSimpleModifiableNode(nextSibling, &aProperty, aAttribute, &aValue)) {
res = MoveNode(&aNode, nextSibling, 0);
NS_ENSURE_SUCCESS(res, res);
return NS_OK;
}
// don't need to do anything if property already set on node
if (mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, aAttribute)) {
// Don't need to do anything if property already set on node
if (mHTMLCSSUtils->IsCSSEditableProperty(&aNode, &aProperty, aAttribute)) {
if (mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(
aNode, aProperty, aAttribute, *aValue, nsHTMLCSSUtils::eComputed)) {
&aNode, &aProperty, aAttribute, aValue, nsHTMLCSSUtils::eComputed)) {
return NS_OK;
}
} else if (IsTextPropertySetByContent(aNode, aProperty,
aAttribute, aValue)) {
} else if (IsTextPropertySetByContent(&aNode, &aProperty,
aAttribute, &aValue)) {
return NS_OK;
}
bool useCSS = (IsCSSEnabled() &&
mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, aAttribute)) ||
mHTMLCSSUtils->IsCSSEditableProperty(&aNode, &aProperty, aAttribute)) ||
// bgcolor is always done using CSS
aAttribute->EqualsLiteral("bgcolor");
@ -456,33 +452,33 @@ nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent* aNode,
nsCOMPtr<dom::Element> tmp;
// We only add style="" to <span>s with no attributes (bug 746515). If we
// don't have one, we need to make one.
if (aNode->IsHTMLElement(nsGkAtoms::span) &&
!aNode->AsElement()->GetAttrCount()) {
tmp = aNode->AsElement();
if (aNode.IsHTMLElement(nsGkAtoms::span) &&
!aNode.AsElement()->GetAttrCount()) {
tmp = aNode.AsElement();
} else {
tmp = InsertContainerAbove(aNode, nsGkAtoms::span);
tmp = InsertContainerAbove(&aNode, nsGkAtoms::span);
NS_ENSURE_STATE(tmp);
}
// Add the CSS styles corresponding to the HTML style request
int32_t count;
res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(tmp->AsDOMNode(),
aProperty, aAttribute,
aValue, &count, false);
&aProperty, aAttribute,
&aValue, &count, false);
NS_ENSURE_SUCCESS(res, res);
return NS_OK;
}
// is it already the right kind of node, but with wrong attribute?
if (aNode->IsHTMLElement(aProperty)) {
if (aNode.IsHTMLElement(&aProperty)) {
// Just set the attribute on it.
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(aNode);
return SetAttribute(elem, *aAttribute, *aValue);
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(&aNode);
return SetAttribute(elem, *aAttribute, aValue);
}
// ok, chuck it in its very own container
nsCOMPtr<Element> tmp = InsertContainerAbove(aNode, aProperty, attrAtom,
aValue);
nsCOMPtr<Element> tmp = InsertContainerAbove(&aNode, &aProperty, attrAtom,
&aValue);
NS_ENSURE_STATE(tmp);
return NS_OK;
@ -527,8 +523,8 @@ nsHTMLEditor::SetInlinePropertyOnNode(nsIContent* aNode,
if (aNode->GetParentNode()) {
// The node is still where it was
return SetInlinePropertyOnNodeImpl(aNode, aProperty,
aAttribute, aValue);
return SetInlinePropertyOnNodeImpl(*aNode, *aProperty,
aAttribute, *aValue);
}
// It's vanished. Use the old siblings for reference to construct a
@ -550,8 +546,8 @@ nsHTMLEditor::SetInlinePropertyOnNode(nsIContent* aNode,
int32_t nodesToSetCount = nodesToSet.Count();
for (int32_t k = 0; k < nodesToSetCount; k++) {
res = SetInlinePropertyOnNodeImpl(nodesToSet[k], aProperty,
aAttribute, aValue);
res = SetInlinePropertyOnNodeImpl(*nodesToSet[k], *aProperty,
aAttribute, *aValue);
NS_ENSURE_SUCCESS(res, res);
}