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.
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.
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.
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.
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"
43 class RenderFullScreen;
46 class Fullscreen FINAL
47 : public NoBaseWillBeGarbageCollectedFinalized<Fullscreen>
48 , public DocumentSupplement
49 , public DocumentLifecycleObserver {
50 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Fullscreen);
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&);
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()
69 void requestFullscreen(Element&, RequestType);
70 static void fullyExitFullscreen(Document&);
71 void exitFullscreen();
73 static bool fullscreenEnabled(Document&);
74 Element* fullscreenElement() const { return !m_fullScreenElementStack.isEmpty() ? m_fullScreenElementStack.last().first.get() : 0; }
76 void didEnterFullScreenForElement(Element*);
77 void didExitFullScreenForElement(Element*);
79 void setFullScreenRenderer(RenderFullScreen*);
80 RenderFullScreen* fullScreenRenderer() const { return m_fullScreenRenderer; }
81 void fullScreenRendererDestroyed();
83 void elementRemoved(Element&);
86 bool webkitFullScreenKeyboardInputAllowed() const { return m_fullScreenElement.get() && m_areKeysEnabledInFullScreen; }
87 Element* webkitCurrentFullScreenElement() const { return m_fullScreenElement.get(); }
89 virtual void documentWasDetached() OVERRIDE;
91 virtual void documentWasDisposed() OVERRIDE;
94 virtual void trace(Visitor*) OVERRIDE;
97 static Fullscreen* fromIfExistsSlow(Document&);
99 explicit Fullscreen(Document&);
101 Document* document();
103 void clearFullscreenElementStack();
104 void popFullscreenElementStack();
105 void pushFullscreenElementStack(Element&, RequestType);
107 void enqueueChangeEvent(Document&, RequestType);
108 void enqueueErrorEvent(Element&, RequestType);
109 void eventQueueTimerFired(Timer<Fullscreen>*);
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;
121 inline bool Fullscreen::isActiveFullScreenElement(const Element& element)
123 Fullscreen* fullscreen = fromIfExists(element.document());
126 return fullscreen->webkitCurrentFullScreenElement() == &element;
129 inline Fullscreen* Fullscreen::fromIfExists(Document& document)
131 if (!document.hasFullscreenSupplement())
133 return fromIfExistsSlow(document);
138 // Needed by the HeapVector<> element stack.
141 template<>struct IsPod<blink::Fullscreen::RequestType> {
142 static const bool value = true;
147 #endif // Fullscreen_h