Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/editor/libeditor/PlaceholderTransaction.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef PlaceholderTransaction_h
7
#define PlaceholderTransaction_h
8
9
#include "EditAggregateTransaction.h"
10
#include "mozilla/EditorUtils.h"
11
#include "mozilla/Maybe.h"
12
#include "nsIAbsorbingTransaction.h"
13
#include "nsCOMPtr.h"
14
#include "nsWeakPtr.h"
15
16
namespace mozilla {
17
18
class CompositionTransaction;
19
20
/**
21
 * An aggregate transaction that knows how to absorb all subsequent
22
 * transactions with the same name.  This transaction does not "Do" anything.
23
 * But it absorbs other transactions via merge, and can undo/redo the
24
 * transactions it has absorbed.
25
 */
26
27
class PlaceholderTransaction final
28
 : public EditAggregateTransaction
29
 , public nsIAbsorbingTransaction
30
{
31
protected:
32
  PlaceholderTransaction(EditorBase& aEditorBase,
33
                         nsAtom* aName,
34
                         Maybe<SelectionState>&& aSelState);
35
36
public:
37
  /**
38
   * Creates a placeholder transaction.  This never returns nullptr.
39
   *
40
   * @param aEditorBase     The editor.
41
   * @param aName           The name of creating transaction.
42
   * @param aSelState       The selection state of aEditorBase.
43
   */
44
  static already_AddRefed<PlaceholderTransaction>
45
  Create(EditorBase& aEditorBase,
46
         nsAtom* aName,
47
         Maybe<SelectionState>&& aSelState)
48
0
  {
49
0
    // Make sure to move aSelState into a local variable to null out the original
50
0
    // Maybe<SelectionState> variable.
51
0
    Maybe<SelectionState> selState(std::move(aSelState));
52
0
    RefPtr<PlaceholderTransaction> transaction =
53
0
      new PlaceholderTransaction(aEditorBase, aName, std::move(selState));
54
0
    return transaction.forget();
55
0
  }
56
57
  NS_DECL_ISUPPORTS_INHERITED
58
59
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTransaction,
60
                                           EditAggregateTransaction)
61
// ------------ EditAggregateTransaction -----------------------
62
63
  NS_DECL_EDITTRANSACTIONBASE
64
65
  NS_IMETHOD RedoTransaction() override;
66
  NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
67
68
// ------------ nsIAbsorbingTransaction -----------------------
69
70
  NS_IMETHOD GetTxnName(nsAtom** aName) override;
71
72
  NS_IMETHOD StartSelectionEquals(SelectionState* aSelState,
73
                                  bool* aResult) override;
74
75
  NS_IMETHOD EndPlaceHolderBatch() override;
76
77
  NS_IMETHOD ForwardEndBatchTo(
78
               nsIAbsorbingTransaction* aForwardingAddress) override;
79
80
  NS_IMETHOD Commit() override;
81
82
  NS_IMETHOD_(PlaceholderTransaction*) AsPlaceholderTransaction() override
83
0
  {
84
0
    return this;
85
0
  }
86
87
  nsresult RememberEndingSelection();
88
89
protected:
90
  virtual ~PlaceholderTransaction();
91
92
  // The editor for this transaction.
93
  RefPtr<EditorBase> mEditorBase;
94
95
  nsWeakPtr mForwarding;
96
  // First IME txn in this placeholder - used for IME merging.
97
  mozilla::CompositionTransaction* mCompositionTransaction;
98
99
  // These next two members store the state of the selection in a safe way.
100
  // Selection at the start of the transaction is stored, as is the selection
101
  // at the end.  This is so that UndoTransaction() and RedoTransaction() can
102
  // restore the selection properly.
103
104
  SelectionState mStartSel;
105
  SelectionState mEndSel;
106
107
  // Do we auto absorb any and all transaction?
108
  bool mAbsorb;
109
  // Do we stop auto absorbing any matching placeholder transactions?
110
  bool mCommitted;
111
};
112
113
} // namespace mozilla
114
115
#endif // #ifndef PlaceholderTransaction_h