OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('options', function() { | 5 cr.define('options', function() { |
6 ///////////////////////////////////////////////////////////////////////////// | 6 ///////////////////////////////////////////////////////////////////////////// |
7 // OptionsPage class: | 7 // OptionsPage class: |
8 | 8 |
9 /** | 9 /** |
10 * Base class for options page. | 10 * Base class for options page. |
11 * @constructor | 11 * @constructor |
12 * @param {string} name Options page name, also defines id of the div element | 12 * @param {string} name Options page name, also defines id of the div element |
13 * containing the options view and the name of options page navigation bar | 13 * containing the options view and the name of options page navigation bar |
14 * item as name+'PageNav'. | 14 * item as name+'PageNav'. |
15 * @param {string} title Options page title, used for navigation bar | 15 * @param {string} title Options page title, used for navigation bar |
16 * @extends {EventTarget} | 16 * @extends {EventTarget} |
17 */ | 17 */ |
18 function OptionsPage(name, title, pageDivName) { | 18 function OptionsPage(name, title, pageDivName) { |
19 this.name = name; | 19 this.name = name; |
20 this.title = title; | 20 this.title = title; |
21 this.pageDivName = pageDivName; | 21 this.pageDivName = pageDivName; |
22 this.pageDiv = $(this.pageDivName); | 22 this.pageDiv = $(this.pageDivName); |
23 this.tab = null; | 23 this.tab = null; |
24 } | 24 } |
25 | 25 |
26 const SUBPAGE_SHEET_COUNT = 2; | 26 const SUBPAGE_SHEET_COUNT = 2; |
27 | 27 |
| 28 const HORIZONTAL_OFFSET = 155; |
| 29 |
28 /** | 30 /** |
29 * Main level option pages. Maps lower-case page names to the respective page | 31 * Main level option pages. Maps lower-case page names to the respective page |
30 * object. | 32 * object. |
31 * @protected | 33 * @protected |
32 */ | 34 */ |
33 OptionsPage.registeredPages = {}; | 35 OptionsPage.registeredPages = {}; |
34 | 36 |
35 /** | 37 /** |
36 * Pages which are meant to behave like modal dialogs. Maps lower-case overlay | 38 * Pages which are meant to behave like modal dialogs. Maps lower-case overlay |
37 * names to the respective overlay object. | 39 * names to the respective overlay object. |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return false; | 268 return false; |
267 | 269 |
268 if ((!rootPage || !rootPage.sticky) && overlay.parentPage) | 270 if ((!rootPage || !rootPage.sticky) && overlay.parentPage) |
269 this.showPageByName(overlay.parentPage.name, false); | 271 this.showPageByName(overlay.parentPage.name, false); |
270 | 272 |
271 if (!overlay.visible) { | 273 if (!overlay.visible) { |
272 overlay.visible = true; | 274 overlay.visible = true; |
273 if (overlay.didShowPage) overlay.didShowPage(); | 275 if (overlay.didShowPage) overlay.didShowPage(); |
274 } | 276 } |
275 | 277 |
276 uber.invokeMethodOnParent('showOverlay'); | |
277 | |
278 return true; | 278 return true; |
279 }; | 279 }; |
280 | 280 |
281 /** | 281 /** |
282 * Returns whether or not an overlay is visible. | 282 * Returns whether or not an overlay is visible. |
283 * @return {boolean} True if an overlay is visible. | 283 * @return {boolean} True if an overlay is visible. |
284 * @private | 284 * @private |
285 */ | 285 */ |
286 OptionsPage.isOverlayVisible_ = function() { | 286 OptionsPage.isOverlayVisible_ = function() { |
287 return this.getVisibleOverlay_() != null; | 287 return this.getVisibleOverlay_() != null; |
(...skipping 15 matching lines...) Expand all Loading... |
303 /** | 303 /** |
304 * Closes the visible overlay. Updates the history state after closing the | 304 * Closes the visible overlay. Updates the history state after closing the |
305 * overlay. | 305 * overlay. |
306 */ | 306 */ |
307 OptionsPage.closeOverlay = function() { | 307 OptionsPage.closeOverlay = function() { |
308 var overlay = this.getVisibleOverlay_(); | 308 var overlay = this.getVisibleOverlay_(); |
309 if (!overlay) | 309 if (!overlay) |
310 return; | 310 return; |
311 | 311 |
312 overlay.visible = false; | 312 overlay.visible = false; |
313 uber.invokeMethodOnParent('hideOverlay'); | |
314 | 313 |
315 if (overlay.didClosePage) overlay.didClosePage(); | 314 if (overlay.didClosePage) overlay.didClosePage(); |
316 this.updateHistoryState_(); | 315 this.updateHistoryState_(); |
317 }; | 316 }; |
318 | 317 |
319 /** | 318 /** |
320 * Hides the visible overlay. Does not affect the history state. | 319 * Hides the visible overlay. Does not affect the history state. |
321 * @private | 320 * @private |
322 */ | 321 */ |
323 OptionsPage.hideOverlay_ = function() { | 322 OptionsPage.hideOverlay_ = function() { |
324 var overlay = this.getVisibleOverlay_(); | 323 var overlay = this.getVisibleOverlay_(); |
325 if (overlay) { | 324 if (overlay) |
326 overlay.visible = false; | 325 overlay.visible = false; |
327 uber.invokeMethodOnParent('hideOverlay'); | |
328 } | |
329 }; | 326 }; |
330 | 327 |
331 /** | 328 /** |
332 * Returns the pages which are currently visible, ordered by nesting level | 329 * Returns the pages which are currently visible, ordered by nesting level |
333 * (ascending). | 330 * (ascending). |
334 * @return {Array.OptionPage} The pages which are currently visible, ordered | 331 * @return {Array.OptionPage} The pages which are currently visible, ordered |
335 * by nesting level (ascending). | 332 * by nesting level (ascending). |
336 */ | 333 */ |
337 OptionsPage.getVisiblePages_ = function() { | 334 OptionsPage.getVisiblePages_ = function() { |
338 var visiblePages = []; | 335 var visiblePages = []; |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 }; | 642 }; |
646 | 643 |
647 // Install handler for key presses. | 644 // Install handler for key presses. |
648 document.addEventListener('keydown', | 645 document.addEventListener('keydown', |
649 this.keyDownEventHandler_.bind(this)); | 646 this.keyDownEventHandler_.bind(this)); |
650 | 647 |
651 document.addEventListener('focus', this.manageFocusChange_.bind(this), | 648 document.addEventListener('focus', this.manageFocusChange_.bind(this), |
652 true); | 649 true); |
653 } | 650 } |
654 | 651 |
655 // Calculate and store the horizontal locations of elements that may be | |
656 // frozen later. | |
657 var sidebarWidth = | |
658 parseInt(window.getComputedStyle($('mainview')).webkitPaddingStart, 10); | |
659 $('page-container').horizontalOffset = sidebarWidth + | |
660 parseInt(window.getComputedStyle( | |
661 $('mainview-content')).webkitPaddingStart, 10); | |
662 for (var level = 1; level <= SUBPAGE_SHEET_COUNT; level++) { | |
663 var containerId = 'subpage-sheet-container-' + level; | |
664 $(containerId).horizontalOffset = sidebarWidth; | |
665 } | |
666 $('subpage-backdrop').horizontalOffset = sidebarWidth; | |
667 // Trigger the resize handler manually to set the initial state. | 652 // Trigger the resize handler manually to set the initial state. |
668 this.handleResize_(null); | 653 this.handleResize_(null); |
669 }; | 654 }; |
670 | 655 |
671 /** | 656 /** |
672 * Does a bounds check for the element on the given x, y client coordinates. | 657 * Does a bounds check for the element on the given x, y client coordinates. |
673 * @param {Element} e The DOM element. | 658 * @param {Element} e The DOM element. |
674 * @param {number} x The client X to check. | 659 * @param {number} x The client X to check. |
675 * @param {number} y The client Y to check. | 660 * @param {number} y The client Y to check. |
676 * @return {boolean} True if the point falls within the element's bounds. | 661 * @return {boolean} True if the point falls within the element's bounds. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 * but should only behave as if they are fixed for vertical scrolling. | 698 * but should only behave as if they are fixed for vertical scrolling. |
714 * @param {Event} e The scroll event. | 699 * @param {Event} e The scroll event. |
715 * @private | 700 * @private |
716 */ | 701 */ |
717 OptionsPage.handleScroll_ = function(e) { | 702 OptionsPage.handleScroll_ = function(e) { |
718 var scrollHorizontalOffset = document.body.scrollLeft; | 703 var scrollHorizontalOffset = document.body.scrollLeft; |
719 // position:fixed doesn't seem to work for horizontal scrolling in RTL mode, | 704 // position:fixed doesn't seem to work for horizontal scrolling in RTL mode, |
720 // so only adjust in LTR mode (where scroll values will be positive). | 705 // so only adjust in LTR mode (where scroll values will be positive). |
721 if (scrollHorizontalOffset >= 0) { | 706 if (scrollHorizontalOffset >= 0) { |
722 var subpageBackdrop = $('subpage-backdrop'); | 707 var subpageBackdrop = $('subpage-backdrop'); |
723 subpageBackdrop.style.left = subpageBackdrop.horizontalOffset - | 708 subpageBackdrop.style.left = HORIZONTAL_OFFSET - |
724 scrollHorizontalOffset + 'px'; | 709 scrollHorizontalOffset + 'px'; |
725 this.updateAllFrozenElementPositions_(); | 710 this.updateAllFrozenElementPositions_(); |
726 } | 711 } |
727 }; | 712 }; |
728 | 713 |
729 /** | 714 /** |
730 * Updates all frozen pages to match the horizontal scroll position. | 715 * Updates all frozen pages to match the horizontal scroll position. |
731 * @private | 716 * @private |
732 */ | 717 */ |
733 OptionsPage.updateAllFrozenElementPositions_ = function() { | 718 OptionsPage.updateAllFrozenElementPositions_ = function() { |
734 var frozenElements = document.querySelectorAll('.frozen'); | 719 var frozenElements = document.querySelectorAll('.frozen'); |
735 for (var i = 0; i < frozenElements.length; i++) { | 720 for (var i = 0; i < frozenElements.length; i++) { |
736 this.updateFrozenElementHorizontalPosition_(frozenElements[i]); | 721 this.updateFrozenElementHorizontalPosition_(frozenElements[i]); |
737 } | 722 } |
738 }; | 723 }; |
739 | 724 |
740 /** | 725 /** |
741 * Updates the given frozen element to match the horizontal scroll position. | 726 * Updates the given frozen element to match the horizontal scroll position. |
742 * @param {HTMLElement} e The frozen element to update | 727 * @param {HTMLElement} e The frozen element to update |
743 * @private | 728 * @private |
744 */ | 729 */ |
745 OptionsPage.updateFrozenElementHorizontalPosition_ = function(e) { | 730 OptionsPage.updateFrozenElementHorizontalPosition_ = function(e) { |
746 if (document.documentElement.dir == 'rtl') | 731 if (document.documentElement.dir == 'rtl') |
747 e.style.right = e.horizontalOffset + 'px'; | 732 e.style.right = HORIZONTAL_OFFSET + 'px'; |
748 else | 733 else |
749 e.style.left = e.horizontalOffset - document.body.scrollLeft + 'px'; | 734 e.style.left = HORIZONTAL_OFFSET - document.body.scrollLeft + 'px'; |
750 }; | 735 }; |
751 | 736 |
752 /** | 737 /** |
753 * Called when the page is resized; adjusts the size of elements that depend | 738 * Called when the page is resized; adjusts the size of elements that depend |
754 * on the veiwport. | 739 * on the veiwport. |
755 * @param {Event} e The resize event. | 740 * @param {Event} e The resize event. |
756 * @private | 741 * @private |
757 */ | 742 */ |
758 OptionsPage.handleResize_ = function(e) { | 743 OptionsPage.handleResize_ = function(e) { |
759 // Set an explicit height equal to the viewport on all the subpage | 744 // Set an explicit height equal to the viewport on all the subpage |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 } else { | 952 } else { |
968 var nestingLevel = this.nestingLevel; | 953 var nestingLevel = this.nestingLevel; |
969 if (nestingLevel > 0) | 954 if (nestingLevel > 0) |
970 container = $('subpage-sheet-container-' + nestingLevel); | 955 container = $('subpage-sheet-container-' + nestingLevel); |
971 } | 956 } |
972 var isSubpage = !this.isOverlay; | 957 var isSubpage = !this.isOverlay; |
973 | 958 |
974 if (!container) | 959 if (!container) |
975 return; | 960 return; |
976 | 961 |
| 962 if (visible) |
| 963 uber.invokeMethodOnParent('beginInterceptingEvents'); |
| 964 |
977 if (container.hidden != visible) { | 965 if (container.hidden != visible) { |
978 if (visible) { | 966 if (visible) { |
979 // If the container is set hidden and then immediately set visible | 967 // If the container is set hidden and then immediately set visible |
980 // again, the fadeCompleted_ callback would cause it to be erroneously | 968 // again, the fadeCompleted_ callback would cause it to be erroneously |
981 // hidden again. Removing the transparent tag avoids that. | 969 // hidden again. Removing the transparent tag avoids that. |
982 container.classList.remove('transparent'); | 970 container.classList.remove('transparent'); |
983 } | 971 } |
984 return; | 972 return; |
985 } | 973 } |
986 | 974 |
(...skipping 21 matching lines...) Expand all Loading... |
1008 container.classList.add('transparent'); | 996 container.classList.add('transparent'); |
1009 } | 997 } |
1010 }, | 998 }, |
1011 | 999 |
1012 /** | 1000 /** |
1013 * Called when a container opacity transition finishes. | 1001 * Called when a container opacity transition finishes. |
1014 * @param {HTMLElement} container The container element. | 1002 * @param {HTMLElement} container The container element. |
1015 * @private | 1003 * @private |
1016 */ | 1004 */ |
1017 fadeCompleted_: function(container) { | 1005 fadeCompleted_: function(container) { |
1018 if (container.classList.contains('transparent')) | 1006 if (container.classList.contains('transparent')) { |
1019 container.hidden = true; | 1007 container.hidden = true; |
| 1008 uber.invokeMethodOnParent('stopInterceptingEvents'); |
| 1009 } |
1020 }, | 1010 }, |
1021 | 1011 |
1022 /** | 1012 /** |
1023 * Focuses the first control on the page. | 1013 * Focuses the first control on the page. |
1024 */ | 1014 */ |
1025 focusFirstElement: function() { | 1015 focusFirstElement: function() { |
1026 // Sets focus on the first interactive element in the page. | 1016 // Sets focus on the first interactive element in the page. |
1027 var focusElement = | 1017 var focusElement = |
1028 this.pageDiv.querySelector('button, input, list, select'); | 1018 this.pageDiv.querySelector('button, input, list, select'); |
1029 if (focusElement) | 1019 if (focusElement) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 canShowPage: function() { | 1066 canShowPage: function() { |
1077 return true; | 1067 return true; |
1078 }, | 1068 }, |
1079 }; | 1069 }; |
1080 | 1070 |
1081 // Export | 1071 // Export |
1082 return { | 1072 return { |
1083 OptionsPage: OptionsPage | 1073 OptionsPage: OptionsPage |
1084 }; | 1074 }; |
1085 }); | 1075 }); |
OLD | NEW |