mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Introduce RootedVec<JS<T>>::r()
This commit is contained in:
parent
658c3d05ae
commit
389a9ff643
4 changed files with 24 additions and 20 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue