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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/source_frame/SourceFrame.js

Issue 1830003002: [DevTools] SourceFrame implements Search interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
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 /** 31 /**
32 * @implements {WebInspector.Searchable}
32 * @extends {WebInspector.VBoxWithToolbarItems} 33 * @extends {WebInspector.VBoxWithToolbarItems}
33 * @constructor 34 * @constructor
34 * @implements {WebInspector.Replaceable} 35 * @implements {WebInspector.Replaceable}
35 * @param {!WebInspector.ContentProvider} contentProvider 36 * @param {!WebInspector.ContentProvider} contentProvider
36 */ 37 */
37 WebInspector.SourceFrame = function(contentProvider) 38 WebInspector.SourceFrame = function(contentProvider)
38 { 39 {
39 WebInspector.VBoxWithToolbarItems.call(this); 40 WebInspector.VBoxWithToolbarItems.call(this);
40 41
41 this._url = contentProvider.contentURL(); 42 this._url = contentProvider.contentURL();
42 this._contentProvider = contentProvider; 43 this._contentProvider = contentProvider;
43 44
44 var textEditorDelegate = new WebInspector.TextEditorDelegateForSourceFrame(t his); 45 var textEditorDelegate = new WebInspector.TextEditorDelegateForSourceFrame(t his);
45 46
46 this._textEditor = new WebInspector.CodeMirrorTextEditor(this._url, textEdit orDelegate); 47 this._textEditor = new WebInspector.CodeMirrorTextEditor(this._url, textEdit orDelegate);
47 48
48 this._currentSearchResultIndex = -1; 49 this._currentSearchResultIndex = -1;
49 this._searchResults = []; 50 this._searchResults = [];
50 51
51 this._textEditor.setReadOnly(!this.canEditSource()); 52 this._textEditor.setReadOnly(!this.canEditSource());
52 53
53 this._shortcuts = {}; 54 this._shortcuts = {};
54 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), fal se); 55 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), fal se);
55 56
56 this._sourcePosition = new WebInspector.ToolbarText(); 57 this._sourcePosition = new WebInspector.ToolbarText();
58
59 /**
60 * @type {?WebInspector.SearchableView}
61 */
62 this._searchableView = null;
57 } 63 }
58 64
59 WebInspector.SourceFrame.Events = { 65 WebInspector.SourceFrame.Events = {
60 ScrollChanged: "ScrollChanged", 66 ScrollChanged: "ScrollChanged",
61 SelectionChanged: "SelectionChanged", 67 SelectionChanged: "SelectionChanged",
62 JumpHappened: "JumpHappened" 68 JumpHappened: "JumpHappened"
63 } 69 }
64 70
65 WebInspector.SourceFrame.prototype = { 71 WebInspector.SourceFrame.prototype = {
66 /** 72 /**
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 this._innerSetSelectionIfNeeded(); 229 this._innerSetSelectionIfNeeded();
224 this._innerScrollToLineIfNeeded(); 230 this._innerScrollToLineIfNeeded();
225 }, 231 },
226 232
227 /** 233 /**
228 * @param {!WebInspector.TextRange} oldRange 234 * @param {!WebInspector.TextRange} oldRange
229 * @param {!WebInspector.TextRange} newRange 235 * @param {!WebInspector.TextRange} newRange
230 */ 236 */
231 onTextChanged: function(oldRange, newRange) 237 onTextChanged: function(oldRange, newRange)
232 { 238 {
233 if (this._searchResultsChangedCallback) 239 if (this._searchConfig && this._searchableView)
234 this._searchResultsChangedCallback(); 240 this.performSearch(this._searchConfig, false, false);
235 }, 241 },
236 242
237 /** 243 /**
238 * @param {string} content 244 * @param {string} content
239 * @param {string} mimeType 245 * @param {string} mimeType
240 * @return {string} 246 * @return {string}
241 */ 247 */
242 _simplifyMimeType: function(content, mimeType) 248 _simplifyMimeType: function(content, mimeType)
243 { 249 {
244 if (!mimeType) 250 if (!mimeType)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (this._delayedFindSearchMatches) { 299 if (this._delayedFindSearchMatches) {
294 this._delayedFindSearchMatches(); 300 this._delayedFindSearchMatches();
295 delete this._delayedFindSearchMatches; 301 delete this._delayedFindSearchMatches;
296 } 302 }
297 this.onTextEditorContentLoaded(); 303 this.onTextEditorContentLoaded();
298 }, 304 },
299 305
300 onTextEditorContentLoaded: function() {}, 306 onTextEditorContentLoaded: function() {},
301 307
302 /** 308 /**
309 * @param {?WebInspector.SearchableView} view
310 */
311 setSearchableView: function(view)
312 {
313 this._searchableView = view;
314 },
315
316 /**
303 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig 317 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
304 * @param {boolean} shouldJump 318 * @param {boolean} shouldJump
305 * @param {boolean} jumpBackwards 319 * @param {boolean} jumpBackwards
306 * @param {function(!WebInspector.Widget, number)} searchFinishedCallback
307 */ 320 */
308 _doFindSearchMatches: function(searchConfig, shouldJump, jumpBackwards, sear chFinishedCallback) 321 _doFindSearchMatches: function(searchConfig, shouldJump, jumpBackwards)
309 { 322 {
310 this._currentSearchResultIndex = -1; 323 this._currentSearchResultIndex = -1;
311 this._searchResults = []; 324 this._searchResults = [];
312 325
313 var regex = searchConfig.toSearchRegex(); 326 var regex = searchConfig.toSearchRegex();
314 this._searchRegex = regex; 327 this._searchRegex = regex;
315 this._searchResults = this._collectRegexMatches(regex); 328 this._searchResults = this._collectRegexMatches(regex);
316 searchFinishedCallback(this, this._searchResults.length); 329
330 this._searchableView.updateSearchMatchesCount(this._searchResults.length );
331
317 if (!this._searchResults.length) 332 if (!this._searchResults.length)
318 this._textEditor.cancelSearchResultsHighlight(); 333 this._textEditor.cancelSearchResultsHighlight();
319 else if (shouldJump && jumpBackwards) 334 else if (shouldJump && jumpBackwards)
320 this.jumpToPreviousSearchResult(); 335 this.jumpToPreviousSearchResult();
321 else if (shouldJump) 336 else if (shouldJump)
322 this.jumpToNextSearchResult(); 337 this.jumpToNextSearchResult();
323 else 338 else
324 this._textEditor.highlightSearchResults(regex, null); 339 this._textEditor.highlightSearchResults(regex, null);
325 }, 340 },
326 341
327 /** 342 /**
343 * @override
328 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig 344 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
329 * @param {boolean} shouldJump 345 * @param {boolean} shouldJump
330 * @param {boolean} jumpBackwards 346 * @param {boolean=} jumpBackwards
331 * @param {function(!WebInspector.Widget, number)} searchFinishedCallback
332 * @param {function(number)} currentMatchChangedCallback
333 * @param {function()} searchResultsChangedCallback
334 */ 347 */
335 performSearch: function(searchConfig, shouldJump, jumpBackwards, searchFinis hedCallback, currentMatchChangedCallback, searchResultsChangedCallback) 348 performSearch: function(searchConfig, shouldJump, jumpBackwards)
336 { 349 {
350 if (this._searchableView)
351 this._searchableView.updateSearchMatchesCount(0);
352
337 this._resetSearch(); 353 this._resetSearch();
338 this._currentSearchMatchChangedCallback = currentMatchChangedCallback; 354 this._searchConfig = searchConfig;
339 this._searchResultsChangedCallback = searchResultsChangedCallback;
340 var searchFunction = this._doFindSearchMatches.bind(this, searchConfig, shouldJump, jumpBackwards, searchFinishedCallback);
341 if (this.loaded) 355 if (this.loaded)
342 searchFunction.call(this); 356 this._doFindSearchMatches(searchConfig, shouldJump, !!jumpBackwards)
343 else 357 else
344 this._delayedFindSearchMatches = searchFunction; 358 this._delayedFindSearchMatches = this._doFindSearchMatches.bind(this , searchConfig, shouldJump, !!jumpBackwards);
345 359
346 this._ensureContentLoaded(); 360 this._ensureContentLoaded();
347 }, 361 },
348 362
349 _editorFocused: function() 363 _editorFocused: function()
350 { 364 {
351 this._resetCurrentSearchResultIndex(); 365 this._resetCurrentSearchResultIndex();
352 }, 366 },
353 367
354 _resetCurrentSearchResultIndex: function() 368 _resetCurrentSearchResultIndex: function()
355 { 369 {
356 if (!this._searchResults.length) 370 if (!this._searchResults.length)
357 return; 371 return;
358 this._currentSearchResultIndex = -1; 372 this._currentSearchResultIndex = -1;
359 if (this._currentSearchMatchChangedCallback) 373 if (this._searchableView)
360 this._currentSearchMatchChangedCallback(this._currentSearchResultInd ex); 374 this._searchableView.updateCurrentMatchIndex(this._currentSearchResu ltIndex);
361 this._textEditor.highlightSearchResults(this._searchRegex, null); 375 this._textEditor.highlightSearchResults(this._searchRegex, null);
362 }, 376 },
363 377
364 _resetSearch: function() 378 _resetSearch: function()
365 { 379 {
380 delete this._searchConfig;
366 delete this._delayedFindSearchMatches; 381 delete this._delayedFindSearchMatches;
367 delete this._currentSearchMatchChangedCallback;
368 delete this._searchResultsChangedCallback;
369 this._currentSearchResultIndex = -1; 382 this._currentSearchResultIndex = -1;
370 this._searchResults = []; 383 this._searchResults = [];
371 delete this._searchRegex; 384 delete this._searchRegex;
372 }, 385 },
373 386
387 /**
388 * @override
389 */
374 searchCanceled: function() 390 searchCanceled: function()
375 { 391 {
376 var range = this._currentSearchResultIndex !== -1 ? this._searchResults[ this._currentSearchResultIndex] : null; 392 var range = this._currentSearchResultIndex !== -1 ? this._searchResults[ this._currentSearchResultIndex] : null;
377 this._resetSearch(); 393 this._resetSearch();
378 if (!this.loaded) 394 if (!this.loaded)
379 return; 395 return;
380 this._textEditor.cancelSearchResultsHighlight(); 396 this._textEditor.cancelSearchResultsHighlight();
381 if (range) 397 if (range)
382 this.setSelection(range); 398 this.setSelection(range);
383 }, 399 },
(...skipping 17 matching lines...) Expand all
401 }, 417 },
402 418
403 /** 419 /**
404 * @return {number} 420 * @return {number}
405 */ 421 */
406 _searchResultIndexForCurrentSelection: function() 422 _searchResultIndexForCurrentSelection: function()
407 { 423 {
408 return this._searchResults.lowerBound(this._textEditor.selection().colla pseToEnd(), WebInspector.TextRange.comparator); 424 return this._searchResults.lowerBound(this._textEditor.selection().colla pseToEnd(), WebInspector.TextRange.comparator);
409 }, 425 },
410 426
427 /**
428 * @override
429 */
411 jumpToNextSearchResult: function() 430 jumpToNextSearchResult: function()
412 { 431 {
413 var currentIndex = this._searchResultIndexForCurrentSelection(); 432 var currentIndex = this._searchResultIndexForCurrentSelection();
414 var nextIndex = this._currentSearchResultIndex === -1 ? currentIndex : c urrentIndex + 1; 433 var nextIndex = this._currentSearchResultIndex === -1 ? currentIndex : c urrentIndex + 1;
415 this.jumpToSearchResult(nextIndex); 434 this.jumpToSearchResult(nextIndex);
416 }, 435 },
417 436
437 /**
438 * @override
439 */
418 jumpToPreviousSearchResult: function() 440 jumpToPreviousSearchResult: function()
419 { 441 {
420 var currentIndex = this._searchResultIndexForCurrentSelection(); 442 var currentIndex = this._searchResultIndexForCurrentSelection();
421 this.jumpToSearchResult(currentIndex - 1); 443 this.jumpToSearchResult(currentIndex - 1);
422 }, 444 },
423 445
446 /**
447 * @override
448 * @return {boolean}
449 */
450 supportsCaseSensitiveSearch: function ()
451 {
452 return true;
453 },
454
455 /**
456 * @override
457 * @return {boolean}
458 */
459 supportsRegexSearch: function()
460 {
461 return true;
462 },
463
424 get currentSearchResultIndex() 464 get currentSearchResultIndex()
425 { 465 {
426 return this._currentSearchResultIndex; 466 return this._currentSearchResultIndex;
427 }, 467 },
428 468
429 jumpToSearchResult: function(index) 469 jumpToSearchResult: function(index)
430 { 470 {
431 if (!this.loaded || !this._searchResults.length) 471 if (!this.loaded || !this._searchResults.length)
432 return; 472 return;
433 this._currentSearchResultIndex = (index + this._searchResults.length) % this._searchResults.length; 473 this._currentSearchResultIndex = (index + this._searchResults.length) % this._searchResults.length;
434 if (this._currentSearchMatchChangedCallback) 474 if (this._searchableView)
435 this._currentSearchMatchChangedCallback(this._currentSearchResultInd ex); 475 this._searchableView.updateCurrentMatchIndex(this._currentSearchResu ltIndex);
436 this._textEditor.highlightSearchResults(this._searchRegex, this._searchR esults[this._currentSearchResultIndex]); 476 this._textEditor.highlightSearchResults(this._searchRegex, this._searchR esults[this._currentSearchResultIndex]);
437 }, 477 },
438 478
439 /** 479 /**
440 * @override 480 * @override
441 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig 481 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
442 * @param {string} replacement 482 * @param {string} replacement
443 */ 483 */
444 replaceSelectionWith: function(searchConfig, replacement) 484 replaceSelectionWith: function(searchConfig, replacement)
445 { 485 {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 /** 718 /**
679 * @override 719 * @override
680 * @param {?WebInspector.TextRange} from 720 * @param {?WebInspector.TextRange} from
681 * @param {?WebInspector.TextRange} to 721 * @param {?WebInspector.TextRange} to
682 */ 722 */
683 onJumpToPosition: function(from, to) 723 onJumpToPosition: function(from, to)
684 { 724 {
685 this._sourceFrame.onJumpToPosition(from, to); 725 this._sourceFrame.onJumpToPosition(from, to);
686 } 726 }
687 } 727 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698