1 /** 2 * Copyright (C) 2013 KO GmbH <aditya.bhatt@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 core, gui, ops, runtime*/ 26 27 /** 28 * @class 29 * The ShadowCursor class provides a very minimal OdtCursor-like interface. 30 * It does not insert anything into the DOM, and is useful mainly for 31 * simulating a Cursor when you cannot/should not use a real cursor. 32 * 33 * @constructor 34 * @param {!ops.Document} document 35 */ 36 gui.ShadowCursor = function ShadowCursor(document) { 37 "use strict"; 38 var /**@type{!Range}*/ 39 selectedRange = /**@type{!Range}*/(document.getDOMDocument().createRange()), 40 forwardSelection = true; 41 42 /*jslint emptyblock: true*/ 43 this.removeFromDocument = function () {}; 44 /*jslint emptyblock: false*/ 45 46 /** 47 * Obtain the memberid the cursor is assigned to. For a shadow cursor, 48 * this value is always gui.ShadowCursor.ShadowCursorMemberId 49 * @return {string} 50 */ 51 this.getMemberId = function () { 52 return gui.ShadowCursor.ShadowCursorMemberId; 53 }; 54 55 /** 56 * Obtain the currently selected range to which the cursor corresponds. 57 * @return {!Range} 58 */ 59 this.getSelectedRange = function () { 60 return selectedRange; 61 }; 62 63 /** 64 * Set the given range as the selected range for this cursor 65 * @param {!Range} range 66 * @param {boolean=} isForwardSelection Assumed to be true by default 67 * @return {undefined} 68 */ 69 this.setSelectedRange = function (range, isForwardSelection) { 70 selectedRange = range; 71 forwardSelection = isForwardSelection !== false; 72 }; 73 74 /** 75 * Returns if the selection of this cursor has the 76 * same direction as the direction of the range 77 * @return {boolean} 78 */ 79 this.hasForwardSelection = function () { 80 return forwardSelection; 81 }; 82 83 /** 84 * Obtain the document to which the cursor corresponds. 85 * @return {!ops.Document} 86 */ 87 this.getDocument = function () { 88 return document; 89 }; 90 91 /** 92 * Gets the current selection type. For a shadow cursor, this value is always 93 * ops.OdtCursor.RangeSelection 94 * @return {!string} 95 */ 96 this.getSelectionType = function () { 97 return ops.OdtCursor.RangeSelection; 98 }; 99 100 function init() { 101 selectedRange.setStart(document.getRootNode(), 0); 102 } 103 init(); 104 }; 105 106 /** @const @type {!string} */gui.ShadowCursor.ShadowCursorMemberId = ""; 107