editor code cleanup (use contract IDs); r=timeless; sr=kin; bug=209548

This commit is contained in:
brade%netscape.com 2003-07-08 20:22:56 +00:00
parent 44a2105094
commit 9371323b42
13 changed files with 117 additions and 232 deletions

View File

@ -39,11 +39,8 @@
#include "nsIServiceManager.h"
#include "nsIParserService.h"
#include "nsParserCIID.h"
#include "nsEditorParserObserver.h"
static NS_DEFINE_IID(kParserServiceCID, NS_PARSERSERVICE_CID);
NS_IMPL_ADDREF(nsEditorParserObserver);
NS_IMPL_RELEASE(nsEditorParserObserver);
@ -115,7 +112,7 @@ NS_IMETHODIMP nsEditorParserObserver::Start(eHTMLTags* aWatchTags)
{
nsresult res = NS_OK;
nsCOMPtr<nsIParserService> parserService(do_GetService(kParserServiceCID));
nsCOMPtr<nsIParserService> parserService(do_GetService("@mozilla.org/parser/parser-service;1"));
if (!parserService) {
return NS_ERROR_OUT_OF_MEMORY;
@ -130,7 +127,7 @@ NS_IMETHODIMP nsEditorParserObserver::Start(eHTMLTags* aWatchTags)
NS_IMETHODIMP nsEditorParserObserver::End()
{
nsresult res = NS_OK;
nsCOMPtr<nsIParserService> parserService(do_GetService(kParserServiceCID));
nsCOMPtr<nsIParserService> parserService(do_GetService("@mozilla.org/parser/parser-service;1"));
if (!parserService) {
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -40,7 +40,6 @@
#include "nsEditorSpellCheck.h"
#include "nsTextServicesCID.h"
#include "nsITextServicesDocument.h"
#include "nsISpellChecker.h"
#include "nsISelection.h"
@ -58,8 +57,6 @@
#include "nsReadableUtils.h"
#include "nsComposeTxtSrvFilter.h"
static NS_DEFINE_CID(kCTextServicesDocumentCID, NS_TEXTSERVICESDOCUMENT_CID);
NS_IMPL_ISUPPORTS1(nsEditorSpellCheck, nsIEditorSpellCheck);
nsEditorSpellCheck::nsEditorSpellCheck()
@ -81,11 +78,8 @@ nsEditorSpellCheck::InitSpellChecker(nsIEditor* aEditor, PRBool aEnableSelection
nsresult rv;
// We can spell check with any editor type
nsCOMPtr<nsITextServicesDocument>tsDoc;
rv = nsComponentManager::CreateInstance(kCTextServicesDocumentCID,
nsnull,
NS_GET_IID(nsITextServicesDocument),
(void **)getter_AddRefs(tsDoc));
nsCOMPtr<nsITextServicesDocument>tsDoc =
do_CreateInstance("@mozilla.org/textservices/textservicesdocument;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (!tsDoc)

View File

@ -47,7 +47,7 @@
#include "TransactionFactory.h"
#include "nsIContentIterator.h"
#include "nsIContent.h"
#include "nsLayoutCID.h"
#include "nsComponentManagerUtils.h"
#ifdef NS_DEBUG
static PRBool gNoisy = PR_FALSE;
@ -321,11 +321,9 @@ NS_IMETHODIMP DeleteRangeTxn::CreateTxnsToDeleteContent(nsIDOMNode *aParent,
return result;
}
static NS_DEFINE_IID(kSubtreeIteratorCID, NS_SUBTREEITERATOR_CID);
NS_IMETHODIMP DeleteRangeTxn::CreateTxnsToDeleteNodesBetween()
{
nsCOMPtr<nsIContentIterator> iter = do_CreateInstance(kSubtreeIteratorCID);
nsCOMPtr<nsIContentIterator> iter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1");
if (!iter) return NS_ERROR_NULL_POINTER;
nsresult result = iter->Init(mRange);

View File

@ -43,12 +43,10 @@
#include "nsIPrivateTextRange.h"
#include "nsISelection.h"
#include "nsISelectionPrivate.h"
#include "nsLayoutCID.h"
#include "nsISelectionController.h"
#include "nsComponentManagerUtils.h"
// #define DEBUG_IMETXN
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
nsIAtom *IMETextTxn::gIMETextTxnName = nsnull;
@ -350,18 +348,14 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void)
if(selectionStart == selectionEnd)
continue;
nsCOMPtr<nsIDOMRange> newRange;
result= selCon->GetSelection(TextRangeToSelection(textRangeType),
getter_AddRefs(imeSel));
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot get selction");
if(NS_FAILED(result))
break;
result = nsComponentManager::CreateInstance(kRangeCID,
nsnull,
NS_GET_IID(nsIDOMRange),
getter_AddRefs(newRange));
nsCOMPtr<nsIDOMRange> newRange = do_CreateInstance(
"@mozilla.org/content/range;1", &result);
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot create new nsIDOMRange");
if(NS_FAILED(result))
break;

View File

@ -89,9 +89,6 @@ nsAutoSelectionReset::Abort()
* some helper classes for iterating the dom tree
*****************************************************************************/
static NS_DEFINE_IID(kSubtreeIteratorCID, NS_SUBTREEITERATOR_CID);
static NS_DEFINE_IID(kContentIteratorCID, NS_CONTENTITERATOR_CID);
nsDOMIterator::nsDOMIterator() :
mIter(nsnull)
{
@ -104,22 +101,20 @@ nsDOMIterator::~nsDOMIterator()
nsresult
nsDOMIterator::Init(nsIDOMRange* aRange)
{
nsresult res = nsComponentManager::CreateInstance(kContentIteratorCID,
nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(mIter));
nsresult res;
mIter = do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
if (NS_FAILED(res)) return res;
if (!mIter) return NS_ERROR_FAILURE;
return mIter->Init(aRange);
}
nsresult
nsDOMIterator::Init(nsIDOMNode* aNode)
{
nsresult res = nsComponentManager::CreateInstance(kContentIteratorCID,
nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(mIter));
nsresult res;
mIter = do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
if (NS_FAILED(res)) return res;
if (!mIter) return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
return mIter->Init(content);
}
@ -180,22 +175,20 @@ nsDOMSubtreeIterator::~nsDOMSubtreeIterator()
nsresult
nsDOMSubtreeIterator::Init(nsIDOMRange* aRange)
{
nsresult res = nsComponentManager::CreateInstance(kSubtreeIteratorCID,
nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(mIter));
nsresult res;
mIter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
if (NS_FAILED(res)) return res;
if (!mIter) return NS_ERROR_FAILURE;
return mIter->Init(aRange);
}
nsresult
nsDOMSubtreeIterator::Init(nsIDOMNode* aNode)
{
nsresult res = nsComponentManager::CreateInstance(kSubtreeIteratorCID,
nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(mIter));
nsresult res;
mIter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
if (NS_FAILED(res)) return res;
if (!mIter) return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
return mIter->Init(content);
}

View File

@ -75,8 +75,6 @@
#include "nsIEnumerator.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsEditorCID.h"
#include "nsLayoutCID.h"
#include "nsIDOMRange.h"
#include "nsIDOMNSRange.h"
#include "nsISupportsArray.h"
@ -86,7 +84,6 @@
#include "nsIURL.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsWidgetsCID.h"
#include "nsIDocumentEncoder.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIPresShell.h"
@ -106,7 +103,6 @@
#include "nsNetUtil.h"
// Drag & Drop, Clipboard
#include "nsWidgetsCID.h"
#include "nsIClipboard.h"
#include "nsITransferable.h"
#include "nsIDragService.h"
@ -121,13 +117,8 @@
const PRUnichar nbsp = 160;
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID);
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
// Drag & Drop, Clipboard Support
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
static NS_DEFINE_CID(kCHTMLFormatConverterCID, NS_HTMLFORMATCONVERTER_CID);
// private clipboard data flavors for html copy/paste
#define kHTMLContext "text/_moz_htmlcontext"
#define kHTMLInfo "text/_moz_htmlinfo"
@ -873,7 +864,7 @@ NS_IMETHODIMP nsHTMLEditor::PrepareHTMLTransferable(nsITransferable **aTransfera
PRBool aHavePrivFlavor)
{
// Create generic Transferable for getting the data
nsresult rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
nsresult rv = nsComponentManager::CreateInstance("@mozilla.org/widget/transferable;1", nsnull,
NS_GET_IID(nsITransferable),
(void**)aTransferable);
if (NS_FAILED(rv))
@ -1207,13 +1198,15 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDrop(nsIDOMEvent* aDropEvent)
PRUint32 contextLen, infoLen;
nsCOMPtr<nsISupportsString> textDataObj;
nsCOMPtr<nsITransferable> contextTrans = do_CreateInstance(kCTransferableCID);
nsCOMPtr<nsITransferable> contextTrans =
do_CreateInstance("@mozilla.org/widget/transferable;1");
NS_ENSURE_TRUE(contextTrans, NS_ERROR_NULL_POINTER);
contextTrans->AddDataFlavor(kHTMLContext);
dragSession->GetData(contextTrans, i);
contextTrans->GetTransferData(kHTMLContext, getter_AddRefs(contextDataObj), &contextLen);
nsCOMPtr<nsITransferable> infoTrans = do_CreateInstance(kCTransferableCID);
nsCOMPtr<nsITransferable> infoTrans =
do_CreateInstance("@mozilla.org/widget/transferable;1");
NS_ENSURE_TRUE(infoTrans, NS_ERROR_NULL_POINTER);
infoTrans->AddDataFlavor(kHTMLInfo);
dragSession->GetData(infoTrans, i);
@ -1422,7 +1415,7 @@ nsHTMLEditor::PutDragDataInTransferable(nsITransferable **aTransferable)
if (NS_FAILED(rv)) return rv;
/* create html flavor transferable */
nsCOMPtr<nsITransferable> trans = do_CreateInstance(kCTransferableCID);
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1");
NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
if (bIsPlainTextControl)
@ -1451,7 +1444,8 @@ nsHTMLEditor::PutDragDataInTransferable(nsITransferable **aTransferable)
rv = trans->AddDataFlavor(kHTMLMime);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIFormatConverter> htmlConverter = do_CreateInstance(kCHTMLFormatConverterCID);
nsCOMPtr<nsIFormatConverter> htmlConverter =
do_CreateInstance("@mozilla.org/widget/htmlformatconverter;1");
NS_ENSURE_TRUE(htmlConverter, NS_ERROR_FAILURE);
rv = trans->SetConverter(htmlConverter);
@ -1522,7 +1516,7 @@ NS_IMETHODIMP nsHTMLEditor::Paste(PRInt32 aSelectionType)
// Get Clipboard Service
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
if (NS_FAILED(rv))
return rv;
@ -1548,13 +1542,15 @@ NS_IMETHODIMP nsHTMLEditor::Paste(PRInt32 aSelectionType)
PRUint32 contextLen, infoLen;
nsCOMPtr<nsISupportsString> textDataObj;
nsCOMPtr<nsITransferable> contextTrans = do_CreateInstance(kCTransferableCID);
nsCOMPtr<nsITransferable> contextTrans =
do_CreateInstance("@mozilla.org/widget/transferable;1");
NS_ENSURE_TRUE(contextTrans, NS_ERROR_NULL_POINTER);
contextTrans->AddDataFlavor(kHTMLContext);
clipboard->GetData(contextTrans, aSelectionType);
contextTrans->GetTransferData(kHTMLContext, getter_AddRefs(contextDataObj), &contextLen);
nsCOMPtr<nsITransferable> infoTrans = do_CreateInstance(kCTransferableCID);
nsCOMPtr<nsITransferable> infoTrans =
do_CreateInstance("@mozilla.org/widget/transferable;1");
NS_ENSURE_TRUE(infoTrans, NS_ERROR_NULL_POINTER);
infoTrans->AddDataFlavor(kHTMLInfo);
clipboard->GetData(infoTrans, aSelectionType);
@ -1602,7 +1598,7 @@ NS_IMETHODIMP nsHTMLEditor::PasteNoFormatting(PRInt32 aSelectionType)
// Get Clipboard Service
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
if (NS_FAILED(rv))
return rv;
@ -1635,16 +1631,15 @@ NS_IMETHODIMP nsHTMLEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste)
return NS_OK;
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
if (NS_FAILED(rv)) return rv;
// the flavors that we can deal with
const char* const textEditorFlavors[] = { kUnicodeMime, nsnull };
const char* const htmlEditorFlavors[] = { kHTMLMime, kJPEGImageMime, nsnull };
nsCOMPtr<nsISupportsArray> flavorsList;
rv = nsComponentManager::CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, nsnull,
NS_GET_IID(nsISupportsArray), getter_AddRefs(flavorsList));
nsCOMPtr<nsISupportsArray> flavorsList =
do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
PRUint32 editorFlags;
@ -1752,14 +1747,12 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsPlaintextQuotation(PRInt32 aSelectionType)
{
// Get Clipboard Service
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
if (NS_FAILED(rv)) return rv;
// Create generic Transferable for getting the data
nsCOMPtr<nsITransferable> trans;
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
NS_GET_IID(nsITransferable),
(void**) getter_AddRefs(trans));
nsCOMPtr<nsITransferable> trans =
do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
if (NS_SUCCEEDED(rv) && trans)
{
// We only handle plaintext pastes here
@ -2242,9 +2235,8 @@ nsresult nsHTMLEditor::ParseFragment(const nsAString & aFragStr,
PRBool bContext = (aTagStack.Count()==0);
// create the parser to do the conversion.
nsCOMPtr<nsIParser> parser;
nsresult res = nsComponentManager::CreateInstance(kCParserCID, nsnull, NS_GET_IID(nsIParser),
getter_AddRefs(parser));
nsresult res;
nsCOMPtr<nsIParser> parser = do_CreateInstance(kCParserCID, &res);
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(parser, NS_ERROR_FAILURE);
@ -2354,8 +2346,8 @@ nsresult nsHTMLEditor::CreateListOfNodesToPaste(nsIDOMNode *aFragmentAsNode,
aEndOffset = fragLen;
}
nsCOMPtr<nsIDOMRange> docFragRange;
docFragRange = do_CreateInstance(kCRangeCID);
nsCOMPtr<nsIDOMRange> docFragRange =
do_CreateInstance("@mozilla.org/content/range;1");
if (!docFragRange) return NS_ERROR_OUT_OF_MEMORY;
res = docFragRange->SetStart(aStartNode, aStartOffset);

View File

@ -67,7 +67,6 @@
#include "nsIDOMCharacterData.h"
#include "nsIEnumerator.h"
#include "nsIPresShell.h"
#include "nsLayoutCID.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIDOMNamedNodeMap.h"
@ -83,10 +82,6 @@
//const static char* kMOZEditorBogusNodeAttr="MOZ_EDITOR_BOGUS_NODE";
//const static char* kMOZEditorBogusNodeValue="TRUE";
const static PRUnichar nbsp = 160;
static NS_DEFINE_IID(kContentIteratorCID, NS_CONTENTITERATOR_CID);
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
enum
{
@ -274,7 +269,7 @@ nsHTMLEditRules::Init(nsPlaintextEditor *aEditor, PRUint32 aFlags)
}
// make a utility range for use by the listenter
mUtilRange = do_CreateInstance(kRangeCID);
mUtilRange = do_CreateInstance("@mozilla.org/content/range;1");
if (!mUtilRange) return NS_ERROR_NULL_POINTER;
// set up mDocChangeRange to be whole doc
@ -288,7 +283,7 @@ nsHTMLEditRules::Init(nsPlaintextEditor *aEditor, PRUint32 aFlags)
nsAutoLockRulesSniffing lockIt((nsTextEditRules*)this);
if (!mDocChangeRange)
{
mDocChangeRange = do_CreateInstance(kRangeCID);
mDocChangeRange = do_CreateInstance("@mozilla.org/content/range;1");
if (!mDocChangeRange) return NS_ERROR_NULL_POINTER;
}
mDocChangeRange->SelectNode(bodyNode);
@ -1496,7 +1491,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
// the correct portion of the document.
if (!mDocChangeRange)
{
mDocChangeRange = do_CreateInstance(kRangeCID);
mDocChangeRange = do_CreateInstance("@mozilla.org/content/range;1");
if (!mDocChangeRange) return NS_ERROR_NULL_POINTER;
}
res = mDocChangeRange->SetStart(selNode, selOffset);
@ -5023,7 +5018,7 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection)
PRBool nodeBefore=PR_FALSE, nodeAfter=PR_FALSE;
// create a range that represents expanded selection
nsCOMPtr<nsIDOMRange> range = do_CreateInstance(kRangeCID);
nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1");
if (!range) return NS_ERROR_NULL_POINTER;
res = range->SetStart(selStartNode, selStartOffset);
if (NS_FAILED(res)) return res;
@ -6104,7 +6099,7 @@ nsHTMLEditRules::GetNodesFromPoint(DOMPoint point,
point.GetPoint(node, offset);
// use it to make a range
nsCOMPtr<nsIDOMRange> range = do_CreateInstance(kRangeCID);
nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1");
res = range->SetStart(node, offset);
if (NS_FAILED(res)) return res;
/* SetStart() will also set the end for this new range
@ -7298,7 +7293,7 @@ nsHTMLEditRules::PinSelectionToNewBlock(nsISelection *aSelection)
temp = selNode;
// use ranges and mRangeHelper to compare sel point to new block
nsCOMPtr<nsIDOMRange> range = do_CreateInstance(kRangeCID);
nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1");
res = range->SetStart(selNode, selOffset);
if (NS_FAILED(res)) return res;
res = range->SetEnd(selNode, selOffset);
@ -7644,7 +7639,6 @@ nsHTMLEditRules::InDifferentTableElements(nsIDOMNode *aNode1, nsIDOMNode *aNode2
nsresult
nsHTMLEditRules::RemoveEmptyNodes()
{
nsCOMPtr<nsIContentIterator> iter;
nsCOMArray<nsIDOMNode> arrayOfEmptyNodes, arrayOfEmptyCites;
nsCOMPtr<nsISupports> isupports;
PRInt32 nodeCount,j;
@ -7672,7 +7666,8 @@ nsHTMLEditRules::RemoveEmptyNodes()
// _examined_ children empty, but still not have an empty parent.
// need an iterator
iter = do_CreateInstance(kContentIteratorCID);
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/post-content-iterator;1");
if (!iter) return NS_ERROR_NULL_POINTER;
nsresult res = iter->Init(mDocChangeRange);

View File

@ -87,9 +87,6 @@
#include "nsIEnumerator.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsEditorCID.h"
#include "nsLayoutCID.h"
#include "nsContentCID.h"
#include "nsIDOMRange.h"
#include "nsIDOMNSRange.h"
#include "nsISupportsArray.h"
@ -97,7 +94,6 @@
#include "nsIURL.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsWidgetsCID.h"
#include "nsIDocumentEncoder.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIPresShell.h"
@ -117,7 +113,6 @@
#include "nsNetUtil.h"
// Drag & Drop, Clipboard
#include "nsWidgetsCID.h"
#include "nsIClipboard.h"
#include "nsITransferable.h"
#include "nsIDragService.h"
@ -141,13 +136,7 @@
#include "nsIView.h"
#include "nsIWidget.h"
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
static NS_DEFINE_IID(kSubtreeIteratorCID, NS_SUBTREEITERATOR_CID);
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID);
static NS_DEFINE_IID(kRangeUtilsCID, NS_RANGEUTILS_CID);
static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
static NS_DEFINE_CID(kCTransitionalDTDCID, NS_CTRANSITIONAL_DTD_CID);
static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
// Some utilities to handle annoying overloading of "A" tag for link and named anchor
static char hrefText[] = "href";
@ -250,7 +239,7 @@ NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc,
nsresult result = NS_OK, rulesRes = NS_OK;
// make a range util object for comparing dom points
mRangeHelper = do_CreateInstance(kRangeUtilsCID);
mRangeHelper = do_CreateInstance("@mozilla.org/content/range-utils;1");
if (!mRangeHelper) return NS_ERROR_NULL_POINTER;
if (1)
@ -601,7 +590,7 @@ nsHTMLEditor::NodeIsBlockStatic(nsIDOMNode *aNode, PRBool *aIsBlock)
if (!tagAtom) return NS_ERROR_NULL_POINTER;
if (!sParserService) {
sParserService = do_GetService(kParserServiceCID, &rv);
sParserService = do_GetService("@mozilla.org/parser/parser-service;1", &rv);
if (NS_FAILED(rv)) return rv;
}
@ -895,9 +884,8 @@ nsHTMLEditor::GetBlockSectionsForRange(nsIDOMRange *aRange,
if (!aRange) {return NS_ERROR_NULL_POINTER;}
nsresult result;
nsCOMPtr<nsIContentIterator>iter;
result = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator), getter_AddRefs(iter));
nsCOMPtr<nsIContentIterator>iter =
do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &result);
if ((NS_SUCCEEDED(result)) && iter)
{
nsCOMPtr<nsIDOMRange> lastRange;
@ -959,9 +947,8 @@ nsHTMLEditor::GetBlockSectionsForRange(nsIDOMRange *aRange,
}
if (PR_TRUE==addRange)
{
nsCOMPtr<nsIDOMRange> range;
result = nsComponentManager::CreateInstance(kCRangeCID, nsnull,
NS_GET_IID(nsIDOMRange), getter_AddRefs(range));
nsCOMPtr<nsIDOMRange> range =
do_CreateInstance("@mozilla.org/content/range;1", &result);
if ((NS_SUCCEEDED(result)) && range)
{ // initialize the range
range->SetStart(leftNode, 0);
@ -999,10 +986,10 @@ nsHTMLEditor::NextNodeInBlock(nsIDOMNode *aNode, IterDirection aDir)
if (!aNode) return nullNode;
nsCOMPtr<nsIContentIterator> iter;
if (NS_FAILED(nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter))))
nsresult rv;
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &rv);
if (NS_FAILED(rv))
return nullNode;
// much gnashing of teeth as we twit back and forth between content and domnode types
@ -1440,10 +1427,8 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled)
// advance to next cell
// first create an iterator over the table
nsCOMPtr<nsIContentIterator> iter;
res = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter));
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
if (NS_FAILED(res)) return res;
if (!iter) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> cTbl = do_QueryInterface(tbl);
@ -3238,10 +3223,8 @@ nsHTMLEditor::GetSelectedElement(const nsAString& aTagName, nsIDOMElement** aRet
if ((NS_SUCCEEDED(res)) && currentItem)
{
nsCOMPtr<nsIDOMRange> currange( do_QueryInterface(currentItem) );
nsCOMPtr<nsIContentIterator> iter;
res = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter));
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
if (NS_FAILED(res)) return res;
if (iter)
{
@ -3457,8 +3440,8 @@ nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)
{
// We must clear the string buffers
// because GetName, GetValue appends to previous string!
name.SetLength(0);
value.SetLength(0);
name.Truncate();
value.Truncate();
res = attribute->GetName(name);
if (NS_FAILED(res)) return res;
@ -3563,10 +3546,8 @@ nsHTMLEditor::GetLinkedObjects(nsISupportsArray** aNodeList)
if (NS_FAILED(res)) return res;
if (!*aNodeList) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContentIterator> iter;
res = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter));
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
if (!iter) return NS_ERROR_NULL_POINTER;
if ((NS_SUCCEEDED(res)))
{
@ -3971,10 +3952,8 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList)
if (NS_FAILED(res)) return res;
if (!*aNodeList) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContentIterator> iter;
res = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter));
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
if (!iter) return NS_ERROR_NULL_POINTER;
if ((NS_SUCCEEDED(res)))
{
@ -4825,10 +4804,9 @@ nsHTMLEditor::CollapseAdjacentTextNodes(nsIDOMRange *aInRange)
// build a list of editable text nodes
nsCOMPtr<nsIContentIterator> iter;
nsresult result = nsComponentManager::CreateInstance(kSubtreeIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter));
nsresult result;
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &result);
if (NS_FAILED(result)) return result;
if (!iter) return NS_ERROR_NULL_POINTER;
@ -5813,10 +5791,8 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor)
// a list of them (since doing operations on the document during
// iteration would perturb the iterator).
nsCOMPtr<nsIContentIterator> iter;
res = nsComponentManager::CreateInstance(kSubtreeIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter));
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
if (NS_FAILED(res)) return res;
if (!iter) return NS_ERROR_FAILURE;
@ -5982,7 +5958,7 @@ nsHTMLEditor::ParseStyleAttrIntoCSSRule(const nsAString& aString,
return NS_ERROR_UNEXPECTED;
nsCOMPtr <nsIURI> docURL;
doc->GetBaseURL(getter_AddRefs(docURL));
nsCOMPtr<nsICSSParser> css = do_CreateInstance(kCSSParserCID);;
nsCOMPtr<nsICSSParser> css = do_CreateInstance("@mozilla.org/content/css-parser;1");
NS_ASSERTION(css, "can't get a css parser");
if (!css) return NS_ERROR_NULL_POINTER;

View File

@ -60,11 +60,6 @@
#include "nsIEnumerator.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsEditorCID.h"
#include "nsLayoutCID.h"
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
static NS_DEFINE_IID(kSubtreeIteratorCID, NS_SUBTREEITERATOR_CID);
NS_IMETHODIMP nsHTMLEditor::AddDefaultProperty(nsIAtom *aProperty,
@ -220,10 +215,8 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty,
// a list of them (since doing operations on the document during
// iteration would perturb the iterator).
nsCOMPtr<nsIContentIterator> iter;
res = nsComponentManager::CreateInstance(kSubtreeIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter));
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
if (NS_FAILED(res)) return res;
if (!iter) return NS_ERROR_FAILURE;
@ -1089,8 +1082,8 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
}
// non-collapsed selection
nsCOMPtr<nsIContentIterator> iter;
iter = do_CreateInstance(kCContentIteratorCID);
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/post-content-iterator;1");
if (!iter) return NS_ERROR_NULL_POINTER;
iter->Init(range);
@ -1382,10 +1375,8 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr
else
{
// not the easy case. range not contained in single text node.
nsCOMPtr<nsIContentIterator> iter;
res = nsComponentManager::CreateInstance(kSubtreeIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter));
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
if (NS_FAILED(res)) return res;
if (!iter) return NS_ERROR_FAILURE;
@ -1563,10 +1554,8 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange)
// a list of them (since doing operations on the document during
// iteration would perturb the iterator).
nsCOMPtr<nsIContentIterator> iter;
res = nsComponentManager::CreateInstance(kSubtreeIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter));
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
if (NS_FAILED(res)) return res;
if (!iter) return NS_ERROR_FAILURE;

View File

@ -39,20 +39,14 @@
#include "nsTextFragment.h"
#include "nsWSRunObject.h"
#include "nsIDOMNode.h"
//#include "nsIModule.h"
#include "nsHTMLEditor.h"
#include "nsHTMLEditUtils.h"
#include "nsTextEditUtils.h"
#include "nsIContent.h"
#include "nsLayoutCID.h"
#include "nsIDOMCharacterData.h"
#include "nsEditorUtils.h"
#include "nsCRT.h"
const PRUnichar nbsp = 160;
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID);
static PRBool IsBlockNode(nsIDOMNode* node)
{
PRBool isBlock (PR_FALSE);
@ -1592,7 +1586,8 @@ nsWSRunObject::DeleteChars(nsIDOMNode *aStartNode, PRInt32 aStartOffset,
{
if (!range)
{
range = do_CreateInstance(kCRangeCID);
range = do_CreateInstance("@mozilla.org/content/range;1");
if (!range) return NS_ERROR_OUT_OF_MEMORY;
res = range->SetStart(aStartNode, aStartOffset);
NS_ENSURE_SUCCESS(res, res);
res = range->SetEnd(aEndNode, aEndOffset);

View File

@ -50,16 +50,15 @@
#include "nsILineBreakerFactory.h"
#include "nsLWBrkCIID.h"
static PRUnichar gt ('>');
static PRUnichar space (' ');
static PRUnichar nbsp (0xa0);
static PRUnichar nl ('\n');
static PRUnichar cr('\r');
const PRUnichar gt ('>');
const PRUnichar space (' ');
const PRUnichar nbsp (0xa0);
const PRUnichar nl ('\n');
const PRUnichar cr('\r');
/** Mail citations using the Internet style: > This is a citation
*/
static NS_DEFINE_CID(kLWBrkCID, NS_LWBRK_CID);
nsInternetCiter::nsInternetCiter()
{
@ -204,18 +203,18 @@ nsInternetCiter::Rewrap(const nsAString& aInString,
nsCOMPtr<nsILineBreaker> lineBreaker;
nsILineBreakerFactory *lf;
nsresult rv = NS_OK;
rv = nsServiceManager::GetService(kLWBrkCID,
nsresult rv;
rv = nsServiceManager::GetService(NS_LWBRK_CONTRACTID,
NS_GET_IID(nsILineBreakerFactory),
(nsISupports **)&lf);
if (NS_SUCCEEDED(rv))
{
nsAutoString lbarg;
rv = lf->GetBreaker(lbarg, getter_AddRefs(lineBreaker));
nsServiceManager::ReleaseService(kLWBrkCID, lf);
nsServiceManager::ReleaseService(NS_LWBRK_CONTRACTID, lf);
}
aOutString.SetLength(0);
aOutString.Truncate();
// Loop over lines in the input string, rewrapping each one.
PRUint32 length = aInString.Length();

View File

@ -56,7 +56,6 @@
#include "nsISupportsPrimitives.h"
// Drag & Drop, Clipboard
#include "nsWidgetsCID.h"
#include "nsIClipboard.h"
#include "nsITransferable.h"
#include "nsIDragService.h"
@ -67,15 +66,10 @@
const PRUnichar nbsp = 160;
// Drag & Drop, Clipboard Support
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
static NS_DEFINE_CID(kCHTMLFormatConverterCID, NS_HTMLFORMATCONVERTER_CID);
NS_IMETHODIMP nsPlaintextEditor::PrepareTransferable(nsITransferable **transferable)
{
// Create generic Transferable for getting the data
nsresult rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
nsresult rv = nsComponentManager::CreateInstance("@mozilla.org/widget/transferable;1", nsnull,
NS_GET_IID(nsITransferable),
(void**)transferable);
if (NS_FAILED(rv))
@ -170,8 +164,7 @@ NS_IMETHODIMP nsPlaintextEditor::InsertFromDrop(nsIDOMEvent* aDropEvent)
// transferable hooks
nsCOMPtr<nsIDOMDocument> domdoc;
GetDocument(getter_AddRefs(domdoc));
PRBool isAllowed = nsEditorHookUtils::DoAllowDropHook(domdoc, aDropEvent, dragSession);
if (!isAllowed)
if (!nsEditorHookUtils::DoAllowDropHook(domdoc, aDropEvent, dragSession))
return NS_OK;
// Get the nsITransferable interface for getting the data from the drop
@ -302,8 +295,7 @@ NS_IMETHODIMP nsPlaintextEditor::InsertFromDrop(nsIDOMEvent* aDropEvent)
doPlaceCaret = PR_FALSE;
}
PRBool doInsert = nsEditorHookUtils::DoInsertionHook(domdoc, aDropEvent, trans);
if (!doInsert)
if (!nsEditorHookUtils::DoInsertionHook(domdoc, aDropEvent, trans))
return NS_OK;
rv = InsertTextFromTransferable(trans, newSelectionParent, newSelectionOffset, deleteSelection);
@ -429,7 +421,7 @@ NS_IMETHODIMP nsPlaintextEditor::Paste(PRInt32 aSelectionType)
// Get Clipboard Service
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard( do_GetService( kCClipboardCID, &rv ) );
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
if ( NS_FAILED(rv) )
return rv;
@ -444,8 +436,7 @@ NS_IMETHODIMP nsPlaintextEditor::Paste(PRInt32 aSelectionType)
// handle transferable hooks
nsCOMPtr<nsIDOMDocument> domdoc;
GetDocument(getter_AddRefs(domdoc));
PRBool doInsert = nsEditorHookUtils::DoInsertionHook(domdoc, nsnull, trans);
if (!doInsert)
if (!nsEditorHookUtils::DoInsertionHook(domdoc, nsnull, trans))
return NS_OK;
rv = InsertTextFromTransferable(trans, nsnull, nsnull, PR_TRUE);
@ -467,7 +458,7 @@ NS_IMETHODIMP nsPlaintextEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPa
return NS_OK;
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
if (NS_FAILED(rv)) return rv;
// the flavors that we can deal with
@ -576,7 +567,7 @@ nsPlaintextEditor::PutDragDataInTransferable(nsITransferable **aTransferable)
if (NS_FAILED(rv)) return rv;
/* create html flavor transferable */
nsCOMPtr<nsITransferable> trans = do_CreateInstance(kCTransferableCID, &rv);
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
// find out if we're a plaintext control or not
@ -596,7 +587,7 @@ nsPlaintextEditor::PutDragDataInTransferable(nsITransferable **aTransferable)
rv = trans->AddDataFlavor(kHTMLMime);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIFormatConverter> htmlConverter = do_CreateInstance(kCHTMLFormatConverterCID);
nsCOMPtr<nsIFormatConverter> htmlConverter = do_CreateInstance("@mozilla.org/widget/htmlformatconverter;1");
NS_ENSURE_TRUE(htmlConverter, NS_ERROR_FAILURE);
rv = trans->SetConverter(htmlConverter);

View File

@ -70,8 +70,6 @@
#include "nsIEnumerator.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsEditorCID.h"
#include "nsLayoutCID.h"
#include "nsIDOMRange.h"
#include "nsIDOMNSRange.h"
#include "nsISupportsArray.h"
@ -79,7 +77,6 @@
#include "nsIURL.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsWidgetsCID.h"
#include "nsIDocumentEncoder.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIPresShell.h"
@ -102,21 +99,11 @@
#include "nsInternetCiter.h"
// Drag & Drop, Clipboard
//#include "nsWidgetsCID.h"
#include "nsIClipboard.h"
#include "nsITransferable.h"
//#include "nsIDragService.h"
//#include "nsIDOMNSUIEvent.h"
const PRUnichar nbsp = 160;
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID);
static NS_DEFINE_CID(kCDOMSelectionCID, NS_DOMSELECTION_CID);
// Drag & Drop, Clipboard Support
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
// prototype for rules creation shortcut
nsresult NS_NewTextEditRules(nsIEditRules** aInstancePtrResult);
@ -730,10 +717,8 @@ nsPlaintextEditor::GetAbsoluteOffsetsForPoints(nsIDOMNode *aInStartNode,
aOutStartOffset = 0; // default to first char in selection
aOutEndOffset = -1; // default to total length of text in selection
nsCOMPtr<nsIContentIterator> iter;
result = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,
NS_GET_IID(nsIContentIterator),
getter_AddRefs(iter));
nsCOMPtr<nsIContentIterator> iter = do_CreateInstance(
"@mozilla.org/content/post-content-iterator;1", &result);
if (NS_FAILED(result)) return result;
if (!iter) return NS_ERROR_NULL_POINTER;
@ -1453,11 +1438,11 @@ nsPlaintextEditor::GetAndInitDocEncoder(const nsAString& aFormatType,
if (!nsTextEditUtils::IsBody(rootElement))
{
// XXX Why does this use range rather than selection collapse/extend?
nsCOMPtr<nsIDOMRange> range (do_CreateInstance(kCRangeCID, &rv));
nsCOMPtr<nsIDOMRange> range (do_CreateInstance("@mozilla.org/content/range;1", &rv));
if (NS_FAILED(rv)) return rv;
if (!range) return NS_ERROR_FAILURE;
nsCOMPtr<nsISelection> selection (do_CreateInstance(kCDOMSelectionCID,
&rv));
nsCOMPtr<nsISelection> selection (do_CreateInstance(
"@mozilla.org/content/dom-selection;1", &rv));
if (NS_FAILED(rv)) return rv;
if (!selection) return NS_ERROR_FAILURE;
@ -1571,14 +1556,11 @@ nsPlaintextEditor::PasteAsQuotation(PRInt32 aSelectionType)
{
// Get Clipboard Service
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
if (NS_FAILED(rv)) return rv;
// Create generic Transferable for getting the data
nsCOMPtr<nsITransferable> trans;
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
NS_GET_IID(nsITransferable),
(void**) getter_AddRefs(trans));
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
if (NS_SUCCEEDED(rv) && trans)
{
// We only handle plaintext pastes here
@ -2096,20 +2078,10 @@ NS_IMETHODIMP nsPlaintextEditor::GetLayoutObject(nsIDOMNode *aNode, nsISupports
NS_IMETHODIMP
nsPlaintextEditor::IsRootTag(nsString &aTag, PRBool &aIsTag)
{
static char bodyTag[] = "body";
static char tdTag[] = "td";
static char thTag[] = "th";
static char captionTag[] = "caption";
if (aTag.EqualsIgnoreCase(bodyTag) ||
aTag.EqualsIgnoreCase(tdTag) ||
aTag.EqualsIgnoreCase(thTag) ||
aTag.EqualsIgnoreCase(captionTag) )
{
aIsTag = PR_TRUE;
}
else {
aIsTag = PR_FALSE;
}
aIsTag = (aTag.EqualsIgnoreCase("body") ||
aTag.EqualsIgnoreCase("td") ||
aTag.EqualsIgnoreCase("th") ||
aTag.EqualsIgnoreCase("caption") );
return NS_OK;
}