Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / layout / generic / AutoCopyListener.h
blobacb0aaa46d044f848b545d0ca072755702622423
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"
15 namespace mozilla {
17 class AutoCopyListener final {
18 public:
19 /**
20 * OnSelectionChange() is called when a Selection whose NotifyAutoCopy() was
21 * called is changed.
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);
31 /**
32 * Init() initializes all static members of this class. Should be called
33 * only once.
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;
40 sInitialized = true;
44 /**
45 * IsPrefEnabled() returns true if the pref enables auto-copy feature.
47 static bool IsPrefEnabled() { return StaticPrefs::clipboard_autocopy(); }
49 private:
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