1 /**
  2  * Copyright (C) 2012-2013 KO GmbH <copyright@kogmbh.com>
  3  *
  4  * @licstart
  5  * This file is part of WebODF.
  6  *
  7  * WebODF is free software: you can redistribute it and/or modify it
  8  * under the terms of the GNU Affero General Public License (GNU AGPL)
  9  * as published by the Free Software Foundation, either version 3 of
 10  * the License, or (at your option) any later version.
 11  *
 12  * WebODF is distributed in the hope that it will be useful, but
 13  * WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15  * GNU Affero General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Affero General Public License
 18  * along with WebODF.  If not, see <http://www.gnu.org/licenses/>.
 19  * @licend
 20  *
 21  * @source: http://www.webodf.org/
 22  * @source: https://github.com/kogmbh/WebODF/
 23  */
 24 
 25 /*global runtime, ops*/
 26 
 27 /**
 28  * @constructor
 29  * @implements ops.Operation
 30  */
 31 ops.OpMoveCursor = function OpMoveCursor() {
 32     "use strict";
 33 
 34     var memberid, timestamp, position, length, /**@type {!string}*/selectionType;
 35 
 36     /**
 37      * @param {!ops.OpMoveCursor.InitSpec} data
 38      */
 39     this.init = function (data) {
 40         memberid = data.memberid;
 41         timestamp = data.timestamp;
 42         position = data.position;
 43         length = data.length || 0;
 44         selectionType = data.selectionType || ops.OdtCursor.RangeSelection;
 45     };
 46 
 47     this.isEdit = false;
 48     this.group = undefined;
 49 
 50     /**
 51      * @param {!ops.Document} document
 52      */
 53     this.execute = function (document) {
 54         var odtDocument = /**@type{ops.OdtDocument}*/(document),
 55             cursor = odtDocument.getCursor(memberid),
 56             selectedRange;
 57 
 58         if (!cursor) {
 59             return false;
 60         }
 61 
 62         selectedRange = odtDocument.convertCursorToDomRange(position, length);
 63         cursor.setSelectedRange(selectedRange, length >= 0);
 64         cursor.setSelectionType(selectionType);
 65         odtDocument.emit(ops.Document.signalCursorMoved, cursor);
 66         return true;
 67     };
 68 
 69     /**
 70      * @return {!ops.OpMoveCursor.Spec}
 71      */
 72     this.spec = function () {
 73         return {
 74             optype: "MoveCursor",
 75             memberid: memberid,
 76             timestamp: timestamp,
 77             position: position,
 78             length: length,
 79             selectionType: selectionType
 80         };
 81     };
 82 };
 83 /**@typedef{{
 84     optype:string,
 85     memberid:string,
 86     timestamp:number,
 87     position:number,
 88     length:number,
 89     selectionType:string
 90 }}*/
 91 ops.OpMoveCursor.Spec;
 92 /**@typedef{{
 93     memberid:string,
 94     timestamp:(number|undefined),
 95     position:number,
 96     length:number,
 97     selectionType:(string|undefined)
 98 }}*/
 99 ops.OpMoveCursor.InitSpec;
100