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

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

Issue 2278203003: DevTools: Allow shadow-editor value manipulation with arrow keys and mousewheel (Closed)
Patch Set: Check key pressed inside createReplacementString Created 4 years, 3 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/CSSShadowEditor.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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 if (event.key === "ArrowUp" || event.key === "PageUp") 379 if (event.key === "ArrowUp" || event.key === "PageUp")
380 direction = "Up"; 380 direction = "Up";
381 else if (event.key === "ArrowDown" || event.key === "PageDown") 381 else if (event.key === "ArrowDown" || event.key === "PageDown")
382 direction = "Down"; 382 direction = "Down";
383 } 383 }
384 return direction; 384 return direction;
385 } 385 }
386 386
387 /** 387 /**
388 * @param {string} hexString 388 * @param {string} hexString
389 * @param {!Event} event 389 * @param {!Event} event
dgozman 2016/08/29 17:47:20 Let's add @return annotation.
flandy 2016/08/29 18:47:06 Done. The lack of return annotations here skirte
390 */ 390 */
391 WebInspector._modifiedHexValue = function(hexString, event) 391 WebInspector._modifiedHexValue = function(hexString, event)
392 { 392 {
393 var direction = WebInspector._valueModificationDirection(event); 393 var direction = WebInspector._valueModificationDirection(event);
394 if (!direction) 394 if (!direction)
395 return hexString; 395 return null;
396 396
397 var mouseEvent = /** @type {!MouseEvent} */(event); 397 var mouseEvent = /** @type {!MouseEvent} */(event);
398 var number = parseInt(hexString, 16); 398 var number = parseInt(hexString, 16);
399 if (isNaN(number) || !isFinite(number)) 399 if (isNaN(number) || !isFinite(number))
400 return hexString; 400 return null;
401 401
402 var hexStrLen = hexString.length; 402 var hexStrLen = hexString.length;
403 var channelLen = hexStrLen / 3; 403 var channelLen = hexStrLen / 3;
404 404
405 // Colors are either rgb or rrggbb. 405 // Colors are either rgb or rrggbb.
406 if (channelLen !== 1 && channelLen !== 2) 406 if (channelLen !== 1 && channelLen !== 2)
407 return hexString; 407 return null;
408 408
409 // Precision modifier keys work with both mousewheel and up/down keys. 409 // Precision modifier keys work with both mousewheel and up/down keys.
410 // When ctrl is pressed, increase R by 1. 410 // When ctrl is pressed, increase R by 1.
411 // When shift is pressed, increase G by 1. 411 // When shift is pressed, increase G by 1.
412 // When alt is pressed, increase B by 1. 412 // When alt is pressed, increase B by 1.
413 // If no shortcut keys are pressed then increase hex value by 1. 413 // If no shortcut keys are pressed then increase hex value by 1.
414 // Keys can be pressed together to increase RGB channels. e.g trying differe nt shades. 414 // Keys can be pressed together to increase RGB channels. e.g trying differe nt shades.
415 var delta = 0; 415 var delta = 0;
416 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(mouseEvent)) 416 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(mouseEvent))
417 delta += Math.pow(16, channelLen * 2); 417 delta += Math.pow(16, channelLen * 2);
(...skipping 18 matching lines...) Expand all
436 } 436 }
437 437
438 /** 438 /**
439 * @param {number} number 439 * @param {number} number
440 * @param {!Event} event 440 * @param {!Event} event
441 */ 441 */
442 WebInspector._modifiedFloatNumber = function(number, event) 442 WebInspector._modifiedFloatNumber = function(number, event)
443 { 443 {
444 var direction = WebInspector._valueModificationDirection(event); 444 var direction = WebInspector._valueModificationDirection(event);
445 if (!direction) 445 if (!direction)
446 return number; 446 return null;
447 447
448 var mouseEvent = /** @type {!MouseEvent} */(event); 448 var mouseEvent = /** @type {!MouseEvent} */(event);
449 449
450 // Precision modifier keys work with both mousewheel and up/down keys. 450 // Precision modifier keys work with both mousewheel and up/down keys.
451 // When ctrl is pressed, increase by 100. 451 // When ctrl is pressed, increase by 100.
452 // When shift is pressed, increase by 10. 452 // When shift is pressed, increase by 10.
453 // When alt is pressed, increase by 0.1. 453 // When alt is pressed, increase by 0.1.
454 // Otherwise increase by 1. 454 // Otherwise increase by 1.
455 var delta = 1; 455 var delta = 1;
456 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(mouseEvent)) 456 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(mouseEvent))
(...skipping 17 matching lines...) Expand all
474 474
475 /** 475 /**
476 * @param {string} wordString 476 * @param {string} wordString
477 * @param {!Event} event 477 * @param {!Event} event
478 * @param {function(string, number, string):string=} customNumberHandler 478 * @param {function(string, number, string):string=} customNumberHandler
479 * @return {?string} 479 * @return {?string}
480 */ 480 */
481 WebInspector.createReplacementString = function(wordString, event, customNumberH andler) 481 WebInspector.createReplacementString = function(wordString, event, customNumberH andler)
482 { 482 {
483 var replacementString; 483 var replacementString;
484 var prefix, suffix, number; 484 var prefix = "";
485 485 var suffix = "";
486 var number = null;
486 var matches; 487 var matches;
487 matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString); 488 matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString);
488 if (matches && matches.length) { 489 if (matches && matches.length) {
489 prefix = matches[1]; 490 prefix = matches[1];
490 suffix = matches[3]; 491 suffix = matches[3];
491 number = WebInspector._modifiedHexValue(matches[2], event); 492 number = WebInspector._modifiedHexValue(matches[2], event);
492
493 replacementString = customNumberHandler ? customNumberHandler(prefix, nu mber, suffix) : prefix + number + suffix;
494 } else { 493 } else {
495 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString); 494 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString);
496 if (matches && matches.length) { 495 if (matches && matches.length) {
497 prefix = matches[1]; 496 prefix = matches[1];
498 suffix = matches[3]; 497 suffix = matches[3];
499 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), e vent); 498 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), e vent);
500
501 // Need to check for null explicitly.
502 if (number === null)
503 return null;
504
505 replacementString = customNumberHandler ? customNumberHandler(prefix , number, suffix) : prefix + number + suffix;
506 } 499 }
507 } 500 }
501 // Need to check for null explicitly.
502 if (number === null)
503 return null;
504 replacementString = customNumberHandler ? customNumberHandler(prefix, number , suffix) : prefix + number + suffix;
508 return replacementString || null; 505 return replacementString || null;
509 } 506 }
510 507
511 /** 508 /**
512 * @param {!Event} event 509 * @param {!Event} event
513 * @param {!Element} element 510 * @param {!Element} element
514 * @param {function(string,string)=} finishHandler 511 * @param {function(string,string)=} finishHandler
515 * @param {function(string)=} suggestionHandler 512 * @param {function(string)=} suggestionHandler
516 * @param {function(string, number, string):string=} customNumberHandler 513 * @param {function(string, number, string):string=} customNumberHandler
517 * @return {boolean} 514 * @return {boolean}
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 * @param {string} title 2003 * @param {string} title
2007 * @return {!Element} 2004 * @return {!Element}
2008 */ 2005 */
2009 WebInspector.linkifyDocumentationURLAsNode = function(article, title) 2006 WebInspector.linkifyDocumentationURLAsNode = function(article, title)
2010 { 2007 {
2011 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool s/chrome-devtools/" + article, title, undefined, true); 2008 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool s/chrome-devtools/" + article, title, undefined, true);
2012 } 2009 }
2013 2010
2014 /** @type {!WebInspector.ThemeSupport} */ 2011 /** @type {!WebInspector.ThemeSupport} */
2015 WebInspector.themeSupport; 2012 WebInspector.themeSupport;
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/CSSShadowEditor.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698