diff options
author | Pyfisch <pyfisch@gmail.com> | 2018-11-17 17:02:31 +0100 |
---|---|---|
committer | Pyfisch <pyfisch@gmail.com> | 2018-11-19 22:07:05 +0100 |
commit | b936fea79de985213c053e67f77458b37f4b2995 (patch) | |
tree | ce7ef296552b39c9a5d3c427f3d1d1a955cb9216 /components/script/dom/document.rs | |
parent | 1ac6f435c8637d01279b51fecb535a19b639aea5 (diff) | |
download | servo-b936fea79de985213c053e67f77458b37f4b2995.tar.gz servo-b936fea79de985213c053e67f77458b37f4b2995.zip |
Forward WebDriver CompositionEvent
Dispatch composition events in JS.
Insert characters from composition events to text input.
CompositionEvents currently can only be
created by WebDriver and not by embedders.
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index a18da3f112f..fdebc5e69b2 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -38,6 +38,7 @@ use crate::dom::bindings::xmlname::{ }; use crate::dom::closeevent::CloseEvent; use crate::dom::comment::Comment; +use crate::dom::compositionevent::CompositionEvent; use crate::dom::cssstylesheet::CSSStyleSheet; use crate::dom::customelementregistry::CustomElementDefinition; use crate::dom::customevent::CustomEvent; @@ -1465,6 +1466,37 @@ impl Document { self.window.reflow(ReflowGoal::Full, ReflowReason::KeyEvent); } + pub fn dispatch_composition_event( + &self, + composition_event: ::keyboard_types::CompositionEvent, + ) { + // spec: https://w3c.github.io/uievents/#compositionstart + // spec: https://w3c.github.io/uievents/#compositionupdate + // spec: https://w3c.github.io/uievents/#compositionend + // > Event.target : focused element processing the composition + let focused = self.get_focused_element(); + let target = if let Some(elem) = &focused { + elem.upcast() + } else { + // Event is only dispatched if there is a focused element. + return; + }; + + let cancelable = composition_event.state == keyboard_types::CompositionState::Start; + + let compositionevent = CompositionEvent::new( + &self.window, + DOMString::from(composition_event.state.to_string()), + true, + cancelable, + Some(&self.window), + 0, + DOMString::from(composition_event.data), + ); + let event = compositionevent.upcast::<Event>(); + event.fire(target); + } + // https://dom.spec.whatwg.org/#converting-nodes-into-a-node pub fn node_from_nodes_and_strings( &self, |