Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(890)

Side by Side Diff: chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js

Issue 2862393002: [Media Router] Force DEFAULT cast mode when starting presentations from content. (Closed)
Patch Set: Update unittests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // This Polymer element contains the entire media router interface. It handles 5 // This Polymer element contains the entire media router interface. It handles
6 // hiding and showing specific components. 6 // hiding and showing specific components.
7 Polymer({ 7 Polymer({
8 is: 'media-router-container', 8 is: 'media-router-container',
9 9
10 properties: { 10 properties: {
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 523
524 /** 524 /**
525 * Checks that the currently selected cast mode is still in the 525 * Checks that the currently selected cast mode is still in the
526 * updated list of available cast modes. If not, then update the selected 526 * updated list of available cast modes. If not, then update the selected
527 * cast mode to the first available cast mode on the list. 527 * cast mode to the first available cast mode on the list.
528 */ 528 */
529 checkCurrentCastMode_: function() { 529 checkCurrentCastMode_: function() {
530 if (!this.castModeList.length) 530 if (!this.castModeList.length)
531 return; 531 return;
532 532
533 // If there is a forced mode make sure it is shown.
534 if (this.findForcedCastMode_()) {
535 this.rebuildSinksToShow_();
536 }
537
533 // If we are currently showing auto mode, then nothing needs to be done. 538 // If we are currently showing auto mode, then nothing needs to be done.
534 // Otherwise, if the cast mode currently shown no longer exists (regardless 539 // Otherwise, if the cast mode currently shown no longer exists (regardless
535 // of whether it was selected by user), then switch back to auto cast mode. 540 // of whether it was selected by user), then switch back to auto cast mode.
536 if (this.shownCastModeValue_ != media_router.CastModeType.AUTO && 541 if (this.shownCastModeValue_ != media_router.CastModeType.AUTO &&
537 !this.findCastModeByType_(this.shownCastModeValue_)) { 542 !this.findCastModeByType_(this.shownCastModeValue_)) {
538 this.setShownCastMode_(media_router.AUTO_CAST_MODE); 543 this.setShownCastMode_(media_router.AUTO_CAST_MODE);
539 this.rebuildSinksToShow_(); 544 this.rebuildSinksToShow_();
540 } 545 }
541 }, 546 },
542 547
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 * @param {number} distance Number of pixels that will be traveled. 609 * @param {number} distance Number of pixels that will be traveled.
605 * @private 610 * @private
606 */ 611 */
607 computeAnimationDuration_: function(distance) { 612 computeAnimationDuration_: function(distance) {
608 // The duration of the animation can be found by abs(distance)/speed, where 613 // The duration of the animation can be found by abs(distance)/speed, where
609 // speed is fixed at 1000 pixels per second, or 1 pixel per millisecond. 614 // speed is fixed at 1000 pixels per second, or 1 pixel per millisecond.
610 return Math.abs(distance); 615 return Math.abs(distance);
611 }, 616 },
612 617
613 /** 618 /**
614 * If |allSinks| supports only a single cast mode, returns that cast mode. 619 * If there is a forced cast mode, returns that cast mode. If |allSinks|
615 * Otherwise, returns AUTO_MODE. Only called if |userHasSelectedCastMode_| is 620 * supports only a single cast mode, returns that cast mode. Otherwise,
616 * |false|. 621 * returns AUTO_MODE. Only called if |userHasSelectedCastMode_| is |false|.
622 *
617 * @return {!media_router.CastMode} The single cast mode supported by 623 * @return {!media_router.CastMode} The single cast mode supported by
618 * |allSinks|, or AUTO_MODE. 624 * |allSinks|, or AUTO_MODE.
619 */ 625 */
620 computeCastMode_: function() { 626 computeCastMode_: function() {
627 /** @const */ var forcedMode = this.findForcedCastMode_();
628 if (forcedMode)
629 return forcedMode;
630
621 var allCastModes = this.allSinks.reduce(function(castModesSoFar, sink) { 631 var allCastModes = this.allSinks.reduce(function(castModesSoFar, sink) {
622 return castModesSoFar | sink.castModes; 632 return castModesSoFar | sink.castModes;
623 }, 0); 633 }, 0);
624 634
625 // This checks whether |castModes| does not consist of exactly 1 cast mode. 635 // This checks whether |castModes| does not consist of exactly 1 cast mode.
626 if (!allCastModes || allCastModes & (allCastModes - 1)) 636 if (!allCastModes || allCastModes & (allCastModes - 1))
627 return media_router.AUTO_CAST_MODE; 637 return media_router.AUTO_CAST_MODE;
628 638
629 var castMode = this.findCastModeByType_(allCastModes); 639 var castMode = this.findCastModeByType_(allCastModes);
630 if (castMode) 640 if (castMode)
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 * @return {media_router.CastMode|undefined} CastMode object with the given 1152 * @return {media_router.CastMode|undefined} CastMode object with the given
1143 * type in castModeList, or undefined if not found. 1153 * type in castModeList, or undefined if not found.
1144 */ 1154 */
1145 findCastModeByType_: function(castModeType) { 1155 findCastModeByType_: function(castModeType) {
1146 return this.castModeList.find(function(element, index, array) { 1156 return this.castModeList.find(function(element, index, array) {
1147 return element.type == castModeType; 1157 return element.type == castModeType;
1148 }); 1158 });
1149 }, 1159 },
1150 1160
1151 /** 1161 /**
1162 * Helper function to return a forced CastMode, if any.
1163 *
1164 * @return {media_router.CastMode|undefined} CastMode object with
1165 * isForced = true, or undefined if not found.
1166 */
1167 findForcedCastMode_: function() {
1168 return this.castModeList &&
1169 this.castModeList.find(element => element.isForced);
1170 },
1171
1172 /**
1152 * @param {?Element} element Element to compute padding for. 1173 * @param {?Element} element Element to compute padding for.
1153 * @return {!Array<number>} Array containing the element's bottom padding 1174 * @return {!Array<number>} Array containing the element's bottom padding
1154 * value and the element's top padding value, in that order. 1175 * value and the element's top padding value, in that order.
1155 * @private 1176 * @private
1156 */ 1177 */
1157 getElementVerticalPadding_: function(element) { 1178 getElementVerticalPadding_: function(element) {
1158 var style = window.getComputedStyle(element); 1179 var style = window.getComputedStyle(element);
1159 return [parseInt(style.getPropertyValue('padding-bottom'), 10) || 0, 1180 return [parseInt(style.getPropertyValue('padding-bottom'), 10) || 0,
1160 parseInt(style.getPropertyValue('padding-top'), 10) || 0]; 1181 parseInt(style.getPropertyValue('padding-top'), 10) || 0];
1161 }, 1182 },
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2366 /** 2387 /**
2367 * Update the max dialog height and update the positioning of the elements. 2388 * Update the max dialog height and update the positioning of the elements.
2368 * 2389 *
2369 * @param {number} height The max height of the Media Router dialog. 2390 * @param {number} height The max height of the Media Router dialog.
2370 */ 2391 */
2371 updateMaxDialogHeight: function(height) { 2392 updateMaxDialogHeight: function(height) {
2372 this.dialogHeight_ = height; 2393 this.dialogHeight_ = height;
2373 this.updateElementPositioning_(); 2394 this.updateElementPositioning_();
2374 }, 2395 },
2375 }); 2396 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698