Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef nsAutoCopyListener_h_
7 : #define nsAutoCopyListener_h_
8 :
9 : #include "nsISelectionListener.h"
10 : #include "nsISelectionPrivate.h"
11 : #include "mozilla/Attributes.h"
12 :
13 : class nsAutoCopyListener final : public nsISelectionListener
14 : {
15 : public:
16 : NS_DECL_ISUPPORTS
17 : NS_DECL_NSISELECTIONLISTENER
18 :
19 2 : explicit nsAutoCopyListener(int16_t aClipboardID)
20 2 : : mCachedClipboard(aClipboardID)
21 2 : {}
22 :
23 32 : void Listen(nsISelectionPrivate *aSelection)
24 : {
25 32 : NS_ASSERTION(aSelection, "Null selection passed to Listen()");
26 32 : aSelection->AddSelectionListener(this);
27 32 : }
28 :
29 32 : static nsAutoCopyListener* GetInstance(int16_t aClipboardID)
30 : {
31 32 : if (!sInstance) {
32 2 : sInstance = new nsAutoCopyListener(aClipboardID);
33 :
34 2 : NS_ADDREF(sInstance);
35 : }
36 :
37 32 : return sInstance;
38 : }
39 :
40 0 : static void Shutdown()
41 : {
42 0 : NS_IF_RELEASE(sInstance);
43 0 : }
44 :
45 : private:
46 0 : ~nsAutoCopyListener() {}
47 :
48 : static nsAutoCopyListener* sInstance;
49 : int16_t mCachedClipboard;
50 : };
51 :
52 : #endif
|