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

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

Issue 1824683002: Fixes 590477: Style pane numeric property change modifier shortcuts are undiscoverable. Shift mouse… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes 590477: Style pane numeric property change modifier shortcuts are undiscoverable. Shift mouse… Created 4 years, 7 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/TextPrompt.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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 296
297 /** 297 /**
298 * @param {!Event} event 298 * @param {!Event} event
299 * @return {?string} 299 * @return {?string}
300 */ 300 */
301 WebInspector._valueModificationDirection = function(event) 301 WebInspector._valueModificationDirection = function(event)
302 { 302 {
303 var direction = null; 303 var direction = null;
304 if (event.type === "mousewheel") { 304 if (event.type === "mousewheel") {
305 if (event.wheelDeltaY > 0) 305 // When shift is pressed while spinning mousewheel, delta comes as wheel DeltaX.
306 if (event.wheelDeltaY > 0 || event.wheelDeltaX > 0)
306 direction = "Up"; 307 direction = "Up";
307 else if (event.wheelDeltaY < 0) 308 else if (event.wheelDeltaY < 0 || event.wheelDeltaX < 0)
308 direction = "Down"; 309 direction = "Down";
309 } else { 310 } else {
310 if (event.keyIdentifier === "Up" || event.keyIdentifier === "PageUp") 311 if (event.keyIdentifier === "Up" || event.keyIdentifier === "PageUp")
311 direction = "Up"; 312 direction = "Up";
312 else if (event.keyIdentifier === "Down" || event.keyIdentifier === "Page Down") 313 else if (event.keyIdentifier === "Down" || event.keyIdentifier === "Page Down")
313 direction = "Down"; 314 direction = "Down";
314 } 315 }
315 return direction; 316 return direction;
316 } 317 }
317 318
318 /** 319 /**
319 * @param {string} hexString 320 * @param {string} hexString
320 * @param {!Event} event 321 * @param {!Event} event
321 */ 322 */
322 WebInspector._modifiedHexValue = function(hexString, event) 323 WebInspector._modifiedHexValue = function(hexString, event)
323 { 324 {
324 var direction = WebInspector._valueModificationDirection(event); 325 var direction = WebInspector._valueModificationDirection(event);
325 if (!direction) 326 if (!direction)
326 return hexString; 327 return hexString;
327 328
328 var number = parseInt(hexString, 16); 329 var number = parseInt(hexString, 16);
329 if (isNaN(number) || !isFinite(number)) 330 if (isNaN(number) || !isFinite(number))
330 return hexString; 331 return hexString;
331 332
332 var maxValue = Math.pow(16, hexString.length) - 1; 333 var hexStrLen = hexString.length;
333 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyId entifier === "Down" || event.type === "mousewheel"); 334 var channelLen = hexStrLen / 3;
334 var delta;
335 335
336 if (arrowKeyOrMouseWheelEvent) 336 // Colors are either rgb or rrggbb.
337 delta = (direction === "Up") ? 1 : -1; 337 if (channelLen !== 1 && channelLen !== 2)
338 else 338 return hexString;
339 delta = (event.keyIdentifier === "PageUp") ? 16 : -16;
340 339
340 // Precision modifier keys work with both mousewheel and up/down keys.
341 // When ctrl is pressed, increase R by 1.
342 // When shift is pressed, increase G by 1.
343 // When alt is pressed, increase B by 1.
344 // If no shortcut keys are pressed then increase hex value by 1.
345 // Keys can be pressed together to increase RGB channels. e.g trying differe nt shades.
346 var delta = 0;
347 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event))
348 delta += Math.pow(16, channelLen * 2);
341 if (event.shiftKey) 349 if (event.shiftKey)
342 delta *= 16; 350 delta += Math.pow(16, channelLen);
351 if (event.altKey)
352 delta += 1;
353 if (delta === 0)
354 delta = 1;
355 if (direction === "Down")
356 delta *= -1;
343 357
344 var result = number + delta; 358 // Increase hex value by 1 and clamp from 0 ... maxValue.
345 if (result < 0) 359 var maxValue = Math.pow(16, hexStrLen) - 1;
346 result = 0; // Color hex values are never negative, so clamp to 0. 360 var result = Number.constrain(number + delta, 0, maxValue);
347 else if (result > maxValue)
348 return hexString;
349 361
350 // Ensure the result length is the same as the original hex value. 362 // Ensure the result length is the same as the original hex value.
351 var resultString = result.toString(16).toUpperCase(); 363 var resultString = result.toString(16).toUpperCase();
352 for (var i = 0, lengthDelta = hexString.length - resultString.length; i < le ngthDelta; ++i) 364 for (var i = 0, lengthDelta = hexStrLen - resultString.length; i < lengthDel ta; ++i)
353 resultString = "0" + resultString; 365 resultString = "0" + resultString;
354 return resultString; 366 return resultString;
355 } 367 }
356 368
357 /** 369 /**
358 * @param {number} number 370 * @param {number} number
359 * @param {!Event} event 371 * @param {!Event} event
360 */ 372 */
361 WebInspector._modifiedFloatNumber = function(number, event) 373 WebInspector._modifiedFloatNumber = function(number, event)
362 { 374 {
363 var direction = WebInspector._valueModificationDirection(event); 375 var direction = WebInspector._valueModificationDirection(event);
364 if (!direction) 376 if (!direction)
365 return number; 377 return number;
366 378
367 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyId entifier === "Down" || event.type === "mousewheel"); 379 // Precision modifier keys work with both mousewheel and up/down keys.
368 380 // When ctrl is pressed, increase by 100.
369 // Jump by 10 when shift is down or jump by 0.1 when Alt/Option is down. 381 // When shift is pressed, increase by 10.
370 // Also jump by 10 for page up and down, or by 100 if shift is held with a p age key. 382 // When alt is pressed, increase by 0.1.
371 var changeAmount = 1; 383 // Otherwise increase by 1.
372 if (event.shiftKey && !arrowKeyOrMouseWheelEvent) 384 var delta = 1;
373 changeAmount = 100; 385 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event))
374 else if (event.shiftKey || !arrowKeyOrMouseWheelEvent) 386 delta = 100;
375 changeAmount = 10; 387 else if (event.shiftKey)
388 delta = 10;
376 else if (event.altKey) 389 else if (event.altKey)
377 changeAmount = 0.1; 390 delta = 0.1;
378 391
379 if (direction === "Down") 392 if (direction === "Down")
380 changeAmount *= -1; 393 delta *= -1;
381 394
382 // Make the new number and constrain it to a precision of 6, this matches nu mbers the engine returns. 395 // Make the new number and constrain it to a precision of 6, this matches nu mbers the engine returns.
383 // Use the Number constructor to forget the fixed precision, so 1.100000 wil l print as 1.1. 396 // Use the Number constructor to forget the fixed precision, so 1.100000 wil l print as 1.1.
384 var result = Number((number + changeAmount).toFixed(6)); 397 var result = Number((number + delta).toFixed(6));
385 if (!String(result).match(WebInspector.CSSNumberRegex)) 398 if (!String(result).match(WebInspector.CSSNumberRegex))
386 return null; 399 return null;
387 400
388 return result; 401 return result;
389 } 402 }
390 403
391 /** 404 /**
392 * @param {string} wordString 405 * @param {string} wordString
393 * @param {!Event} event 406 * @param {!Event} event
394 * @param {function(string, number, string):string=} customNumberHandler 407 * @param {function(string, number, string):string=} customNumberHandler
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 * @param {string} title 1910 * @param {string} title
1898 * @return {!Element} 1911 * @return {!Element}
1899 */ 1912 */
1900 WebInspector.linkifyDocumentationURLAsNode = function(article, title) 1913 WebInspector.linkifyDocumentationURLAsNode = function(article, title)
1901 { 1914 {
1902 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool s/chrome-devtools/" + article, title, undefined, true); 1915 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool s/chrome-devtools/" + article, title, undefined, true);
1903 } 1916 }
1904 1917
1905 /** @type {!WebInspector.ThemeSupport} */ 1918 /** @type {!WebInspector.ThemeSupport} */
1906 WebInspector.themeSupport; 1919 WebInspector.themeSupport;
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/TextPrompt.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698