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

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

Issue 2326083002: Attach to window, add some editable markers, and add a license file. (Closed) Base URL: https://chromium.googlesource.com/chromium/extensions-by-google.git@master
Patch Set: Add TODO with shadow DOM bug Created 4 years, 3 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 | « go-back-with-backspace/content_script.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Determine whether focus is in an editable text field. 1 // Determine whether focus is in an editable text field.
2 function isEditable(path) { 2 function isEditable(target) {
3 var target = path[0];
4
5 // Elements may be explicitly marked as editable. 3 // Elements may be explicitly marked as editable.
6 if (target.isContentEditable) 4 if (target.isContentEditable)
7 return true; 5 return true;
8 6
7 // Entire documents may be editable.
8 if (target.ownerDocument.designMode.toLowerCase() === 'on')
9 return true;
10
9 // Many types of input fields are editable, but not all (e.g., checkboxes). 11 // Many types of input fields are editable, but not all (e.g., checkboxes).
10 var nodeName = target.nodeName.toUpperCase(); 12 var nodeName = target.nodeName.toUpperCase();
11 var nodeType = target.type || ''; 13 var nodeType = target.type || '';
12 nodeType = nodeType.toLowerCase(); 14 nodeType = nodeType.toLowerCase();
13 if (nodeName === 'TEXTAREA' || 15 if (nodeName === 'TEXTAREA' ||
14 (nodeName === 'INPUT' && (nodeType === 'text' || 16 (nodeName === 'INPUT' && (nodeType === 'text' ||
15 nodeType === 'password' || 17 nodeType === 'password' ||
16 nodeType === 'search' || 18 nodeType === 'search' ||
17 nodeType === 'date' || 19 nodeType === 'date' ||
18 nodeType === 'datetime' || 20 nodeType === 'datetime' ||
19 nodeType === 'datetime-local' || 21 nodeType === 'datetime-local' ||
20 nodeType === 'email' || 22 nodeType === 'email' ||
21 nodeType === 'month' || 23 nodeType === 'month' ||
22 nodeType === 'number' || 24 nodeType === 'number' ||
23 nodeType === 'tel' || 25 nodeType === 'tel' ||
24 nodeType === 'time' || 26 nodeType === 'time' ||
25 nodeType === 'url' || 27 nodeType === 'url' ||
26 nodeType === 'week'))) { 28 nodeType === 'week'))) {
27 return true; 29 return true;
28 } 30 }
29 31
30 // Certain CSS styles, on elements or their parents, also indicate editable 32 // Certain CSS styles, on elements or their parents, also indicate editable
31 // fields. 33 // fields.
32 var pathLength = path.length; 34 while (target) {
33 for (var i = 0; i < pathLength; ++i) {
34 target = path[i];
35 if (target.nodeType == 1) { // Only Elements have computed styles. 35 if (target.nodeType == 1) { // Only Elements have computed styles.
36 var userModify = getComputedStyle(path[i])['-webkit-user-select']; 36 var userModify = getComputedStyle(target)['-webkit-user-modify'];
37 if (userModify == 'read-write' || userModify == 'write-only') 37 if (userModify === 'read-write' ||
38 userModify === 'write-only' ||
39 userModify === 'read-write-plaintext-only') {
38 return true; 40 return true;
41 }
39 } 42 }
43 target = target.parentNode || null;
40 } 44 }
41 return false; 45 return false;
42 } 46 }
OLDNEW
« no previous file with comments | « go-back-with-backspace/content_script.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698