mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
auto merge of #5004 : Ms2ger/servo/handle_click_event, r=jdm
This commit is contained in:
commit
e68d6d2924
1 changed files with 42 additions and 41 deletions
|
@ -400,52 +400,53 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
let window = window.r();
|
let window = window.r();
|
||||||
let page = window.page();
|
let page = window.page();
|
||||||
match page.hit_test(&point) {
|
let node = match page.hit_test(&point) {
|
||||||
Some(node_address) => {
|
Some(node_address) => {
|
||||||
debug!("node address is {:?}", node_address.0);
|
debug!("node address is {:?}", node_address.0);
|
||||||
|
node::from_untrusted_node_address(js_runtime, node_address)
|
||||||
|
},
|
||||||
|
None => return,
|
||||||
|
}.root();
|
||||||
|
|
||||||
let temp_node =
|
let el = match ElementCast::to_ref(node.r()) {
|
||||||
node::from_untrusted_node_address(
|
Some(el) => el,
|
||||||
js_runtime, node_address).root();
|
None => {
|
||||||
|
let ancestor = node.r()
|
||||||
let maybe_elem: Option<JSRef<Element>> = ElementCast::to_ref(temp_node.r());
|
.ancestors()
|
||||||
let maybe_node = match maybe_elem {
|
.filter_map(ElementCast::to_ref)
|
||||||
Some(element) => Some(element),
|
.next();
|
||||||
None => temp_node.r().ancestors().filter_map(ElementCast::to_ref).next(),
|
match ancestor {
|
||||||
};
|
Some(ancestor) => ancestor,
|
||||||
|
None => return,
|
||||||
match maybe_node {
|
|
||||||
Some(el) => {
|
|
||||||
let node: JSRef<Node> = NodeCast::from_ref(el);
|
|
||||||
debug!("clicked on {:?}", node.debug_str());
|
|
||||||
// Prevent click event if form control element is disabled.
|
|
||||||
if node.click_event_filter_by_disabled_state() { return; }
|
|
||||||
match *page.frame() {
|
|
||||||
Some(ref frame) => {
|
|
||||||
let window = frame.window.root();
|
|
||||||
let doc = window.r().Document().root();
|
|
||||||
doc.r().begin_focus_transaction();
|
|
||||||
|
|
||||||
let event =
|
|
||||||
Event::new(GlobalRef::Window(window.r()),
|
|
||||||
"click".to_owned(),
|
|
||||||
EventBubbles::Bubbles,
|
|
||||||
EventCancelable::Cancelable).root();
|
|
||||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#trusted-events
|
|
||||||
event.r().set_trusted(true);
|
|
||||||
// https://html.spec.whatwg.org/multipage/interaction.html#run-authentic-click-activation-steps
|
|
||||||
el.authentic_click_activation(event.r());
|
|
||||||
|
|
||||||
doc.r().commit_focus_transaction();
|
|
||||||
window.r().flush_layout(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery);
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let node: JSRef<Node> = NodeCast::from_ref(el);
|
||||||
|
debug!("clicked on {:?}", node.debug_str());
|
||||||
|
// Prevent click event if form control element is disabled.
|
||||||
|
if node.click_event_filter_by_disabled_state() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
match *page.frame() {
|
||||||
|
Some(ref frame) => {
|
||||||
|
let window = frame.window.root();
|
||||||
|
let doc = window.r().Document().root();
|
||||||
|
doc.r().begin_focus_transaction();
|
||||||
|
|
||||||
|
let event = Event::new(GlobalRef::Window(window.r()),
|
||||||
|
"click".to_owned(),
|
||||||
|
EventBubbles::Bubbles,
|
||||||
|
EventCancelable::Cancelable).root();
|
||||||
|
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#trusted-events
|
||||||
|
event.r().set_trusted(true);
|
||||||
|
// https://html.spec.whatwg.org/multipage/interaction.html#run-authentic-click-activation-steps
|
||||||
|
el.authentic_click_activation(event.r());
|
||||||
|
|
||||||
|
doc.r().commit_focus_transaction();
|
||||||
|
window.r().flush_layout(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery);
|
||||||
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue