diff --git a/mozilla/accessible/src/base/nsCaretAccessible.cpp b/mozilla/accessible/src/base/nsCaretAccessible.cpp index 9c7a467624b..6e8c7151b9b 100644 --- a/mozilla/accessible/src/base/nsCaretAccessible.cpp +++ b/mozilla/accessible/src/base/nsCaretAccessible.cpp @@ -127,7 +127,7 @@ NS_IMETHODIMP nsCaretAccessible::AttachNewSelectionListener(nsIDOMNode *aCurrent return selPrivate->AddSelectionListener(this); } -NS_IMETHODIMP nsCaretAccessible::NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, short aReason) +NS_IMETHODIMP nsCaretAccessible::NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, PRInt16 aReason) { #ifdef MOZ_ACCESSIBILITY_ATK if (nsAccessibleText::gSuppressedNotifySelectionChanged) diff --git a/mozilla/accessible/src/base/nsCaretAccessible.h b/mozilla/accessible/src/base/nsCaretAccessible.h index a13a3800374..25c1599d709 100644 --- a/mozilla/accessible/src/base/nsCaretAccessible.h +++ b/mozilla/accessible/src/base/nsCaretAccessible.h @@ -76,7 +76,7 @@ public: NS_IMETHOD RemoveSelectionListener(); /* ----- nsISelectionListener ---- */ - NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, short aReason); + NS_DECL_NSISELECTIONLISTENER /* ----- nsIAccessNode ----- */ NS_IMETHOD Shutdown(); diff --git a/mozilla/editor/composer/src/nsComposerCommandsUpdater.cpp b/mozilla/editor/composer/src/nsComposerCommandsUpdater.cpp index f7c642078e9..d886290eb03 100644 --- a/mozilla/editor/composer/src/nsComposerCommandsUpdater.cpp +++ b/mozilla/editor/composer/src/nsComposerCommandsUpdater.cpp @@ -112,7 +112,7 @@ nsComposerCommandsUpdater::NotifyDocumentStateChanged(PRBool aNowDirty) NS_IMETHODIMP nsComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument *, - nsISelection *, short) + nsISelection *, PRInt16) { return PrimeUpdateTimer(); } diff --git a/mozilla/editor/libeditor/html/TypeInState.cpp b/mozilla/editor/libeditor/html/TypeInState.cpp index ed27e0cf87b..d83fdf63867 100644 --- a/mozilla/editor/libeditor/html/TypeInState.cpp +++ b/mozilla/editor/libeditor/html/TypeInState.cpp @@ -84,7 +84,7 @@ nsresult TypeInState::UpdateSelState(nsISelection *aSelection) } -NS_IMETHODIMP TypeInState::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aSelection, short) +NS_IMETHODIMP TypeInState::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aSelection, PRInt16) { // XXX: Selection currently generates bogus selection changed notifications // XXX: (bug 140303). It can notify us when the selection hasn't actually diff --git a/mozilla/editor/libeditor/html/TypeInState.h b/mozilla/editor/libeditor/html/TypeInState.h index a69d0135c55..ae2f7bd08d8 100644 --- a/mozilla/editor/libeditor/html/TypeInState.h +++ b/mozilla/editor/libeditor/html/TypeInState.h @@ -68,7 +68,9 @@ public: virtual ~TypeInState(); nsresult UpdateSelState(nsISelection *aSelection); - NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, short aReason); + + // nsISelectionListener + NS_DECL_NSISELECTIONLISTENER nsresult SetProp(nsIAtom *aProp); nsresult SetProp(nsIAtom *aProp, const nsString &aAttr); diff --git a/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp b/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp index e23baa8b6db..ecafdcd9849 100644 --- a/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp @@ -111,7 +111,7 @@ ResizerSelectionListener::~ResizerSelectionListener() } NS_IMETHODIMP -ResizerSelectionListener::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aSelection,short aReason) +ResizerSelectionListener::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aSelection, PRInt16 aReason) { if ((aReason & (nsISelectionListener::MOUSEDOWN_REASON | nsISelectionListener::KEYPRESS_REASON | diff --git a/mozilla/extensions/typeaheadfind/src/nsTypeAheadFind.cpp b/mozilla/extensions/typeaheadfind/src/nsTypeAheadFind.cpp index f55eea3f69b..6f84432b86d 100644 --- a/mozilla/extensions/typeaheadfind/src/nsTypeAheadFind.cpp +++ b/mozilla/extensions/typeaheadfind/src/nsTypeAheadFind.cpp @@ -1694,7 +1694,7 @@ nsTypeAheadFind::ScrollPositionDidChange(nsIScrollableView *aScrollableView, NS_IMETHODIMP nsTypeAheadFind::NotifySelectionChanged(nsIDOMDocument *aDoc, - nsISelection *aSel, short aReason) + nsISelection *aSel, PRInt16 aReason) { if (!mIsFindingText) { if (mRepeatingMode != eRepeatingNone) { diff --git a/mozilla/layout/base/Makefile.in b/mozilla/layout/base/Makefile.in index 921aef401e7..bc2c872d92d 100644 --- a/mozilla/layout/base/Makefile.in +++ b/mozilla/layout/base/Makefile.in @@ -92,7 +92,6 @@ EXPORTS = \ nsFrameManager.h \ nsFrameManagerBase.h \ nsFrameTraversal.h \ - nsIAutoCopy.h \ nsICaret.h \ nsIDocumentViewer.h \ nsIFrameSelection.h \ @@ -114,7 +113,6 @@ EXPORTS = \ $(NULL) CPPSRCS = \ - nsAutoCopy.cpp \ nsBidiUtils.cpp \ nsCSSColorUtils.cpp \ nsCSSFrameConstructor.cpp \ diff --git a/mozilla/layout/base/nsAutoCopy.cpp b/mozilla/layout/base/nsAutoCopy.cpp deleted file mode 100644 index 8094000e1a0..00000000000 --- a/mozilla/layout/base/nsAutoCopy.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * shaver@mozilla.org - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsCOMPtr.h" -#include "nsIServiceManager.h" - -#include "nsIAutoCopy.h" -#include "nsISelection.h" -#include "nsISelectionPrivate.h" -#include "nsISelectionListener.h" -#include "nsIDOMDocument.h" -#include "nsCopySupport.h" -#include "nsIClipboard.h" - -#include "nsIDocument.h" -#include "nsSupportsPrimitives.h" - -class nsAutoCopyService : public nsIAutoCopyService , public nsISelectionListener -{ -public: - NS_DECL_ISUPPORTS - - nsAutoCopyService(); - virtual ~nsAutoCopyService(){}//someday maybe we have it able to shutdown during run - - //nsIAutoCopyService interfaces - NS_IMETHOD Listen(nsISelection *aDomSelection); - //end nsIAutoCopyService - - //nsISelectionListener interfaces - NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, short aReason); - //end nsISelectionListener -}; - -// Implement our nsISupports methods -NS_IMPL_ISUPPORTS2(nsAutoCopyService, nsIAutoCopyService,nsISelectionListener) - -nsresult -NS_NewAutoCopyService(nsIAutoCopyService** aResult) -{ - *aResult = new nsAutoCopyService; - if (!*aResult) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(*aResult); - return NS_OK; -} - -nsAutoCopyService::nsAutoCopyService() -{ -} - -NS_IMETHODIMP -nsAutoCopyService::Listen(nsISelection *aDomSelection) -{ - if (!aDomSelection) - return NS_ERROR_NULL_POINTER; - nsCOMPtr selection(aDomSelection); - nsCOMPtr selectionPrivate(do_QueryInterface(selection)); - return selectionPrivate->AddSelectionListener(this); -} - - -/* - * What we do now: - * On every selection change, we copy to the clipboard anew, creating a - * HTML buffer, a transferable, an nsISupportsString and - * a huge mess every time. This is basically what nsPresShell::DoCopy does - * to move the selection into the clipboard for Edit->Copy. - * - * What we should do, to make our end of the deal faster: - * Create a singleton transferable with our own magic converter. When selection - * changes (use a quick cache to detect ``real'' changes), we put the new - * nsISelection in the transferable. Our magic converter will take care of - * transferable->whatever-other-format when the time comes to actually - * hand over the clipboard contents. - * - * Other issues: - * - which X clipboard should we populate? - * - should we use a different one than Edit->Copy, so that inadvertant - * selections (or simple clicks, which currently cause a selection - * notification, regardless of if they're in the document which currently has - * selection!) don't lose the contents of the ``application''? Or should we - * just put some intelligence in the ``is this a real selection?'' code to - * protect our selection against clicks in other documents that don't create - * selections? - * - maybe we should just never clear the X clipboard? That would make this - * problem just go away, which is very tempting. - */ - -#define DRAGGING 1 - -NS_IMETHODIMP -nsAutoCopyService::NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, short aReason) -{ - nsresult rv; - - if (!(aReason & nsISelectionListener::MOUSEUP_REASON || - aReason & nsISelectionListener::SELECTALL_REASON || - aReason & nsISelectionListener::KEYPRESS_REASON)) - return NS_OK; //dont care if we are still dragging - PRBool collapsed; - if (!aDoc || !aSel || NS_FAILED(aSel->GetIsCollapsed(&collapsed)) || collapsed) { -#ifdef DEBUG_CLIPBOARD - fprintf(stderr, "CLIPBOARD: no selection/collapsed selection\n"); -#endif - /* clear X clipboard? */ - return NS_OK; - } - - nsCOMPtr doc; - doc = do_QueryInterface(NS_REINTERPRET_CAST(nsISupports *,aDoc),&rv); - if (NS_FAILED(rv)) - return rv; - if (!doc) - return NS_ERROR_NULL_POINTER; - - // call the copy code - rv = nsCopySupport::HTMLCopy(aSel, doc, nsIClipboard::kSelectionClipboard); - return rv; -} - diff --git a/mozilla/layout/base/nsCaret.cpp b/mozilla/layout/base/nsCaret.cpp index f23dd449c40..3c409ede359 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -423,7 +423,7 @@ NS_IMETHODIMP nsCaret::DrawAtPosition(nsIDOMNode* aNode, PRInt32 aOffset) #endif //----------------------------------------------------------------------------- -NS_IMETHODIMP nsCaret::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aDomSel, short aReason) +NS_IMETHODIMP nsCaret::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aDomSel, PRInt16 aReason) { if (aReason & nsISelectionListener::MOUSEUP_REASON)//this wont do return NS_OK; diff --git a/mozilla/layout/base/nsCaret.h b/mozilla/layout/base/nsCaret.h index 79c522325d8..c8f766a75f1 100644 --- a/mozilla/layout/base/nsCaret.h +++ b/mozilla/layout/base/nsCaret.h @@ -81,7 +81,7 @@ class nsCaret : public nsICaret, NS_IMETHOD DrawAtPosition(nsIDOMNode* aNode, PRInt32 aOffset); //nsISelectionListener interface - NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, short aReason); + NS_DECL_NSISELECTIONLISTENER static void CaretBlinkCallback(nsITimer *aTimer, void *aClosure); diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index dcc93cd7df6..b71f3391b3a 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -2922,7 +2922,7 @@ NS_IMETHODIMP DocumentViewerImpl::GetInImage(PRBool* aInImage) return NS_OK; } -NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocument *, nsISelection *, short) +NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocument *, nsISelection *, PRInt16) { NS_ASSERTION(mDocViewer, "Should have doc viewer!"); diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index b1eb1ed4438..06145c61d9a 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -120,7 +120,6 @@ #include "nsTextTransformer.h" #include "nsIFrameTraversal.h" #include "nsISelectionImageService.h" -#include "nsIAutoCopy.h" #include "nsCSSLoader.h" #include "nsXULAtoms.h" #include "nsLayoutCID.h" @@ -148,6 +147,7 @@ #include "nsScriptNameSpaceManager.h" #include "nsIControllerContext.h" #include "nsDOMScriptObjectFactory.h" +#include "nsAutoCopyListener.h" class nsIDocumentLoaderFactory; @@ -436,6 +436,7 @@ Shutdown() nsDOMClassInfo::ShutDown(); nsTextControlFrame::ShutDown(); nsXBLWindowKeyHandler::ShutDown(); + nsAutoCopyListener::Shutdown(); } #ifdef NS_DEBUG @@ -460,7 +461,6 @@ nsresult NS_NewCanvasRenderingContext2D(nsICanvasRenderingContext2D** aResult); #endif nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult); -nsresult NS_NewAutoCopyService(nsIAutoCopyService** aResult); nsresult NS_NewSelectionImageService(nsISelectionImageService** aResult); nsresult NS_NewSelection(nsIFrameSelection** aResult); @@ -535,7 +535,6 @@ MAKE_CTOR(CreateNewCanvasBoxObject, nsIBoxObject, NS_NewCanvasBoxO MAKE_CTOR(CreateNewCanvasRenderingContext2D, nsICanvasRenderingContext2D, NS_NewCanvasRenderingContext2D) #endif #endif -MAKE_CTOR(CreateNewAutoCopyService, nsIAutoCopyService, NS_NewAutoCopyService) MAKE_CTOR(CreateSelectionImageService, nsISelectionImageService,NS_NewSelectionImageService) #ifdef MOZ_SVG #ifdef MOZ_SVG_RENDERER_GDIPLUS @@ -909,11 +908,6 @@ static const nsModuleComponentInfo gComponents[] = { #endif - { "AutoCopy Service", - NS_AUTOCOPYSERVICE_CID, - "@mozilla.org/autocopy;1", - CreateNewAutoCopyService }, - { "Namespace manager", NS_NAMESPACEMANAGER_CID, NS_NAMESPACEMANAGER_CONTRACTID, diff --git a/mozilla/layout/base/nsIAutoCopy.h b/mozilla/layout/generic/nsAutoCopyListener.h old mode 100644 new mode 100755 similarity index 71% rename from mozilla/layout/base/nsIAutoCopy.h rename to mozilla/layout/generic/nsAutoCopyListener.h index df619dddc19..1e3399d3d14 --- a/mozilla/layout/base/nsIAutoCopy.h +++ b/mozilla/layout/generic/nsAutoCopyListener.h @@ -35,30 +35,44 @@ * * ***** END LICENSE BLOCK ***** */ +#ifndef nsAutoCopyListener_h_ +#define nsAutoCopyListener_h_ -#include "nsISupports.h" +#include "nsISelectionListener.h" +#include "nsISelectionPrivate.h" - -#ifndef nsIAutoCopyService_h__ -#define nsIAutoCopyService_h__ - -// {558B93CD-95C1-417d-A66E-F9CA66DC98A8} -#define NS_IAUTOCOPYSERVICE_IID \ -{ 0x558b93cd, 0x95c1, 0x417d, { 0xa6, 0x6e, 0xf9, 0xca, 0x66, 0xdc, 0x98, 0xa8 } } - - -class nsISelection; - -class nsIAutoCopyService : public nsISupports +class nsAutoCopyListener : public nsISelectionListener { public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IAUTOCOPYSERVICE_IID) - - //This will add this service as a selection listener. - NS_IMETHOD Listen(nsISelection *aDomSelection)=0; + NS_DECL_ISUPPORTS + NS_DECL_NSISELECTIONLISTENER + void Listen(nsISelectionPrivate *aSelection) + { + NS_ASSERTION(aSelection, "Null selection passed to Listen()"); + aSelection->AddSelectionListener(this); + } + + static nsAutoCopyListener* GetInstance() + { + if (!sInstance) { + sInstance = new nsAutoCopyListener(); + if (!sInstance) + return nsnull; + + NS_ADDREF(sInstance); + } + + return sInstance; + } + + static void Shutdown() + { + NS_IF_RELEASE(sInstance); + } + +private: + static nsAutoCopyListener* sInstance; }; - -#endif //nsIAutoCopyService_h__ - +#endif diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index 349dff40e5e..aed8ddfaba3 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -93,7 +93,6 @@ static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID); #include "nsIDeviceContext.h" #include "nsITimer.h" #include "nsIServiceManager.h" -#include "nsIAutoCopy.h" #include "nsIEventQueue.h" #include "nsIEventQueueService.h" @@ -103,6 +102,9 @@ static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID); #include "nsISelectionController.h"//for the enums #include "nsHTMLAtoms.h" +#include "nsAutoCopyListener.h" +#include "nsCopySupport.h" +#include "nsIClipboard.h" #define STATUS_CHECK_RETURN_MACRO() {if (!mShell) return NS_ERROR_FAILURE;} @@ -915,14 +917,13 @@ nsSelection::nsSelection() // Check to see if the autocopy pref is enabled // and add the autocopy listener if it is if (nsContentUtils::GetBoolPref("clipboard.autocopy")) { - nsCOMPtr autoCopyService = - do_GetService("@mozilla.org/autocopy;1"); + nsAutoCopyListener *autoCopy = nsAutoCopyListener::GetInstance(); - if (autoCopyService) { + if (autoCopy) { PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); if (mDomSelections[index]) { - autoCopyService->Listen(mDomSelections[index]); + autoCopy->Listen(mDomSelections[index]); } } } @@ -7385,3 +7386,63 @@ nsTypedSelection::SelectionLanguageChange(PRBool aLangRTL) } return NS_OK; } + + +// nsAutoCopyListener + +nsAutoCopyListener* nsAutoCopyListener::sInstance = nsnull; + +NS_IMPL_ISUPPORTS1(nsAutoCopyListener, nsISelectionListener) + +/* + * What we do now: + * On every selection change, we copy to the clipboard anew, creating a + * HTML buffer, a transferable, an nsISupportsString and + * a huge mess every time. This is basically what nsPresShell::DoCopy does + * to move the selection into the clipboard for Edit->Copy. + * + * What we should do, to make our end of the deal faster: + * Create a singleton transferable with our own magic converter. When selection + * changes (use a quick cache to detect ``real'' changes), we put the new + * nsISelection in the transferable. Our magic converter will take care of + * transferable->whatever-other-format when the time comes to actually + * hand over the clipboard contents. + * + * Other issues: + * - which X clipboard should we populate? + * - should we use a different one than Edit->Copy, so that inadvertant + * selections (or simple clicks, which currently cause a selection + * notification, regardless of if they're in the document which currently has + * selection!) don't lose the contents of the ``application''? Or should we + * just put some intelligence in the ``is this a real selection?'' code to + * protect our selection against clicks in other documents that don't create + * selections? + * - maybe we should just never clear the X clipboard? That would make this + * problem just go away, which is very tempting. + */ + +NS_IMETHODIMP +nsAutoCopyListener::NotifySelectionChanged(nsIDOMDocument *aDoc, + nsISelection *aSel, PRInt16 aReason) +{ + if (!(aReason & nsISelectionListener::MOUSEUP_REASON || + aReason & nsISelectionListener::SELECTALL_REASON || + aReason & nsISelectionListener::KEYPRESS_REASON)) + return NS_OK; //dont care if we are still dragging + + PRBool collapsed; + if (!aDoc || !aSel || + NS_FAILED(aSel->GetIsCollapsed(&collapsed)) || collapsed) { +#ifdef DEBUG_CLIPBOARD + fprintf(stderr, "CLIPBOARD: no selection/collapsed selection\n"); +#endif + /* clear X clipboard? */ + return NS_OK; + } + + nsCOMPtr doc = do_QueryInterface(aDoc); + NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); + + // call the copy code + return nsCopySupport::HTMLCopy(aSel, doc, nsIClipboard::kSelectionClipboard); +}