2016-07-07 09:20:22 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef DeleteTextTransaction_h
|
|
|
|
#define DeleteTextTransaction_h
|
|
|
|
|
2016-07-08 08:03:31 +03:00
|
|
|
#include "mozilla/EditTransactionBase.h"
|
2018-03-19 22:18:07 +03:00
|
|
|
#include "mozilla/dom/CharacterData.h"
|
2016-07-07 09:20:22 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
class EditorBase;
|
2016-06-24 09:01:40 +03:00
|
|
|
class RangeUpdater;
|
|
|
|
|
2016-07-07 09:20:22 +03:00
|
|
|
/**
|
|
|
|
* A transaction that removes text from a content node.
|
|
|
|
*/
|
2016-07-08 03:48:34 +03:00
|
|
|
class DeleteTextTransaction final : public EditTransactionBase
|
2016-07-07 09:20:22 +03:00
|
|
|
{
|
2017-12-15 14:43:26 +03:00
|
|
|
protected:
|
|
|
|
DeleteTextTransaction(EditorBase& aEditorBase,
|
2018-03-19 22:18:06 +03:00
|
|
|
dom::CharacterData& aCharData,
|
2017-12-15 14:43:26 +03:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLengthToDelete);
|
|
|
|
|
2016-07-07 09:20:22 +03:00
|
|
|
public:
|
2017-12-15 14:43:26 +03:00
|
|
|
|
2016-07-07 09:20:22 +03:00
|
|
|
/**
|
2017-12-15 14:43:26 +03:00
|
|
|
* Creates a delete text transaction to remove given range. This returns
|
|
|
|
* nullptr if it cannot modify the text node.
|
|
|
|
*
|
2016-07-08 07:10:13 +03:00
|
|
|
* @param aEditorBase The provider of basic editing operations.
|
2017-12-15 14:43:26 +03:00
|
|
|
* @param aCharData The content node to remove text from.
|
2016-07-07 09:20:22 +03:00
|
|
|
* @param aOffset The location in aElement to begin the deletion.
|
2017-12-15 14:43:26 +03:00
|
|
|
* @param aLenthToDelete The length to delete.
|
2016-07-07 09:20:22 +03:00
|
|
|
*/
|
2017-12-15 14:43:26 +03:00
|
|
|
static already_AddRefed<DeleteTextTransaction>
|
|
|
|
MaybeCreate(EditorBase& aEditorBase,
|
2018-03-19 22:18:06 +03:00
|
|
|
dom::CharacterData& aCharData,
|
2017-12-15 14:43:26 +03:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLengthToDelete);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a delete text transaction to remove a previous or next character.
|
|
|
|
* Those methods MAY return nullptr.
|
|
|
|
*
|
|
|
|
* @param aEditorBase The provider of basic editing operations.
|
|
|
|
* @param aCharData The content node to remove text from.
|
|
|
|
* @param aOffset The location in aElement to begin the deletion.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<DeleteTextTransaction>
|
|
|
|
MaybeCreateForPreviousCharacter(EditorBase& aEditorBase,
|
2018-03-19 22:18:06 +03:00
|
|
|
dom::CharacterData& aCharData,
|
2017-12-15 14:43:26 +03:00
|
|
|
uint32_t aOffset);
|
|
|
|
static already_AddRefed<DeleteTextTransaction>
|
|
|
|
MaybeCreateForNextCharacter(EditorBase& aEditorBase,
|
2018-03-19 22:18:06 +03:00
|
|
|
dom::CharacterData& aCharData,
|
2017-12-15 14:43:26 +03:00
|
|
|
uint32_t aOffset);
|
2016-07-07 09:20:22 +03:00
|
|
|
|
2017-03-10 07:38:28 +03:00
|
|
|
/**
|
|
|
|
* CanDoIt() returns true if there are enough members and can modify the
|
|
|
|
* text. Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool CanDoIt() const;
|
2016-07-07 09:20:22 +03:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteTextTransaction,
|
|
|
|
EditTransactionBase)
|
2016-07-07 09:20:22 +03:00
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_DECL_EDITTRANSACTIONBASE
|
2016-07-07 09:20:22 +03:00
|
|
|
|
2017-12-15 14:43:26 +03:00
|
|
|
uint32_t Offset() { return mOffset; }
|
2016-07-07 09:20:22 +03:00
|
|
|
|
2017-12-15 14:43:26 +03:00
|
|
|
uint32_t LengthToDelete() { return mLengthToDelete; }
|
2016-07-07 09:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// The provider of basic editing operations.
|
2017-03-21 13:00:36 +03:00
|
|
|
RefPtr<EditorBase> mEditorBase;
|
2016-07-07 09:20:22 +03:00
|
|
|
|
|
|
|
// The CharacterData node to operate upon.
|
2018-03-19 22:18:06 +03:00
|
|
|
RefPtr<dom::CharacterData> mCharData;
|
2016-07-07 09:20:22 +03:00
|
|
|
|
|
|
|
// The offset into mCharData where the deletion is to take place.
|
|
|
|
uint32_t mOffset;
|
|
|
|
|
2017-12-15 14:43:26 +03:00
|
|
|
// The length to delete.
|
|
|
|
uint32_t mLengthToDelete;
|
2016-07-07 09:20:22 +03:00
|
|
|
|
|
|
|
// The text that was deleted.
|
|
|
|
nsString mDeletedText;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // #ifndef DeleteTextTransaction_h
|