2015-05-03 19:32:37 +00: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-04 06:54:26 +00: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-22 00:05:20 +00:00
|
|
|
#include "nsIContent.h"
|
2013-01-04 06:54:26 +00:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "mozilla/dom/Nullable.h"
|
|
|
|
|
|
|
|
class nsITransactionManager;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
|
|
|
namespace dom {
|
|
|
|
|
2013-02-06 09:42:33 +00:00
|
|
|
class DOMTransaction;
|
|
|
|
class DOMTransactionCallback;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class UndoManager final : public nsISupports,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsWrapperCache
|
2013-01-04 06:54:26 +00: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 09:42:33 +00:00
|
|
|
void Transact(JSContext* aCx, DOMTransaction& aTransaction,
|
2013-01-04 06:54:26 +00:00
|
|
|
bool aMerge, ErrorResult& aRv);
|
|
|
|
void Undo(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
void Redo(JSContext* acx, ErrorResult& aRv);
|
|
|
|
void Item(uint32_t aIndex,
|
2015-10-18 05:24:48 +00:00
|
|
|
Nullable<nsTArray<RefPtr<DOMTransaction> > >& aItems,
|
2013-01-04 06:54:26 +00: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 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2013-01-04 06:54:26 +00: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 14:13:33 +00:00
|
|
|
return mozilla::dom::UndoManagerBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-04 06:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsITransactionManager* GetTransactionManager();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~UndoManager();
|
|
|
|
nsCOMPtr<nsITransactionManager> mTxnManager;
|
|
|
|
nsCOMPtr<nsIContent> mHostNode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes |aTransaction| as a manual transaction.
|
|
|
|
*/
|
2013-02-06 09:42:33 +00:00
|
|
|
void ManualTransact(DOMTransaction* aTransaction,
|
2013-01-04 06:54:26 +00:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
/**
|
2013-02-06 09:42:33 +00:00
|
|
|
* Executes |aTransaction| as an automatic transaction, calling
|
|
|
|
* aCallback to do the work.
|
2013-01-04 06:54:26 +00:00
|
|
|
*/
|
2013-02-06 09:42:33 +00:00
|
|
|
void AutomaticTransact(DOMTransaction* aTransaction,
|
|
|
|
DOMTransactionCallback* aCallback,
|
2013-01-04 06:54:26 +00: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 09:42:33 +00:00
|
|
|
nsTArray<DOMTransaction*>& aItems,
|
2013-01-04 06:54:26 +00: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
|