Bug 572618 - Make debugging the editor easier - Part 1: Replace all if(NS_FAILED) checks with NS_ENSURE_SUCCESS; r=roc
This commit is contained in:
@@ -81,7 +81,7 @@ nsHTMLEditor::AbsolutePositionSelection(PRBool aEnabled)
|
||||
// Find out if the selection is collapsed:
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
nsresult res = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (!selection) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsTextRulesInfo ruleInfo(aEnabled ?
|
||||
@@ -100,7 +100,7 @@ nsHTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement **_retval)
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
nsresult res = GetSelectionContainer(getter_AddRefs(element));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
nsAutoString positionStr;
|
||||
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(element);
|
||||
@@ -109,13 +109,13 @@ nsHTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement **_retval)
|
||||
while (!resultNode && !nsEditor::NodeIsType(node, nsEditProperty::html)) {
|
||||
res = mHTMLCSSUtils->GetComputedProperty(node, nsEditProperty::cssPosition,
|
||||
positionStr);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (positionStr.EqualsLiteral("absolute"))
|
||||
resultNode = node;
|
||||
else {
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
res = node->GetParentNode(getter_AddRefs(parentNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
node.swap(parentNode);
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ nsHTMLEditor::RelativeChangeElementZIndex(nsIDOMElement * aElement,
|
||||
|
||||
PRInt32 zIndex;
|
||||
nsresult res = GetElementZIndex(aElement, &zIndex);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
zIndex = NS_MAX(zIndex + aChange, 0);
|
||||
SetElementZIndex(aElement, zIndex);
|
||||
@@ -197,7 +197,7 @@ nsHTMLEditor::RelativeChangeZIndex(PRInt32 aChange)
|
||||
// Find out if the selection is collapsed:
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
nsresult res = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (!selection) return NS_ERROR_NULL_POINTER;
|
||||
nsTextRulesInfo ruleInfo((aChange < 0) ? nsTextEditRules::kDecreaseZIndex:
|
||||
nsTextEditRules::kIncreaseZIndex);
|
||||
@@ -219,13 +219,13 @@ nsHTMLEditor::GetElementZIndex(nsIDOMElement * aElement,
|
||||
nsresult res = mHTMLCSSUtils->GetSpecifiedProperty(aElement,
|
||||
nsEditProperty::cssZIndex,
|
||||
zIndexStr);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (zIndexStr.EqualsLiteral("auto")) {
|
||||
// we have to look at the positioned ancestors
|
||||
// cf. CSS 2 spec section 9.9.1
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
res = aElement->GetParentNode(getter_AddRefs(parentNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsCOMPtr<nsIDOMNode> node = parentNode;
|
||||
nsAutoString positionStr;
|
||||
while (node &&
|
||||
@@ -234,17 +234,17 @@ nsHTMLEditor::GetElementZIndex(nsIDOMElement * aElement,
|
||||
res = mHTMLCSSUtils->GetComputedProperty(node,
|
||||
nsEditProperty::cssPosition,
|
||||
positionStr);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (positionStr.EqualsLiteral("absolute")) {
|
||||
// ah, we found one, what's its z-index ? If its z-index is auto,
|
||||
// we have to continue climbing the document's tree
|
||||
res = mHTMLCSSUtils->GetComputedProperty(node,
|
||||
nsEditProperty::cssZIndex,
|
||||
zIndexStr);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
}
|
||||
res = node->GetParentNode(getter_AddRefs(parentNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
node = parentNode;
|
||||
}
|
||||
}
|
||||
@@ -293,7 +293,7 @@ nsHTMLEditor::RefreshGrabber()
|
||||
mPositionedObjectMarginLeft,
|
||||
mPositionedObjectMarginTop);
|
||||
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
SetAnonymousElementPosition(mPositionedObjectX+12,
|
||||
mPositionedObjectY-14,
|
||||
@@ -306,7 +306,7 @@ nsHTMLEditor::HideGrabber()
|
||||
{
|
||||
nsresult res =
|
||||
mAbsolutelyPositionedObject->RemoveAttribute(NS_LITERAL_STRING("_moz_abspos"));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
mAbsolutelyPositionedObject = nsnull;
|
||||
NS_ENSURE_TRUE(mGrabber, NS_ERROR_NULL_POINTER);
|
||||
@@ -344,11 +344,11 @@ nsHTMLEditor::ShowGrabberOnElement(nsIDOMElement * aElement)
|
||||
|
||||
nsAutoString classValue;
|
||||
nsresult res = CheckPositionedElementBGandFG(aElement, classValue);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
res = aElement->SetAttribute(NS_LITERAL_STRING("_moz_abspos"),
|
||||
classValue);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
// first, let's keep track of that element...
|
||||
mAbsolutelyPositionedObject = aElement;
|
||||
@@ -467,7 +467,7 @@ nsresult
|
||||
nsHTMLEditor::SetFinalPosition(PRInt32 aX, PRInt32 aY)
|
||||
{
|
||||
nsresult res = EndMoving();
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
// we have now to set the new width and height of the resized object
|
||||
// we don't set the x and y position because we don't control that in
|
||||
@@ -552,15 +552,15 @@ nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement * aElement,
|
||||
// container
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
res = aElement->GetParentNode(getter_AddRefs(parentNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
nsCOMPtr<nsIDOMNodeList> childNodes;
|
||||
res = parentNode->GetChildNodes(getter_AddRefs(childNodes));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (!childNodes) return NS_ERROR_NULL_POINTER;
|
||||
PRUint32 childCount;
|
||||
res = childNodes->GetLength(&childCount);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
if (childCount == 1) {
|
||||
nsCOMPtr<nsIDOMNode> brNode;
|
||||
@@ -592,12 +592,12 @@ nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement * aElement,
|
||||
|
||||
PRBool hasStyleOrIdOrClass;
|
||||
res = HasStyleOrIdOrClass(aElement, &hasStyleOrIdOrClass);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (!hasStyleOrIdOrClass && nsHTMLEditUtils::IsDiv(aElement)) {
|
||||
nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules);
|
||||
if (!htmlRules) return NS_ERROR_FAILURE;
|
||||
res = htmlRules->MakeSureElemStartsOrEndsOnCR(aElement);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
res = RemoveContainer(aElement);
|
||||
}
|
||||
}
|
||||
@@ -680,52 +680,52 @@ nsHTMLEditor::CheckPositionedElementBGandFG(nsIDOMElement * aElement,
|
||||
mHTMLCSSUtils->GetComputedProperty(aElement,
|
||||
nsEditProperty::cssBackgroundImage,
|
||||
bgImageStr);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (bgImageStr.EqualsLiteral("none")) {
|
||||
nsAutoString bgColorStr;
|
||||
res =
|
||||
mHTMLCSSUtils->GetComputedProperty(aElement,
|
||||
nsEditProperty::cssBackgroundColor,
|
||||
bgColorStr);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (bgColorStr.EqualsLiteral("transparent")) {
|
||||
|
||||
nsCOMPtr<nsIDOMViewCSS> viewCSS;
|
||||
res = mHTMLCSSUtils->GetDefaultViewCSS(aElement, getter_AddRefs(viewCSS));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
||||
res = viewCSS->GetComputedStyle(aElement, EmptyString(), getter_AddRefs(cssDecl));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
// from these declarations, get the one we want and that one only
|
||||
nsCOMPtr<nsIDOMCSSValue> colorCssValue;
|
||||
res = cssDecl->GetPropertyCSSValue(NS_LITERAL_STRING("color"), getter_AddRefs(colorCssValue));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
PRUint16 type;
|
||||
res = colorCssValue->GetCssValueType(&type);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (nsIDOMCSSValue::CSS_PRIMITIVE_VALUE == type) {
|
||||
nsCOMPtr<nsIDOMCSSPrimitiveValue> val = do_QueryInterface(colorCssValue);
|
||||
res = val->GetPrimitiveType(&type);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (nsIDOMCSSPrimitiveValue::CSS_RGBCOLOR == type) {
|
||||
nsCOMPtr<nsIDOMRGBColor> rgbColor;
|
||||
res = val->GetRGBColorValue(getter_AddRefs(rgbColor));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsCOMPtr<nsIDOMCSSPrimitiveValue> red, green, blue;
|
||||
float r, g, b;
|
||||
res = rgbColor->GetRed(getter_AddRefs(red));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
res = rgbColor->GetGreen(getter_AddRefs(green));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
res = rgbColor->GetBlue(getter_AddRefs(blue));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
res = red->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_NUMBER, &r);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
res = green->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_NUMBER, &g);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
res = blue->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_NUMBER, &b);
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (r >= BLACK_BG_RGB_TRIGGER &&
|
||||
g >= BLACK_BG_RGB_TRIGGER &&
|
||||
b >= BLACK_BG_RGB_TRIGGER)
|
||||
|
||||
Reference in New Issue
Block a user