Skip to content

Commit

Permalink
make use of ScriptToConstellationChan
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Aug 15, 2017
1 parent 817de15 commit d241389
Show file tree
Hide file tree
Showing 24 changed files with 285 additions and 280 deletions.
164 changes: 93 additions & 71 deletions components/constellation/constellation.rs

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions components/constellation/pipeline.rs
Expand Up @@ -21,10 +21,10 @@ use net_traits::{IpcSend, ResourceThreads};
use net_traits::image_cache::ImageCache;
use profile_traits::mem as profile_mem;
use profile_traits::time;
use script_traits::{ConstellationControlMsg, DiscardBrowsingContext};
use script_traits::{ConstellationControlMsg, DiscardBrowsingContext, ScriptToConstellationChan};
use script_traits::{DocumentActivity, InitialScriptState};
use script_traits::{LayoutControlMsg, LayoutMsg, LoadData, MozBrowserEvent};
use script_traits::{NewLayoutInfo, SWManagerMsg, SWManagerSenders, ScriptMsg};
use script_traits::{NewLayoutInfo, SWManagerMsg, SWManagerSenders};
use script_traits::{ScriptThreadFactory, TimerSchedulerMsg, WindowSizeData};
use servo_config::opts::{self, Opts};
use servo_config::prefs::{PREFS, Pref};
Expand Down Expand Up @@ -112,7 +112,7 @@ pub struct InitialPipelineState {
pub parent_info: Option<(PipelineId, FrameType)>,

/// A channel to the associated constellation.
pub constellation_chan: IpcSender<ScriptMsg>,
pub script_to_constellation_chan: ScriptToConstellationChan,

/// A channel for the layout thread to send messages to the constellation.
pub layout_to_constellation_chan: IpcSender<LayoutMsg>,
Expand Down Expand Up @@ -246,7 +246,7 @@ impl Pipeline {
browsing_context_id: state.browsing_context_id,
top_level_browsing_context_id: state.top_level_browsing_context_id,
parent_info: state.parent_info,
constellation_chan: state.constellation_chan,
script_to_constellation_chan: state.script_to_constellation_chan.clone(),
scheduler_chan: state.scheduler_chan,
devtools_chan: script_to_devtools_chan,
bluetooth_thread: state.bluetooth_thread,
Expand Down Expand Up @@ -446,7 +446,7 @@ pub struct UnprivilegedPipelineContent {
top_level_browsing_context_id: TopLevelBrowsingContextId,
browsing_context_id: BrowsingContextId,
parent_info: Option<(PipelineId, FrameType)>,
constellation_chan: IpcSender<ScriptMsg>,
script_to_constellation_chan: ScriptToConstellationChan,
layout_to_constellation_chan: IpcSender<LayoutMsg>,
scheduler_chan: IpcSender<TimerSchedulerMsg>,
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
Expand Down Expand Up @@ -487,7 +487,7 @@ impl UnprivilegedPipelineContent {
parent_info: self.parent_info,
control_chan: self.script_chan.clone(),
control_port: self.script_port,
constellation_chan: self.constellation_chan,
script_to_constellation_chan: self.script_to_constellation_chan.clone(),
layout_to_constellation_chan: self.layout_to_constellation_chan.clone(),
scheduler_chan: self.scheduler_chan,
bluetooth_thread: self.bluetooth_thread,
Expand Down Expand Up @@ -595,8 +595,8 @@ impl UnprivilegedPipelineContent {
}
}

pub fn constellation_chan(&self) -> IpcSender<ScriptMsg> {
self.constellation_chan.clone()
pub fn script_to_constellation_chan(&self) -> &ScriptToConstellationChan {
&self.script_to_constellation_chan
}

pub fn opts(&self) -> Opts {
Expand Down
12 changes: 6 additions & 6 deletions components/script/clipboard_provider.rs
Expand Up @@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use ipc_channel::ipc::{self, IpcSender};
use script_traits::ScriptMsg as ConstellationMsg;
use ipc_channel::ipc::channel;
use script_traits::{ScriptToConstellationChan, ScriptMsg};
use std::borrow::ToOwned;

pub trait ClipboardProvider {
Expand All @@ -13,14 +13,14 @@ pub trait ClipboardProvider {
fn set_clipboard_contents(&mut self, String);
}

impl ClipboardProvider for IpcSender<ConstellationMsg> {
impl ClipboardProvider for ScriptToConstellationChan {
fn clipboard_contents(&mut self) -> String {
let (tx, rx) = ipc::channel().unwrap();
self.send(ConstellationMsg::GetClipboardContents(tx)).unwrap();
let (tx, rx) = channel().unwrap();
self.send(ScriptMsg::GetClipboardContents(tx)).unwrap();
rx.recv().unwrap()
}
fn set_clipboard_contents(&mut self, s: String) {
self.send(ConstellationMsg::SetClipboardContents(s)).unwrap();
self.send(ScriptMsg::SetClipboardContents(s)).unwrap();
}
}

Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/bindings/trace.rs
Expand Up @@ -73,7 +73,7 @@ use profile_traits::time::ProfilerChan as TimeProfilerChan;
use script_layout_interface::OpaqueStyleAndLayoutData;
use script_layout_interface::reporter::CSSErrorReporter;
use script_layout_interface::rpc::LayoutRPC;
use script_traits::{DocumentActivity, TimerEventId, TimerSource, TouchpadPressurePhase};
use script_traits::{DocumentActivity, ScriptToConstellationChan, TimerEventId, TimerSource, TouchpadPressurePhase};
use script_traits::{UntrustedNodeAddress, WindowSizeData, WindowSizeType};
use script_traits::DrawAPaintImageResult;
use selectors::matching::ElementSelectorFlags;
Expand Down Expand Up @@ -400,6 +400,7 @@ unsafe_no_jsmanaged_fields!(WebGLTextureId);
unsafe_no_jsmanaged_fields!(WebGLVertexArrayId);
unsafe_no_jsmanaged_fields!(MediaList);
unsafe_no_jsmanaged_fields!(WebVRGamepadHand);
unsafe_no_jsmanaged_fields!(ScriptToConstellationChan);

unsafe impl<'a> JSTraceable for &'a str {
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/canvasrenderingcontext2d.rs
Expand Up @@ -42,7 +42,7 @@ use net_traits::image_cache::ImageResponse;
use net_traits::image_cache::ImageState;
use net_traits::image_cache::UsePlaceholder;
use num_traits::ToPrimitive;
use script_traits::ScriptMsg as ConstellationMsg;
use script_traits::ScriptMsg;
use servo_url::ServoUrl;
use std::{cmp, fmt, mem};
use std::cell::Cell;
Expand Down Expand Up @@ -130,9 +130,9 @@ impl CanvasRenderingContext2D {
-> CanvasRenderingContext2D {
debug!("Creating new canvas rendering context.");
let (sender, receiver) = ipc::channel().unwrap();
let constellation_chan = global.constellation_chan();
let script_to_constellation_chan = global.script_to_constellation_chan();
debug!("Asking constellation to create new canvas thread.");
constellation_chan.send(ConstellationMsg::CreateCanvasPaintThread(size, sender)).unwrap();
script_to_constellation_chan.send(ScriptMsg::CreateCanvasPaintThread(size, sender)).unwrap();
let ipc_renderer = receiver.recv().unwrap();
debug!("Done.");
CanvasRenderingContext2D {
Expand Down
8 changes: 4 additions & 4 deletions components/script/dom/dissimilaroriginwindow.rs
Expand Up @@ -17,7 +17,7 @@ use ipc_channel::ipc;
use js::jsapi::{JSContext, HandleValue};
use js::jsval::{JSVal, UndefinedValue};
use msg::constellation_msg::PipelineId;
use script_traits::ScriptMsg as ConstellationMsg;
use script_traits::ScriptMsg;
use servo_url::ImmutableOrigin;
use servo_url::MutableOrigin;
use servo_url::ServoUrl;
Expand Down Expand Up @@ -54,7 +54,7 @@ impl DissimilarOriginWindow {
global_to_clone_from.devtools_chan().cloned(),
global_to_clone_from.mem_profiler_chan().clone(),
global_to_clone_from.time_profiler_chan().clone(),
global_to_clone_from.constellation_chan().clone(),
global_to_clone_from.script_to_constellation_chan().clone(),
global_to_clone_from.scheduler_chan().clone(),
global_to_clone_from.resource_threads().clone(),
timer_event_chan,
Expand Down Expand Up @@ -184,9 +184,9 @@ impl DissimilarOriginWindowMethods for DissimilarOriginWindow {

impl DissimilarOriginWindow {
pub fn post_message(&self, origin: Option<ImmutableOrigin>, data: StructuredCloneData) {
let msg = ConstellationMsg::PostMessage(self.window_proxy.browsing_context_id(),
let msg = ScriptMsg::PostMessage(self.window_proxy.browsing_context_id(),
origin,
data.move_to_arraybuffer());
let _ = self.upcast::<GlobalScope>().constellation_chan().send(msg);
let _ = self.upcast::<GlobalScope>().script_to_constellation_chan().send(msg);
}
}
82 changes: 34 additions & 48 deletions components/script/dom/document.rs
Expand Up @@ -115,7 +115,7 @@ use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread};
use script_traits::{AnimationState, CompositorEvent, DocumentActivity};
use script_traits::{MouseButton, MouseEventType, MozBrowserEvent};
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TouchpadPressurePhase};
use script_traits::{MsDuration, ScriptMsg, TouchpadPressurePhase};
use script_traits::{TouchEventType, TouchId};
use script_traits::UntrustedNodeAddress;
use servo_arc::Arc;
Expand Down Expand Up @@ -795,9 +795,7 @@ impl Document {
// Update the focus state for all elements in the focus chain.
// https://html.spec.whatwg.org/multipage/#focus-chain
if focus_type == FocusType::Element {
let global_scope = self.window.upcast::<GlobalScope>();
let event = ConstellationMsg::Focus(global_scope.pipeline_id());
global_scope.constellation_chan().send(event).unwrap();
self.send_to_constellation(ScriptMsg::Focus);
}
}
}
Expand All @@ -808,19 +806,14 @@ impl Document {
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsertitlechange
self.trigger_mozbrowser_event(MozBrowserEvent::TitleChange(String::from(self.Title())));

self.send_title_to_compositor();
self.send_title_to_constellation();
}
}

/// Sends this document's title to the compositor.
pub fn send_title_to_compositor(&self) {
let window = self.window();
let global_scope = window.upcast::<GlobalScope>();
global_scope
.constellation_chan()
.send(ConstellationMsg::SetTitle(global_scope.pipeline_id(),
Some(String::from(self.Title()))))
.unwrap();
/// Sends this document's title to the constellation.
pub fn send_title_to_constellation(&self) {
let title = Some(String::from(self.Title()));
self.send_to_constellation(ScriptMsg::SetTitle(title));
}

pub fn dirty_all_nodes(&self) {
Expand Down Expand Up @@ -872,8 +865,8 @@ impl Document {
let child_point = client_point - child_origin;

let event = CompositorEvent::MouseButtonEvent(mouse_event_type, button, child_point);
let event = ConstellationMsg::ForwardEvent(pipeline_id, event);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
let event = ScriptMsg::ForwardEvent(pipeline_id, event);
self.send_to_constellation(event);
}
return;
}
Expand Down Expand Up @@ -1029,8 +1022,8 @@ impl Document {
let event = CompositorEvent::TouchpadPressureEvent(child_point,
pressure,
phase_now);
let event = ConstellationMsg::ForwardEvent(pipeline_id, event);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
let event = ScriptMsg::ForwardEvent(pipeline_id, event);
self.send_to_constellation(event);
}
return;
}
Expand Down Expand Up @@ -1131,8 +1124,8 @@ impl Document {
let child_point = client_point - child_origin;

let event = CompositorEvent::MouseMoveEvent(Some(child_point));
let event = ConstellationMsg::ForwardEvent(pipeline_id, event);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
let event = ScriptMsg::ForwardEvent(pipeline_id, event);
self.send_to_constellation(event);
}
return;
}
Expand Down Expand Up @@ -1238,8 +1231,8 @@ impl Document {
let child_point = point - child_origin;

let event = CompositorEvent::TouchEvent(event_type, touch_id, child_point);
let event = ConstellationMsg::ForwardEvent(pipeline_id, event);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
let event = ScriptMsg::ForwardEvent(pipeline_id, event);
self.send_to_constellation(event);
}
return TouchEventResult::Forwarded;
}
Expand Down Expand Up @@ -1330,8 +1323,7 @@ impl Document {
ch: Option<char>,
key: Key,
state: KeyState,
modifiers: KeyModifiers,
constellation: &IpcSender<ConstellationMsg>) {
modifiers: KeyModifiers) {
let focused = self.get_focused_element();
let body = self.GetBody();

Expand Down Expand Up @@ -1407,7 +1399,8 @@ impl Document {
}

if cancel_state == EventDefault::Allowed {
constellation.send(ConstellationMsg::SendKeyEvent(ch, key, state, modifiers)).unwrap();
let msg = ScriptMsg::SendKeyEvent(ch, key, state, modifiers);
self.send_to_constellation(msg);

// This behavior is unspecced
// We are supposed to dispatch synthetic click activation for Space and/or Return,
Expand Down Expand Up @@ -1525,11 +1518,8 @@ impl Document {
pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) {
if PREFS.is_mozbrowser_enabled() {
if let Some((parent_pipeline_id, _)) = self.window.parent_info() {
let top_level_browsing_context_id = self.window.window_proxy().top_level_browsing_context_id();
let event = ConstellationMsg::MozBrowserEvent(parent_pipeline_id,
top_level_browsing_context_id,
event);
self.window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
let event = ScriptMsg::MozBrowserEvent(parent_pipeline_id, event);
self.send_to_constellation(event);
}
}
}
Expand Down Expand Up @@ -1559,11 +1549,8 @@ impl Document {
// This reduces CPU usage by avoiding needless thread wakeups in the common case of
// repeated rAF.

let global_scope = self.window.upcast::<GlobalScope>();
let event = ConstellationMsg::ChangeRunningAnimationsState(
global_scope.pipeline_id(),
AnimationState::AnimationCallbacksPresent);
global_scope.constellation_chan().send(event).unwrap();
let event = ScriptMsg::ChangeRunningAnimationsState(AnimationState::AnimationCallbacksPresent);
self.send_to_constellation(event);
}

ident
Expand Down Expand Up @@ -1629,11 +1616,8 @@ impl Document {
(!was_faking_animation_frames && self.is_faking_animation_frames()) {
mem::swap(&mut *self.animation_frame_list.borrow_mut(),
&mut *animation_frame_list);
let global_scope = self.window.upcast::<GlobalScope>();
let event = ConstellationMsg::ChangeRunningAnimationsState(
global_scope.pipeline_id(),
AnimationState::NoAnimationCallbacksPresent);
global_scope.constellation_chan().send(event).unwrap();
let event = ScriptMsg::ChangeRunningAnimationsState(AnimationState::NoAnimationCallbacksPresent);
self.send_to_constellation(event);
}

// Update the counter of spurious animation frames.
Expand Down Expand Up @@ -1896,10 +1880,7 @@ impl Document {
}

pub fn notify_constellation_load(&self) {
let global_scope = self.window.upcast::<GlobalScope>();
let pipeline_id = global_scope.pipeline_id();
let load_event = ConstellationMsg::LoadComplete(pipeline_id);
global_scope.constellation_chan().send(load_event).unwrap();
self.send_to_constellation(ScriptMsg::LoadComplete);
}

pub fn set_current_parser(&self, script: Option<&ServoParser>) {
Expand Down Expand Up @@ -2018,6 +1999,11 @@ impl Document {

registry.lookup_definition(local_name, is)
}

fn send_to_constellation(&self, msg: ScriptMsg) {
let global_scope = self.window.upcast::<GlobalScope>();
global_scope.script_to_constellation_chan().send(msg).unwrap();
}
}

#[derive(PartialEq, HeapSizeOf)]
Expand Down Expand Up @@ -2519,8 +2505,8 @@ impl Document {
let window = self.window();
// Step 6
if !error {
let event = ConstellationMsg::SetFullscreenState(true);
window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
let event = ScriptMsg::SetFullscreenState(true);
self.send_to_constellation(event);
}

// Step 7
Expand Down Expand Up @@ -2552,8 +2538,8 @@ impl Document {

let window = self.window();
// Step 8
let event = ConstellationMsg::SetFullscreenState(false);
window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
let event = ScriptMsg::SetFullscreenState(false);
self.send_to_constellation(event);

// Step 9
let trusted_element = Trusted::new(element.r());
Expand Down

0 comments on commit d241389

Please sign in to comment.