Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / html / shadow / MediaControls.h
index ebf7eed..c2bae97 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef MediaControls_h
-#define MediaControls_h
+#pragma once
 
 #if ENABLE(VIDEO)
 
-#include "Timer.h"
+#include "Chrome.h"
+#include "HTMLDivElement.h"
+#include "MediaControlElements.h"
 #include <wtf/RefPtr.h>
 
+#if ENABLE(VIDEO_TRACK)
+#include "TextTrackCue.h"
+#endif
+
 namespace WebCore {
 
-class HTMLElement;
-class HTMLInputElement;
-class HTMLMediaElement;
+class Document;
 class Event;
-class MediaControlMuteButtonElement;
-class MediaControlPlayButtonElement;
-class MediaControlSeekButtonElement;
-class MediaControlShadowRootElement;
-class MediaControlRewindButtonElement;
-class MediaControlReturnToRealtimeButtonElement;
-class MediaControlToggleClosedCaptionsButtonElement;
-class MediaControlTimelineElement;
-class MediaControlVolumeSliderElement;
-class MediaControlFullscreenButtonElement;
-class MediaControlTimeDisplayElement;
-class MediaControlStatusDisplayElement;
-class MediaControlTimelineContainerElement;
-class MediaControlVolumeSliderContainerElement;
-class MediaControlElement;
-class MediaControlFullscreenVolumeMinButtonElement;
-class MediaControlFullscreenVolumeSliderElement;
-class MediaControlFullscreenVolumeMaxButtonElement;
 class MediaPlayer;
 
 class RenderBox;
 class RenderMedia;
 
-class MediaControls {
-public:
-    MediaControls(HTMLMediaElement*);
+// An abstract class with the media control elements that all ports support.
+class MediaControls : public HTMLDivElement {
+  public:
+    virtual ~MediaControls() = default;
 
-    void reset();
+    // This function is to be implemented in your port-specific media
+    // controls implementation since it will return a child instance.
+    static RefPtr<MediaControls> tryCreate(Document&);
 
-    void playbackProgressed();
-    void playbackStarted();
-    void playbackStopped();
+    virtual void setMediaController(MediaControllerInterface*);
 
-    void changedMute();
-    void changedVolume();
-    void changedClosedCaptionsVisibility();
+    virtual void reset();
+    virtual void reportedError();
+    virtual void loadedMetadata();
 
-    void destroy();
-    void update();
-    void updateStyle();
-    void forwardEvent(Event*);
-    void updateTimeDisplay();
+    virtual void show();
+    virtual void hide();
+    virtual void makeOpaque();
+    virtual void makeTransparent();
+    virtual bool shouldHideControls();
 
-    // FIXME: This is temporary to allow RenderMedia::layout tweak the position of controls.
-    // Once shadow DOM refactoring is complete, the tweaking will be in MediaControlsShadowRoot and this accessor will no longer be necessary.
-    RenderBox* renderBox();
+    virtual void bufferingProgressed();
+    virtual void playbackStarted();
+    virtual void playbackProgressed();
+    virtual void playbackStopped();
 
-private:
-    PassRefPtr<MediaControlShadowRootElement> create(HTMLMediaElement*);
+    virtual void updateStatusDisplay() { };
+    virtual void updateCurrentTimeDisplay();
+    virtual void showVolumeSlider();
+
+    virtual void changedMute();
+    virtual void changedVolume();
+
+    virtual void changedClosedCaptionsVisibility();
+    virtual void refreshClosedCaptionsButtonVisibility();
+    virtual void toggleClosedCaptionTrackList() { }
+    virtual void closedCaptionTracksChanged();
+
+    virtual void enteredFullscreen();
+    virtual void exitedFullscreen();
+
+#if !PLATFORM(IOS)
+    bool willRespondToMouseMoveEvents() override { return true; }
+#endif
+
+    virtual void hideFullscreenControlsTimerFired();
+    virtual void startHideFullscreenControlsTimer();
+    virtual void stopHideFullscreenControlsTimer();
+
+#if ENABLE(VIDEO_TRACK)
+    virtual void createTextTrackDisplay();
+    virtual void showTextTrackDisplay();
+    virtual void hideTextTrackDisplay();
+    virtual void updateTextTrackDisplay();
+    virtual void textTrackPreferencesChanged();
+    virtual void clearTextDisplayContainer();
+#endif
+
+protected:
+    explicit MediaControls(Document&);
+
+    void defaultEventHandler(Event&) override;
 
-    void updateControlVisibility();
-    void changeOpacity(HTMLElement*, float opacity);
-    void opacityAnimationTimerFired(Timer<MediaControls>*);
+    virtual bool containsRelatedTarget(Event&);
 
-    void updateVolumeSliderContainer(bool visible);
+    void setSliderVolume();
+
+    MediaControllerInterface* m_mediaController;
+
+    // Container for the media control elements.
+    MediaControlPanelElement* m_panel;
+
+    // Container for the text track cues.
+#if ENABLE(VIDEO_TRACK)
+    MediaControlTextTrackContainerElement* m_textDisplayContainer;
+#endif
+
+    // Media control elements.
+    MediaControlPlayButtonElement* m_playButton;
+    MediaControlCurrentTimeDisplayElement* m_currentTimeDisplay;
+    MediaControlTimelineElement* m_timeline;
+    MediaControlPanelMuteButtonElement* m_panelMuteButton;
+    MediaControlPanelVolumeSliderElement* m_volumeSlider;
+    MediaControlToggleClosedCaptionsButtonElement* m_toggleClosedCaptionsButton;
+    MediaControlFullscreenButtonElement* m_fullScreenButton;
+
+    Timer m_hideFullscreenControlsTimer;
+    bool m_isFullscreen;
+    bool m_isMouseOverControls;
 
 private:
-    RefPtr<MediaControlShadowRootElement> m_controlsShadowRoot;
-    RefPtr<MediaControlElement> m_panel;
-    RefPtr<MediaControlMuteButtonElement> m_muteButton;
-    RefPtr<MediaControlPlayButtonElement> m_playButton;
-    RefPtr<MediaControlSeekButtonElement> m_seekBackButton;
-    RefPtr<MediaControlSeekButtonElement> m_seekForwardButton;
-    RefPtr<MediaControlRewindButtonElement> m_rewindButton;
-    RefPtr<MediaControlReturnToRealtimeButtonElement> m_returnToRealtimeButton;
-    RefPtr<MediaControlToggleClosedCaptionsButtonElement> m_toggleClosedCaptionsButton;
-    RefPtr<MediaControlTimelineElement> m_timeline;
-    RefPtr<MediaControlVolumeSliderElement> m_volumeSlider;
-    RefPtr<MediaControlMuteButtonElement> m_volumeSliderMuteButton;
-    RefPtr<MediaControlFullscreenButtonElement> m_fullscreenButton;
-    RefPtr<MediaControlTimelineContainerElement> m_timelineContainer;
-    RefPtr<MediaControlVolumeSliderContainerElement> m_volumeSliderContainer;
-    RefPtr<MediaControlTimeDisplayElement> m_currentTimeDisplay;
-    RefPtr<MediaControlTimeDisplayElement> m_timeRemainingDisplay;
-    RefPtr<MediaControlStatusDisplayElement> m_statusDisplay;
-    RefPtr<MediaControlFullscreenVolumeMinButtonElement> m_fullScreenMinVolumeButton;
-    RefPtr<MediaControlFullscreenVolumeSliderElement> m_fullScreenVolumeSlider;
-    RefPtr<MediaControlFullscreenVolumeMaxButtonElement> m_fullScreenMaxVolumeButton;
-
-    HTMLMediaElement* m_mediaElement;
-    Timer<MediaControls> m_opacityAnimationTimer;
-
-    double m_opacityAnimationStartTime;
-    double m_opacityAnimationDuration;
-    float m_opacityAnimationFrom;
-    float m_opacityAnimationTo;
-
-    bool m_mouseOver;
+    bool isMediaControls() const final { return true; }
 };
 
-
+inline MediaControls* toMediaControls(Node* node)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isMediaControls());
+    return static_cast<MediaControls*>(node);
 }
 
-#endif
-#endif
+// This will catch anyone doing an unneccessary cast.
+void toMediaControls(const MediaControls*);
+
+} // namespace WebCore
+
+#endif // ENABLE(VIDEO)