5734: put back working copy from version 1.17, which got accidentally stomped in a cvs merge. a=cyeh,kostello
This commit is contained in:
@@ -948,39 +948,59 @@ nsHTMLEditor::InsertImage(nsString& aURL,
|
||||
nsString& aAlignment)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
(void)nsEditor::BeginTransaction();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> newNode;
|
||||
nsAutoString tag("IMG");
|
||||
res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
|
||||
if (!NS_SUCCEEDED(res) || !newNode)
|
||||
|
||||
nsCOMPtr<nsIDOMDocument>doc;
|
||||
res = GetDocument(getter_AddRefs(doc));
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
(void)nsEditor::EndTransaction();
|
||||
nsAutoString tag("IMG");
|
||||
nsCOMPtr<nsIDOMElement>newElement;
|
||||
res = doc->CreateElement(tag, getter_AddRefs(newElement));
|
||||
if (NS_SUCCEEDED(res) && newElement)
|
||||
{
|
||||
newNode = do_QueryInterface(newElement);
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> image (do_QueryInterface(newNode));
|
||||
// Set all the attributes now, before we insert into the tree:
|
||||
if (image)
|
||||
{
|
||||
if (NS_SUCCEEDED(res = image->SetSrc(aURL)))
|
||||
if (NS_SUCCEEDED(res = image->SetWidth(aWidth)))
|
||||
if (NS_SUCCEEDED(res = image->SetHeight(aHeight)))
|
||||
if (NS_SUCCEEDED(res = image->SetAlt(aAlt)))
|
||||
if (NS_SUCCEEDED(res = image->SetBorder(aBorder)))
|
||||
if (NS_SUCCEEDED(res = image->SetAlign(aAlignment)))
|
||||
if (NS_SUCCEEDED(res = image->SetHspace(aHspace)))
|
||||
if (NS_SUCCEEDED(res = image->SetVspace(aVspace)))
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If any of these failed, then don't insert the new node into the tree
|
||||
if (!NS_SUCCEEDED(res))
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Some failure creating the new image node\n");
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> image (do_QueryInterface(newNode));
|
||||
if (!image)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Not an image element\n");
|
||||
#endif
|
||||
(void)nsEditor::EndTransaction();
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
//
|
||||
// Now we're ready to insert the new image node:
|
||||
// Starting now, don't return without ending the transaction!
|
||||
//
|
||||
(void)nsEditor::BeginTransaction();
|
||||
|
||||
// Can't return from any of these intermediates
|
||||
// because then we won't hit the EndTransaction()
|
||||
if (NS_SUCCEEDED(res = image->SetSrc(aURL)))
|
||||
if (NS_SUCCEEDED(res = image->SetWidth(aWidth)))
|
||||
if (NS_SUCCEEDED(res = image->SetHeight(aHeight)))
|
||||
if (NS_SUCCEEDED(res = image->SetAlt(aAlt)))
|
||||
if (NS_SUCCEEDED(res = image->SetBorder(aBorder)))
|
||||
if (NS_SUCCEEDED(res = image->SetAlign(aAlignment)))
|
||||
if (NS_SUCCEEDED(res = image->SetHspace(aHspace)))
|
||||
if (NS_SUCCEEDED(res = image->SetVspace(aVspace)))
|
||||
;
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
PRInt32 offsetOfNewNode;
|
||||
res = nsEditor::DeleteSelectionAndPrepareToCreateNode(parentNode,
|
||||
offsetOfNewNode);
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
// and insert it into the right place in the tree:
|
||||
res = InsertNode(newNode, parentNode, offsetOfNewNode);
|
||||
}
|
||||
|
||||
(void)nsEditor::EndTransaction(); // don't return this result!
|
||||
|
||||
|
||||
@@ -948,39 +948,59 @@ nsHTMLEditor::InsertImage(nsString& aURL,
|
||||
nsString& aAlignment)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
(void)nsEditor::BeginTransaction();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> newNode;
|
||||
nsAutoString tag("IMG");
|
||||
res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
|
||||
if (!NS_SUCCEEDED(res) || !newNode)
|
||||
|
||||
nsCOMPtr<nsIDOMDocument>doc;
|
||||
res = GetDocument(getter_AddRefs(doc));
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
(void)nsEditor::EndTransaction();
|
||||
nsAutoString tag("IMG");
|
||||
nsCOMPtr<nsIDOMElement>newElement;
|
||||
res = doc->CreateElement(tag, getter_AddRefs(newElement));
|
||||
if (NS_SUCCEEDED(res) && newElement)
|
||||
{
|
||||
newNode = do_QueryInterface(newElement);
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> image (do_QueryInterface(newNode));
|
||||
// Set all the attributes now, before we insert into the tree:
|
||||
if (image)
|
||||
{
|
||||
if (NS_SUCCEEDED(res = image->SetSrc(aURL)))
|
||||
if (NS_SUCCEEDED(res = image->SetWidth(aWidth)))
|
||||
if (NS_SUCCEEDED(res = image->SetHeight(aHeight)))
|
||||
if (NS_SUCCEEDED(res = image->SetAlt(aAlt)))
|
||||
if (NS_SUCCEEDED(res = image->SetBorder(aBorder)))
|
||||
if (NS_SUCCEEDED(res = image->SetAlign(aAlignment)))
|
||||
if (NS_SUCCEEDED(res = image->SetHspace(aHspace)))
|
||||
if (NS_SUCCEEDED(res = image->SetVspace(aVspace)))
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If any of these failed, then don't insert the new node into the tree
|
||||
if (!NS_SUCCEEDED(res))
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Some failure creating the new image node\n");
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> image (do_QueryInterface(newNode));
|
||||
if (!image)
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Not an image element\n");
|
||||
#endif
|
||||
(void)nsEditor::EndTransaction();
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
//
|
||||
// Now we're ready to insert the new image node:
|
||||
// Starting now, don't return without ending the transaction!
|
||||
//
|
||||
(void)nsEditor::BeginTransaction();
|
||||
|
||||
// Can't return from any of these intermediates
|
||||
// because then we won't hit the EndTransaction()
|
||||
if (NS_SUCCEEDED(res = image->SetSrc(aURL)))
|
||||
if (NS_SUCCEEDED(res = image->SetWidth(aWidth)))
|
||||
if (NS_SUCCEEDED(res = image->SetHeight(aHeight)))
|
||||
if (NS_SUCCEEDED(res = image->SetAlt(aAlt)))
|
||||
if (NS_SUCCEEDED(res = image->SetBorder(aBorder)))
|
||||
if (NS_SUCCEEDED(res = image->SetAlign(aAlignment)))
|
||||
if (NS_SUCCEEDED(res = image->SetHspace(aHspace)))
|
||||
if (NS_SUCCEEDED(res = image->SetVspace(aVspace)))
|
||||
;
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
PRInt32 offsetOfNewNode;
|
||||
res = nsEditor::DeleteSelectionAndPrepareToCreateNode(parentNode,
|
||||
offsetOfNewNode);
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
// and insert it into the right place in the tree:
|
||||
res = InsertNode(newNode, parentNode, offsetOfNewNode);
|
||||
}
|
||||
|
||||
(void)nsEditor::EndTransaction(); // don't return this result!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user