tor-browser

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

AutoSelectionRestorer.cpp (1174B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "AutoSelectionRestorer.h"
      7 
      8 namespace mozilla {
      9 
     10 AutoSelectionRestorer::AutoSelectionRestorer(EditorBase* aEditor) {
     11  if (!aEditor) {
     12    return;
     13  }
     14  if (aEditor->ArePreservingSelection()) {
     15    // We already have initialized mParentData::mSavedSelection, so this must
     16    // be nested call.
     17    return;
     18  }
     19  MOZ_ASSERT(aEditor->IsEditActionDataAvailable());
     20  mEditor = aEditor;
     21  mEditor->PreserveSelectionAcrossActions();
     22 }
     23 
     24 AutoSelectionRestorer::~AutoSelectionRestorer() {
     25  if (!mEditor || !mEditor->ArePreservingSelection()) {
     26    return;
     27  }
     28  DebugOnly<nsresult> rvIgnored = mEditor->RestorePreservedSelection();
     29  NS_WARNING_ASSERTION(
     30      NS_SUCCEEDED(rvIgnored),
     31      "EditorBase::RestorePreservedSelection() failed, but ignored");
     32 }
     33 
     34 void AutoSelectionRestorer::Abort() {
     35  if (mEditor) {
     36    mEditor->StopPreservingSelection();
     37  }
     38 }
     39 
     40 }  // namespace mozilla