code cleanup; r=timeless, sr=kin, bug=209548
git-svn-id: svn://10.0.0.236/trunk@144260 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
9fdcf02118
commit
867d6187f8
@ -39,16 +39,12 @@
|
||||
|
||||
#include "ChangeCSSInlineStyleTxn.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsEditor.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsIDOMElementCSSInlineStyle.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsEditProperty.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIHTMLObjectResizer.h"
|
||||
|
||||
#define kNullCh (PRUnichar('\0'))
|
||||
|
||||
@ -169,8 +165,8 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::Init(nsIEditor *aEditor,
|
||||
mRemoveProperty = aRemoveProperty;
|
||||
mUndoAttributeWasSet = PR_FALSE;
|
||||
mRedoAttributeWasSet = PR_FALSE;
|
||||
mUndoValue.SetLength(0);
|
||||
mRedoValue.SetLength(0);
|
||||
mUndoValue.Truncate();
|
||||
mRedoValue.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -179,24 +175,18 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::DoTransaction(void)
|
||||
NS_ASSERTION(mEditor && mElement, "bad state");
|
||||
if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
|
||||
|
||||
nsresult result = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
||||
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(mElement);
|
||||
if (!inlineStyles) return NS_ERROR_NULL_POINTER;
|
||||
result = inlineStyles->GetStyle(getter_AddRefs(cssDecl));
|
||||
|
||||
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
||||
nsresult result = inlineStyles->GetStyle(getter_AddRefs(cssDecl));
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!cssDecl) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsAutoString propertyNameString;
|
||||
mProperty->ToString(propertyNameString);
|
||||
|
||||
// does this property accept more than 1 value ?
|
||||
// we need to know that because of bug 62682
|
||||
PRBool multiple = AcceptsMoreThanOneValue(mProperty);
|
||||
|
||||
nsAutoString styleAttr(NS_LITERAL_STRING("style"));
|
||||
|
||||
NS_NAMED_LITERAL_STRING(styleAttr, "style");
|
||||
result = mElement->HasAttribute(styleAttr, &mUndoAttributeWasSet);
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
@ -205,6 +195,10 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::DoTransaction(void)
|
||||
if (NS_FAILED(result)) return result;
|
||||
mUndoValue.Assign(values);
|
||||
|
||||
// does this property accept more than 1 value ?
|
||||
// we need to know that because of bug 62682
|
||||
PRBool multiple = AcceptsMoreThanOneValue(mProperty);
|
||||
|
||||
if (mRemoveProperty) {
|
||||
nsAutoString returnString;
|
||||
if (multiple) {
|
||||
@ -272,15 +266,15 @@ nsresult ChangeCSSInlineStyleTxn::SetStyle(PRBool aAttributeWasSet,
|
||||
NS_ASSERTION(mEditor && mElement, "bad state");
|
||||
if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
|
||||
|
||||
nsresult result = NS_OK;
|
||||
nsresult result;
|
||||
if (aAttributeWasSet) {
|
||||
// the style attribute was set and not empty, let's recreate the declaration
|
||||
nsAutoString propertyNameString;
|
||||
mProperty->ToString(propertyNameString);
|
||||
|
||||
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
||||
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(mElement);
|
||||
if (!inlineStyles) return NS_ERROR_NULL_POINTER;
|
||||
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
||||
result = inlineStyles->GetStyle(getter_AddRefs(cssDecl));
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!cssDecl) return NS_ERROR_NULL_POINTER;
|
||||
@ -316,8 +310,8 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::RedoTransaction(void)
|
||||
|
||||
NS_IMETHODIMP ChangeCSSInlineStyleTxn::Merge(nsITransaction *aTransaction, PRBool *aDidMerge)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
if (aDidMerge)
|
||||
*aDidMerge = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -339,11 +333,8 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::GetTxnDescription(nsAString& aString)
|
||||
PRBool
|
||||
ChangeCSSInlineStyleTxn::AcceptsMoreThanOneValue(nsIAtom *aCSSProperty)
|
||||
{
|
||||
PRBool res = PR_FALSE;
|
||||
nsIAtom * textDecorationAtom = NS_NewAtom("text-decoration");
|
||||
if (textDecorationAtom == aCSSProperty) {
|
||||
res = PR_TRUE;
|
||||
}
|
||||
PRBool res = (textDecorationAtom == aCSSProperty);
|
||||
NS_IF_RELEASE(textDecorationAtom);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -152,10 +152,10 @@ protected:
|
||||
|
||||
/** the value to set the property to for undo */
|
||||
nsString mUndoValue;
|
||||
/** true if the style attribute was present and not empty before DoTransaction */
|
||||
PRBool mUndoAttributeWasSet;
|
||||
/** the value to set the property to for redo */
|
||||
nsString mRedoValue;
|
||||
/** true if the style attribute was present and not empty before DoTransaction */
|
||||
PRBool mUndoAttributeWasSet;
|
||||
/** true if the style attribute is present and not empty after DoTransaction */
|
||||
PRBool mRedoAttributeWasSet;
|
||||
|
||||
|
||||
@ -99,19 +99,18 @@ NS_IMETHODIMP CreateElementTxn::DoTransaction(void)
|
||||
|
||||
NS_ASSERTION(mEditor && mParent, "bad state");
|
||||
if (!mEditor || !mParent) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult result;
|
||||
// create a new node
|
||||
nsCOMPtr<nsIDOMDocument>doc;
|
||||
result = mEditor->GetDocument(getter_AddRefs(doc));
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!doc) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsAutoString textNodeTag;
|
||||
result = nsEditor::GetTextNodeTag(textNodeTag);
|
||||
nsresult result = nsEditor::GetTextNodeTag(textNodeTag);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
|
||||
if (textNodeTag == mTag)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument>doc;
|
||||
result = mEditor->GetDocument(getter_AddRefs(doc));
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!doc) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
const nsString stringData;
|
||||
nsCOMPtr<nsIDOMText>newTextNode;
|
||||
result = doc->CreateTextNode(stringData, getter_AddRefs(newTextNode));
|
||||
@ -122,12 +121,11 @@ NS_IMETHODIMP CreateElementTxn::DoTransaction(void)
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
nsCOMPtr<nsIDOMElement>newElement;
|
||||
|
||||
//new call to use instead to get proper HTML element, bug# 39919
|
||||
result = mEditor->CreateHTMLContent(mTag, getter_AddRefs(newContent));
|
||||
newElement = do_QueryInterface(newContent);
|
||||
if (NS_FAILED(result)) return result;
|
||||
nsCOMPtr<nsIDOMElement>newElement = do_QueryInterface(newContent);
|
||||
if (!newElement) return NS_ERROR_NULL_POINTER;
|
||||
mNewNode = do_QueryInterface(newElement);
|
||||
// Try to insert formatting whitespace for the new node:
|
||||
@ -199,8 +197,7 @@ NS_IMETHODIMP CreateElementTxn::UndoTransaction(void)
|
||||
if (!mEditor || !mParent) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
nsresult result = mParent->RemoveChild(mNewNode, getter_AddRefs(resultNode));
|
||||
return result;
|
||||
return mParent->RemoveChild(mNewNode, getter_AddRefs(resultNode));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::RedoTransaction(void)
|
||||
@ -213,8 +210,7 @@ NS_IMETHODIMP CreateElementTxn::RedoTransaction(void)
|
||||
if (!mEditor || !mParent) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// first, reset mNewNode so it has no attributes or content
|
||||
nsCOMPtr<nsIDOMCharacterData>nodeAsText;
|
||||
nodeAsText = do_QueryInterface(mNewNode);
|
||||
nsCOMPtr<nsIDOMCharacterData>nodeAsText = do_QueryInterface(mNewNode);
|
||||
if (nodeAsText)
|
||||
{
|
||||
nsAutoString nullString;
|
||||
@ -223,13 +219,12 @@ NS_IMETHODIMP CreateElementTxn::RedoTransaction(void)
|
||||
|
||||
// now, reinsert mNewNode
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
nsresult result = mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode));
|
||||
return result;
|
||||
return mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CreateElementTxn::Merge(nsITransaction *aTransaction, PRBool *aDidMerge)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
if (aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -87,13 +87,11 @@ NS_IMETHODIMP DeleteElementTxn::DoTransaction(void)
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
// begin debug output
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
element = do_QueryInterface(mElement);
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mElement);
|
||||
nsAutoString elementTag(NS_LITERAL_STRING("text node"));
|
||||
if (element)
|
||||
element->GetTagName(elementTag);
|
||||
nsCOMPtr<nsIDOMElement> parentElement;
|
||||
parentElement = do_QueryInterface(mParent);
|
||||
nsCOMPtr<nsIDOMElement> parentElement = do_QueryInterface(mParent);
|
||||
nsAutoString parentElementTag(NS_LITERAL_STRING("text node"));
|
||||
if (parentElement)
|
||||
parentElement->GetTagName(parentElementTag);
|
||||
@ -102,10 +100,8 @@ NS_IMETHODIMP DeleteElementTxn::DoTransaction(void)
|
||||
p = ToNewCString(parentElementTag);
|
||||
if (c&&p)
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
if (gNoisy)
|
||||
printf(" DeleteElementTxn: deleting child %s from parent %s\n", c, p);
|
||||
#endif
|
||||
|
||||
nsCRT::free(c);
|
||||
nsCRT::free(p);
|
||||
@ -122,9 +118,7 @@ NS_IMETHODIMP DeleteElementTxn::DoTransaction(void)
|
||||
mRangeUpdater->SelAdjDeleteNode(mElement);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
result = mParent->RemoveChild(mElement, getter_AddRefs(resultNode));
|
||||
|
||||
return result;
|
||||
return mParent->RemoveChild(mElement, getter_AddRefs(resultNode));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::UndoTransaction(void)
|
||||
@ -138,13 +132,11 @@ NS_IMETHODIMP DeleteElementTxn::UndoTransaction(void)
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
// begin debug output
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
element = do_QueryInterface(mElement);
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mElement);
|
||||
nsAutoString elementTag(NS_LITERAL_STRING("text node"));
|
||||
if (element)
|
||||
element->GetTagName(elementTag);
|
||||
nsCOMPtr<nsIDOMElement> parentElement;
|
||||
parentElement = do_QueryInterface(mParent);
|
||||
nsCOMPtr<nsIDOMElement> parentElement = do_QueryInterface(mParent);
|
||||
nsAutoString parentElementTag(NS_LITERAL_STRING("text node"));
|
||||
if (parentElement)
|
||||
parentElement->GetTagName(parentElementTag);
|
||||
@ -165,8 +157,7 @@ NS_IMETHODIMP DeleteElementTxn::UndoTransaction(void)
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
nsresult result = mParent->InsertBefore(mElement, mRefNode, getter_AddRefs(resultNode));
|
||||
return result;
|
||||
return mParent->InsertBefore(mElement, mRefNode, getter_AddRefs(resultNode));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::RedoTransaction(void)
|
||||
@ -182,15 +173,14 @@ NS_IMETHODIMP DeleteElementTxn::RedoTransaction(void)
|
||||
mRangeUpdater->SelAdjDeleteNode(mElement);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> resultNode;
|
||||
nsresult result = mParent->RemoveChild(mElement, getter_AddRefs(resultNode));
|
||||
return result;
|
||||
return mParent->RemoveChild(mElement, getter_AddRefs(resultNode));
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP DeleteElementTxn::Merge(nsITransaction *aTransaction, PRBool *aDidMerge)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
*aDidMerge=PR_FALSE;
|
||||
if (aDidMerge)
|
||||
*aDidMerge = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user