Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce VirtualMethods::children_changed() #6660

Merged
merged 2 commits into from Jul 25, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -70,6 +70,7 @@ use std::collections::hash_state::HashState;
use std::ffi::CString;
use std::hash::{Hash, Hasher};
use std::intrinsics::return_address;
use std::mem;
use std::ops::{Deref, DerefMut};
use std::rc::Rc;
use std::sync::Arc;
@@ -482,6 +483,13 @@ impl<T: JSTraceable + Reflectable> RootedVec<T> {
}
}

impl<T: JSTraceable + Reflectable> RootedVec<JS<T>> {
/// Obtain a safe slice of references that can't outlive that RootedVec.
pub fn r(&self) -> &[&T] {
unsafe { mem::transmute(&*self.v) }
}
}

impl<T: JSTraceable + Reflectable> Drop for RootedVec<T> {
fn drop(&mut self) {
RootedTraceableSet::remove(self);
@@ -733,15 +733,13 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
// Set hover state for any elements in the current mouse over list.
// Check if any of them changed state to determine whether to
// force a reflow below.
for target in mouse_over_targets.iter() {
let target = target.root();
let target_ref = target.r();
if !target_ref.get_hover_state() {
target_ref.set_hover_state(true);
for target in mouse_over_targets.r() {
if !target.get_hover_state() {
target.set_hover_state(true);

let target = EventTargetCast::from_ref(target_ref);
let target = EventTargetCast::from_ref(*target);

self.fire_mouse_event(point, &target, "mouseover".to_owned());
self.fire_mouse_event(point, target, "mouseover".to_owned());

}
}
@@ -865,9 +865,9 @@ impl<'a> AttributeHandlers for &'a Element {
fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
let mut attributes = RootedVec::new();
self.get_attributes(local_name, &mut attributes);
attributes.iter()
.map(|attr| attr.root())
.find(|attr| attr.r().namespace() == namespace)
attributes.r().iter()
.find(|attr| attr.namespace() == namespace)
.map(|attr| Root::from_ref(*attr))
}

// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
@@ -41,14 +41,13 @@ pub fn dispatch_event<'a, 'b>(target: &'a EventTarget,
//FIXME: The "callback this value" should be currentTarget

/* capturing */
for cur_target in chain.iter().rev() {
let cur_target = cur_target.root();
let stopped = match cur_target.r().get_listeners_for(&type_, ListenerPhase::Capturing) {
for cur_target in chain.r().iter().rev() {
let stopped = match cur_target.get_listeners_for(&type_, ListenerPhase::Capturing) {
Some(listeners) => {
event.set_current_target(cur_target.r());
event.set_current_target(cur_target);
for listener in listeners.iter() {
// Explicitly drop any exception on the floor.
let _ = listener.HandleEvent_(cur_target.r(), event, Report);
let _ = listener.HandleEvent_(*cur_target, event, Report);

if event.stop_immediate() {
break;
@@ -87,14 +86,13 @@ pub fn dispatch_event<'a, 'b>(target: &'a EventTarget,
if event.bubbles() && !event.stop_propagation() {
event.set_phase(EventPhase::Bubbling);

for cur_target in chain.iter() {
let cur_target = cur_target.root();
let stopped = match cur_target.r().get_listeners_for(&type_, ListenerPhase::Bubbling) {
for cur_target in chain.r() {
let stopped = match cur_target.get_listeners_for(&type_, ListenerPhase::Bubbling) {
Some(listeners) => {
event.set_current_target(cur_target.r());
event.set_current_target(cur_target);
for listener in listeners.iter() {
// Explicitly drop any exception on the floor.
let _ = listener.HandleEvent_(cur_target.r(), event, Report);
let _ = listener.HandleEvent_(*cur_target, event, Report);

if event.stop_immediate() {
break;
@@ -27,7 +27,8 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers};
use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node, CloneChildrenFlag};
use dom::node::{ChildrenMutation, CloneChildrenFlag, Node, NodeHelpers};
use dom::node::{NodeTypeId, document_from_node, window_from_node};
use dom::servohtmlparser::ServoHTMLParserHelpers;
use dom::virtualmethods::VirtualMethods;
use dom::window::{WindowHelpers, ScriptHelpers};
@@ -564,9 +565,9 @@ impl<'a> VirtualMethods for &'a HTMLScriptElement {
}
}

fn child_inserted(&self, child: &Node) {
fn children_changed(&self, mutation: &ChildrenMutation) {
if let Some(ref s) = self.super_type() {
s.child_inserted(child);
s.children_changed(mutation);
}
let node = NodeCast::from_ref(*self);
if !self.parser_inserted.get() && node.is_in_doc() {
@@ -11,7 +11,8 @@ use dom::document::Document;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::element::{ElementTypeId, AttributeHandlers};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node};
use dom::node::{ChildrenMutation, Node, NodeHelpers, NodeTypeId};
use dom::node::window_from_node;
use dom::virtualmethods::VirtualMethods;
use dom::window::WindowHelpers;
use layout_interface::{LayoutChan, Msg};
@@ -86,11 +87,10 @@ impl<'a> VirtualMethods for &'a HTMLStyleElement {
Some(htmlelement as &VirtualMethods)
}

fn child_inserted(&self, child: &Node) {
fn children_changed(&self, mutation: &ChildrenMutation) {
if let Some(ref s) = self.super_type() {
s.child_inserted(child);
s.children_changed(mutation);
}

let node = NodeCast::from_ref(*self);
if node.is_in_doc() {
self.parse_own_css();
@@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaEl
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::codegen::InheritTypes::{KeyboardEventCast, TextDerived};
use dom::bindings::codegen::InheritTypes::KeyboardEventCast;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{LayoutJS, Root};
use dom::bindings::refcounted::Trusted;
@@ -23,8 +23,8 @@ use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlformelement::FormControl;
use dom::keyboardevent::KeyboardEvent;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeDamage, NodeTypeId};
use dom::node::{document_from_node, window_from_node};
use dom::node::{ChildrenMutation, DisabledStateHelpers, Node, NodeDamage};
use dom::node::{NodeHelpers, NodeTypeId, document_from_node, window_from_node};
use textinput::{TextInput, Lines, KeyReaction};
use dom::virtualmethods::VirtualMethods;
use dom::window::WindowHelpers;
@@ -330,12 +330,11 @@ impl<'a> VirtualMethods for &'a HTMLTextAreaElement {
}
}

fn child_inserted(&self, child: &Node) {
if let Some(s) = self.super_type() {
s.child_inserted(child);
fn children_changed(&self, mutation: &ChildrenMutation) {
if let Some(ref s) = self.super_type() {
s.children_changed(mutation);
}

if child.is_text() && !self.value_changed.get() {
if !self.value_changed.get() {
self.reset();
}
}
@@ -13,7 +13,7 @@ use dom::document::{Document, DocumentHelpers};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeHelpers, NodeTypeId};
use dom::node::{ChildrenMutation, Node, NodeHelpers, NodeTypeId};
use dom::text::Text;
use dom::virtualmethods::VirtualMethods;
use util::str::DOMString;
@@ -75,15 +75,13 @@ impl<'a> VirtualMethods for &'a HTMLTitleElement {
Some(htmlelement as &VirtualMethods)
}

fn child_inserted(&self, child: &Node) {
fn children_changed(&self, mutation: &ChildrenMutation) {
if let Some(ref s) = self.super_type() {
s.child_inserted(child);
s.children_changed(mutation);
}

let node = NodeCast::from_ref(*self);
if node.is_in_doc() {
let document = node.owner_doc();
document.r().title_changed();
node.owner_doc().title_changed();
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.