Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: Source/core/html/shadow/MediaControls.cpp

Issue 456323002: [WIP] Re-implement MediaControls in Blink-in-JS (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 10 matching lines...) Expand all
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/html/shadow/MediaControls.h" 28 #include "core/html/shadow/MediaControls.h"
29 29
30 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 30 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
31 #include "bindings/core/v8/V8MediaControls.h"
32 #include "bindings/core/v8/PrivateScriptRunner.h"
31 #include "core/events/MouseEvent.h" 33 #include "core/events/MouseEvent.h"
32 #include "core/frame/Settings.h" 34 #include "core/frame/Settings.h"
33 #include "core/html/HTMLMediaElement.h" 35 #include "core/html/HTMLMediaElement.h"
36 #include "core/html/HTMLVideoElement.h"
34 #include "core/html/MediaController.h" 37 #include "core/html/MediaController.h"
35 #include "core/rendering/RenderTheme.h" 38 #include "core/rendering/RenderTheme.h"
39 #include "core/rendering/RenderVideo.h"
40 #include "wtf/text/Base64.h"
36 41
37 namespace blink { 42 namespace blink {
38 43
39 // If you change this value, then also update the corresponding value in 44 // If you change this value, then also update the corresponding value in
40 // LayoutTests/media/media-controls.js. 45 // LayoutTests/media/media-controls.js.
41 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; 46 //static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3;
42 47
43 static bool fullscreenIsSupported(const Document& document) 48 static bool fullscreenIsSupported(const Document& document)
44 { 49 {
45 return !document.settings() || document.settings()->fullscreenSupported(); 50 return !document.settings() || document.settings()->fullscreenSupported();
46 } 51 }
47 52
48 MediaControls::MediaControls(HTMLMediaElement& mediaElement) 53 MediaControls::MediaControls(HTMLMediaElement& mediaElement)
49 : HTMLDivElement(mediaElement.document()) 54 : HTMLDivElement(mediaElement.document())
50 , m_mediaElement(&mediaElement) 55 , m_mediaElement(&mediaElement)
51 , m_panel(nullptr) 56 , m_panel(nullptr)
52 , m_textDisplayContainer(nullptr) 57 , m_textDisplayContainer(nullptr)
53 , m_overlayPlayButton(nullptr) 58 , m_overlayPlayButton(nullptr)
54 , m_overlayEnclosure(nullptr) 59 , m_overlayEnclosure(nullptr)
55 , m_playButton(nullptr) 60 , m_playButton(nullptr)
56 , m_currentTimeDisplay(nullptr) 61 , m_currentTimeDisplay(nullptr)
57 , m_timeline(nullptr) 62 , m_timeline(nullptr)
58 , m_muteButton(nullptr) 63 , m_muteButton(nullptr)
59 , m_volumeSlider(nullptr) 64 , m_volumeSlider(nullptr)
60 , m_toggleClosedCaptionsButton(nullptr) 65 , m_toggleClosedCaptionsButton(nullptr)
61 , m_fullScreenButton(nullptr) 66 , m_fullScreenButton(nullptr)
62 , m_durationDisplay(nullptr) 67 , m_durationDisplay(nullptr)
63 , m_enclosure(nullptr) 68 , m_enclosure(nullptr)
64 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired ) 69 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired )
65 , m_isMouseOverControls(false) 70 //, m_isMouseOverControls(false)
66 , m_isPausedForScrubbing(false) 71 //, m_isPausedForScrubbing(false)
67 { 72 {
73 ScriptWrappable::init(this);
74 v8::Handle<v8::Value> classObject = PrivateScriptRunner::installClassIfNeede d(document().frame(), "MediaControls");
75 RELEASE_ASSERT(!classObject.IsEmpty());
68 } 76 }
69 77
70 PassRefPtrWillBeRawPtr<MediaControls> MediaControls::create(HTMLMediaElement& me diaElement) 78 PassRefPtrWillBeRawPtr<MediaControls> MediaControls::create(HTMLMediaElement& me diaElement)
71 { 79 {
72 RefPtrWillBeRawPtr<MediaControls> controls = adoptRefWillBeNoop(new MediaCon trols(mediaElement)); 80 RefPtrWillBeRawPtr<MediaControls> controls = adoptRefWillBeNoop(new MediaCon trols(mediaElement));
73 81
74 if (controls->initializeControls()) 82 /*if (!controls->initializeControls())
75 return controls.release(); 83 return nullptr;*/
76 84
77 return nullptr; 85 PassRefPtrWillBeRawPtr<HTMLMediaElement> media(&mediaElement);
86 if (!V8MediaControls::PrivateScript::createdCallbackMethod(controls->documen t().frame(), controls.get(), media))
87 return nullptr;
88
89 return controls.release();
78 } 90 }
79 91
80 bool MediaControls::initializeControls() 92 bool MediaControls::initializeControls()
81 { 93 {
82 TrackExceptionState exceptionState; 94 TrackExceptionState exceptionState;
83 95
84 if (document().settings() && document().settings()->mediaControlsOverlayPlay ButtonEnabled()) { 96 if (document().settings() && document().settings()->mediaControlsOverlayPlay ButtonEnabled()) {
85 RefPtrWillBeRawPtr<MediaControlOverlayEnclosureElement> overlayEnclosure = MediaControlOverlayEnclosureElement::create(*this); 97 RefPtrWillBeRawPtr<MediaControlOverlayEnclosureElement> overlayEnclosure = MediaControlOverlayEnclosureElement::create(*this);
86 RefPtrWillBeRawPtr<MediaControlOverlayPlayButtonElement> overlayPlayButt on = MediaControlOverlayPlayButtonElement::create(*this); 98 RefPtrWillBeRawPtr<MediaControlOverlayPlayButtonElement> overlayPlayButt on = MediaControlOverlayPlayButtonElement::create(*this);
87 m_overlayPlayButton = overlayPlayButton.get(); 99 m_overlayPlayButton = overlayPlayButton.get();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 m_enclosure = enclosure.get(); 169 m_enclosure = enclosure.get();
158 appendChild(enclosure.release(), exceptionState); 170 appendChild(enclosure.release(), exceptionState);
159 if (exceptionState.hadException()) 171 if (exceptionState.hadException())
160 return false; 172 return false;
161 173
162 return true; 174 return true;
163 } 175 }
164 176
165 void MediaControls::reset() 177 void MediaControls::reset()
166 { 178 {
167 double duration = mediaElement().duration(); 179 /*double duration = mediaElement().duration();
168 m_durationDisplay->setInnerText(RenderTheme::theme().formatMediaControlsTime (duration), ASSERT_NO_EXCEPTION); 180 m_durationDisplay->setInnerText(RenderTheme::theme().formatMediaControlsTime (duration), ASSERT_NO_EXCEPTION);
169 m_durationDisplay->setCurrentValue(duration); 181 m_durationDisplay->setCurrentValue(duration);
170 182
171 updatePlayState(); 183 updatePlayState();
172 184
173 updateCurrentTimeDisplay(); 185 updateCurrentTimeDisplay();
174 186
175 m_timeline->setDuration(duration); 187 m_timeline->setDuration(duration);
176 m_timeline->setPosition(mediaElement().currentTime()); 188 m_timeline->setPosition(mediaElement().currentTime());
177 189
178 if (!mediaElement().hasAudio()) 190 if (!mediaElement().hasAudio())
179 m_volumeSlider->hide(); 191 m_volumeSlider->hide();
180 else 192 else
181 m_volumeSlider->show(); 193 m_volumeSlider->show();
182 updateVolume(); 194 updateVolume();
183 195
184 refreshClosedCaptionsButtonVisibility(); 196 refreshClosedCaptionsButtonVisibility();
185 197
186 if (mediaElement().hasVideo() && fullscreenIsSupported(document())) 198 if (mediaElement().hasVideo() && fullscreenIsSupported())
187 m_fullScreenButton->show(); 199 m_fullScreenButton->show();
188 else 200 else
189 m_fullScreenButton->hide(); 201 m_fullScreenButton->hide();
190 202
191 makeOpaque(); 203 makeOpaque();*/
204
205 V8MediaControls::PrivateScript::resetMethod(document().frame(), this);
192 } 206 }
193 207
194 void MediaControls::show() 208 void MediaControls::show()
195 { 209 {
196 makeOpaque(); 210 /*makeOpaque();
197 m_panel->setIsDisplayed(true); 211 m_panel->setIsDisplayed(true);
198 m_panel->show(); 212 m_panel->show();
199 if (m_overlayPlayButton) 213 if (m_overlayPlayButton)
200 m_overlayPlayButton->updateDisplayType(); 214 m_overlayPlayButton->updateDisplayType();*/
215
216 V8MediaControls::PrivateScript::showMethod(document().frame(), this);
201 } 217 }
202 218
203 void MediaControls::mediaElementFocused() 219 void MediaControls::mediaElementFocused()
204 { 220 {
205 show(); 221 /*show();
206 stopHideMediaControlsTimer(); 222 stopHideMediaControlsTimer();*/
223
224 V8MediaControls::PrivateScript::mediaElementFocusedMethod(document().frame() , this);
207 } 225 }
208 226
209 void MediaControls::hide() 227 void MediaControls::hide()
210 { 228 {
211 m_panel->setIsDisplayed(false); 229 /*m_panel->setIsDisplayed(false);
212 m_panel->hide(); 230 m_panel->hide();
213 if (m_overlayPlayButton) 231 if (m_overlayPlayButton)
214 m_overlayPlayButton->hide(); 232 m_overlayPlayButton->hide();*/
233
234 V8MediaControls::PrivateScript::hideMethod(document().frame(), this);
215 } 235 }
216 236
217 void MediaControls::makeOpaque() 237 void MediaControls::makeOpaque()
218 { 238 {
219 m_panel->makeOpaque(); 239 //m_panel->makeOpaque();
220 } 240 }
221 241
222 void MediaControls::makeTransparent() 242 void MediaControls::makeTransparent()
223 { 243 {
224 m_panel->makeTransparent(); 244 //m_panel->makeTransparent();
225 } 245 }
226 246
227 bool MediaControls::shouldHideMediaControls(unsigned behaviorFlags) const 247 bool MediaControls::shouldHideMediaControls(unsigned behaviorFlags) const
228 { 248 {
229 // Never hide for a media element without visual representation. 249 /*// Never hide for a media element without visual representation.
230 if (!mediaElement().hasVideo()) 250 if (!mediaElement().hasVideo())
231 return false; 251 return false;
232 // Don't hide if the controls are hovered or the mouse is over the video are a. 252 // Don't hide if the controls are hovered or the mouse is over the video are a.
233 const bool ignoreVideoHover = behaviorFlags & IgnoreVideoHover; 253 const bool ignoreVideoHover = behaviorFlags & IgnoreVideoHover;
234 if (m_panel->hovered() || (!ignoreVideoHover && m_isMouseOverControls)) 254 if (m_panel->hovered() || (!ignoreVideoHover && m_isMouseOverControls))
235 return false; 255 return false;
236 // Don't hide if focus is on the HTMLMediaElement or within the 256 // Don't hide if focus is on the HTMLMediaElement or within the
237 // controls/shadow tree. (Perform the checks separately to avoid going 257 // controls/shadow tree. (Perform the checks separately to avoid going
238 // through all the potential ancestor hosts for the focused element.) 258 // through all the potential ancestor hosts for the focused element.)
239 const bool ignoreFocus = behaviorFlags & IgnoreFocus; 259 const bool ignoreFocus = behaviorFlags & IgnoreFocus;
240 if (!ignoreFocus && (mediaElement().focused() || contains(document().focused Element()))) 260 if (!ignoreFocus && (mediaElement().focused() || contains(document().focused Element())))
241 return false; 261 return false;
242 return true; 262 return true;*/
263
264 return false;
243 } 265 }
244 266
245 void MediaControls::playbackStarted() 267 void MediaControls::playbackStarted()
246 { 268 {
247 m_currentTimeDisplay->show(); 269 /* m_currentTimeDisplay->show();
248 m_durationDisplay->hide(); 270 m_durationDisplay->hide();
249 271
250 updatePlayState(); 272 updatePlayState();
251 m_timeline->setPosition(mediaElement().currentTime()); 273 m_timeline->setPosition(mediaElement().currentTime());
252 updateCurrentTimeDisplay(); 274 updateCurrentTimeDisplay();
253 275
254 startHideMediaControlsTimer(); 276 startHideMediaControlsTimer();*/
277
278 V8MediaControls::PrivateScript::playbackStartedMethod(document().frame(), th is);
255 } 279 }
256 280
257 void MediaControls::playbackProgressed() 281 void MediaControls::playbackProgressed()
258 { 282 {
259 m_timeline->setPosition(mediaElement().currentTime()); 283 /*m_timeline->setPosition(mediaElement().currentTime());
260 updateCurrentTimeDisplay(); 284 updateCurrentTimeDisplay();
261 285
262 if (shouldHideMediaControls()) 286 if (shouldHideMediaControls())
263 makeTransparent(); 287 makeTransparent();*/
288
289 V8MediaControls::PrivateScript::playbackProgressedMethod(document().frame(), this);
264 } 290 }
265 291
266 void MediaControls::playbackStopped() 292 void MediaControls::playbackStopped()
267 { 293 {
268 updatePlayState(); 294 /*updatePlayState();
269 m_timeline->setPosition(mediaElement().currentTime()); 295 m_timeline->setPosition(mediaElement().currentTime());
270 updateCurrentTimeDisplay(); 296 updateCurrentTimeDisplay();
271 makeOpaque(); 297 makeOpaque();
272 298
273 stopHideMediaControlsTimer(); 299 stopHideMediaControlsTimer();*/
300
301 V8MediaControls::PrivateScript::playbackStoppedMethod(document().frame(), th is);
274 } 302 }
275 303
276 void MediaControls::updatePlayState() 304 void MediaControls::updatePlayState()
277 { 305 {
278 if (m_isPausedForScrubbing) 306 /*if (m_isPausedForScrubbing)
279 return; 307 return;
280 308
281 if (m_overlayPlayButton) 309 if (m_overlayPlayButton)
282 m_overlayPlayButton->updateDisplayType(); 310 m_overlayPlayButton->updateDisplayType();
283 m_playButton->updateDisplayType(); 311 m_playButton->updateDisplayType();*/
284 } 312 }
285 313
286 void MediaControls::beginScrubbing() 314 void MediaControls::beginScrubbing()
287 { 315 {
288 if (!mediaElement().togglePlayStateWillPlay()) { 316 /*if (!mediaElement().togglePlayStateWillPlay()) {
289 m_isPausedForScrubbing = true; 317 m_isPausedForScrubbing = true;
290 mediaElement().togglePlayState(); 318 mediaElement().togglePlayState();
291 } 319 }*/
320
321 V8MediaControls::PrivateScript::beginScrubbingMethod(document().frame(), thi s);
292 } 322 }
293 323
294 void MediaControls::endScrubbing() 324 void MediaControls::endScrubbing()
295 { 325 {
296 if (m_isPausedForScrubbing) { 326 /*if (m_isPausedForScrubbing) {
297 m_isPausedForScrubbing = false; 327 m_isPausedForScrubbing = false;
298 if (mediaElement().togglePlayStateWillPlay()) 328 if (mediaElement().togglePlayStateWillPlay())
299 mediaElement().togglePlayState(); 329 mediaElement().togglePlayState();
300 } 330 }*/
331
332 V8MediaControls::PrivateScript::endScrubbingMethod(document().frame(), this) ;
301 } 333 }
302 334
303 void MediaControls::updateCurrentTimeDisplay() 335 void MediaControls::updateCurrentTimeDisplay()
304 { 336 {
305 double now = mediaElement().currentTime(); 337 /*double now = mediaElement().currentTime();
306 double duration = mediaElement().duration(); 338 double duration = mediaElement().duration();
307 339
308 // After seek, hide duration display and show current time. 340 // After seek, hide duration display and show current time.
309 if (now > 0) { 341 if (now > 0) {
310 m_currentTimeDisplay->show(); 342 m_currentTimeDisplay->show();
311 m_durationDisplay->hide(); 343 m_durationDisplay->hide();
312 } 344 }
313 345
314 // Allow the theme to format the time. 346 // Allow the theme to format the time.
315 m_currentTimeDisplay->setInnerText(RenderTheme::theme().formatMediaControlsC urrentTime(now, duration), IGNORE_EXCEPTION); 347 m_currentTimeDisplay->setInnerText(RenderTheme::theme().formatMediaControlsC urrentTime(now, duration), IGNORE_EXCEPTION);
316 m_currentTimeDisplay->setCurrentValue(now); 348 m_currentTimeDisplay->setCurrentValue(now);*/
349
350 V8MediaControls::PrivateScript::updateCurrentTimeDisplayMethod(document().fr ame(), this);
317 } 351 }
318 352
319 void MediaControls::updateVolume() 353 void MediaControls::updateVolume()
320 { 354 {
321 m_muteButton->updateDisplayType(); 355 /*m_muteButton->updateDisplayType();
322 if (m_muteButton->renderer()) 356 if (m_muteButton->renderer())
323 m_muteButton->renderer()->setShouldDoFullPaintInvalidation(true); 357 m_muteButton->renderer()->setShouldDoFullPaintInvalidation(true);
324 358
325 if (mediaElement().muted()) 359 if (mediaElement().muted())
326 m_volumeSlider->setVolume(0); 360 m_volumeSlider->setVolume(0);
327 else 361 else
328 m_volumeSlider->setVolume(mediaElement().volume()); 362 m_volumeSlider->setVolume(mediaElement().volume());*/
363
364 V8MediaControls::PrivateScript::updateVolumeMethod(document().frame(), this) ;
329 } 365 }
330 366
331 void MediaControls::changedClosedCaptionsVisibility() 367 void MediaControls::changedClosedCaptionsVisibility()
332 { 368 {
333 m_toggleClosedCaptionsButton->updateDisplayType(); 369 //m_toggleClosedCaptionsButton->updateDisplayType();
370
371 V8MediaControls::PrivateScript::changedClosedCaptionsVisibilityMethod(docume nt().frame(), this);
334 } 372 }
335 373
336 void MediaControls::refreshClosedCaptionsButtonVisibility() 374 void MediaControls::refreshClosedCaptionsButtonVisibility()
337 { 375 {
338 if (mediaElement().hasClosedCaptions()) 376 /*if (mediaElement().hasClosedCaptions())
339 m_toggleClosedCaptionsButton->show(); 377 m_toggleClosedCaptionsButton->show();
340 else 378 else
341 m_toggleClosedCaptionsButton->hide(); 379 m_toggleClosedCaptionsButton->hide();*/
380
381 V8MediaControls::PrivateScript::refreshClosedCaptionsButtonVisibilityMethod( document().frame(), this);
342 } 382 }
343 383
344 void MediaControls::closedCaptionTracksChanged() 384 void MediaControls::closedCaptionTracksChanged()
345 { 385 {
346 refreshClosedCaptionsButtonVisibility(); 386 //refreshClosedCaptionsButtonVisibility();
387
388 V8MediaControls::PrivateScript::closedCaptionTracksChangedMethod(document(). frame(), this);
347 } 389 }
348 390
349 void MediaControls::enteredFullscreen() 391 void MediaControls::enteredFullscreen()
350 { 392 {
351 m_fullScreenButton->setIsFullscreen(true); 393 /*m_fullScreenButton->setIsFullscreen(true);
352 stopHideMediaControlsTimer(); 394 stopHideMediaControlsTimer();
353 startHideMediaControlsTimer(); 395 startHideMediaControlsTimer();*/
396
397 V8MediaControls::PrivateScript::enteredFullscreenMethod(document().frame(), this);
354 } 398 }
355 399
356 void MediaControls::exitedFullscreen() 400 void MediaControls::exitedFullscreen()
357 { 401 {
358 m_fullScreenButton->setIsFullscreen(false); 402 /*m_fullScreenButton->setIsFullscreen(false);
359 stopHideMediaControlsTimer(); 403 stopHideMediaControlsTimer();
360 startHideMediaControlsTimer(); 404 startHideMediaControlsTimer();*/
405
406 V8MediaControls::PrivateScript::exitedFullscreenMethod(document().frame(), t his);
361 } 407 }
362 408
363 void MediaControls::defaultEventHandler(Event* event) 409 void MediaControls::defaultEventHandler(Event* event)
364 { 410 {
365 HTMLDivElement::defaultEventHandler(event); 411 /*HTMLDivElement::defaultEventHandler(event);
366 412
367 if (event->type() == EventTypeNames::mouseover) { 413 if (event->type() == EventTypeNames::mouseover) {
368 if (!containsRelatedTarget(event)) { 414 if (!containsRelatedTarget(event)) {
369 m_isMouseOverControls = true; 415 m_isMouseOverControls = true;
370 if (!mediaElement().togglePlayStateWillPlay()) { 416 if (!mediaElement().togglePlayStateWillPlay()) {
371 makeOpaque(); 417 makeOpaque();
372 if (shouldHideMediaControls()) 418 if (shouldHideMediaControls())
373 startHideMediaControlsTimer(); 419 startHideMediaControlsTimer();
374 } 420 }
375 } 421 }
376 return; 422 return;
377 } 423 }
378 424
379 if (event->type() == EventTypeNames::mouseout) { 425 if (event->type() == EventTypeNames::mouseout) {
380 if (!containsRelatedTarget(event)) { 426 if (!containsRelatedTarget(event)) {
381 m_isMouseOverControls = false; 427 m_isMouseOverControls = false;
382 stopHideMediaControlsTimer(); 428 stopHideMediaControlsTimer();
383 } 429 }
384 return; 430 return;
385 } 431 }
386 432
387 if (event->type() == EventTypeNames::mousemove) { 433 if (event->type() == EventTypeNames::mousemove) {
388 // When we get a mouse move, show the media controls, and start a timer 434 // When we get a mouse move, show the media controls, and start a timer
389 // that will hide the media controls after a 3 seconds without a mouse m ove. 435 // that will hide the media controls after a 3 seconds without a mouse m ove.
390 makeOpaque(); 436 makeOpaque();
391 if (shouldHideMediaControls(IgnoreVideoHover)) 437 if (shouldHideMediaControls(IgnoreVideoHover))
392 startHideMediaControlsTimer(); 438 startHideMediaControlsTimer();
393 return; 439 return;
394 } 440 }*/
395 } 441 }
396 442
397 void MediaControls::hideMediaControlsTimerFired(Timer<MediaControls>*) 443 void MediaControls::hideMediaControlsTimerFired(Timer<MediaControls>*)
398 { 444 {
399 if (mediaElement().togglePlayStateWillPlay()) 445 /*if (mediaElement().togglePlayStateWillPlay())
400 return; 446 return;
401 447
402 if (!shouldHideMediaControls(IgnoreFocus | IgnoreVideoHover)) 448 if (!shouldHideMediaControls(IgnoreFocus | IgnoreVideoHover))
403 return; 449 return;
404 450
405 makeTransparent(); 451 makeTransparent();*/
406 } 452 }
407 453
408 void MediaControls::startHideMediaControlsTimer() 454 void MediaControls::startHideMediaControlsTimer()
409 { 455 {
410 m_hideMediaControlsTimer.startOneShot(timeWithoutMouseMovementBeforeHidingMe diaControls, FROM_HERE); 456 //m_hideMediaControlsTimer.startOneShot(timeWithoutMouseMovementBeforeHiding MediaControls, FROM_HERE);
411 } 457 }
412 458
413 void MediaControls::stopHideMediaControlsTimer() 459 void MediaControls::stopHideMediaControlsTimer()
414 { 460 {
415 m_hideMediaControlsTimer.stop(); 461 //m_hideMediaControlsTimer.stop();
416 } 462 }
417 463
418 const AtomicString& MediaControls::shadowPseudoId() const 464 const AtomicString& MediaControls::shadowPseudoId() const
419 { 465 {
420 DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls")); 466 DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls"));
421 return id; 467 return id;
422 } 468 }
423 469
424 bool MediaControls::containsRelatedTarget(Event* event) 470 bool MediaControls::containsRelatedTarget(Event* event)
425 { 471 {
426 if (!event->isMouseEvent()) 472 /*if (!event->isMouseEvent())
427 return false; 473 return false;
428 EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget(); 474 EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget();
429 if (!relatedTarget) 475 if (!relatedTarget)
430 return false; 476 return false;
431 return contains(relatedTarget->toNode()); 477 return contains(relatedTarget->toNode());*/
478
479 return false;
432 } 480 }
433 481
434 void MediaControls::createTextTrackDisplay() 482 void MediaControls::createTextTrackDisplay()
435 { 483 {
436 if (m_textDisplayContainer) 484 /*if (m_textDisplayContainer)
437 return; 485 return;
438 486
439 RefPtrWillBeRawPtr<MediaControlTextTrackContainerElement> textDisplayContain er = MediaControlTextTrackContainerElement::create(*this); 487 RefPtrWillBeRawPtr<MediaControlTextTrackContainerElement> textDisplayContain er = MediaControlTextTrackContainerElement::create(*this);
440 m_textDisplayContainer = textDisplayContainer.get(); 488 m_textDisplayContainer = textDisplayContainer.get();
441 489
442 // Insert it before (behind) all other control elements. 490 // Insert it before (behind) all other control elements.
443 if (m_overlayEnclosure && m_overlayPlayButton) 491 if (m_overlayEnclosure && m_overlayPlayButton)
444 m_overlayEnclosure->insertBefore(textDisplayContainer.release(), m_overl ayPlayButton); 492 m_overlayEnclosure->insertBefore(textDisplayContainer.release(), m_overl ayPlayButton);
445 else 493 else
446 insertBefore(textDisplayContainer.release(), m_enclosure); 494 insertBefore(textDisplayContainer.release(), m_enclosure);*/
447 } 495 }
448 496
449 void MediaControls::showTextTrackDisplay() 497 void MediaControls::showTextTrackDisplay()
450 { 498 {
451 if (!m_textDisplayContainer) 499 /*if (!m_textDisplayContainer)
452 createTextTrackDisplay(); 500 createTextTrackDisplay();
453 m_textDisplayContainer->show(); 501 m_textDisplayContainer->show();*/
454 } 502 }
455 503
456 void MediaControls::hideTextTrackDisplay() 504 void MediaControls::hideTextTrackDisplay()
457 { 505 {
458 if (!m_textDisplayContainer) 506 /*if (!m_textDisplayContainer)
459 createTextTrackDisplay(); 507 createTextTrackDisplay();
460 m_textDisplayContainer->hide(); 508 m_textDisplayContainer->hide();*/
461 } 509 }
462 510
463 void MediaControls::updateTextTrackDisplay() 511 void MediaControls::updateTextTrackDisplay()
464 { 512 {
465 if (!m_textDisplayContainer) 513 /*if (!m_textDisplayContainer)
466 createTextTrackDisplay(); 514 createTextTrackDisplay();
467 515
468 m_textDisplayContainer->updateDisplay(); 516 m_textDisplayContainer->updateDisplay();*/
517 }
518
519 String MediaControls::getResourceDataURL(String name)
520 {
521 // FIXME: Use cache
522 Image* image = Image::loadPlatformResource(name.utf8().data()).leakRef();
523
524 // FIXME: This depends on the fact the resource image is PNG.
525 Vector<char> imageData;
526 imageData.append(image->data()->data(), image->data()->size());
527 Vector<char> base64Data;
528 WTF::base64Encode(imageData, base64Data);
529 return "data:image/png;base64," + base64Data;
530 }
531
532 bool MediaControls::isOverlayPlayButtonEnabled()
533 {
534 return document().settings() && document().settings()->mediaControlsOverlayP layButtonEnabled();
535 }
536
537 bool MediaControls::shouldShowControls() const
538 {
539 return mediaElement().shouldShowControls();
540 }
541
542 void MediaControls::setDivDisplayType(RefPtrWillBeRawPtr<HTMLElement> element, u nsigned type)
543 {
544 RefPtrWillBeRawPtr<MediaControlDivElement> mediaDivElement = static_pointer_ cast<MediaControlDivElement>(element);
545 mediaDivElement->setDisplayType(static_cast<MediaControlElementType>(type));
546 }
547
548 void MediaControls::setInputDisplayType(RefPtrWillBeRawPtr<HTMLElement> element, unsigned type)
549 {
550 //RefPtrWillBeRawPtr<MediaControlInputElement> mediaInputElement = static_po inter_cast<MediaControlInputElement>(element);
551 // This doesn't work!!!
552 //mediaInputElement->setDisplayType(static_cast<MediaControlElementType>(typ e));
553 }
554
555 bool MediaControls::fullscreenIsSupported() const
556 {
557 return blink::fullscreenIsSupported(document());
558 }
559
560 bool MediaControls::hasAudio() const
561 {
562 return mediaElement().hasAudio();
563 }
564
565 bool MediaControls::hasVideo() const
566 {
567 return mediaElement().hasVideo();
568 }
569
570 bool MediaControls::hasClosedCaptions() const
571 {
572 return mediaElement().hasClosedCaptions();
573 }
574
575 bool MediaControls::togglePlayStateWillPlay() const
576 {
577 return mediaElement().togglePlayStateWillPlay();
578 }
579
580 void MediaControls::togglePlayState()
581 {
582 mediaElement().togglePlayState();
583 }
584
585 void MediaControls::setCurrentTime(double time)
586 {
587 if (mediaElement().controller())
588 mediaElement().controller()->setCurrentTime(time, IGNORE_EXCEPTION);
589 else
590 mediaElement().setCurrentTime(time, IGNORE_EXCEPTION);
591 }
592
593 bool MediaControls::isClosedCaptionsVisible() const
594 {
595 return mediaElement().closedCaptionsVisible();
596 }
597
598 void MediaControls::toggleClosedCaptionsVisible()
599 {
600 mediaElement().setClosedCaptionsVisible(!mediaElement().closedCaptionsVisibl e());
601 }
602
603 void MediaControls::toggleFullscreen()
604 {
605 if (mediaElement().isFullscreen())
606 mediaElement().exitFullscreen();
607 else
608 mediaElement().enterFullscreen();
609 }
610
611 double MediaControls::getTextTrackContainerFontSize()
612 {
613 if (!document().isActive())
614 return 0;
615
616 IntRect videoBox;
617
618 if (!mediaElement().renderer() || !mediaElement().renderer()->isVideo())
619 return 0;
620 videoBox = toRenderVideo(mediaElement().renderer())->videoBox();
621
622 m_videoDisplaySize = videoBox;
623
624 float smallestDimension = std::min(videoBox.size().height(), videoBox.size() .width());
625
626 return smallestDimension * 0.05f;
627 }
628
629 void MediaControls::updateTextTrackContainerDisplay(RefPtrWillBeRawPtr<HTMLEleme nt> textTrackContainer)
630 {
631 if (!mediaElement().closedCaptionsVisible()) {
632 textTrackContainer->removeChildren();
633 return;
634 }
635
636 // 1. If the media element is an audio element, or is another playback
637 // mechanism with no rendering area, abort these steps. There is nothing to
638 // render.
639 if (isHTMLAudioElement(mediaElement()))
640 return;
641
642 // 2. Let video be the media element or other playback mechanism.
643 HTMLVideoElement& video = toHTMLVideoElement(mediaElement());
644
645 // 3. Let output be an empty list of absolutely positioned CSS block boxes.
646
647 // 4. If the user agent is exposing a user interface for video, add to
648 // output one or more completely transparent positioned CSS block boxes that
649 // cover the same region as the user interface.
650
651 // 5. If the last time these rules were run, the user agent was not exposing
652 // a user interface for video, but now it is, let reset be true. Otherwise,
653 // let reset be false.
654
655 // There is nothing to be done explicitly for 4th and 5th steps, as
656 // everything is handled through CSS. The caption box is on top of the
657 // controls box, in a container set with the -webkit-box display property.
658
659 // 6. Let tracks be the subset of video's list of text tracks that have as
660 // their rules for updating the text track rendering these rules for
661 // updating the display of WebVTT text tracks, and whose text track mode is
662 // showing or showing by default.
663 // 7. Let cues be an empty list of text track cues.
664 // 8. For each track track in tracks, append to cues all the cues from
665 // track's list of cues that have their text track cue active flag set.
666 CueList activeCues = video.currentlyActiveCues();
667
668 // 9. If reset is false, then, for each text track cue cue in cues: if cue's
669 // text track cue display state has a set of CSS boxes, then add those boxes
670 // to output, and remove cue from cues.
671
672 // There is nothing explicitly to be done here, as all the caching occurs
673 // within the TextTrackCue instance itself. If parameters of the cue change,
674 // the display tree is cleared.
675
676 // 10. For each text track cue cue in cues that has not yet had
677 // corresponding CSS boxes added to output, in text track cue order, run the
678 // following substeps:
679 for (size_t i = 0; i < activeCues.size(); ++i) {
680 TextTrackCue* cue = activeCues[i].data();
681
682 ASSERT(cue->isActive());
683 if (!cue->track() || !cue->track()->isRendered() || !cue->isActive())
684 continue;
685
686 cue->updateDisplay(m_videoDisplaySize.size(), *this);
687 }
469 } 688 }
470 689
471 void MediaControls::trace(Visitor* visitor) 690 void MediaControls::trace(Visitor* visitor)
472 { 691 {
473 visitor->trace(m_mediaElement); 692 visitor->trace(m_mediaElement);
474 visitor->trace(m_panel); 693 visitor->trace(m_panel);
475 visitor->trace(m_textDisplayContainer); 694 visitor->trace(m_textDisplayContainer);
476 visitor->trace(m_overlayPlayButton); 695 visitor->trace(m_overlayPlayButton);
477 visitor->trace(m_overlayEnclosure); 696 visitor->trace(m_overlayEnclosure);
478 visitor->trace(m_playButton); 697 visitor->trace(m_playButton);
479 visitor->trace(m_currentTimeDisplay); 698 visitor->trace(m_currentTimeDisplay);
480 visitor->trace(m_timeline); 699 visitor->trace(m_timeline);
481 visitor->trace(m_muteButton); 700 visitor->trace(m_muteButton);
482 visitor->trace(m_volumeSlider); 701 visitor->trace(m_volumeSlider);
483 visitor->trace(m_toggleClosedCaptionsButton); 702 visitor->trace(m_toggleClosedCaptionsButton);
484 visitor->trace(m_fullScreenButton); 703 visitor->trace(m_fullScreenButton);
485 visitor->trace(m_durationDisplay); 704 visitor->trace(m_durationDisplay);
486 visitor->trace(m_enclosure); 705 visitor->trace(m_enclosure);
487 HTMLDivElement::trace(visitor); 706 HTMLDivElement::trace(visitor);
488 } 707 }
489 708
490 } 709 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698