| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 /** | 30 /** |
| 31 * @interface | 31 * @interface |
| 32 */ | 32 */ |
| 33 WebInspector.HistoryEntry = function() {}; | 33 Sources.HistoryEntry = function() {}; |
| 34 | 34 |
| 35 WebInspector.HistoryEntry.prototype = { | 35 Sources.HistoryEntry.prototype = { |
| 36 /** | 36 /** |
| 37 * @return {boolean} | 37 * @return {boolean} |
| 38 */ | 38 */ |
| 39 valid: function() {}, | 39 valid: function() {}, |
| 40 | 40 |
| 41 reveal: function() {} | 41 reveal: function() {} |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 /** | 44 /** |
| 45 * @unrestricted | 45 * @unrestricted |
| 46 */ | 46 */ |
| 47 WebInspector.SimpleHistoryManager = class { | 47 Sources.SimpleHistoryManager = class { |
| 48 /** | 48 /** |
| 49 * @param {number} historyDepth | 49 * @param {number} historyDepth |
| 50 */ | 50 */ |
| 51 constructor(historyDepth) { | 51 constructor(historyDepth) { |
| 52 this._entries = []; | 52 this._entries = []; |
| 53 this._activeEntryIndex = -1; | 53 this._activeEntryIndex = -1; |
| 54 this._coalescingReadonly = 0; | 54 this._coalescingReadonly = 0; |
| 55 this._historyDepth = historyDepth; | 55 this._historyDepth = historyDepth; |
| 56 } | 56 } |
| 57 | 57 |
| 58 readOnlyLock() { | 58 readOnlyLock() { |
| 59 ++this._coalescingReadonly; | 59 ++this._coalescingReadonly; |
| 60 } | 60 } |
| 61 | 61 |
| 62 releaseReadOnlyLock() { | 62 releaseReadOnlyLock() { |
| 63 --this._coalescingReadonly; | 63 --this._coalescingReadonly; |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * @return {boolean} | 67 * @return {boolean} |
| 68 */ | 68 */ |
| 69 readOnly() { | 69 readOnly() { |
| 70 return !!this._coalescingReadonly; | 70 return !!this._coalescingReadonly; |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * @param {function(!WebInspector.HistoryEntry):boolean} filterOutCallback | 74 * @param {function(!Sources.HistoryEntry):boolean} filterOutCallback |
| 75 */ | 75 */ |
| 76 filterOut(filterOutCallback) { | 76 filterOut(filterOutCallback) { |
| 77 if (this.readOnly()) | 77 if (this.readOnly()) |
| 78 return; | 78 return; |
| 79 var filteredEntries = []; | 79 var filteredEntries = []; |
| 80 var removedBeforeActiveEntry = 0; | 80 var removedBeforeActiveEntry = 0; |
| 81 for (var i = 0; i < this._entries.length; ++i) { | 81 for (var i = 0; i < this._entries.length; ++i) { |
| 82 if (!filterOutCallback(this._entries[i])) { | 82 if (!filterOutCallback(this._entries[i])) { |
| 83 filteredEntries.push(this._entries[i]); | 83 filteredEntries.push(this._entries[i]); |
| 84 } else if (i <= this._activeEntryIndex) | 84 } else if (i <= this._activeEntryIndex) |
| 85 ++removedBeforeActiveEntry; | 85 ++removedBeforeActiveEntry; |
| 86 } | 86 } |
| 87 this._entries = filteredEntries; | 87 this._entries = filteredEntries; |
| 88 this._activeEntryIndex = Math.max(0, this._activeEntryIndex - removedBeforeA
ctiveEntry); | 88 this._activeEntryIndex = Math.max(0, this._activeEntryIndex - removedBeforeA
ctiveEntry); |
| 89 } | 89 } |
| 90 | 90 |
| 91 /** | 91 /** |
| 92 * @return {boolean} | 92 * @return {boolean} |
| 93 */ | 93 */ |
| 94 empty() { | 94 empty() { |
| 95 return !this._entries.length; | 95 return !this._entries.length; |
| 96 } | 96 } |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * @return {?WebInspector.HistoryEntry} | 99 * @return {?Sources.HistoryEntry} |
| 100 */ | 100 */ |
| 101 active() { | 101 active() { |
| 102 return this.empty() ? null : this._entries[this._activeEntryIndex]; | 102 return this.empty() ? null : this._entries[this._activeEntryIndex]; |
| 103 } | 103 } |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * @param {!WebInspector.HistoryEntry} entry | 106 * @param {!Sources.HistoryEntry} entry |
| 107 */ | 107 */ |
| 108 push(entry) { | 108 push(entry) { |
| 109 if (this.readOnly()) | 109 if (this.readOnly()) |
| 110 return; | 110 return; |
| 111 if (!this.empty()) | 111 if (!this.empty()) |
| 112 this._entries.splice(this._activeEntryIndex + 1); | 112 this._entries.splice(this._activeEntryIndex + 1); |
| 113 this._entries.push(entry); | 113 this._entries.push(entry); |
| 114 if (this._entries.length > this._historyDepth) | 114 if (this._entries.length > this._historyDepth) |
| 115 this._entries.shift(); | 115 this._entries.shift(); |
| 116 this._activeEntryIndex = this._entries.length - 1; | 116 this._activeEntryIndex = this._entries.length - 1; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 return false; | 149 return false; |
| 150 | 150 |
| 151 this.readOnlyLock(); | 151 this.readOnlyLock(); |
| 152 this._entries[revealIndex].reveal(); | 152 this._entries[revealIndex].reveal(); |
| 153 this.releaseReadOnlyLock(); | 153 this.releaseReadOnlyLock(); |
| 154 | 154 |
| 155 this._activeEntryIndex = revealIndex; | 155 this._activeEntryIndex = revealIndex; |
| 156 return true; | 156 return true; |
| 157 } | 157 } |
| 158 }; | 158 }; |
| OLD | NEW |