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

Generalise RootedVec::<JS<T>>::r as [JS<T>]::r #11171

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Remove some .r() calls where Deref is enough

  • Loading branch information
nox committed May 16, 2016
commit d398d16b01ede749fd2ae58bf55c53118de6a186
@@ -125,7 +125,7 @@ pub fn handle_get_layout(context: &BrowsingContext,

let window = context.active_window();
let elem = node.downcast::<Element>().expect("should be getting layout of element");
let computed_style = window.r().GetComputedStyle(elem, None);
let computed_style = window.GetComputedStyle(elem, None);

reply.send(ComputedNodeLayout {
display: String::from(computed_style.Display()),
@@ -61,11 +61,11 @@ pub fn synthetic_click_activation(element: &Element,
// https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event
let win = window_from_node(element);
let target = element.upcast::<EventTarget>();
let mouse = MouseEvent::new(win.r(),
let mouse = MouseEvent::new(&win,
DOMString::from("click"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
Some(win.r()),
Some(&win),
1,
0,
0,
@@ -33,6 +33,6 @@ impl Comment {

pub fn Constructor(global: GlobalRef, data: DOMString) -> Fallible<Root<Comment>> {
let document = global.as_window().Document();
Ok(Comment::new(data, document.r()))
Ok(Comment::new(data, &document))
}
}
@@ -41,7 +41,7 @@ impl DocumentFragment {
pub fn Constructor(global: GlobalRef) -> Fallible<Root<DocumentFragment>> {
let document = global.as_window().Document();

Ok(DocumentFragment::new(document.r()))
Ok(DocumentFragment::new(&document))
}
}

@@ -134,7 +134,7 @@ impl DOMImplementationMethods for DOMImplementation {
{
// Step 3.
let doc_node = doc.upcast::<Node>();
let doc_type = DocumentType::new(DOMString::from("html"), None, None, doc.r());
let doc_type = DocumentType::new(DOMString::from("html"), None, None, &doc);
doc_node.AppendChild(doc_type.upcast()).unwrap();
}

@@ -143,14 +143,14 @@ impl DOMImplementationMethods for DOMImplementation {
let doc_node = doc.upcast::<Node>();
let doc_html = Root::upcast::<Node>(HTMLHtmlElement::new(atom!("html"),
None,
doc.r()));
&doc));
doc_node.AppendChild(&doc_html).expect("Appending failed");

{
// Step 5.
let doc_head = Root::upcast::<Node>(HTMLHeadElement::new(atom!("head"),
None,
doc.r()));
&doc));
doc_html.AppendChild(&doc_head).unwrap();

// Step 6.
@@ -161,18 +161,18 @@ impl DOMImplementationMethods for DOMImplementation {
let doc_title =
Root::upcast::<Node>(HTMLTitleElement::new(atom!("title"),
None,
doc.r()));
&doc));
doc_head.AppendChild(&doc_title).unwrap();

// Step 6.2.
let title_text = Text::new(title_str, doc.r());
let title_text = Text::new(title_str, &doc);
doc_title.AppendChild(title_text.upcast()).unwrap();
}
}
}

// Step 7.
let doc_body = HTMLBodyElement::new(atom!("body"), None, doc.r());
let doc_body = HTMLBodyElement::new(atom!("body"), None, &doc);
doc_html.AppendChild(doc_body.upcast()).unwrap();
}

@@ -54,7 +54,6 @@ impl DOMParserMethods for DOMParser {
let content_type =
DOMString::from(DOMParserBinding::SupportedTypeValues::strings[ty as usize]);
let doc = self.window.Document();
let doc = doc.r();
let loader = DocumentLoader::new(&*doc.loader());
match ty {
Text_html => {
@@ -66,7 +65,7 @@ impl DOMParserMethods for DOMParser {
None,
DocumentSource::FromParser,
loader);
parse_html(document.r(), s, url, ParseContext::Owner(None));
parse_html(&document, s, url, ParseContext::Owner(None));
document.set_ready_state(DocumentReadyState::Complete);
Ok(document)
}
@@ -80,7 +79,7 @@ impl DOMParserMethods for DOMParser {
None,
DocumentSource::NotFromParser,
loader);
parse_xml(document.r(), s, url, xml::ParseContext::Owner(None));
parse_xml(&document, s, url, xml::ParseContext::Owner(None));
Ok(document)
}
}
@@ -29,7 +29,7 @@ impl DOMStringMap {
pub fn new(element: &HTMLElement) -> Root<DOMStringMap> {
let window = window_from_node(element);
reflect_dom_object(box DOMStringMap::new_inherited(element),
GlobalRef::Window(window.r()),
GlobalRef::Window(&window),
DOMStringMapBinding::Wrap)
}
}
@@ -33,7 +33,7 @@ impl DOMTokenList {
pub fn new(element: &Element, local_name: &Atom) -> Root<DOMTokenList> {
let window = window_from_node(element);
reflect_dom_object(box DOMTokenList::new_inherited(element, local_name.clone()),
GlobalRef::Window(window.r()),
GlobalRef::Window(&window),
DOMTokenListBinding::Wrap)
}

@@ -55,7 +55,6 @@ impl DOMTokenListMethods for DOMTokenList {
// https://dom.spec.whatwg.org/#dom-domtokenlist-length
fn Length(&self) -> u32 {
self.attribute().map_or(0, |attr| {
let attr = attr.r();
attr.value().as_tokens().len()
}) as u32
}
@@ -72,7 +71,6 @@ impl DOMTokenListMethods for DOMTokenList {
fn Contains(&self, token: DOMString) -> Fallible<bool> {
self.check_token_exceptions(&token).map(|token| {
self.attribute().map_or(false, |attr| {
let attr = attr.r();
attr.value()
.as_tokens()
.iter()
@@ -66,7 +66,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
// https://html.spec.whatwg.org/multipage/#dom-cva-validity
fn Validity(&self) -> Root<ValidityState> {
let window = window_from_node(self);
ValidityState::new(window.r(), self.upcast())
ValidityState::new(&window, self.upcast())
}

// https://html.spec.whatwg.org/multipage/#dom-fe-disabled
@@ -258,7 +258,7 @@ impl Activatable for HTMLButtonElement {
node.query_selector_iter(DOMString::from("button[type=submit]")).unwrap()
.filter_map(Root::downcast::<HTMLButtonElement>)
.find(|r| r.form_owner() == owner)
.map(|s| synthetic_click_activation(s.r().as_element(),
.map(|s| synthetic_click_activation(s.as_element(),
ctrlKey,
shiftKey,
altKey,
@@ -144,7 +144,7 @@ impl HTMLCanvasElement {
if self.context.borrow().is_none() {
let window = window_from_node(self);
let size = self.get_size();
let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size);
let context = CanvasRenderingContext2D::new(GlobalRef::Window(&window), self, size);
*self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context)));
}

@@ -173,7 +173,7 @@ impl HTMLCanvasElement {
GLContextAttributes::default()
};

let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs);
let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(&window), self, size, attrs);

*self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx)));
}
@@ -274,7 +274,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64),
Finite::wrap(self.Width() as f64),
Finite::wrap(self.Height() as f64)));
image_data.get_data_array(&GlobalRef::Window(window.r()))
image_data.get_data_array(&GlobalRef::Window(&window))
}
None => {
// Each pixel is fully-transparent black.
@@ -106,7 +106,7 @@ impl HTMLCollection {
fn set_cached_cursor(&self, index: u32, element: Option<Root<Element>>) -> Option<Root<Element>> {
if let Some(element) = element {
self.cached_cursor_index.set(OptionU32::some(index));
self.cached_cursor_element.set(Some(element.r()));
self.cached_cursor_element.set(Some(&element));
Some(element)
} else {
None
@@ -281,13 +281,13 @@ impl HTMLCollectionMethods for HTMLCollection {
// Iterate forwards, starting at the cursor.
let offset = index - (cached_index + 1);
let node: Root<Node> = Root::upcast(element);
self.set_cached_cursor(index, self.elements_iter_after(node.r()).nth(offset as usize))
self.set_cached_cursor(index, self.elements_iter_after(&node).nth(offset as usize))
} else {
// The cursor is after the element we're looking for
// Iterate backwards, starting at the cursor.
let offset = cached_index - (index + 1);
let node: Root<Node> = Root::upcast(element);
self.set_cached_cursor(index, self.elements_iter_before(node.r()).nth(offset as usize))
self.set_cached_cursor(index, self.elements_iter_before(&node).nth(offset as usize))
}
} else {
// Cache miss
@@ -51,6 +51,6 @@ impl HTMLDataListElementMethods for HTMLDataListElement {
}
let filter = box HTMLDataListOptionsFilter;
let window = window_from_node(self);
HTMLCollection::create(window.r(), self.upcast(), filter)
HTMLCollection::create(&window, self.upcast(), filter)
}
}
@@ -71,7 +71,6 @@ impl VirtualMethods for HTMLDetailsElement {
self.toggle_counter.set(counter);

let window = window_from_node(self);
let window = window.r();
let task_source = window.dom_manipulation_task_source();
let details = Trusted::new(self);
let runnable = box DetailsNotificationRunnable {
@@ -218,7 +218,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
}
let filter = box ElementsFilter { form: Root::from_ref(self) };
let window = window_from_node(self);
let elements = HTMLFormControlsCollection::new(window.r(), self.upcast(), filter);
let elements = HTMLFormControlsCollection::new(&window, self.upcast(), filter);
self.elements.set(Some(&elements));
elements
}
@@ -725,11 +725,11 @@ pub enum FormSubmittableElement {
impl FormSubmittableElement {
fn as_event_target(&self) -> &EventTarget {
match *self {
FormSubmittableElement::ButtonElement(ref button) => button.r().upcast(),
FormSubmittableElement::InputElement(ref input) => input.r().upcast(),
FormSubmittableElement::ObjectElement(ref object) => object.r().upcast(),
FormSubmittableElement::SelectElement(ref select) => select.r().upcast(),
FormSubmittableElement::TextAreaElement(ref textarea) => textarea.r().upcast()
FormSubmittableElement::ButtonElement(ref button) => button.upcast(),
FormSubmittableElement::InputElement(ref input) => input.upcast(),
FormSubmittableElement::ObjectElement(ref object) => object.upcast(),
FormSubmittableElement::SelectElement(ref select) => select.upcast(),
FormSubmittableElement::TextAreaElement(ref textarea) => textarea.upcast()
}
}
}
@@ -867,7 +867,7 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable {
if self.to_element().has_attribute(attr) {
input(self)
} else {
self.form_owner().map_or(DOMString::new(), |t| owner(t.r()))
self.form_owner().map_or(DOMString::new(), |t| owner(&t))
}
}

@@ -882,7 +882,7 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable {
if self.to_element().has_attribute(attr) {
input(self)
} else {
self.form_owner().map_or(false, |t| owner(t.r()))
self.form_owner().map_or(false, |t| owner(&t))
}
}

@@ -120,7 +120,6 @@ impl HTMLIFrameElement {
}

let window = window_from_node(self);
let window = window.r();
let (new_subpage_id, old_subpage_id) = self.generate_new_subpage_id();
let new_pipeline_id = self.pipeline_id.get().unwrap();
let private_iframe = self.privatebrowsing();
@@ -165,7 +164,7 @@ impl HTMLIFrameElement {
let mut detail = RootedValue::new(cx, UndefinedValue());
let event_name = Atom::from(event.name());
self.build_mozbrowser_event_detail(event, cx, detail.handle_mut());
CustomEvent::new(GlobalRef::Window(window.r()),
CustomEvent::new(GlobalRef::Window(&window),
event_name,
true,
true,
@@ -372,7 +371,6 @@ pub fn Navigate(iframe: &HTMLIFrameElement, direction: NavigationDirection) -> E
if iframe.Mozbrowser() {
if iframe.upcast::<Node>().is_in_doc() {
let window = window_from_node(iframe);
let window = window.r();

let pipeline_info = Some((window.pipeline(),
iframe.subpage_id().unwrap()));
@@ -414,7 +412,6 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
fn GetContentWindow(&self) -> Option<Root<Window>> {
self.subpage_id.get().and_then(|subpage_id| {
let window = window_from_node(self);
let window = window.r();
let browsing_context = window.browsing_context();
browsing_context.find_child_by_subpage(subpage_id)
})
@@ -568,7 +565,6 @@ impl VirtualMethods for HTMLIFrameElement {
// https://html.spec.whatwg.org/multipage/#a-browsing-context-is-discarded
if let Some(pipeline_id) = self.pipeline_id.get() {
let window = window_from_node(self);
let window = window.r();

// The only reason we're waiting for the iframe to be totally
// removed is to ensure the script thread can't add iframes faster
@@ -81,7 +81,6 @@ impl Runnable for ImageResponseHandlerRunnable {
fn handler(self: Box<Self>) {
// Update the image field
let element = self.element.root();
let element_ref = element.r();
let (image, metadata, trigger_image_load) = match self.image {
ImageResponse::Loaded(image) | ImageResponse::PlaceholderLoaded(image) => {
(Some(image.clone()), Some(ImageMetadata { height: image.height, width: image.width } ), true)
@@ -91,8 +90,8 @@ impl Runnable for ImageResponseHandlerRunnable {
}
ImageResponse::None => (None, None, true)
};
element_ref.current_request.borrow_mut().image = image;
element_ref.current_request.borrow_mut().metadata = metadata;
element.current_request.borrow_mut().image = image;
element.current_request.borrow_mut().metadata = metadata;

// Mark the node dirty
let document = document_from_node(&*element);
@@ -104,7 +103,7 @@ impl Runnable for ImageResponseHandlerRunnable {
}

// Trigger reflow
let window = window_from_node(document.r());
let window = window_from_node(&*document);
window.add_pending_reflow();
}
}
@@ -178,7 +177,7 @@ impl HTMLImageElement {
width: Option<u32>,
height: Option<u32>) -> Fallible<Root<HTMLImageElement>> {
let document = global.as_window().Document();
let image = HTMLImageElement::new(atom!("img"), None, document.r());
let image = HTMLImageElement::new(atom!("img"), None, &document);
if let Some(w) = width {
image.SetWidth(w);
}
@@ -77,7 +77,7 @@ impl HTMLObjectElementMethods for HTMLObjectElement {
// https://html.spec.whatwg.org/multipage/#dom-cva-validity
fn Validity(&self) -> Root<ValidityState> {
let window = window_from_node(self);
ValidityState::new(window.r(), self.upcast())
ValidityState::new(&window, self.upcast())
}

// https://html.spec.whatwg.org/multipage/#dom-object-type
@@ -43,7 +43,7 @@ impl HTMLOutputElementMethods for HTMLOutputElement {
// https://html.spec.whatwg.org/multipage/#dom-cva-validity
fn Validity(&self) -> Root<ValidityState> {
let window = window_from_node(self);
ValidityState::new(window.r(), self.upcast())
ValidityState::new(&window, self.upcast())
}

// https://html.spec.whatwg.org/multipage/#dom-fae-form
@@ -64,11 +64,11 @@ impl HTMLSelectElement {
for opt in node.traverse_preorder().filter_map(Root::downcast::<HTMLOptionElement>) {
if opt.Selected() {
opt.set_selectedness(false);
last_selected = Some(Root::from_ref(opt.r()));
last_selected = Some(Root::from_ref(&opt));
}
let element = opt.upcast::<Element>();
if first_enabled.is_none() && !element.disabled_state() {
first_enabled = Some(Root::from_ref(opt.r()));
first_enabled = Some(Root::from_ref(&opt));
}
}

@@ -131,7 +131,7 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
// https://html.spec.whatwg.org/multipage/#dom-cva-validity
fn Validity(&self) -> Root<ValidityState> {
let window = window_from_node(self);
ValidityState::new(window.r(), self.upcast())
ValidityState::new(&window, self.upcast())
}

// Note: this function currently only exists for union.html.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.