diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 1ecdd6bd249a..197d147036ee 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -40,7 +40,9 @@ #include "nsIAtom.h" #include "nsVoidArray.h" #include "nsICaret.h" +#ifndef NEW_CLIPBOARD_SUPPORT #include "nsISelectionMgr.h" +#endif #include "nsIContent.h" #include "nsIContentIterator.h" @@ -71,8 +73,6 @@ // END #endif -//#define NEW_CLIPBOARD_SUPPORT - #ifdef NEW_CLIPBOARD_SUPPORT // Drag & Drop, Clipboard @@ -836,12 +836,15 @@ NS_IMETHODIMP nsEditor::Cut() return res; } +#ifndef NEW_CLIPBOARD_SUPPORT extern "C" NS_EXPORT nsISelectionMgr* GetSelectionMgr(); +#endif NS_IMETHODIMP nsEditor::Copy() { //printf("nsEditor::Copy\n"); +#ifndef NEW_CLIPBOARD_SUPPORT // Get the nsSelectionMgr: // XXX BWEEP BWEEP TEMPORARY! // The selection mgr needs to be a service. @@ -857,6 +860,10 @@ NS_IMETHODIMP nsEditor::Copy() //NS_ADD_REF(theSelectionMgr); return mPresShell->DoCopy(selectionMgr); +#else + return mPresShell->DoCopy(); +#endif + } NS_IMETHODIMP nsEditor::Paste() diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 1ecdd6bd249a..197d147036ee 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -40,7 +40,9 @@ #include "nsIAtom.h" #include "nsVoidArray.h" #include "nsICaret.h" +#ifndef NEW_CLIPBOARD_SUPPORT #include "nsISelectionMgr.h" +#endif #include "nsIContent.h" #include "nsIContentIterator.h" @@ -71,8 +73,6 @@ // END #endif -//#define NEW_CLIPBOARD_SUPPORT - #ifdef NEW_CLIPBOARD_SUPPORT // Drag & Drop, Clipboard @@ -836,12 +836,15 @@ NS_IMETHODIMP nsEditor::Cut() return res; } +#ifndef NEW_CLIPBOARD_SUPPORT extern "C" NS_EXPORT nsISelectionMgr* GetSelectionMgr(); +#endif NS_IMETHODIMP nsEditor::Copy() { //printf("nsEditor::Copy\n"); +#ifndef NEW_CLIPBOARD_SUPPORT // Get the nsSelectionMgr: // XXX BWEEP BWEEP TEMPORARY! // The selection mgr needs to be a service. @@ -857,6 +860,10 @@ NS_IMETHODIMP nsEditor::Copy() //NS_ADD_REF(theSelectionMgr); return mPresShell->DoCopy(selectionMgr); +#else + return mPresShell->DoCopy(); +#endif + } NS_IMETHODIMP nsEditor::Paste() diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index 0329f3b860e8..ceeac10c6363 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -38,7 +38,9 @@ class nsString; class nsStringArray; class nsICaret; class nsIStyleContext; +#ifndef NEW_CLIPBOARD_SUPPORT class nsISelectionMgr; +#endif #define NS_IPRESSHELL_IID \ { 0x76e79c60, 0x944e, 0x11d1, \ @@ -261,7 +263,11 @@ public: /** * Notify the SelectionMgr that we have something to copy. */ +#ifndef NEW_CLIPBOARD_SUPPORT NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr) = 0; +#else + NS_IMETHOD DoCopy() = 0; +#endif /** * Get the caret, if it exists. AddRefs it. diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index e2e201ba97a1..87497ad16002 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -326,7 +326,12 @@ public: PRUint32 aVFlags, PRInt32 aHOffsetPercent, PRUint32 aHFlags) const; + +#ifdef NEW_CLIPBOARD_SUPPORT + NS_IMETHOD DoCopy(); +#else NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr); +#endif //nsIViewObserver interface @@ -1542,6 +1547,83 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame, return rv; } + + + +#ifdef NEW_CLIPBOARD_SUPPORT +// New way +NS_IMETHODIMP +PresShell::DoCopy() +{ + nsCOMPtr doc; + GetDocument(getter_AddRefs(doc)); + if (doc) { + nsString buffer; + + nsIDOMSelection* sel = nsnull; + GetSelection(&sel); + + if (sel != nsnull) + doc->CreateXIF(buffer,sel); + NS_IF_RELEASE(sel); + + // Get the Clipboard + nsIClipboard* clipboard; + nsresult rv = nsServiceManager::GetService(kCClipboardCID, + kIClipboardIID, + (nsISupports **)&clipboard); + + if (NS_OK == rv) { + + // Create a data flavor to tell the transferable + // that it is about to receive XIF + nsIDataFlavor * flavor; + rv = nsComponentManager::CreateInstance(kCDataFlavorCID, + nsnull, + kIDataFlavorIID, (void**) &flavor); + if (NS_OK == rv) { + // Initialize data flavor to XIF + flavor->Init(kXIFMime, "XIF"); + + // Create a transferable for putting data on the Clipboard + nsITransferable * trans; + rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, + kITransferableIID, (void**) &trans); + if (NS_OK == rv) { + // The data on the clipboard will be in "XIF" format + // so give the clipboard transferable a "XIFConverter" for + // converting from XIF to other formats + nsIFormatConverter * xifConverter; + rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull, + kIFormatConverterIID, (void**) &xifConverter); + if (NS_OK == rv) { + // Add the XIF DataFlavor to the transferable + // this tells the transferable that it can handle receiving the XIF format + trans->AddDataFlavor(flavor); + + // Add the converter for going from XIF to other formats + trans->SetConverter(xifConverter); + + // Now add the XIF data to the transferable + trans->SetTransferData(flavor, buffer.ToNewCString(), buffer.Length()); + + // put the transferable on the clipboard + clipboard->SetData(trans, nsnull); + + NS_IF_RELEASE(xifConverter); + } + NS_IF_RELEASE(trans); + } + NS_IF_RELEASE(flavor); + } + NS_IF_RELEASE(clipboard); + } + } + return NS_OK; +} +#else + +// Old SelectionMgr implementation. NS_IMETHODIMP PresShell::DoCopy(nsISelectionMgr* aSelectionMgr) { @@ -1557,8 +1639,6 @@ PresShell::DoCopy(nsISelectionMgr* aSelectionMgr) doc->CreateXIF(buffer,sel); NS_IF_RELEASE(sel); -////////////////////////// Old Way -#ifndef NEW_CLIPBOARD_SUPPORT nsIParser* parser; static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); @@ -1605,61 +1685,13 @@ PresShell::DoCopy(nsISelectionMgr* aSelectionMgr) NS_IF_RELEASE(sink); NS_RELEASE(parser); -#else /////////////////////////// New Way - // Put XIF into transferable - - // Get the Clipboard - nsIClipboard* clipboard; - nsresult rv = nsServiceManager::GetService(kCClipboardCID, - kIClipboardIID, - (nsISupports **)&clipboard); - - if (NS_OK == rv) { - - // Create a data flavor to tell the transferable - // that it is about to receive XIF - nsIDataFlavor * flavor; - rv = nsComponentManager::CreateInstance(kCDataFlavorCID, nsnull, kIDataFlavorIID, (void**) &flavor); - if (NS_OK == rv) { - // Initialize data flavor to XIF - flavor->Init(kXIFMime, "XIF"); - - // Create a transferable for putting data on the Clipboard - nsITransferable * trans; - rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, kITransferableIID, (void**) &trans); - if (NS_OK == rv) { - // The data on the clipboard will be in "XIF" format - // so give the clipboard transferable a "XIFConverter" for - // converting from XIF to other formats - nsIFormatConverter * xifConverter; - rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull, kIFormatConverterIID, (void**) &xifConverter); - if (NS_OK == rv) { - // Add the XIF DataFlavor to the transferable - // this tells the transferable that it can handle receiving the XIF format - trans->AddDataFlavor(flavor); - - // Add the converter for going from XIF to other formats - trans->SetConverter(xifConverter); - - // Now add the XIF data to the transferable - trans->SetTransferData(flavor, buffer.ToNewCString(), buffer.Length()); - - // put the transferable on the clipboard - clipboard->SetData(trans, nsnull); - - NS_IF_RELEASE(xifConverter); - } - NS_IF_RELEASE(trans); - } - NS_IF_RELEASE(flavor); - } - NS_IF_RELEASE(clipboard); - } -#endif } return NS_OK; } +#endif // NEW_CLIPBOARD_SUPPORT + + NS_IMETHODIMP PresShell::ContentChanged(nsIDocument *aDocument, nsIContent* aContent, diff --git a/layout/base/public/nsIPresShell.h b/layout/base/public/nsIPresShell.h index 0329f3b860e8..ceeac10c6363 100644 --- a/layout/base/public/nsIPresShell.h +++ b/layout/base/public/nsIPresShell.h @@ -38,7 +38,9 @@ class nsString; class nsStringArray; class nsICaret; class nsIStyleContext; +#ifndef NEW_CLIPBOARD_SUPPORT class nsISelectionMgr; +#endif #define NS_IPRESSHELL_IID \ { 0x76e79c60, 0x944e, 0x11d1, \ @@ -261,7 +263,11 @@ public: /** * Notify the SelectionMgr that we have something to copy. */ +#ifndef NEW_CLIPBOARD_SUPPORT NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr) = 0; +#else + NS_IMETHOD DoCopy() = 0; +#endif /** * Get the caret, if it exists. AddRefs it. diff --git a/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index e2e201ba97a1..87497ad16002 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/layout/html/base/src/nsPresShell.cpp @@ -326,7 +326,12 @@ public: PRUint32 aVFlags, PRInt32 aHOffsetPercent, PRUint32 aHFlags) const; + +#ifdef NEW_CLIPBOARD_SUPPORT + NS_IMETHOD DoCopy(); +#else NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr); +#endif //nsIViewObserver interface @@ -1542,6 +1547,83 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame, return rv; } + + + +#ifdef NEW_CLIPBOARD_SUPPORT +// New way +NS_IMETHODIMP +PresShell::DoCopy() +{ + nsCOMPtr doc; + GetDocument(getter_AddRefs(doc)); + if (doc) { + nsString buffer; + + nsIDOMSelection* sel = nsnull; + GetSelection(&sel); + + if (sel != nsnull) + doc->CreateXIF(buffer,sel); + NS_IF_RELEASE(sel); + + // Get the Clipboard + nsIClipboard* clipboard; + nsresult rv = nsServiceManager::GetService(kCClipboardCID, + kIClipboardIID, + (nsISupports **)&clipboard); + + if (NS_OK == rv) { + + // Create a data flavor to tell the transferable + // that it is about to receive XIF + nsIDataFlavor * flavor; + rv = nsComponentManager::CreateInstance(kCDataFlavorCID, + nsnull, + kIDataFlavorIID, (void**) &flavor); + if (NS_OK == rv) { + // Initialize data flavor to XIF + flavor->Init(kXIFMime, "XIF"); + + // Create a transferable for putting data on the Clipboard + nsITransferable * trans; + rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, + kITransferableIID, (void**) &trans); + if (NS_OK == rv) { + // The data on the clipboard will be in "XIF" format + // so give the clipboard transferable a "XIFConverter" for + // converting from XIF to other formats + nsIFormatConverter * xifConverter; + rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull, + kIFormatConverterIID, (void**) &xifConverter); + if (NS_OK == rv) { + // Add the XIF DataFlavor to the transferable + // this tells the transferable that it can handle receiving the XIF format + trans->AddDataFlavor(flavor); + + // Add the converter for going from XIF to other formats + trans->SetConverter(xifConverter); + + // Now add the XIF data to the transferable + trans->SetTransferData(flavor, buffer.ToNewCString(), buffer.Length()); + + // put the transferable on the clipboard + clipboard->SetData(trans, nsnull); + + NS_IF_RELEASE(xifConverter); + } + NS_IF_RELEASE(trans); + } + NS_IF_RELEASE(flavor); + } + NS_IF_RELEASE(clipboard); + } + } + return NS_OK; +} +#else + +// Old SelectionMgr implementation. NS_IMETHODIMP PresShell::DoCopy(nsISelectionMgr* aSelectionMgr) { @@ -1557,8 +1639,6 @@ PresShell::DoCopy(nsISelectionMgr* aSelectionMgr) doc->CreateXIF(buffer,sel); NS_IF_RELEASE(sel); -////////////////////////// Old Way -#ifndef NEW_CLIPBOARD_SUPPORT nsIParser* parser; static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); @@ -1605,61 +1685,13 @@ PresShell::DoCopy(nsISelectionMgr* aSelectionMgr) NS_IF_RELEASE(sink); NS_RELEASE(parser); -#else /////////////////////////// New Way - // Put XIF into transferable - - // Get the Clipboard - nsIClipboard* clipboard; - nsresult rv = nsServiceManager::GetService(kCClipboardCID, - kIClipboardIID, - (nsISupports **)&clipboard); - - if (NS_OK == rv) { - - // Create a data flavor to tell the transferable - // that it is about to receive XIF - nsIDataFlavor * flavor; - rv = nsComponentManager::CreateInstance(kCDataFlavorCID, nsnull, kIDataFlavorIID, (void**) &flavor); - if (NS_OK == rv) { - // Initialize data flavor to XIF - flavor->Init(kXIFMime, "XIF"); - - // Create a transferable for putting data on the Clipboard - nsITransferable * trans; - rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, kITransferableIID, (void**) &trans); - if (NS_OK == rv) { - // The data on the clipboard will be in "XIF" format - // so give the clipboard transferable a "XIFConverter" for - // converting from XIF to other formats - nsIFormatConverter * xifConverter; - rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull, kIFormatConverterIID, (void**) &xifConverter); - if (NS_OK == rv) { - // Add the XIF DataFlavor to the transferable - // this tells the transferable that it can handle receiving the XIF format - trans->AddDataFlavor(flavor); - - // Add the converter for going from XIF to other formats - trans->SetConverter(xifConverter); - - // Now add the XIF data to the transferable - trans->SetTransferData(flavor, buffer.ToNewCString(), buffer.Length()); - - // put the transferable on the clipboard - clipboard->SetData(trans, nsnull); - - NS_IF_RELEASE(xifConverter); - } - NS_IF_RELEASE(trans); - } - NS_IF_RELEASE(flavor); - } - NS_IF_RELEASE(clipboard); - } -#endif } return NS_OK; } +#endif // NEW_CLIPBOARD_SUPPORT + + NS_IMETHODIMP PresShell::ContentChanged(nsIDocument *aDocument, nsIContent* aContent, diff --git a/xpfe/AppCores/src/nsBrowserAppCore.cpp b/xpfe/AppCores/src/nsBrowserAppCore.cpp index bacdefbd990b..19cd1a923489 100644 --- a/xpfe/AppCores/src/nsBrowserAppCore.cpp +++ b/xpfe/AppCores/src/nsBrowserAppCore.cpp @@ -929,7 +929,7 @@ nsBrowserAppCore::Copy() #ifdef NEW_CLIPBOARD_SUPPORT nsIPresShell * presShell = GetPresShellFor(mContentAreaWebShell); if (nsnull != presShell) { - presShell->DoCopy(nsnull); + presShell->DoCopy(); } #endif