Source: ui/externs/ui.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @externs
  19. * @suppress {duplicate} To prevent compiler errors with the namespace
  20. * being declared both here and by goog.provide in the library.
  21. */
  22. /** @namespace */
  23. var shaka = {};
  24. /** @namespace */
  25. shaka.extern = {};
  26. /**
  27. * @typedef {{
  28. * base: string,
  29. * buffered: string,
  30. * played: string
  31. * }}
  32. *
  33. * @property {string} base
  34. * The CSS background color applied to the base of the seek bar, on top of
  35. * which the buffer level and playback position are shown.
  36. * @property {string} buffered
  37. * The CSS background color applied to the portion of the seek bar showing
  38. * what has been buffered ahead of the playback position.
  39. * @property {string} played
  40. * The CSS background color applied to the portion of the seek bar showing
  41. * what has been played already.
  42. * @exportDoc
  43. */
  44. shaka.extern.UISeekBarColors;
  45. /**
  46. * @typedef {{
  47. * base: string,
  48. * level: string
  49. * }}
  50. *
  51. * @property {string} base
  52. * The CSS background color applied to the base of the volume bar, on top of
  53. * which the volume level is shown.
  54. * @property {string} level
  55. * The CSS background color applied to the portion of the volume bar showing
  56. * the volume level.
  57. * @exportDoc
  58. */
  59. shaka.extern.UIVolumeBarColors;
  60. /**
  61. * @description
  62. * The UI's configuration options.
  63. *
  64. * @typedef {{
  65. * controlPanelElements: !Array.<string>,
  66. * overflowMenuButtons: !Array.<string>,
  67. * addSeekBar: boolean,
  68. * addBigPlayButton: boolean,
  69. * castReceiverAppId: string,
  70. * clearBufferOnQualityChange: boolean,
  71. * showUnbufferedStart: boolean,
  72. * seekBarColors: shaka.extern.UISeekBarColors,
  73. * volumeBarColors: shaka.extern.UIVolumeBarColors,
  74. * trackLabelFormat: shaka.ui.Overlay.TrackLabelFormat,
  75. * fadeDelay: number,
  76. * doubleClickForFullscreen: boolean,
  77. * enableKeyboardPlaybackControls: boolean,
  78. * enableFullscreenOnRotation: boolean
  79. * }}
  80. *
  81. * @property {!Array.<string>} controlPanelElements
  82. * The ordered list of control panel elements of the UI.
  83. * @property {!Array.<string>} overflowMenuButtons
  84. * The ordered list of the overflow menu buttons.
  85. * @property {boolean} addSeekBar
  86. * Whether or not a seek bar should be part of the UI.
  87. * @property {boolean} addBigPlayButton
  88. * Whether or not a big play button in the center of the video
  89. * should be part of the UI.
  90. * @property {string} castReceiverAppId
  91. * Receiver app id to use for the Chromecast support.
  92. * @property {boolean} clearBufferOnQualityChange
  93. * Only applicable if the resolution selection is part of the UI.
  94. * Whether buffer should be cleared when changing resolution
  95. * via UI. Clearing buffer would result in immidiate change of quality,
  96. * but playback may flicker/stall for a sec as the content in new
  97. * resolution is being buffered. Not clearing the buffer will mean
  98. * we play the content in the previously selected resolution that we
  99. * already have buffered before switching to the new resolution.
  100. * @property {boolean} showUnbufferedStart
  101. * If true, color any unbuffered region at the start of the seek bar as
  102. * unbuffered (using the "base" color). If false, color any unbuffered region
  103. * at the start of the seek bar as played (using the "played" color).
  104. * <br>
  105. * A value of false matches the default behavior of Chrome's native controls
  106. * and Shaka Player v3.0+.
  107. * <br>
  108. * A value of true matches the default behavior of Shaka Player v2.5.
  109. * <br>
  110. * Defaults to true in v2.5. Will default to false in v3.0+.
  111. * @property {shaka.extern.UISeekBarColors} seekBarColors
  112. * The CSS colors applied to the seek bar. This allows you to override the
  113. * colors used in the linear gradient constructed in JavaScript, since you
  114. * cannot easily do this in pure CSS.
  115. * @property {shaka.extern.UIVolumeBarColors} volumeBarColors
  116. * The CSS colors applied to the volume bar. This allows you to override the
  117. * colors used in the linear gradient constructed in JavaScript, since you
  118. * cannot do this in pure CSS.
  119. * @property {shaka.ui.Overlay.TrackLabelFormat} trackLabelFormat
  120. * An enum that determines what is shown in the labels for text track and
  121. * audio variant selection.
  122. * LANGUAGE means that only the language of the item is shown.
  123. * ROLE means that only the role of the item is shown.
  124. * LANGUAGE_ROLE means both are shown, or just language if there is no role.
  125. * Defaults to LANGUAGE.
  126. * @property {number} fadeDelay
  127. * The delay (in seconds) before fading out the controls once the user stops
  128. * interacting with them. We recommend setting this to 3 on your cast
  129. * receiver UI.
  130. * Defaults to 0.
  131. * @property {boolean} doubleClickForFullscreen
  132. * Whether or not double-clicking on the UI should cause it to enter
  133. * fullscreen.
  134. * Defaults to true.
  135. * @property {boolean} enableKeyboardPlaybackControls
  136. * Whether or not playback controls via keyboard is enabled, such as seek
  137. * forward, seek backward, jump to the beginning/end of the video.
  138. * Defaults to true.
  139. * @property {boolean} enableFullscreenOnRotation
  140. * Whether or not to enter/exit fullscreen mode when the screen is rotated.
  141. * Defaults to true.
  142. * @exportDoc
  143. */
  144. shaka.extern.UIConfiguration;
  145. /**
  146. * Interface for UI elements.
  147. *
  148. * @extends {shaka.util.IDestroyable}
  149. * @interface
  150. * @exportDoc
  151. */
  152. shaka.extern.IUIElement = class {
  153. /**
  154. * @param {!HTMLElement} parent
  155. * @param {!shaka.ui.Controls} controls
  156. */
  157. constructor(parent, controls) {
  158. /**
  159. * @protected {HTMLElement}
  160. * @exportDoc
  161. */
  162. this.parent;
  163. /**
  164. * @protected {shaka.ui.Controls}
  165. * @exportDoc
  166. */
  167. this.controls;
  168. /**
  169. * @protected {shaka.util.EventManager}
  170. * @exportDoc
  171. */
  172. this.eventManager;
  173. /**
  174. * @protected {shaka.ui.Localization}
  175. * @exportDoc
  176. */
  177. this.localization;
  178. /**
  179. * @protected {shaka.Player}
  180. * @exportDoc
  181. */
  182. this.player;
  183. /**
  184. * @protected {HTMLMediaElement}
  185. * @exportDoc
  186. */
  187. this.video;
  188. }
  189. /**
  190. * @override
  191. */
  192. destroy() {}
  193. };
  194. /**
  195. * A factory for creating a UI element.
  196. *
  197. * @interface
  198. * @exportDoc
  199. */
  200. shaka.extern.IUIElement.Factory = class {
  201. /**
  202. * @param {!HTMLElement} rootElement
  203. * @param {!shaka.ui.Controls} controls
  204. * @return {!shaka.extern.IUIElement}
  205. */
  206. create(rootElement, controls) {}
  207. };
  208. /**
  209. * Interface for UI range elements. UI range elements should inherit from the
  210. * concrete base class shaka.ui.RangeElement. The members defined in this
  211. * extern's constructor are all available from the base class, and are defined
  212. * here to keep the compiler from renaming them.
  213. *
  214. * @extends {shaka.extern.IUIElement}
  215. * @interface
  216. * @exportDoc
  217. */
  218. shaka.extern.IUIRangeElement = class {
  219. /**
  220. * @param {!HTMLElement} parent
  221. * @param {!shaka.ui.Controls} controls
  222. * @param {!Array.<string>} containerClassNames
  223. * @param {!Array.<string>} barClassNames
  224. */
  225. constructor(parent, controls, containerClassNames, barClassNames) {
  226. /**
  227. * @protected {!HTMLElement}
  228. * @exportDoc
  229. */
  230. this.container;
  231. /**
  232. * @protected {!HTMLInputElement}
  233. * @exportDoc
  234. */
  235. this.bar;
  236. }
  237. /**
  238. * @param {number} min
  239. * @param {number} max
  240. */
  241. setRange(min, max) {}
  242. /**
  243. * Called when user interaction begins.
  244. * To be overridden by subclasses.
  245. */
  246. onChangeStart() {}
  247. /**
  248. * Called when a new value is set by user interaction.
  249. * To be overridden by subclasses.
  250. */
  251. onChange() {}
  252. /**
  253. * Called when user interaction ends.
  254. * To be overridden by subclasses.
  255. */
  256. onChangeEnd() {}
  257. /** @return {number} */
  258. getValue() {}
  259. /** @param {number} value */
  260. setValue(value) {}
  261. /** @param {number} value */
  262. changeTo(value) {}
  263. };
  264. /**
  265. * Interface for UI settings menus. UI settings menus should inherit from the
  266. * concrete base class shaka.ui.SettingsMenu. The members defined in this
  267. * extern's constructor are all available from the base class, and are defined
  268. * here to keep the compiler from renaming them.
  269. *
  270. * @extends {shaka.extern.IUIElement}
  271. * @interface
  272. * @exportDoc
  273. */
  274. shaka.extern.IUISettingsMenu = class {
  275. /**
  276. * @param {!HTMLElement} parent
  277. * @param {!shaka.ui.Controls} controls
  278. * @param {string} iconText
  279. */
  280. constructor(parent, controls, iconText) {
  281. /**
  282. * @protected {!HTMLButtonElement}
  283. * @exportDoc
  284. */
  285. this.button;
  286. /**
  287. * @protected {!HTMLElement}
  288. * @exportDoc
  289. */
  290. this.icon;
  291. /**
  292. * @protected {!HTMLElement}
  293. * @exportDoc
  294. */
  295. this.nameSpan;
  296. /**
  297. * @protected {!HTMLElement}
  298. * @exportDoc
  299. */
  300. this.currentSelection;
  301. /**
  302. * @protected {!HTMLElement}
  303. * @exportDoc
  304. */
  305. this.menu;
  306. /**
  307. * @protected {!HTMLButtonElement}
  308. * @exportDoc
  309. */
  310. this.backButton;
  311. /**
  312. * @protected {!HTMLElement}
  313. * @exportDoc
  314. */
  315. this.backSpan;
  316. }
  317. };