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

Side by Side Diff: Source/devtools/front_end/ui/UIUtils.js

Issue 1175113007: Devtools: Fix "unable to change the value of R/G/B/A" in color picker (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rename variable Created 5 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/elements/Spectrum.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // Make the new number and constrain it to a precision of 6, this matches nu mbers the engine returns. 354 // Make the new number and constrain it to a precision of 6, this matches nu mbers the engine returns.
355 // Use the Number constructor to forget the fixed precision, so 1.100000 wil l print as 1.1. 355 // Use the Number constructor to forget the fixed precision, so 1.100000 wil l print as 1.1.
356 var result = Number((number + changeAmount).toFixed(6)); 356 var result = Number((number + changeAmount).toFixed(6));
357 if (!String(result).match(WebInspector.CSSNumberRegex)) 357 if (!String(result).match(WebInspector.CSSNumberRegex))
358 return null; 358 return null;
359 359
360 return result; 360 return result;
361 } 361 }
362 362
363 /** 363 /**
364 * @param {string} wordString
365 * @param {!Event} event
366 * @param {function(string, number, string):string=} customNumberHandler
367 * @return {?string}
368 */
369 WebInspector.createReplacementString = function(wordString, event, customNumberH andler)
370 {
371 var replacementString;
372 var prefix, suffix, number;
373
374 var matches;
375 matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString);
376 if (matches && matches.length) {
377 prefix = matches[1];
378 suffix = matches[3];
379 number = WebInspector._modifiedHexValue(matches[2], event);
380
381 replacementString = customNumberHandler ? customNumberHandler(prefix, nu mber, suffix) : prefix + number + suffix;
382 } else {
383 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString);
384 if (matches && matches.length) {
385 prefix = matches[1];
386 suffix = matches[3];
387 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), e vent);
388
389 // Need to check for null explicitly.
390 if (number === null)
391 return null;
392
393 replacementString = customNumberHandler ? customNumberHandler(prefix , number, suffix) : prefix + number + suffix;
394 }
395 }
396 return replacementString || null;
397 }
398
399 /**
364 * @param {!Event} event 400 * @param {!Event} event
365 * @param {!Element} element 401 * @param {!Element} element
366 * @param {function(string,string)=} finishHandler 402 * @param {function(string,string)=} finishHandler
367 * @param {function(string)=} suggestionHandler 403 * @param {function(string)=} suggestionHandler
368 * @param {function(string, number, string):string=} customNumberHandler 404 * @param {function(string, number, string):string=} customNumberHandler
369 * @return {boolean} 405 * @return {boolean}
370 */ 406 */
371 WebInspector.handleElementValueModifications = function(event, element, finishHa ndler, suggestionHandler, customNumberHandler) 407 WebInspector.handleElementValueModifications = function(event, element, finishHa ndler, suggestionHandler, customNumberHandler)
372 { 408 {
373 /** 409 /**
(...skipping 18 matching lines...) Expand all
392 if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(element)) 428 if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(element))
393 return false; 429 return false;
394 430
395 var originalValue = element.textContent; 431 var originalValue = element.textContent;
396 var wordRange = selectionRange.startContainer.rangeOfWord(selectionRange.sta rtOffset, WebInspector.StyleValueDelimiters, element); 432 var wordRange = selectionRange.startContainer.rangeOfWord(selectionRange.sta rtOffset, WebInspector.StyleValueDelimiters, element);
397 var wordString = wordRange.toString(); 433 var wordString = wordRange.toString();
398 434
399 if (suggestionHandler && suggestionHandler(wordString)) 435 if (suggestionHandler && suggestionHandler(wordString))
400 return false; 436 return false;
401 437
402 var replacementString; 438 var replacementString = WebInspector.createReplacementString(wordString, eve nt, customNumberHandler);
403 var prefix, suffix, number;
404
405 var matches;
406 matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString);
407 if (matches && matches.length) {
408 prefix = matches[1];
409 suffix = matches[3];
410 number = WebInspector._modifiedHexValue(matches[2], event);
411
412 replacementString = customNumberHandler ? customNumberHandler(prefix, nu mber, suffix) : prefix + number + suffix;
413 } else {
414 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString);
415 if (matches && matches.length) {
416 prefix = matches[1];
417 suffix = matches[3];
418 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), e vent);
419
420 // Need to check for null explicitly.
421 if (number === null)
422 return false;
423
424 replacementString = customNumberHandler ? customNumberHandler(prefix , number, suffix) : prefix + number + suffix;
425 }
426 }
427 439
428 if (replacementString) { 440 if (replacementString) {
429 var replacementTextNode = createTextNode(replacementString); 441 var replacementTextNode = createTextNode(replacementString);
430 442
431 wordRange.deleteContents(); 443 wordRange.deleteContents();
432 wordRange.insertNode(replacementTextNode); 444 wordRange.insertNode(replacementTextNode);
433 445
434 var finalSelectionRange = createRange(); 446 var finalSelectionRange = createRange();
435 finalSelectionRange.setStart(replacementTextNode, 0); 447 finalSelectionRange.setStart(replacementTextNode, 0);
436 finalSelectionRange.setEnd(replacementTextNode, replacementString.length ); 448 finalSelectionRange.setEnd(replacementTextNode, replacementString.length );
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 // Due to the nature of regex, |items| array has matched elements on its even indexes. 1455 // Due to the nature of regex, |items| array has matched elements on its even indexes.
1444 var items = text.replace(regex, "\0$1\0").split("\0"); 1456 var items = text.replace(regex, "\0$1\0").split("\0");
1445 for (var i = 0; i < items.length; ++i) { 1457 for (var i = 0; i < items.length; ++i) {
1446 var processedNode = i % 2 ? processor(items[i]) : this._runProcessor (processorIndex + 1, items[i]); 1458 var processedNode = i % 2 ? processor(items[i]) : this._runProcessor (processorIndex + 1, items[i]);
1447 container.appendChild(processedNode); 1459 container.appendChild(processedNode);
1448 } 1460 }
1449 1461
1450 return container; 1462 return container;
1451 } 1463 }
1452 } 1464 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/elements/Spectrum.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698