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"
18 class AutoCopyListener final
{
21 * OnSelectionChange() is called when a Selection whose NotifyAutoCopy() was
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
);
33 * IsEnabled() returns true if the auto-copy feature is enabled.
35 static bool IsEnabled() {
39 return StaticPrefs::clipboard_autocopy();
45 // On macOS, cache the current selection to send to service menu of macOS.
46 static const nsIClipboard::ClipboardType sClipboardID
=
47 nsIClipboard::kSelectionCache
;
49 // Make the normal Selection notifies auto-copy listener of its changes.
50 static const nsIClipboard::ClipboardType sClipboardID
=
51 nsIClipboard::kSelectionClipboard
;
55 } // namespace mozilla
57 #endif // #ifndef mozilla_AutoCopyListener_h