OLD | NEW |
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 clearInterval(startTimer); | 60 clearInterval(startTimer); |
61 startTimer = null; | 61 startTimer = null; |
62 } | 62 } |
63 | 63 |
64 var startTimer; | 64 var startTimer; |
65 element.addEventListener("mousedown", onMouseDown, false); | 65 element.addEventListener("mousedown", onMouseDown, false); |
66 if (startDelay) | 66 if (startDelay) |
67 element.addEventListener("mouseup", onMouseUp, false); | 67 element.addEventListener("mouseup", onMouseUp, false); |
68 if (hoverCursor !== null) | 68 if (hoverCursor !== null) |
69 element.style.cursor = hoverCursor || cursor; | 69 element.style.cursor = hoverCursor || cursor; |
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 WebInspector.elementDragStart = function(targetElement, elementDragStart, elemen
tDrag, elementDragEnd, cursor, event) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 targetElement.style.cursor = cursor; | 113 targetElement.style.cursor = cursor; |
114 targetDocument.body.style.cursor = cursor; | 114 targetDocument.body.style.cursor = cursor; |
115 } | 115 } |
116 function restoreCursor(oldCursor) | 116 function restoreCursor(oldCursor) |
117 { | 117 { |
118 targetDocument.body.style.removeProperty("cursor"); | 118 targetDocument.body.style.removeProperty("cursor"); |
119 targetElement.style.cursor = oldCursor; | 119 targetElement.style.cursor = oldCursor; |
120 WebInspector._restoreCursorAfterDrag = null; | 120 WebInspector._restoreCursorAfterDrag = null; |
121 } | 121 } |
122 event.preventDefault(); | 122 event.preventDefault(); |
123 } | 123 }; |
124 | 124 |
125 WebInspector._mouseOutWhileDragging = function() | 125 WebInspector._mouseOutWhileDragging = function() |
126 { | 126 { |
127 var document = WebInspector._mouseOutWhileDraggingTargetDocument; | 127 var document = WebInspector._mouseOutWhileDraggingTargetDocument; |
128 WebInspector._unregisterMouseOutWhileDragging(); | 128 WebInspector._unregisterMouseOutWhileDragging(); |
129 WebInspector._elementDraggingGlassPane = new WebInspector.GlassPane(document
); | 129 WebInspector._elementDraggingGlassPane = new WebInspector.GlassPane(document
); |
130 } | 130 }; |
131 | 131 |
132 WebInspector._unregisterMouseOutWhileDragging = function() | 132 WebInspector._unregisterMouseOutWhileDragging = function() |
133 { | 133 { |
134 if (!WebInspector._mouseOutWhileDraggingTargetDocument) | 134 if (!WebInspector._mouseOutWhileDraggingTargetDocument) |
135 return; | 135 return; |
136 WebInspector._mouseOutWhileDraggingTargetDocument.removeEventListener("mouse
out", WebInspector._mouseOutWhileDragging, true); | 136 WebInspector._mouseOutWhileDraggingTargetDocument.removeEventListener("mouse
out", WebInspector._mouseOutWhileDragging, true); |
137 delete WebInspector._mouseOutWhileDraggingTargetDocument; | 137 delete WebInspector._mouseOutWhileDraggingTargetDocument; |
138 } | 138 }; |
139 | 139 |
140 WebInspector._unregisterDragEvents = function() | 140 WebInspector._unregisterDragEvents = function() |
141 { | 141 { |
142 if (!WebInspector._dragEventsTargetDocument) | 142 if (!WebInspector._dragEventsTargetDocument) |
143 return; | 143 return; |
144 WebInspector._dragEventsTargetDocument.removeEventListener("mousemove", WebI
nspector._elementDragMove, true); | 144 WebInspector._dragEventsTargetDocument.removeEventListener("mousemove", WebI
nspector._elementDragMove, true); |
145 WebInspector._dragEventsTargetDocument.removeEventListener("mouseup", WebIns
pector._elementDragEnd, true); | 145 WebInspector._dragEventsTargetDocument.removeEventListener("mouseup", WebIns
pector._elementDragEnd, true); |
146 if (WebInspector._dragEventsTargetDocument !== WebInspector._dragEventsTarge
tDocumentTop) | 146 if (WebInspector._dragEventsTargetDocument !== WebInspector._dragEventsTarge
tDocumentTop) |
147 WebInspector._dragEventsTargetDocumentTop.removeEventListener("mouseup",
WebInspector._elementDragEnd, true); | 147 WebInspector._dragEventsTargetDocumentTop.removeEventListener("mouseup",
WebInspector._elementDragEnd, true); |
148 delete WebInspector._dragEventsTargetDocument; | 148 delete WebInspector._dragEventsTargetDocument; |
149 delete WebInspector._dragEventsTargetDocumentTop; | 149 delete WebInspector._dragEventsTargetDocumentTop; |
150 } | 150 }; |
151 | 151 |
152 /** | 152 /** |
153 * @param {!Event} event | 153 * @param {!Event} event |
154 */ | 154 */ |
155 WebInspector._elementDragMove = function(event) | 155 WebInspector._elementDragMove = function(event) |
156 { | 156 { |
157 if (event.buttons !== 1) { | 157 if (event.buttons !== 1) { |
158 WebInspector._elementDragEnd(event); | 158 WebInspector._elementDragEnd(event); |
159 return; | 159 return; |
160 } | 160 } |
161 | 161 |
162 if (WebInspector._elementDraggingEventListener(/** @type {!MouseEvent} */ (e
vent))) | 162 if (WebInspector._elementDraggingEventListener(/** @type {!MouseEvent} */ (e
vent))) |
163 WebInspector._cancelDragEvents(event); | 163 WebInspector._cancelDragEvents(event); |
164 } | 164 }; |
165 | 165 |
166 /** | 166 /** |
167 * @param {!Event} event | 167 * @param {!Event} event |
168 */ | 168 */ |
169 WebInspector._cancelDragEvents = function(event) | 169 WebInspector._cancelDragEvents = function(event) |
170 { | 170 { |
171 WebInspector._unregisterDragEvents(); | 171 WebInspector._unregisterDragEvents(); |
172 WebInspector._unregisterMouseOutWhileDragging(); | 172 WebInspector._unregisterMouseOutWhileDragging(); |
173 | 173 |
174 if (WebInspector._restoreCursorAfterDrag) | 174 if (WebInspector._restoreCursorAfterDrag) |
175 WebInspector._restoreCursorAfterDrag(); | 175 WebInspector._restoreCursorAfterDrag(); |
176 | 176 |
177 if (WebInspector._elementDraggingGlassPane) | 177 if (WebInspector._elementDraggingGlassPane) |
178 WebInspector._elementDraggingGlassPane.dispose(); | 178 WebInspector._elementDraggingGlassPane.dispose(); |
179 | 179 |
180 delete WebInspector._elementDraggingGlassPane; | 180 delete WebInspector._elementDraggingGlassPane; |
181 delete WebInspector._elementDraggingEventListener; | 181 delete WebInspector._elementDraggingEventListener; |
182 delete WebInspector._elementEndDraggingEventListener; | 182 delete WebInspector._elementEndDraggingEventListener; |
183 } | 183 }; |
184 | 184 |
185 /** | 185 /** |
186 * @param {!Event} event | 186 * @param {!Event} event |
187 */ | 187 */ |
188 WebInspector._elementDragEnd = function(event) | 188 WebInspector._elementDragEnd = function(event) |
189 { | 189 { |
190 var elementDragEnd = WebInspector._elementEndDraggingEventListener; | 190 var elementDragEnd = WebInspector._elementEndDraggingEventListener; |
191 | 191 |
192 WebInspector._cancelDragEvents(/** @type {!MouseEvent} */ (event)); | 192 WebInspector._cancelDragEvents(/** @type {!MouseEvent} */ (event)); |
193 | 193 |
194 event.preventDefault(); | 194 event.preventDefault(); |
195 if (elementDragEnd) | 195 if (elementDragEnd) |
196 elementDragEnd(/** @type {!MouseEvent} */ (event)); | 196 elementDragEnd(/** @type {!MouseEvent} */ (event)); |
197 } | 197 }; |
198 | 198 |
199 /** | 199 /** |
200 * @param {!Element} element | 200 * @param {!Element} element |
201 * @param {function(number, number, !MouseEvent): boolean} elementDragStart | 201 * @param {function(number, number, !MouseEvent): boolean} elementDragStart |
202 * @param {function(number, number)} elementDrag | 202 * @param {function(number, number)} elementDrag |
203 * @param {function(number, number)} elementDragEnd | 203 * @param {function(number, number)} elementDragEnd |
204 * @param {string} cursor | 204 * @param {string} cursor |
205 * @param {?string=} hoverCursor | 205 * @param {?string=} hoverCursor |
206 * @param {number=} startDelay | 206 * @param {number=} startDelay |
207 * @param {number=} friction | 207 * @param {number=} friction |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 if (!duration) | 262 if (!duration) |
263 return; | 263 return; |
264 lastTime = now; | 264 lastTime = now; |
265 lastX += velocityX * duration; | 265 lastX += velocityX * duration; |
266 lastY += velocityY * duration; | 266 lastY += velocityY * duration; |
267 var k = Math.pow(1 / (1 + friction), duration / 1000); | 267 var k = Math.pow(1 / (1 + friction), duration / 1000); |
268 velocityX *= k; | 268 velocityX *= k; |
269 velocityY *= k; | 269 velocityY *= k; |
270 elementDrag(lastX, lastY); | 270 elementDrag(lastX, lastY); |
271 } | 271 } |
272 } | 272 }; |
273 | 273 |
274 /** | 274 /** |
275 * @constructor | 275 * @constructor |
276 * @param {!Document} document | 276 * @param {!Document} document |
277 * @param {boolean=} dimmed | 277 * @param {boolean=} dimmed |
278 */ | 278 */ |
279 WebInspector.GlassPane = function(document, dimmed) | 279 WebInspector.GlassPane = function(document, dimmed) |
280 { | 280 { |
281 this.element = createElement("div"); | 281 this.element = createElement("div"); |
282 var background = dimmed ? "rgba(255, 255, 255, 0.5)" : "transparent"; | 282 var background = dimmed ? "rgba(255, 255, 255, 0.5)" : "transparent"; |
283 this._zIndex = WebInspector._glassPane ? WebInspector._glassPane._zIndex + 1
000 : 3000; // Deliberately starts with 3000 to hide other z-indexed elements be
low. | 283 this._zIndex = WebInspector._glassPane ? WebInspector._glassPane._zIndex + 1
000 : 3000; // Deliberately starts with 3000 to hide other z-indexed elements be
low. |
284 this.element.style.cssText = "position:absolute;top:0;bottom:0;left:0;right:
0;background-color:" + background + ";z-index:" + this._zIndex + ";overflow:hidd
en;"; | 284 this.element.style.cssText = "position:absolute;top:0;bottom:0;left:0;right:
0;background-color:" + background + ";z-index:" + this._zIndex + ";overflow:hidd
en;"; |
285 document.body.appendChild(this.element); | 285 document.body.appendChild(this.element); |
286 WebInspector._glassPane = this; | 286 WebInspector._glassPane = this; |
287 // TODO(dgozman): disallow focus outside of glass pane? | 287 // TODO(dgozman): disallow focus outside of glass pane? |
288 } | 288 }; |
289 | 289 |
290 WebInspector.GlassPane.prototype = { | 290 WebInspector.GlassPane.prototype = { |
291 dispose: function() | 291 dispose: function() |
292 { | 292 { |
293 delete WebInspector._glassPane; | 293 delete WebInspector._glassPane; |
294 this.element.remove(); | 294 this.element.remove(); |
295 } | 295 } |
296 } | 296 }; |
297 | 297 |
298 /** @type {!WebInspector.GlassPane|undefined} */ | 298 /** @type {!WebInspector.GlassPane|undefined} */ |
299 WebInspector._glassPane; | 299 WebInspector._glassPane; |
300 | 300 |
301 /** | 301 /** |
302 * @param {?Node=} node | 302 * @param {?Node=} node |
303 * @return {boolean} | 303 * @return {boolean} |
304 */ | 304 */ |
305 WebInspector.isBeingEdited = function(node) | 305 WebInspector.isBeingEdited = function(node) |
306 { | 306 { |
307 if (!node || node.nodeType !== Node.ELEMENT_NODE) | 307 if (!node || node.nodeType !== Node.ELEMENT_NODE) |
308 return false; | 308 return false; |
309 var element = /** {!Element} */ (node); | 309 var element = /** {!Element} */ (node); |
310 if (element.classList.contains("text-prompt") || element.nodeName === "INPUT
" || element.nodeName === "TEXTAREA") | 310 if (element.classList.contains("text-prompt") || element.nodeName === "INPUT
" || element.nodeName === "TEXTAREA") |
311 return true; | 311 return true; |
312 | 312 |
313 if (!WebInspector.__editingCount) | 313 if (!WebInspector.__editingCount) |
314 return false; | 314 return false; |
315 | 315 |
316 while (element) { | 316 while (element) { |
317 if (element.__editing) | 317 if (element.__editing) |
318 return true; | 318 return true; |
319 element = element.parentElementOrShadowHost(); | 319 element = element.parentElementOrShadowHost(); |
320 } | 320 } |
321 return false; | 321 return false; |
322 } | 322 }; |
323 | 323 |
324 /** | 324 /** |
325 * @return {boolean} | 325 * @return {boolean} |
326 * @suppressGlobalPropertiesCheck | 326 * @suppressGlobalPropertiesCheck |
327 */ | 327 */ |
328 WebInspector.isEditing = function() | 328 WebInspector.isEditing = function() |
329 { | 329 { |
330 if (WebInspector.__editingCount) | 330 if (WebInspector.__editingCount) |
331 return true; | 331 return true; |
332 | 332 |
333 var focused = document.deepActiveElement(); | 333 var focused = document.deepActiveElement(); |
334 if (!focused) | 334 if (!focused) |
335 return false; | 335 return false; |
336 return focused.classList.contains("text-prompt") || focused.nodeName === "IN
PUT" || focused.nodeName === "TEXTAREA"; | 336 return focused.classList.contains("text-prompt") || focused.nodeName === "IN
PUT" || focused.nodeName === "TEXTAREA"; |
337 } | 337 }; |
338 | 338 |
339 /** | 339 /** |
340 * @param {!Element} element | 340 * @param {!Element} element |
341 * @param {boolean} value | 341 * @param {boolean} value |
342 * @return {boolean} | 342 * @return {boolean} |
343 */ | 343 */ |
344 WebInspector.markBeingEdited = function(element, value) | 344 WebInspector.markBeingEdited = function(element, value) |
345 { | 345 { |
346 if (value) { | 346 if (value) { |
347 if (element.__editing) | 347 if (element.__editing) |
348 return false; | 348 return false; |
349 element.classList.add("being-edited"); | 349 element.classList.add("being-edited"); |
350 element.__editing = true; | 350 element.__editing = true; |
351 WebInspector.__editingCount = (WebInspector.__editingCount || 0) + 1; | 351 WebInspector.__editingCount = (WebInspector.__editingCount || 0) + 1; |
352 } else { | 352 } else { |
353 if (!element.__editing) | 353 if (!element.__editing) |
354 return false; | 354 return false; |
355 element.classList.remove("being-edited"); | 355 element.classList.remove("being-edited"); |
356 delete element.__editing; | 356 delete element.__editing; |
357 --WebInspector.__editingCount; | 357 --WebInspector.__editingCount; |
358 } | 358 } |
359 return true; | 359 return true; |
360 } | 360 }; |
361 | 361 |
362 WebInspector.CSSNumberRegex = /^(-?(?:\d+(?:\.\d+)?|\.\d+))$/; | 362 WebInspector.CSSNumberRegex = /^(-?(?:\d+(?:\.\d+)?|\.\d+))$/; |
363 | 363 |
364 WebInspector.StyleValueDelimiters = " \xA0\t\n\"':;,/()"; | 364 WebInspector.StyleValueDelimiters = " \xA0\t\n\"':;,/()"; |
365 | 365 |
366 | 366 |
367 /** | 367 /** |
368 * @param {!Event} event | 368 * @param {!Event} event |
369 * @return {?string} | 369 * @return {?string} |
370 */ | 370 */ |
371 WebInspector._valueModificationDirection = function(event) | 371 WebInspector._valueModificationDirection = function(event) |
372 { | 372 { |
373 var direction = null; | 373 var direction = null; |
374 if (event.type === "mousewheel") { | 374 if (event.type === "mousewheel") { |
375 // When shift is pressed while spinning mousewheel, delta comes as wheel
DeltaX. | 375 // When shift is pressed while spinning mousewheel, delta comes as wheel
DeltaX. |
376 if (event.wheelDeltaY > 0 || event.wheelDeltaX > 0) | 376 if (event.wheelDeltaY > 0 || event.wheelDeltaX > 0) |
377 direction = "Up"; | 377 direction = "Up"; |
378 else if (event.wheelDeltaY < 0 || event.wheelDeltaX < 0) | 378 else if (event.wheelDeltaY < 0 || event.wheelDeltaX < 0) |
379 direction = "Down"; | 379 direction = "Down"; |
380 } else { | 380 } else { |
381 if (event.key === "ArrowUp" || event.key === "PageUp") | 381 if (event.key === "ArrowUp" || event.key === "PageUp") |
382 direction = "Up"; | 382 direction = "Up"; |
383 else if (event.key === "ArrowDown" || event.key === "PageDown") | 383 else if (event.key === "ArrowDown" || event.key === "PageDown") |
384 direction = "Down"; | 384 direction = "Down"; |
385 } | 385 } |
386 return direction; | 386 return direction; |
387 } | 387 }; |
388 | 388 |
389 /** | 389 /** |
390 * @param {string} hexString | 390 * @param {string} hexString |
391 * @param {!Event} event | 391 * @param {!Event} event |
392 * @return {?string} | 392 * @return {?string} |
393 */ | 393 */ |
394 WebInspector._modifiedHexValue = function(hexString, event) | 394 WebInspector._modifiedHexValue = function(hexString, event) |
395 { | 395 { |
396 var direction = WebInspector._valueModificationDirection(event); | 396 var direction = WebInspector._valueModificationDirection(event); |
397 if (!direction) | 397 if (!direction) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 | 429 |
430 // Increase hex value by 1 and clamp from 0 ... maxValue. | 430 // Increase hex value by 1 and clamp from 0 ... maxValue. |
431 var maxValue = Math.pow(16, hexStrLen) - 1; | 431 var maxValue = Math.pow(16, hexStrLen) - 1; |
432 var result = Number.constrain(number + delta, 0, maxValue); | 432 var result = Number.constrain(number + delta, 0, maxValue); |
433 | 433 |
434 // Ensure the result length is the same as the original hex value. | 434 // Ensure the result length is the same as the original hex value. |
435 var resultString = result.toString(16).toUpperCase(); | 435 var resultString = result.toString(16).toUpperCase(); |
436 for (var i = 0, lengthDelta = hexStrLen - resultString.length; i < lengthDel
ta; ++i) | 436 for (var i = 0, lengthDelta = hexStrLen - resultString.length; i < lengthDel
ta; ++i) |
437 resultString = "0" + resultString; | 437 resultString = "0" + resultString; |
438 return resultString; | 438 return resultString; |
439 } | 439 }; |
440 | 440 |
441 /** | 441 /** |
442 * @param {number} number | 442 * @param {number} number |
443 * @param {!Event} event | 443 * @param {!Event} event |
444 * @return {?number} | 444 * @return {?number} |
445 */ | 445 */ |
446 WebInspector._modifiedFloatNumber = function(number, event) | 446 WebInspector._modifiedFloatNumber = function(number, event) |
447 { | 447 { |
448 var direction = WebInspector._valueModificationDirection(event); | 448 var direction = WebInspector._valueModificationDirection(event); |
449 if (!direction) | 449 if (!direction) |
(...skipping 17 matching lines...) Expand all Loading... |
467 if (direction === "Down") | 467 if (direction === "Down") |
468 delta *= -1; | 468 delta *= -1; |
469 | 469 |
470 // Make the new number and constrain it to a precision of 6, this matches nu
mbers the engine returns. | 470 // Make the new number and constrain it to a precision of 6, this matches nu
mbers the engine returns. |
471 // Use the Number constructor to forget the fixed precision, so 1.100000 wil
l print as 1.1. | 471 // Use the Number constructor to forget the fixed precision, so 1.100000 wil
l print as 1.1. |
472 var result = Number((number + delta).toFixed(6)); | 472 var result = Number((number + delta).toFixed(6)); |
473 if (!String(result).match(WebInspector.CSSNumberRegex)) | 473 if (!String(result).match(WebInspector.CSSNumberRegex)) |
474 return null; | 474 return null; |
475 | 475 |
476 return result; | 476 return result; |
477 } | 477 }; |
478 | 478 |
479 /** | 479 /** |
480 * @param {string} wordString | 480 * @param {string} wordString |
481 * @param {!Event} event | 481 * @param {!Event} event |
482 * @param {function(string, number, string):string=} customNumberHandler | 482 * @param {function(string, number, string):string=} customNumberHandler |
483 * @return {?string} | 483 * @return {?string} |
484 */ | 484 */ |
485 WebInspector.createReplacementString = function(wordString, event, customNumberH
andler) | 485 WebInspector.createReplacementString = function(wordString, event, customNumberH
andler) |
486 { | 486 { |
487 var prefix; | 487 var prefix; |
(...skipping 11 matching lines...) Expand all Loading... |
499 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString); | 499 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString); |
500 if (matches && matches.length) { | 500 if (matches && matches.length) { |
501 prefix = matches[1]; | 501 prefix = matches[1]; |
502 suffix = matches[3]; | 502 suffix = matches[3]; |
503 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), e
vent); | 503 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), e
vent); |
504 if (number !== null) | 504 if (number !== null) |
505 replacementString = customNumberHandler ? customNumberHandler(pr
efix, number, suffix) : prefix + number + suffix; | 505 replacementString = customNumberHandler ? customNumberHandler(pr
efix, number, suffix) : prefix + number + suffix; |
506 } | 506 } |
507 } | 507 } |
508 return replacementString; | 508 return replacementString; |
509 } | 509 }; |
510 | 510 |
511 /** | 511 /** |
512 * @param {!Event} event | 512 * @param {!Event} event |
513 * @param {!Element} element | 513 * @param {!Element} element |
514 * @param {function(string,string)=} finishHandler | 514 * @param {function(string,string)=} finishHandler |
515 * @param {function(string)=} suggestionHandler | 515 * @param {function(string)=} suggestionHandler |
516 * @param {function(string, number, string):string=} customNumberHandler | 516 * @param {function(string, number, string):string=} customNumberHandler |
517 * @return {boolean} | 517 * @return {boolean} |
518 */ | 518 */ |
519 WebInspector.handleElementValueModifications = function(event, element, finishHa
ndler, suggestionHandler, customNumberHandler) | 519 WebInspector.handleElementValueModifications = function(event, element, finishHa
ndler, suggestionHandler, customNumberHandler) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 | 564 |
565 event.handled = true; | 565 event.handled = true; |
566 event.preventDefault(); | 566 event.preventDefault(); |
567 | 567 |
568 if (finishHandler) | 568 if (finishHandler) |
569 finishHandler(originalValue, replacementString); | 569 finishHandler(originalValue, replacementString); |
570 | 570 |
571 return true; | 571 return true; |
572 } | 572 } |
573 return false; | 573 return false; |
574 } | 574 }; |
575 | 575 |
576 /** | 576 /** |
577 * @param {number} ms | 577 * @param {number} ms |
578 * @param {number=} precision | 578 * @param {number=} precision |
579 * @return {string} | 579 * @return {string} |
580 */ | 580 */ |
581 Number.preciseMillisToString = function(ms, precision) | 581 Number.preciseMillisToString = function(ms, precision) |
582 { | 582 { |
583 precision = precision || 0; | 583 precision = precision || 0; |
584 var format = "%." + precision + "f\u2009ms"; | 584 var format = "%." + precision + "f\u2009ms"; |
585 return WebInspector.UIString(format, ms); | 585 return WebInspector.UIString(format, ms); |
586 } | 586 }; |
587 | 587 |
588 /** @type {!WebInspector.UIStringFormat} */ | 588 /** @type {!WebInspector.UIStringFormat} */ |
589 WebInspector._microsFormat = new WebInspector.UIStringFormat("%.0f\u2009\u03bcs"
); | 589 WebInspector._microsFormat = new WebInspector.UIStringFormat("%.0f\u2009\u03bcs"
); |
590 | 590 |
591 /** @type {!WebInspector.UIStringFormat} */ | 591 /** @type {!WebInspector.UIStringFormat} */ |
592 WebInspector._subMillisFormat = new WebInspector.UIStringFormat("%.2f\u2009ms"); | 592 WebInspector._subMillisFormat = new WebInspector.UIStringFormat("%.2f\u2009ms"); |
593 | 593 |
594 /** @type {!WebInspector.UIStringFormat} */ | 594 /** @type {!WebInspector.UIStringFormat} */ |
595 WebInspector._millisFormat = new WebInspector.UIStringFormat("%.0f\u2009ms"); | 595 WebInspector._millisFormat = new WebInspector.UIStringFormat("%.0f\u2009ms"); |
596 | 596 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 var minutes = seconds / 60; | 633 var minutes = seconds / 60; |
634 if (minutes < 60) | 634 if (minutes < 60) |
635 return WebInspector._minutesFormat.format(minutes); | 635 return WebInspector._minutesFormat.format(minutes); |
636 | 636 |
637 var hours = minutes / 60; | 637 var hours = minutes / 60; |
638 if (hours < 24) | 638 if (hours < 24) |
639 return WebInspector._hoursFormat.format(hours); | 639 return WebInspector._hoursFormat.format(hours); |
640 | 640 |
641 var days = hours / 24; | 641 var days = hours / 24; |
642 return WebInspector._daysFormat.format(days); | 642 return WebInspector._daysFormat.format(days); |
643 } | 643 }; |
644 | 644 |
645 /** | 645 /** |
646 * @param {number} seconds | 646 * @param {number} seconds |
647 * @param {boolean=} higherResolution | 647 * @param {boolean=} higherResolution |
648 * @return {string} | 648 * @return {string} |
649 */ | 649 */ |
650 Number.secondsToString = function(seconds, higherResolution) | 650 Number.secondsToString = function(seconds, higherResolution) |
651 { | 651 { |
652 if (!isFinite(seconds)) | 652 if (!isFinite(seconds)) |
653 return "-"; | 653 return "-"; |
654 return Number.millisToString(seconds * 1000, higherResolution); | 654 return Number.millisToString(seconds * 1000, higherResolution); |
655 } | 655 }; |
656 | 656 |
657 /** | 657 /** |
658 * @param {number} bytes | 658 * @param {number} bytes |
659 * @return {string} | 659 * @return {string} |
660 */ | 660 */ |
661 Number.bytesToString = function(bytes) | 661 Number.bytesToString = function(bytes) |
662 { | 662 { |
663 if (bytes < 1024) | 663 if (bytes < 1024) |
664 return WebInspector.UIString("%.0f\u2009B", bytes); | 664 return WebInspector.UIString("%.0f\u2009B", bytes); |
665 | 665 |
666 var kilobytes = bytes / 1024; | 666 var kilobytes = bytes / 1024; |
667 if (kilobytes < 100) | 667 if (kilobytes < 100) |
668 return WebInspector.UIString("%.1f\u2009KB", kilobytes); | 668 return WebInspector.UIString("%.1f\u2009KB", kilobytes); |
669 if (kilobytes < 1024) | 669 if (kilobytes < 1024) |
670 return WebInspector.UIString("%.0f\u2009KB", kilobytes); | 670 return WebInspector.UIString("%.0f\u2009KB", kilobytes); |
671 | 671 |
672 var megabytes = kilobytes / 1024; | 672 var megabytes = kilobytes / 1024; |
673 if (megabytes < 100) | 673 if (megabytes < 100) |
674 return WebInspector.UIString("%.1f\u2009MB", megabytes); | 674 return WebInspector.UIString("%.1f\u2009MB", megabytes); |
675 else | 675 else |
676 return WebInspector.UIString("%.0f\u2009MB", megabytes); | 676 return WebInspector.UIString("%.0f\u2009MB", megabytes); |
677 } | 677 }; |
678 | 678 |
679 /** | 679 /** |
680 * @param {number} num | 680 * @param {number} num |
681 * @return {string} | 681 * @return {string} |
682 */ | 682 */ |
683 Number.withThousandsSeparator = function(num) | 683 Number.withThousandsSeparator = function(num) |
684 { | 684 { |
685 var str = num + ""; | 685 var str = num + ""; |
686 var re = /(\d+)(\d{3})/; | 686 var re = /(\d+)(\d{3})/; |
687 while (str.match(re)) | 687 while (str.match(re)) |
688 str = str.replace(re, "$1\u2009$2"); // \u2009 is a thin space. | 688 str = str.replace(re, "$1\u2009$2"); // \u2009 is a thin space. |
689 return str; | 689 return str; |
690 } | 690 }; |
691 | 691 |
692 /** | 692 /** |
693 * @param {string} format | 693 * @param {string} format |
694 * @param {?ArrayLike} substitutions | 694 * @param {?ArrayLike} substitutions |
695 * @return {!Element} | 695 * @return {!Element} |
696 */ | 696 */ |
697 WebInspector.formatLocalized = function(format, substitutions) | 697 WebInspector.formatLocalized = function(format, substitutions) |
698 { | 698 { |
699 var formatters = { | 699 var formatters = { |
700 s: substitution => substitution | 700 s: substitution => substitution |
701 }; | 701 }; |
702 /** | 702 /** |
703 * @param {!Element} a | 703 * @param {!Element} a |
704 * @param {string|!Element} b | 704 * @param {string|!Element} b |
705 * @return {!Element} | 705 * @return {!Element} |
706 */ | 706 */ |
707 function append(a, b) | 707 function append(a, b) |
708 { | 708 { |
709 a.appendChild(typeof b === "string" ? createTextNode(b) : b); | 709 a.appendChild(typeof b === "string" ? createTextNode(b) : b); |
710 return a; | 710 return a; |
711 } | 711 } |
712 return String.format(WebInspector.UIString(format), substitutions, formatter
s, createElement("span"), append).formattedResult; | 712 return String.format(WebInspector.UIString(format), substitutions, formatter
s, createElement("span"), append).formattedResult; |
713 } | 713 }; |
714 | 714 |
715 /** | 715 /** |
716 * @return {string} | 716 * @return {string} |
717 */ | 717 */ |
718 WebInspector.openLinkExternallyLabel = function() | 718 WebInspector.openLinkExternallyLabel = function() |
719 { | 719 { |
720 return WebInspector.UIString.capitalize("Open ^link in ^new ^tab"); | 720 return WebInspector.UIString.capitalize("Open ^link in ^new ^tab"); |
721 } | 721 }; |
722 | 722 |
723 /** | 723 /** |
724 * @return {string} | 724 * @return {string} |
725 */ | 725 */ |
726 WebInspector.copyLinkAddressLabel = function() | 726 WebInspector.copyLinkAddressLabel = function() |
727 { | 727 { |
728 return WebInspector.UIString.capitalize("Copy ^link ^address"); | 728 return WebInspector.UIString.capitalize("Copy ^link ^address"); |
729 } | 729 }; |
730 | 730 |
731 /** | 731 /** |
732 * @return {string} | 732 * @return {string} |
733 */ | 733 */ |
734 WebInspector.anotherProfilerActiveLabel = function() | 734 WebInspector.anotherProfilerActiveLabel = function() |
735 { | 735 { |
736 return WebInspector.UIString("Another profiler is already active"); | 736 return WebInspector.UIString("Another profiler is already active"); |
737 } | 737 }; |
738 | 738 |
739 /** | 739 /** |
740 * @param {string|undefined} description | 740 * @param {string|undefined} description |
741 * @return {string} | 741 * @return {string} |
742 */ | 742 */ |
743 WebInspector.asyncStackTraceLabel = function(description) | 743 WebInspector.asyncStackTraceLabel = function(description) |
744 { | 744 { |
745 if (description) | 745 if (description) |
746 return description + " " + WebInspector.UIString("(async)"); | 746 return description + " " + WebInspector.UIString("(async)"); |
747 return WebInspector.UIString("Async Call"); | 747 return WebInspector.UIString("Async Call"); |
748 } | 748 }; |
749 | 749 |
750 /** | 750 /** |
751 * @param {!Element} element | 751 * @param {!Element} element |
752 */ | 752 */ |
753 WebInspector.installComponentRootStyles = function(element) | 753 WebInspector.installComponentRootStyles = function(element) |
754 { | 754 { |
755 WebInspector.appendStyle(element, "ui/inspectorCommon.css"); | 755 WebInspector.appendStyle(element, "ui/inspectorCommon.css"); |
756 WebInspector.themeSupport.injectHighlightStyleSheets(element); | 756 WebInspector.themeSupport.injectHighlightStyleSheets(element); |
757 element.classList.add("platform-" + WebInspector.platform()); | 757 element.classList.add("platform-" + WebInspector.platform()); |
758 } | 758 }; |
759 | 759 |
760 /** | 760 /** |
761 * @param {!Element} element | 761 * @param {!Element} element |
762 * @param {string=} cssFile | 762 * @param {string=} cssFile |
763 * @return {!DocumentFragment} | 763 * @return {!DocumentFragment} |
764 */ | 764 */ |
765 WebInspector.createShadowRootWithCoreStyles = function(element, cssFile) | 765 WebInspector.createShadowRootWithCoreStyles = function(element, cssFile) |
766 { | 766 { |
767 var shadowRoot = element.createShadowRoot(); | 767 var shadowRoot = element.createShadowRoot(); |
768 WebInspector.appendStyle(shadowRoot, "ui/inspectorCommon.css"); | 768 WebInspector.appendStyle(shadowRoot, "ui/inspectorCommon.css"); |
769 WebInspector.themeSupport.injectHighlightStyleSheets(shadowRoot); | 769 WebInspector.themeSupport.injectHighlightStyleSheets(shadowRoot); |
770 if (cssFile) | 770 if (cssFile) |
771 WebInspector.appendStyle(shadowRoot, cssFile); | 771 WebInspector.appendStyle(shadowRoot, cssFile); |
772 shadowRoot.addEventListener("focus", WebInspector._focusChanged.bind(WebInsp
ector), true); | 772 shadowRoot.addEventListener("focus", WebInspector._focusChanged.bind(WebInsp
ector), true); |
773 return shadowRoot; | 773 return shadowRoot; |
774 } | 774 }; |
775 | 775 |
776 /** | 776 /** |
777 * @param {!Document} document | 777 * @param {!Document} document |
778 * @param {!Event} event | 778 * @param {!Event} event |
779 */ | 779 */ |
780 WebInspector._windowFocused = function(document, event) | 780 WebInspector._windowFocused = function(document, event) |
781 { | 781 { |
782 if (event.target.document.nodeType === Node.DOCUMENT_NODE) | 782 if (event.target.document.nodeType === Node.DOCUMENT_NODE) |
783 document.body.classList.remove("inactive"); | 783 document.body.classList.remove("inactive"); |
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._windowBlurred = function(document, event) | 790 WebInspector._windowBlurred = function(document, event) |
791 { | 791 { |
792 if (event.target.document.nodeType === Node.DOCUMENT_NODE) | 792 if (event.target.document.nodeType === Node.DOCUMENT_NODE) |
793 document.body.classList.add("inactive"); | 793 document.body.classList.add("inactive"); |
794 } | 794 }; |
795 | 795 |
796 /** | 796 /** |
797 * @param {!Event} event | 797 * @param {!Event} event |
798 */ | 798 */ |
799 WebInspector._focusChanged = function(event) | 799 WebInspector._focusChanged = function(event) |
800 { | 800 { |
801 var document = event.target && event.target.ownerDocument; | 801 var document = event.target && event.target.ownerDocument; |
802 var element = document ? document.deepActiveElement() : null; | 802 var element = document ? document.deepActiveElement() : null; |
803 WebInspector.Widget.focusWidgetForNode(element); | 803 WebInspector.Widget.focusWidgetForNode(element); |
804 } | 804 }; |
805 | 805 |
806 /** | 806 /** |
807 * @param {!Element} element | 807 * @param {!Element} element |
808 * @constructor | 808 * @constructor |
809 */ | 809 */ |
810 WebInspector.ElementFocusRestorer = function(element) | 810 WebInspector.ElementFocusRestorer = function(element) |
811 { | 811 { |
812 this._element = element; | 812 this._element = element; |
813 this._previous = element.ownerDocument.deepActiveElement(); | 813 this._previous = element.ownerDocument.deepActiveElement(); |
814 element.focus(); | 814 element.focus(); |
815 } | 815 }; |
816 | 816 |
817 WebInspector.ElementFocusRestorer.prototype = { | 817 WebInspector.ElementFocusRestorer.prototype = { |
818 restore: function() | 818 restore: function() |
819 { | 819 { |
820 if (!this._element) | 820 if (!this._element) |
821 return; | 821 return; |
822 if (this._element.hasFocus() && this._previous) | 822 if (this._element.hasFocus() && this._previous) |
823 this._previous.focus(); | 823 this._previous.focus(); |
824 this._previous = null; | 824 this._previous = null; |
825 this._element = null; | 825 this._element = null; |
826 } | 826 } |
827 } | 827 }; |
828 | 828 |
829 /** | 829 /** |
830 * @param {!Element} element | 830 * @param {!Element} element |
831 * @param {number} offset | 831 * @param {number} offset |
832 * @param {number} length | 832 * @param {number} length |
833 * @param {!Array.<!Object>=} domChanges | 833 * @param {!Array.<!Object>=} domChanges |
834 * @return {?Element} | 834 * @return {?Element} |
835 */ | 835 */ |
836 WebInspector.highlightSearchResult = function(element, offset, length, domChange
s) | 836 WebInspector.highlightSearchResult = function(element, offset, length, domChange
s) |
837 { | 837 { |
838 var result = WebInspector.highlightSearchResults(element, [new WebInspector.
SourceRange(offset, length)], domChanges); | 838 var result = WebInspector.highlightSearchResults(element, [new WebInspector.
SourceRange(offset, length)], domChanges); |
839 return result.length ? result[0] : null; | 839 return result.length ? result[0] : null; |
840 } | 840 }; |
841 | 841 |
842 /** | 842 /** |
843 * @param {!Element} element | 843 * @param {!Element} element |
844 * @param {!Array.<!WebInspector.SourceRange>} resultRanges | 844 * @param {!Array.<!WebInspector.SourceRange>} resultRanges |
845 * @param {!Array.<!Object>=} changes | 845 * @param {!Array.<!Object>=} changes |
846 * @return {!Array.<!Element>} | 846 * @return {!Array.<!Element>} |
847 */ | 847 */ |
848 WebInspector.highlightSearchResults = function(element, resultRanges, changes) | 848 WebInspector.highlightSearchResults = function(element, resultRanges, changes) |
849 { | 849 { |
850 return WebInspector.highlightRangesWithStyleClass(element, resultRanges, Web
Inspector.highlightedSearchResultClassName, changes); | 850 return WebInspector.highlightRangesWithStyleClass(element, resultRanges, Web
Inspector.highlightedSearchResultClassName, changes); |
851 } | 851 }; |
852 | 852 |
853 /** | 853 /** |
854 * @param {!Element} element | 854 * @param {!Element} element |
855 * @param {string} className | 855 * @param {string} className |
856 */ | 856 */ |
857 WebInspector.runCSSAnimationOnce = function(element, className) | 857 WebInspector.runCSSAnimationOnce = function(element, className) |
858 { | 858 { |
859 function animationEndCallback() | 859 function animationEndCallback() |
860 { | 860 { |
861 element.classList.remove(className); | 861 element.classList.remove(className); |
862 element.removeEventListener("webkitAnimationEnd", animationEndCallback,
false); | 862 element.removeEventListener("webkitAnimationEnd", animationEndCallback,
false); |
863 } | 863 } |
864 | 864 |
865 if (element.classList.contains(className)) | 865 if (element.classList.contains(className)) |
866 element.classList.remove(className); | 866 element.classList.remove(className); |
867 | 867 |
868 element.addEventListener("webkitAnimationEnd", animationEndCallback, false); | 868 element.addEventListener("webkitAnimationEnd", animationEndCallback, false); |
869 element.classList.add(className); | 869 element.classList.add(className); |
870 } | 870 }; |
871 | 871 |
872 /** | 872 /** |
873 * @param {!Element} element | 873 * @param {!Element} element |
874 * @param {!Array.<!WebInspector.SourceRange>} resultRanges | 874 * @param {!Array.<!WebInspector.SourceRange>} resultRanges |
875 * @param {string} styleClass | 875 * @param {string} styleClass |
876 * @param {!Array.<!Object>=} changes | 876 * @param {!Array.<!Object>=} changes |
877 * @return {!Array.<!Element>} | 877 * @return {!Array.<!Element>} |
878 */ | 878 */ |
879 WebInspector.highlightRangesWithStyleClass = function(element, resultRanges, sty
leClass, changes) | 879 WebInspector.highlightRangesWithStyleClass = function(element, resultRanges, sty
leClass, changes) |
880 { | 880 { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 textNode.textContent = ""; | 945 textNode.textContent = ""; |
946 changes.push({ node: textNode, type: "changed", oldText: text, n
ewText: textNode.textContent }); | 946 changes.push({ node: textNode, type: "changed", oldText: text, n
ewText: textNode.textContent }); |
947 } | 947 } |
948 } | 948 } |
949 startIndex = endIndex; | 949 startIndex = endIndex; |
950 nodeRanges[startIndex].offset = endOffset; | 950 nodeRanges[startIndex].offset = endOffset; |
951 nodeRanges[startIndex].length = lastTextNode.textContent.length; | 951 nodeRanges[startIndex].length = lastTextNode.textContent.length; |
952 | 952 |
953 } | 953 } |
954 return highlightNodes; | 954 return highlightNodes; |
955 } | 955 }; |
956 | 956 |
957 WebInspector.applyDomChanges = function(domChanges) | 957 WebInspector.applyDomChanges = function(domChanges) |
958 { | 958 { |
959 for (var i = 0, size = domChanges.length; i < size; ++i) { | 959 for (var i = 0, size = domChanges.length; i < size; ++i) { |
960 var entry = domChanges[i]; | 960 var entry = domChanges[i]; |
961 switch (entry.type) { | 961 switch (entry.type) { |
962 case "added": | 962 case "added": |
963 entry.parent.insertBefore(entry.node, entry.nextSibling); | 963 entry.parent.insertBefore(entry.node, entry.nextSibling); |
964 break; | 964 break; |
965 case "changed": | 965 case "changed": |
966 entry.node.textContent = entry.newText; | 966 entry.node.textContent = entry.newText; |
967 break; | 967 break; |
968 } | 968 } |
969 } | 969 } |
970 } | 970 }; |
971 | 971 |
972 WebInspector.revertDomChanges = function(domChanges) | 972 WebInspector.revertDomChanges = function(domChanges) |
973 { | 973 { |
974 for (var i = domChanges.length - 1; i >= 0; --i) { | 974 for (var i = domChanges.length - 1; i >= 0; --i) { |
975 var entry = domChanges[i]; | 975 var entry = domChanges[i]; |
976 switch (entry.type) { | 976 switch (entry.type) { |
977 case "added": | 977 case "added": |
978 entry.node.remove(); | 978 entry.node.remove(); |
979 break; | 979 break; |
980 case "changed": | 980 case "changed": |
981 entry.node.textContent = entry.oldText; | 981 entry.node.textContent = entry.oldText; |
982 break; | 982 break; |
983 } | 983 } |
984 } | 984 } |
985 } | 985 }; |
986 | 986 |
987 /** | 987 /** |
988 * @param {!Element} element | 988 * @param {!Element} element |
989 * @param {?Element=} containerElement | 989 * @param {?Element=} containerElement |
990 * @return {!Size} | 990 * @return {!Size} |
991 */ | 991 */ |
992 WebInspector.measurePreferredSize = function(element, containerElement) | 992 WebInspector.measurePreferredSize = function(element, containerElement) |
993 { | 993 { |
994 var oldParent = element.parentElement; | 994 var oldParent = element.parentElement; |
995 var oldNextSibling = element.nextSibling; | 995 var oldNextSibling = element.nextSibling; |
996 containerElement = containerElement || element.ownerDocument.body; | 996 containerElement = containerElement || element.ownerDocument.body; |
997 containerElement.appendChild(element); | 997 containerElement.appendChild(element); |
998 element.positionAt(0, 0); | 998 element.positionAt(0, 0); |
999 var result = new Size(element.offsetWidth, element.offsetHeight); | 999 var result = new Size(element.offsetWidth, element.offsetHeight); |
1000 | 1000 |
1001 element.positionAt(undefined, undefined); | 1001 element.positionAt(undefined, undefined); |
1002 if (oldParent) | 1002 if (oldParent) |
1003 oldParent.insertBefore(element, oldNextSibling); | 1003 oldParent.insertBefore(element, oldNextSibling); |
1004 else | 1004 else |
1005 element.remove(); | 1005 element.remove(); |
1006 return result; | 1006 return result; |
1007 } | 1007 }; |
1008 | 1008 |
1009 /** | 1009 /** |
1010 * @constructor | 1010 * @constructor |
1011 * @param {boolean} autoInvoke | 1011 * @param {boolean} autoInvoke |
1012 */ | 1012 */ |
1013 WebInspector.InvokeOnceHandlers = function(autoInvoke) | 1013 WebInspector.InvokeOnceHandlers = function(autoInvoke) |
1014 { | 1014 { |
1015 this._handlers = null; | 1015 this._handlers = null; |
1016 this._autoInvoke = autoInvoke; | 1016 this._autoInvoke = autoInvoke; |
1017 } | 1017 }; |
1018 | 1018 |
1019 WebInspector.InvokeOnceHandlers.prototype = { | 1019 WebInspector.InvokeOnceHandlers.prototype = { |
1020 /** | 1020 /** |
1021 * @param {!Object} object | 1021 * @param {!Object} object |
1022 * @param {function()} method | 1022 * @param {function()} method |
1023 */ | 1023 */ |
1024 add: function(object, method) | 1024 add: function(object, method) |
1025 { | 1025 { |
1026 if (!this._handlers) { | 1026 if (!this._handlers) { |
1027 this._handlers = new Map(); | 1027 this._handlers = new Map(); |
(...skipping 22 matching lines...) Expand all Loading... |
1050 var handlers = this._handlers; | 1050 var handlers = this._handlers; |
1051 this._handlers = null; | 1051 this._handlers = null; |
1052 var keys = handlers.keysArray(); | 1052 var keys = handlers.keysArray(); |
1053 for (var i = 0; i < keys.length; ++i) { | 1053 for (var i = 0; i < keys.length; ++i) { |
1054 var object = keys[i]; | 1054 var object = keys[i]; |
1055 var methods = handlers.get(object).valuesArray(); | 1055 var methods = handlers.get(object).valuesArray(); |
1056 for (var j = 0; j < methods.length; ++j) | 1056 for (var j = 0; j < methods.length; ++j) |
1057 methods[j].call(object); | 1057 methods[j].call(object); |
1058 } | 1058 } |
1059 } | 1059 } |
1060 } | 1060 }; |
1061 | 1061 |
1062 WebInspector._coalescingLevel = 0; | 1062 WebInspector._coalescingLevel = 0; |
1063 WebInspector._postUpdateHandlers = null; | 1063 WebInspector._postUpdateHandlers = null; |
1064 | 1064 |
1065 WebInspector.startBatchUpdate = function() | 1065 WebInspector.startBatchUpdate = function() |
1066 { | 1066 { |
1067 if (!WebInspector._coalescingLevel++) | 1067 if (!WebInspector._coalescingLevel++) |
1068 WebInspector._postUpdateHandlers = new WebInspector.InvokeOnceHandlers(f
alse); | 1068 WebInspector._postUpdateHandlers = new WebInspector.InvokeOnceHandlers(f
alse); |
1069 } | 1069 }; |
1070 | 1070 |
1071 WebInspector.endBatchUpdate = function() | 1071 WebInspector.endBatchUpdate = function() |
1072 { | 1072 { |
1073 if (--WebInspector._coalescingLevel) | 1073 if (--WebInspector._coalescingLevel) |
1074 return; | 1074 return; |
1075 WebInspector._postUpdateHandlers.scheduleInvoke(); | 1075 WebInspector._postUpdateHandlers.scheduleInvoke(); |
1076 WebInspector._postUpdateHandlers = null; | 1076 WebInspector._postUpdateHandlers = null; |
1077 } | 1077 }; |
1078 | 1078 |
1079 /** | 1079 /** |
1080 * @param {!Object} object | 1080 * @param {!Object} object |
1081 * @param {function()} method | 1081 * @param {function()} method |
1082 */ | 1082 */ |
1083 WebInspector.invokeOnceAfterBatchUpdate = function(object, method) | 1083 WebInspector.invokeOnceAfterBatchUpdate = function(object, method) |
1084 { | 1084 { |
1085 if (!WebInspector._postUpdateHandlers) | 1085 if (!WebInspector._postUpdateHandlers) |
1086 WebInspector._postUpdateHandlers = new WebInspector.InvokeOnceHandlers(t
rue); | 1086 WebInspector._postUpdateHandlers = new WebInspector.InvokeOnceHandlers(t
rue); |
1087 WebInspector._postUpdateHandlers.add(object, method); | 1087 WebInspector._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 WebInspector.animateFunction = function(window, func, params, frames, animationC
omplete) |
(...skipping 25 matching lines...) Expand all Loading... |
1124 func.apply(null, values); | 1124 func.apply(null, values); |
1125 raf = window.requestAnimationFrame(animationStep); | 1125 raf = window.requestAnimationFrame(animationStep); |
1126 } | 1126 } |
1127 | 1127 |
1128 function cancelAnimation() | 1128 function cancelAnimation() |
1129 { | 1129 { |
1130 window.cancelAnimationFrame(raf); | 1130 window.cancelAnimationFrame(raf); |
1131 } | 1131 } |
1132 | 1132 |
1133 return cancelAnimation; | 1133 return cancelAnimation; |
1134 } | 1134 }; |
1135 | 1135 |
1136 /** | 1136 /** |
1137 * @constructor | 1137 * @constructor |
1138 * @extends {WebInspector.Object} | 1138 * @extends {WebInspector.Object} |
1139 * @param {!Element} element | 1139 * @param {!Element} element |
1140 * @param {function(!Event)} callback | 1140 * @param {function(!Event)} callback |
1141 */ | 1141 */ |
1142 WebInspector.LongClickController = function(element, callback) | 1142 WebInspector.LongClickController = function(element, callback) |
1143 { | 1143 { |
1144 this._element = element; | 1144 this._element = element; |
1145 this._callback = callback; | 1145 this._callback = callback; |
1146 this._enable(); | 1146 this._enable(); |
1147 } | 1147 }; |
1148 | 1148 |
1149 WebInspector.LongClickController.prototype = { | 1149 WebInspector.LongClickController.prototype = { |
1150 reset: function() | 1150 reset: function() |
1151 { | 1151 { |
1152 if (this._longClickInterval) { | 1152 if (this._longClickInterval) { |
1153 clearInterval(this._longClickInterval); | 1153 clearInterval(this._longClickInterval); |
1154 delete this._longClickInterval; | 1154 delete this._longClickInterval; |
1155 } | 1155 } |
1156 }, | 1156 }, |
1157 | 1157 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 if (!this._longClickData) | 1199 if (!this._longClickData) |
1200 return; | 1200 return; |
1201 this._element.removeEventListener("mousedown", this._longClickData.mouse
Down, false); | 1201 this._element.removeEventListener("mousedown", this._longClickData.mouse
Down, false); |
1202 this._element.removeEventListener("mouseout", this._longClickData.reset,
false); | 1202 this._element.removeEventListener("mouseout", this._longClickData.reset,
false); |
1203 this._element.removeEventListener("mouseup", this._longClickData.mouseUp
, false); | 1203 this._element.removeEventListener("mouseup", this._longClickData.mouseUp
, false); |
1204 this._element.addEventListener("click", this._longClickData.reset, true)
; | 1204 this._element.addEventListener("click", this._longClickData.reset, true)
; |
1205 delete this._longClickData; | 1205 delete this._longClickData; |
1206 }, | 1206 }, |
1207 | 1207 |
1208 __proto__: WebInspector.Object.prototype | 1208 __proto__: WebInspector.Object.prototype |
1209 } | 1209 }; |
1210 | 1210 |
1211 /** | 1211 /** |
1212 * @param {!Document} document | 1212 * @param {!Document} document |
1213 * @param {!WebInspector.Setting} themeSetting | 1213 * @param {!WebInspector.Setting} themeSetting |
1214 */ | 1214 */ |
1215 WebInspector.initializeUIUtils = function(document, themeSetting) | 1215 WebInspector.initializeUIUtils = function(document, themeSetting) |
1216 { | 1216 { |
1217 document.defaultView.addEventListener("focus", WebInspector._windowFocused.b
ind(WebInspector, document), false); | 1217 document.defaultView.addEventListener("focus", WebInspector._windowFocused.b
ind(WebInspector, document), false); |
1218 document.defaultView.addEventListener("blur", WebInspector._windowBlurred.bi
nd(WebInspector, document), false); | 1218 document.defaultView.addEventListener("blur", WebInspector._windowBlurred.bi
nd(WebInspector, document), false); |
1219 document.addEventListener("focus", WebInspector._focusChanged.bind(WebInspec
tor), true); | 1219 document.addEventListener("focus", WebInspector._focusChanged.bind(WebInspec
tor), true); |
1220 | 1220 |
1221 if (!WebInspector.themeSupport) | 1221 if (!WebInspector.themeSupport) |
1222 WebInspector.themeSupport = new WebInspector.ThemeSupport(themeSetting); | 1222 WebInspector.themeSupport = new WebInspector.ThemeSupport(themeSetting); |
1223 WebInspector.themeSupport.applyTheme(document); | 1223 WebInspector.themeSupport.applyTheme(document); |
1224 | 1224 |
1225 var body = /** @type {!Element} */ (document.body); | 1225 var body = /** @type {!Element} */ (document.body); |
1226 WebInspector.appendStyle(body, "ui/inspectorStyle.css"); | 1226 WebInspector.appendStyle(body, "ui/inspectorStyle.css"); |
1227 WebInspector.appendStyle(body, "ui/popover.css"); | 1227 WebInspector.appendStyle(body, "ui/popover.css"); |
1228 } | 1228 }; |
1229 | 1229 |
1230 /** | 1230 /** |
1231 * @param {string} name | 1231 * @param {string} name |
1232 * @return {string} | 1232 * @return {string} |
1233 */ | 1233 */ |
1234 WebInspector.beautifyFunctionName = function(name) | 1234 WebInspector.beautifyFunctionName = function(name) |
1235 { | 1235 { |
1236 return name || WebInspector.UIString("(anonymous)"); | 1236 return name || WebInspector.UIString("(anonymous)"); |
1237 } | 1237 }; |
1238 | 1238 |
1239 /** | 1239 /** |
1240 * @param {string} localName | 1240 * @param {string} localName |
1241 * @param {string} typeExtension | 1241 * @param {string} typeExtension |
1242 * @param {!Object} prototype | 1242 * @param {!Object} prototype |
1243 * @return {function()} | 1243 * @return {function()} |
1244 * @suppressGlobalPropertiesCheck | 1244 * @suppressGlobalPropertiesCheck |
1245 * @template T | 1245 * @template T |
1246 */ | 1246 */ |
1247 function registerCustomElement(localName, typeExtension, prototype) | 1247 function registerCustomElement(localName, typeExtension, prototype) |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 function setValue(value) | 1646 function setValue(value) |
1647 { | 1647 { |
1648 if (value === input.value) | 1648 if (value === input.value) |
1649 return; | 1649 return; |
1650 var valid = validate(value); | 1650 var valid = validate(value); |
1651 input.classList.toggle("error-input", !valid); | 1651 input.classList.toggle("error-input", !valid); |
1652 input.value = value; | 1652 input.value = value; |
1653 } | 1653 } |
1654 | 1654 |
1655 return setValue; | 1655 return setValue; |
1656 } | 1656 }; |
1657 | 1657 |
1658 /** | 1658 /** |
1659 * @constructor | 1659 * @constructor |
1660 * @param {!WebInspector.Setting} setting | 1660 * @param {!WebInspector.Setting} setting |
1661 */ | 1661 */ |
1662 WebInspector.ThemeSupport = function(setting) | 1662 WebInspector.ThemeSupport = function(setting) |
1663 { | 1663 { |
1664 this._themeName = setting.get() || "default"; | 1664 this._themeName = setting.get() || "default"; |
1665 this._themableProperties = new Set([ | 1665 this._themableProperties = new Set([ |
1666 "color", "box-shadow", "text-shadow", "outline-color", | 1666 "color", "box-shadow", "text-shadow", "outline-color", |
1667 "background-image", "background-color", | 1667 "background-image", "background-color", |
1668 "border-left-color", "border-right-color", "border-top-color", "border-b
ottom-color", | 1668 "border-left-color", "border-right-color", "border-top-color", "border-b
ottom-color", |
1669 "-webkit-border-image"]); | 1669 "-webkit-border-image"]); |
1670 /** @type {!Map<string, string>} */ | 1670 /** @type {!Map<string, string>} */ |
1671 this._cachedThemePatches = new Map(); | 1671 this._cachedThemePatches = new Map(); |
1672 this._setting = setting; | 1672 this._setting = setting; |
1673 } | 1673 }; |
1674 | 1674 |
1675 /** | 1675 /** |
1676 * @enum {number} | 1676 * @enum {number} |
1677 */ | 1677 */ |
1678 WebInspector.ThemeSupport.ColorUsage = { | 1678 WebInspector.ThemeSupport.ColorUsage = { |
1679 Unknown: 0, | 1679 Unknown: 0, |
1680 Foreground: 1 << 0, | 1680 Foreground: 1 << 0, |
1681 Background: 1 << 1, | 1681 Background: 1 << 1, |
1682 Selection: 1 << 2, | 1682 Selection: 1 << 2, |
1683 }; | 1683 }; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1868 | 1868 |
1869 /** | 1869 /** |
1870 * @param {!Array<number>} hsla | 1870 * @param {!Array<number>} hsla |
1871 * @param {!WebInspector.ThemeSupport.ColorUsage} colorUsage | 1871 * @param {!WebInspector.ThemeSupport.ColorUsage} colorUsage |
1872 */ | 1872 */ |
1873 _patchHSLA: function(hsla, colorUsage) | 1873 _patchHSLA: function(hsla, colorUsage) |
1874 { | 1874 { |
1875 var hue = hsla[0]; | 1875 var hue = hsla[0]; |
1876 var sat = hsla[1]; | 1876 var sat = hsla[1]; |
1877 var lit = hsla[2]; | 1877 var lit = hsla[2]; |
1878 var alpha = hsla[3] | 1878 var alpha = hsla[3]; |
1879 | 1879 |
1880 switch (this._themeName) { | 1880 switch (this._themeName) { |
1881 case "dark": | 1881 case "dark": |
1882 if (colorUsage & WebInspector.ThemeSupport.ColorUsage.Selection) | 1882 if (colorUsage & WebInspector.ThemeSupport.ColorUsage.Selection) |
1883 hue = (hue + 0.5) % 1; | 1883 hue = (hue + 0.5) % 1; |
1884 var minCap = colorUsage & WebInspector.ThemeSupport.ColorUsage.Backg
round ? 0.14 : 0; | 1884 var minCap = colorUsage & WebInspector.ThemeSupport.ColorUsage.Backg
round ? 0.14 : 0; |
1885 var maxCap = colorUsage & WebInspector.ThemeSupport.ColorUsage.Foreg
round ? 0.9 : 1; | 1885 var maxCap = colorUsage & WebInspector.ThemeSupport.ColorUsage.Foreg
round ? 0.9 : 1; |
1886 lit = 1 - lit; | 1886 lit = 1 - lit; |
1887 if (lit < minCap * 2) | 1887 if (lit < minCap * 2) |
1888 lit = minCap + lit / 2; | 1888 lit = minCap + lit / 2; |
1889 else if (lit > 2 * maxCap - 1) | 1889 else if (lit > 2 * maxCap - 1) |
1890 lit = maxCap - 1 / 2 + lit / 2; | 1890 lit = maxCap - 1 / 2 + lit / 2; |
1891 | 1891 |
1892 break; | 1892 break; |
1893 } | 1893 } |
1894 hsla[0] = Number.constrain(hue, 0, 1); | 1894 hsla[0] = Number.constrain(hue, 0, 1); |
1895 hsla[1] = Number.constrain(sat, 0, 1); | 1895 hsla[1] = Number.constrain(sat, 0, 1); |
1896 hsla[2] = Number.constrain(lit, 0, 1); | 1896 hsla[2] = Number.constrain(lit, 0, 1); |
1897 hsla[3] = Number.constrain(alpha, 0, 1); | 1897 hsla[3] = Number.constrain(alpha, 0, 1); |
1898 } | 1898 } |
1899 } | 1899 }; |
1900 | 1900 |
1901 /** | 1901 /** |
1902 * @param {?NetworkAgent.ResourcePriority} priority | 1902 * @param {?NetworkAgent.ResourcePriority} priority |
1903 * @return {string} | 1903 * @return {string} |
1904 */ | 1904 */ |
1905 WebInspector.uiLabelForPriority = function(priority) | 1905 WebInspector.uiLabelForPriority = function(priority) |
1906 { | 1906 { |
1907 var labelMap = WebInspector.uiLabelForPriority._priorityToUILabel; | 1907 var labelMap = WebInspector.uiLabelForPriority._priorityToUILabel; |
1908 if (!labelMap) { | 1908 if (!labelMap) { |
1909 labelMap = new Map([ | 1909 labelMap = new Map([ |
1910 [NetworkAgent.ResourcePriority.VeryLow, WebInspector.UIString("Lowes
t")], | 1910 [NetworkAgent.ResourcePriority.VeryLow, WebInspector.UIString("Lowes
t")], |
1911 [NetworkAgent.ResourcePriority.Low, WebInspector.UIString("Low")], | 1911 [NetworkAgent.ResourcePriority.Low, WebInspector.UIString("Low")], |
1912 [NetworkAgent.ResourcePriority.Medium, WebInspector.UIString("Medium
")], | 1912 [NetworkAgent.ResourcePriority.Medium, WebInspector.UIString("Medium
")], |
1913 [NetworkAgent.ResourcePriority.High, WebInspector.UIString("High")], | 1913 [NetworkAgent.ResourcePriority.High, WebInspector.UIString("High")], |
1914 [NetworkAgent.ResourcePriority.VeryHigh, WebInspector.UIString("High
est")] | 1914 [NetworkAgent.ResourcePriority.VeryHigh, WebInspector.UIString("High
est")] |
1915 ]); | 1915 ]); |
1916 WebInspector.uiLabelForPriority._priorityToUILabel = labelMap; | 1916 WebInspector.uiLabelForPriority._priorityToUILabel = labelMap; |
1917 } | 1917 } |
1918 return labelMap.get(priority) || WebInspector.UIString("Unknown"); | 1918 return labelMap.get(priority) || WebInspector.UIString("Unknown"); |
1919 } | 1919 }; |
1920 | 1920 |
1921 /** | 1921 /** |
1922 * @param {string} url | 1922 * @param {string} url |
1923 * @param {string=} linkText | 1923 * @param {string=} linkText |
1924 * @param {string=} classes | 1924 * @param {string=} classes |
1925 * @param {boolean=} isExternal | 1925 * @param {boolean=} isExternal |
1926 * @param {string=} tooltipText | 1926 * @param {string=} tooltipText |
1927 * @return {!Element} | 1927 * @return {!Element} |
1928 */ | 1928 */ |
1929 WebInspector.linkifyURLAsNode = function(url, linkText, classes, isExternal, too
ltipText) | 1929 WebInspector.linkifyURLAsNode = function(url, linkText, classes, isExternal, too
ltipText) |
(...skipping 13 matching lines...) Expand all Loading... |
1943 } | 1943 } |
1944 if (!tooltipText && linkText !== url) | 1944 if (!tooltipText && linkText !== url) |
1945 a.title = url; | 1945 a.title = url; |
1946 else if (tooltipText) | 1946 else if (tooltipText) |
1947 a.title = tooltipText; | 1947 a.title = tooltipText; |
1948 a.textContent = linkText.trimMiddle(150); | 1948 a.textContent = linkText.trimMiddle(150); |
1949 if (isExternal) | 1949 if (isExternal) |
1950 a.setAttribute("target", "_blank"); | 1950 a.setAttribute("target", "_blank"); |
1951 | 1951 |
1952 return a; | 1952 return a; |
1953 } | 1953 }; |
1954 | 1954 |
1955 /** | 1955 /** |
1956 * @param {string} article | 1956 * @param {string} article |
1957 * @param {string} title | 1957 * @param {string} title |
1958 * @return {!Element} | 1958 * @return {!Element} |
1959 */ | 1959 */ |
1960 WebInspector.linkifyDocumentationURLAsNode = function(article, title) | 1960 WebInspector.linkifyDocumentationURLAsNode = function(article, title) |
1961 { | 1961 { |
1962 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool
s/chrome-devtools/" + article, title, undefined, true); | 1962 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool
s/chrome-devtools/" + article, title, undefined, true); |
1963 } | 1963 }; |
1964 | 1964 |
1965 /** @type {!WebInspector.ThemeSupport} */ | 1965 /** @type {!WebInspector.ThemeSupport} */ |
1966 WebInspector.themeSupport; | 1966 WebInspector.themeSupport; |
OLD | NEW |