1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_AutoCopyListener_h
8 #define mozilla_AutoCopyListener_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/Selection.h"
12 #include "mozilla/StaticPrefs_clipboard.h"
13 #include "nsIClipboard.h"
17 class AutoCopyListener final
{
20 * OnSelectionChange() is called when a Selection whose NotifyAutoCopy() was
23 * @param aDocument The document of the Selection. May be nullptr.
24 * @param aSelection The selection.
25 * @param aReason The reasons of the change.
26 * See nsISelectionListener::*_REASON.
28 static void OnSelectionChange(dom::Document
* aDocument
,
29 dom::Selection
& aSelection
, int16_t aReason
);
32 * Init() initializes all static members of this class. Should be called
35 static void Init(int16_t aClipboardID
) {
36 MOZ_ASSERT(IsValidClipboardID(aClipboardID
));
37 static bool sInitialized
= false;
38 if (!sInitialized
&& IsValidClipboardID(aClipboardID
)) {
39 sClipboardID
= aClipboardID
;
45 * IsPrefEnabled() returns true if the pref enables auto-copy feature.
47 static bool IsPrefEnabled() { return StaticPrefs::clipboard_autocopy(); }
50 static bool IsValidClipboardID(int16_t aClipboardID
) {
51 return aClipboardID
>= nsIClipboard::kSelectionClipboard
&&
52 aClipboardID
<= nsIClipboard::kSelectionCache
;
55 static int16_t sClipboardID
;
58 } // namespace mozilla
60 #endif // #ifndef mozilla_AutoCopyListener_h