207bd113f6178397b54143ef6a7165fef81e1581
[platform/framework/web/crosswalk-tizen.git] /
1 /*
2  * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
3  * Copyright (C) 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  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef MediaControlElementTypes_h
31 #define MediaControlElementTypes_h
32
33 #include "core/CoreExport.h"
34 #include "core/html/HTMLDivElement.h"
35 #include "core/html/HTMLInputElement.h"
36 #include "public/platform/WebLocalizedString.h"
37
38 namespace blink {
39
40 class HTMLMediaElement;
41 class MediaControls;
42
43 enum MediaControlElementType {
44   MediaEnterFullscreenButton = 0,
45   MediaMuteButton,
46   MediaPlayButton,
47 #if defined(OS_TIZEN)
48   MediaSeekBackButton,
49   MediaSeekForwardButton,
50 #endif
51   MediaSlider,
52   MediaSliderThumb,
53   MediaShowClosedCaptionsButton,
54   MediaHideClosedCaptionsButton,
55   MediaTextTrackList,
56   MediaUnMuteButton,
57   MediaPauseButton,
58   MediaTimelineContainer,
59   MediaCurrentTimeDisplay,
60   MediaTimeRemainingDisplay,
61   MediaTrackSelectionCheckmark,
62   MediaControlsPanel,
63   MediaVolumeSliderContainer,
64   MediaVolumeSlider,
65   MediaVolumeSliderThumb,
66   MediaFullscreenVolumeSlider,
67   MediaFullscreenVolumeSliderThumb,
68   MediaExitFullscreenButton,
69   MediaOverlayPlayButton,
70 #if defined(TIZEN_VIDEO_MANUAL_ROTATION_SUPPORT)
71   MediaRotateButton,
72 #endif
73   MediaCastOffButton,
74   MediaCastOnButton,
75   MediaOverlayCastOffButton,
76   MediaOverlayCastOnButton,
77   MediaOverflowButton,
78   MediaOverflowList,
79   MediaDownloadButton,
80 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
81   MediaOverlaySpinner,
82 #endif
83 };
84
85 CORE_EXPORT const HTMLMediaElement* toParentMediaElement(const Node*);
86 CORE_EXPORT const HTMLMediaElement* toParentMediaElement(const LayoutObject&);
87
88 CORE_EXPORT MediaControlElementType mediaControlElementType(const Node*);
89
90 // ----------------------------
91
92 class MediaControlElement : public GarbageCollectedMixin {
93  public:
94   // These hold the state about whether this control should be shown if
95   // space permits.  These will also show / hide as needed.
96   void setIsWanted(bool);
97   bool isWanted();
98
99   // Tell us whether we fit or not.  This will hide / show the control as
100   // needed, also.
101   void setDoesFit(bool);
102
103   MediaControlElementType displayType() const { return m_displayType; }
104
105   // By default, media controls elements are not added to the overflow menu.
106   // Controls that can be added to the overflow menu should override this
107   // function and return true.
108   virtual bool hasOverflowButton() { return false; }
109
110   // If true, shows the overflow menu item if it exists. Hides it if false.
111   void shouldShowButtonInOverflowMenu(bool);
112
113   // Returns a string representation of the media control element. Used for
114   // the overflow menu.
115   String getOverflowMenuString();
116
117   // Updates the value of the Text string shown in the overflow menu.
118   void updateOverflowString();
119
120   DECLARE_VIRTUAL_TRACE();
121
122  protected:
123   MediaControlElement(MediaControls&, MediaControlElementType, HTMLElement*);
124
125   MediaControls& mediaControls() const {
126     DCHECK(m_mediaControls);
127     return *m_mediaControls;
128   }
129   HTMLMediaElement& mediaElement() const;
130
131   void setDisplayType(MediaControlElementType);
132
133   // Represents the overflow menu element for this media control.
134   // The Element contains the button that the user can click on, but having
135   // the button within an Element enables us to style the overflow menu.
136   // Setting this pointer is optional so it may be null.
137   Member<Element> m_overflowMenuElement;
138
139   // The text representation of the button within the overflow menu.
140   Member<Text> m_overflowMenuText;
141
142  private:
143   // Hide or show based on our fits / wanted state.  We want to show
144   // if and only if we're wanted and we fit.
145   void updateShownState();
146
147   // Returns a string representation of the media control element.
148   // Subclasses should override this method to return the string representation
149   // of the overflow button.
150   virtual WebLocalizedString::Name getOverflowStringName() {
151     NOTREACHED();
152     return WebLocalizedString::AXAMPMFieldText;
153   }
154
155   Member<MediaControls> m_mediaControls;
156   MediaControlElementType m_displayType;
157   Member<HTMLElement> m_element;
158   bool m_isWanted : 1;
159   bool m_doesFit : 1;
160 };
161
162 // ----------------------------
163
164 class MediaControlDivElement : public HTMLDivElement,
165                                public MediaControlElement {
166   USING_GARBAGE_COLLECTED_MIXIN(MediaControlDivElement);
167
168  public:
169   DECLARE_VIRTUAL_TRACE();
170
171  protected:
172   MediaControlDivElement(MediaControls&, MediaControlElementType);
173
174  private:
175   bool isMediaControlElement() const final { return true; }
176 };
177
178 // ----------------------------
179
180 class MediaControlInputElement : public HTMLInputElement,
181                                  public MediaControlElement {
182   USING_GARBAGE_COLLECTED_MIXIN(MediaControlInputElement);
183
184  public:
185   DECLARE_VIRTUAL_TRACE();
186
187   // Creates an overflow menu element with the given button as a child.
188   HTMLElement* createOverflowElement(MediaControls&, MediaControlInputElement*);
189
190  protected:
191   MediaControlInputElement(MediaControls&, MediaControlElementType);
192
193  private:
194   virtual void updateDisplayType() {}
195   bool isMediaControlElement() const final { return true; }
196   bool isMouseFocusable() const override;
197
198   // Creates an overflow menu HTML element.
199   virtual MediaControlInputElement* createOverflowButton(MediaControls&) {
200     return nullptr;
201   }
202 };
203
204 // ----------------------------
205
206 class MediaControlTimeDisplayElement : public MediaControlDivElement {
207  public:
208   void setCurrentValue(double);
209   double currentValue() const { return m_currentValue; }
210
211  protected:
212   MediaControlTimeDisplayElement(MediaControls&, MediaControlElementType);
213
214  private:
215   double m_currentValue;
216 };
217
218 }  // namespace blink
219
220 #endif  // MediaControlElementTypes_h