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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/UIUtils.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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). 4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com).
5 * Copyright (C) 2009 Joseph Pecoraro 5 * Copyright (C) 2009 Joseph Pecoraro
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 10 *
(...skipping 10 matching lines...) Expand all
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 WebInspector.highlightedSearchResultClassName = 'highlighted-search-result'; 31 UI.highlightedSearchResultClassName = 'highlighted-search-result';
32 WebInspector.highlightedCurrentSearchResultClassName = 'current-search-result'; 32 UI.highlightedCurrentSearchResultClassName = 'current-search-result';
33 33
34 /** 34 /**
35 * @param {!Element} element 35 * @param {!Element} element
36 * @param {?function(!MouseEvent): boolean} elementDragStart 36 * @param {?function(!MouseEvent): boolean} elementDragStart
37 * @param {function(!MouseEvent)} elementDrag 37 * @param {function(!MouseEvent)} elementDrag
38 * @param {?function(!MouseEvent)} elementDragEnd 38 * @param {?function(!MouseEvent)} elementDragEnd
39 * @param {string} cursor 39 * @param {string} cursor
40 * @param {?string=} hoverCursor 40 * @param {?string=} hoverCursor
41 * @param {number=} startDelay 41 * @param {number=} startDelay
42 */ 42 */
43 WebInspector.installDragHandle = function( 43 UI.installDragHandle = function(
44 element, elementDragStart, elementDrag, elementDragEnd, cursor, hoverCursor, startDelay) { 44 element, elementDragStart, elementDrag, elementDragEnd, cursor, hoverCursor, startDelay) {
45 /** 45 /**
46 * @param {!Event} event 46 * @param {!Event} event
47 */ 47 */
48 function onMouseDown(event) { 48 function onMouseDown(event) {
49 var dragHandler = new WebInspector.DragHandler(); 49 var dragHandler = new UI.DragHandler();
50 var dragStart = dragHandler.elementDragStart.bind( 50 var dragStart = dragHandler.elementDragStart.bind(
51 dragHandler, element, elementDragStart, elementDrag, elementDragEnd, cur sor, event); 51 dragHandler, element, elementDragStart, elementDrag, elementDragEnd, cur sor, event);
52 if (startDelay) 52 if (startDelay)
53 startTimer = setTimeout(dragStart, startDelay); 53 startTimer = setTimeout(dragStart, startDelay);
54 else 54 else
55 dragStart(); 55 dragStart();
56 } 56 }
57 57
58 function onMouseUp() { 58 function onMouseUp() {
59 if (startTimer) 59 if (startTimer)
(...skipping 10 matching lines...) Expand all
70 }; 70 };
71 71
72 /** 72 /**
73 * @param {!Element} targetElement 73 * @param {!Element} targetElement
74 * @param {?function(!MouseEvent):boolean} elementDragStart 74 * @param {?function(!MouseEvent):boolean} elementDragStart
75 * @param {function(!MouseEvent)} elementDrag 75 * @param {function(!MouseEvent)} elementDrag
76 * @param {?function(!MouseEvent)} elementDragEnd 76 * @param {?function(!MouseEvent)} elementDragEnd
77 * @param {string} cursor 77 * @param {string} cursor
78 * @param {!Event} event 78 * @param {!Event} event
79 */ 79 */
80 WebInspector.elementDragStart = function(targetElement, elementDragStart, elemen tDrag, elementDragEnd, cursor, event) { 80 UI.elementDragStart = function(targetElement, elementDragStart, elementDrag, ele mentDragEnd, cursor, event) {
81 var dragHandler = new WebInspector.DragHandler(); 81 var dragHandler = new UI.DragHandler();
82 dragHandler.elementDragStart(targetElement, elementDragStart, elementDrag, ele mentDragEnd, cursor, event); 82 dragHandler.elementDragStart(targetElement, elementDragStart, elementDrag, ele mentDragEnd, cursor, event);
83 }; 83 };
84 84
85 /** 85 /**
86 * @unrestricted 86 * @unrestricted
87 */ 87 */
88 WebInspector.DragHandler = class { 88 UI.DragHandler = class {
89 constructor() { 89 constructor() {
90 this._elementDragMove = this._elementDragMove.bind(this); 90 this._elementDragMove = this._elementDragMove.bind(this);
91 this._elementDragEnd = this._elementDragEnd.bind(this); 91 this._elementDragEnd = this._elementDragEnd.bind(this);
92 this._mouseOutWhileDragging = this._mouseOutWhileDragging.bind(this); 92 this._mouseOutWhileDragging = this._mouseOutWhileDragging.bind(this);
93 } 93 }
94 94
95 _createGlassPane() { 95 _createGlassPane() {
96 this._glassPaneInUse = true; 96 this._glassPaneInUse = true;
97 if (!WebInspector.DragHandler._glassPaneUsageCount++) 97 if (!UI.DragHandler._glassPaneUsageCount++)
98 WebInspector.DragHandler._glassPane = new WebInspector.GlassPane(WebInspec tor.DragHandler._documentForMouseOut); 98 UI.DragHandler._glassPane = new UI.GlassPane(UI.DragHandler._documentForMo useOut);
99 } 99 }
100 100
101 _disposeGlassPane() { 101 _disposeGlassPane() {
102 if (!this._glassPaneInUse) 102 if (!this._glassPaneInUse)
103 return; 103 return;
104 this._glassPaneInUse = false; 104 this._glassPaneInUse = false;
105 if (--WebInspector.DragHandler._glassPaneUsageCount) 105 if (--UI.DragHandler._glassPaneUsageCount)
106 return; 106 return;
107 WebInspector.DragHandler._glassPane.dispose(); 107 UI.DragHandler._glassPane.dispose();
108 delete WebInspector.DragHandler._glassPane; 108 delete UI.DragHandler._glassPane;
109 delete WebInspector.DragHandler._documentForMouseOut; 109 delete UI.DragHandler._documentForMouseOut;
110 } 110 }
111 111
112 /** 112 /**
113 * @param {!Element} targetElement 113 * @param {!Element} targetElement
114 * @param {?function(!MouseEvent):boolean} elementDragStart 114 * @param {?function(!MouseEvent):boolean} elementDragStart
115 * @param {function(!MouseEvent)} elementDrag 115 * @param {function(!MouseEvent)} elementDrag
116 * @param {?function(!MouseEvent)} elementDragEnd 116 * @param {?function(!MouseEvent)} elementDragEnd
117 * @param {string} cursor 117 * @param {string} cursor
118 * @param {!Event} event 118 * @param {!Event} event
119 */ 119 */
120 elementDragStart(targetElement, elementDragStart, elementDrag, elementDragEnd, cursor, event) { 120 elementDragStart(targetElement, elementDragStart, elementDrag, elementDragEnd, cursor, event) {
121 // Only drag upon left button. Right will likely cause a context menu. So wi ll ctrl-click on mac. 121 // Only drag upon left button. Right will likely cause a context menu. So wi ll ctrl-click on mac.
122 if (event.button || (WebInspector.isMac() && event.ctrlKey)) 122 if (event.button || (Host.isMac() && event.ctrlKey))
123 return; 123 return;
124 124
125 if (this._elementDraggingEventListener) 125 if (this._elementDraggingEventListener)
126 return; 126 return;
127 127
128 if (elementDragStart && !elementDragStart(/** @type {!MouseEvent} */ (event) )) 128 if (elementDragStart && !elementDragStart(/** @type {!MouseEvent} */ (event) ))
129 return; 129 return;
130 130
131 var targetDocument = event.target.ownerDocument; 131 var targetDocument = event.target.ownerDocument;
132 this._elementDraggingEventListener = elementDrag; 132 this._elementDraggingEventListener = elementDrag;
133 this._elementEndDraggingEventListener = elementDragEnd; 133 this._elementEndDraggingEventListener = elementDragEnd;
134 console.assert( 134 console.assert(
135 (WebInspector.DragHandler._documentForMouseOut || targetDocument) === ta rgetDocument, 135 (UI.DragHandler._documentForMouseOut || targetDocument) === targetDocume nt,
136 'Dragging on multiple documents.'); 136 'Dragging on multiple documents.');
137 WebInspector.DragHandler._documentForMouseOut = targetDocument; 137 UI.DragHandler._documentForMouseOut = targetDocument;
138 this._dragEventsTargetDocument = targetDocument; 138 this._dragEventsTargetDocument = targetDocument;
139 this._dragEventsTargetDocumentTop = targetDocument.defaultView.top.document; 139 this._dragEventsTargetDocumentTop = targetDocument.defaultView.top.document;
140 140
141 targetDocument.addEventListener('mousemove', this._elementDragMove, true); 141 targetDocument.addEventListener('mousemove', this._elementDragMove, true);
142 targetDocument.addEventListener('mouseup', this._elementDragEnd, true); 142 targetDocument.addEventListener('mouseup', this._elementDragEnd, true);
143 targetDocument.addEventListener('mouseout', this._mouseOutWhileDragging, tru e); 143 targetDocument.addEventListener('mouseout', this._mouseOutWhileDragging, tru e);
144 if (targetDocument !== this._dragEventsTargetDocumentTop) 144 if (targetDocument !== this._dragEventsTargetDocumentTop)
145 this._dragEventsTargetDocumentTop.addEventListener('mouseup', this._elemen tDragEnd, true); 145 this._dragEventsTargetDocumentTop.addEventListener('mouseup', this._elemen tDragEnd, true);
146 146
147 if (typeof cursor === 'string') { 147 if (typeof cursor === 'string') {
148 this._restoreCursorAfterDrag = restoreCursor.bind(this, targetElement.styl e.cursor); 148 this._restoreCursorAfterDrag = restoreCursor.bind(this, targetElement.styl e.cursor);
149 targetElement.style.cursor = cursor; 149 targetElement.style.cursor = cursor;
150 targetDocument.body.style.cursor = cursor; 150 targetDocument.body.style.cursor = cursor;
151 } 151 }
152 /** 152 /**
153 * @param {string} oldCursor 153 * @param {string} oldCursor
154 * @this {WebInspector.DragHandler} 154 * @this {UI.DragHandler}
155 */ 155 */
156 function restoreCursor(oldCursor) { 156 function restoreCursor(oldCursor) {
157 targetDocument.body.style.removeProperty('cursor'); 157 targetDocument.body.style.removeProperty('cursor');
158 targetElement.style.cursor = oldCursor; 158 targetElement.style.cursor = oldCursor;
159 this._restoreCursorAfterDrag = null; 159 this._restoreCursorAfterDrag = null;
160 } 160 }
161 event.preventDefault(); 161 event.preventDefault();
162 } 162 }
163 163
164 _mouseOutWhileDragging() { 164 _mouseOutWhileDragging() {
165 this._unregisterMouseOutWhileDragging(); 165 this._unregisterMouseOutWhileDragging();
166 this._createGlassPane(); 166 this._createGlassPane();
167 } 167 }
168 168
169 _unregisterMouseOutWhileDragging() { 169 _unregisterMouseOutWhileDragging() {
170 if (!WebInspector.DragHandler._documentForMouseOut) 170 if (!UI.DragHandler._documentForMouseOut)
171 return; 171 return;
172 WebInspector.DragHandler._documentForMouseOut.removeEventListener('mouseout' , this._mouseOutWhileDragging, true); 172 UI.DragHandler._documentForMouseOut.removeEventListener('mouseout', this._mo useOutWhileDragging, true);
173 } 173 }
174 174
175 _unregisterDragEvents() { 175 _unregisterDragEvents() {
176 if (!this._dragEventsTargetDocument) 176 if (!this._dragEventsTargetDocument)
177 return; 177 return;
178 this._dragEventsTargetDocument.removeEventListener('mousemove', this._elemen tDragMove, true); 178 this._dragEventsTargetDocument.removeEventListener('mousemove', this._elemen tDragMove, true);
179 this._dragEventsTargetDocument.removeEventListener('mouseup', this._elementD ragEnd, true); 179 this._dragEventsTargetDocument.removeEventListener('mouseup', this._elementD ragEnd, true);
180 if (this._dragEventsTargetDocument !== this._dragEventsTargetDocumentTop) 180 if (this._dragEventsTargetDocument !== this._dragEventsTargetDocumentTop)
181 this._dragEventsTargetDocumentTop.removeEventListener('mouseup', this._ele mentDragEnd, true); 181 this._dragEventsTargetDocumentTop.removeEventListener('mouseup', this._ele mentDragEnd, true);
182 delete this._dragEventsTargetDocument; 182 delete this._dragEventsTargetDocument;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 */ 216 */
217 _elementDragEnd(event) { 217 _elementDragEnd(event) {
218 var elementDragEnd = this._elementEndDraggingEventListener; 218 var elementDragEnd = this._elementEndDraggingEventListener;
219 this._cancelDragEvents(/** @type {!MouseEvent} */ (event)); 219 this._cancelDragEvents(/** @type {!MouseEvent} */ (event));
220 event.preventDefault(); 220 event.preventDefault();
221 if (elementDragEnd) 221 if (elementDragEnd)
222 elementDragEnd(/** @type {!MouseEvent} */ (event)); 222 elementDragEnd(/** @type {!MouseEvent} */ (event));
223 } 223 }
224 }; 224 };
225 225
226 WebInspector.DragHandler._glassPaneUsageCount = 0; 226 UI.DragHandler._glassPaneUsageCount = 0;
227 227
228 /** 228 /**
229 * @param {!Element} element 229 * @param {!Element} element
230 * @param {function(number, number, !MouseEvent): boolean} elementDragStart 230 * @param {function(number, number, !MouseEvent): boolean} elementDragStart
231 * @param {function(number, number)} elementDrag 231 * @param {function(number, number)} elementDrag
232 * @param {function(number, number)} elementDragEnd 232 * @param {function(number, number)} elementDragEnd
233 * @param {string} cursor 233 * @param {string} cursor
234 * @param {?string=} hoverCursor 234 * @param {?string=} hoverCursor
235 * @param {number=} startDelay 235 * @param {number=} startDelay
236 * @param {number=} friction 236 * @param {number=} friction
237 */ 237 */
238 WebInspector.installInertialDragHandle = function( 238 UI.installInertialDragHandle = function(
239 element, elementDragStart, elementDrag, elementDragEnd, cursor, hoverCursor, startDelay, friction) { 239 element, elementDragStart, elementDrag, elementDragEnd, cursor, hoverCursor, startDelay, friction) {
240 WebInspector.installDragHandle( 240 UI.installDragHandle(
241 element, drag.bind(null, elementDragStart), drag.bind(null, elementDrag), dragEnd, cursor, hoverCursor, 241 element, drag.bind(null, elementDragStart), drag.bind(null, elementDrag), dragEnd, cursor, hoverCursor,
242 startDelay); 242 startDelay);
243 if (typeof friction !== 'number') 243 if (typeof friction !== 'number')
244 friction = 50; 244 friction = 50;
245 var lastX; 245 var lastX;
246 var lastY; 246 var lastY;
247 var lastTime; 247 var lastTime;
248 var velocityX; 248 var velocityX;
249 var velocityY; 249 var velocityY;
250 var holding = false; 250 var holding = false;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 var k = Math.pow(1 / (1 + friction), duration / 1000); 295 var k = Math.pow(1 / (1 + friction), duration / 1000);
296 velocityX *= k; 296 velocityX *= k;
297 velocityY *= k; 297 velocityY *= k;
298 elementDrag(lastX, lastY); 298 elementDrag(lastX, lastY);
299 } 299 }
300 }; 300 };
301 301
302 /** 302 /**
303 * @unrestricted 303 * @unrestricted
304 */ 304 */
305 WebInspector.GlassPane = class { 305 UI.GlassPane = class {
306 /** 306 /**
307 * @param {!Document} document 307 * @param {!Document} document
308 * @param {boolean=} dimmed 308 * @param {boolean=} dimmed
309 */ 309 */
310 constructor(document, dimmed) { 310 constructor(document, dimmed) {
311 this.element = createElement('div'); 311 this.element = createElement('div');
312 var background = dimmed ? 'rgba(255, 255, 255, 0.5)' : 'transparent'; 312 var background = dimmed ? 'rgba(255, 255, 255, 0.5)' : 'transparent';
313 this._zIndex = WebInspector._glassPane ? 313 this._zIndex = UI._glassPane ?
314 WebInspector._glassPane._zIndex + 1000 : 314 UI._glassPane._zIndex + 1000 :
315 3000; // Deliberately starts with 3000 to hide other z-indexed elements below. 315 3000; // Deliberately starts with 3000 to hide other z-indexed elements below.
316 this.element.style.cssText = 'position:absolute;top:0;bottom:0;left:0;right: 0;background-color:' + background + 316 this.element.style.cssText = 'position:absolute;top:0;bottom:0;left:0;right: 0;background-color:' + background +
317 ';z-index:' + this._zIndex + ';overflow:hidden;'; 317 ';z-index:' + this._zIndex + ';overflow:hidden;';
318 document.body.appendChild(this.element); 318 document.body.appendChild(this.element);
319 WebInspector._glassPane = this; 319 UI._glassPane = this;
320 // TODO(dgozman): disallow focus outside of glass pane? 320 // TODO(dgozman): disallow focus outside of glass pane?
321 } 321 }
322 322
323 dispose() { 323 dispose() {
324 delete WebInspector._glassPane; 324 delete UI._glassPane;
325 this.element.remove(); 325 this.element.remove();
326 } 326 }
327 }; 327 };
328 328
329 /** @type {!WebInspector.GlassPane|undefined} */ 329 /** @type {!UI.GlassPane|undefined} */
330 WebInspector._glassPane; 330 UI._glassPane;
331 331
332 /** 332 /**
333 * @param {?Node=} node 333 * @param {?Node=} node
334 * @return {boolean} 334 * @return {boolean}
335 */ 335 */
336 WebInspector.isBeingEdited = function(node) { 336 UI.isBeingEdited = function(node) {
337 if (!node || node.nodeType !== Node.ELEMENT_NODE) 337 if (!node || node.nodeType !== Node.ELEMENT_NODE)
338 return false; 338 return false;
339 var element = /** {!Element} */ (node); 339 var element = /** {!Element} */ (node);
340 if (element.classList.contains('text-prompt') || element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') 340 if (element.classList.contains('text-prompt') || element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA')
341 return true; 341 return true;
342 342
343 if (!WebInspector.__editingCount) 343 if (!UI.__editingCount)
344 return false; 344 return false;
345 345
346 while (element) { 346 while (element) {
347 if (element.__editing) 347 if (element.__editing)
348 return true; 348 return true;
349 element = element.parentElementOrShadowHost(); 349 element = element.parentElementOrShadowHost();
350 } 350 }
351 return false; 351 return false;
352 }; 352 };
353 353
354 /** 354 /**
355 * @return {boolean} 355 * @return {boolean}
356 * @suppressGlobalPropertiesCheck 356 * @suppressGlobalPropertiesCheck
357 */ 357 */
358 WebInspector.isEditing = function() { 358 UI.isEditing = function() {
359 if (WebInspector.__editingCount) 359 if (UI.__editingCount)
360 return true; 360 return true;
361 361
362 var focused = document.deepActiveElement(); 362 var focused = document.deepActiveElement();
363 if (!focused) 363 if (!focused)
364 return false; 364 return false;
365 return focused.classList.contains('text-prompt') || focused.nodeName === 'INPU T' || focused.nodeName === 'TEXTAREA'; 365 return focused.classList.contains('text-prompt') || focused.nodeName === 'INPU T' || focused.nodeName === 'TEXTAREA';
366 }; 366 };
367 367
368 /** 368 /**
369 * @param {!Element} element 369 * @param {!Element} element
370 * @param {boolean} value 370 * @param {boolean} value
371 * @return {boolean} 371 * @return {boolean}
372 */ 372 */
373 WebInspector.markBeingEdited = function(element, value) { 373 UI.markBeingEdited = function(element, value) {
374 if (value) { 374 if (value) {
375 if (element.__editing) 375 if (element.__editing)
376 return false; 376 return false;
377 element.classList.add('being-edited'); 377 element.classList.add('being-edited');
378 element.__editing = true; 378 element.__editing = true;
379 WebInspector.__editingCount = (WebInspector.__editingCount || 0) + 1; 379 UI.__editingCount = (UI.__editingCount || 0) + 1;
380 } else { 380 } else {
381 if (!element.__editing) 381 if (!element.__editing)
382 return false; 382 return false;
383 element.classList.remove('being-edited'); 383 element.classList.remove('being-edited');
384 delete element.__editing; 384 delete element.__editing;
385 --WebInspector.__editingCount; 385 --UI.__editingCount;
386 } 386 }
387 return true; 387 return true;
388 }; 388 };
389 389
390 WebInspector.CSSNumberRegex = /^(-?(?:\d+(?:\.\d+)?|\.\d+))$/; 390 UI.CSSNumberRegex = /^(-?(?:\d+(?:\.\d+)?|\.\d+))$/;
391 391
392 WebInspector.StyleValueDelimiters = ' \xA0\t\n"\':;,/()'; 392 UI.StyleValueDelimiters = ' \xA0\t\n"\':;,/()';
393 393
394 /** 394 /**
395 * @param {!Event} event 395 * @param {!Event} event
396 * @return {?string} 396 * @return {?string}
397 */ 397 */
398 WebInspector._valueModificationDirection = function(event) { 398 UI._valueModificationDirection = function(event) {
399 var direction = null; 399 var direction = null;
400 if (event.type === 'mousewheel') { 400 if (event.type === 'mousewheel') {
401 // When shift is pressed while spinning mousewheel, delta comes as wheelDelt aX. 401 // When shift is pressed while spinning mousewheel, delta comes as wheelDelt aX.
402 if (event.wheelDeltaY > 0 || event.wheelDeltaX > 0) 402 if (event.wheelDeltaY > 0 || event.wheelDeltaX > 0)
403 direction = 'Up'; 403 direction = 'Up';
404 else if (event.wheelDeltaY < 0 || event.wheelDeltaX < 0) 404 else if (event.wheelDeltaY < 0 || event.wheelDeltaX < 0)
405 direction = 'Down'; 405 direction = 'Down';
406 } else { 406 } else {
407 if (event.key === 'ArrowUp' || event.key === 'PageUp') 407 if (event.key === 'ArrowUp' || event.key === 'PageUp')
408 direction = 'Up'; 408 direction = 'Up';
409 else if (event.key === 'ArrowDown' || event.key === 'PageDown') 409 else if (event.key === 'ArrowDown' || event.key === 'PageDown')
410 direction = 'Down'; 410 direction = 'Down';
411 } 411 }
412 return direction; 412 return direction;
413 }; 413 };
414 414
415 /** 415 /**
416 * @param {string} hexString 416 * @param {string} hexString
417 * @param {!Event} event 417 * @param {!Event} event
418 * @return {?string} 418 * @return {?string}
419 */ 419 */
420 WebInspector._modifiedHexValue = function(hexString, event) { 420 UI._modifiedHexValue = function(hexString, event) {
421 var direction = WebInspector._valueModificationDirection(event); 421 var direction = UI._valueModificationDirection(event);
422 if (!direction) 422 if (!direction)
423 return null; 423 return null;
424 424
425 var mouseEvent = /** @type {!MouseEvent} */ (event); 425 var mouseEvent = /** @type {!MouseEvent} */ (event);
426 var number = parseInt(hexString, 16); 426 var number = parseInt(hexString, 16);
427 if (isNaN(number) || !isFinite(number)) 427 if (isNaN(number) || !isFinite(number))
428 return null; 428 return null;
429 429
430 var hexStrLen = hexString.length; 430 var hexStrLen = hexString.length;
431 var channelLen = hexStrLen / 3; 431 var channelLen = hexStrLen / 3;
432 432
433 // Colors are either rgb or rrggbb. 433 // Colors are either rgb or rrggbb.
434 if (channelLen !== 1 && channelLen !== 2) 434 if (channelLen !== 1 && channelLen !== 2)
435 return null; 435 return null;
436 436
437 // Precision modifier keys work with both mousewheel and up/down keys. 437 // Precision modifier keys work with both mousewheel and up/down keys.
438 // When ctrl is pressed, increase R by 1. 438 // When ctrl is pressed, increase R by 1.
439 // When shift is pressed, increase G by 1. 439 // When shift is pressed, increase G by 1.
440 // When alt is pressed, increase B by 1. 440 // When alt is pressed, increase B by 1.
441 // If no shortcut keys are pressed then increase hex value by 1. 441 // If no shortcut keys are pressed then increase hex value by 1.
442 // Keys can be pressed together to increase RGB channels. e.g trying different shades. 442 // Keys can be pressed together to increase RGB channels. e.g trying different shades.
443 var delta = 0; 443 var delta = 0;
444 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(mouseEvent)) 444 if (UI.KeyboardShortcut.eventHasCtrlOrMeta(mouseEvent))
445 delta += Math.pow(16, channelLen * 2); 445 delta += Math.pow(16, channelLen * 2);
446 if (mouseEvent.shiftKey) 446 if (mouseEvent.shiftKey)
447 delta += Math.pow(16, channelLen); 447 delta += Math.pow(16, channelLen);
448 if (mouseEvent.altKey) 448 if (mouseEvent.altKey)
449 delta += 1; 449 delta += 1;
450 if (delta === 0) 450 if (delta === 0)
451 delta = 1; 451 delta = 1;
452 if (direction === 'Down') 452 if (direction === 'Down')
453 delta *= -1; 453 delta *= -1;
454 454
455 // Increase hex value by 1 and clamp from 0 ... maxValue. 455 // Increase hex value by 1 and clamp from 0 ... maxValue.
456 var maxValue = Math.pow(16, hexStrLen) - 1; 456 var maxValue = Math.pow(16, hexStrLen) - 1;
457 var result = Number.constrain(number + delta, 0, maxValue); 457 var result = Number.constrain(number + delta, 0, maxValue);
458 458
459 // Ensure the result length is the same as the original hex value. 459 // Ensure the result length is the same as the original hex value.
460 var resultString = result.toString(16).toUpperCase(); 460 var resultString = result.toString(16).toUpperCase();
461 for (var i = 0, lengthDelta = hexStrLen - resultString.length; i < lengthDelta ; ++i) 461 for (var i = 0, lengthDelta = hexStrLen - resultString.length; i < lengthDelta ; ++i)
462 resultString = '0' + resultString; 462 resultString = '0' + resultString;
463 return resultString; 463 return resultString;
464 }; 464 };
465 465
466 /** 466 /**
467 * @param {number} number 467 * @param {number} number
468 * @param {!Event} event 468 * @param {!Event} event
469 * @return {?number} 469 * @return {?number}
470 */ 470 */
471 WebInspector._modifiedFloatNumber = function(number, event) { 471 UI._modifiedFloatNumber = function(number, event) {
472 var direction = WebInspector._valueModificationDirection(event); 472 var direction = UI._valueModificationDirection(event);
473 if (!direction) 473 if (!direction)
474 return null; 474 return null;
475 475
476 var mouseEvent = /** @type {!MouseEvent} */ (event); 476 var mouseEvent = /** @type {!MouseEvent} */ (event);
477 477
478 // Precision modifier keys work with both mousewheel and up/down keys. 478 // Precision modifier keys work with both mousewheel and up/down keys.
479 // When ctrl is pressed, increase by 100. 479 // When ctrl is pressed, increase by 100.
480 // When shift is pressed, increase by 10. 480 // When shift is pressed, increase by 10.
481 // When alt is pressed, increase by 0.1. 481 // When alt is pressed, increase by 0.1.
482 // Otherwise increase by 1. 482 // Otherwise increase by 1.
483 var delta = 1; 483 var delta = 1;
484 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(mouseEvent)) 484 if (UI.KeyboardShortcut.eventHasCtrlOrMeta(mouseEvent))
485 delta = 100; 485 delta = 100;
486 else if (mouseEvent.shiftKey) 486 else if (mouseEvent.shiftKey)
487 delta = 10; 487 delta = 10;
488 else if (mouseEvent.altKey) 488 else if (mouseEvent.altKey)
489 delta = 0.1; 489 delta = 0.1;
490 490
491 if (direction === 'Down') 491 if (direction === 'Down')
492 delta *= -1; 492 delta *= -1;
493 493
494 // Make the new number and constrain it to a precision of 6, this matches numb ers the engine returns. 494 // Make the new number and constrain it to a precision of 6, this matches numb ers the engine returns.
495 // Use the Number constructor to forget the fixed precision, so 1.100000 will print as 1.1. 495 // Use the Number constructor to forget the fixed precision, so 1.100000 will print as 1.1.
496 var result = Number((number + delta).toFixed(6)); 496 var result = Number((number + delta).toFixed(6));
497 if (!String(result).match(WebInspector.CSSNumberRegex)) 497 if (!String(result).match(UI.CSSNumberRegex))
498 return null; 498 return null;
499 499
500 return result; 500 return result;
501 }; 501 };
502 502
503 /** 503 /**
504 * @param {string} wordString 504 * @param {string} wordString
505 * @param {!Event} event 505 * @param {!Event} event
506 * @param {function(string, number, string):string=} customNumberHandler 506 * @param {function(string, number, string):string=} customNumberHandler
507 * @return {?string} 507 * @return {?string}
508 */ 508 */
509 WebInspector.createReplacementString = function(wordString, event, customNumberH andler) { 509 UI.createReplacementString = function(wordString, event, customNumberHandler) {
510 var prefix; 510 var prefix;
511 var suffix; 511 var suffix;
512 var number; 512 var number;
513 var replacementString = null; 513 var replacementString = null;
514 var matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString); 514 var matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString);
515 if (matches && matches.length) { 515 if (matches && matches.length) {
516 prefix = matches[1]; 516 prefix = matches[1];
517 suffix = matches[3]; 517 suffix = matches[3];
518 number = WebInspector._modifiedHexValue(matches[2], event); 518 number = UI._modifiedHexValue(matches[2], event);
519 if (number !== null) 519 if (number !== null)
520 replacementString = prefix + number + suffix; 520 replacementString = prefix + number + suffix;
521 } else { 521 } else {
522 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString); 522 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString);
523 if (matches && matches.length) { 523 if (matches && matches.length) {
524 prefix = matches[1]; 524 prefix = matches[1];
525 suffix = matches[3]; 525 suffix = matches[3];
526 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), event); 526 number = UI._modifiedFloatNumber(parseFloat(matches[2]), event);
527 if (number !== null) 527 if (number !== null)
528 replacementString = 528 replacementString =
529 customNumberHandler ? customNumberHandler(prefix, number, suffix) : prefix + number + suffix; 529 customNumberHandler ? customNumberHandler(prefix, number, suffix) : prefix + number + suffix;
530 } 530 }
531 } 531 }
532 return replacementString; 532 return replacementString;
533 }; 533 };
534 534
535 /** 535 /**
536 * @param {!Event} event 536 * @param {!Event} event
537 * @param {!Element} element 537 * @param {!Element} element
538 * @param {function(string,string)=} finishHandler 538 * @param {function(string,string)=} finishHandler
539 * @param {function(string)=} suggestionHandler 539 * @param {function(string)=} suggestionHandler
540 * @param {function(string, number, string):string=} customNumberHandler 540 * @param {function(string, number, string):string=} customNumberHandler
541 * @return {boolean} 541 * @return {boolean}
542 */ 542 */
543 WebInspector.handleElementValueModifications = function( 543 UI.handleElementValueModifications = function(
544 event, element, finishHandler, suggestionHandler, customNumberHandler) { 544 event, element, finishHandler, suggestionHandler, customNumberHandler) {
545 /** 545 /**
546 * @return {?Range} 546 * @return {?Range}
547 * @suppressGlobalPropertiesCheck 547 * @suppressGlobalPropertiesCheck
548 */ 548 */
549 function createRange() { 549 function createRange() {
550 return document.createRange(); 550 return document.createRange();
551 } 551 }
552 552
553 var arrowKeyOrMouseWheelEvent = (event.key === 'ArrowUp' || event.key === 'Arr owDown' || event.type === 'mousewheel'); 553 var arrowKeyOrMouseWheelEvent = (event.key === 'ArrowUp' || event.key === 'Arr owDown' || event.type === 'mousewheel');
554 var pageKeyPressed = (event.key === 'PageUp' || event.key === 'PageDown'); 554 var pageKeyPressed = (event.key === 'PageUp' || event.key === 'PageDown');
555 if (!arrowKeyOrMouseWheelEvent && !pageKeyPressed) 555 if (!arrowKeyOrMouseWheelEvent && !pageKeyPressed)
556 return false; 556 return false;
557 557
558 var selection = element.getComponentSelection(); 558 var selection = element.getComponentSelection();
559 if (!selection.rangeCount) 559 if (!selection.rangeCount)
560 return false; 560 return false;
561 561
562 var selectionRange = selection.getRangeAt(0); 562 var selectionRange = selection.getRangeAt(0);
563 if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(element)) 563 if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(element))
564 return false; 564 return false;
565 565
566 var originalValue = element.textContent; 566 var originalValue = element.textContent;
567 var wordRange = 567 var wordRange =
568 selectionRange.startContainer.rangeOfWord(selectionRange.startOffset, WebI nspector.StyleValueDelimiters, element); 568 selectionRange.startContainer.rangeOfWord(selectionRange.startOffset, UI.S tyleValueDelimiters, element);
569 var wordString = wordRange.toString(); 569 var wordString = wordRange.toString();
570 570
571 if (suggestionHandler && suggestionHandler(wordString)) 571 if (suggestionHandler && suggestionHandler(wordString))
572 return false; 572 return false;
573 573
574 var replacementString = WebInspector.createReplacementString(wordString, event , customNumberHandler); 574 var replacementString = UI.createReplacementString(wordString, event, customNu mberHandler);
575 575
576 if (replacementString) { 576 if (replacementString) {
577 var replacementTextNode = createTextNode(replacementString); 577 var replacementTextNode = createTextNode(replacementString);
578 578
579 wordRange.deleteContents(); 579 wordRange.deleteContents();
580 wordRange.insertNode(replacementTextNode); 580 wordRange.insertNode(replacementTextNode);
581 581
582 var finalSelectionRange = createRange(); 582 var finalSelectionRange = createRange();
583 finalSelectionRange.setStart(replacementTextNode, 0); 583 finalSelectionRange.setStart(replacementTextNode, 0);
584 finalSelectionRange.setEnd(replacementTextNode, replacementString.length); 584 finalSelectionRange.setEnd(replacementTextNode, replacementString.length);
(...skipping 13 matching lines...) Expand all
598 }; 598 };
599 599
600 /** 600 /**
601 * @param {number} ms 601 * @param {number} ms
602 * @param {number=} precision 602 * @param {number=} precision
603 * @return {string} 603 * @return {string}
604 */ 604 */
605 Number.preciseMillisToString = function(ms, precision) { 605 Number.preciseMillisToString = function(ms, precision) {
606 precision = precision || 0; 606 precision = precision || 0;
607 var format = '%.' + precision + 'f\u2009ms'; 607 var format = '%.' + precision + 'f\u2009ms';
608 return WebInspector.UIString(format, ms); 608 return Common.UIString(format, ms);
609 }; 609 };
610 610
611 /** @type {!WebInspector.UIStringFormat} */ 611 /** @type {!Common.UIStringFormat} */
612 WebInspector._microsFormat = new WebInspector.UIStringFormat('%.0f\u2009\u03bcs' ); 612 UI._microsFormat = new Common.UIStringFormat('%.0f\u2009\u03bcs');
613 613
614 /** @type {!WebInspector.UIStringFormat} */ 614 /** @type {!Common.UIStringFormat} */
615 WebInspector._subMillisFormat = new WebInspector.UIStringFormat('%.2f\u2009ms'); 615 UI._subMillisFormat = new Common.UIStringFormat('%.2f\u2009ms');
616 616
617 /** @type {!WebInspector.UIStringFormat} */ 617 /** @type {!Common.UIStringFormat} */
618 WebInspector._millisFormat = new WebInspector.UIStringFormat('%.0f\u2009ms'); 618 UI._millisFormat = new Common.UIStringFormat('%.0f\u2009ms');
619 619
620 /** @type {!WebInspector.UIStringFormat} */ 620 /** @type {!Common.UIStringFormat} */
621 WebInspector._secondsFormat = new WebInspector.UIStringFormat('%.2f\u2009s'); 621 UI._secondsFormat = new Common.UIStringFormat('%.2f\u2009s');
622 622
623 /** @type {!WebInspector.UIStringFormat} */ 623 /** @type {!Common.UIStringFormat} */
624 WebInspector._minutesFormat = new WebInspector.UIStringFormat('%.1f\u2009min'); 624 UI._minutesFormat = new Common.UIStringFormat('%.1f\u2009min');
625 625
626 /** @type {!WebInspector.UIStringFormat} */ 626 /** @type {!Common.UIStringFormat} */
627 WebInspector._hoursFormat = new WebInspector.UIStringFormat('%.1f\u2009hrs'); 627 UI._hoursFormat = new Common.UIStringFormat('%.1f\u2009hrs');
628 628
629 /** @type {!WebInspector.UIStringFormat} */ 629 /** @type {!Common.UIStringFormat} */
630 WebInspector._daysFormat = new WebInspector.UIStringFormat('%.1f\u2009days'); 630 UI._daysFormat = new Common.UIStringFormat('%.1f\u2009days');
631 631
632 /** 632 /**
633 * @param {number} ms 633 * @param {number} ms
634 * @param {boolean=} higherResolution 634 * @param {boolean=} higherResolution
635 * @return {string} 635 * @return {string}
636 */ 636 */
637 Number.millisToString = function(ms, higherResolution) { 637 Number.millisToString = function(ms, higherResolution) {
638 if (!isFinite(ms)) 638 if (!isFinite(ms))
639 return '-'; 639 return '-';
640 640
641 if (ms === 0) 641 if (ms === 0)
642 return '0'; 642 return '0';
643 643
644 if (higherResolution && ms < 0.1) 644 if (higherResolution && ms < 0.1)
645 return WebInspector._microsFormat.format(ms * 1000); 645 return UI._microsFormat.format(ms * 1000);
646 if (higherResolution && ms < 1000) 646 if (higherResolution && ms < 1000)
647 return WebInspector._subMillisFormat.format(ms); 647 return UI._subMillisFormat.format(ms);
648 if (ms < 1000) 648 if (ms < 1000)
649 return WebInspector._millisFormat.format(ms); 649 return UI._millisFormat.format(ms);
650 650
651 var seconds = ms / 1000; 651 var seconds = ms / 1000;
652 if (seconds < 60) 652 if (seconds < 60)
653 return WebInspector._secondsFormat.format(seconds); 653 return UI._secondsFormat.format(seconds);
654 654
655 var minutes = seconds / 60; 655 var minutes = seconds / 60;
656 if (minutes < 60) 656 if (minutes < 60)
657 return WebInspector._minutesFormat.format(minutes); 657 return UI._minutesFormat.format(minutes);
658 658
659 var hours = minutes / 60; 659 var hours = minutes / 60;
660 if (hours < 24) 660 if (hours < 24)
661 return WebInspector._hoursFormat.format(hours); 661 return UI._hoursFormat.format(hours);
662 662
663 var days = hours / 24; 663 var days = hours / 24;
664 return WebInspector._daysFormat.format(days); 664 return UI._daysFormat.format(days);
665 }; 665 };
666 666
667 /** 667 /**
668 * @param {number} seconds 668 * @param {number} seconds
669 * @param {boolean=} higherResolution 669 * @param {boolean=} higherResolution
670 * @return {string} 670 * @return {string}
671 */ 671 */
672 Number.secondsToString = function(seconds, higherResolution) { 672 Number.secondsToString = function(seconds, higherResolution) {
673 if (!isFinite(seconds)) 673 if (!isFinite(seconds))
674 return '-'; 674 return '-';
675 return Number.millisToString(seconds * 1000, higherResolution); 675 return Number.millisToString(seconds * 1000, higherResolution);
676 }; 676 };
677 677
678 /** 678 /**
679 * @param {number} bytes 679 * @param {number} bytes
680 * @return {string} 680 * @return {string}
681 */ 681 */
682 Number.bytesToString = function(bytes) { 682 Number.bytesToString = function(bytes) {
683 if (bytes < 1024) 683 if (bytes < 1024)
684 return WebInspector.UIString('%.0f\u2009B', bytes); 684 return Common.UIString('%.0f\u2009B', bytes);
685 685
686 var kilobytes = bytes / 1024; 686 var kilobytes = bytes / 1024;
687 if (kilobytes < 100) 687 if (kilobytes < 100)
688 return WebInspector.UIString('%.1f\u2009KB', kilobytes); 688 return Common.UIString('%.1f\u2009KB', kilobytes);
689 if (kilobytes < 1024) 689 if (kilobytes < 1024)
690 return WebInspector.UIString('%.0f\u2009KB', kilobytes); 690 return Common.UIString('%.0f\u2009KB', kilobytes);
691 691
692 var megabytes = kilobytes / 1024; 692 var megabytes = kilobytes / 1024;
693 if (megabytes < 100) 693 if (megabytes < 100)
694 return WebInspector.UIString('%.1f\u2009MB', megabytes); 694 return Common.UIString('%.1f\u2009MB', megabytes);
695 else 695 else
696 return WebInspector.UIString('%.0f\u2009MB', megabytes); 696 return Common.UIString('%.0f\u2009MB', megabytes);
697 }; 697 };
698 698
699 /** 699 /**
700 * @param {number} num 700 * @param {number} num
701 * @return {string} 701 * @return {string}
702 */ 702 */
703 Number.withThousandsSeparator = function(num) { 703 Number.withThousandsSeparator = function(num) {
704 var str = num + ''; 704 var str = num + '';
705 var re = /(\d+)(\d{3})/; 705 var re = /(\d+)(\d{3})/;
706 while (str.match(re)) 706 while (str.match(re))
707 str = str.replace(re, '$1\u2009$2'); // \u2009 is a thin space. 707 str = str.replace(re, '$1\u2009$2'); // \u2009 is a thin space.
708 return str; 708 return str;
709 }; 709 };
710 710
711 /** 711 /**
712 * @param {string} format 712 * @param {string} format
713 * @param {?ArrayLike} substitutions 713 * @param {?ArrayLike} substitutions
714 * @return {!Element} 714 * @return {!Element}
715 */ 715 */
716 WebInspector.formatLocalized = function(format, substitutions) { 716 UI.formatLocalized = function(format, substitutions) {
717 var formatters = {s: substitution => substitution}; 717 var formatters = {s: substitution => substitution};
718 /** 718 /**
719 * @param {!Element} a 719 * @param {!Element} a
720 * @param {string|!Element} b 720 * @param {string|!Element} b
721 * @return {!Element} 721 * @return {!Element}
722 */ 722 */
723 function append(a, b) { 723 function append(a, b) {
724 a.appendChild(typeof b === 'string' ? createTextNode(b) : b); 724 a.appendChild(typeof b === 'string' ? createTextNode(b) : b);
725 return a; 725 return a;
726 } 726 }
727 return String.format(WebInspector.UIString(format), substitutions, formatters, createElement('span'), append) 727 return String.format(Common.UIString(format), substitutions, formatters, creat eElement('span'), append)
728 .formattedResult; 728 .formattedResult;
729 }; 729 };
730 730
731 /** 731 /**
732 * @return {string} 732 * @return {string}
733 */ 733 */
734 WebInspector.openLinkExternallyLabel = function() { 734 UI.openLinkExternallyLabel = function() {
735 return WebInspector.UIString.capitalize('Open ^link in ^new ^tab'); 735 return Common.UIString.capitalize('Open ^link in ^new ^tab');
736 }; 736 };
737 737
738 /** 738 /**
739 * @return {string} 739 * @return {string}
740 */ 740 */
741 WebInspector.copyLinkAddressLabel = function() { 741 UI.copyLinkAddressLabel = function() {
742 return WebInspector.UIString.capitalize('Copy ^link ^address'); 742 return Common.UIString.capitalize('Copy ^link ^address');
743 }; 743 };
744 744
745 /** 745 /**
746 * @return {string} 746 * @return {string}
747 */ 747 */
748 WebInspector.anotherProfilerActiveLabel = function() { 748 UI.anotherProfilerActiveLabel = function() {
749 return WebInspector.UIString('Another profiler is already active'); 749 return Common.UIString('Another profiler is already active');
750 }; 750 };
751 751
752 /** 752 /**
753 * @param {string|undefined} description 753 * @param {string|undefined} description
754 * @return {string} 754 * @return {string}
755 */ 755 */
756 WebInspector.asyncStackTraceLabel = function(description) { 756 UI.asyncStackTraceLabel = function(description) {
757 if (description) 757 if (description)
758 return description + ' ' + WebInspector.UIString('(async)'); 758 return description + ' ' + Common.UIString('(async)');
759 return WebInspector.UIString('Async Call'); 759 return Common.UIString('Async Call');
760 }; 760 };
761 761
762 /** 762 /**
763 * @param {!Element} element 763 * @param {!Element} element
764 */ 764 */
765 WebInspector.installComponentRootStyles = function(element) { 765 UI.installComponentRootStyles = function(element) {
766 WebInspector.appendStyle(element, 'ui/inspectorCommon.css'); 766 UI.appendStyle(element, 'ui/inspectorCommon.css');
767 WebInspector.themeSupport.injectHighlightStyleSheets(element); 767 UI.themeSupport.injectHighlightStyleSheets(element);
768 element.classList.add('platform-' + WebInspector.platform()); 768 element.classList.add('platform-' + Host.platform());
769 }; 769 };
770 770
771 /** 771 /**
772 * @param {!Element} element 772 * @param {!Element} element
773 * @param {string=} cssFile 773 * @param {string=} cssFile
774 * @return {!DocumentFragment} 774 * @return {!DocumentFragment}
775 */ 775 */
776 WebInspector.createShadowRootWithCoreStyles = function(element, cssFile) { 776 UI.createShadowRootWithCoreStyles = function(element, cssFile) {
777 var shadowRoot = element.createShadowRoot(); 777 var shadowRoot = element.createShadowRoot();
778 WebInspector.appendStyle(shadowRoot, 'ui/inspectorCommon.css'); 778 UI.appendStyle(shadowRoot, 'ui/inspectorCommon.css');
779 WebInspector.themeSupport.injectHighlightStyleSheets(shadowRoot); 779 UI.themeSupport.injectHighlightStyleSheets(shadowRoot);
780 if (cssFile) 780 if (cssFile)
781 WebInspector.appendStyle(shadowRoot, cssFile); 781 UI.appendStyle(shadowRoot, cssFile);
782 shadowRoot.addEventListener('focus', WebInspector._focusChanged.bind(WebInspec tor), true); 782 shadowRoot.addEventListener('focus', UI._focusChanged.bind(UI), true);
783 return shadowRoot; 783 return shadowRoot;
784 }; 784 };
785 785
786 /** 786 /**
787 * @param {!Document} document 787 * @param {!Document} document
788 * @param {!Event} event 788 * @param {!Event} event
789 */ 789 */
790 WebInspector._windowFocused = function(document, event) { 790 UI._windowFocused = function(document, event) {
791 if (event.target.document.nodeType === Node.DOCUMENT_NODE) 791 if (event.target.document.nodeType === Node.DOCUMENT_NODE)
792 document.body.classList.remove('inactive'); 792 document.body.classList.remove('inactive');
793 }; 793 };
794 794
795 /** 795 /**
796 * @param {!Document} document 796 * @param {!Document} document
797 * @param {!Event} event 797 * @param {!Event} event
798 */ 798 */
799 WebInspector._windowBlurred = function(document, event) { 799 UI._windowBlurred = function(document, event) {
800 if (event.target.document.nodeType === Node.DOCUMENT_NODE) 800 if (event.target.document.nodeType === Node.DOCUMENT_NODE)
801 document.body.classList.add('inactive'); 801 document.body.classList.add('inactive');
802 }; 802 };
803 803
804 /** 804 /**
805 * @param {!Event} event 805 * @param {!Event} event
806 */ 806 */
807 WebInspector._focusChanged = function(event) { 807 UI._focusChanged = function(event) {
808 var document = event.target && event.target.ownerDocument; 808 var document = event.target && event.target.ownerDocument;
809 var element = document ? document.deepActiveElement() : null; 809 var element = document ? document.deepActiveElement() : null;
810 WebInspector.Widget.focusWidgetForNode(element); 810 UI.Widget.focusWidgetForNode(element);
811 }; 811 };
812 812
813 /** 813 /**
814 * @unrestricted 814 * @unrestricted
815 */ 815 */
816 WebInspector.ElementFocusRestorer = class { 816 UI.ElementFocusRestorer = class {
817 /** 817 /**
818 * @param {!Element} element 818 * @param {!Element} element
819 */ 819 */
820 constructor(element) { 820 constructor(element) {
821 this._element = element; 821 this._element = element;
822 this._previous = element.ownerDocument.deepActiveElement(); 822 this._previous = element.ownerDocument.deepActiveElement();
823 element.focus(); 823 element.focus();
824 } 824 }
825 825
826 restore() { 826 restore() {
827 if (!this._element) 827 if (!this._element)
828 return; 828 return;
829 if (this._element.hasFocus() && this._previous) 829 if (this._element.hasFocus() && this._previous)
830 this._previous.focus(); 830 this._previous.focus();
831 this._previous = null; 831 this._previous = null;
832 this._element = null; 832 this._element = null;
833 } 833 }
834 }; 834 };
835 835
836 /** 836 /**
837 * @param {!Element} element 837 * @param {!Element} element
838 * @param {number} offset 838 * @param {number} offset
839 * @param {number} length 839 * @param {number} length
840 * @param {!Array.<!Object>=} domChanges 840 * @param {!Array.<!Object>=} domChanges
841 * @return {?Element} 841 * @return {?Element}
842 */ 842 */
843 WebInspector.highlightSearchResult = function(element, offset, length, domChange s) { 843 UI.highlightSearchResult = function(element, offset, length, domChanges) {
844 var result = WebInspector.highlightSearchResults(element, [new WebInspector.So urceRange(offset, length)], domChanges); 844 var result = UI.highlightSearchResults(element, [new Common.SourceRange(offset , length)], domChanges);
845 return result.length ? result[0] : null; 845 return result.length ? result[0] : null;
846 }; 846 };
847 847
848 /** 848 /**
849 * @param {!Element} element 849 * @param {!Element} element
850 * @param {!Array.<!WebInspector.SourceRange>} resultRanges 850 * @param {!Array.<!Common.SourceRange>} resultRanges
851 * @param {!Array.<!Object>=} changes 851 * @param {!Array.<!Object>=} changes
852 * @return {!Array.<!Element>} 852 * @return {!Array.<!Element>}
853 */ 853 */
854 WebInspector.highlightSearchResults = function(element, resultRanges, changes) { 854 UI.highlightSearchResults = function(element, resultRanges, changes) {
855 return WebInspector.highlightRangesWithStyleClass( 855 return UI.highlightRangesWithStyleClass(
856 element, resultRanges, WebInspector.highlightedSearchResultClassName, chan ges); 856 element, resultRanges, UI.highlightedSearchResultClassName, changes);
857 }; 857 };
858 858
859 /** 859 /**
860 * @param {!Element} element 860 * @param {!Element} element
861 * @param {string} className 861 * @param {string} className
862 */ 862 */
863 WebInspector.runCSSAnimationOnce = function(element, className) { 863 UI.runCSSAnimationOnce = function(element, className) {
864 function animationEndCallback() { 864 function animationEndCallback() {
865 element.classList.remove(className); 865 element.classList.remove(className);
866 element.removeEventListener('webkitAnimationEnd', animationEndCallback, fals e); 866 element.removeEventListener('webkitAnimationEnd', animationEndCallback, fals e);
867 } 867 }
868 868
869 if (element.classList.contains(className)) 869 if (element.classList.contains(className))
870 element.classList.remove(className); 870 element.classList.remove(className);
871 871
872 element.addEventListener('webkitAnimationEnd', animationEndCallback, false); 872 element.addEventListener('webkitAnimationEnd', animationEndCallback, false);
873 element.classList.add(className); 873 element.classList.add(className);
874 }; 874 };
875 875
876 /** 876 /**
877 * @param {!Element} element 877 * @param {!Element} element
878 * @param {!Array.<!WebInspector.SourceRange>} resultRanges 878 * @param {!Array.<!Common.SourceRange>} resultRanges
879 * @param {string} styleClass 879 * @param {string} styleClass
880 * @param {!Array.<!Object>=} changes 880 * @param {!Array.<!Object>=} changes
881 * @return {!Array.<!Element>} 881 * @return {!Array.<!Element>}
882 */ 882 */
883 WebInspector.highlightRangesWithStyleClass = function(element, resultRanges, sty leClass, changes) { 883 UI.highlightRangesWithStyleClass = function(element, resultRanges, styleClass, c hanges) {
884 changes = changes || []; 884 changes = changes || [];
885 var highlightNodes = []; 885 var highlightNodes = [];
886 var textNodes = element.childTextNodes(); 886 var textNodes = element.childTextNodes();
887 var lineText = textNodes 887 var lineText = textNodes
888 .map(function(node) { 888 .map(function(node) {
889 return node.textContent; 889 return node.textContent;
890 }) 890 })
891 .join(''); 891 .join('');
892 var ownerDocument = element.ownerDocument; 892 var ownerDocument = element.ownerDocument;
893 893
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 changes.push({node: textNode, type: 'changed', oldText: text, newText: t extNode.textContent}); 955 changes.push({node: textNode, type: 'changed', oldText: text, newText: t extNode.textContent});
956 } 956 }
957 } 957 }
958 startIndex = endIndex; 958 startIndex = endIndex;
959 nodeRanges[startIndex].offset = endOffset; 959 nodeRanges[startIndex].offset = endOffset;
960 nodeRanges[startIndex].length = lastTextNode.textContent.length; 960 nodeRanges[startIndex].length = lastTextNode.textContent.length;
961 } 961 }
962 return highlightNodes; 962 return highlightNodes;
963 }; 963 };
964 964
965 WebInspector.applyDomChanges = function(domChanges) { 965 UI.applyDomChanges = function(domChanges) {
966 for (var i = 0, size = domChanges.length; i < size; ++i) { 966 for (var i = 0, size = domChanges.length; i < size; ++i) {
967 var entry = domChanges[i]; 967 var entry = domChanges[i];
968 switch (entry.type) { 968 switch (entry.type) {
969 case 'added': 969 case 'added':
970 entry.parent.insertBefore(entry.node, entry.nextSibling); 970 entry.parent.insertBefore(entry.node, entry.nextSibling);
971 break; 971 break;
972 case 'changed': 972 case 'changed':
973 entry.node.textContent = entry.newText; 973 entry.node.textContent = entry.newText;
974 break; 974 break;
975 } 975 }
976 } 976 }
977 }; 977 };
978 978
979 WebInspector.revertDomChanges = function(domChanges) { 979 UI.revertDomChanges = function(domChanges) {
980 for (var i = domChanges.length - 1; i >= 0; --i) { 980 for (var i = domChanges.length - 1; i >= 0; --i) {
981 var entry = domChanges[i]; 981 var entry = domChanges[i];
982 switch (entry.type) { 982 switch (entry.type) {
983 case 'added': 983 case 'added':
984 entry.node.remove(); 984 entry.node.remove();
985 break; 985 break;
986 case 'changed': 986 case 'changed':
987 entry.node.textContent = entry.oldText; 987 entry.node.textContent = entry.oldText;
988 break; 988 break;
989 } 989 }
990 } 990 }
991 }; 991 };
992 992
993 /** 993 /**
994 * @param {!Element} element 994 * @param {!Element} element
995 * @param {?Element=} containerElement 995 * @param {?Element=} containerElement
996 * @return {!Size} 996 * @return {!Size}
997 */ 997 */
998 WebInspector.measurePreferredSize = function(element, containerElement) { 998 UI.measurePreferredSize = function(element, containerElement) {
999 var oldParent = element.parentElement; 999 var oldParent = element.parentElement;
1000 var oldNextSibling = element.nextSibling; 1000 var oldNextSibling = element.nextSibling;
1001 containerElement = containerElement || element.ownerDocument.body; 1001 containerElement = containerElement || element.ownerDocument.body;
1002 containerElement.appendChild(element); 1002 containerElement.appendChild(element);
1003 element.positionAt(0, 0); 1003 element.positionAt(0, 0);
1004 var result = new Size(element.offsetWidth, element.offsetHeight); 1004 var result = new Size(element.offsetWidth, element.offsetHeight);
1005 1005
1006 element.positionAt(undefined, undefined); 1006 element.positionAt(undefined, undefined);
1007 if (oldParent) 1007 if (oldParent)
1008 oldParent.insertBefore(element, oldNextSibling); 1008 oldParent.insertBefore(element, oldNextSibling);
1009 else 1009 else
1010 element.remove(); 1010 element.remove();
1011 return result; 1011 return result;
1012 }; 1012 };
1013 1013
1014 /** 1014 /**
1015 * @unrestricted 1015 * @unrestricted
1016 */ 1016 */
1017 WebInspector.InvokeOnceHandlers = class { 1017 UI.InvokeOnceHandlers = class {
1018 /** 1018 /**
1019 * @param {boolean} autoInvoke 1019 * @param {boolean} autoInvoke
1020 */ 1020 */
1021 constructor(autoInvoke) { 1021 constructor(autoInvoke) {
1022 this._handlers = null; 1022 this._handlers = null;
1023 this._autoInvoke = autoInvoke; 1023 this._autoInvoke = autoInvoke;
1024 } 1024 }
1025 1025
1026 /** 1026 /**
1027 * @param {!Object} object 1027 * @param {!Object} object
(...skipping 27 matching lines...) Expand all
1055 var keys = handlers.keysArray(); 1055 var keys = handlers.keysArray();
1056 for (var i = 0; i < keys.length; ++i) { 1056 for (var i = 0; i < keys.length; ++i) {
1057 var object = keys[i]; 1057 var object = keys[i];
1058 var methods = handlers.get(object).valuesArray(); 1058 var methods = handlers.get(object).valuesArray();
1059 for (var j = 0; j < methods.length; ++j) 1059 for (var j = 0; j < methods.length; ++j)
1060 methods[j].call(object); 1060 methods[j].call(object);
1061 } 1061 }
1062 } 1062 }
1063 }; 1063 };
1064 1064
1065 WebInspector._coalescingLevel = 0; 1065 UI._coalescingLevel = 0;
1066 WebInspector._postUpdateHandlers = null; 1066 UI._postUpdateHandlers = null;
1067 1067
1068 WebInspector.startBatchUpdate = function() { 1068 UI.startBatchUpdate = function() {
1069 if (!WebInspector._coalescingLevel++) 1069 if (!UI._coalescingLevel++)
1070 WebInspector._postUpdateHandlers = new WebInspector.InvokeOnceHandlers(false ); 1070 UI._postUpdateHandlers = new UI.InvokeOnceHandlers(false);
1071 }; 1071 };
1072 1072
1073 WebInspector.endBatchUpdate = function() { 1073 UI.endBatchUpdate = function() {
1074 if (--WebInspector._coalescingLevel) 1074 if (--UI._coalescingLevel)
1075 return; 1075 return;
1076 WebInspector._postUpdateHandlers.scheduleInvoke(); 1076 UI._postUpdateHandlers.scheduleInvoke();
1077 WebInspector._postUpdateHandlers = null; 1077 UI._postUpdateHandlers = null;
1078 }; 1078 };
1079 1079
1080 /** 1080 /**
1081 * @param {!Object} object 1081 * @param {!Object} object
1082 * @param {function()} method 1082 * @param {function()} method
1083 */ 1083 */
1084 WebInspector.invokeOnceAfterBatchUpdate = function(object, method) { 1084 UI.invokeOnceAfterBatchUpdate = function(object, method) {
1085 if (!WebInspector._postUpdateHandlers) 1085 if (!UI._postUpdateHandlers)
1086 WebInspector._postUpdateHandlers = new WebInspector.InvokeOnceHandlers(true) ; 1086 UI._postUpdateHandlers = new UI.InvokeOnceHandlers(true);
1087 WebInspector._postUpdateHandlers.add(object, method); 1087 UI._postUpdateHandlers.add(object, method);
1088 }; 1088 };
1089 1089
1090 /** 1090 /**
1091 * @param {!Window} window 1091 * @param {!Window} window
1092 * @param {!Function} func 1092 * @param {!Function} func
1093 * @param {!Array.<{from:number, to:number}>} params 1093 * @param {!Array.<{from:number, to:number}>} params
1094 * @param {number} frames 1094 * @param {number} frames
1095 * @param {function()=} animationComplete 1095 * @param {function()=} animationComplete
1096 * @return {function()} 1096 * @return {function()}
1097 */ 1097 */
1098 WebInspector.animateFunction = function(window, func, params, frames, animationC omplete) { 1098 UI.animateFunction = function(window, func, params, frames, animationComplete) {
1099 var values = new Array(params.length); 1099 var values = new Array(params.length);
1100 var deltas = new Array(params.length); 1100 var deltas = new Array(params.length);
1101 for (var i = 0; i < params.length; ++i) { 1101 for (var i = 0; i < params.length; ++i) {
1102 values[i] = params[i].from; 1102 values[i] = params[i].from;
1103 deltas[i] = (params[i].to - params[i].from) / frames; 1103 deltas[i] = (params[i].to - params[i].from) / frames;
1104 } 1104 }
1105 1105
1106 var raf = window.requestAnimationFrame(animationStep); 1106 var raf = window.requestAnimationFrame(animationStep);
1107 1107
1108 var framesLeft = frames; 1108 var framesLeft = frames;
(...skipping 17 matching lines...) Expand all
1126 function cancelAnimation() { 1126 function cancelAnimation() {
1127 window.cancelAnimationFrame(raf); 1127 window.cancelAnimationFrame(raf);
1128 } 1128 }
1129 1129
1130 return cancelAnimation; 1130 return cancelAnimation;
1131 }; 1131 };
1132 1132
1133 /** 1133 /**
1134 * @unrestricted 1134 * @unrestricted
1135 */ 1135 */
1136 WebInspector.LongClickController = class extends WebInspector.Object { 1136 UI.LongClickController = class extends Common.Object {
1137 /** 1137 /**
1138 * @param {!Element} element 1138 * @param {!Element} element
1139 * @param {function(!Event)} callback 1139 * @param {function(!Event)} callback
1140 */ 1140 */
1141 constructor(element, callback) { 1141 constructor(element, callback) {
1142 super(); 1142 super();
1143 this._element = element; 1143 this._element = element;
1144 this._callback = callback; 1144 this._callback = callback;
1145 this._enable(); 1145 this._enable();
1146 } 1146 }
(...skipping 14 matching lines...) Expand all
1161 1161
1162 this._element.addEventListener('mousedown', boundMouseDown, false); 1162 this._element.addEventListener('mousedown', boundMouseDown, false);
1163 this._element.addEventListener('mouseout', boundReset, false); 1163 this._element.addEventListener('mouseout', boundReset, false);
1164 this._element.addEventListener('mouseup', boundMouseUp, false); 1164 this._element.addEventListener('mouseup', boundMouseUp, false);
1165 this._element.addEventListener('click', boundReset, true); 1165 this._element.addEventListener('click', boundReset, true);
1166 1166
1167 this._longClickData = {mouseUp: boundMouseUp, mouseDown: boundMouseDown, res et: boundReset}; 1167 this._longClickData = {mouseUp: boundMouseUp, mouseDown: boundMouseDown, res et: boundReset};
1168 1168
1169 /** 1169 /**
1170 * @param {!Event} e 1170 * @param {!Event} e
1171 * @this {WebInspector.LongClickController} 1171 * @this {UI.LongClickController}
1172 */ 1172 */
1173 function mouseDown(e) { 1173 function mouseDown(e) {
1174 if (e.which !== 1) 1174 if (e.which !== 1)
1175 return; 1175 return;
1176 var callback = this._callback; 1176 var callback = this._callback;
1177 this._longClickInterval = setTimeout(callback.bind(null, e), 200); 1177 this._longClickInterval = setTimeout(callback.bind(null, e), 200);
1178 } 1178 }
1179 1179
1180 /** 1180 /**
1181 * @param {!Event} e 1181 * @param {!Event} e
1182 * @this {WebInspector.LongClickController} 1182 * @this {UI.LongClickController}
1183 */ 1183 */
1184 function mouseUp(e) { 1184 function mouseUp(e) {
1185 if (e.which !== 1) 1185 if (e.which !== 1)
1186 return; 1186 return;
1187 this.reset(); 1187 this.reset();
1188 } 1188 }
1189 } 1189 }
1190 1190
1191 dispose() { 1191 dispose() {
1192 if (!this._longClickData) 1192 if (!this._longClickData)
1193 return; 1193 return;
1194 this._element.removeEventListener('mousedown', this._longClickData.mouseDown , false); 1194 this._element.removeEventListener('mousedown', this._longClickData.mouseDown , false);
1195 this._element.removeEventListener('mouseout', this._longClickData.reset, fal se); 1195 this._element.removeEventListener('mouseout', this._longClickData.reset, fal se);
1196 this._element.removeEventListener('mouseup', this._longClickData.mouseUp, fa lse); 1196 this._element.removeEventListener('mouseup', this._longClickData.mouseUp, fa lse);
1197 this._element.addEventListener('click', this._longClickData.reset, true); 1197 this._element.addEventListener('click', this._longClickData.reset, true);
1198 delete this._longClickData; 1198 delete this._longClickData;
1199 } 1199 }
1200 }; 1200 };
1201 1201
1202 /** 1202 /**
1203 * @param {!Document} document 1203 * @param {!Document} document
1204 * @param {!WebInspector.Setting} themeSetting 1204 * @param {!Common.Setting} themeSetting
1205 */ 1205 */
1206 WebInspector.initializeUIUtils = function(document, themeSetting) { 1206 UI.initializeUIUtils = function(document, themeSetting) {
1207 document.defaultView.addEventListener('focus', WebInspector._windowFocused.bin d(WebInspector, document), false); 1207 document.defaultView.addEventListener('focus', UI._windowFocused.bind(UI, docu ment), false);
1208 document.defaultView.addEventListener('blur', WebInspector._windowBlurred.bind (WebInspector, document), false); 1208 document.defaultView.addEventListener('blur', UI._windowBlurred.bind(UI, docum ent), false);
1209 document.addEventListener('focus', WebInspector._focusChanged.bind(WebInspecto r), true); 1209 document.addEventListener('focus', UI._focusChanged.bind(UI), true);
1210 1210
1211 if (!WebInspector.themeSupport) 1211 if (!UI.themeSupport)
1212 WebInspector.themeSupport = new WebInspector.ThemeSupport(themeSetting); 1212 UI.themeSupport = new UI.ThemeSupport(themeSetting);
1213 WebInspector.themeSupport.applyTheme(document); 1213 UI.themeSupport.applyTheme(document);
1214 1214
1215 var body = /** @type {!Element} */ (document.body); 1215 var body = /** @type {!Element} */ (document.body);
1216 WebInspector.appendStyle(body, 'ui/inspectorStyle.css'); 1216 UI.appendStyle(body, 'ui/inspectorStyle.css');
1217 WebInspector.appendStyle(body, 'ui/popover.css'); 1217 UI.appendStyle(body, 'ui/popover.css');
1218 }; 1218 };
1219 1219
1220 /** 1220 /**
1221 * @param {string} name 1221 * @param {string} name
1222 * @return {string} 1222 * @return {string}
1223 */ 1223 */
1224 WebInspector.beautifyFunctionName = function(name) { 1224 UI.beautifyFunctionName = function(name) {
1225 return name || WebInspector.UIString('(anonymous)'); 1225 return name || Common.UIString('(anonymous)');
1226 }; 1226 };
1227 1227
1228 /** 1228 /**
1229 * @param {string} localName 1229 * @param {string} localName
1230 * @param {string} typeExtension 1230 * @param {string} typeExtension
1231 * @param {!Object} prototype 1231 * @param {!Object} prototype
1232 * @return {function()} 1232 * @return {function()}
1233 * @suppressGlobalPropertiesCheck 1233 * @suppressGlobalPropertiesCheck
1234 * @template T 1234 * @template T
1235 */ 1235 */
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 element.sliderElement.step = 1; 1313 element.sliderElement.step = 1;
1314 element.sliderElement.tabIndex = tabIndex; 1314 element.sliderElement.tabIndex = tabIndex;
1315 return element; 1315 return element;
1316 } 1316 }
1317 1317
1318 /** 1318 /**
1319 * @param {!Node} node 1319 * @param {!Node} node
1320 * @param {string} cssFile 1320 * @param {string} cssFile
1321 * @suppressGlobalPropertiesCheck 1321 * @suppressGlobalPropertiesCheck
1322 */ 1322 */
1323 WebInspector.appendStyle = 1323 UI.appendStyle = function(node, cssFile) {
1324 function(node, cssFile) {
1325 var content = Runtime.cachedResources[cssFile] || ''; 1324 var content = Runtime.cachedResources[cssFile] || '';
1326 if (!content) 1325 if (!content)
1327 console.error(cssFile + ' not preloaded. Check module.json'); 1326 console.error(cssFile + ' not preloaded. Check module.json');
1328 var styleElement = createElement('style'); 1327 var styleElement = createElement('style');
1329 styleElement.type = 'text/css'; 1328 styleElement.type = 'text/css';
1330 styleElement.textContent = content; 1329 styleElement.textContent = content;
1331 node.appendChild(styleElement); 1330 node.appendChild(styleElement);
1332 1331
1333 var themeStyleSheet = WebInspector.themeSupport.themeStyleSheet(cssFile, conte nt); 1332 var themeStyleSheet = UI.themeSupport.themeStyleSheet(cssFile, content);
1334 if (themeStyleSheet) { 1333 if (themeStyleSheet) {
1335 styleElement = createElement('style'); 1334 styleElement = createElement('style');
1336 styleElement.type = 'text/css'; 1335 styleElement.type = 'text/css';
1337 styleElement.textContent = themeStyleSheet + '\n' + Runtime.resolveSourceURL (cssFile + '.theme'); 1336 styleElement.textContent = themeStyleSheet + '\n' + Runtime.resolveSourceURL (cssFile + '.theme');
1338 node.appendChild(styleElement); 1337 node.appendChild(styleElement);
1339 } 1338 }
1340 } 1339 }
1341 1340
1342 ; 1341 ;
1343 (function() { 1342 (function() {
1344 registerCustomElement('button', 'text-button', { 1343 registerCustomElement('button', 'text-button', {
1345 /** 1344 /**
1346 * @this {Element} 1345 * @this {Element}
1347 */ 1346 */
1348 createdCallback: function() { 1347 createdCallback: function() {
1349 this.type = 'button'; 1348 this.type = 'button';
1350 var root = WebInspector.createShadowRootWithCoreStyles(this, 'ui/textButto n.css'); 1349 var root = UI.createShadowRootWithCoreStyles(this, 'ui/textButton.css');
1351 root.createChild('content'); 1350 root.createChild('content');
1352 }, 1351 },
1353 1352
1354 __proto__: HTMLButtonElement.prototype 1353 __proto__: HTMLButtonElement.prototype
1355 }); 1354 });
1356 1355
1357 registerCustomElement('label', 'dt-radio', { 1356 registerCustomElement('label', 'dt-radio', {
1358 /** 1357 /**
1359 * @this {Element} 1358 * @this {Element}
1360 */ 1359 */
1361 createdCallback: function() { 1360 createdCallback: function() {
1362 this.radioElement = this.createChild('input', 'dt-radio-button'); 1361 this.radioElement = this.createChild('input', 'dt-radio-button');
1363 this.radioElement.type = 'radio'; 1362 this.radioElement.type = 'radio';
1364 var root = WebInspector.createShadowRootWithCoreStyles(this, 'ui/radioButt on.css'); 1363 var root = UI.createShadowRootWithCoreStyles(this, 'ui/radioButton.css');
1365 root.createChild('content').select = '.dt-radio-button'; 1364 root.createChild('content').select = '.dt-radio-button';
1366 root.createChild('content'); 1365 root.createChild('content');
1367 this.addEventListener('click', radioClickHandler, false); 1366 this.addEventListener('click', radioClickHandler, false);
1368 }, 1367 },
1369 1368
1370 __proto__: HTMLLabelElement.prototype 1369 __proto__: HTMLLabelElement.prototype
1371 }); 1370 });
1372 1371
1373 /** 1372 /**
1374 * @param {!Event} event 1373 * @param {!Event} event
1375 * @suppressReceiverCheck 1374 * @suppressReceiverCheck
1376 * @this {Element} 1375 * @this {Element}
1377 */ 1376 */
1378 function radioClickHandler(event) { 1377 function radioClickHandler(event) {
1379 if (this.radioElement.checked || this.radioElement.disabled) 1378 if (this.radioElement.checked || this.radioElement.disabled)
1380 return; 1379 return;
1381 this.radioElement.checked = true; 1380 this.radioElement.checked = true;
1382 this.radioElement.dispatchEvent(new Event('change')); 1381 this.radioElement.dispatchEvent(new Event('change'));
1383 } 1382 }
1384 1383
1385 registerCustomElement('label', 'dt-checkbox', { 1384 registerCustomElement('label', 'dt-checkbox', {
1386 /** 1385 /**
1387 * @this {Element} 1386 * @this {Element}
1388 */ 1387 */
1389 createdCallback: function() { 1388 createdCallback: function() {
1390 this._root = WebInspector.createShadowRootWithCoreStyles(this, 'ui/checkbo xTextLabel.css'); 1389 this._root = UI.createShadowRootWithCoreStyles(this, 'ui/checkboxTextLabel .css');
1391 var checkboxElement = createElementWithClass('input', 'dt-checkbox-button' ); 1390 var checkboxElement = createElementWithClass('input', 'dt-checkbox-button' );
1392 checkboxElement.type = 'checkbox'; 1391 checkboxElement.type = 'checkbox';
1393 this._root.appendChild(checkboxElement); 1392 this._root.appendChild(checkboxElement);
1394 this.checkboxElement = checkboxElement; 1393 this.checkboxElement = checkboxElement;
1395 1394
1396 this.addEventListener('click', toggleCheckbox.bind(this)); 1395 this.addEventListener('click', toggleCheckbox.bind(this));
1397 1396
1398 /** 1397 /**
1399 * @param {!Event} event 1398 * @param {!Event} event
1400 * @this {Node} 1399 * @this {Node}
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 }, 1446 },
1448 1447
1449 __proto__: HTMLLabelElement.prototype 1448 __proto__: HTMLLabelElement.prototype
1450 }); 1449 });
1451 1450
1452 registerCustomElement('label', 'dt-icon-label', { 1451 registerCustomElement('label', 'dt-icon-label', {
1453 /** 1452 /**
1454 * @this {Element} 1453 * @this {Element}
1455 */ 1454 */
1456 createdCallback: function() { 1455 createdCallback: function() {
1457 var root = WebInspector.createShadowRootWithCoreStyles(this); 1456 var root = UI.createShadowRootWithCoreStyles(this);
1458 this._iconElement = WebInspector.Icon.create(); 1457 this._iconElement = UI.Icon.create();
1459 this._iconElement.style.setProperty('margin-right', '4px'); 1458 this._iconElement.style.setProperty('margin-right', '4px');
1460 root.appendChild(this._iconElement); 1459 root.appendChild(this._iconElement);
1461 root.createChild('content'); 1460 root.createChild('content');
1462 }, 1461 },
1463 1462
1464 /** 1463 /**
1465 * @param {string} type 1464 * @param {string} type
1466 * @this {Element} 1465 * @this {Element}
1467 */ 1466 */
1468 set type(type) { 1467 set type(type) {
1469 this._iconElement.setIconType(type); 1468 this._iconElement.setIconType(type);
1470 }, 1469 },
1471 1470
1472 __proto__: HTMLLabelElement.prototype 1471 __proto__: HTMLLabelElement.prototype
1473 }); 1472 });
1474 1473
1475 registerCustomElement('label', 'dt-slider', { 1474 registerCustomElement('label', 'dt-slider', {
1476 /** 1475 /**
1477 * @this {Element} 1476 * @this {Element}
1478 */ 1477 */
1479 createdCallback: function() { 1478 createdCallback: function() {
1480 var root = WebInspector.createShadowRootWithCoreStyles(this, 'ui/slider.cs s'); 1479 var root = UI.createShadowRootWithCoreStyles(this, 'ui/slider.css');
1481 this.sliderElement = createElementWithClass('input', 'dt-range-input'); 1480 this.sliderElement = createElementWithClass('input', 'dt-range-input');
1482 this.sliderElement.type = 'range'; 1481 this.sliderElement.type = 'range';
1483 root.appendChild(this.sliderElement); 1482 root.appendChild(this.sliderElement);
1484 }, 1483 },
1485 1484
1486 /** 1485 /**
1487 * @param {number} amount 1486 * @param {number} amount
1488 * @this {Element} 1487 * @this {Element}
1489 */ 1488 */
1490 set value(amount) { 1489 set value(amount) {
1491 this.sliderElement.value = amount; 1490 this.sliderElement.value = amount;
1492 }, 1491 },
1493 1492
1494 /** 1493 /**
1495 * @this {Element} 1494 * @this {Element}
1496 */ 1495 */
1497 get value() { 1496 get value() {
1498 return this.sliderElement.value; 1497 return this.sliderElement.value;
1499 }, 1498 },
1500 1499
1501 __proto__: HTMLLabelElement.prototype 1500 __proto__: HTMLLabelElement.prototype
1502 }); 1501 });
1503 1502
1504 registerCustomElement('label', 'dt-small-bubble', { 1503 registerCustomElement('label', 'dt-small-bubble', {
1505 /** 1504 /**
1506 * @this {Element} 1505 * @this {Element}
1507 */ 1506 */
1508 createdCallback: function() { 1507 createdCallback: function() {
1509 var root = WebInspector.createShadowRootWithCoreStyles(this, 'ui/smallBubb le.css'); 1508 var root = UI.createShadowRootWithCoreStyles(this, 'ui/smallBubble.css');
1510 this._textElement = root.createChild('div'); 1509 this._textElement = root.createChild('div');
1511 this._textElement.className = 'info'; 1510 this._textElement.className = 'info';
1512 this._textElement.createChild('content'); 1511 this._textElement.createChild('content');
1513 }, 1512 },
1514 1513
1515 /** 1514 /**
1516 * @param {string} type 1515 * @param {string} type
1517 * @this {Element} 1516 * @this {Element}
1518 */ 1517 */
1519 set type(type) { 1518 set type(type) {
1520 this._textElement.className = type; 1519 this._textElement.className = type;
1521 }, 1520 },
1522 1521
1523 __proto__: HTMLLabelElement.prototype 1522 __proto__: HTMLLabelElement.prototype
1524 }); 1523 });
1525 1524
1526 registerCustomElement('div', 'dt-close-button', { 1525 registerCustomElement('div', 'dt-close-button', {
1527 /** 1526 /**
1528 * @this {Element} 1527 * @this {Element}
1529 */ 1528 */
1530 createdCallback: function() { 1529 createdCallback: function() {
1531 var root = WebInspector.createShadowRootWithCoreStyles(this, 'ui/closeButt on.css'); 1530 var root = UI.createShadowRootWithCoreStyles(this, 'ui/closeButton.css');
1532 this._buttonElement = root.createChild('div', 'close-button'); 1531 this._buttonElement = root.createChild('div', 'close-button');
1533 }, 1532 },
1534 1533
1535 /** 1534 /**
1536 * @param {boolean} gray 1535 * @param {boolean} gray
1537 * @this {Element} 1536 * @this {Element}
1538 */ 1537 */
1539 set gray(gray) { 1538 set gray(gray) {
1540 this._buttonElement.className = gray ? 'close-button-gray' : 'close-button '; 1539 this._buttonElement.className = gray ? 'close-button-gray' : 'close-button ';
1541 }, 1540 },
1542 1541
1543 __proto__: HTMLDivElement.prototype 1542 __proto__: HTMLDivElement.prototype
1544 }); 1543 });
1545 })(); 1544 })();
1546 1545
1547 /** 1546 /**
1548 * @param {!Element} input 1547 * @param {!Element} input
1549 * @param {function(string)} apply 1548 * @param {function(string)} apply
1550 * @param {function(string):boolean} validate 1549 * @param {function(string):boolean} validate
1551 * @param {boolean} numeric 1550 * @param {boolean} numeric
1552 * @return {function(string)} 1551 * @return {function(string)}
1553 */ 1552 */
1554 WebInspector.bindInput = function(input, apply, validate, numeric) { 1553 UI.bindInput = function(input, apply, validate, numeric) {
1555 input.addEventListener('change', onChange, false); 1554 input.addEventListener('change', onChange, false);
1556 input.addEventListener('input', onInput, false); 1555 input.addEventListener('input', onInput, false);
1557 input.addEventListener('keydown', onKeyDown, false); 1556 input.addEventListener('keydown', onKeyDown, false);
1558 input.addEventListener('focus', input.select.bind(input), false); 1557 input.addEventListener('focus', input.select.bind(input), false);
1559 1558
1560 function onInput() { 1559 function onInput() {
1561 input.classList.toggle('error-input', !validate(input.value)); 1560 input.classList.toggle('error-input', !validate(input.value));
1562 } 1561 }
1563 1562
1564 function onChange() { 1563 function onChange() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 1613
1615 return setValue; 1614 return setValue;
1616 }; 1615 };
1617 1616
1618 /** 1617 /**
1619 * @param {!CanvasRenderingContext2D} context 1618 * @param {!CanvasRenderingContext2D} context
1620 * @param {string} text 1619 * @param {string} text
1621 * @param {number} maxWidth 1620 * @param {number} maxWidth
1622 * @return {string} 1621 * @return {string}
1623 */ 1622 */
1624 WebInspector.trimTextMiddle = function(context, text, maxWidth) { 1623 UI.trimTextMiddle = function(context, text, maxWidth) {
1625 const maxLength = 200; 1624 const maxLength = 200;
1626 if (maxWidth <= 10) 1625 if (maxWidth <= 10)
1627 return ''; 1626 return '';
1628 if (text.length > maxLength) 1627 if (text.length > maxLength)
1629 text = text.trimMiddle(maxLength); 1628 text = text.trimMiddle(maxLength);
1630 const textWidth = WebInspector.measureTextWidth(context, text); 1629 const textWidth = UI.measureTextWidth(context, text);
1631 if (textWidth <= maxWidth) 1630 if (textWidth <= maxWidth)
1632 return text; 1631 return text;
1633 1632
1634 var l = 0; 1633 var l = 0;
1635 var r = text.length; 1634 var r = text.length;
1636 var lv = 0; 1635 var lv = 0;
1637 var rv = textWidth; 1636 var rv = textWidth;
1638 while (l < r && lv !== rv && lv !== maxWidth) { 1637 while (l < r && lv !== rv && lv !== maxWidth) {
1639 const m = Math.ceil(l + (r - l) * (maxWidth - lv) / (rv - lv)); 1638 const m = Math.ceil(l + (r - l) * (maxWidth - lv) / (rv - lv));
1640 const mv = WebInspector.measureTextWidth(context, text.trimMiddle(m)); 1639 const mv = UI.measureTextWidth(context, text.trimMiddle(m));
1641 if (mv <= maxWidth) { 1640 if (mv <= maxWidth) {
1642 l = m; 1641 l = m;
1643 lv = mv; 1642 lv = mv;
1644 } else { 1643 } else {
1645 r = m - 1; 1644 r = m - 1;
1646 rv = mv; 1645 rv = mv;
1647 } 1646 }
1648 } 1647 }
1649 text = text.trimMiddle(l); 1648 text = text.trimMiddle(l);
1650 return text !== '\u2026' ? text : ''; 1649 return text !== '\u2026' ? text : '';
1651 }; 1650 };
1652 1651
1653 /** 1652 /**
1654 * @param {!CanvasRenderingContext2D} context 1653 * @param {!CanvasRenderingContext2D} context
1655 * @param {string} text 1654 * @param {string} text
1656 * @return {number} 1655 * @return {number}
1657 */ 1656 */
1658 WebInspector.measureTextWidth = function(context, text) { 1657 UI.measureTextWidth = function(context, text) {
1659 const maxCacheableLength = 200; 1658 const maxCacheableLength = 200;
1660 if (text.length > maxCacheableLength) 1659 if (text.length > maxCacheableLength)
1661 return context.measureText(text).width; 1660 return context.measureText(text).width;
1662 1661
1663 var widthCache = WebInspector.measureTextWidth._textWidthCache; 1662 var widthCache = UI.measureTextWidth._textWidthCache;
1664 if (!widthCache) { 1663 if (!widthCache) {
1665 widthCache = new Map(); 1664 widthCache = new Map();
1666 WebInspector.measureTextWidth._textWidthCache = widthCache; 1665 UI.measureTextWidth._textWidthCache = widthCache;
1667 } 1666 }
1668 const font = context.font; 1667 const font = context.font;
1669 var textWidths = widthCache.get(font); 1668 var textWidths = widthCache.get(font);
1670 if (!textWidths) { 1669 if (!textWidths) {
1671 textWidths = new Map(); 1670 textWidths = new Map();
1672 widthCache.set(font, textWidths); 1671 widthCache.set(font, textWidths);
1673 } 1672 }
1674 var width = textWidths.get(text); 1673 var width = textWidths.get(text);
1675 if (!width) { 1674 if (!width) {
1676 width = context.measureText(text).width; 1675 width = context.measureText(text).width;
1677 textWidths.set(text, width); 1676 textWidths.set(text, width);
1678 } 1677 }
1679 return width; 1678 return width;
1680 }; 1679 };
1681 1680
1682 /** 1681 /**
1683 * @unrestricted 1682 * @unrestricted
1684 */ 1683 */
1685 WebInspector.ThemeSupport = class { 1684 UI.ThemeSupport = class {
1686 /** 1685 /**
1687 * @param {!WebInspector.Setting} setting 1686 * @param {!Common.Setting} setting
1688 */ 1687 */
1689 constructor(setting) { 1688 constructor(setting) {
1690 this._themeName = setting.get() || 'default'; 1689 this._themeName = setting.get() || 'default';
1691 this._themableProperties = new Set([ 1690 this._themableProperties = new Set([
1692 'color', 'box-shadow', 'text-shadow', 'outline-color', 'background-image', 'background-color', 1691 'color', 'box-shadow', 'text-shadow', 'outline-color', 'background-image', 'background-color',
1693 'border-left-color', 'border-right-color', 'border-top-color', 'border-bot tom-color', '-webkit-border-image' 1692 'border-left-color', 'border-right-color', 'border-top-color', 'border-bot tom-color', '-webkit-border-image'
1694 ]); 1693 ]);
1695 /** @type {!Map<string, string>} */ 1694 /** @type {!Map<string, string>} */
1696 this._cachedThemePatches = new Map(); 1695 this._cachedThemePatches = new Map();
1697 this._setting = setting; 1696 this._setting = setting;
(...skipping 11 matching lines...) Expand all
1709 */ 1708 */
1710 themeName() { 1709 themeName() {
1711 return this._themeName; 1710 return this._themeName;
1712 } 1711 }
1713 1712
1714 /** 1713 /**
1715 * @param {!Element} element 1714 * @param {!Element} element
1716 */ 1715 */
1717 injectHighlightStyleSheets(element) { 1716 injectHighlightStyleSheets(element) {
1718 this._injectingStyleSheet = true; 1717 this._injectingStyleSheet = true;
1719 WebInspector.appendStyle(element, 'ui/inspectorSyntaxHighlight.css'); 1718 UI.appendStyle(element, 'ui/inspectorSyntaxHighlight.css');
1720 if (this._themeName === 'dark') 1719 if (this._themeName === 'dark')
1721 WebInspector.appendStyle(element, 'ui/inspectorSyntaxHighlightDark.css'); 1720 UI.appendStyle(element, 'ui/inspectorSyntaxHighlightDark.css');
1722 this._injectingStyleSheet = false; 1721 this._injectingStyleSheet = false;
1723 } 1722 }
1724 1723
1725 /** 1724 /**
1726 * @param {!Document} document 1725 * @param {!Document} document
1727 */ 1726 */
1728 applyTheme(document) { 1727 applyTheme(document) {
1729 if (!this.hasTheme()) 1728 if (!this.hasTheme())
1730 return; 1729 return;
1731 1730
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 var isSelection = selectorText.indexOf('.-theme-selection-color') !== -1; 1825 var isSelection = selectorText.indexOf('.-theme-selection-color') !== -1;
1827 if (selectorText.indexOf('-theme-') !== -1 && !isSelection) 1826 if (selectorText.indexOf('-theme-') !== -1 && !isSelection)
1828 return; 1827 return;
1829 1828
1830 if (name === '-webkit-border-image') { 1829 if (name === '-webkit-border-image') {
1831 output.push('-webkit-filter: invert(100%)'); 1830 output.push('-webkit-filter: invert(100%)');
1832 return; 1831 return;
1833 } 1832 }
1834 1833
1835 isSelection = isSelection || selectorText.indexOf('selected') !== -1 || sele ctorText.indexOf('.selection') !== -1; 1834 isSelection = isSelection || selectorText.indexOf('selected') !== -1 || sele ctorText.indexOf('.selection') !== -1;
1836 var colorUsage = WebInspector.ThemeSupport.ColorUsage.Unknown; 1835 var colorUsage = UI.ThemeSupport.ColorUsage.Unknown;
1837 if (isSelection) 1836 if (isSelection)
1838 colorUsage |= WebInspector.ThemeSupport.ColorUsage.Selection; 1837 colorUsage |= UI.ThemeSupport.ColorUsage.Selection;
1839 if (name.indexOf('background') === 0 || name.indexOf('border') === 0) 1838 if (name.indexOf('background') === 0 || name.indexOf('border') === 0)
1840 colorUsage |= WebInspector.ThemeSupport.ColorUsage.Background; 1839 colorUsage |= UI.ThemeSupport.ColorUsage.Background;
1841 if (name.indexOf('background') === -1) 1840 if (name.indexOf('background') === -1)
1842 colorUsage |= WebInspector.ThemeSupport.ColorUsage.Foreground; 1841 colorUsage |= UI.ThemeSupport.ColorUsage.Foreground;
1843 1842
1844 output.push(name); 1843 output.push(name);
1845 output.push(':'); 1844 output.push(':');
1846 var items = value.replace(WebInspector.Color.Regex, '\0$1\0').split('\0'); 1845 var items = value.replace(Common.Color.Regex, '\0$1\0').split('\0');
1847 for (var i = 0; i < items.length; ++i) 1846 for (var i = 0; i < items.length; ++i)
1848 output.push(this.patchColor(items[i], colorUsage)); 1847 output.push(this.patchColor(items[i], colorUsage));
1849 if (style.getPropertyPriority(name)) 1848 if (style.getPropertyPriority(name))
1850 output.push(' !important'); 1849 output.push(' !important');
1851 output.push(';'); 1850 output.push(';');
1852 } 1851 }
1853 1852
1854 /** 1853 /**
1855 * @param {string} text 1854 * @param {string} text
1856 * @param {!WebInspector.ThemeSupport.ColorUsage} colorUsage 1855 * @param {!UI.ThemeSupport.ColorUsage} colorUsage
1857 * @return {string} 1856 * @return {string}
1858 */ 1857 */
1859 patchColor(text, colorUsage) { 1858 patchColor(text, colorUsage) {
1860 var color = WebInspector.Color.parse(text); 1859 var color = Common.Color.parse(text);
1861 if (!color) 1860 if (!color)
1862 return text; 1861 return text;
1863 1862
1864 var hsla = color.hsla(); 1863 var hsla = color.hsla();
1865 this._patchHSLA(hsla, colorUsage); 1864 this._patchHSLA(hsla, colorUsage);
1866 var rgba = []; 1865 var rgba = [];
1867 WebInspector.Color.hsl2rgb(hsla, rgba); 1866 Common.Color.hsl2rgb(hsla, rgba);
1868 var outColor = new WebInspector.Color(rgba, color.format()); 1867 var outColor = new Common.Color(rgba, color.format());
1869 var outText = outColor.asString(null); 1868 var outText = outColor.asString(null);
1870 if (!outText) 1869 if (!outText)
1871 outText = outColor.asString(outColor.hasAlpha() ? WebInspector.Color.Forma t.RGBA : WebInspector.Color.Format.RGB); 1870 outText = outColor.asString(outColor.hasAlpha() ? Common.Color.Format.RGBA : Common.Color.Format.RGB);
1872 return outText || text; 1871 return outText || text;
1873 } 1872 }
1874 1873
1875 /** 1874 /**
1876 * @param {!Array<number>} hsla 1875 * @param {!Array<number>} hsla
1877 * @param {!WebInspector.ThemeSupport.ColorUsage} colorUsage 1876 * @param {!UI.ThemeSupport.ColorUsage} colorUsage
1878 */ 1877 */
1879 _patchHSLA(hsla, colorUsage) { 1878 _patchHSLA(hsla, colorUsage) {
1880 var hue = hsla[0]; 1879 var hue = hsla[0];
1881 var sat = hsla[1]; 1880 var sat = hsla[1];
1882 var lit = hsla[2]; 1881 var lit = hsla[2];
1883 var alpha = hsla[3]; 1882 var alpha = hsla[3];
1884 1883
1885 switch (this._themeName) { 1884 switch (this._themeName) {
1886 case 'dark': 1885 case 'dark':
1887 if (colorUsage & WebInspector.ThemeSupport.ColorUsage.Selection) 1886 if (colorUsage & UI.ThemeSupport.ColorUsage.Selection)
1888 hue = (hue + 0.5) % 1; 1887 hue = (hue + 0.5) % 1;
1889 var minCap = colorUsage & WebInspector.ThemeSupport.ColorUsage.Backgroun d ? 0.14 : 0; 1888 var minCap = colorUsage & UI.ThemeSupport.ColorUsage.Background ? 0.14 : 0;
1890 var maxCap = colorUsage & WebInspector.ThemeSupport.ColorUsage.Foregroun d ? 0.9 : 1; 1889 var maxCap = colorUsage & UI.ThemeSupport.ColorUsage.Foreground ? 0.9 : 1;
1891 lit = 1 - lit; 1890 lit = 1 - lit;
1892 if (lit < minCap * 2) 1891 if (lit < minCap * 2)
1893 lit = minCap + lit / 2; 1892 lit = minCap + lit / 2;
1894 else if (lit > 2 * maxCap - 1) 1893 else if (lit > 2 * maxCap - 1)
1895 lit = maxCap - 1 / 2 + lit / 2; 1894 lit = maxCap - 1 / 2 + lit / 2;
1896 1895
1897 break; 1896 break;
1898 } 1897 }
1899 hsla[0] = Number.constrain(hue, 0, 1); 1898 hsla[0] = Number.constrain(hue, 0, 1);
1900 hsla[1] = Number.constrain(sat, 0, 1); 1899 hsla[1] = Number.constrain(sat, 0, 1);
1901 hsla[2] = Number.constrain(lit, 0, 1); 1900 hsla[2] = Number.constrain(lit, 0, 1);
1902 hsla[3] = Number.constrain(alpha, 0, 1); 1901 hsla[3] = Number.constrain(alpha, 0, 1);
1903 } 1902 }
1904 }; 1903 };
1905 1904
1906 /** 1905 /**
1907 * @enum {number} 1906 * @enum {number}
1908 */ 1907 */
1909 WebInspector.ThemeSupport.ColorUsage = { 1908 UI.ThemeSupport.ColorUsage = {
1910 Unknown: 0, 1909 Unknown: 0,
1911 Foreground: 1 << 0, 1910 Foreground: 1 << 0,
1912 Background: 1 << 1, 1911 Background: 1 << 1,
1913 Selection: 1 << 2, 1912 Selection: 1 << 2,
1914 }; 1913 };
1915 1914
1916 /** 1915 /**
1917 * @param {string} url 1916 * @param {string} url
1918 * @param {string=} linkText 1917 * @param {string=} linkText
1919 * @param {string=} classes 1918 * @param {string=} classes
1920 * @param {boolean=} isExternal 1919 * @param {boolean=} isExternal
1921 * @param {string=} tooltipText 1920 * @param {string=} tooltipText
1922 * @return {!Element} 1921 * @return {!Element}
1923 */ 1922 */
1924 WebInspector.linkifyURLAsNode = function(url, linkText, classes, isExternal, too ltipText) { 1923 UI.linkifyURLAsNode = function(url, linkText, classes, isExternal, tooltipText) {
1925 if (!linkText) 1924 if (!linkText)
1926 linkText = url; 1925 linkText = url;
1927 1926
1928 var a = createElementWithClass('a', classes); 1927 var a = createElementWithClass('a', classes);
1929 var href = url; 1928 var href = url;
1930 if (url.trim().toLowerCase().startsWith('javascript:')) 1929 if (url.trim().toLowerCase().startsWith('javascript:'))
1931 href = null; 1930 href = null;
1932 if (isExternal && WebInspector.ParsedURL.isRelativeURL(url)) 1931 if (isExternal && Common.ParsedURL.isRelativeURL(url))
1933 href = null; 1932 href = null;
1934 if (href !== null) { 1933 if (href !== null) {
1935 a.href = href; 1934 a.href = href;
1936 a.classList.add(isExternal ? 'webkit-html-external-link' : 'webkit-html-reso urce-link'); 1935 a.classList.add(isExternal ? 'webkit-html-external-link' : 'webkit-html-reso urce-link');
1937 } 1936 }
1938 if (!tooltipText && linkText !== url) 1937 if (!tooltipText && linkText !== url)
1939 a.title = url; 1938 a.title = url;
1940 else if (tooltipText) 1939 else if (tooltipText)
1941 a.title = tooltipText; 1940 a.title = tooltipText;
1942 a.textContent = linkText.trimMiddle(150); 1941 a.textContent = linkText.trimMiddle(150);
1943 if (isExternal) 1942 if (isExternal)
1944 a.setAttribute('target', '_blank'); 1943 a.setAttribute('target', '_blank');
1945 1944
1946 return a; 1945 return a;
1947 }; 1946 };
1948 1947
1949 /** 1948 /**
1950 * @param {string} article 1949 * @param {string} article
1951 * @param {string} title 1950 * @param {string} title
1952 * @return {!Element} 1951 * @return {!Element}
1953 */ 1952 */
1954 WebInspector.linkifyDocumentationURLAsNode = function(article, title) { 1953 UI.linkifyDocumentationURLAsNode = function(article, title) {
1955 return WebInspector.linkifyURLAsNode( 1954 return UI.linkifyURLAsNode(
1956 'https://developers.google.com/web/tools/chrome-devtools/' + article, titl e, undefined, true); 1955 'https://developers.google.com/web/tools/chrome-devtools/' + article, titl e, undefined, true);
1957 }; 1956 };
1958 1957
1959 /** 1958 /**
1960 * @param {string} url 1959 * @param {string} url
1961 * @return {!Promise<?Image>} 1960 * @return {!Promise<?Image>}
1962 */ 1961 */
1963 WebInspector.loadImage = function(url) { 1962 UI.loadImage = function(url) {
1964 return new Promise(fulfill => { 1963 return new Promise(fulfill => {
1965 var image = new Image(); 1964 var image = new Image();
1966 image.addEventListener('load', () => fulfill(image)); 1965 image.addEventListener('load', () => fulfill(image));
1967 image.addEventListener('error', () => fulfill(null)); 1966 image.addEventListener('error', () => fulfill(null));
1968 image.src = url; 1967 image.src = url;
1969 }); 1968 });
1970 }; 1969 };
1971 1970
1972 /** @type {!WebInspector.ThemeSupport} */ 1971 /** @type {!UI.ThemeSupport} */
1973 WebInspector.themeSupport; 1972 UI.themeSupport;
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/Tooltip.js ('k') | third_party/WebKit/Source/devtools/front_end/ui/View.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698