1/*
2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef RenderMedia_h
27#define RenderMedia_h
28
29#if ENABLE(VIDEO)
30
31#include "RenderImage.h"
32#include "Timer.h"
33
34namespace WebCore {
35
36class HTMLInputElement;
37class HTMLMediaElement;
38class MediaControlMuteButtonElement;
39class MediaControlPlayButtonElement;
40class MediaControlSeekButtonElement;
41class MediaControlRewindButtonElement;
42class MediaControlReturnToRealtimeButtonElement;
43class MediaControlToggleClosedCaptionsButtonElement;
44class MediaControlTimelineElement;
45class MediaControlVolumeSliderElement;
46class MediaControlFullscreenButtonElement;
47class MediaControlTimeDisplayElement;
48class MediaControlStatusDisplayElement;
49class MediaControlTimelineContainerElement;
50class MediaControlVolumeSliderContainerElement;
51class MediaControlElement;
52class MediaPlayer;
53
54class RenderMedia : public RenderImage {
55public:
56    RenderMedia(HTMLMediaElement*);
57    RenderMedia(HTMLMediaElement*, const IntSize& intrinsicSize);
58    virtual ~RenderMedia();
59
60    const RenderObjectChildList* children() const { return &m_children; }
61    RenderObjectChildList* children() { return &m_children; }
62
63    HTMLMediaElement* mediaElement() const;
64    MediaPlayer* player() const;
65
66    bool shouldShowTimeDisplayControls() const;
67
68    void updateFromElement();
69    void updatePlayer();
70    void updateControls();
71    void updateTimeDisplay();
72
73    void forwardEvent(Event*);
74
75protected:
76    virtual void layout();
77
78private:
79    virtual RenderObjectChildList* virtualChildren() { return children(); }
80    virtual const RenderObjectChildList* virtualChildren() const { return children(); }
81
82    virtual void destroy();
83
84    virtual const char* renderName() const { return "RenderMedia"; }
85    virtual bool isMedia() const { return true; }
86    virtual bool isImage() const { return false; }
87
88    virtual int lowestPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
89    virtual int rightmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
90    virtual int leftmostPosition(bool includeOverflowInterior = true, bool includeSelf = true) const;
91
92    void createControlsShadowRoot();
93    void destroyControlsShadowRoot();
94    void createPanel();
95    void createMuteButton();
96    void createPlayButton();
97    void createSeekBackButton();
98    void createSeekForwardButton();
99    void createRewindButton();
100    void createReturnToRealtimeButton();
101    void createToggleClosedCaptionsButton();
102    void createStatusDisplay();
103    void createTimelineContainer();
104    void createTimeline();
105    void createVolumeSliderContainer();
106    void createVolumeSlider();
107    void createCurrentTimeDisplay();
108    void createTimeRemainingDisplay();
109    void createFullscreenButton();
110
111    void timeUpdateTimerFired(Timer<RenderMedia>*);
112
113    void updateControlVisibility();
114    void changeOpacity(HTMLElement*, float opacity);
115    void opacityAnimationTimerFired(Timer<RenderMedia>*);
116
117    void updateVolumeSliderContainer(bool visible);
118
119    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
120
121    RefPtr<HTMLElement> m_controlsShadowRoot;
122    RefPtr<MediaControlElement> m_panel;
123    RefPtr<MediaControlMuteButtonElement> m_muteButton;
124    RefPtr<MediaControlPlayButtonElement> m_playButton;
125    RefPtr<MediaControlSeekButtonElement> m_seekBackButton;
126    RefPtr<MediaControlSeekButtonElement> m_seekForwardButton;
127    RefPtr<MediaControlRewindButtonElement> m_rewindButton;
128    RefPtr<MediaControlReturnToRealtimeButtonElement> m_returnToRealtimeButton;
129    RefPtr<MediaControlToggleClosedCaptionsButtonElement> m_toggleClosedCaptionsButton;
130    RefPtr<MediaControlTimelineElement> m_timeline;
131    RefPtr<MediaControlVolumeSliderElement> m_volumeSlider;
132    RefPtr<MediaControlFullscreenButtonElement> m_fullscreenButton;
133    RefPtr<MediaControlTimelineContainerElement> m_timelineContainer;
134    RefPtr<MediaControlVolumeSliderContainerElement> m_volumeSliderContainer;
135    RefPtr<MediaControlTimeDisplayElement> m_currentTimeDisplay;
136    RefPtr<MediaControlTimeDisplayElement> m_timeRemainingDisplay;
137    RefPtr<MediaControlStatusDisplayElement> m_statusDisplay;
138    RenderObjectChildList m_children;
139    Node* m_lastUnderNode;
140    Node* m_nodeUnderMouse;
141
142    Timer<RenderMedia> m_timeUpdateTimer;
143    Timer<RenderMedia> m_opacityAnimationTimer;
144    bool m_mouseOver;
145    double m_opacityAnimationStartTime;
146    double m_opacityAnimationDuration;
147    float m_opacityAnimationFrom;
148    float m_opacityAnimationTo;
149};
150
151inline RenderMedia* toRenderMedia(RenderObject* object)
152{
153    ASSERT(!object || object->isMedia());
154    return static_cast<RenderMedia*>(object);
155}
156
157// This will catch anyone doing an unnecessary cast.
158void toRenderMedia(const RenderMedia*);
159
160} // namespace WebCore
161
162#endif
163#endif // RenderMedia_h
164