mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Remove helper traits
Now that JSRef<T> is gone, there is no need to have helper traits. On components/script/*.rs: # Remove imports. /^ *use dom::[a-z]+::\{.*Helpers/ { s/\{(Raw[^L]|[^L][^a])[a-zA-Z]+Helpers, /\{/ s/, (Raw[^L]|[^L][^a])[a-zA-Z]+Helpers([,}])/\2/g s/\{([a-zA-Z]+)\}/\1/ /\{\}/d s/::self;$/;/ } /^ *use dom::[a-z]+::\{?(Raw[^L]|[^L][^a])[a-zA-Z]+Helpers\}?;$/d On components/script/dom/*.rs: # Ignore layout things. /^(pub )?(impl|trait).*Layout.* \{/,/^}$/ { P; D; } # Delete helpers traits. /^(pub )?trait ([^L][^ ]|L[^a])[^ ]+Helpers(<'a>)? \{$/,/^\}$/D # Patch private helpers. /^impl.*Private.*Helpers/,/^\}$/ { s/^impl<'a> Private([^L][^ ]|L[^a])[^ ]+Helpers(<'a>)? for &'a ([^ ]+) \{$/impl \3 {/ /^ *(unsafe )?fn .*\(self.*[<&]'a/ { s/&'a /\&/g s/<'a, /</g } /^ *(unsafe )?fn /s/\(self([,)])/\(\&self\1/ } # Patch public helpers. /^impl.*Helpers/,/^\}$/ { s/^impl(<'a>)? ([^L][^ ]|L[^a])[^ ]+Helpers(<'a>)? for (&'a )?([^ ]+) \{$/impl \5 {/ /^ *(unsafe )?fn .*\(self.*[<&]'a/ { s/&'a /\&/g s/<'a, /</g } /^ *(unsafe )?fn .*\(&?self[,)]/s/(unsafe )?fn/pub &/ /^ *pub (unsafe )?fn /s/\(self([,)])/\(\&self\1/ } The few error cases were then fixed by hand.
This commit is contained in:
parent
1384ff5e9f
commit
c831c2c0a5
90 changed files with 597 additions and 1284 deletions
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::attr::Attr;
|
||||
use dom::attr::AttrHelpers;
|
||||
use dom::attr::AttrValue;
|
||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||
use dom::bindings::codegen::Bindings::HTMLElementBinding;
|
||||
|
@ -18,16 +17,15 @@ use dom::bindings::error::ErrorResult;
|
|||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||
use dom::bindings::utils::Reflectable;
|
||||
use dom::cssstyledeclaration::{CSSStyleDeclaration, CSSModificationAccess};
|
||||
use dom::document::{Document, DocumentHelpers};
|
||||
use dom::document::Document;
|
||||
use dom::domstringmap::DOMStringMap;
|
||||
use dom::element::{Element, ElementTypeId, ActivationElementHelpers, AttributeHandlers};
|
||||
use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId};
|
||||
use dom::element::{Element, ElementTypeId, AttributeHandlers};
|
||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
use dom::htmlinputelement::HTMLInputElement;
|
||||
use dom::htmlmediaelement::HTMLMediaElementTypeId;
|
||||
use dom::htmltablecellelement::HTMLTableCellElementTypeId;
|
||||
use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node, SEQUENTIALLY_FOCUSABLE};
|
||||
use dom::node::{Node, NodeTypeId, document_from_node, window_from_node, SEQUENTIALLY_FOCUSABLE};
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use dom::window::WindowHelpers;
|
||||
|
||||
use msg::constellation_msg::FocusType;
|
||||
use util::str::DOMString;
|
||||
|
@ -81,18 +79,14 @@ impl HTMLElement {
|
|||
}
|
||||
}
|
||||
|
||||
trait PrivateHTMLElementHelpers {
|
||||
fn is_body_or_frameset(self) -> bool;
|
||||
fn update_sequentially_focusable_status(self);
|
||||
}
|
||||
|
||||
impl<'a> PrivateHTMLElementHelpers for &'a HTMLElement {
|
||||
fn is_body_or_frameset(self) -> bool {
|
||||
impl HTMLElement {
|
||||
fn is_body_or_frameset(&self) -> bool {
|
||||
let eventtarget = EventTargetCast::from_ref(self);
|
||||
eventtarget.is_htmlbodyelement() || eventtarget.is_htmlframesetelement()
|
||||
}
|
||||
|
||||
fn update_sequentially_focusable_status(self) {
|
||||
fn update_sequentially_focusable_status(&self) {
|
||||
let element = ElementCast::from_ref(self);
|
||||
let node = NodeCast::from_ref(self);
|
||||
if element.has_attribute(&atom!("tabindex")) {
|
||||
|
@ -276,11 +270,6 @@ impl<'a> HTMLElementMethods for &'a HTMLElement {
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#attr-data-*
|
||||
pub trait HTMLElementCustomAttributeHelpers {
|
||||
fn set_custom_attr(self, name: DOMString, value: DOMString) -> ErrorResult;
|
||||
fn get_custom_attr(self, name: DOMString) -> Option<DOMString>;
|
||||
fn delete_custom_attr(self, name: DOMString);
|
||||
}
|
||||
|
||||
fn to_snake_case(name: DOMString) -> DOMString {
|
||||
let mut attr_name = "data-".to_owned();
|
||||
|
@ -295,8 +284,8 @@ fn to_snake_case(name: DOMString) -> DOMString {
|
|||
attr_name
|
||||
}
|
||||
|
||||
impl<'a> HTMLElementCustomAttributeHelpers for &'a HTMLElement {
|
||||
fn set_custom_attr(self, name: DOMString, value: DOMString) -> ErrorResult {
|
||||
impl HTMLElement {
|
||||
pub fn set_custom_attr(&self, name: DOMString, value: DOMString) -> ErrorResult {
|
||||
if name.chars()
|
||||
.skip_while(|&ch| ch != '\u{2d}')
|
||||
.nth(1).map_or(false, |ch| ch >= 'a' && ch <= 'z') {
|
||||
|
@ -306,7 +295,7 @@ impl<'a> HTMLElementCustomAttributeHelpers for &'a HTMLElement {
|
|||
element.set_custom_attribute(to_snake_case(name), value)
|
||||
}
|
||||
|
||||
fn get_custom_attr(self, local_name: DOMString) -> Option<DOMString> {
|
||||
pub fn get_custom_attr(&self, local_name: DOMString) -> Option<DOMString> {
|
||||
let element = ElementCast::from_ref(self);
|
||||
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
||||
element.get_attribute(&ns!(""), &local_name).map(|attr| {
|
||||
|
@ -314,7 +303,7 @@ impl<'a> HTMLElementCustomAttributeHelpers for &'a HTMLElement {
|
|||
})
|
||||
}
|
||||
|
||||
fn delete_custom_attr(self, local_name: DOMString) {
|
||||
pub fn delete_custom_attr(&self, local_name: DOMString) {
|
||||
let element = ElementCast::from_ref(self);
|
||||
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
||||
element.remove_attribute(&ns!(""), &local_name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue