OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MediaControlsRotateToFullscreenDelegate_h |
| 6 #define MediaControlsRotateToFullscreenDelegate_h |
| 7 |
| 8 #include "core/events/EventListener.h" |
| 9 #include "modules/ModulesExport.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 class HTMLVideoElement; |
| 14 class ElementVisibilityObserver; |
| 15 |
| 16 // MediaControlsRotateToFullscreenDelegate automatically enters and exits |
| 17 // fullscreen when the device is rotated whilst watching a <video>. It is meant |
| 18 // to be created by `MediaControlsImpl` when the feature applies. Once created, |
| 19 // it will listen for events. |
| 20 class MediaControlsRotateToFullscreenDelegate final : public EventListener { |
| 21 public: |
| 22 explicit MediaControlsRotateToFullscreenDelegate(HTMLVideoElement&); |
| 23 |
| 24 // Called by MediaControlsImpl when the HTMLMediaElement is added to a |
| 25 // document. All event listeners should be added. |
| 26 void Attach(); |
| 27 |
| 28 // Called by MediaControlsImpl when the HTMLMediaElement is no longer in the |
| 29 // document. All event listeners should be removed in order to prepare the |
| 30 // object to be garbage collected. |
| 31 void Detach(); |
| 32 |
| 33 // EventListener implementation. |
| 34 bool operator==(const EventListener&) const override; |
| 35 |
| 36 DECLARE_VIRTUAL_TRACE(); |
| 37 |
| 38 private: |
| 39 friend class MediaControlsRotateToFullscreenDelegateTest; |
| 40 |
| 41 // Represents either screen orientation or video aspect ratio. |
| 42 enum class SimpleOrientation { kPortrait, kLandscape, kUnknown }; |
| 43 |
| 44 // EventListener implementation. |
| 45 void handleEvent(ExecutionContext*, Event*) override; |
| 46 |
| 47 void OnStateChange(); |
| 48 void OnVisibilityChange(bool is_visible); |
| 49 void OnScreenOrientationChange(); |
| 50 |
| 51 MODULES_EXPORT SimpleOrientation ComputeVideoOrientation() const; |
| 52 SimpleOrientation ComputeScreenOrientation() const; |
| 53 |
| 54 SimpleOrientation current_screen_orientation_ = SimpleOrientation::kUnknown; |
| 55 |
| 56 // Only valid when visibility_observer_ is active and the first |
| 57 // OnVisibilityChanged has been received; otherwise assume video is hidden. |
| 58 bool is_visible_ = false; |
| 59 |
| 60 // This is null whenever we're not listening. |
| 61 Member<ElementVisibilityObserver> visibility_observer_ = nullptr; |
| 62 |
| 63 // `video_element_` owns MediaControlsImpl that owns |this|. |
| 64 Member<HTMLVideoElement> video_element_; |
| 65 }; |
| 66 |
| 67 } // namespace blink |
| 68 |
| 69 #endif // MediaControlsRotateToFullscreenDelegate_h |
OLD | NEW |