OLD | NEW |
---|---|
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 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 // If you change this value, then also update the corresponding value in | 39 // If you change this value, then also update the corresponding value in |
40 // LayoutTests/media/media-controls.js. | 40 // LayoutTests/media/media-controls.js. |
41 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; | 41 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; |
42 | 42 |
43 static bool fullscreenIsSupported(const Document& document) | 43 static bool fullscreenIsSupported(const Document& document) |
44 { | 44 { |
45 return !document.settings() || document.settings()->fullscreenSupported(); | 45 return !document.settings() || document.settings()->fullscreenSupported(); |
46 } | 46 } |
47 | 47 |
48 static bool deviceSupportsMouse(const Document& document) | |
49 { | |
50 return !document.settings() || document.settings()->deviceSupportsMouse(); | |
51 } | |
52 | |
53 MediaControls::MediaControls(HTMLMediaElement& mediaElement) | 48 MediaControls::MediaControls(HTMLMediaElement& mediaElement) |
54 : HTMLDivElement(mediaElement.document()) | 49 : HTMLDivElement(mediaElement.document()) |
55 , m_mediaElement(&mediaElement) | 50 , m_mediaElement(&mediaElement) |
56 , m_panel(nullptr) | 51 , m_panel(nullptr) |
57 , m_textDisplayContainer(nullptr) | 52 , m_textDisplayContainer(nullptr) |
58 , m_overlayPlayButton(nullptr) | 53 , m_overlayPlayButton(nullptr) |
59 , m_overlayEnclosure(nullptr) | 54 , m_overlayEnclosure(nullptr) |
60 , m_playButton(nullptr) | 55 , m_playButton(nullptr) |
61 , m_currentTimeDisplay(nullptr) | 56 , m_currentTimeDisplay(nullptr) |
62 , m_timeline(nullptr) | 57 , m_timeline(nullptr) |
63 , m_muteButton(nullptr) | 58 , m_muteButton(nullptr) |
64 , m_volumeSlider(nullptr) | 59 , m_volumeSlider(nullptr) |
65 , m_toggleClosedCaptionsButton(nullptr) | 60 , m_toggleClosedCaptionsButton(nullptr) |
66 , m_fullScreenButton(nullptr) | 61 , m_fullScreenButton(nullptr) |
67 , m_durationDisplay(nullptr) | 62 , m_durationDisplay(nullptr) |
68 , m_enclosure(nullptr) | 63 , m_enclosure(nullptr) |
69 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired ) | 64 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired ) |
70 , m_isMouseOverControls(false) | 65 , m_isMouseOverControls(false) |
71 , m_isPausedForScrubbing(false) | 66 , m_isPausedForScrubbing(false) |
67 , m_wasLastEventTouch(false) | |
72 { | 68 { |
73 } | 69 } |
74 | 70 |
75 PassRefPtrWillBeRawPtr<MediaControls> MediaControls::create(HTMLMediaElement& me diaElement) | 71 PassRefPtrWillBeRawPtr<MediaControls> MediaControls::create(HTMLMediaElement& me diaElement) |
76 { | 72 { |
77 RefPtrWillBeRawPtr<MediaControls> controls = adoptRefWillBeNoop(new MediaCon trols(mediaElement)); | 73 RefPtrWillBeRawPtr<MediaControls> controls = adoptRefWillBeNoop(new MediaCon trols(mediaElement)); |
78 | 74 |
79 if (controls->initializeControls()) | 75 if (controls->initializeControls()) |
80 return controls.release(); | 76 return controls.release(); |
81 | 77 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 m_panel->hide(); | 213 m_panel->hide(); |
218 if (m_overlayPlayButton) | 214 if (m_overlayPlayButton) |
219 m_overlayPlayButton->hide(); | 215 m_overlayPlayButton->hide(); |
220 } | 216 } |
221 | 217 |
222 void MediaControls::makeOpaque() | 218 void MediaControls::makeOpaque() |
223 { | 219 { |
224 m_panel->makeOpaque(); | 220 m_panel->makeOpaque(); |
225 } | 221 } |
226 | 222 |
223 void MediaControls::makeOpaqueIfNeeded(Event* event) | |
224 { | |
225 // Fake mouse events generated by blink that do not derive from | |
226 // real input should not make the controls visible. | |
227 if (event->isMouseEvent() && toMouseEvent(event)->notFromInput()) | |
228 return; | |
229 | |
230 makeOpaque(); | |
231 } | |
232 | |
227 void MediaControls::makeTransparent() | 233 void MediaControls::makeTransparent() |
228 { | 234 { |
229 m_panel->makeTransparent(); | 235 m_panel->makeTransparent(); |
230 } | 236 } |
231 | 237 |
232 bool MediaControls::shouldHideMediaControls(unsigned behaviorFlags) const | 238 bool MediaControls::shouldHideMediaControls(unsigned behaviorFlags) const |
233 { | 239 { |
234 // Never hide for a media element without visual representation. | 240 // Never hide for a media element without visual representation. |
235 if (!mediaElement().hasVideo()) | 241 if (!mediaElement().hasVideo()) |
236 return false; | 242 return false; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 void MediaControls::exitedFullscreen() | 371 void MediaControls::exitedFullscreen() |
366 { | 372 { |
367 m_fullScreenButton->setIsFullscreen(false); | 373 m_fullScreenButton->setIsFullscreen(false); |
368 stopHideMediaControlsTimer(); | 374 stopHideMediaControlsTimer(); |
369 startHideMediaControlsTimer(); | 375 startHideMediaControlsTimer(); |
370 } | 376 } |
371 | 377 |
372 void MediaControls::defaultEventHandler(Event* event) | 378 void MediaControls::defaultEventHandler(Event* event) |
373 { | 379 { |
374 HTMLDivElement::defaultEventHandler(event); | 380 HTMLDivElement::defaultEventHandler(event); |
381 m_wasLastEventTouch = event->isTouchEvent() || (event->isMouseEvent() && toM ouseEvent(event)->fromTouch()); | |
Rick Byers
2014/08/22 18:11:13
Do you really want to consider touch events here?
Ignacio Solla
2014/08/26 13:40:53
Good catch, I consider gesture events now too.
I
Rick Byers
2014/08/26 15:25:46
I see. Seems fine to me. Ideally maybe this woul
Ignacio Solla
2014/08/26 17:30:42
Acknowledged.
| |
375 | 382 |
376 if (event->type() == EventTypeNames::mouseover) { | 383 if (event->type() == EventTypeNames::mouseover) { |
377 if (!containsRelatedTarget(event)) { | 384 if (!containsRelatedTarget(event)) { |
378 m_isMouseOverControls = true; | 385 m_isMouseOverControls = true; |
379 if (!mediaElement().togglePlayStateWillPlay()) { | 386 if (!mediaElement().togglePlayStateWillPlay()) { |
380 makeOpaque(); | 387 makeOpaqueIfNeeded(event); |
381 if (shouldHideMediaControls()) | 388 if (shouldHideMediaControls()) |
382 startHideMediaControlsTimer(); | 389 startHideMediaControlsTimer(); |
383 } | 390 } |
384 } | 391 } |
385 return; | 392 return; |
386 } | 393 } |
387 | 394 |
388 if (event->type() == EventTypeNames::mouseout) { | 395 if (event->type() == EventTypeNames::mouseout) { |
389 if (!containsRelatedTarget(event)) { | 396 if (!containsRelatedTarget(event)) { |
390 m_isMouseOverControls = false; | 397 m_isMouseOverControls = false; |
391 stopHideMediaControlsTimer(); | 398 stopHideMediaControlsTimer(); |
392 } | 399 } |
393 return; | 400 return; |
394 } | 401 } |
395 | 402 |
396 if (event->type() == EventTypeNames::mousemove) { | 403 if (event->type() == EventTypeNames::mousemove) { |
397 // When we get a mouse move, show the media controls, and start a timer | 404 // 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. | 405 // that will hide the media controls after a 3 seconds without a mouse m ove. |
399 makeOpaque(); | 406 makeOpaqueIfNeeded(event); |
400 if (shouldHideMediaControls(IgnoreVideoHover)) | 407 if (shouldHideMediaControls(IgnoreVideoHover)) |
401 startHideMediaControlsTimer(); | 408 startHideMediaControlsTimer(); |
402 return; | 409 return; |
403 } | 410 } |
404 } | 411 } |
405 | 412 |
406 void MediaControls::hideMediaControlsTimerFired(Timer<MediaControls>*) | 413 void MediaControls::hideMediaControlsTimerFired(Timer<MediaControls>*) |
407 { | 414 { |
408 if (mediaElement().togglePlayStateWillPlay()) | 415 if (mediaElement().togglePlayStateWillPlay()) |
409 return; | 416 return; |
410 | 417 |
411 unsigned behaviorFlags = IgnoreFocus | IgnoreVideoHover; | 418 unsigned behaviorFlags = IgnoreFocus | IgnoreVideoHover; |
412 // FIXME: improve this check, see http://www.crbug.com/401177. | 419 if (m_wasLastEventTouch) { |
413 if (!deviceSupportsMouse(document())) { | |
414 behaviorFlags |= IgnoreControlsHover; | 420 behaviorFlags |= IgnoreControlsHover; |
415 } | 421 } |
416 if (!shouldHideMediaControls(behaviorFlags)) | 422 if (!shouldHideMediaControls(behaviorFlags)) |
417 return; | 423 return; |
418 | 424 |
419 makeTransparent(); | 425 makeTransparent(); |
420 } | 426 } |
421 | 427 |
422 void MediaControls::startHideMediaControlsTimer() | 428 void MediaControls::startHideMediaControlsTimer() |
423 { | 429 { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 visitor->trace(m_muteButton); | 501 visitor->trace(m_muteButton); |
496 visitor->trace(m_volumeSlider); | 502 visitor->trace(m_volumeSlider); |
497 visitor->trace(m_toggleClosedCaptionsButton); | 503 visitor->trace(m_toggleClosedCaptionsButton); |
498 visitor->trace(m_fullScreenButton); | 504 visitor->trace(m_fullScreenButton); |
499 visitor->trace(m_durationDisplay); | 505 visitor->trace(m_durationDisplay); |
500 visitor->trace(m_enclosure); | 506 visitor->trace(m_enclosure); |
501 HTMLDivElement::trace(visitor); | 507 HTMLDivElement::trace(visitor); |
502 } | 508 } |
503 | 509 |
504 } | 510 } |
OLD | NEW |