Shaka Player Embedded
event.h
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_JS_EVENTS_EVENT_H_
16 #define SHAKA_EMBEDDED_JS_EVENTS_EVENT_H_
17 
18 #include <string>
19 
20 #include "src/core/member.h"
24 
25 namespace shaka {
26 namespace js {
27 namespace events {
28 
29 class EventTarget;
30 
31 class Event : public BackingObject {
32  DECLARE_TYPE_INFO(Event);
33 
34  protected:
35  explicit Event(const std::string& type);
36 
37  public:
38  enum EventPhase {
39  NONE = 0,
41  AT_TARGET = 2,
43  };
44 
45  explicit Event(EventType type);
46 
47  static Event* Create(const std::string& type) {
48  return new Event(type);
49  }
50 
51  void Trace(memory::HeapTracer* tracer) const override;
52  bool IsShortLived() const override;
53 
54  bool is_stopped() const {
55  return stop_propagation_;
56  }
57  bool is_immediate_stopped() const {
58  return stop_immediate_propagation_;
59  }
60 
61  // Exposed methods.
62  void PreventDefault();
64  void StopPropagation();
65 
66  // Exposed fields.
67  const bool bubbles = false;
68  const bool cancelable = false;
69  const bool is_trusted = false;
70  const std::string type;
71  const double time_stamp;
75  bool default_prevented = false;
76 
77  private:
78  bool stop_propagation_ = false;
79  bool stop_immediate_propagation_ = false;
80 };
81 
82 class EventFactory : public BackingObjectFactory<Event> {
83  public:
84  EventFactory();
85  ~EventFactory() override;
86 };
87 
88 } // namespace events
89 } // namespace js
90 } // namespace shaka
91 
92 #endif // SHAKA_EMBEDDED_JS_EVENTS_EVENT_H_
static Event * Create(const std::string &type)
Definition: event.h:47
bool is_immediate_stopped() const
Definition: event.h:57
void Trace(memory::HeapTracer *tracer) const override
Definition: event.cc:37
bool is_stopped() const
Definition: event.h:54
Event(const std::string &type)
Definition: event.cc:28
const std::string type
Definition: event.h:70
Member< EventTarget > current_target
Definition: event.h:72
const bool cancelable
Definition: event.h:68
Member< EventTarget > target
Definition: event.h:73
const bool is_trusted
Definition: event.h:69
const double time_stamp
Definition: event.h:71
bool IsShortLived() const override
Definition: event.cc:43
const bool bubbles
Definition: event.h:67
void StopImmediatePropagation()
Definition: event.cc:52