summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/fullscreen/fullscreen.h
blob: 34c1d12d7364e2f824860f3499c5a2bd6155fb21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 *           (C) 2001 Dirk Mueller (mueller@kde.org)
 *           (C) 2006 Alexey Proskuryakov (ap@webkit.org)
 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All
 * rights reserved.
 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
 * (http://www.torchmobile.com/)
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
 * Copyright (C) 2013 Google Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FULLSCREEN_FULLSCREEN_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FULLSCREEN_FULLSCREEN_H_

#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/fullscreen/fullscreen_request_type.h"
#include "third_party/blink/renderer/platform/geometry/layout_rect.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

class LocalDOMWindow;
class FullscreenOptions;
class ScriptPromiseResolver;

// The Fullscreen class implements most of the Fullscreen API Standard,
// https://fullscreen.spec.whatwg.org/, especially its algorithms. It is a
// Document supplement as each document has some fullscreen state, and to
// actually enter and exit fullscreen it (indirectly) uses FullscreenController.
class CORE_EXPORT Fullscreen final : public GarbageCollected<Fullscreen>,
                                     public Supplement<LocalDOMWindow>,
                                     public ExecutionContextLifecycleObserver {
 public:
  static const char kSupplementName[];

  explicit Fullscreen(LocalDOMWindow&);
  ~Fullscreen() override;

  static Element* FullscreenElementFrom(Document&);
  static Element* FullscreenElementForBindingFrom(TreeScope&);
  static bool IsFullscreenElement(const Element&);
  static bool IsInFullscreenElementStack(const Element&);

  static void RequestFullscreen(Element&);
  static ScriptPromise RequestFullscreen(
      Element&,
      const FullscreenOptions*,
      FullscreenRequestType,
      ScriptState* state = nullptr,
      ExceptionState* exception_state = nullptr);

  static void FullyExitFullscreen(Document&, bool ua_originated = false);
  static ScriptPromise ExitFullscreen(Document&,
                                      ScriptState* state = nullptr,
                                      ExceptionState* exception_state = nullptr,
                                      bool ua_originated = false);

  static bool FullscreenEnabled(Document&);

  // Called by FullscreenController to notify that we've entered or exited
  // fullscreen. All frames are notified, so there may be no pending request.
  static void DidResolveEnterFullscreenRequest(Document&, bool granted);
  static void DidExitFullscreen(Document&);

  static void DidUpdateSize(Element&);

  static void ElementRemoved(Element&);

  // ExecutionContextLifecycleObserver:
  void ContextDestroyed() override;

  void Trace(Visitor*) const override;

 private:
  static Fullscreen& From(LocalDOMWindow&);

  static void ContinueRequestFullscreen(Document&,
                                        Element&,
                                        FullscreenRequestType,
                                        const FullscreenOptions*,
                                        ScriptPromiseResolver* resolver,
                                        bool error);

  static void ContinueExitFullscreen(Document*,
                                     ScriptPromiseResolver* resolver,
                                     bool resize);

  void FullscreenElementChanged(Element* old_element,
                                Element* new_element,
                                FullscreenRequestType new_request_type);

  // Stores the pending request, promise and the type for executing
  // the asynchronous portion of the request.
  class PendingRequest : public GarbageCollected<PendingRequest> {
   public:
    PendingRequest(Element* element,
                   FullscreenRequestType type,
                   const FullscreenOptions* options,
                   ScriptPromiseResolver* resolver);
    virtual ~PendingRequest();
    virtual void Trace(Visitor* visitor) const;

    Element* element() { return element_; }
    FullscreenRequestType type() { return type_; }
    const FullscreenOptions* options() { return options_; }
    ScriptPromiseResolver* resolver() { return resolver_; }

   private:
    Member<Element> element_;
    FullscreenRequestType type_;
    Member<const FullscreenOptions> options_;
    Member<ScriptPromiseResolver> resolver_;

    DISALLOW_COPY_AND_ASSIGN(PendingRequest);
  };
  using PendingRequests = HeapVector<Member<PendingRequest>>;
  PendingRequests pending_requests_;

  using PendingExit = ScriptPromiseResolver;
  using PendingExits = HeapVector<Member<PendingExit>>;
  PendingExits pending_exits_;
};

inline bool Fullscreen::IsFullscreenElement(const Element& element) {
  return FullscreenElementFrom(element.GetDocument()) == &element;
}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FULLSCREEN_FULLSCREEN_H_