Bug 830992 part 2. Switch DOMTransaction to WebIDL codegen. r=wchen,peterv

This commit is contained in:
Boris Zbarsky 2013-02-06 09:42:33 +00:00
Родитель 454062c586
Коммит 82c6f6b490
8 изменённых файлов: 70 добавлений и 84 удалений

Просмотреть файл

@ -1,8 +1,10 @@
/* -*- 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/. */
#include "mozilla/dom/UndoManager.h"
#include "mozilla/dom/DOMTransactionBinding.h"
#include "nsDOMClassInfoID.h"
#include "nsIClassInfo.h"
@ -18,8 +20,6 @@
#include "mozilla/Preferences.h"
#include "mozilla/ErrorResult.h"
#include "nsIUndoManagerTransaction.h"
// Includes for mutation observer.
#include "nsIDOMHTMLElement.h"
#include "nsStubMutationObserver.h"
@ -725,14 +725,13 @@ class FunctionCallTxn : public UndoTxn {
NS_IMETHOD RedoTransaction();
NS_IMETHOD UndoTransaction();
FunctionCallTxn(nsIUndoManagerTransaction* aTransaction, uint32_t aFlags);
FunctionCallTxn(DOMTransaction* aTransaction, uint32_t aFlags);
protected:
/**
* Call a function member on the transaction object with the
* specified function name.
*/
nsresult CallTransactionMember(const char* aFunctionName);
nsCOMPtr<nsIUndoManagerTransaction> mTransaction;
nsRefPtr<DOMTransaction> mTransaction;
uint32_t mFlags;
};
@ -746,7 +745,7 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(FunctionCallTxn)
NS_IMPL_CYCLE_COLLECTING_RELEASE(FunctionCallTxn)
FunctionCallTxn::FunctionCallTxn(nsIUndoManagerTransaction* aTransaction,
FunctionCallTxn::FunctionCallTxn(DOMTransaction* aTransaction,
uint32_t aFlags)
: mTransaction(aTransaction), mFlags(aFlags) {}
@ -757,7 +756,13 @@ FunctionCallTxn::RedoTransaction()
return NS_OK;
}
mTransaction->Redo();
ErrorResult rv;
nsRefPtr<DOMTransactionCallback> redo = mTransaction->GetRedo(rv);
if (!rv.Failed() && redo) {
redo->Call(mTransaction.get(), rv);
}
// We ignore rv because we want to avoid the rollback behavior of the
// nsITransactionManager.
return NS_OK;
}
@ -769,7 +774,13 @@ FunctionCallTxn::UndoTransaction()
return NS_OK;
}
mTransaction->Undo();
ErrorResult rv;
nsRefPtr<DOMTransactionCallback> undo = mTransaction->GetUndo(rv);
if (!rv.Failed() && undo) {
undo->Call(mTransaction.get(), rv);
}
// We ignore rv because we want to avoid the rollback behavior of the
// nsITransactionManager.
return NS_OK;
}
@ -822,7 +833,7 @@ UndoManager::UndoManager(nsIContent* aNode)
UndoManager::~UndoManager() {}
void
UndoManager::Transact(JSContext* aCx, nsIUndoManagerTransaction& aTransaction,
UndoManager::Transact(JSContext* aCx, DOMTransaction& aTransaction,
bool aMerge, ErrorResult& aRv)
{
if (mIsDisconnected || mInTransaction) {
@ -833,12 +844,15 @@ UndoManager::Transact(JSContext* aCx, nsIUndoManagerTransaction& aTransaction,
TxnScopeGuard guard(this);
// First try executing an automatic transaction.
AutomaticTransact(&aTransaction, aRv);
if (aRv.ErrorCode() == NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED) {
// If the automatic transaction didn't work due to the function being
// undefined, then try a manual transaction.
aRv = NS_OK;
nsRefPtr<DOMTransactionCallback> executeAutomatic =
aTransaction.GetExecuteAutomatic(aRv);
if (aRv.Failed()) {
return;
}
if (executeAutomatic) {
AutomaticTransact(&aTransaction, executeAutomatic, aRv);
} else {
ManualTransact(&aTransaction, aRv);
}
@ -861,9 +875,12 @@ UndoManager::Transact(JSContext* aCx, nsIUndoManagerTransaction& aTransaction,
}
void
UndoManager::AutomaticTransact(nsIUndoManagerTransaction* aTransaction,
UndoManager::AutomaticTransact(DOMTransaction* aTransaction,
DOMTransactionCallback* aCallback,
ErrorResult& aRv)
{
MOZ_ASSERT(aCallback);
nsCOMPtr<nsIMutationObserver> mutationObserver =
new UndoMutationObserver(mTxnManager);
@ -881,29 +898,29 @@ UndoManager::AutomaticTransact(nsIUndoManagerTransaction* aTransaction,
mTxnManager->DoTransaction(undoTxn);
mHostNode->AddMutationObserver(mutationObserver);
nsresult rv = aTransaction->ExecuteAutomatic();
aCallback->Call(aTransaction, aRv);
mHostNode->RemoveMutationObserver(mutationObserver);
mTxnManager->DoTransaction(redoTxn);
mTxnManager->EndBatch(true);
if (NS_FAILED(rv)) {
if (aRv.Failed()) {
mTxnManager->RemoveTopUndo();
aRv.Throw(rv);
return;
}
}
void
UndoManager::ManualTransact(nsIUndoManagerTransaction* aTransaction,
UndoManager::ManualTransact(DOMTransaction* aTransaction,
ErrorResult& aRv)
{
nsRefPtr<FunctionCallTxn> txn = new FunctionCallTxn(aTransaction,
FunctionCallTxn::CALL_ON_REDO | FunctionCallTxn::CALL_ON_UNDO);
nsresult rv = aTransaction->Execute();
if (NS_FAILED(rv)) {
aRv.Throw(rv);
nsRefPtr<DOMTransactionCallback> execute = aTransaction->GetExecute(aRv);
if (!aRv.Failed() && execute) {
execute->Call(aTransaction, aRv);
}
if (aRv.Failed()) {
return;
}
@ -948,7 +965,7 @@ UndoManager::GetLength(ErrorResult& aRv)
void
UndoManager::ItemInternal(uint32_t aIndex,
nsTArray<nsIUndoManagerTransaction*>& aItems,
nsTArray<DOMTransaction*>& aItems,
ErrorResult& aRv)
{
int32_t numRedo;
@ -984,7 +1001,7 @@ UndoManager::ItemInternal(uint32_t aIndex,
}
// Obtain data from transaction list and convert to list of
// nsIUndoManagerTransaction.
// DOMTransaction*.
nsISupports** listData;
uint32_t listDataLength;
rv = txnList->GetData(listIndex, &listDataLength, &listData);
@ -994,11 +1011,7 @@ UndoManager::ItemInternal(uint32_t aIndex,
}
for (uint32_t i = 0; i < listDataLength; i++) {
nsCOMPtr<nsIUndoManagerTransaction> transaction =
do_QueryInterface(listData[i]);
MOZ_ASSERT(transaction,
"Only nsIUndoManagerTransaction should be stored as data.");
aItems.AppendElement(transaction);
aItems.AppendElement(static_cast<DOMTransaction*>(listData[i]));
NS_RELEASE(listData[i]);
}
NS_Free(listData);
@ -1006,7 +1019,7 @@ UndoManager::ItemInternal(uint32_t aIndex,
void
UndoManager::Item(uint32_t aIndex,
Nullable<nsTArray<nsRefPtr<nsIUndoManagerTransaction> > >& aItems,
Nullable<nsTArray<nsRefPtr<DOMTransaction> > >& aItems,
ErrorResult& aRv)
{
int32_t numRedo;
@ -1031,13 +1044,13 @@ UndoManager::Item(uint32_t aIndex,
return;
}
nsTArray<nsIUndoManagerTransaction*> transactions;
nsTArray<DOMTransaction*> transactions;
ItemInternal(aIndex, transactions, aRv);
if (aRv.Failed()) {
return;
}
nsTArray<nsRefPtr<nsIUndoManagerTransaction> >& items = aItems.SetValue();
nsTArray<nsRefPtr<DOMTransaction> >& items = aItems.SetValue();
for (uint32_t i = 0; i < transactions.Length(); i++) {
items.AppendElement(transactions[i]);
}
@ -1117,7 +1130,7 @@ UndoManager::DispatchTransactionEvent(JSContext* aCx, const nsAString& aType,
uint32_t aPreviousPosition,
ErrorResult& aRv)
{
nsTArray<nsIUndoManagerTransaction*> items;
nsTArray<DOMTransaction*> items;
ItemInternal(aPreviousPosition, items, aRv);
if (aRv.Failed()) {
return;
@ -1145,16 +1158,12 @@ UndoManager::DispatchTransactionEvent(JSContext* aCx, const nsAString& aType,
nsCOMPtr<nsIWritableVariant> transactions = new nsVariant();
// Unwrap the nsIUndoManagerTransactions into jsvals, then convert
// Unwrap the DOMTransactions into jsvals, then convert
// to nsIVariant then put into a nsIVariant array. Arrays in XPIDL suck.
JSObject* obj;
nsCOMArray<nsIVariant> keepAlive;
nsTArray<nsIVariant*> transactionItems;
for (uint32_t i = 0; i < items.Length(); i++) {
nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS = do_QueryInterface(items[i]);
MOZ_ASSERT(wrappedJS, "All transactions should be WrappedJS.");
wrappedJS->GetJSObject(&obj);
jsval txVal = JS::ObjectValue(*obj);
JS::Value txVal = JS::ObjectValue(*items[i]->Callback());
if (!JS_WrapValue(aCx, &txVal)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;

Просмотреть файл

@ -15,7 +15,6 @@
#include "mozilla/dom/Nullable.h"
#include "nsIContent.h"
class nsIUndoManagerTransaction;
class nsITransactionManager;
class nsIMutationObserver;
@ -23,6 +22,9 @@ namespace mozilla {
class ErrorResult;
namespace dom {
class DOMTransaction;
class DOMTransactionCallback;
class UndoManager : public nsISupports,
public nsWrapperCache
{
@ -33,12 +35,12 @@ public:
explicit UndoManager(nsIContent* aNode);
void Transact(JSContext* aCx, nsIUndoManagerTransaction& aTransaction,
void Transact(JSContext* aCx, DOMTransaction& aTransaction,
bool aMerge, ErrorResult& aRv);
void Undo(JSContext* aCx, ErrorResult& aRv);
void Redo(JSContext* acx, ErrorResult& aRv);
void Item(uint32_t aIndex,
Nullable<nsTArray<nsRefPtr<nsIUndoManagerTransaction> > >& aItems,
Nullable<nsTArray<nsRefPtr<DOMTransaction> > >& aItems,
ErrorResult& aRv);
uint32_t GetLength(ErrorResult& aRv);
uint32_t GetPosition(ErrorResult& aRv);
@ -69,13 +71,15 @@ protected:
/**
* Executes |aTransaction| as a manual transaction.
*/
void ManualTransact(nsIUndoManagerTransaction* aTransaction,
void ManualTransact(DOMTransaction* aTransaction,
ErrorResult& aRv);
/**
* Executes |aTransaction| as an automatic transaction.
* Executes |aTransaction| as an automatic transaction, calling
* aCallback to do the work.
*/
void AutomaticTransact(nsIUndoManagerTransaction* aTransaction,
void AutomaticTransact(DOMTransaction* aTransaction,
DOMTransactionCallback* aCallback,
ErrorResult& aRv);
/**
@ -83,7 +87,7 @@ protected:
* to the array |aItems|.
*/
void ItemInternal(uint32_t aIndex,
nsTArray<nsIUndoManagerTransaction*>& aItems,
nsTArray<DOMTransaction*>& aItems,
ErrorResult& aRv);
/**

Просмотреть файл

@ -322,12 +322,6 @@ DOMInterfaces = {
'workers': True,
},
'DOMTransaction': [
{
'nativeType': 'nsIUndoManagerTransaction',
'headerFile': 'nsIUndoManagerTransaction.h',
}],
'UndoManager': [
{
'implicitJSContext' : [ 'undo', 'redo', 'transact' ]

Просмотреть файл

@ -2479,8 +2479,7 @@ for (uint32_t i = 0; i < length; ++i) {
if (descriptor.interface.isCallback() and
descriptor.interface.identifier.name != "NodeFilter" and
descriptor.interface.identifier.name != "EventListener" and
descriptor.interface.identifier.name != "DOMTransaction"):
descriptor.interface.identifier.name != "EventListener"):
if descriptor.workers:
if type.nullable():
declType = CGGeneric("JSObject*")
@ -3322,8 +3321,7 @@ if (!returnArray) {
if (type.isGeckoInterface() and
(not type.isCallbackInterface() or
type.unroll().inner.identifier.name == "EventListener" or
type.unroll().inner.identifier.name == "NodeFilter" or
type.unroll().inner.identifier.name == "DOMTransaction")):
type.unroll().inner.identifier.name == "NodeFilter")):
descriptor = descriptorProvider.getDescriptor(type.unroll().inner.identifier.name)
if type.nullable():
wrappingCode = ("if (!%s) {\n" % (result) +
@ -7283,8 +7281,7 @@ class CGNativeMember(ClassMethod):
if (type.isGeckoInterface() and
(not type.isCallbackInterface() or
type.unroll().inner.identifier.name == "NodeFilter" or
type.unroll().inner.identifier.name == "EventListener" or
type.unroll().inner.identifier.name == "DOMTransaction")):
type.unroll().inner.identifier.name == "EventListener")):
iface = type.unroll().inner
argIsPointer = type.nullable() or iface.isExternal()
forceOwningType = iface.isCallback() or isMember

Просмотреть файл

@ -84,7 +84,6 @@ SDK_XPIDLSRCS = \
nsIDOMHTMLVideoElement.idl \
nsIDOMHTMLAudioElement.idl \
nsIDOMValidityState.idl \
nsIUndoManagerTransaction.idl \
nsIDOMMozBrowserFrame.idl \
$(NULL)

Просмотреть файл

@ -1,17 +0,0 @@
/* -*- Mode: IDL; 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/. */
#include "nsISupports.idl"
[scriptable, uuid(3802f155-e0f5-49ba-9972-e1aadcf2fdf0)]
interface nsIUndoManagerTransaction : nsISupports
{
attribute DOMString label;
void executeAutomatic();
void execute();
void undo();
void redo();
};

Просмотреть файл

@ -10,11 +10,13 @@
* liability, trademark and document use rules apply.
*/
callback DOMTransactionCallback = void();
callback interface DOMTransaction {
attribute DOMString label;
void executeAutomatic();
void execute();
void undo();
void redo();
readonly attribute DOMString? label;
readonly attribute DOMTransactionCallback? executeAutomatic;
readonly attribute DOMTransactionCallback? execute;
readonly attribute DOMTransactionCallback? undo;
readonly attribute DOMTransactionCallback? redo;
};

Просмотреть файл

@ -10,8 +10,6 @@
* liability, trademark and document use rules apply.
*/
interface DOMTransaction;
[PrefControlled]
interface UndoManager {
[Throws] void transact(DOMTransaction transaction, boolean merge);