Save and restore focus once per batch of operations

Focus saving and restoring is expensive on most browsers, so major gains
in performance are realised by not doing this for every operation. A new
pair of signals implemented by operation routers denotes when a batch of
operations is about to processed, and when the router has completed this
batch.

Note, there is no implied promises about how many operations are executed
within a batch. This is left as a choice to the router implementations.
This commit is contained in:
Philip Peitsch
2014-02-05 23:41:57 +11:00
parent 558a1e3e23
commit 26a9252edb
6 changed files with 59 additions and 10 deletions
+2 -2
View File
@@ -924,9 +924,9 @@ gui.SessionController = (function () {
odtDocument.subscribe(ops.OdtDocument.signalOperationEnd, redrawRegionSelectionTask.trigger);
odtDocument.subscribe(ops.OdtDocument.signalCursorAdded, inputMethodEditor.registerCursor);
odtDocument.subscribe(ops.OdtDocument.signalCursorRemoved, inputMethodEditor.removeCursor);
odtDocument.subscribe(ops.OdtDocument.signalOperationStart, saveFocus);
odtDocument.subscribe(ops.OdtDocument.signalOperationEnd, restoreFocus);
odtDocument.subscribe(ops.OdtDocument.signalOperationEnd, updateUndoStack);
odtDocument.subscribe(ops.OdtDocument.signalProcessingBatchStart, saveFocus);
odtDocument.subscribe(ops.OdtDocument.signalProcessingBatchEnd, restoreFocus);
}
init();
+1
View File
@@ -576,6 +576,7 @@
"odf/OdfUtils.js"
],
"ops/TrivialOperationRouter.js": [
"core/EventNotifier.js",
"ops/Operation.js",
"ops/OperationFactory.js",
"ops/OperationRouter.js"
+4
View File
@@ -79,6 +79,8 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
ops.OdtDocument.signalTableAdded,
ops.OdtDocument.signalOperationStart,
ops.OdtDocument.signalOperationEnd,
ops.OdtDocument.signalProcessingBatchStart,
ops.OdtDocument.signalProcessingBatchEnd,
ops.OdtDocument.signalUndoStackChanged,
ops.OdtDocument.signalStepsInserted,
ops.OdtDocument.signalStepsRemoved
@@ -908,6 +910,8 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
/**@const*/ops.OdtDocument.signalParagraphStyleModified = "paragraphstyle/modified";
/**@const*/ops.OdtDocument.signalOperationStart = "operation/start";
/**@const*/ops.OdtDocument.signalOperationEnd = "operation/end";
/**@const*/ops.OdtDocument.signalProcessingBatchStart = "router/batchstart";
/**@const*/ops.OdtDocument.signalProcessingBatchEnd = "router/batchend";
/**@const*/ops.OdtDocument.signalUndoStackChanged = "undo/changed";
/**@const*/ops.OdtDocument.signalStepsInserted = "steps/inserted";
/**@const*/ops.OdtDocument.signalStepsRemoved = "steps/removed";
+14
View File
@@ -115,3 +115,17 @@ ops.OperationRouter.prototype.hasLocalUnsyncedOps = function () {"use strict"; }
* @return {!boolean}
*/
ops.OperationRouter.prototype.hasSessionHostConnection = function () {"use strict"; };
/**
* Signal that the operation router is about to process a batch of operations.
* @const
* @type {string}
*/
ops.OperationRouter.signalProcessingBatchStart = "router/batchstart";
/**
* Signal that the operation router has just completed processing a batch of operations.
* @const
* @type {string}
*/
ops.OperationRouter.signalProcessingBatchEnd = "router/batchend";
+24
View File
@@ -57,6 +57,24 @@ ops.Session = function Session(odfCanvas) {
/**@type{?ops.OperationRouter}*/
operationRouter = null;
/**
* Forward the router's batch start signal on to the document
* @param {*} args
* @return {undefined}
*/
function forwardBatchStart(args) {
odtDocument.emit(ops.OdtDocument.signalProcessingBatchStart, args);
}
/**
* Forward the router's batch end signal on to the document
* @param {*} args
* @return {undefined}
*/
function forwardBatchEnd(args) {
odtDocument.emit(ops.OdtDocument.signalProcessingBatchEnd, args);
}
/**
* @param {!ops.OperationFactory} opFactory
*/
@@ -72,7 +90,13 @@ ops.Session = function Session(odfCanvas) {
* @return {undefined}
*/
this.setOperationRouter = function (opRouter) {
if (operationRouter) {
operationRouter.unsubscribe(ops.OperationRouter.signalProcessingBatchStart, forwardBatchStart);
operationRouter.unsubscribe(ops.OperationRouter.signalProcessingBatchEnd, forwardBatchEnd);
}
operationRouter = opRouter;
operationRouter.subscribe(ops.OperationRouter.signalProcessingBatchStart, forwardBatchStart);
operationRouter.subscribe(ops.OperationRouter.signalProcessingBatchEnd, forwardBatchEnd);
opRouter.setPlaybackFunction(function (op) {
odtDocument.emit(ops.OdtDocument.signalOperationStart, op);
if (op.execute(odtDocument)) {
+14 -8
View File
@@ -35,7 +35,9 @@
* @source: http://www.webodf.org/
* @source: https://github.com/kogmbh/WebODF/
*/
/*global ops*/
/*global ops, runtime, core*/
runtime.loadClass("core.EventNotifier");
/*
* route the operations.
@@ -52,7 +54,11 @@
ops.TrivialOperationRouter = function TrivialOperationRouter() {
"use strict";
var operationFactory,
var events = new core.EventNotifier([
ops.OperationRouter.signalProcessingBatchStart,
ops.OperationRouter.signalProcessingBatchEnd
]),
operationFactory,
playbackFunction,
groupIdentifier = 0;
@@ -89,6 +95,7 @@ ops.TrivialOperationRouter = function TrivialOperationRouter() {
// The current implementation is only designed for a localeditor instance & the TrivialUndoManager.
// TODO redesign this concept to work with collaborative editing
groupIdentifier += 1;
events.emit(ops.OperationRouter.signalProcessingBatchStart, {});
operations.forEach(function(op) {
var timedOp,
opspec = op.spec();
@@ -100,6 +107,7 @@ ops.TrivialOperationRouter = function TrivialOperationRouter() {
// TODO: handle return flag in error case
playbackFunction(timedOp);
});
events.emit(ops.OperationRouter.signalProcessingBatchEnd, {});
};
this.close = function (cb) {
@@ -111,20 +119,18 @@ ops.TrivialOperationRouter = function TrivialOperationRouter() {
* @param {!Function} cb
* @return {undefined}
*/
/*jslint emptyblock: true, unparam: true*/
this.subscribe = function (eventId, cb) {
this.subscribe = function(eventId, cb) {
events.subscribe(eventId, cb);
};
/*jslint emptyblock: false, unparam: false*/
/**
* @param {!string} eventId
* @param {!Function} cb
* @return {undefined}
*/
/*jslint emptyblock: true, unparam: true*/
this.unsubscribe = function (eventId, cb) {
this.unsubscribe = function(eventId, cb) {
events.unsubscribe(eventId, cb);
};
/*jslint emptyblock: false, unparam: false*/
/**
* @return {!boolean}