constellation: notify embedder when events are hit-tested to browsers (#30841)

* constellation: notify embedder when events are hit-tested to browsers

* fix compile error in libsimpleservo

* impl From<&CompositorEvent> for CompositorEventVariant

* remove msg temporaries in Constellation::forward_event

* use single wildcard arm in EventDelivered case in handle_servo_events
This commit is contained in:
Delan Azabani 2023-12-12 14:36:27 +08:00 committed by GitHub
parent 676c170b07
commit 8a226fdb19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 10 deletions

View file

@ -1548,9 +1548,10 @@ where
fn handle_request_from_script(&mut self, message: (PipelineId, FromScriptMsg)) {
let (source_pipeline_id, content) = message;
debug!(
trace!(
"{}: Message from pipeline: {:?}",
source_pipeline_id, content,
source_pipeline_id,
content,
);
let source_top_ctx_id = match self
@ -2904,15 +2905,23 @@ where
self.pressed_mouse_buttons = 0;
}
let msg = ConstellationControlMsg::SendEvent(destination_pipeline_id, event);
let result = match self.pipelines.get(&destination_pipeline_id) {
let pipeline = match self.pipelines.get(&destination_pipeline_id) {
None => {
debug!("{}: Got event after closure", destination_pipeline_id);
return;
},
Some(pipeline) => pipeline.event_loop.send(msg),
Some(pipeline) => pipeline,
};
if let Err(e) = result {
self.embedder_proxy.send((
Some(pipeline.top_level_browsing_context_id),
EmbedderMsg::EventDelivered((&event).into()),
));
if let Err(e) = pipeline.event_loop.send(ConstellationControlMsg::SendEvent(
destination_pipeline_id,
event,
)) {
self.handle_send_error(destination_pipeline_id, e);
}
}

View file

@ -208,6 +208,21 @@ pub enum EmbedderMsg {
OnDevtoolsStarted(Result<u16, ()>, String),
/// Compositing done, but external code needs to present.
ReadyToPresent,
/// The given event was delivered to a pipeline in the given browser.
EventDelivered(CompositorEventVariant),
}
/// The variant of CompositorEvent that was delivered to a pipeline.
#[derive(Debug, Deserialize, Serialize)]
pub enum CompositorEventVariant {
ResizeEvent,
MouseButtonEvent,
MouseMoveEvent,
TouchEvent,
WheelEvent,
KeyboardEvent,
CompositionEvent,
IMEDismissedEvent,
}
impl Debug for EmbedderMsg {
@ -245,6 +260,7 @@ impl Debug for EmbedderMsg {
EmbedderMsg::OnDevtoolsStarted(..) => write!(f, "OnDevtoolsStarted"),
EmbedderMsg::ShowContextMenu(..) => write!(f, "ShowContextMenu"),
EmbedderMsg::ReadyToPresent => write!(f, "ReadyToPresent"),
EmbedderMsg::EventDelivered(..) => write!(f, "HitTestedEvent"),
}
}
}

View file

@ -27,7 +27,7 @@ use canvas_traits::webgl::WebGLPipeline;
use compositor::ScrollTreeNodeId;
use crossbeam_channel::{Receiver, RecvTimeoutError, Sender};
use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId};
use embedder_traits::Cursor;
use embedder_traits::{CompositorEventVariant, Cursor};
use euclid::default::Point2D;
use euclid::{Length, Rect, Scale, Size2D, UnknownUnit, Vector2D};
use gfx_traits::Epoch;
@ -571,6 +571,21 @@ pub enum CompositorEvent {
IMEDismissedEvent,
}
impl From<&CompositorEvent> for CompositorEventVariant {
fn from(value: &CompositorEvent) -> Self {
match value {
CompositorEvent::ResizeEvent(..) => CompositorEventVariant::ResizeEvent,
CompositorEvent::MouseButtonEvent(..) => CompositorEventVariant::MouseButtonEvent,
CompositorEvent::MouseMoveEvent(..) => CompositorEventVariant::MouseMoveEvent,
CompositorEvent::TouchEvent(..) => CompositorEventVariant::TouchEvent,
CompositorEvent::WheelEvent(..) => CompositorEventVariant::WheelEvent,
CompositorEvent::KeyboardEvent(..) => CompositorEventVariant::KeyboardEvent,
CompositorEvent::CompositionEvent(..) => CompositorEventVariant::CompositionEvent,
CompositorEvent::IMEDismissedEvent => CompositorEventVariant::IMEDismissedEvent,
}
}
}
/// Requests a TimerEvent-Message be sent after the given duration.
#[derive(Debug, Deserialize, Serialize)]
pub struct TimerEventRequest(

View file

@ -799,7 +799,8 @@ impl ServoGlue {
EmbedderMsg::HeadParsed |
EmbedderMsg::SetFullscreenState(..) |
EmbedderMsg::ReadyToPresent |
EmbedderMsg::ReportProfile(..) => {},
EmbedderMsg::ReportProfile(..) |
EmbedderMsg::EventDelivered(..) => {},
}
}
Ok(())

View file

@ -14,8 +14,8 @@ use keyboard_types::{Key, KeyboardEvent, Modifiers, ShortcutMatcher};
use log::{debug, error, info, trace, warn};
use servo::compositing::windowing::{EmbedderEvent, WebRenderDebugOption};
use servo::embedder_traits::{
ContextMenuResult, EmbedderMsg, FilterPattern, PermissionPrompt, PermissionRequest,
PromptDefinition, PromptOrigin, PromptResult,
CompositorEventVariant, ContextMenuResult, EmbedderMsg, FilterPattern, PermissionPrompt,
PermissionRequest, PromptDefinition, PromptOrigin, PromptResult,
};
use servo::msg::constellation_msg::{TopLevelBrowsingContextId as BrowserId, TraversalDirection};
use servo::script_traits::TouchEventType;
@ -545,6 +545,13 @@ where
EmbedderMsg::ReadyToPresent => {
need_present = true;
},
EmbedderMsg::EventDelivered(event) => match (browser_id, event) {
(Some(browser_id), CompositorEventVariant::MouseButtonEvent) => {
// TODO Focus browser and/or raise to top if needed.
trace!("{}: Got a mouse button event", browser_id);
},
(_, _) => {},
},
}
}