diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2014-12-10 11:56:20 +0530 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2014-12-27 02:53:36 +0530 |
commit | 21a888341d3e184b0835c4de73959b851d275571 (patch) | |
tree | e019676e6d0cc048d26ce610f9725628eac5efca /components/script/dom | |
parent | d761877ef692f46970315ee0008fe0f3254323eb (diff) | |
download | servo-21a888341d3e184b0835c4de73959b851d275571.tar.gz servo-21a888341d3e184b0835c4de73959b851d275571.zip |
Ensure that Reflectors are the first field
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/domexception.rs | 4 | ||||
-rw-r--r-- | components/script/dom/domimplementation.rs | 4 | ||||
-rw-r--r-- | components/script/dom/domparser.rs | 4 | ||||
-rw-r--r-- | components/script/dom/event.rs | 4 | ||||
-rw-r--r-- | components/script/dom/eventtarget.rs | 4 | ||||
-rw-r--r-- | components/script/dom/formdata.rs | 4 | ||||
-rw-r--r-- | components/script/dom/htmlcollection.rs | 4 | ||||
-rw-r--r-- | components/script/dom/htmltablerowelement.rs | 43 | ||||
-rw-r--r-- | components/script/dom/htmltablesectionelement.rs | 42 | ||||
-rw-r--r-- | components/script/dom/htmltextareaelement.rs | 17 | ||||
-rw-r--r-- | components/script/dom/htmltitleelement.rs | 14 | ||||
-rw-r--r-- | components/script/dom/nodelist.rs | 4 | ||||
-rw-r--r-- | components/script/dom/urlsearchparams.rs | 4 |
13 files changed, 134 insertions, 18 deletions
diff --git a/components/script/dom/domexception.rs b/components/script/dom/domexception.rs index 2d71a1b26e4..d3375fd8e05 100644 --- a/components/script/dom/domexception.rs +++ b/components/script/dom/domexception.rs @@ -62,15 +62,15 @@ impl DOMErrorName { #[dom_struct] pub struct DOMException { + reflector_: Reflector, code: DOMErrorName, - reflector_: Reflector } impl DOMException { fn new_inherited(code: DOMErrorName) -> DOMException { DOMException { + reflector_: Reflector::new(), code: code, - reflector_: Reflector::new() } } diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 2f593e5fe7b..0d227f81733 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -27,15 +27,15 @@ use servo_util::str::DOMString; #[dom_struct] pub struct DOMImplementation { - document: JS<Document>, reflector_: Reflector, + document: JS<Document>, } impl DOMImplementation { fn new_inherited(document: JSRef<Document>) -> DOMImplementation { DOMImplementation { - document: JS::from_rooted(document), reflector_: Reflector::new(), + document: JS::from_rooted(document), } } diff --git a/components/script/dom/domparser.rs b/components/script/dom/domparser.rs index 06c3cb36813..a77a21d83d5 100644 --- a/components/script/dom/domparser.rs +++ b/components/script/dom/domparser.rs @@ -19,15 +19,15 @@ use servo_util::str::DOMString; #[dom_struct] pub struct DOMParser { + reflector_: Reflector, window: JS<Window>, //XXXjdm Document instead? - reflector_: Reflector } impl DOMParser { fn new_inherited(window: JSRef<Window>) -> DOMParser { DOMParser { + reflector_: Reflector::new(), window: JS::from_rooted(window), - reflector_: Reflector::new() } } diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index a8455a94e6f..ea885e02a9a 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -51,8 +51,8 @@ pub enum EventCancelable { #[dom_struct] pub struct Event { - type_id: EventTypeId, reflector_: Reflector, + type_id: EventTypeId, current_target: MutNullableJS<EventTarget>, target: MutNullableJS<EventTarget>, type_: DOMRefCell<DOMString>, @@ -71,8 +71,8 @@ pub struct Event { impl Event { pub fn new_inherited(type_id: EventTypeId) -> Event { Event { - type_id: type_id, reflector_: Reflector::new(), + type_id: type_id, current_target: Default::default(), target: Default::default(), phase: Cell::new(EventPhase::None), diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 227212077d7..9decaf829ab 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -72,16 +72,16 @@ pub struct EventListenerEntry { #[dom_struct] pub struct EventTarget { - type_id: EventTargetTypeId, reflector_: Reflector, + type_id: EventTargetTypeId, handlers: DOMRefCell<HashMap<DOMString, Vec<EventListenerEntry>, FnvHasher>>, } impl EventTarget { pub fn new_inherited(type_id: EventTargetTypeId) -> EventTarget { EventTarget { - type_id: type_id, reflector_: Reflector::new(), + type_id: type_id, handlers: DOMRefCell::new(HashMap::with_hasher(FnvHasher)), } } diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index 8de4263a61e..461207f11a8 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -29,8 +29,8 @@ pub enum FormDatum { #[dom_struct] pub struct FormData { - data: DOMRefCell<HashMap<DOMString, Vec<FormDatum>>>, reflector_: Reflector, + data: DOMRefCell<HashMap<DOMString, Vec<FormDatum>>>, global: GlobalField, form: Option<JS<HTMLFormElement>> } @@ -38,8 +38,8 @@ pub struct FormData { impl FormData { fn new_inherited(form: Option<JSRef<HTMLFormElement>>, global: &GlobalRef) -> FormData { FormData { - data: DOMRefCell::new(HashMap::new()), reflector_: Reflector::new(), + data: DOMRefCell::new(HashMap::new()), global: GlobalField::from_rooted(global), form: form.map(|f| JS::from_rooted(f)), } diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 7e08fcb6e2d..af885c0b561 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -32,15 +32,15 @@ pub enum CollectionTypeId { #[dom_struct] pub struct HTMLCollection { - collection: CollectionTypeId, reflector_: Reflector, + collection: CollectionTypeId, } impl HTMLCollection { fn new_inherited(collection: CollectionTypeId) -> HTMLCollection { HTMLCollection { - collection: collection, reflector_: Reflector::new(), + collection: collection, } } diff --git a/components/script/dom/htmltablerowelement.rs b/components/script/dom/htmltablerowelement.rs index d8e9aad1323..287b994a81b 100644 --- a/components/script/dom/htmltablerowelement.rs +++ b/components/script/dom/htmltablerowelement.rs @@ -50,3 +50,46 @@ impl HTMLTableRowElement { } } + +pub trait HTMLTableRowElementHelpers { + fn get_background_color(&self) -> Option<RGBA>; +} + +impl HTMLTableRowElementHelpers for HTMLTableRowElement { + fn get_background_color(&self) -> Option<RGBA> { + self.background_color.get() + } +} + +impl<'a> VirtualMethods for JSRef<'a, HTMLTableRowElement> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { + let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self); + Some(htmlelement as &VirtualMethods) + } + + fn after_set_attr(&self, attr: JSRef<Attr>) { + match self.super_type() { + Some(ref s) => s.after_set_attr(attr), + _ => () + } + + match attr.local_name() { + &atom!("bgcolor") => { + self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok()) + } + _ => {} + } + } + + fn before_remove_attr(&self, attr: JSRef<Attr>) { + match self.super_type() { + Some(ref s) => s.before_remove_attr(attr), + _ => () + } + + match attr.local_name() { + &atom!("bgcolor") => self.background_color.set(None), + _ => {} + } + } +} diff --git a/components/script/dom/htmltablesectionelement.rs b/components/script/dom/htmltablesectionelement.rs index 40e7f91ac0a..5894d20bab5 100644 --- a/components/script/dom/htmltablesectionelement.rs +++ b/components/script/dom/htmltablesectionelement.rs @@ -49,3 +49,45 @@ impl HTMLTableSectionElement { } } +pub trait HTMLTableSectionElementHelpers { + fn get_background_color(&self) -> Option<RGBA>; +} + +impl HTMLTableSectionElementHelpers for HTMLTableSectionElement { + fn get_background_color(&self) -> Option<RGBA> { + self.background_color.get() + } +} + +impl<'a> VirtualMethods for JSRef<'a, HTMLTableSectionElement> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { + let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self); + Some(htmlelement as &VirtualMethods) + } + + fn after_set_attr(&self, attr: JSRef<Attr>) { + match self.super_type() { + Some(ref s) => s.after_set_attr(attr), + _ => () + } + + match attr.local_name() { + &atom!("bgcolor") => { + self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok()) + } + _ => {} + } + } + + fn before_remove_attr(&self, attr: JSRef<Attr>) { + match self.super_type() { + Some(ref s) => s.before_remove_attr(attr), + _ => () + } + + match attr.local_name() { + &atom!("bgcolor") => self.background_color.set(None), + _ => {} + } + } +} diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 5637cf74318..ea0d1156bb4 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -329,3 +329,20 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTextAreaElement> { } } +impl<'a> FormControl<'a> for JSRef<'a, HTMLTextAreaElement> { + fn to_element(self) -> JSRef<'a, Element> { + ElementCast::from_ref(self) + } + + // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable + fn mutable(self) -> bool { + // https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element:concept-fe-mutable + !(self.Disabled() || self.ReadOnly()) + } + + fn reset(self) { + // https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element:concept-form-reset-control + self.SetValue(self.DefaultValue()); + self.value_changed.set(false); + } +} diff --git a/components/script/dom/htmltitleelement.rs b/components/script/dom/htmltitleelement.rs index fb3a4a5eace..c7f42c85eb9 100644 --- a/components/script/dom/htmltitleelement.rs +++ b/components/script/dom/htmltitleelement.rs @@ -64,3 +64,17 @@ impl<'a> HTMLTitleElementMethods for JSRef<'a, HTMLTitleElement> { } } +impl<'a> VirtualMethods for JSRef<'a, HTMLTitleElement> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { + let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self); + Some(htmlelement as &VirtualMethods) + } + + fn bind_to_tree(&self, is_in_doc: bool) { + let node: JSRef<Node> = NodeCast::from_ref(*self); + if is_in_doc { + let document = node.owner_doc().root(); + document.send_title_to_compositor() + } + } +} diff --git a/components/script/dom/nodelist.rs b/components/script/dom/nodelist.rs index 61087cdcb32..5714764eeaf 100644 --- a/components/script/dom/nodelist.rs +++ b/components/script/dom/nodelist.rs @@ -19,15 +19,15 @@ pub enum NodeListType { #[dom_struct] pub struct NodeList { - list_type: NodeListType, reflector_: Reflector, + list_type: NodeListType, } impl NodeList { fn new_inherited(list_type: NodeListType) -> NodeList { NodeList { - list_type: list_type, reflector_: Reflector::new(), + list_type: list_type, } } diff --git a/components/script/dom/urlsearchparams.rs b/components/script/dom/urlsearchparams.rs index a45230726c6..d472d294d5f 100644 --- a/components/script/dom/urlsearchparams.rs +++ b/components/script/dom/urlsearchparams.rs @@ -24,15 +24,15 @@ use std::ascii::OwnedAsciiExt; #[dom_struct] pub struct URLSearchParams { - data: DOMRefCell<HashMap<DOMString, Vec<DOMString>>>, reflector_: Reflector, + data: DOMRefCell<HashMap<DOMString, Vec<DOMString>>>, } impl URLSearchParams { fn new_inherited() -> URLSearchParams { URLSearchParams { - data: DOMRefCell::new(HashMap::new()), reflector_: Reflector::new(), + data: DOMRefCell::new(HashMap::new()), } } |