OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All |
7 * rights reserved. | 7 * rights reserved. |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
10 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 10 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
(...skipping 17 matching lines...) Expand all Loading... |
28 */ | 28 */ |
29 | 29 |
30 #ifndef Fullscreen_h | 30 #ifndef Fullscreen_h |
31 #define Fullscreen_h | 31 #define Fullscreen_h |
32 | 32 |
33 #include "core/CoreExport.h" | 33 #include "core/CoreExport.h" |
34 #include "core/dom/ContextLifecycleObserver.h" | 34 #include "core/dom/ContextLifecycleObserver.h" |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/dom/Element.h" | 36 #include "core/dom/Element.h" |
37 #include "platform/Supplementable.h" | 37 #include "platform/Supplementable.h" |
| 38 #include "platform/Timer.h" |
38 #include "platform/geometry/LayoutRect.h" | 39 #include "platform/geometry/LayoutRect.h" |
39 #include "wtf/Deque.h" | 40 #include "wtf/Deque.h" |
40 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
41 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
42 | 43 |
43 namespace blink { | 44 namespace blink { |
44 | 45 |
45 class ComputedStyle; | 46 class ComputedStyle; |
46 class LayoutFullScreen; | 47 class LayoutFullScreen; |
47 | 48 |
48 class CORE_EXPORT Fullscreen final | 49 class CORE_EXPORT Fullscreen final |
49 : public GarbageCollectedFinalized<Fullscreen>, | 50 : public GarbageCollectedFinalized<Fullscreen>, |
50 public Supplement<Document>, | 51 public Supplement<Document>, |
51 public ContextLifecycleObserver { | 52 public ContextLifecycleObserver { |
52 USING_GARBAGE_COLLECTED_MIXIN(Fullscreen); | 53 USING_GARBAGE_COLLECTED_MIXIN(Fullscreen); |
53 | 54 |
54 public: | 55 public: |
55 virtual ~Fullscreen(); | 56 virtual ~Fullscreen(); |
56 static const char* supplementName(); | 57 static const char* supplementName(); |
57 static Fullscreen& from(Document&); | 58 static Fullscreen& from(Document&); |
58 static Fullscreen* fromIfExists(Document&); | 59 static Fullscreen* fromIfExists(Document&); |
59 static Element* fullscreenElementFrom(Document&); | 60 static Element* fullscreenElementFrom(Document&); |
60 static Element* fullscreenElementForBindingFrom(TreeScope&); | 61 static Element* fullscreenElementForBindingFrom(TreeScope&); |
61 static size_t fullscreenElementStackSizeFrom(Document&); | 62 static Element* currentFullScreenElementFrom(Document&); |
62 static bool isFullscreenElement(const Element&); | 63 static Element* currentFullScreenElementForBindingFrom(Document&); |
| 64 static bool isCurrentFullScreenElement(const Element&); |
63 | 65 |
64 enum class RequestType { | 66 enum class RequestType { |
65 // Element.requestFullscreen() | 67 // Element.requestFullscreen() |
66 Unprefixed, | 68 Unprefixed, |
67 // Element.webkitRequestFullscreen()/webkitRequestFullScreen() and | 69 // Element.webkitRequestFullscreen()/webkitRequestFullScreen() and |
68 // HTMLVideoElement.webkitEnterFullscreen()/webkitEnterFullScreen() | 70 // HTMLVideoElement.webkitEnterFullscreen()/webkitEnterFullScreen() |
69 Prefixed, | 71 Prefixed, |
70 // For WebRemoteFrameImpl to notify that a cross-process descendant frame | |
71 // has requested and is about to enter fullscreen. | |
72 PrefixedForCrossProcessDescendant, | |
73 }; | 72 }; |
74 | 73 |
75 static void requestFullscreen(Element&); | 74 static void requestFullscreen(Element&); |
76 static void requestFullscreen(Element&, RequestType); | 75 |
| 76 // |forCrossProcessDescendant| is used in OOPIF scenarios and is set to |
| 77 // true when fullscreen is requested for an out-of-process descendant |
| 78 // element. |
| 79 static void requestFullscreen(Element&, |
| 80 RequestType, |
| 81 bool forCrossProcessDescendant = false); |
77 | 82 |
78 static void fullyExitFullscreen(Document&); | 83 static void fullyExitFullscreen(Document&); |
79 | 84 static void exitFullscreen(Document&); |
80 enum class ExitType { | |
81 // Exits fullscreen for one element in the document. | |
82 Default, | |
83 // Fully exits fullscreen for the document. | |
84 Fully, | |
85 }; | |
86 | |
87 static void exitFullscreen(Document&, ExitType = ExitType::Default); | |
88 | 85 |
89 static bool fullscreenEnabled(Document&); | 86 static bool fullscreenEnabled(Document&); |
| 87 // TODO(foolip): The fullscreen element stack is modified synchronously in |
| 88 // requestFullscreen(), which is not per spec and means that |
| 89 // |fullscreenElement()| is not always the same as |
| 90 // |currentFullScreenElement()|, see https://crbug.com/402421. |
90 Element* fullscreenElement() const { | 91 Element* fullscreenElement() const { |
91 return !m_fullscreenElementStack.isEmpty() | 92 return !m_fullscreenElementStack.isEmpty() |
92 ? m_fullscreenElementStack.back().first.get() | 93 ? m_fullscreenElementStack.back().first.get() |
93 : nullptr; | 94 : nullptr; |
94 } | 95 } |
95 | 96 |
96 // Called by FullscreenController to notify that we've entered or exited | 97 // Called by FullscreenController to notify that we've entered or exited |
97 // fullscreen. All frames are notified, so there may be no pending request. | 98 // fullscreen. All frames are notified, so there may be no pending request. |
98 void didEnterFullscreen(); | 99 void didEnterFullscreen(); |
99 void didExitFullscreen(); | 100 void didExitFullscreen(); |
100 | 101 |
101 void setFullScreenLayoutObject(LayoutFullScreen*); | 102 void setFullScreenLayoutObject(LayoutFullScreen*); |
102 LayoutFullScreen* fullScreenLayoutObject() const { | 103 LayoutFullScreen* fullScreenLayoutObject() const { |
103 return m_fullScreenLayoutObject; | 104 return m_fullScreenLayoutObject; |
104 } | 105 } |
105 void fullScreenLayoutObjectDestroyed(); | 106 void fullScreenLayoutObjectDestroyed(); |
106 | 107 |
107 void elementRemoved(Element&); | 108 void elementRemoved(Element&); |
108 | 109 |
| 110 // Returns true if the current fullscreen element stack corresponds to a |
| 111 // container for an actual fullscreen element in a descendant |
| 112 // out-of-process iframe. |
| 113 bool forCrossProcessDescendant() { return m_forCrossProcessDescendant; } |
| 114 |
| 115 // Mozilla API |
| 116 // TODO(foolip): |currentFullScreenElement()| is a remnant from before the |
| 117 // fullscreen element stack. It is still maintained separately from the |
| 118 // stack and is is what the :-webkit-full-screen pseudo-class depends on. It |
| 119 // should be removed, see https://crbug.com/402421. |
| 120 Element* currentFullScreenElement() const { |
| 121 return m_currentFullScreenElement.get(); |
| 122 } |
| 123 |
109 // ContextLifecycleObserver: | 124 // ContextLifecycleObserver: |
110 void contextDestroyed(ExecutionContext*) override; | 125 void contextDestroyed(ExecutionContext*) override; |
111 | 126 |
112 DECLARE_VIRTUAL_TRACE(); | 127 DECLARE_VIRTUAL_TRACE(); |
113 | 128 |
114 private: | 129 private: |
115 static Fullscreen* fromIfExistsSlow(Document&); | 130 static Fullscreen* fromIfExistsSlow(Document&); |
116 | 131 |
117 explicit Fullscreen(Document&); | 132 explicit Fullscreen(Document&); |
118 | 133 |
119 Document* document(); | 134 Document* document(); |
120 | 135 |
121 static void enqueueTaskForRequest(Document&, | |
122 Element&, | |
123 RequestType, | |
124 bool error); | |
125 static void runTaskForRequest(Document*, Element*, RequestType, bool error); | |
126 | |
127 static void enqueueTaskForExit(Document&, ExitType); | |
128 static void runTaskForExit(Document*, ExitType); | |
129 | |
130 void clearFullscreenElementStack(); | 136 void clearFullscreenElementStack(); |
131 void popFullscreenElementStack(); | 137 void popFullscreenElementStack(); |
132 void pushFullscreenElementStack(Element&, RequestType); | 138 void pushFullscreenElementStack(Element&, RequestType); |
133 void fullscreenElementChanged(Element* fromElement, | |
134 Element* toElement, | |
135 RequestType toRequestType); | |
136 | 139 |
137 using ElementStackEntry = std::pair<Member<Element>, RequestType>; | 140 void enqueueChangeEvent(Document&, RequestType); |
138 using ElementStack = HeapVector<ElementStackEntry>; | 141 void enqueueErrorEvent(Element&, RequestType); |
139 ElementStack m_pendingRequests; | 142 void eventQueueTimerFired(TimerBase*); |
140 ElementStack m_fullscreenElementStack; | |
141 | 143 |
| 144 Member<Element> m_pendingFullscreenElement; |
| 145 HeapVector<std::pair<Member<Element>, RequestType>> m_fullscreenElementStack; |
| 146 Member<Element> m_currentFullScreenElement; |
142 LayoutFullScreen* m_fullScreenLayoutObject; | 147 LayoutFullScreen* m_fullScreenLayoutObject; |
| 148 TaskRunnerTimer<Fullscreen> m_eventQueueTimer; |
| 149 HeapDeque<Member<Event>> m_eventQueue; |
143 LayoutRect m_savedPlaceholderFrameRect; | 150 LayoutRect m_savedPlaceholderFrameRect; |
144 RefPtr<ComputedStyle> m_savedPlaceholderComputedStyle; | 151 RefPtr<ComputedStyle> m_savedPlaceholderComputedStyle; |
| 152 |
| 153 // TODO(alexmos, dcheng): Currently, this assumes that if fullscreen was |
| 154 // entered for an element in an out-of-process iframe, then it's not |
| 155 // possible to re-enter fullscreen for a different element in this |
| 156 // document, since that requires a user gesture, which can't be obtained |
| 157 // since nothing in this document is visible, and since user gestures can't |
| 158 // be forwarded across processes. However, the latter assumption could |
| 159 // change if https://crbug.com/161068 is fixed so that cross-process |
| 160 // postMessage can carry user gestures. If that happens, this should be |
| 161 // moved to be part of |m_fullscreenElementStack|. |
| 162 bool m_forCrossProcessDescendant; |
145 }; | 163 }; |
146 | 164 |
147 inline Fullscreen* Fullscreen::fromIfExists(Document& document) { | 165 inline Fullscreen* Fullscreen::fromIfExists(Document& document) { |
148 if (!document.hasFullscreenSupplement()) | 166 if (!document.hasFullscreenSupplement()) |
149 return nullptr; | 167 return nullptr; |
150 return fromIfExistsSlow(document); | 168 return fromIfExistsSlow(document); |
151 } | 169 } |
152 | 170 |
153 inline bool Fullscreen::isFullscreenElement(const Element& element) { | 171 inline bool Fullscreen::isCurrentFullScreenElement(const Element& element) { |
154 if (Fullscreen* found = fromIfExists(element.document())) | 172 if (Fullscreen* found = fromIfExists(element.document())) |
155 return found->fullscreenElement() == &element; | 173 return found->currentFullScreenElement() == &element; |
156 return false; | 174 return false; |
157 } | 175 } |
158 | 176 |
159 } // namespace blink | 177 } // namespace blink |
160 | 178 |
161 #endif // Fullscreen_h | 179 #endif // Fullscreen_h |
OLD | NEW |