2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-01-14 21:02:45 +03:00
|
|
|
|
2016-07-07 08:56:53 +03:00
|
|
|
#ifndef DeleteRangeTransaction_h
|
|
|
|
#define DeleteRangeTransaction_h
|
1999-01-14 21:02:45 +03:00
|
|
|
|
2016-07-07 11:11:30 +03:00
|
|
|
#include "EditAggregateTransaction.h"
|
2017-11-08 09:01:23 +03:00
|
|
|
#include "mozilla/RangeBoundary.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
2012-06-25 14:22:49 +04:00
|
|
|
#include "nsRange.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nscore.h"
|
1999-01-14 21:02:45 +03:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsINode;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
2016-07-07 08:56:53 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
class EditorBase;
|
2016-06-24 09:01:40 +03:00
|
|
|
class RangeUpdater;
|
|
|
|
|
1999-01-14 21:02:45 +03:00
|
|
|
/**
|
|
|
|
* A transaction that deletes an entire range in the content tree
|
|
|
|
*/
|
2016-07-07 11:11:30 +03:00
|
|
|
class DeleteRangeTransaction final : public EditAggregateTransaction {
|
2017-12-18 12:08:43 +03:00
|
|
|
protected:
|
|
|
|
DeleteRangeTransaction(EditorBase& aEditorBase, nsRange& aRangeToDelete);
|
|
|
|
|
1999-01-14 21:02:45 +03:00
|
|
|
public:
|
2016-07-07 08:56:53 +03:00
|
|
|
/**
|
2017-12-18 12:08:43 +03:00
|
|
|
* Creates a delete range transaction. This never returns nullptr.
|
|
|
|
*
|
2017-03-09 05:19:39 +03:00
|
|
|
* @param aEditorBase The object providing basic editing operations.
|
|
|
|
* @param aRangeToDelete The range to delete.
|
2016-07-07 08:56:53 +03:00
|
|
|
*/
|
2017-12-18 12:08:43 +03:00
|
|
|
static already_AddRefed<DeleteRangeTransaction> Create(
|
|
|
|
EditorBase& aEditorBase, nsRange& aRangeToDelete) {
|
|
|
|
RefPtr<DeleteRangeTransaction> transaction =
|
|
|
|
new DeleteRangeTransaction(aEditorBase, aRangeToDelete);
|
|
|
|
return transaction.forget();
|
|
|
|
}
|
1999-01-21 04:51:09 +03:00
|
|
|
|
2016-07-07 08:56:53 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteRangeTransaction,
|
2016-07-07 11:11:30 +03:00
|
|
|
EditAggregateTransaction)
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
2009-05-09 08:59:25 +04:00
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_DECL_EDITTRANSACTIONBASE
|
1999-01-14 21:02:45 +03:00
|
|
|
|
2020-04-03 11:32:01 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT NS_IMETHOD RedoTransaction() override;
|
1999-09-22 02:31:27 +04:00
|
|
|
|
2016-07-07 08:56:53 +03:00
|
|
|
protected:
|
2017-11-08 09:01:23 +03:00
|
|
|
/**
|
|
|
|
* CreateTxnsToDeleteBetween() creates a DeleteTextTransaction or some
|
|
|
|
* DeleteNodeTransactions to remove text or nodes between aStart and aEnd
|
|
|
|
* and appends the created transactions to the array.
|
|
|
|
*
|
|
|
|
* @param aStart Must be set and valid point.
|
|
|
|
* @param aEnd Must be set and valid point. Additionally, the
|
|
|
|
* container must be same as aStart's container.
|
|
|
|
* And of course, this must not be before aStart in
|
|
|
|
* the DOM tree order.
|
|
|
|
* @return Returns NS_OK in most cases.
|
|
|
|
* When the arguments are invalid, returns
|
|
|
|
* NS_ERROR_INVALID_ARG.
|
|
|
|
* When mEditorBase isn't available, returns
|
|
|
|
* NS_ERROR_NOT_AVAIALBLE.
|
|
|
|
* When created DeleteTextTransaction cannot do its
|
|
|
|
* transaction, returns NS_ERROR_FAILURE.
|
|
|
|
* Note that even if one of created DeleteNodeTransaction
|
|
|
|
* cannot do its transaction, this returns NS_OK.
|
|
|
|
*/
|
|
|
|
nsresult CreateTxnsToDeleteBetween(const RawRangeBoundary& aStart,
|
|
|
|
const RawRangeBoundary& aEnd);
|
1999-01-21 04:51:09 +03:00
|
|
|
|
2017-03-24 23:07:11 +03:00
|
|
|
nsresult CreateTxnsToDeleteNodesBetween(nsRange* aRangeToDelete);
|
2012-06-25 14:22:49 +04:00
|
|
|
|
2017-11-08 09:01:23 +03:00
|
|
|
/**
|
|
|
|
* CreateTxnsToDeleteContent() creates a DeleteTextTransaction to delete
|
2017-12-07 12:45:52 +03:00
|
|
|
* text between start of aPoint.GetContainer() and aPoint or aPoint and end of
|
|
|
|
* aPoint.GetContainer() and appends the created transaction to the array.
|
2017-11-08 09:01:23 +03:00
|
|
|
*
|
|
|
|
* @param aPoint Must be set and valid point. If the container is not
|
|
|
|
* a data node, this method does nothing.
|
|
|
|
* @param aAction If nsIEditor::eNext, this method creates a transaction
|
|
|
|
* to delete text from aPoint to the end of the data node.
|
|
|
|
* Otherwise, this method creates a transaction to delete
|
|
|
|
* text from start of the data node to aPoint.
|
|
|
|
* @return Returns NS_OK in most cases.
|
|
|
|
* When the arguments are invalid, returns
|
|
|
|
* NS_ERROR_INVALID_ARG.
|
|
|
|
* When mEditorBase isn't available, returns
|
|
|
|
* NS_ERROR_NOT_AVAIALBLE.
|
|
|
|
* When created DeleteTextTransaction cannot do its
|
|
|
|
* transaction, returns NS_ERROR_FAILURE.
|
|
|
|
* Note that even if no character will be deleted,
|
|
|
|
* this returns NS_OK.
|
|
|
|
*/
|
|
|
|
nsresult CreateTxnsToDeleteContent(const RawRangeBoundary& aPoint,
|
2012-06-25 14:22:49 +04:00
|
|
|
nsIEditor::EDirection aAction);
|
1999-01-21 04:51:09 +03:00
|
|
|
|
2016-07-07 08:56:53 +03:00
|
|
|
// The editor for this transaction.
|
2017-03-21 13:00:36 +03:00
|
|
|
RefPtr<EditorBase> mEditorBase;
|
2017-03-09 05:19:39 +03:00
|
|
|
|
2017-03-24 23:07:11 +03:00
|
|
|
// P1 in the range. This is only non-null until DoTransaction is called and
|
|
|
|
// we convert it into child transactions.
|
2017-03-09 05:19:39 +03:00
|
|
|
RefPtr<nsRange> mRangeToDelete;
|
1999-01-14 21:02:45 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 08:56:53 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // #ifndef DeleteRangeTransaction_h
|