1 | /* |
2 | * Copyright (C) 2019 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 INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(FULLSCREEN_API) |
29 | |
30 | #include "Document.h" |
31 | #include "GenericTaskQueue.h" |
32 | #include "LayoutRect.h" |
33 | #include <wtf/Deque.h> |
34 | #include <wtf/RefPtr.h> |
35 | #include <wtf/Vector.h> |
36 | #include <wtf/WeakHashSet.h> |
37 | |
38 | namespace WebCore { |
39 | |
40 | class RenderFullScreen; |
41 | class RenderTreeBuilder; |
42 | class RenderStyle; |
43 | |
44 | class FullscreenManager { |
45 | public: |
46 | FullscreenManager(Document&); |
47 | ~FullscreenManager(); |
48 | |
49 | Document& document() { return m_document; } |
50 | const Document& document() const { return m_document; } |
51 | Document& topDocument() const { return m_document.topDocument(); } |
52 | Page* page() const { return m_document.page(); } |
53 | Frame* frame() const { return m_document.frame(); } |
54 | Element* documentElement() const { return m_document.documentElement(); } |
55 | bool hasLivingRenderTree() const { return m_document.hasLivingRenderTree(); } |
56 | Document::PageCacheState pageCacheState() const { return m_document.pageCacheState(); } |
57 | void scheduleFullStyleRebuild() { m_document.scheduleFullStyleRebuild(); } |
58 | |
59 | // W3C Fullscreen API |
60 | Element* fullscreenElement() const { return !m_fullscreenElementStack.isEmpty() ? m_fullscreenElementStack.last().get() : nullptr; } |
61 | WEBCORE_EXPORT bool isFullscreenEnabled() const; |
62 | WEBCORE_EXPORT void exitFullscreen(); |
63 | |
64 | // Mozilla versions. |
65 | bool isFullscreen() const { return m_fullscreenElement.get(); } |
66 | bool isFullscreenKeyboardInputAllowed() const { return m_fullscreenElement.get() && m_areKeysEnabledInFullscreen; } |
67 | Element* currentFullscreenElement() const { return m_fullscreenElement.get(); } |
68 | WEBCORE_EXPORT void cancelFullscreen(); |
69 | |
70 | enum FullscreenCheckType { |
71 | EnforceIFrameAllowFullscreenRequirement, |
72 | ExemptIFrameAllowFullscreenRequirement, |
73 | }; |
74 | void requestFullscreenForElement(Element*, FullscreenCheckType); |
75 | |
76 | WEBCORE_EXPORT void willEnterFullscreen(Element&); |
77 | WEBCORE_EXPORT void didEnterFullscreen(); |
78 | WEBCORE_EXPORT void willExitFullscreen(); |
79 | WEBCORE_EXPORT void didExitFullscreen(); |
80 | |
81 | void setFullscreenRenderer(RenderTreeBuilder&, RenderFullScreen&); |
82 | RenderFullScreen* fullscreenRenderer() const { return m_fullscreenRenderer.get(); } |
83 | |
84 | void dispatchFullscreenChangeEvents(); |
85 | bool fullscreenIsAllowedForElement(Element&) const; |
86 | void fullscreenElementRemoved(); |
87 | |
88 | void adjustFullscreenElementOnNodeRemoval(Node&, Document::NodeRemoval = Document::NodeRemoval::Node); |
89 | |
90 | WEBCORE_EXPORT bool isAnimatingFullscreen() const; |
91 | WEBCORE_EXPORT void setAnimatingFullscreen(bool); |
92 | |
93 | WEBCORE_EXPORT bool areFullscreenControlsHidden() const; |
94 | WEBCORE_EXPORT void setFullscreenControlsHidden(bool); |
95 | |
96 | void clear(); |
97 | void emptyEventQueue(); |
98 | |
99 | protected: |
100 | friend class Document; |
101 | |
102 | void dispatchFullscreenChangeOrErrorEvent(Deque<RefPtr<Node>>&, const AtomicString& eventName, bool shouldNotifyMediaElement); |
103 | void clearFullscreenElementStack(); |
104 | void popFullscreenElementStack(); |
105 | void pushFullscreenElementStack(Element&); |
106 | void addDocumentToFullscreenChangeEventQueue(Document&); |
107 | |
108 | private: |
109 | Document& m_document; |
110 | |
111 | RefPtr<Element> m_fullscreenElement; |
112 | Vector<RefPtr<Element>> m_fullscreenElementStack; |
113 | WeakPtr<RenderFullScreen> m_fullscreenRenderer { nullptr }; |
114 | GenericTaskQueue<Timer> m_fullscreenTaskQueue; |
115 | Deque<RefPtr<Node>> m_fullscreenChangeEventTargetQueue; |
116 | Deque<RefPtr<Node>> m_fullscreenErrorEventTargetQueue; |
117 | LayoutRect m_savedPlaceholderFrameRect; |
118 | std::unique_ptr<RenderStyle> m_savedPlaceholderRenderStyle; |
119 | |
120 | bool m_areKeysEnabledInFullscreen { false }; |
121 | bool m_isAnimatingFullscreen { false }; |
122 | bool m_areFullscreenControlsHidden { false }; |
123 | }; |
124 | |
125 | } |
126 | |
127 | #endif |
128 | |