OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 User pod row implementation. | 6 * @fileoverview User pod row implementation. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('login', function() { | 9 cr.define('login', function() { |
10 /** | 10 /** |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 /** | 155 /** |
156 * Helper function to remove a class from given element. | 156 * Helper function to remove a class from given element. |
157 * @param {!HTMLElement} el Element whose class list to change. | 157 * @param {!HTMLElement} el Element whose class list to change. |
158 * @param {string} cl Class to remove. | 158 * @param {string} cl Class to remove. |
159 */ | 159 */ |
160 function removeClass(el, cl) { | 160 function removeClass(el, cl) { |
161 el.classList.remove(cl); | 161 el.classList.remove(cl); |
162 } | 162 } |
163 | 163 |
164 /** | 164 /** |
| 165 * Helper function to switch directions for right-to-left languages. |
| 166 * @param {!HTMLElement} el Element whose style needs to change. |
| 167 */ |
| 168 function switchDirection(el) { |
| 169 var leftStyle = el.style.left; |
| 170 el.style.left = el.style.right; |
| 171 el.style.right = leftStyle; |
| 172 } |
| 173 |
| 174 /** |
165 * Creates a user pod. | 175 * Creates a user pod. |
166 * @constructor | 176 * @constructor |
167 * @extends {HTMLDivElement} | 177 * @extends {HTMLDivElement} |
168 */ | 178 */ |
169 var UserPod = cr.ui.define(function() { | 179 var UserPod = cr.ui.define(function() { |
170 var node = $('user-pod-template').cloneNode(true); | 180 var node = $('user-pod-template').cloneNode(true); |
171 node.removeAttribute('id'); | 181 node.removeAttribute('id'); |
172 return node; | 182 return node; |
173 }); | 183 }); |
174 | 184 |
(...skipping 3703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3878 }, | 3888 }, |
3879 | 3889 |
3880 /** | 3890 /** |
3881 * Called after pod placement and before showing the pod row. Updates | 3891 * Called after pod placement and before showing the pod row. Updates |
3882 * elements whose style may depend on the pod placement outcome. | 3892 * elements whose style may depend on the pod placement outcome. |
3883 * @private | 3893 * @private |
3884 */ | 3894 */ |
3885 handleAfterPodPlacement_: function() { | 3895 handleAfterPodPlacement_: function() { |
3886 var pods = this.pods; | 3896 var pods = this.pods; |
3887 for (var pod of pods) { | 3897 for (var pod of pods) { |
3888 if (pods.length > POD_ROW_LIMIT && pod != this.mainPod_) | 3898 if (pod.getPodStyle() != UserPod.Style.LARGE) |
3889 continue; | 3899 continue; |
3890 // Make sure that user name on each large pod is centered and extra | 3900 // Make sure that user name on each large pod is centered and extra |
3891 // long names don't exceed maximum pod width. | 3901 // long names don't exceed maximum pod width. |
3892 var nameArea = pod.querySelector('.name-container'); | 3902 var nameArea = pod.querySelector('.name-container'); |
3893 var leftMargin = (CROS_POD_WIDTH - pod.nameElement.offsetWidth) / 2; | 3903 var leftMargin = (CROS_POD_WIDTH - pod.nameElement.offsetWidth) / 2; |
3894 if (leftMargin > 0) | 3904 if (leftMargin > 0) { |
3895 nameArea.style.left = cr.ui.toCssPx(leftMargin); | 3905 nameArea.style.left = cr.ui.toCssPx(leftMargin); |
3896 else { | 3906 nameArea.style.right = 'auto'; |
| 3907 } else { |
3897 pod.nameElement.style.width = cr.ui.toCssPx(CROS_POD_WIDTH); | 3908 pod.nameElement.style.width = cr.ui.toCssPx(CROS_POD_WIDTH); |
3898 nameArea.style.left = cr.ui.toCssPx(0); | 3909 nameArea.style.left = cr.ui.toCssPx(0); |
| 3910 nameArea.style.right = 'auto'; |
3899 } | 3911 } |
| 3912 |
3900 // Update info container area for public session pods. | 3913 // Update info container area for public session pods. |
3901 if (pod.isPublicSessionPod) { | 3914 if (pod.isPublicSessionPod) { |
3902 var infoElement = pod.querySelector('.info'); | 3915 var infoElement = pod.querySelector('.info'); |
3903 var infoIcon = pod.querySelector('.learn-more'); | 3916 var infoIcon = pod.querySelector('.learn-more'); |
3904 var totalWidth = PUBLIC_SESSION_ICON_WIDTH + infoElement.offsetWidth; | 3917 var totalWidth = PUBLIC_SESSION_ICON_WIDTH + infoElement.offsetWidth; |
3905 var infoLeftMargin = (CROS_POD_WIDTH - totalWidth) / 2; | 3918 var infoLeftMargin = (CROS_POD_WIDTH - totalWidth) / 2; |
3906 if (infoLeftMargin > 0) { | 3919 if (infoLeftMargin > 0) { |
3907 infoIcon.style.left = cr.ui.toCssPx(infoLeftMargin); | 3920 infoIcon.style.left = cr.ui.toCssPx(infoLeftMargin); |
| 3921 infoIcon.style.right = 'auto'; |
3908 infoElement.style.left = | 3922 infoElement.style.left = |
3909 cr.ui.toCssPx(infoLeftMargin + PUBLIC_SESSION_ICON_WIDTH); | 3923 cr.ui.toCssPx(infoLeftMargin + PUBLIC_SESSION_ICON_WIDTH); |
| 3924 infoElement.style.right = 'auto'; |
3910 } else { | 3925 } else { |
3911 infoIcon.style.left = cr.ui.toCssPx(0); | 3926 infoIcon.style.left = cr.ui.toCssPx(0); |
| 3927 infoIcon.style.right = 'auto'; |
3912 infoElement.style.left = cr.ui.toCssPx(PUBLIC_SESSION_ICON_WIDTH); | 3928 infoElement.style.left = cr.ui.toCssPx(PUBLIC_SESSION_ICON_WIDTH); |
| 3929 infoElement.style.right = 'auto'; |
3913 infoElement.style.width = cr.ui.toCssPx( | 3930 infoElement.style.width = cr.ui.toCssPx( |
3914 CROS_POD_WIDTH - PUBLIC_SESSION_ICON_WIDTH - | 3931 CROS_POD_WIDTH - PUBLIC_SESSION_ICON_WIDTH - |
3915 infoElement.style.paddingLeft); | 3932 infoElement.style.paddingLeft); |
3916 } | 3933 } |
3917 // If the public session pod is already expanded, make sure it's | 3934 // If the public session pod is already expanded, make sure it's |
3918 // still centered. | 3935 // still centered. |
3919 if (pod.expanded) | 3936 if (pod.expanded) |
3920 this.centerPod_(pod, PUBLIC_EXPANDED_WIDTH, PUBLIC_EXPANDED_HEIGHT); | 3937 this.centerPod_(pod, PUBLIC_EXPANDED_WIDTH, PUBLIC_EXPANDED_HEIGHT); |
3921 } | 3938 } |
| 3939 |
3922 // Update action box menu position to ensure it doesn't overlap with | 3940 // Update action box menu position to ensure it doesn't overlap with |
3923 // elements outside the pod. | 3941 // elements outside the pod. |
3924 var actionBoxMenu = pod.querySelector('.action-box-menu'); | 3942 var actionBoxMenu = pod.querySelector('.action-box-menu'); |
3925 var actionBoxButton = pod.querySelector('.action-box-button'); | 3943 var actionBoxButton = pod.querySelector('.action-box-button'); |
3926 var MENU_TOP_PADDING = 7; | 3944 var MENU_TOP_PADDING = 7; |
3927 if (this.isPortraitMode_() && pods.length > 1) { | 3945 if (this.isPortraitMode_() && pods.length > 1) { |
3928 // Confine the menu inside the pod when it may overlap with outside | 3946 // Confine the menu inside the pod when it may overlap with outside |
3929 // elements. | 3947 // elements. |
3930 actionBoxMenu.style.left = 'auto'; | 3948 actionBoxMenu.style.left = 'auto'; |
3931 actionBoxMenu.style.right = cr.ui.toCssPx(0); | 3949 actionBoxMenu.style.right = cr.ui.toCssPx(0); |
3932 actionBoxMenu.style.top = | 3950 actionBoxMenu.style.top = |
3933 cr.ui.toCssPx(actionBoxButton.offsetHeight + MENU_TOP_PADDING); | 3951 cr.ui.toCssPx(actionBoxButton.offsetHeight + MENU_TOP_PADDING); |
3934 } else if (!this.isPortraitMode_() && this.isScreenShrinked_()) { | 3952 } else if (!this.isPortraitMode_() && this.isScreenShrinked_()) { |
3935 // Prevent the virtual keyboard from blocking the remove user button. | 3953 // Prevent the virtual keyboard from blocking the remove user button. |
3936 actionBoxMenu.style.left = cr.ui.toCssPx( | 3954 actionBoxMenu.style.left = cr.ui.toCssPx( |
3937 pod.nameElement.offsetWidth + actionBoxButton.offsetWidth); | 3955 pod.nameElement.offsetWidth + actionBoxButton.offsetWidth); |
3938 actionBoxMenu.style.right = 'auto'; | 3956 actionBoxMenu.style.right = 'auto'; |
3939 actionBoxMenu.style.top = cr.ui.toCssPx(0); | 3957 actionBoxMenu.style.top = cr.ui.toCssPx(0); |
3940 } else { | 3958 } else { |
3941 actionBoxMenu.style.left = cr.ui.toCssPx( | 3959 actionBoxMenu.style.left = cr.ui.toCssPx( |
3942 pod.nameElement.offsetWidth + actionBoxButton.style.marginLeft); | 3960 pod.nameElement.offsetWidth + actionBoxButton.style.marginLeft); |
3943 actionBoxMenu.style.right = 'auto'; | 3961 actionBoxMenu.style.right = 'auto'; |
3944 actionBoxMenu.style.top = | 3962 actionBoxMenu.style.top = |
3945 cr.ui.toCssPx(actionBoxButton.offsetHeight + MENU_TOP_PADDING); | 3963 cr.ui.toCssPx(actionBoxButton.offsetHeight + MENU_TOP_PADDING); |
3946 } | 3964 } |
| 3965 |
3947 // Update password container width based on the visibility of the | 3966 // Update password container width based on the visibility of the |
3948 // custom icon container. | 3967 // custom icon container. |
3949 pod.querySelector('.password-container') | 3968 pod.querySelector('.password-container') |
3950 .classList.toggle( | 3969 .classList.toggle( |
3951 'custom-icon-shown', !pod.customIconElement.hidden); | 3970 'custom-icon-shown', !pod.customIconElement.hidden); |
3952 // Add ripple animation. | 3971 // Add ripple animation. |
3953 var actionBoxRippleEffect = | 3972 var actionBoxRippleEffect = |
3954 pod.querySelector('.action-box-button.ripple-circle'); | 3973 pod.querySelector('.action-box-button.ripple-circle'); |
3955 actionBoxRippleEffect.style.left = cr.ui.toCssPx( | 3974 actionBoxRippleEffect.style.left = cr.ui.toCssPx( |
3956 pod.nameElement.offsetWidth + actionBoxButton.style.marginLeft); | 3975 pod.nameElement.offsetWidth + actionBoxButton.style.marginLeft); |
| 3976 actionBoxRippleEffect.style.right = 'auto'; |
3957 actionBoxRippleEffect.style.top = | 3977 actionBoxRippleEffect.style.top = |
3958 cr.ui.toCssPx(actionBoxButton.style.marginTop); | 3978 cr.ui.toCssPx(actionBoxButton.style.marginTop); |
3959 // Adjust the vertical position of the pod if pin keyboard is shown. | 3979 // Adjust the vertical position of the pod if pin keyboard is shown. |
3960 if (pod.isPinShown() && !this.isScreenShrinked_()) | 3980 if (pod.isPinShown() && !this.isScreenShrinked_()) |
3961 pod.top = (this.screenSize.height - CROS_POD_HEIGHT_WITH_PIN) / 2; | 3981 pod.top = (this.screenSize.height - CROS_POD_HEIGHT_WITH_PIN) / 2; |
| 3982 |
| 3983 // In the end, switch direction of the above elements if right-to-left |
| 3984 // language is used. |
| 3985 if (isRTL()) { |
| 3986 switchDirection(nameArea); |
| 3987 switchDirection(actionBoxMenu); |
| 3988 switchDirection(actionBoxRippleEffect); |
| 3989 if (pod.isPublicSessionPod) { |
| 3990 switchDirection(pod.querySelector('.info')); |
| 3991 switchDirection(pod.querySelector('.learn-more')); |
| 3992 } |
| 3993 } |
3962 } | 3994 } |
3963 // Update the position of the sign-in banner if it's shown. | 3995 // Update the position of the sign-in banner if it's shown. |
3964 if ($('signin-banner').textContent.length != 0) { | 3996 if ($('signin-banner').textContent.length != 0) { |
3965 var bannerContainer = $('signin-banner-container1'); | 3997 var bannerContainer = $('signin-banner-container1'); |
3966 bannerContainer.style.top = cr.ui.toCssPx(this.mainPod_.top / 2); | 3998 bannerContainer.style.top = cr.ui.toCssPx(this.mainPod_.top / 2); |
3967 if (this.pods.length <= POD_ROW_LIMIT) { | 3999 if (this.pods.length <= POD_ROW_LIMIT) { |
3968 bannerContainer.style.left = cr.ui.toCssPx( | 4000 bannerContainer.style.left = cr.ui.toCssPx( |
3969 (this.screenSize.width - bannerContainer.offsetWidth) / 2); | 4001 (this.screenSize.width - bannerContainer.offsetWidth) / 2); |
3970 } | 4002 } |
3971 else { | 4003 else { |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4665 if (pod && pod.multiProfilesPolicyApplied) { | 4697 if (pod && pod.multiProfilesPolicyApplied) { |
4666 pod.userTypeBubbleElement.classList.remove('bubble-shown'); | 4698 pod.userTypeBubbleElement.classList.remove('bubble-shown'); |
4667 } | 4699 } |
4668 } | 4700 } |
4669 }; | 4701 }; |
4670 | 4702 |
4671 return { | 4703 return { |
4672 PodRow: PodRow | 4704 PodRow: PodRow |
4673 }; | 4705 }; |
4674 }); | 4706 }); |
OLD | NEW |