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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/terminal/TerminalWidget.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4
5 /** 4 /**
6 * @constructor 5 * @unrestricted
7 * @extends {WebInspector.VBox}
8 */ 6 */
9 WebInspector.TerminalWidget = function() 7 WebInspector.TerminalWidget = class extends WebInspector.VBox {
10 { 8 constructor() {
11 WebInspector.VBox.call(this, false); 9 super(false);
12 this.registerRequiredCSS("terminal/xterm.js/build/xterm.css"); 10 this.registerRequiredCSS('terminal/xterm.js/build/xterm.css');
13 this.registerRequiredCSS("terminal/terminal.css"); 11 this.registerRequiredCSS('terminal/terminal.css');
14 this.element.classList.add("terminal-root"); 12 this.element.classList.add('terminal-root');
15 this.element.addEventListener("mousemove", this._mouseMove.bind(this), false ); 13 this.element.addEventListener('mousemove', this._mouseMove.bind(this), false );
16 this._init(); 14 this._init();
17 this._linkifier = new WebInspector.Linkifier(); 15 this._linkifier = new WebInspector.Linkifier();
18 this._linkifyFunction = this._linkifyURL.bind(this); 16 this._linkifyFunction = this._linkifyURL.bind(this);
17 }
18
19 _init() {
20 WebInspector.serviceManager.createRemoteService('Terminal').then(this._initi alized.bind(this));
21 }
22
23 /**
24 * @param {?WebInspector.ServiceManager.Service} backend
25 */
26 _initialized(backend) {
27 if (!backend) {
28 if (!this._unavailableLabel) {
29 this._unavailableLabel = this.element.createChild('div', 'terminal-error -message fill');
30 this._unavailableLabel.createChild('div').textContent =
31 WebInspector.UIString('Terminal service is not available');
32 }
33 if (this.isShowing())
34 setTimeout(this._init.bind(this), 2000);
35 return;
36 }
37
38 if (this._unavailableLabel) {
39 this._unavailableLabel.remove();
40 delete this._unavailableLabel;
41 }
42
43 this._backend = backend;
44
45 if (!this._term) {
46 this._term = new Terminal({cursorBlink: true});
47 this._term.open(this.contentElement);
48 this._term.on('data', data => {
49 this._backend.send('write', {data: data});
50 });
51 this._term.fit();
52 this._term.on('resize', size => {
53 this._backend.send('resize', {cols: size.cols, rows: size.rows});
54 });
55 }
56
57 this._backend.send('init', {cols: this._term.cols, rows: this._term.rows});
58 this._backend.on('data', result => {
59 this._term.write(result.data);
60 this._linkifyUpToDate = false;
61 });
62 this._backend.on('disposed', this._disposed.bind(this));
63 }
64
65 _mouseMove() {
66 if (this._linkifyUpToDate)
67 return;
68 if (this._term)
69 this._linkify();
70 this._linkifyUpToDate = true;
71 }
72
73 /**
74 * @override
75 */
76 onResize() {
77 if (this._term)
78 this._term.fit();
79 }
80
81 _disposed() {
82 this._initialized(null);
83 }
84
85 /**
86 * @override
87 */
88 wasDetachedFromHierarchy() {
89 if (this._backend)
90 this._backend.dispose();
91 }
92
93 _linkify() {
94 if (!this._term)
95 return;
96 this._linkifier.reset();
97 var rows = this._term.rowContainer.children;
98 for (var i = 0; i < rows.length; i++)
99 this._linkifyTerminalLine(rows[i]);
100 }
101
102 /**
103 * @param {!Node} line
104 */
105 _linkifyTerminalLine(line) {
106 var node = line.firstChild;
107 while (node) {
108 if (node.nodeType !== Node.TEXT_NODE) {
109 node = node.nextSibling;
110 continue;
111 }
112 var nextNode = node.nextSibling;
113 node.remove();
114 var linkified = WebInspector.linkifyStringAsFragmentWithCustomLinkifier(no de.textContent, this._linkifyFunction);
115 line.insertBefore(linkified, nextNode);
116 node = nextNode;
117 }
118 }
119
120 /**
121 * @param {string} title
122 * @param {string} url
123 * @param {number=} lineNumber
124 * @param {number=} columnNumber
125 */
126 _linkifyURL(title, url, lineNumber, columnNumber) {
127 return this._linkifier.linkifyScriptLocation(null, null, url, lineNumber || 0, columnNumber || 0);
128 }
19 }; 129 };
20
21 WebInspector.TerminalWidget.prototype = {
22 _init: function()
23 {
24 WebInspector.serviceManager.createRemoteService("Terminal").then(this._i nitialized.bind(this));
25 },
26
27 /**
28 * @param {?WebInspector.ServiceManager.Service} backend
29 */
30 _initialized: function(backend)
31 {
32 if (!backend) {
33 if (!this._unavailableLabel) {
34 this._unavailableLabel = this.element.createChild("div", "termin al-error-message fill");
35 this._unavailableLabel.createChild("div").textContent = WebInspe ctor.UIString("Terminal service is not available");
36 }
37 if (this.isShowing())
38 setTimeout(this._init.bind(this), 2000);
39 return;
40 }
41
42 if (this._unavailableLabel) {
43 this._unavailableLabel.remove();
44 delete this._unavailableLabel;
45 }
46
47 this._backend = backend;
48
49 if (!this._term) {
50 this._term = new Terminal({ cursorBlink: true });
51 this._term.open(this.contentElement);
52 this._term.on("data", data => {
53 this._backend.send("write", { data: data });
54 });
55 this._term.fit();
56 this._term.on("resize", size => {
57 this._backend.send("resize", { cols: size.cols, rows: size.rows });
58 });
59 }
60
61 this._backend.send("init", { cols: this._term.cols, rows: this._term.row s });
62 this._backend.on("data", result => {
63 this._term.write(result.data);
64 this._linkifyUpToDate = false;
65 });
66 this._backend.on("disposed", this._disposed.bind(this));
67 },
68
69 _mouseMove: function()
70 {
71 if (this._linkifyUpToDate)
72 return;
73 if (this._term)
74 this._linkify();
75 this._linkifyUpToDate = true;
76 },
77
78 onResize: function()
79 {
80 if (this._term)
81 this._term.fit();
82 },
83
84 _disposed: function()
85 {
86 this._initialized(null);
87 },
88
89 /**
90 * @override
91 */
92 wasDetachedFromHierarchy: function()
93 {
94 if (this._backend)
95 this._backend.dispose();
96 },
97
98 _linkify: function()
99 {
100 if (!this._term)
101 return;
102 this._linkifier.reset();
103 var rows = this._term.rowContainer.children;
104 for (var i = 0; i < rows.length; i++)
105 this._linkifyTerminalLine(rows[i]);
106 },
107
108 /**
109 * @param {!Node} line
110 */
111 _linkifyTerminalLine: function(line)
112 {
113 var node = line.firstChild;
114 while (node) {
115 if (node.nodeType !== Node.TEXT_NODE) {
116 node = node.nextSibling;
117 continue;
118 }
119 var nextNode = node.nextSibling;
120 node.remove();
121 var linkified = WebInspector.linkifyStringAsFragmentWithCustomLinkif ier(node.textContent, this._linkifyFunction);
122 line.insertBefore(linkified, nextNode);
123 node = nextNode;
124 }
125 },
126
127 /**
128 * @param {string} title
129 * @param {string} url
130 * @param {number=} lineNumber
131 * @param {number=} columnNumber
132 */
133 _linkifyURL: function(title, url, lineNumber, columnNumber)
134 {
135 return this._linkifier.linkifyScriptLocation(null, null, url, lineNumber || 0, columnNumber || 0);
136 },
137
138 __proto__: WebInspector.VBox.prototype
139 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698