Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 * @const | 21 * @const |
| 22 */ | 22 */ |
| 23 var MARGIN_BY_COLUMNS = [undefined, 40, 40, 40, 40, 40, 12]; | 23 var MARGIN_BY_COLUMNS = [undefined, 40, 40, 40, 40, 40, 12]; |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Mapping between number of columns in the desktop pod-row and margin | 26 * Mapping between number of columns in the desktop pod-row and margin |
| 27 * between user pods for such layout. | 27 * between user pods for such layout. |
| 28 * @type {Array<number>} | 28 * @type {Array<number>} |
| 29 * @const | 29 * @const |
| 30 */ | 30 */ |
| 31 var DESKTOP_MARGIN_BY_COLUMNS = [undefined, 15, 15, 15, 15, 15, 15]; | 31 var DESKTOP_MARGIN_BY_COLUMNS = [undefined, 32, 32, 32, 32, 32, 32]; |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Maximal number of columns currently supported by pod-row. | 34 * Maximal number of columns currently supported by pod-row. |
| 35 * @type {number} | 35 * @type {number} |
| 36 * @const | 36 * @const |
| 37 */ | 37 */ |
| 38 var MAX_NUMBER_OF_COLUMNS = 6; | 38 var MAX_NUMBER_OF_COLUMNS = 6; |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * Maximal number of rows if sign-in banner is displayed alonside. | 41 * Maximal number of rows if sign-in banner is displayed alonside. |
| 42 * @type {number} | 42 * @type {number} |
| 43 * @const | 43 * @const |
| 44 */ | 44 */ |
| 45 var MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER = 2; | 45 var MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER = 2; |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * Variables used for pod placement processing. Width and height should be | 48 * Variables used for pod placement processing. Width and height should be |
| 49 * synced with computed CSS sizes of pods. | 49 * synced with computed CSS sizes of pods. |
| 50 */ | 50 */ |
| 51 var POD_WIDTH = 180; | 51 var CROS_POD_WIDTH = 180; |
| 52 var DESKTOP_POD_WIDTH = 160; | |
| 52 var PUBLIC_EXPANDED_BASIC_WIDTH = 500; | 53 var PUBLIC_EXPANDED_BASIC_WIDTH = 500; |
| 53 var PUBLIC_EXPANDED_ADVANCED_WIDTH = 610; | 54 var PUBLIC_EXPANDED_ADVANCED_WIDTH = 610; |
| 54 var CROS_POD_HEIGHT = 213; | 55 var CROS_POD_HEIGHT = 213; |
| 55 var DESKTOP_POD_HEIGHT = 226; | 56 var DESKTOP_POD_HEIGHT = 200; |
| 56 var POD_ROW_PADDING = 10; | 57 var POD_ROW_PADDING = 10; |
| 57 var DESKTOP_ROW_PADDING = 15; | 58 var DESKTOP_ROW_PADDING = 32; |
| 58 var CUSTOM_ICON_CONTAINER_SIZE = 40; | 59 var CUSTOM_ICON_CONTAINER_SIZE = 40; |
| 59 | 60 |
| 60 /** | 61 /** |
| 61 * Minimal padding between user pod and virtual keyboard. | 62 * Minimal padding between user pod and virtual keyboard. |
| 62 * @type {number} | 63 * @type {number} |
| 63 * @const | 64 * @const |
| 64 */ | 65 */ |
| 65 var USER_POD_KEYBOARD_MIN_PADDING = 20; | 66 var USER_POD_KEYBOARD_MIN_PADDING = 20; |
| 66 | 67 |
| 67 /** | 68 /** |
| (...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1541 * @param {string} profilePath The filepath of the URL (must be verified). | 1542 * @param {string} profilePath The filepath of the URL (must be verified). |
| 1542 * @param {string} message The message to be written. | 1543 * @param {string} message The message to be written. |
| 1543 * @param {number|string=} count The number or string to replace $1 in | 1544 * @param {number|string=} count The number or string to replace $1 in |
| 1544 * |message|. Can be omitted if $1 is not present in |message|. | 1545 * |message|. Can be omitted if $1 is not present in |message|. |
| 1545 */ | 1546 */ |
| 1546 updateRemoveWarningDialogSetMessage_: function(profilePath, message, | 1547 updateRemoveWarningDialogSetMessage_: function(profilePath, message, |
| 1547 count) { | 1548 count) { |
| 1548 if (profilePath !== this.user.profilePath) | 1549 if (profilePath !== this.user.profilePath) |
| 1549 return; | 1550 return; |
| 1550 // Add localized messages where $1 will be replaced with | 1551 // Add localized messages where $1 will be replaced with |
| 1551 // <span class="total-count"></span>. | 1552 // <span class="total-count"></span> and $2 will be replaced with |
| 1553 // <span class="email"></span>. | |
| 1552 var element = this.querySelector('.action-box-remove-user-warning-text'); | 1554 var element = this.querySelector('.action-box-remove-user-warning-text'); |
| 1553 element.textContent = ''; | 1555 element.textContent = ''; |
| 1554 | 1556 |
| 1555 messageParts = message.split('$1'); | 1557 messageParts = message.split(/(\$1|\$2)/); |
|
Dan Beam
2016/04/19 03:44:06
nit: /\$[12]/
Moe
2016/04/19 15:20:08
Done. /(\$[12])/ to keep the delimiters.
| |
| 1556 var numParts = messageParts.length; | 1558 var numParts = messageParts.length; |
| 1557 for (var j = 0; j < numParts; j++) { | 1559 for (var j = 0; j < numParts; j++) { |
| 1558 element.appendChild(document.createTextNode(messageParts[j])); | 1560 if (messageParts[j] === '$1') { |
| 1559 if (j < numParts - 1) { | |
| 1560 var elementToAdd = document.createElement('span'); | 1561 var elementToAdd = document.createElement('span'); |
| 1561 elementToAdd.classList.add('total-count'); | 1562 elementToAdd.classList.add('total-count'); |
| 1562 elementToAdd.textContent = count; | 1563 elementToAdd.textContent = count; |
| 1563 element.appendChild(elementToAdd); | 1564 element.appendChild(elementToAdd); |
| 1565 } else if (messageParts[j] === '$2') { | |
| 1566 var elementToAdd = document.createElement('span'); | |
| 1567 elementToAdd.classList.add('email'); | |
| 1568 elementToAdd.textContent = this.user.emailAddress; | |
| 1569 element.appendChild(elementToAdd); | |
| 1570 } else { | |
| 1571 element.appendChild(document.createTextNode(messageParts[j])); | |
| 1564 } | 1572 } |
| 1565 } | 1573 } |
| 1566 this.moveActionMenuUpIfNeeded_(); | 1574 this.moveActionMenuUpIfNeeded_(); |
| 1567 }, | 1575 }, |
| 1568 | 1576 |
| 1569 /** | 1577 /** |
| 1570 * Handles a click event on remove user confirmation button. | 1578 * Handles a click event on remove user confirmation button. |
| 1571 * @param {Event} e Click event. | 1579 * @param {Event} e Click event. |
| 1572 */ | 1580 */ |
| 1573 handleRemoveUserConfirmationClick_: function(e) { | 1581 handleRemoveUserConfirmationClick_: function(e) { |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2307 focus: [this.handleFocus_.bind(this), true /* useCapture */], | 2315 focus: [this.handleFocus_.bind(this), true /* useCapture */], |
| 2308 click: [this.handleClick_.bind(this), true], | 2316 click: [this.handleClick_.bind(this), true], |
| 2309 mousemove: [this.handleMouseMove_.bind(this), false], | 2317 mousemove: [this.handleMouseMove_.bind(this), false], |
| 2310 keydown: [this.handleKeyDown.bind(this), false] | 2318 keydown: [this.handleKeyDown.bind(this), false] |
| 2311 }; | 2319 }; |
| 2312 | 2320 |
| 2313 var isDesktopUserManager = Oobe.getInstance().displayType == | 2321 var isDesktopUserManager = Oobe.getInstance().displayType == |
| 2314 DISPLAY_TYPE.DESKTOP_USER_MANAGER; | 2322 DISPLAY_TYPE.DESKTOP_USER_MANAGER; |
| 2315 this.userPodHeight_ = isDesktopUserManager ? DESKTOP_POD_HEIGHT : | 2323 this.userPodHeight_ = isDesktopUserManager ? DESKTOP_POD_HEIGHT : |
| 2316 CROS_POD_HEIGHT; | 2324 CROS_POD_HEIGHT; |
| 2317 // Same for Chrome OS and desktop. | 2325 this.userPodWidth_ = isDesktopUserManager ? DESKTOP_POD_WIDTH : |
| 2318 this.userPodWidth_ = POD_WIDTH; | 2326 CROS_POD_WIDTH; |
| 2319 }, | 2327 }, |
| 2320 | 2328 |
| 2321 /** | 2329 /** |
| 2322 * Returns all the pods in this pod row. | 2330 * Returns all the pods in this pod row. |
| 2323 * @type {NodeList} | 2331 * @type {NodeList} |
| 2324 */ | 2332 */ |
| 2325 get pods() { | 2333 get pods() { |
| 2326 return Array.prototype.slice.call(this.children); | 2334 return Array.prototype.slice.call(this.children); |
| 2327 }, | 2335 }, |
| 2328 | 2336 |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2775 return 2 * rowPadding + rows * this.userPodHeight_; | 2783 return 2 * rowPadding + rows * this.userPodHeight_; |
| 2776 }, | 2784 }, |
| 2777 | 2785 |
| 2778 /** | 2786 /** |
| 2779 * Calculates number of columns and rows that podrow should have in order to | 2787 * Calculates number of columns and rows that podrow should have in order to |
| 2780 * hold as much its pods as possible for current screen size. Also it tries | 2788 * hold as much its pods as possible for current screen size. Also it tries |
| 2781 * to choose layout that looks good. | 2789 * to choose layout that looks good. |
| 2782 * @return {{columns: number, rows: number}} | 2790 * @return {{columns: number, rows: number}} |
| 2783 */ | 2791 */ |
| 2784 calculateLayout_: function() { | 2792 calculateLayout_: function() { |
| 2793 var isDesktopUserManager = Oobe.getInstance().displayType == | |
| 2794 DISPLAY_TYPE.DESKTOP_USER_MANAGER; | |
| 2785 var preferredColumns = this.pods.length < COLUMNS.length ? | 2795 var preferredColumns = this.pods.length < COLUMNS.length ? |
| 2786 COLUMNS[this.pods.length] : COLUMNS[COLUMNS.length - 1]; | 2796 COLUMNS[this.pods.length] : COLUMNS[COLUMNS.length - 1]; |
| 2787 var maxWidth = Oobe.getInstance().clientAreaSize.width; | 2797 var maxWidth = Oobe.getInstance().clientAreaSize.width; |
| 2788 var columns = preferredColumns; | 2798 var columns = preferredColumns; |
| 2789 while (maxWidth < this.columnsToWidth_(columns) && columns > 1) | 2799 while (maxWidth < this.columnsToWidth_(columns) && columns > 1) |
| 2790 --columns; | 2800 --columns; |
| 2791 var rows = Math.floor((this.pods.length - 1) / columns) + 1; | 2801 var rows = Math.floor((this.pods.length - 1) / columns) + 1; |
| 2792 if (getComputedStyle( | 2802 if (getComputedStyle( |
| 2793 $('signin-banner'), null).getPropertyValue('display') != 'none') { | 2803 $('signin-banner'), null).getPropertyValue('display') != 'none') { |
| 2794 rows = Math.min(rows, MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER); | 2804 rows = Math.min(rows, MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER); |
| 2795 } | 2805 } |
| 2796 var maxHeigth = Oobe.getInstance().clientAreaSize.height; | 2806 if (!isDesktopUserManager) { |
| 2797 while (maxHeigth < this.rowsToHeight_(rows) && rows > 1) | 2807 var maxHeigth = Oobe.getInstance().clientAreaSize.height; |
| 2798 --rows; | 2808 while (maxHeigth < this.rowsToHeight_(rows) && rows > 1) |
| 2809 --rows; | |
| 2810 } | |
| 2799 // One more iteration if it's not enough cells to place all pods. | 2811 // One more iteration if it's not enough cells to place all pods. |
| 2800 while (maxWidth >= this.columnsToWidth_(columns + 1) && | 2812 while (maxWidth >= this.columnsToWidth_(columns + 1) && |
| 2801 columns * rows < this.pods.length && | 2813 columns * rows < this.pods.length && |
| 2802 columns < MAX_NUMBER_OF_COLUMNS) { | 2814 columns < MAX_NUMBER_OF_COLUMNS) { |
| 2803 ++columns; | 2815 ++columns; |
| 2804 } | 2816 } |
| 2805 return {columns: columns, rows: rows}; | 2817 return {columns: columns, rows: rows}; |
| 2806 }, | 2818 }, |
| 2807 | 2819 |
| 2808 /** | 2820 /** |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3324 if (pod && pod.multiProfilesPolicyApplied) { | 3336 if (pod && pod.multiProfilesPolicyApplied) { |
| 3325 pod.userTypeBubbleElement.classList.remove('bubble-shown'); | 3337 pod.userTypeBubbleElement.classList.remove('bubble-shown'); |
| 3326 } | 3338 } |
| 3327 } | 3339 } |
| 3328 }; | 3340 }; |
| 3329 | 3341 |
| 3330 return { | 3342 return { |
| 3331 PodRow: PodRow | 3343 PodRow: PodRow |
| 3332 }; | 3344 }; |
| 3333 }); | 3345 }); |
| OLD | NEW |