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

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

Powered by Google App Engine
This is Rietveld 408576698