Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/shadow/MediaControlsOrientationLockDelegate.h |
| diff --git a/third_party/WebKit/Source/core/html/shadow/MediaControlsOrientationLockDelegate.h b/third_party/WebKit/Source/core/html/shadow/MediaControlsOrientationLockDelegate.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..122d80d602f22e53d6aa176f7a4aeec699537a7e |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/html/shadow/MediaControlsOrientationLockDelegate.h |
| @@ -0,0 +1,94 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MediaControlsOrientationLockDelegate_h |
| +#define MediaControlsOrientationLockDelegate_h |
| + |
| +#include "core/CoreExport.h" |
| +#include "core/events/EventListener.h" |
| +#include "core/html/shadow/MediaControls.h" |
| +#include "public/platform/modules/screen_orientation/WebScreenOrientationLockType.h" |
| + |
| +namespace blink { |
| + |
| +class Document; |
| +class HTMLVideoElement; |
| + |
| +// MediaControlsOrientationLockDelegate is implementing the orientation lock |
|
foolip
2016/12/12 23:16:05
Great documentation!
|
| +// feature when a <video> is fullscreen. It is meant to be created by |
| +// `MediaControls` when the feature apply. Once created, it will use events to |
| +// change state. |
| +// |
| +// The different states of the class are: |
| +// - PendingFullscreen: the object is created and is waiting for the associated |
| +// <video> to go fullscreen in order to apply an orientation lock; |
| +// - PendingMetadata: the <video> is fullscreen but the metadata have not been |
| +// downloaded yet. It can happen because of network latency or because the |
| +// <video> went fullscreen before playback and download started; |
| +// - MaybeLockedFullscreen: the <video> is fullscreen and a screen orientation |
| +// lock was applied. |
| +// |
| +// The possible state transitions are: |
| +// - PendingFullscreen => PendingMetadata: on fullscreenchange event (entering |
| +// fullscreen) when metadata are not available; |
| +// - PendingFullscreen => MaybeLockedFullscreen: on fullscreenchange event |
| +// (entering fullscreen) when metadata are available; |
| +// - PendingMetadata => MaybeLockedFullscreen: on loadedmetadata; |
| +// - PendingMetadata => PendingFullscreen: on fullscreenchange event (leaving |
| +// fullscreen); |
| +// - MaybeLockedFullscreen => PendingFullscreen: on fullscreenchange event |
| +// (leaving fullscreen). |
| +class CORE_EXPORT MediaControlsOrientationLockDelegate final |
| + : public EventListener { |
| + public: |
| + explicit MediaControlsOrientationLockDelegate(MediaControls*); |
| + |
| + // EventListener implementation. |
| + bool operator==(const EventListener&) const override; |
| + |
| + DECLARE_VIRTUAL_TRACE(); |
| + |
| + private: |
| + friend class MediaControlsOrientationLockDelegateTest; |
| + |
| + enum class State { |
| + PendingFullscreen, |
| + PendingMetadata, |
| + MaybeLockedFullscreen, |
| + }; |
| + |
| + // EventListener implementation. |
| + void handleEvent(ExecutionContext*, Event*) override; |
| + |
| + HTMLVideoElement& videoElement() const; |
| + Document& document() const; |
| + |
| + // Returns the orientation in which the video should be locked based on its |
| + // size. |
| + WebScreenOrientationLockType computeOrientationLock() const; |
| + |
| + // Locks the screen orientation if the video has metadata information |
| + // available. Delays locking orientation until metadata are available |
| + // otherwise. |
| + void maybeLockOrientation(); |
| + |
| + // Unlocks the screen orientation if the screen orientation was previously |
| + // locked. |
| + void maybeUnlockOrientation(); |
| + |
| + // Current state of the object. See comment at the top of the file for a |
| + // detailed description. |
| + State m_state = State::PendingFullscreen; |
| + |
| + // Whether the controls should unlock the screen orientation when possible. |
| + // In other words, whether the orientation was locked. |
| + bool m_shouldUnlockOrientation = false; |
| + |
| + // MediaControls owns |this|. |
| + Member<MediaControls> m_mediaControls; |
|
Zhiqiang Zhang (Slow)
2016/12/13 11:53:28
nit: seems like we only use MediaControls to acces
mlamouri (slow - plz ping)
2016/12/13 21:15:16
Done. Even used HTMLVideoElement.
|
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // MediaControlsOrientationLockDelegate_h |