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

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

Issue 2238883004: DevTools: Split off SourcesTextEditor from CodeMirrorTextEditor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 15 matching lines...) Expand all
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 * @constructor 32 * @constructor
33 * @extends {WebInspector.SimpleView} 33 * @extends {WebInspector.SimpleView}
34 * @implements {WebInspector.Searchable} 34 * @implements {WebInspector.Searchable}
35 * @implements {WebInspector.Replaceable} 35 * @implements {WebInspector.Replaceable}
36 * @implements {WebInspector.SourcesTextEditorDelegate}
36 * @param {string} url 37 * @param {string} url
37 * @param {function(): !Promise<?string>} lazyContent 38 * @param {function(): !Promise<?string>} lazyContent
38 */ 39 */
39 WebInspector.SourceFrame = function(url, lazyContent) 40 WebInspector.SourceFrame = function(url, lazyContent)
40 { 41 {
41 WebInspector.SimpleView.call(this, WebInspector.UIString("Source")); 42 WebInspector.SimpleView.call(this, WebInspector.UIString("Source"));
42 43
43 this._url = url; 44 this._url = url;
44 this._lazyContent = lazyContent; 45 this._lazyContent = lazyContent;
45 46
46 var textEditorDelegate = new WebInspector.TextEditorDelegateForSourceFrame(t his); 47 this._textEditor = new WebInspector.SourcesTextEditor(this);
47
48 this._textEditor = new WebInspector.CodeMirrorTextEditor(this._url, textEdit orDelegate);
49 48
50 this._currentSearchResultIndex = -1; 49 this._currentSearchResultIndex = -1;
51 this._searchResults = []; 50 this._searchResults = [];
52 51
53 this._textEditor.setReadOnly(!this.canEditSource()); 52 this._textEditor.setReadOnly(!this.canEditSource());
54 53
55 this._shortcuts = {}; 54 this._shortcuts = {};
56 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), fal se); 55 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), fal se);
57 56
58 this._sourcePosition = new WebInspector.ToolbarText(); 57 this._sourcePosition = new WebInspector.ToolbarText();
(...skipping 13 matching lines...) Expand all
72 WebInspector.SourceFrame.prototype = { 71 WebInspector.SourceFrame.prototype = {
73 /** 72 /**
74 * @param {number} key 73 * @param {number} key
75 * @param {function():boolean} handler 74 * @param {function():boolean} handler
76 */ 75 */
77 addShortcut: function(key, handler) 76 addShortcut: function(key, handler)
78 { 77 {
79 this._shortcuts[key] = handler; 78 this._shortcuts[key] = handler;
80 }, 79 },
81 80
81 /**
82 * @override
83 */
82 wasShown: function() 84 wasShown: function()
83 { 85 {
84 this._ensureContentLoaded(); 86 this._ensureContentLoaded();
85 this._textEditor.show(this.element); 87 this._textEditor.show(this.element);
86 this._editorAttached = true; 88 this._editorAttached = true;
87 this._wasShownOrLoaded(); 89 this._wasShownOrLoaded();
88 }, 90 },
89 91
90 /** 92 /**
91 * @return {boolean} 93 * @return {boolean}
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 }, 218 },
217 219
218 _wasShownOrLoaded: function() 220 _wasShownOrLoaded: function()
219 { 221 {
220 this._innerRevealPositionIfNeeded(); 222 this._innerRevealPositionIfNeeded();
221 this._innerSetSelectionIfNeeded(); 223 this._innerSetSelectionIfNeeded();
222 this._innerScrollToLineIfNeeded(); 224 this._innerScrollToLineIfNeeded();
223 }, 225 },
224 226
225 /** 227 /**
228 * @override
226 * @param {!WebInspector.TextRange} oldRange 229 * @param {!WebInspector.TextRange} oldRange
227 * @param {!WebInspector.TextRange} newRange 230 * @param {!WebInspector.TextRange} newRange
228 */ 231 */
229 onTextChanged: function(oldRange, newRange) 232 onTextChanged: function(oldRange, newRange)
230 { 233 {
231 if (this._searchConfig && this._searchableView) 234 if (this._searchConfig && this._searchableView)
232 this.performSearch(this._searchConfig, false, false); 235 this.performSearch(this._searchConfig, false, false);
233 }, 236 },
234 237
235 /** 238 /**
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 this._resetSearch(); 349 this._resetSearch();
347 this._searchConfig = searchConfig; 350 this._searchConfig = searchConfig;
348 if (this.loaded) 351 if (this.loaded)
349 this._doFindSearchMatches(searchConfig, shouldJump, !!jumpBackwards) 352 this._doFindSearchMatches(searchConfig, shouldJump, !!jumpBackwards)
350 else 353 else
351 this._delayedFindSearchMatches = this._doFindSearchMatches.bind(this , searchConfig, shouldJump, !!jumpBackwards); 354 this._delayedFindSearchMatches = this._doFindSearchMatches.bind(this , searchConfig, shouldJump, !!jumpBackwards);
352 355
353 this._ensureContentLoaded(); 356 this._ensureContentLoaded();
354 }, 357 },
355 358
356 _editorFocused: function() 359 /**
360 * @override
361 */
362 editorFocused: function()
357 { 363 {
358 this._resetCurrentSearchResultIndex(); 364 this._resetCurrentSearchResultIndex();
359 }, 365 },
360 366
361 _resetCurrentSearchResultIndex: function() 367 _resetCurrentSearchResultIndex: function()
362 { 368 {
363 if (!this._searchResults.length) 369 if (!this._searchResults.length)
364 return; 370 return;
365 this._currentSearchResultIndex = -1; 371 this._currentSearchResultIndex = -1;
366 if (this._searchableView) 372 if (this._searchableView)
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 ranges.push(new WebInspector.TextRange(i, offset + match .index, i, offset + matchEndIndex)); 551 ranges.push(new WebInspector.TextRange(i, offset + match .index, i, offset + matchEndIndex));
546 offset += matchEndIndex; 552 offset += matchEndIndex;
547 line = line.substring(matchEndIndex); 553 line = line.substring(matchEndIndex);
548 } 554 }
549 } while (match && line); 555 } while (match && line);
550 } 556 }
551 return ranges; 557 return ranges;
552 }, 558 },
553 559
554 /** 560 /**
561 * @override
555 * @return {!Promise} 562 * @return {!Promise}
556 */ 563 */
557 populateLineGutterContextMenu: function(contextMenu, lineNumber) 564 populateLineGutterContextMenu: function(contextMenu, lineNumber)
558 { 565 {
559 return Promise.resolve(); 566 return Promise.resolve();
560 }, 567 },
561 568
562 /** 569 /**
570 * @override
563 * @return {!Promise} 571 * @return {!Promise}
564 */ 572 */
565 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber) 573 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber)
566 { 574 {
567 return Promise.resolve(); 575 return Promise.resolve();
568 }, 576 },
569 577
570 /** 578 /**
579 * @override
571 * @param {?WebInspector.TextRange} from 580 * @param {?WebInspector.TextRange} from
572 * @param {?WebInspector.TextRange} to 581 * @param {?WebInspector.TextRange} to
573 */ 582 */
574 onJumpToPosition: function(from, to) 583 onJumpToPosition: function(from, to)
575 { 584 {
576 this.dispatchEventToListeners(WebInspector.SourceFrame.Events.JumpHappen ed, { 585 this.dispatchEventToListeners(WebInspector.SourceFrame.Events.JumpHappen ed, {
577 from: from, 586 from: from,
578 to: to 587 to: to
579 }); 588 });
580 }, 589 },
581 590
582 /** 591 /**
583 * @return {boolean} 592 * @return {boolean}
584 */ 593 */
585 canEditSource: function() 594 canEditSource: function()
586 { 595 {
587 return false; 596 return false;
588 }, 597 },
589 598
590 /** 599 /**
600 * @override
591 * @param {!WebInspector.TextRange} textRange 601 * @param {!WebInspector.TextRange} textRange
592 */ 602 */
593 selectionChanged: function(textRange) 603 selectionChanged: function(textRange)
594 { 604 {
595 this._updateSourcePosition(); 605 this._updateSourcePosition();
596 this.dispatchEventToListeners(WebInspector.SourceFrame.Events.SelectionC hanged, textRange); 606 this.dispatchEventToListeners(WebInspector.SourceFrame.Events.SelectionC hanged, textRange);
597 WebInspector.notifications.dispatchEventToListeners(WebInspector.SourceF rame.Events.SelectionChanged, textRange); 607 WebInspector.notifications.dispatchEventToListeners(WebInspector.SourceF rame.Events.SelectionChanged, textRange);
598 }, 608 },
599 609
600 _updateSourcePosition: function() 610 _updateSourcePosition: function()
(...skipping 13 matching lines...) Expand all
614 textRange = textRange.normalize(); 624 textRange = textRange.normalize();
615 625
616 var selectedText = this._textEditor.copyRange(textRange); 626 var selectedText = this._textEditor.copyRange(textRange);
617 if (textRange.startLine === textRange.endLine) 627 if (textRange.startLine === textRange.endLine)
618 this._sourcePosition.setText(WebInspector.UIString("%d characters se lected", selectedText.length)); 628 this._sourcePosition.setText(WebInspector.UIString("%d characters se lected", selectedText.length));
619 else 629 else
620 this._sourcePosition.setText(WebInspector.UIString("%d lines, %d cha racters selected", textRange.endLine - textRange.startLine + 1, selectedText.len gth)); 630 this._sourcePosition.setText(WebInspector.UIString("%d lines, %d cha racters selected", textRange.endLine - textRange.startLine + 1, selectedText.len gth));
621 }, 631 },
622 632
623 /** 633 /**
634 * @override
624 * @param {number} lineNumber 635 * @param {number} lineNumber
625 */ 636 */
626 scrollChanged: function(lineNumber) 637 scrollChanged: function(lineNumber)
627 { 638 {
628 if (this._scrollTimer) 639 if (this._scrollTimer)
629 clearTimeout(this._scrollTimer); 640 clearTimeout(this._scrollTimer);
630 this._scrollTimer = setTimeout(this.dispatchEventToListeners.bind(this, WebInspector.SourceFrame.Events.ScrollChanged, lineNumber), 100); 641 this._scrollTimer = setTimeout(this.dispatchEventToListeners.bind(this, WebInspector.SourceFrame.Events.ScrollChanged, lineNumber), 100);
631 }, 642 },
632 643
633 _handleKeyDown: function(e) 644 _handleKeyDown: function(e)
634 { 645 {
635 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e); 646 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e);
636 var handler = this._shortcuts[shortcutKey]; 647 var handler = this._shortcuts[shortcutKey];
637 if (handler && handler()) 648 if (handler && handler())
638 e.consume(true); 649 e.consume(true);
639 }, 650 },
640 651
641 __proto__: WebInspector.SimpleView.prototype 652 __proto__: WebInspector.SimpleView.prototype
642 } 653 }
643
644 /**
645 * @implements {WebInspector.TextEditorDelegate}
646 * @constructor
647 */
648 WebInspector.TextEditorDelegateForSourceFrame = function(sourceFrame)
649 {
650 this._sourceFrame = sourceFrame;
651 }
652
653 WebInspector.TextEditorDelegateForSourceFrame.prototype = {
654 /**
655 * @override
656 * @param {!WebInspector.TextRange} oldRange
657 * @param {!WebInspector.TextRange} newRange
658 */
659 onTextChanged: function(oldRange, newRange)
660 {
661 this._sourceFrame.onTextChanged(oldRange, newRange);
662 },
663
664 /**
665 * @override
666 * @param {!WebInspector.TextRange} textRange
667 */
668 selectionChanged: function(textRange)
669 {
670 this._sourceFrame.selectionChanged(textRange);
671 },
672
673 /**
674 * @override
675 * @param {number} lineNumber
676 */
677 scrollChanged: function(lineNumber)
678 {
679 this._sourceFrame.scrollChanged(lineNumber);
680 },
681
682 /**
683 * @override
684 */
685 editorFocused: function()
686 {
687 this._sourceFrame._editorFocused();
688 },
689
690 /**
691 * @override
692 * @param {!WebInspector.ContextMenu} contextMenu
693 * @param {number} lineNumber
694 * @return {!Promise}
695 */
696 populateLineGutterContextMenu: function(contextMenu, lineNumber)
697 {
698 return this._sourceFrame.populateLineGutterContextMenu(contextMenu, line Number);
699 },
700
701 /**
702 * @override
703 * @param {!WebInspector.ContextMenu} contextMenu
704 * @param {number} lineNumber
705 * @param {number} columnNumber
706 * @return {!Promise}
707 */
708 populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber)
709 {
710 return this._sourceFrame.populateTextAreaContextMenu(contextMenu, lineNu mber, columnNumber);
711 },
712
713 /**
714 * @override
715 * @param {?WebInspector.TextRange} from
716 * @param {?WebInspector.TextRange} to
717 */
718 onJumpToPosition: function(from, to)
719 {
720 this._sourceFrame.onJumpToPosition(from, to);
721 }
722 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698