aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/node.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2020-02-13 17:37:12 -0500
committerGitHub <noreply@github.com>2020-02-13 17:37:12 -0500
commite697e6cca70bec57b5ed9512b95c2a72359d6ca1 (patch)
tree99fa07d2761b0ff18f7c166b8f0a98e1fc8b513e /components/script/dom/node.rs
parent9c135f0e9554bd78bb7a432a872257e2cae13a48 (diff)
parent01aba1fcc453192da64272dcc180135ce11e4ea7 (diff)
downloadservo-e697e6cca70bec57b5ed9512b95c2a72359d6ca1.tar.gz
servo-e697e6cca70bec57b5ed9512b95c2a72359d6ca1.zip
Auto merge of #25488 - pshaughn:clickactivate, r=jdm
Event dispatch rewritten to align to spec, activate on clicks better I went over the changes to the event dispatch spec that had accumulated over the past few years, rewriting dispatch/invoke/inner-invoke almost completely and modifying other code where it was relevant. Most of the remaining obvious deviations from spec are things that will only come up when we start handling events in shadow DOM. I am pushing now because I want to see CI test results, but please do not approve this PR just if automated test improvements look good. I may have broken some actual UI interactions in the course of fixing synthetic events, and some manual testing is needed, including checking that manual interactions with interactive content continue to fire the events they're supposed to. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #25384 and fix #22783 and fix #25199 <!-- Either: --> - [ ] There are automated tests for the synthetic-click parts of these changes, BUT the effects on real UI events need some manual testing before merging <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/script/dom/node.rs')
-rw-r--r--components/script/dom/node.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index b6d4389d441..0081e997bb9 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -37,6 +37,7 @@ use crate::dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLD
use crate::dom::documentfragment::DocumentFragment;
use crate::dom::documenttype::DocumentType;
use crate::dom::element::{CustomElementCreationMode, Element, ElementCreator};
+use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlbodyelement::HTMLBodyElement;
@@ -51,6 +52,7 @@ use crate::dom::htmlmediaelement::{HTMLMediaElement, LayoutHTMLMediaElementHelpe
use crate::dom::htmlmetaelement::HTMLMetaElement;
use crate::dom::htmlstyleelement::HTMLStyleElement;
use crate::dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaElementHelpers};
+use crate::dom::mouseevent::MouseEvent;
use crate::dom::mutationobserver::{Mutation, MutationObserver, RegisteredObserver};
use crate::dom::nodelist::NodeList;
use crate::dom::processinginstruction::ProcessingInstruction;
@@ -389,6 +391,46 @@ impl Node {
}
})
}
+
+ // https://html.spec.whatg.org/#fire_a_synthetic_mouse_event
+ pub fn fire_synthetic_mouse_event_not_trusted(&self, name: DOMString) {
+ // Spec says the choice of which global to create
+ // the mouse event on is not well-defined,
+ // and refers to heycam/webidl#135
+ let win = window_from_node(self);
+
+ let mouse_event = MouseEvent::new(
+ &win, // ambiguous in spec
+ name,
+ EventBubbles::Bubbles, // Step 3: bubbles
+ EventCancelable::Cancelable, // Step 3: cancelable,
+ Some(&win), // Step 7: view (this is unambiguous in spec)
+ 0, // detail uninitialized
+ 0, // coordinates uninitialized
+ 0, // coordinates uninitialized
+ 0, // coordinates uninitialized
+ 0, // coordinates uninitialized
+ false,
+ false,
+ false,
+ false, // Step 6 modifier keys TODO compositor hook needed
+ 0, // button uninitialized (and therefore left)
+ 0, // buttons uninitialized (and therefore none)
+ None, // related_target uninitialized,
+ None, // point_in_target uninitialized,
+ );
+
+ // Step 4: TODO composed flag for shadow root
+
+ // Step 5
+ mouse_event.upcast::<Event>().set_trusted(false);
+
+ // Step 8: TODO keyboard modifiers
+
+ mouse_event
+ .upcast::<Event>()
+ .dispatch(self.upcast::<EventTarget>(), false);
+ }
}
pub struct QuerySelectorIterator {