Shaka Player Embedded
event.cc
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 #include "src/js/events/event.h"
16 
17 #include "src/js/dom/document.h"
19 #include "src/memory/heap_tracer.h"
20 #include "src/util/clock.h"
21 
22 namespace shaka {
23 namespace js {
24 namespace events {
25 
26 Event::Event(EventType type) : Event(to_string(type)) {}
27 
28 Event::Event(const std::string& type)
29  : type(type),
30  time_stamp(util::Clock::Instance.GetMonotonicTime() -
31  dom::Document::EnsureGlobalDocument()->created_at()) {}
32 
33 // \cond Doxygen_Skip
34 Event::~Event() {}
35 // \endcond Doxygen_Skip
36 
37 void Event::Trace(memory::HeapTracer* tracer) const {
38  BackingObject::Trace(tracer);
39  tracer->Trace(&current_target);
40  tracer->Trace(&target);
41 }
42 
43 bool Event::IsShortLived() const {
44  return true;
45 }
46 
48  if (cancelable)
49  default_prevented = true;
50 }
51 
53  stop_propagation_ = true;
54  stop_immediate_propagation_ = true;
55 }
56 
58  stop_propagation_ = true;
59 }
60 
61 
63  AddReadOnlyProperty("bubbles", &Event::bubbles);
64  AddReadOnlyProperty("cancelable", &Event::cancelable);
65  AddReadOnlyProperty("currentTarget", &Event::current_target);
66  AddReadOnlyProperty("defaultPrevented", &Event::default_prevented);
67  AddReadOnlyProperty("eventPhase", &Event::event_phase);
68  AddReadOnlyProperty("target", &Event::target);
69  AddReadOnlyProperty("timeStamp", &Event::time_stamp);
70  AddReadOnlyProperty("type", &Event::type);
71  AddReadOnlyProperty("isTrusted", &Event::is_trusted);
72 
73  AddMemberFunction("preventDefault", &Event::PreventDefault);
74  AddMemberFunction("stopImmediatePropagation",
76  AddMemberFunction("stopPropagation", &Event::StopPropagation);
77 }
79 
80 } // namespace events
81 } // namespace js
82 } // namespace shaka
void Trace(memory::HeapTracer *tracer) const override
void Trace(memory::HeapTracer *tracer) const override
Definition: event.cc:37
std::string to_string(VideoReadyState state)
Definition: media_player.cc:32
ExceptionCode type
void Trace(const Traceable *ptr)
Definition: heap_tracer.cc:43
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