Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 MediaControls class implements media playback controls | 6 * @fileoverview MediaControls class implements media playback controls |
| 7 * that exist outside of the audio/video HTML element. | 7 * that exist outside of the audio/video HTML element. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 // not known to be bounded yet. In such cases, we should hide duration. | 482 // not known to be bounded yet. In such cases, we should hide duration. |
| 483 this.currentTime_.textContent = MediaControls.formatTime_(current); | 483 this.currentTime_.textContent = MediaControls.formatTime_(current); |
| 484 this.currentTimeSpacer_.textContent = MediaControls.formatTime_(current); | 484 this.currentTimeSpacer_.textContent = MediaControls.formatTime_(current); |
| 485 } | 485 } |
| 486 }; | 486 }; |
| 487 | 487 |
| 488 /* | 488 /* |
| 489 * Volume controls | 489 * Volume controls |
| 490 */ | 490 */ |
| 491 | 491 |
| 492 MediaControls.STORAGE_PREFIX = 'videoplayer-'; | |
| 493 | |
| 494 MediaControls.KEY_NORMALIZED_VOLUME = | |
| 495 MediaControls.STORAGE_PREFIX + 'normalized-volume'; | |
| 496 | |
| 492 /** | 497 /** |
| 493 * @param {HTMLElement=} opt_parent Parent element for the controls. | 498 * @param {HTMLElement=} opt_parent Parent element for the controls. |
| 494 */ | 499 */ |
| 495 MediaControls.prototype.initVolumeControls = function(opt_parent) { | 500 MediaControls.prototype.initVolumeControls = function(opt_parent) { |
| 496 var volumeControls = this.createControl('volume-controls', opt_parent); | 501 var volumeControls = this.createControl('volume-controls', opt_parent); |
| 497 | 502 |
| 498 this.soundButton_ = this.createButton('sound media-control', | 503 this.soundButton_ = this.createButton('sound media-control', |
| 499 this.onSoundButtonClick_.bind(this), volumeControls); | 504 this.onSoundButtonClick_.bind(this), volumeControls); |
| 500 this.soundButton_.setAttribute('level', 3); // max level. | 505 this.soundButton_.setAttribute('level', 3); // max level. |
| 501 this.soundButton_.setAttribute('aria-label', | 506 this.soundButton_.setAttribute('aria-label', |
| 502 str('MEDIA_PLAYER_MUTE_BUTTON_LABEL')); | 507 str('MEDIA_PLAYER_MUTE_BUTTON_LABEL')); |
| 503 | 508 |
| 504 this.volume_ = /** @type {!PaperSliderElement} */ ( | 509 this.volume_ = /** @type {!PaperSliderElement} */ ( |
| 505 document.createElement('paper-slider')); | 510 document.createElement('paper-slider')); |
| 506 this.volume_.classList.add('volume', 'media-control'); | 511 this.volume_.classList.add('volume', 'media-control'); |
| 507 this.volume_.setAttribute('aria-label', | 512 this.volume_.setAttribute('aria-label', |
| 508 str('MEDIA_PLAYER_VOLUME_SLIDER_LABEL')); | 513 str('MEDIA_PLAYER_VOLUME_SLIDER_LABEL')); |
| 509 this.volume_.addEventListener('change', function(event) { | 514 this.volume_.addEventListener('change', function(event) { |
| 510 this.onVolumeChange_(this.volume_.ratio); | 515 this.onVolumeChange_(this.volume_.ratio); |
| 511 }.bind(this)); | 516 }.bind(this)); |
| 512 this.volume_.addEventListener('immediate-value-change', function(event) { | 517 this.volume_.addEventListener('immediate-value-change', function(event) { |
| 513 this.onVolumeDrag_(); | 518 this.onVolumeDrag_(); |
| 514 }.bind(this)); | 519 }.bind(this)); |
| 515 this.volume_.value = this.volume_.max; | 520 this.loadVolumeControlState(); |
| 516 volumeControls.appendChild(this.volume_); | 521 volumeControls.appendChild(this.volume_); |
| 517 }; | 522 }; |
| 518 | 523 |
| 524 MediaControls.prototype.loadVolumeControlState = function() { | |
| 525 chrome.storage.local.get([MediaControls.KEY_NORMALIZED_VOLUME], | |
| 526 function(retrieved) { | |
| 527 var normalized_volume = (MediaControls.KEY_NORMALIZED_VOLUME | |
|
oka
2016/11/29 07:13:01
Use camelCase.
https://google.github.io/styleguide
yamaguchi
2016/11/29 07:25:02
Done.
| |
| 528 in retrieved) | |
| 529 ? retrieved[MediaControls.KEY_NORMALIZED_VOLUME] : 1; | |
| 530 this.volume_.value = this.volume_.max * normalized_volume; | |
| 531 }.bind(this)); | |
| 532 }; | |
| 533 | |
| 534 MediaControls.prototype.saveVolumeControlState = function() { | |
| 535 var valuesToStore = {}; | |
| 536 valuesToStore[MediaControls.KEY_NORMALIZED_VOLUME] = this.media_.volume; | |
| 537 chrome.storage.local.set(valuesToStore); | |
| 538 }; | |
| 539 | |
| 519 /** | 540 /** |
| 520 * Click handler for the sound level button. | 541 * Click handler for the sound level button. |
| 521 * @private | 542 * @private |
| 522 */ | 543 */ |
| 523 MediaControls.prototype.onSoundButtonClick_ = function() { | 544 MediaControls.prototype.onSoundButtonClick_ = function() { |
| 524 if (this.media_.volume == 0) { | 545 if (this.media_.volume == 0) { |
| 525 this.volume_.value = (this.savedVolume_ || 1) * this.volume_.max; | 546 this.volume_.value = (this.savedVolume_ || 1) * this.volume_.max; |
| 526 this.soundButton_.setAttribute('aria-label', | 547 this.soundButton_.setAttribute('aria-label', |
| 527 str('MEDIA_PLAYER_MUTE_BUTTON_LABEL')); | 548 str('MEDIA_PLAYER_MUTE_BUTTON_LABEL')); |
| 528 } else { | 549 } else { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 552 */ | 573 */ |
| 553 MediaControls.prototype.onVolumeChange_ = function(value) { | 574 MediaControls.prototype.onVolumeChange_ = function(value) { |
| 554 if (!this.media_) | 575 if (!this.media_) |
| 555 return; // Media is detached. | 576 return; // Media is detached. |
| 556 | 577 |
| 557 this.media_.volume = value; | 578 this.media_.volume = value; |
| 558 this.soundButton_.setAttribute('level', MediaControls.getVolumeLevel_(value)); | 579 this.soundButton_.setAttribute('level', MediaControls.getVolumeLevel_(value)); |
| 559 this.soundButton_.setAttribute('aria-label', | 580 this.soundButton_.setAttribute('aria-label', |
| 560 value === 0 ? str('MEDIA_PLAYER_UNMUTE_BUTTON_LABEL') | 581 value === 0 ? str('MEDIA_PLAYER_UNMUTE_BUTTON_LABEL') |
| 561 : str('MEDIA_PLAYER_MUTE_BUTTON_LABEL')); | 582 : str('MEDIA_PLAYER_MUTE_BUTTON_LABEL')); |
| 583 this.saveVolumeControlState(); | |
| 562 }; | 584 }; |
| 563 | 585 |
| 564 /** | 586 /** |
| 565 * @private | 587 * @private |
| 566 */ | 588 */ |
| 567 MediaControls.prototype.onVolumeDrag_ = function() { | 589 MediaControls.prototype.onVolumeDrag_ = function() { |
| 568 if (this.media_.volume !== 0) { | 590 if (this.media_.volume !== 0) { |
| 569 this.savedVolume_ = this.media_.volume; | 591 this.savedVolume_ = this.media_.volume; |
| 570 } | 592 } |
| 571 }; | 593 }; |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 this.fullscreenButton_.setAttribute('aria-label', | 1115 this.fullscreenButton_.setAttribute('aria-label', |
| 1094 fullscreen ? str('VIDEO_PLAYER_EXIT_FULL_SCREEN_BUTTON_LABEL') | 1116 fullscreen ? str('VIDEO_PLAYER_EXIT_FULL_SCREEN_BUTTON_LABEL') |
| 1095 : str('VIDEO_PLAYER_FULL_SCREEN_BUTTON_LABEL'));; | 1117 : str('VIDEO_PLAYER_FULL_SCREEN_BUTTON_LABEL'));; |
| 1096 // If the fullscreen button has focus on entering fullscreen mode, reset the | 1118 // If the fullscreen button has focus on entering fullscreen mode, reset the |
| 1097 // focus to make the spacebar toggle play/pause state. This is the | 1119 // focus to make the spacebar toggle play/pause state. This is the |
| 1098 // consistent behavior with Youtube Web UI. | 1120 // consistent behavior with Youtube Web UI. |
| 1099 if (fullscreen) | 1121 if (fullscreen) |
| 1100 this.fullscreenButton_.blur(); | 1122 this.fullscreenButton_.blur(); |
| 1101 } | 1123 } |
| 1102 }; | 1124 }; |
| OLD | NEW |