Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/editor/libeditor/DeleteRangeTransaction.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 DeleteRangeTransaction_h
7
#define DeleteRangeTransaction_h
8
9
#include "EditAggregateTransaction.h"
10
#include "mozilla/RangeBoundary.h"
11
#include "nsCycleCollectionParticipant.h"
12
#include "nsID.h"
13
#include "nsIEditor.h"
14
#include "nsISupportsImpl.h"
15
#include "nsRange.h"
16
#include "nscore.h"
17
18
class nsINode;
19
20
namespace mozilla {
21
22
class EditorBase;
23
class RangeUpdater;
24
25
/**
26
 * A transaction that deletes an entire range in the content tree
27
 */
28
class DeleteRangeTransaction final : public EditAggregateTransaction
29
{
30
protected:
31
  DeleteRangeTransaction(EditorBase& aEditorBase,
32
                         nsRange& aRangeToDelete);
33
34
public:
35
  /**
36
   * Creates a delete range transaction.  This never returns nullptr.
37
   *
38
   * @param aEditorBase         The object providing basic editing operations.
39
   * @param aRangeToDelete      The range to delete.
40
   */
41
  static already_AddRefed<DeleteRangeTransaction>
42
  Create(EditorBase& aEditorBase,
43
         nsRange& aRangeToDelete)
44
0
  {
45
0
    RefPtr<DeleteRangeTransaction> transaction =
46
0
      new DeleteRangeTransaction(aEditorBase, aRangeToDelete);
47
0
    return transaction.forget();
48
0
  }
49
50
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteRangeTransaction,
51
                                           EditAggregateTransaction)
52
  NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
53
54
  NS_DECL_EDITTRANSACTIONBASE
55
56
  NS_IMETHOD RedoTransaction() override;
57
58
protected:
59
  /**
60
   * CreateTxnsToDeleteBetween() creates a DeleteTextTransaction or some
61
   * DeleteNodeTransactions to remove text or nodes between aStart and aEnd
62
   * and appends the created transactions to the array.
63
   *
64
   * @param aStart      Must be set and valid point.
65
   * @param aEnd        Must be set and valid point.  Additionally, the
66
   *                    container must be same as aStart's container.
67
   *                    And of course, this must not be before aStart in
68
   *                    the DOM tree order.
69
   * @return            Returns NS_OK in most cases.
70
   *                    When the arguments are invalid, returns
71
   *                    NS_ERROR_INVALID_ARG.
72
   *                    When mEditorBase isn't available, returns
73
   *                    NS_ERROR_NOT_AVAIALBLE.
74
   *                    When created DeleteTextTransaction cannot do its
75
   *                    transaction, returns NS_ERROR_FAILURE.
76
   *                    Note that even if one of created DeleteNodeTransaction
77
   *                    cannot do its transaction, this returns NS_OK.
78
   */
79
  nsresult CreateTxnsToDeleteBetween(const RawRangeBoundary& aStart,
80
                                     const RawRangeBoundary& aEnd);
81
82
  nsresult CreateTxnsToDeleteNodesBetween(nsRange* aRangeToDelete);
83
84
  /**
85
   * CreateTxnsToDeleteContent() creates a DeleteTextTransaction to delete
86
   * text between start of aPoint.GetContainer() and aPoint or aPoint and end of
87
   * aPoint.GetContainer() and appends the created transaction to the array.
88
   *
89
   * @param aPoint      Must be set and valid point.  If the container is not
90
   *                    a data node, this method does nothing.
91
   * @param aAction     If nsIEditor::eNext, this method creates a transaction
92
   *                    to delete text from aPoint to the end of the data node.
93
   *                    Otherwise, this method creates a transaction to delete
94
   *                    text from start of the data node to aPoint.
95
   * @return            Returns NS_OK in most cases.
96
   *                    When the arguments are invalid, returns
97
   *                    NS_ERROR_INVALID_ARG.
98
   *                    When mEditorBase isn't available, returns
99
   *                    NS_ERROR_NOT_AVAIALBLE.
100
   *                    When created DeleteTextTransaction cannot do its
101
   *                    transaction, returns NS_ERROR_FAILURE.
102
   *                    Note that even if no character will be deleted,
103
   *                    this returns NS_OK.
104
   */
105
  nsresult CreateTxnsToDeleteContent(const RawRangeBoundary& aPoint,
106
                                     nsIEditor::EDirection aAction);
107
108
  // The editor for this transaction.
109
  RefPtr<EditorBase> mEditorBase;
110
111
  // P1 in the range.  This is only non-null until DoTransaction is called and
112
  // we convert it into child transactions.
113
  RefPtr<nsRange> mRangeToDelete;
114
};
115
116
} // namespace mozilla
117
118
#endif // #ifndef DeleteRangeTransaction_h