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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/command_handler.js

Issue 2601333002: Update json_schema_compiler to handle the Automation extension API (Closed)
Patch Set: Address lots of feedback Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 4
5 /** 5 /**
6 * @fileoverview ChromeVox commands. 6 * @fileoverview ChromeVox commands.
7 */ 7 */
8 8
9 goog.provide('CommandHandler'); 9 goog.provide('CommandHandler');
10 10
(...skipping 24 matching lines...) Expand all
35 35
36 if (!focusedNode) 36 if (!focusedNode)
37 ChromeVoxState.instance.setCurrentRange(null); 37 ChromeVoxState.instance.setCurrentRange(null);
38 }); 38 });
39 39
40 // These commands don't require a current range and work in all modes. 40 // These commands don't require a current range and work in all modes.
41 switch (command) { 41 switch (command) {
42 case 'speakTimeAndDate': 42 case 'speakTimeAndDate':
43 chrome.automation.getDesktop(function(d) { 43 chrome.automation.getDesktop(function(d) {
44 // First, try speaking the on-screen time. 44 // First, try speaking the on-screen time.
45 var allTime = d.findAll({role: RoleType.time}); 45 var allTime = d.findAll({role: RoleType.TIME});
46 allTime.filter(function(t) { return t.root.role == RoleType.desktop; }); 46 allTime.filter(function(t) { return t.root.role == RoleType.DESKTOP; });
47 47
48 var timeString = ''; 48 var timeString = '';
49 allTime.forEach(function(t) { 49 allTime.forEach(function(t) {
50 if (t.name) timeString = t.name; 50 if (t.name) timeString = t.name;
51 }); 51 });
52 if (timeString) { 52 if (timeString) {
53 cvox.ChromeVox.tts.speak(timeString, cvox.QueueMode.FLUSH); 53 cvox.ChromeVox.tts.speak(timeString, cvox.QueueMode.FLUSH);
54 } else { 54 } else {
55 // Fallback to the old way of speaking time. 55 // Fallback to the old way of speaking time.
56 var output = new Output(); 56 var output = new Output();
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 break; 441 break;
442 case 'jumpToBottom': 442 case 'jumpToBottom':
443 var node = AutomationUtil.findNodePost( 443 var node = AutomationUtil.findNodePost(
444 current.start.node.root, Dir.BACKWARD, AutomationPredicate.leaf); 444 current.start.node.root, Dir.BACKWARD, AutomationPredicate.leaf);
445 if (node) 445 if (node)
446 current = cursors.Range.fromNode(node); 446 current = cursors.Range.fromNode(node);
447 break; 447 break;
448 case 'forceClickOnCurrentItem': 448 case 'forceClickOnCurrentItem':
449 if (ChromeVoxState.instance.currentRange_) { 449 if (ChromeVoxState.instance.currentRange_) {
450 var actionNode = ChromeVoxState.instance.currentRange_.start.node; 450 var actionNode = ChromeVoxState.instance.currentRange_.start.node;
451 if (actionNode.role == RoleType.inlineTextBox) 451 if (actionNode.role == RoleType.INLINE_TEXT_BOX)
452 actionNode = actionNode.parent; 452 actionNode = actionNode.parent;
453 actionNode.doDefault(); 453 actionNode.doDefault();
454 } 454 }
455 // Skip all other processing; if focus changes, we should get an event 455 // Skip all other processing; if focus changes, we should get an event
456 // for that. 456 // for that.
457 return false; 457 return false;
458 case 'readFromHere': 458 case 'readFromHere':
459 ChromeVoxState.isReadingContinuously = true; 459 ChromeVoxState.isReadingContinuously = true;
460 var continueReading = function() { 460 var continueReading = function() {
461 if (!ChromeVoxState.isReadingContinuously || 461 if (!ChromeVoxState.isReadingContinuously ||
462 !ChromeVoxState.instance.currentRange_) 462 !ChromeVoxState.instance.currentRange_)
463 return; 463 return;
464 464
465 var prevRange = ChromeVoxState.instance.currentRange_; 465 var prevRange = ChromeVoxState.instance.currentRange_;
466 var newRange = 466 var newRange =
467 ChromeVoxState.instance.currentRange_.move( 467 ChromeVoxState.instance.currentRange_.move(
468 cursors.Unit.NODE, Dir.FORWARD); 468 cursors.Unit.NODE, Dir.FORWARD);
469 469
470 // Stop if we've wrapped back to the document. 470 // Stop if we've wrapped back to the document.
471 var maybeDoc = newRange.start.node; 471 var maybeDoc = newRange.start.node;
472 if (maybeDoc.role == RoleType.rootWebArea && 472 if (maybeDoc.role == RoleType.ROOT_WEB_AREA &&
473 maybeDoc.parent.root.role == RoleType.desktop) { 473 maybeDoc.parent.root.role == RoleType.DESKTOP) {
474 ChromeVoxState.isReadingContinuously = false; 474 ChromeVoxState.isReadingContinuously = false;
475 return; 475 return;
476 } 476 }
477 477
478 ChromeVoxState.instance.setCurrentRange(newRange); 478 ChromeVoxState.instance.setCurrentRange(newRange);
479 479
480 new Output() 480 new Output()
481 .withRichSpeechAndBraille(ChromeVoxState.instance.currentRange_, 481 .withRichSpeechAndBraille(ChromeVoxState.instance.currentRange_,
482 prevRange, 482 prevRange,
483 Output.EventType.NAVIGATE) 483 Output.EventType.NAVIGATE)
484 .onSpeechEnd(continueReading) 484 .onSpeechEnd(continueReading)
485 .go(); 485 .go();
486 }.bind(this); 486 }.bind(this);
487 487
488 new Output() 488 new Output()
489 .withRichSpeechAndBraille(ChromeVoxState.instance.currentRange_, 489 .withRichSpeechAndBraille(ChromeVoxState.instance.currentRange_,
490 null, 490 null,
491 Output.EventType.NAVIGATE) 491 Output.EventType.NAVIGATE)
492 .onSpeechEnd(continueReading) 492 .onSpeechEnd(continueReading)
493 .go(); 493 .go();
494 494
495 return false; 495 return false;
496 case 'contextMenu': 496 case 'contextMenu':
497 if (ChromeVoxState.instance.currentRange_) { 497 if (ChromeVoxState.instance.currentRange_) {
498 var actionNode = ChromeVoxState.instance.currentRange_.start.node; 498 var actionNode = ChromeVoxState.instance.currentRange_.start.node;
499 if (actionNode.role == RoleType.inlineTextBox) 499 if (actionNode.role == RoleType.INLINE_TEXT_BOX)
500 actionNode = actionNode.parent; 500 actionNode = actionNode.parent;
501 actionNode.showContextMenu(); 501 actionNode.showContextMenu();
502 return false; 502 return false;
503 } 503 }
504 break; 504 break;
505 case 'toggleKeyboardHelp': 505 case 'toggleKeyboardHelp':
506 (new PanelCommand(PanelCommandType.OPEN_MENUS)).send(); 506 (new PanelCommand(PanelCommandType.OPEN_MENUS)).send();
507 return false; 507 return false;
508 case 'showHeadingsList': 508 case 'showHeadingsList':
509 (new PanelCommand(PanelCommandType.OPEN_MENUS, 'role_heading')).send(); 509 (new PanelCommand(PanelCommandType.OPEN_MENUS, 'role_heading')).send();
(...skipping 10 matching lines...) Expand all
520 case 'showTablesList': 520 case 'showTablesList':
521 (new PanelCommand(PanelCommandType.OPEN_MENUS, 'table_strategy')).send(); 521 (new PanelCommand(PanelCommandType.OPEN_MENUS, 'table_strategy')).send();
522 return false; 522 return false;
523 case 'toggleSearchWidget': 523 case 'toggleSearchWidget':
524 (new PanelCommand(PanelCommandType.SEARCH)).send(); 524 (new PanelCommand(PanelCommandType.SEARCH)).send();
525 return false; 525 return false;
526 case 'readCurrentTitle': 526 case 'readCurrentTitle':
527 var target = ChromeVoxState.instance.currentRange_.start.node; 527 var target = ChromeVoxState.instance.currentRange_.start.node;
528 var output = new Output(); 528 var output = new Output();
529 529
530 if (target.root.role == RoleType.rootWebArea) { 530 if (target.root.role == RoleType.ROOT_WEB_AREA) {
531 // Web. 531 // Web.
532 target = target.root; 532 target = target.root;
533 output.withString(target.name || target.docUrl); 533 output.withString(target.name || target.docUrl);
534 } else { 534 } else {
535 // Views. 535 // Views.
536 while (target.role != RoleType.window) target = target.parent; 536 while (target.role != RoleType.WINDOW) target = target.parent;
537 if (target) 537 if (target)
538 output.withString(target.name || ''); 538 output.withString(target.name || '');
539 } 539 }
540 output.go(); 540 output.go();
541 return false; 541 return false;
542 case 'readCurrentURL': 542 case 'readCurrentURL':
543 var output = new Output(); 543 var output = new Output();
544 var target = ChromeVoxState.instance.currentRange_.start.node.root; 544 var target = ChromeVoxState.instance.currentRange_.start.node.root;
545 output.withString(target.docUrl || '').go(); 545 output.withString(target.docUrl || '').go();
546 return false; 546 return false;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 dir = Dir.FORWARD; 611 dir = Dir.FORWARD;
612 var tableOpts = {col: true, dir: dir}; 612 var tableOpts = {col: true, dir: dir};
613 pred = AutomationPredicate.makeTableCellPredicate( 613 pred = AutomationPredicate.makeTableCellPredicate(
614 current.start.node, tableOpts); 614 current.start.node, tableOpts);
615 predErrorMsg = 'no_cell_right'; 615 predErrorMsg = 'no_cell_right';
616 rootPred = AutomationPredicate.row; 616 rootPred = AutomationPredicate.row;
617 break; 617 break;
618 case 'goToRowFirstCell': 618 case 'goToRowFirstCell':
619 case 'goToRowLastCell': 619 case 'goToRowLastCell':
620 var node = current.start.node; 620 var node = current.start.node;
621 while (node && node.role != RoleType.row) 621 while (node && node.role != RoleType.ROW)
622 node = node.parent; 622 node = node.parent;
623 if (!node) 623 if (!node)
624 break; 624 break;
625 var end = AutomationUtil.findNodePost(node, 625 var end = AutomationUtil.findNodePost(node,
626 command == 'goToRowLastCell' ? Dir.BACKWARD : Dir.FORWARD, 626 command == 'goToRowLastCell' ? Dir.BACKWARD : Dir.FORWARD,
627 AutomationPredicate.leaf); 627 AutomationPredicate.leaf);
628 if (end) 628 if (end)
629 current = cursors.Range.fromNode(end); 629 current = cursors.Range.fromNode(end);
630 break; 630 break;
631 case 'goToColFirstCell': 631 case 'goToColFirstCell':
632 dir = Dir.FORWARD; 632 dir = Dir.FORWARD;
633 var node = current.start.node; 633 var node = current.start.node;
634 while (node && node.role != RoleType.table) 634 while (node && node.role != RoleType.TABLE)
635 node = node.parent; 635 node = node.parent;
636 if (!node || !node.firstChild) 636 if (!node || !node.firstChild)
637 return false; 637 return false;
638 var tableOpts = {col: true, dir: dir, end: true}; 638 var tableOpts = {col: true, dir: dir, end: true};
639 pred = AutomationPredicate.makeTableCellPredicate( 639 pred = AutomationPredicate.makeTableCellPredicate(
640 current.start.node, tableOpts); 640 current.start.node, tableOpts);
641 current = cursors.Range.fromNode(node.firstChild); 641 current = cursors.Range.fromNode(node.firstChild);
642 // Should not be outputted. 642 // Should not be outputted.
643 predErrorMsg = 'no_cell_above'; 643 predErrorMsg = 'no_cell_above';
644 rootPred = AutomationPredicate.table; 644 rootPred = AutomationPredicate.table;
645 break; 645 break;
646 case 'goToColLastCell': 646 case 'goToColLastCell':
647 dir = Dir.BACKWARD; 647 dir = Dir.BACKWARD;
648 var node = current.start.node; 648 var node = current.start.node;
649 while (node && node.role != RoleType.table) 649 while (node && node.role != RoleType.TABLE)
650 node = node.parent; 650 node = node.parent;
651 if (!node || !node.lastChild) 651 if (!node || !node.lastChild)
652 return false; 652 return false;
653 var tableOpts = {col: true, dir: dir, end: true}; 653 var tableOpts = {col: true, dir: dir, end: true};
654 pred = AutomationPredicate.makeTableCellPredicate( 654 pred = AutomationPredicate.makeTableCellPredicate(
655 current.start.node, tableOpts); 655 current.start.node, tableOpts);
656 current = cursors.Range.fromNode(node.lastChild); 656 current = cursors.Range.fromNode(node.lastChild);
657 // Should not be outputted. 657 // Should not be outputted.
658 predErrorMsg = 'no_cell_below'; 658 predErrorMsg = 'no_cell_below';
659 rootPred = AutomationPredicate.table; 659 rootPred = AutomationPredicate.table;
660 break; 660 break;
661 case 'goToFirstCell': 661 case 'goToFirstCell':
662 case 'goToLastCell': 662 case 'goToLastCell':
663 node = current.start.node; 663 node = current.start.node;
664 while (node && node.role != RoleType.table) 664 while (node && node.role != RoleType.TABLE)
665 node = node.parent; 665 node = node.parent;
666 if (!node) 666 if (!node)
667 break; 667 break;
668 var end = AutomationUtil.findNodePost(node, 668 var end = AutomationUtil.findNodePost(node,
669 command == 'goToLastCell' ? Dir.BACKWARD : Dir.FORWARD, 669 command == 'goToLastCell' ? Dir.BACKWARD : Dir.FORWARD,
670 AutomationPredicate.leaf); 670 AutomationPredicate.leaf);
671 if (end) 671 if (end)
672 current = cursors.Range.fromNode(end); 672 current = cursors.Range.fromNode(end);
673 break; 673 break;
674 default: 674 default:
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 break; 771 break;
772 } 772 }
773 if (announcement) { 773 if (announcement) {
774 cvox.ChromeVox.tts.speak( 774 cvox.ChromeVox.tts.speak(
775 announcement, cvox.QueueMode.FLUSH, 775 announcement, cvox.QueueMode.FLUSH,
776 cvox.AbstractTts.PERSONALITY_ANNOTATION); 776 cvox.AbstractTts.PERSONALITY_ANNOTATION);
777 } 777 }
778 }; 778 };
779 779
780 }); // goog.scope 780 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698