Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/editor/libeditor/DeleteTextTransaction.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 DeleteTextTransaction_h
7
#define DeleteTextTransaction_h
8
9
#include "mozilla/EditTransactionBase.h"
10
#include "mozilla/dom/CharacterData.h"
11
#include "nsCOMPtr.h"
12
#include "nsCycleCollectionParticipant.h"
13
#include "nsID.h"
14
#include "nsString.h"
15
#include "nscore.h"
16
17
namespace mozilla {
18
19
class EditorBase;
20
class RangeUpdater;
21
22
/**
23
 * A transaction that removes text from a content node.
24
 */
25
class DeleteTextTransaction final : public EditTransactionBase
26
{
27
protected:
28
  DeleteTextTransaction(EditorBase& aEditorBase,
29
                        dom::CharacterData& aCharData,
30
                        uint32_t aOffset,
31
                        uint32_t aLengthToDelete);
32
33
public:
34
35
  /**
36
   * Creates a delete text transaction to remove given range.  This returns
37
   * nullptr if it cannot modify the text node.
38
   *
39
   * @param aEditorBase         The provider of basic editing operations.
40
   * @param aCharData           The content node to remove text from.
41
   * @param aOffset             The location in aElement to begin the deletion.
42
   * @param aLenthToDelete      The length to delete.
43
   */
44
  static already_AddRefed<DeleteTextTransaction>
45
  MaybeCreate(EditorBase& aEditorBase,
46
              dom::CharacterData& aCharData,
47
              uint32_t aOffset,
48
              uint32_t aLengthToDelete);
49
50
  /**
51
   * Creates a delete text transaction to remove a previous or next character.
52
   * Those methods MAY return nullptr.
53
   *
54
   * @param aEditorBase         The provider of basic editing operations.
55
   * @param aCharData           The content node to remove text from.
56
   * @param aOffset             The location in aElement to begin the deletion.
57
   */
58
  static already_AddRefed<DeleteTextTransaction>
59
  MaybeCreateForPreviousCharacter(EditorBase& aEditorBase,
60
                                  dom::CharacterData& aCharData,
61
                                  uint32_t aOffset);
62
  static already_AddRefed<DeleteTextTransaction>
63
  MaybeCreateForNextCharacter(EditorBase& aEditorBase,
64
                              dom::CharacterData& aCharData,
65
                              uint32_t aOffset);
66
67
  /**
68
   * CanDoIt() returns true if there are enough members and can modify the
69
   * text.  Otherwise, false.
70
   */
71
  bool CanDoIt() const;
72
73
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteTextTransaction,
74
                                           EditTransactionBase)
75
  NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
76
77
  NS_DECL_EDITTRANSACTIONBASE
78
79
0
  uint32_t Offset() { return mOffset; }
80
81
0
  uint32_t LengthToDelete() { return mLengthToDelete; }
82
83
protected:
84
  // The provider of basic editing operations.
85
  RefPtr<EditorBase> mEditorBase;
86
87
  // The CharacterData node to operate upon.
88
  RefPtr<dom::CharacterData> mCharData;
89
90
  // The offset into mCharData where the deletion is to take place.
91
  uint32_t mOffset;
92
93
  // The length to delete.
94
  uint32_t mLengthToDelete;
95
96
  // The text that was deleted.
97
  nsString mDeletedText;
98
};
99
100
} // namespace mozilla
101
102
#endif // #ifndef DeleteTextTransaction_h