Backout changeset ac6a27516edb (bug 1190172 part 3)

--HG--
extra : rebase_source : 17c98f03485a964e74f58d0c684ed756f6a37441
This commit is contained in:
Masayuki Nakano 2016-04-23 20:01:32 +09:00
parent 4656c119c1
commit 65acec6efb
2 changed files with 36 additions and 6 deletions

View File

@ -670,6 +670,10 @@ protected:
nsIContent** aOutLeftNode = nullptr,
nsIContent** aOutRightNode = nullptr);
nsresult ApplyDefaultProperties();
nsresult RemoveStyleInside(nsIDOMNode *aNode,
nsIAtom *aProperty,
const nsAString *aAttribute,
const bool aChildrenOnly = false);
nsresult RemoveStyleInside(nsIContent& aNode,
nsIAtom* aProperty,
const nsAString* aAttribute,
@ -681,6 +685,7 @@ protected:
bool HasAttr(nsIDOMNode *aNode, const nsAString *aAttribute);
bool IsAtFrontOfNode(nsIDOMNode *aNode, int32_t aOffset);
bool IsAtEndOfNode(nsIDOMNode *aNode, int32_t aOffset);
bool IsOnlyAttribute(nsIDOMNode *aElement, const nsAString *aAttribute);
bool IsOnlyAttribute(const nsIContent* aElement, const nsAString& aAttribute);
nsresult RemoveBlockContainer(nsIDOMNode *inNode);

View File

@ -673,7 +673,7 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
// selection.
nsAutoTrackDOMPoint tracker(mRangeUpdater,
address_of(newSelParent), &newSelOffset);
res = RemoveStyleInside(*leftNode, aProperty, aAttribute);
res = RemoveStyleInside(GetAsDOMNode(leftNode), aProperty, aAttribute);
NS_ENSURE_SUCCESS(res, res);
}
// reset our node offset values to the resulting new sel point
@ -710,6 +710,19 @@ nsresult nsHTMLEditor::ApplyDefaultProperties()
return res;
}
nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode,
// null here means remove all properties
nsIAtom *aProperty,
const nsAString *aAttribute,
const bool aChildrenOnly)
{
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
NS_ENSURE_STATE(content);
return RemoveStyleInside(*content, aProperty, aAttribute, aChildrenOnly);
}
nsresult
nsHTMLEditor::RemoveStyleInside(nsIContent& aNode,
nsIAtom* aProperty,
@ -821,6 +834,17 @@ nsHTMLEditor::RemoveStyleInside(nsIContent& aNode,
return NS_OK;
}
bool nsHTMLEditor::IsOnlyAttribute(nsIDOMNode *aNode,
const nsAString *aAttribute)
{
NS_ENSURE_TRUE(aNode && aAttribute, false); // ooops
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
NS_ENSURE_TRUE(content, false); // ooops
return IsOnlyAttribute(content, *aAttribute);
}
bool
nsHTMLEditor::IsOnlyAttribute(const nsIContent* aContent,
const nsAString& aAttribute)
@ -1329,21 +1353,21 @@ nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom* aProperty,
// Not the easy case. Range not contained in single text node.
nsCOMPtr<nsIContentIterator> iter = NS_NewContentSubtreeIterator();
nsTArray<OwningNonNull<nsIContent>> arrayOfNodes;
nsTArray<nsCOMPtr<nsINode>> arrayOfNodes;
// Iterate range and build up array
for (iter->Init(range); !iter->IsDone(); iter->Next()) {
nsCOMPtr<nsINode> node = iter->GetCurrentNode();
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
if (IsEditable(node) && node->IsContent()) {
arrayOfNodes.AppendElement(*node->AsContent());
if (IsEditable(node)) {
arrayOfNodes.AppendElement(node);
}
}
// Loop through the list, remove the property on each node
for (auto& node : arrayOfNodes) {
res = RemoveStyleInside(node, aProperty, aAttribute);
res = RemoveStyleInside(GetAsDOMNode(node), aProperty, aAttribute);
NS_ENSURE_SUCCESS(res, res);
if (IsCSSEnabled() &&
mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
@ -1358,7 +1382,8 @@ nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom* aProperty,
// "inverting" the style
mHTMLCSSUtils->IsCSSInvertible(*aProperty, aAttribute)) {
NS_NAMED_LITERAL_STRING(value, "-moz-editor-invert-value");
SetInlinePropertyOnNode(node, *aProperty, aAttribute, value);
SetInlinePropertyOnNode(*node->AsContent(), *aProperty,
aAttribute, value);
}
}
}