Chromium Code Reviews| 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 containerElement = textTrackContainerElement(parentElement); | |
| 83 var displayElement = mediaControlsElement(containerElement.firstChild, "-web kit-media-text-track-display"); | |
|
foolip
2016/07/06 10:00:47
Can this just call textTrackCueDisplayElement(pare
Srirama
2016/07/06 11:35:49
Done.
| |
| 84 if (displayElement) { | |
| 85 for (i = 0; i < cueIndex; i++) | |
| 86 displayElement = displayElement.nextSibling; | |
| 87 } | |
| 88 | |
| 89 return displayElement; | |
| 90 } | |
| 91 | |
| 92 // TODO(srirama.m): Phase out the uses of this function and | |
| 93 // replace with more specific functions at each call site. | |
| 94 // For ex: textTrackDisplayElement(video, 'region') => textTrackRegionElement(vi deo) and | |
| 95 // textTrackDisplayElement(video, 'region-container') => textTrackRegionContaine rElement(video). | |
| 71 function textTrackDisplayElement(parentElement, id, cueNumber) | 96 function textTrackDisplayElement(parentElement, id, cueNumber) |
| 72 { | 97 { |
| 73 var textTrackContainerID = "-webkit-media-text-track-container"; | 98 var containerElement = textTrackContainerElement(parentElement); |
| 74 var containerElement = mediaControlsElement(internals.shadowRoot(parentEleme nt).firstChild, textTrackContainerID); | |
| 75 | 99 |
| 76 if (!containerElement) | 100 if (!containerElement) |
| 77 throw "Failed to find text track container element"; | 101 throw "Failed to find text track container element"; |
| 78 | 102 |
| 79 if (!id) | 103 if (!id) |
| 80 return containerElement; | 104 return containerElement; |
| 81 | 105 |
| 82 if (arguments[1] != 'cue') | 106 var controlID = id; |
| 83 var controlID = "-webkit-media-text-track-" + arguments[1]; | 107 if (controlID != 'cue') |
| 84 else | 108 controlID = "-webkit-media-text-track-" + id; |
| 85 var controlID = arguments[1]; | |
| 86 | 109 |
| 87 var displayElement = mediaControlsElement(containerElement.firstChild, contr olID); | 110 var displayElement = mediaControlsElement(containerElement.firstChild, contr olID); |
| 88 if (!displayElement) | 111 if (!displayElement) |
| 89 throw "No text track cue with display id '" + controlID + "' is currentl y visible"; | 112 throw "No text track cue with display id '" + controlID + "' is currentl y visible"; |
| 90 | 113 |
| 91 if (cueNumber) { | 114 if (cueNumber) { |
| 92 for (i = 0; i < cueNumber; i++) | 115 for (i = 0; i < cueNumber; i++) |
| 93 displayElement = displayElement.nextSibling; | 116 displayElement = displayElement.nextSibling; |
| 94 | 117 |
| 95 if (!displayElement) | 118 if (!displayElement) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 } | 190 } |
| 168 | 191 |
| 169 function selectTextTrack(video, index) | 192 function selectTextTrack(video, index) |
| 170 { | 193 { |
| 171 clickCCButton(); | 194 clickCCButton(); |
| 172 var trackListItemElement = textTrackListItemAtIndex(video, index); | 195 var trackListItemElement = textTrackListItemAtIndex(video, index); |
| 173 var trackListItemCoordinates = elementCoordinates(trackListItemElement); | 196 var trackListItemCoordinates = elementCoordinates(trackListItemElement); |
| 174 clickAtCoordinates(trackListItemCoordinates[0], trackListItemCoordinates[1]) ; | 197 clickAtCoordinates(trackListItemCoordinates[0], trackListItemCoordinates[1]) ; |
| 175 } | 198 } |
| 176 | 199 |
| 200 function clickTextTrackAtIndex(video, index) | |
| 201 { | |
| 202 var captionsButtonCoordinates = mediaControlsButtonCoordinates(video, "toggl e-closed-captions-button"); | |
| 203 clickAtCoordinates(captionsButtonCoordinates[0], captionsButtonCoordinates[1 ]); | |
| 204 var trackListItemElement = textTrackListItemAtIndex(video, index); | |
| 205 var trackListItemCoordinates = elementCoordinates(trackListItemElement); | |
| 206 clickAtCoordinates(trackListItemCoordinates[0], trackListItemCoordinates[1]) ; | |
| 207 } | |
| 208 | |
| 177 function turnClosedCaptionsOff(video) | 209 function turnClosedCaptionsOff(video) |
| 178 { | 210 { |
| 179 selectTextTrack(video, -1); | 211 clickTextTrackAtIndex(video, -1); |
| 180 } | 212 } |
| 181 | 213 |
| 182 function runAfterHideMediaControlsTimerFired(func, mediaElement) | 214 function runAfterHideMediaControlsTimerFired(func, mediaElement) |
| 183 { | 215 { |
| 184 if (mediaElement.paused) | 216 if (mediaElement.paused) |
| 185 throw "The media element is not playing"; | 217 throw "The media element is not playing"; |
| 186 | 218 |
| 187 // Compute the time it'll take until the controls will be invisible - | 219 // Compute the time it'll take until the controls will be invisible - |
| 188 // assuming playback has been started prior to invoking this | 220 // assuming playback has been started prior to invoking this |
| 189 // function. Allow 500ms slack. | 221 // function. Allow 500ms slack. |
| 190 var hideTimeoutMs = controlsMouseMovementTimeoutMs + controlsFadeOutDuration Ms + 500; | 222 var hideTimeoutMs = controlsMouseMovementTimeoutMs + controlsFadeOutDuration Ms + 500; |
| 191 | 223 |
| 192 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - m ediaElement.currentTime)) | 224 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - m ediaElement.currentTime)) |
| 193 throw "The media will end before the controls have been hidden"; | 225 throw "The media will end before the controls have been hidden"; |
| 194 | 226 |
| 195 setTimeout(func, hideTimeoutMs); | 227 setTimeout(func, hideTimeoutMs); |
| 196 } | 228 } |
| OLD | NEW |