Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/EditingLocationHistoryManager.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
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 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 WebInspector.EditingLocationHistoryManager = class { 34 Sources.EditingLocationHistoryManager = class {
35 /** 35 /**
36 * @param {!WebInspector.SourcesView} sourcesView 36 * @param {!Sources.SourcesView} sourcesView
37 * @param {function():?WebInspector.SourceFrame} currentSourceFrameCallback 37 * @param {function():?SourceFrame.SourceFrame} currentSourceFrameCallback
38 */ 38 */
39 constructor(sourcesView, currentSourceFrameCallback) { 39 constructor(sourcesView, currentSourceFrameCallback) {
40 this._sourcesView = sourcesView; 40 this._sourcesView = sourcesView;
41 this._historyManager = 41 this._historyManager =
42 new WebInspector.SimpleHistoryManager(WebInspector.EditingLocationHistor yManager.HistoryDepth); 42 new Sources.SimpleHistoryManager(Sources.EditingLocationHistoryManager.H istoryDepth);
43 this._currentSourceFrameCallback = currentSourceFrameCallback; 43 this._currentSourceFrameCallback = currentSourceFrameCallback;
44 } 44 }
45 45
46 /** 46 /**
47 * @param {!WebInspector.UISourceCodeFrame} sourceFrame 47 * @param {!Sources.UISourceCodeFrame} sourceFrame
48 */ 48 */
49 trackSourceFrameCursorJumps(sourceFrame) { 49 trackSourceFrameCursorJumps(sourceFrame) {
50 sourceFrame.textEditor.addEventListener( 50 sourceFrame.textEditor.addEventListener(
51 WebInspector.SourcesTextEditor.Events.JumpHappened, this._onJumpHappened .bind(this)); 51 SourceFrame.SourcesTextEditor.Events.JumpHappened, this._onJumpHappened. bind(this));
52 } 52 }
53 53
54 /** 54 /**
55 * @param {!WebInspector.Event} event 55 * @param {!Common.Event} event
56 */ 56 */
57 _onJumpHappened(event) { 57 _onJumpHappened(event) {
58 if (event.data.from) 58 if (event.data.from)
59 this._updateActiveState(event.data.from); 59 this._updateActiveState(event.data.from);
60 if (event.data.to) 60 if (event.data.to)
61 this._pushActiveState(event.data.to); 61 this._pushActiveState(event.data.to);
62 } 62 }
63 63
64 rollback() { 64 rollback() {
65 this._historyManager.rollback(); 65 this._historyManager.rollback();
(...skipping 11 matching lines...) Expand all
77 } 77 }
78 78
79 pushNewState() { 79 pushNewState() {
80 var sourceFrame = this._currentSourceFrameCallback(); 80 var sourceFrame = this._currentSourceFrameCallback();
81 if (!sourceFrame) 81 if (!sourceFrame)
82 return; 82 return;
83 this._pushActiveState(sourceFrame.textEditor.selection()); 83 this._pushActiveState(sourceFrame.textEditor.selection());
84 } 84 }
85 85
86 /** 86 /**
87 * @param {!WebInspector.TextRange} selection 87 * @param {!Common.TextRange} selection
88 */ 88 */
89 _updateActiveState(selection) { 89 _updateActiveState(selection) {
90 var active = this._historyManager.active(); 90 var active = this._historyManager.active();
91 if (!active) 91 if (!active)
92 return; 92 return;
93 var sourceFrame = this._currentSourceFrameCallback(); 93 var sourceFrame = this._currentSourceFrameCallback();
94 if (!sourceFrame) 94 if (!sourceFrame)
95 return; 95 return;
96 var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesView, this, sourceFrame, selection); 96 var entry = new Sources.EditingLocationHistoryEntry(this._sourcesView, this, sourceFrame, selection);
97 active.merge(entry); 97 active.merge(entry);
98 } 98 }
99 99
100 /** 100 /**
101 * @param {!WebInspector.TextRange} selection 101 * @param {!Common.TextRange} selection
102 */ 102 */
103 _pushActiveState(selection) { 103 _pushActiveState(selection) {
104 var sourceFrame = this._currentSourceFrameCallback(); 104 var sourceFrame = this._currentSourceFrameCallback();
105 if (!sourceFrame) 105 if (!sourceFrame)
106 return; 106 return;
107 var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesView, this, sourceFrame, selection); 107 var entry = new Sources.EditingLocationHistoryEntry(this._sourcesView, this, sourceFrame, selection);
108 this._historyManager.push(entry); 108 this._historyManager.push(entry);
109 } 109 }
110 110
111 /** 111 /**
112 * @param {!WebInspector.UISourceCode} uiSourceCode 112 * @param {!Workspace.UISourceCode} uiSourceCode
113 */ 113 */
114 removeHistoryForSourceCode(uiSourceCode) { 114 removeHistoryForSourceCode(uiSourceCode) {
115 function filterOut(entry) { 115 function filterOut(entry) {
116 return entry._projectId === uiSourceCode.project().id() && entry._url === uiSourceCode.url(); 116 return entry._projectId === uiSourceCode.project().id() && entry._url === uiSourceCode.url();
117 } 117 }
118 118
119 this._historyManager.filterOut(filterOut); 119 this._historyManager.filterOut(filterOut);
120 } 120 }
121 }; 121 };
122 122
123 WebInspector.EditingLocationHistoryManager.HistoryDepth = 20; 123 Sources.EditingLocationHistoryManager.HistoryDepth = 20;
124 124
125 /** 125 /**
126 * @implements {WebInspector.HistoryEntry} 126 * @implements {Sources.HistoryEntry}
127 * @unrestricted 127 * @unrestricted
128 */ 128 */
129 WebInspector.EditingLocationHistoryEntry = class { 129 Sources.EditingLocationHistoryEntry = class {
130 /** 130 /**
131 * @param {!WebInspector.SourcesView} sourcesView 131 * @param {!Sources.SourcesView} sourcesView
132 * @param {!WebInspector.EditingLocationHistoryManager} editingLocationManager 132 * @param {!Sources.EditingLocationHistoryManager} editingLocationManager
133 * @param {!WebInspector.SourceFrame} sourceFrame 133 * @param {!SourceFrame.SourceFrame} sourceFrame
134 * @param {!WebInspector.TextRange} selection 134 * @param {!Common.TextRange} selection
135 */ 135 */
136 constructor(sourcesView, editingLocationManager, sourceFrame, selection) { 136 constructor(sourcesView, editingLocationManager, sourceFrame, selection) {
137 this._sourcesView = sourcesView; 137 this._sourcesView = sourcesView;
138 this._editingLocationManager = editingLocationManager; 138 this._editingLocationManager = editingLocationManager;
139 var uiSourceCode = sourceFrame.uiSourceCode(); 139 var uiSourceCode = sourceFrame.uiSourceCode();
140 this._projectId = uiSourceCode.project().id(); 140 this._projectId = uiSourceCode.project().id();
141 this._url = uiSourceCode.url(); 141 this._url = uiSourceCode.url();
142 142
143 var position = this._positionFromSelection(selection); 143 var position = this._positionFromSelection(selection);
144 this._positionHandle = sourceFrame.textEditor.textEditorPositionHandle(posit ion.lineNumber, position.columnNumber); 144 this._positionHandle = sourceFrame.textEditor.textEditorPositionHandle(posit ion.lineNumber, position.columnNumber);
145 } 145 }
146 146
147 /** 147 /**
148 * @param {!WebInspector.HistoryEntry} entry 148 * @param {!Sources.HistoryEntry} entry
149 */ 149 */
150 merge(entry) { 150 merge(entry) {
151 if (this._projectId !== entry._projectId || this._url !== entry._url) 151 if (this._projectId !== entry._projectId || this._url !== entry._url)
152 return; 152 return;
153 this._positionHandle = entry._positionHandle; 153 this._positionHandle = entry._positionHandle;
154 } 154 }
155 155
156 /** 156 /**
157 * @param {!WebInspector.TextRange} selection 157 * @param {!Common.TextRange} selection
158 * @return {!{lineNumber: number, columnNumber: number}} 158 * @return {!{lineNumber: number, columnNumber: number}}
159 */ 159 */
160 _positionFromSelection(selection) { 160 _positionFromSelection(selection) {
161 return {lineNumber: selection.endLine, columnNumber: selection.endColumn}; 161 return {lineNumber: selection.endLine, columnNumber: selection.endColumn};
162 } 162 }
163 163
164 /** 164 /**
165 * @override 165 * @override
166 * @return {boolean} 166 * @return {boolean}
167 */ 167 */
168 valid() { 168 valid() {
169 var position = this._positionHandle.resolve(); 169 var position = this._positionHandle.resolve();
170 var uiSourceCode = WebInspector.workspace.uiSourceCode(this._projectId, this ._url); 170 var uiSourceCode = Workspace.workspace.uiSourceCode(this._projectId, this._u rl);
171 return !!(position && uiSourceCode); 171 return !!(position && uiSourceCode);
172 } 172 }
173 173
174 /** 174 /**
175 * @override 175 * @override
176 */ 176 */
177 reveal() { 177 reveal() {
178 var position = this._positionHandle.resolve(); 178 var position = this._positionHandle.resolve();
179 var uiSourceCode = WebInspector.workspace.uiSourceCode(this._projectId, this ._url); 179 var uiSourceCode = Workspace.workspace.uiSourceCode(this._projectId, this._u rl);
180 if (!position || !uiSourceCode) 180 if (!position || !uiSourceCode)
181 return; 181 return;
182 182
183 this._editingLocationManager.updateCurrentState(); 183 this._editingLocationManager.updateCurrentState();
184 this._sourcesView.showSourceLocation(uiSourceCode, position.lineNumber, posi tion.columnNumber); 184 this._sourcesView.showSourceLocation(uiSourceCode, position.lineNumber, posi tion.columnNumber);
185 } 185 }
186 }; 186 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698