| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @fileoverview 'settings-device-page' is the settings page for device and | 6 * @fileoverview 'settings-device-page' is the settings page for device and |
| 7 * peripheral settings. | 7 * peripheral settings. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-device-page', | 10 is: 'settings-device-page', |
| 11 | 11 |
| 12 behaviors: [ |
| 13 I18nBehavior, |
| 14 WebUIListenerBehavior, |
| 15 ], |
| 16 |
| 12 properties: { | 17 properties: { |
| 13 /** The current active route. */ | 18 /** The current active route. */ |
| 14 currentRoute: { | 19 currentRoute: { |
| 15 type: Object, | 20 type: Object, |
| 16 notify: true, | 21 notify: true, |
| 22 observers: 'currentRouteChanged_', |
| 17 }, | 23 }, |
| 18 | 24 |
| 19 /** Preferences state. */ | 25 /** Preferences state. */ |
| 20 prefs: { | 26 prefs: { |
| 21 type: Object, | 27 type: Object, |
| 22 notify: true, | 28 notify: true, |
| 23 }, | 29 }, |
| 30 |
| 31 /** @private */ |
| 32 hasMouse_: { |
| 33 type: Boolean, |
| 34 value: false, |
| 35 }, |
| 36 |
| 37 /** @private */ |
| 38 hasTouchpad_: { |
| 39 type: Boolean, |
| 40 value: false, |
| 41 }, |
| 42 }, |
| 43 |
| 44 observers: [ |
| 45 'pointersChanged_(hasMouse_, hasTouchpad_)', |
| 46 ], |
| 47 |
| 48 ready: function() { |
| 49 cr.addWebUIListener('has-mouse-changed', this.set.bind(this, 'hasMouse_')); |
| 50 cr.addWebUIListener( |
| 51 'has-touchpad-changed', this.set.bind(this, 'hasTouchpad_')); |
| 52 settings.DevicePageBrowserProxyImpl.getInstance().initializePointers(); |
| 24 }, | 53 }, |
| 25 | 54 |
| 26 /** | 55 /** |
| 27 * Handler for tapping the Touchpad settings menu item. | 56 * @return {string} |
| 28 * @private | 57 * @private |
| 29 */ | 58 */ |
| 30 onTouchpadTap_: function() { | 59 getPointersTitle_: function() { |
| 31 this.$.pages.setSubpageChain(['touchpad']); | 60 if (this.hasMouse_ && this.hasTouchpad_) |
| 61 return this.i18n('mouseAndTouchpadTitle'); |
| 62 if (this.hasMouse_) |
| 63 return this.i18n('mouseTitle'); |
| 64 if (this.hasTouchpad_) |
| 65 return this.i18n('touchpadTitle'); |
| 66 return ''; |
| 32 }, | 67 }, |
| 33 | 68 |
| 34 /** | 69 /** |
| 70 * @return {string} |
| 71 * @private |
| 72 */ |
| 73 getPointersIcon_: function() { |
| 74 if (this.hasMouse_) |
| 75 return 'settings:mouse'; |
| 76 if (this.hasTouchpad_) |
| 77 return 'settings:touch-app'; |
| 78 return ''; |
| 79 }, |
| 80 |
| 81 /** |
| 82 * Handler for tapping the mouse and touchpad settings menu item. |
| 83 * @private |
| 84 */ |
| 85 onPointersTap_: function() { |
| 86 this.$.pages.setSubpageChain(['pointers']); |
| 87 }, |
| 88 |
| 89 /** |
| 35 * Handler for tapping the Keyboard settings menu item. | 90 * Handler for tapping the Keyboard settings menu item. |
| 36 * @private | 91 * @private |
| 37 */ | 92 */ |
| 38 onKeyboardTap_: function() { | 93 onKeyboardTap_: function() { |
| 39 this.$.pages.setSubpageChain(['keyboard']); | 94 this.$.pages.setSubpageChain(['keyboard']); |
| 40 }, | 95 }, |
| 41 | 96 |
| 42 /** | 97 /** |
| 43 * Handler for tapping the Display settings menu item. | 98 * Handler for tapping the Display settings menu item. |
| 44 * @private | 99 * @private |
| 45 */ | 100 */ |
| 46 onDisplayTap_: function() { | 101 onDisplayTap_: function() { |
| 47 this.$.pages.setSubpageChain(['display']); | 102 this.$.pages.setSubpageChain(['display']); |
| 48 }, | 103 }, |
| 104 |
| 105 /** @private */ |
| 106 currentRouteChanged_: function() { |
| 107 this.checkPointerSubpage_(); |
| 108 }, |
| 109 |
| 110 /** |
| 111 * @param {boolean} hasMouse |
| 112 * @param {boolean} hasTouchpad |
| 113 * @private |
| 114 */ |
| 115 pointersChanged_: function(hasMouse, hasTouchpad) { |
| 116 this.$.pointersRow.hidden = !hasMouse && !hasTouchpad; |
| 117 this.checkPointerSubpage_(); |
| 118 }, |
| 119 |
| 120 /** |
| 121 * Leaves the pointer subpage if all pointing devices are detached. |
| 122 * @private |
| 123 */ |
| 124 checkPointerSubpage_: function() { |
| 125 if (!this.hasMouse_ && !this.hasTouchpad_ && |
| 126 this.isCurrentRouteOnPointersPage_()) { |
| 127 this.$.pages.fire('subpage-back'); |
| 128 } |
| 129 }, |
| 130 |
| 131 /** |
| 132 * TODO(michaelpg): create generic fn for this and isCurrentRouteOnSyncPage_. |
| 133 * @return {boolean} Whether the current route shows the pointers page. |
| 134 * @private |
| 135 */ |
| 136 isCurrentRouteOnPointersPage_: function() { |
| 137 return this.currentRoute && |
| 138 this.currentRoute.page == 'basic' && |
| 139 this.currentRoute.section == 'device' && |
| 140 this.currentRoute.subpage.length == 1 && |
| 141 this.currentRoute.subpage[0] == 'pointers'; |
| 142 }, |
| 49 }); | 143 }); |
| OLD | NEW |