mirror of
https://github.com/servo/servo.git
synced 2025-06-14 11:24:33 +00:00
Do not root Document::window
This commit is contained in:
parent
264e943597
commit
e889b0914b
1 changed files with 66 additions and 111 deletions
|
@ -248,9 +248,7 @@ impl Document {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#fully-active
|
// https://html.spec.whatwg.org/multipage/#fully-active
|
||||||
pub fn is_fully_active(&self) -> bool {
|
pub fn is_fully_active(&self) -> bool {
|
||||||
let window = self.window.root();
|
let browsing_context = self.window.browsing_context();
|
||||||
let window = window.r();
|
|
||||||
let browsing_context = window.browsing_context();
|
|
||||||
let browsing_context = browsing_context.as_ref().unwrap();
|
let browsing_context = browsing_context.as_ref().unwrap();
|
||||||
let active_document = browsing_context.active_document();
|
let active_document = browsing_context.active_document();
|
||||||
|
|
||||||
|
@ -308,9 +306,7 @@ impl Document {
|
||||||
self.quirks_mode.set(mode);
|
self.quirks_mode.set(mode);
|
||||||
|
|
||||||
if mode == Quirks {
|
if mode == Quirks {
|
||||||
let window = self.window.root();
|
let LayoutChan(ref layout_chan) = self.window.layout_chan();
|
||||||
let window = window.r();
|
|
||||||
let LayoutChan(ref layout_chan) = window.layout_chan();
|
|
||||||
layout_chan.send(Msg::SetQuirksMode).unwrap();
|
layout_chan.send(Msg::SetQuirksMode).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,10 +332,9 @@ impl Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.reflow_timeout.set(None);
|
self.reflow_timeout.set(None);
|
||||||
let window = self.window.root();
|
self.window.reflow(ReflowGoal::ForDisplay,
|
||||||
window.r().reflow(ReflowGoal::ForDisplay,
|
ReflowQueryType::NoQuery,
|
||||||
ReflowQueryType::NoQuery,
|
ReflowReason::RefreshTick);
|
||||||
ReflowReason::RefreshTick);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,8 +444,7 @@ impl Document {
|
||||||
None => return None,
|
None => return None,
|
||||||
};
|
};
|
||||||
let root = NodeCast::from_ref(root);
|
let root = NodeCast::from_ref(root);
|
||||||
let win = self.window.root();
|
let address = match self.window.layout().hit_test(root.to_trusted_node_address(), *point) {
|
||||||
let address = match win.r().layout().hit_test(root.to_trusted_node_address(), *point) {
|
|
||||||
Ok(HitTestResponse(node_address)) => Some(node_address),
|
Ok(HitTestResponse(node_address)) => Some(node_address),
|
||||||
Err(()) => {
|
Err(()) => {
|
||||||
debug!("layout query error");
|
debug!("layout query error");
|
||||||
|
@ -467,8 +461,7 @@ impl Document {
|
||||||
None => return vec!(),
|
None => return vec!(),
|
||||||
};
|
};
|
||||||
let root = NodeCast::from_ref(root);
|
let root = NodeCast::from_ref(root);
|
||||||
let win = self.window.root();
|
match self.window.layout().mouse_over(root.to_trusted_node_address(), *point) {
|
||||||
match win.r().layout().mouse_over(root.to_trusted_node_address(), *point) {
|
|
||||||
Ok(MouseOverResponse(node_address)) => node_address,
|
Ok(MouseOverResponse(node_address)) => node_address,
|
||||||
Err(()) => vec!(),
|
Err(()) => vec!(),
|
||||||
}
|
}
|
||||||
|
@ -478,8 +471,7 @@ impl Document {
|
||||||
pub fn set_ready_state(&self, state: DocumentReadyState) {
|
pub fn set_ready_state(&self, state: DocumentReadyState) {
|
||||||
self.ready_state.set(state);
|
self.ready_state.set(state);
|
||||||
|
|
||||||
let window = self.window.root();
|
let event = Event::new(GlobalRef::Window(&self.window), "readystatechange".to_owned(),
|
||||||
let event = Event::new(GlobalRef::Window(window.r()), "readystatechange".to_owned(),
|
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = EventTargetCast::from_ref(self);
|
||||||
|
@ -529,9 +521,8 @@ impl Document {
|
||||||
// Update the focus state for all elements in the focus chain.
|
// Update the focus state for all elements in the focus chain.
|
||||||
// https://html.spec.whatwg.org/multipage/#focus-chain
|
// https://html.spec.whatwg.org/multipage/#focus-chain
|
||||||
if focus_type == FocusType::Element {
|
if focus_type == FocusType::Element {
|
||||||
let window = self.window.root();
|
let ConstellationChan(ref chan) = self.window.constellation_chan();
|
||||||
let ConstellationChan(ref chan) = window.r().constellation_chan();
|
let event = ConstellationMsg::Focus(self.window.pipeline());
|
||||||
let event = ConstellationMsg::Focus(window.r().pipeline());
|
|
||||||
chan.send(event).unwrap();
|
chan.send(event).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -600,17 +591,15 @@ impl Document {
|
||||||
self.begin_focus_transaction();
|
self.begin_focus_transaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
let window = self.window.root();
|
|
||||||
|
|
||||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-click
|
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-click
|
||||||
let x = point.x as i32;
|
let x = point.x as i32;
|
||||||
let y = point.y as i32;
|
let y = point.y as i32;
|
||||||
let clickCount = 1;
|
let clickCount = 1;
|
||||||
let event = MouseEvent::new(window.r(),
|
let event = MouseEvent::new(&self.window,
|
||||||
mouse_event_type_string,
|
mouse_event_type_string,
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable,
|
EventCancelable::Cancelable,
|
||||||
Some(window.r()),
|
Some(&self.window),
|
||||||
clickCount,
|
clickCount,
|
||||||
x, y, x, y,
|
x, y, x, y,
|
||||||
false, false, false, false,
|
false, false, false, false,
|
||||||
|
@ -632,7 +621,9 @@ impl Document {
|
||||||
if let MouseEventType::Click = mouse_event_type {
|
if let MouseEventType::Click = mouse_event_type {
|
||||||
self.commit_focus_transaction(FocusType::Element);
|
self.commit_focus_transaction(FocusType::Element);
|
||||||
}
|
}
|
||||||
window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::MouseEvent);
|
self.window.reflow(ReflowGoal::ForDisplay,
|
||||||
|
ReflowQueryType::NoQuery,
|
||||||
|
ReflowReason::MouseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fire_mouse_event(&self,
|
pub fn fire_mouse_event(&self,
|
||||||
|
@ -642,13 +633,11 @@ impl Document {
|
||||||
let x = point.x.to_i32().unwrap_or(0);
|
let x = point.x.to_i32().unwrap_or(0);
|
||||||
let y = point.y.to_i32().unwrap_or(0);
|
let y = point.y.to_i32().unwrap_or(0);
|
||||||
|
|
||||||
let window = self.window.root();
|
let mouse_event = MouseEvent::new(&self.window,
|
||||||
|
|
||||||
let mouse_event = MouseEvent::new(window.r(),
|
|
||||||
event_name,
|
event_name,
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable,
|
EventCancelable::Cancelable,
|
||||||
Some(window.r()),
|
Some(&self.window),
|
||||||
0i32,
|
0i32,
|
||||||
x, y, x, y,
|
x, y, x, y,
|
||||||
false, false, false, false,
|
false, false, false, false,
|
||||||
|
@ -715,10 +704,9 @@ impl Document {
|
||||||
prev_mouse_over_targets.clear();
|
prev_mouse_over_targets.clear();
|
||||||
prev_mouse_over_targets.append(&mut *mouse_over_targets);
|
prev_mouse_over_targets.append(&mut *mouse_over_targets);
|
||||||
|
|
||||||
let window = self.window.root();
|
self.window.reflow(ReflowGoal::ForDisplay,
|
||||||
window.r().reflow(ReflowGoal::ForDisplay,
|
ReflowQueryType::NoQuery,
|
||||||
ReflowQueryType::NoQuery,
|
ReflowReason::MouseEvent);
|
||||||
ReflowReason::MouseEvent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The entry point for all key processing for web content
|
/// The entry point for all key processing for web content
|
||||||
|
@ -727,14 +715,13 @@ impl Document {
|
||||||
state: KeyState,
|
state: KeyState,
|
||||||
modifiers: KeyModifiers,
|
modifiers: KeyModifiers,
|
||||||
compositor: &mut IpcSender<ScriptToCompositorMsg>) {
|
compositor: &mut IpcSender<ScriptToCompositorMsg>) {
|
||||||
let window = self.window.root();
|
|
||||||
let focused = self.get_focused_element();
|
let focused = self.get_focused_element();
|
||||||
let body = self.GetBody();
|
let body = self.GetBody();
|
||||||
|
|
||||||
let target = match (&focused, &body) {
|
let target = match (&focused, &body) {
|
||||||
(&Some(ref focused), _) => EventTargetCast::from_ref(focused.r()),
|
(&Some(ref focused), _) => EventTargetCast::from_ref(focused.r()),
|
||||||
(&None, &Some(ref body)) => EventTargetCast::from_ref(body.r()),
|
(&None, &Some(ref body)) => EventTargetCast::from_ref(body.r()),
|
||||||
(&None, &None) => EventTargetCast::from_ref(window.r()),
|
(&None, &None) => EventTargetCast::from_ref(&*self.window),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ctrl = modifiers.contains(CONTROL);
|
let ctrl = modifiers.contains(CONTROL);
|
||||||
|
@ -751,8 +738,8 @@ impl Document {
|
||||||
|
|
||||||
let props = KeyboardEvent::key_properties(key, modifiers);
|
let props = KeyboardEvent::key_properties(key, modifiers);
|
||||||
|
|
||||||
let keyevent = KeyboardEvent::new(window.r(), ev_type, true, true,
|
let keyevent = KeyboardEvent::new(&self.window, ev_type, true, true,
|
||||||
Some(window.r()), 0, Some(key),
|
Some(&self.window), 0, Some(key),
|
||||||
props.key_string.to_owned(), props.code.to_owned(),
|
props.key_string.to_owned(), props.code.to_owned(),
|
||||||
props.location, is_repeating, is_composing,
|
props.location, is_repeating, is_composing,
|
||||||
ctrl, alt, shift, meta,
|
ctrl, alt, shift, meta,
|
||||||
|
@ -764,8 +751,8 @@ impl Document {
|
||||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys
|
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys
|
||||||
if state != KeyState::Released && props.is_printable() && !prevented {
|
if state != KeyState::Released && props.is_printable() && !prevented {
|
||||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keypress-event-order
|
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keypress-event-order
|
||||||
let event = KeyboardEvent::new(window.r(), "keypress".to_owned(),
|
let event = KeyboardEvent::new(&self.window, "keypress".to_owned(),
|
||||||
true, true, Some(window.r()), 0, Some(key),
|
true, true, Some(&self.window), 0, Some(key),
|
||||||
props.key_string.to_owned(), props.code.to_owned(),
|
props.key_string.to_owned(), props.code.to_owned(),
|
||||||
props.location, is_repeating, is_composing,
|
props.location, is_repeating, is_composing,
|
||||||
ctrl, alt, shift, meta,
|
ctrl, alt, shift, meta,
|
||||||
|
@ -805,7 +792,9 @@ impl Document {
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
|
||||||
window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::KeyEvent);
|
self.window.reflow(ReflowGoal::ForDisplay,
|
||||||
|
ReflowQueryType::NoQuery,
|
||||||
|
ReflowReason::KeyEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_from_nodes_and_strings(&self, nodes: Vec<NodeOrString>)
|
pub fn node_from_nodes_and_strings(&self, nodes: Vec<NodeOrString>)
|
||||||
|
@ -857,10 +846,8 @@ impl Document {
|
||||||
|
|
||||||
pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) {
|
pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) {
|
||||||
if htmliframeelement::mozbrowser_enabled() {
|
if htmliframeelement::mozbrowser_enabled() {
|
||||||
let window = self.window.root();
|
if let Some((containing_pipeline_id, subpage_id)) = self.window.parent_info() {
|
||||||
|
let ConstellationChan(ref chan) = self.window.constellation_chan();
|
||||||
if let Some((containing_pipeline_id, subpage_id)) = window.r().parent_info() {
|
|
||||||
let ConstellationChan(ref chan) = window.r().constellation_chan();
|
|
||||||
let event = ConstellationMsg::MozBrowserEvent(containing_pipeline_id,
|
let event = ConstellationMsg::MozBrowserEvent(containing_pipeline_id,
|
||||||
subpage_id,
|
subpage_id,
|
||||||
event);
|
event);
|
||||||
|
@ -871,16 +858,14 @@ impl Document {
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#dom-window-requestanimationframe
|
/// https://html.spec.whatwg.org/multipage/#dom-window-requestanimationframe
|
||||||
pub fn request_animation_frame(&self, callback: Box<FnBox(f64)>) -> u32 {
|
pub fn request_animation_frame(&self, callback: Box<FnBox(f64)>) -> u32 {
|
||||||
let window = self.window.root();
|
|
||||||
let window = window.r();
|
|
||||||
let ident = self.animation_frame_ident.get() + 1;
|
let ident = self.animation_frame_ident.get() + 1;
|
||||||
|
|
||||||
self.animation_frame_ident.set(ident);
|
self.animation_frame_ident.set(ident);
|
||||||
self.animation_frame_list.borrow_mut().insert(ident, callback);
|
self.animation_frame_list.borrow_mut().insert(ident, callback);
|
||||||
|
|
||||||
// TODO: Should tick animation only when document is visible
|
// TODO: Should tick animation only when document is visible
|
||||||
let ConstellationChan(ref chan) = window.constellation_chan();
|
let ConstellationChan(ref chan) = self.window.constellation_chan();
|
||||||
let event = ConstellationMsg::ChangeRunningAnimationsState(window.pipeline(),
|
let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline(),
|
||||||
AnimationState::AnimationCallbacksPresent);
|
AnimationState::AnimationCallbacksPresent);
|
||||||
chan.send(event).unwrap();
|
chan.send(event).unwrap();
|
||||||
|
|
||||||
|
@ -891,10 +876,8 @@ impl Document {
|
||||||
pub fn cancel_animation_frame(&self, ident: u32) {
|
pub fn cancel_animation_frame(&self, ident: u32) {
|
||||||
self.animation_frame_list.borrow_mut().remove(&ident);
|
self.animation_frame_list.borrow_mut().remove(&ident);
|
||||||
if self.animation_frame_list.borrow().is_empty() {
|
if self.animation_frame_list.borrow().is_empty() {
|
||||||
let window = self.window.root();
|
let ConstellationChan(ref chan) = self.window.constellation_chan();
|
||||||
let window = window.r();
|
let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline(),
|
||||||
let ConstellationChan(ref chan) = window.constellation_chan();
|
|
||||||
let event = ConstellationMsg::ChangeRunningAnimationsState(window.pipeline(),
|
|
||||||
AnimationState::NoAnimationCallbacksPresent);
|
AnimationState::NoAnimationCallbacksPresent);
|
||||||
chan.send(event).unwrap();
|
chan.send(event).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -907,16 +890,12 @@ impl Document {
|
||||||
let mut list = self.animation_frame_list.borrow_mut();
|
let mut list = self.animation_frame_list.borrow_mut();
|
||||||
animation_frame_list = Vec::from_iter(list.drain());
|
animation_frame_list = Vec::from_iter(list.drain());
|
||||||
|
|
||||||
let window = self.window.root();
|
let ConstellationChan(ref chan) = self.window.constellation_chan();
|
||||||
let window = window.r();
|
let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline(),
|
||||||
let ConstellationChan(ref chan) = window.constellation_chan();
|
|
||||||
let event = ConstellationMsg::ChangeRunningAnimationsState(window.pipeline(),
|
|
||||||
AnimationState::NoAnimationCallbacksPresent);
|
AnimationState::NoAnimationCallbacksPresent);
|
||||||
chan.send(event).unwrap();
|
chan.send(event).unwrap();
|
||||||
}
|
}
|
||||||
let window = self.window.root();
|
let performance = self.window.Performance();
|
||||||
let window = window.r();
|
|
||||||
let performance = window.Performance();
|
|
||||||
let performance = performance.r();
|
let performance = performance.r();
|
||||||
let timing = performance.Now();
|
let timing = performance.Now();
|
||||||
|
|
||||||
|
@ -924,9 +903,9 @@ impl Document {
|
||||||
callback(*timing);
|
callback(*timing);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.reflow(ReflowGoal::ForDisplay,
|
self.window.reflow(ReflowGoal::ForDisplay,
|
||||||
ReflowQueryType::NoQuery,
|
ReflowQueryType::NoQuery,
|
||||||
ReflowReason::RequestAnimationFrame);
|
ReflowReason::RequestAnimationFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prepare_async_load(&self, load: LoadType) -> PendingAsyncLoad {
|
pub fn prepare_async_load(&self, load: LoadType) -> PendingAsyncLoad {
|
||||||
|
@ -950,9 +929,8 @@ impl Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notify_constellation_load(&self) {
|
pub fn notify_constellation_load(&self) {
|
||||||
let window = self.window.root();
|
let pipeline_id = self.window.pipeline();
|
||||||
let pipeline_id = window.r().pipeline();
|
let ConstellationChan(ref chan) = self.window.constellation_chan();
|
||||||
let ConstellationChan(ref chan) = window.r().constellation_chan();
|
|
||||||
let event = ConstellationMsg::DOMLoad(pipeline_id);
|
let event = ConstellationMsg::DOMLoad(pipeline_id);
|
||||||
chan.send(event).unwrap();
|
chan.send(event).unwrap();
|
||||||
|
|
||||||
|
@ -1093,12 +1071,11 @@ impl Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_node_list<F: Fn(&Node) -> bool>(&self, callback: F) -> Root<NodeList> {
|
fn create_node_list<F: Fn(&Node) -> bool>(&self, callback: F) -> Root<NodeList> {
|
||||||
let window = self.window.root();
|
|
||||||
let doc = self.GetDocumentElement();
|
let doc = self.GetDocumentElement();
|
||||||
let maybe_node = doc.r().map(NodeCast::from_ref);
|
let maybe_node = doc.r().map(NodeCast::from_ref);
|
||||||
let iter = maybe_node.iter().flat_map(|node| node.traverse_preorder())
|
let iter = maybe_node.iter().flat_map(|node| node.traverse_preorder())
|
||||||
.filter(|node| callback(node.r()));
|
.filter(|node| callback(node.r()));
|
||||||
NodeList::new_simple_list(window.r(), iter)
|
NodeList::new_simple_list(&self.window, iter)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_html_element(&self) -> Option<Root<HTMLHtmlElement>> {
|
fn get_html_element(&self) -> Option<Root<HTMLHtmlElement>> {
|
||||||
|
@ -1168,9 +1145,7 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-hasfocus
|
// https://html.spec.whatwg.org/multipage/#dom-document-hasfocus
|
||||||
fn HasFocus(&self) -> bool {
|
fn HasFocus(&self) -> bool {
|
||||||
let target = self; // Step 1.
|
let target = self; // Step 1.
|
||||||
let window = self.window.root();
|
let browsing_context = self.window.browsing_context();
|
||||||
let window = window.r();
|
|
||||||
let browsing_context = window.browsing_context();
|
|
||||||
let browsing_context = browsing_context.as_ref();
|
let browsing_context = browsing_context.as_ref();
|
||||||
|
|
||||||
match browsing_context {
|
match browsing_context {
|
||||||
|
@ -1230,22 +1205,18 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagname
|
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagname
|
||||||
fn GetElementsByTagName(&self, tag_name: DOMString) -> Root<HTMLCollection> {
|
fn GetElementsByTagName(&self, tag_name: DOMString) -> Root<HTMLCollection> {
|
||||||
let window = self.window.root();
|
HTMLCollection::by_tag_name(&self.window, NodeCast::from_ref(self), tag_name)
|
||||||
HTMLCollection::by_tag_name(window.r(), NodeCast::from_ref(self), tag_name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
|
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
|
||||||
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, tag_name: DOMString)
|
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, tag_name: DOMString)
|
||||||
-> Root<HTMLCollection> {
|
-> Root<HTMLCollection> {
|
||||||
let window = self.window.root();
|
HTMLCollection::by_tag_name_ns(&self.window, NodeCast::from_ref(self), tag_name, maybe_ns)
|
||||||
HTMLCollection::by_tag_name_ns(window.r(), NodeCast::from_ref(self), tag_name, maybe_ns)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-getelementsbyclassname
|
// https://dom.spec.whatwg.org/#dom-document-getelementsbyclassname
|
||||||
fn GetElementsByClassName(&self, classes: DOMString) -> Root<HTMLCollection> {
|
fn GetElementsByClassName(&self, classes: DOMString) -> Root<HTMLCollection> {
|
||||||
let window = self.window.root();
|
HTMLCollection::by_class_name(&self.window, NodeCast::from_ref(self), classes)
|
||||||
|
|
||||||
HTMLCollection::by_class_name(window.r(), NodeCast::from_ref(self), classes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
||||||
|
@ -1284,13 +1255,12 @@ impl DocumentMethods for Document {
|
||||||
return Err(Error::InvalidCharacter);
|
return Err(Error::InvalidCharacter);
|
||||||
}
|
}
|
||||||
|
|
||||||
let window = self.window.root();
|
|
||||||
let name = Atom::from_slice(&local_name);
|
let name = Atom::from_slice(&local_name);
|
||||||
// repetition used because string_cache::atom::Atom is non-copyable
|
// repetition used because string_cache::atom::Atom is non-copyable
|
||||||
let l_name = Atom::from_slice(&local_name);
|
let l_name = Atom::from_slice(&local_name);
|
||||||
let value = AttrValue::String("".to_owned());
|
let value = AttrValue::String("".to_owned());
|
||||||
|
|
||||||
Ok(Attr::new(window.r(), name, value, l_name, ns!(""), None, None))
|
Ok(Attr::new(&self.window, name, value, l_name, ns!(""), None, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-createattributens
|
// https://dom.spec.whatwg.org/#dom-document-createattributens
|
||||||
|
@ -1298,10 +1268,9 @@ impl DocumentMethods for Document {
|
||||||
-> Fallible<Root<Attr>> {
|
-> Fallible<Root<Attr>> {
|
||||||
let (namespace, prefix, local_name) =
|
let (namespace, prefix, local_name) =
|
||||||
try!(validate_and_extract(namespace, &qualified_name));
|
try!(validate_and_extract(namespace, &qualified_name));
|
||||||
let window = self.window.root();
|
|
||||||
let value = AttrValue::String("".to_owned());
|
let value = AttrValue::String("".to_owned());
|
||||||
let qualified_name = Atom::from_slice(&qualified_name);
|
let qualified_name = Atom::from_slice(&qualified_name);
|
||||||
Ok(Attr::new(window.r(), local_name, value, qualified_name,
|
Ok(Attr::new(&self.window, local_name, value, qualified_name,
|
||||||
namespace, prefix, None))
|
namespace, prefix, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1369,22 +1338,20 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-createevent
|
// https://dom.spec.whatwg.org/#dom-document-createevent
|
||||||
fn CreateEvent(&self, mut interface: DOMString) -> Fallible<Root<Event>> {
|
fn CreateEvent(&self, mut interface: DOMString) -> Fallible<Root<Event>> {
|
||||||
let window = self.window.root();
|
|
||||||
|
|
||||||
interface.make_ascii_lowercase();
|
interface.make_ascii_lowercase();
|
||||||
match &*interface {
|
match &*interface {
|
||||||
"uievents" | "uievent" => Ok(EventCast::from_root(
|
"uievents" | "uievent" => Ok(EventCast::from_root(
|
||||||
UIEvent::new_uninitialized(window.r()))),
|
UIEvent::new_uninitialized(&self.window))),
|
||||||
"mouseevents" | "mouseevent" => Ok(EventCast::from_root(
|
"mouseevents" | "mouseevent" => Ok(EventCast::from_root(
|
||||||
MouseEvent::new_uninitialized(window.r()))),
|
MouseEvent::new_uninitialized(&self.window))),
|
||||||
"customevent" => Ok(EventCast::from_root(
|
"customevent" => Ok(EventCast::from_root(
|
||||||
CustomEvent::new_uninitialized(GlobalRef::Window(window.r())))),
|
CustomEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||||
"htmlevents" | "events" | "event" => Ok(Event::new_uninitialized(
|
"htmlevents" | "events" | "event" => Ok(Event::new_uninitialized(
|
||||||
GlobalRef::Window(window.r()))),
|
GlobalRef::Window(&self.window))),
|
||||||
"keyboardevent" | "keyevents" => Ok(EventCast::from_root(
|
"keyboardevent" | "keyevents" => Ok(EventCast::from_root(
|
||||||
KeyboardEvent::new_uninitialized(window.r()))),
|
KeyboardEvent::new_uninitialized(&self.window))),
|
||||||
"messageevent" => Ok(EventCast::from_root(
|
"messageevent" => Ok(EventCast::from_root(
|
||||||
MessageEvent::new_uninitialized(GlobalRef::Window(window.r())))),
|
MessageEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||||
_ => Err(Error::NotSupported)
|
_ => Err(Error::NotSupported)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1585,20 +1552,18 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-images
|
// https://html.spec.whatwg.org/multipage/#dom-document-images
|
||||||
fn Images(&self) -> Root<HTMLCollection> {
|
fn Images(&self) -> Root<HTMLCollection> {
|
||||||
self.images.or_init(|| {
|
self.images.or_init(|| {
|
||||||
let window = self.window.root();
|
|
||||||
let root = NodeCast::from_ref(self);
|
let root = NodeCast::from_ref(self);
|
||||||
let filter = box ImagesFilter;
|
let filter = box ImagesFilter;
|
||||||
HTMLCollection::create(window.r(), root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-embeds
|
// https://html.spec.whatwg.org/multipage/#dom-document-embeds
|
||||||
fn Embeds(&self) -> Root<HTMLCollection> {
|
fn Embeds(&self) -> Root<HTMLCollection> {
|
||||||
self.embeds.or_init(|| {
|
self.embeds.or_init(|| {
|
||||||
let window = self.window.root();
|
|
||||||
let root = NodeCast::from_ref(self);
|
let root = NodeCast::from_ref(self);
|
||||||
let filter = box EmbedsFilter;
|
let filter = box EmbedsFilter;
|
||||||
HTMLCollection::create(window.r(), root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1610,40 +1575,36 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-links
|
// https://html.spec.whatwg.org/multipage/#dom-document-links
|
||||||
fn Links(&self) -> Root<HTMLCollection> {
|
fn Links(&self) -> Root<HTMLCollection> {
|
||||||
self.links.or_init(|| {
|
self.links.or_init(|| {
|
||||||
let window = self.window.root();
|
|
||||||
let root = NodeCast::from_ref(self);
|
let root = NodeCast::from_ref(self);
|
||||||
let filter = box LinksFilter;
|
let filter = box LinksFilter;
|
||||||
HTMLCollection::create(window.r(), root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-forms
|
// https://html.spec.whatwg.org/multipage/#dom-document-forms
|
||||||
fn Forms(&self) -> Root<HTMLCollection> {
|
fn Forms(&self) -> Root<HTMLCollection> {
|
||||||
self.forms.or_init(|| {
|
self.forms.or_init(|| {
|
||||||
let window = self.window.root();
|
|
||||||
let root = NodeCast::from_ref(self);
|
let root = NodeCast::from_ref(self);
|
||||||
let filter = box FormsFilter;
|
let filter = box FormsFilter;
|
||||||
HTMLCollection::create(window.r(), root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-scripts
|
// https://html.spec.whatwg.org/multipage/#dom-document-scripts
|
||||||
fn Scripts(&self) -> Root<HTMLCollection> {
|
fn Scripts(&self) -> Root<HTMLCollection> {
|
||||||
self.scripts.or_init(|| {
|
self.scripts.or_init(|| {
|
||||||
let window = self.window.root();
|
|
||||||
let root = NodeCast::from_ref(self);
|
let root = NodeCast::from_ref(self);
|
||||||
let filter = box ScriptsFilter;
|
let filter = box ScriptsFilter;
|
||||||
HTMLCollection::create(window.r(), root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-anchors
|
// https://html.spec.whatwg.org/multipage/#dom-document-anchors
|
||||||
fn Anchors(&self) -> Root<HTMLCollection> {
|
fn Anchors(&self) -> Root<HTMLCollection> {
|
||||||
self.anchors.or_init(|| {
|
self.anchors.or_init(|| {
|
||||||
let window = self.window.root();
|
|
||||||
let root = NodeCast::from_ref(self);
|
let root = NodeCast::from_ref(self);
|
||||||
let filter = box AnchorsFilter;
|
let filter = box AnchorsFilter;
|
||||||
HTMLCollection::create(window.r(), root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1651,24 +1612,20 @@ impl DocumentMethods for Document {
|
||||||
fn Applets(&self) -> Root<HTMLCollection> {
|
fn Applets(&self) -> Root<HTMLCollection> {
|
||||||
// FIXME: This should be return OBJECT elements containing applets.
|
// FIXME: This should be return OBJECT elements containing applets.
|
||||||
self.applets.or_init(|| {
|
self.applets.or_init(|| {
|
||||||
let window = self.window.root();
|
|
||||||
let root = NodeCast::from_ref(self);
|
let root = NodeCast::from_ref(self);
|
||||||
let filter = box AppletsFilter;
|
let filter = box AppletsFilter;
|
||||||
HTMLCollection::create(window.r(), root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-location
|
// https://html.spec.whatwg.org/multipage/#dom-document-location
|
||||||
fn Location(&self) -> Root<Location> {
|
fn Location(&self) -> Root<Location> {
|
||||||
let window = self.window.root();
|
self.location.or_init(|| Location::new(&self.window))
|
||||||
let window = window.r();
|
|
||||||
self.location.or_init(|| Location::new(window))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
||||||
fn Children(&self) -> Root<HTMLCollection> {
|
fn Children(&self) -> Root<HTMLCollection> {
|
||||||
let window = self.window.root();
|
HTMLCollection::children(&self.window, NodeCast::from_ref(self))
|
||||||
HTMLCollection::children(window.r(), NodeCast::from_ref(self))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
||||||
|
@ -1725,9 +1682,8 @@ impl DocumentMethods for Document {
|
||||||
if !is_scheme_host_port_tuple(&url) {
|
if !is_scheme_host_port_tuple(&url) {
|
||||||
return Err(Error::Security);
|
return Err(Error::Security);
|
||||||
}
|
}
|
||||||
let window = self.window.root();
|
|
||||||
let (tx, rx) = ipc::channel().unwrap();
|
let (tx, rx) = ipc::channel().unwrap();
|
||||||
let _ = window.r().resource_task().send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
|
let _ = self.window.resource_task().send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
|
||||||
let cookies = rx.recv().unwrap();
|
let cookies = rx.recv().unwrap();
|
||||||
Ok(cookies.unwrap_or("".to_owned()))
|
Ok(cookies.unwrap_or("".to_owned()))
|
||||||
}
|
}
|
||||||
|
@ -1739,8 +1695,7 @@ impl DocumentMethods for Document {
|
||||||
if !is_scheme_host_port_tuple(url) {
|
if !is_scheme_host_port_tuple(url) {
|
||||||
return Err(Error::Security);
|
return Err(Error::Security);
|
||||||
}
|
}
|
||||||
let window = self.window.root();
|
let _ = self.window.resource_task().send(SetCookiesForUrl((*url).clone(), cookie, NonHTTP));
|
||||||
let _ = window.r().resource_task().send(SetCookiesForUrl((*url).clone(), cookie, NonHTTP));
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue