Bug 724261 - Use nsINode in nsHTMLEditRules::RelativeChangeIndentationOfElementNode; r=ehsan

This commit is contained in:
Ms2ger 2012-02-10 11:04:46 +01:00
Родитель 99918bf221
Коммит 972b3f0fdb
1 изменённых файлов: 66 добавлений и 73 удалений

Просмотреть файл

@ -8888,28 +8888,26 @@ nsHTMLEditRules::RelativeChangeIndentationOfElementNode(nsIDOMNode *aNode, PRInt
{
NS_ENSURE_ARG_POINTER(aNode);
if ( !( (aRelativeChange==1) || (aRelativeChange==-1) ) )
if (aRelativeChange != 1 && aRelativeChange != -1) {
return NS_ERROR_ILLEGAL_VALUE;
}
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
NS_ASSERTION(element, "not an element node");
if (!element) {
return NS_OK;
}
if (element) {
nsIAtom* marginProperty = MarginPropertyAtomForIndent(mHTMLEditor->mHTMLCSSUtils, element);
nsAutoString value;
nsresult res;
mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(aNode, marginProperty, value);
float f;
nsIAtom * unit;
mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, &unit);
nsCOMPtr<nsIAtom> unit;
mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
if (0 == f) {
NS_IF_RELEASE(unit);
nsAutoString defaultLengthUnit;
mHTMLEditor->mHTMLCSSUtils->GetDefaultLengthUnit(defaultLengthUnit);
unit = NS_NewAtom(defaultLengthUnit);
unit = do_GetAtom(defaultLengthUnit);
}
nsAutoString unitString;
unit->ToString(unitString);
if (nsEditProperty::cssInUnit == unit)
f += NS_EDITOR_INDENT_INCREMENT_IN * aRelativeChange;
else if (nsEditProperty::cssCmUnit == unit)
@ -8929,42 +8927,37 @@ nsHTMLEditRules::RelativeChangeIndentationOfElementNode(nsIDOMNode *aNode, PRInt
else if (nsEditProperty::cssPercentUnit == unit)
f += NS_EDITOR_INDENT_INCREMENT_PERCENT * aRelativeChange;
NS_IF_RELEASE(unit);
if (0 < f) {
nsAutoString newValue;
newValue.AppendFloat(f);
newValue.Append(unitString);
newValue.Append(nsDependentAtomString(unit));
mHTMLEditor->mHTMLCSSUtils->SetCSSProperty(element, marginProperty, newValue, false);
return NS_OK;
}
else {
mHTMLEditor->mHTMLCSSUtils->RemoveCSSProperty(element, marginProperty, value, false);
// remove unnecessary DIV blocks:
// we could skip this section but that would cause a FAIL in
// editor/libeditor/html/tests/browserscope/richtext.html, which expects
// to unapply a CSS "indent" (<div style="margin-left: 40px;">) by
// removing the DIV container instead of just removing the CSS property.
nsCOMPtr<dom::Element> node = do_QueryInterface(aNode);
if (node && node->IsHTML(nsGkAtoms::div) &&
node != mHTMLEditor->GetActiveEditingHost() &&
mHTMLEditor->IsNodeInActiveEditor(node)) {
// we deal with an editable DIV;
// let's see if it is useless and if we can remove it
nsCOMPtr<nsIDOMNamedNodeMap> attributeList;
res = element->GetAttributes(getter_AddRefs(attributeList));
NS_ENSURE_SUCCESS(res, res);
PRUint32 count;
attributeList->GetLength(&count);
if (!count ||
(1 == count && node->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdirty))) {
// the DIV has no attribute at all or just a _moz_dirty, let's remove it
res = mHTMLEditor->RemoveContainer(element);
NS_ENSURE_SUCCESS(res, res);
}
}
}
}
if (!node || !node->IsHTML(nsGkAtoms::div) ||
node == mHTMLEditor->GetActiveEditingHost() ||
!mHTMLEditor->IsNodeInActiveEditor(node)) {
return NS_OK;
}
// We deal with an editable DIV; let's see if it is useless and if we can
// remove it.
PRUint32 count = node->GetAttrCount();
if (count > 1 ||
(count == 1 && !node->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdirty))) {
return NS_OK;
}
return mHTMLEditor->RemoveContainer(element);
}
//