3ecd2fad963c17db36e9cfef7ec3018a64453097
[platform/framework/web/crosswalk-tizen.git] /
1 /*
2  * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3  * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
25  */
26
27 #ifndef MediaControls_h
28 #define MediaControls_h
29
30 #include "core/html/HTMLDivElement.h"
31 #include "core/html/shadow/MediaControlElements.h"
32
33 namespace blink {
34
35 class Event;
36 class MediaControlsMediaEventListener;
37 class MediaControlsWindowEventListener;
38
39 class CORE_EXPORT MediaControls final : public HTMLDivElement {
40  public:
41   static MediaControls* create(HTMLMediaElement&);
42
43   HTMLMediaElement& mediaElement() const { return *m_mediaElement; }
44
45   void reset();
46
47   void show();
48   void hide();
49   bool isVisible() const;
50
51   void playbackStarted();
52   void playbackProgressed();
53   void playbackStopped();
54
55   void beginScrubbing();
56   void endScrubbing();
57
58   void updateCurrentTimeDisplay();
59
60   void changedClosedCaptionsVisibility();
61   void refreshClosedCaptionsButtonVisibility();
62   void toggleTextTrackList();
63   void showTextTrackAtIndex(unsigned indexToEnable);
64   void disableShowingTextTracks();
65
66   void enteredFullscreen();
67   void exitedFullscreen();
68
69   void startedCasting();
70   void stoppedCasting();
71   void refreshCastButtonVisibility();
72   void showOverlayCastButtonIfNeeded();
73   // Update cast button visibility, but don't try to update our panel
74   // button visibility for space.
75   void refreshCastButtonVisibilityWithoutUpdate();
76
77   void setAllowHiddenVolumeControls(bool);
78
79   // Returns the layout object for the part of the controls that should be
80   // used for overlap checking during text track layout. May be null.
81   LayoutObject* layoutObjectForTextTrackLayout();
82
83   // Return the internal elements, which is used by registering clicking
84   // EventHandlers from MediaControlsWindowEventListener.
85   MediaControlPanelElement* panelElement() { return m_panel; }
86   MediaControlTimelineElement* timelineElement() { return m_timeline; }
87   MediaControlCastButtonElement* castButtonElement() { return m_castButton; }
88   MediaControlVolumeSliderElement* volumeSliderElement() {
89     return m_volumeSlider;
90   }
91
92   // Notify us that our controls enclosure has changed width.
93   void notifyPanelWidthChanged(const LayoutUnit& newWidth);
94
95   // Notify us that the media element's network state has changed.
96   void networkStateChanged();
97
98   void toggleOverflowMenu();
99
100   bool overflowMenuVisible();
101
102 #if defined(TIZEN_VIDEO_MANUAL_ROTATION_SUPPORT)
103   void enableManualRotateButton(bool);
104 #endif
105
106   DECLARE_VIRTUAL_TRACE();
107
108 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
109   void startSpinner();
110   void stopSpinner();
111   int getSpinnerProgressCount() const;
112   void setSpinnerProgressCount(int);
113
114   void systemVolumeChanged();
115 #endif
116
117  private:
118   friend class MediaControlsMediaEventListener;
119   friend class MediaControlsTest;
120
121   void invalidate(Element*);
122
123   class BatchedControlUpdate;
124
125   explicit MediaControls(HTMLMediaElement&);
126
127   void initializeControls();
128
129   void makeOpaque();
130   void makeTransparent();
131
132 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
133   void onSpinnerTimerFired(TimerBase*);
134 #endif
135
136   void updatePlayState();
137
138   enum HideBehaviorFlags {
139     IgnoreNone = 0,
140     IgnoreVideoHover = 1 << 0,
141     IgnoreFocus = 1 << 1,
142     IgnoreControlsHover = 1 << 2,
143     IgnoreWaitForTimer = 1 << 3,
144   };
145
146   bool shouldHideMediaControls(unsigned behaviorFlags = 0) const;
147   void hideMediaControlsTimerFired(TimerBase*);
148   void startHideMediaControlsTimer();
149   void stopHideMediaControlsTimer();
150   void resetHideMediaControlsTimer();
151
152   void panelWidthChangedTimerFired(TimerBase*);
153
154   void hideAllMenus();
155
156   // Hide elements that don't fit, and show those things that we want which
157   // do fit.  This requires that m_panelWidth is current.
158   void computeWhichControlsFit();
159
160   // Node
161   bool isMediaControls() const override { return true; }
162   bool willRespondToMouseMoveEvents() override { return true; }
163   void defaultEventHandler(Event*) override;
164   bool containsRelatedTarget(Event*);
165
166   // Methods called by MediaControlsMediaEventListener.
167   void onVolumeChange();
168   void onFocusIn();
169
170   Member<HTMLMediaElement> m_mediaElement;
171
172   // Media control elements.
173   Member<MediaControlOverlayEnclosureElement> m_overlayEnclosure;
174   Member<MediaControlOverlayPlayButtonElement> m_overlayPlayButton;
175
176 #if defined(TIZEN_VIDEO_MANUAL_ROTATION_SUPPORT)
177   Member<MediaControlRotateButtonElement> m_rotateButton;
178 #endif
179
180   Member<MediaControlCastButtonElement> m_overlayCastButton;
181   Member<MediaControlPanelEnclosureElement> m_enclosure;
182   Member<MediaControlPanelElement> m_panel;
183   Member<MediaControlPlayButtonElement> m_playButton;
184
185 #if defined(OS_TIZEN)
186   Member<MediaControlSeekBackButtonElement> m_seekBackButton;
187   Member<MediaControlSeekForwardButtonElement> m_seekForwardButton;
188 #endif
189
190   Member<MediaControlTimelineElement> m_timeline;
191   Member<MediaControlCurrentTimeDisplayElement> m_currentTimeDisplay;
192   Member<MediaControlTimeRemainingDisplayElement> m_durationDisplay;
193   Member<MediaControlMuteButtonElement> m_muteButton;
194   Member<MediaControlVolumeSliderElement> m_volumeSlider;
195   Member<MediaControlToggleClosedCaptionsButtonElement>
196       m_toggleClosedCaptionsButton;
197   Member<MediaControlTextTrackListElement> m_textTrackList;
198   Member<MediaControlOverflowMenuButtonElement> m_overflowMenu;
199   Member<MediaControlOverflowMenuListElement> m_overflowList;
200
201   Member<MediaControlCastButtonElement> m_castButton;
202   Member<MediaControlFullscreenButtonElement> m_fullscreenButton;
203   Member<MediaControlDownloadButtonElement> m_downloadButton;
204
205   Member<MediaControlsMediaEventListener> m_mediaEventListener;
206   Member<MediaControlsWindowEventListener> m_windowEventListener;
207
208   Timer<MediaControls> m_hideMediaControlsTimer;
209   unsigned m_hideTimerBehaviorFlags;
210   bool m_isMouseOverControls : 1;
211   bool m_isPausedForScrubbing : 1;
212
213 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
214   Member<MediaControlOverlaySpinnerElement> m_overlaySpinner;
215   Timer<MediaControls> m_spinnerTimer;
216
217   int m_spinnerProgressCount;
218 #endif
219
220   Timer<MediaControls> m_panelWidthChangedTimer;
221   int m_panelWidth;
222
223   bool m_keepShowingUntilTimerFires : 1;
224 };
225
226 DEFINE_ELEMENT_TYPE_CASTS(MediaControls, isMediaControls());
227
228 }  // namespace blink
229
230 #endif