| 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 "platform/wtf/Deque.h" | 39 #include "platform/wtf/Deque.h" |
| 41 #include "platform/wtf/RefPtr.h" | 40 #include "platform/wtf/RefPtr.h" |
| 42 #include "platform/wtf/Vector.h" | 41 #include "platform/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 static bool IsInFullscreenElementStack(const Element&); | 63 static bool IsInFullscreenElementStack(const Element&); |
| 66 | 64 |
| 67 enum class RequestType { | 65 enum class RequestType { |
| 68 // Element.requestFullscreen() | 66 // Element.requestFullscreen() |
| 69 kUnprefixed, | 67 kUnprefixed, |
| 70 // Element.webkitRequestFullscreen()/webkitRequestFullScreen() and | 68 // Element.webkitRequestFullscreen()/webkitRequestFullScreen() and |
| 71 // HTMLVideoElement.webkitEnterFullscreen()/webkitEnterFullScreen() | 69 // HTMLVideoElement.webkitEnterFullscreen()/webkitEnterFullScreen() |
| 72 kPrefixed, | 70 kPrefixed, |
| 71 // For WebRemoteFrameImpl to notify that a cross-process descendant frame |
| 72 // has requested and is about to enter fullscreen. |
| 73 kPrefixedForCrossProcessDescendant, |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 static void RequestFullscreen(Element&); | 76 static void RequestFullscreen(Element&); |
| 76 | 77 static void RequestFullscreen(Element&, RequestType); |
| 77 // |forCrossProcessDescendant| is used in OOPIF scenarios and is set to | |
| 78 // true when fullscreen is requested for an out-of-process descendant | |
| 79 // element. | |
| 80 static void RequestFullscreen(Element&, | |
| 81 RequestType, | |
| 82 bool for_cross_process_descendant = false); | |
| 83 | 78 |
| 84 static void FullyExitFullscreen(Document&); | 79 static void FullyExitFullscreen(Document&); |
| 85 static void ExitFullscreen(Document&); | 80 |
| 81 enum class ExitType { |
| 82 // Exits fullscreen for one element in the document. |
| 83 kDefault, |
| 84 // Fully exits fullscreen for the document. |
| 85 kFully, |
| 86 }; |
| 87 |
| 88 static void ExitFullscreen(Document&, ExitType = ExitType::kDefault); |
| 86 | 89 |
| 87 static bool FullscreenEnabled(Document&); | 90 static bool FullscreenEnabled(Document&); |
| 88 // TODO(foolip): The fullscreen element stack is modified synchronously in | |
| 89 // requestFullscreen(), which is not per spec and means that | |
| 90 // |fullscreenElement()| is not always the same as | |
| 91 // |currentFullScreenElement()|, see https://crbug.com/402421. | |
| 92 Element* FullscreenElement() const { | 91 Element* FullscreenElement() const { |
| 93 return !fullscreen_element_stack_.IsEmpty() | 92 return !fullscreen_element_stack_.IsEmpty() |
| 94 ? fullscreen_element_stack_.back().first.Get() | 93 ? fullscreen_element_stack_.back().first.Get() |
| 95 : nullptr; | 94 : nullptr; |
| 96 } | 95 } |
| 97 | 96 |
| 98 // Called by FullscreenController to notify that we've entered or exited | 97 // Called by FullscreenController to notify that we've entered or exited |
| 99 // 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. |
| 100 void DidEnterFullscreen(); | 99 void DidEnterFullscreen(); |
| 101 void DidExitFullscreen(); | 100 void DidExitFullscreen(); |
| 102 | 101 |
| 103 void SetFullScreenLayoutObject(LayoutFullScreen*); | 102 void SetFullScreenLayoutObject(LayoutFullScreen*); |
| 104 LayoutFullScreen* FullScreenLayoutObject() const { | 103 LayoutFullScreen* FullScreenLayoutObject() const { |
| 105 return full_screen_layout_object_; | 104 return full_screen_layout_object_; |
| 106 } | 105 } |
| 107 void FullScreenLayoutObjectDestroyed(); | 106 void FullScreenLayoutObjectDestroyed(); |
| 108 | 107 |
| 109 void ElementRemoved(Element&); | 108 void ElementRemoved(Element&); |
| 110 | 109 |
| 111 // Returns true if the current fullscreen element stack corresponds to a | |
| 112 // container for an actual fullscreen element in a descendant | |
| 113 // out-of-process iframe. | |
| 114 bool ForCrossProcessDescendant() { return for_cross_process_descendant_; } | |
| 115 | |
| 116 // Mozilla API | |
| 117 // TODO(foolip): |currentFullScreenElement()| is a remnant from before the | |
| 118 // fullscreen element stack. It is still maintained separately from the | |
| 119 // stack and is is what the :-webkit-full-screen pseudo-class depends on. It | |
| 120 // should be removed, see https://crbug.com/402421. | |
| 121 Element* CurrentFullScreenElement() const { | |
| 122 return current_full_screen_element_.Get(); | |
| 123 } | |
| 124 | |
| 125 // ContextLifecycleObserver: | 110 // ContextLifecycleObserver: |
| 126 void ContextDestroyed(ExecutionContext*) override; | 111 void ContextDestroyed(ExecutionContext*) override; |
| 127 | 112 |
| 128 DECLARE_VIRTUAL_TRACE(); | 113 DECLARE_VIRTUAL_TRACE(); |
| 129 | 114 |
| 130 private: | 115 private: |
| 131 static Fullscreen* FromIfExistsSlow(Document&); | 116 static Fullscreen* FromIfExistsSlow(Document&); |
| 132 | 117 |
| 133 explicit Fullscreen(Document&); | 118 explicit Fullscreen(Document&); |
| 134 | 119 |
| 135 Document* GetDocument(); | 120 Document* GetDocument(); |
| 136 | 121 |
| 122 static void EnqueueTaskForRequest(Document&, |
| 123 Element&, |
| 124 RequestType, |
| 125 bool error); |
| 126 static void RunTaskForRequest(Document*, Element*, RequestType, bool error); |
| 127 |
| 128 static void EnqueueTaskForExit(Document&, ExitType); |
| 129 static void RunTaskForExit(Document*, ExitType); |
| 130 |
| 137 void ClearFullscreenElementStack(); | 131 void ClearFullscreenElementStack(); |
| 138 void PopFullscreenElementStack(); | 132 void PopFullscreenElementStack(); |
| 139 void PushFullscreenElementStack(Element&, RequestType); | 133 void PushFullscreenElementStack(Element&, RequestType); |
| 134 void FullscreenElementChanged(Element* from_element, |
| 135 Element* to_element, |
| 136 RequestType to_request_type); |
| 140 | 137 |
| 141 void EnqueueChangeEvent(Document&, RequestType); | 138 using ElementStackEntry = std::pair<Member<Element>, RequestType>; |
| 142 void EnqueueErrorEvent(Element&, RequestType); | 139 using ElementStack = HeapVector<ElementStackEntry>; |
| 143 void EventQueueTimerFired(TimerBase*); | 140 ElementStack pending_requests_; |
| 141 ElementStack fullscreen_element_stack_; |
| 144 | 142 |
| 145 Member<Element> pending_fullscreen_element_; | |
| 146 HeapVector<std::pair<Member<Element>, RequestType>> fullscreen_element_stack_; | |
| 147 Member<Element> current_full_screen_element_; | |
| 148 LayoutFullScreen* full_screen_layout_object_; | 143 LayoutFullScreen* full_screen_layout_object_; |
| 149 TaskRunnerTimer<Fullscreen> event_queue_timer_; | |
| 150 HeapDeque<Member<Event>> event_queue_; | |
| 151 LayoutRect saved_placeholder_frame_rect_; | 144 LayoutRect saved_placeholder_frame_rect_; |
| 152 RefPtr<ComputedStyle> saved_placeholder_computed_style_; | 145 RefPtr<ComputedStyle> saved_placeholder_computed_style_; |
| 153 | |
| 154 // TODO(alexmos, dcheng): Currently, this assumes that if fullscreen was | |
| 155 // entered for an element in an out-of-process iframe, then it's not | |
| 156 // possible to re-enter fullscreen for a different element in this | |
| 157 // document, since that requires a user gesture, which can't be obtained | |
| 158 // since nothing in this document is visible, and since user gestures can't | |
| 159 // be forwarded across processes. However, the latter assumption could | |
| 160 // change if https://crbug.com/161068 is fixed so that cross-process | |
| 161 // postMessage can carry user gestures. If that happens, this should be | |
| 162 // moved to be part of |m_fullscreenElementStack|. | |
| 163 bool for_cross_process_descendant_; | |
| 164 }; | 146 }; |
| 165 | 147 |
| 166 inline Fullscreen* Fullscreen::FromIfExists(Document& document) { | 148 inline Fullscreen* Fullscreen::FromIfExists(Document& document) { |
| 167 if (!document.HasFullscreenSupplement()) | 149 if (!document.HasFullscreenSupplement()) |
| 168 return nullptr; | 150 return nullptr; |
| 169 return FromIfExistsSlow(document); | 151 return FromIfExistsSlow(document); |
| 170 } | 152 } |
| 171 | 153 |
| 172 inline bool Fullscreen::IsCurrentFullScreenElement(const Element& element) { | 154 inline bool Fullscreen::IsFullscreenElement(const Element& element) { |
| 173 if (Fullscreen* found = FromIfExists(element.GetDocument())) | 155 if (Fullscreen* found = FromIfExists(element.GetDocument())) |
| 174 return found->CurrentFullScreenElement() == &element; | 156 return found->FullscreenElement() == &element; |
| 175 return false; | 157 return false; |
| 176 } | 158 } |
| 177 | 159 |
| 178 } // namespace blink | 160 } // namespace blink |
| 179 | 161 |
| 180 #endif // Fullscreen_h | 162 #endif // Fullscreen_h |
| OLD | NEW |