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 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1499 | 1500 |
| 1500 var is_synced_user = this.user.emailAddress !== ""; | 1501 var is_synced_user = this.user.emailAddress !== ""; |
| 1501 // Write total number if all statistics are loaded. | 1502 // Write total number if all statistics are loaded. |
| 1502 if (num_stats_loaded === Object.keys(stats_elements).length) { | 1503 if (num_stats_loaded === Object.keys(stats_elements).length) { |
| 1503 if (!total_count) { | 1504 if (!total_count) { |
| 1504 this.classList.add('has-no-stats'); | 1505 this.classList.add('has-no-stats'); |
| 1505 var message = loadTimeData.getString( | 1506 var message = loadTimeData.getString( |
| 1506 is_synced_user ? 'removeUserWarningTextSyncNoStats' : | 1507 is_synced_user ? 'removeUserWarningTextSyncNoStats' : |
| 1507 'removeUserWarningTextNonSyncNoStats'); | 1508 'removeUserWarningTextNonSyncNoStats'); |
| 1508 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, | 1509 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
| 1509 message); | 1510 message, is_synced_user); |
| 1510 } else { | 1511 } else { |
| 1511 window.updateRemoveWarningDialogSetMessage = | 1512 window.updateRemoveWarningDialogSetMessage = |
| 1512 this.updateRemoveWarningDialogSetMessage_.bind(this); | 1513 this.updateRemoveWarningDialogSetMessage_.bind(this); |
| 1513 chrome.send('getRemoveWarningDialogMessage',[{ | 1514 chrome.send('getRemoveWarningDialogMessage',[{ |
| 1514 profilePath: this.user.profilePath, | 1515 profilePath: this.user.profilePath, |
| 1515 isSyncedUser: is_synced_user, | 1516 isSyncedUser: is_synced_user, |
| 1516 hasErrors: hasErrors, | 1517 hasErrors: hasErrors, |
| 1517 totalCount: total_count | 1518 totalCount: total_count |
| 1518 }]); | 1519 }]); |
| 1519 } | 1520 } |
| 1520 } else if (isInitial) { | 1521 } else if (isInitial) { |
| 1521 if (!this.user.isProfileLoaded) { | 1522 if (!this.user.isProfileLoaded) { |
| 1522 message = loadTimeData.getString( | 1523 message = loadTimeData.getString( |
| 1523 is_synced_user ? 'removeUserWarningTextSyncNoStats' : | 1524 is_synced_user ? 'removeUserWarningTextSyncNoStats' : |
| 1524 'removeUserWarningTextNonSyncNoStats'); | 1525 'removeUserWarningTextNonSyncNoStats'); |
| 1525 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, | 1526 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
| 1526 message); | 1527 message, is_synced_user); |
| 1527 } else { | 1528 } else { |
| 1528 message = loadTimeData.getString( | 1529 message = loadTimeData.getString( |
| 1529 is_synced_user ? 'removeUserWarningTextSyncCalculating' : | 1530 is_synced_user ? 'removeUserWarningTextSyncCalculating' : |
| 1530 'removeUserWarningTextNonSyncCalculating'); | 1531 'removeUserWarningTextNonSyncCalculating'); |
| 1531 substitute = loadTimeData.getString( | 1532 substitute = loadTimeData.getString( |
| 1532 'removeUserWarningTextCalculating'); | 1533 'removeUserWarningTextCalculating'); |
| 1533 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, | 1534 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
| 1534 message, substitute); | 1535 message, is_synced_user, |
| 1536 substitute); | |
| 1535 } | 1537 } |
| 1536 } | 1538 } |
| 1537 }, | 1539 }, |
| 1538 | 1540 |
| 1539 /** | 1541 /** |
| 1540 * Refresh the message in the remove user warning dialog. | 1542 * Refresh the message in the remove user warning dialog. |
| 1541 * @param {string} profilePath The filepath of the URL (must be verified). | 1543 * @param {string} profilePath The filepath of the URL (must be verified). |
| 1542 * @param {string} message The message to be written. | 1544 * @param {string} message The message to be written. |
| 1543 * @param {number|string=} count The number or string to replace $1 in | 1545 * @param {number|string=} count The number or string to replace $1 in |
|
dzhioev (left Google)
2016/02/19 06:09:41
Add a comment about |is_synced_user|.
Moe
2016/02/19 15:07:41
Removed the parameter altogether.
| |
| 1544 * |message|. Can be omitted if $1 is not present in |message|. | 1546 * |message|. Can be omitted if $1 is not present in |message|. |
| 1545 */ | 1547 */ |
| 1546 updateRemoveWarningDialogSetMessage_: function(profilePath, message, | 1548 updateRemoveWarningDialogSetMessage_: function(profilePath, message, |
| 1547 count) { | 1549 is_synced_user, count) { |
| 1548 if (profilePath !== this.user.profilePath) | 1550 if (profilePath !== this.user.profilePath) |
| 1549 return; | 1551 return; |
| 1550 // Add localized messages where $1 will be replaced with | 1552 // Add localized messages where $1 will be replaced with |
| 1551 // <span class="total-count"></span>. | 1553 // <span class="total-count"></span>. |
| 1554 // and $2 will be replaced with <span class="email"></span>. | |
| 1552 var element = this.querySelector('.action-box-remove-user-warning-text'); | 1555 var element = this.querySelector('.action-box-remove-user-warning-text'); |
| 1553 element.textContent = ''; | 1556 element.textContent = ''; |
|
dzhioev (left Google)
2016/02/19 06:09:41
Wow, I haven't seen this function before. I think
Moe
2016/02/19 15:07:41
Agreed! Done.
| |
| 1554 | 1557 |
| 1555 messageParts = message.split('$1'); | 1558 messageParts = message.split(/(\$1|\$2)/); |
|
Moe
2016/04/08 13:44:38
Here's how the logic will more or less look like w
| |
| 1556 var numParts = messageParts.length; | 1559 var numParts = messageParts.length; |
| 1557 for (var j = 0; j < numParts; j++) { | 1560 for (var j = 0; j < numParts; j++) { |
| 1558 element.appendChild(document.createTextNode(messageParts[j])); | 1561 var elementToAdd; |
| 1559 if (j < numParts - 1) { | 1562 if (messageParts[j] === '$1') { |
| 1560 var elementToAdd = document.createElement('span'); | 1563 elementToAdd = document.createElement('span'); |
| 1561 elementToAdd.classList.add('total-count'); | 1564 elementToAdd.classList.add('total-count'); |
| 1562 elementToAdd.textContent = count; | 1565 elementToAdd.textContent = count; |
| 1563 element.appendChild(elementToAdd); | 1566 element.appendChild(elementToAdd); |
| 1567 } else if (messageParts[j] === '$2' && is_synced_user) { | |
| 1568 elementToAdd = document.createElement('span'); | |
| 1569 elementToAdd.classList.add('email'); | |
| 1570 elementToAdd.textContent = this.user.emailAddress; | |
| 1571 element.appendChild(elementToAdd); | |
| 1572 } else { | |
| 1573 element.appendChild(document.createTextNode(messageParts[j])); | |
| 1564 } | 1574 } |
| 1565 } | 1575 } |
| 1566 this.moveActionMenuUpIfNeeded_(); | 1576 this.moveActionMenuUpIfNeeded_(); |
| 1567 }, | 1577 }, |
| 1568 | 1578 |
| 1579 substituteElement_: function(placeholder, elementToAdd) { | |
|
dzhioev (left Google)
2016/02/19 06:09:41
This seems unused.
Moe
2016/02/19 15:07:41
Done.
| |
| 1580 | |
| 1581 }, | |
| 1582 | |
| 1569 /** | 1583 /** |
| 1570 * Handles a click event on remove user confirmation button. | 1584 * Handles a click event on remove user confirmation button. |
| 1571 * @param {Event} e Click event. | 1585 * @param {Event} e Click event. |
| 1572 */ | 1586 */ |
| 1573 handleRemoveUserConfirmationClick_: function(e) { | 1587 handleRemoveUserConfirmationClick_: function(e) { |
| 1574 if (this.isActionBoxMenuActive) { | 1588 if (this.isActionBoxMenuActive) { |
| 1575 this.isActionBoxMenuActive = false; | 1589 this.isActionBoxMenuActive = false; |
| 1576 this.removeUser(this.user); | 1590 this.removeUser(this.user); |
| 1577 e.stopPropagation(); | 1591 e.stopPropagation(); |
| 1578 } | 1592 } |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2307 focus: [this.handleFocus_.bind(this), true /* useCapture */], | 2321 focus: [this.handleFocus_.bind(this), true /* useCapture */], |
| 2308 click: [this.handleClick_.bind(this), true], | 2322 click: [this.handleClick_.bind(this), true], |
| 2309 mousemove: [this.handleMouseMove_.bind(this), false], | 2323 mousemove: [this.handleMouseMove_.bind(this), false], |
| 2310 keydown: [this.handleKeyDown.bind(this), false] | 2324 keydown: [this.handleKeyDown.bind(this), false] |
| 2311 }; | 2325 }; |
| 2312 | 2326 |
| 2313 var isDesktopUserManager = Oobe.getInstance().displayType == | 2327 var isDesktopUserManager = Oobe.getInstance().displayType == |
| 2314 DISPLAY_TYPE.DESKTOP_USER_MANAGER; | 2328 DISPLAY_TYPE.DESKTOP_USER_MANAGER; |
| 2315 this.userPodHeight_ = isDesktopUserManager ? DESKTOP_POD_HEIGHT : | 2329 this.userPodHeight_ = isDesktopUserManager ? DESKTOP_POD_HEIGHT : |
| 2316 CROS_POD_HEIGHT; | 2330 CROS_POD_HEIGHT; |
| 2317 // Same for Chrome OS and desktop. | 2331 this.userPodWidth_ = isDesktopUserManager ? DESKTOP_POD_WIDTH : |
| 2318 this.userPodWidth_ = POD_WIDTH; | 2332 CROS_POD_WIDTH; |
| 2319 }, | 2333 }, |
| 2320 | 2334 |
| 2321 /** | 2335 /** |
| 2322 * Returns all the pods in this pod row. | 2336 * Returns all the pods in this pod row. |
| 2323 * @type {NodeList} | 2337 * @type {NodeList} |
| 2324 */ | 2338 */ |
| 2325 get pods() { | 2339 get pods() { |
| 2326 return Array.prototype.slice.call(this.children); | 2340 return Array.prototype.slice.call(this.children); |
| 2327 }, | 2341 }, |
| 2328 | 2342 |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2775 return 2 * rowPadding + rows * this.userPodHeight_; | 2789 return 2 * rowPadding + rows * this.userPodHeight_; |
| 2776 }, | 2790 }, |
| 2777 | 2791 |
| 2778 /** | 2792 /** |
| 2779 * Calculates number of columns and rows that podrow should have in order to | 2793 * 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 | 2794 * hold as much its pods as possible for current screen size. Also it tries |
| 2781 * to choose layout that looks good. | 2795 * to choose layout that looks good. |
| 2782 * @return {{columns: number, rows: number}} | 2796 * @return {{columns: number, rows: number}} |
| 2783 */ | 2797 */ |
| 2784 calculateLayout_: function() { | 2798 calculateLayout_: function() { |
| 2799 var isDesktopUserManager = Oobe.getInstance().displayType == | |
| 2800 DISPLAY_TYPE.DESKTOP_USER_MANAGER; | |
| 2785 var preferredColumns = this.pods.length < COLUMNS.length ? | 2801 var preferredColumns = this.pods.length < COLUMNS.length ? |
| 2786 COLUMNS[this.pods.length] : COLUMNS[COLUMNS.length - 1]; | 2802 COLUMNS[this.pods.length] : COLUMNS[COLUMNS.length - 1]; |
| 2787 var maxWidth = Oobe.getInstance().clientAreaSize.width; | 2803 var maxWidth = Oobe.getInstance().clientAreaSize.width; |
| 2788 var columns = preferredColumns; | 2804 var columns = preferredColumns; |
| 2789 while (maxWidth < this.columnsToWidth_(columns) && columns > 1) | 2805 while (maxWidth < this.columnsToWidth_(columns) && columns > 1) |
| 2790 --columns; | 2806 --columns; |
| 2791 var rows = Math.floor((this.pods.length - 1) / columns) + 1; | 2807 var rows = Math.floor((this.pods.length - 1) / columns) + 1; |
| 2792 if (getComputedStyle( | 2808 if (getComputedStyle( |
| 2793 $('signin-banner'), null).getPropertyValue('display') != 'none') { | 2809 $('signin-banner'), null).getPropertyValue('display') != 'none') { |
| 2794 rows = Math.min(rows, MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER); | 2810 rows = Math.min(rows, MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER); |
| 2795 } | 2811 } |
| 2796 var maxHeigth = Oobe.getInstance().clientAreaSize.height; | 2812 if (!isDesktopUserManager) { |
| 2797 while (maxHeigth < this.rowsToHeight_(rows) && rows > 1) | 2813 var maxHeigth = Oobe.getInstance().clientAreaSize.height; |
| 2798 --rows; | 2814 while (maxHeigth < this.rowsToHeight_(rows) && rows > 1) |
| 2815 --rows; | |
| 2816 } | |
| 2799 // One more iteration if it's not enough cells to place all pods. | 2817 // One more iteration if it's not enough cells to place all pods. |
| 2800 while (maxWidth >= this.columnsToWidth_(columns + 1) && | 2818 while (maxWidth >= this.columnsToWidth_(columns + 1) && |
| 2801 columns * rows < this.pods.length && | 2819 columns * rows < this.pods.length && |
| 2802 columns < MAX_NUMBER_OF_COLUMNS) { | 2820 columns < MAX_NUMBER_OF_COLUMNS) { |
| 2803 ++columns; | 2821 ++columns; |
| 2804 } | 2822 } |
| 2805 return {columns: columns, rows: rows}; | 2823 return {columns: columns, rows: rows}; |
| 2806 }, | 2824 }, |
| 2807 | 2825 |
| 2808 /** | 2826 /** |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3320 if (pod && pod.multiProfilesPolicyApplied) { | 3338 if (pod && pod.multiProfilesPolicyApplied) { |
| 3321 pod.userTypeBubbleElement.classList.remove('bubble-shown'); | 3339 pod.userTypeBubbleElement.classList.remove('bubble-shown'); |
| 3322 } | 3340 } |
| 3323 } | 3341 } |
| 3324 }; | 3342 }; |
| 3325 | 3343 |
| 3326 return { | 3344 return { |
| 3327 PodRow: PodRow | 3345 PodRow: PodRow |
| 3328 }; | 3346 }; |
| 3329 }); | 3347 }); |
| OLD | NEW |