Chromium Code Reviews| Index: chrome/browser/resources/hterm/js/hterm.js |
| diff --git a/chrome/browser/resources/hterm/js/hterm.js b/chrome/browser/resources/hterm/js/hterm.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0825caa23388d12ecaadc88fecdebeb3bff8ce76 |
| --- /dev/null |
| +++ b/chrome/browser/resources/hterm/js/hterm.js |
| @@ -0,0 +1,159 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview Declares the hterm.* namespace and some basic shared utilities |
| + * that are too small to deserve dedicated files. |
| + */ |
| +var hterm = {}; |
| + |
| +/** |
| + * Clamp a given integer to a specified range. |
| + * |
| + * @param {integer} v The value to be clamped. |
| + * @param {integer} min The minimum acceptable value. |
| + * @param {integer} max The maximum acceptable value. |
| + */ |
| +hterm.clamp = function(v, min, max) { |
| + if (v < min) |
| + return min; |
| + if (v > max) |
| + return max; |
| + return v; |
| +}; |
| + |
| +/** |
| + * Return a string containing a given number of space characters. |
| + * |
| + * This method maintains a static cache of the largest amount of whitespace |
| + * ever requested. It shouldn't be used to generate an insanely huge amount of |
| + * whitespace. |
| + * |
| + * @param {integer} length The desired amount of whitespace. |
| + * @param {string} A string of spaces of the requested length. |
| + */ |
| +hterm.getWhitespace = function(length) { |
| + if (length == 0) |
| + return ''; |
| + |
| + var f = this.getWhitespace; |
| + if (!f.whitespace) |
| + f.whitespace = ' '; |
| + |
| + while (length > f.whitespace.length) { |
| + f.whitespace += f.whitespace; |
| + } |
| + |
| + return f.whitespace.substr(0, length); |
| +}; |
| + |
| +/** |
| + * Constructor for a hterm.Size record. |
| + * |
| + * Instances of this class have public read/write members for width and height. |
| + * |
| + * @param {integer} width The width of this record. |
| + * @param {integer} height The height of this record. |
| + */ |
| +hterm.Size = function(width, height) { |
| + this.width = width; |
| + this.height = height; |
| +}; |
| + |
| +/** |
| + * Adjust the width and height of this record. |
| + * |
| + * @param {integer} width The new width of this record. |
| + * @param {integer} height The new height of this record. |
| + */ |
| +hterm.Size.prototype.resize = function(width, height) { |
| + this.width = width; |
| + this.height = height; |
| +}; |
| + |
| +/** |
| + * Return a copy of this record. |
| + * |
| + * @return {hterm.Size} A new hterm.Size instance with the same width and |
| + * height. |
| + */ |
| +hterm.Size.prototype.clone = function() { |
| + return new hterm.Size(this.width, this.height); |
| +}; |
| + |
| +/** |
| + * Test if another hterm.Size instance is equal to this one. |
| + * |
| + * @param {hterm.Size} that The other hterm.Size instance. |
| + * @return {boolen} True if both instances have the same width/height, false |
| + * otherwise. |
| + */ |
| +hterm.Size.prototype.equals = function(that) { |
| + return this.width = that.width && this.height == that.height; |
| +}; |
| + |
| +/** |
| + * Return a string representation of this instance. |
| + * |
| + * @return {string} A string that identifies the width and height of this |
| + * instance. |
| + */ |
| +hterm.Size.prototype.toString = function() { |
| + return '[hterm.Size: ' + this.width + ', ' + this.height + ']'; |
| +}; |
| + |
| +/** |
| + * Constructor for a hterm.RowCol record. |
| + * |
| + * Instances of this class have public read/write members for row and column. |
| + * |
| + * @param {integer} row The row of this record. |
| + * @param {integer} column The column of this record. |
| + */ |
| +hterm.RowCol = function(row, column) { |
| + this.row = row; |
| + this.column = column; |
| +}; |
| + |
| +/** |
| + * Adjust the row and column of this record. |
| + * |
| + * @param {integer} row The new row of this record. |
| + * @param {integer} column The new column of this record. |
| + */ |
| +hterm.RowCol.prototype.move = function(row, column) { |
| + this.row = row; |
| + this.column = column; |
| +}; |
| + |
| +/** |
| + * Return a copy of this record. |
| + * |
| + * @return {hterm.RowCol} A new hterm.RowCol instance with the same row and |
| + * column. |
| + */ |
| +hterm.RowCol.prototype.clone = function() { |
| + return new hterm.RowCol(this.row, this.column); |
| +}; |
| + |
| +/** |
| + * Test if another hterm.RowCol instance is equal to this one. |
| + * |
| + * @param {hterm.RowCol} that The other hterm.RowCol instance. |
| + * @return {boolen} True if both instances have the same row/column, false |
| + * otherwise. |
| + */ |
| +hterm.RowCol.prototype.equals = function(that) { |
| + return this.row = that.row && this.column == that.column; |
|
mdhayter
2011/11/30 05:07:47
this.row == that.row?
|
| +}; |
| + |
| +/** |
| + * Return a string representation of this instance. |
| + * |
| + * @return {string} A string that identifies the row and column of this |
| + * instance. |
| + */ |
| +hterm.RowCol.prototype.toString = function() { |
| + return '[hterm.RowCol: ' + this.row + ', ' + this.column + ']'; |
| +}; |