Source: ui/recenter_vr.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.ui.RecenterVRButton');
  7. goog.require('shaka.ui.Controls');
  8. goog.require('shaka.ui.Element');
  9. goog.require('shaka.ui.Enums');
  10. goog.require('shaka.ui.Locales');
  11. goog.require('shaka.ui.Localization');
  12. goog.require('shaka.ui.OverflowMenu');
  13. goog.require('shaka.ui.Utils');
  14. goog.require('shaka.util.Dom');
  15. goog.requireType('shaka.ui.Controls');
  16. /**
  17. * @extends {shaka.ui.Element}
  18. * @final
  19. * @export
  20. */
  21. shaka.ui.RecenterVRButton = class extends shaka.ui.Element {
  22. /**
  23. * @param {!HTMLElement} parent
  24. * @param {!shaka.ui.Controls} controls
  25. */
  26. constructor(parent, controls) {
  27. super(parent, controls);
  28. /** @private {!HTMLButtonElement} */
  29. this.recenterVRButton_ = shaka.util.Dom.createButton();
  30. this.recenterVRButton_.classList.add('shaka-recenter-vr-button');
  31. this.recenterVRButton_.classList.add('shaka-tooltip');
  32. this.recenterVRButton_.ariaPressed = 'false';
  33. /** @private {!HTMLElement} */
  34. this.recenterVRIcon_ = shaka.util.Dom.createHTMLElement('i');
  35. this.recenterVRIcon_.classList.add('material-icons-round');
  36. this.recenterVRIcon_.textContent =
  37. shaka.ui.Enums.MaterialDesignIcons.RECENTER_VR;
  38. this.recenterVRButton_.appendChild(this.recenterVRIcon_);
  39. const label = shaka.util.Dom.createHTMLElement('label');
  40. label.classList.add('shaka-overflow-button-label');
  41. label.classList.add('shaka-overflow-menu-only');
  42. this.recenterVRNameSpan_ = shaka.util.Dom.createHTMLElement('span');
  43. label.appendChild(this.recenterVRNameSpan_);
  44. this.recenterVRCurrentSelectionSpan_ =
  45. shaka.util.Dom.createHTMLElement('span');
  46. this.recenterVRCurrentSelectionSpan_.classList.add(
  47. 'shaka-current-selection-span');
  48. label.appendChild(this.recenterVRCurrentSelectionSpan_);
  49. this.recenterVRButton_.appendChild(label);
  50. this.parent.appendChild(this.recenterVRButton_);
  51. // Setup strings in the correct language
  52. this.updateLocalizedStrings_();
  53. this.eventManager.listen(
  54. this.localization, shaka.ui.Localization.LOCALE_UPDATED, () => {
  55. this.updateLocalizedStrings_();
  56. });
  57. this.eventManager.listen(
  58. this.localization, shaka.ui.Localization.LOCALE_CHANGED, () => {
  59. this.updateLocalizedStrings_();
  60. });
  61. const vr = this.controls.getVR();
  62. this.eventManager.listen(this.recenterVRButton_, 'click', () => {
  63. vr.reset();
  64. });
  65. this.eventManager.listen(vr, 'vrstatuschanged', () => {
  66. this.checkAvailability_();
  67. });
  68. this.checkAvailability_();
  69. }
  70. /**
  71. * @private
  72. */
  73. checkAvailability_() {
  74. shaka.ui.Utils.setDisplay(this.recenterVRButton_,
  75. this.controls.isPlayingVR());
  76. }
  77. /**
  78. * @private
  79. */
  80. updateLocalizedStrings_() {
  81. const LocIds = shaka.ui.Locales.Ids;
  82. this.recenterVRButton_.ariaLabel =
  83. this.localization.resolve(LocIds.RECENTER_VR);
  84. this.recenterVRNameSpan_.textContent =
  85. this.localization.resolve(LocIds.RECENTER_VR);
  86. }
  87. };
  88. /**
  89. * @implements {shaka.extern.IUIElement.Factory}
  90. * @final
  91. */
  92. shaka.ui.RecenterVRButton.Factory = class {
  93. /** @override */
  94. create(rootElement, controls) {
  95. return new shaka.ui.RecenterVRButton(rootElement, controls);
  96. }
  97. };
  98. shaka.ui.OverflowMenu.registerElement(
  99. 'recenter_vr', new shaka.ui.RecenterVRButton.Factory());
  100. shaka.ui.Controls.registerElement(
  101. 'recenter_vr', new shaka.ui.RecenterVRButton.Factory());