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 15 matching lines...) Expand all Loading... |
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 "core/dom/ClientRect.h" | 31 #include "core/dom/ClientRect.h" |
32 #include "core/events/MouseEvent.h" | 32 #include "core/events/MouseEvent.h" |
33 #include "core/frame/Settings.h" | 33 #include "core/frame/Settings.h" |
34 #include "core/html/HTMLMediaElement.h" | 34 #include "core/html/HTMLMediaElement.h" |
35 #include "core/html/MediaController.h" | 35 #include "core/html/MediaController.h" |
| 36 #include "core/html/track/TextTrackContainer.h" |
36 #include "core/layout/LayoutTheme.h" | 37 #include "core/layout/LayoutTheme.h" |
37 | 38 |
38 namespace blink { | 39 namespace blink { |
39 | 40 |
40 // If you change this value, then also update the corresponding value in | 41 // If you change this value, then also update the corresponding value in |
41 // LayoutTests/media/media-controls.js. | 42 // LayoutTests/media/media-controls.js. |
42 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; | 43 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; |
43 | 44 |
44 static bool fullscreenIsSupported(const Document& document) | 45 static bool fullscreenIsSupported(const Document& document) |
45 { | 46 { |
46 return !document.settings() || document.settings()->fullscreenSupported(); | 47 return !document.settings() || document.settings()->fullscreenSupported(); |
47 } | 48 } |
48 | 49 |
49 MediaControls::MediaControls(HTMLMediaElement& mediaElement) | 50 MediaControls::MediaControls(HTMLMediaElement& mediaElement) |
50 : HTMLDivElement(mediaElement.document()) | 51 : HTMLDivElement(mediaElement.document()) |
51 , m_mediaElement(&mediaElement) | 52 , m_mediaElement(&mediaElement) |
52 , m_panel(nullptr) | 53 , m_panel(nullptr) |
53 , m_textDisplayContainer(nullptr) | 54 , m_textTrackContainer(nullptr) |
54 , m_overlayPlayButton(nullptr) | 55 , m_overlayPlayButton(nullptr) |
55 , m_overlayEnclosure(nullptr) | 56 , m_overlayEnclosure(nullptr) |
56 , m_playButton(nullptr) | 57 , m_playButton(nullptr) |
57 , m_currentTimeDisplay(nullptr) | 58 , m_currentTimeDisplay(nullptr) |
58 , m_timeline(nullptr) | 59 , m_timeline(nullptr) |
59 , m_muteButton(nullptr) | 60 , m_muteButton(nullptr) |
60 , m_volumeSlider(nullptr) | 61 , m_volumeSlider(nullptr) |
61 , m_toggleClosedCaptionsButton(nullptr) | 62 , m_toggleClosedCaptionsButton(nullptr) |
62 , m_fullScreenButton(nullptr) | 63 , m_fullScreenButton(nullptr) |
63 , m_castButton(nullptr) | 64 , m_castButton(nullptr) |
(...skipping 12 matching lines...) Expand all Loading... |
76 RefPtrWillBeRawPtr<MediaControls> controls = adoptRefWillBeNoop(new MediaCon
trols(mediaElement)); | 77 RefPtrWillBeRawPtr<MediaControls> controls = adoptRefWillBeNoop(new MediaCon
trols(mediaElement)); |
77 controls->setShadowPseudoId(AtomicString("-webkit-media-controls", AtomicStr
ing::ConstructFromLiteral)); | 78 controls->setShadowPseudoId(AtomicString("-webkit-media-controls", AtomicStr
ing::ConstructFromLiteral)); |
78 controls->initializeControls(); | 79 controls->initializeControls(); |
79 return controls.release(); | 80 return controls.release(); |
80 } | 81 } |
81 | 82 |
82 // The media controls DOM structure looks like: | 83 // The media controls DOM structure looks like: |
83 // | 84 // |
84 // MediaControls (-webkit-media-controls) | 85 // MediaControls (-webkit-media-controls) |
85 // +-MediaControlOverlayEnclosureElement (-webkit-media-controls-o
verlay-enclosure) | 86 // +-MediaControlOverlayEnclosureElement (-webkit-media-controls-o
verlay-enclosure) |
86 // | +-MediaControlTextTrackContainerElement (-webkit-media-text-track
-container) | 87 // | +-TextTrackContainer (-webkit-media-text-track
-container) |
87 // | | {when text tracks are enabled} | 88 // | | {when text tracks are enabled} |
88 // | +-MediaControlOverlayPlayButtonElement (-webkit-media-controls-o
verlay-play-button) | 89 // | +-MediaControlOverlayPlayButtonElement (-webkit-media-controls-o
verlay-play-button) |
89 // | | {if mediaControlsOverlayPlayButtonEnabled} | 90 // | | {if mediaControlsOverlayPlayButtonEnabled} |
90 // | \-MediaControlCastButtonElement (-internal-media-controls
-overlay-cast-button) | 91 // | \-MediaControlCastButtonElement (-internal-media-controls
-overlay-cast-button) |
91 // \-MediaControlPanelEnclosureElement (-webkit-media-controls-e
nclosure) | 92 // \-MediaControlPanelEnclosureElement (-webkit-media-controls-e
nclosure) |
92 // \-MediaControlPanelElement (-webkit-media-controls-p
anel) | 93 // \-MediaControlPanelElement (-webkit-media-controls-p
anel) |
93 // +-MediaControlPlayButtonElement (-webkit-media-controls-p
lay-button) | 94 // +-MediaControlPlayButtonElement (-webkit-media-controls-p
lay-button) |
94 // +-MediaControlTimelineElement (-webkit-media-controls-t
imeline) | 95 // +-MediaControlTimelineElement (-webkit-media-controls-t
imeline) |
95 // +-MediaControlCurrentTimeDisplayElement (-webkit-media-controls-c
urrent-time-display) | 96 // +-MediaControlCurrentTimeDisplayElement (-webkit-media-controls-c
urrent-time-display) |
96 // +-MediaControlTimeRemainingDisplayElement (-webkit-media-controls-t
ime-remaining-display) | 97 // +-MediaControlTimeRemainingDisplayElement (-webkit-media-controls-t
ime-remaining-display) |
97 // +-MediaControlMuteButtonElement (-webkit-media-controls-m
ute-button) | 98 // +-MediaControlMuteButtonElement (-webkit-media-controls-m
ute-button) |
98 // +-MediaControlVolumeSliderElement (-webkit-media-controls-v
olume-slider) | 99 // +-MediaControlVolumeSliderElement (-webkit-media-controls-v
olume-slider) |
99 // +-MediaControlToggleClosedCaptionsButtonElement (-webkit-media-controls-t
oggle-closed-captions-button) | 100 // +-MediaControlToggleClosedCaptionsButtonElement (-webkit-media-controls-t
oggle-closed-captions-button) |
100 // +-MediaControlCastButtonElement (-internal-media-controls
-cast-button) | 101 // +-MediaControlCastButtonElement (-internal-media-controls
-cast-button) |
101 // \-MediaControlFullscreenButtonElement (-webkit-media-controls-f
ullscreen-button) | 102 // \-MediaControlFullscreenButtonElement (-webkit-media-controls-f
ullscreen-button) |
102 // | 103 // |
103 // Most of the structure is built by MediaControls::initializeControls() - the | 104 // Most of the structure is built by MediaControls::initializeControls() - the |
104 // exception being MediaControlTextTrackContainerElement which is added | 105 // exception being TextTrackContainer which is added on-demand by |
105 // on-demand by MediaControls::createTextTrackDisplay(). | 106 // MediaControls::textTrackContainer(). |
106 void MediaControls::initializeControls() | 107 void MediaControls::initializeControls() |
107 { | 108 { |
108 RefPtrWillBeRawPtr<MediaControlOverlayEnclosureElement> overlayEnclosure = M
ediaControlOverlayEnclosureElement::create(*this); | 109 RefPtrWillBeRawPtr<MediaControlOverlayEnclosureElement> overlayEnclosure = M
ediaControlOverlayEnclosureElement::create(*this); |
109 | 110 |
110 if (document().settings() && document().settings()->mediaControlsOverlayPlay
ButtonEnabled()) { | 111 if (document().settings() && document().settings()->mediaControlsOverlayPlay
ButtonEnabled()) { |
111 RefPtrWillBeRawPtr<MediaControlOverlayPlayButtonElement> overlayPlayButt
on = MediaControlOverlayPlayButtonElement::create(*this); | 112 RefPtrWillBeRawPtr<MediaControlOverlayPlayButtonElement> overlayPlayButt
on = MediaControlOverlayPlayButtonElement::create(*this); |
112 m_overlayPlayButton = overlayPlayButton.get(); | 113 m_overlayPlayButton = overlayPlayButton.get(); |
113 overlayEnclosure->appendChild(overlayPlayButton.release()); | 114 overlayEnclosure->appendChild(overlayPlayButton.release()); |
114 } | 115 } |
115 | 116 |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 bool MediaControls::containsRelatedTarget(Event* event) | 510 bool MediaControls::containsRelatedTarget(Event* event) |
510 { | 511 { |
511 if (!event->isMouseEvent()) | 512 if (!event->isMouseEvent()) |
512 return false; | 513 return false; |
513 EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget(); | 514 EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget(); |
514 if (!relatedTarget) | 515 if (!relatedTarget) |
515 return false; | 516 return false; |
516 return contains(relatedTarget->toNode()); | 517 return contains(relatedTarget->toNode()); |
517 } | 518 } |
518 | 519 |
519 void MediaControls::createTextTrackDisplay() | 520 TextTrackContainer* MediaControls::textTrackContainer() |
520 { | 521 { |
521 if (m_textDisplayContainer) | 522 if (!m_textTrackContainer) { |
522 return; | 523 RefPtrWillBeRawPtr<TextTrackContainer> textTrackContainer = TextTrackCon
tainer::create(mediaElement().document()); |
| 524 m_textTrackContainer = textTrackContainer.get(); |
523 | 525 |
524 RefPtrWillBeRawPtr<MediaControlTextTrackContainerElement> textDisplayContain
er = MediaControlTextTrackContainerElement::create(*this); | 526 // Insert it before (behind) all other control elements. |
525 m_textDisplayContainer = textDisplayContainer.get(); | 527 m_overlayEnclosure->insertBefore(textTrackContainer.release(), m_overlay
Enclosure->firstChild()); |
526 | 528 } |
527 // Insert it before (behind) all other control elements. | 529 return m_textTrackContainer.get(); |
528 m_overlayEnclosure->insertBefore(textDisplayContainer.release(), m_overlayEn
closure->firstChild()); | |
529 } | |
530 | |
531 void MediaControls::updateTextTrackDisplay() | |
532 { | |
533 if (!m_textDisplayContainer) | |
534 createTextTrackDisplay(); | |
535 | |
536 m_textDisplayContainer->updateDisplay(); | |
537 } | 530 } |
538 | 531 |
539 DEFINE_TRACE(MediaControls) | 532 DEFINE_TRACE(MediaControls) |
540 { | 533 { |
541 visitor->trace(m_mediaElement); | 534 visitor->trace(m_mediaElement); |
542 visitor->trace(m_panel); | 535 visitor->trace(m_panel); |
543 visitor->trace(m_textDisplayContainer); | 536 visitor->trace(m_textTrackContainer); |
544 visitor->trace(m_overlayPlayButton); | 537 visitor->trace(m_overlayPlayButton); |
545 visitor->trace(m_overlayEnclosure); | 538 visitor->trace(m_overlayEnclosure); |
546 visitor->trace(m_playButton); | 539 visitor->trace(m_playButton); |
547 visitor->trace(m_currentTimeDisplay); | 540 visitor->trace(m_currentTimeDisplay); |
548 visitor->trace(m_timeline); | 541 visitor->trace(m_timeline); |
549 visitor->trace(m_muteButton); | 542 visitor->trace(m_muteButton); |
550 visitor->trace(m_volumeSlider); | 543 visitor->trace(m_volumeSlider); |
551 visitor->trace(m_toggleClosedCaptionsButton); | 544 visitor->trace(m_toggleClosedCaptionsButton); |
552 visitor->trace(m_fullScreenButton); | 545 visitor->trace(m_fullScreenButton); |
553 visitor->trace(m_durationDisplay); | 546 visitor->trace(m_durationDisplay); |
554 visitor->trace(m_enclosure); | 547 visitor->trace(m_enclosure); |
555 visitor->trace(m_castButton); | 548 visitor->trace(m_castButton); |
556 visitor->trace(m_overlayCastButton); | 549 visitor->trace(m_overlayCastButton); |
557 HTMLDivElement::trace(visitor); | 550 HTMLDivElement::trace(visitor); |
558 } | 551 } |
559 | 552 |
560 } | 553 } |
OLD | NEW |