2015-05-03 12:32:37 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-01-03 22:54:26 -08: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_UndoManager_h
|
|
|
|
#define mozilla_dom_UndoManager_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/UndoManagerBinding.h"
|
|
|
|
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCOMArray.h"
|
2013-03-21 17:05:20 -07:00
|
|
|
#include "nsIContent.h"
|
2013-01-03 22:54:26 -08:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "mozilla/dom/Nullable.h"
|
|
|
|
|
|
|
|
class nsITransactionManager;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
|
|
|
namespace dom {
|
|
|
|
|
2013-02-06 01:42:33 -08:00
|
|
|
class DOMTransaction;
|
|
|
|
class DOMTransactionCallback;
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class UndoManager final : public nsISupports,
|
2015-03-27 11:52:19 -07:00
|
|
|
public nsWrapperCache
|
2013-01-03 22:54:26 -08:00
|
|
|
{
|
|
|
|
friend class TxnScopeGuard;
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(UndoManager)
|
|
|
|
|
|
|
|
explicit UndoManager(nsIContent* aNode);
|
|
|
|
|
2013-02-06 01:42:33 -08:00
|
|
|
void Transact(JSContext* aCx, DOMTransaction& aTransaction,
|
2013-01-03 22:54:26 -08:00
|
|
|
bool aMerge, ErrorResult& aRv);
|
|
|
|
void Undo(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
void Redo(JSContext* acx, ErrorResult& aRv);
|
|
|
|
void Item(uint32_t aIndex,
|
2015-10-17 22:24:48 -07:00
|
|
|
Nullable<nsTArray<RefPtr<DOMTransaction> > >& aItems,
|
2013-01-03 22:54:26 -08:00
|
|
|
ErrorResult& aRv);
|
|
|
|
uint32_t GetLength(ErrorResult& aRv);
|
|
|
|
uint32_t GetPosition(ErrorResult& aRv);
|
|
|
|
void ClearUndo(ErrorResult& aRv);
|
|
|
|
void ClearRedo(ErrorResult& aRv);
|
|
|
|
void Disconnect();
|
|
|
|
|
|
|
|
nsISupports* GetParentObject() const
|
|
|
|
{
|
|
|
|
return mHostNode;
|
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2013-01-03 22:54:26 -08:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return mozilla::dom::UndoManagerBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-03 22:54:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsITransactionManager* GetTransactionManager();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~UndoManager();
|
|
|
|
nsCOMPtr<nsITransactionManager> mTxnManager;
|
|
|
|
nsCOMPtr<nsIContent> mHostNode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes |aTransaction| as a manual transaction.
|
|
|
|
*/
|
2013-02-06 01:42:33 -08:00
|
|
|
void ManualTransact(DOMTransaction* aTransaction,
|
2013-01-03 22:54:26 -08:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
/**
|
2013-02-06 01:42:33 -08:00
|
|
|
* Executes |aTransaction| as an automatic transaction, calling
|
|
|
|
* aCallback to do the work.
|
2013-01-03 22:54:26 -08:00
|
|
|
*/
|
2013-02-06 01:42:33 -08:00
|
|
|
void AutomaticTransact(DOMTransaction* aTransaction,
|
|
|
|
DOMTransactionCallback* aCallback,
|
2013-01-03 22:54:26 -08:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Appends the transactions in the undo transaction history at |aIndex|
|
|
|
|
* to the array |aItems|.
|
|
|
|
*/
|
|
|
|
void ItemInternal(uint32_t aIndex,
|
2013-02-06 01:42:33 -08:00
|
|
|
nsTArray<DOMTransaction*>& aItems,
|
2013-01-03 22:54:26 -08:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches an event to the undo scope host.
|
|
|
|
* @param aPreviousPosition The index of the transaction that
|
|
|
|
* triggered the event.
|
|
|
|
*/
|
|
|
|
void DispatchTransactionEvent(JSContext* aCx, const nsAString& aType,
|
|
|
|
uint32_t aPreviousPosition,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
bool mInTransaction;
|
|
|
|
bool mIsDisconnected;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|