| 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 var direction = null; | 212 var direction = null; |
| 213 if (event.type === "mousewheel") { | 213 if (event.type === "mousewheel") { |
| 214 if (event.wheelDeltaY > 0) | 214 if (event.wheelDeltaY > 0) |
| 215 direction = "Up"; | 215 direction = "Up"; |
| 216 else if (event.wheelDeltaY < 0) | 216 else if (event.wheelDeltaY < 0) |
| 217 direction = "Down"; | 217 direction = "Down"; |
| 218 } else { | 218 } else { |
| 219 if (event.keyIdentifier === "Up" || event.keyIdentifier === "PageUp") | 219 if (event.keyIdentifier === "Up" || event.keyIdentifier === "PageUp") |
| 220 direction = "Up"; | 220 direction = "Up"; |
| 221 else if (event.keyIdentifier === "Down" || event.keyIdentifier === "Page
Down") | 221 else if (event.keyIdentifier === "Down" || event.keyIdentifier === "Page
Down") |
| 222 direction = "Down"; | 222 direction = "Down"; |
| 223 } | 223 } |
| 224 return direction; | 224 return direction; |
| 225 } | 225 } |
| 226 | 226 |
| 227 /** | 227 /** |
| 228 * @param {string} hexString | 228 * @param {string} hexString |
| 229 * @param {!Event} event | 229 * @param {!Event} event |
| 230 */ | 230 */ |
| 231 WebInspector._modifiedHexValue = function(hexString, event) | 231 WebInspector._modifiedHexValue = function(hexString, event) |
| 232 { | 232 { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 265 |
| 266 /** | 266 /** |
| 267 * @param {number} number | 267 * @param {number} number |
| 268 * @param {!Event} event | 268 * @param {!Event} event |
| 269 */ | 269 */ |
| 270 WebInspector._modifiedFloatNumber = function(number, event) | 270 WebInspector._modifiedFloatNumber = function(number, event) |
| 271 { | 271 { |
| 272 var direction = WebInspector._valueModificationDirection(event); | 272 var direction = WebInspector._valueModificationDirection(event); |
| 273 if (!direction) | 273 if (!direction) |
| 274 return number; | 274 return number; |
| 275 | 275 |
| 276 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyId
entifier === "Down" || event.type === "mousewheel"); | 276 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyId
entifier === "Down" || event.type === "mousewheel"); |
| 277 | 277 |
| 278 // Jump by 10 when shift is down or jump by 0.1 when Alt/Option is down. | 278 // Jump by 10 when shift is down or jump by 0.1 when Alt/Option is down. |
| 279 // Also jump by 10 for page up and down, or by 100 if shift is held with a p
age key. | 279 // Also jump by 10 for page up and down, or by 100 if shift is held with a p
age key. |
| 280 var changeAmount = 1; | 280 var changeAmount = 1; |
| 281 if (event.shiftKey && !arrowKeyOrMouseWheelEvent) | 281 if (event.shiftKey && !arrowKeyOrMouseWheelEvent) |
| 282 changeAmount = 100; | 282 changeAmount = 100; |
| 283 else if (event.shiftKey || !arrowKeyOrMouseWheelEvent) | 283 else if (event.shiftKey || !arrowKeyOrMouseWheelEvent) |
| 284 changeAmount = 10; | 284 changeAmount = 10; |
| 285 else if (event.altKey) | 285 else if (event.altKey) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 316 if (!selection.rangeCount) | 316 if (!selection.rangeCount) |
| 317 return false; | 317 return false; |
| 318 | 318 |
| 319 var selectionRange = selection.getRangeAt(0); | 319 var selectionRange = selection.getRangeAt(0); |
| 320 if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(element)) | 320 if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(element)) |
| 321 return false; | 321 return false; |
| 322 | 322 |
| 323 var originalValue = element.textContent; | 323 var originalValue = element.textContent; |
| 324 var wordRange = selectionRange.startContainer.rangeOfWord(selectionRange.sta
rtOffset, WebInspector.StyleValueDelimiters, element); | 324 var wordRange = selectionRange.startContainer.rangeOfWord(selectionRange.sta
rtOffset, WebInspector.StyleValueDelimiters, element); |
| 325 var wordString = wordRange.toString(); | 325 var wordString = wordRange.toString(); |
| 326 | 326 |
| 327 if (suggestionHandler && suggestionHandler(wordString)) | 327 if (suggestionHandler && suggestionHandler(wordString)) |
| 328 return false; | 328 return false; |
| 329 | 329 |
| 330 var replacementString; | 330 var replacementString; |
| 331 var prefix, suffix, number; | 331 var prefix, suffix, number; |
| 332 | 332 |
| 333 var matches; | 333 var matches; |
| 334 matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString); | 334 matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString); |
| 335 if (matches && matches.length) { | 335 if (matches && matches.length) { |
| 336 prefix = matches[1]; | 336 prefix = matches[1]; |
| 337 suffix = matches[3]; | 337 suffix = matches[3]; |
| 338 number = WebInspector._modifiedHexValue(matches[2], event); | 338 number = WebInspector._modifiedHexValue(matches[2], event); |
| 339 | 339 |
| 340 if (customNumberHandler) | 340 if (customNumberHandler) |
| 341 number = customNumberHandler(number); | 341 number = customNumberHandler(number); |
| 342 | 342 |
| 343 replacementString = prefix + number + suffix; | 343 replacementString = prefix + number + suffix; |
| 344 } else { | 344 } else { |
| 345 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString); | 345 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString); |
| 346 if (matches && matches.length) { | 346 if (matches && matches.length) { |
| 347 prefix = matches[1]; | 347 prefix = matches[1]; |
| 348 suffix = matches[3]; | 348 suffix = matches[3]; |
| 349 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), e
vent); | 349 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), e
vent); |
| 350 | 350 |
| 351 // Need to check for null explicitly. | 351 // Need to check for null explicitly. |
| 352 if (number === null) | 352 if (number === null) |
| 353 return false; | 353 return false; |
| 354 | 354 |
| 355 if (customNumberHandler) | 355 if (customNumberHandler) |
| 356 number = customNumberHandler(number); | 356 number = customNumberHandler(number); |
| 357 | 357 |
| 358 replacementString = prefix + number + suffix; | 358 replacementString = prefix + number + suffix; |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 if (replacementString) { | 362 if (replacementString) { |
| 363 var replacementTextNode = document.createTextNode(replacementString); | 363 var replacementTextNode = document.createTextNode(replacementString); |
| 364 | 364 |
| 365 wordRange.deleteContents(); | 365 wordRange.deleteContents(); |
| 366 wordRange.insertNode(replacementTextNode); | 366 wordRange.insertNode(replacementTextNode); |
| 367 | 367 |
| 368 var finalSelectionRange = document.createRange(); | 368 var finalSelectionRange = document.createRange(); |
| 369 finalSelectionRange.setStart(replacementTextNode, 0); | 369 finalSelectionRange.setStart(replacementTextNode, 0); |
| 370 finalSelectionRange.setEnd(replacementTextNode, replacementString.length
); | 370 finalSelectionRange.setEnd(replacementTextNode, replacementString.length
); |
| 371 | 371 |
| 372 selection.removeAllRanges(); | 372 selection.removeAllRanges(); |
| 373 selection.addRange(finalSelectionRange); | 373 selection.addRange(finalSelectionRange); |
| 374 | 374 |
| 375 event.handled = true; | 375 event.handled = true; |
| 376 event.preventDefault(); | 376 event.preventDefault(); |
| 377 | 377 |
| 378 if (finishHandler) | 378 if (finishHandler) |
| 379 finishHandler(originalValue, replacementString); | 379 finishHandler(originalValue, replacementString); |
| 380 | 380 |
| 381 return true; | 381 return true; |
| 382 } | 382 } |
| 383 return false; | 383 return false; |
| 384 } | 384 } |
| 385 | 385 |
| 386 /** | 386 /** |
| 387 * @param {number} ms | 387 * @param {number} ms |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 532 |
| 533 WebInspector._documentBlurred = function(event) | 533 WebInspector._documentBlurred = function(event) |
| 534 { | 534 { |
| 535 // We want to know when currentFocusElement loses focus to nowhere. | 535 // We want to know when currentFocusElement loses focus to nowhere. |
| 536 // This is the case when event.relatedTarget is null (no element is being fo
cused) | 536 // This is the case when event.relatedTarget is null (no element is being fo
cused) |
| 537 // and document.activeElement is reset to default (this is not a window blur
). | 537 // and document.activeElement is reset to default (this is not a window blur
). |
| 538 if (!event.relatedTarget && document.activeElement === document.body) | 538 if (!event.relatedTarget && document.activeElement === document.body) |
| 539 WebInspector.setCurrentFocusElement(null); | 539 WebInspector.setCurrentFocusElement(null); |
| 540 } | 540 } |
| 541 | 541 |
| 542 WebInspector._textInputTypes = ["text", "search", "tel", "url", "email", "passwo
rd"].keySet(); | 542 WebInspector._textInputTypes = ["text", "search", "tel", "url", "email", "passwo
rd"].keySet(); |
| 543 WebInspector._isTextEditingElement = function(element) | 543 WebInspector._isTextEditingElement = function(element) |
| 544 { | 544 { |
| 545 if (element instanceof HTMLInputElement) | 545 if (element instanceof HTMLInputElement) |
| 546 return element.type in WebInspector._textInputTypes; | 546 return element.type in WebInspector._textInputTypes; |
| 547 | 547 |
| 548 if (element instanceof HTMLTextAreaElement) | 548 if (element instanceof HTMLTextAreaElement) |
| 549 return true; | 549 return true; |
| 550 | 550 |
| 551 return false; | 551 return false; |
| 552 } | 552 } |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 | 784 |
| 785 WebInspector.endBatchUpdate = function() | 785 WebInspector.endBatchUpdate = function() |
| 786 { | 786 { |
| 787 if (--WebInspector._coalescingLevel) | 787 if (--WebInspector._coalescingLevel) |
| 788 return; | 788 return; |
| 789 | 789 |
| 790 var handlers = WebInspector._postUpdateHandlers; | 790 var handlers = WebInspector._postUpdateHandlers; |
| 791 delete WebInspector._postUpdateHandlers; | 791 delete WebInspector._postUpdateHandlers; |
| 792 | 792 |
| 793 window.requestAnimationFrame(function() { | 793 window.requestAnimationFrame(function() { |
| 794 if (WebInspector._coalescingLevel) | |
| 795 return; | |
| 796 var keys = handlers.keys(); | 794 var keys = handlers.keys(); |
| 797 for (var i = 0; i < keys.length; ++i) { | 795 for (var i = 0; i < keys.length; ++i) { |
| 798 var object = keys[i]; | 796 var object = keys[i]; |
| 799 var methods = handlers.get(object).keys(); | 797 var methods = handlers.get(object).items(); |
| 800 for (var j = 0; j < methods.length; ++j) | 798 for (var j = 0; j < methods.length; ++j) |
| 801 methods[j].call(object); | 799 methods[j].call(object); |
| 802 } | 800 } |
| 803 }); | 801 }); |
| 804 } | 802 } |
| 805 | 803 |
| 806 /** | 804 /** |
| 807 * @param {!Object} object | 805 * @param {!Object} object |
| 808 * @param {function()} method | 806 * @param {function()} method |
| 809 */ | 807 */ |
| 810 WebInspector.invokeOnceAfterBatchUpdate = function(object, method) | 808 WebInspector.invokeOnceAfterBatchUpdate = function(object, method) |
| 811 { | 809 { |
| 812 if (!WebInspector._coalescingLevel) { | 810 if (!WebInspector._coalescingLevel) { |
| 813 window.requestAnimationFrame(function() { | 811 window.requestAnimationFrame(method.bind(object)); |
| 814 if (!WebInspector._coalescingLevel) | |
| 815 method.call(object); | |
| 816 }); | |
| 817 return; | 812 return; |
| 818 } | 813 } |
| 819 | 814 |
| 820 var methods = WebInspector._postUpdateHandlers.get(object); | 815 var methods = WebInspector._postUpdateHandlers.get(object); |
| 821 if (!methods) { | 816 if (!methods) { |
| 822 methods = new Map(); | 817 methods = new Set(); |
| 823 WebInspector._postUpdateHandlers.put(object, methods); | 818 WebInspector._postUpdateHandlers.put(object, methods); |
| 824 } | 819 } |
| 825 methods.put(method); | 820 methods.add(method); |
| 826 } | 821 } |
| 827 | 822 |
| 828 ;(function() { | 823 ;(function() { |
| 829 | 824 |
| 830 function windowLoaded() | 825 function windowLoaded() |
| 831 { | 826 { |
| 832 window.addEventListener("focus", WebInspector._windowFocused, false); | 827 window.addEventListener("focus", WebInspector._windowFocused, false); |
| 833 window.addEventListener("blur", WebInspector._windowBlurred, false); | 828 window.addEventListener("blur", WebInspector._windowBlurred, false); |
| 834 document.addEventListener("focus", WebInspector._focusChanged, true); | 829 document.addEventListener("focus", WebInspector._focusChanged, true); |
| 835 document.addEventListener("blur", WebInspector._documentBlurred, true); | 830 document.addEventListener("blur", WebInspector._documentBlurred, true); |
| 836 window.removeEventListener("DOMContentLoaded", windowLoaded, false); | 831 window.removeEventListener("DOMContentLoaded", windowLoaded, false); |
| 837 } | 832 } |
| 838 | 833 |
| 839 window.addEventListener("DOMContentLoaded", windowLoaded, false); | 834 window.addEventListener("DOMContentLoaded", windowLoaded, false); |
| 840 | 835 |
| 841 })(); | 836 })(); |
| OLD | NEW |