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

Unified Diff: chrome/browser/resources/shared/js/cr/ui/list.js

Issue 5685003: DOMUI Prefs: Add a deletable item list type, and use it for startup pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits fixed Created 10 years 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 | « chrome/browser/resources/options/startup_page_manager.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/shared/js/cr/ui/list.js
diff --git a/chrome/browser/resources/shared/js/cr/ui/list.js b/chrome/browser/resources/shared/js/cr/ui/list.js
index 33a984ebf5e87e3565666798f8bf9ca90a2343d6..5db46a3cddcdffceaba626825f0d8a0c685e72f5 100644
--- a/chrome/browser/resources/shared/js/cr/ui/list.js
+++ b/chrome/browser/resources/shared/js/cr/ui/list.js
@@ -303,19 +303,24 @@ cr.define('cr.ui', function() {
if (target == this && !inViewport(target, e))
return;
- while (target && target.parentNode != this) {
- target = target.parentNode;
- }
+ target = this.getListItemAncestor(target);
- if (!target) {
- this.selectionController_.handleMouseDownUp(e, -1);
- } else {
- var cs = getComputedStyle(target);
- var top = target.offsetTop -
- parseFloat(cs.marginTop);
- var index = Math.floor(top / this.getItemHeight_());
- this.selectionController_.handleMouseDownUp(e, index);
+ var index = target ? this.getIndexOfListItem(target) : -1;
+ this.selectionController_.handleMouseDownUp(e, index);
+ },
+
+ /**
+ * Returns the list item element containing the given element, or null if
+ * it doesn't belong to any list item element.
+ * @param {HTMLElement} element The element.
+ * @return {ListItem} The list item containing |element|, or null.
+ */
+ getListItemAncestor: function(element) {
+ var container = element;
+ while (container && container.parentNode != this) {
+ container = container.parentNode;
}
+ return container;
},
/**
@@ -455,6 +460,22 @@ cr.define('cr.ui', function() {
},
/**
+ * Find the index of the given list item element.
+ * @param {ListItem} item The list item to get the index of.
+ * @return {number} The index of the list item, or -1 if not found.
+ */
+ getIndexOfListItem: function(item) {
+ var cs = getComputedStyle(item);
+ var top = item.offsetTop - parseFloat(cs.marginTop);
+ var index = Math.floor(top / this.getItemHeight_());
+ var childIndex = index - this.firstIndex_ + 1;
+ if (childIndex >= 0 && childIndex < this.children.length &&
+ this.children[childIndex] == item)
+ return index;
+ return -1;
+ },
+
+ /**
* Creates a new list item.
* @param {*} value The value to use for the item.
* @return {!ListItem} The newly created list item.
« no previous file with comments | « chrome/browser/resources/options/startup_page_manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698