From cb9cfe2b22e6d80e8b30ad64f2cff5e22a61c284 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Wed, 25 Mar 2015 10:58:54 -0400 Subject: [PATCH] Replace (String, Option) with MozBrowserEvent in uses of MozBrowserEventMsg. --- components/compositing/constellation.rs | 21 +++---- components/compositing/pipeline.rs | 12 ++-- components/msg/constellation_msg.rs | 66 +++++++++++++++++++++- components/script/dom/document.rs | 17 +++--- components/script/dom/htmliframeelement.rs | 12 ++-- components/script/script_task.rs | 19 +++---- components/script_traits/lib.rs | 4 +- 7 files changed, 102 insertions(+), 49 deletions(-) diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 45dd597b4137..e5eccca7e1a9 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -20,7 +20,7 @@ use msg::constellation_msg::{self, ConstellationChan, Failure}; use msg::constellation_msg::{IFrameSandboxState, NavigationDirection}; use msg::constellation_msg::{Key, KeyState, KeyModifiers, LoadData}; use msg::constellation_msg::{FrameId, PipelineExitType, PipelineId}; -use msg::constellation_msg::{SubpageId, WindowSizeData}; +use msg::constellation_msg::{SubpageId, WindowSizeData, MozBrowserEvent}; use msg::constellation_msg::Msg as ConstellationMsg; use net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient}; use net::resource_task::{self, ResourceTask}; @@ -364,15 +364,13 @@ impl Constellation { debug!("constellation got get-pipeline-title message"); self.handle_get_pipeline_title_msg(pipeline_id); } - ConstellationMsg::MozBrowserEvent(pipeline_id, - subpage_id, - event_name, - event_detail) => { + ConstellationMsg::MozBrowserEventMsg(pipeline_id, + subpage_id, + event) => { debug!("constellation got mozbrowser event message"); self.handle_mozbrowser_event_msg(pipeline_id, subpage_id, - event_name, - event_detail); + event); } } true @@ -643,14 +641,13 @@ impl Constellation { fn handle_mozbrowser_event_msg(&mut self, containing_pipeline_id: PipelineId, subpage_id: SubpageId, - event_name: String, - event_detail: Option) { + event: MozBrowserEvent) { assert!(opts::experimental_enabled()); // Find the script channel for the given parent pipeline, // and pass the event to that script task. let pipeline = self.pipeline(containing_pipeline_id); - pipeline.trigger_mozbrowser_event(subpage_id, event_name, event_detail); + pipeline.trigger_mozbrowser_event(subpage_id, event); } fn add_or_replace_pipeline_in_frame_tree(&mut self, frame_change: FrameChange) { @@ -880,9 +877,7 @@ impl Constellation { // If this is an iframe, then send the event with new url if let Some((containing_pipeline_id, subpage_id, url)) = event_info { let parent_pipeline = self.pipeline(containing_pipeline_id); - parent_pipeline.trigger_mozbrowser_event(subpage_id, - "mozbrowserlocationchange".to_owned(), - Some(url)); + parent_pipeline.trigger_mozbrowser_event(subpage_id, MozBrowserEvent::LocationChange(url)); } } } diff --git a/components/compositing/pipeline.rs b/components/compositing/pipeline.rs index b5fcebb578ae..a0b3c4b06dc8 100644 --- a/components/compositing/pipeline.rs +++ b/components/compositing/pipeline.rs @@ -15,7 +15,7 @@ use gfx::paint_task::{PaintChan, PaintTask}; use gfx::font_cache_task::FontCacheTask; use layers::geometry::DevicePixel; use msg::constellation_msg::{ConstellationChan, Failure, FrameId, PipelineId, SubpageId}; -use msg::constellation_msg::{LoadData, WindowSizeData, PipelineExitType}; +use msg::constellation_msg::{LoadData, WindowSizeData, PipelineExitType, MozBrowserEvent}; use net::image_cache_task::ImageCacheTask; use net::resource_task::ResourceTask; use net::storage_task::StorageTask; @@ -248,15 +248,13 @@ impl Pipeline { pub fn trigger_mozbrowser_event(&self, subpage_id: SubpageId, - event_name: String, - event_detail: Option) { + event: MozBrowserEvent) { assert!(opts::experimental_enabled()); let ScriptControlChan(ref script_channel) = self.script_chan; - let event = ConstellationControlMsg::MozBrowserEvent(self.id, - subpage_id, - event_name, - event_detail); + let event = ConstellationControlMsg::MozBrowserEventMsg(self.id, + subpage_id, + event); script_channel.send(event).unwrap(); } } diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 28528a6ff8e3..d260d344b2d3 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -213,9 +213,73 @@ pub enum Msg { /// Requests that the constellation inform the compositor of the a cursor change. SetCursor(Cursor), /// Dispatch a mozbrowser event to a given iframe. Only available in experimental mode. - MozBrowserEvent(PipelineId, SubpageId, String, Option), + MozBrowserEventMsg(PipelineId, SubpageId, MozBrowserEvent), } +// https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API#Events +pub enum MozBrowserEvent { + /// Sent when the scroll position within a browser