aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/document.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r--components/script/dom/document.rs106
1 files changed, 49 insertions, 57 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index c63295a0674..39f5a8e6d38 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -95,7 +95,7 @@ use dom_struct::dom_struct;
use encoding::EncodingRef;
use encoding::all::UTF_8;
use euclid::{Point2D, Vector2D};
-use html5ever::{LocalName, QualName};
+use html5ever::{LocalName, Namespace, QualName};
use hyper::header::{Header, SetCookie};
use hyper_serde::Serde;
use ipc_channel::ipc::{self, IpcSender};
@@ -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;
@@ -633,7 +633,7 @@ impl Document {
// reset_form_owner_for_listeners -> reset_form_owner -> GetElementById
{
let mut id_map = self.id_map.borrow_mut();
- let mut elements = id_map.entry(id.clone()).or_insert(Vec::new());
+ let elements = id_map.entry(id.clone()).or_insert(Vec::new());
elements.insert_pre_order(element, root.r().upcast::<Node>());
}
self.reset_form_owner_for_listeners(&id);
@@ -642,7 +642,7 @@ impl Document {
pub fn register_form_id_listener<T: ?Sized + FormControl>(&self, id: DOMString, listener: &T) {
let mut map = self.form_id_listener_map.borrow_mut();
let listener = listener.to_element();
- let mut set = map.entry(Atom::from(id)).or_insert(HashSet::new());
+ let set = map.entry(Atom::from(id)).or_insert(HashSet::new());
set.insert(JS::from_ref(listener));
}
@@ -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);
}
}
}
@@ -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) {
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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();
@@ -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,
@@ -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);
}
}
}
@@ -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
@@ -1572,7 +1559,7 @@ impl Document {
/// https://html.spec.whatwg.org/multipage/#dom-window-cancelanimationframe
pub fn cancel_animation_frame(&self, ident: u32) {
let mut list = self.animation_frame_list.borrow_mut();
- if let Some(mut pair) = list.iter_mut().find(|pair| pair.0 == ident) {
+ if let Some(pair) = list.iter_mut().find(|pair| pair.0 == ident) {
pair.1 = None;
}
}
@@ -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.
@@ -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>) {
@@ -2001,13 +1982,19 @@ impl Document {
/// https://html.spec.whatwg.org/multipage/#look-up-a-custom-element-definition
pub fn lookup_custom_element_definition(&self,
- local_name: LocalName,
- is: Option<LocalName>)
+ namespace: &Namespace,
+ local_name: &LocalName,
+ is: Option<&LocalName>)
-> Option<Rc<CustomElementDefinition>> {
if !PREFS.get("dom.customelements.enabled").as_boolean().unwrap_or(false) {
return None;
}
+ // Step 1
+ if *namespace != ns!(html) {
+ return None;
+ }
+
// Step 2
if !self.has_browsing_context {
return None;
@@ -2018,6 +2005,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)]
@@ -2399,7 +2391,7 @@ impl Document {
if entry.snapshot.is_none() {
entry.snapshot = Some(Snapshot::new(el.html_element_in_html_document()));
}
- let mut snapshot = entry.snapshot.as_mut().unwrap();
+ let snapshot = entry.snapshot.as_mut().unwrap();
if snapshot.state.is_none() {
snapshot.state = Some(el.state());
}
@@ -2426,7 +2418,7 @@ impl Document {
entry.hint.insert(RESTYLE_SELF);
}
- let mut snapshot = entry.snapshot.as_mut().unwrap();
+ let snapshot = entry.snapshot.as_mut().unwrap();
if attr.local_name() == &local_name!("id") {
snapshot.id_changed = true;
} else if attr.local_name() == &local_name!("class") {
@@ -2519,8 +2511,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
@@ -2552,8 +2544,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());
@@ -4027,7 +4019,7 @@ impl PendingInOrderScriptVec {
fn loaded(&self, element: &HTMLScriptElement, result: ScriptResult) {
let mut scripts = self.scripts.borrow_mut();
- let mut entry = scripts.iter_mut().find(|entry| &*entry.element == element).unwrap();
+ let entry = scripts.iter_mut().find(|entry| &*entry.element == element).unwrap();
entry.loaded(result);
}