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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 return null; | 310 return null; |
311 | 311 |
312 return result; | 312 return result; |
313 } | 313 } |
314 | 314 |
315 /** | 315 /** |
316 * @param {?Event} event | 316 * @param {?Event} event |
317 * @param {!Element} element | 317 * @param {!Element} element |
318 * @param {function(string,string)=} finishHandler | 318 * @param {function(string,string)=} finishHandler |
319 * @param {function(string)=} suggestionHandler | 319 * @param {function(string)=} suggestionHandler |
320 * @param {function(number):number=} customNumberHandler | 320 * @param {function(string, number, string):string=} customNumberHandler |
321 * @return {boolean} | 321 * @return {boolean} |
322 */ | 322 */ |
323 WebInspector.handleElementValueModifications = function(event, element, finishHa
ndler, suggestionHandler, customNumberHandler) | 323 WebInspector.handleElementValueModifications = function(event, element, finishHa
ndler, suggestionHandler, customNumberHandler) |
324 { | 324 { |
325 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyId
entifier === "Down" || event.type === "mousewheel"); | 325 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyId
entifier === "Down" || event.type === "mousewheel"); |
326 var pageKeyPressed = (event.keyIdentifier === "PageUp" || event.keyIdentifie
r === "PageDown"); | 326 var pageKeyPressed = (event.keyIdentifier === "PageUp" || event.keyIdentifie
r === "PageDown"); |
327 if (!arrowKeyOrMouseWheelEvent && !pageKeyPressed) | 327 if (!arrowKeyOrMouseWheelEvent && !pageKeyPressed) |
328 return false; | 328 return false; |
329 | 329 |
330 var selection = window.getSelection(); | 330 var selection = window.getSelection(); |
(...skipping 14 matching lines...) Expand all Loading... |
345 var replacementString; | 345 var replacementString; |
346 var prefix, suffix, number; | 346 var prefix, suffix, number; |
347 | 347 |
348 var matches; | 348 var matches; |
349 matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString); | 349 matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString); |
350 if (matches && matches.length) { | 350 if (matches && matches.length) { |
351 prefix = matches[1]; | 351 prefix = matches[1]; |
352 suffix = matches[3]; | 352 suffix = matches[3]; |
353 number = WebInspector._modifiedHexValue(matches[2], event); | 353 number = WebInspector._modifiedHexValue(matches[2], event); |
354 | 354 |
355 if (customNumberHandler) | 355 replacementString = customNumberHandler ? customNumberHandler(prefix, nu
mber, suffix) : prefix + number + suffix; |
356 number = customNumberHandler(number); | |
357 | |
358 replacementString = prefix + number + suffix; | |
359 } else { | 356 } else { |
360 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString); | 357 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString); |
361 if (matches && matches.length) { | 358 if (matches && matches.length) { |
362 prefix = matches[1]; | 359 prefix = matches[1]; |
363 suffix = matches[3]; | 360 suffix = matches[3]; |
364 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), e
vent); | 361 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), e
vent); |
365 | 362 |
366 // Need to check for null explicitly. | 363 // Need to check for null explicitly. |
367 if (number === null) | 364 if (number === null) |
368 return false; | 365 return false; |
369 | 366 |
370 if (customNumberHandler) | 367 replacementString = customNumberHandler ? customNumberHandler(prefix
, number, suffix) : prefix + number + suffix; |
371 number = customNumberHandler(number); | |
372 | |
373 replacementString = prefix + number + suffix; | |
374 } | 368 } |
375 } | 369 } |
376 | 370 |
377 if (replacementString) { | 371 if (replacementString) { |
378 var replacementTextNode = document.createTextNode(replacementString); | 372 var replacementTextNode = document.createTextNode(replacementString); |
379 | 373 |
380 wordRange.deleteContents(); | 374 wordRange.deleteContents(); |
381 wordRange.insertNode(replacementTextNode); | 375 wordRange.insertNode(replacementTextNode); |
382 | 376 |
383 var finalSelectionRange = document.createRange(); | 377 var finalSelectionRange = document.createRange(); |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 window.addEventListener("focus", WebInspector._windowFocused, false); | 904 window.addEventListener("focus", WebInspector._windowFocused, false); |
911 window.addEventListener("blur", WebInspector._windowBlurred, false); | 905 window.addEventListener("blur", WebInspector._windowBlurred, false); |
912 document.addEventListener("focus", WebInspector._focusChanged, true); | 906 document.addEventListener("focus", WebInspector._focusChanged, true); |
913 document.addEventListener("blur", WebInspector._documentBlurred, true); | 907 document.addEventListener("blur", WebInspector._documentBlurred, true); |
914 window.removeEventListener("DOMContentLoaded", windowLoaded, false); | 908 window.removeEventListener("DOMContentLoaded", windowLoaded, false); |
915 } | 909 } |
916 | 910 |
917 window.addEventListener("DOMContentLoaded", windowLoaded, false); | 911 window.addEventListener("DOMContentLoaded", windowLoaded, false); |
918 | 912 |
919 })(); | 913 })(); |
OLD | NEW |