Update configs. IGNORE BROKEN CHANGESETS CLOSED TREE NO BUG a=release ba=release
[gecko.git] / layout / generic / AutoCopyListener.h
blobab6889bb068fb6771b5d95068609e41a22fd687d
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/Maybe.h"
12 #include "mozilla/dom/Selection.h"
13 #include "mozilla/StaticPrefs_clipboard.h"
14 #include "nsIClipboard.h"
16 namespace mozilla {
18 class AutoCopyListener final {
19 public:
20 /**
21 * OnSelectionChange() is called when a Selection whose NotifyAutoCopy() was
22 * called is changed.
24 * @param aDocument The document of the Selection. May be nullptr.
25 * @param aSelection The selection.
26 * @param aReason The reasons of the change.
27 * See nsISelectionListener::*_REASON.
29 static void OnSelectionChange(dom::Document* aDocument,
30 dom::Selection& aSelection, int16_t aReason);
32 /**
33 * IsEnabled() returns true if the auto-copy feature is enabled.
35 static bool IsEnabled() {
36 #ifdef XP_MACOSX
37 return true;
38 #else
39 return StaticPrefs::clipboard_autocopy();
40 #endif
43 private:
44 #ifdef XP_MACOSX
45 // On macOS, cache the current selection to send to service menu of macOS.
46 static const nsIClipboard::ClipboardType sClipboardID =
47 nsIClipboard::kSelectionCache;
48 #else
49 // Make the normal Selection notifies auto-copy listener of its changes.
50 static const nsIClipboard::ClipboardType sClipboardID =
51 nsIClipboard::kSelectionClipboard;
52 #endif
55 } // namespace mozilla
57 #endif // #ifndef mozilla_AutoCopyListener_h