tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AutoCopyListener.h (1741B)


      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/. */
      6 
      7 #ifndef mozilla_AutoCopyListener_h
      8 #define mozilla_AutoCopyListener_h
      9 
     10 #include "mozilla/StaticPrefs_clipboard.h"
     11 #include "mozilla/dom/Selection.h"
     12 #include "nsIClipboard.h"
     13 
     14 namespace mozilla {
     15 
     16 class AutoCopyListener final {
     17 public:
     18  /**
     19   * OnSelectionChange() is called when a Selection whose NotifyAutoCopy() was
     20   * called is changed.
     21   *
     22   * @param aDocument           The document of the Selection.  May be nullptr.
     23   * @param aSelection          The selection.
     24   * @param aReason             The reasons of the change.
     25   *                            See nsISelectionListener::*_REASON.
     26   */
     27  static void OnSelectionChange(dom::Document* aDocument,
     28                                dom::Selection& aSelection, int16_t aReason);
     29 
     30  /**
     31   * IsEnabled() returns true if the auto-copy feature is enabled.
     32   */
     33  static bool IsEnabled() {
     34 #ifdef XP_MACOSX
     35    return true;
     36 #else
     37    return StaticPrefs::clipboard_autocopy();
     38 #endif
     39  }
     40 
     41 private:
     42 #ifdef XP_MACOSX
     43  // On macOS, cache the current selection to send to service menu of macOS.
     44  static const nsIClipboard::ClipboardType sClipboardID =
     45      nsIClipboard::kSelectionCache;
     46 #else
     47  // Make the normal Selection notifies auto-copy listener of its changes.
     48  static const nsIClipboard::ClipboardType sClipboardID =
     49      nsIClipboard::kSelectionClipboard;
     50 #endif
     51 };
     52 
     53 }  // namespace mozilla
     54 
     55 #endif  // #ifndef mozilla_AutoCopyListener_h