зеркало из https://github.com/mozilla/gecko-dev.git
More ViXEn transaction system love.
NOT PART OF BUILD.
This commit is contained in:
Родитель
fdb5df401b
Коммит
f5cbbaec62
|
@ -81,11 +81,11 @@ var vxPalette =
|
|||
var txns = [radiogroupTxn, radiogroupAttrTxn, radioTxn, radioAttrTxn];
|
||||
var aggregateTxn = new vxAggregateTxn(txns);
|
||||
aggregateTxn.init();
|
||||
|
||||
|
||||
var txmgr = focusedWindow.vxVFD.mTxMgrShell;
|
||||
txmgr.addListener([radioAttrTxn, radioTxn, radioAttrTxn]);
|
||||
aggregateTxn.addListener([radiogroupAttrTxn, radioTxn, radioAttrTxn]);
|
||||
txmgr.doTransaction(aggregateTxn);
|
||||
txmgr.removeListener([radioAttrTxn, radioTxn, radioAttrTxn]);
|
||||
aggregateTxn.removeListener([radiogroupAttrTxn, radioTxn, radioAttrTxn]);
|
||||
},
|
||||
|
||||
incrementElementCount: function (aNodeName)
|
||||
|
@ -104,9 +104,8 @@ var vxPalette =
|
|||
// need to check to see if the focused window is a vfd
|
||||
|
||||
var insertionPoint = focusedWindow.vxVFD.getInsertionPoint();
|
||||
|
||||
var vfdDocument = focusedWindow.vxVFD.getContent(true).document;
|
||||
|
||||
|
||||
var elementTxn = new vxCreateElementTxn(vfdDocument, aNodeName, insertionPoint.parent, insertionPoint.index);
|
||||
elementTxn.init();
|
||||
var elementAttrTxn = new vxChangeAttributeTxn(elementTxn.mID, aAttributes, aValues, false);
|
||||
|
@ -120,6 +119,16 @@ var vxPalette =
|
|||
txmgr.addListener(elementAttrTxn);
|
||||
txmgr.doTransaction(aggregateTxn);
|
||||
txmgr.removeListener(elementAttrTxn);
|
||||
},
|
||||
|
||||
/**
|
||||
* Implements nsITransactionListener
|
||||
*/
|
||||
didUndo: function (aTransactionManager, aTransaction, aInterrupt)
|
||||
{
|
||||
// Register the palette as a transaction listener so that the instance
|
||||
// count for each type of widget can be decremented when a transaction
|
||||
// is done.
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<script src="chrome://vixen/content/palette/vxPalette.js"></script>
|
||||
|
||||
<!-- supported txns -->
|
||||
<script src="chrome://vixen/content/vfd/vxBaseTxn.js"></script>
|
||||
<script src="chrome://vixen/content/vfd/vxAggregateTxn.js"></script>
|
||||
<script src="chrome://vixen/content/vfd/vxChangeAttributeTxn.js"></script>
|
||||
<script src="chrome://vixen/content/vfd/vxCreateElementTxn.js"></script>
|
||||
|
|
|
@ -36,33 +36,41 @@ function vxAggregateTxn (aTransactionList)
|
|||
this.mTransactionList[aTransactionList[i].mID] = aTransactionList[i];
|
||||
|
||||
this.mID = "aggregate-txn::";
|
||||
|
||||
this.mTransactionListeners = [];
|
||||
}
|
||||
|
||||
vxAggregateTxn.prototype = {
|
||||
init: function ()
|
||||
{
|
||||
this.mID += generateID();
|
||||
},
|
||||
__proto__: vxBaseTxn.prototype,
|
||||
|
||||
doTransaction: function ()
|
||||
{
|
||||
_dd("vxAggregateTxn::doTransaction");
|
||||
for (var i in this.mTransactionList)
|
||||
for (var i in this.mTransactionList) {
|
||||
var irq = { };
|
||||
this.notifyListeners("willDo", this.mTransactionList[i], irq);
|
||||
this.mTransactionList[i].doTransaction();
|
||||
this.notifyListeners("didDo", this.mTransactionList[i], irq);
|
||||
}
|
||||
},
|
||||
|
||||
undoTransaction: function ()
|
||||
{
|
||||
_dd("vxAggregateTxn::undoTransaction");
|
||||
for (var i in this.mTransactionList)
|
||||
for (var i in this.mTransactionList) {
|
||||
var irq = { };
|
||||
this.notifyListeners("willUndo", this.mTransactionList[i], irq);
|
||||
this.mTransactionList[i].undoTransaction();
|
||||
this.notifyListeners("didUndo", this.mTransactionList[i], irq);
|
||||
}
|
||||
},
|
||||
|
||||
redoTransaction: function ()
|
||||
{
|
||||
_dd("vxAggregateTxn::redoTransaction");
|
||||
for (var i in this.mTransactionList)
|
||||
for (var i in this.mTransactionList) {
|
||||
var irq = { };
|
||||
this.notifyListeners("willRedo", this.mTransactionList[i], irq);
|
||||
this.mTransactionList[i].redoTransaction();
|
||||
this.notifyListeners("didRedo", this.mTransactionList[i], irq);
|
||||
}
|
||||
},
|
||||
|
||||
get commandString()
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
function vxBaseTxn ()
|
||||
{
|
||||
}
|
||||
|
||||
vxBaseTxn.prototype = {
|
||||
mID: null,
|
||||
|
||||
mListeners: [],
|
||||
|
||||
notifyListeners: function (aEvent, aTransaction, aIRQ)
|
||||
{
|
||||
_dd("vxBaseTxn::notifyListeners");
|
||||
for (var i = 0; i < this.mListeners.length; i++) {
|
||||
if (aEvent in this.mListeners[i]) {
|
||||
_ddf("calling listener for transaction complete", aTransaction.commandString);
|
||||
this.mListeners[i][aEvent](undefined, aTransaction, aIRQ);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
addListener: function (aListener)
|
||||
{
|
||||
_dd("vxBaseTxn::addListener");
|
||||
this.mListeners = this.mListeners.concat(aListener);
|
||||
_ddf("vxBaseTxn::mListeners", this.mListeners);
|
||||
},
|
||||
|
||||
removeListener: function (aListener)
|
||||
{
|
||||
_dd("vxBaseTxn::removeListener");
|
||||
var listeners = [].concat(aListener);
|
||||
for (var i = 0; i < this.mListeners.length; i++) {
|
||||
for (var k = 0; k < listeners.length; k++) {
|
||||
if (this.mListeners[i] == listeners[k]) {
|
||||
this.mListeners.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
init: function ()
|
||||
{
|
||||
this.mID += this.generateID();
|
||||
},
|
||||
|
||||
/**
|
||||
* Generate a unique identifier for a transaction
|
||||
*/
|
||||
generateID: function ()
|
||||
{
|
||||
var val = ((new Date()).getUTCMilliseconds())*Math.random()*100000;
|
||||
_ddf("value", val);
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
|
@ -57,18 +57,14 @@ function vxChangeAttributeTxn(aElement, aAttribute, aValue, aRemoveFlag)
|
|||
}
|
||||
|
||||
vxChangeAttributeTxn.prototype = {
|
||||
init: function ()
|
||||
{
|
||||
this.mID += generateID();
|
||||
},
|
||||
|
||||
__proto__: vxBaseTxn.prototype,
|
||||
|
||||
doTransaction: function ()
|
||||
{
|
||||
if (!this.mElementCreated)
|
||||
if (!this.mElementCreated)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < this.mAttributes.length; i++) {
|
||||
_ddf("changing attribute", this.mAttributes[i]);
|
||||
this.mUndoValues[i] = this.mElement.getAttribute(this.mAttributes[i]);
|
||||
if (!this.mRemoveFlags[i])
|
||||
this.mElement.setAttribute(this.mAttributes[i], this.mValues[i]);
|
||||
|
@ -113,16 +109,18 @@ vxChangeAttributeTxn.prototype = {
|
|||
*/
|
||||
didDo: function (aTransactionManager, aTransaction, aInterrupt)
|
||||
{
|
||||
_ddf("aTransaction is a", aTransaction.commandString);
|
||||
if (aTransaction.commandString.indexOf("aggregate-txn") >= 0) {
|
||||
var createElementTxn = aTransaction.mTransactionList[this.mElementTxnID];
|
||||
_ddf("the transaction ahead of us is", createElementTxn.commandString);
|
||||
_ddf("and its element is", createElementTxn.mLocalName);
|
||||
if (createElementTxn.commandString.indexOf("create-element") >= 0) {
|
||||
this.mElement = createElementTxn.mElement;
|
||||
this.mElementCreated = true;
|
||||
this.doTransaction();
|
||||
}
|
||||
var prevTxn = null;
|
||||
if (aTransaction.commandString.indexOf("aggregate-txn") >= 0)
|
||||
prevTxn = aTransaction.mTransactionList[this.mElementTxnID];
|
||||
else
|
||||
prevTxn = aTransaction;
|
||||
|
||||
if (prevTxn.commandString.indexOf("create-element") >= 0) {
|
||||
_ddf("did create element of", prevTxn.mLocalName);
|
||||
this.mElement = prevTxn.mElement;
|
||||
this.mElementCreated = true;
|
||||
_ddf("going to actually do this transaction now", this.mAttributes);
|
||||
this.doTransaction();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -45,17 +45,12 @@ function vxCreateElementTxn(aDocument, aLocalName, aParentNode, aChildOffset)
|
|||
}
|
||||
|
||||
vxCreateElementTxn.prototype = {
|
||||
init: function ()
|
||||
{
|
||||
this.mID += generateID();
|
||||
},
|
||||
__proto__: vxBaseTxn.prototype,
|
||||
|
||||
doTransaction: function ()
|
||||
{
|
||||
_ddf("creating element", this.mLocalName);
|
||||
if (!this.mElementCreated) {
|
||||
_dd("aParentNode is an id, bailing early");
|
||||
_ddf("localname is", this.mLocalName);
|
||||
_dd("element we rely on does not yet exist, so bail for now");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -96,9 +91,14 @@ vxCreateElementTxn.prototype = {
|
|||
*/
|
||||
didDo: function (aTransactionManager, aTransaction, aInterrupt)
|
||||
{
|
||||
var createElementTxn = aTransaction.mTransactionList[this.mElementTxnID];
|
||||
if (createElementTxn.commandString.indexOf("create-element") >= 0) {
|
||||
this.mElement = createElementTxn.mElement;
|
||||
var prevTxn = null;
|
||||
if (aTransaction.commandString.indexOf("aggregate-txn") >= 0)
|
||||
prevTxn = aTransaction.mTransactionList[this.mElementTxnID];
|
||||
else
|
||||
prevTxn = aTransaction;
|
||||
|
||||
if (prevTxn.commandString.indexOf("create-element") >= 0) {
|
||||
this.mParentNode = prevTxn.mElement;
|
||||
this.mElementCreated = true;
|
||||
this.doTransaction();
|
||||
}
|
||||
|
|
|
@ -63,8 +63,8 @@ vxVFDTransactionManager.prototype =
|
|||
|
||||
// likewise with the RDF Seq.
|
||||
var seqCount = this.mTxnSeq.GetCount();
|
||||
for (i = this.mTxnStack.index; i < seqCount; i++)
|
||||
this.mTxnSeq.RemoveElementAt(i);
|
||||
for (i = seqCount-1; i >= this.mTxnStack.index; i--)
|
||||
this.mTxnSeq.RemoveElementAt(i, true);
|
||||
}
|
||||
|
||||
// append the transaction to our list
|
||||
|
@ -76,7 +76,6 @@ vxVFDTransactionManager.prototype =
|
|||
for (i = 0; i < this.mTransactionListeners.length; i++) {
|
||||
interruptRequest = {};
|
||||
if ("didDo" in this.mTransactionListeners[i]) {
|
||||
_ddf("transaction listener " + i, this.mTransactionListeners[i].commandString);
|
||||
this.mTransactionListeners[i].didDo(this, aTransaction, interruptRequest);
|
||||
// do something with irq here once we figure out what it does.
|
||||
}
|
||||
|
@ -98,7 +97,6 @@ vxVFDTransactionManager.prototype =
|
|||
|
||||
// undo the transaction
|
||||
if (txn) {
|
||||
_ddf("going to undo the txn at", this.mTxnStack.index-1);
|
||||
txn.undoTransaction();
|
||||
this.mTxnStack.index--;
|
||||
}
|
||||
|
@ -232,6 +230,12 @@ var vxVFDTransactionDS =
|
|||
return null;
|
||||
},
|
||||
|
||||
GetTargets: function (aSource, aProperty, aTruthValue)
|
||||
{
|
||||
var targets = [].concat(this.GetTarget(aSource, aProperty, aTruthValue));
|
||||
return new ArrayEnumerator(targets);
|
||||
},
|
||||
|
||||
mObservers: [],
|
||||
AddObserver: function (aObserver)
|
||||
{
|
||||
|
@ -282,7 +286,6 @@ vxVFDTransactionStack.prototype =
|
|||
|
||||
set index (aValue)
|
||||
{
|
||||
_ddf("setting index to", aValue);
|
||||
this.mIndex = aValue;
|
||||
return this.mIndex;
|
||||
},
|
||||
|
|
|
@ -44,16 +44,6 @@ var vxUtils = {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate a unique identifier for a transaction
|
||||
*/
|
||||
function generateID()
|
||||
{
|
||||
var val = ((new Date()).getUTCMilliseconds())*Math.random()*100000;
|
||||
_ddf("value", val);
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* dumps the DOM tree under a given node.
|
||||
*/
|
||||
|
@ -64,3 +54,25 @@ function dumpDOM(aNode)
|
|||
dumpDOM(aNode.childNodes[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a regular js array into an nsISimpleEnumerator
|
||||
*/
|
||||
function ArrayEnumerator(aArray)
|
||||
{
|
||||
this.mArray = aArray;
|
||||
this.mIndex = 0;
|
||||
}
|
||||
|
||||
ArrayEnumerator.prototype = {
|
||||
getNext: function ()
|
||||
{
|
||||
return this.mArray[this.mIndex++];
|
||||
},
|
||||
|
||||
hasMoreElements: function ()
|
||||
{
|
||||
if (this.mIndex < this.mArray.length)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -18,6 +18,7 @@ vixen.jar:
|
|||
content/vixen/vfd/vxVFDSelectionManager.js (content/vfd/vxVFDSelectionManager.js)
|
||||
content/vixen/vfd/vxVFDTransactionManager.js (content/vfd/vxVFDTransactionManager.js)
|
||||
content/vixen/vfd/vxAggregateTxn.js (content/vfd/vxAggregateTxn.js)
|
||||
content/vixen/vfd/vxBaseTxn.js (content/vfd/vxBaseTxn.js)
|
||||
skin/modern/vixen/contents.rdf (skin/contents.rdf)
|
||||
skin/modern/vixen/vfdScratch.css (skin/vfdScratch.css)
|
||||
locale/en-US/vixen/contents.rdf (locale/en-US/contents.rdf)
|
||||
|
|
Загрузка…
Ссылка в новой задаче