mockrenderer.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. define(function(require, exports, module) {
  31. "use strict";
  32. var MockRenderer = exports.MockRenderer = function(visibleRowCount) {
  33. this.container = document.createElement("div");
  34. this.scroller = document.createElement("div");
  35. this.visibleRowCount = visibleRowCount || 20;
  36. this.layerConfig = {
  37. firstVisibleRow : 0,
  38. lastVisibleRow : this.visibleRowCount
  39. };
  40. this.isMockRenderer = true;
  41. this.$gutter = {};
  42. };
  43. MockRenderer.prototype.getFirstVisibleRow = function() {
  44. return this.layerConfig.firstVisibleRow;
  45. };
  46. MockRenderer.prototype.getLastVisibleRow = function() {
  47. return this.layerConfig.lastVisibleRow;
  48. };
  49. MockRenderer.prototype.getFirstFullyVisibleRow = function() {
  50. return this.layerConfig.firstVisibleRow;
  51. };
  52. MockRenderer.prototype.getLastFullyVisibleRow = function() {
  53. return this.layerConfig.lastVisibleRow;
  54. };
  55. MockRenderer.prototype.getContainerElement = function() {
  56. return this.container;
  57. };
  58. MockRenderer.prototype.getMouseEventTarget = function() {
  59. return this.container;
  60. };
  61. MockRenderer.prototype.getTextAreaContainer = function() {
  62. return this.container;
  63. };
  64. MockRenderer.prototype.addGutterDecoration = function() {
  65. };
  66. MockRenderer.prototype.removeGutterDecoration = function() {
  67. };
  68. MockRenderer.prototype.moveTextAreaToCursor = function() {
  69. };
  70. MockRenderer.prototype.setSession = function(session) {
  71. this.session = session;
  72. };
  73. MockRenderer.prototype.getSession = function(session) {
  74. return this.session;
  75. };
  76. MockRenderer.prototype.setTokenizer = function() {
  77. };
  78. MockRenderer.prototype.on = function() {
  79. };
  80. MockRenderer.prototype.updateCursor = function() {
  81. };
  82. MockRenderer.prototype.animateScrolling = function(fromValue, callback) {
  83. callback && callback();
  84. };
  85. MockRenderer.prototype.scrollToX = function(scrollTop) {};
  86. MockRenderer.prototype.scrollToY = function(scrollLeft) {};
  87. MockRenderer.prototype.scrollToLine = function(line, center) {
  88. var lineHeight = 16;
  89. var row = 0;
  90. for (var l = 1; l < line; l++) {
  91. row += this.session.getRowLength(l-1);
  92. }
  93. if (center) {
  94. row -= this.visibleRowCount / 2;
  95. }
  96. this.scrollToRow(row);
  97. };
  98. MockRenderer.prototype.scrollSelectionIntoView = function() {
  99. };
  100. MockRenderer.prototype.scrollCursorIntoView = function() {
  101. var cursor = this.session.getSelection().getCursor();
  102. if (cursor.row < this.layerConfig.firstVisibleRow) {
  103. this.scrollToRow(cursor.row);
  104. }
  105. else if (cursor.row > this.layerConfig.lastVisibleRow) {
  106. this.scrollToRow(cursor.row);
  107. }
  108. };
  109. MockRenderer.prototype.scrollToRow = function(row) {
  110. var row = Math.min(this.session.getLength() - this.visibleRowCount, Math.max(0,
  111. row));
  112. this.layerConfig.firstVisibleRow = row;
  113. this.layerConfig.lastVisibleRow = row + this.visibleRowCount;
  114. };
  115. MockRenderer.prototype.getScrollTopRow = function() {
  116. return this.layerConfig.firstVisibleRow;
  117. };
  118. MockRenderer.prototype.draw = function() {
  119. };
  120. MockRenderer.prototype.onChangeTabSize = function(startRow, endRow) {
  121. };
  122. MockRenderer.prototype.updateLines = function(startRow, endRow) {
  123. };
  124. MockRenderer.prototype.updateBackMarkers = function() {
  125. };
  126. MockRenderer.prototype.updateFrontMarkers = function() {
  127. };
  128. MockRenderer.prototype.updateBreakpoints = function() {
  129. };
  130. MockRenderer.prototype.onResize = function() {
  131. };
  132. MockRenderer.prototype.updateFull = function() {
  133. };
  134. MockRenderer.prototype.updateText = function() {
  135. };
  136. MockRenderer.prototype.showCursor = function() {
  137. };
  138. MockRenderer.prototype.visualizeFocus = function() {
  139. };
  140. MockRenderer.prototype.setAnnotations = function() {
  141. };
  142. MockRenderer.prototype.setStyle = function() {
  143. };
  144. MockRenderer.prototype.unsetStyle = function() {
  145. };
  146. MockRenderer.prototype.textToScreenCoordinates = function() {
  147. return {
  148. pageX: 0,
  149. pageY: 0
  150. }
  151. };
  152. MockRenderer.prototype.screenToTextCoordinates = function() {
  153. return {
  154. row: 0,
  155. column: 0
  156. }
  157. };
  158. MockRenderer.prototype.adjustWrapLimit = function () {
  159. };
  160. });