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 29 matching lines...) Expand all Loading... |
40 | 40 |
41 function mediaControlsButton(element, id) | 41 function mediaControlsButton(element, id) |
42 { | 42 { |
43 var controlID = "-webkit-media-controls-" + id; | 43 var controlID = "-webkit-media-controls-" + id; |
44 var button = mediaControlsElement(internals.shadowRoot(element).firstChild,
controlID); | 44 var button = mediaControlsElement(internals.shadowRoot(element).firstChild,
controlID); |
45 if (!button) | 45 if (!button) |
46 throw "Failed to find media control element ID '" + id + "'"; | 46 throw "Failed to find media control element ID '" + id + "'"; |
47 return button; | 47 return button; |
48 } | 48 } |
49 | 49 |
| 50 function elementCoordinates(element) |
| 51 { |
| 52 var elementBoundingRect = element.getBoundingClientRect(); |
| 53 var x = elementBoundingRect.left + elementBoundingRect.width / 2; |
| 54 var y = elementBoundingRect.top + elementBoundingRect.height / 2; |
| 55 return new Array(x, y); |
| 56 } |
| 57 |
50 function mediaControlsButtonCoordinates(element, id) | 58 function mediaControlsButtonCoordinates(element, id) |
51 { | 59 { |
52 var button = mediaControlsButton(element, id); | 60 var button = mediaControlsButton(element, id); |
53 var buttonBoundingRect = button.getBoundingClientRect(); | 61 return elementCoordinates(button); |
54 var x = buttonBoundingRect.left + buttonBoundingRect.width / 2; | |
55 var y = buttonBoundingRect.top + buttonBoundingRect.height / 2; | |
56 return new Array(x, y); | |
57 } | 62 } |
58 | 63 |
59 function mediaControlsButtonDimensions(element, id) | 64 function mediaControlsButtonDimensions(element, id) |
60 { | 65 { |
61 var button = mediaControlsButton(element, id); | 66 var button = mediaControlsButton(element, id); |
62 var buttonBoundingRect = button.getBoundingClientRect(); | 67 var buttonBoundingRect = button.getBoundingClientRect(); |
63 return new Array(buttonBoundingRect.width, buttonBoundingRect.height); | 68 return new Array(buttonBoundingRect.width, buttonBoundingRect.height); |
64 } | 69 } |
65 | 70 |
66 function textTrackDisplayElement(parentElement, id, cueNumber) | 71 function textTrackDisplayElement(parentElement, id, cueNumber) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 testExpected("captionsButtonCoordinates[0]", 0, ">"); | 117 testExpected("captionsButtonCoordinates[0]", 0, ">"); |
113 testExpected("captionsButtonCoordinates[1]", 0, ">"); | 118 testExpected("captionsButtonCoordinates[1]", 0, ">"); |
114 testExpected("captionsButtonElement.disabled", false); | 119 testExpected("captionsButtonElement.disabled", false); |
115 } else { | 120 } else { |
116 consoleWrite("** Caption button should not be visible."); | 121 consoleWrite("** Caption button should not be visible."); |
117 testExpected("captionsButtonCoordinates[0]", 0, "<="); | 122 testExpected("captionsButtonCoordinates[0]", 0, "<="); |
118 testExpected("captionsButtonCoordinates[1]", 0, "<="); | 123 testExpected("captionsButtonCoordinates[1]", 0, "<="); |
119 } | 124 } |
120 } | 125 } |
121 | 126 |
| 127 function clickAtCoordinates(x, y) |
| 128 { |
| 129 eventSender.mouseMoveTo(x, y); |
| 130 eventSender.mouseDown(); |
| 131 eventSender.mouseUp(); |
| 132 } |
| 133 |
122 function clickCCButton() | 134 function clickCCButton() |
123 { | 135 { |
124 consoleWrite("*** Click the CC button."); | 136 consoleWrite("*** Click the CC button."); |
125 eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordina
tes[1]); | 137 clickAtCoordinates(captionsButtonCoordinates[0], captionsButtonCoordinates[1
]); |
126 eventSender.mouseDown(); | 138 } |
127 eventSender.mouseUp(); | 139 |
| 140 function textTrackListItemAtIndex(video, index) |
| 141 { |
| 142 var textTrackListElementID = "-internal-media-controls-text-track-list"; |
| 143 var textTrackListElement = mediaControlsElement(internals.shadowRoot(video).
firstChild, textTrackListElementID); |
| 144 if (!textTrackListElement) |
| 145 throw "Failed to find text track list element"; |
| 146 |
| 147 var trackListItems = textTrackListElement.childNodes; |
| 148 for (var i = 0; i < trackListItems.length; i++) { |
| 149 var trackListItem = trackListItems[i]; |
| 150 if (trackListItem.firstChild.getAttribute("data-track-index") == index) |
| 151 return trackListItem; |
| 152 } |
| 153 } |
| 154 |
| 155 function selectTextTrack(video, index) |
| 156 { |
| 157 clickCCButton(); |
| 158 var trackListItemElement = textTrackListItemAtIndex(video, index); |
| 159 var trackListItemCoordinates = elementCoordinates(trackListItemElement); |
| 160 clickAtCoordinates(trackListItemCoordinates[0], trackListItemCoordinates[1])
; |
| 161 } |
| 162 |
| 163 function turnClosedCaptionsOff(video) |
| 164 { |
| 165 selectTextTrack(video, -1); |
128 } | 166 } |
129 | 167 |
130 function runAfterHideMediaControlsTimerFired(func, mediaElement) | 168 function runAfterHideMediaControlsTimerFired(func, mediaElement) |
131 { | 169 { |
132 if (mediaElement.paused) | 170 if (mediaElement.paused) |
133 throw "The media element is not playing"; | 171 throw "The media element is not playing"; |
134 | 172 |
135 // Compute the time it'll take until the controls will be invisible - | 173 // Compute the time it'll take until the controls will be invisible - |
136 // assuming playback has been started prior to invoking this | 174 // assuming playback has been started prior to invoking this |
137 // function. Allow 500ms slack. | 175 // function. Allow 500ms slack. |
138 var hideTimeoutMs = controlsMouseMovementTimeoutMs + controlsFadeOutDuration
Ms + 500; | 176 var hideTimeoutMs = controlsMouseMovementTimeoutMs + controlsFadeOutDuration
Ms + 500; |
139 | 177 |
140 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - m
ediaElement.currentTime)) | 178 if (!mediaElement.loop && hideTimeoutMs >= 1000 * (mediaElement.duration - m
ediaElement.currentTime)) |
141 throw "The media will end before the controls have been hidden"; | 179 throw "The media will end before the controls have been hidden"; |
142 | 180 |
143 setTimeout(func, hideTimeoutMs); | 181 setTimeout(func, hideTimeoutMs); |
144 } | 182 } |
OLD | NEW |