script/dom/activation.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use js::context::JSContext;
6
7use crate::dom::element::Element;
8use crate::dom::event::Event;
9use crate::dom::eventtarget::EventTarget;
10use crate::dom::html::input_element::InputActivationState;
11
12/// Trait for elements with defined activation behavior
13pub(crate) trait Activatable {
14 fn as_element(&self) -> ∈
15
16 // Is this particular instance of the element activatable?
17 fn is_instance_activatable(&self) -> bool;
18
19 /// <https://dom.spec.whatwg.org/#eventtarget-legacy-pre-activation-behavior>
20 fn legacy_pre_activation_behavior(&self, _cx: &mut JSContext) -> Option<InputActivationState> {
21 None
22 }
23
24 /// <https://dom.spec.whatwg.org/#eventtarget-legacy-canceled-activation-behavior>
25 fn legacy_canceled_activation_behavior(
26 &self,
27 _cx: &mut JSContext,
28 _state_before: Option<InputActivationState>,
29 ) {
30 }
31
32 // https://dom.spec.whatwg.org/#eventtarget-activation-behavior
33 // event and target are used only by HTMLAnchorElement, in the case
34 // where the target is an <img ismap> so the href gets coordinates appended
35 fn activation_behavior(
36 &self,
37 cx: &mut js::context::JSContext,
38 event: &Event,
39 target: &EventTarget,
40 );
41
42 /// <https://html.spec.whatwg.org/multipage/#concept-selector-active>
43 fn enter_formal_activation_state(&self) {
44 self.as_element().set_active_state(true);
45 }
46
47 fn exit_formal_activation_state(&self) {
48 self.as_element().set_active_state(false);
49 }
50}