/
githubmirror
/
servo
Обзор
Документация
Войти
/
githubmirror
/
servo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
components/script/dom/event/commandevent.rs
129 строк
4 KB
Tim van der Lippe
script: Remove `reflect_dom_object_with_proto_and_cx` (#47092)
09 авг 2026, 00:46
Не верифицирован
09 авг 2026, 00:46
9978b48
Код
Авторство
О чём код?
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use dom_struct::dom_struct; use js::context::JSContext; use js::rust::HandleObject; use script_bindings::codegen::GenericBindings::NodeBinding::NodeMethods; use script_bindings::inheritance::Castable; use script_bindings::reflector::reflect_dom_object_with_proto; use stylo_atoms::Atom; use crate::dom::bindings::codegen::Bindings::CommandEventBinding; use crate::dom::bindings::codegen::Bindings::CommandEventBinding::CommandEventMethods; use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods; use crate::dom::bindings::error::Fallible; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::DOMString; use crate::dom::element::Element; use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::eventtarget::EventTarget; use crate::dom::node::Node; use crate::dom::types::Window; #[dom_struct] pub(crate) struct CommandEvent { event: Event, /// <https://html.spec.whatwg.org/multipage/#dom-commandevent-source> source: Option<Dom<Element>>, /// <https://html.spec.whatwg.org/multipage/#dom-commandevent-command> command: DOMString, } impl CommandEvent { pub(crate) fn new_inherited(source: Option<&Element>, command: DOMString) -> CommandEvent { CommandEvent { event: Event::new_inherited(), source: source.map(Dom::from_ref), command, } } #[allow(clippy::too_many_arguments)] fn new_with_proto( cx: &mut JSContext, window: &Window, proto: Option<HandleObject>, type_: Atom, bubbles: EventBubbles, cancelable: EventCancelable, source: Option<&Element>, command: DOMString, ) -> DomRoot<CommandEvent> { let event = Box::new(CommandEvent::new_inherited(source, command)); let event = reflect_dom_object_with_proto(cx, event, window, proto); { let event = event.upcast::<Event>(); event.init_event(type_, bool::from(bubbles), bool::from(cancelable)); } event } #[allow(clippy::too_many_arguments)] pub(crate) fn new( cx: &mut JSContext, window: &Window, type_: Atom, bubbles: EventBubbles, cancelable: EventCancelable, source: Option<&Element>, command: DOMString, ) -> DomRoot<CommandEvent> { Self::new_with_proto( cx, window, None, type_, bubbles, cancelable, source, command, ) } } impl CommandEventMethods<crate::DomTypeHolder> for CommandEvent { /// <https://html.spec.whatwg.org/multipage/#commandevent> fn Constructor( cx: &mut JSContext, window: &Window, proto: Option<HandleObject>, type_: DOMString, init: &CommandEventBinding::CommandEventInit, ) -> Fallible<DomRoot<CommandEvent>> { let bubbles = EventBubbles::from(init.parent.bubbles); let cancelable = EventCancelable::from(init.parent.cancelable); Ok(CommandEvent::new_with_proto( cx, window, proto, Atom::from(type_), bubbles, cancelable, init.source.as_deref(), init.command.clone(), )) } /// <https://dom.spec.whatwg.org/#dom-event-istrusted> fn IsTrusted(&self) -> bool { self.event.IsTrusted() } /// <https://html.spec.whatwg.org/multipage/#dom-commandevent-command> fn Command(&self) -> DOMString { // The command attribute must return the value it was initialized to. self.command.clone() } /// <https://html.spec.whatwg.org/multipage/#dom-commandevent-source> fn GetSource(&self) -> Option<DomRoot<Element>> { // The source getter steps are to return the result of retargeting source against this's currentTarget. let source = self.source.as_ref()?; if let Some(current_target) = self.event.GetCurrentTarget() { let retargeted = source.upcast::<EventTarget>().retarget(¤t_target); return retargeted.downcast::<Element>().map(DomRoot::from_ref); } let document = source.upcast::<Node>().GetOwnerDocument().unwrap(); let retargeted = source .upcast::<EventTarget>() .retarget(document.upcast::<EventTarget>()); retargeted.downcast::<Element>().map(DomRoot::from_ref) } }