| 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" | |
| 39 #include "platform/geometry/LayoutRect.h" | 38 #include "platform/geometry/LayoutRect.h" |
| 40 #include "wtf/Deque.h" | 39 #include "wtf/Deque.h" |
| 41 #include "wtf/RefPtr.h" | 40 #include "wtf/RefPtr.h" |
| 42 #include "wtf/Vector.h" | 41 #include "wtf/Vector.h" |
| 43 | 42 |
| 44 namespace blink { | 43 namespace blink { |
| 45 | 44 |
| 46 class ComputedStyle; | 45 class ComputedStyle; |
| 47 class LayoutFullScreen; | 46 class LayoutFullScreen; |
| 48 | 47 |
| 49 class CORE_EXPORT Fullscreen final | 48 class CORE_EXPORT Fullscreen final |
| 50 : public GarbageCollectedFinalized<Fullscreen>, | 49 : public GarbageCollectedFinalized<Fullscreen>, |
| 51 public Supplement<Document>, | 50 public Supplement<Document>, |
| 52 public ContextLifecycleObserver { | 51 public ContextLifecycleObserver { |
| 53 USING_GARBAGE_COLLECTED_MIXIN(Fullscreen); | 52 USING_GARBAGE_COLLECTED_MIXIN(Fullscreen); |
| 54 | 53 |
| 55 public: | 54 public: |
| 56 virtual ~Fullscreen(); | 55 virtual ~Fullscreen(); |
| 57 static const char* supplementName(); | 56 static const char* supplementName(); |
| 58 static Fullscreen& from(Document&); | 57 static Fullscreen& from(Document&); |
| 59 static Fullscreen* fromIfExists(Document&); | 58 static Fullscreen* fromIfExists(Document&); |
| 60 static Element* fullscreenElementFrom(Document&); | 59 static Element* fullscreenElementFrom(Document&); |
| 61 static Element* fullscreenElementForBindingFrom(TreeScope&); | 60 static Element* fullscreenElementForBindingFrom(TreeScope&); |
| 62 static Element* currentFullScreenElementFrom(Document&); | 61 static size_t fullscreenElementStackSizeFrom(Document&); |
| 63 static Element* currentFullScreenElementForBindingFrom(Document&); | 62 static bool isFullscreenElement(const Element&); |
| 64 static bool isCurrentFullScreenElement(const Element&); | |
| 65 | 63 |
| 66 enum class RequestType { | 64 enum class RequestType { |
| 67 // Element.requestFullscreen() | 65 // Element.requestFullscreen() |
| 68 Unprefixed, | 66 Unprefixed, |
| 69 // Element.webkitRequestFullscreen()/webkitRequestFullScreen() and | 67 // Element.webkitRequestFullscreen()/webkitRequestFullScreen() and |
| 70 // HTMLVideoElement.webkitEnterFullscreen()/webkitEnterFullScreen() | 68 // HTMLVideoElement.webkitEnterFullscreen()/webkitEnterFullScreen() |
| 71 Prefixed, | 69 Prefixed, |
| 70 // For WebRemoteFrameImpl to notify that a cross-process descendant frame |
| 71 // has requested and is about to enter fullscreen. |
| 72 PrefixedForCrossProcessDescendant, |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 static void requestFullscreen(Element&); | 75 static void requestFullscreen(Element&); |
| 75 | 76 static void requestFullscreen(Element&, RequestType); |
| 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); | |
| 82 | 77 |
| 83 static void fullyExitFullscreen(Document&); | 78 static void fullyExitFullscreen(Document&); |
| 84 static void exitFullscreen(Document&); | 79 |
| 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); |
| 85 | 88 |
| 86 static bool fullscreenEnabled(Document&); | 89 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. | |
| 91 Element* fullscreenElement() const { | 90 Element* fullscreenElement() const { |
| 92 return !m_fullscreenElementStack.isEmpty() | 91 return !m_fullscreenElementStack.isEmpty() |
| 93 ? m_fullscreenElementStack.back().first.get() | 92 ? m_fullscreenElementStack.back().first.get() |
| 94 : nullptr; | 93 : nullptr; |
| 95 } | 94 } |
| 96 | 95 |
| 97 // Called by FullscreenController to notify that we've entered or exited | 96 // Called by FullscreenController to notify that we've entered or exited |
| 98 // fullscreen. All frames are notified, so there may be no pending request. | 97 // fullscreen. All frames are notified, so there may be no pending request. |
| 99 void didEnterFullscreen(); | 98 void didEnterFullscreen(); |
| 100 void didExitFullscreen(); | 99 void didExitFullscreen(); |
| 101 | 100 |
| 102 void setFullScreenLayoutObject(LayoutFullScreen*); | 101 void setFullScreenLayoutObject(LayoutFullScreen*); |
| 103 LayoutFullScreen* fullScreenLayoutObject() const { | 102 LayoutFullScreen* fullScreenLayoutObject() const { |
| 104 return m_fullScreenLayoutObject; | 103 return m_fullScreenLayoutObject; |
| 105 } | 104 } |
| 106 void fullScreenLayoutObjectDestroyed(); | 105 void fullScreenLayoutObjectDestroyed(); |
| 107 | 106 |
| 108 void elementRemoved(Element&); | 107 void elementRemoved(Element&); |
| 109 | 108 |
| 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 | |
| 124 // ContextLifecycleObserver: | 109 // ContextLifecycleObserver: |
| 125 void contextDestroyed() override; | 110 void contextDestroyed() override; |
| 126 | 111 |
| 127 DECLARE_VIRTUAL_TRACE(); | 112 DECLARE_VIRTUAL_TRACE(); |
| 128 | 113 |
| 129 private: | 114 private: |
| 130 static Fullscreen* fromIfExistsSlow(Document&); | 115 static Fullscreen* fromIfExistsSlow(Document&); |
| 131 | 116 |
| 132 explicit Fullscreen(Document&); | 117 explicit Fullscreen(Document&); |
| 133 | 118 |
| 134 Document* document(); | 119 Document* document(); |
| 135 | 120 |
| 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 |
| 136 void clearFullscreenElementStack(); | 130 void clearFullscreenElementStack(); |
| 137 void popFullscreenElementStack(); | 131 void popFullscreenElementStack(); |
| 138 void pushFullscreenElementStack(Element&, RequestType); | 132 void pushFullscreenElementStack(Element&, RequestType); |
| 133 void fullscreenElementChanged(Element* fromElement, |
| 134 Element* toElement, |
| 135 RequestType toRequestType); |
| 139 | 136 |
| 140 void enqueueChangeEvent(Document&, RequestType); | 137 using ElementStackEntry = std::pair<Member<Element>, RequestType>; |
| 141 void enqueueErrorEvent(Element&, RequestType); | 138 using ElementStack = HeapVector<ElementStackEntry>; |
| 142 void eventQueueTimerFired(TimerBase*); | 139 ElementStack m_pendingRequests; |
| 140 ElementStack m_fullscreenElementStack; |
| 143 | 141 |
| 144 Member<Element> m_pendingFullscreenElement; | |
| 145 HeapVector<std::pair<Member<Element>, RequestType>> m_fullscreenElementStack; | |
| 146 Member<Element> m_currentFullScreenElement; | |
| 147 LayoutFullScreen* m_fullScreenLayoutObject; | 142 LayoutFullScreen* m_fullScreenLayoutObject; |
| 148 Timer<Fullscreen> m_eventQueueTimer; | |
| 149 HeapDeque<Member<Event>> m_eventQueue; | |
| 150 LayoutRect m_savedPlaceholderFrameRect; | 143 LayoutRect m_savedPlaceholderFrameRect; |
| 151 RefPtr<ComputedStyle> m_savedPlaceholderComputedStyle; | 144 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; | |
| 163 }; | 145 }; |
| 164 | 146 |
| 165 inline Fullscreen* Fullscreen::fromIfExists(Document& document) { | 147 inline Fullscreen* Fullscreen::fromIfExists(Document& document) { |
| 166 if (!document.hasFullscreenSupplement()) | 148 if (!document.hasFullscreenSupplement()) |
| 167 return nullptr; | 149 return nullptr; |
| 168 return fromIfExistsSlow(document); | 150 return fromIfExistsSlow(document); |
| 169 } | 151 } |
| 170 | 152 |
| 171 inline bool Fullscreen::isCurrentFullScreenElement(const Element& element) { | 153 inline bool Fullscreen::isFullscreenElement(const Element& element) { |
| 172 if (Fullscreen* found = fromIfExists(element.document())) | 154 if (Fullscreen* found = fromIfExists(element.document())) |
| 173 return found->currentFullScreenElement() == &element; | 155 return found->fullscreenElement() == &element; |
| 174 return false; | 156 return false; |
| 175 } | 157 } |
| 176 | 158 |
| 177 } // namespace blink | 159 } // namespace blink |
| 178 | 160 |
| 179 #endif // Fullscreen_h | 161 #endif // Fullscreen_h |
| OLD | NEW |