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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | go-back-with-backspace/manifest.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go-back-with-backspace/content_script.js
diff --git a/go-back-with-backspace/content_script.js b/go-back-with-backspace/content_script.js
index ea6cecb9faed2c4f69ea92af858ad7961f53eac5..1e41c87bd97bca582a3f344b68ee7f440877f841 100644
--- a/go-back-with-backspace/content_script.js
+++ b/go-back-with-backspace/content_script.js
@@ -2,17 +2,21 @@
// an editable field. We capture the event at the Window to let any handlers
// or listeners registered on the Document have a chance to handle it first.
window.addEventListener('keydown', function(e) {
- // Listening on the Window means the event has no path (see
- // http://crbug.com/645527), so we'll have to look at the focused (active)
- // element. This means it will not work properly with shadow DOM.
- // TODO: Fix behavior with shadow DOM when the above bug is resolved.
+ // Before Chrome 55, listening on the Window means the event has no path,
+ // instead pointing to the Window (see http://crbug.com/645527). In that
+ // case, we have to look at the focused (active) element.
+ // TODO: Switch entirely to e.path once Chrome 55 is launched.
if (e.key === 'Backspace' &&
!e.defaultPrevented &&
!e.altKey &&
!e.ctrlKey &&
- !e.metaKey &&
- !isEditable(document.activeElement)) {
- e.shiftKey ? window.history.forward(): window.history.back();
- e.preventDefault();
+ !e.metaKey) {
+ var target = e.path[0];
+ if (target === window)
+ target = document.activeElement;
+ if (!isEditable(target)) {
+ e.shiftKey ? window.history.forward(): window.history.back();
+ e.preventDefault();
+ }
}
});
« 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