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 crate::dom::element::Element;
6use crate::dom::event::Event;
7use crate::dom::eventtarget::EventTarget;
8use crate::dom::html::htmlinputelement::InputActivationState;
9use crate::script_runtime::CanGc;
10
11/// Trait for elements with defined activation behavior
12pub(crate) trait Activatable {
13    fn as_element(&self) -> ∈
14
15    // Is this particular instance of the element activatable?
16    fn is_instance_activatable(&self) -> bool;
17
18    // https://dom.spec.whatwg.org/#eventtarget-legacy-pre-activation-behavior
19    fn legacy_pre_activation_behavior(&self, _can_gc: CanGc) -> Option<InputActivationState> {
20        None
21    }
22
23    // https://dom.spec.whatwg.org/#eventtarget-legacy-canceled-activation-behavior
24    fn legacy_canceled_activation_behavior(
25        &self,
26        _state_before: Option<InputActivationState>,
27        _can_gc: CanGc,
28    ) {
29    }
30
31    // https://dom.spec.whatwg.org/#eventtarget-activation-behavior
32    // event and target are used only by HTMLAnchorElement, in the case
33    // where the target is an <img ismap> so the href gets coordinates appended
34    fn activation_behavior(&self, event: &Event, target: &EventTarget, can_gc: CanGc);
35
36    // https://html.spec.whatwg.org/multipage/#concept-selector-active
37    fn enter_formal_activation_state(&self) {
38        self.as_element().set_active_state(true);
39    }
40
41    fn exit_formal_activation_state(&self) {
42        self.as_element().set_active_state(false);
43    }
44}