diff options
Diffstat (limited to 'components/script')
154 files changed, 1623 insertions, 1162 deletions
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index f8f0b8f0d4b..81bf9bde314 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -25,6 +25,7 @@ angle = {git = "https://github.com/servo/angle", branch = "servo"} app_units = "0.3" audio-video-metadata = "0.1.2" bitflags = "0.7" +bluetooth_traits = {path = "../bluetooth_traits"} canvas_traits = {path = "../canvas_traits"} caseless = "0.1.0" cookie = {version = "0.2.5", features = ["serialize-rustc"]} @@ -35,13 +36,15 @@ euclid = "0.10.1" fnv = "1.0" gfx_traits = {path = "../gfx_traits"} heapsize = "0.3.6" -heapsize_plugin = "0.1.2" -html5ever = {version = "0.5.1", features = ["heap_size", "unstable"]} +heapsize_derive = "0.1" +html5ever = {version = "0.9.0", features = ["heap_size", "unstable"]} +html5ever-atoms = {version = "0.1", features = ["heap_size"]} hyper = "0.9.9" hyper_serde = "0.1.4" image = "0.10" ipc-channel = "0.5" js = {git = "https://github.com/servo/rust-mozjs", features = ["promises"]} +jstraceable_derive = {path = "../jstraceable_derive"} libc = "0.2" log = "0.3.5" mime = "0.2.1" @@ -65,15 +68,16 @@ script_layout_interface = {path = "../script_layout_interface"} script_traits = {path = "../script_traits"} selectors = "0.14" serde = "0.8" +servo_atoms = {path = "../atoms"} smallvec = "0.1" -string_cache = {version = "0.2.26", features = ["heap_size", "unstable"]} style = {path = "../style"} +style_traits = {path = "../style_traits"} time = "0.1.12" url = {version = "1.2", features = ["heap_size", "query_encoding"]} util = {path = "../util"} uuid = {version = "0.3.1", features = ["v4"]} websocket = "0.17" -xml5ever = {version = "0.1.2", features = ["unstable"]} +xml5ever = {version = "0.2", features = ["unstable"]} [dependencies.webrender_traits] git = "https://github.com/servo/webrender" diff --git a/components/script/document_loader.rs b/components/script/document_loader.rs index 837660109c3..04b9e258573 100644 --- a/components/script/document_loader.rs +++ b/components/script/document_loader.rs @@ -94,6 +94,7 @@ impl DocumentLoader { pub fn new_with_threads(resource_threads: ResourceThreads, initial_load: Option<Url>) -> DocumentLoader { + debug!("Initial blocking load {:?}.", initial_load); let initial_loads = initial_load.into_iter().map(LoadType::PageSource).collect(); DocumentLoader { @@ -105,6 +106,7 @@ impl DocumentLoader { /// Add a load to the list of blocking loads. fn add_blocking_load(&mut self, load: LoadType) { + debug!("Adding blocking load {:?} ({}).", load, self.blocking_loads.len()); self.blocking_loads.push(load); } @@ -119,6 +121,7 @@ impl DocumentLoader { /// Mark an in-progress network request complete. pub fn finish_load(&mut self, load: &LoadType) { + debug!("Removing blocking load {:?} ({}).", load, self.blocking_loads.len()); let idx = self.blocking_loads.iter().position(|unfinished| *unfinished == *load); self.blocking_loads.remove(idx.expect(&format!("unknown completed load {:?}", load))); } diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 89b8e68ff7a..2aae65af920 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -13,10 +13,11 @@ use dom::bindings::str::DOMString; use dom::element::{AttributeMutation, Element}; use dom::virtualmethods::vtable_for; use dom::window::Window; +use html5ever_atoms::{Prefix, LocalName, Namespace}; +use servo_atoms::Atom; use std::borrow::ToOwned; use std::cell::Ref; use std::mem; -use string_cache::{Atom, Namespace}; use style::attr::{AttrIdentifier, AttrValue}; // https://dom.spec.whatwg.org/#interface-attr @@ -31,11 +32,11 @@ pub struct Attr { } impl Attr { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, value: AttrValue, - name: Atom, + name: LocalName, namespace: Namespace, - prefix: Option<Atom>, + prefix: Option<Prefix>, owner: Option<&Element>) -> Attr { Attr { @@ -52,11 +53,11 @@ impl Attr { } pub fn new(window: &Window, - local_name: Atom, + local_name: LocalName, value: AttrValue, - name: Atom, + name: LocalName, namespace: Namespace, - prefix: Option<Atom>, + prefix: Option<Prefix>, owner: Option<&Element>) -> Root<Attr> { reflect_dom_object(box Attr::new_inherited(local_name, @@ -70,7 +71,7 @@ impl Attr { } #[inline] - pub fn name(&self) -> &Atom { + pub fn name(&self) -> &LocalName { &self.identifier.name } @@ -80,7 +81,7 @@ impl Attr { } #[inline] - pub fn prefix(&self) -> &Option<Atom> { + pub fn prefix(&self) -> &Option<Prefix> { &self.identifier.prefix } } @@ -88,7 +89,7 @@ impl Attr { impl AttrMethods for Attr { // https://dom.spec.whatwg.org/#dom-attr-localname fn LocalName(&self) -> DOMString { - // FIXME(ajeffrey): convert directly from Atom to DOMString + // FIXME(ajeffrey): convert directly from LocalName to DOMString DOMString::from(&**self.local_name()) } @@ -132,7 +133,7 @@ impl AttrMethods for Attr { // https://dom.spec.whatwg.org/#dom-attr-name fn Name(&self) -> DOMString { - // FIXME(ajeffrey): convert directly from Atom to DOMString + // FIXME(ajeffrey): convert directly from LocalName to DOMString DOMString::from(&*self.identifier.name) } @@ -143,16 +144,15 @@ impl AttrMethods for Attr { // https://dom.spec.whatwg.org/#dom-attr-namespaceuri fn GetNamespaceURI(&self) -> Option<DOMString> { - let Namespace(ref atom) = self.identifier.namespace; - match &**atom { - "" => None, - url => Some(DOMString::from(url)), + match self.identifier.namespace { + ns!() => None, + ref url => Some(DOMString::from(&**url)), } } // https://dom.spec.whatwg.org/#dom-attr-prefix fn GetPrefix(&self) -> Option<DOMString> { - // FIXME(ajeffrey): convert directly from Atom to DOMString + // FIXME(ajeffrey): convert directly from LocalName to DOMString self.prefix().as_ref().map(|p| DOMString::from(&**p)) } @@ -192,7 +192,7 @@ impl Attr { self.value.borrow() } - pub fn local_name(&self) -> &Atom { + pub fn local_name(&self) -> &LocalName { &self.identifier.local_name } @@ -216,9 +216,8 @@ impl Attr { } pub fn summarize(&self) -> AttrInfo { - let Namespace(ref ns) = self.identifier.namespace; AttrInfo { - namespace: (**ns).to_owned(), + namespace: (*self.identifier.namespace).to_owned(), name: String::from(self.Name()), value: String::from(self.Value()), } @@ -231,7 +230,7 @@ pub trait AttrHelpersForLayout { unsafe fn value_ref_forever(&self) -> &'static str; unsafe fn value_atom_forever(&self) -> Option<Atom>; unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]>; - unsafe fn local_name_atom_forever(&self) -> Atom; + unsafe fn local_name_atom_forever(&self) -> LocalName; unsafe fn value_for_layout(&self) -> &AttrValue; } @@ -267,7 +266,7 @@ impl AttrHelpersForLayout for LayoutJS<Attr> { } #[inline] - unsafe fn local_name_atom_forever(&self) -> Atom { + unsafe fn local_name_atom_forever(&self) -> LocalName { (*self.unsafe_get()).identifier.local_name.clone() } diff --git a/components/script/dom/beforeunloadevent.rs b/components/script/dom/beforeunloadevent.rs index 413a26a8de8..c79ca70c28e 100644 --- a/components/script/dom/beforeunloadevent.rs +++ b/components/script/dom/beforeunloadevent.rs @@ -12,7 +12,7 @@ use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::globalscope::GlobalScope; -use string_cache::Atom; +use servo_atoms::Atom; // https://html.spec.whatwg.org/multipage/#beforeunloadevent #[dom_struct] diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf index 434450d2bcc..5647679f446 100644 --- a/components/script/dom/bindings/codegen/Bindings.conf +++ b/components/script/dom/bindings/codegen/Bindings.conf @@ -14,12 +14,16 @@ DOMInterfaces = { +'MediaQueryList': { + 'weakReferenceable': True, +}, + 'Promise': { 'spiderMonkeyInterface': True, }, 'Range': { - 'weakReferenceable': True, + 'weakReferenceable': True, }, #FIXME(jdm): This should be 'register': False, but then we don't generate enum types diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index b65d2e65cdb..246d155d1e0 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2936,7 +2936,7 @@ assert!(!unforgeable_holder.is_null()); code.append(InitUnforgeablePropertiesOnHolder(self.descriptor, self.properties)) code.append(CGGeneric("""\ JS_SetReservedSlot(prototype.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, - ObjectValue(&*unforgeable_holder.get()))""")) + ObjectValue(unforgeable_holder.get()))""")) return CGList(code, "\n") @@ -6276,7 +6276,7 @@ class CGCallback(CGClass): }) bodyWithoutThis = string.Template( setupCall + - "rooted!(in(s.get_context()) let thisObjJS = ptr::null_mut());" + "rooted!(in(s.get_context()) let thisObjJS = ptr::null_mut());\n" "return ${methodName}(${callArgs});").substitute({ "callArgs": ", ".join(argnamesWithoutThis), "methodName": 'self.' + method.name, @@ -6607,7 +6607,7 @@ class CallCallback(CallbackMethod): return "aThisObj.get()" def getCallableDecl(self): - return "rooted!(in(cx) let callable = ObjectValue(&*self.parent.callback()));\n" + return "rooted!(in(cx) let callable = ObjectValue(self.parent.callback()));\n" def getCallGuard(self): if self.callback._treatNonObjectAsNull: @@ -6646,7 +6646,7 @@ class CallbackOperationBase(CallbackMethod): 'rooted!(in(cx) let callable =\n' + CGIndenter( CGIfElseWrapper('isCallable', - CGGeneric('ObjectValue(&*self.parent.callback())'), + CGGeneric('ObjectValue(self.parent.callback())'), CGGeneric(getCallableFromProp))).define() + ');\n') def getCallGuard(self): @@ -6734,10 +6734,10 @@ class CGIterableMethodGenerator(CGGeneric): throw_type_error(cx, "Argument 1 of ${ifaceName}.forEach is not callable."); return false; } - rooted!(in(cx) let arg0 = ObjectValue(&*arg0)); + rooted!(in(cx) let arg0 = ObjectValue(arg0)); rooted!(in(cx) let mut call_arg1 = UndefinedValue()); rooted!(in(cx) let mut call_arg2 = UndefinedValue()); - let mut call_args = vec![UndefinedValue(), UndefinedValue(), ObjectValue(&**_obj)]; + let mut call_args = vec![UndefinedValue(), UndefinedValue(), ObjectValue(*_obj)]; rooted!(in(cx) let mut ignoredReturnVal = UndefinedValue()); for i in 0..(*this).get_iterable_length() { (*this).get_value_at_index(i).to_jsval(cx, call_arg1.handle_mut()); diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index db723ad141c..9143c9cb75b 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -310,9 +310,9 @@ impl ToJSValConvertible for Reflector { assert!(!obj.is_null()); let same_compartment = IsObjectInContextCompartment(obj, cx); if same_compartment { - rval.set(ObjectValue(&*ToWindowProxyIfWindow(obj))); + rval.set(ObjectValue(ToWindowProxyIfWindow(obj))); } else { - rval.set(ObjectValue(&*obj)); + rval.set(ObjectValue(obj)); if !JS_WrapValue(cx, rval) { panic!("JS_WrapValue failed."); diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 779cb62d634..11aed4be9af 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -625,6 +625,12 @@ impl<T: Reflectable> Deref for Root<T> { } } +impl<T: Reflectable + HeapSizeOf> HeapSizeOf for Root<T> { + fn heap_size_of_children(&self) -> usize { + (**self).heap_size_of_children() + } +} + impl<T: Reflectable> PartialEq for Root<T> { fn eq(&self, other: &Self) -> bool { self.ptr == other.ptr diff --git a/components/script/dom/bindings/mozmap.rs b/components/script/dom/bindings/mozmap.rs index d44114cd057..5ef102539b7 100644 --- a/components/script/dom/bindings/mozmap.rs +++ b/components/script/dom/bindings/mozmap.rs @@ -105,6 +105,6 @@ impl<T: ToJSValConvertible> ToJSValConvertible for MozMap<T> { None)); } - rval.set(ObjectValue(&*js_object.handle().get())); + rval.set(ObjectValue(js_object.handle().get())); } } diff --git a/components/script/dom/bindings/num.rs b/components/script/dom/bindings/num.rs index fde24d08421..03b0c743f9f 100644 --- a/components/script/dom/bindings/num.rs +++ b/components/script/dom/bindings/num.rs @@ -4,6 +4,7 @@ //! The `Finite<T>` struct. +use heapsize::HeapSizeOf; use num_traits::Float; use std::ops::Deref; @@ -38,3 +39,9 @@ impl<T: Float> Deref for Finite<T> { value } } + +impl<T: Float + HeapSizeOf> HeapSizeOf for Finite<T> { + fn heap_size_of_children(&self) -> usize { + (**self).heap_size_of_children() + } +} diff --git a/components/script/dom/bindings/proxyhandler.rs b/components/script/dom/bindings/proxyhandler.rs index b5230b1b81a..cc4e535e4f2 100644 --- a/components/script/dom/bindings/proxyhandler.rs +++ b/components/script/dom/bindings/proxyhandler.rs @@ -178,7 +178,7 @@ pub fn ensure_expando_object(cx: *mut JSContext, obj: HandleObject) -> *mut JSOb expando = JS_NewObjectWithGivenProto(cx, ptr::null_mut(), HandleObject::null()); assert!(!expando.is_null()); - SetProxyExtra(obj.get(), JSPROXYSLOT_EXPANDO, &ObjectValue(&*expando)); + SetProxyExtra(obj.get(), JSPROXYSLOT_EXPANDO, &ObjectValue(expando)); } expando } diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index 2e28a1b314e..d7984939e28 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -4,6 +4,8 @@ //! The `ByteString` struct. +use html5ever_atoms::{LocalName, Namespace}; +use servo_atoms::Atom; use std::ascii::AsciiExt; use std::borrow::{Borrow, Cow, ToOwned}; use std::fmt; @@ -12,7 +14,6 @@ use std::ops; use std::ops::{Deref, DerefMut}; use std::str; use std::str::{Bytes, FromStr}; -use string_cache::Atom; /// Encapsulates the IDL `ByteString` type. #[derive(JSTraceable, Clone, Eq, PartialEq, HeapSizeOf, Debug)] @@ -255,6 +256,18 @@ impl<'a> From<Cow<'a, str>> for DOMString { } } +impl From<DOMString> for LocalName { + fn from(contents: DOMString) -> LocalName { + LocalName::from(contents.0) + } +} + +impl From<DOMString> for Namespace { + fn from(contents: DOMString) -> Namespace { + Namespace::from(contents.0) + } +} + impl From<DOMString> for Atom { fn from(contents: DOMString) -> Atom { Atom::from(contents.0) diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 9ac91f7078c..59a6178e462 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -47,6 +47,7 @@ use euclid::length::Length as EuclidLength; use euclid::rect::Rect; use euclid::size::Size2D; use html5ever::tree_builder::QuirksMode; +use html5ever_atoms::{Prefix, LocalName, Namespace, QualName}; use hyper::header::Headers; use hyper::method::Method; use hyper::mime::Mime; @@ -57,8 +58,8 @@ use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind}; use js::jsval::JSVal; use js::rust::Runtime; use libc; -use msg::constellation_msg::{FrameId, FrameType, PipelineId, ReferrerPolicy}; -use net_traits::{Metadata, NetworkError, ResourceThreads}; +use msg::constellation_msg::{FrameId, FrameType, PipelineId}; +use net_traits::{Metadata, NetworkError, ReferrerPolicy, ResourceThreads}; use net_traits::filemanager_thread::RelativePos; use net_traits::image::base::{Image, ImageMetadata}; use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread}; @@ -76,6 +77,7 @@ use script_runtime::ScriptChan; use script_traits::{TimerEventId, TimerSource, TouchpadPressurePhase}; use script_traits::{UntrustedNodeAddress, WindowSizeData, WindowSizeType}; use serde::{Deserialize, Serialize}; +use servo_atoms::Atom; use smallvec::SmallVec; use std::boxed::FnBox; use std::cell::{Cell, UnsafeCell}; @@ -88,9 +90,9 @@ use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::sync::mpsc::{Receiver, Sender}; use std::time::{SystemTime, Instant}; -use string_cache::{Atom, Namespace, QualName}; use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto}; use style::element_state::*; +use style::media_queries::MediaQueryList; use style::properties::PropertyDeclarationBlock; use style::selector_impl::{ElementSnapshot, PseudoElement}; use style::values::specified::Length; @@ -310,7 +312,7 @@ no_jsmanaged_fields!(Arc<T>); no_jsmanaged_fields!(Image, ImageMetadata, ImageCacheChan, ImageCacheThread); no_jsmanaged_fields!(Metadata); no_jsmanaged_fields!(NetworkError); -no_jsmanaged_fields!(Atom, Namespace, QualName); +no_jsmanaged_fields!(Atom, Prefix, LocalName, Namespace, QualName); no_jsmanaged_fields!(Trusted<T: Reflectable>); no_jsmanaged_fields!(TrustedPromise); no_jsmanaged_fields!(PropertyDeclarationBlock); @@ -367,7 +369,7 @@ no_jsmanaged_fields!(WebGLProgramId); no_jsmanaged_fields!(WebGLRenderbufferId); no_jsmanaged_fields!(WebGLShaderId); no_jsmanaged_fields!(WebGLTextureId); - +no_jsmanaged_fields!(MediaQueryList); impl JSTraceable for Box<ScriptChan + Send> { #[inline] diff --git a/components/script/dom/bindings/xmlname.rs b/components/script/dom/bindings/xmlname.rs index 11b83be7b99..4522c9c4ac0 100644 --- a/components/script/dom/bindings/xmlname.rs +++ b/components/script/dom/bindings/xmlname.rs @@ -6,7 +6,7 @@ use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::str::DOMString; -use string_cache::{Atom, Namespace}; +use html5ever_atoms::{Prefix, LocalName, Namespace}; /// Validate a qualified name. See https://dom.spec.whatwg.org/#validate for details. pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult { @@ -27,7 +27,7 @@ pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult { /// See https://dom.spec.whatwg.org/#validate-and-extract for details. pub fn validate_and_extract(namespace: Option<DOMString>, qualified_name: &str) - -> Fallible<(Namespace, Option<Atom>, Atom)> { + -> Fallible<(Namespace, Option<Prefix>, LocalName)> { // Step 1. let namespace = namespace_from_domstring(namespace); @@ -75,7 +75,7 @@ pub fn validate_and_extract(namespace: Option<DOMString>, }, (ns, p) => { // Step 10. - Ok((ns, p.map(Atom::from), Atom::from(local_name))) + Ok((ns, p.map(Prefix::from), LocalName::from(local_name))) } } } @@ -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::from(s), } } diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index 863d75bfec4..b6f8544aeab 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -3,6 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted}; +use bluetooth_traits::{BluetoothError, BluetoothMethodMsg}; +use bluetooth_traits::scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence}; +use bluetooth_traits::scanfilter::{RequestDeviceoptions, ServiceUUIDSequence}; use core::clone::Clone; use dom::bindings::codegen::Bindings::BluetoothBinding::{self, BluetoothMethods, BluetoothRequestDeviceFilter}; use dom::bindings::codegen::Bindings::BluetoothBinding::RequestDeviceOptions; @@ -18,9 +21,6 @@ use dom::globalscope::GlobalScope; use dom::promise::Promise; use ipc_channel::ipc::{self, IpcSender}; use js::conversions::ToJSValConvertible; -use net_traits::bluetooth_scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence}; -use net_traits::bluetooth_scanfilter::{RequestDeviceoptions, ServiceUUIDSequence}; -use net_traits::bluetooth_thread::{BluetoothError, BluetoothMethodMsg}; use std::rc::Rc; const FILTER_EMPTY_ERROR: &'static str = "'filters' member, if present, must be nonempty to find any devices."; diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index 95b26ff66c1..0fae7548ede 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted}; +use bluetooth_traits::BluetoothMethodMsg; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::BluetoothCharacteristicPropertiesBinding:: BluetoothCharacteristicPropertiesMethods; @@ -25,7 +26,6 @@ use dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID}; use dom::globalscope::GlobalScope; use dom::promise::Promise; use ipc_channel::ipc::{self, IpcSender}; -use net_traits::bluetooth_thread::BluetoothMethodMsg; use std::rc::Rc; // Maximum length of an attribute value. diff --git a/components/script/dom/bluetoothremotegattdescriptor.rs b/components/script/dom/bluetoothremotegattdescriptor.rs index f066bb9d22a..5ca51f45439 100644 --- a/components/script/dom/bluetoothremotegattdescriptor.rs +++ b/components/script/dom/bluetoothremotegattdescriptor.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted}; +use bluetooth_traits::BluetoothMethodMsg; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods; use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding:: @@ -21,7 +22,6 @@ use dom::bluetoothremotegattcharacteristic::{BluetoothRemoteGATTCharacteristic, use dom::globalscope::GlobalScope; use dom::promise::Promise; use ipc_channel::ipc::{self, IpcSender}; -use net_traits::bluetooth_thread::BluetoothMethodMsg; use std::rc::Rc; // http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs index fe19651ebf4..5e589fe07af 100644 --- a/components/script/dom/bluetoothremotegattserver.rs +++ b/components/script/dom/bluetoothremotegattserver.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted}; +use bluetooth_traits::BluetoothMethodMsg; use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods; use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding; use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods; @@ -18,7 +19,6 @@ use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID}; use dom::globalscope::GlobalScope; use dom::promise::Promise; use ipc_channel::ipc::{self, IpcSender}; -use net_traits::bluetooth_thread::BluetoothMethodMsg; use std::cell::Cell; use std::rc::Rc; diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs index bce51131649..a4fc78c8d93 100644 --- a/components/script/dom/bluetoothremotegattservice.rs +++ b/components/script/dom/bluetoothremotegattservice.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted}; +use bluetooth_traits::BluetoothMethodMsg; use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding; use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods; use dom::bindings::error::Error::{self, Security}; @@ -18,7 +19,6 @@ use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothServiceUUID, Blue use dom::globalscope::GlobalScope; use dom::promise::Promise; use ipc_channel::ipc::{self, IpcSender}; -use net_traits::bluetooth_thread::BluetoothMethodMsg; use std::rc::Rc; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice diff --git a/components/script/dom/closeevent.rs b/components/script/dom/closeevent.rs index a66af7bd75f..a4ad9893d80 100644 --- a/components/script/dom/closeevent.rs +++ b/components/script/dom/closeevent.rs @@ -12,7 +12,7 @@ use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::globalscope::GlobalScope; -use string_cache::Atom; +use servo_atoms::Atom; #[dom_struct] pub struct CloseEvent { diff --git a/components/script/dom/create.rs b/components/script/dom/create.rs index 98a2e5ad4ed..42a3c8158a1 100644 --- a/components/script/dom/create.rs +++ b/components/script/dom/create.rs @@ -77,7 +77,7 @@ use dom::htmlulistelement::HTMLUListElement; use dom::htmlunknownelement::HTMLUnknownElement; use dom::htmlvideoelement::HTMLVideoElement; use dom::svgsvgelement::SVGSVGElement; -use string_cache::{Atom, QualName}; +use html5ever_atoms::{Prefix, QualName}; use util::prefs::PREFS; fn create_svg_element(name: QualName, @@ -102,7 +102,7 @@ fn create_svg_element(name: QualName, } match name.local { - atom!("svg") => make!(SVGSVGElement), + local_name!("svg") => make!(SVGSVGElement), _ => Element::new(name.local, name.ns, prefix, document), } } @@ -128,157 +128,157 @@ fn create_html_element(name: QualName, // This is a big match, and the IDs for inline-interned atoms are not very structured. // Perhaps we should build a perfect hash from those IDs instead. match name.local { - atom!("a") => make!(HTMLAnchorElement), - atom!("abbr") => make!(HTMLElement), - atom!("acronym") => make!(HTMLElement), - atom!("address") => make!(HTMLElement), - atom!("applet") => make!(HTMLAppletElement), - atom!("area") => make!(HTMLAreaElement), - atom!("article") => make!(HTMLElement), - atom!("aside") => make!(HTMLElement), - atom!("audio") => make!(HTMLAudioElement), - atom!("b") => make!(HTMLElement), - atom!("base") => make!(HTMLBaseElement), - atom!("bdi") => make!(HTMLElement), - atom!("bdo") => make!(HTMLElement), + local_name!("a") => make!(HTMLAnchorElement), + local_name!("abbr") => make!(HTMLElement), + local_name!("acronym") => make!(HTMLElement), + local_name!("address") => make!(HTMLElement), + local_name!("applet") => make!(HTMLAppletElement), + local_name!("area") => make!(HTMLAreaElement), + local_name!("article") => make!(HTMLElement), + local_name!("aside") => make!(HTMLElement), + local_name!("audio") => make!(HTMLAudioElement), + local_name!("b") => make!(HTMLElement), + local_name!("base") => make!(HTMLBaseElement), + local_name!("bdi") => make!(HTMLElement), + local_name!("bdo") => make!(HTMLElement), // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:bgsound - atom!("bgsound") => make!(HTMLUnknownElement), - atom!("big") => make!(HTMLElement), + local_name!("bgsound") => make!(HTMLUnknownElement), + local_name!("big") => make!(HTMLElement), // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:blink - atom!("blink") => make!(HTMLUnknownElement), + local_name!("blink") => make!(HTMLUnknownElement), // https://html.spec.whatwg.org/multipage/#the-blockquote-element - atom!("blockquote") => make!(HTMLQuoteElement), - atom!("body") => make!(HTMLBodyElement), - atom!("br") => make!(HTMLBRElement), - atom!("button") => make!(HTMLButtonElement), - atom!("canvas") => make!(HTMLCanvasElement), - atom!("caption") => make!(HTMLTableCaptionElement), - atom!("center") => make!(HTMLElement), - atom!("cite") => make!(HTMLElement), - atom!("code") => make!(HTMLElement), - atom!("col") => make!(HTMLTableColElement), - atom!("colgroup") => make!(HTMLTableColElement), - atom!("data") => make!(HTMLDataElement), - atom!("datalist") => make!(HTMLDataListElement), - atom!("dd") => make!(HTMLElement), - atom!("del") => make!(HTMLModElement), - atom!("details") => make!(HTMLDetailsElement), - atom!("dfn") => make!(HTMLElement), - atom!("dialog") => make!(HTMLDialogElement), - atom!("dir") => make!(HTMLDirectoryElement), - atom!("div") => make!(HTMLDivElement), - atom!("dl") => make!(HTMLDListElement), - atom!("dt") => make!(HTMLElement), - atom!("em") => make!(HTMLElement), - atom!("embed") => make!(HTMLEmbedElement), - atom!("fieldset") => make!(HTMLFieldSetElement), - atom!("figcaption") => make!(HTMLElement), - atom!("figure") => make!(HTMLElement), - atom!("font") => make!(HTMLFontElement), - atom!("footer") => make!(HTMLElement), - atom!("form") => make!(HTMLFormElement), - atom!("frame") => make!(HTMLFrameElement), - atom!("frameset") => make!(HTMLFrameSetElement), - atom!("h1") => make!(HTMLHeadingElement, HeadingLevel::Heading1), - atom!("h2") => make!(HTMLHeadingElement, HeadingLevel::Heading2), - atom!("h3") => make!(HTMLHeadingElement, HeadingLevel::Heading3), - atom!("h4") => make!(HTMLHeadingElement, HeadingLevel::Heading4), - atom!("h5") => make!(HTMLHeadingElement, HeadingLevel::Heading5), - atom!("h6") => make!(HTMLHeadingElement, HeadingLevel::Heading6), - atom!("head") => make!(HTMLHeadElement), - atom!("header") => make!(HTMLElement), - atom!("hgroup") => make!(HTMLElement), - atom!("hr") => make!(HTMLHRElement), - atom!("html") => make!(HTMLHtmlElement), - atom!("i") => make!(HTMLElement), - atom!("iframe") => make!(HTMLIFrameElement), - atom!("img") => make!(HTMLImageElement), - atom!("input") => make!(HTMLInputElement), - atom!("ins") => make!(HTMLModElement), + local_name!("blockquote") => make!(HTMLQuoteElement), + local_name!("body") => make!(HTMLBodyElement), + local_name!("br") => make!(HTMLBRElement), + local_name!("button") => make!(HTMLButtonElement), + local_name!("canvas") => make!(HTMLCanvasElement), + local_name!("caption") => make!(HTMLTableCaptionElement), + local_name!("center") => make!(HTMLElement), + local_name!("cite") => make!(HTMLElement), + local_name!("code") => make!(HTMLElement), + local_name!("col") => make!(HTMLTableColElement), + local_name!("colgroup") => make!(HTMLTableColElement), + local_name!("data") => make!(HTMLDataElement), + local_name!("datalist") => make!(HTMLDataListElement), + local_name!("dd") => make!(HTMLElement), + local_name!("del") => make!(HTMLModElement), + local_name!("details") => make!(HTMLDetailsElement), + local_name!("dfn") => make!(HTMLElement), + local_name!("dialog") => make!(HTMLDialogElement), + local_name!("dir") => make!(HTMLDirectoryElement), + local_name!("div") => make!(HTMLDivElement), + local_name!("dl") => make!(HTMLDListElement), + local_name!("dt") => make!(HTMLElement), + local_name!("em") => make!(HTMLElement), + local_name!("embed") => make!(HTMLEmbedElement), + local_name!("fieldset") => make!(HTMLFieldSetElement), + local_name!("figcaption") => make!(HTMLElement), + local_name!("figure") => make!(HTMLElement), + local_name!("font") => make!(HTMLFontElement), + local_name!("footer") => make!(HTMLElement), + local_name!("form") => make!(HTMLFormElement), + local_name!("frame") => make!(HTMLFrameElement), + local_name!("frameset") => make!(HTMLFrameSetElement), + local_name!("h1") => make!(HTMLHeadingElement, HeadingLevel::Heading1), + local_name!("h2") => make!(HTMLHeadingElement, HeadingLevel::Heading2), + local_name!("h3") => make!(HTMLHeadingElement, HeadingLevel::Heading3), + local_name!("h4") => make!(HTMLHeadingElement, HeadingLevel::Heading4), + local_name!("h5") => make!(HTMLHeadingElement, HeadingLevel::Heading5), + local_name!("h6") => make!(HTMLHeadingElement, HeadingLevel::Heading6), + local_name!("head") => make!(HTMLHeadElement), + local_name!("header") => make!(HTMLElement), + local_name!("hgroup") => make!(HTMLElement), + local_name!("hr") => make!(HTMLHRElement), + local_name!("html") => make!(HTMLHtmlElement), + local_name!("i") => make!(HTMLElement), + local_name!("iframe") => make!(HTMLIFrameElement), + local_name!("img") => make!(HTMLImageElement), + local_name!("input") => make!(HTMLInputElement), + local_name!("ins") => make!(HTMLModElement), // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:isindex-2 - atom!("isindex") => make!(HTMLUnknownElement), - atom!("kbd") => make!(HTMLElement), - atom!("label") => make!(HTMLLabelElement), - atom!("legend") => make!(HTMLLegendElement), - atom!("li") => make!(HTMLLIElement), - atom!("link") => make!(HTMLLinkElement, creator), + local_name!("isindex") => make!(HTMLUnknownElement), + local_name!("kbd") => make!(HTMLElement), + local_name!("label") => make!(HTMLLabelElement), + local_name!("legend") => make!(HTMLLegendElement), + local_name!("li") => make!(HTMLLIElement), + local_name!("link") => make!(HTMLLinkElement, creator), // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:listing - atom!("listing") => make!(HTMLPreElement), - atom!("main") => make!(HTMLElement), - atom!("map") => make!(HTMLMapElement), - atom!("mark") => make!(HTMLElement), - atom!("marquee") => make!(HTMLElement), - atom!("meta") => make!(HTMLMetaElement), - atom!("meter") => make!(HTMLMeterElement), + local_name!("listing") => make!(HTMLPreElement), + local_name!("main") => make!(HTMLElement), + local_name!("map") => make!(HTMLMapElement), + local_name!("mark") => make!(HTMLElement), + local_name!("marquee") => make!(HTMLElement), + local_name!("meta") => make!(HTMLMetaElement), + local_name!("meter") => make!(HTMLMeterElement), // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:multicol - atom!("multicol") => make!(HTMLUnknownElement), - atom!("nav") => make!(HTMLElement), + local_name!("multicol") => make!(HTMLUnknownElement), + local_name!("nav") => make!(HTMLElement), // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:nextid - atom!("nextid") => make!(HTMLUnknownElement), - atom!("nobr") => make!(HTMLElement), - atom!("noframes") => make!(HTMLElement), - atom!("noscript") => make!(HTMLElement), - atom!("object") => make!(HTMLObjectElement), - atom!("ol") => make!(HTMLOListElement), - atom!("optgroup") => make!(HTMLOptGroupElement), - atom!("option") => make!(HTMLOptionElement), - atom!("output") => make!(HTMLOutputElement), - atom!("p") => make!(HTMLParagraphElement), - atom!("param") => make!(HTMLParamElement), - atom!("plaintext") => make!(HTMLPreElement), - atom!("pre") => make!(HTMLPreElement), - atom!("progress") => make!(HTMLProgressElement), - atom!("q") => make!(HTMLQuoteElement), - atom!("rp") => make!(HTMLElement), - atom!("rt") => make!(HTMLElement), - atom!("ruby") => make!(HTMLElement), - atom!("s") => make!(HTMLElement), - atom!("samp") => make!(HTMLElement), - atom!("script") => make!(HTMLScriptElement, creator), - atom!("section") => make!(HTMLElement), - atom!("select") => make!(HTMLSelectElement), - atom!("small") => make!(HTMLElement), - atom!("source") => make!(HTMLSourceElement), + local_name!("nextid") => make!(HTMLUnknownElement), + local_name!("nobr") => make!(HTMLElement), + local_name!("noframes") => make!(HTMLElement), + local_name!("noscript") => make!(HTMLElement), + local_name!("object") => make!(HTMLObjectElement), + local_name!("ol") => make!(HTMLOListElement), + local_name!("optgroup") => make!(HTMLOptGroupElement), + local_name!("option") => make!(HTMLOptionElement), + local_name!("output") => make!(HTMLOutputElement), + local_name!("p") => make!(HTMLParagraphElement), + local_name!("param") => make!(HTMLParamElement), + local_name!("plaintext") => make!(HTMLPreElement), + local_name!("pre") => make!(HTMLPreElement), + local_name!("progress") => make!(HTMLProgressElement), + local_name!("q") => make!(HTMLQuoteElement), + local_name!("rp") => make!(HTMLElement), + local_name!("rt") => make!(HTMLElement), + local_name!("ruby") => make!(HTMLElement), + local_name!("s") => make!(HTMLElement), + local_name!("samp") => make!(HTMLElement), + local_name!("script") => make!(HTMLScriptElement, creator), + local_name!("section") => make!(HTMLElement), + local_name!("select") => make!(HTMLSelectElement), + local_name!("small") => make!(HTMLElement), + local_name!("source") => make!(HTMLSourceElement), // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:spacer - atom!("spacer") => make!(HTMLUnknownElement), - atom!("span") => make!(HTMLSpanElement), - atom!("strike") => make!(HTMLElement), - atom!("strong") => make!(HTMLElement), - atom!("style") => make!(HTMLStyleElement), - atom!("sub") => make!(HTMLElement), - atom!("summary") => make!(HTMLElement), - atom!("sup") => make!(HTMLElement), - atom!("table") => make!(HTMLTableElement), - atom!("tbody") => make!(HTMLTableSectionElement), - atom!("td") => make!(HTMLTableDataCellElement), - atom!("template") => make!(HTMLTemplateElement), - atom!("textarea") => make!(HTMLTextAreaElement), + local_name!("spacer") => make!(HTMLUnknownElement), + local_name!("span") => make!(HTMLSpanElement), + local_name!("strike") => make!(HTMLElement), + local_name!("strong") => make!(HTMLElement), + local_name!("style") => make!(HTMLStyleElement), + local_name!("sub") => make!(HTMLElement), + local_name!("summary") => make!(HTMLElement), + local_name!("sup") => make!(HTMLElement), + local_name!("table") => make!(HTMLTableElement), + local_name!("tbody") => make!(HTMLTableSectionElement), + local_name!("td") => make!(HTMLTableDataCellElement), + local_name!("template") => make!(HTMLTemplateElement), + local_name!("textarea") => make!(HTMLTextAreaElement), // https://html.spec.whatwg.org/multipage/#the-tfoot-element:concept-element-dom - atom!("tfoot") => make!(HTMLTableSectionElement), - atom!("th") => make!(HTMLTableHeaderCellElement), + local_name!("tfoot") => make!(HTMLTableSectionElement), + local_name!("th") => make!(HTMLTableHeaderCellElement), // https://html.spec.whatwg.org/multipage/#the-thead-element:concept-element-dom - atom!("thead") => make!(HTMLTableSectionElement), - atom!("time") => make!(HTMLTimeElement), - atom!("title") => make!(HTMLTitleElement), - atom!("tr") => make!(HTMLTableRowElement), - atom!("tt") => make!(HTMLElement), - atom!("track") => make!(HTMLTrackElement), - atom!("u") => make!(HTMLElement), - atom!("ul") => make!(HTMLUListElement), - atom!("var") => make!(HTMLElement), - atom!("video") => make!(HTMLVideoElement), - atom!("wbr") => make!(HTMLElement), - atom!("xmp") => make!(HTMLPreElement), + local_name!("thead") => make!(HTMLTableSectionElement), + local_name!("time") => make!(HTMLTimeElement), + local_name!("title") => make!(HTMLTitleElement), + local_name!("tr") => make!(HTMLTableRowElement), + local_name!("tt") => make!(HTMLElement), + local_name!("track") => make!(HTMLTrackElement), + local_name!("u") => make!(HTMLElement), + local_name!("ul") => make!(HTMLUListElement), + local_name!("var") => make!(HTMLElement), + local_name!("video") => make!(HTMLVideoElement), + local_name!("wbr") => make!(HTMLElement), + local_name!("xmp") => make!(HTMLPreElement), _ => make!(HTMLUnknownElement), } } pub fn create_element(name: QualName, - prefix: Option<Atom>, + prefix: Option<Prefix>, document: &Document, creator: ElementCreator) -> Root<Element> { - // FIXME(ajeffrey): Convert directly from Atom to DOMString. + // FIXME(ajeffrey): Convert directly from Prefix to DOMString. let prefix = prefix.map(|p| DOMString::from(&*p)); diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 37ff6e7a3bf..c7b607b8ae2 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -13,9 +13,9 @@ use dom::element::Element; use dom::node::{Node, NodeDamage, window_from_node}; use dom::window::Window; use parking_lot::RwLock; +use servo_atoms::Atom; use std::ascii::AsciiExt; use std::sync::Arc; -use string_cache::Atom; use style::parser::ParserContextExtraData; use style::properties::{Shorthand, Importance, PropertyDeclarationBlock}; use style::properties::{is_supported_property, parse_one_declaration, parse_style_attribute}; diff --git a/components/script/dom/customevent.rs b/components/script/dom/customevent.rs index d7e026d69bc..a70aa096e43 100644 --- a/components/script/dom/customevent.rs +++ b/components/script/dom/customevent.rs @@ -14,7 +14,7 @@ use dom::event::Event; use dom::globalscope::GlobalScope; use js::jsapi::{HandleValue, JSContext}; use js::jsval::JSVal; -use string_cache::Atom; +use servo_atoms::Atom; // https://dom.spec.whatwg.org/#interface-customevent #[dom_struct] diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 1dd69a26159..86aac32df1b 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -27,7 +27,8 @@ use js::jsapi::{JSAutoCompartment, JSContext}; use js::jsval::UndefinedValue; use js::rust::Runtime; use msg::constellation_msg::PipelineId; -use net_traits::{IpcSend, LoadContext, load_whole_resource}; +use net_traits::{IpcSend, load_whole_resource}; +use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType}; use rand::random; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, StackRootTLS, get_reports, new_rt_and_cx}; use script_runtime::ScriptThreadEventCategory::WorkerEvent; @@ -160,10 +161,24 @@ impl DedicatedWorkerGlobalScope { let roots = RootCollection::new(); let _stack_roots_tls = StackRootTLS::new(&roots); - let (metadata, bytes) = match load_whole_resource(LoadContext::Script, - &init.resource_threads.sender(), - worker_url, - &worker_load_origin) { + + let WorkerScriptLoadOrigin { referrer_url, referrer_policy, pipeline_id } = worker_load_origin; + + let request = RequestInit { + url: worker_url.clone(), + type_: RequestType::Script, + destination: Destination::Worker, + credentials_mode: CredentialsMode::Include, + use_url_credentials: true, + origin: worker_url, + pipeline_id: pipeline_id, + referrer_url: referrer_url, + referrer_policy: referrer_policy, + .. RequestInit::default() + }; + + let (metadata, bytes) = match load_whole_resource(request, + &init.resource_threads.sender()) { Err(_) => { println!("error loading script {}", serialized_worker_url); parent_sender.send(CommonScriptMsg::RunnableMsg(WorkerEvent, diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 1f48f8fea01..5f930f0814d 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -91,13 +91,13 @@ use encoding::EncodingRef; use encoding::all::UTF_8; use euclid::point::Point2D; use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks, QuirksMode}; +use html5ever_atoms::{LocalName, QualName}; use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::{JSContext, JSObject, JSRuntime}; use js::jsapi::JS_GetRuntime; use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; -use msg::constellation_msg::{Key, KeyModifiers, KeyState}; -use msg::constellation_msg::{PipelineId, ReferrerPolicy}; -use net_traits::{FetchResponseMsg, IpcSend}; +use msg::constellation_msg::{FrameId, Key, KeyModifiers, KeyState}; +use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy}; use net_traits::CookieSource::NonHTTP; use net_traits::CoreResourceMsg::{GetCookiesForUrl, SetCookiesForUrl}; use net_traits::request::RequestInit; @@ -110,6 +110,7 @@ use script_traits::{AnimationState, CompositorEvent, MouseButton, MouseEventType use script_traits::{ScriptMsg as ConstellationMsg, TouchpadPressurePhase}; use script_traits::{TouchEventType, TouchId}; use script_traits::UntrustedNodeAddress; +use servo_atoms::Atom; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::boxed::FnBox; @@ -122,7 +123,6 @@ use std::mem; use std::rc::Rc; use std::sync::Arc; use std::time::{Duration, Instant}; -use string_cache::{Atom, QualName}; use style::attr::AttrValue; use style::context::ReflowGoal; use style::selector_impl::ElementSnapshot; @@ -175,7 +175,7 @@ pub struct Document { quirks_mode: Cell<QuirksMode>, /// Caches for the getElement methods id_map: DOMRefCell<HashMap<Atom, Vec<JS<Element>>>>, - tag_map: DOMRefCell<HashMap<Atom, JS<HTMLCollection>>>, + tag_map: DOMRefCell<HashMap<LocalName, JS<HTMLCollection>>>, tagns_map: DOMRefCell<HashMap<QualName, JS<HTMLCollection>>>, classes_map: DOMRefCell<HashMap<Vec<Atom>, JS<HTMLCollection>>>, images: MutNullableHeap<JS<HTMLCollection>>, @@ -288,7 +288,7 @@ struct LinksFilter; impl CollectionFilter for LinksFilter { fn filter(&self, elem: &Element, _root: &Node) -> bool { (elem.is::<HTMLAnchorElement>() || elem.is::<HTMLAreaElement>()) && - elem.has_attribute(&atom!("href")) + elem.has_attribute(&local_name!("href")) } } @@ -312,7 +312,7 @@ impl CollectionFilter for ScriptsFilter { struct AnchorsFilter; impl CollectionFilter for AnchorsFilter { fn filter(&self, elem: &Element, _root: &Node) -> bool { - elem.is::<HTMLAnchorElement>() && elem.has_attribute(&atom!("href")) + elem.is::<HTMLAnchorElement>() && elem.has_attribute(&local_name!("href")) } } @@ -428,7 +428,7 @@ impl Document { let base = self.upcast::<Node>() .traverse_preorder() .filter_map(Root::downcast::<HTMLBaseElement>) - .find(|element| element.upcast::<Element>().has_attribute(&atom!("href"))); + .find(|element| element.upcast::<Element>().has_attribute(&local_name!("href"))); self.base_element.set(base.r()); } @@ -577,7 +577,7 @@ impl Document { fn get_anchor_by_name(&self, name: &str) -> Option<Root<Element>> { let check_anchor = |node: &HTMLAnchorElement| { let elem = node.upcast::<Element>(); - elem.get_attribute(&ns!(), &atom!("name")) + elem.get_attribute(&ns!(), &local_name!("name")) .map_or(false, |attr| &**attr.value() == name) }; let doc_node = self.upcast::<Node>(); @@ -605,7 +605,7 @@ impl Document { self.ready_state.set(state); - self.upcast::<EventTarget>().fire_simple_event("readystatechange"); + self.upcast::<EventTarget>().fire_event(atom!("readystatechange")); } /// Return whether scripting is enabled or not @@ -1322,7 +1322,7 @@ impl Document { } } - pub fn get_body_attribute(&self, local_name: &Atom) -> DOMString { + pub fn get_body_attribute(&self, local_name: &LocalName) -> DOMString { match self.GetBody().and_then(Root::downcast::<HTMLBodyElement>) { Some(ref body) => { body.upcast::<Element>().get_string_attribute(local_name) @@ -1331,7 +1331,7 @@ impl Document { } } - pub fn set_body_attribute(&self, local_name: &Atom, value: DOMString) { + pub fn set_body_attribute(&self, local_name: &LocalName, value: DOMString) { if let Some(ref body) = self.GetBody().and_then(Root::downcast::<HTMLBodyElement>) { let body = body.upcast::<Element>(); let value = body.parse_attribute(&ns!(), &local_name, value); @@ -1399,7 +1399,7 @@ impl Document { if let Some((parent_pipeline_id, _)) = self.window.parent_info() { let global_scope = self.window.upcast::<GlobalScope>(); let event = ConstellationMsg::MozBrowserEvent(parent_pipeline_id, - Some(global_scope.pipeline_id()), + global_scope.pipeline_id(), event); global_scope.constellation_chan().send(event).unwrap(); } @@ -1512,8 +1512,10 @@ impl Document { } } - let loader = self.loader.borrow(); - if !loader.is_blocked() && !loader.events_inhibited() { + if !self.loader.borrow().is_blocked() && !self.loader.borrow().events_inhibited() { + // Schedule a task to fire a "load" event (if no blocking loads have arrived in the mean time) + // NOTE: we can end up executing this code more than once, in case more blocking loads arrive. + debug!("Document loads are complete."); let win = self.window(); let msg = MainThreadScriptMsg::DocumentLoadsComplete( win.upcast::<GlobalScope>().pipeline_id()); @@ -1629,11 +1631,11 @@ impl Document { } /// Find an iframe element in the document. - pub fn find_iframe(&self, pipeline: PipelineId) -> Option<Root<HTMLIFrameElement>> { + pub fn find_iframe(&self, frame_id: FrameId) -> Option<Root<HTMLIFrameElement>> { self.upcast::<Node>() .traverse_preorder() .filter_map(Root::downcast::<HTMLIFrameElement>) - .find(|node| node.pipeline_id() == Some(pipeline)) + .find(|node| node.frame_id() == frame_id) } pub fn get_dom_loading(&self) -> u64 { @@ -2174,18 +2176,13 @@ impl DocumentMethods for Document { } // https://dom.spec.whatwg.org/#dom-document-getelementsbytagname - fn GetElementsByTagName(&self, tag_name: DOMString) -> Root<HTMLCollection> { - let tag_atom = Atom::from(&*tag_name); - match self.tag_map.borrow_mut().entry(tag_atom.clone()) { + fn GetElementsByTagName(&self, qualified_name: DOMString) -> Root<HTMLCollection> { + let qualified_name = LocalName::from(&*qualified_name); + match self.tag_map.borrow_mut().entry(qualified_name.clone()) { Occupied(entry) => Root::from_ref(entry.get()), Vacant(entry) => { - let mut tag_copy = tag_name; - tag_copy.make_ascii_lowercase(); - let ascii_lower_tag = Atom::from(tag_copy); - let result = HTMLCollection::by_atomic_tag_name(&self.window, - self.upcast(), - tag_atom, - ascii_lower_tag); + let result = HTMLCollection::by_qualified_name( + &self.window, self.upcast(), qualified_name); entry.insert(JS::from_ref(&*result)); result } @@ -2198,7 +2195,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 = LocalName::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()), @@ -2241,7 +2238,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), LocalName::from(local_name)); Ok(Element::create(name, None, self, ElementCreator::ScriptCreated)) } @@ -2265,7 +2262,7 @@ impl DocumentMethods for Document { if self.is_html_document { local_name.make_ascii_lowercase(); } - let name = Atom::from(local_name); + let name = LocalName::from(local_name); let value = AttrValue::String("".to_owned()); Ok(Attr::new(&self.window, name.clone(), value, name, ns!(), None, None)) @@ -2279,7 +2276,7 @@ impl DocumentMethods for Document { let (namespace, prefix, local_name) = try!(validate_and_extract(namespace, &qualified_name)); let value = AttrValue::String("".to_owned()); - let qualified_name = Atom::from(qualified_name); + let qualified_name = LocalName::from(qualified_name); Ok(Attr::new(&self.window, local_name, value, @@ -2465,12 +2462,12 @@ impl DocumentMethods for Document { // https://html.spec.whatwg.org/multipage/#document.title fn Title(&self) -> DOMString { let title = self.GetDocumentElement().and_then(|root| { - if root.namespace() == &ns!(svg) && root.local_name() == &atom!("svg") { + if root.namespace() == &ns!(svg) && root.local_name() == &local_name!("svg") { // Step 1. root.upcast::<Node>() .child_elements() .find(|node| { - node.namespace() == &ns!(svg) && node.local_name() == &atom!("title") + node.namespace() == &ns!(svg) && node.local_name() == &local_name!("title") }) .map(Root::upcast::<Node>) } else { @@ -2498,14 +2495,14 @@ impl DocumentMethods for Document { None => return, }; - let elem = if root.namespace() == &ns!(svg) && root.local_name() == &atom!("svg") { + let elem = if root.namespace() == &ns!(svg) && root.local_name() == &local_name!("svg") { let elem = root.upcast::<Node>().child_elements().find(|node| { - node.namespace() == &ns!(svg) && node.local_name() == &atom!("title") + node.namespace() == &ns!(svg) && node.local_name() == &local_name!("title") }); match elem { Some(elem) => Root::upcast::<Node>(elem), None => { - let name = QualName::new(ns!(svg), atom!("title")); + let name = QualName::new(ns!(svg), local_name!("title")); let elem = Element::create(name, None, self, ElementCreator::ScriptCreated); let parent = root.upcast::<Node>(); let child = elem.upcast::<Node>(); @@ -2522,7 +2519,7 @@ impl DocumentMethods for Document { None => { match self.GetHead() { Some(head) => { - let name = QualName::new(ns!(html), atom!("title")); + let name = QualName::new(ns!(html), local_name!("title")); let elem = Element::create(name, None, self, @@ -2617,7 +2614,7 @@ impl DocumentMethods for Document { if element.namespace() != &ns!(html) { return false; } - element.get_attribute(&ns!(), &atom!("name")) + element.get_attribute(&ns!(), &local_name!("name")) .map_or(false, |attr| &**attr.value() == &*name) }) } @@ -2785,22 +2782,22 @@ impl DocumentMethods for Document { // https://html.spec.whatwg.org/multipage/#dom-document-bgcolor fn BgColor(&self) -> DOMString { - self.get_body_attribute(&atom!("bgcolor")) + self.get_body_attribute(&local_name!("bgcolor")) } // https://html.spec.whatwg.org/multipage/#dom-document-bgcolor fn SetBgColor(&self, value: DOMString) { - self.set_body_attribute(&atom!("bgcolor"), value) + self.set_body_attribute(&local_name!("bgcolor"), value) } // https://html.spec.whatwg.org/multipage/#dom-document-fgcolor fn FgColor(&self) -> DOMString { - self.get_body_attribute(&atom!("text")) + self.get_body_attribute(&local_name!("text")) } // https://html.spec.whatwg.org/multipage/#dom-document-fgcolor fn SetFgColor(&self, value: DOMString) { - self.set_body_attribute(&atom!("text"), value) + self.set_body_attribute(&local_name!("text"), value) } #[allow(unsafe_code)] @@ -2827,10 +2824,10 @@ impl DocumentMethods for Document { }; match html_elem_type { HTMLElementTypeId::HTMLAppletElement => { - match elem.get_attribute(&ns!(), &atom!("name")) { + match elem.get_attribute(&ns!(), &local_name!("name")) { Some(ref attr) if attr.value().as_atom() == name => true, _ => { - match elem.get_attribute(&ns!(), &atom!("id")) { + match elem.get_attribute(&ns!(), &local_name!("id")) { Some(ref attr) => attr.value().as_atom() == name, None => false, } @@ -2838,18 +2835,18 @@ impl DocumentMethods for Document { } }, HTMLElementTypeId::HTMLFormElement => { - match elem.get_attribute(&ns!(), &atom!("name")) { + match elem.get_attribute(&ns!(), &local_name!("name")) { Some(ref attr) => attr.value().as_atom() == name, None => false, } }, HTMLElementTypeId::HTMLImageElement => { - match elem.get_attribute(&ns!(), &atom!("name")) { + match elem.get_attribute(&ns!(), &local_name!("name")) { Some(ref attr) => { if attr.value().as_atom() == name { true } else { - match elem.get_attribute(&ns!(), &atom!("id")) { + match elem.get_attribute(&ns!(), &local_name!("id")) { Some(ref attr) => attr.value().as_atom() == name, None => false, } diff --git a/components/script/dom/documentfragment.rs b/components/script/dom/documentfragment.rs index c9692aa4b1c..334e083f1b7 100644 --- a/components/script/dom/documentfragment.rs +++ b/components/script/dom/documentfragment.rs @@ -16,7 +16,7 @@ use dom::globalscope::GlobalScope; use dom::htmlcollection::HTMLCollection; use dom::node::{Node, window_from_node}; use dom::nodelist::NodeList; -use string_cache::Atom; +use servo_atoms::Atom; // https://dom.spec.whatwg.org/#documentfragment #[dom_struct] @@ -57,7 +57,7 @@ impl DocumentFragmentMethods for DocumentFragment { let node = self.upcast::<Node>(); let id = Atom::from(id); node.traverse_preorder().filter_map(Root::downcast::<Element>).find(|descendant| { - match descendant.get_attribute(&ns!(), &atom!("id")) { + match descendant.get_attribute(&ns!(), &local_name!("id")) { None => false, Some(attr) => *attr.value().as_atom() == id, } diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 4c7de14ee91..7556e64d0a7 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -142,14 +142,14 @@ impl DOMImplementationMethods for DOMImplementation { { // Step 4. let doc_node = doc.upcast::<Node>(); - let doc_html = Root::upcast::<Node>(HTMLHtmlElement::new(atom!("html"), + let doc_html = Root::upcast::<Node>(HTMLHtmlElement::new(local_name!("html"), None, &doc)); doc_node.AppendChild(&doc_html).expect("Appending failed"); { // Step 5. - let doc_head = Root::upcast::<Node>(HTMLHeadElement::new(atom!("head"), + let doc_head = Root::upcast::<Node>(HTMLHeadElement::new(local_name!("head"), None, &doc)); doc_html.AppendChild(&doc_head).unwrap(); @@ -160,7 +160,7 @@ impl DOMImplementationMethods for DOMImplementation { Some(title_str) => { // Step 6.1. let doc_title = - Root::upcast::<Node>(HTMLTitleElement::new(atom!("title"), + Root::upcast::<Node>(HTMLTitleElement::new(local_name!("title"), None, &doc)); doc_head.AppendChild(&doc_title).unwrap(); @@ -173,7 +173,7 @@ impl DOMImplementationMethods for DOMImplementation { } // Step 7. - let doc_body = HTMLBodyElement::new(atom!("body"), None, &doc); + let doc_body = HTMLBodyElement::new(local_name!("body"), None, &doc); doc_html.AppendChild(doc_body.upcast()).unwrap(); } diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index bc6c82ac6b2..95f42d12460 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -11,18 +11,19 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::str::DOMString; use dom::element::Element; use dom::node::window_from_node; -use string_cache::Atom; +use html5ever_atoms::LocalName; +use servo_atoms::Atom; use style::str::HTML_SPACE_CHARACTERS; #[dom_struct] pub struct DOMTokenList { reflector_: Reflector, element: JS<Element>, - local_name: Atom, + local_name: LocalName, } impl DOMTokenList { - pub fn new_inherited(element: &Element, local_name: Atom) -> DOMTokenList { + pub fn new_inherited(element: &Element, local_name: LocalName) -> DOMTokenList { DOMTokenList { reflector_: Reflector::new(), element: JS::from_ref(element), @@ -30,7 +31,7 @@ impl DOMTokenList { } } - pub fn new(element: &Element, local_name: &Atom) -> Root<DOMTokenList> { + pub fn new(element: &Element, local_name: &LocalName) -> Root<DOMTokenList> { let window = window_from_node(element); reflect_dom_object(box DOMTokenList::new_inherited(element, local_name.clone()), &*window, diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 28ab35979ba..15a4ef816c8 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -69,10 +69,12 @@ use html5ever::serialize::SerializeOpts; use html5ever::serialize::TraversalScope; use html5ever::serialize::TraversalScope::{ChildrenOnly, IncludeNode}; use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks}; +use html5ever_atoms::{Prefix, LocalName, Namespace, QualName}; use parking_lot::RwLock; use selectors::matching::{ElementFlags, MatchingReason, matches}; use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS}; use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str}; +use servo_atoms::Atom; use std::ascii::AsciiExt; use std::borrow::Cow; use std::cell::{Cell, Ref}; @@ -81,7 +83,6 @@ use std::default::Default; use std::fmt; use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; -use string_cache::{Atom, Namespace, QualName}; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; use style::element_state::*; use style::matching::{common_style_affecting_attributes, rare_style_affecting_attributes}; @@ -102,7 +103,7 @@ use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage}; #[dom_struct] pub struct Element { node: Node, - local_name: Atom, + local_name: LocalName, tag_name: TagName, namespace: Namespace, prefix: Option<DOMString>, @@ -157,20 +158,20 @@ impl<'a> TryFrom<&'a str> for AdjacentPosition { // Element methods // impl Element { - pub fn create(name: QualName, prefix: Option<Atom>, + pub fn create(name: QualName, prefix: Option<Prefix>, document: &Document, creator: ElementCreator) -> Root<Element> { create_element(name, prefix, document, creator) } - pub fn new_inherited(local_name: Atom, + pub fn new_inherited(local_name: LocalName, namespace: Namespace, prefix: Option<DOMString>, document: &Document) -> Element { Element::new_inherited_with_state(ElementState::empty(), local_name, namespace, prefix, document) } - pub fn new_inherited_with_state(state: ElementState, local_name: Atom, + pub fn new_inherited_with_state(state: ElementState, local_name: LocalName, namespace: Namespace, prefix: Option<DOMString>, document: &Document) -> Element { @@ -190,7 +191,7 @@ impl Element { } } - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, namespace: Namespace, prefix: Option<DOMString>, document: &Document) -> Root<Element> { @@ -232,16 +233,16 @@ impl Element { #[allow(unsafe_code)] pub trait RawLayoutElementHelpers { - unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom) + unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &LocalName) -> Option<&'a AttrValue>; - unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom) + unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &LocalName) -> Option<&'a str>; - unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &Atom) -> Vec<&'a str>; + unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &LocalName) -> Vec<&'a str>; } #[inline] #[allow(unsafe_code)] -pub unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, name: &Atom) +pub unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, name: &LocalName) -> Option<LayoutJS<Attr>> { // cast to point to T in RefCell<T> directly let attrs = elem.attrs.borrow_for_layout(); @@ -255,14 +256,14 @@ pub unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, #[allow(unsafe_code)] impl RawLayoutElementHelpers for Element { #[inline] - unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom) + unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &LocalName) -> Option<&'a AttrValue> { get_attr_for_layout(self, namespace, name).map(|attr| { attr.value_forever() }) } - unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom) + unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &LocalName) -> Option<&'a str> { get_attr_for_layout(self, namespace, name).map(|attr| { attr.value_ref_forever() @@ -270,7 +271,7 @@ impl RawLayoutElementHelpers for Element { } #[inline] - unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &Atom) -> Vec<&'a str> { + unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &LocalName) -> Vec<&'a str> { let attrs = self.attrs.borrow_for_layout(); attrs.iter().filter_map(|attr| { let attr = attr.to_layout(); @@ -298,7 +299,7 @@ pub trait LayoutElementHelpers { unsafe fn html_element_in_html_document_for_layout(&self) -> bool; fn id_attribute(&self) -> *const Option<Atom>; fn style_attribute(&self) -> *const Option<Arc<RwLock<PropertyDeclarationBlock>>>; - fn local_name(&self) -> &Atom; + fn local_name(&self) -> &LocalName; fn namespace(&self) -> &Namespace; fn get_checked_state_for_layout(&self) -> bool; fn get_indeterminate_state_for_layout(&self) -> bool; @@ -310,7 +311,7 @@ impl LayoutElementHelpers for LayoutJS<Element> { #[allow(unsafe_code)] #[inline] unsafe fn has_class_for_layout(&self, name: &Atom) -> bool { - get_attr_for_layout(&*self.unsafe_get(), &ns!(), &atom!("class")).map_or(false, |attr| { + get_attr_for_layout(&*self.unsafe_get(), &ns!(), &local_name!("class")).map_or(false, |attr| { attr.value_tokens_forever().unwrap().iter().any(|atom| atom == name) }) } @@ -318,7 +319,7 @@ impl LayoutElementHelpers for LayoutJS<Element> { #[allow(unsafe_code)] #[inline] unsafe fn get_classes_for_layout(&self) -> Option<&'static [Atom]> { - get_attr_for_layout(&*self.unsafe_get(), &ns!(), &atom!("class")) + get_attr_for_layout(&*self.unsafe_get(), &ns!(), &local_name!("class")) .map(|attr| attr.value_tokens_forever().unwrap()) } @@ -327,10 +328,10 @@ impl LayoutElementHelpers for LayoutJS<Element> { where V: Push<ApplicableDeclarationBlock> { #[inline] - fn from_declaration(rule: PropertyDeclaration) -> ApplicableDeclarationBlock { + fn from_declaration(declaration: PropertyDeclaration) -> ApplicableDeclarationBlock { ApplicableDeclarationBlock::from_declarations( Arc::new(RwLock::new(PropertyDeclarationBlock { - declarations: vec![(rule, Importance::Normal)], + declarations: vec![(declaration, Importance::Normal)], important_count: 0, })), Importance::Normal) @@ -440,7 +441,7 @@ impl LayoutElementHelpers for LayoutJS<Element> { let size = if let Some(this) = self.downcast::<HTMLInputElement>() { // FIXME(pcwalton): More use of atoms, please! - match (*self.unsafe_get()).get_attr_val_for_layout(&ns!(), &atom!("type")) { + match (*self.unsafe_get()).get_attr_val_for_layout(&ns!(), &local_name!("type")) { // Not text entry widget Some("hidden") | Some("date") | Some("month") | Some("week") | Some("time") | Some("datetime-local") | Some("number") | Some("range") | @@ -622,7 +623,7 @@ impl LayoutElementHelpers for LayoutJS<Element> { } #[allow(unsafe_code)] - fn local_name(&self) -> &Atom { + fn local_name(&self) -> &LocalName { unsafe { &(*self.unsafe_get()).local_name } @@ -681,15 +682,15 @@ impl Element { self.namespace == ns!(html) && self.upcast::<Node>().is_in_html_doc() } - pub fn local_name(&self) -> &Atom { + pub fn local_name(&self) -> &LocalName { &self.local_name } - pub fn parsed_name(&self, mut name: DOMString) -> Atom { + pub fn parsed_name(&self, mut name: DOMString) -> LocalName { if self.html_element_in_html_document() { name.make_ascii_lowercase(); } - Atom::from(name) + LocalName::from(name) } pub fn namespace(&self) -> &Namespace { @@ -722,10 +723,14 @@ impl Element { /* List of void elements from https://html.spec.whatwg.org/multipage/#html-fragment-serialisation-algorithm */ - atom!("area") | atom!("base") | atom!("basefont") | atom!("bgsound") | atom!("br") | - atom!("col") | atom!("embed") | atom!("frame") | atom!("hr") | atom!("img") | - atom!("input") | atom!("keygen") | atom!("link") | atom!("menuitem") | atom!("meta") | - atom!("param") | atom!("source") | atom!("track") | atom!("wbr") => true, + local_name!("area") | local_name!("base") | local_name!("basefont") | + local_name!("bgsound") | local_name!("br") | + local_name!("col") | local_name!("embed") | local_name!("frame") | + local_name!("hr") | local_name!("img") | + local_name!("input") | local_name!("keygen") | local_name!("link") | + local_name!("menuitem") | local_name!("meta") | + local_name!("param") | local_name!("source") | local_name!("track") | + local_name!("wbr") => true, _ => false } } @@ -735,7 +740,7 @@ impl Element { pub fn set_style_attr(&self, new_value: String) { let mut new_style = AttrValue::String(new_value); - if let Some(style_attr) = self.attrs.borrow().iter().find(|a| a.name() == &atom!("style")) { + if let Some(style_attr) = self.attrs.borrow().iter().find(|a| a.name() == &local_name!("style")) { style_attr.swap_value(&mut new_style); return; } @@ -744,11 +749,11 @@ impl Element { // in order to avoid triggering mutation events let window = window_from_node(self); let attr = Attr::new(&window, - atom!("style"), + local_name!("style"), new_style, - atom!("style"), + local_name!("style"), ns!(), - Some(atom!("style")), + None, Some(self)); assert!(attr.GetOwnerElement().r() == Some(self)); @@ -798,8 +803,8 @@ impl Element { // Step 2. for attr in element.attrs.borrow().iter() { - if *attr.prefix() == Some(atom!("xmlns")) && - **attr.value() == *namespace.0 { + if *attr.prefix() == Some(namespace_prefix!("xmlns")) && + **attr.value() == *namespace { return Some(attr.LocalName()); } } @@ -809,10 +814,7 @@ impl Element { } None } -} - -impl Element { pub fn is_focusable_area(&self) -> bool { if self.is_actually_disabled() { return false; @@ -851,16 +853,13 @@ impl Element { _ => false, } } -} - -impl Element { pub fn push_new_attribute(&self, - local_name: Atom, + local_name: LocalName, value: AttrValue, - name: Atom, + name: LocalName, namespace: Namespace, - prefix: Option<Atom>) { + prefix: Option<Prefix>) { let window = window_from_node(self); let attr = Attr::new(&window, local_name, @@ -881,7 +880,7 @@ impl Element { } } - pub fn get_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> { + pub fn get_attribute(&self, namespace: &Namespace, local_name: &LocalName) -> Option<Root<Attr>> { self.attrs .borrow() .iter() @@ -898,7 +897,7 @@ impl Element { pub fn set_attribute_from_parser(&self, qname: QualName, value: DOMString, - prefix: Option<Atom>) { + prefix: Option<Prefix>) { // Don't set if the attribute already exists, so we can handle add_attrs_if_missing if self.attrs .borrow() @@ -911,14 +910,14 @@ impl Element { None => qname.local.clone(), Some(ref prefix) => { let name = format!("{}:{}", &**prefix, &*qname.local); - Atom::from(name) + LocalName::from(name) }, }; let value = self.parse_attribute(&qname.ns, &qname.local, value); self.push_new_attribute(qname.local, value, name, qname.ns, prefix); } - pub fn set_attribute(&self, name: &Atom, value: AttrValue) { + pub fn set_attribute(&self, name: &LocalName, value: AttrValue) { assert!(name == &name.to_ascii_lowercase()); assert!(!name.contains(":")); @@ -938,7 +937,7 @@ impl Element { } // Steps 2-5. - let name = Atom::from(name); + let name = LocalName::from(name); let value = self.parse_attribute(&ns!(), &name, value); self.set_first_matching_attribute(name.clone(), value, @@ -952,11 +951,11 @@ impl Element { } fn set_first_matching_attribute<F>(&self, - local_name: Atom, + local_name: LocalName, value: AttrValue, - name: Atom, + name: LocalName, namespace: Namespace, - prefix: Option<Atom>, + prefix: Option<Prefix>, find: F) where F: Fn(&Attr) -> bool { @@ -974,7 +973,7 @@ impl Element { pub fn parse_attribute(&self, namespace: &Namespace, - local_name: &Atom, + local_name: &LocalName, value: DOMString) -> AttrValue { if *namespace == ns!() { @@ -984,13 +983,13 @@ impl Element { } } - pub fn remove_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> { + pub fn remove_attribute(&self, namespace: &Namespace, local_name: &LocalName) -> Option<Root<Attr>> { self.remove_first_matching_attribute(|attr| { attr.namespace() == namespace && attr.local_name() == local_name }) } - pub fn remove_attribute_by_name(&self, name: &Atom) -> Option<Root<Attr>> { + pub fn remove_attribute_by_name(&self, name: &LocalName) -> Option<Root<Attr>> { self.remove_first_matching_attribute(|attr| attr.name() == name) } @@ -1019,17 +1018,17 @@ impl Element { Quirks => lhs.eq_ignore_ascii_case(&rhs), } }; - self.get_attribute(&ns!(), &atom!("class")) + self.get_attribute(&ns!(), &local_name!("class")) .map_or(false, |attr| attr.value().as_tokens().iter().any(|atom| is_equal(name, atom))) } - pub fn set_atomic_attribute(&self, local_name: &Atom, value: DOMString) { + pub fn set_atomic_attribute(&self, local_name: &LocalName, value: DOMString) { assert!(*local_name == local_name.to_ascii_lowercase()); let value = AttrValue::from_atomic(value.into()); self.set_attribute(local_name, value); } - pub fn has_attribute(&self, local_name: &Atom) -> bool { + pub fn has_attribute(&self, local_name: &LocalName) -> bool { assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b)); self.attrs .borrow() @@ -1037,7 +1036,7 @@ impl Element { .any(|attr| attr.local_name() == local_name && attr.namespace() == &ns!()) } - pub fn set_bool_attribute(&self, local_name: &Atom, value: bool) { + pub fn set_bool_attribute(&self, local_name: &LocalName, value: bool) { if self.has_attribute(local_name) == value { return; } @@ -1048,7 +1047,7 @@ impl Element { } } - pub fn get_url_attribute(&self, local_name: &Atom) -> DOMString { + pub fn get_url_attribute(&self, local_name: &LocalName) -> DOMString { assert!(*local_name == local_name.to_ascii_lowercase()); if !self.has_attribute(local_name) { return DOMString::new(); @@ -1063,22 +1062,22 @@ impl Element { Err(_) => DOMString::from(""), } } - pub fn set_url_attribute(&self, local_name: &Atom, value: DOMString) { + pub fn set_url_attribute(&self, local_name: &LocalName, value: DOMString) { self.set_string_attribute(local_name, value); } - pub fn get_string_attribute(&self, local_name: &Atom) -> DOMString { + pub fn get_string_attribute(&self, local_name: &LocalName) -> DOMString { match self.get_attribute(&ns!(), local_name) { Some(x) => x.Value(), None => DOMString::new(), } } - pub fn set_string_attribute(&self, local_name: &Atom, value: DOMString) { + pub fn set_string_attribute(&self, local_name: &LocalName, value: DOMString) { assert!(*local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::String(value.into())); } - pub fn get_tokenlist_attribute(&self, local_name: &Atom) -> Vec<Atom> { + pub fn get_tokenlist_attribute(&self, local_name: &LocalName) -> Vec<Atom> { self.get_attribute(&ns!(), local_name).map(|attr| { attr.value() .as_tokens() @@ -1086,18 +1085,18 @@ impl Element { }).unwrap_or(vec!()) } - pub fn set_tokenlist_attribute(&self, local_name: &Atom, value: DOMString) { + pub fn set_tokenlist_attribute(&self, local_name: &LocalName, value: DOMString) { assert!(*local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::from_serialized_tokenlist(value.into())); } - pub fn set_atomic_tokenlist_attribute(&self, local_name: &Atom, tokens: Vec<Atom>) { + pub fn set_atomic_tokenlist_attribute(&self, local_name: &LocalName, tokens: Vec<Atom>) { assert!(*local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::from_atomic_tokens(tokens)); } - pub fn get_int_attribute(&self, local_name: &Atom, default: i32) -> i32 { + pub fn get_int_attribute(&self, local_name: &LocalName, default: i32) -> i32 { // TODO: Is this assert necessary? assert!(local_name.chars().all(|ch| { !ch.is_ascii() || ch.to_ascii_lowercase() == ch @@ -1116,12 +1115,12 @@ impl Element { } } - pub fn set_int_attribute(&self, local_name: &Atom, value: i32) { + pub fn set_int_attribute(&self, local_name: &LocalName, value: i32) { assert!(*local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::Int(value.to_string(), value)); } - pub fn get_uint_attribute(&self, local_name: &Atom, default: u32) -> u32 { + pub fn get_uint_attribute(&self, local_name: &LocalName, default: u32) -> u32 { assert!(local_name.chars().all(|ch| !ch.is_ascii() || ch.to_ascii_lowercase() == ch)); let attribute = self.get_attribute(&ns!(), local_name); match attribute { @@ -1134,7 +1133,7 @@ impl Element { None => default, } } - pub fn set_uint_attribute(&self, local_name: &Atom, value: u32) { + pub fn set_uint_attribute(&self, local_name: &LocalName, value: u32) { assert!(*local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value)); } @@ -1226,7 +1225,7 @@ impl ElementMethods for Element { // https://dom.spec.whatwg.org/#dom-element-localname fn LocalName(&self) -> DOMString { - // FIXME(ajeffrey): Convert directly from Atom to DOMString + // FIXME(ajeffrey): Convert directly from LocalName to DOMString DOMString::from(&*self.local_name) } @@ -1245,9 +1244,9 @@ impl ElementMethods for Element { None => Cow::Borrowed(&*self.local_name) }; if self.html_element_in_html_document() { - Atom::from(qualified_name.to_ascii_uppercase()) + LocalName::from(qualified_name.to_ascii_uppercase()) } else { - Atom::from(qualified_name) + LocalName::from(qualified_name) } }); DOMString::from(&*name) @@ -1255,27 +1254,27 @@ impl ElementMethods for Element { // https://dom.spec.whatwg.org/#dom-element-id fn Id(&self) -> DOMString { - self.get_string_attribute(&atom!("id")) + self.get_string_attribute(&local_name!("id")) } // https://dom.spec.whatwg.org/#dom-element-id fn SetId(&self, id: DOMString) { - self.set_atomic_attribute(&atom!("id"), id); + self.set_atomic_attribute(&local_name!("id"), id); } // https://dom.spec.whatwg.org/#dom-element-classname fn ClassName(&self) -> DOMString { - self.get_string_attribute(&atom!("class")) + self.get_string_attribute(&local_name!("class")) } // https://dom.spec.whatwg.org/#dom-element-classname fn SetClassName(&self, class: DOMString) { - self.set_tokenlist_attribute(&atom!("class"), class); + self.set_tokenlist_attribute(&local_name!("class"), class); } // https://dom.spec.whatwg.org/#dom-element-classlist fn ClassList(&self) -> Root<DOMTokenList> { - self.class_list.or_init(|| DOMTokenList::new(self, &atom!("class"))) + self.class_list.or_init(|| DOMTokenList::new(self, &local_name!("class"))) } // https://dom.spec.whatwg.org/#dom-element-attributes @@ -1319,7 +1318,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, &LocalName::from(local_name)) } // https://dom.spec.whatwg.org/#dom-element-setattribute @@ -1347,7 +1346,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 = LocalName::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, @@ -1413,7 +1412,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 = LocalName::from(local_name); self.remove_attribute(&namespace, &local_name); } @@ -1436,7 +1435,7 @@ impl ElementMethods for Element { // https://dom.spec.whatwg.org/#dom-element-getelementsbytagname fn GetElementsByTagName(&self, localname: DOMString) -> Root<HTMLCollection> { let window = window_from_node(self); - HTMLCollection::by_tag_name(&window, self.upcast(), localname) + HTMLCollection::by_qualified_name(&window, self.upcast(), LocalName::from(&*localname)) } // https://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens @@ -1781,7 +1780,7 @@ impl ElementMethods for Element { // Step 4. NodeTypeId::DocumentFragment => { - let body_elem = Element::create(QualName::new(ns!(html), atom!("body")), + let body_elem = Element::create(QualName::new(ns!(html), local_name!("body")), None, &context_document, ElementCreator::ScriptCreated); Root::upcast(body_elem) @@ -1944,9 +1943,9 @@ impl ElementMethods for Element { // Step 2. let context = match context.downcast::<Element>() { - Some(elem) if elem.local_name() != &atom!("html") || + Some(elem) if elem.local_name() != &local_name!("html") || !elem.html_element_in_html_document() => Root::from_ref(elem), - _ => Root::upcast(HTMLBodyElement::new(atom!("body"), None, &*context.owner_doc())), + _ => Root::upcast(HTMLBodyElement::new(local_name!("body"), None, &*context.owner_doc())), }; // Step 3. @@ -1978,8 +1977,8 @@ impl ElementMethods for Element { } } -pub fn fragment_affecting_attributes() -> [Atom; 3] { - [atom!("width"), atom!("height"), atom!("src")] +pub fn fragment_affecting_attributes() -> [LocalName; 3] { + [local_name!("width"), local_name!("height"), local_name!("src")] } impl VirtualMethods for Element { @@ -1992,7 +1991,7 @@ impl VirtualMethods for Element { let node = self.upcast::<Node>(); let doc = node.owner_doc(); match attr.local_name() { - &atom!("style") => { + &local_name!("style") => { // Modifying the `style` attribute might change style. *self.style_attribute.borrow_mut() = mutation.new_value(attr).map(|value| { @@ -2007,7 +2006,7 @@ impl VirtualMethods for Element { node.dirty(NodeDamage::NodeStyleDamaged); } }, - &atom!("id") => { + &local_name!("id") => { *self.id_attribute.borrow_mut() = mutation.new_value(attr).and_then(|value| { let value = value.as_atom(); @@ -2039,7 +2038,7 @@ impl VirtualMethods for Element { }, _ if attr.namespace() == &ns!() => { if fragment_affecting_attributes().iter().any(|a| a == attr.local_name()) || - common_style_affecting_attributes().iter().any(|a| &a.atom == attr.local_name()) || + common_style_affecting_attributes().iter().any(|a| &a.attr_name == attr.local_name()) || rare_style_affecting_attributes().iter().any(|a| a == attr.local_name()) { node.dirty(NodeDamage::OtherNodeDamage); @@ -2054,10 +2053,10 @@ impl VirtualMethods for Element { node.rev_version(); } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("id") => AttrValue::from_atomic(value.into()), - &atom!("class") => AttrValue::from_serialized_tokenlist(value.into()), + &local_name!("id") => AttrValue::from_atomic(value.into()), + &local_name!("class") => AttrValue::from_serialized_tokenlist(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } @@ -2191,7 +2190,7 @@ impl<'a> ::selectors::Element for Root<Element> { }) } - fn get_local_name(&self) -> &Atom { + fn get_local_name(&self) -> &LocalName { self.local_name() } @@ -2246,7 +2245,7 @@ impl<'a> ::selectors::Element for Root<Element> { fn each_class<F>(&self, mut callback: F) where F: FnMut(&Atom) { - if let Some(ref attr) = self.get_attribute(&ns!(), &atom!("class")) { + if let Some(ref attr) = self.get_attribute(&ns!(), &local_name!("class")) { let tokens = attr.value(); let tokens = tokens.as_tokens(); for token in tokens { @@ -2357,7 +2356,7 @@ impl Element { NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => { - self.has_attribute(&atom!("href")) + self.has_attribute(&local_name!("href")) }, _ => false, } @@ -2551,7 +2550,7 @@ impl Element { } pub fn check_disabled_attribute(&self) { - let has_disabled_attrib = self.has_attribute(&atom!("disabled")); + let has_disabled_attrib = self.has_attribute(&local_name!("disabled")); self.set_disabled_state(has_disabled_attrib); self.set_enabled_state(!has_disabled_attrib); } @@ -2600,7 +2599,7 @@ impl AtomicElementFlags { /// owner changes. #[derive(JSTraceable, HeapSizeOf)] struct TagName { - ptr: DOMRefCell<Option<Atom>>, + ptr: DOMRefCell<Option<LocalName>>, } impl TagName { @@ -2610,8 +2609,8 @@ impl TagName { /// Retrieve a copy of the current inner value. If it is `None`, it is /// initialized with the result of `cb` first. - fn or_init<F>(&self, cb: F) -> Atom - where F: FnOnce() -> Atom + fn or_init<F>(&self, cb: F) -> LocalName + where F: FnOnce() -> LocalName { match &mut *self.ptr.borrow_mut() { &mut Some(ref name) => name.clone(), diff --git a/components/script/dom/errorevent.rs b/components/script/dom/errorevent.rs index edf1118b58c..65f3be9e32b 100644 --- a/components/script/dom/errorevent.rs +++ b/components/script/dom/errorevent.rs @@ -15,8 +15,8 @@ use dom::event::{Event, EventBubbles, EventCancelable}; use dom::globalscope::GlobalScope; use js::jsapi::{HandleValue, JSContext}; use js::jsval::JSVal; +use servo_atoms::Atom; use std::cell::Cell; -use string_cache::Atom; #[dom_struct] pub struct ErrorEvent { diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index cdbfdafec2e..d67d1f64e78 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -14,9 +14,9 @@ use dom::eventdispatcher::EventStatus; use dom::eventtarget::EventTarget; use dom::globalscope::GlobalScope; use script_thread::Runnable; +use servo_atoms::Atom; use std::cell::Cell; use std::default::Default; -use string_cache::Atom; use time; #[derive(JSTraceable, Copy, Clone, Debug, PartialEq, Eq)] @@ -330,7 +330,9 @@ impl Runnable for EventRunnable { fn handler(self: Box<EventRunnable>) { let target = self.target.root(); - target.fire_event(&*self.name, self.bubbles, self.cancelable); + let bubbles = self.bubbles; + let cancelable = self.cancelable; + target.fire_event_with_params(self.name, bubbles, cancelable); } } @@ -345,6 +347,6 @@ impl Runnable for SimpleEventRunnable { fn handler(self: Box<SimpleEventRunnable>) { let target = self.target.root(); - target.fire_simple_event(&*self.name); + target.fire_event(self.name); } } diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index a17bac4a35c..48ba920ad60 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -32,6 +32,7 @@ use heapsize::HeapSizeOf; use js::jsapi::{CompileFunction, JS_GetFunctionObject, JSAutoCompartment}; use js::rust::{AutoObjectVectorWrapper, CompileOptionsWrapper}; use libc::{c_char, size_t}; +use servo_atoms::Atom; use std::collections::HashMap; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::default::Default; @@ -41,7 +42,6 @@ use std::mem; use std::ops::{Deref, DerefMut}; use std::ptr; use std::rc::Rc; -use string_cache::Atom; use url::Url; #[derive(PartialEq, Clone, JSTraceable)] @@ -490,21 +490,42 @@ impl EventTarget { !self.handlers.borrow().is_empty() } - // https://html.spec.whatwg.org/multipage/#fire-a-simple-event - pub fn fire_simple_event(&self, name: &str) -> Root<Event> { - self.fire_event(name, EventBubbles::DoesNotBubble, - EventCancelable::NotCancelable) + // https://dom.spec.whatwg.org/#concept-event-fire + pub fn fire_event(&self, name: Atom) -> Root<Event> { + self.fire_event_with_params(name, + EventBubbles::DoesNotBubble, + EventCancelable::NotCancelable) } // https://dom.spec.whatwg.org/#concept-event-fire - pub fn fire_event(&self, name: &str, - bubbles: EventBubbles, - cancelable: EventCancelable) - -> Root<Event> { - let event = Event::new(&self.global(), Atom::from(name), bubbles, cancelable); + pub fn fire_bubbling_event(&self, name: Atom) -> Root<Event> { + self.fire_event_with_params(name, + EventBubbles::Bubbles, + EventCancelable::NotCancelable) + } - event.fire(self); + // https://dom.spec.whatwg.org/#concept-event-fire + pub fn fire_cancelable_event(&self, name: Atom) -> Root<Event> { + self.fire_event_with_params(name, + EventBubbles::DoesNotBubble, + EventCancelable::Cancelable) + } + // https://dom.spec.whatwg.org/#concept-event-fire + pub fn fire_bubbling_cancelable_event(&self, name: Atom) -> Root<Event> { + self.fire_event_with_params(name, + EventBubbles::Bubbles, + EventCancelable::Cancelable) + } + + // https://dom.spec.whatwg.org/#concept-event-fire + pub fn fire_event_with_params(&self, + name: Atom, + bubbles: EventBubbles, + cancelable: EventCancelable) + -> Root<Event> { + let event = Event::new(&self.global(), name, bubbles, cancelable); + event.fire(self); event } } diff --git a/components/script/dom/extendableevent.rs b/components/script/dom/extendableevent.rs index d859d8f4724..55e9500a8e4 100644 --- a/components/script/dom/extendableevent.rs +++ b/components/script/dom/extendableevent.rs @@ -12,7 +12,7 @@ use dom::bindings::str::DOMString; use dom::event::Event; use dom::globalscope::GlobalScope; use js::jsapi::{HandleValue, JSContext}; -use string_cache::Atom; +use servo_atoms::Atom; // https://w3c.github.io/ServiceWorker/#extendable-event #[dom_struct] diff --git a/components/script/dom/extendablemessageevent.rs b/components/script/dom/extendablemessageevent.rs index 0a5968d1d99..b3f3a5318f7 100644 --- a/components/script/dom/extendablemessageevent.rs +++ b/components/script/dom/extendablemessageevent.rs @@ -15,8 +15,8 @@ use dom::extendableevent::ExtendableEvent; use dom::globalscope::GlobalScope; use js::jsapi::{HandleValue, Heap, JSContext}; use js::jsval::JSVal; +use servo_atoms::Atom; use std::default::Default; -use string_cache::Atom; #[dom_struct] pub struct ExtendableMessageEvent { diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index d9fd00630de..2594b196918 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -30,10 +30,10 @@ use js::jsval::{self, JSVal}; use js::typedarray::Uint8Array; use rustc_serialize::base64::{CharacterSet, Config, Newline, ToBase64}; use script_thread::RunnableWrapper; +use servo_atoms::Atom; use std::cell::Cell; use std::ptr; use std::sync::Arc; -use string_cache::Atom; use task_source::TaskSource; use task_source::file_reading::{FileReadingTaskSource, FileReadingRunnable, FileReadingTask}; use util::thread::spawn_named; @@ -274,7 +274,7 @@ impl FileReader { *result.borrow_mut() = Some(FileReaderResult::ArrayBuffer(Heap::default())); if let Some(FileReaderResult::ArrayBuffer(ref mut heap)) = *result.borrow_mut() { - heap.set(jsval::ObjectValue(&*array_buffer.get())); + heap.set(jsval::ObjectValue(array_buffer.get())); }; } } diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index 2c8f99b424b..a971bb48f21 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -15,24 +15,24 @@ use dom::blob::{Blob, BlobImpl}; use dom::file::File; use dom::globalscope::GlobalScope; use dom::htmlformelement::{HTMLFormElement, FormDatumValue, FormDatum}; +use html5ever_atoms::LocalName; use std::collections::HashMap; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::iter; -use string_cache::Atom; #[dom_struct] pub struct FormData { reflector_: Reflector, - data: DOMRefCell<HashMap<Atom, Vec<FormDatum>>>, + data: DOMRefCell<HashMap<LocalName, Vec<FormDatum>>>, } impl FormData { fn new_inherited(opt_form: Option<&HTMLFormElement>) -> FormData { - let mut hashmap: HashMap<Atom, Vec<FormDatum>> = HashMap::new(); + let mut hashmap: HashMap<LocalName, Vec<FormDatum>> = HashMap::new(); if let Some(form) = opt_form { for datum in form.get_form_dataset(None) { - match hashmap.entry(Atom::from(datum.name.as_ref())) { + match hashmap.entry(LocalName::from(datum.name.as_ref())) { Occupied(entry) => entry.into_mut().push(datum), Vacant(entry) => { entry.insert(vec!(datum)); } } @@ -66,7 +66,7 @@ impl FormDataMethods for FormData { }; let mut data = self.data.borrow_mut(); - match data.entry(Atom::from(name.0)) { + match data.entry(LocalName::from(name.0)) { Occupied(entry) => entry.into_mut().push(datum), Vacant(entry) => { entry.insert(vec!(datum)); } } @@ -83,7 +83,7 @@ impl FormDataMethods for FormData { let mut data = self.data.borrow_mut(); - match data.entry(Atom::from(name.0)) { + match data.entry(LocalName::from(name.0)) { Occupied(entry) => entry.into_mut().push(datum), Vacant(entry) => { entry.insert(vec!(datum)); }, } @@ -91,13 +91,13 @@ impl FormDataMethods for FormData { // https://xhr.spec.whatwg.org/#dom-formdata-delete fn Delete(&self, name: USVString) { - self.data.borrow_mut().remove(&Atom::from(name.0)); + self.data.borrow_mut().remove(&LocalName::from(name.0)); } // https://xhr.spec.whatwg.org/#dom-formdata-get fn Get(&self, name: USVString) -> Option<FileOrUSVString> { self.data.borrow() - .get(&Atom::from(name.0)) + .get(&LocalName::from(name.0)) .map(|entry| match entry[0].value { FormDatumValue::String(ref s) => FileOrUSVString::USVString(USVString(s.to_string())), FormDatumValue::File(ref b) => FileOrUSVString::File(Root::from_ref(&*b)), @@ -107,7 +107,7 @@ impl FormDataMethods for FormData { // https://xhr.spec.whatwg.org/#dom-formdata-getall fn GetAll(&self, name: USVString) -> Vec<FileOrUSVString> { self.data.borrow() - .get(&Atom::from(name.0)) + .get(&LocalName::from(name.0)) .map_or(vec![], |data| data.iter().map(|item| match item.value { FormDatumValue::String(ref s) => FileOrUSVString::USVString(USVString(s.to_string())), @@ -118,12 +118,12 @@ impl FormDataMethods for FormData { // https://xhr.spec.whatwg.org/#dom-formdata-has fn Has(&self, name: USVString) -> bool { - self.data.borrow().contains_key(&Atom::from(name.0)) + self.data.borrow().contains_key(&LocalName::from(name.0)) } // https://xhr.spec.whatwg.org/#dom-formdata-set fn Set(&self, name: USVString, str_value: USVString) { - self.data.borrow_mut().insert(Atom::from(name.0.clone()), vec![FormDatum { + self.data.borrow_mut().insert(LocalName::from(name.0.clone()), vec![FormDatum { ty: DOMString::from("string"), name: DOMString::from(name.0), value: FormDatumValue::String(DOMString::from(str_value.0)), @@ -133,7 +133,7 @@ impl FormDataMethods for FormData { #[allow(unrooted_must_root)] // https://xhr.spec.whatwg.org/#dom-formdata-set fn Set_(&self, name: USVString, blob: &Blob, filename: Option<USVString>) { - self.data.borrow_mut().insert(Atom::from(name.0.clone()), vec![FormDatum { + self.data.borrow_mut().insert(LocalName::from(name.0.clone()), vec![FormDatum { ty: DOMString::from("file"), name: DOMString::from(name.0), value: FormDatumValue::File(Root::from_ref(&*self.get_file(blob, filename))), diff --git a/components/script/dom/hashchangeevent.rs b/components/script/dom/hashchangeevent.rs index 0fd753c433c..b93b7a93631 100644 --- a/components/script/dom/hashchangeevent.rs +++ b/components/script/dom/hashchangeevent.rs @@ -12,7 +12,7 @@ use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::{DOMString, USVString}; use dom::event::Event; use dom::globalscope::GlobalScope; -use string_cache::Atom; +use servo_atoms::Atom; // https://html.spec.whatwg.org/multipage/#hashchangeevent #[dom_struct] diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index 2ed6d4fe5e5..7683fc02330 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -24,11 +24,11 @@ use dom::mouseevent::MouseEvent; use dom::node::{Node, document_from_node, window_from_node}; use dom::urlhelper::UrlHelper; use dom::virtualmethods::VirtualMethods; -use msg::constellation_msg::ReferrerPolicy; +use html5ever_atoms::LocalName; +use net_traits::ReferrerPolicy; use num_traits::ToPrimitive; use script_traits::MozBrowserEvent; use std::default::Default; -use string_cache::Atom; use style::attr::AttrValue; use url::Url; use util::prefs::PREFS; @@ -41,7 +41,7 @@ pub struct HTMLAnchorElement { } impl HTMLAnchorElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLAnchorElement { HTMLAnchorElement { @@ -53,7 +53,7 @@ impl HTMLAnchorElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLAnchorElement> { Node::reflect_node(box HTMLAnchorElement::new_inherited(local_name, prefix, document), @@ -63,7 +63,7 @@ impl HTMLAnchorElement { // https://html.spec.whatwg.org/multipage/#concept-hyperlink-url-set fn set_url(&self) { - let attribute = self.upcast::<Element>().get_attribute(&ns!(), &atom!("href")); + let attribute = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href")); *self.url.borrow_mut() = attribute.and_then(|attribute| { let document = document_from_node(self); document.base_url().join(&attribute.value()).ok() @@ -84,7 +84,7 @@ impl HTMLAnchorElement { // https://html.spec.whatwg.org/multipage/#update-href fn update_href(&self, url: DOMString) { - self.upcast::<Element>().set_string_attribute(&atom!("href"), url); + self.upcast::<Element>().set_string_attribute(&local_name!("href"), url); } } @@ -93,9 +93,9 @@ impl VirtualMethods for HTMLAnchorElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("rel") => AttrValue::from_serialized_tokenlist(value.into()), + &local_name!("rel") => AttrValue::from_serialized_tokenlist(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } @@ -115,7 +115,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement { // https://html.spec.whatwg.org/multipage/#dom-a-rellist fn RelList(&self) -> Root<DOMTokenList> { self.rel_list.or_init(|| { - DOMTokenList::new(self.upcast(), &atom!("rel")) + DOMTokenList::new(self.upcast(), &local_name!("rel")) }) } @@ -265,7 +265,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement { USVString(match *self.url.borrow() { None => { - match self.upcast::<Element>().get_attribute(&ns!(), &atom!("href")) { + match self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href")) { // Step 3. None => String::new(), // Step 4. @@ -279,7 +279,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement { // https://html.spec.whatwg.org/multipage/#dom-hyperlink-href fn SetHref(&self, value: USVString) { - self.upcast::<Element>().set_string_attribute(&atom!("href"), + self.upcast::<Element>().set_string_attribute(&local_name!("href"), DOMString::from_string(value.0)); self.set_url(); } @@ -499,7 +499,7 @@ impl Activatable for HTMLAnchorElement { // hyperlink" // https://html.spec.whatwg.org/multipage/#the-a-element // "The activation behaviour of a elements *that create hyperlinks*" - self.upcast::<Element>().has_attribute(&atom!("href")) + self.upcast::<Element>().has_attribute(&local_name!("href")) } @@ -525,7 +525,7 @@ impl Activatable for HTMLAnchorElement { let mouse_event = event.downcast::<MouseEvent>().unwrap(); let mut ismap_suffix = None; if let Some(element) = target.downcast::<Element>() { - if target.is::<HTMLImageElement>() && element.has_attribute(&atom!("ismap")) { + if target.is::<HTMLImageElement>() && element.has_attribute(&local_name!("ismap")) { let target_node = element.upcast::<Node>(); let rect = window_from_node(target_node).content_box_query( target_node.to_trusted_node_address()); @@ -563,10 +563,10 @@ fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<String>, referre // Step 1: replace. // Step 2: source browsing context. // Step 3: target browsing context. - let target = subject.get_attribute(&ns!(), &atom!("target")); + let target = subject.get_attribute(&ns!(), &local_name!("target")); // Step 4: disown target's opener if needed. - let attribute = subject.get_attribute(&ns!(), &atom!("href")).unwrap(); + let attribute = subject.get_attribute(&ns!(), &local_name!("href")).unwrap(); let mut href = attribute.Value(); // Step 7: append a hyperlink suffix. diff --git a/components/script/dom/htmlappletelement.rs b/components/script/dom/htmlappletelement.rs index dfc43386492..081172031a3 100644 --- a/components/script/dom/htmlappletelement.rs +++ b/components/script/dom/htmlappletelement.rs @@ -11,7 +11,7 @@ use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::attr::AttrValue; #[dom_struct] @@ -20,7 +20,7 @@ pub struct HTMLAppletElement { } impl HTMLAppletElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLAppletElement { HTMLAppletElement { @@ -30,7 +30,7 @@ impl HTMLAppletElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLAppletElement> { Node::reflect_node(box HTMLAppletElement::new_inherited(local_name, prefix, document), @@ -52,9 +52,9 @@ impl VirtualMethods for HTMLAppletElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("name") => AttrValue::from_atomic(value.into()), + &local_name!("name") => AttrValue::from_atomic(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs index 6ba229640fd..b8df3806a3f 100644 --- a/components/script/dom/htmlareaelement.rs +++ b/components/script/dom/htmlareaelement.rs @@ -12,8 +12,8 @@ use dom::domtokenlist::DOMTokenList; use dom::htmlelement::HTMLElement; use dom::node::Node; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use std::default::Default; -use string_cache::Atom; use style::attr::AttrValue; #[dom_struct] @@ -23,7 +23,7 @@ pub struct HTMLAreaElement { } impl HTMLAreaElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLAreaElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLAreaElement { HTMLAreaElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), rel_list: Default::default(), @@ -31,7 +31,7 @@ impl HTMLAreaElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLAreaElement> { Node::reflect_node(box HTMLAreaElement::new_inherited(local_name, prefix, document), @@ -45,9 +45,9 @@ impl VirtualMethods for HTMLAreaElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("rel") => AttrValue::from_serialized_tokenlist(value.into()), + &local_name!("rel") => AttrValue::from_serialized_tokenlist(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } @@ -57,7 +57,7 @@ impl HTMLAreaElementMethods for HTMLAreaElement { // https://html.spec.whatwg.org/multipage/#dom-area-rellist fn RelList(&self) -> Root<DOMTokenList> { self.rel_list.or_init(|| { - DOMTokenList::new(self.upcast(), &atom!("rel")) + DOMTokenList::new(self.upcast(), &local_name!("rel")) }) } } diff --git a/components/script/dom/htmlaudioelement.rs b/components/script/dom/htmlaudioelement.rs index 95342e2087d..66c5b2b2fca 100644 --- a/components/script/dom/htmlaudioelement.rs +++ b/components/script/dom/htmlaudioelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlmediaelement::HTMLMediaElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLAudioElement { @@ -16,7 +16,7 @@ pub struct HTMLAudioElement { } impl HTMLAudioElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLAudioElement { HTMLAudioElement { @@ -26,7 +26,7 @@ impl HTMLAudioElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLAudioElement> { Node::reflect_node(box HTMLAudioElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlbaseelement.rs b/components/script/dom/htmlbaseelement.rs index 1a70759de44..9fd34768b36 100644 --- a/components/script/dom/htmlbaseelement.rs +++ b/components/script/dom/htmlbaseelement.rs @@ -13,7 +13,7 @@ use dom::element::{AttributeMutation, Element}; use dom::htmlelement::HTMLElement; use dom::node::{Node, UnbindContext, document_from_node}; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::attr::AttrValue; use url::Url; @@ -23,14 +23,14 @@ pub struct HTMLBaseElement { } impl HTMLBaseElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLBaseElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLBaseElement { HTMLBaseElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLBaseElement> { Node::reflect_node(box HTMLBaseElement::new_inherited(local_name, prefix, document), @@ -40,7 +40,7 @@ impl HTMLBaseElement { /// https://html.spec.whatwg.org/multipage/#frozen-base-url pub fn frozen_base_url(&self) -> Url { - let href = self.upcast::<Element>().get_attribute(&ns!(), &atom!("href")) + let href = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href")) .expect("The frozen base url is only defined for base elements \ that have a base url."); let document = document_from_node(self); @@ -56,7 +56,7 @@ impl HTMLBaseElement { return; } - if self.upcast::<Element>().has_attribute(&atom!("href")) { + if self.upcast::<Element>().has_attribute(&local_name!("href")) { let document = document_from_node(self); document.refresh_base_element(); } @@ -69,7 +69,7 @@ impl HTMLBaseElementMethods for HTMLBaseElement { let document = document_from_node(self); // Step 1. - if !self.upcast::<Element>().has_attribute(&atom!("href")) { + if !self.upcast::<Element>().has_attribute(&local_name!("href")) { return DOMString::from(document.base_url().as_str()); } @@ -77,7 +77,7 @@ impl HTMLBaseElementMethods for HTMLBaseElement { let fallback_base_url = document.fallback_base_url(); // Step 3. - let url = self.upcast::<Element>().get_url_attribute(&atom!("href")); + let url = self.upcast::<Element>().get_url_attribute(&local_name!("href")); // Step 4. let url_record = fallback_base_url.join(&*url); @@ -97,7 +97,7 @@ impl VirtualMethods for HTMLBaseElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); - if *attr.local_name() == atom!("href") { + if *attr.local_name() == local_name!("href") { document_from_node(self).refresh_base_element(); } } diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index 1cab444e871..e89dc21f3da 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -17,8 +17,8 @@ use dom::globalscope::GlobalScope; use dom::htmlelement::HTMLElement; use dom::node::{Node, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use script_traits::ScriptMsg as ConstellationMsg; -use string_cache::Atom; use style::attr::AttrValue; use time; use url::Url; @@ -33,7 +33,7 @@ pub struct HTMLBodyElement { } impl HTMLBodyElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLBodyElement { HTMLBodyElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), @@ -41,7 +41,7 @@ impl HTMLBodyElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document) + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLBodyElement> { Node::reflect_node(box HTMLBodyElement::new_inherited(local_name, prefix, document), document, @@ -93,7 +93,7 @@ impl HTMLBodyElementLayoutHelpers for LayoutJS<HTMLBodyElement> { fn get_background_color(&self) -> Option<RGBA> { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("bgcolor")) + .get_attr_for_layout(&ns!(), &local_name!("bgcolor")) .and_then(AttrValue::as_color) .cloned() } @@ -103,7 +103,7 @@ impl HTMLBodyElementLayoutHelpers for LayoutJS<HTMLBodyElement> { fn get_color(&self) -> Option<RGBA> { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("text")) + .get_attr_for_layout(&ns!(), &local_name!("text")) .and_then(AttrValue::as_color) .cloned() } @@ -113,7 +113,7 @@ impl HTMLBodyElementLayoutHelpers for LayoutJS<HTMLBodyElement> { fn get_background(&self) -> Option<Url> { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("background")) + .get_attr_for_layout(&ns!(), &local_name!("background")) .and_then(AttrValue::as_url) .cloned() } @@ -141,11 +141,11 @@ impl VirtualMethods for HTMLBodyElement { window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap(); } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match *name { - atom!("bgcolor") | - atom!("text") => AttrValue::from_legacy_color(value.into()), - atom!("background") => { + local_name!("bgcolor") | + local_name!("text") => AttrValue::from_legacy_color(value.into()), + local_name!("background") => { AttrValue::from_url(document_from_node(self).url(), value.into()) }, _ => self.super_type().unwrap().parse_plain_attribute(name, value), @@ -159,11 +159,14 @@ impl VirtualMethods for HTMLBodyElement { // https://html.spec.whatwg.org/multipage/ // #event-handlers-on-elements,-document-objects,-and-window-objects:event-handlers-3 match name { - &atom!("onfocus") | &atom!("onload") | &atom!("onscroll") | &atom!("onafterprint") | - &atom!("onbeforeprint") | &atom!("onbeforeunload") | &atom!("onhashchange") | - &atom!("onlanguagechange") | &atom!("onmessage") | &atom!("onoffline") | &atom!("ononline") | - &atom!("onpagehide") | &atom!("onpageshow") | &atom!("onpopstate") | &atom!("onstorage") | - &atom!("onresize") | &atom!("onunload") | &atom!("onerror") + &local_name!("onfocus") | &local_name!("onload") | &local_name!("onscroll") | + &local_name!("onafterprint") | &local_name!("onbeforeprint") | + &local_name!("onbeforeunload") | &local_name!("onhashchange") | + &local_name!("onlanguagechange") | &local_name!("onmessage") | + &local_name!("onoffline") | &local_name!("ononline") | + &local_name!("onpagehide") | &local_name!("onpageshow") | + &local_name!("onpopstate") | &local_name!("onstorage") | + &local_name!("onresize") | &local_name!("onunload") | &local_name!("onerror") => { let evtarget = window.upcast::<EventTarget>(); // forwarded event let source_line = 1; //TODO(#9604) obtain current JS execution line diff --git a/components/script/dom/htmlbrelement.rs b/components/script/dom/htmlbrelement.rs index 09c92ccf45d..498013fc6c8 100644 --- a/components/script/dom/htmlbrelement.rs +++ b/components/script/dom/htmlbrelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLBRElement { @@ -16,14 +16,14 @@ pub struct HTMLBRElement { } impl HTMLBRElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLBRElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLBRElement { HTMLBRElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLBRElement> { Node::reflect_node(box HTMLBRElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 95b85d0da8d..b309da6466a 100644 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -23,8 +23,8 @@ use dom::nodelist::NodeList; use dom::validation::Validatable; use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use std::cell::Cell; -use string_cache::Atom; use style::element_state::*; #[derive(JSTraceable, PartialEq, Copy, Clone)] @@ -43,7 +43,7 @@ pub struct HTMLButtonElement { } impl HTMLButtonElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLButtonElement { HTMLButtonElement { @@ -55,7 +55,7 @@ impl HTMLButtonElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLButtonElement> { Node::reflect_node(box HTMLButtonElement::new_inherited(local_name, prefix, document), @@ -180,7 +180,7 @@ impl VirtualMethods for HTMLButtonElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("disabled") => { + &local_name!("disabled") => { let el = self.upcast::<Element>(); match mutation { AttributeMutation::Set(Some(_)) => {} @@ -195,7 +195,7 @@ impl VirtualMethods for HTMLButtonElement { } } }, - &atom!("type") => { + &local_name!("type") => { match mutation { AttributeMutation::Set(_) => { let value = match &**attr.value() { diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index c63ab1a9531..60f6482a49f 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -25,6 +25,7 @@ use dom::node::{Node, window_from_node}; use dom::virtualmethods::VirtualMethods; use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; use euclid::size::Size2D; +use html5ever_atoms::LocalName; use image::ColorType; use image::png::PNGEncoder; use ipc_channel::ipc::{self, IpcSender}; @@ -34,7 +35,6 @@ use offscreen_gl_context::GLContextAttributes; use rustc_serialize::base64::{STANDARD, ToBase64}; use script_layout_interface::HTMLCanvasData; use std::iter::repeat; -use string_cache::Atom; use style::attr::AttrValue; const DEFAULT_WIDTH: u32 = 300; @@ -56,7 +56,7 @@ pub struct HTMLCanvasElement { } impl HTMLCanvasElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLCanvasElement { HTMLCanvasElement { @@ -66,7 +66,7 @@ impl HTMLCanvasElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLCanvasElement> { Node::reflect_node(box HTMLCanvasElement::new_inherited(local_name, prefix, document), @@ -116,8 +116,8 @@ impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> { } }); - let width_attr = canvas.upcast::<Element>().get_attr_for_layout(&ns!(), &atom!("width")); - let height_attr = canvas.upcast::<Element>().get_attr_for_layout(&ns!(), &atom!("height")); + let width_attr = canvas.upcast::<Element>().get_attr_for_layout(&ns!(), &local_name!("width")); + let height_attr = canvas.upcast::<Element>().get_attr_for_layout(&ns!(), &local_name!("height")); HTMLCanvasData { ipc_renderer: ipc_renderer, width: width_attr.map_or(DEFAULT_WIDTH, |val| val.as_uint()), @@ -307,15 +307,15 @@ impl VirtualMethods for HTMLCanvasElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("width") | &atom!("height") => self.recreate_contexts(), + &local_name!("width") | &local_name!("height") => self.recreate_contexts(), _ => (), }; } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("width") => AttrValue::from_u32(value.into(), DEFAULT_WIDTH), - &atom!("height") => AttrValue::from_u32(value.into(), DEFAULT_HEIGHT), + &local_name!("width") => AttrValue::from_u32(value.into(), DEFAULT_WIDTH), + &local_name!("height") => AttrValue::from_u32(value.into(), DEFAULT_HEIGHT), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 230102bd423..71fc6a1ecf1 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -13,9 +13,9 @@ use dom::bindings::xmlname::namespace_from_domstring; use dom::element::Element; use dom::node::Node; use dom::window::Window; -use std::ascii::AsciiExt; +use html5ever_atoms::{LocalName, QualName}; +use servo_atoms::Atom; use std::cell::Cell; -use string_cache::{Atom, Namespace, QualName}; use style::str::split_html_space_chars; pub trait CollectionFilter : JSTraceable { @@ -113,42 +113,55 @@ impl HTMLCollection { } } - pub fn by_tag_name(window: &Window, root: &Node, mut tag: DOMString) - -> Root<HTMLCollection> { - let tag_atom = Atom::from(&*tag); - tag.make_ascii_lowercase(); - 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) - } + // https://dom.spec.whatwg.org/#concept-getelementsbytagname + pub fn by_qualified_name(window: &Window, root: &Node, qualified_name: LocalName) + -> Root<HTMLCollection> { + // case 1 + if qualified_name == local_name!("*") { + #[derive(JSTraceable, HeapSizeOf)] + struct AllFilter; + impl CollectionFilter for AllFilter { + fn filter(&self, _elem: &Element, _root: &Node) -> bool { + true + } + } + return HTMLCollection::create(window, root, box AllFilter); + } - pub fn by_atomic_tag_name(window: &Window, root: &Node, tag_atom: Atom, ascii_lower_tag: Atom) - -> Root<HTMLCollection> { #[derive(JSTraceable, HeapSizeOf)] - struct TagNameFilter { - tag: Atom, - ascii_lower_tag: Atom, + struct HtmlDocumentFilter { + qualified_name: LocalName, + ascii_lower_qualified_name: LocalName, } - impl CollectionFilter for TagNameFilter { - fn filter(&self, elem: &Element, _root: &Node) -> bool { - if self.tag == atom!("*") { - true - } else if elem.html_element_in_html_document() { - *elem.local_name() == self.ascii_lower_tag - } else { - *elem.local_name() == self.tag + impl CollectionFilter for HtmlDocumentFilter { + fn filter(&self, elem: &Element, root: &Node) -> bool { + if root.is_in_html_doc() && elem.namespace() == &ns!(html) { // case 2 + HTMLCollection::match_element(elem, &self.ascii_lower_qualified_name) + } else { // case 2 and 3 + HTMLCollection::match_element(elem, &self.qualified_name) } } } - let filter = TagNameFilter { - tag: tag_atom, - ascii_lower_tag: ascii_lower_tag, + + let filter = HtmlDocumentFilter { + ascii_lower_qualified_name: qualified_name.to_ascii_lowercase(), + qualified_name: qualified_name, }; HTMLCollection::create(window, root, box filter) } + fn match_element(elem: &Element, qualified_name: &LocalName) -> bool { + match *elem.prefix() { + None => elem.local_name() == qualified_name, + Some(ref prefix) => qualified_name.starts_with(prefix as &str) && + qualified_name.find(":") == Some((prefix as &str).len()) && + qualified_name.ends_with(elem.local_name() as &str), + } + } + pub fn by_tag_name_ns(window: &Window, root: &Node, tag: DOMString, maybe_ns: Option<DOMString>) -> Root<HTMLCollection> { - let local = Atom::from(tag); + let local = LocalName::from(tag); let ns = namespace_from_domstring(maybe_ns); let qname = QualName::new(ns, local); HTMLCollection::by_qual_tag_name(window, root, qname) @@ -161,8 +174,8 @@ impl HTMLCollection { } impl CollectionFilter for TagNameNSFilter { fn filter(&self, elem: &Element, _root: &Node) -> bool { - ((self.qname.ns == Namespace(atom!("*"))) || (self.qname.ns == *elem.namespace())) && - ((self.qname.local == atom!("*")) || (self.qname.local == *elem.local_name())) + ((self.qname.ns == namespace_url!("*")) || (self.qname.ns == *elem.namespace())) && + ((self.qname.local == local_name!("*")) || (self.qname.local == *elem.local_name())) } } let filter = TagNameNSFilter { @@ -205,24 +218,24 @@ impl HTMLCollection { HTMLCollection::create(window, root, box ElementChildFilter) } - pub fn elements_iter_after(&self, after: &Node) -> HTMLCollectionElementsIter { + pub fn elements_iter_after<'a>(&'a self, after: &'a Node) -> impl Iterator<Item=Root<Element>> + 'a { // Iterate forwards from a node. HTMLCollectionElementsIter { - node_iter: box after.following_nodes(&self.root), + node_iter: after.following_nodes(&self.root), root: Root::from_ref(&self.root), filter: &self.filter, } } - pub fn elements_iter(&self) -> HTMLCollectionElementsIter { + pub fn elements_iter<'a>(&'a self) -> impl Iterator<Item=Root<Element>> + 'a { // Iterate forwards from the root. self.elements_iter_after(&*self.root) } - pub fn elements_iter_before(&self, before: &Node) -> HTMLCollectionElementsIter { + pub fn elements_iter_before<'a>(&'a self, before: &'a Node) -> impl Iterator<Item=Root<Element>> + 'a { // Iterate backwards from a node. HTMLCollectionElementsIter { - node_iter: box before.preceding_nodes(&self.root), + node_iter: before.preceding_nodes(&self.root), root: Root::from_ref(&self.root), filter: &self.filter, } @@ -234,13 +247,13 @@ impl HTMLCollection { } // TODO: Make this generic, and avoid code duplication -pub struct HTMLCollectionElementsIter<'a> { - node_iter: Box<Iterator<Item = Root<Node>>>, +struct HTMLCollectionElementsIter<'a, I> { + node_iter: I, root: Root<Node>, filter: &'a Box<CollectionFilter>, } -impl<'a> Iterator for HTMLCollectionElementsIter<'a> { +impl<'a, I: Iterator<Item=Root<Node>>> Iterator for HTMLCollectionElementsIter<'a, I> { type Item = Root<Element>; fn next(&mut self) -> Option<Self::Item> { @@ -284,13 +297,15 @@ 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).nth(offset as usize)) + let mut iter = self.elements_iter_after(&node); + self.set_cached_cursor(index, iter.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).nth(offset as usize)) + let mut iter = self.elements_iter_before(&node); + self.set_cached_cursor(index, iter.nth(offset as usize)) } } else { // Cache miss @@ -313,8 +328,8 @@ impl HTMLCollectionMethods for HTMLCollection { // Step 2. self.elements_iter().find(|elem| { - elem.get_string_attribute(&atom!("id")) == key || - (elem.namespace() == &ns!(html) && elem.get_string_attribute(&atom!("name")) == key) + elem.get_string_attribute(&local_name!("id")) == key || + (elem.namespace() == &ns!(html) && elem.get_string_attribute(&local_name!("name")) == key) }) } @@ -336,12 +351,12 @@ impl HTMLCollectionMethods for HTMLCollection { // Step 2 for elem in self.elements_iter() { // Step 2.1 - let id_attr = elem.get_string_attribute(&atom!("id")); + let id_attr = elem.get_string_attribute(&local_name!("id")); if !id_attr.is_empty() && !result.contains(&id_attr) { result.push(id_attr) } // Step 2.2 - let name_attr = elem.get_string_attribute(&atom!("name")); + let name_attr = elem.get_string_attribute(&local_name!("name")); if !name_attr.is_empty() && !result.contains(&name_attr) && *elem.namespace() == ns!(html) { result.push(name_attr) } diff --git a/components/script/dom/htmldataelement.rs b/components/script/dom/htmldataelement.rs index 2ef14159f10..dcd15f9261a 100644 --- a/components/script/dom/htmldataelement.rs +++ b/components/script/dom/htmldataelement.rs @@ -9,7 +9,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLDataElement { @@ -17,7 +17,7 @@ pub struct HTMLDataElement { } impl HTMLDataElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLDataElement { HTMLDataElement { @@ -26,7 +26,7 @@ impl HTMLDataElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLDataElement> { Node::reflect_node(box HTMLDataElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmldatalistelement.rs b/components/script/dom/htmldatalistelement.rs index c0f3683cb97..616bcd80792 100644 --- a/components/script/dom/htmldatalistelement.rs +++ b/components/script/dom/htmldatalistelement.rs @@ -13,7 +13,7 @@ use dom::htmlcollection::{CollectionFilter, HTMLCollection}; use dom::htmlelement::HTMLElement; use dom::htmloptionelement::HTMLOptionElement; use dom::node::{Node, window_from_node}; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLDataListElement { @@ -21,7 +21,7 @@ pub struct HTMLDataListElement { } impl HTMLDataListElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLDataListElement { HTMLDataListElement { @@ -31,7 +31,7 @@ impl HTMLDataListElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLDataListElement> { Node::reflect_node(box HTMLDataListElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmldetailselement.rs b/components/script/dom/htmldetailselement.rs index 9a7cf6e13f8..8df0f1a62fb 100644 --- a/components/script/dom/htmldetailselement.rs +++ b/components/script/dom/htmldetailselement.rs @@ -15,9 +15,9 @@ use dom::eventtarget::EventTarget; use dom::htmlelement::HTMLElement; use dom::node::{Node, window_from_node}; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use script_thread::Runnable; use std::cell::Cell; -use string_cache::Atom; use task_source::TaskSource; #[dom_struct] @@ -27,7 +27,7 @@ pub struct HTMLDetailsElement { } impl HTMLDetailsElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLDetailsElement { HTMLDetailsElement { @@ -38,7 +38,7 @@ impl HTMLDetailsElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLDetailsElement> { Node::reflect_node(box HTMLDetailsElement::new_inherited(local_name, prefix, document), @@ -67,7 +67,7 @@ impl VirtualMethods for HTMLDetailsElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); - if attr.local_name() == &atom!("open") { + if attr.local_name() == &local_name!("open") { let counter = self.toggle_counter.get() + 1; self.toggle_counter.set(counter); @@ -94,7 +94,7 @@ impl Runnable for DetailsNotificationRunnable { fn handler(self: Box<DetailsNotificationRunnable>) { let target = self.element.root(); if target.check_toggle_count(self.toggle_number) { - target.upcast::<EventTarget>().fire_simple_event("toggle"); + target.upcast::<EventTarget>().fire_event(atom!("toggle")); } } } diff --git a/components/script/dom/htmldialogelement.rs b/components/script/dom/htmldialogelement.rs index 8d20bb75392..80ee9499a9f 100644 --- a/components/script/dom/htmldialogelement.rs +++ b/components/script/dom/htmldialogelement.rs @@ -13,7 +13,7 @@ use dom::element::Element; use dom::eventtarget::EventTarget; use dom::htmlelement::HTMLElement; use dom::node::{Node, window_from_node}; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLDialogElement { @@ -22,7 +22,7 @@ pub struct HTMLDialogElement { } impl HTMLDialogElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLDialogElement { HTMLDialogElement { @@ -33,7 +33,7 @@ impl HTMLDialogElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLDialogElement> { Node::reflect_node(box HTMLDialogElement::new_inherited(local_name, prefix, document), @@ -67,7 +67,7 @@ impl HTMLDialogElementMethods for HTMLDialogElement { let win = window_from_node(self); // Step 1 & 2 - if element.remove_attribute(&ns!(), &atom!("open")).is_none() { + if element.remove_attribute(&ns!(), &local_name!("open")).is_none() { return; } diff --git a/components/script/dom/htmldirectoryelement.rs b/components/script/dom/htmldirectoryelement.rs index 63677ce4140..bd40c508ffe 100644 --- a/components/script/dom/htmldirectoryelement.rs +++ b/components/script/dom/htmldirectoryelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLDirectoryElement { @@ -16,7 +16,7 @@ pub struct HTMLDirectoryElement { } impl HTMLDirectoryElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLDirectoryElement { HTMLDirectoryElement { @@ -26,7 +26,7 @@ impl HTMLDirectoryElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLDirectoryElement> { Node::reflect_node(box HTMLDirectoryElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmldivelement.rs b/components/script/dom/htmldivelement.rs index 943dd8302ee..ba738ca75e2 100644 --- a/components/script/dom/htmldivelement.rs +++ b/components/script/dom/htmldivelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLDivElement { @@ -16,7 +16,7 @@ pub struct HTMLDivElement { } impl HTMLDivElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLDivElement { HTMLDivElement { @@ -25,7 +25,7 @@ impl HTMLDivElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLDivElement> { Node::reflect_node(box HTMLDivElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmldlistelement.rs b/components/script/dom/htmldlistelement.rs index 589eb7bc890..db319c37458 100644 --- a/components/script/dom/htmldlistelement.rs +++ b/components/script/dom/htmldlistelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLDListElement { @@ -16,7 +16,7 @@ pub struct HTMLDListElement { } impl HTMLDListElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLDListElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLDListElement { HTMLDListElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) @@ -24,7 +24,7 @@ impl HTMLDListElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLDListElement> { Node::reflect_node(box HTMLDListElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 502242535c5..d4490357650 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -29,11 +29,11 @@ use dom::node::{Node, SEQUENTIALLY_FOCUSABLE}; use dom::node::{document_from_node, window_from_node}; use dom::nodelist::NodeList; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::default::Default; use std::rc::Rc; -use string_cache::Atom; use style::attr::AttrValue; use style::element_state::*; @@ -45,12 +45,12 @@ pub struct HTMLElement { } impl HTMLElement { - pub fn new_inherited(tag_name: Atom, prefix: Option<DOMString>, + pub fn new_inherited(tag_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLElement { HTMLElement::new_inherited_with_state(ElementState::empty(), tag_name, prefix, document) } - pub fn new_inherited_with_state(state: ElementState, tag_name: Atom, + pub fn new_inherited_with_state(state: ElementState, tag_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLElement { HTMLElement { @@ -62,7 +62,7 @@ impl HTMLElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> Root<HTMLElement> { + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLElement> { Node::reflect_node(box HTMLElement::new_inherited(local_name, prefix, document), document, HTMLElementBinding::Wrap) @@ -76,7 +76,7 @@ impl HTMLElement { fn update_sequentially_focusable_status(&self) { let element = self.upcast::<Element>(); let node = self.upcast::<Node>(); - if element.has_attribute(&atom!("tabindex")) { + if element.has_attribute(&local_name!("tabindex")) { node.set_flag(SEQUENTIALLY_FOCUSABLE, true); } else { match node.type_id() { @@ -87,12 +87,12 @@ impl HTMLElement { => node.set_flag(SEQUENTIALLY_FOCUSABLE, true), NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => { - if element.has_attribute(&atom!("href")) { + if element.has_attribute(&local_name!("href")) { node.set_flag(SEQUENTIALLY_FOCUSABLE, true); } }, _ => { - if let Some(attr) = element.get_attribute(&ns!(), &atom!("draggable")) { + if let Some(attr) = element.get_attribute(&ns!(), &local_name!("draggable")) { let value = attr.value(); let is_true = match *value { AttrValue::String(ref string) => string == "true", @@ -393,16 +393,16 @@ 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)); + // FIXME(ajeffrey): Convert directly from DOMString to LocalName + let local_name = LocalName::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 }) } 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)); + // FIXME(ajeffrey): Convert directly from DOMString to LocalName + let local_name = LocalName::from(to_snake_case(local_name)); self.upcast::<Element>().remove_attribute(&ns!(), &local_name); } @@ -430,7 +430,7 @@ impl HTMLElement { pub fn is_listed_element(&self) -> bool { // Servo does not implement HTMLKeygenElement // https://github.com/servo/servo/issues/2782 - if self.upcast::<Element>().local_name() == &atom!("keygen") { + if self.upcast::<Element>().local_name() == &local_name!("keygen") { return true; } @@ -475,7 +475,7 @@ impl HTMLElement { // will be a label for this HTMLElement .take_while(|elem| !elem.is_labelable_element()) .filter_map(Root::downcast::<HTMLLabelElement>) - .filter(|elem| !elem.upcast::<Element>().has_attribute(&atom!("for"))) + .filter(|elem| !elem.upcast::<Element>().has_attribute(&local_name!("for"))) .filter(|elem| elem.first_labelable_descendant().r() == Some(self)) .map(Root::upcast::<Node>); @@ -491,7 +491,7 @@ impl HTMLElement { let children = root_node.traverse_preorder() .filter_map(Root::downcast::<Element>) .filter(|elem| elem.is::<HTMLLabelElement>()) - .filter(|elem| elem.get_string_attribute(&atom!("for")) == id) + .filter(|elem| elem.get_string_attribute(&local_name!("for")) == id) .map(Root::upcast::<Node>); NodeList::new_simple_list(&window, children.chain(ancestors)) diff --git a/components/script/dom/htmlembedelement.rs b/components/script/dom/htmlembedelement.rs index c527ee2cce7..0c4610f0948 100644 --- a/components/script/dom/htmlembedelement.rs +++ b/components/script/dom/htmlembedelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLEmbedElement { @@ -16,14 +16,14 @@ pub struct HTMLEmbedElement { } impl HTMLEmbedElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLEmbedElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLEmbedElement { HTMLEmbedElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLEmbedElement> { Node::reflect_node(box HTMLEmbedElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs index 8ad987f0f16..4168659b741 100644 --- a/components/script/dom/htmlfieldsetelement.rs +++ b/components/script/dom/htmlfieldsetelement.rs @@ -17,7 +17,7 @@ use dom::htmllegendelement::HTMLLegendElement; use dom::node::{Node, window_from_node}; use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::element_state::*; #[dom_struct] @@ -26,7 +26,7 @@ pub struct HTMLFieldSetElement { } impl HTMLFieldSetElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLFieldSetElement { HTMLFieldSetElement { @@ -37,7 +37,7 @@ impl HTMLFieldSetElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLFieldSetElement> { Node::reflect_node(box HTMLFieldSetElement::new_inherited(local_name, prefix, document), @@ -88,7 +88,7 @@ impl VirtualMethods for HTMLFieldSetElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("disabled") => { + &local_name!("disabled") => { let disabled_state = match mutation { AttributeMutation::Set(None) => true, AttributeMutation::Set(Some(_)) => { diff --git a/components/script/dom/htmlfontelement.rs b/components/script/dom/htmlfontelement.rs index ee7c67e45e5..0eca01a47f9 100644 --- a/components/script/dom/htmlfontelement.rs +++ b/components/script/dom/htmlfontelement.rs @@ -13,7 +13,8 @@ use dom::element::{Element, RawLayoutElementHelpers}; use dom::htmlelement::HTMLElement; use dom::node::Node; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; +use servo_atoms::Atom; use style::attr::AttrValue; use style::str::{HTML_SPACE_CHARACTERS, read_numbers}; use style::values::specified; @@ -25,14 +26,14 @@ pub struct HTMLFontElement { impl HTMLFontElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLFontElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLFontElement { HTMLFontElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLFontElement> { Node::reflect_node(box HTMLFontElement::new_inherited(local_name, prefix, document), @@ -61,7 +62,7 @@ impl HTMLFontElementMethods for HTMLFontElement { fn SetSize(&self, value: DOMString) { let element = self.upcast::<Element>(); let length = parse_length(&value); - element.set_attribute(&atom!("size"), AttrValue::Length(value.into(), length)); + element.set_attribute(&local_name!("size"), AttrValue::Length(value.into(), length)); } } @@ -70,11 +71,11 @@ impl VirtualMethods for HTMLFontElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("face") => AttrValue::from_atomic(value.into()), - &atom!("color") => AttrValue::from_legacy_color(value.into()), - &atom!("size") => { + &local_name!("face") => AttrValue::from_atomic(value.into()), + &local_name!("color") => AttrValue::from_legacy_color(value.into()), + &local_name!("size") => { let length = parse_length(&value); AttrValue::Length(value.into(), length) }, @@ -94,7 +95,7 @@ impl HTMLFontElementLayoutHelpers for LayoutJS<HTMLFontElement> { fn get_color(&self) -> Option<RGBA> { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("color")) + .get_attr_for_layout(&ns!(), &local_name!("color")) .and_then(AttrValue::as_color) .cloned() } @@ -104,7 +105,7 @@ impl HTMLFontElementLayoutHelpers for LayoutJS<HTMLFontElement> { fn get_face(&self) -> Option<Atom> { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("face")) + .get_attr_for_layout(&ns!(), &local_name!("face")) .map(AttrValue::as_atom) .cloned() } @@ -114,7 +115,7 @@ impl HTMLFontElementLayoutHelpers for LayoutJS<HTMLFontElement> { fn get_size(&self) -> Option<specified::Length> { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("size")) + .get_attr_for_layout(&ns!(), &local_name!("size")) .and_then(AttrValue::as_length) .cloned() } diff --git a/components/script/dom/htmlformcontrolscollection.rs b/components/script/dom/htmlformcontrolscollection.rs index 3986692099c..6fc52e099e7 100644 --- a/components/script/dom/htmlformcontrolscollection.rs +++ b/components/script/dom/htmlformcontrolscollection.rs @@ -50,8 +50,8 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection { if name.is_empty() { return None; } let mut filter_map = self.collection.elements_iter().filter_map(|elem| { - if elem.get_string_attribute(&atom!("name")) == name - || elem.get_string_attribute(&atom!("id")) == name { + if elem.get_string_attribute(&local_name!("name")) == name + || elem.get_string_attribute(&local_name!("id")) == name { Some(elem) } else { None } }); diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 78167022773..4ecc6a44fa0 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -20,7 +20,6 @@ use dom::bindings::str::DOMString; use dom::blob::Blob; use dom::document::Document; use dom::element::Element; -use dom::event::{EventBubbles, EventCancelable}; use dom::eventtarget::EventTarget; use dom::file::File; use dom::globalscope::GlobalScope; @@ -40,6 +39,7 @@ use dom::virtualmethods::VirtualMethods; use encoding::EncodingRef; use encoding::all::UTF_8; use encoding::label::encoding_from_whatwg_label; +use html5ever_atoms::LocalName; use hyper::header::{Charset, ContentDisposition, ContentType, DispositionParam, DispositionType}; use hyper::method::Method; use msg::constellation_msg::PipelineId; @@ -49,7 +49,6 @@ use script_traits::LoadData; use std::borrow::ToOwned; use std::cell::Cell; use std::sync::mpsc::Sender; -use string_cache::Atom; use style::attr::AttrValue; use style::str::split_html_space_chars; use task_source::TaskSource; @@ -66,7 +65,7 @@ pub struct HTMLFormElement { } impl HTMLFormElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLFormElement { HTMLFormElement { @@ -78,7 +77,7 @@ impl HTMLFormElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLFormElement> { Node::reflect_node(box HTMLFormElement::new_inherited(local_name, prefix, document), @@ -205,7 +204,7 @@ impl HTMLFormElementMethods for HTMLFormElement { } _ => { debug_assert!(!elem.downcast::<HTMLElement>().unwrap().is_listed_element() || - elem.local_name() == &atom!("keygen")); + elem.local_name() == &local_name!("keygen")); return false; } } @@ -255,9 +254,9 @@ impl HTMLFormElement { // https://html.spec.whatwg.org/multipage/#picking-an-encoding-for-the-form fn pick_encoding(&self) -> EncodingRef { // Step 2 - if self.upcast::<Element>().has_attribute(&atom!("accept-charset")) { + if self.upcast::<Element>().has_attribute(&local_name!("accept-charset")) { // Substep 1 - let input = self.upcast::<Element>().get_string_attribute(&atom!("accept-charset")); + let input = self.upcast::<Element>().get_string_attribute(&local_name!("accept-charset")); // Substep 2, 3, 4 let mut candidate_encodings = split_html_space_chars(&*input).filter_map(encoding_from_whatwg_label); @@ -305,16 +304,14 @@ impl HTMLFormElement { { if self.interactive_validation().is_err() { // TODO: Implement event handlers on all form control elements - self.upcast::<EventTarget>().fire_simple_event("invalid"); + self.upcast::<EventTarget>().fire_event(atom!("invalid")); return; } } // Step 5 if submit_method_flag == SubmittedFrom::NotFromForm { let event = self.upcast::<EventTarget>() - .fire_event("submit", - EventBubbles::Bubbles, - EventCancelable::Cancelable); + .fire_bubbling_cancelable_event(atom!("submit")); if event.DefaultPrevented() { return; } @@ -484,9 +481,7 @@ impl HTMLFormElement { // Step 5-6 let unhandled_invalid_controls = invalid_controls.into_iter().filter_map(|field| { let event = field.as_event_target() - .fire_event("invalid", - EventBubbles::DoesNotBubble, - EventCancelable::Cancelable); + .fire_cancelable_event(atom!("invalid")); if !event.DefaultPrevented() { return Some(field); } None }).collect::<Vec<FormSubmittableElement>>(); @@ -615,9 +610,7 @@ impl HTMLFormElement { } let event = self.upcast::<EventTarget>() - .fire_event("reset", - EventBubbles::Bubbles, - EventCancelable::Cancelable); + .fire_bubbling_cancelable_event(atom!("reset")); if event.DefaultPrevented() { return; } @@ -728,12 +721,12 @@ impl<'a> FormSubmitter<'a> { match *self { FormSubmitter::FormElement(form) => form.Action(), FormSubmitter::InputElement(input_element) => { - input_element.get_form_attribute(&atom!("formaction"), + input_element.get_form_attribute(&local_name!("formaction"), |i| i.FormAction(), |f| f.Action()) }, FormSubmitter::ButtonElement(button_element) => { - button_element.get_form_attribute(&atom!("formaction"), + button_element.get_form_attribute(&local_name!("formaction"), |i| i.FormAction(), |f| f.Action()) } @@ -744,12 +737,12 @@ impl<'a> FormSubmitter<'a> { let attr = match *self { FormSubmitter::FormElement(form) => form.Enctype(), FormSubmitter::InputElement(input_element) => { - input_element.get_form_attribute(&atom!("formenctype"), + input_element.get_form_attribute(&local_name!("formenctype"), |i| i.FormEnctype(), |f| f.Enctype()) }, FormSubmitter::ButtonElement(button_element) => { - button_element.get_form_attribute(&atom!("formenctype"), + button_element.get_form_attribute(&local_name!("formenctype"), |i| i.FormEnctype(), |f| f.Enctype()) } @@ -767,12 +760,12 @@ impl<'a> FormSubmitter<'a> { let attr = match *self { FormSubmitter::FormElement(form) => form.Method(), FormSubmitter::InputElement(input_element) => { - input_element.get_form_attribute(&atom!("formmethod"), + input_element.get_form_attribute(&local_name!("formmethod"), |i| i.FormMethod(), |f| f.Method()) }, FormSubmitter::ButtonElement(button_element) => { - button_element.get_form_attribute(&atom!("formmethod"), + button_element.get_form_attribute(&local_name!("formmethod"), |i| i.FormMethod(), |f| f.Method()) } @@ -788,12 +781,12 @@ impl<'a> FormSubmitter<'a> { match *self { FormSubmitter::FormElement(form) => form.Target(), FormSubmitter::InputElement(input_element) => { - input_element.get_form_attribute(&atom!("formtarget"), + input_element.get_form_attribute(&local_name!("formtarget"), |i| i.FormTarget(), |f| f.Target()) }, FormSubmitter::ButtonElement(button_element) => { - button_element.get_form_attribute(&atom!("formtarget"), + button_element.get_form_attribute(&local_name!("formtarget"), |i| i.FormTarget(), |f| f.Target()) } @@ -804,12 +797,12 @@ impl<'a> FormSubmitter<'a> { match *self { FormSubmitter::FormElement(form) => form.NoValidate(), FormSubmitter::InputElement(input_element) => { - input_element.get_form_boolean_attribute(&atom!("formnovalidate"), + input_element.get_form_boolean_attribute(&local_name!("formnovalidate"), |i| i.FormNoValidate(), |f| f.NoValidate()) } FormSubmitter::ButtonElement(button_element) => { - button_element.get_form_boolean_attribute(&atom!("formnovalidate"), + button_element.get_form_boolean_attribute(&local_name!("formnovalidate"), |i| i.FormNoValidate(), |f| f.NoValidate()) } @@ -823,7 +816,7 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable { fn form_owner(&self) -> Option<Root<HTMLFormElement>> { // https://html.spec.whatwg.org/multipage/#reset-the-form-owner let elem = self.to_element(); - let owner = elem.get_string_attribute(&atom!("form")); + let owner = elem.get_string_attribute(&local_name!("form")); if !owner.is_empty() { let doc = document_from_node(elem); let owner = doc.GetElementById(owner); @@ -838,7 +831,7 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable { } fn get_form_attribute<InputFn, OwnerFn>(&self, - attr: &Atom, + attr: &LocalName, input: InputFn, owner: OwnerFn) -> DOMString @@ -853,7 +846,7 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable { } fn get_form_boolean_attribute<InputFn, OwnerFn>(&self, - attr: &Atom, + attr: &LocalName, input: InputFn, owner: OwnerFn) -> bool @@ -881,9 +874,9 @@ impl VirtualMethods for HTMLFormElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("name") => AttrValue::from_atomic(value.into()), + &local_name!("name") => AttrValue::from_atomic(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/htmlframeelement.rs b/components/script/dom/htmlframeelement.rs index b8ba42bec63..919c460dee5 100644 --- a/components/script/dom/htmlframeelement.rs +++ b/components/script/dom/htmlframeelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLFrameElement { @@ -16,14 +16,14 @@ pub struct HTMLFrameElement { } impl HTMLFrameElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLFrameElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLFrameElement { HTMLFrameElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLFrameElement> { Node::reflect_node(box HTMLFrameElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlframesetelement.rs b/components/script/dom/htmlframesetelement.rs index bac782288b3..b238692dc11 100644 --- a/components/script/dom/htmlframesetelement.rs +++ b/components/script/dom/htmlframesetelement.rs @@ -11,7 +11,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::{Node, window_from_node}; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLFrameSetElement { @@ -19,7 +19,7 @@ pub struct HTMLFrameSetElement { } impl HTMLFrameSetElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLFrameSetElement { HTMLFrameSetElement { @@ -29,7 +29,7 @@ impl HTMLFrameSetElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLFrameSetElement> { Node::reflect_node(box HTMLFrameSetElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlheadelement.rs b/components/script/dom/htmlheadelement.rs index 26d966a05d1..419644c5bb3 100644 --- a/components/script/dom/htmlheadelement.rs +++ b/components/script/dom/htmlheadelement.rs @@ -14,7 +14,7 @@ use dom::htmlmetaelement::HTMLMetaElement; use dom::node::{Node, document_from_node}; use dom::userscripts::load_script; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLHeadElement { @@ -22,7 +22,7 @@ pub struct HTMLHeadElement { } impl HTMLHeadElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLHeadElement { HTMLHeadElement { @@ -31,7 +31,7 @@ impl HTMLHeadElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLHeadElement> { Node::reflect_node(box HTMLHeadElement::new_inherited(local_name, prefix, document), @@ -51,11 +51,11 @@ impl HTMLHeadElement { let candidates = node.traverse_preorder() .filter_map(Root::downcast::<Element>) .filter(|elem| elem.is::<HTMLMetaElement>()) - .filter(|elem| elem.get_string_attribute(&atom!("name")) == "referrer") - .filter(|elem| elem.get_attribute(&ns!(), &atom!("content")).is_some()); + .filter(|elem| elem.get_string_attribute(&local_name!("name")) == "referrer") + .filter(|elem| elem.get_attribute(&ns!(), &local_name!("content")).is_some()); for meta in candidates { - if let Some(content) = meta.get_attribute(&ns!(), &atom!("content")).r() { + if let Some(content) = meta.get_attribute(&ns!(), &local_name!("content")).r() { let content = content.value(); let content_val = content.trim(); if !content_val.is_empty() { diff --git a/components/script/dom/htmlheadingelement.rs b/components/script/dom/htmlheadingelement.rs index 90fbd259818..edfd894c51e 100644 --- a/components/script/dom/htmlheadingelement.rs +++ b/components/script/dom/htmlheadingelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[derive(JSTraceable, HeapSizeOf)] pub enum HeadingLevel { @@ -27,7 +27,7 @@ pub struct HTMLHeadingElement { } impl HTMLHeadingElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document, level: HeadingLevel) -> HTMLHeadingElement { @@ -39,7 +39,7 @@ impl HTMLHeadingElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document, level: HeadingLevel) -> Root<HTMLHeadingElement> { diff --git a/components/script/dom/htmlhrelement.rs b/components/script/dom/htmlhrelement.rs index ee2e9f4f12e..939e389e81f 100644 --- a/components/script/dom/htmlhrelement.rs +++ b/components/script/dom/htmlhrelement.rs @@ -12,7 +12,7 @@ use dom::element::{Element, RawLayoutElementHelpers}; use dom::htmlelement::HTMLElement; use dom::node::Node; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; #[dom_struct] @@ -21,14 +21,14 @@ pub struct HTMLHRElement { } impl HTMLHRElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLHRElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLHRElement { HTMLHRElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLHRElement> { Node::reflect_node(box HTMLHRElement::new_inherited(local_name, prefix, document), @@ -67,7 +67,7 @@ impl HTMLHRLayoutHelpers for LayoutJS<HTMLHRElement> { fn get_color(&self) -> Option<RGBA> { unsafe { (&*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("color")) + .get_attr_for_layout(&ns!(), &local_name!("color")) .and_then(AttrValue::as_color) .cloned() } @@ -77,7 +77,7 @@ impl HTMLHRLayoutHelpers for LayoutJS<HTMLHRElement> { fn get_width(&self) -> LengthOrPercentageOrAuto { unsafe { (&*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("width")) + .get_attr_for_layout(&ns!(), &local_name!("width")) .map(AttrValue::as_dimension) .cloned() .unwrap_or(LengthOrPercentageOrAuto::Auto) @@ -91,11 +91,11 @@ impl VirtualMethods for HTMLHRElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("align") => AttrValue::from_dimension(value.into()), - &atom!("color") => AttrValue::from_legacy_color(value.into()), - &atom!("width") => AttrValue::from_dimension(value.into()), + &local_name!("align") => AttrValue::from_dimension(value.into()), + &local_name!("color") => AttrValue::from_legacy_color(value.into()), + &local_name!("width") => AttrValue::from_dimension(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/htmlhtmlelement.rs b/components/script/dom/htmlhtmlelement.rs index 3b397c7fd04..d79fbadcae2 100644 --- a/components/script/dom/htmlhtmlelement.rs +++ b/components/script/dom/htmlhtmlelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLHtmlElement { @@ -16,14 +16,14 @@ pub struct HTMLHtmlElement { } impl HTMLHtmlElement { - fn new_inherited(localName: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLHtmlElement { + fn new_inherited(localName: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLHtmlElement { HTMLHtmlElement { htmlelement: HTMLElement::new_inherited(localName, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(localName: Atom, + pub fn new(localName: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLHtmlElement> { Node::reflect_node(box HTMLHtmlElement::new_inherited(localName, prefix, document), diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 5215359df8a..2b56b9d697c 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -35,6 +35,7 @@ use dom::node::{Node, NodeDamage, UnbindContext, document_from_node, window_from use dom::urlhelper::UrlHelper; use dom::virtualmethods::VirtualMethods; use dom::window::{ReflowReason, Window}; +use html5ever_atoms::LocalName; use ipc_channel::ipc; use js::jsapi::{JSAutoCompartment, JSContext, MutableHandleValue}; use js::jsval::{NullValue, UndefinedValue}; @@ -43,8 +44,8 @@ use net_traits::response::HttpsState; use script_layout_interface::message::ReflowQueryType; use script_traits::{IFrameLoadInfo, LoadData, MozBrowserEvent, ScriptMsg as ConstellationMsg}; use script_traits::IFrameSandboxState::{IFrameSandboxed, IFrameUnsandboxed}; +use servo_atoms::Atom; use std::cell::Cell; -use string_cache::Atom; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; use style::context::ReflowGoal; use url::Url; @@ -84,7 +85,7 @@ impl HTMLIFrameElement { /// step 1. fn get_url(&self) -> Url { let element = self.upcast::<Element>(); - element.get_attribute(&ns!(), &atom!("src")).and_then(|src| { + element.get_attribute(&ns!(), &local_name!("src")).and_then(|src| { let url = src.value(); if url.is_empty() { None @@ -178,7 +179,7 @@ impl HTMLIFrameElement { self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage); } - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLIFrameElement { HTMLIFrameElement { @@ -193,7 +194,7 @@ impl HTMLIFrameElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLIFrameElement> { Node::reflect_node(box HTMLIFrameElement::new_inherited(local_name, prefix, document), @@ -206,6 +207,11 @@ impl HTMLIFrameElement { self.pipeline_id.get() } + #[inline] + pub fn frame_id(&self) -> FrameId { + self.frame_id + } + pub fn change_visibility_status(&self, visibility: bool) { if self.visibility.get() != visibility { self.visibility.set(visibility); @@ -238,7 +244,7 @@ impl HTMLIFrameElement { // TODO Step 3 - set child document `mut iframe load` flag // Step 4 - self.upcast::<EventTarget>().fire_simple_event("load"); + self.upcast::<EventTarget>().fire_event(atom!("load")); let mut blocker = self.load_blocker.borrow_mut(); LoadBlocker::terminate(&mut blocker); @@ -255,7 +261,7 @@ impl HTMLIFrameElement { pub fn privatebrowsing(&self) -> bool { if self.Mozbrowser() { let element = self.upcast::<Element>(); - element.has_attribute(&Atom::from("mozprivatebrowsing")) + element.has_attribute(&LocalName::from("mozprivatebrowsing")) } else { false } @@ -290,7 +296,7 @@ impl HTMLIFrameElementLayoutMethods for LayoutJS<HTMLIFrameElement> { fn get_width(&self) -> LengthOrPercentageOrAuto { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("width")) + .get_attr_for_layout(&ns!(), &local_name!("width")) .map(AttrValue::as_dimension) .cloned() .unwrap_or(LengthOrPercentageOrAuto::Auto) @@ -301,7 +307,7 @@ impl HTMLIFrameElementLayoutMethods for LayoutJS<HTMLIFrameElement> { fn get_height(&self) -> LengthOrPercentageOrAuto { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("height")) + .get_attr_for_layout(&ns!(), &local_name!("height")) .map(AttrValue::as_dimension) .cloned() .unwrap_or(LengthOrPercentageOrAuto::Auto) @@ -408,7 +414,7 @@ unsafe fn build_mozbrowser_event_detail(event: MozBrowserEvent, pub fn Navigate(iframe: &HTMLIFrameElement, direction: TraversalDirection) -> ErrorResult { if iframe.Mozbrowser() { - if iframe.upcast::<Node>().is_in_doc() { + if iframe.upcast::<Node>().is_in_doc_with_browsing_context() { let window = window_from_node(iframe); let msg = ConstellationMsg::TraverseHistory(iframe.pipeline_id(), direction); window.upcast::<GlobalScope>().constellation_chan().send(msg).unwrap(); @@ -425,17 +431,17 @@ pub fn Navigate(iframe: &HTMLIFrameElement, direction: TraversalDirection) -> Er impl HTMLIFrameElementMethods for HTMLIFrameElement { // https://html.spec.whatwg.org/multipage/#dom-iframe-src fn Src(&self) -> DOMString { - self.upcast::<Element>().get_string_attribute(&atom!("src")) + self.upcast::<Element>().get_string_attribute(&local_name!("src")) } // https://html.spec.whatwg.org/multipage/#dom-iframe-src fn SetSrc(&self, src: DOMString) { - self.upcast::<Element>().set_url_attribute(&atom!("src"), src) + self.upcast::<Element>().set_url_attribute(&local_name!("src"), src) } // https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox fn Sandbox(&self) -> Root<DOMTokenList> { - self.sandbox.or_init(|| DOMTokenList::new(self.upcast::<Element>(), &atom!("sandbox"))) + self.sandbox.or_init(|| DOMTokenList::new(self.upcast::<Element>(), &local_name!("sandbox"))) } // https://html.spec.whatwg.org/multipage/#dom-iframe-contentwindow @@ -469,7 +475,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement { fn Mozbrowser(&self) -> bool { if window_from_node(self).is_mozbrowser() { let element = self.upcast::<Element>(); - element.has_attribute(&atom!("mozbrowser")) + element.has_attribute(&local_name!("mozbrowser")) } else { false } @@ -478,7 +484,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement { // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser fn SetMozbrowser(&self, value: bool) { let element = self.upcast::<Element>(); - element.set_bool_attribute(&atom!("mozbrowser"), value); + element.set_bool_attribute(&local_name!("mozbrowser"), value); } // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goBack @@ -494,7 +500,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement { // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/reload fn Reload(&self, _hard_reload: bool) -> ErrorResult { if self.Mozbrowser() { - if self.upcast::<Node>().is_in_doc() { + if self.upcast::<Node>().is_in_doc_with_browsing_context() { self.navigate_or_reload_child_browsing_context(None, true); } Ok(()) @@ -552,13 +558,13 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement { // check-tidy: no specs after this line fn SetMozprivatebrowsing(&self, value: bool) { let element = self.upcast::<Element>(); - element.set_bool_attribute(&Atom::from("mozprivatebrowsing"), value); + element.set_bool_attribute(&LocalName::from("mozprivatebrowsing"), value); } fn Mozprivatebrowsing(&self) -> bool { if window_from_node(self).is_mozbrowser() { let element = self.upcast::<Element>(); - element.has_attribute(&Atom::from("mozprivatebrowsing")) + element.has_attribute(&LocalName::from("mozprivatebrowsing")) } else { false } @@ -573,7 +579,7 @@ impl VirtualMethods for HTMLIFrameElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("sandbox") => { + &local_name!("sandbox") => { self.sandbox_allowance.set(mutation.new_value(attr).map(|value| { let mut modes = ALLOW_NOTHING; for token in value.as_tokens() { @@ -590,9 +596,18 @@ impl VirtualMethods for HTMLIFrameElement { modes })); }, - &atom!("src") => { + &local_name!("src") => { if let AttributeMutation::Set(_) = mutation { - if self.upcast::<Node>().is_in_doc() { + // https://html.spec.whatwg.org/multipage/#the-iframe-element + // "Similarly, whenever an iframe element with a non-null nested browsing context + // but with no srcdoc attribute specified has its src attribute set, changed, or removed, + // the user agent must process the iframe attributes," + // but we can't check that directly, since the child browsing context + // may be in a different script thread. Instread, we check to see if the parent + // is in a document tree and has a browsing context, which is what causes + // the child browsing context to be created. + if self.upcast::<Node>().is_in_doc_with_browsing_context() { + debug!("iframe {} src set while in browsing context.", self.frame_id); self.process_the_iframe_attributes(); } } @@ -601,11 +616,11 @@ impl VirtualMethods for HTMLIFrameElement { } } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("sandbox") => AttrValue::from_serialized_tokenlist(value.into()), - &atom!("width") => AttrValue::from_dimension(value.into()), - &atom!("height") => AttrValue::from_dimension(value.into()), + &local_name!("sandbox") => AttrValue::from_serialized_tokenlist(value.into()), + &local_name!("width") => AttrValue::from_dimension(value.into()), + &local_name!("height") => AttrValue::from_dimension(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } @@ -615,7 +630,14 @@ impl VirtualMethods for HTMLIFrameElement { s.bind_to_tree(tree_in_doc); } - if tree_in_doc { + // https://html.spec.whatwg.org/multipage/#the-iframe-element + // "When an iframe element is inserted into a document that has + // a browsing context, the user agent must create a new + // browsing context, set the element's nested browsing context + // to the newly-created browsing context, and then process the + // iframe attributes for the "first time"." + if self.upcast::<Node>().is_in_doc_with_browsing_context() { + debug!("iframe {} bound to browsing context.", self.frame_id); self.process_the_iframe_attributes(); } } diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 911f305e9f9..e8a269c782c 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -21,6 +21,7 @@ use dom::htmlelement::HTMLElement; use dom::node::{Node, NodeDamage, document_from_node, window_from_node}; use dom::values::UNSIGNED_LONG_MAX; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use ipc_channel::ipc; use ipc_channel::router::ROUTER; use net_traits::image::base::{Image, ImageMetadata}; @@ -30,7 +31,6 @@ use script_runtime::ScriptThreadEventCategory::UpdateReplacedElement; use script_thread::Runnable; use std::i32; use std::sync::Arc; -use string_cache::Atom; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; use task_source::TaskSource; use url::Url; @@ -105,12 +105,12 @@ impl Runnable for ImageResponseHandlerRunnable { // Fire image.onload if trigger_image_load { - element.upcast::<EventTarget>().fire_simple_event("load"); + element.upcast::<EventTarget>().fire_event(atom!("load")); } // Fire image.onerror if trigger_image_error { - element.upcast::<EventTarget>().fire_simple_event("error"); + element.upcast::<EventTarget>().fire_event(atom!("error")); } // Trigger reflow @@ -180,8 +180,8 @@ impl HTMLImageElement { // Step 11, substep 5 let img = self.img.root(); img.current_request.borrow_mut().source_url = Some(self.src.into()); - img.upcast::<EventTarget>().fire_simple_event("error"); - img.upcast::<EventTarget>().fire_simple_event("loadend"); + img.upcast::<EventTarget>().fire_event(atom!("error")); + img.upcast::<EventTarget>().fire_event(atom!("loadend")); } } @@ -195,7 +195,7 @@ impl HTMLImageElement { } } } - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLImageElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLImageElement { HTMLImageElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), current_request: DOMRefCell::new(ImageRequest { @@ -216,7 +216,7 @@ impl HTMLImageElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLImageElement> { Node::reflect_node(box HTMLImageElement::new_inherited(local_name, prefix, document), @@ -228,7 +228,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); + let image = HTMLImageElement::new(local_name!("img"), None, &document); if let Some(w) = width { image.SetWidth(w); } @@ -266,7 +266,7 @@ impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> { fn get_width(&self) -> LengthOrPercentageOrAuto { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("width")) + .get_attr_for_layout(&ns!(), &local_name!("width")) .map(AttrValue::as_dimension) .cloned() .unwrap_or(LengthOrPercentageOrAuto::Auto) @@ -277,7 +277,7 @@ impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> { fn get_height(&self) -> LengthOrPercentageOrAuto { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("height")) + .get_attr_for_layout(&ns!(), &local_name!("height")) .map(AttrValue::as_dimension) .cloned() .unwrap_or(LengthOrPercentageOrAuto::Auto) @@ -320,7 +320,7 @@ impl HTMLImageElementMethods for HTMLImageElement { // https://html.spec.whatwg.org/multipage/#dom-img-width fn SetWidth(&self, value: u32) { - image_dimension_setter(self.upcast(), atom!("width"), value); + image_dimension_setter(self.upcast(), local_name!("width"), value); } // https://html.spec.whatwg.org/multipage/#dom-img-height @@ -332,7 +332,7 @@ impl HTMLImageElementMethods for HTMLImageElement { // https://html.spec.whatwg.org/multipage/#dom-img-height fn SetHeight(&self, value: u32) { - image_dimension_setter(self.upcast(), atom!("height"), value); + image_dimension_setter(self.upcast(), local_name!("height"), value); } // https://html.spec.whatwg.org/multipage/#dom-img-naturalwidth @@ -415,7 +415,7 @@ impl VirtualMethods for HTMLImageElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("src") => { + &local_name!("src") => { self.update_image(mutation.new_value(attr).map(|value| { // FIXME(ajeffrey): convert directly from AttrValue to DOMString (DOMString::from(&**value), document_from_node(self).base_url()) @@ -425,17 +425,17 @@ impl VirtualMethods for HTMLImageElement { } } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("name") => AttrValue::from_atomic(value.into()), - &atom!("width") | &atom!("height") => AttrValue::from_dimension(value.into()), - &atom!("hspace") | &atom!("vspace") => AttrValue::from_u32(value.into(), 0), + &local_name!("name") => AttrValue::from_atomic(value.into()), + &local_name!("width") | &local_name!("height") => AttrValue::from_dimension(value.into()), + &local_name!("hspace") | &local_name!("vspace") => AttrValue::from_u32(value.into(), 0), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } } -fn image_dimension_setter(element: &Element, attr: Atom, value: u32) { +fn image_dimension_setter(element: &Element, attr: LocalName, value: u32) { // This setter is a bit weird: the IDL type is unsigned long, but it's parsed as // a dimension for rendering. let value = if value > UNSIGNED_LONG_MAX { diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 049d765b831..b599d4369dc 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -32,6 +32,7 @@ use dom::node::{document_from_node, window_from_node}; use dom::nodelist::NodeList; use dom::validation::Validatable; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use ipc_channel::ipc::{self, IpcSender}; use mime_guess; use msg::constellation_msg::Key; @@ -39,10 +40,10 @@ use net_traits::{CoreResourceMsg, IpcSend}; use net_traits::blob_url_store::get_blob_origin; use net_traits::filemanager_thread::{FileManagerThreadMsg, FilterPattern}; use script_traits::ScriptMsg as ConstellationMsg; +use servo_atoms::Atom; use std::borrow::ToOwned; use std::cell::Cell; use std::ops::Range; -use string_cache::Atom; use style::attr::AttrValue; use style::element_state::*; use style::str::split_commas; @@ -128,7 +129,7 @@ static DEFAULT_MAX_LENGTH: i32 = -1; static DEFAULT_MIN_LENGTH: i32 = -1; impl HTMLInputElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLInputElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLInputElement { let chan = document.window().upcast::<GlobalScope>().constellation_chan().clone(); HTMLInputElement { htmlelement: @@ -154,7 +155,7 @@ impl HTMLInputElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLInputElement> { Node::reflect_node(box HTMLInputElement::new_inherited(local_name, prefix, document), @@ -164,7 +165,7 @@ impl HTMLInputElement { pub fn type_(&self) -> Atom { self.upcast::<Element>() - .get_attribute(&ns!(), &atom!("type")) + .get_attribute(&ns!(), &local_name!("type")) .map_or_else(|| atom!(""), |a| a.value().as_atom().to_owned()) } @@ -209,7 +210,7 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> { unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>, default: &str) -> String { let elem = input.upcast::<Element>(); let value = (*elem.unsafe_get()) - .get_attr_val_for_layout(&ns!(), &atom!("value")) + .get_attr_val_for_layout(&ns!(), &local_name!("value")) .unwrap_or(default); String::from(value) } @@ -371,13 +372,13 @@ impl HTMLInputElementMethods for HTMLInputElement { ValueMode::Value => self.textinput.borrow().get_content(), ValueMode::Default => { self.upcast::<Element>() - .get_attribute(&ns!(), &atom!("value")) + .get_attribute(&ns!(), &local_name!("value")) .map_or(DOMString::from(""), |a| DOMString::from(a.summarize().value)) } ValueMode::DefaultOn => { self.upcast::<Element>() - .get_attribute(&ns!(), &atom!("value")) + .get_attribute(&ns!(), &local_name!("value")) .map_or(DOMString::from("on"), |a| DOMString::from(a.summarize().value)) } @@ -407,7 +408,7 @@ impl HTMLInputElementMethods for HTMLInputElement { } ValueMode::Default | ValueMode::DefaultOn => { - self.upcast::<Element>().set_string_attribute(&atom!("value"), value); + self.upcast::<Element>().set_string_attribute(&local_name!("value"), value); } ValueMode::Filename => { if value.is_empty() { @@ -734,7 +735,7 @@ impl HTMLInputElement { fn radio_group_name(&self) -> Option<Atom> { //TODO: determine form owner self.upcast::<Element>() - .get_attribute(&ns!(), &atom!("name")) + .get_attribute(&ns!(), &local_name!("name")) .map(|name| name.value().as_atom().clone()) } @@ -848,12 +849,8 @@ impl HTMLInputElement { let filelist = FileList::new(&window, files); self.filelist.set(Some(&filelist)); - target.fire_event("input", - EventBubbles::Bubbles, - EventCancelable::NotCancelable); - target.fire_event("change", - EventBubbles::Bubbles, - EventCancelable::NotCancelable); + target.fire_bubbling_event(atom!("input")); + target.fire_bubbling_event(atom!("change")); } } } @@ -867,7 +864,7 @@ impl VirtualMethods for HTMLInputElement { self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("disabled") => { + &local_name!("disabled") => { let disabled_state = match mutation { AttributeMutation::Set(None) => true, AttributeMutation::Set(Some(_)) => { @@ -886,7 +883,7 @@ impl VirtualMethods for HTMLInputElement { el.set_read_write_state(read_write); } }, - &atom!("checked") if !self.checked_changed.get() => { + &local_name!("checked") if !self.checked_changed.get() => { let checked_state = match mutation { AttributeMutation::Set(None) => true, AttributeMutation::Set(Some(_)) => { @@ -897,13 +894,13 @@ impl VirtualMethods for HTMLInputElement { }; self.update_checked_state(checked_state, false); }, - &atom!("size") => { + &local_name!("size") => { let size = mutation.new_value(attr).map(|value| { value.as_uint() }); self.size.set(size.unwrap_or(DEFAULT_INPUT_SIZE)); } - &atom!("type") => { + &local_name!("type") => { let el = self.upcast::<Element>(); match mutation { AttributeMutation::Set(_) => { @@ -948,7 +945,7 @@ impl VirtualMethods for HTMLInputElement { // Step 2 (_, _, ValueMode::Value) if old_value_mode != ValueMode::Value => { self.SetValue(self.upcast::<Element>() - .get_attribute(&ns!(), &atom!("value")) + .get_attribute(&ns!(), &local_name!("value")) .map_or(DOMString::from(""), |a| DOMString::from(a.summarize().value))) .expect("Failed to set input value on type change to ValueMode::Value."); @@ -987,17 +984,17 @@ impl VirtualMethods for HTMLInputElement { self.update_placeholder_shown_state(); }, - &atom!("value") if !self.value_changed.get() => { + &local_name!("value") if !self.value_changed.get() => { let value = mutation.new_value(attr).map(|value| (**value).to_owned()); self.textinput.borrow_mut().set_content( value.map_or(DOMString::new(), DOMString::from)); self.update_placeholder_shown_state(); }, - &atom!("name") if self.input_type.get() == InputType::InputRadio => { + &local_name!("name") if self.input_type.get() == InputType::InputRadio => { self.radio_group_updated( mutation.new_value(attr).as_ref().map(|name| name.as_atom())); }, - &atom!("maxlength") => { + &local_name!("maxlength") => { match *attr.value() { AttrValue::Int(_, value) => { if value < 0 { @@ -1009,7 +1006,7 @@ impl VirtualMethods for HTMLInputElement { _ => panic!("Expected an AttrValue::Int"), } }, - &atom!("minlength") => { + &local_name!("minlength") => { match *attr.value() { AttrValue::Int(_, value) => { if value < 0 { @@ -1021,7 +1018,7 @@ impl VirtualMethods for HTMLInputElement { _ => panic!("Expected an AttrValue::Int"), } }, - &atom!("placeholder") => { + &local_name!("placeholder") => { { let mut placeholder = self.placeholder.borrow_mut(); placeholder.clear(); @@ -1032,7 +1029,7 @@ impl VirtualMethods for HTMLInputElement { } self.update_placeholder_shown_state(); }, - &atom!("readonly") if self.input_type.get() == InputType::InputText => { + &local_name!("readonly") if self.input_type.get() == InputType::InputText => { let el = self.upcast::<Element>(); match mutation { AttributeMutation::Set(_) => { @@ -1047,14 +1044,14 @@ impl VirtualMethods for HTMLInputElement { } } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("accept") => AttrValue::from_comma_separated_tokenlist(value.into()), - &atom!("name") => AttrValue::from_atomic(value.into()), - &atom!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE), - &atom!("type") => AttrValue::from_atomic(value.into()), - &atom!("maxlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MAX_LENGTH), - &atom!("minlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MIN_LENGTH), + &local_name!("accept") => AttrValue::from_comma_separated_tokenlist(value.into()), + &local_name!("name") => AttrValue::from_atomic(value.into()), + &local_name!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE), + &local_name!("type") => AttrValue::from_atomic(value.into()), + &local_name!("maxlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MAX_LENGTH), + &local_name!("minlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MIN_LENGTH), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } @@ -1289,12 +1286,8 @@ impl Activatable for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#radio-button-state-(type=radio):activation-behavior // Check if document owner is fully active let target = self.upcast::<EventTarget>(); - target.fire_event("input", - EventBubbles::Bubbles, - EventCancelable::NotCancelable); - target.fire_event("change", - EventBubbles::Bubbles, - EventCancelable::NotCancelable); + target.fire_bubbling_event(atom!("input")); + target.fire_bubbling_event(atom!("change")); }, InputType::InputFile => self.select_files(None), _ => () diff --git a/components/script/dom/htmllabelelement.rs b/components/script/dom/htmllabelelement.rs index 39869a50f49..5d954cfc5dd 100644 --- a/components/script/dom/htmllabelelement.rs +++ b/components/script/dom/htmllabelelement.rs @@ -16,7 +16,7 @@ use dom::htmlelement::HTMLElement; use dom::htmlformelement::{FormControl, HTMLFormElement}; use dom::node::{document_from_node, Node}; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::attr::AttrValue; #[dom_struct] @@ -25,7 +25,7 @@ pub struct HTMLLabelElement { } impl HTMLLabelElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLLabelElement { HTMLLabelElement { @@ -35,7 +35,7 @@ impl HTMLLabelElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLLabelElement> { Node::reflect_node(box HTMLLabelElement::new_inherited(local_name, prefix, document), @@ -102,7 +102,7 @@ impl HTMLLabelElementMethods for HTMLLabelElement { return None; } - let for_attr = match self.upcast::<Element>().get_attribute(&ns!(), &atom!("for")) { + let for_attr = match self.upcast::<Element>().get_attribute(&ns!(), &local_name!("for")) { Some(for_attr) => for_attr, None => return self.first_labelable_descendant(), }; @@ -121,9 +121,9 @@ impl VirtualMethods for HTMLLabelElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("for") => AttrValue::from_atomic(value.into()), + &local_name!("for") => AttrValue::from_atomic(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/htmllegendelement.rs b/components/script/dom/htmllegendelement.rs index e5c5e29aae2..0b9cbf3992c 100644 --- a/components/script/dom/htmllegendelement.rs +++ b/components/script/dom/htmllegendelement.rs @@ -15,7 +15,7 @@ use dom::htmlfieldsetelement::HTMLFieldSetElement; use dom::htmlformelement::{HTMLFormElement, FormControl}; use dom::node::{Node, UnbindContext}; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLLegendElement { @@ -23,7 +23,7 @@ pub struct HTMLLegendElement { } impl HTMLLegendElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLLegendElement { @@ -31,7 +31,7 @@ impl HTMLLegendElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLLegendElement> { diff --git a/components/script/dom/htmllielement.rs b/components/script/dom/htmllielement.rs index d08b677a947..4d17eb9376d 100644 --- a/components/script/dom/htmllielement.rs +++ b/components/script/dom/htmllielement.rs @@ -11,7 +11,7 @@ use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::attr::AttrValue; #[dom_struct] @@ -20,14 +20,14 @@ pub struct HTMLLIElement { } impl HTMLLIElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLLIElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLLIElement { HTMLLIElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLLIElement> { Node::reflect_node(box HTMLLIElement::new_inherited(local_name, prefix, document), @@ -49,9 +49,9 @@ impl VirtualMethods for HTMLLIElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("value") => AttrValue::from_i32(value.into(), 0), + &local_name!("value") => AttrValue::from_i32(value.into(), 0), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 903352338fc..ed8bc27ccdb 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -24,13 +24,13 @@ use dom::node::{Node, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; use encoding::EncodingRef; use encoding::all::UTF_8; +use html5ever_atoms::LocalName; use hyper::header::ContentType; use hyper::mime::{Mime, TopLevel, SubLevel}; use hyper_serde::Serde; use ipc_channel::ipc; use ipc_channel::router::ROUTER; -use msg::constellation_msg::ReferrerPolicy; -use net_traits::{FetchResponseListener, FetchMetadata, Metadata, NetworkError}; +use net_traits::{FetchResponseListener, FetchMetadata, Metadata, NetworkError, ReferrerPolicy}; use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType}; use network_listener::{NetworkListener, PreInvoke}; use script_layout_interface::message::Msg; @@ -41,7 +41,6 @@ use std::cell::Cell; use std::default::Default; use std::mem; use std::sync::{Arc, Mutex}; -use string_cache::Atom; use style::attr::AttrValue; use style::media_queries::{MediaQueryList, parse_media_query_list}; use style::parser::ParserContextExtraData; @@ -63,7 +62,7 @@ pub struct HTMLLinkElement { } impl HTMLLinkElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document, creator: ElementCreator) -> HTMLLinkElement { HTMLLinkElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), @@ -74,7 +73,7 @@ impl HTMLLinkElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document, creator: ElementCreator) -> Root<HTMLLinkElement> { @@ -88,7 +87,7 @@ impl HTMLLinkElement { } } -fn get_attr(element: &Element, local_name: &Atom) -> Option<String> { +fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> { let elem = element.get_attribute(&ns!(), local_name); elem.map(|e| { let value = e.value(); @@ -139,26 +138,26 @@ impl VirtualMethods for HTMLLinkElement { return; } - let rel = get_attr(self.upcast(), &atom!("rel")); + let rel = get_attr(self.upcast(), &local_name!("rel")); match attr.local_name() { - &atom!("href") => { + &local_name!("href") => { if string_is_stylesheet(&rel) { self.handle_stylesheet_url(&attr.value()); } else if is_favicon(&rel) { - let sizes = get_attr(self.upcast(), &atom!("sizes")); + let sizes = get_attr(self.upcast(), &local_name!("sizes")); self.handle_favicon_url(rel.as_ref().unwrap(), &attr.value(), &sizes); } }, - &atom!("sizes") => { + &local_name!("sizes") => { if is_favicon(&rel) { - if let Some(ref href) = get_attr(self.upcast(), &atom!("href")) { + if let Some(ref href) = get_attr(self.upcast(), &local_name!("href")) { self.handle_favicon_url(rel.as_ref().unwrap(), href, &Some(attr.value().to_string())); } } }, - &atom!("media") => { + &local_name!("media") => { if string_is_stylesheet(&rel) { - if let Some(href) = self.upcast::<Element>().get_attribute(&ns!(), &atom!("href")) { + if let Some(href) = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href")) { self.handle_stylesheet_url(&href.value()); } } @@ -167,9 +166,9 @@ impl VirtualMethods for HTMLLinkElement { } } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("rel") => AttrValue::from_serialized_tokenlist(value.into()), + &local_name!("rel") => AttrValue::from_serialized_tokenlist(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } @@ -182,9 +181,9 @@ impl VirtualMethods for HTMLLinkElement { if tree_in_doc { let element = self.upcast(); - let rel = get_attr(element, &atom!("rel")); - let href = get_attr(element, &atom!("href")); - let sizes = get_attr(self.upcast(), &atom!("sizes")); + let rel = get_attr(element, &local_name!("rel")); + let href = get_attr(element, &local_name!("href")); + let sizes = get_attr(self.upcast(), &local_name!("sizes")); match href { Some(ref href) if string_is_stylesheet(&rel) => { @@ -221,7 +220,7 @@ impl HTMLLinkElement { let element = self.upcast::<Element>(); - let mq_attribute = element.get_attribute(&ns!(), &atom!("media")); + let mq_attribute = element.get_attribute(&ns!(), &local_name!("media")); let value = mq_attribute.r().map(|a| a.value()); let mq_str = match value { Some(ref value) => &***value, @@ -325,7 +324,7 @@ impl FetchResponseListener for StylesheetContext { if let Some(ref meta) = self.metadata { if let Some(Serde(ContentType(Mime(TopLevel::Text, SubLevel::Css, _)))) = meta.content_type { } else { - self.elem.root().upcast::<EventTarget>().fire_simple_event("error"); + self.elem.root().upcast::<EventTarget>().fire_event(atom!("error")); } } } @@ -380,9 +379,9 @@ impl FetchResponseListener for StylesheetContext { document.finish_load(LoadType::Stylesheet(self.url.clone())); - let event = if successful { "load" } else { "error" }; + let event = if successful { atom!("load") } else { atom!("error") }; - elem.upcast::<EventTarget>().fire_simple_event(event); + elem.upcast::<EventTarget>().fire_event(event); } } @@ -398,7 +397,7 @@ impl HTMLLinkElementMethods for HTMLLinkElement { // https://html.spec.whatwg.org/multipage/#dom-link-rel fn SetRel(&self, rel: DOMString) { - self.upcast::<Element>().set_tokenlist_attribute(&atom!("rel"), rel); + self.upcast::<Element>().set_tokenlist_attribute(&local_name!("rel"), rel); } // https://html.spec.whatwg.org/multipage/#dom-link-media @@ -421,7 +420,7 @@ impl HTMLLinkElementMethods for HTMLLinkElement { // https://html.spec.whatwg.org/multipage/#dom-link-rellist fn RelList(&self) -> Root<DOMTokenList> { - self.rel_list.or_init(|| DOMTokenList::new(self.upcast(), &atom!("rel"))) + self.rel_list.or_init(|| DOMTokenList::new(self.upcast(), &local_name!("rel"))) } // https://html.spec.whatwg.org/multipage/#dom-link-charset diff --git a/components/script/dom/htmlmapelement.rs b/components/script/dom/htmlmapelement.rs index 5bf05ef7747..8ef091b0762 100644 --- a/components/script/dom/htmlmapelement.rs +++ b/components/script/dom/htmlmapelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLMapElement { @@ -16,7 +16,7 @@ pub struct HTMLMapElement { } impl HTMLMapElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLMapElement { HTMLMapElement { @@ -25,7 +25,7 @@ impl HTMLMapElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLMapElement> { Node::reflect_node(box HTMLMapElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index 203763d3e15..0627bcf0ffb 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -27,15 +27,16 @@ use dom::htmlvideoelement::HTMLVideoElement; use dom::mediaerror::MediaError; use dom::node::{window_from_node, document_from_node, Node, UnbindContext}; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use ipc_channel::ipc; use ipc_channel::router::ROUTER; use net_traits::{FetchResponseListener, FetchMetadata, Metadata, NetworkError}; use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType}; use network_listener::{NetworkListener, PreInvoke}; use script_thread::{Runnable, ScriptThread}; +use servo_atoms::Atom; use std::cell::Cell; use std::sync::{Arc, Mutex}; -use string_cache::Atom; use task_source::TaskSource; use time::{self, Timespec, Duration}; use url::Url; @@ -224,7 +225,7 @@ pub struct HTMLMediaElement { } impl HTMLMediaElement { - pub fn new_inherited(tag_name: Atom, + pub fn new_inherited(tag_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLMediaElement { HTMLMediaElement { @@ -443,7 +444,7 @@ impl HTMLMediaElement { let mode = if false { // TODO media provider object ResourceSelectionMode::Object - } else if let Some(attr) = self.upcast::<Element>().get_attribute(&ns!(), &atom!("src")) { + } else if let Some(attr) = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("src")) { ResourceSelectionMode::Attribute(attr.Value().to_string()) } else if false { // TODO <source> child @@ -770,7 +771,7 @@ impl VirtualMethods for HTMLMediaElement { self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("src") => { + &local_name!("src") => { if mutation.new_value(attr).is_some() { self.media_element_load_algorithm(); } diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs index 219b0cbce90..14f9cd78555 100644 --- a/components/script/dom/htmlmetaelement.rs +++ b/components/script/dom/htmlmetaelement.rs @@ -16,10 +16,10 @@ use dom::htmlelement::HTMLElement; use dom::htmlheadelement::HTMLHeadElement; use dom::node::{Node, UnbindContext, document_from_node}; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use parking_lot::RwLock; use std::ascii::AsciiExt; use std::sync::Arc; -use string_cache::Atom; use style::attr::AttrValue; use style::str::HTML_SPACE_CHARACTERS; use style::stylesheets::{Stylesheet, CSSRule, Origin}; @@ -33,7 +33,7 @@ pub struct HTMLMetaElement { } impl HTMLMetaElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLMetaElement { HTMLMetaElement { @@ -43,7 +43,7 @@ impl HTMLMetaElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLMetaElement> { Node::reflect_node(box HTMLMetaElement::new_inherited(local_name, prefix, document), @@ -57,7 +57,7 @@ impl HTMLMetaElement { fn process_attributes(&self) { let element = self.upcast::<Element>(); - if let Some(name) = element.get_attribute(&ns!(), &atom!("name")).r() { + if let Some(name) = element.get_attribute(&ns!(), &local_name!("name")).r() { let name = name.value().to_ascii_lowercase(); let name = name.trim_matches(HTML_SPACE_CHARACTERS); @@ -76,7 +76,7 @@ impl HTMLMetaElement { return; } let element = self.upcast::<Element>(); - if let Some(content) = element.get_attribute(&ns!(), &atom!("content")).r() { + if let Some(content) = element.get_attribute(&ns!(), &local_name!("content")).r() { let content = content.value(); if !content.is_empty() { if let Some(translated_rule) = ViewportRule::from_meta(&**content) { @@ -97,7 +97,7 @@ impl HTMLMetaElement { fn process_referrer_attribute(&self) { let element = self.upcast::<Element>(); - if let Some(name) = element.get_attribute(&ns!(), &atom!("name")).r() { + if let Some(name) = element.get_attribute(&ns!(), &local_name!("name")).r() { let name = name.value().to_ascii_lowercase(); let name = name.trim_matches(HTML_SPACE_CHARACTERS); @@ -146,9 +146,9 @@ impl VirtualMethods for HTMLMetaElement { } } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("name") => AttrValue::from_atomic(value.into()), + &local_name!("name") => AttrValue::from_atomic(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/htmlmeterelement.rs b/components/script/dom/htmlmeterelement.rs index 151ea555c1b..e323af1485b 100644 --- a/components/script/dom/htmlmeterelement.rs +++ b/components/script/dom/htmlmeterelement.rs @@ -10,7 +10,7 @@ use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; use dom::nodelist::NodeList; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLMeterElement { @@ -18,7 +18,7 @@ pub struct HTMLMeterElement { } impl HTMLMeterElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLMeterElement { HTMLMeterElement { @@ -27,7 +27,7 @@ impl HTMLMeterElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLMeterElement> { Node::reflect_node(box HTMLMeterElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlmodelement.rs b/components/script/dom/htmlmodelement.rs index 86357e820f4..6cd63d24505 100644 --- a/components/script/dom/htmlmodelement.rs +++ b/components/script/dom/htmlmodelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLModElement { @@ -16,7 +16,7 @@ pub struct HTMLModElement { } impl HTMLModElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLModElement { HTMLModElement { @@ -26,7 +26,7 @@ impl HTMLModElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLModElement> { Node::reflect_node(box HTMLModElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlobjectelement.rs b/components/script/dom/htmlobjectelement.rs index 6e82b9f9bd6..8e934b96808 100644 --- a/components/script/dom/htmlobjectelement.rs +++ b/components/script/dom/htmlobjectelement.rs @@ -17,9 +17,9 @@ use dom::node::{Node, window_from_node}; use dom::validation::Validatable; use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use net_traits::image::base::Image; use std::sync::Arc; -use string_cache::Atom; #[dom_struct] pub struct HTMLObjectElement { @@ -29,7 +29,7 @@ pub struct HTMLObjectElement { } impl HTMLObjectElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLObjectElement { HTMLObjectElement { @@ -40,7 +40,7 @@ impl HTMLObjectElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLObjectElement> { Node::reflect_node(box HTMLObjectElement::new_inherited(local_name, prefix, document), @@ -60,8 +60,8 @@ impl<'a> ProcessDataURL for &'a HTMLObjectElement { let elem = self.upcast::<Element>(); // TODO: support other values - match (elem.get_attribute(&ns!(), &atom!("type")), - elem.get_attribute(&ns!(), &atom!("data"))) { + match (elem.get_attribute(&ns!(), &local_name!("type")), + elem.get_attribute(&ns!(), &local_name!("data"))) { (None, Some(_uri)) => { // TODO(gw): Prefetch the image here. } @@ -99,7 +99,7 @@ impl VirtualMethods for HTMLObjectElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("data") => { + &local_name!("data") => { if let AttributeMutation::Set(_) = mutation { self.process_data_url(); } diff --git a/components/script/dom/htmlolistelement.rs b/components/script/dom/htmlolistelement.rs index 9447053e5e8..19c731bdc0a 100644 --- a/components/script/dom/htmlolistelement.rs +++ b/components/script/dom/htmlolistelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLOListElement { @@ -16,7 +16,7 @@ pub struct HTMLOListElement { } impl HTMLOListElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLOListElement { HTMLOListElement { @@ -25,7 +25,7 @@ impl HTMLOListElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLOListElement> { Node::reflect_node(box HTMLOListElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmloptgroupelement.rs b/components/script/dom/htmloptgroupelement.rs index 3d6f020e6f1..583c32337db 100644 --- a/components/script/dom/htmloptgroupelement.rs +++ b/components/script/dom/htmloptgroupelement.rs @@ -14,7 +14,7 @@ use dom::htmlelement::HTMLElement; use dom::htmloptionelement::HTMLOptionElement; use dom::node::Node; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::element_state::*; #[dom_struct] @@ -23,7 +23,7 @@ pub struct HTMLOptGroupElement { } impl HTMLOptGroupElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLOptGroupElement { HTMLOptGroupElement { @@ -34,7 +34,7 @@ impl HTMLOptGroupElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLOptGroupElement> { Node::reflect_node(box HTMLOptGroupElement::new_inherited(local_name, prefix, document), @@ -59,7 +59,7 @@ impl VirtualMethods for HTMLOptGroupElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("disabled") => { + &local_name!("disabled") => { let disabled_state = match mutation { AttributeMutation::Set(None) => true, AttributeMutation::Set(Some(_)) => { diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs index 1b27a10b311..d1576d532e3 100644 --- a/components/script/dom/htmloptionelement.rs +++ b/components/script/dom/htmloptionelement.rs @@ -22,8 +22,8 @@ use dom::htmlselectelement::HTMLSelectElement; use dom::node::{Node, UnbindContext}; use dom::text::Text; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use std::cell::Cell; -use string_cache::Atom; use style::element_state::*; use style::str::{split_html_space_chars, str_join}; @@ -39,7 +39,7 @@ pub struct HTMLOptionElement { } impl HTMLOptionElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLOptionElement { HTMLOptionElement { @@ -52,7 +52,7 @@ impl HTMLOptionElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLOptionElement> { Node::reflect_node(box HTMLOptionElement::new_inherited(local_name, prefix, document), @@ -82,7 +82,7 @@ impl HTMLOptionElement { // FIXME(ajeffrey): Provide a way of buffering DOMStrings other than using Strings fn collect_text(element: &Element, value: &mut String) { - let svg_script = *element.namespace() == ns!(svg) && element.local_name() == &atom!("script"); + let svg_script = *element.namespace() == ns!(svg) && element.local_name() == &local_name!("script"); let html_script = element.is::<HTMLScriptElement>(); if svg_script || html_script { return; @@ -133,7 +133,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement { // https://html.spec.whatwg.org/multipage/#attr-option-value fn Value(&self) -> DOMString { let element = self.upcast::<Element>(); - let attr = &atom!("value"); + let attr = &local_name!("value"); if element.has_attribute(attr) { element.get_string_attribute(attr) } else { @@ -147,7 +147,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement { // https://html.spec.whatwg.org/multipage/#attr-option-label fn Label(&self) -> DOMString { let element = self.upcast::<Element>(); - let attr = &atom!("label"); + let attr = &local_name!("label"); if element.has_attribute(attr) { element.get_string_attribute(attr) } else { @@ -185,7 +185,7 @@ impl VirtualMethods for HTMLOptionElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("disabled") => { + &local_name!("disabled") => { let el = self.upcast::<Element>(); match mutation { AttributeMutation::Set(_) => { @@ -199,7 +199,7 @@ impl VirtualMethods for HTMLOptionElement { } } }, - &atom!("selected") => { + &local_name!("selected") => { match mutation { AttributeMutation::Set(_) => { // https://html.spec.whatwg.org/multipage/#concept-option-selectedness diff --git a/components/script/dom/htmloptionscollection.rs b/components/script/dom/htmloptionscollection.rs index 033868f2af8..2e4ce0f9a37 100644 --- a/components/script/dom/htmloptionscollection.rs +++ b/components/script/dom/htmloptionscollection.rs @@ -44,7 +44,7 @@ impl HTMLOptionsCollection { let document = document_from_node(&*root); for _ in 0..count { - let element = HTMLOptionElement::new(atom!("option"), None, &document); + let element = HTMLOptionElement::new(local_name!("option"), None, &document); let node = element.upcast::<Node>(); try!(root.AppendChild(node)); }; diff --git a/components/script/dom/htmloutputelement.rs b/components/script/dom/htmloutputelement.rs index 29b69f31cf2..16af40f12cc 100644 --- a/components/script/dom/htmloutputelement.rs +++ b/components/script/dom/htmloutputelement.rs @@ -13,7 +13,7 @@ use dom::htmlformelement::{FormControl, HTMLFormElement}; use dom::node::{Node, window_from_node}; use dom::nodelist::NodeList; use dom::validitystate::ValidityState; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLOutputElement { @@ -21,7 +21,7 @@ pub struct HTMLOutputElement { } impl HTMLOutputElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLOutputElement { HTMLOutputElement { @@ -31,7 +31,7 @@ impl HTMLOutputElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLOutputElement> { Node::reflect_node(box HTMLOutputElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlparagraphelement.rs b/components/script/dom/htmlparagraphelement.rs index f437b429b9c..f3976d8d202 100644 --- a/components/script/dom/htmlparagraphelement.rs +++ b/components/script/dom/htmlparagraphelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLParagraphElement { @@ -16,7 +16,7 @@ pub struct HTMLParagraphElement { } impl HTMLParagraphElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLParagraphElement { HTMLParagraphElement { @@ -26,7 +26,7 @@ impl HTMLParagraphElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLParagraphElement> { Node::reflect_node(box HTMLParagraphElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlparamelement.rs b/components/script/dom/htmlparamelement.rs index 8a335a90bec..d27a85bc8bd 100644 --- a/components/script/dom/htmlparamelement.rs +++ b/components/script/dom/htmlparamelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLParamElement { @@ -16,7 +16,7 @@ pub struct HTMLParamElement { } impl HTMLParamElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLParamElement { HTMLParamElement { @@ -26,7 +26,7 @@ impl HTMLParamElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLParamElement> { Node::reflect_node(box HTMLParamElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlpreelement.rs b/components/script/dom/htmlpreelement.rs index 599d9731e2e..cfe9de10999 100644 --- a/components/script/dom/htmlpreelement.rs +++ b/components/script/dom/htmlpreelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLPreElement { @@ -16,7 +16,7 @@ pub struct HTMLPreElement { } impl HTMLPreElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLPreElement { HTMLPreElement { @@ -26,7 +26,7 @@ impl HTMLPreElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLPreElement> { Node::reflect_node(box HTMLPreElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlprogresselement.rs b/components/script/dom/htmlprogresselement.rs index 81275b9fe72..258527ac368 100644 --- a/components/script/dom/htmlprogresselement.rs +++ b/components/script/dom/htmlprogresselement.rs @@ -10,7 +10,7 @@ use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; use dom::nodelist::NodeList; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLProgressElement { @@ -18,7 +18,7 @@ pub struct HTMLProgressElement { } impl HTMLProgressElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLProgressElement { HTMLProgressElement { @@ -28,7 +28,7 @@ impl HTMLProgressElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLProgressElement> { Node::reflect_node(box HTMLProgressElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlquoteelement.rs b/components/script/dom/htmlquoteelement.rs index d72f8dc67bd..72e0329fe17 100644 --- a/components/script/dom/htmlquoteelement.rs +++ b/components/script/dom/htmlquoteelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLQuoteElement { @@ -16,7 +16,7 @@ pub struct HTMLQuoteElement { } impl HTMLQuoteElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLQuoteElement { HTMLQuoteElement { @@ -26,7 +26,7 @@ impl HTMLQuoteElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLQuoteElement> { Node::reflect_node(box HTMLQuoteElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index d441d840d90..3b2057e4338 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -28,16 +28,17 @@ use dom::virtualmethods::VirtualMethods; use encoding::label::encoding_from_whatwg_label; use encoding::types::{DecoderTrap, EncodingRef}; use html5ever::tree_builder::NextParserState; +use html5ever_atoms::LocalName; use ipc_channel::ipc; use ipc_channel::router::ROUTER; use js::jsval::UndefinedValue; use net_traits::{FetchMetadata, FetchResponseListener, Metadata, NetworkError}; use net_traits::request::{CORSSettings, CredentialsMode, Destination, RequestInit, RequestMode, Type as RequestType}; use network_listener::{NetworkListener, PreInvoke}; +use servo_atoms::Atom; use std::ascii::AsciiExt; use std::cell::Cell; use std::sync::{Arc, Mutex}; -use string_cache::Atom; use style::str::{HTML_SPACE_CHARACTERS, StaticStringVec}; use url::Url; @@ -67,7 +68,7 @@ pub struct HTMLScriptElement { } impl HTMLScriptElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document, creator: ElementCreator) -> HTMLScriptElement { HTMLScriptElement { htmlelement: @@ -82,7 +83,7 @@ impl HTMLScriptElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document, creator: ElementCreator) -> Root<HTMLScriptElement> { Node::reflect_node(box HTMLScriptElement::new_inherited(local_name, prefix, document, creator), document, @@ -286,7 +287,7 @@ impl HTMLScriptElement { // Step 3. let element = self.upcast::<Element>(); - let async = element.has_attribute(&atom!("async")); + let async = element.has_attribute(&local_name!("async")); // Note: confusingly, this is done if the element does *not* have an "async" attribute. if was_parser_inserted && !async { self.non_blocking.set(true); @@ -294,7 +295,7 @@ impl HTMLScriptElement { // Step 4. let text = self.Text(); - if text.is_empty() && !element.has_attribute(&atom!("src")) { + if text.is_empty() && !element.has_attribute(&local_name!("src")) { return NextParserState::Continue; } @@ -331,8 +332,8 @@ impl HTMLScriptElement { // TODO(#4577): Step 11: CSP. // Step 12. - let for_attribute = element.get_attribute(&ns!(), &atom!("for")); - let event_attribute = element.get_attribute(&ns!(), &atom!("event")); + let for_attribute = element.get_attribute(&ns!(), &local_name!("for")); + let event_attribute = element.get_attribute(&ns!(), &local_name!("event")); match (for_attribute.r(), event_attribute.r()) { (Some(for_attribute), Some(event_attribute)) => { let for_value = for_attribute.value().to_ascii_lowercase(); @@ -351,7 +352,7 @@ impl HTMLScriptElement { } // Step 13. - let encoding = element.get_attribute(&ns!(), &atom!("charset")) + let encoding = element.get_attribute(&ns!(), &local_name!("charset")) .and_then(|charset| encoding_from_whatwg_label(&charset.value())) .unwrap_or_else(|| doc.encoding()); @@ -370,7 +371,7 @@ impl HTMLScriptElement { // TODO: Step 17: environment settings object. let base_url = doc.base_url(); - let is_external = match element.get_attribute(&ns!(), &atom!("src")) { + let is_external = match element.get_attribute(&ns!(), &local_name!("src")) { // Step 18. Some(ref src) => { // Step 18.1. @@ -402,7 +403,7 @@ impl HTMLScriptElement { }; // Step 20. - let deferred = element.has_attribute(&atom!("defer")); + let deferred = element.has_attribute(&local_name!("defer")); // Step 20.a: classic, has src, has defer, was parser-inserted, is not async. if is_external && deferred && @@ -555,7 +556,7 @@ impl HTMLScriptElement { pub fn is_javascript(&self) -> bool { let element = self.upcast::<Element>(); - let type_attr = element.get_attribute(&ns!(), &atom!("type")); + let type_attr = element.get_attribute(&ns!(), &local_name!("type")); let is_js = match type_attr.as_ref().map(|s| s.value()) { Some(ref s) if s.is_empty() => { // type attr exists, but empty means js @@ -568,7 +569,7 @@ impl HTMLScriptElement { }, None => { debug!("no script type"); - let language_attr = element.get_attribute(&ns!(), &atom!("language")); + let language_attr = element.get_attribute(&ns!(), &local_name!("language")); let is_js = match language_attr.as_ref().map(|s| s.value()) { Some(ref s) if s.is_empty() => { debug!("script language empty, inferring js"); @@ -615,7 +616,7 @@ impl VirtualMethods for HTMLScriptElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match *attr.local_name() { - atom!("src") => { + local_name!("src") => { if let AttributeMutation::Set(_) = mutation { if !self.parser_inserted.get() && self.upcast::<Node>().is_in_doc() { self.prepare(); @@ -692,7 +693,7 @@ impl HTMLScriptElementMethods for HTMLScriptElement { // https://html.spec.whatwg.org/multipage/#dom-script-crossorigin fn GetCrossOrigin(&self) -> Option<DOMString> { let element = self.upcast::<Element>(); - let attr = element.get_attribute(&ns!(), &atom!("crossorigin")); + let attr = element.get_attribute(&ns!(), &local_name!("crossorigin")); if let Some(mut val) = attr.map(|v| v.Value()) { val.make_ascii_lowercase(); @@ -708,9 +709,9 @@ impl HTMLScriptElementMethods for HTMLScriptElement { fn SetCrossOrigin(&self, value: Option<DOMString>) { let element = self.upcast::<Element>(); match value { - Some(val) => element.set_string_attribute(&atom!("crossorigin"), val), + Some(val) => element.set_string_attribute(&local_name!("crossorigin"), val), None => { - element.remove_attribute(&ns!(), &atom!("crossorigin")); + element.remove_attribute(&ns!(), &local_name!("crossorigin")); } } } diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs index c44dac71000..8a5f2529d6a 100644 --- a/components/script/dom/htmlselectelement.rs +++ b/components/script/dom/htmlselectelement.rs @@ -30,7 +30,7 @@ use dom::nodelist::NodeList; use dom::validation::Validatable; use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::attr::AttrValue; use style::element_state::*; @@ -64,7 +64,7 @@ pub struct HTMLSelectElement { static DEFAULT_SELECT_SIZE: u32 = 0; impl HTMLSelectElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLSelectElement { HTMLSelectElement { @@ -76,7 +76,7 @@ impl HTMLSelectElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLSelectElement> { Node::reflect_node(box HTMLSelectElement::new_inherited(local_name, prefix, document), @@ -338,7 +338,7 @@ impl VirtualMethods for HTMLSelectElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); - if attr.local_name() == &atom!("disabled") { + if attr.local_name() == &local_name!("disabled") { let el = self.upcast::<Element>(); match mutation { AttributeMutation::Set(_) => { @@ -374,9 +374,9 @@ impl VirtualMethods for HTMLSelectElement { } } - fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue { match *local_name { - atom!("size") => AttrValue::from_u32(value.into(), DEFAULT_SELECT_SIZE), + local_name!("size") => AttrValue::from_u32(value.into(), DEFAULT_SELECT_SIZE), _ => self.super_type().unwrap().parse_plain_attribute(local_name, value), } } diff --git a/components/script/dom/htmlsourceelement.rs b/components/script/dom/htmlsourceelement.rs index 3e1b878b802..a5c93ba2b8f 100644 --- a/components/script/dom/htmlsourceelement.rs +++ b/components/script/dom/htmlsourceelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLSourceElement { @@ -16,7 +16,7 @@ pub struct HTMLSourceElement { } impl HTMLSourceElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLSourceElement { HTMLSourceElement { @@ -26,7 +26,7 @@ impl HTMLSourceElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLSourceElement> { Node::reflect_node(box HTMLSourceElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlspanelement.rs b/components/script/dom/htmlspanelement.rs index d8fb4554b49..cc8127d651a 100644 --- a/components/script/dom/htmlspanelement.rs +++ b/components/script/dom/htmlspanelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLSpanElement { @@ -16,14 +16,14 @@ pub struct HTMLSpanElement { } impl HTMLSpanElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLSpanElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLSpanElement { HTMLSpanElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLSpanElement> { Node::reflect_node(box HTMLSpanElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index 63884305010..34d5ba79ec9 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -14,9 +14,9 @@ use dom::element::Element; use dom::htmlelement::HTMLElement; use dom::node::{ChildrenMutation, Node, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use script_layout_interface::message::Msg; use std::sync::Arc; -use string_cache::Atom; use style::media_queries::parse_media_query_list; use style::parser::ParserContextExtraData; use style::stylesheets::{Stylesheet, Origin}; @@ -29,7 +29,7 @@ pub struct HTMLStyleElement { } impl HTMLStyleElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLStyleElement { HTMLStyleElement { @@ -39,7 +39,7 @@ impl HTMLStyleElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLStyleElement> { Node::reflect_node(box HTMLStyleElement::new_inherited(local_name, prefix, document), @@ -55,7 +55,7 @@ impl HTMLStyleElement { let win = window_from_node(node); let url = win.get_url(); - let mq_attribute = element.get_attribute(&ns!(), &atom!("media")); + let mq_attribute = element.get_attribute(&ns!(), &local_name!("media")); let mq_str = match mq_attribute { Some(a) => String::from(&**a.value()), None => String::new(), diff --git a/components/script/dom/htmltablecaptionelement.rs b/components/script/dom/htmltablecaptionelement.rs index 89c5f8307c9..e6ced76b973 100644 --- a/components/script/dom/htmltablecaptionelement.rs +++ b/components/script/dom/htmltablecaptionelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLTableCaptionElement { @@ -16,7 +16,7 @@ pub struct HTMLTableCaptionElement { } impl HTMLTableCaptionElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTableCaptionElement { HTMLTableCaptionElement { @@ -26,7 +26,7 @@ impl HTMLTableCaptionElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTableCaptionElement> { Node::reflect_node(box HTMLTableCaptionElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs index 5c30132b7f9..1ec389d9977 100644 --- a/components/script/dom/htmltablecellelement.rs +++ b/components/script/dom/htmltablecellelement.rs @@ -14,7 +14,7 @@ use dom::htmlelement::HTMLElement; use dom::htmltablerowelement::HTMLTableRowElement; use dom::node::Node; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; const DEFAULT_COLSPAN: u32 = 1; @@ -25,7 +25,7 @@ pub struct HTMLTableCellElement { } impl HTMLTableCellElement { - pub fn new_inherited(tag_name: Atom, + pub fn new_inherited(tag_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTableCellElement { @@ -88,7 +88,7 @@ impl HTMLTableCellElementLayoutHelpers for LayoutJS<HTMLTableCellElement> { fn get_background_color(&self) -> Option<RGBA> { unsafe { (&*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("bgcolor")) + .get_attr_for_layout(&ns!(), &local_name!("bgcolor")) .and_then(AttrValue::as_color) .cloned() } @@ -97,7 +97,7 @@ impl HTMLTableCellElementLayoutHelpers for LayoutJS<HTMLTableCellElement> { fn get_colspan(&self) -> Option<u32> { unsafe { (&*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("colspan")) + .get_attr_for_layout(&ns!(), &local_name!("colspan")) .map(AttrValue::as_uint) } } @@ -105,7 +105,7 @@ impl HTMLTableCellElementLayoutHelpers for LayoutJS<HTMLTableCellElement> { fn get_width(&self) -> LengthOrPercentageOrAuto { unsafe { (&*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("width")) + .get_attr_for_layout(&ns!(), &local_name!("width")) .map(AttrValue::as_dimension) .cloned() .unwrap_or(LengthOrPercentageOrAuto::Auto) @@ -118,11 +118,11 @@ impl VirtualMethods for HTMLTableCellElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue { match *local_name { - atom!("colspan") => AttrValue::from_u32(value.into(), DEFAULT_COLSPAN), - atom!("bgcolor") => AttrValue::from_legacy_color(value.into()), - atom!("width") => AttrValue::from_nonzero_dimension(value.into()), + local_name!("colspan") => AttrValue::from_u32(value.into(), DEFAULT_COLSPAN), + local_name!("bgcolor") => AttrValue::from_legacy_color(value.into()), + local_name!("width") => AttrValue::from_nonzero_dimension(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(local_name, value), } } diff --git a/components/script/dom/htmltablecolelement.rs b/components/script/dom/htmltablecolelement.rs index 38f839a811e..cad7ecffbcd 100644 --- a/components/script/dom/htmltablecolelement.rs +++ b/components/script/dom/htmltablecolelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLTableColElement { @@ -16,7 +16,7 @@ pub struct HTMLTableColElement { } impl HTMLTableColElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTableColElement { HTMLTableColElement { @@ -26,7 +26,7 @@ impl HTMLTableColElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTableColElement> { Node::reflect_node(box HTMLTableColElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmltabledatacellelement.rs b/components/script/dom/htmltabledatacellelement.rs index 989aa0e12fe..da723fe10e1 100644 --- a/components/script/dom/htmltabledatacellelement.rs +++ b/components/script/dom/htmltabledatacellelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmltablecellelement::HTMLTableCellElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLTableDataCellElement { @@ -16,7 +16,7 @@ pub struct HTMLTableDataCellElement { } impl HTMLTableDataCellElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTableDataCellElement { HTMLTableDataCellElement { @@ -26,7 +26,7 @@ impl HTMLTableDataCellElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document) + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTableDataCellElement> { Node::reflect_node(box HTMLTableDataCellElement::new_inherited(local_name, prefix, diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index c3ef9eaf842..e533c9acdcd 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -22,8 +22,8 @@ use dom::htmltablerowelement::HTMLTableRowElement; use dom::htmltablesectionelement::HTMLTableSectionElement; use dom::node::{Node, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use std::cell::Cell; -use string_cache::Atom; use style::attr::{AttrValue, LengthOrPercentageOrAuto, parse_unsigned_integer}; #[dom_struct] @@ -49,7 +49,7 @@ impl CollectionFilter for TableRowFilter { } impl HTMLTableElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTableElement { HTMLTableElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), @@ -60,7 +60,7 @@ impl HTMLTableElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document) + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTableElement> { Node::reflect_node(box HTMLTableElement::new_inherited(local_name, prefix, document), document, @@ -73,7 +73,7 @@ impl HTMLTableElement { // https://html.spec.whatwg.org/multipage/#dom-table-thead // https://html.spec.whatwg.org/multipage/#dom-table-tfoot - fn get_first_section_of_type(&self, atom: &Atom) -> Option<Root<HTMLTableSectionElement>> { + fn get_first_section_of_type(&self, atom: &LocalName) -> Option<Root<HTMLTableSectionElement>> { self.upcast::<Node>() .child_elements() .find(|n| n.is::<HTMLTableSectionElement>() && n.local_name() == atom) @@ -83,7 +83,7 @@ impl HTMLTableElement { // https://html.spec.whatwg.org/multipage/#dom-table-thead // https://html.spec.whatwg.org/multipage/#dom-table-tfoot fn set_first_section_of_type<P>(&self, - atom: &Atom, + atom: &LocalName, section: Option<&HTMLTableSectionElement>, reference_predicate: P) -> ErrorResult @@ -110,7 +110,7 @@ impl HTMLTableElement { // https://html.spec.whatwg.org/multipage/#dom-table-createthead // https://html.spec.whatwg.org/multipage/#dom-table-createtfoot - fn create_section_of_type(&self, atom: &Atom) -> Root<HTMLTableSectionElement> { + fn create_section_of_type(&self, atom: &LocalName) -> Root<HTMLTableSectionElement> { if let Some(section) = self.get_first_section_of_type(atom) { return section } @@ -119,8 +119,8 @@ impl HTMLTableElement { None, &document_from_node(self)); match atom { - &atom!("thead") => self.SetTHead(Some(§ion)), - &atom!("tfoot") => self.SetTFoot(Some(§ion)), + &local_name!("thead") => self.SetTHead(Some(§ion)), + &local_name!("tfoot") => self.SetTFoot(Some(§ion)), _ => unreachable!("unexpected section type") }.expect("unexpected section type"); @@ -129,7 +129,7 @@ impl HTMLTableElement { // https://html.spec.whatwg.org/multipage/#dom-table-deletethead // https://html.spec.whatwg.org/multipage/#dom-table-deletetfoot - fn delete_first_section_of_type(&self, atom: &Atom) { + fn delete_first_section_of_type(&self, atom: &LocalName) { if let Some(thead) = self.get_first_section_of_type(atom) { thead.upcast::<Node>().remove_self(); } @@ -176,7 +176,7 @@ impl HTMLTableElementMethods for HTMLTableElement { match self.GetCaption() { Some(caption) => caption, None => { - let caption = HTMLTableCaptionElement::new(atom!("caption"), + let caption = HTMLTableCaptionElement::new(local_name!("caption"), None, &document_from_node(self)); self.SetCaption(Some(&caption)); @@ -195,41 +195,41 @@ impl HTMLTableElementMethods for HTMLTableElement { // https://html.spec.whatwg.org/multipage/#dom-table-thead fn GetTHead(&self) -> Option<Root<HTMLTableSectionElement>> { - self.get_first_section_of_type(&atom!("thead")) + self.get_first_section_of_type(&local_name!("thead")) } // https://html.spec.whatwg.org/multipage/#dom-table-thead fn SetTHead(&self, thead: Option<&HTMLTableSectionElement>) -> ErrorResult { - self.set_first_section_of_type(&atom!("thead"), thead, |n| { + self.set_first_section_of_type(&local_name!("thead"), thead, |n| { !n.is::<HTMLTableCaptionElement>() && !n.is::<HTMLTableColElement>() }) } // https://html.spec.whatwg.org/multipage/#dom-table-createthead fn CreateTHead(&self) -> Root<HTMLTableSectionElement> { - self.create_section_of_type(&atom!("thead")) + self.create_section_of_type(&local_name!("thead")) } // https://html.spec.whatwg.org/multipage/#dom-table-deletethead fn DeleteTHead(&self) { - self.delete_first_section_of_type(&atom!("thead")) + self.delete_first_section_of_type(&local_name!("thead")) } // https://html.spec.whatwg.org/multipage/#dom-table-tfoot fn GetTFoot(&self) -> Option<Root<HTMLTableSectionElement>> { - self.get_first_section_of_type(&atom!("tfoot")) + self.get_first_section_of_type(&local_name!("tfoot")) } // https://html.spec.whatwg.org/multipage/#dom-table-tfoot fn SetTFoot(&self, tfoot: Option<&HTMLTableSectionElement>) -> ErrorResult { - self.set_first_section_of_type(&atom!("tfoot"), tfoot, |n| { + self.set_first_section_of_type(&local_name!("tfoot"), tfoot, |n| { if n.is::<HTMLTableCaptionElement>() || n.is::<HTMLTableColElement>() { return false; } if n.is::<HTMLTableSectionElement>() { let name = n.local_name(); - if name == &atom!("thead") || name == &atom!("tbody") { + if name == &local_name!("thead") || name == &local_name!("tbody") { return false; } @@ -241,12 +241,12 @@ impl HTMLTableElementMethods for HTMLTableElement { // https://html.spec.whatwg.org/multipage/#dom-table-createtfoot fn CreateTFoot(&self) -> Root<HTMLTableSectionElement> { - self.create_section_of_type(&atom!("tfoot")) + self.create_section_of_type(&local_name!("tfoot")) } // https://html.spec.whatwg.org/multipage/#dom-table-deletetfoot fn DeleteTFoot(&self) { - self.delete_first_section_of_type(&atom!("tfoot")) + self.delete_first_section_of_type(&local_name!("tfoot")) } // https://html.spec.whatwg.org/multipage/#dom-table-tbodies @@ -256,7 +256,7 @@ impl HTMLTableElementMethods for HTMLTableElement { impl CollectionFilter for TBodiesFilter { fn filter(&self, elem: &Element, root: &Node) -> bool { elem.is::<HTMLTableSectionElement>() && - elem.local_name() == &atom!("tbody") && + elem.local_name() == &local_name!("tbody") && elem.upcast::<Node>().GetParentNode().r() == Some(root) } } @@ -271,14 +271,14 @@ impl HTMLTableElementMethods for HTMLTableElement { // https://html.spec.whatwg.org/multipage/#dom-table-createtbody fn CreateTBody(&self) -> Root<HTMLTableSectionElement> { - let tbody = HTMLTableSectionElement::new(atom!("tbody"), + let tbody = HTMLTableSectionElement::new(local_name!("tbody"), None, &document_from_node(self)); let node = self.upcast::<Node>(); let last_tbody = node.rev_children() .filter_map(Root::downcast::<Element>) - .find(|n| n.is::<HTMLTableSectionElement>() && n.local_name() == &atom!("tbody")); + .find(|n| n.is::<HTMLTableSectionElement>() && n.local_name() == &local_name!("tbody")); let reference_element = last_tbody.and_then(|t| t.upcast::<Node>().GetNextSibling()); @@ -296,7 +296,7 @@ impl HTMLTableElementMethods for HTMLTableElement { return Err(Error::IndexSize); } - let new_row = HTMLTableRowElement::new(atom!("tr"), + let new_row = HTMLTableRowElement::new(local_name!("tr"), None, &document_from_node(self)); let node = self.upcast::<Node>(); @@ -305,7 +305,7 @@ impl HTMLTableElementMethods for HTMLTableElement { // append new row to last or new tbody in table if let Some(last_tbody) = node.rev_children() .filter_map(Root::downcast::<Element>) - .find(|n| n.is::<HTMLTableSectionElement>() && n.local_name() == &atom!("tbody")) { + .find(|n| n.is::<HTMLTableSectionElement>() && n.local_name() == &local_name!("tbody")) { last_tbody.upcast::<Node>().AppendChild(new_row.upcast::<Node>()) .expect("InsertRow failed to append first row."); } else { @@ -383,7 +383,7 @@ impl HTMLTableElementLayoutHelpers for LayoutJS<HTMLTableElement> { fn get_background_color(&self) -> Option<RGBA> { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("bgcolor")) + .get_attr_for_layout(&ns!(), &local_name!("bgcolor")) .and_then(AttrValue::as_color) .cloned() } @@ -407,7 +407,7 @@ impl HTMLTableElementLayoutHelpers for LayoutJS<HTMLTableElement> { fn get_width(&self) -> LengthOrPercentageOrAuto { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("width")) + .get_attr_for_layout(&ns!(), &local_name!("width")) .map(AttrValue::as_dimension) .cloned() .unwrap_or(LengthOrPercentageOrAuto::Auto) @@ -423,13 +423,13 @@ impl VirtualMethods for HTMLTableElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match *attr.local_name() { - atom!("border") => { + local_name!("border") => { // According to HTML5 § 14.3.9, invalid values map to 1px. self.border.set(mutation.new_value(attr).map(|value| { parse_unsigned_integer(value.chars()).unwrap_or(1) })); } - atom!("cellspacing") => { + local_name!("cellspacing") => { self.cellspacing.set(mutation.new_value(attr).and_then(|value| { parse_unsigned_integer(value.chars()).ok() })); @@ -438,11 +438,11 @@ impl VirtualMethods for HTMLTableElement { } } - fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue { match *local_name { - atom!("border") => AttrValue::from_u32(value.into(), 1), - atom!("width") => AttrValue::from_nonzero_dimension(value.into()), - atom!("bgcolor") => AttrValue::from_legacy_color(value.into()), + local_name!("border") => AttrValue::from_u32(value.into(), 1), + local_name!("width") => AttrValue::from_nonzero_dimension(value.into()), + local_name!("bgcolor") => AttrValue::from_legacy_color(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(local_name, value), } } diff --git a/components/script/dom/htmltableheadercellelement.rs b/components/script/dom/htmltableheadercellelement.rs index 9e0247f0f1b..c24c68479c8 100644 --- a/components/script/dom/htmltableheadercellelement.rs +++ b/components/script/dom/htmltableheadercellelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmltablecellelement::HTMLTableCellElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLTableHeaderCellElement { @@ -16,7 +16,7 @@ pub struct HTMLTableHeaderCellElement { } impl HTMLTableHeaderCellElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTableHeaderCellElement { HTMLTableHeaderCellElement { @@ -26,7 +26,7 @@ impl HTMLTableHeaderCellElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTableHeaderCellElement> { Node::reflect_node(box HTMLTableHeaderCellElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmltablerowelement.rs b/components/script/dom/htmltablerowelement.rs index 7a7273c3597..b95aba1c3e0 100644 --- a/components/script/dom/htmltablerowelement.rs +++ b/components/script/dom/htmltablerowelement.rs @@ -21,7 +21,7 @@ use dom::htmltableheadercellelement::HTMLTableHeaderCellElement; use dom::htmltablesectionelement::HTMLTableSectionElement; use dom::node::{Node, window_from_node}; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::attr::AttrValue; #[derive(JSTraceable)] @@ -40,7 +40,7 @@ pub struct HTMLTableRowElement { } impl HTMLTableRowElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTableRowElement { HTMLTableRowElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), @@ -49,7 +49,7 @@ impl HTMLTableRowElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document) + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTableRowElement> { Node::reflect_node(box HTMLTableRowElement::new_inherited(local_name, prefix, document), document, @@ -87,7 +87,7 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement { node.insert_cell_or_row( index, || self.Cells(), - || HTMLTableDataCellElement::new(atom!("td"), None, &node.owner_doc())) + || HTMLTableDataCellElement::new(local_name!("td"), None, &node.owner_doc())) } // https://html.spec.whatwg.org/multipage/#dom-tr-deletecell @@ -145,7 +145,7 @@ impl HTMLTableRowElementLayoutHelpers for LayoutJS<HTMLTableRowElement> { fn get_background_color(&self) -> Option<RGBA> { unsafe { (&*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("bgcolor")) + .get_attr_for_layout(&ns!(), &local_name!("bgcolor")) .and_then(AttrValue::as_color) .cloned() } @@ -157,9 +157,9 @@ impl VirtualMethods for HTMLTableRowElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue { match *local_name { - atom!("bgcolor") => AttrValue::from_legacy_color(value.into()), + local_name!("bgcolor") => AttrValue::from_legacy_color(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(local_name, value), } } diff --git a/components/script/dom/htmltablesectionelement.rs b/components/script/dom/htmltablesectionelement.rs index a64ae3fa35c..2f5fcaca566 100644 --- a/components/script/dom/htmltablesectionelement.rs +++ b/components/script/dom/htmltablesectionelement.rs @@ -16,7 +16,7 @@ use dom::htmlelement::HTMLElement; use dom::htmltablerowelement::HTMLTableRowElement; use dom::node::{Node, window_from_node}; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::attr::AttrValue; #[dom_struct] @@ -25,7 +25,7 @@ pub struct HTMLTableSectionElement { } impl HTMLTableSectionElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTableSectionElement { HTMLTableSectionElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), @@ -33,7 +33,7 @@ impl HTMLTableSectionElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document) + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTableSectionElement> { Node::reflect_node(box HTMLTableSectionElement::new_inherited(local_name, prefix, document), document, @@ -62,7 +62,7 @@ impl HTMLTableSectionElementMethods for HTMLTableSectionElement { node.insert_cell_or_row( index, || self.Rows(), - || HTMLTableRowElement::new(atom!("tr"), None, &node.owner_doc())) + || HTMLTableRowElement::new(local_name!("tr"), None, &node.owner_doc())) } // https://html.spec.whatwg.org/multipage/#dom-tbody-deleterow @@ -84,7 +84,7 @@ impl HTMLTableSectionElementLayoutHelpers for LayoutJS<HTMLTableSectionElement> fn get_background_color(&self) -> Option<RGBA> { unsafe { (&*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("bgcolor")) + .get_attr_for_layout(&ns!(), &local_name!("bgcolor")) .and_then(AttrValue::as_color) .cloned() } @@ -96,9 +96,9 @@ impl VirtualMethods for HTMLTableSectionElement { Some(self.upcast::<HTMLElement>() as &VirtualMethods) } - fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue { match *local_name { - atom!("bgcolor") => AttrValue::from_legacy_color(value.into()), + local_name!("bgcolor") => AttrValue::from_legacy_color(value.into()), _ => self.super_type().unwrap().parse_plain_attribute(local_name, value), } } diff --git a/components/script/dom/htmltemplateelement.rs b/components/script/dom/htmltemplateelement.rs index bf659987620..7ee8d03b163 100644 --- a/components/script/dom/htmltemplateelement.rs +++ b/components/script/dom/htmltemplateelement.rs @@ -14,7 +14,7 @@ use dom::documentfragment::DocumentFragment; use dom::htmlelement::HTMLElement; use dom::node::{CloneChildrenFlag, Node, document_from_node}; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLTemplateElement { @@ -25,7 +25,7 @@ pub struct HTMLTemplateElement { } impl HTMLTemplateElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTemplateElement { HTMLTemplateElement { @@ -36,7 +36,7 @@ impl HTMLTemplateElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTemplateElement> { Node::reflect_node(box HTMLTemplateElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 7023b47c31b..268998c8e58 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -25,11 +25,11 @@ use dom::node::{document_from_node, window_from_node}; use dom::nodelist::NodeList; use dom::validation::Validatable; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use ipc_channel::ipc::IpcSender; use script_traits::ScriptMsg as ConstellationMsg; use std::cell::Cell; use std::ops::Range; -use string_cache::Atom; use style::attr::AttrValue; use style::element_state::*; use textinput::{KeyReaction, Lines, SelectionDirection, TextInput}; @@ -75,7 +75,7 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> { fn get_cols(self) -> u32 { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("cols")) + .get_attr_for_layout(&ns!(), &local_name!("cols")) .map_or(DEFAULT_COLS, AttrValue::as_uint) } } @@ -84,7 +84,7 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> { fn get_rows(self) -> u32 { unsafe { (*self.upcast::<Element>().unsafe_get()) - .get_attr_for_layout(&ns!(), &atom!("rows")) + .get_attr_for_layout(&ns!(), &local_name!("rows")) .map_or(DEFAULT_ROWS, AttrValue::as_uint) } } @@ -97,7 +97,7 @@ static DEFAULT_COLS: u32 = 20; static DEFAULT_ROWS: u32 = 2; impl HTMLTextAreaElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTextAreaElement { let chan = document.window().upcast::<GlobalScope>().constellation_chan().clone(); @@ -112,7 +112,7 @@ impl HTMLTextAreaElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTextAreaElement> { Node::reflect_node(box HTMLTextAreaElement::new_inherited(local_name, prefix, document), @@ -291,7 +291,7 @@ impl VirtualMethods for HTMLTextAreaElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); match *attr.local_name() { - atom!("disabled") => { + local_name!("disabled") => { let el = self.upcast::<Element>(); match mutation { AttributeMutation::Set(_) => { @@ -311,7 +311,7 @@ impl VirtualMethods for HTMLTextAreaElement { } } }, - atom!("readonly") => { + local_name!("readonly") => { let el = self.upcast::<Element>(); match mutation { AttributeMutation::Set(_) => { @@ -334,10 +334,10 @@ impl VirtualMethods for HTMLTextAreaElement { self.upcast::<Element>().check_ancestors_disabled_state_for_form_control(); } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match *name { - atom!("cols") => AttrValue::from_limited_u32(value.into(), DEFAULT_COLS), - atom!("rows") => AttrValue::from_limited_u32(value.into(), DEFAULT_ROWS), + local_name!("cols") => AttrValue::from_limited_u32(value.into(), DEFAULT_COLS), + local_name!("rows") => AttrValue::from_limited_u32(value.into(), DEFAULT_ROWS), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/htmltimeelement.rs b/components/script/dom/htmltimeelement.rs index 8ba41e25a2b..e7d9e049baa 100644 --- a/components/script/dom/htmltimeelement.rs +++ b/components/script/dom/htmltimeelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLTimeElement { @@ -16,14 +16,14 @@ pub struct HTMLTimeElement { } impl HTMLTimeElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLTimeElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTimeElement { HTMLTimeElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTimeElement> { Node::reflect_node(box HTMLTimeElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmltitleelement.rs b/components/script/dom/htmltitleelement.rs index 49994c4bcb8..c124a4a3604 100644 --- a/components/script/dom/htmltitleelement.rs +++ b/components/script/dom/htmltitleelement.rs @@ -14,7 +14,7 @@ use dom::htmlelement::HTMLElement; use dom::node::{ChildrenMutation, Node}; use dom::text::Text; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLTitleElement { @@ -22,14 +22,14 @@ pub struct HTMLTitleElement { } impl HTMLTitleElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLTitleElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTitleElement { HTMLTitleElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTitleElement> { Node::reflect_node(box HTMLTitleElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmltrackelement.rs b/components/script/dom/htmltrackelement.rs index ae96aae3306..4c4263aa949 100644 --- a/components/script/dom/htmltrackelement.rs +++ b/components/script/dom/htmltrackelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLTrackElement { @@ -16,14 +16,14 @@ pub struct HTMLTrackElement { } impl HTMLTrackElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLTrackElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTrackElement { HTMLTrackElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLTrackElement> { Node::reflect_node(box HTMLTrackElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlulistelement.rs b/components/script/dom/htmlulistelement.rs index b5da24728fc..211b77bb8b6 100644 --- a/components/script/dom/htmlulistelement.rs +++ b/components/script/dom/htmlulistelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLUListElement { @@ -16,14 +16,14 @@ pub struct HTMLUListElement { } impl HTMLUListElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLUListElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLUListElement { HTMLUListElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document) } } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLUListElement> { Node::reflect_node(box HTMLUListElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlunknownelement.rs b/components/script/dom/htmlunknownelement.rs index 4ae99cfae58..22930a32d78 100644 --- a/components/script/dom/htmlunknownelement.rs +++ b/components/script/dom/htmlunknownelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlelement::HTMLElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLUnknownElement { @@ -16,7 +16,7 @@ pub struct HTMLUnknownElement { } impl HTMLUnknownElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLUnknownElement { HTMLUnknownElement { @@ -26,7 +26,7 @@ impl HTMLUnknownElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLUnknownElement> { Node::reflect_node(box HTMLUnknownElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/htmlvideoelement.rs b/components/script/dom/htmlvideoelement.rs index d9635538e9b..940888c3466 100644 --- a/components/script/dom/htmlvideoelement.rs +++ b/components/script/dom/htmlvideoelement.rs @@ -8,7 +8,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::htmlmediaelement::HTMLMediaElement; use dom::node::Node; -use string_cache::Atom; +use html5ever_atoms::LocalName; #[dom_struct] pub struct HTMLVideoElement { @@ -16,7 +16,7 @@ pub struct HTMLVideoElement { } impl HTMLVideoElement { - fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLVideoElement { + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLVideoElement { HTMLVideoElement { htmlmediaelement: HTMLMediaElement::new_inherited(local_name, prefix, document) @@ -24,7 +24,7 @@ impl HTMLVideoElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLVideoElement> { Node::reflect_node(box HTMLVideoElement::new_inherited(local_name, prefix, document), diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 2fa6a87b980..82800be2ff2 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -9,7 +9,7 @@ macro_rules! make_getter( use dom::bindings::inheritance::Castable; use dom::element::Element; let element = self.upcast::<Element>(); - element.get_string_attribute(&atom!($htmlname)) + element.get_string_attribute(&local_name!($htmlname)) } ); ); @@ -21,7 +21,7 @@ macro_rules! make_bool_getter( use dom::bindings::inheritance::Castable; use dom::element::Element; let element = self.upcast::<Element>(); - element.has_attribute(&atom!($htmlname)) + element.has_attribute(&local_name!($htmlname)) } ); ); @@ -40,7 +40,7 @@ macro_rules! make_limited_int_setter( }; let element = self.upcast::<Element>(); - element.set_int_attribute(&atom!($htmlname), value); + element.set_int_attribute(&local_name!($htmlname), value); Ok(()) } ); @@ -54,7 +54,7 @@ macro_rules! make_int_setter( use dom::element::Element; let element = self.upcast::<Element>(); - element.set_int_attribute(&atom!($htmlname), value) + element.set_int_attribute(&local_name!($htmlname), value) } ); ($attr:ident, $htmlname:tt) => { @@ -69,7 +69,7 @@ macro_rules! make_int_getter( use dom::bindings::inheritance::Castable; use dom::element::Element; let element = self.upcast::<Element>(); - element.get_int_attribute(&atom!($htmlname), $default) + element.get_int_attribute(&local_name!($htmlname), $default) } ); @@ -85,7 +85,7 @@ macro_rules! make_uint_getter( use dom::bindings::inheritance::Castable; use dom::element::Element; let element = self.upcast::<Element>(); - element.get_uint_attribute(&atom!($htmlname), $default) + element.get_uint_attribute(&local_name!($htmlname), $default) } ); ($attr:ident, $htmlname:tt) => { @@ -100,7 +100,7 @@ macro_rules! make_url_getter( use dom::bindings::inheritance::Castable; use dom::element::Element; let element = self.upcast::<Element>(); - element.get_url_attribute(&atom!($htmlname)) + element.get_url_attribute(&local_name!($htmlname)) } ); ); @@ -112,7 +112,7 @@ macro_rules! make_url_or_base_getter( use dom::bindings::inheritance::Castable; use dom::element::Element; let element = self.upcast::<Element>(); - let url = element.get_url_attribute(&atom!($htmlname)); + let url = element.get_url_attribute(&local_name!($htmlname)); if url.is_empty() { let window = window_from_node(self); DOMString::from(window.get_url().into_string()) @@ -131,7 +131,7 @@ macro_rules! make_string_or_document_url_getter( use dom::element::Element; use dom::node::document_from_node; let element = self.upcast::<Element>(); - let val = element.get_string_attribute(&atom!($htmlname)); + let val = element.get_string_attribute(&local_name!($htmlname)); if val.is_empty() { let doc = document_from_node(self); @@ -151,7 +151,7 @@ macro_rules! make_enumerated_getter( use dom::element::Element; use std::ascii::AsciiExt; let element = self.upcast::<Element>(); - let mut val = element.get_string_attribute(&atom!($htmlname)); + let mut val = element.get_string_attribute(&local_name!($htmlname)); val.make_ascii_lowercase(); // https://html.spec.whatwg.org/multipage/#attr-fs-method match &*val { @@ -171,7 +171,7 @@ macro_rules! make_setter( use dom::bindings::inheritance::Castable; use dom::element::Element; let element = self.upcast::<Element>(); - element.set_string_attribute(&atom!($htmlname), value) + element.set_string_attribute(&local_name!($htmlname), value) } ); ); @@ -183,7 +183,7 @@ macro_rules! make_bool_setter( use dom::bindings::inheritance::Castable; use dom::element::Element; let element = self.upcast::<Element>(); - element.set_bool_attribute(&atom!($htmlname), value) + element.set_bool_attribute(&local_name!($htmlname), value) } ); ); @@ -198,7 +198,7 @@ macro_rules! make_url_setter( let value = AttrValue::from_url(document_from_node(self).url(), value.into()); let element = self.upcast::<Element>(); - element.set_attribute(&atom!($htmlname), value); + element.set_attribute(&local_name!($htmlname), value); } ); ); @@ -216,7 +216,7 @@ macro_rules! make_uint_setter( value }; let element = self.upcast::<Element>(); - element.set_uint_attribute(&atom!($htmlname), value) + element.set_uint_attribute(&local_name!($htmlname), value) } ); ($attr:ident, $htmlname:tt) => { @@ -239,7 +239,7 @@ macro_rules! make_limited_uint_setter( value }; let element = self.upcast::<Element>(); - element.set_uint_attribute(&atom!($htmlname), value); + element.set_uint_attribute(&local_name!($htmlname), value); Ok(()) } ); @@ -255,7 +255,7 @@ macro_rules! make_atomic_setter( use dom::bindings::inheritance::Castable; use dom::element::Element; let element = self.upcast::<Element>(); - element.set_atomic_attribute(&atom!($htmlname), value) + element.set_atomic_attribute(&local_name!($htmlname), value) } ); ); @@ -269,7 +269,7 @@ macro_rules! make_legacy_color_setter( use style::attr::AttrValue; let element = self.upcast::<Element>(); let value = AttrValue::from_legacy_color(value.into()); - element.set_attribute(&atom!($htmlname), value) + element.set_attribute(&local_name!($htmlname), value) } ); ); @@ -282,7 +282,7 @@ macro_rules! make_dimension_setter( use dom::element::Element; let element = self.upcast::<Element>(); let value = AttrValue::from_dimension(value.into()); - element.set_attribute(&atom!($htmlname), value) + element.set_attribute(&local_name!($htmlname), value) } ); ); @@ -295,7 +295,7 @@ macro_rules! make_nonzero_dimension_setter( use dom::element::Element; let element = self.upcast::<Element>(); let value = AttrValue::from_nonzero_dimension(value.into()); - element.set_attribute(&atom!($htmlname), value) + element.set_attribute(&local_name!($htmlname), value) } ); ); diff --git a/components/script/dom/mediaquerylist.rs b/components/script/dom/mediaquerylist.rs new file mode 100644 index 00000000000..3c6215b883f --- /dev/null +++ b/components/script/dom/mediaquerylist.rs @@ -0,0 +1,154 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 cssparser::ToCss; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; +use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener; +use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; +use dom::bindings::codegen::Bindings::MediaQueryListBinding::{self, MediaQueryListMethods}; +use dom::bindings::inheritance::Castable; +use dom::bindings::js::{JS, Root}; +use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::str::DOMString; +use dom::bindings::trace::JSTraceable; +use dom::bindings::weakref::{WeakRef, WeakRefVec}; +use dom::document::Document; +use dom::eventtarget::EventTarget; +use euclid::scale_factor::ScaleFactor; +use js::jsapi::JSTracer; +use std::cell::Cell; +use std::rc::Rc; +use style; +use style::media_queries::{Device, MediaType}; +use style_traits::{PagePx, ViewportPx}; + +pub enum MediaQueryListMatchState { + Same(bool), + Changed(bool), +} + +#[dom_struct] +pub struct MediaQueryList { + eventtarget: EventTarget, + document: JS<Document>, + media_query_list: style::media_queries::MediaQueryList, + last_match_state: Cell<Option<bool>> +} + +impl MediaQueryList { + fn new_inherited(document: &Document, + media_query_list: style::media_queries::MediaQueryList) -> MediaQueryList { + MediaQueryList { + eventtarget: EventTarget::new_inherited(), + document: JS::from_ref(document), + media_query_list: media_query_list, + last_match_state: Cell::new(None), + } + } + + pub fn new(document: &Document, + media_query_list: style::media_queries::MediaQueryList) -> Root<MediaQueryList> { + reflect_dom_object(box MediaQueryList::new_inherited(document, media_query_list), + document.window(), + MediaQueryListBinding::Wrap) + } +} + +impl MediaQueryList { + fn evaluate_changes(&self) -> MediaQueryListMatchState { + let matches = self.evaluate(); + + let result = if let Some(old_matches) = self.last_match_state.get() { + if old_matches == matches { + MediaQueryListMatchState::Same(matches) + } else { + MediaQueryListMatchState::Changed(matches) + } + } else { + MediaQueryListMatchState::Changed(matches) + }; + + self.last_match_state.set(Some(matches)); + result + } + + pub fn evaluate(&self) -> bool { + if let Some(window_size) = self.document.window().window_size() { + let viewport_size = window_size.visible_viewport; + // TODO: support real ViewportPx, including zoom level + // This information seems not to be tracked currently, so we assume + // ViewportPx == PagePx + let page_to_viewport: ScaleFactor<f32, PagePx, ViewportPx> = ScaleFactor::new(1.0); + let device = Device::new(MediaType::Screen, viewport_size * page_to_viewport); + self.media_query_list.evaluate(&device) + } else { + false + } + } +} + +impl MediaQueryListMethods for MediaQueryList { + // https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-media + fn Media(&self) -> DOMString { + let mut s = String::new(); + self.media_query_list.to_css(&mut s).unwrap(); + DOMString::from_string(s) + } + + // https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-matches + fn Matches(&self) -> bool { + match self.last_match_state.get() { + None => self.evaluate(), + Some(state) => state, + } + } + + // https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-addlistener + fn AddListener(&self, listener: Option<Rc<EventListener>>) { + self.upcast::<EventTarget>().AddEventListener(DOMString::from_string("change".to_owned()), + listener, false); + } + + // https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-removelistener + fn RemoveListener(&self, listener: Option<Rc<EventListener>>) { + self.upcast::<EventTarget>().RemoveEventListener(DOMString::from_string("change".to_owned()), + listener, false); + } + + // https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-onchange + event_handler!(change, GetOnchange, SetOnchange); +} + +#[derive(HeapSizeOf)] +pub struct WeakMediaQueryListVec { + cell: DOMRefCell<WeakRefVec<MediaQueryList>>, +} + +impl WeakMediaQueryListVec { + /// Create a new vector of weak references to MediaQueryList + pub fn new() -> Self { + WeakMediaQueryListVec { cell: DOMRefCell::new(WeakRefVec::new()) } + } + + pub fn push(&self, mql: &MediaQueryList) { + self.cell.borrow_mut().push(WeakRef::new(mql)); + } + + /// Evaluate media query lists and report changes + /// https://drafts.csswg.org/cssom-view/#evaluate-media-queries-and-report-changes + pub fn evaluate_and_report_changes(&self) { + for mql in self.cell.borrow().iter() { + if let MediaQueryListMatchState::Changed(_) = mql.root().unwrap().evaluate_changes() { + mql.root().unwrap().upcast::<EventTarget>().fire_event(atom!("change")); + } + } + } +} + +impl JSTraceable for WeakMediaQueryListVec { + fn trace(&self, _: *mut JSTracer) { + self.cell.borrow_mut().retain_alive() + } +} diff --git a/components/script/dom/messageevent.rs b/components/script/dom/messageevent.rs index 53143711cf0..f3d2aa79ba4 100644 --- a/components/script/dom/messageevent.rs +++ b/components/script/dom/messageevent.rs @@ -15,8 +15,8 @@ use dom::eventtarget::EventTarget; use dom::globalscope::GlobalScope; use js::jsapi::{HandleValue, Heap, JSContext}; use js::jsval::JSVal; +use servo_atoms::Atom; use std::default::Default; -use string_cache::Atom; #[dom_struct] pub struct MessageEvent { diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 4c6c7c941c4..d419d41ec61 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -357,6 +357,7 @@ pub mod imagedata; pub mod keyboardevent; pub mod location; pub mod mediaerror; +pub mod mediaquerylist; pub mod messageevent; pub mod mimetype; pub mod mimetypearray; @@ -398,6 +399,7 @@ pub mod testbinding; pub mod testbindingiterable; pub mod testbindingpairiterable; pub mod testbindingproxy; +pub mod testrunner; pub mod text; pub mod textdecoder; pub mod textencoder; diff --git a/components/script/dom/namednodemap.rs b/components/script/dom/namednodemap.rs index 1145ff60562..148822cabb2 100644 --- a/components/script/dom/namednodemap.rs +++ b/components/script/dom/namednodemap.rs @@ -13,8 +13,8 @@ use dom::bindings::str::DOMString; use dom::bindings::xmlname::namespace_from_domstring; use dom::element::Element; use dom::window::Window; +use html5ever_atoms::LocalName; use std::ascii::AsciiExt; -use string_cache::Atom; #[dom_struct] pub struct NamedNodeMap { @@ -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, &LocalName::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, &LocalName::from(local_name)) .ok_or(Error::NotFound) } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 767a3132eb3..5fcfd74f1f6 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -57,6 +57,7 @@ use euclid::rect::Rect; use euclid::size::Size2D; use heapsize::{HeapSizeOf, heap_size_of}; use html5ever::tree_builder::QuirksMode; +use html5ever_atoms::{Prefix, LocalName, Namespace, QualName}; use js::jsapi::{JSContext, JSObject, JSRuntime}; use libc::{self, c_void, uintptr_t}; use msg::constellation_msg::PipelineId; @@ -75,7 +76,6 @@ use std::default::Default; use std::iter; use std::mem; use std::ops::Range; -use string_cache::{Atom, Namespace, QualName}; use style::dom::OpaqueNode; use style::selector_impl::ServoSelectorImpl; use style::thread_state; @@ -771,6 +771,10 @@ impl Node { self.owner_doc().is_html_document() } + pub fn is_in_doc_with_browsing_context(&self) -> bool { + self.is_in_doc() && self.owner_doc().browsing_context().is_some() + } + pub fn children(&self) -> NodeSiblingIterator { NodeSiblingIterator { current: self.GetFirstChild(), @@ -849,22 +853,23 @@ impl Node { let tr = new_child(); - let after_node = if index == -1 { - None - } else { - match get_items().elements_iter() - .map(Root::upcast::<Node>) - .map(Some) - .chain(iter::once(None)) - .nth(index as usize) { - None => return Err(Error::IndexSize), - Some(node) => node, - } - }; { let tr_node = tr.upcast::<Node>(); - try!(self.InsertBefore(tr_node, after_node.r())); + if index == -1 { + try!(self.InsertBefore(tr_node, None)); + } else { + let items = get_items(); + let node = match items.elements_iter() + .map(Root::upcast::<Node>) + .map(Some) + .chain(iter::once(None)) + .nth(index as usize) { + None => return Err(Error::IndexSize), + Some(node) => node, + }; + try!(self.InsertBefore(tr_node, node.r())); + } } Ok(Root::upcast::<HTMLElement>(tr)) @@ -1752,7 +1757,7 @@ impl Node { local: element.local_name().clone() }; let element = Element::create(name, - element.prefix().as_ref().map(|p| Atom::from(&**p)), + element.prefix().as_ref().map(|p| Prefix::from(&**p)), &document, ElementCreator::ScriptCreated); Root::upcast::<Node>(element) }, @@ -1818,21 +1823,21 @@ impl Node { pub fn namespace_to_string(namespace: Namespace) -> Option<DOMString> { match namespace { ns!() => None, - // FIXME(ajeffrey): convert directly from &Atom to DOMString - Namespace(ref ns) => Some(DOMString::from(&**ns)) + // FIXME(ajeffrey): convert directly from Namespace to DOMString + _ => Some(DOMString::from(&*namespace)) } } // https://dom.spec.whatwg.org/#locate-a-namespace pub fn locate_namespace(node: &Node, prefix: Option<DOMString>) -> Namespace { fn attr_defines_namespace(attr: &Attr, - prefix: &Option<Atom>) -> bool { + defined_prefix: &Option<LocalName>) -> bool { *attr.namespace() == ns!(xmlns) && - match (attr.prefix(), prefix) { - (&Some(ref attr_prefix), &Some(ref prefix)) => - attr_prefix == &atom!("xmlns") && - attr.local_name() == prefix, - (&None, &None) => *attr.local_name() == atom!("xmlns"), + match (attr.prefix(), defined_prefix) { + (&Some(ref attr_prefix), &Some(ref defined_prefix)) => + attr_prefix == &namespace_prefix!("xmlns") && + attr.local_name() == defined_prefix, + (&None, &None) => *attr.local_name() == local_name!("xmlns"), _ => false } } @@ -1845,8 +1850,11 @@ impl Node { return element.namespace().clone() } - // FIXME(ajeffrey): directly convert DOMString to Atom - let prefix_atom = prefix.as_ref().map(|s| Atom::from(&**s)); + // Even though this is conceptually a namespace prefix, + // in the `xmlns:foo="https://example.net/namespace" declaration + // it is a local name. + // FIXME(ajeffrey): directly convert DOMString to LocalName + let prefix_atom = prefix.as_ref().map(|s| LocalName::from(&**s)); // Step 2. let attrs = element.attrs(); diff --git a/components/script/dom/pagetransitionevent.rs b/components/script/dom/pagetransitionevent.rs index 883f3319394..b40f6c1ab39 100644 --- a/components/script/dom/pagetransitionevent.rs +++ b/components/script/dom/pagetransitionevent.rs @@ -12,8 +12,8 @@ use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::Event; use dom::globalscope::GlobalScope; +use servo_atoms::Atom; use std::cell::Cell; -use string_cache::Atom; // https://html.spec.whatwg.org/multipage/#pagetransitionevent #[dom_struct] diff --git a/components/script/dom/popstateevent.rs b/components/script/dom/popstateevent.rs index 7b7af62a6fe..153c30531fe 100644 --- a/components/script/dom/popstateevent.rs +++ b/components/script/dom/popstateevent.rs @@ -14,7 +14,7 @@ use dom::event::Event; use dom::globalscope::GlobalScope; use js::jsapi::{HandleValue, JSContext}; use js::jsval::JSVal; -use string_cache::Atom; +use servo_atoms::Atom; // https://html.spec.whatwg.org/multipage/#the-popstateevent-interface #[dom_struct] diff --git a/components/script/dom/progressevent.rs b/components/script/dom/progressevent.rs index 189f65412fe..b8d3d5ba9f7 100644 --- a/components/script/dom/progressevent.rs +++ b/components/script/dom/progressevent.rs @@ -12,7 +12,7 @@ use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::globalscope::GlobalScope; -use string_cache::Atom; +use servo_atoms::Atom; #[dom_struct] pub struct ProgressEvent { diff --git a/components/script/dom/promise.rs b/components/script/dom/promise.rs index c0842dce4fa..81149f8e193 100644 --- a/components/script/dom/promise.rs +++ b/components/script/dom/promise.rs @@ -51,7 +51,7 @@ impl PromiseHelper for Rc<Promise> { #[allow(unsafe_code)] unsafe fn initialize(&self, cx: *mut JSContext) { let obj = self.reflector().get_jsobject(); - self.permanent_js_root.set(ObjectValue(&**obj)); + self.permanent_js_root.set(ObjectValue(*obj)); assert!(AddRawValueRoot(cx, self.permanent_js_root.get_unsafe(), b"Promise::root\0" as *const _ as *const _)); @@ -278,7 +278,7 @@ fn create_native_handler_function(cx: *mut JSContext, assert!(!obj.is_null()); SetFunctionNativeReserved(obj.get(), SLOT_NATIVEHANDLER, - &ObjectValue(&**holder)); + &ObjectValue(*holder)); SetFunctionNativeReserved(obj.get(), SLOT_NATIVEHANDLER_TASK, &Int32Value(task as i32)); diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs index 08b5842dbff..c0709f17c7c 100644 --- a/components/script/dom/range.rs +++ b/components/script/dom/range.rs @@ -913,10 +913,10 @@ impl RangeMethods for Range { // Step 2. let should_create_body = element.as_ref().map_or(true, |elem| { let elem = elem.downcast::<Element>().unwrap(); - elem.local_name() == &atom!("html") && elem.html_element_in_html_document() + elem.local_name() == &local_name!("html") && elem.html_element_in_html_document() }); let element: Root<Node> = if should_create_body { - Root::upcast(HTMLBodyElement::new(atom!("body"), None, &self.StartContainer().owner_doc())) + Root::upcast(HTMLBodyElement::new(local_name!("body"), None, &self.StartContainer().owner_doc())) } else { Root::upcast(element.unwrap()) }; diff --git a/components/script/dom/request.rs b/components/script/dom/request.rs index 3358fc63ef5..a748b18715c 100644 --- a/components/script/dom/request.rs +++ b/components/script/dom/request.rs @@ -25,7 +25,7 @@ use dom::headers::{Guard, Headers}; use dom::promise::Promise; use dom::xmlhttprequest::Extractable; use hyper::method::Method as HttpMethod; -use msg::constellation_msg::ReferrerPolicy as MsgReferrerPolicy; +use net_traits::ReferrerPolicy as MsgReferrerPolicy; use net_traits::request::{Origin, Window}; use net_traits::request::CacheMode as NetTraitsRequestCache; use net_traits::request::CredentialsMode as NetTraitsRequestCredentials; diff --git a/components/script/dom/serviceworker.rs b/components/script/dom/serviceworker.rs index 8f3686f0b0c..373ed38c761 100644 --- a/components/script/dom/serviceworker.rs +++ b/components/script/dom/serviceworker.rs @@ -18,6 +18,7 @@ use dom::globalscope::GlobalScope; use js::jsapi::{HandleValue, JSContext}; use script_thread::Runnable; use script_traits::{ScriptMsg, DOMMessage}; +use servo_atoms::Atom; use std::cell::Cell; use url::Url; @@ -56,12 +57,12 @@ impl ServiceWorker { pub fn dispatch_simple_error(address: TrustedServiceWorkerAddress) { let service_worker = address.root(); - service_worker.upcast().fire_simple_event("error"); + service_worker.upcast().fire_event(atom!("error")); } pub fn set_transition_state(&self, state: ServiceWorkerState) { self.state.set(state); - self.upcast::<EventTarget>().fire_simple_event("statechange"); + self.upcast::<EventTarget>().fire_event(Atom::from("statechange")); } pub fn get_script_url(&self) -> Url { diff --git a/components/script/dom/serviceworkercontainer.rs b/components/script/dom/serviceworkercontainer.rs index a28440e5c42..c83d859b4ce 100644 --- a/components/script/dom/serviceworkercontainer.rs +++ b/components/script/dom/serviceworkercontainer.rs @@ -15,6 +15,7 @@ use dom::promise::Promise; use dom::serviceworker::ServiceWorker; use dom::serviceworkerregistration::ServiceWorkerRegistration; use script_thread::ScriptThread; +use servo_atoms::Atom; use std::ascii::AsciiExt; use std::default::Default; use std::rc::Rc; @@ -45,7 +46,7 @@ pub trait Controllable { impl Controllable for ServiceWorkerContainer { fn set_controller(&self, active_worker: &ServiceWorker) { self.controller.set(Some(active_worker)); - self.upcast::<EventTarget>().fire_simple_event("controllerchange"); + self.upcast::<EventTarget>().fire_event(Atom::from("controllerchange")); } } diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs index 10d01d4b41a..adf416d4fc3 100644 --- a/components/script/dom/serviceworkerglobalscope.rs +++ b/components/script/dom/serviceworkerglobalscope.rs @@ -23,10 +23,12 @@ use ipc_channel::router::ROUTER; use js::jsapi::{JS_SetInterruptCallback, JSAutoCompartment, JSContext}; use js::jsval::UndefinedValue; use js::rust::Runtime; -use net_traits::{LoadContext, load_whole_resource, IpcSend, CustomResponseMediator}; +use net_traits::{load_whole_resource, IpcSend, CustomResponseMediator}; +use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType}; use rand::random; use script_runtime::{CommonScriptMsg, StackRootTLS, get_reports, new_rt_and_cx, ScriptChan}; -use script_traits::{TimerEvent, WorkerGlobalScopeInit, ScopeThings, ServiceWorkerMsg}; +use script_traits::{TimerEvent, WorkerGlobalScopeInit, ScopeThings, ServiceWorkerMsg, WorkerScriptLoadOrigin}; +use servo_atoms::Atom; use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel}; use std::thread; use std::time::Duration; @@ -151,10 +153,24 @@ impl ServiceWorkerGlobalScope { thread_state::initialize(SCRIPT | IN_WORKER); let roots = RootCollection::new(); let _stack_roots_tls = StackRootTLS::new(&roots); - let (url, source) = match load_whole_resource(LoadContext::Script, - &init.resource_threads.sender(), - script_url, - &worker_load_origin) { + + let WorkerScriptLoadOrigin { referrer_url, referrer_policy, pipeline_id } = worker_load_origin; + + let request = RequestInit { + url: script_url.clone(), + type_: RequestType::Script, + destination: Destination::ServiceWorker, + credentials_mode: CredentialsMode::Include, + use_url_credentials: true, + origin: script_url, + pipeline_id: pipeline_id, + referrer_url: referrer_url, + referrer_policy: referrer_policy, + .. RequestInit::default() + }; + + let (url, source) = match load_whole_resource(request, + &init.resource_threads.sender()) { Err(_) => { println!("error loading script {}", serialized_worker_url); return; @@ -253,7 +269,7 @@ impl ServiceWorkerGlobalScope { // TODO XXXcreativcoder This will eventually use a FetchEvent interface to fire event // when we have the Request and Response dom api's implemented // https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/index.html#fetch-event-section - self.upcast::<EventTarget>().fire_simple_event("fetch"); + self.upcast::<EventTarget>().fire_event(Atom::from("fetch")); let _ = mediator.response_chan.send(None); } } diff --git a/components/script/dom/servoparser/html.rs b/components/script/dom/servoparser/html.rs index 26db7aa4b0c..fd4a5a923b9 100644 --- a/components/script/dom/servoparser/html.rs +++ b/components/script/dom/servoparser/html.rs @@ -29,14 +29,14 @@ use html5ever::serialize::{AttrRef, Serializable, Serializer}; use html5ever::serialize::TraversalScope; use html5ever::serialize::TraversalScope::{ChildrenOnly, IncludeNode}; use html5ever::tendril::StrTendril; -use html5ever::tokenizer::{Tokenizer as HtmlTokenizer, TokenizerOpts}; +use html5ever::tokenizer::{Tokenizer as H5ETokenizer, TokenizerOpts}; use html5ever::tree_builder::{NextParserState, NodeOrText, QuirksMode}; use html5ever::tree_builder::{TreeBuilder, TreeBuilderOpts, TreeSink}; +use html5ever_atoms::QualName; use msg::constellation_msg::PipelineId; use std::borrow::Cow; use std::io::{self, Write}; -use string_cache::QualName; -use super::{LastChunkState, ServoParser, Sink, Tokenizer}; +use super::{HtmlTokenizer, LastChunkState, ServoParser, Sink, Tokenizer}; use url::Url; fn insert(parent: &Node, reference_child: Option<&Node>, child: NodeOrText<JS<Node>>) { @@ -276,10 +276,13 @@ pub fn parse_html(document: &Document, let parser = match context { ParseContext::Owner(owner) => { let tb = TreeBuilder::new(sink, options); - let tok = HtmlTokenizer::new(tb, Default::default()); + let tok = H5ETokenizer::new(tb, Default::default()); ServoParser::new( - document, owner, Tokenizer::HTML(tok), LastChunkState::NotReceived) + document, + owner, + Tokenizer::HTML(HtmlTokenizer::new(tok)), + LastChunkState::NotReceived) }, ParseContext::Fragment(fc) => { let tb = TreeBuilder::new_for_fragment( @@ -292,10 +295,13 @@ pub fn parse_html(document: &Document, initial_state: Some(tb.tokenizer_state_for_context_elem()), .. Default::default() }; - let tok = HtmlTokenizer::new(tb, tok_options); + let tok = H5ETokenizer::new(tb, tok_options); ServoParser::new( - document, None, Tokenizer::HTML(tok), LastChunkState::Received) + document, + None, + Tokenizer::HTML(HtmlTokenizer::new(tok)), + LastChunkState::Received) } }; parser.parse_chunk(String::from(input)); diff --git a/components/script/dom/servoparser/mod.rs b/components/script/dom/servoparser/mod.rs index cb8fc3d753d..4df82a457a7 100644 --- a/components/script/dom/servoparser/mod.rs +++ b/components/script/dom/servoparser/mod.rs @@ -20,7 +20,8 @@ use dom::htmlimageelement::HTMLImageElement; use dom::node::Node; use encoding::all::UTF_8; use encoding::types::{DecoderTrap, Encoding}; -use html5ever::tokenizer::Tokenizer as HtmlTokenizer; +use html5ever::tokenizer::Tokenizer as H5ETokenizer; +use html5ever::tokenizer::buffer_queue::BufferQueue; use html5ever::tree_builder::Tracer as HtmlTracer; use html5ever::tree_builder::TreeBuilder as HtmlTreeBuilder; use hyper::header::ContentType; @@ -28,7 +29,7 @@ use hyper::mime::{Mime, SubLevel, TopLevel}; use hyper_serde::Serde; use js::jsapi::JSTracer; use msg::constellation_msg::PipelineId; -use net_traits::{AsyncResponseListener, Metadata, NetworkError}; +use net_traits::{FetchMetadata, FetchResponseListener, Metadata, NetworkError}; use network_listener::PreInvoke; use profile_traits::time::{TimerMetadata, TimerMetadataFrameType}; use profile_traits::time::{TimerMetadataReflowType, ProfilerCategory, profile}; @@ -136,10 +137,6 @@ impl ServoParser { self.tokenizer.borrow_mut().set_plaintext_state() } - pub fn end_tokenizer(&self) { - self.tokenizer.borrow_mut().end() - } - pub fn suspend(&self) { assert!(!self.suspended.get()); self.suspended.set(true); @@ -220,16 +217,50 @@ impl ServoParser { #[derive(HeapSizeOf)] #[must_root] enum Tokenizer { - HTML( - #[ignore_heap_size_of = "Defined in html5ever"] - HtmlTokenizer<HtmlTreeBuilder<JS<Node>, Sink>> - ), + HTML(HtmlTokenizer), XML( #[ignore_heap_size_of = "Defined in xml5ever"] XmlTokenizer<XmlTreeBuilder<JS<Node>, Sink>> ), } +#[derive(HeapSizeOf)] +#[must_root] +struct HtmlTokenizer { + #[ignore_heap_size_of = "Defined in html5ever"] + inner: H5ETokenizer<HtmlTreeBuilder<JS<Node>, Sink>>, + #[ignore_heap_size_of = "Defined in html5ever"] + input_buffer: BufferQueue, +} + +impl HtmlTokenizer { + #[allow(unrooted_must_root)] + fn new(inner: H5ETokenizer<HtmlTreeBuilder<JS<Node>, Sink>>) -> Self { + HtmlTokenizer { + inner: inner, + input_buffer: BufferQueue::new(), + } + } + + fn feed(&mut self, input: String) { + self.input_buffer.push_back(input.into()); + self.run(); + } + + fn run(&mut self) { + self.inner.feed(&mut self.input_buffer); + } + + fn end(&mut self) { + assert!(self.input_buffer.is_empty()); + self.inner.end(); + } + + fn set_plaintext_state(&mut self) { + self.inner.set_plaintext_state(); + } +} + #[derive(JSTraceable, HeapSizeOf)] #[must_root] struct Sink { @@ -240,7 +271,7 @@ struct Sink { impl Tokenizer { fn feed(&mut self, input: String) { match *self { - Tokenizer::HTML(ref mut tokenizer) => tokenizer.feed(input.into()), + Tokenizer::HTML(ref mut tokenizer) => tokenizer.feed(input), Tokenizer::XML(ref mut tokenizer) => tokenizer.feed(input.into()), } } @@ -288,7 +319,7 @@ impl JSTraceable for Tokenizer { node.trace(self.0); } } - let tree_builder = tokenizer.sink(); + let tree_builder = tokenizer.inner.sink(); tree_builder.trace_handles(&tracer); tree_builder.sink().trace(trc); }, @@ -332,11 +363,21 @@ impl ParserContext { } } -impl AsyncResponseListener for ParserContext { - fn headers_available(&mut self, meta_result: Result<Metadata, NetworkError>) { +impl FetchResponseListener for ParserContext { + fn process_request_body(&mut self) {} + + fn process_request_eof(&mut self) {} + + fn process_response(&mut self, + meta_result: Result<FetchMetadata, NetworkError>) { let mut ssl_error = None; let metadata = match meta_result { - Ok(meta) => Some(meta), + Ok(meta) => { + Some(match meta { + FetchMetadata::Unfiltered(m) => m, + FetchMetadata::Filtered { unsafe_, .. } => unsafe_ + }) + }, Err(NetworkError::SslValidation(url, reason)) => { ssl_error = Some(reason); let mut meta = Metadata::default(url); @@ -365,7 +406,7 @@ impl AsyncResponseListener for ParserContext { let doc = parser.document(); let doc_body = Root::upcast::<Node>(doc.GetBody().unwrap()); - let img = HTMLImageElement::new(atom!("img"), None, doc); + let img = HTMLImageElement::new(local_name!("img"), None, doc); img.SetSrc(DOMString::from(self.url.to_string())); doc_body.AppendChild(&Root::upcast::<Node>(img)).expect("Appending failed"); @@ -408,7 +449,7 @@ impl AsyncResponseListener for ParserContext { } } - fn data_available(&mut self, payload: Vec<u8>) { + fn process_response_chunk(&mut self, payload: Vec<u8>) { if !self.is_synthesized_document { // FIXME: use Vec<u8> (html5ever #34) let data = UTF_8.decode(&payload, DecoderTrap::Replace).unwrap(); @@ -420,7 +461,7 @@ impl AsyncResponseListener for ParserContext { } } - fn response_complete(&mut self, status: Result<(), NetworkError>) { + fn process_response_eof(&mut self, status: Result<(), NetworkError>) { let parser = match self.parser.as_ref() { Some(parser) => parser.root(), None => return, diff --git a/components/script/dom/servoparser/xml.rs b/components/script/dom/servoparser/xml.rs index e37feb43da7..879bb9320d6 100644 --- a/components/script/dom/servoparser/xml.rs +++ b/components/script/dom/servoparser/xml.rs @@ -17,9 +17,9 @@ use dom::node::Node; use dom::processinginstruction::ProcessingInstruction; use dom::text::Text; use html5ever; +use html5ever_atoms::{Prefix, QualName}; use msg::constellation_msg::PipelineId; use std::borrow::Cow; -use string_cache::{Atom, QualName, Namespace}; use super::{LastChunkState, ServoParser, Sink, Tokenizer}; use url::Url; use xml5ever::tendril::StrTendril; @@ -41,17 +41,17 @@ impl<'a> TreeSink for Sink { let elem = target.downcast::<Element>() .expect("tried to get name of non-Element in XML parsing"); QName { - prefix: elem.prefix().as_ref().map_or(atom!(""), |p| Atom::from(&**p)), - namespace_url: elem.namespace().0.clone(), + prefix: elem.prefix().as_ref().map_or(namespace_prefix!(""), |p| Prefix::from(&**p)), + namespace_url: elem.namespace().clone(), local: elem.local_name().clone(), } } fn create_element(&mut self, name: QName, attrs: Vec<Attribute>) -> JS<Node> { - let prefix = if name.prefix == atom!("") { None } else { Some(name.prefix) }; + let prefix = if name.prefix == namespace_prefix!("") { None } else { Some(name.prefix) }; let name = QualName { - ns: Namespace(name.namespace_url), + ns: name.namespace_url, local: name.local, }; let elem = Element::create(name, prefix, &*self.document, @@ -59,7 +59,7 @@ impl<'a> TreeSink for Sink { for attr in attrs { let name = QualName { - ns: Namespace(attr.name.namespace_url), + ns: attr.name.namespace_url, local: attr.name.local, }; elem.set_attribute_from_parser(name, DOMString::from(String::from(attr.value)), None); diff --git a/components/script/dom/storageevent.rs b/components/script/dom/storageevent.rs index 21c16f1db78..172a7be9ed8 100644 --- a/components/script/dom/storageevent.rs +++ b/components/script/dom/storageevent.rs @@ -14,7 +14,7 @@ use dom::event::{Event, EventBubbles, EventCancelable}; use dom::globalscope::GlobalScope; use dom::storage::Storage; use dom::window::Window; -use string_cache::Atom; +use servo_atoms::Atom; #[dom_struct] pub struct StorageEvent { diff --git a/components/script/dom/svgelement.rs b/components/script/dom/svgelement.rs index 95fd42c40b6..c89bab166ee 100644 --- a/components/script/dom/svgelement.rs +++ b/components/script/dom/svgelement.rs @@ -10,7 +10,7 @@ use dom::document::Document; use dom::element::Element; use dom::node::Node; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::element_state::ElementState; #[dom_struct] @@ -19,12 +19,12 @@ pub struct SVGElement { } impl SVGElement { - pub fn new_inherited(tag_name: Atom, prefix: Option<DOMString>, + pub fn new_inherited(tag_name: LocalName, prefix: Option<DOMString>, document: &Document) -> SVGElement { SVGElement::new_inherited_with_state(ElementState::empty(), tag_name, prefix, document) } - pub fn new_inherited_with_state(state: ElementState, tag_name: Atom, + pub fn new_inherited_with_state(state: ElementState, tag_name: LocalName, prefix: Option<DOMString>, document: &Document) -> SVGElement { SVGElement { @@ -34,7 +34,7 @@ impl SVGElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> Root<SVGElement> { + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<SVGElement> { Node::reflect_node(box SVGElement::new_inherited(local_name, prefix, document), document, SVGElementBinding::Wrap) diff --git a/components/script/dom/svggraphicselement.rs b/components/script/dom/svggraphicselement.rs index bd7c8d581f7..9435cc6d6b7 100644 --- a/components/script/dom/svggraphicselement.rs +++ b/components/script/dom/svggraphicselement.rs @@ -10,7 +10,7 @@ use dom::document::Document; use dom::node::Node; use dom::svgelement::SVGElement; use dom::virtualmethods::VirtualMethods; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::element_state::ElementState; #[dom_struct] @@ -19,12 +19,12 @@ pub struct SVGGraphicsElement { } impl SVGGraphicsElement { - pub fn new_inherited(tag_name: Atom, prefix: Option<DOMString>, + pub fn new_inherited(tag_name: LocalName, prefix: Option<DOMString>, document: &Document) -> SVGGraphicsElement { SVGGraphicsElement::new_inherited_with_state(ElementState::empty(), tag_name, prefix, document) } - pub fn new_inherited_with_state(state: ElementState, tag_name: Atom, + pub fn new_inherited_with_state(state: ElementState, tag_name: LocalName, prefix: Option<DOMString>, document: &Document) -> SVGGraphicsElement { SVGGraphicsElement { @@ -34,7 +34,7 @@ impl SVGGraphicsElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> Root<SVGGraphicsElement> { + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<SVGGraphicsElement> { Node::reflect_node(box SVGGraphicsElement::new_inherited(local_name, prefix, document), document, SVGGraphicsElementBinding::Wrap) diff --git a/components/script/dom/svgsvgelement.rs b/components/script/dom/svgsvgelement.rs index 11c1e35b9e9..e872fc25c8e 100644 --- a/components/script/dom/svgsvgelement.rs +++ b/components/script/dom/svgsvgelement.rs @@ -12,8 +12,8 @@ use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers}; use dom::node::Node; use dom::svggraphicselement::SVGGraphicsElement; use dom::virtualmethods::VirtualMethods; +use html5ever_atoms::LocalName; use script_layout_interface::SVGSVGData; -use string_cache::Atom; use style::attr::AttrValue; const DEFAULT_WIDTH: u32 = 300; @@ -25,7 +25,7 @@ pub struct SVGSVGElement { } impl SVGSVGElement { - fn new_inherited(local_name: Atom, + fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> SVGSVGElement { SVGSVGElement { @@ -35,7 +35,7 @@ impl SVGSVGElement { } #[allow(unrooted_must_root)] - pub fn new(local_name: Atom, + pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<SVGSVGElement> { Node::reflect_node(box SVGSVGElement::new_inherited(local_name, prefix, document), @@ -54,8 +54,8 @@ impl LayoutSVGSVGElementHelpers for LayoutJS<SVGSVGElement> { unsafe { let SVG = &*self.unsafe_get(); - let width_attr = SVG.upcast::<Element>().get_attr_for_layout(&ns!(), &atom!("width")); - let height_attr = SVG.upcast::<Element>().get_attr_for_layout(&ns!(), &atom!("height")); + let width_attr = SVG.upcast::<Element>().get_attr_for_layout(&ns!(), &local_name!("width")); + let height_attr = SVG.upcast::<Element>().get_attr_for_layout(&ns!(), &local_name!("height")); SVGSVGData { width: width_attr.map_or(DEFAULT_WIDTH, |val| val.as_uint()), height: height_attr.map_or(DEFAULT_HEIGHT, |val| val.as_uint()), @@ -73,10 +73,10 @@ impl VirtualMethods for SVGSVGElement { self.super_type().unwrap().attribute_mutated(attr, mutation); } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match name { - &atom!("width") => AttrValue::from_u32(value.into(), DEFAULT_WIDTH), - &atom!("height") => AttrValue::from_u32(value.into(), DEFAULT_HEIGHT), + &local_name!("width") => AttrValue::from_u32(value.into(), DEFAULT_WIDTH), + &local_name!("height") => AttrValue::from_u32(value.into(), DEFAULT_HEIGHT), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/testrunner.rs b/components/script/dom/testrunner.rs new file mode 100644 index 00000000000..f96ab6dbf65 --- /dev/null +++ b/components/script/dom/testrunner.rs @@ -0,0 +1,53 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 bluetooth_traits::BluetoothMethodMsg; +use dom::bindings::codegen::Bindings::TestRunnerBinding; +use dom::bindings::codegen::Bindings::TestRunnerBinding::TestRunnerMethods; +use dom::bindings::error::{Error, ErrorResult}; +use dom::bindings::js::Root; +use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; +use dom::bindings::str::DOMString; +use dom::globalscope::GlobalScope; +use ipc_channel::ipc::{self, IpcSender}; + +// https://webbluetoothcg.github.io/web-bluetooth/tests#test-runner + #[dom_struct] +pub struct TestRunner { + reflector_: Reflector, +} + +impl TestRunner { + pub fn new_inherited() -> TestRunner { + TestRunner { + reflector_: Reflector::new(), + } + } + + pub fn new(global: &GlobalScope) -> Root<TestRunner> { + reflect_dom_object(box TestRunner::new_inherited(), + global, + TestRunnerBinding::Wrap) + } + + fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> { + self.global().as_window().bluetooth_thread() + } +} + +impl TestRunnerMethods for TestRunner { + // https://webbluetoothcg.github.io/web-bluetooth/tests#setBluetoothMockDataSet + fn SetBluetoothMockDataSet(&self, dataSetName: DOMString) -> ErrorResult { + let (sender, receiver) = ipc::channel().unwrap(); + self.get_bluetooth_thread().send(BluetoothMethodMsg::Test(String::from(dataSetName), sender)).unwrap(); + match receiver.recv().unwrap().into() { + Ok(()) => { + Ok(()) + }, + Err(error) => { + Err(Error::from(error)) + }, + } + } +} diff --git a/components/script/dom/transitionevent.rs b/components/script/dom/transitionevent.rs index fc454483f50..1f487cb38a5 100644 --- a/components/script/dom/transitionevent.rs +++ b/components/script/dom/transitionevent.rs @@ -13,7 +13,7 @@ use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::Event; use dom::globalscope::GlobalScope; -use string_cache::Atom; +use servo_atoms::Atom; #[dom_struct] pub struct TransitionEvent { diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs index 99e25b80902..08e1b0c912c 100644 --- a/components/script/dom/uievent.rs +++ b/components/script/dom/uievent.rs @@ -14,9 +14,9 @@ use dom::bindings::str::DOMString; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::globalscope::GlobalScope; use dom::window::Window; +use servo_atoms::Atom; use std::cell::Cell; use std::default::Default; -use string_cache::Atom; // https://w3c.github.io/uievents/#interface-uievent #[dom_struct] diff --git a/components/script/dom/userscripts.rs b/components/script/dom/userscripts.rs index a406041e3c4..a4051f44581 100644 --- a/components/script/dom/userscripts.rs +++ b/components/script/dom/userscripts.rs @@ -45,7 +45,7 @@ pub fn load_script(head: &HTMLHeadElement) { _ => continue }; let new_script = doc.CreateElement(DOMString::from("script")).unwrap(); - new_script.set_string_attribute(&atom!("src"), DOMString::from(name)); + new_script.set_string_attribute(&local_name!("src"), DOMString::from(name)); node.InsertBefore(new_script.upcast(), first_child.r()).unwrap(); } } diff --git a/components/script/dom/validitystate.rs b/components/script/dom/validitystate.rs index 938320b7254..c6bb0761f3c 100644 --- a/components/script/dom/validitystate.rs +++ b/components/script/dom/validitystate.rs @@ -10,8 +10,8 @@ use dom::element::Element; use dom::window::Window; // https://html.spec.whatwg.org/multipage/#validity-states -#[derive_JSTraceable] -#[derive_HeapSizeOf] +#[derive(JSTraceable)] +#[derive(HeapSizeOf)] pub enum ValidityStatus { ValueMissing, TypeMismatch, diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index c8a8a7436a4..e10e48e8ab8 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -50,7 +50,7 @@ use dom::htmltextareaelement::HTMLTextAreaElement; use dom::htmltitleelement::HTMLTitleElement; use dom::node::{ChildrenMutation, CloneChildrenFlag, Node, UnbindContext}; use dom::svgsvgelement::SVGSVGElement; -use string_cache::Atom; +use html5ever_atoms::LocalName; use style::attr::AttrValue; /// Trait to allow DOM nodes to opt-in to overriding (or adding to) common @@ -71,7 +71,7 @@ pub trait VirtualMethods { /// Returns the right AttrValue variant for the attribute with name `name` /// on this element. - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { match self.super_type() { Some(ref s) => s.parse_plain_attribute(name, value), _ => AttrValue::String(value.into()), diff --git a/components/script/dom/webglcontextevent.rs b/components/script/dom/webglcontextevent.rs index 079218ab3ae..c128515e81a 100644 --- a/components/script/dom/webglcontextevent.rs +++ b/components/script/dom/webglcontextevent.rs @@ -13,7 +13,7 @@ use dom::bindings::reflector::reflect_dom_object; use dom::bindings::str::DOMString; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::globalscope::GlobalScope; -use string_cache::Atom; +use servo_atoms::Atom; #[dom_struct] pub struct WebGLContextEvent { diff --git a/components/script/dom/webidls/Document.webidl b/components/script/dom/webidls/Document.webidl index 81a6c032df7..192c3d03714 100644 --- a/components/script/dom/webidls/Document.webidl +++ b/components/script/dom/webidls/Document.webidl @@ -28,8 +28,8 @@ interface Document : Node { readonly attribute DocumentType? doctype; [Pure] readonly attribute Element? documentElement; - HTMLCollection getElementsByTagName(DOMString localName); - HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName); + HTMLCollection getElementsByTagName(DOMString qualifiedName); + HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString qualifiedName); HTMLCollection getElementsByClassName(DOMString classNames); [NewObject, Throws] diff --git a/components/script/dom/webidls/MediaQueryList.webidl b/components/script/dom/webidls/MediaQueryList.webidl new file mode 100644 index 00000000000..2991efa89a8 --- /dev/null +++ b/components/script/dom/webidls/MediaQueryList.webidl @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +// https://drafts.csswg.org/cssom-view/#mediaquerylist + +[Exposed=(Window)] +interface MediaQueryList : EventTarget { + readonly attribute DOMString media; + readonly attribute boolean matches; + void addListener(EventListener? listener); + void removeListener(EventListener? listener); + attribute EventHandler onchange; +}; diff --git a/components/script/dom/webidls/TestRunner.webidl b/components/script/dom/webidls/TestRunner.webidl new file mode 100644 index 00000000000..0326c14dbec --- /dev/null +++ b/components/script/dom/webidls/TestRunner.webidl @@ -0,0 +1,16 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +// https://webbluetoothcg.github.io/web-bluetooth/tests#test-runner + +// callback BluetoothManualChooserEventsCallback = void(sequence<DOMString> events); + +[Pref="dom.bluetooth.testing.enabled", Exposed=Window] +interface TestRunner { + [Throws] + void setBluetoothMockDataSet(DOMString dataSetName); + // void setBluetoothManualChooser(); + // void getBluetoothManualChooserEvents(BluetoothManualChooserEventsCallback callback); + // void sendBluetoothManualChooserEvent(DOMString event, DOMString argument); +}; diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index 87cc3f3e486..5e7e08d4b18 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -120,7 +120,7 @@ dictionary ScrollToOptions : ScrollOptions { // http://dev.w3.org/csswg/cssom-view/#extensions-to-the-window-interface partial interface Window { - //MediaQueryList matchMedia(DOMString query); + [Exposed=(Window), NewObject] MediaQueryList matchMedia(DOMString query); [SameObject] readonly attribute Screen screen; // browsing context @@ -185,3 +185,10 @@ Window implements WindowLocalStorage; // http://w3c.github.io/animation-timing/#framerequestcallback callback FrameRequestCallback = void (DOMHighResTimeStamp time); + +// https://webbluetoothcg.github.io/web-bluetooth/tests#test-interfaces +partial interface Window { + [Pref="dom.bluetooth.testing.enabled", Exposed=Window] + readonly attribute TestRunner testRunner; + //readonly attribute EventSender eventSender; +}; diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 5914ff7ea89..dd49f62d247 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -498,7 +498,7 @@ impl Runnable for ConnectionEstablishedTask { } // Step 6. - ws.upcast().fire_simple_event("open"); + ws.upcast().fire_event(atom!("open")); } } @@ -548,7 +548,7 @@ impl Runnable for CloseTask { // Step 2. if self.failed { - ws.upcast().fire_simple_event("error"); + ws.upcast().fire_event(atom!("error")); } // Step 3. diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 5afbf475cc9..3d3d7dde2a7 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -3,6 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use app_units::Au; +use bluetooth_traits::BluetoothMethodMsg; +use cssparser::Parser; use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType}; use dom::bindings::callback::ExceptionHandling; use dom::bindings::cell::DOMRefCell; @@ -35,6 +37,7 @@ use dom::globalscope::GlobalScope; use dom::history::History; use dom::htmliframeelement::build_mozbrowser_custom_event; use dom::location::Location; +use dom::mediaquerylist::{MediaQueryList, WeakMediaQueryListVec}; use dom::messageevent::MessageEvent; use dom::navigator::Navigator; use dom::node::{Node, from_untrusted_node_address, window_from_node}; @@ -42,6 +45,7 @@ use dom::performance::Performance; use dom::promise::Promise; use dom::screen::Screen; use dom::storage::Storage; +use dom::testrunner::TestRunner; use euclid::{Point2D, Rect, Size2D}; use fetch; use ipc_channel::ipc::{self, IpcSender}; @@ -49,9 +53,8 @@ use js::jsapi::{HandleObject, HandleValue, JSAutoCompartment, JSContext}; use js::jsapi::{JS_GC, JS_GetRuntime, SetWindowProxy}; use js::jsval::UndefinedValue; use js::rust::Runtime; -use msg::constellation_msg::{FrameType, PipelineId, ReferrerPolicy}; -use net_traits::ResourceThreads; -use net_traits::bluetooth_thread::BluetoothMethodMsg; +use msg::constellation_msg::{FrameType, PipelineId}; +use net_traits::{ResourceThreads, ReferrerPolicy}; use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread}; use net_traits::storage_thread::StorageType; use num_traits::ToPrimitive; @@ -72,6 +75,7 @@ use script_traits::{ConstellationControlMsg, LoadData, MozBrowserEvent, Untruste use script_traits::{DocumentState, TimerEvent, TimerEventId}; use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest, WindowSizeData, WindowSizeType}; use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult}; +use servo_atoms::Atom; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; @@ -83,9 +87,9 @@ use std::sync::{Arc, Mutex}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::{Sender, channel}; use std::sync::mpsc::TryRecvError::{Disconnected, Empty}; -use string_cache::Atom; use style::context::ReflowGoal; use style::error_reporting::ParseErrorReporter; +use style::media_queries; use style::properties::longhands::overflow_x; use style::selector_impl::PseudoElement; use style::str::HTML_SPACE_CHARACTERS; @@ -233,6 +237,11 @@ pub struct Window { /// A list of scroll offsets for each scrollable element. scroll_offsets: DOMRefCell<HashMap<UntrustedNodeAddress, Point2D<f32>>>, + + /// All the MediaQueryLists we need to update + media_query_lists: WeakMediaQueryListVec, + + test_runner: MutNullableHeap<JS<TestRunner>>, } impl Window { @@ -309,6 +318,10 @@ impl Window { pub fn set_scroll_offsets(&self, offsets: HashMap<UntrustedNodeAddress, Point2D<f32>>) { *self.scroll_offsets.borrow_mut() = offsets } + + pub fn current_viewport(&self) -> Rect<Au> { + self.current_viewport.clone().get() + } } #[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))] @@ -856,11 +869,25 @@ impl WindowMethods for Window { } } + // https://drafts.csswg.org/cssom-view/#dom-window-matchmedia + fn MatchMedia(&self, query: DOMString) -> Root<MediaQueryList> { + let mut parser = Parser::new(&query); + let media_query_list = media_queries::parse_media_query_list(&mut parser); + let document = self.Document(); + let mql = MediaQueryList::new(&document, media_query_list); + self.media_query_lists.push(&*mql); + mql + } + #[allow(unrooted_must_root)] // https://fetch.spec.whatwg.org/#fetch-method fn Fetch(&self, input: RequestOrUSVString, init: &RequestInit) -> Rc<Promise> { fetch::Fetch(&self.upcast(), input, init) } + + fn TestRunner(&self) -> Root<TestRunner> { + self.test_runner.or_init(|| TestRunner::new(self.upcast())) + } } impl Window { @@ -1477,6 +1504,10 @@ impl Window { let custom_event = build_mozbrowser_custom_event(&self, event); custom_event.upcast::<Event>().fire(self.upcast()); } + + pub fn evaluate_media_queries_and_report_changes(&self) { + self.media_query_lists.evaluate_and_report_changes(); + } } impl Window { @@ -1563,6 +1594,8 @@ impl Window { ignore_further_async_events: Arc::new(AtomicBool::new(false)), error_reporter: error_reporter, scroll_offsets: DOMRefCell::new(HashMap::new()), + media_query_lists: WeakMediaQueryListVec::new(), + test_runner: Default::default(), }; WindowBinding::Wrap(runtime.cx(), win) diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index 87cf1f3e55e..42c0d1e553d 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -138,7 +138,7 @@ impl Worker { pub fn dispatch_simple_error(address: TrustedWorkerAddress) { let worker = address.root(); - worker.upcast().fire_simple_event("error"); + worker.upcast().fire_event(atom!("error")); } #[allow(unsafe_code)] diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 8cd09b3fdbe..2efa2920cb8 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -27,9 +27,8 @@ use ipc_channel::ipc::IpcSender; use js::jsapi::{HandleValue, JSAutoCompartment, JSContext, JSRuntime}; use js::jsval::UndefinedValue; use js::rust::Runtime; -use msg::constellation_msg::{PipelineId, ReferrerPolicy}; -use net_traits::{IpcSend, LoadOrigin}; -use net_traits::{LoadContext, load_whole_resource}; +use net_traits::{IpcSend, load_whole_resource}; +use net_traits::request::{CredentialsMode, Destination, RequestInit as NetRequestInit, Type as RequestType}; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_result}; use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback}; use script_thread::{Runnable, RunnableWrapper}; @@ -179,18 +178,6 @@ impl WorkerGlobalScope { } } -impl LoadOrigin for WorkerGlobalScope { - fn referrer_url(&self) -> Option<Url> { - None - } - fn referrer_policy(&self) -> Option<ReferrerPolicy> { - None - } - fn pipeline_id(&self) -> Option<PipelineId> { - Some(self.upcast::<GlobalScope>().pipeline_id()) - } -} - impl WorkerGlobalScopeMethods for WorkerGlobalScope { // https://html.spec.whatwg.org/multipage/#dom-workerglobalscope-self fn Self_(&self) -> Root<WorkerGlobalScope> { @@ -221,10 +208,20 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope { rooted!(in(self.runtime.cx()) let mut rval = UndefinedValue()); for url in urls { let global_scope = self.upcast::<GlobalScope>(); - let (url, source) = match load_whole_resource(LoadContext::Script, - &global_scope.resource_threads().sender(), - url, - self) { + let request = NetRequestInit { + url: url.clone(), + type_: RequestType::Script, + destination: Destination::Script, + credentials_mode: CredentialsMode::Include, + use_url_credentials: true, + origin: self.worker_url.clone(), + pipeline_id: Some(self.upcast::<GlobalScope>().pipeline_id()), + referrer_url: None, + referrer_policy: None, + .. NetRequestInit::default() + }; + let (url, source) = match load_whole_resource(request, + &global_scope.resource_threads().sender()) { Err(_) => return Err(Error::Network), Ok((metadata, bytes)) => { (metadata.final_url, String::from_utf8(bytes).unwrap()) diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 1f25a9e02d1..c404c482308 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -48,21 +48,21 @@ use ipc_channel::router::ROUTER; use js::jsapi::{JSContext, JS_ParseJSON}; use js::jsapi::JS_ClearPendingException; use js::jsval::{JSVal, NullValue, UndefinedValue}; -use msg::constellation_msg::{PipelineId, ReferrerPolicy}; +use msg::constellation_msg::PipelineId; use net_traits::{CoreResourceThread, FetchMetadata, FilteredMetadata}; -use net_traits::{FetchResponseListener, LoadOrigin, NetworkError}; +use net_traits::{FetchResponseListener, LoadOrigin, NetworkError, ReferrerPolicy}; use net_traits::CoreResourceMsg::Fetch; use net_traits::request::{CredentialsMode, Destination, RequestInit, RequestMode}; use net_traits::trim_http_whitespace; use network_listener::{NetworkListener, PreInvoke}; use script_runtime::ScriptChan; +use servo_atoms::Atom; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; use std::default::Default; use std::str; use std::sync::{Arc, Mutex}; -use string_cache::Atom; use time; use timers::{OneshotTimerCallback, OneshotTimerHandle}; use url::{Position, Url}; diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs index ace0e7f40f7..c83e8232a40 100644 --- a/components/script/layout_wrapper.rs +++ b/components/script/layout_wrapper.rs @@ -40,6 +40,7 @@ use dom::node::{CAN_BE_FRAGMENTED, DIRTY_ON_VIEWPORT_SIZE_CHANGE, HAS_CHANGED, H use dom::node::{LayoutNodeHelpers, Node}; use dom::text::Text; use gfx_traits::ByteIndex; +use html5ever_atoms::{LocalName, Namespace}; use msg::constellation_msg::PipelineId; use parking_lot::RwLock; use range::Range; @@ -50,12 +51,12 @@ use script_layout_interface::wrapper_traits::{DangerousThreadSafeLayoutNode, Get use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; use selectors::matching::ElementFlags; use selectors::parser::{AttrSelector, NamespaceConstraint}; +use servo_atoms::Atom; use std::fmt; use std::marker::PhantomData; use std::mem::transmute; use std::sync::Arc; use std::sync::atomic::Ordering; -use string_cache::{Atom, Namespace}; use style::atomic_refcell::{AtomicRef, AtomicRefCell}; use style::attr::AttrValue; use style::computed_values::display; @@ -451,12 +452,12 @@ impl<'le> TElement for ServoLayoutElement<'le> { } #[inline] - fn has_attr(&self, namespace: &Namespace, attr: &Atom) -> bool { + fn has_attr(&self, namespace: &Namespace, attr: &LocalName) -> bool { self.get_attr(namespace, attr).is_some() } #[inline] - fn attr_equals(&self, namespace: &Namespace, attr: &Atom, val: &Atom) -> bool { + fn attr_equals(&self, namespace: &Namespace, attr: &LocalName, val: &Atom) -> bool { self.get_attr(namespace, attr).map_or(false, |x| x == val) } @@ -526,7 +527,7 @@ impl<'le> ServoLayoutElement<'le> { } #[inline] - fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&str> { + fn get_attr(&self, namespace: &Namespace, name: &LocalName) -> Option<&str> { unsafe { (*self.element.unsafe_get()).get_attr_val_for_layout(namespace, name) } @@ -628,7 +629,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> { } #[inline] - fn get_local_name(&self) -> &Atom { + fn get_local_name(&self) -> &LocalName { self.element.local_name() } @@ -647,14 +648,14 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> { NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => - (*self.element.unsafe_get()).get_attr_val_for_layout(&ns!(), &atom!("href")).is_some(), + (*self.element.unsafe_get()).get_attr_val_for_layout(&ns!(), &local_name!("href")).is_some(), _ => false, } }, NonTSPseudoClass::Visited => false, NonTSPseudoClass::ServoNonZeroBorder => unsafe { - match (*self.element.unsafe_get()).get_attr_for_layout(&ns!(), &atom!("border")) { + match (*self.element.unsafe_get()).get_attr_for_layout(&ns!(), &local_name!("border")) { None | Some(&AttrValue::UInt(_, 0)) => false, _ => true, } @@ -962,7 +963,7 @@ impl<ConcreteNode> Iterator for ThreadSafeLayoutNodeChildrenIterator<ConcreteNod loop { let next_node = if let Some(ref node) = current_node { if node.is_element() && - node.as_element().unwrap().get_local_name() == &atom!("summary") && + node.as_element().unwrap().get_local_name() == &local_name!("summary") && node.as_element().unwrap().get_namespace() == &ns!(html) { self.current_node = None; return Some(node.clone()); @@ -980,7 +981,7 @@ impl<ConcreteNode> Iterator for ThreadSafeLayoutNodeChildrenIterator<ConcreteNod let node = self.current_node.clone(); let node = node.and_then(|node| { if node.is_element() && - node.as_element().unwrap().get_local_name() == &atom!("summary") && + node.as_element().unwrap().get_local_name() == &local_name!("summary") && node.as_element().unwrap().get_namespace() == &ns!(html) { unsafe { node.dangerous_next_sibling() } } else { @@ -1061,7 +1062,7 @@ impl<'le> ThreadSafeLayoutElement for ServoThreadSafeLayoutElement<'le> { self.as_node().type_id() } - fn get_attr<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str> { + fn get_attr<'a>(&'a self, namespace: &Namespace, name: &LocalName) -> Option<&'a str> { self.element.get_attr(namespace, name) } @@ -1137,7 +1138,7 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> { } #[inline] - fn get_local_name(&self) -> &Atom { + fn get_local_name(&self) -> &LocalName { self.element.get_local_name() } diff --git a/components/script/lib.rs b/components/script/lib.rs index f2227fc363a..d847af7b62f 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -6,14 +6,13 @@ #![feature(conservative_impl_trait)] #![feature(const_fn)] #![feature(core_intrinsics)] -#![feature(custom_attribute)] -#![feature(custom_derive)] #![feature(fnbox)] #![feature(mpsc_select)] #![feature(nonzero)] #![feature(on_unimplemented)] #![feature(optin_builtin_traits)] #![feature(plugin)] +#![feature(proc_macro)] #![feature(slice_patterns)] #![feature(stmt_expr_attributes)] #![feature(try_from)] @@ -24,7 +23,6 @@ #![doc = "The script crate contains all matters DOM."] -#![plugin(heapsize_plugin)] #![plugin(phf_macros)] #![plugin(plugins)] @@ -34,6 +32,7 @@ extern crate audio_video_metadata; #[allow(unused_extern_crates)] #[macro_use] extern crate bitflags; +extern crate bluetooth_traits; extern crate canvas_traits; extern crate caseless; extern crate cookie as cookie_rs; @@ -46,13 +45,17 @@ extern crate euclid; extern crate fnv; extern crate gfx_traits; extern crate heapsize; +#[macro_use] extern crate heapsize_derive; extern crate html5ever; +#[macro_use] extern crate html5ever_atoms; extern crate hyper; extern crate hyper_serde; extern crate image; extern crate ipc_channel; #[macro_use] extern crate js; +#[macro_use] +extern crate jstraceable_derive; extern crate libc; #[macro_use] extern crate log; @@ -77,10 +80,11 @@ extern crate script_layout_interface; extern crate script_traits; extern crate selectors; extern crate serde; +#[macro_use] extern crate servo_atoms; extern crate smallvec; -#[macro_use(atom, ns)] extern crate string_cache; #[macro_use] extern crate style; +extern crate style_traits; extern crate time; #[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))] extern crate tinyfiledialogs; diff --git a/components/script/network_listener.rs b/components/script/network_listener.rs index 4ff65bf8073..d69b7334bad 100644 --- a/components/script/network_listener.rs +++ b/components/script/network_listener.rs @@ -2,8 +2,7 @@ * 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 net_traits::{Action, AsyncResponseListener, FetchResponseListener}; -use net_traits::{FetchResponseMsg, ResponseAction}; +use net_traits::{Action, FetchResponseListener, FetchResponseMsg}; use script_runtime::{CommonScriptMsg, ScriptChan}; use script_runtime::ScriptThreadEventCategory::NetworkEvent; use script_thread::{Runnable, RunnableWrapper}; @@ -35,13 +34,6 @@ impl<Listener: PreInvoke + Send + 'static> NetworkListener<Listener> { } // helps type inference -impl<Listener: AsyncResponseListener + PreInvoke + Send + 'static> NetworkListener<Listener> { - pub fn notify_action(&self, action: ResponseAction) { - self.notify(action); - } -} - -// helps type inference impl<Listener: FetchResponseListener + PreInvoke + Send + 'static> NetworkListener<Listener> { pub fn notify_fetch(&self, action: FetchResponseMsg) { self.notify(action); diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index d98298d0cb7..86d742680ee 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -17,6 +17,7 @@ //! a page runs its course and the script thread returns to processing events in the main event //! loop. +use bluetooth_traits::BluetoothMethodMsg; use devtools; use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo}; use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId}; @@ -57,7 +58,7 @@ use dom::window::{ReflowReason, Window}; use dom::worker::TrustedWorkerAddress; use euclid::Rect; use euclid::point::Point2D; -use hyper::header::{ContentType, Headers, HttpDate, LastModified}; +use hyper::header::{ContentType, HttpDate, LastModified}; use hyper::header::ReferrerPolicy as ReferrerPolicyHeader; use hyper::method::Method; use hyper::mime::{Mime, SubLevel, TopLevel}; @@ -71,11 +72,10 @@ use js::jsval::UndefinedValue; use js::rust::Runtime; use layout_wrapper::ServoLayoutNode; use mem::heap_size_of_self_and_children; -use msg::constellation_msg::{FrameType, PipelineId, PipelineNamespace, ReferrerPolicy}; -use net_traits::{AsyncResponseTarget, CoreResourceMsg, LoadConsumer, LoadContext, Metadata, ResourceThreads}; -use net_traits::{IpcSend, LoadData as NetLoadData}; -use net_traits::bluetooth_thread::BluetoothMethodMsg; +use msg::constellation_msg::{FrameId, FrameType, PipelineId, PipelineNamespace}; +use net_traits::{CoreResourceMsg, IpcSend, Metadata, ReferrerPolicy, ResourceThreads}; use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCacheThread}; +use net_traits::request::{CredentialsMode, Destination, RequestInit}; use network_listener::NetworkListener; use profile_traits::mem::{self, OpaqueSender, Report, ReportKind, ReportsChan}; use profile_traits::time::{self, ProfilerCategory, profile}; @@ -135,6 +135,8 @@ pub unsafe fn trace_thread(tr: *mut JSTracer) { struct InProgressLoad { /// The pipeline which requested this load. pipeline_id: PipelineId, + /// The frame being loaded into. + frame_id: FrameId, /// The parent pipeline and frame type associated with this load, if any. parent_info: Option<(PipelineId, FrameType)>, /// The current window size associated with this pipeline. @@ -154,12 +156,14 @@ struct InProgressLoad { impl InProgressLoad { /// Create a new InProgressLoad object. fn new(id: PipelineId, + frame_id: FrameId, parent_info: Option<(PipelineId, FrameType)>, layout_chan: Sender<message::Msg>, window_size: Option<WindowSizeData>, url: Url) -> InProgressLoad { InProgressLoad { pipeline_id: id, + frame_id: frame_id, parent_info: parent_info, layout_chan: layout_chan, window_size: window_size, @@ -452,15 +456,15 @@ impl ScriptThreadFactory for ScriptThread { let (sender, receiver) = channel(); let layout_chan = sender.clone(); - let pipeline_id = state.id; thread::spawn_named(format!("ScriptThread {:?}", state.id), move || { thread_state::initialize(thread_state::SCRIPT); - PipelineId::install(pipeline_id); + PipelineId::install(state.id); PipelineNamespace::install(state.pipeline_namespace_id); let roots = RootCollection::new(); let _stack_roots_tls = StackRootTLS::new(&roots); let id = state.id; + let frame_id = state.frame_id; let parent_info = state.parent_info; let mem_profiler_chan = state.mem_profiler_chan.clone(); let window_size = state.window_size; @@ -474,7 +478,7 @@ impl ScriptThreadFactory for ScriptThread { let mut failsafe = ScriptMemoryFailsafe::new(&script_thread); - let new_load = InProgressLoad::new(id, parent_info, layout_chan, window_size, + let new_load = InProgressLoad::new(id, frame_id, parent_info, layout_chan, window_size, load_data.url.clone()); script_thread.start_page_load(new_load, load_data); @@ -888,8 +892,8 @@ impl ScriptThread { fn handle_msg_from_constellation(&self, msg: ConstellationControlMsg) { match msg { - ConstellationControlMsg::Navigate(parent_pipeline_id, pipeline_id, load_data, replace) => - self.handle_navigate(parent_pipeline_id, Some(pipeline_id), load_data, replace), + ConstellationControlMsg::Navigate(parent_pipeline_id, frame_id, load_data, replace) => + self.handle_navigate(parent_pipeline_id, Some(frame_id), load_data, replace), ConstellationControlMsg::SendEvent(id, event) => self.handle_event(id, event), ConstellationControlMsg::ResizeInactive(id, new_size) => @@ -902,22 +906,22 @@ impl ScriptThread { self.handle_thaw_msg(pipeline_id), ConstellationControlMsg::ChangeFrameVisibilityStatus(pipeline_id, visible) => self.handle_visibility_change_msg(pipeline_id, visible), - ConstellationControlMsg::NotifyVisibilityChange(parent_pipeline_id, pipeline_id, visible) => - self.handle_visibility_change_complete_msg(parent_pipeline_id, pipeline_id, visible), + ConstellationControlMsg::NotifyVisibilityChange(parent_pipeline_id, frame_id, visible) => + self.handle_visibility_change_complete_msg(parent_pipeline_id, frame_id, visible), ConstellationControlMsg::MozBrowserEvent(parent_pipeline_id, - pipeline_id, + frame_id, event) => self.handle_mozbrowser_event_msg(parent_pipeline_id, - pipeline_id, + frame_id, event), ConstellationControlMsg::UpdatePipelineId(parent_pipeline_id, - old_pipeline_id, + frame_id, new_pipeline_id) => self.handle_update_pipeline_id(parent_pipeline_id, - old_pipeline_id, + frame_id, new_pipeline_id), - ConstellationControlMsg::FocusIFrame(parent_pipeline_id, pipeline_id) => - self.handle_focus_iframe_msg(parent_pipeline_id, pipeline_id), + ConstellationControlMsg::FocusIFrame(parent_pipeline_id, frame_id) => + self.handle_focus_iframe_msg(parent_pipeline_id, frame_id), ConstellationControlMsg::WebDriverScriptCommand(pipeline_id, msg) => self.handle_webdriver_msg(pipeline_id, msg), ConstellationControlMsg::TickAllAnimations(pipeline_id) => @@ -927,10 +931,10 @@ impl ScriptThread { ConstellationControlMsg::WebFontLoaded(pipeline_id) => self.handle_web_font_loaded(pipeline_id), ConstellationControlMsg::DispatchFrameLoadEvent { - target: pipeline_id, parent: parent_pipeline_id } => - self.handle_frame_load_event(parent_pipeline_id, pipeline_id), - ConstellationControlMsg::FramedContentChanged(parent_pipeline_id, pipeline_id) => - self.handle_framed_content_changed(parent_pipeline_id, pipeline_id), + target: frame_id, parent: parent_id, child: child_id } => + self.handle_frame_load_event(parent_id, frame_id, child_id), + ConstellationControlMsg::FramedContentChanged(parent_pipeline_id, frame_id) => + self.handle_framed_content_changed(parent_pipeline_id, frame_id), ConstellationControlMsg::ReportCSSError(pipeline_id, filename, line, column, msg) => self.handle_css_error_reporting(pipeline_id, filename, line, column, msg), ConstellationControlMsg::Reload(pipeline_id) => @@ -1139,6 +1143,7 @@ impl ScriptThread { let NewLayoutInfo { parent_pipeline_id, new_pipeline_id, + frame_id, frame_type, load_data, pipeline_port, @@ -1175,7 +1180,7 @@ impl ScriptThread { .unwrap(); // Kick off the fetch for the new resource. - let new_load = InProgressLoad::new(new_pipeline_id, Some((parent_pipeline_id, frame_type)), + let new_load = InProgressLoad::new(new_pipeline_id, frame_id, Some((parent_pipeline_id, frame_type)), layout_chan, parent_window.window_size(), load_data.url.clone()); self.start_page_load(new_load, load_data); @@ -1187,12 +1192,15 @@ impl ScriptThread { None => return warn!("Message sent to closed pipeline {}.", pipeline), }; if doc.loader().is_blocked() { + debug!("Script thread got loads complete while loader is blocked."); return; } doc.mut_loader().inhibit_events(); // https://html.spec.whatwg.org/multipage/#the-end step 7 + // Schedule a task to fire a "load" event (if no blocking loads have arrived in the mean time) + // NOTE: we can end up executing this code more than once, in case more blocking loads arrive. let handler = box DocumentProgressHandler::new(Trusted::new(&doc)); self.dom_manipulation_task_source.queue(handler, doc.window().upcast()).unwrap(); @@ -1259,7 +1267,7 @@ impl ScriptThread { } /// Updates iframe element after a change in visibility - fn handle_visibility_change_complete_msg(&self, parent_pipeline_id: PipelineId, id: PipelineId, visible: bool) { + fn handle_visibility_change_complete_msg(&self, parent_pipeline_id: PipelineId, id: FrameId, visible: bool) { if let Some(root_context) = self.browsing_context.get() { if let Some(ref inner_context) = root_context.find(parent_pipeline_id) { if let Some(iframe) = inner_context.active_document().find_iframe(id) { @@ -1328,12 +1336,12 @@ impl ScriptThread { fn handle_focus_iframe_msg(&self, parent_pipeline_id: PipelineId, - pipeline_id: PipelineId) { + frame_id: FrameId) { let borrowed_context = self.root_browsing_context(); let context = borrowed_context.find(parent_pipeline_id).unwrap(); let doc = context.active_document(); - let frame_element = doc.find_iframe(pipeline_id); + let frame_element = doc.find_iframe(frame_id); if let Some(ref frame_element) = frame_element { doc.begin_focus_transaction(); @@ -1344,11 +1352,11 @@ impl ScriptThread { fn handle_framed_content_changed(&self, parent_pipeline_id: PipelineId, - pipeline_id: PipelineId) { + frame_id: FrameId) { let root_context = self.root_browsing_context(); let context = root_context.find(parent_pipeline_id).unwrap(); let doc = context.active_document(); - let frame_element = doc.find_iframe(pipeline_id); + let frame_element = doc.find_iframe(frame_id); if let Some(ref frame_element) = frame_element { frame_element.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage); let window = context.active_window(); @@ -1362,14 +1370,14 @@ impl ScriptThread { /// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserloadstart fn handle_mozbrowser_event_msg(&self, parent_pipeline_id: PipelineId, - pipeline_id: Option<PipelineId>, + frame_id: Option<FrameId>, event: MozBrowserEvent) { match self.root_browsing_context().find(parent_pipeline_id) { None => warn!("Mozbrowser event after pipeline {:?} closed.", parent_pipeline_id), - Some(context) => match pipeline_id { + Some(context) => match frame_id { None => context.active_window().dispatch_mozbrowser_event(event), - Some(pipeline_id) => match context.active_document().find_iframe(pipeline_id) { - None => warn!("Mozbrowser event after iframe {:?}/{:?} closed.", parent_pipeline_id, pipeline_id), + Some(frame_id) => match context.active_document().find_iframe(frame_id) { + None => warn!("Mozbrowser event after iframe {:?}/{:?} closed.", parent_pipeline_id, frame_id), Some(frame_element) => frame_element.dispatch_mozbrowser_event(event), }, }, @@ -1378,13 +1386,13 @@ impl ScriptThread { fn handle_update_pipeline_id(&self, parent_pipeline_id: PipelineId, - old_pipeline_id: PipelineId, + frame_id: FrameId, new_pipeline_id: PipelineId) { let borrowed_context = self.root_browsing_context(); let frame_element = borrowed_context.find(parent_pipeline_id).and_then(|context| { let doc = context.active_document(); - doc.find_iframe(old_pipeline_id) + doc.find_iframe(frame_id) }); frame_element.unwrap().update_pipeline_id(new_pipeline_id); @@ -1567,13 +1575,15 @@ impl ScriptThread { } /// Notify the containing document of a child frame that has completed loading. - fn handle_frame_load_event(&self, parent_pipeline_id: PipelineId, id: PipelineId) { - let document = match self.root_browsing_context().find(parent_pipeline_id) { + fn handle_frame_load_event(&self, parent_id: PipelineId, frame_id: FrameId, child_id: PipelineId) { + let document = match self.root_browsing_context().find(parent_id) { Some(browsing_context) => browsing_context.active_document(), - None => return warn!("Message sent to closed pipeline {}.", parent_pipeline_id), + None => return warn!("Message sent to closed pipeline {}.", parent_id), }; - if let Some(iframe) = document.find_iframe(id) { - iframe.iframe_load_event_steps(id); + if let Some(iframe) = document.find_iframe(frame_id) { + if iframe.pipeline_id() == Some(child_id) { + iframe.iframe_load_event_steps(child_id); + } } } @@ -1609,7 +1619,7 @@ impl ScriptThread { root_context.and_then(|root_context| { root_context.find(parent_id).and_then(|context| { let doc = context.active_document(); - doc.find_iframe(incomplete.pipeline_id) + doc.find_iframe(incomplete.frame_id) }) }) }); @@ -1937,7 +1947,7 @@ impl ScriptThread { .filter_map(Root::downcast::<HTMLAnchorElement>) .next() { let status = anchor.upcast::<Element>() - .get_attribute(&ns!(), &atom!("href")) + .get_attribute(&ns!(), &local_name!("href")) .and_then(|href| { let value = href.value(); let url = document.url(); @@ -2033,7 +2043,7 @@ impl ScriptThread { /// The entry point for content to notify that a new load has been requested /// for the given pipeline (specifically the "navigate" algorithm). fn handle_navigate(&self, parent_pipeline_id: PipelineId, - pipeline_id: Option<PipelineId>, + frame_id: Option<FrameId>, load_data: LoadData, replace: bool) { // Step 7. @@ -2053,12 +2063,12 @@ impl ScriptThread { } } - match pipeline_id { - Some(pipeline_id) => { + match frame_id { + Some(frame_id) => { let root_context = self.root_browsing_context(); let iframe = root_context.find(parent_pipeline_id).and_then(|context| { let doc = context.active_document(); - doc.find_iframe(pipeline_id) + doc.find_iframe(frame_id) }); if let Some(iframe) = iframe.r() { iframe.navigate_or_reload_child_browsing_context(Some(load_data), replace); @@ -2099,6 +2109,11 @@ impl ScriptThread { 0i32); uievent.upcast::<Event>().fire(window.upcast()); } + + // https://html.spec.whatwg.org/multipage/#event-loop-processing-model + // Step 7.7 - evaluate media queries and report changes + // Since we have resized, we need to re-evaluate MQLs + window.evaluate_media_queries_and_report_changes(); } /// Initiate a non-blocking fetch for a specified resource. Stores the InProgressLoad @@ -2114,30 +2129,29 @@ impl ScriptThread { wrapper: None, }; ROUTER.add_route(action_receiver.to_opaque(), box move |message| { - listener.notify_action(message.to().unwrap()); + listener.notify_fetch(message.to().unwrap()); }); - let response_target = AsyncResponseTarget { - sender: action_sender, - }; if load_data.url.scheme() == "javascript" { load_data.url = Url::parse("about:blank").unwrap(); } - self.resource_threads.send(CoreResourceMsg::Load(NetLoadData { - context: LoadContext::Browsing, - url: load_data.url, + let request = RequestInit { + url: load_data.url.clone(), method: load_data.method, - headers: Headers::new(), - preserved_headers: load_data.headers, - data: load_data.data, - cors: None, + destination: Destination::Document, + credentials_mode: CredentialsMode::Include, + use_url_credentials: true, + origin: load_data.url, pipeline_id: Some(id), - credentials_flag: true, + referrer_url: load_data.referrer_url, referrer_policy: load_data.referrer_policy, - referrer_url: load_data.referrer_url - }, LoadConsumer::Listener(response_target), None)).unwrap(); + headers: load_data.headers, + body: load_data.data, + .. RequestInit::default() + }; + self.resource_threads.send(CoreResourceMsg::Fetch(request, action_sender)).unwrap(); self.incomplete_loads.borrow_mut().push(incomplete); } diff --git a/components/script/task_source/dom_manipulation.rs b/components/script/task_source/dom_manipulation.rs index c5b4e4b5f73..75fd4021168 100644 --- a/components/script/task_source/dom_manipulation.rs +++ b/components/script/task_source/dom_manipulation.rs @@ -8,9 +8,9 @@ use dom::event::{EventBubbles, EventCancelable, EventRunnable, SimpleEventRunnab use dom::eventtarget::EventTarget; use dom::window::Window; use script_thread::{MainThreadScriptMsg, Runnable, RunnableWrapper, ScriptThread}; +use servo_atoms::Atom; use std::result::Result; use std::sync::mpsc::Sender; -use string_cache::Atom; use task_source::TaskSource; #[derive(JSTraceable, Clone)] diff --git a/components/script/task_source/user_interaction.rs b/components/script/task_source/user_interaction.rs index d3850e9f813..c97e1e1895a 100644 --- a/components/script/task_source/user_interaction.rs +++ b/components/script/task_source/user_interaction.rs @@ -8,9 +8,9 @@ use dom::event::{EventBubbles, EventCancelable, EventRunnable}; use dom::eventtarget::EventTarget; use dom::window::Window; use script_thread::{MainThreadScriptMsg, Runnable, RunnableWrapper, ScriptThread}; +use servo_atoms::Atom; use std::result::Result; use std::sync::mpsc::Sender; -use string_cache::Atom; use task_source::TaskSource; #[derive(JSTraceable, Clone)] |