2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @param {number} startLine
34 * @param {number} startColumn
35 * @param {number} endLine
36 * @param {number} endColumn
38 WebInspector.TextRange = function(startLine, startColumn, endLine, endColumn)
40 this.startLine = startLine;
41 this.startColumn = startColumn;
42 this.endLine = endLine;
43 this.endColumn = endColumn;
46 WebInspector.TextRange.createFromLocation = function(line, column)
48 return new WebInspector.TextRange(line, column, line, column);
52 * @param {!Object} serializedTextRange
53 * @return {!WebInspector.TextRange}
55 WebInspector.TextRange.fromObject = function(serializedTextRange)
57 return new WebInspector.TextRange(serializedTextRange.startLine, serializedTextRange.startColumn, serializedTextRange.endLine, serializedTextRange.endColumn);
60 WebInspector.TextRange.prototype = {
66 return this.startLine === this.endLine && this.startColumn === this.endColumn;
70 * @param {!WebInspector.TextRange} range
73 immediatelyPrecedes: function(range)
77 return this.endLine === range.startLine && this.endColumn === range.startColumn;
81 * @param {!WebInspector.TextRange} range
84 immediatelyFollows: function(range)
88 return range.immediatelyPrecedes(this);
96 return this.endLine - this.startLine;
100 * @return {!WebInspector.TextRange}
102 collapseToEnd: function()
104 return new WebInspector.TextRange(this.endLine, this.endColumn, this.endLine, this.endColumn);
108 * @return {!WebInspector.TextRange}
110 normalize: function()
112 if (this.startLine > this.endLine || (this.startLine === this.endLine && this.startColumn > this.endColumn))
113 return new WebInspector.TextRange(this.endLine, this.endColumn, this.startLine, this.startColumn);
119 * @return {!WebInspector.TextRange}
123 return new WebInspector.TextRange(this.startLine, this.startColumn, this.endLine, this.endColumn);
129 serializeToObject: function()
131 var serializedTextRange = {};
132 serializedTextRange.startLine = this.startLine;
133 serializedTextRange.startColumn = this.startColumn;
134 serializedTextRange.endLine = this.endLine;
135 serializedTextRange.endColumn = this.endColumn;
136 return serializedTextRange;
140 * @param {!WebInspector.TextRange} other
143 compareTo: function(other)
145 if (this.startLine > other.startLine)
147 if (this.startLine < other.startLine)
149 if (this.startColumn > other.startColumn)
151 if (this.startColumn < other.startColumn)
157 * @param {!WebInspector.TextRange} other
160 equal: function(other)
162 return this.startLine === other.startLine && this.endLine === other.endLine &&
163 this.startColumn === other.startColumn && this.endColumn === other.endColumn;
167 * @param {number} lineOffset
168 * @return {!WebInspector.TextRange}
170 shift: function(lineOffset)
172 return new WebInspector.TextRange(this.startLine + lineOffset, this.startColumn, this.endLine + lineOffset, this.endColumn);
180 return JSON.stringify(this);
186 * @param {number} offset
187 * @param {number} length
189 WebInspector.SourceRange = function(offset, length)
191 this.offset = offset;
192 this.length = length;