mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Usage of JSRef<Attr> in before_remove_attr & after_set_attr
JSRef<Attr> does not require allocating a DOMString for value, which are unused in most cases. It also provides more access to Attr data.
This commit is contained in:
parent
f5e8df9dac
commit
bbab8831e0
18 changed files with 255 additions and 225 deletions
|
@ -2,6 +2,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::attr::Attr;
|
||||
use dom::attr::AttrHelpers;
|
||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding;
|
||||
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::HTMLBodyElementMethods;
|
||||
|
@ -18,7 +20,6 @@ use dom::node::{Node, ElementNodeTypeId, window_from_node};
|
|||
use dom::virtualmethods::VirtualMethods;
|
||||
|
||||
use servo_util::str::DOMString;
|
||||
use string_cache::Atom;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct HTMLBodyElement {
|
||||
|
@ -63,13 +64,14 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
|
|||
Some(element as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn after_set_attr(&self, name: &Atom, value: DOMString) {
|
||||
fn after_set_attr(&self, attr: JSRef<Attr>) {
|
||||
match self.super_type() {
|
||||
Some(ref s) => s.after_set_attr(name, value.clone()),
|
||||
Some(ref s) => s.after_set_attr(attr),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
if name.as_slice().starts_with("on") {
|
||||
let name = attr.local_name().as_slice();
|
||||
if name.starts_with("on") {
|
||||
static forwarded_events: &'static [&'static str] =
|
||||
&["onfocus", "onload", "onscroll", "onafterprint", "onbeforeprint",
|
||||
"onbeforeunload", "onhashchange", "onlanguagechange", "onmessage",
|
||||
|
@ -80,14 +82,14 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
|
|||
window.get_url(),
|
||||
window.reflector().get_jsobject());
|
||||
let evtarget: JSRef<EventTarget> =
|
||||
if forwarded_events.iter().any(|&event| name.as_slice() == event) {
|
||||
if forwarded_events.iter().any(|&event| name == event) {
|
||||
EventTargetCast::from_ref(*window)
|
||||
} else {
|
||||
EventTargetCast::from_ref(*self)
|
||||
};
|
||||
evtarget.set_event_handler_uncompiled(cx, url, reflector,
|
||||
name.as_slice().slice_from(2),
|
||||
value);
|
||||
name.slice_from(2),
|
||||
attr.value().as_slice().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue