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

Side by Side Diff: go-back-with-backspace/content_script.js

Issue 2407473002: Look at e.path where available (M55+) (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | go-back-with-backspace/manifest.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Listen for shift-backspace or unmodified backspace and navigate if not in 1 // Listen for shift-backspace or unmodified backspace and navigate if not in
2 // an editable field. We capture the event at the Window to let any handlers 2 // an editable field. We capture the event at the Window to let any handlers
3 // or listeners registered on the Document have a chance to handle it first. 3 // or listeners registered on the Document have a chance to handle it first.
4 window.addEventListener('keydown', function(e) { 4 window.addEventListener('keydown', function(e) {
5 // Listening on the Window means the event has no path (see 5 // Before Chrome 55, listening on the Window means the event has no path,
6 // http://crbug.com/645527), so we'll have to look at the focused (active) 6 // instead pointing to the Window (see http://crbug.com/645527). In that
7 // element. This means it will not work properly with shadow DOM. 7 // case, we have to look at the focused (active) element.
8 // TODO: Fix behavior with shadow DOM when the above bug is resolved. 8 // TODO: Switch entirely to e.path once Chrome 55 is launched.
9 if (e.key === 'Backspace' && 9 if (e.key === 'Backspace' &&
10 !e.defaultPrevented && 10 !e.defaultPrevented &&
11 !e.altKey && 11 !e.altKey &&
12 !e.ctrlKey && 12 !e.ctrlKey &&
13 !e.metaKey && 13 !e.metaKey) {
14 !isEditable(document.activeElement)) { 14 var target = e.path[0];
15 e.shiftKey ? window.history.forward(): window.history.back(); 15 if (target === window)
16 e.preventDefault(); 16 target = document.activeElement;
17 if (!isEditable(target)) {
18 e.shiftKey ? window.history.forward(): window.history.back();
19 e.preventDefault();
20 }
17 } 21 }
18 }); 22 });
OLDNEW
« no previous file with comments | « no previous file | go-back-with-backspace/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698