зеркало из https://github.com/mozilla/pjs.git
Removing text styles in CSS mode was potentially removing too much if the styles were added in HTML mode
The fix creates a span element that will carry the inline styles and class of the HTML element to be removed, if any. b=202037, r=kaie, sr=dmose
This commit is contained in:
Родитель
23192c33a9
Коммит
bef7afc6f3
|
@ -373,6 +373,21 @@ interface nsIEditor : nsISupports
|
|||
void removeAttribute(in nsIDOMElement aElement,
|
||||
in AString aAttribute);
|
||||
|
||||
/**
|
||||
* cloneAttribute() copies the attribute from the source node to
|
||||
* the destination node and delete those not in the source.
|
||||
*
|
||||
* The supplied nodes MUST BE ELEMENTS (most callers are working with nodes)
|
||||
* @param aAttribute the name of the attribute to copy
|
||||
* @param aDestNode the destination element to operate on
|
||||
* @param aSourceNode the source element to copy attributes from
|
||||
* @exception NS_ERROR_NULL_POINTER at least one of the nodes is null
|
||||
* @exception NS_ERROR_NO_INTERFACE at least one of the nodes is not an
|
||||
* element
|
||||
*/
|
||||
void cloneAttribute(in AString aAttribute,
|
||||
in nsIDOMNode aDestNode, in nsIDOMNode aSourceNode);
|
||||
|
||||
/**
|
||||
* cloneAttributes() is similar to nsIDOMNode::cloneNode(),
|
||||
* it assures the attribute nodes of the destination are identical
|
||||
|
|
|
@ -2223,6 +2223,36 @@ nsEditor::EndOperation()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditor::CloneAttribute(const nsAString & aAttribute,
|
||||
nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!aDestNode || !aSourceNode)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> destElement = do_QueryInterface(aDestNode);
|
||||
nsCOMPtr<nsIDOMElement> sourceElement = do_QueryInterface(aSourceNode);
|
||||
if (!destElement || !sourceElement)
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
|
||||
nsAutoString attrValue;
|
||||
PRBool isAttrSet;
|
||||
rv = GetAttributeValue(sourceElement,
|
||||
aAttribute,
|
||||
attrValue,
|
||||
&isAttrSet);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (isAttrSet)
|
||||
rv = SetAttribute(destElement, aAttribute, attrValue);
|
||||
else
|
||||
rv = RemoveAttribute(destElement, aAttribute);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Objects must be DOM elements
|
||||
NS_IMETHODIMP
|
||||
nsEditor::CloneAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
||||
|
|
|
@ -691,6 +691,27 @@ nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode,
|
|||
// remove any matching inlinestyles entirely
|
||||
if (!aAttribute || aAttribute->IsEmpty())
|
||||
{
|
||||
NS_NAMED_LITERAL_STRING(styleAttr, "style");
|
||||
NS_NAMED_LITERAL_STRING(classAttr, "class");
|
||||
PRBool hasStyleAttr = HasAttr(aNode, &styleAttr);
|
||||
PRBool hasClassAtrr = HasAttr(aNode, &classAttr);
|
||||
if (hasStyleAttr || hasClassAtrr) {
|
||||
// aNode carries inline styles or a class attribute so we can't
|
||||
// just remove the element... We need to create above the element
|
||||
// a span that will carry those styles or class, then we can delete
|
||||
// the node.
|
||||
nsCOMPtr<nsIDOMNode> spanNode;
|
||||
res = InsertContainerAbove(aNode, address_of(spanNode),
|
||||
NS_LITERAL_STRING("span"));
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
res = CloneAttribute(styleAttr, spanNode, aNode);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
res = CloneAttribute(classAttr, spanNode, aNode);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
}
|
||||
res = RemoveContainer(aNode);
|
||||
}
|
||||
// otherwise we just want to eliminate the attribute
|
||||
|
|
Загрузка…
Ссылка в новой задаче