mirror of
https://github.com/servo/servo.git
synced 2025-06-19 14:48:59 +01:00
Auto merge of #18957 - mhaessig:fire-mouse-event-enum, r=jdm
Made fire_mouse_event take an enum for event_name Added an enum with the mouse event options for `fire_mouse_event` and refactored the `event_name` parameter to take the enum as argument. I also added two options (Leave and Enter) which are noted as todo in the comments. - [x] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These Changes fix #18943. - [X] These changes do not require tests because the issue said a clean build suffices. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18957) <!-- Reviewable:end -->
This commit is contained in:
commit
1b08bfc5c0
1 changed files with 21 additions and 5 deletions
|
@ -158,6 +158,22 @@ pub enum TouchEventResult {
|
|||
Forwarded,
|
||||
}
|
||||
|
||||
pub enum FireMouseEventType {
|
||||
Move,
|
||||
Over,
|
||||
Out,
|
||||
}
|
||||
|
||||
impl FireMouseEventType {
|
||||
pub fn as_str(&self) -> &str {
|
||||
match self {
|
||||
&FireMouseEventType::Move => "mousemove",
|
||||
&FireMouseEventType::Over => "mouseout",
|
||||
&FireMouseEventType::Out => "mouseover",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
pub enum IsHTMLDocument {
|
||||
HTMLDocument,
|
||||
|
@ -1037,13 +1053,13 @@ impl Document {
|
|||
event.fire(target);
|
||||
}
|
||||
|
||||
pub fn fire_mouse_event(&self, client_point: Point2D<f32>, target: &EventTarget, event_name: String) {
|
||||
pub fn fire_mouse_event(&self, client_point: Point2D<f32>, target: &EventTarget, event_name: FireMouseEventType) {
|
||||
let client_x = client_point.x.to_i32().unwrap_or(0);
|
||||
let client_y = client_point.y.to_i32().unwrap_or(0);
|
||||
|
||||
let mouse_event = MouseEvent::new(
|
||||
&self.window,
|
||||
DOMString::from(event_name),
|
||||
DOMString::from(event_name.as_str()),
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::Cancelable,
|
||||
Some(&self.window),
|
||||
|
@ -1096,7 +1112,7 @@ impl Document {
|
|||
None => return,
|
||||
};
|
||||
|
||||
self.fire_mouse_event(client_point, new_target.upcast(), "mousemove".to_owned());
|
||||
self.fire_mouse_event(client_point, new_target.upcast(), FireMouseEventType::Move);
|
||||
|
||||
// Nothing more to do here, mousemove is sent,
|
||||
// and the element under the mouse hasn't changed.
|
||||
|
@ -1125,7 +1141,7 @@ impl Document {
|
|||
}
|
||||
|
||||
// Remove hover state to old target and its parents
|
||||
self.fire_mouse_event(client_point, old_target.upcast(), "mouseout".to_owned());
|
||||
self.fire_mouse_event(client_point, old_target.upcast(), FireMouseEventType::Out);
|
||||
|
||||
// TODO: Fire mouseleave here only if the old target is
|
||||
// not an ancestor of the new target.
|
||||
|
@ -1142,7 +1158,7 @@ impl Document {
|
|||
element.set_hover_state(true);
|
||||
}
|
||||
|
||||
self.fire_mouse_event(client_point, &new_target.upcast(), "mouseover".to_owned());
|
||||
self.fire_mouse_event(client_point, &new_target.upcast(), FireMouseEventType::Over);
|
||||
|
||||
// TODO: Fire mouseenter here.
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue