Source: ui/fullscreen_button.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.ui.FullscreenButton');
  7. goog.require('shaka.ads.Utils');
  8. goog.require('shaka.ui.Controls');
  9. goog.require('shaka.ui.Element');
  10. goog.require('shaka.ui.Enums');
  11. goog.require('shaka.ui.Locales');
  12. goog.require('shaka.ui.Localization');
  13. goog.require('shaka.util.Dom');
  14. /**
  15. * @extends {shaka.ui.Element}
  16. * @final
  17. * @export
  18. */
  19. shaka.ui.FullscreenButton = class extends shaka.ui.Element {
  20. /**
  21. * @param {!HTMLElement} parent
  22. * @param {!shaka.ui.Controls} controls
  23. */
  24. constructor(parent, controls) {
  25. super(parent, controls);
  26. /** @private {HTMLMediaElement} */
  27. this.localVideo_ = this.controls.getLocalVideo();
  28. /** @private {!HTMLButtonElement} */
  29. this.button_ = shaka.util.Dom.createButton();
  30. this.button_.classList.add('shaka-fullscreen-button');
  31. this.button_.classList.add('material-icons-round');
  32. this.button_.classList.add('shaka-tooltip');
  33. this.checkSupport_();
  34. this.button_.textContent = shaka.ui.Enums.MaterialDesignIcons.FULLSCREEN;
  35. this.parent.appendChild(this.button_);
  36. this.updateAriaLabel_();
  37. this.eventManager.listen(
  38. this.localization, shaka.ui.Localization.LOCALE_UPDATED, () => {
  39. this.updateAriaLabel_();
  40. });
  41. this.eventManager.listen(
  42. this.localization, shaka.ui.Localization.LOCALE_CHANGED, () => {
  43. this.updateAriaLabel_();
  44. });
  45. this.eventManager.listen(this.button_, 'click', async () => {
  46. await this.controls.toggleFullScreen();
  47. });
  48. this.eventManager.listen(document, 'fullscreenchange', () => {
  49. this.updateIcon_();
  50. this.updateAriaLabel_();
  51. });
  52. this.eventManager.listen(this.localVideo_, 'loadedmetadata', () => {
  53. this.checkSupport_();
  54. });
  55. this.eventManager.listen(this.localVideo_, 'loadeddata', () => {
  56. this.checkSupport_();
  57. });
  58. this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_STARTED, () => {
  59. this.checkSupport_();
  60. });
  61. this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_STOPPED, () => {
  62. this.checkSupport_();
  63. });
  64. }
  65. /**
  66. * @private
  67. */
  68. checkSupport_() {
  69. // Don't show the button if fullscreen is not supported
  70. if (!this.controls.isFullScreenSupported()) {
  71. this.button_.classList.add('shaka-hidden');
  72. } else {
  73. this.button_.classList.remove('shaka-hidden');
  74. }
  75. }
  76. /**
  77. * @private
  78. */
  79. updateAriaLabel_() {
  80. const LocIds = shaka.ui.Locales.Ids;
  81. const label = this.controls.isFullScreenEnabled() ?
  82. LocIds.EXIT_FULL_SCREEN : LocIds.FULL_SCREEN;
  83. this.button_.ariaLabel = this.localization.resolve(label);
  84. }
  85. /**
  86. * @private
  87. */
  88. updateIcon_() {
  89. this.button_.textContent =
  90. this.controls.isFullScreenEnabled() ?
  91. shaka.ui.Enums.MaterialDesignIcons.EXIT_FULLSCREEN :
  92. shaka.ui.Enums.MaterialDesignIcons.FULLSCREEN;
  93. }
  94. };
  95. /**
  96. * @implements {shaka.extern.IUIElement.Factory}
  97. * @final
  98. */
  99. shaka.ui.FullscreenButton.Factory = class {
  100. /** @override */
  101. create(rootElement, controls) {
  102. return new shaka.ui.FullscreenButton(rootElement, controls);
  103. }
  104. };
  105. shaka.ui.Controls.registerElement(
  106. 'fullscreen', new shaka.ui.FullscreenButton.Factory());