mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implement From<DOMString> for Atom
This commit is contained in:
parent
f7fb035188
commit
0adfb08089
20 changed files with 44 additions and 38 deletions
|
@ -174,6 +174,6 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
pub fn namespace_from_domstring(url: Option<DOMString>) -> Namespace {
|
||||
match url {
|
||||
None => ns!(),
|
||||
Some(s) => Namespace(Atom::from(&*s)),
|
||||
Some(s) => Namespace(Atom::from(s)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ impl CloseEvent {
|
|||
EventCancelable::NotCancelable
|
||||
};
|
||||
Ok(CloseEvent::new(global,
|
||||
Atom::from(&*type_),
|
||||
Atom::from(type_),
|
||||
bubbles,
|
||||
cancelable,
|
||||
init.wasClean,
|
||||
|
|
|
@ -146,7 +146,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
|||
|
||||
// Step 1
|
||||
property.make_ascii_lowercase();
|
||||
let property = Atom::from(&*property);
|
||||
let property = Atom::from(property);
|
||||
|
||||
if self.readonly {
|
||||
// Readonly style declarations are used for getComputedStyle.
|
||||
|
@ -185,7 +185,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
|||
fn GetPropertyPriority(&self, mut property: DOMString) -> DOMString {
|
||||
// Step 1
|
||||
property.make_ascii_lowercase();
|
||||
let property = Atom::from(&*property);
|
||||
let property = Atom::from(property);
|
||||
|
||||
// Step 2
|
||||
if let Some(shorthand) = Shorthand::from_name(&property) {
|
||||
|
|
|
@ -53,7 +53,7 @@ impl CustomEvent {
|
|||
init: &CustomEventBinding::CustomEventInit)
|
||||
-> Fallible<Root<CustomEvent>> {
|
||||
Ok(CustomEvent::new(global,
|
||||
Atom::from(&*type_),
|
||||
Atom::from(type_),
|
||||
init.parent.bubbles,
|
||||
init.parent.cancelable,
|
||||
unsafe { HandleValue::from_marked_location(&init.detail) }))
|
||||
|
@ -87,7 +87,7 @@ impl CustomEventMethods for CustomEvent {
|
|||
can_bubble: bool,
|
||||
cancelable: bool,
|
||||
detail: HandleValue) {
|
||||
self.init_custom_event(Atom::from(&*type_), can_bubble, cancelable, detail)
|
||||
self.init_custom_event(Atom::from(type_), can_bubble, cancelable, detail)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-istrusted
|
||||
|
|
|
@ -1847,7 +1847,7 @@ impl DocumentMethods for Document {
|
|||
Vacant(entry) => {
|
||||
let mut tag_copy = tag_name;
|
||||
tag_copy.make_ascii_lowercase();
|
||||
let ascii_lower_tag = Atom::from(&*tag_copy);
|
||||
let ascii_lower_tag = Atom::from(tag_copy);
|
||||
let result = HTMLCollection::by_atomic_tag_name(&self.window,
|
||||
self.upcast(),
|
||||
tag_atom,
|
||||
|
@ -1864,7 +1864,7 @@ impl DocumentMethods for Document {
|
|||
tag_name: DOMString)
|
||||
-> Root<HTMLCollection> {
|
||||
let ns = namespace_from_domstring(maybe_ns);
|
||||
let local = Atom::from(&*tag_name);
|
||||
let local = Atom::from(tag_name);
|
||||
let qname = QualName::new(ns, local);
|
||||
match self.tagns_map.borrow_mut().entry(qname.clone()) {
|
||||
Occupied(entry) => Root::from_ref(entry.get()),
|
||||
|
@ -1895,7 +1895,7 @@ impl DocumentMethods for Document {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
||||
fn GetElementById(&self, id: DOMString) -> Option<Root<Element>> {
|
||||
self.get_element_by_id(&Atom::from(&*id))
|
||||
self.get_element_by_id(&Atom::from(id))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-document-createelement
|
||||
|
@ -1907,7 +1907,7 @@ impl DocumentMethods for Document {
|
|||
if self.is_html_document {
|
||||
local_name.make_ascii_lowercase();
|
||||
}
|
||||
let name = QualName::new(ns!(html), Atom::from(&*local_name));
|
||||
let name = QualName::new(ns!(html), Atom::from(local_name));
|
||||
Ok(Element::create(name, None, self, ElementCreator::ScriptCreated))
|
||||
}
|
||||
|
||||
|
@ -1931,7 +1931,7 @@ impl DocumentMethods for Document {
|
|||
if self.is_html_document {
|
||||
local_name.make_ascii_lowercase();
|
||||
}
|
||||
let name = Atom::from(&*local_name);
|
||||
let name = Atom::from(local_name);
|
||||
let value = AttrValue::String(DOMString::new());
|
||||
|
||||
Ok(Attr::new(&self.window, name.clone(), value, name, ns!(), None, None))
|
||||
|
@ -1945,7 +1945,7 @@ impl DocumentMethods for Document {
|
|||
let (namespace, prefix, local_name) = try!(validate_and_extract(namespace,
|
||||
&qualified_name));
|
||||
let value = AttrValue::String(DOMString::new());
|
||||
let qualified_name = Atom::from(&*qualified_name);
|
||||
let qualified_name = Atom::from(qualified_name);
|
||||
Ok(Attr::new(&self.window,
|
||||
local_name,
|
||||
value,
|
||||
|
@ -2491,7 +2491,7 @@ impl DocumentMethods for Document {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
let name = Atom::from(&*name);
|
||||
let name = Atom::from(name);
|
||||
let root = self.upcast::<Node>();
|
||||
{
|
||||
// Step 1.
|
||||
|
|
|
@ -55,7 +55,7 @@ impl DocumentFragmentMethods for DocumentFragment {
|
|||
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
||||
fn GetElementById(&self, id: DOMString) -> Option<Root<Element>> {
|
||||
let node = self.upcast::<Node>();
|
||||
let id = Atom::from(&*id);
|
||||
let id = Atom::from(id);
|
||||
node.traverse_preorder().filter_map(Root::downcast::<Element>).find(|descendant| {
|
||||
match descendant.get_attribute(&ns!(), &atom!("id")) {
|
||||
None => false,
|
||||
|
|
|
@ -617,7 +617,7 @@ impl Element {
|
|||
if self.html_element_in_html_document() {
|
||||
name.make_ascii_lowercase();
|
||||
}
|
||||
Atom::from(&*name)
|
||||
Atom::from(name)
|
||||
}
|
||||
|
||||
pub fn namespace(&self) -> &Namespace {
|
||||
|
@ -952,7 +952,7 @@ impl Element {
|
|||
}
|
||||
|
||||
// Steps 2-5.
|
||||
let name = Atom::from(&*name);
|
||||
let name = Atom::from(name);
|
||||
let value = self.parse_attribute(&ns!(), &name, value);
|
||||
self.set_first_matching_attribute(name.clone(),
|
||||
value,
|
||||
|
@ -1249,7 +1249,7 @@ impl ElementMethods for Element {
|
|||
local_name: DOMString)
|
||||
-> Option<Root<Attr>> {
|
||||
let namespace = &namespace_from_domstring(namespace);
|
||||
self.get_attribute(namespace, &Atom::from(&*local_name))
|
||||
self.get_attribute(namespace, &Atom::from(local_name))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-setattribute
|
||||
|
@ -1277,7 +1277,7 @@ impl ElementMethods for Element {
|
|||
value: DOMString) -> ErrorResult {
|
||||
let (namespace, prefix, local_name) =
|
||||
try!(validate_and_extract(namespace, &qualified_name));
|
||||
let qualified_name = Atom::from(&*qualified_name);
|
||||
let qualified_name = Atom::from(qualified_name);
|
||||
let value = self.parse_attribute(&namespace, &local_name, value);
|
||||
self.set_first_matching_attribute(
|
||||
local_name.clone(), value, qualified_name, namespace.clone(), prefix,
|
||||
|
@ -1344,7 +1344,7 @@ impl ElementMethods for Element {
|
|||
// https://dom.spec.whatwg.org/#dom-element-removeattributens
|
||||
fn RemoveAttributeNS(&self, namespace: Option<DOMString>, local_name: DOMString) {
|
||||
let namespace = namespace_from_domstring(namespace);
|
||||
let local_name = Atom::from(&*local_name);
|
||||
let local_name = Atom::from(local_name);
|
||||
self.remove_attribute(&namespace, &local_name);
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ impl ErrorEvent {
|
|||
// Dictionaries need to be rooted
|
||||
// https://github.com/servo/servo/issues/6381
|
||||
let error = RootedValue::new(global.get_cx(), init.error);
|
||||
let event = ErrorEvent::new(global, Atom::from(&*type_),
|
||||
let event = ErrorEvent::new(global, Atom::from(type_),
|
||||
bubbles, cancelable,
|
||||
msg, file_name,
|
||||
line_num, col_num,
|
||||
|
|
|
@ -96,7 +96,7 @@ impl Event {
|
|||
init: &EventBinding::EventInit) -> Fallible<Root<Event>> {
|
||||
let bubbles = if init.bubbles { EventBubbles::Bubbles } else { EventBubbles::DoesNotBubble };
|
||||
let cancelable = if init.cancelable { EventCancelable::Cancelable } else { EventCancelable::NotCancelable };
|
||||
Ok(Event::new(global, Atom::from(&*type_), bubbles, cancelable))
|
||||
Ok(Event::new(global, Atom::from(type_), bubbles, cancelable))
|
||||
}
|
||||
|
||||
pub fn init_event(&self, type_: Atom, bubbles: bool, cancelable: bool) {
|
||||
|
@ -240,7 +240,7 @@ impl EventMethods for Event {
|
|||
type_: DOMString,
|
||||
bubbles: bool,
|
||||
cancelable: bool) {
|
||||
self.init_event(Atom::from(&*type_), bubbles, cancelable)
|
||||
self.init_event(Atom::from(type_), bubbles, cancelable)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-event-istrusted
|
||||
|
|
|
@ -494,7 +494,7 @@ impl EventTargetMethods for EventTarget {
|
|||
capture: bool) {
|
||||
if let Some(listener) = listener {
|
||||
let mut handlers = self.handlers.borrow_mut();
|
||||
let entry = match handlers.entry(Atom::from(&*ty)) {
|
||||
let entry = match handlers.entry(Atom::from(ty)) {
|
||||
Occupied(entry) => entry.into_mut(),
|
||||
Vacant(entry) => entry.insert(EventListeners(vec!())),
|
||||
};
|
||||
|
@ -517,7 +517,7 @@ impl EventTargetMethods for EventTarget {
|
|||
capture: bool) {
|
||||
if let Some(ref listener) = listener {
|
||||
let mut handlers = self.handlers.borrow_mut();
|
||||
let entry = handlers.get_mut(&Atom::from(&*ty));
|
||||
let entry = handlers.get_mut(&Atom::from(ty));
|
||||
for entry in entry {
|
||||
let phase = if capture { ListenerPhase::Capturing } else { ListenerPhase::Bubbling };
|
||||
let old_entry = EventListenerEntry {
|
||||
|
|
|
@ -115,9 +115,9 @@ impl HTMLCollection {
|
|||
|
||||
pub fn by_tag_name(window: &Window, root: &Node, mut tag: DOMString)
|
||||
-> Root<HTMLCollection> {
|
||||
let tag_atom = Atom::from(&*tag); // FIXME(ajeffrey): Convert directly from DOMString to Atom
|
||||
let tag_atom = Atom::from(&*tag);
|
||||
tag.make_ascii_lowercase();
|
||||
let ascii_lower_tag = Atom::from(&*tag); // FIXME(ajeffrey): Convert directly from DOMString to Atom
|
||||
let ascii_lower_tag = Atom::from(tag); // FIXME(ajeffrey): don't clone atom if it was already lowercased.
|
||||
HTMLCollection::by_atomic_tag_name(window, root, tag_atom, ascii_lower_tag)
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ impl HTMLCollection {
|
|||
|
||||
pub fn by_tag_name_ns(window: &Window, root: &Node, tag: DOMString,
|
||||
maybe_ns: Option<DOMString>) -> Root<HTMLCollection> {
|
||||
let local = Atom::from(&*tag); // FIXME(ajeffrey): Convert directly from DOMString to Atom
|
||||
let local = Atom::from(tag);
|
||||
let ns = namespace_from_domstring(maybe_ns);
|
||||
let qname = QualName::new(ns, local);
|
||||
HTMLCollection::by_qual_tag_name(window, root, qname)
|
||||
|
|
|
@ -340,7 +340,7 @@ impl HTMLElement {
|
|||
|
||||
pub fn get_custom_attr(&self, local_name: DOMString) -> Option<DOMString> {
|
||||
// FIXME(ajeffrey): Convert directly from DOMString to Atom
|
||||
let local_name = Atom::from(&*to_snake_case(local_name));
|
||||
let local_name = Atom::from(to_snake_case(local_name));
|
||||
self.upcast::<Element>().get_attribute(&ns!(), &local_name).map(|attr| {
|
||||
DOMString::from(&**attr.value()) // FIXME(ajeffrey): Convert directly from AttrValue to DOMString
|
||||
})
|
||||
|
@ -348,7 +348,7 @@ impl HTMLElement {
|
|||
|
||||
pub fn delete_custom_attr(&self, local_name: DOMString) {
|
||||
// FIXME(ajeffrey): Convert directly from DOMString to Atom
|
||||
let local_name = Atom::from(&*to_snake_case(local_name));
|
||||
let local_name = Atom::from(to_snake_case(local_name));
|
||||
self.upcast::<Element>().remove_attribute(&ns!(), &local_name);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ impl MessageEvent {
|
|||
// Dictionaries need to be rooted
|
||||
// https://github.com/servo/servo/issues/6381
|
||||
let data = RootedValue::new(global.get_cx(), init.data);
|
||||
let ev = MessageEvent::new(global, Atom::from(&*type_), init.parent.bubbles, init.parent.cancelable,
|
||||
let ev = MessageEvent::new(global, Atom::from(type_), init.parent.bubbles, init.parent.cancelable,
|
||||
data.handle(),
|
||||
init.origin.clone(), init.lastEventId.clone());
|
||||
Ok(ev)
|
||||
|
|
|
@ -56,7 +56,7 @@ impl NamedNodeMapMethods for NamedNodeMap {
|
|||
fn GetNamedItemNS(&self, namespace: Option<DOMString>, local_name: DOMString)
|
||||
-> Option<Root<Attr>> {
|
||||
let ns = namespace_from_domstring(namespace);
|
||||
self.owner.get_attribute(&ns, &Atom::from(&*local_name))
|
||||
self.owner.get_attribute(&ns, &Atom::from(local_name))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-namednodemap-setnameditem
|
||||
|
@ -79,7 +79,7 @@ impl NamedNodeMapMethods for NamedNodeMap {
|
|||
fn RemoveNamedItemNS(&self, namespace: Option<DOMString>, local_name: DOMString)
|
||||
-> Fallible<Root<Attr>> {
|
||||
let ns = namespace_from_domstring(namespace);
|
||||
self.owner.remove_attribute(&ns, &Atom::from(&*local_name))
|
||||
self.owner.remove_attribute(&ns, &Atom::from(local_name))
|
||||
.ok_or(Error::NotFound)
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ impl ProgressEvent {
|
|||
let bubbles = if init.parent.bubbles { EventBubbles::Bubbles } else { EventBubbles::DoesNotBubble };
|
||||
let cancelable = if init.parent.cancelable { EventCancelable::Cancelable }
|
||||
else { EventCancelable::NotCancelable };
|
||||
let ev = ProgressEvent::new(global, Atom::from(&*type_), bubbles, cancelable,
|
||||
let ev = ProgressEvent::new(global, Atom::from(type_), bubbles, cancelable,
|
||||
init.lengthComputable, init.loaded, init.total);
|
||||
Ok(ev)
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ impl StorageEvent {
|
|||
} else {
|
||||
EventCancelable::NotCancelable
|
||||
};
|
||||
let event = StorageEvent::new(global, Atom::from(&*type_),
|
||||
let event = StorageEvent::new(global, Atom::from(type_),
|
||||
bubbles, cancelable,
|
||||
key, oldValue, newValue,
|
||||
url, storageArea);
|
||||
|
|
|
@ -92,7 +92,7 @@ impl UIEventMethods for UIEvent {
|
|||
return;
|
||||
}
|
||||
|
||||
event.init_event(Atom::from(&*type_), can_bubble, cancelable);
|
||||
event.init_event(Atom::from(type_), can_bubble, cancelable);
|
||||
self.view.set(view);
|
||||
self.detail.set(detail);
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ impl WebGLContextEvent {
|
|||
EventCancelable::NotCancelable
|
||||
};
|
||||
|
||||
Ok(WebGLContextEvent::new(global, Atom::from(&*type_),
|
||||
Ok(WebGLContextEvent::new(global, Atom::from(type_),
|
||||
bubbles,
|
||||
cancelable,
|
||||
status_message))
|
||||
|
|
|
@ -129,8 +129,7 @@ impl AttrValue {
|
|||
}
|
||||
|
||||
pub fn from_atomic(string: DOMString) -> AttrValue {
|
||||
// FIXME(ajeffrey): convert directly from DOMString to Atom
|
||||
let value = Atom::from(&*string);
|
||||
let value = Atom::from(string);
|
||||
AttrValue::Atom(value)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use std::fmt;
|
|||
use std::iter::{Filter, Peekable};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::str::{Bytes, CharIndices, FromStr, Split, from_utf8};
|
||||
use string_cache::Atom;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
|
||||
pub struct DOMString(String);
|
||||
|
@ -96,6 +97,12 @@ impl<'a> From<&'a str> for DOMString {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<DOMString> for Atom {
|
||||
fn from(contents: DOMString) -> Atom {
|
||||
Atom::from(contents.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DOMString> for String {
|
||||
fn from(contents: DOMString) -> String {
|
||||
contents.0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue