Skip to content

Commit

Permalink
Upgrade to SM 39
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwu committed Jun 19, 2015
1 parent a256f39 commit 675267b
Show file tree
Hide file tree
Showing 205 changed files with 6,535 additions and 5,329 deletions.
2 changes: 2 additions & 0 deletions components/layout/wrapper.rs
Expand Up @@ -521,6 +521,7 @@ pub struct LayoutElement<'le> {

impl<'le> LayoutElement<'le> {
pub fn style_attribute(&self) -> &'le Option<PropertyDeclarationBlock> {
use script::dom::element::ElementHelpers;
let style: &Option<PropertyDeclarationBlock> = unsafe {
&*self.element.style_attribute().borrow_for_layout()
};
Expand All @@ -536,6 +537,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> {

#[inline]
fn get_namespace(self) -> &'le Namespace {
use script::dom::element::ElementHelpers;
self.element.namespace()
}

Expand Down
5 changes: 2 additions & 3 deletions components/plugins/lints/unrooted_must_root.rs
Expand Up @@ -34,8 +34,7 @@ pub struct UnrootedPass;
// TODO (#3874, sort of): unwrap other types like Vec/Option/HashMap/etc
fn lint_unrooted_ty(cx: &Context, ty: &ast::Ty, warning: &str) {
match ty.node {
ast::TyVec(ref t) | ast::TyFixedLengthVec(ref t, _) |
ast::TyPtr(ast::MutTy { ty: ref t, ..}) | ast::TyRptr(_, ast::MutTy { ty: ref t, ..}) =>
ast::TyVec(ref t) | ast::TyFixedLengthVec(ref t, _) =>
lint_unrooted_ty(cx, &**t, warning),
ast::TyPath(..) => {
match cx.tcx.def_map.borrow()[&ty.id] {
Expand All @@ -47,7 +46,7 @@ fn lint_unrooted_ty(cx: &Context, ty: &ast::Ty, warning: &str) {
_ => (),
}
}
_ => (),
_ => (),
};
}

Expand Down
6 changes: 6 additions & 0 deletions components/plugins/reflector.rs
Expand Up @@ -25,6 +25,9 @@ pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable:
fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector {
&self.$field_name
}
fn init_reflector(&mut self, obj: *mut ::js::jsapi::JSObject) {
self.$field_name.set_jsobject(obj);
}
}
);
impl_item.map(|it| push(Annotatable::Item(it)))
Expand All @@ -37,6 +40,9 @@ pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable:
fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector {
self.$field_name.reflector()
}
fn init_reflector(&mut self, obj: *mut ::js::jsapi::JSObject) {
self.$field_name.init_reflector(obj);
}
}
);
impl_item.map(|it| push(Annotatable::Item(it)))
Expand Down
67 changes: 34 additions & 33 deletions components/script/devtools.rs
Expand Up @@ -6,72 +6,74 @@ use devtools_traits::{CachedConsoleMessage, CachedConsoleMessageTypes, PAGE_ERRO
use devtools_traits::{EvaluateJSReply, NodeInfo, Modification, TimelineMarker, TimelineMarkerType};
use dom::bindings::conversions::FromJSValConvertible;
use dom::bindings::conversions::StringificationBehavior;
use dom::bindings::js::{JSRef, OptionalRootable, Rootable, Temporary};
use dom::bindings::js::Root;
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast};
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::DOMRectBinding::{DOMRectMethods};
use dom::bindings::codegen::Bindings::ElementBinding::{ElementMethods};
use dom::node::{Node, NodeHelpers};
use dom::window::{WindowHelpers, ScriptHelpers};
use dom::element::Element;
use dom::document::DocumentHelpers;
use page::{IterablePage, Page};
use msg::constellation_msg::PipelineId;
use script_task::{get_page, ScriptTask};
use js::jsapi::RootedValue;
use js::jsval::UndefinedValue;

use std::sync::mpsc::Sender;
use std::rc::Rc;


pub fn handle_evaluate_js(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<EvaluateJSReply>){
let page = get_page(&*page, pipeline);
let window = page.window().root();
let window = page.window();
let cx = window.r().get_cx();
let rval = window.r().evaluate_js_on_global_with_result(&eval);
let mut rval = RootedValue::new(cx, UndefinedValue());
window.r().evaluate_js_on_global_with_result(&eval, rval.handle_mut());

reply.send(if rval.is_undefined() {
reply.send(if rval.ptr.is_undefined() {
EvaluateJSReply::VoidValue
} else if rval.is_boolean() {
EvaluateJSReply::BooleanValue(rval.to_boolean())
} else if rval.is_double() {
EvaluateJSReply::NumberValue(FromJSValConvertible::from_jsval(cx, rval, ()).unwrap())
} else if rval.is_string() {
} else if rval.ptr.is_boolean() {
EvaluateJSReply::BooleanValue(rval.ptr.to_boolean())
} else if rval.ptr.is_double() {
EvaluateJSReply::NumberValue(FromJSValConvertible::from_jsval(cx, rval.handle(), ()).unwrap())
} else if rval.ptr.is_string() {
//FIXME: use jsstring_to_str when jsval grows to_jsstring
EvaluateJSReply::StringValue(
FromJSValConvertible::from_jsval(cx, rval, StringificationBehavior::Default).unwrap())
} else if rval.is_null() {
FromJSValConvertible::from_jsval(cx, rval.handle(), StringificationBehavior::Default).unwrap())
} else if rval.ptr.is_null() {
EvaluateJSReply::NullValue
} else {
//FIXME: jsvals don't have an is_int32/is_number yet
assert!(rval.is_object());
assert!(rval.ptr.is_object());
panic!("object values unimplemented")
}).unwrap();
}

pub fn handle_get_root_node(page: &Rc<Page>, pipeline: PipelineId, reply: Sender<NodeInfo>) {
let page = get_page(&*page, pipeline);
let document = page.document().root();
let document = page.document();

let node: JSRef<Node> = NodeCast::from_ref(document.r());
let node = NodeCast::from_ref(document.r());
reply.send(node.summarize()).unwrap();
}

pub fn handle_get_document_element(page: &Rc<Page>, pipeline: PipelineId, reply: Sender<NodeInfo>) {
let page = get_page(&*page, pipeline);
let document = page.document().root();
let document_element = document.r().GetDocumentElement().root().unwrap();
let document = page.document();
let document_element = document.r().GetDocumentElement().unwrap();

let node: JSRef<Node> = NodeCast::from_ref(document_element.r());
let node = NodeCast::from_ref(document_element.r());
reply.send(node.summarize()).unwrap();
}

fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Temporary<Node> {
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Root<Node> {
let page = get_page(&*page, pipeline);
let document = page.document().root();
let node: JSRef<Node> = NodeCast::from_ref(document.r());
let document = page.document();
let node = NodeCast::from_ref(document.r());

for candidate in node.traverse_preorder() {
if candidate.root().r().get_unique_id() == node_id {
if candidate.r().get_unique_id() == node_id {
return candidate;
}
}
Expand All @@ -80,18 +82,17 @@ fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String
}

pub fn handle_get_children(page: &Rc<Page>, pipeline: PipelineId, node_id: String, reply: Sender<Vec<NodeInfo>>) {
let parent = find_node_by_unique_id(&*page, pipeline, node_id).root();
let parent = find_node_by_unique_id(&*page, pipeline, node_id);
let children = parent.r().children().map(|child| {
let child = child.root();
child.r().summarize()
}).collect();
reply.send(children).unwrap();
}

pub fn handle_get_layout(page: &Rc<Page>, pipeline: PipelineId, node_id: String, reply: Sender<(f32, f32)>) {
let node = find_node_by_unique_id(&*page, pipeline, node_id).root();
let elem: JSRef<Element> = ElementCast::to_ref(node.r()).expect("should be getting layout of element");
let rect = elem.GetBoundingClientRect().root();
let node = find_node_by_unique_id(&*page, pipeline, node_id);
let elem = ElementCast::to_ref(node.r()).expect("should be getting layout of element");
let rect = elem.GetBoundingClientRect();
let width = *rect.r().Width();
let height = *rect.r().Height();
reply.send((width, height)).unwrap();
Expand Down Expand Up @@ -141,8 +142,8 @@ pub fn handle_modify_attribute(page: &Rc<Page>,
pipeline: PipelineId,
node_id: String,
modifications: Vec<Modification>) {
let node = find_node_by_unique_id(&*page, pipeline, node_id).root();
let elem: JSRef<Element> = ElementCast::to_ref(node.r()).expect("should be getting layout of element");
let node = find_node_by_unique_id(&*page, pipeline, node_id);
let elem = ElementCast::to_ref(node.r()).expect("should be getting layout of element");

for modification in modifications.iter(){
match modification.newValue {
Expand All @@ -156,7 +157,7 @@ pub fn handle_modify_attribute(page: &Rc<Page>,

pub fn handle_wants_live_notifications(page: &Rc<Page>, pipeline_id: PipelineId, send_notifications: bool) {
let page = get_page(&*page, pipeline_id);
let window = page.window().root();
let window = page.window();
window.r().set_devtools_wants_updates(send_notifications);
}

Expand All @@ -167,7 +168,7 @@ pub fn handle_set_timeline_markers(page: &Rc<Page>,
for marker_type in &marker_types {
match *marker_type {
TimelineMarkerType::Reflow => {
let window = page.window().root();
let window = page.window();
window.r().set_devtools_timeline_marker(TimelineMarkerType::Reflow, reply.clone());
}
TimelineMarkerType::DOMEvent => {
Expand All @@ -180,7 +181,7 @@ pub fn handle_set_timeline_markers(page: &Rc<Page>,
pub fn handle_drop_timeline_markers(page: &Rc<Page>,
script_task: &ScriptTask,
marker_types: Vec<TimelineMarkerType>) {
let window = page.window().root();
let window = page.window();
for marker_type in &marker_types {
match *marker_type {
TimelineMarkerType::Reflow => {
Expand All @@ -195,6 +196,6 @@ pub fn handle_drop_timeline_markers(page: &Rc<Page>,

pub fn handle_request_animation_frame(page: &Rc<Page>, id: PipelineId, callback: Box<Fn(f64, )>) {
let page = page.find(id).expect("There is no such page");
let doc = page.document().root();
let doc = page.document();
doc.r().request_animation_frame(callback);
}
21 changes: 10 additions & 11 deletions components/script/dom/activation.rs
Expand Up @@ -4,7 +4,6 @@

use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast};
use dom::bindings::js::{JSRef, Temporary, OptionalRootable, Rootable};
use dom::element::{Element, ActivationElementHelpers};
use dom::event::{Event, EventHelpers, EventBubbles, EventCancelable};
use dom::eventtarget::EventTarget;
Expand All @@ -15,7 +14,7 @@ use std::borrow::ToOwned;

/// Trait for elements with defined activation behavior
pub trait Activatable {
fn as_element(&self) -> Temporary<Element>;
fn as_element<'a>(&'a self) -> &'a Element;

// Is this particular instance of the element activatable?
fn is_instance_activatable(&self) -> bool;
Expand All @@ -27,32 +26,32 @@ pub trait Activatable {
fn canceled_activation(&self);

// https://html.spec.whatwg.org/multipage/#run-post-click-activation-steps
fn activation_behavior(&self, event: JSRef<Event>, target: JSRef<EventTarget>);
fn activation_behavior(&self, event: &Event, target: &EventTarget);

// https://html.spec.whatwg.org/multipage/#implicit-submission
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool);

// https://html.spec.whatwg.org/multipage/#run-synthetic-click-activation-steps
fn synthetic_click_activation(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
let element = self.as_element().root();
let element = self.as_element();
// Step 1
if element.r().click_in_progress() {
if element.click_in_progress() {
return;
}
// Step 2
element.r().set_click_in_progress(true);
element.set_click_in_progress(true);
// Step 3
self.pre_click_activation();

// Step 4
// https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event
let win = window_from_node(element.r()).root();
let target: JSRef<EventTarget> = EventTargetCast::from_ref(element.r());
let win = window_from_node(element);
let target = EventTargetCast::from_ref(element);
let mouse = MouseEvent::new(win.r(), "click".to_owned(),
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, Some(win.r()), 1,
0, 0, 0, 0, ctrlKey, shiftKey, altKey, metaKey,
0, None).root();
let event: JSRef<Event> = EventCast::from_ref(mouse.r());
0, None);
let event = EventCast::from_ref(mouse.r());
event.fire(target);

// Step 5
Expand All @@ -64,6 +63,6 @@ pub trait Activatable {
}

// Step 6
element.r().set_click_in_progress(false);
element.set_click_in_progress(false);
}
}

0 comments on commit 675267b

Please sign in to comment.