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

Side by Side Diff: ui/keyboard/resources/main.js

Issue 150783002: Aligns the Q A Z keys on the a11y keyboard. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change space bar color and fix font size bug. Created 6 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 (function(exports) { 4 (function(exports) {
5 /** 5 /**
6 * Alignment options for a keyset. 6 * Alignment options for a keyset.
7 * @param {Object=} opt_keyset The keyset to calculate the dimensions for. 7 * @param {Object=} opt_keyset The keyset to calculate the dimensions for.
8 * Defaults to the current active keyset. 8 * Defaults to the current active keyset.
9 */ 9 */
10 var AlignmentOptions = function(opt_keyset) { 10 var AlignmentOptions = function(opt_keyset) {
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 * @param {number} width The total extraneous width to distribute. 301 * @param {number} width The total extraneous width to distribute.
302 * @param {number} keyHeight The height of each key. 302 * @param {number} keyHeight The height of each key.
303 * @param {number} yOffset The y-coordinate of the top edge of the row. 303 * @param {number} yOffset The y-coordinate of the top edge of the row.
304 */ 304 */
305 function redistribute(allKeys, pitch, xOffset, width, keyHeight, yOffset) { 305 function redistribute(allKeys, pitch, xOffset, width, keyHeight, yOffset) {
306 var weight = 0; 306 var weight = 0;
307 for (var i = 0; i < allKeys.length; i++) { 307 for (var i = 0; i < allKeys.length; i++) {
308 weight += allKeys[i].weight; 308 weight += allKeys[i].weight;
309 } 309 }
310 var availableWidth = width - (allKeys.length - 1) * pitch; 310 var availableWidth = width - (allKeys.length - 1) * pitch;
311 var pixelsPerWeight = width / weight; 311 var pixelsPerWeight = availableWidth / weight;
312 for (var i = 0; i < allKeys.length; i++) { 312 for (var i = 0; i < allKeys.length; i++) {
313 var keyWidth = Math.floor(allKeys[i].weight * pixelsPerWeight); 313 var keyWidth = Math.floor(allKeys[i].weight * pixelsPerWeight);
314 if (i == allKeys.length -1) { 314 if (i == allKeys.length -1) {
315 keyWidth = availableWidth; 315 keyWidth = availableWidth;
316 } 316 }
317 updateKey(allKeys[i], keyWidth, keyHeight, xOffset, yOffset) 317 updateKey(allKeys[i], keyWidth, keyHeight, xOffset, yOffset)
318 availableWidth -= keyWidth; 318 availableWidth -= keyWidth;
319 xOffset += keyWidth + pitch; 319 xOffset += keyWidth + pitch;
320 } 320 }
321 } 321 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 // All left-over pixels assigned to right most key. 448 // All left-over pixels assigned to right most key.
449 if (i == (stretch.length - 1)) 449 if (i == (stretch.length - 1))
450 stretch[i].setAttribute('bonus', bonus + extra); 450 stretch[i].setAttribute('bonus', bonus + extra);
451 else 451 else
452 stretch[i].setAttribute('bonus', bonus); 452 stretch[i].setAttribute('bonus', bonus);
453 } 453 }
454 break; 454 break;
455 case RowAlignment.CENTER: 455 case RowAlignment.CENTER:
456 xOffset += Math.floor(extra/2) 456 xOffset += Math.floor(extra/2)
457 break; 457 break;
458 case RowAlignment.JUSTIFY: 458 case RowAlignment.RIGHT:
459 xOffset += extra; 459 xOffset += extra;
460 break; 460 break;
461 case RowAlignment.STRETCHRIGHT:
462 all[all.length-1].setAttribute('bonus', extra);
kevers 2014/01/31 20:11:00 See comment below on "bonus".
rsadam 2014/01/31 20:40:18 Done.
461 default: 463 default:
462 break; 464 break;
463 }; 465 };
464 466
465 var yOffset = params.offsetTop + heightOffset; 467 var yOffset = params.offsetTop + heightOffset;
466 var left = xOffset; 468 var left = xOffset;
467 for (var i = 0; i < all.length; i++) { 469 for (var i = 0; i < all.length; i++) {
468 var key = all[i]; 470 var key = all[i];
469 var width = params.keyWidth; 471 var width = params.keyWidth;
470 if (key.weight != DEFAULT_KEY_WEIGHT_X) { 472 if (key.weight != DEFAULT_KEY_WEIGHT_X)
471 width = Math.floor((params.keyWidth/DEFAULT_KEY_WEIGHT_X) * key.weight) 473 width = Math.floor((params.keyWidth/DEFAULT_KEY_WEIGHT_X) * key.weight)
472 var bonus = key.getAttribute('bonus') 474 var bonus = key.getAttribute('bonus')
kevers 2014/01/31 20:11:00 "bonus" is too generic. Also, we should be taking
rsadam 2014/01/31 20:40:18 Done.
473 if (bonus) 475 if (bonus)
474 width += parseInt(bonus) 476 width += parseInt(bonus)
475 }
476 updateKey(key, width, params.keyHeight, left, yOffset) 477 updateKey(key, width, params.keyHeight, left, yOffset)
477 left += (width + params.pitchX); 478 left += (width + params.pitchX);
478 } 479 }
479 } 480 }
480 481
481 /** 482 /**
482 * Realigns the keysets in all layouts of the keyboard. 483 * Realigns the keysets in all layouts of the keyboard.
483 */ 484 */
484 function realignAll() { 485 function realignAll() {
485 var keyboard = $('keyboard'); 486 var keyboard = $('keyboard');
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 keyboard.stale = false; 519 keyboard.stale = false;
519 } 520 }
520 521
521 /* 522 /*
522 * Realigns a given keyset. 523 * Realigns a given keyset.
523 * @param {Object} keyset The keyset to realign. 524 * @param {Object} keyset The keyset to realign.
524 * @param {!AlignmentOptions} params The parameters used to align the keyset. 525 * @param {!AlignmentOptions} params The parameters used to align the keyset.
525 */ 526 */
526 function realignKeyset(keyset, params) { 527 function realignKeyset(keyset, params) {
527 var rows = keyset.querySelectorAll('kb-row').array(); 528 var rows = keyset.querySelectorAll('kb-row').array();
529 var maxSize = getKeyboardBounds();
530 var height = (maxSize.width > ASPECT_RATIO * maxSize.height) ?
531 maxSize.height : Math.floor(maxSize.width / ASPECT_RATIO);
532 keyset.style.fontSize = (height / FONT_SIZE_RATIO / rows.length) + 'px';
533
528 var heightOffset = 0; 534 var heightOffset = 0;
529 for (var i = 0; i < rows.length; i++) { 535 for (var i = 0; i < rows.length; i++) {
530 var row = rows[i]; 536 var row = rows[i];
531 if (row.querySelector('.space') && (i > 1)) { 537 if (row.querySelector('.space') && (i > 1)) {
532 realignSpacebarRow(row, rows[i-1], params, heightOffset) 538 realignSpacebarRow(row, rows[i-1], params, heightOffset)
533 } else { 539 } else {
534 realignRow(row, params, heightOffset); 540 realignRow(row, params, heightOffset);
535 } 541 }
536 heightOffset += (params.keyHeight + params.pitchY); 542 heightOffset += (params.keyHeight + params.pitchY);
537 } 543 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 var importedContent = importHTML(content); 593 var importedContent = importHTML(content);
588 expandHTML(importedContent); 594 expandHTML(importedContent);
589 return importedContent; 595 return importedContent;
590 } 596 }
591 597
592 // Prevents all default actions of touch. Keyboard should use its own gesture 598 // Prevents all default actions of touch. Keyboard should use its own gesture
593 // recognizer. 599 // recognizer.
594 addEventListener('touchstart', function(e) { e.preventDefault() }); 600 addEventListener('touchstart', function(e) { e.preventDefault() });
595 addEventListener('touchend', function(e) { e.preventDefault() }); 601 addEventListener('touchend', function(e) { e.preventDefault() });
596 addEventListener('touchmove', function(e) { e.preventDefault() }); 602 addEventListener('touchmove', function(e) { e.preventDefault() });
OLDNEW
« ui/keyboard/resources/constants.js ('K') | « ui/keyboard/resources/layouts/system-qwerty.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698