1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
9 * Copyright (C) 2013 Google Inc. All rights reserved.
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
25 *
26 */
27
28 #ifndef Fullscreen_h
29 #define Fullscreen_h
30
31 #include "core/dom/Document.h"
32 #include "core/dom/DocumentLifecycleObserver.h"
33 #include "core/dom/Element.h"
34 #include "platform/Supplementable.h"
35 #include "platform/Timer.h"
36 #include "platform/geometry/LayoutRect.h"
37 #include "wtf/Deque.h"
38 #include "wtf/RefPtr.h"
39 #include "wtf/Vector.h"
40
41 namespace blink {
42
43 class RenderFullScreen;
44 class RenderStyle;
45
46 class Fullscreen FINAL
47 : public NoBaseWillBeGarbageCollectedFinalized<Fullscreen>
48 , public DocumentSupplement
49 , public DocumentLifecycleObserver {
50 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Fullscreen);
51 public:
52 virtual ~Fullscreen();
53 static const char* supplementName();
54 static Fullscreen& from(Document&);
55 static Fullscreen* fromIfExists(Document&);
56 static Element* fullscreenElementFrom(Document&);
57 static Element* currentFullScreenElementFrom(Document&);
58 static bool isFullScreen(Document&);
59 static bool isActiveFullScreenElement(const Element&);
60
61 enum RequestType {
62 UnprefixedRequest, // Element.requestFullscreen()
63 PrefixedRequest, // Element.webkitRequestFullscreen()
64 PrefixedMozillaRequest, // Element.webkitRequestFullScreen()
65 PrefixedMozillaAllowKeyboardInputRequest, // Element.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT)
66 PrefixedVideoRequest, // HTMLVideoElement.webkitEnterFullscreen() and webkitEnterFullScreen()
67 };
68
69 void requestFullscreen(Element&, RequestType);
70 static void fullyExitFullscreen(Document&);
71 void exitFullscreen();
72
73 static bool fullscreenEnabled(Document&);
fullscreenElement()74 Element* fullscreenElement() const { return !m_fullScreenElementStack.isEmpty() ? m_fullScreenElementStack.last().first.get() : 0; }
75
76 void didEnterFullScreenForElement(Element*);
77 void didExitFullScreenForElement(Element*);
78
79 void setFullScreenRenderer(RenderFullScreen*);
fullScreenRenderer()80 RenderFullScreen* fullScreenRenderer() const { return m_fullScreenRenderer; }
81 void fullScreenRendererDestroyed();
82
83 void elementRemoved(Element&);
84
85 // Mozilla API
webkitFullScreenKeyboardInputAllowed()86 bool webkitFullScreenKeyboardInputAllowed() const { return m_fullScreenElement.get() && m_areKeysEnabledInFullScreen; }
webkitCurrentFullScreenElement()87 Element* webkitCurrentFullScreenElement() const { return m_fullScreenElement.get(); }
88
89 virtual void documentWasDetached() OVERRIDE;
90 #if !ENABLE(OILPAN)
91 virtual void documentWasDisposed() OVERRIDE;
92 #endif
93
94 virtual void trace(Visitor*) OVERRIDE;
95
96 private:
97 static Fullscreen* fromIfExistsSlow(Document&);
98
99 explicit Fullscreen(Document&);
100
101 Document* document();
102
103 void clearFullscreenElementStack();
104 void popFullscreenElementStack();
105 void pushFullscreenElementStack(Element&, RequestType);
106
107 void enqueueChangeEvent(Document&, RequestType);
108 void enqueueErrorEvent(Element&, RequestType);
109 void eventQueueTimerFired(Timer<Fullscreen>*);
110
111 bool m_areKeysEnabledInFullScreen;
112 RefPtrWillBeMember<Element> m_fullScreenElement;
113 WillBeHeapVector<std::pair<RefPtrWillBeMember<Element>, RequestType> > m_fullScreenElementStack;
114 RawPtrWillBeMember<RenderFullScreen> m_fullScreenRenderer;
115 Timer<Fullscreen> m_eventQueueTimer;
116 WillBeHeapDeque<RefPtrWillBeMember<Event> > m_eventQueue;
117 LayoutRect m_savedPlaceholderFrameRect;
118 RefPtr<RenderStyle> m_savedPlaceholderRenderStyle;
119 };
120
isActiveFullScreenElement(const Element & element)121 inline bool Fullscreen::isActiveFullScreenElement(const Element& element)
122 {
123 Fullscreen* fullscreen = fromIfExists(element.document());
124 if (!fullscreen)
125 return false;
126 return fullscreen->webkitCurrentFullScreenElement() == &element;
127 }
128
fromIfExists(Document & document)129 inline Fullscreen* Fullscreen::fromIfExists(Document& document)
130 {
131 if (!document.hasFullscreenSupplement())
132 return 0;
133 return fromIfExistsSlow(document);
134 }
135
136 } // namespace blink
137
138 // Needed by the HeapVector<> element stack.
139 namespace WTF {
140
141 template<>struct IsPod<blink::Fullscreen::RequestType> {
142 static const bool value = true;
143 };
144
145 } // namespace WTF
146
147 #endif // Fullscreen_h
148