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

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: Fix bug found by closure compiler 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 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 var pendingPseudoSink = this.pseudoSinkSearchState_.getPseudoSink(); 1992 var pendingPseudoSink = this.pseudoSinkSearchState_.getPseudoSink();
1972 // Here we will treat the pseudo sink that launched the search as a real 1993 // Here we will treat the pseudo sink that launched the search as a real
1973 // sink until one is returned by search. This way it isn't possible to 1994 // sink until one is returned by search. This way it isn't possible to
1974 // ever reach a UI state where there is no spinner being shown in the sink 1995 // ever reach a UI state where there is no spinner being shown in the sink
1975 // list but |currentLaunchingSinkId_| is non-empty (thereby preventing any 1996 // list but |currentLaunchingSinkId_| is non-empty (thereby preventing any
1976 // other sink from launching). 1997 // other sink from launching).
1977 if (pendingPseudoSink.id == this.currentLaunchingSinkId_) { 1998 if (pendingPseudoSink.id == this.currentLaunchingSinkId_) {
1978 updatedSinkList.unshift(pendingPseudoSink); 1999 updatedSinkList.unshift(pendingPseudoSink);
1979 } 2000 }
1980 } 2001 }
1981 if (this.userHasSelectedCastMode_) { 2002 // If user did not select a cast mode, then:
1982 // If user explicitly selected a cast mode, then we show only sinks that 2003 // - If there is a forced cast mode, it is shown.
1983 // are compatible with current cast mode or sinks that are active. 2004 // - If all sinks support only a single cast mode, then the cast mode is
2005 // switched to that mode.
2006 // - Otherwise, the cast mode becomes AUTO mode.
2007 if (!this.userHasSelectedCastMode_)
2008 this.setShownCastMode_(this.computeCastMode_());
2009
2010 // Non-AUTO modes may show a subset of sinks based on compatibility with the
2011 // shown value.
2012 if (this.shownCastModeValue_ != media_router.CastModeType.AUTO) {
1984 updatedSinkList = updatedSinkList.filter(function(element) { 2013 updatedSinkList = updatedSinkList.filter(function(element) {
1985 return (element.castModes & this.shownCastModeValue_) || 2014 return (element.castModes & this.shownCastModeValue_) ||
1986 this.sinkToRouteMap_[element.id]; 2015 this.sinkToRouteMap_[element.id];
1987 }, this); 2016 }, this);
1988 } else {
1989 // If user did not select a cast mode, then:
1990 // - If all sinks support only a single cast mode, then the cast mode is
1991 // switched to that mode.
1992 // - Otherwise, the cast mode becomes auto mode.
1993 // Either way, all sinks will be shown.
1994 this.setShownCastMode_(this.computeCastMode_());
1995 } 2017 }
1996 2018
1997 // When there's an updated list of sinks, append any new sinks to the end 2019 // When there's an updated list of sinks, append any new sinks to the end
1998 // of the existing list. This prevents sinks randomly jumping around the 2020 // of the existing list. This prevents sinks randomly jumping around the
1999 // dialog, which can surprise users / lead to inadvertently casting to the 2021 // dialog, which can surprise users / lead to inadvertently casting to the
2000 // wrong sink. 2022 // wrong sink.
2001 if (this.sinksToShow_) { 2023 if (this.sinksToShow_) {
2002 for (var i = this.sinksToShow_.length - 1; i >= 0; i--) { 2024 for (var i = this.sinksToShow_.length - 1; i >= 0; i--) {
2003 var index = updatedSinkList.findIndex(function(updatedSink) { 2025 var index = updatedSinkList.findIndex(function(updatedSink) {
2004 return this.sinksToShow_[i].id == updatedSink.id; }.bind(this)); 2026 return this.sinksToShow_[i].id == updatedSink.id; }.bind(this));
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2366 /** 2388 /**
2367 * Update the max dialog height and update the positioning of the elements. 2389 * Update the max dialog height and update the positioning of the elements.
2368 * 2390 *
2369 * @param {number} height The max height of the Media Router dialog. 2391 * @param {number} height The max height of the Media Router dialog.
2370 */ 2392 */
2371 updateMaxDialogHeight: function(height) { 2393 updateMaxDialogHeight: function(height) {
2372 this.dialogHeight_ = height; 2394 this.dialogHeight_ = height;
2373 this.updateElementPositioning_(); 2395 this.updateElementPositioning_();
2374 }, 2396 },
2375 }); 2397 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698