Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 // Helpers | 2 // Helpers |
| 3 | 3 |
| 4 function $(id) { | 4 function $(id) { |
| 5 return document.getElementById(id); | 5 return document.getElementById(id); |
| 6 } | 6 } |
| 7 | 7 |
| 8 // TODO(arv): Remove these when classList is available in HTML5. | 8 // TODO(arv): Remove these when classList is available in HTML5. |
| 9 // https://bugs.webkit.org/show_bug.cgi?id=20709 | 9 // https://bugs.webkit.org/show_bug.cgi?id=20709 |
| 10 function hasClass(el, name) { | 10 function hasClass(el, name) { |
| (...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 891 this.button.onkeydown = bind(this.handleKeyDown, this); | 891 this.button.onkeydown = bind(this.handleKeyDown, this); |
| 892 this.boundHideMenu_ = bind(this.hide, this); | 892 this.boundHideMenu_ = bind(this.hide, this); |
| 893 this.boundMaybeHide_ = bind(this.maybeHide_, this); | 893 this.boundMaybeHide_ = bind(this.maybeHide_, this); |
| 894 this.menu.onmouseover = bind(this.handleMouseOver, this); | 894 this.menu.onmouseover = bind(this.handleMouseOver, this); |
| 895 this.menu.onmouseout = bind(this.handleMouseOut, this); | 895 this.menu.onmouseout = bind(this.handleMouseOut, this); |
| 896 this.menu.onmouseup = bind(this.handleMouseUp, this); | 896 this.menu.onmouseup = bind(this.handleMouseUp, this); |
| 897 } | 897 } |
| 898 | 898 |
| 899 OptionMenu.prototype = { | 899 OptionMenu.prototype = { |
| 900 show: function() { | 900 show: function() { |
| 901 windowTooltip.hide(); | |
| 902 | |
| 903 this.menu.style.display = 'block'; | 901 this.menu.style.display = 'block'; |
| 904 this.button.focus(); | 902 this.button.focus(); |
| 905 | 903 |
| 906 // Listen to document and window events so that we hide the menu when the | 904 // Listen to document and window events so that we hide the menu when the |
| 907 // user clicks outside the menu or tabs away or the whole window is blurred. | 905 // user clicks outside the menu or tabs away or the whole window is blurred. |
| 908 document.addEventListener('focus', this.boundMaybeHide_, true); | 906 document.addEventListener('focus', this.boundMaybeHide_, true); |
| 909 document.addEventListener('mousedown', this.boundMaybeHide_, true); | 907 document.addEventListener('mousedown', this.boundMaybeHide_, true); |
| 910 }, | 908 }, |
| 911 | 909 |
| 912 hide: function() { | 910 hide: function() { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1130 } | 1128 } |
| 1131 | 1129 |
| 1132 WindowTooltip.trackMouseMove_ = function(e) { | 1130 WindowTooltip.trackMouseMove_ = function(e) { |
| 1133 WindowTooltip.clientX = e.clientX; | 1131 WindowTooltip.clientX = e.clientX; |
| 1134 WindowTooltip.clientY = e.clientY; | 1132 WindowTooltip.clientY = e.clientY; |
| 1135 }; | 1133 }; |
| 1136 | 1134 |
| 1137 WindowTooltip.prototype = { | 1135 WindowTooltip.prototype = { |
| 1138 timer: 0, | 1136 timer: 0, |
| 1139 handleMouseOver: function(e, linkEl, tabs) { | 1137 handleMouseOver: function(e, linkEl, tabs) { |
| 1140 document.addEventListener('mousemove', WindowTooltip.trackMouseMove_); | 1138 this.linkEl_ = linkEl; |
| 1139 if (e.type == 'mouseover') { | |
| 1140 this.linkEl_.addEventListener('mousemove', WindowTooltip.trackMouseMove_); | |
| 1141 this.linkEl_.addEventListener('mouseout', this.boundHandleMouseOut_); | |
| 1142 } else { // focus | |
|
Glen Murphy
2009/08/06 00:05:27
two spaces before //, I think
arv (Not doing code reviews)
2009/08/06 00:18:50
I've never seen that in any style guide. There is
| |
| 1143 this.linkEl_.addEventListener('blur', this.boundHide_); | |
| 1144 } | |
| 1141 this.timer = window.setTimeout(bind(this.show, this, e.type, linkEl, tabs), | 1145 this.timer = window.setTimeout(bind(this.show, this, e.type, linkEl, tabs), |
| 1142 300); | 1146 300); |
| 1143 }, | 1147 }, |
| 1144 show: function(type, linkEl, tabs) { | 1148 show: function(type, linkEl, tabs) { |
| 1145 document.removeEventListener('mousemove', WindowTooltip.trackMouseMove_); | 1149 this.linkEl_.removeEventListener('mousemove', |
| 1150 WindowTooltip.trackMouseMove_); | |
| 1146 clearTimeout(this.timer); | 1151 clearTimeout(this.timer); |
| 1147 | 1152 |
| 1148 processData('#window-tooltip', tabs); | 1153 processData('#window-tooltip', tabs); |
| 1149 var rect = linkEl.getBoundingClientRect(); | 1154 var rect = linkEl.getBoundingClientRect(); |
| 1150 var bodyRect = document.body.getBoundingClientRect() | 1155 var bodyRect = document.body.getBoundingClientRect() |
| 1151 var rtl = document.documentElement.dir == 'rtl'; | 1156 var rtl = document.documentElement.dir == 'rtl'; |
| 1152 | 1157 |
| 1153 this.tooltipEl.style.display = 'block'; | 1158 this.tooltipEl.style.display = 'block'; |
| 1154 | 1159 |
| 1155 // When focused show below, like a drop down menu. | 1160 // When focused show below, like a drop down menu. |
| 1156 if (type == 'focus') { | 1161 if (type == 'focus') { |
| 1157 this.tooltipEl.style.left = (rtl ? | 1162 this.tooltipEl.style.left = (rtl ? |
| 1158 rect.left + bodyRect.left + rect.width - this.tooltipEl.offsetWidth : | 1163 rect.left + bodyRect.left + rect.width - this.tooltipEl.offsetWidth : |
| 1159 rect.left + bodyRect.left) + 'px'; | 1164 rect.left + bodyRect.left) + 'px'; |
| 1160 this.tooltipEl.style.top = rect.top + bodyRect.top + rect.height + 'px'; | 1165 this.tooltipEl.style.top = rect.top + bodyRect.top + rect.height + 'px'; |
| 1161 } else { | 1166 } else { |
| 1162 this.tooltipEl.style.left = bodyRect.left + (rtl ? | 1167 this.tooltipEl.style.left = bodyRect.left + (rtl ? |
| 1163 WindowTooltip.clientX - this.tooltipEl.offsetWidth : | 1168 WindowTooltip.clientX - this.tooltipEl.offsetWidth : |
| 1164 WindowTooltip.clientX) + 'px'; | 1169 WindowTooltip.clientX) + 'px'; |
| 1165 // Offset like a tooltip | 1170 // Offset like a tooltip |
| 1166 this.tooltipEl.style.top = 20 + WindowTooltip.clientY + bodyRect.top + | 1171 this.tooltipEl.style.top = 20 + WindowTooltip.clientY + bodyRect.top + |
| 1167 'px'; | 1172 'px'; |
| 1168 } | 1173 } |
| 1169 | |
| 1170 if (type == 'focus') { | |
| 1171 linkEl.onblur = this.boundHide_; | |
| 1172 } else { // mouseover | |
| 1173 linkEl.onmouseout = this.boundHandleMouseOut_; | |
| 1174 } | |
| 1175 }, | 1174 }, |
| 1176 handleMouseOut: function(e) { | 1175 handleMouseOut: function(e) { |
| 1177 // Don't hide when move to another item in the link. | 1176 // Don't hide when move to another item in the link. |
| 1178 var f = function(el) { | 1177 var f = function(el) { |
| 1179 return el.tabItems !== undefined; | 1178 return el.tabItems !== undefined; |
| 1180 }; | 1179 }; |
| 1181 var el = findAncestor(e.target, f); | 1180 var el = findAncestor(e.target, f); |
| 1182 var relatedEl = findAncestor(e.relatedTarget, f); | 1181 var relatedEl = findAncestor(e.relatedTarget, f); |
| 1183 if (el && el != relatedEl) { | 1182 if (el && el != relatedEl) { |
| 1184 this.hide(); | 1183 this.hide(); |
| 1185 } | 1184 } |
| 1186 }, | 1185 }, |
| 1187 hide: function() { | 1186 hide: function() { |
| 1188 window.clearTimeout(this.timer); | 1187 window.clearTimeout(this.timer); |
| 1189 document.removeEventListener('mousemove', WindowTooltip.trackMouseMove_); | 1188 this.linkEl_.removeEventListener('mousemove', |
| 1189 WindowTooltip.trackMouseMove_); | |
| 1190 this.linkEl_.removeEventListener('mouseout', this.boundHandleMouseOut_); | |
| 1191 this.linkEl_.removeEventListener('blur', this.boundHide_); | |
| 1192 this.linkEl_ = null; | |
| 1193 | |
| 1190 this.tooltipEl.style.display = 'none'; | 1194 this.tooltipEl.style.display = 'none'; |
| 1191 } | 1195 } |
| 1192 }; | 1196 }; |
| 1193 | 1197 |
| 1194 var windowTooltip = new WindowTooltip($('window-tooltip')); | 1198 var windowTooltip = new WindowTooltip($('window-tooltip')); |
| 1195 | 1199 |
| 1196 function getCheckboxHandler(section) { | 1200 function getCheckboxHandler(section) { |
| 1197 return function(e) { | 1201 return function(e) { |
| 1198 if (e.type == 'keydown') { | 1202 if (e.type == 'keydown') { |
| 1199 if (e.keyIdentifier == 'Enter') { | 1203 if (e.keyIdentifier == 'Enter') { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1420 el.addEventListener('dragover', bind(this.handleDragOver, this)); | 1424 el.addEventListener('dragover', bind(this.handleDragOver, this)); |
| 1421 el.addEventListener('dragleave', bind(this.handleDragLeave, this)); | 1425 el.addEventListener('dragleave', bind(this.handleDragLeave, this)); |
| 1422 el.addEventListener('drop', bind(this.handleDrop, this)); | 1426 el.addEventListener('drop', bind(this.handleDrop, this)); |
| 1423 el.addEventListener('dragend', bind(this.handleDragEnd, this)); | 1427 el.addEventListener('dragend', bind(this.handleDragEnd, this)); |
| 1424 el.addEventListener('drag', bind(this.handleDrag, this)); | 1428 el.addEventListener('drag', bind(this.handleDrag, this)); |
| 1425 el.addEventListener('mousedown', bind(this.handleMouseDown, this)); | 1429 el.addEventListener('mousedown', bind(this.handleMouseDown, this)); |
| 1426 } | 1430 } |
| 1427 }; | 1431 }; |
| 1428 | 1432 |
| 1429 dnd.init(); | 1433 dnd.init(); |
| OLD | NEW |