mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Fix comments for handle_mouse_move_event method
This commit is contained in:
parent
c235e1ee43
commit
da45522085
1 changed files with 42 additions and 47 deletions
|
@ -1406,21 +1406,16 @@ impl Document {
|
||||||
.map_or(true, |old_target| old_target != new_target);
|
.map_or(true, |old_target| old_target != new_target);
|
||||||
|
|
||||||
// Here we know the target has changed, so we must update the state,
|
// Here we know the target has changed, so we must update the state,
|
||||||
// dispatch mouseout to the previous one, mouseover to the new one,
|
// dispatch mouseout to the previous one, mouseover to the new one.
|
||||||
if target_has_changed {
|
if target_has_changed {
|
||||||
// Dispatch mouseout to previous target
|
// Dispatch mouseout and mouseleave to previous target.
|
||||||
if let Some(old_target) = prev_mouse_over_target.get() {
|
if let Some(old_target) = prev_mouse_over_target.get() {
|
||||||
let old_target_is_ancestor_of_new_target = prev_mouse_over_target
|
let old_target_is_ancestor_of_new_target = old_target
|
||||||
.get()
|
.upcast::<Node>()
|
||||||
.as_ref()
|
.is_ancestor_of(new_target.upcast::<Node>());
|
||||||
.map_or(false, |old_target| {
|
|
||||||
old_target
|
|
||||||
.upcast::<Node>()
|
|
||||||
.is_ancestor_of(new_target.upcast::<Node>())
|
|
||||||
});
|
|
||||||
|
|
||||||
// If the old target is an ancestor of the new target, this can be skipped
|
// If the old target is an ancestor of the new target, this can be skipped
|
||||||
// completely, since the node's hover state will be reseted below.
|
// completely, since the node's hover state will be reset below.
|
||||||
if !old_target_is_ancestor_of_new_target {
|
if !old_target_is_ancestor_of_new_target {
|
||||||
for element in old_target
|
for element in old_target
|
||||||
.upcast::<Node>()
|
.upcast::<Node>()
|
||||||
|
@ -1432,7 +1427,6 @@ impl Document {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove hover state to old target and its parents
|
|
||||||
self.fire_mouse_event(
|
self.fire_mouse_event(
|
||||||
client_point,
|
client_point,
|
||||||
old_target.upcast(),
|
old_target.upcast(),
|
||||||
|
@ -1455,41 +1449,38 @@ impl Document {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch mouseover to new target - TODO: Redundant check?
|
// Dispatch mouseover and mouseenter to new target.
|
||||||
if let Some(new_target) = maybe_new_target.as_ref() {
|
for element in new_target
|
||||||
for element in new_target
|
.upcast::<Node>()
|
||||||
.upcast::<Node>()
|
.inclusive_ancestors(ShadowIncluding::No)
|
||||||
.inclusive_ancestors(ShadowIncluding::No)
|
.filter_map(DomRoot::downcast::<Element>)
|
||||||
.filter_map(DomRoot::downcast::<Element>)
|
{
|
||||||
{
|
if element.hover_state() {
|
||||||
if element.hover_state() {
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
element.set_hover_state(true);
|
|
||||||
}
|
}
|
||||||
|
element.set_hover_state(true);
|
||||||
self.fire_mouse_event(
|
|
||||||
client_point,
|
|
||||||
new_target.upcast(),
|
|
||||||
FireMouseEventType::Over,
|
|
||||||
EventBubbles::Bubbles,
|
|
||||||
EventCancelable::Cancelable,
|
|
||||||
pressed_mouse_buttons,
|
|
||||||
);
|
|
||||||
|
|
||||||
let moving_from = prev_mouse_over_target
|
|
||||||
.get()
|
|
||||||
.map(|old_target| DomRoot::from_ref(old_target.upcast::<Node>()));
|
|
||||||
let event_target = DomRoot::from_ref(new_target.upcast::<Node>());
|
|
||||||
self.handle_mouse_enter_leave_event(
|
|
||||||
client_point,
|
|
||||||
FireMouseEventType::Enter,
|
|
||||||
moving_from,
|
|
||||||
event_target,
|
|
||||||
pressed_mouse_buttons,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.fire_mouse_event(
|
||||||
|
client_point,
|
||||||
|
new_target.upcast(),
|
||||||
|
FireMouseEventType::Over,
|
||||||
|
EventBubbles::Bubbles,
|
||||||
|
EventCancelable::Cancelable,
|
||||||
|
pressed_mouse_buttons,
|
||||||
|
);
|
||||||
|
|
||||||
|
let moving_from = prev_mouse_over_target
|
||||||
|
.get()
|
||||||
|
.map(|old_target| DomRoot::from_ref(old_target.upcast::<Node>()));
|
||||||
|
let event_target = DomRoot::from_ref(new_target.upcast::<Node>());
|
||||||
|
self.handle_mouse_enter_leave_event(
|
||||||
|
client_point,
|
||||||
|
FireMouseEventType::Enter,
|
||||||
|
moving_from,
|
||||||
|
event_target,
|
||||||
|
pressed_mouse_buttons,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send mousemove event to topmost target, unless it's an iframe, in which case the
|
// Send mousemove event to topmost target, unless it's an iframe, in which case the
|
||||||
|
@ -1503,10 +1494,9 @@ impl Document {
|
||||||
pressed_mouse_buttons,
|
pressed_mouse_buttons,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// If the target has changed then store the current mouse over target for next frame.
|
||||||
if target_has_changed {
|
if target_has_changed {
|
||||||
// Store the current mouse over target for next frame.
|
|
||||||
prev_mouse_over_target.set(maybe_new_target.as_deref());
|
prev_mouse_over_target.set(maybe_new_target.as_deref());
|
||||||
|
|
||||||
self.window
|
self.window
|
||||||
.reflow(ReflowGoal::Full, ReflowReason::MouseEvent);
|
.reflow(ReflowGoal::Full, ReflowReason::MouseEvent);
|
||||||
}
|
}
|
||||||
|
@ -1530,6 +1520,8 @@ impl Document {
|
||||||
|related_target| event_target.common_ancestor(related_target, ShadowIncluding::No),
|
|related_target| event_target.common_ancestor(related_target, ShadowIncluding::No),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// We need to create a target chain in case the event target shares
|
||||||
|
// its boundaries with its ancestors.
|
||||||
let mut targets = vec![];
|
let mut targets = vec![];
|
||||||
let mut current = Some(event_target);
|
let mut current = Some(event_target);
|
||||||
while let Some(node) = current {
|
while let Some(node) = current {
|
||||||
|
@ -1539,6 +1531,9 @@ impl Document {
|
||||||
current = node.GetParentNode();
|
current = node.GetParentNode();
|
||||||
targets.push(node);
|
targets.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The order for dispatching mouseenter events starts from the topmost
|
||||||
|
// common ancestor of the event target and the related target.
|
||||||
if event_type == FireMouseEventType::Enter {
|
if event_type == FireMouseEventType::Enter {
|
||||||
targets = targets.into_iter().rev().collect();
|
targets = targets.into_iter().rev().collect();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue