Chromium Code Reviews| Index: chrome/browser/resources/options/options_page.js |
| diff --git a/chrome/browser/resources/options/options_page.js b/chrome/browser/resources/options/options_page.js |
| index 057e86dd637e376a886a1c7022df619022727046..94c2cf34ad1e92d6e02a93a4487b8072b29076bf 100644 |
| --- a/chrome/browser/resources/options/options_page.js |
| +++ b/chrome/browser/resources/options/options_page.js |
| @@ -319,14 +319,23 @@ cr.define('options', function() { |
| var containerId = 'subpage-sheet-container-' + level; |
| $(containerId).onclick = this.subPageClosingClickHandler_(level); |
| } |
| - // Hook up the close buttons. |
| + |
| var self = this; |
| + // Close subpages if the user clicks on the html body. Listen in the |
| + // capturing phase so that we can stop the click from doing anything. |
| + document.body.addEventListener('click', this.bodyMouseEventHandler_(), |
|
arv (Not doing code reviews)
2011/01/18 19:06:07
Use bind instead?
Evan Stade
2011/01/18 22:37:09
Done.
|
| + true); |
| + // We also need to cancel mousedowns on non-subpage content. |
| + document.body.addEventListener('mousedown', this.bodyMouseEventHandler_(), |
| + true); |
| + |
| + // Hook up the close buttons. |
| subpageCloseButtons = document.querySelectorAll('.close-subpage'); |
| for (var i = 0; i < subpageCloseButtons.length; i++) { |
| subpageCloseButtons[i].onclick = function() { |
| self.closeTopSubPage(); |
| }; |
| - } |
| + }; |
| // Close the top overlay or sub-page on esc. |
| document.addEventListener('keydown', function(e) { |
| @@ -349,11 +358,47 @@ cr.define('options', function() { |
| OptionsPage.subPageClosingClickHandler_ = function(level) { |
| var self = this; |
| return function(event) { |
| - // Clicks on the visible part of the parent page should close the overlay, |
| + // Clicks on the narrow strip between the left of the subpage sheet and |
| + // that shows part of the parent page should close the overlay, but |
| // not fall through to the parent page. |
| if (!$('subpage-sheet-' + level).contains(event.target)) |
| self.closeSubPagesToLevel(level - 1); |
| event.stopPropagation(); |
| + event.preventDefault(); |
| + }; |
| + }; |
| + |
| + /** |
| + * Returns a function to handle mouse events (mousedown or click) on the html |
| + * body by closing subpages and/or stopping event propagation. |
| + * @return {function} a function to handle mouse events while a subpage is |
|
arv (Not doing code reviews)
2011/01/18 19:06:07
{Function}
only value types are lower case
Evan Stade
2011/01/18 22:37:09
Done.
|
| + * showing. |
| + * @private |
| + */ |
| + OptionsPage.bodyMouseEventHandler_ = function() { |
| + var self = this; |
| + return function(event) { |
| + // Do nothing if a subpage isn't showing. |
| + var topPage = self.getTopmostVisiblePage(); |
| + if (!(topPage && topPage.parentPage)) |
| + return; |
| + |
| + // If the click was within a subpage, do nothing. |
| + for (var level = 1; level <= 2; level++) { |
| + if ($('subpage-sheet-container-' + level).contains(event.target)) |
| + return; |
| + } |
| + |
| + // Close all subpages on click. |
| + if (event.type == 'click') |
| + self.closeSubPagesToLevel(0); |
| + |
| + // Events should not fall through to the main view, |
| + // but they can fall through for the sidebar. |
| + if ($('mainview-content').contains(event.target)) { |
| + event.stopPropagation(); |
| + event.preventDefault(); |
| + } |
| }; |
| }; |