Bug 840024 - Cleanup nsHTMLEditor::RemoveAttributeOrEquivalent some; r=ehsan

This commit is contained in:
Ms2ger 2013-03-10 08:58:34 +01:00
parent 0d3aeed377
commit 964738391b
3 changed files with 48 additions and 15 deletions

View File

@ -964,7 +964,22 @@ nsHTMLCSSUtils::RemoveCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
bool aSuppressTransaction)
{
nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
if (!element || !IsCSSEditableProperty(element, aHTMLProperty, aAttribute)) {
NS_ENSURE_TRUE(element, NS_OK);
return RemoveCSSEquivalentToHTMLStyle(element, aHTMLProperty, aAttribute,
aValue, aSuppressTransaction);
}
nsresult
nsHTMLCSSUtils::RemoveCSSEquivalentToHTMLStyle(dom::Element* aElement,
nsIAtom* aHTMLProperty,
const nsAString* aAttribute,
const nsAString* aValue,
bool aSuppressTransaction)
{
MOZ_ASSERT(aElement);
if (!IsCSSEditableProperty(aElement, aHTMLProperty, aAttribute)) {
return NS_OK;
}
@ -974,11 +989,11 @@ nsHTMLCSSUtils::RemoveCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
// Find the CSS equivalence to the HTML style
nsTArray<nsIAtom*> cssPropertyArray;
nsTArray<nsString> cssValueArray;
GenerateCSSDeclarationsFromHTMLStyle(element, aHTMLProperty, aAttribute,
GenerateCSSDeclarationsFromHTMLStyle(aElement, aHTMLProperty, aAttribute,
aValue, cssPropertyArray, cssValueArray,
true);
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(element);
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(aElement);
// remove the individual CSS inline styles
int32_t count = cssPropertyArray.Length();
for (int32_t index = 0; index < count; index++) {

View File

@ -239,6 +239,20 @@ public:
const nsAString *aAttribute,
const nsAString *aValue,
bool aSuppressTransaction);
/** removes from the node the CSS inline styles equivalent to the HTML style
*
* @param aElement [IN] a DOM Element (must not be null)
* @param aHTMLProperty [IN] an atom containing an HTML property
* @param aAttribute [IN] a pointer to an attribute name or nullptr if irrelevant
* @param aValue [IN] the attribute value
* @param aSuppressTransaction [IN] a boolean indicating, when true,
* that no transaction should be recorded
*/
nsresult RemoveCSSEquivalentToHTMLStyle(mozilla::dom::Element* aElement,
nsIAtom* aHTMLProperty,
const nsAString* aAttribute,
const nsAString* aValue,
bool aSuppressTransaction);
/** parses a "xxxx.xxxxxuuu" string where x is a digit and u an alpha char
* we need such a parser because nsIDOMCSSStyleDeclaration::GetPropertyCSSValue() is not

View File

@ -4579,26 +4579,30 @@ nsHTMLEditor::SetAttributeOrEquivalent(nsIDOMElement * aElement,
}
nsresult
nsHTMLEditor::RemoveAttributeOrEquivalent(nsIDOMElement * aElement,
const nsAString & aAttribute,
nsHTMLEditor::RemoveAttributeOrEquivalent(nsIDOMElement* aElement,
const nsAString& aAttribute,
bool aSuppressTransaction)
{
nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
NS_ENSURE_TRUE(element, NS_OK);
nsCOMPtr<nsIAtom> attribute = do_GetAtom(aAttribute);
MOZ_ASSERT(attribute);
nsresult res = NS_OK;
if (IsCSSEnabled() && mHTMLCSSUtils) {
res = mHTMLCSSUtils->RemoveCSSEquivalentToHTMLStyle(aElement, nullptr, &aAttribute, nullptr,
aSuppressTransaction);
res = mHTMLCSSUtils->RemoveCSSEquivalentToHTMLStyle(
element, nullptr, &aAttribute, nullptr, aSuppressTransaction);
NS_ENSURE_SUCCESS(res, res);
}
nsAutoString existingValue;
bool wasSet = false;
res = GetAttributeValue(aElement, aAttribute, existingValue, &wasSet);
NS_ENSURE_SUCCESS(res, res);
if (wasSet) {
if (aSuppressTransaction)
res = aElement->RemoveAttribute(aAttribute);
else
if (element->HasAttr(kNameSpaceID_None, attribute)) {
if (aSuppressTransaction) {
res = element->UnsetAttr(kNameSpaceID_None, attribute,
/* aNotify = */ true);
} else {
res = RemoveAttribute(aElement, aAttribute);
}
}
return res;
}