+2011-02-17 Ojan Vafai <ojan@chromium.org>
+
+ Reviewed by Adam Barth.
+
+ use actual browser focus in the code review tool
+ https://bugs.webkit.org/show_bug.cgi?id=54726
+
+ This makes keyboard handling play better with focusable element
+ (i.e. links/textareas/buttons). Also, in theory, this makes
+ the review tool more amenable to screen readers (I think).
+
+ * PrettyPatch/PrettyPatch.rb:
+ * code-review.js:
+
2011-02-17 Ojan Vafai <ojan@chromium.org>
Reviewed by Antonio Gomes.
updateToolbarAnchorState();
loadDiffState();
-
- // Ensure the body has focus so that it receives key events.
- document.body.focus();
});
function handleReviewFormLoad() {
}
function focusOn(node) {
- // FIXME: We should probably give propery browser focus here.
- $('.focused').removeClass('focused');
if (node.length == 0)
return;
- $(document).scrollTop(node.addClass('focused').position().top - window.innerHeight / 2);
+
+ // Give a tabindex so the element can receive actual browser focus.
+ // -1 makes the element focusable without actually putting in in the tab order.
+ node.attr('tabindex', -1);
+ node.focus();
+ $(document).scrollTop(node.position().top - window.innerHeight / 2);
}
function focusNext(filter, direction) {
- var focusable_nodes = $('.frozenComment,.previousComment,.DiffBlock,.overallComments').filter(function() {
+ var focusable_nodes = $('a,.frozenComment,.previousComment,.DiffBlock,.overallComments').filter(function() {
return !$(this).hasClass('DiffBlock') || $('.add,.remove', this).size();
});
var is_backward = direction == DIRECTION.BACKWARD;
- var index = focusable_nodes.index($('.focused'));
+ var index = focusable_nodes.index($(document.activeElement));
if (index == -1 && is_backward)
index = focusable_nodes.length;
}
function handleEnterKeyPress() {
- var focused = $('.focused');
- if (!focused.size())
- return false;
+ if (document.activeElement.nodeName == 'BODY')
+ return;
+
+ var focused = $(document.activeElement);
if (focused.hasClass('frozenComment')) {
unfreezeComment(focused);