• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FullscreenElementStack_h
29 #define FullscreenElementStack_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 WebCore {
42 
43 class RenderFullScreen;
44 class RenderStyle;
45 
46 class FullscreenElementStack FINAL
47     : public NoBaseWillBeGarbageCollectedFinalized<FullscreenElementStack>
48     , public DocumentSupplement
49     , public DocumentLifecycleObserver {
50     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(FullscreenElementStack);
51 public:
52     virtual ~FullscreenElementStack();
53     static const char* supplementName();
54     static FullscreenElementStack& from(Document&);
55     static FullscreenElementStack* 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 FullScreenCheckType {
62         EnforceIFrameAllowFullScreenRequirement,
63         ExemptIFrameAllowFullScreenRequirement,
64     };
65 
66     void requestFullScreenForElement(Element*, unsigned short flags, FullScreenCheckType);
67     void webkitCancelFullScreen();
68 
69     void webkitWillEnterFullScreenForElement(Element*);
70     void webkitDidEnterFullScreenForElement(Element*);
71     void webkitWillExitFullScreenForElement(Element*);
72     void webkitDidExitFullScreenForElement(Element*);
73 
74     void setFullScreenRenderer(RenderFullScreen*);
fullScreenRenderer()75     RenderFullScreen* fullScreenRenderer() const { return m_fullScreenRenderer; }
76     void fullScreenRendererDestroyed();
77 
78     void clearFullscreenElementStack();
79     void popFullscreenElementStack();
80     void pushFullscreenElementStack(Element*);
81     void addDocumentToFullScreenChangeEventQueue(Document*);
82 
83     bool fullScreenIsAllowedForElement(Element*) const;
84     void fullScreenElementRemoved();
85     void removeFullScreenElementOfSubtree(Node*, bool amongChildrenOnly = false);
86 
87     // W3C API
88     static bool webkitFullscreenEnabled(Document&);
webkitFullscreenElement()89     Element* webkitFullscreenElement() const { return !m_fullScreenElementStack.isEmpty() ? m_fullScreenElementStack.last().get() : 0; }
90     void webkitExitFullscreen();
91 
webkitIsFullScreen()92     bool webkitIsFullScreen() const { return m_fullScreenElement.get(); }
webkitFullScreenKeyboardInputAllowed()93     bool webkitFullScreenKeyboardInputAllowed() const { return m_fullScreenElement.get() && m_areKeysEnabledInFullScreen; }
webkitCurrentFullScreenElement()94     Element* webkitCurrentFullScreenElement() const { return m_fullScreenElement.get(); }
95 
96     virtual void documentWasDetached() OVERRIDE;
97 #if !ENABLE(OILPAN)
98     virtual void documentWasDisposed() OVERRIDE;
99 #endif
100 
101     virtual void trace(Visitor*) OVERRIDE;
102 
103 private:
104     static FullscreenElementStack* fromIfExistsSlow(Document&);
105 
106     explicit FullscreenElementStack(Document&);
107 
108     Document* document();
109     void fullScreenChangeDelayTimerFired(Timer<FullscreenElementStack>*);
110 
111     bool m_areKeysEnabledInFullScreen;
112     RefPtrWillBeMember<Element> m_fullScreenElement;
113     WillBeHeapVector<RefPtrWillBeMember<Element> > m_fullScreenElementStack;
114     RenderFullScreen* m_fullScreenRenderer;
115     Timer<FullscreenElementStack> m_fullScreenChangeDelayTimer;
116     WillBeHeapDeque<RefPtrWillBeMember<Node> > m_fullScreenChangeEventTargetQueue;
117     WillBeHeapDeque<RefPtrWillBeMember<Node> > m_fullScreenErrorEventTargetQueue;
118     LayoutRect m_savedPlaceholderFrameRect;
119     RefPtr<RenderStyle> m_savedPlaceholderRenderStyle;
120 };
121 
isActiveFullScreenElement(const Element * element)122 inline bool FullscreenElementStack::isActiveFullScreenElement(const Element* element)
123 {
124     FullscreenElementStack* controller = fromIfExists(element->document());
125     if (!controller)
126         return false;
127     return controller->webkitIsFullScreen() && controller->webkitCurrentFullScreenElement() == element;
128 }
129 
fromIfExists(Document & document)130 inline FullscreenElementStack* FullscreenElementStack::fromIfExists(Document& document)
131 {
132     if (!document.hasFullscreenElementStack())
133         return 0;
134     return fromIfExistsSlow(document);
135 }
136 
137 } // namespace WebCore
138 
139 #endif // FullscreenElementStack_h
140