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

Unified Diff: go-back-with-backspace/is_editable.js

Issue 2126003003: Go Back With Backspace extension (Closed) Base URL: https://chromium.googlesource.com/chromium/extensions-by-google.git@master
Patch Set: Fix quotation marks Created 4 years, 5 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 | « go-back-with-backspace/icon128.png ('k') | 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/is_editable.js
diff --git a/go-back-with-backspace/is_editable.js b/go-back-with-backspace/is_editable.js
new file mode 100644
index 0000000000000000000000000000000000000000..d2c6e433e89482f1c76488f536abfabc0183fb86
--- /dev/null
+++ b/go-back-with-backspace/is_editable.js
@@ -0,0 +1,32 @@
+// Determine whether focus is in an editable text field.
+function isEditable(path) {
+ var target = path[0];
+
+ // Elements may be explicitly marked as editable.
+ if (target.isContentEditable)
+ return true;
+
+ // Several types of input fields are editable, but not all (e.g., checkboxes).
+ var nodeName = target.nodeName;
+ var nodeType = target.type;
+ if (nodeName === 'TEXTAREA' ||
+ (nodeName === 'INPUT' && (nodeType === 'text' ||
+ nodeType === 'email' ||
+ nodeType === 'password' ||
+ nodeType === 'search'))) {
+ return true;
+ }
+
+ // Certain CSS styles, on elements or their parents, also indicate editable
+ // fields.
+ var pathLength = path.length;
+ for (var i = 0; i < pathLength; ++i) {
+ target = path[i];
+ if (target.nodeType == 1) { // Only Elements have computed styles.
+ var userModify = getComputedStyle(path[i])['-webkit-user-select'];
+ if (userModify == 'read-write' || userModify == 'write-only')
+ return true;
+ }
+ }
+ return false;
+}
« no previous file with comments | « go-back-with-backspace/icon128.png ('k') | go-back-with-backspace/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698