OLD | NEW |
1 var captionsButtonElement; | 1 var captionsButtonElement; |
2 var captionsButtonCoordinates; | 2 var captionsButtonCoordinates; |
3 | 3 |
4 // As specified in mediaControls.css, this is how long it takes to fade out cont
rols | 4 // As specified in mediaControls.css, this is how long it takes to fade out cont
rols |
5 const controlsFadeOutDurationMs = 300; | 5 const controlsFadeOutDurationMs = 300; |
6 | 6 |
7 // The timeout for the hide-after-no-mouse-movement behavior. Defined (and | 7 // The timeout for the hide-after-no-mouse-movement behavior. Defined (and |
8 // should mirror) the value 'timeWithoutMouseMovementBeforeHidingMediaControls' | 8 // should mirror) the value 'timeWithoutMouseMovementBeforeHidingMediaControls' |
9 // in MediaControls.cpp. | 9 // in MediaControls.cpp. |
10 const controlsMouseMovementTimeoutMs = 3000; | 10 const controlsMouseMovementTimeoutMs = 3000; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return elementCoordinates(button); | 61 return elementCoordinates(button); |
62 } | 62 } |
63 | 63 |
64 function mediaControlsButtonDimensions(element, id) | 64 function mediaControlsButtonDimensions(element, id) |
65 { | 65 { |
66 var button = mediaControlsButton(element, id); | 66 var button = mediaControlsButton(element, id); |
67 var buttonBoundingRect = button.getBoundingClientRect(); | 67 var buttonBoundingRect = button.getBoundingClientRect(); |
68 return new Array(buttonBoundingRect.width, buttonBoundingRect.height); | 68 return new Array(buttonBoundingRect.width, buttonBoundingRect.height); |
69 } | 69 } |
70 | 70 |
| 71 function textTrackContainerElement(parentElement) { |
| 72 return mediaControlsElement(internals.shadowRoot(parentElement).firstChild, |
| 73 "-webkit-media-text-track-container"); |
| 74 } |
| 75 |
| 76 function textTrackCueDisplayElement(parentElement) { |
| 77 var containerElement = textTrackContainerElement(parentElement); |
| 78 return mediaControlsElement(containerElement.firstChild, "-webkit-media-text
-track-display"); |
| 79 } |
| 80 |
| 81 function textTrackCueElementByIndex(parentElement, cueIndex) { |
| 82 var displayElement = textTrackCueDisplayElement(parentElement); |
| 83 if (displayElement) { |
| 84 for (i = 0; i < cueIndex; i++) |
| 85 displayElement = displayElement.nextSibling; |
| 86 } |
| 87 |
| 88 return displayElement; |
| 89 } |
| 90 |
| 91 // TODO(srirama.m): Phase out the uses of this function and |
| 92 // replace with more specific functions at each call site. |
| 93 // For ex: textTrackDisplayElement(video, 'region') => textTrackRegionElement(vi
deo) and |
| 94 // textTrackDisplayElement(video, 'region-container') => textTrackRegionContaine
rElement(video). |
71 function textTrackDisplayElement(parentElement, id, cueNumber) | 95 function textTrackDisplayElement(parentElement, id, cueNumber) |
72 { | 96 { |
73 var textTrackContainerID = "-webkit-media-text-track-container"; | 97 var containerElement = textTrackContainerElement(parentElement); |
74 var containerElement = mediaControlsElement(internals.shadowRoot(parentEleme
nt).firstChild, textTrackContainerID); | |
75 | 98 |
76 if (!containerElement) | 99 if (!containerElement) |
77 throw "Failed to find text track container element"; | 100 throw "Failed to find text track container element"; |
78 | 101 |
79 if (!id) | 102 if (!id) |
80 return containerElement; | 103 return containerElement; |
81 | 104 |
82 if (arguments[1] != 'cue') | 105 var controlID = id; |
83 var controlID = "-webkit-media-text-track-" + arguments[1]; | 106 if (controlID != 'cue') |
84 else | 107 controlID = "-webkit-media-text-track-" + id; |
85 var controlID = arguments[1]; | |
86 | 108 |
87 var displayElement = mediaControlsElement(containerElement.firstChild, contr
olID); | 109 var displayElement = mediaControlsElement(containerElement.firstChild, contr
olID); |
88 if (!displayElement) | 110 if (!displayElement) |
89 throw "No text track cue with display id '" + controlID + "' is currentl
y visible"; | 111 throw "No text track cue with display id '" + controlID + "' is currentl
y visible"; |
90 | 112 |
91 if (cueNumber) { | 113 if (cueNumber) { |
92 for (i = 0; i < cueNumber; i++) | 114 for (i = 0; i < cueNumber; i++) |
93 displayElement = displayElement.nextSibling; | 115 displayElement = displayElement.nextSibling; |
94 | 116 |
95 if (!displayElement) | 117 if (!displayElement) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 189 } |
168 | 190 |
169 function selectTextTrack(video, index) | 191 function selectTextTrack(video, index) |
170 { | 192 { |
171 clickCCButton(); | 193 clickCCButton(); |
172 var trackListItemElement = textTrackListItemAtIndex(video, index); | 194 var trackListItemElement = textTrackListItemAtIndex(video, index); |
173 var trackListItemCoordinates = elementCoordinates(trackListItemElement); | 195 var trackListItemCoordinates = elementCoordinates(trackListItemElement); |
174 clickAtCoordinates(trackListItemCoordinates[0], trackListItemCoordinates[1])
; | 196 clickAtCoordinates(trackListItemCoordinates[0], trackListItemCoordinates[1])
; |
175 } | 197 } |
176 | 198 |
| 199 function clickTextTrackAtIndex(video, index) |
| 200 { |
| 201 var captionsButtonCoordinates = mediaControlsButtonCoordinates(video, "toggl
e-closed-captions-button"); |
| 202 clickAtCoordinates(captionsButtonCoordinates[0], captionsButtonCoordinates[1
]); |
| 203 var trackListItemElement = textTrackListItemAtIndex(video, index); |
| 204 var trackListItemCoordinates = elementCoordinates(trackListItemElement); |
| 205 clickAtCoordinates(trackListItemCoordinates[0], trackListItemCoordinates[1])
; |
| 206 } |
| 207 |
177 function turnClosedCaptionsOff(video) | 208 function turnClosedCaptionsOff(video) |
178 { | 209 { |
179 selectTextTrack(video, -1); | 210 clickTextTrackAtIndex(video, -1); |
180 } | 211 } |
181 | 212 |
182 function runAfterHideMediaControlsTimerFired(func, mediaElement) | 213 function runAfterHideMediaControlsTimerFired(func, mediaElement) |
183 { | 214 { |
184 if (mediaElement.paused) | 215 if (mediaElement.paused) |
185 throw "The media element is not playing"; | 216 throw "The media element is not playing"; |
186 | 217 |
187 // Compute the time it'll take until the controls will be invisible - | 218 // Compute the time it'll take until the controls will be invisible - |
188 // assuming playback has been started prior to invoking this | 219 // assuming playback has been started prior to invoking this |
189 // function. Allow 500ms slack. | 220 // function. Allow 500ms slack. |
190 var hideTimeoutMs = controlsMouseMovementTimeoutMs + controlsFadeOutDuration
Ms + 500; | 221 var hideTimeoutMs = controlsMouseMovementTimeoutMs + controlsFadeOutDuration
Ms + 500; |
191 | 222 |
192 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - m
ediaElement.currentTime)) | 223 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - m
ediaElement.currentTime)) |
193 throw "The media will end before the controls have been hidden"; | 224 throw "The media will end before the controls have been hidden"; |
194 | 225 |
195 setTimeout(func, hideTimeoutMs); | 226 setTimeout(func, hideTimeoutMs); |
196 } | 227 } |
OLD | NEW |