mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Minor refactoring of mouse event types
* Move some types into the `msg` crate so they can be shared more. * Use MouseEventType instead of duplicating it in other enums.
This commit is contained in:
parent
2be60be062
commit
8c4fed42b0
13 changed files with 43 additions and 64 deletions
|
@ -30,13 +30,13 @@ use msg::compositor_msg::{Epoch, EventResult, FrameTreeId, LayerId, LayerKind};
|
||||||
use msg::compositor_msg::{LayerProperties, ScrollPolicy};
|
use msg::compositor_msg::{LayerProperties, ScrollPolicy};
|
||||||
use msg::constellation_msg::CompositorMsg as ConstellationMsg;
|
use msg::constellation_msg::CompositorMsg as ConstellationMsg;
|
||||||
use msg::constellation_msg::{AnimationState, Image, PixelFormat};
|
use msg::constellation_msg::{AnimationState, Image, PixelFormat};
|
||||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData};
|
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData, MouseButton};
|
||||||
use msg::constellation_msg::{NavigationDirection, PipelineId, WindowSizeData};
|
use msg::constellation_msg::{NavigationDirection, PipelineId, WindowSizeData};
|
||||||
use pipeline::CompositionPipeline;
|
use pipeline::CompositionPipeline;
|
||||||
use profile_traits::mem::{self, ReportKind, Reporter, ReporterRequest};
|
use profile_traits::mem::{self, ReportKind, Reporter, ReporterRequest};
|
||||||
use profile_traits::time::{self, ProfilerCategory, profile};
|
use profile_traits::time::{self, ProfilerCategory, profile};
|
||||||
use script_traits::CompositorEvent::{MouseMoveEvent, TouchEvent};
|
use script_traits::CompositorEvent::{MouseMoveEvent, TouchEvent};
|
||||||
use script_traits::{ConstellationControlMsg, LayoutControlMsg, MouseButton};
|
use script_traits::{ConstellationControlMsg, LayoutControlMsg};
|
||||||
use script_traits::{TouchEventType, TouchId};
|
use script_traits::{TouchEventType, TouchId};
|
||||||
use scrolling::ScrollingTimerProxy;
|
use scrolling::ScrollingTimerProxy;
|
||||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
|
|
|
@ -12,9 +12,9 @@ use layers::color::Color;
|
||||||
use layers::geometry::LayerPixel;
|
use layers::geometry::LayerPixel;
|
||||||
use layers::layers::{Layer, LayerBufferSet};
|
use layers::layers::{Layer, LayerBufferSet};
|
||||||
use msg::compositor_msg::{Epoch, LayerId, LayerProperties, ScrollPolicy};
|
use msg::compositor_msg::{Epoch, LayerId, LayerProperties, ScrollPolicy};
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::{MouseEventType, PipelineId};
|
||||||
use script_traits::CompositorEvent;
|
use script_traits::CompositorEvent;
|
||||||
use script_traits::CompositorEvent::{ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent};
|
use script_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent};
|
||||||
use script_traits::ConstellationControlMsg;
|
use script_traits::ConstellationControlMsg;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use windowing::{MouseWindowEvent, WindowMethods};
|
use windowing::{MouseWindowEvent, WindowMethods};
|
||||||
|
@ -372,11 +372,11 @@ impl CompositorLayer for Layer<CompositorData> {
|
||||||
let event_point = cursor.to_untyped();
|
let event_point = cursor.to_untyped();
|
||||||
let message = match event {
|
let message = match event {
|
||||||
MouseWindowEvent::Click(button, _) =>
|
MouseWindowEvent::Click(button, _) =>
|
||||||
ClickEvent(button, event_point),
|
MouseButtonEvent(MouseEventType::Click, button, event_point),
|
||||||
MouseWindowEvent::MouseDown(button, _) =>
|
MouseWindowEvent::MouseDown(button, _) =>
|
||||||
MouseDownEvent(button, event_point),
|
MouseButtonEvent(MouseEventType::MouseDown, button, event_point),
|
||||||
MouseWindowEvent::MouseUp(button, _) =>
|
MouseWindowEvent::MouseUp(button, _) =>
|
||||||
MouseUpEvent(button, event_point),
|
MouseButtonEvent(MouseEventType::MouseUp, button, event_point),
|
||||||
};
|
};
|
||||||
self.send_event(compositor, message);
|
self.send_event(compositor, message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ use euclid::size::TypedSize2D;
|
||||||
use euclid::{Point2D, Size2D};
|
use euclid::{Point2D, Size2D};
|
||||||
use layers::geometry::DevicePixel;
|
use layers::geometry::DevicePixel;
|
||||||
use layers::platform::surface::NativeDisplay;
|
use layers::platform::surface::NativeDisplay;
|
||||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
|
use msg::constellation_msg::{Key, KeyModifiers, KeyState, MouseButton};
|
||||||
use net_traits::net_error_list::NetError;
|
use net_traits::net_error_list::NetError;
|
||||||
use script_traits::{MouseButton, TouchEventType, TouchId};
|
use script_traits::{TouchEventType, TouchId};
|
||||||
use std::fmt::{Debug, Error, Formatter};
|
use std::fmt::{Debug, Error, Formatter};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -27,7 +27,6 @@ pub enum MouseWindowEvent {
|
||||||
MouseUp(MouseButton, TypedPoint2D<DevicePixel, f32>),
|
MouseUp(MouseButton, TypedPoint2D<DevicePixel, f32>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum WindowNavigateMsg {
|
pub enum WindowNavigateMsg {
|
||||||
Forward,
|
Forward,
|
||||||
|
|
|
@ -307,6 +307,24 @@ pub enum ScriptMsg {
|
||||||
ViewportConstrained(PipelineId, ViewportConstraints),
|
ViewportConstrained(PipelineId, ViewportConstraints),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, HeapSizeOf, Serialize)]
|
||||||
|
pub enum MouseEventType {
|
||||||
|
Click,
|
||||||
|
MouseDown,
|
||||||
|
MouseUp,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The mouse button involved in the event.
|
||||||
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||||
|
pub enum MouseButton {
|
||||||
|
/// The left mouse button.
|
||||||
|
Left,
|
||||||
|
/// The middle mouse button.
|
||||||
|
Middle,
|
||||||
|
/// The right mouse button.
|
||||||
|
Right,
|
||||||
|
}
|
||||||
|
|
||||||
/// Messages from the paint task to the constellation.
|
/// Messages from the paint task to the constellation.
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub enum PaintMsg {
|
pub enum PaintMsg {
|
||||||
|
|
|
@ -82,13 +82,14 @@ use msg::compositor_msg::ScriptToCompositorMsg;
|
||||||
use msg::constellation_msg::ScriptMsg as ConstellationMsg;
|
use msg::constellation_msg::ScriptMsg as ConstellationMsg;
|
||||||
use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
|
use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
|
||||||
use msg::constellation_msg::{AnimationState, PipelineId};
|
use msg::constellation_msg::{AnimationState, PipelineId};
|
||||||
use msg::constellation_msg::{ConstellationChan, FocusType, Key, KeyModifiers, KeyState, MozBrowserEvent, SubpageId};
|
use msg::constellation_msg::{ConstellationChan, FocusType, Key, KeyModifiers, KeyState};
|
||||||
|
use msg::constellation_msg::{MouseButton, MouseEventType, MozBrowserEvent, SubpageId};
|
||||||
use net_traits::ControlMsg::{GetCookiesForUrl, SetCookiesForUrl};
|
use net_traits::ControlMsg::{GetCookiesForUrl, SetCookiesForUrl};
|
||||||
use net_traits::CookieSource::NonHTTP;
|
use net_traits::CookieSource::NonHTTP;
|
||||||
use net_traits::{AsyncResponseTarget, PendingAsyncLoad};
|
use net_traits::{AsyncResponseTarget, PendingAsyncLoad};
|
||||||
use num::ToPrimitive;
|
use num::ToPrimitive;
|
||||||
use script_task::{MainThreadScriptMsg, Runnable};
|
use script_task::{MainThreadScriptMsg, Runnable};
|
||||||
use script_traits::{MouseButton, TouchEventType, TouchId, UntrustedNodeAddress};
|
use script_traits::{TouchEventType, TouchId, UntrustedNodeAddress};
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::boxed::FnBox;
|
use std::boxed::FnBox;
|
||||||
|
@ -1362,14 +1363,6 @@ impl Document {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(HeapSizeOf)]
|
|
||||||
pub enum MouseEventType {
|
|
||||||
Click,
|
|
||||||
MouseDown,
|
|
||||||
MouseUp,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(PartialEq, HeapSizeOf)]
|
#[derive(PartialEq, HeapSizeOf)]
|
||||||
pub enum DocumentSource {
|
pub enum DocumentSource {
|
||||||
FromParser,
|
FromParser,
|
||||||
|
|
|
@ -31,8 +31,7 @@ use dom::bindings::js::{Root, RootCollectionPtr, RootedReference};
|
||||||
use dom::bindings::refcounted::{LiveDOMReferences, Trusted, TrustedReference, trace_refcounted_objects};
|
use dom::bindings::refcounted::{LiveDOMReferences, Trusted, TrustedReference, trace_refcounted_objects};
|
||||||
use dom::bindings::trace::{JSTraceable, RootedVec, trace_traceables};
|
use dom::bindings::trace::{JSTraceable, RootedVec, trace_traceables};
|
||||||
use dom::bindings::utils::{DOM_CALLBACKS, WRAP_CALLBACKS};
|
use dom::bindings::utils::{DOM_CALLBACKS, WRAP_CALLBACKS};
|
||||||
use dom::document::{Document, DocumentProgressHandler, IsHTMLDocument};
|
use dom::document::{Document, DocumentProgressHandler, DocumentSource, IsHTMLDocument};
|
||||||
use dom::document::{DocumentSource, MouseEventType};
|
|
||||||
use dom::element::Element;
|
use dom::element::Element;
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::htmlanchorelement::HTMLAnchorElement;
|
use dom::htmlanchorelement::HTMLAnchorElement;
|
||||||
|
@ -65,7 +64,7 @@ use mem::heap_size_of_self_and_children;
|
||||||
use msg::compositor_msg::{EventResult, LayerId, ScriptToCompositorMsg};
|
use msg::compositor_msg::{EventResult, LayerId, ScriptToCompositorMsg};
|
||||||
use msg::constellation_msg::ScriptMsg as ConstellationMsg;
|
use msg::constellation_msg::ScriptMsg as ConstellationMsg;
|
||||||
use msg::constellation_msg::{ConstellationChan, FocusType, LoadData};
|
use msg::constellation_msg::{ConstellationChan, FocusType, LoadData};
|
||||||
use msg::constellation_msg::{MozBrowserEvent, PipelineId};
|
use msg::constellation_msg::{MouseButton, MouseEventType, MozBrowserEvent, PipelineId};
|
||||||
use msg::constellation_msg::{PipelineNamespace};
|
use msg::constellation_msg::{PipelineNamespace};
|
||||||
use msg::constellation_msg::{SubpageId, WindowSizeData, WorkerId};
|
use msg::constellation_msg::{SubpageId, WindowSizeData, WorkerId};
|
||||||
use msg::webdriver_msg::WebDriverScriptCommand;
|
use msg::webdriver_msg::WebDriverScriptCommand;
|
||||||
|
@ -78,11 +77,9 @@ use page::{Frame, IterablePage, Page};
|
||||||
use parse::html::{ParseContext, parse_html};
|
use parse::html::{ParseContext, parse_html};
|
||||||
use profile_traits::mem::{self, OpaqueSender, Report, ReportKind, ReportsChan};
|
use profile_traits::mem::{self, OpaqueSender, Report, ReportKind, ReportsChan};
|
||||||
use profile_traits::time::{self, ProfilerCategory, profile};
|
use profile_traits::time::{self, ProfilerCategory, profile};
|
||||||
use script_traits::CompositorEvent::{ClickEvent, ResizeEvent};
|
use script_traits::CompositorEvent::{KeyEvent, MouseButtonEvent, MouseMoveEvent, ResizeEvent};
|
||||||
use script_traits::CompositorEvent::{KeyEvent, MouseMoveEvent};
|
use script_traits::CompositorEvent::{TouchEvent};
|
||||||
use script_traits::CompositorEvent::{MouseDownEvent, MouseUpEvent, TouchEvent};
|
use script_traits::{CompositorEvent, ConstellationControlMsg, InitialScriptState, NewLayoutInfo};
|
||||||
use script_traits::{CompositorEvent, ConstellationControlMsg};
|
|
||||||
use script_traits::{InitialScriptState, MouseButton, NewLayoutInfo};
|
|
||||||
use script_traits::{OpaqueScriptLayoutChannel, ScriptState, ScriptTaskFactory};
|
use script_traits::{OpaqueScriptLayoutChannel, ScriptState, ScriptTaskFactory};
|
||||||
use script_traits::{TimerEvent, TimerEventRequest, TimerSource};
|
use script_traits::{TimerEvent, TimerEventRequest, TimerSource};
|
||||||
use script_traits::{TouchEventType, TouchId};
|
use script_traits::{TouchEventType, TouchId};
|
||||||
|
@ -1786,16 +1783,8 @@ impl ScriptTask {
|
||||||
self.handle_resize_event(pipeline_id, new_size);
|
self.handle_resize_event(pipeline_id, new_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClickEvent(button, point) => {
|
MouseButtonEvent(event_type, button, point) => {
|
||||||
self.handle_mouse_event(pipeline_id, MouseEventType::Click, button, point);
|
self.handle_mouse_event(pipeline_id, event_type, button, point);
|
||||||
}
|
|
||||||
|
|
||||||
MouseDownEvent(button, point) => {
|
|
||||||
self.handle_mouse_event(pipeline_id, MouseEventType::MouseDown, button, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseUpEvent(button, point) => {
|
|
||||||
self.handle_mouse_event(pipeline_id, MouseEventType::MouseUp, button, point);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseMoveEvent(point) => {
|
MouseMoveEvent(point) => {
|
||||||
|
|
|
@ -34,6 +34,7 @@ use msg::compositor_msg::{Epoch, LayerId, ScriptToCompositorMsg};
|
||||||
use msg::constellation_msg::ScriptMsg as ConstellationMsg;
|
use msg::constellation_msg::ScriptMsg as ConstellationMsg;
|
||||||
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId, WindowSizeData};
|
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId, WindowSizeData};
|
||||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData, SubpageId};
|
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData, SubpageId};
|
||||||
|
use msg::constellation_msg::{MouseButton, MouseEventType};
|
||||||
use msg::constellation_msg::{MozBrowserEvent, PipelineNamespaceId};
|
use msg::constellation_msg::{MozBrowserEvent, PipelineNamespaceId};
|
||||||
use msg::webdriver_msg::WebDriverScriptCommand;
|
use msg::webdriver_msg::WebDriverScriptCommand;
|
||||||
use net_traits::ResourceTask;
|
use net_traits::ResourceTask;
|
||||||
|
@ -146,17 +147,6 @@ pub enum ConstellationControlMsg {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The mouse button involved in the event.
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
|
||||||
pub enum MouseButton {
|
|
||||||
/// The left mouse button.
|
|
||||||
Left,
|
|
||||||
/// The middle mouse button.
|
|
||||||
Middle,
|
|
||||||
/// The right mouse button.
|
|
||||||
Right,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The type of input represented by a multi-touch event.
|
/// The type of input represented by a multi-touch event.
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||||
pub enum TouchEventType {
|
pub enum TouchEventType {
|
||||||
|
@ -181,12 +171,8 @@ pub struct TouchId(pub i32);
|
||||||
pub enum CompositorEvent {
|
pub enum CompositorEvent {
|
||||||
/// The window was resized.
|
/// The window was resized.
|
||||||
ResizeEvent(WindowSizeData),
|
ResizeEvent(WindowSizeData),
|
||||||
/// A point was clicked.
|
/// A mouse button state changed.
|
||||||
ClickEvent(MouseButton, Point2D<f32>),
|
MouseButtonEvent(MouseEventType, MouseButton, Point2D<f32>),
|
||||||
/// A mouse button was pressed on a point.
|
|
||||||
MouseDownEvent(MouseButton, Point2D<f32>),
|
|
||||||
/// A mouse button was released on a point.
|
|
||||||
MouseUpEvent(MouseButton, Point2D<f32>),
|
|
||||||
/// The mouse was moved over a point (or was moved out of the recognizable region).
|
/// The mouse was moved over a point (or was moved out of the recognizable region).
|
||||||
MouseMoveEvent(Option<Point2D<f32>>),
|
MouseMoveEvent(Option<Point2D<f32>>),
|
||||||
/// A touch event was generated with a touch ID and location.
|
/// A touch event was generated with a touch ID and location.
|
||||||
|
|
|
@ -14,8 +14,7 @@ use compositing::windowing::{WindowEvent, MouseWindowEvent};
|
||||||
use euclid::point::Point2D;
|
use euclid::point::Point2D;
|
||||||
use euclid::size::Size2D;
|
use euclid::size::Size2D;
|
||||||
use libc::{c_double, c_int};
|
use libc::{c_double, c_int};
|
||||||
use msg::constellation_msg::{self, KeyModifiers, KeyState};
|
use msg::constellation_msg::{self, KeyModifiers, KeyState, MouseButton};
|
||||||
use script_traits::MouseButton;
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
|
||||||
pub struct ServoCefBrowserHost {
|
pub struct ServoCefBrowserHost {
|
||||||
|
|
|
@ -253,7 +253,7 @@ impl Window {
|
||||||
|
|
||||||
/// Helper function to handle a click
|
/// Helper function to handle a click
|
||||||
fn handle_mouse(&self, button: glutin::MouseButton, action: glutin::ElementState, x: i32, y: i32) {
|
fn handle_mouse(&self, button: glutin::MouseButton, action: glutin::ElementState, x: i32, y: i32) {
|
||||||
use script_traits::MouseButton;
|
use msg::constellation_msg::MouseButton;
|
||||||
|
|
||||||
// FIXME(tkuehn): max pixel dist should be based on pixel density
|
// FIXME(tkuehn): max pixel dist should be based on pixel density
|
||||||
let max_pixel_dist = 10f64;
|
let max_pixel_dist = 10f64;
|
||||||
|
|
1
ports/gonk/Cargo.lock
generated
1
ports/gonk/Cargo.lock
generated
|
@ -17,7 +17,6 @@ dependencies = [
|
||||||
"net_traits 0.0.1",
|
"net_traits 0.0.1",
|
||||||
"profile 0.0.1",
|
"profile 0.0.1",
|
||||||
"script 0.0.1",
|
"script 0.0.1",
|
||||||
"script_traits 0.0.1",
|
|
||||||
"servo 0.0.1",
|
"servo 0.0.1",
|
||||||
"time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
"time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"url 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"url 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -18,9 +18,6 @@ path = "../../components/msg"
|
||||||
[dependencies.script]
|
[dependencies.script]
|
||||||
path = "../../components/script"
|
path = "../../components/script"
|
||||||
|
|
||||||
[dependencies.script_traits]
|
|
||||||
path = "../../components/script_traits"
|
|
||||||
|
|
||||||
[dependencies.net_traits]
|
[dependencies.net_traits]
|
||||||
path = "../../components/net_traits"
|
path = "../../components/net_traits"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use compositing::windowing::{WindowEvent, MouseWindowEvent};
|
||||||
use errno::errno;
|
use errno::errno;
|
||||||
use euclid::point::Point2D;
|
use euclid::point::Point2D;
|
||||||
use libc::{c_int, c_long, time_t};
|
use libc::{c_int, c_long, time_t};
|
||||||
use script_traits::MouseButton;
|
use msg::constellation_msg::MouseButton;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::mem::{size_of, transmute, zeroed};
|
use std::mem::{size_of, transmute, zeroed};
|
||||||
|
|
|
@ -33,7 +33,6 @@ extern crate layers;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate msg;
|
extern crate msg;
|
||||||
extern crate net_traits;
|
extern crate net_traits;
|
||||||
extern crate script_traits;
|
|
||||||
extern crate servo;
|
extern crate servo;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue