OLD | NEW |
1 /* Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2014 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 Caret browsing content script, runs in each frame. | 6 * @fileoverview Caret browsing content script, runs in each frame. |
7 * | 7 * |
8 * The behavior is based on Mozilla's spec whenever possible: | 8 * The behavior is based on Mozilla's spec whenever possible: |
9 * http://www.mozilla.org/access/keyboard/proposal | 9 * http://www.mozilla.org/access/keyboard/proposal |
10 * | 10 * |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 node = node.parentNode; | 353 node = node.parentNode; |
354 } | 354 } |
355 | 355 |
356 return false; | 356 return false; |
357 }; | 357 }; |
358 | 358 |
359 /** | 359 /** |
360 * Set focus to the first focusable node in the given list. | 360 * Set focus to the first focusable node in the given list. |
361 * select the text, otherwise it doesn't appear focused to the user. | 361 * select the text, otherwise it doesn't appear focused to the user. |
362 * Every other control behaves normally if you just call focus() on it. | 362 * Every other control behaves normally if you just call focus() on it. |
363 * @param {Array.<Node>} nodeList An array of nodes to focus. | 363 * @param {Array<Node>} nodeList An array of nodes to focus. |
364 * @return {boolean} True if the node was focused. | 364 * @return {boolean} True if the node was focused. |
365 */ | 365 */ |
366 CaretBrowsing.setFocusToFirstFocusable = function(nodeList) { | 366 CaretBrowsing.setFocusToFirstFocusable = function(nodeList) { |
367 for (var i = 0; i < nodeList.length; i++) { | 367 for (var i = 0; i < nodeList.length; i++) { |
368 if (CaretBrowsing.setFocusToNode(nodeList[i])) { | 368 if (CaretBrowsing.setFocusToNode(nodeList[i])) { |
369 return true; | 369 return true; |
370 } | 370 } |
371 } | 371 } |
372 return false; | 372 return false; |
373 }; | 373 }; |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 return evt.altKey; | 761 return evt.altKey; |
762 } else { | 762 } else { |
763 return evt.ctrlKey; | 763 return evt.ctrlKey; |
764 } | 764 } |
765 }; | 765 }; |
766 | 766 |
767 /** | 767 /** |
768 * Moves the cursor forwards to the next valid position. | 768 * Moves the cursor forwards to the next valid position. |
769 * @param {Cursor} cursor The current cursor location. | 769 * @param {Cursor} cursor The current cursor location. |
770 * On exit, the cursor will be at the next position. | 770 * On exit, the cursor will be at the next position. |
771 * @param {Array.<Node>} nodesCrossed Any HTML nodes crossed between the | 771 * @param {Array<Node>} nodesCrossed Any HTML nodes crossed between the |
772 * initial and final cursor position will be pushed onto this array. | 772 * initial and final cursor position will be pushed onto this array. |
773 * @return {?string} The character reached, or null if the bottom of the | 773 * @return {?string} The character reached, or null if the bottom of the |
774 * document has been reached. | 774 * document has been reached. |
775 */ | 775 */ |
776 CaretBrowsing.forwards = function(cursor, nodesCrossed) { | 776 CaretBrowsing.forwards = function(cursor, nodesCrossed) { |
777 var previousCursor = cursor.clone(); | 777 var previousCursor = cursor.clone(); |
778 var result = TraverseUtil.forwardsChar(cursor, nodesCrossed); | 778 var result = TraverseUtil.forwardsChar(cursor, nodesCrossed); |
779 | 779 |
780 // Work around the fact that TraverseUtil.forwardsChar returns once per | 780 // Work around the fact that TraverseUtil.forwardsChar returns once per |
781 // char in a block of text, rather than once per possible selection | 781 // char in a block of text, rather than once per possible selection |
782 // position in a block of text. | 782 // position in a block of text. |
783 if (result && cursor.node != previousCursor.node && cursor.index > 0) { | 783 if (result && cursor.node != previousCursor.node && cursor.index > 0) { |
784 cursor.index = 0; | 784 cursor.index = 0; |
785 } | 785 } |
786 | 786 |
787 return result; | 787 return result; |
788 }; | 788 }; |
789 | 789 |
790 /** | 790 /** |
791 * Moves the cursor backwards to the previous valid position. | 791 * Moves the cursor backwards to the previous valid position. |
792 * @param {Cursor} cursor The current cursor location. | 792 * @param {Cursor} cursor The current cursor location. |
793 * On exit, the cursor will be at the previous position. | 793 * On exit, the cursor will be at the previous position. |
794 * @param {Array.<Node>} nodesCrossed Any HTML nodes crossed between the | 794 * @param {Array<Node>} nodesCrossed Any HTML nodes crossed between the |
795 * initial and final cursor position will be pushed onto this array. | 795 * initial and final cursor position will be pushed onto this array. |
796 * @return {?string} The character reached, or null if the top of the | 796 * @return {?string} The character reached, or null if the top of the |
797 * document has been reached. | 797 * document has been reached. |
798 */ | 798 */ |
799 CaretBrowsing.backwards = function(cursor, nodesCrossed) { | 799 CaretBrowsing.backwards = function(cursor, nodesCrossed) { |
800 var previousCursor = cursor.clone(); | 800 var previousCursor = cursor.clone(); |
801 var result = TraverseUtil.backwardsChar(cursor, nodesCrossed); | 801 var result = TraverseUtil.backwardsChar(cursor, nodesCrossed); |
802 | 802 |
803 // Work around the fact that TraverseUtil.backwardsChar returns once per | 803 // Work around the fact that TraverseUtil.backwardsChar returns once per |
804 // char in a block of text, rather than once per possible selection | 804 // char in a block of text, rather than once per possible selection |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 CaretBrowsing.updateIsCaretVisible(); | 1415 CaretBrowsing.updateIsCaretVisible(); |
1416 } | 1416 } |
1417 | 1417 |
1418 chrome.storage.onChanged.addListener(function() { | 1418 chrome.storage.onChanged.addListener(function() { |
1419 CaretBrowsing.onPrefsUpdated(); | 1419 CaretBrowsing.onPrefsUpdated(); |
1420 }); | 1420 }); |
1421 CaretBrowsing.onPrefsUpdated(); | 1421 CaretBrowsing.onPrefsUpdated(); |
1422 } | 1422 } |
1423 | 1423 |
1424 }, 0); | 1424 }, 0); |
OLD | NEW |