mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Make DOMString a newtype around String, rather than a typedef.
This should make it somewhat easier to experiment with alternative representations in the future. To reduce churn, this commit leaves the String field public, though. Also, this will allow us to use the default String type to represent the IDL USVString type, which explicitly forbids unpaired surrogates, ans as such is a better match to the Rust String type.
This commit is contained in:
parent
e6aa976462
commit
6b75078503
83 changed files with 393 additions and 297 deletions
|
@ -206,16 +206,16 @@ impl NodeInfoToProtocol for NodeInfo {
|
||||||
|
|
||||||
NodeActorMsg {
|
NodeActorMsg {
|
||||||
actor: actor_name,
|
actor: actor_name,
|
||||||
baseURI: self.baseURI,
|
baseURI: self.baseURI.0,
|
||||||
parent: actors.script_to_actor(self.parent.clone()),
|
parent: actors.script_to_actor(self.parent.clone()),
|
||||||
nodeType: self.nodeType,
|
nodeType: self.nodeType,
|
||||||
namespaceURI: self.namespaceURI,
|
namespaceURI: self.namespaceURI.0,
|
||||||
nodeName: self.nodeName,
|
nodeName: self.nodeName.0,
|
||||||
numChildren: self.numChildren,
|
numChildren: self.numChildren,
|
||||||
|
|
||||||
name: self.name,
|
name: self.name.0,
|
||||||
publicId: self.publicId,
|
publicId: self.publicId.0,
|
||||||
systemId: self.systemId,
|
systemId: self.systemId.0,
|
||||||
|
|
||||||
attrs: self.attrs.into_iter().map(|attr| {
|
attrs: self.attrs.into_iter().map(|attr| {
|
||||||
AttrMsg {
|
AttrMsg {
|
||||||
|
@ -233,7 +233,7 @@ impl NodeInfoToProtocol for NodeInfo {
|
||||||
|
|
||||||
isDocumentElement: self.isDocumentElement,
|
isDocumentElement: self.isDocumentElement,
|
||||||
|
|
||||||
shortValue: self.shortValue,
|
shortValue: self.shortValue.0,
|
||||||
incompleteValue: self.incompleteValue,
|
incompleteValue: self.incompleteValue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
|
||||||
let DevtoolsPageInfo { title, url } = page_info;
|
let DevtoolsPageInfo { title, url } = page_info;
|
||||||
let tab = TabActor {
|
let tab = TabActor {
|
||||||
name: actors.new_name("tab"),
|
name: actors.new_name("tab"),
|
||||||
title: title,
|
title: title.0,
|
||||||
url: url.serialize(),
|
url: url.serialize(),
|
||||||
console: console.name(),
|
console: console.name(),
|
||||||
inspector: inspector.name(),
|
inspector: inspector.name(),
|
||||||
|
|
|
@ -102,22 +102,22 @@ pub struct AttrInfo {
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct NodeInfo {
|
pub struct NodeInfo {
|
||||||
pub uniqueId: String,
|
pub uniqueId: String,
|
||||||
pub baseURI: String,
|
pub baseURI: DOMString,
|
||||||
pub parent: String,
|
pub parent: String,
|
||||||
pub nodeType: u16,
|
pub nodeType: u16,
|
||||||
pub namespaceURI: String,
|
pub namespaceURI: DOMString,
|
||||||
pub nodeName: String,
|
pub nodeName: DOMString,
|
||||||
pub numChildren: usize,
|
pub numChildren: usize,
|
||||||
|
|
||||||
pub name: String,
|
pub name: DOMString,
|
||||||
pub publicId: String,
|
pub publicId: DOMString,
|
||||||
pub systemId: String,
|
pub systemId: DOMString,
|
||||||
|
|
||||||
pub attrs: Vec<AttrInfo>,
|
pub attrs: Vec<AttrInfo>,
|
||||||
|
|
||||||
pub isDocumentElement: bool,
|
pub isDocumentElement: bool,
|
||||||
|
|
||||||
pub shortValue: String,
|
pub shortValue: DOMString,
|
||||||
pub incompleteValue: bool,
|
pub incompleteValue: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -982,7 +982,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
||||||
}
|
}
|
||||||
if let Some(input) = this.downcast::<HTMLInputElement>() {
|
if let Some(input) = this.downcast::<HTMLInputElement>() {
|
||||||
let data = unsafe { input.get_value_for_layout() };
|
let data = unsafe { input.get_value_for_layout() };
|
||||||
return TextContent::Text(data);
|
return TextContent::Text(data.0);
|
||||||
}
|
}
|
||||||
if let Some(area) = this.downcast::<HTMLTextAreaElement>() {
|
if let Some(area) = this.downcast::<HTMLTextAreaElement>() {
|
||||||
let data = unsafe { area.get_value_for_layout() };
|
let data = unsafe { area.get_value_for_layout() };
|
||||||
|
|
|
@ -183,7 +183,7 @@ impl StorageManager {
|
||||||
let data = self.select_data(storage_type);
|
let data = self.select_data(storage_type);
|
||||||
sender.send(data.get(&origin)
|
sender.send(data.get(&origin)
|
||||||
.and_then(|&(_, ref entry)| entry.get(&name))
|
.and_then(|&(_, ref entry)| entry.get(&name))
|
||||||
.map(|value| value.to_string())).unwrap();
|
.map(|value| DOMString(value.to_string()))).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends Some(old_value) in case there was a previous value with the key name, otherwise sends None
|
/// Sends Some(old_value) in case there was a previous value with the key name, otherwise sends None
|
||||||
|
|
|
@ -23,6 +23,7 @@ use script_task::get_page;
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use util::str::DOMString;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
@ -39,7 +40,7 @@ pub fn handle_evaluate_js(global: &GlobalRef, eval: String, reply: IpcSender<Eva
|
||||||
EvaluateJSReply::NumberValue(
|
EvaluateJSReply::NumberValue(
|
||||||
FromJSValConvertible::from_jsval(cx, rval.handle(), ()).unwrap())
|
FromJSValConvertible::from_jsval(cx, rval.handle(), ()).unwrap())
|
||||||
} else if rval.ptr.is_string() {
|
} else if rval.ptr.is_string() {
|
||||||
EvaluateJSReply::StringValue(jsstring_to_str(cx, rval.ptr.to_string()))
|
EvaluateJSReply::StringValue(jsstring_to_str(cx, rval.ptr.to_string()).0)
|
||||||
} else if rval.ptr.is_null() {
|
} else if rval.ptr.is_null() {
|
||||||
EvaluateJSReply::NullValue
|
EvaluateJSReply::NullValue
|
||||||
} else {
|
} else {
|
||||||
|
@ -159,9 +160,9 @@ pub fn handle_modify_attribute(page: &Rc<Page>,
|
||||||
for modification in modifications {
|
for modification in modifications {
|
||||||
match modification.newValue {
|
match modification.newValue {
|
||||||
Some(string) => {
|
Some(string) => {
|
||||||
let _ = elem.SetAttribute(modification.attributeName, string);
|
let _ = elem.SetAttribute(DOMString(modification.attributeName), DOMString(string));
|
||||||
},
|
},
|
||||||
None => elem.RemoveAttribute(modification.attributeName),
|
None => elem.RemoveAttribute(DOMString(modification.attributeName)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ use dom::eventtarget::EventTarget;
|
||||||
use dom::mouseevent::MouseEvent;
|
use dom::mouseevent::MouseEvent;
|
||||||
use dom::node::window_from_node;
|
use dom::node::window_from_node;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
use util::str::DOMString;
|
||||||
|
|
||||||
/// Trait for elements with defined activation behavior
|
/// Trait for elements with defined activation behavior
|
||||||
pub trait Activatable {
|
pub trait Activatable {
|
||||||
|
@ -46,7 +47,7 @@ pub trait Activatable {
|
||||||
// https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event
|
// https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event
|
||||||
let win = window_from_node(element);
|
let win = window_from_node(element);
|
||||||
let target = element.upcast();
|
let target = element.upcast();
|
||||||
let mouse = MouseEvent::new(win.r(), "click".to_owned(),
|
let mouse = MouseEvent::new(win.r(), DOMString("click".to_owned()),
|
||||||
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, Some(win.r()), 1,
|
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, Some(win.r()), 1,
|
||||||
0, 0, 0, 0, ctrlKey, shiftKey, altKey, metaKey,
|
0, 0, 0, 0, ctrlKey, shiftKey, altKey, metaKey,
|
||||||
0, None);
|
0, None);
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl AttrValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue {
|
pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue {
|
||||||
let tokens = str_join(&atoms, "\x20");
|
let tokens = DOMString(str_join(&atoms, "\x20"));
|
||||||
AttrValue::TokenList(tokens, atoms)
|
AttrValue::TokenList(tokens, atoms)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,12 +212,12 @@ impl Attr {
|
||||||
impl AttrMethods for Attr {
|
impl AttrMethods for Attr {
|
||||||
// https://dom.spec.whatwg.org/#dom-attr-localname
|
// https://dom.spec.whatwg.org/#dom-attr-localname
|
||||||
fn LocalName(&self) -> DOMString {
|
fn LocalName(&self) -> DOMString {
|
||||||
(**self.local_name()).to_owned()
|
DOMString((**self.local_name()).to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-attr-value
|
// https://dom.spec.whatwg.org/#dom-attr-value
|
||||||
fn Value(&self) -> DOMString {
|
fn Value(&self) -> DOMString {
|
||||||
(**self.value()).to_owned()
|
DOMString((**self.value()).to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-attr-value
|
// https://dom.spec.whatwg.org/#dom-attr-value
|
||||||
|
@ -253,7 +253,7 @@ impl AttrMethods for Attr {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-attr-name
|
// https://dom.spec.whatwg.org/#dom-attr-name
|
||||||
fn Name(&self) -> DOMString {
|
fn Name(&self) -> DOMString {
|
||||||
(*self.name).to_owned()
|
DOMString((*self.name).to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-attr-namespaceuri
|
// https://dom.spec.whatwg.org/#dom-attr-namespaceuri
|
||||||
|
@ -261,13 +261,13 @@ impl AttrMethods for Attr {
|
||||||
let Namespace(ref atom) = self.namespace;
|
let Namespace(ref atom) = self.namespace;
|
||||||
match &**atom {
|
match &**atom {
|
||||||
"" => None,
|
"" => None,
|
||||||
url => Some(url.to_owned()),
|
url => Some(DOMString(url.to_owned())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-attr-prefix
|
// https://dom.spec.whatwg.org/#dom-attr-prefix
|
||||||
fn GetPrefix(&self) -> Option<DOMString> {
|
fn GetPrefix(&self) -> Option<DOMString> {
|
||||||
self.prefix().as_ref().map(|p| (**p).to_owned())
|
self.prefix().as_ref().map(|p| DOMString((**p).to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-attr-ownerelement
|
// https://dom.spec.whatwg.org/#dom-attr-ownerelement
|
||||||
|
@ -326,8 +326,8 @@ impl Attr {
|
||||||
let Namespace(ref ns) = self.namespace;
|
let Namespace(ref ns) = self.namespace;
|
||||||
AttrInfo {
|
AttrInfo {
|
||||||
namespace: (**ns).to_owned(),
|
namespace: (**ns).to_owned(),
|
||||||
name: self.Name(),
|
name: self.Name().0,
|
||||||
value: self.Value(),
|
value: self.Value().0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -829,7 +829,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
default = "None"
|
default = "None"
|
||||||
else:
|
else:
|
||||||
assert defaultValue.type.tag() == IDLType.Tags.domstring
|
assert defaultValue.type.tag() == IDLType.Tags.domstring
|
||||||
default = '"%s".to_owned()' % defaultValue.value
|
default = 'DOMString("%s".to_owned())' % defaultValue.value
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
default = "Some(%s)" % default
|
default = "Some(%s)" % default
|
||||||
|
|
||||||
|
|
|
@ -430,6 +430,13 @@ impl ToJSValConvertible for str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//http://heycam.github.io/webidl/#es-DOMString
|
||||||
|
impl ToJSValConvertible for String {
|
||||||
|
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||||
|
(**self).to_jsval(cx, rval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//http://heycam.github.io/webidl/#es-DOMString
|
//http://heycam.github.io/webidl/#es-DOMString
|
||||||
impl ToJSValConvertible for DOMString {
|
impl ToJSValConvertible for DOMString {
|
||||||
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||||
|
@ -451,7 +458,7 @@ pub enum StringificationBehavior {
|
||||||
pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
|
pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
|
||||||
let mut length = 0;
|
let mut length = 0;
|
||||||
let latin1 = unsafe { JS_StringHasLatin1Chars(s) };
|
let latin1 = unsafe { JS_StringHasLatin1Chars(s) };
|
||||||
if latin1 {
|
DOMString(if latin1 {
|
||||||
let chars = unsafe {
|
let chars = unsafe {
|
||||||
JS_GetLatin1StringCharsAndLength(cx, ptr::null(), s, &mut length)
|
JS_GetLatin1StringCharsAndLength(cx, ptr::null(), s, &mut length)
|
||||||
};
|
};
|
||||||
|
@ -496,7 +503,7 @@ pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s
|
s
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert the given `jsid` to a `DOMString`. Fails if the `jsid` is not a
|
/// Convert the given `jsid` to a `DOMString`. Fails if the `jsid` is not a
|
||||||
|
@ -548,7 +555,7 @@ impl FromJSValConvertible for USVString {
|
||||||
}
|
}
|
||||||
let latin1 = unsafe { JS_StringHasLatin1Chars(jsstr) };
|
let latin1 = unsafe { JS_StringHasLatin1Chars(jsstr) };
|
||||||
if latin1 {
|
if latin1 {
|
||||||
return Ok(USVString(jsstring_to_str(cx, jsstr)));
|
return Ok(USVString(jsstring_to_str(cx, jsstr).0));
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut length = 0;
|
let mut length = 0;
|
||||||
|
|
|
@ -18,7 +18,6 @@ use libc;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::{mem, ptr};
|
use std::{mem, ptr};
|
||||||
use util::mem::HeapSizeOf;
|
use util::mem::HeapSizeOf;
|
||||||
use util::str::DOMString;
|
|
||||||
|
|
||||||
/// DOM exceptions that can be thrown by a native DOM method.
|
/// DOM exceptions that can be thrown by a native DOM method.
|
||||||
#[derive(Debug, Clone, HeapSizeOf)]
|
#[derive(Debug, Clone, HeapSizeOf)]
|
||||||
|
@ -65,9 +64,9 @@ pub enum Error {
|
||||||
TypeMismatch,
|
TypeMismatch,
|
||||||
|
|
||||||
/// TypeError JavaScript Error
|
/// TypeError JavaScript Error
|
||||||
Type(DOMString),
|
Type(String),
|
||||||
/// RangeError JavaScript Error
|
/// RangeError JavaScript Error
|
||||||
Range(DOMString),
|
Range(String),
|
||||||
|
|
||||||
/// A JavaScript exception is already pending.
|
/// A JavaScript exception is already pending.
|
||||||
JSFailed,
|
JSFailed,
|
||||||
|
|
|
@ -83,7 +83,7 @@ use string_cache::{Atom, Namespace};
|
||||||
use style::properties::PropertyDeclarationBlock;
|
use style::properties::PropertyDeclarationBlock;
|
||||||
use style::values::specified::Length;
|
use style::values::specified::Length;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use util::str::{LengthOrPercentageOrAuto};
|
use util::str::{DOMString, LengthOrPercentageOrAuto};
|
||||||
|
|
||||||
|
|
||||||
/// A trait to allow tracing (only) DOM objects.
|
/// A trait to allow tracing (only) DOM objects.
|
||||||
|
@ -285,6 +285,7 @@ no_jsmanaged_fields!(MemProfilerChan);
|
||||||
no_jsmanaged_fields!(PseudoElement);
|
no_jsmanaged_fields!(PseudoElement);
|
||||||
no_jsmanaged_fields!(Length);
|
no_jsmanaged_fields!(Length);
|
||||||
no_jsmanaged_fields!(ElementState);
|
no_jsmanaged_fields!(ElementState);
|
||||||
|
no_jsmanaged_fields!(DOMString);
|
||||||
|
|
||||||
impl JSTraceable for Box<ScriptChan + Send> {
|
impl JSTraceable for Box<ScriptChan + Send> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -452,7 +452,7 @@ pub fn find_enum_string_index(cx: *mut JSContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
let search = jsstring_to_str(cx, jsstr);
|
let search = jsstring_to_str(cx, jsstr);
|
||||||
Ok(values.iter().position(|value| value == &search))
|
Ok(values.iter().position(|value| search == *value))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns wether `obj` is a platform object
|
/// Returns wether `obj` is a platform object
|
||||||
|
|
|
@ -21,12 +21,12 @@ use util::str::DOMString;
|
||||||
pub struct Blob {
|
pub struct Blob {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
bytes: Option<Vec<u8>>,
|
bytes: Option<Vec<u8>>,
|
||||||
typeString: DOMString,
|
typeString: String,
|
||||||
global: GlobalField,
|
global: GlobalField,
|
||||||
isClosed_: Cell<bool>
|
isClosed_: Cell<bool>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_ascii_printable(string: &DOMString) -> bool {
|
fn is_ascii_printable(string: &str) -> bool {
|
||||||
// Step 5.1 in Sec 5.1 of File API spec
|
// Step 5.1 in Sec 5.1 of File API spec
|
||||||
// http://dev.w3.org/2006/webapi/FileAPI/#constructorBlob
|
// http://dev.w3.org/2006/webapi/FileAPI/#constructorBlob
|
||||||
string.chars().all(|c| { c >= '\x20' && c <= '\x7E' })
|
string.chars().all(|c| { c >= '\x20' && c <= '\x7E' })
|
||||||
|
@ -60,7 +60,7 @@ impl Blob {
|
||||||
pub fn Constructor_(global: GlobalRef, blobParts: DOMString,
|
pub fn Constructor_(global: GlobalRef, blobParts: DOMString,
|
||||||
blobPropertyBag: &BlobBinding::BlobPropertyBag) -> Fallible<Root<Blob>> {
|
blobPropertyBag: &BlobBinding::BlobPropertyBag) -> Fallible<Root<Blob>> {
|
||||||
//TODO: accept other blobParts types - ArrayBuffer or ArrayBufferView or Blob
|
//TODO: accept other blobParts types - ArrayBuffer or ArrayBufferView or Blob
|
||||||
let bytes: Option<Vec<u8>> = Some(blobParts.into_bytes());
|
let bytes: Option<Vec<u8>> = Some(blobParts.0.into_bytes());
|
||||||
let typeString = if is_ascii_printable(&blobPropertyBag.type_) {
|
let typeString = if is_ascii_printable(&blobPropertyBag.type_) {
|
||||||
&*blobPropertyBag.type_
|
&*blobPropertyBag.type_
|
||||||
} else {
|
} else {
|
||||||
|
@ -85,7 +85,7 @@ impl BlobMethods for Blob {
|
||||||
|
|
||||||
// https://dev.w3.org/2006/webapi/FileAPI/#dfn-type
|
// https://dev.w3.org/2006/webapi/FileAPI/#dfn-type
|
||||||
fn Type(&self) -> DOMString {
|
fn Type(&self) -> DOMString {
|
||||||
self.typeString.clone()
|
DOMString(self.typeString.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dev.w3.org/2006/webapi/FileAPI/#slice-method-algo
|
// https://dev.w3.org/2006/webapi/FileAPI/#slice-method-algo
|
||||||
|
|
|
@ -12,6 +12,7 @@ use dom::bindings::js::Root;
|
||||||
use dom::bindings::num::Finite;
|
use dom::bindings::num::Finite;
|
||||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||||
use dom::canvasrenderingcontext2d::parse_color;
|
use dom::canvasrenderingcontext2d::parse_color;
|
||||||
|
use util::str::DOMString;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#canvasgradient
|
// https://html.spec.whatwg.org/multipage/#canvasgradient
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -44,7 +45,7 @@ impl CanvasGradient {
|
||||||
|
|
||||||
impl CanvasGradientMethods for CanvasGradient {
|
impl CanvasGradientMethods for CanvasGradient {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-canvasgradient-addcolorstop
|
// https://html.spec.whatwg.org/multipage/#dom-canvasgradient-addcolorstop
|
||||||
fn AddColorStop(&self, offset: Finite<f64>, color: String) -> ErrorResult {
|
fn AddColorStop(&self, offset: Finite<f64>, color: DOMString) -> ErrorResult {
|
||||||
if *offset < 0f64 || *offset > 1f64 {
|
if *offset < 0f64 || *offset > 1f64 {
|
||||||
return Err(Error::IndexSize);
|
return Err(Error::IndexSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -536,10 +536,10 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
|
||||||
fn GlobalCompositeOperation(&self) -> DOMString {
|
fn GlobalCompositeOperation(&self) -> DOMString {
|
||||||
let state = self.state.borrow();
|
let state = self.state.borrow();
|
||||||
match state.global_composition {
|
DOMString(match state.global_composition {
|
||||||
CompositionOrBlending::Composition(op) => op.to_str().to_owned(),
|
CompositionOrBlending::Composition(op) => op.to_str().to_owned(),
|
||||||
CompositionOrBlending::Blending(op) => op.to_str().to_owned(),
|
CompositionOrBlending::Blending(op) => op.to_str().to_owned(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
|
||||||
|
@ -760,7 +760,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
CanvasFillOrStrokeStyle::Color(ref rgba) => {
|
CanvasFillOrStrokeStyle::Color(ref rgba) => {
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
serialize(rgba, &mut result).unwrap();
|
serialize(rgba, &mut result).unwrap();
|
||||||
StringOrCanvasGradientOrCanvasPattern::eString(result)
|
StringOrCanvasGradientOrCanvasPattern::eString(DOMString(result))
|
||||||
},
|
},
|
||||||
CanvasFillOrStrokeStyle::Gradient(ref gradient) => {
|
CanvasFillOrStrokeStyle::Gradient(ref gradient) => {
|
||||||
StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(Root::from_ref(&*gradient))
|
StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(Root::from_ref(&*gradient))
|
||||||
|
@ -800,7 +800,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
CanvasFillOrStrokeStyle::Color(ref rgba) => {
|
CanvasFillOrStrokeStyle::Color(ref rgba) => {
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
serialize(rgba, &mut result).unwrap();
|
serialize(rgba, &mut result).unwrap();
|
||||||
StringOrCanvasGradientOrCanvasPattern::eString(result)
|
StringOrCanvasGradientOrCanvasPattern::eString(DOMString(result))
|
||||||
},
|
},
|
||||||
CanvasFillOrStrokeStyle::Gradient(ref gradient) => {
|
CanvasFillOrStrokeStyle::Gradient(ref gradient) => {
|
||||||
StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(Root::from_ref(&*gradient))
|
StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(Root::from_ref(&*gradient))
|
||||||
|
@ -1001,11 +1001,11 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
||||||
fn LineCap(&self) -> DOMString {
|
fn LineCap(&self) -> DOMString {
|
||||||
let state = self.state.borrow();
|
let state = self.state.borrow();
|
||||||
match state.line_cap {
|
DOMString(match state.line_cap {
|
||||||
LineCapStyle::Butt => "butt".to_owned(),
|
LineCapStyle::Butt => "butt".to_owned(),
|
||||||
LineCapStyle::Round => "round".to_owned(),
|
LineCapStyle::Round => "round".to_owned(),
|
||||||
LineCapStyle::Square => "square".to_owned(),
|
LineCapStyle::Square => "square".to_owned(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
||||||
|
@ -1019,11 +1019,11 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
||||||
fn LineJoin(&self) -> DOMString {
|
fn LineJoin(&self) -> DOMString {
|
||||||
let state = self.state.borrow();
|
let state = self.state.borrow();
|
||||||
match state.line_join {
|
DOMString(match state.line_join {
|
||||||
LineJoinStyle::Round => "round".to_owned(),
|
LineJoinStyle::Round => "round".to_owned(),
|
||||||
LineJoinStyle::Bevel => "bevel".to_owned(),
|
LineJoinStyle::Bevel => "bevel".to_owned(),
|
||||||
LineJoinStyle::Miter => "miter".to_owned(),
|
LineJoinStyle::Miter => "miter".to_owned(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
||||||
|
@ -1098,7 +1098,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
fn ShadowColor(&self) -> DOMString {
|
fn ShadowColor(&self) -> DOMString {
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
serialize(&self.state.borrow().shadow_color, &mut result).unwrap();
|
serialize(&self.state.borrow().shadow_color, &mut result).unwrap();
|
||||||
result
|
DOMString(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor
|
||||||
|
|
|
@ -65,7 +65,7 @@ impl CharacterDataMethods for CharacterData {
|
||||||
// Steps 4.
|
// Steps 4.
|
||||||
Some(count_bytes) => &data_from_offset[..count_bytes],
|
Some(count_bytes) => &data_from_offset[..count_bytes],
|
||||||
};
|
};
|
||||||
Ok(substring.to_owned())
|
Ok(DOMString(substring.to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-characterdata-appenddatadata
|
// https://dom.spec.whatwg.org/#dom-characterdata-appenddatadata
|
||||||
|
@ -103,7 +103,7 @@ impl CharacterDataMethods for CharacterData {
|
||||||
new_data.push_str(prefix);
|
new_data.push_str(prefix);
|
||||||
new_data.push_str(&arg);
|
new_data.push_str(&arg);
|
||||||
new_data.push_str(suffix);
|
new_data.push_str(suffix);
|
||||||
new_data
|
DOMString(new_data)
|
||||||
};
|
};
|
||||||
*self.data.borrow_mut() = new_data;
|
*self.data.borrow_mut() = new_data;
|
||||||
self.content_changed();
|
self.content_changed();
|
||||||
|
@ -150,7 +150,7 @@ impl CharacterData {
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn append_data(&self, data: &str) {
|
pub fn append_data(&self, data: &str) {
|
||||||
self.data.borrow_mut().push_str(data);
|
self.data.borrow_mut().0.push_str(data);
|
||||||
self.content_changed();
|
self.content_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,20 +74,17 @@ impl ConsoleMethods for Console {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console/assert
|
// https://developer.mozilla.org/en-US/docs/Web/API/Console/assert
|
||||||
fn Assert(&self, condition: bool, message: Option<DOMString>) {
|
fn Assert(&self, condition: bool, message: Option<DOMString>) {
|
||||||
if !condition {
|
if !condition {
|
||||||
let message = match message {
|
let message = message.unwrap_or_else(|| DOMString("no message".to_owned()));
|
||||||
Some(ref message) => &**message,
|
|
||||||
None => "no message",
|
|
||||||
};
|
|
||||||
println!("Assertion failed: {}", message);
|
println!("Assertion failed: {}", message);
|
||||||
propagate_console_msg(&self, prepare_message(LogLevel::Error, message.to_owned()));
|
propagate_console_msg(&self, prepare_message(LogLevel::Error, message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_message(logLevel: LogLevel, message: String) -> ConsoleMessage {
|
fn prepare_message(logLevel: LogLevel, message: DOMString) -> ConsoleMessage {
|
||||||
//TODO: Sending fake values for filename, lineNumber and columnNumber in LogMessage; adjust later
|
//TODO: Sending fake values for filename, lineNumber and columnNumber in LogMessage; adjust later
|
||||||
ConsoleMessage {
|
ConsoleMessage {
|
||||||
message: message,
|
message: message.0,
|
||||||
logLevel: logLevel,
|
logLevel: logLevel,
|
||||||
filename: "test".to_owned(),
|
filename: "test".to_owned(),
|
||||||
lineNumber: 1,
|
lineNumber: 1,
|
||||||
|
|
|
@ -76,23 +76,24 @@ use dom::htmlunknownelement::HTMLUnknownElement;
|
||||||
use dom::htmlvideoelement::HTMLVideoElement;
|
use dom::htmlvideoelement::HTMLVideoElement;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use string_cache::{Atom, QualName};
|
use string_cache::{Atom, QualName};
|
||||||
|
use util::str::DOMString;
|
||||||
|
|
||||||
pub fn create_element(name: QualName, prefix: Option<Atom>,
|
pub fn create_element(name: QualName, prefix: Option<Atom>,
|
||||||
document: &Document, creator: ElementCreator)
|
document: &Document, creator: ElementCreator)
|
||||||
-> Root<Element> {
|
-> Root<Element> {
|
||||||
let prefix = prefix.map(|p| (*p).to_owned());
|
let prefix = prefix.map(|p| DOMString((*p).to_owned()));
|
||||||
|
|
||||||
if name.ns != ns!(HTML) {
|
if name.ns != ns!(HTML) {
|
||||||
return Element::new((*name.local).to_owned(), name.ns, prefix, document);
|
return Element::new(DOMString((*name.local).to_owned()), name.ns, prefix, document);
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! make(
|
macro_rules! make(
|
||||||
($ctor:ident) => ({
|
($ctor:ident) => ({
|
||||||
let obj = $ctor::new((*name.local).to_owned(), prefix, document);
|
let obj = $ctor::new(DOMString((*name.local).to_owned()), prefix, document);
|
||||||
Root::upcast(obj)
|
Root::upcast(obj)
|
||||||
});
|
});
|
||||||
($ctor:ident, $($arg:expr),+) => ({
|
($ctor:ident, $($arg:expr),+) => ({
|
||||||
let obj = $ctor::new((*name.local).to_owned(), prefix, document, $($arg),+);
|
let obj = $ctor::new(DOMString((*name.local).to_owned()), prefix, document, $($arg),+);
|
||||||
Root::upcast(obj)
|
Root::upcast(obj)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -20,7 +20,7 @@ impl CSS {
|
||||||
return Err(Error::InvalidCharacter);
|
return Err(Error::InvalidCharacter);
|
||||||
}
|
}
|
||||||
let mut escaped = DOMString::new();
|
let mut escaped = DOMString::new();
|
||||||
serialize_identifier(&ident, &mut escaped).unwrap();
|
serialize_identifier(&ident, &mut escaped.0).unwrap();
|
||||||
Ok(escaped)
|
Ok(escaped)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,10 +39,10 @@ macro_rules! css_properties(
|
||||||
( $([$getter:ident, $setter:ident, $cssprop:expr]),* ) => (
|
( $([$getter:ident, $setter:ident, $cssprop:expr]),* ) => (
|
||||||
$(
|
$(
|
||||||
fn $getter(&self) -> DOMString {
|
fn $getter(&self) -> DOMString {
|
||||||
self.GetPropertyValue($cssprop.to_owned())
|
self.GetPropertyValue(DOMString($cssprop.to_owned()))
|
||||||
}
|
}
|
||||||
fn $setter(&self, value: DOMString) -> ErrorResult {
|
fn $setter(&self, value: DOMString) -> ErrorResult {
|
||||||
self.SetPropertyValue($cssprop.to_owned(), value)
|
self.SetPropertyValue(DOMString($cssprop.to_owned()), value)
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
);
|
);
|
||||||
|
@ -50,7 +50,7 @@ macro_rules! css_properties(
|
||||||
|
|
||||||
fn serialize_list(list: &[Ref<PropertyDeclaration>]) -> DOMString {
|
fn serialize_list(list: &[Ref<PropertyDeclaration>]) -> DOMString {
|
||||||
let str_iter = list.iter().map(|d| d.value());
|
let str_iter = list.iter().map(|d| d.value());
|
||||||
str_join(str_iter, " ")
|
DOMString(str_join(str_iter, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CSSStyleDeclaration {
|
impl CSSStyleDeclaration {
|
||||||
|
@ -113,7 +113,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
result.unwrap_or("".to_owned())
|
DOMString(result.unwrap_or(String::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
||||||
|
@ -153,7 +153,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
|
|
||||||
// Step 3 & 4
|
// Step 3 & 4
|
||||||
let result = match owner.get_inline_style_declaration(&property) {
|
let result = match owner.get_inline_style_declaration(&property) {
|
||||||
Some(declaration) => declaration.value(),
|
Some(declaration) => DOMString(declaration.value()),
|
||||||
None => DOMString::new(),
|
None => DOMString::new(),
|
||||||
};
|
};
|
||||||
result
|
result
|
||||||
|
@ -170,15 +170,15 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
if let Some(longhand_properties) = longhand_properties {
|
if let Some(longhand_properties) = longhand_properties {
|
||||||
// Step 2.1 & 2.2 & 2.3
|
// Step 2.1 & 2.2 & 2.3
|
||||||
if longhand_properties.iter()
|
if longhand_properties.iter()
|
||||||
.map(|&longhand| self.GetPropertyPriority(longhand.to_owned()))
|
.map(|&longhand| self.GetPropertyPriority(DOMString(longhand.to_owned())))
|
||||||
.all(|priority| priority == "important") {
|
.all(|priority| priority == "important") {
|
||||||
|
|
||||||
return "important".to_owned();
|
return DOMString("important".to_owned());
|
||||||
}
|
}
|
||||||
// Step 3
|
// Step 3
|
||||||
} else {
|
} else {
|
||||||
if self.owner.get_important_inline_style_declaration(&property).is_some() {
|
if self.owner.get_important_inline_style_declaration(&property).is_some() {
|
||||||
return "important".to_owned();
|
return DOMString("important".to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,12 +309,12 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
|
|
||||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-cssfloat
|
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-cssfloat
|
||||||
fn CssFloat(&self) -> DOMString {
|
fn CssFloat(&self) -> DOMString {
|
||||||
self.GetPropertyValue("float".to_owned())
|
self.GetPropertyValue(DOMString("float".to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-cssfloat
|
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-cssfloat
|
||||||
fn SetCssFloat(&self, value: DOMString) -> ErrorResult {
|
fn SetCssFloat(&self, value: DOMString) -> ErrorResult {
|
||||||
self.SetPropertyValue("float".to_owned(), value)
|
self.SetPropertyValue(DOMString("float".to_owned()), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
|
// https://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
|
||||||
|
|
|
@ -35,6 +35,7 @@ use std::mem::replace;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel};
|
use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use util::str::DOMString;
|
||||||
use util::task::spawn_named;
|
use util::task::spawn_named;
|
||||||
use util::task_state;
|
use util::task_state;
|
||||||
use util::task_state::{IN_WORKER, SCRIPT};
|
use util::task_state::{IN_WORKER, SCRIPT};
|
||||||
|
@ -263,7 +264,7 @@ impl DedicatedWorkerGlobalScope {
|
||||||
|
|
||||||
{
|
{
|
||||||
let _ar = AutoWorkerReset::new(global.r(), worker);
|
let _ar = AutoWorkerReset::new(global.r(), worker);
|
||||||
scope.execute_script(source);
|
scope.execute_script(DOMString(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
let reporter_name = format!("worker-reporter-{}", random::<u64>());
|
let reporter_name = format!("worker-reporter-{}", random::<u64>());
|
||||||
|
|
|
@ -123,7 +123,7 @@ pub struct Document {
|
||||||
implementation: MutNullableHeap<JS<DOMImplementation>>,
|
implementation: MutNullableHeap<JS<DOMImplementation>>,
|
||||||
location: MutNullableHeap<JS<Location>>,
|
location: MutNullableHeap<JS<Location>>,
|
||||||
content_type: DOMString,
|
content_type: DOMString,
|
||||||
last_modified: Option<DOMString>,
|
last_modified: Option<String>,
|
||||||
encoding_name: DOMRefCell<DOMString>,
|
encoding_name: DOMRefCell<DOMString>,
|
||||||
is_html_document: bool,
|
is_html_document: bool,
|
||||||
url: Url,
|
url: Url,
|
||||||
|
@ -494,7 +494,8 @@ impl Document {
|
||||||
pub fn set_ready_state(&self, state: DocumentReadyState) {
|
pub fn set_ready_state(&self, state: DocumentReadyState) {
|
||||||
self.ready_state.set(state);
|
self.ready_state.set(state);
|
||||||
|
|
||||||
let event = Event::new(GlobalRef::Window(&self.window), "readystatechange".to_owned(),
|
let event = Event::new(GlobalRef::Window(&self.window),
|
||||||
|
DOMString("readystatechange".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let target = self.upcast::<EventTarget>();
|
let target = self.upcast::<EventTarget>();
|
||||||
|
@ -552,7 +553,7 @@ impl Document {
|
||||||
/// Handles any updates when the document's title has changed.
|
/// Handles any updates when the document's title has changed.
|
||||||
pub fn title_changed(&self) {
|
pub fn title_changed(&self) {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsertitlechange
|
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsertitlechange
|
||||||
self.trigger_mozbrowser_event(MozBrowserEvent::TitleChange(self.Title()));
|
self.trigger_mozbrowser_event(MozBrowserEvent::TitleChange(self.Title().0));
|
||||||
|
|
||||||
self.send_title_to_compositor();
|
self.send_title_to_compositor();
|
||||||
}
|
}
|
||||||
|
@ -561,7 +562,7 @@ impl Document {
|
||||||
pub fn send_title_to_compositor(&self) {
|
pub fn send_title_to_compositor(&self) {
|
||||||
let window = self.window();
|
let window = self.window();
|
||||||
let compositor = window.compositor();
|
let compositor = window.compositor();
|
||||||
compositor.send(ScriptToCompositorMsg::SetTitle(window.pipeline(), Some(self.Title()))).unwrap();
|
compositor.send(ScriptToCompositorMsg::SetTitle(window.pipeline(), Some(self.Title().0))).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dirty_all_nodes(&self) {
|
pub fn dirty_all_nodes(&self) {
|
||||||
|
@ -615,7 +616,7 @@ impl Document {
|
||||||
let y = point.y as i32;
|
let y = point.y as i32;
|
||||||
let clickCount = 1;
|
let clickCount = 1;
|
||||||
let event = MouseEvent::new(&self.window,
|
let event = MouseEvent::new(&self.window,
|
||||||
mouse_event_type_string,
|
DOMString(mouse_event_type_string),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable,
|
EventCancelable::Cancelable,
|
||||||
Some(&self.window),
|
Some(&self.window),
|
||||||
|
@ -653,7 +654,7 @@ impl Document {
|
||||||
let y = point.y.to_i32().unwrap_or(0);
|
let y = point.y.to_i32().unwrap_or(0);
|
||||||
|
|
||||||
let mouse_event = MouseEvent::new(&self.window,
|
let mouse_event = MouseEvent::new(&self.window,
|
||||||
event_name,
|
DOMString(event_name),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable,
|
EventCancelable::Cancelable,
|
||||||
Some(&self.window),
|
Some(&self.window),
|
||||||
|
@ -802,7 +803,7 @@ impl Document {
|
||||||
|t| t.Target() == target).cloned());
|
|t| t.Target() == target).cloned());
|
||||||
|
|
||||||
let event = TouchEvent::new(window,
|
let event = TouchEvent::new(window,
|
||||||
event_name.to_owned(),
|
DOMString(event_name.to_owned()),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable,
|
EventCancelable::Cancelable,
|
||||||
Some(window),
|
Some(window),
|
||||||
|
@ -843,16 +844,17 @@ impl Document {
|
||||||
|
|
||||||
let is_composing = false;
|
let is_composing = false;
|
||||||
let is_repeating = state == KeyState::Repeated;
|
let is_repeating = state == KeyState::Repeated;
|
||||||
let ev_type = match state {
|
let ev_type = DOMString(match state {
|
||||||
KeyState::Pressed | KeyState::Repeated => "keydown",
|
KeyState::Pressed | KeyState::Repeated => "keydown",
|
||||||
KeyState::Released => "keyup",
|
KeyState::Released => "keyup",
|
||||||
}.to_owned();
|
}.to_owned());
|
||||||
|
|
||||||
let props = KeyboardEvent::key_properties(key, modifiers);
|
let props = KeyboardEvent::key_properties(key, modifiers);
|
||||||
|
|
||||||
let keyevent = KeyboardEvent::new(&self.window, ev_type, true, true,
|
let keyevent = KeyboardEvent::new(&self.window, ev_type, true, true,
|
||||||
Some(&self.window), 0, Some(key),
|
Some(&self.window), 0, Some(key),
|
||||||
props.key_string.to_owned(), props.code.to_owned(),
|
DOMString(props.key_string.to_owned()),
|
||||||
|
DOMString(props.code.to_owned()),
|
||||||
props.location, is_repeating, is_composing,
|
props.location, is_repeating, is_composing,
|
||||||
ctrl, alt, shift, meta,
|
ctrl, alt, shift, meta,
|
||||||
None, props.key_code);
|
None, props.key_code);
|
||||||
|
@ -863,9 +865,10 @@ impl Document {
|
||||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys
|
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys
|
||||||
if state != KeyState::Released && props.is_printable() && !prevented {
|
if state != KeyState::Released && props.is_printable() && !prevented {
|
||||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keypress-event-order
|
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keypress-event-order
|
||||||
let event = KeyboardEvent::new(&self.window, "keypress".to_owned(),
|
let event = KeyboardEvent::new(&self.window, DOMString("keypress".to_owned()),
|
||||||
true, true, Some(&self.window), 0, Some(key),
|
true, true, Some(&self.window), 0, Some(key),
|
||||||
props.key_string.to_owned(), props.code.to_owned(),
|
DOMString(props.key_string.to_owned()),
|
||||||
|
DOMString(props.code.to_owned()),
|
||||||
props.location, is_repeating, is_composing,
|
props.location, is_repeating, is_composing,
|
||||||
ctrl, alt, shift, meta,
|
ctrl, alt, shift, meta,
|
||||||
props.char_code, 0);
|
props.char_code, 0);
|
||||||
|
@ -1176,7 +1179,8 @@ impl Document {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.domcontentloaded_dispatched.set(true);
|
self.domcontentloaded_dispatched.set(true);
|
||||||
let event = Event::new(GlobalRef::Window(self.window()), "DOMContentLoaded".to_owned(),
|
let event = Event::new(GlobalRef::Window(self.window()),
|
||||||
|
DOMString("DOMContentLoaded".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let doctarget = self.upcast::<EventTarget>();
|
let doctarget = self.upcast::<EventTarget>();
|
||||||
|
@ -1251,7 +1255,7 @@ impl Document {
|
||||||
url: Option<Url>,
|
url: Option<Url>,
|
||||||
is_html_document: IsHTMLDocument,
|
is_html_document: IsHTMLDocument,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<DOMString>,
|
||||||
last_modified: Option<DOMString>,
|
last_modified: Option<String>,
|
||||||
source: DocumentSource,
|
source: DocumentSource,
|
||||||
doc_loader: DocumentLoader) -> Document {
|
doc_loader: DocumentLoader) -> Document {
|
||||||
let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());
|
let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());
|
||||||
|
@ -1270,19 +1274,19 @@ impl Document {
|
||||||
location: Default::default(),
|
location: Default::default(),
|
||||||
content_type: match content_type {
|
content_type: match content_type {
|
||||||
Some(string) => string,
|
Some(string) => string,
|
||||||
None => match is_html_document {
|
None => DOMString(match is_html_document {
|
||||||
// https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
|
// https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
|
||||||
IsHTMLDocument::HTMLDocument => "text/html".to_owned(),
|
IsHTMLDocument::HTMLDocument => "text/html".to_owned(),
|
||||||
// https://dom.spec.whatwg.org/#concept-document-content-type
|
// https://dom.spec.whatwg.org/#concept-document-content-type
|
||||||
IsHTMLDocument::NonHTMLDocument => "application/xml".to_owned()
|
IsHTMLDocument::NonHTMLDocument => "application/xml".to_owned()
|
||||||
}
|
})
|
||||||
},
|
},
|
||||||
last_modified: last_modified,
|
last_modified: last_modified,
|
||||||
url: url,
|
url: url,
|
||||||
// https://dom.spec.whatwg.org/#concept-document-quirks
|
// https://dom.spec.whatwg.org/#concept-document-quirks
|
||||||
quirks_mode: Cell::new(NoQuirks),
|
quirks_mode: Cell::new(NoQuirks),
|
||||||
// https://dom.spec.whatwg.org/#concept-document-encoding
|
// https://dom.spec.whatwg.org/#concept-document-encoding
|
||||||
encoding_name: DOMRefCell::new("UTF-8".to_owned()),
|
encoding_name: DOMRefCell::new(DOMString("UTF-8".to_owned())),
|
||||||
is_html_document: is_html_document == IsHTMLDocument::HTMLDocument,
|
is_html_document: is_html_document == IsHTMLDocument::HTMLDocument,
|
||||||
images: Default::default(),
|
images: Default::default(),
|
||||||
embeds: Default::default(),
|
embeds: Default::default(),
|
||||||
|
@ -1329,7 +1333,7 @@ impl Document {
|
||||||
url: Option<Url>,
|
url: Option<Url>,
|
||||||
doctype: IsHTMLDocument,
|
doctype: IsHTMLDocument,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<DOMString>,
|
||||||
last_modified: Option<DOMString>,
|
last_modified: Option<String>,
|
||||||
source: DocumentSource,
|
source: DocumentSource,
|
||||||
doc_loader: DocumentLoader) -> Root<Document> {
|
doc_loader: DocumentLoader) -> Root<Document> {
|
||||||
let document = reflect_dom_object(box Document::new_inherited(window, url, doctype,
|
let document = reflect_dom_object(box Document::new_inherited(window, url, doctype,
|
||||||
|
@ -1416,7 +1420,7 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-url
|
// https://dom.spec.whatwg.org/#dom-document-url
|
||||||
fn URL(&self) -> DOMString {
|
fn URL(&self) -> DOMString {
|
||||||
self.url().serialize()
|
DOMString(self.url().serialize())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-activeelement
|
// https://html.spec.whatwg.org/multipage/#dom-document-activeelement
|
||||||
|
@ -1458,10 +1462,10 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-compatmode
|
// https://dom.spec.whatwg.org/#dom-document-compatmode
|
||||||
fn CompatMode(&self) -> DOMString {
|
fn CompatMode(&self) -> DOMString {
|
||||||
match self.quirks_mode.get() {
|
DOMString(match self.quirks_mode.get() {
|
||||||
LimitedQuirks | NoQuirks => "CSS1Compat".to_owned(),
|
LimitedQuirks | NoQuirks => "CSS1Compat".to_owned(),
|
||||||
Quirks => "BackCompat".to_owned()
|
Quirks => "BackCompat".to_owned()
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-characterset
|
// https://dom.spec.whatwg.org/#dom-document-characterset
|
||||||
|
@ -1652,10 +1656,10 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-lastmodified
|
// https://html.spec.whatwg.org/multipage/#dom-document-lastmodified
|
||||||
fn LastModified(&self) -> DOMString {
|
fn LastModified(&self) -> DOMString {
|
||||||
match self.last_modified {
|
DOMString(match self.last_modified {
|
||||||
Some(ref t) => t.clone(),
|
Some(ref t) => t.clone(),
|
||||||
None => time::now().strftime("%m/%d/%Y %H:%M:%S").unwrap().to_string(),
|
None => time::now().strftime("%m/%d/%Y %H:%M:%S").unwrap().to_string(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-createrange
|
// https://dom.spec.whatwg.org/#dom-document-createrange
|
||||||
|
@ -1712,7 +1716,7 @@ impl DocumentMethods for Document {
|
||||||
Some(ref title) => {
|
Some(ref title) => {
|
||||||
// Steps 3-4.
|
// Steps 3-4.
|
||||||
let value = Node::collect_text_contents(title.children());
|
let value = Node::collect_text_contents(title.children());
|
||||||
str_join(split_html_space_chars(&value), " ")
|
DOMString(str_join(split_html_space_chars(&value), " "))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1979,7 +1983,7 @@ impl DocumentMethods for Document {
|
||||||
let (tx, rx) = ipc::channel().unwrap();
|
let (tx, rx) = ipc::channel().unwrap();
|
||||||
let _ = self.window.resource_task().send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
|
let _ = self.window.resource_task().send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
|
||||||
let cookies = rx.recv().unwrap();
|
let cookies = rx.recv().unwrap();
|
||||||
Ok(cookies.unwrap_or("".to_owned()))
|
Ok(DOMString(cookies.unwrap_or("".to_owned())))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
|
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
|
||||||
|
@ -1989,7 +1993,7 @@ impl DocumentMethods for Document {
|
||||||
if !is_scheme_host_port_tuple(url) {
|
if !is_scheme_host_port_tuple(url) {
|
||||||
return Err(Error::Security);
|
return Err(Error::Security);
|
||||||
}
|
}
|
||||||
let _ = self.window.resource_task().send(SetCookiesForUrl((*url).clone(), cookie, NonHTTP));
|
let _ = self.window.resource_task().send(SetCookiesForUrl((*url).clone(), cookie.0, NonHTTP));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2139,7 +2143,7 @@ impl DocumentProgressHandler {
|
||||||
fn dispatch_load(&self) {
|
fn dispatch_load(&self) {
|
||||||
let document = self.addr.root();
|
let document = self.addr.root();
|
||||||
let window = document.window();
|
let window = document.window();
|
||||||
let event = Event::new(GlobalRef::Window(window), "load".to_owned(),
|
let event = Event::new(GlobalRef::Window(window), DOMString("load".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let wintarget = window.upcast::<EventTarget>();
|
let wintarget = window.upcast::<EventTarget>();
|
||||||
|
@ -2151,7 +2155,7 @@ impl DocumentProgressHandler {
|
||||||
|
|
||||||
if let Some(frame_element) = browsing_context.frame_element() {
|
if let Some(frame_element) = browsing_context.frame_element() {
|
||||||
let frame_window = window_from_node(frame_element);
|
let frame_window = window_from_node(frame_element);
|
||||||
let event = Event::new(GlobalRef::Window(frame_window.r()), "load".to_owned(),
|
let event = Event::new(GlobalRef::Window(frame_window.r()), DOMString("load".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
event.fire(frame_element.upcast());
|
event.fire(frame_element.upcast());
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl DOMExceptionMethods for DOMException {
|
||||||
|
|
||||||
// https://heycam.github.io/webidl/#idl-DOMException-error-names
|
// https://heycam.github.io/webidl/#idl-DOMException-error-names
|
||||||
fn Name(&self) -> DOMString {
|
fn Name(&self) -> DOMString {
|
||||||
format!("{:?}", self.code)
|
DOMString(format!("{:?}", self.code))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://heycam.github.io/webidl/#error-names
|
// https://heycam.github.io/webidl/#error-names
|
||||||
|
@ -102,11 +102,11 @@ impl DOMExceptionMethods for DOMException {
|
||||||
DOMErrorName::EncodingError => "The encoding operation (either encoded or decoding) failed."
|
DOMErrorName::EncodingError => "The encoding operation (either encoded or decoding) failed."
|
||||||
};
|
};
|
||||||
|
|
||||||
message.to_owned()
|
DOMString(message.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-error.prototype.tostring
|
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-error.prototype.tostring
|
||||||
fn Stringifier(&self) -> String {
|
fn Stringifier(&self) -> DOMString {
|
||||||
format!("{}: {}", self.Name(), self.Message())
|
DOMString(format!("{}: {}", self.Name(), self.Message()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
{
|
{
|
||||||
// Step 3.
|
// Step 3.
|
||||||
let doc_node = doc.upcast::<Node>();
|
let doc_node = doc.upcast::<Node>();
|
||||||
let doc_type = DocumentType::new("html".to_owned(), None, None, doc.r());
|
let doc_type = DocumentType::new(DOMString("html".to_owned()), None, None, doc.r());
|
||||||
doc_node.AppendChild(doc_type.upcast()).unwrap();
|
doc_node.AppendChild(doc_type.upcast()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,13 +117,13 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
// Step 4.
|
// Step 4.
|
||||||
let doc_node = doc.upcast::<Node>();
|
let doc_node = doc.upcast::<Node>();
|
||||||
let doc_html = Root::upcast::<Node>(
|
let doc_html = Root::upcast::<Node>(
|
||||||
HTMLHtmlElement::new("html".to_owned(), None, doc.r()));
|
HTMLHtmlElement::new(DOMString("html".to_owned()), None, doc.r()));
|
||||||
doc_node.AppendChild(&doc_html).expect("Appending failed");
|
doc_node.AppendChild(&doc_html).expect("Appending failed");
|
||||||
|
|
||||||
{
|
{
|
||||||
// Step 5.
|
// Step 5.
|
||||||
let doc_head = Root::upcast::<Node>(
|
let doc_head = Root::upcast::<Node>(
|
||||||
HTMLHeadElement::new("head".to_owned(), None, doc.r()));
|
HTMLHeadElement::new(DOMString("head".to_owned()), None, doc.r()));
|
||||||
doc_html.AppendChild(&doc_head).unwrap();
|
doc_html.AppendChild(&doc_head).unwrap();
|
||||||
|
|
||||||
// Step 6.
|
// Step 6.
|
||||||
|
@ -132,7 +132,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
Some(title_str) => {
|
Some(title_str) => {
|
||||||
// Step 6.1.
|
// Step 6.1.
|
||||||
let doc_title = Root::upcast::<Node>(
|
let doc_title = Root::upcast::<Node>(
|
||||||
HTMLTitleElement::new("title".to_owned(), None, doc.r()));
|
HTMLTitleElement::new(DOMString("title".to_owned()), None, doc.r()));
|
||||||
doc_head.AppendChild(&doc_title).unwrap();
|
doc_head.AppendChild(&doc_title).unwrap();
|
||||||
|
|
||||||
// Step 6.2.
|
// Step 6.2.
|
||||||
|
@ -143,7 +143,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
let doc_body = HTMLBodyElement::new("body".to_owned(), None, doc.r());
|
let doc_body = HTMLBodyElement::new(DOMString("body".to_owned()), None, doc.r());
|
||||||
doc_html.AppendChild(doc_body.upcast()).unwrap();
|
doc_html.AppendChild(doc_body.upcast()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ impl DOMParserMethods for DOMParser {
|
||||||
ty: DOMParserBinding::SupportedType)
|
ty: DOMParserBinding::SupportedType)
|
||||||
-> Fallible<Root<Document>> {
|
-> Fallible<Root<Document>> {
|
||||||
let url = self.window.get_url();
|
let url = self.window.get_url();
|
||||||
let content_type = DOMParserBinding::SupportedTypeValues::strings[ty as usize].to_owned();
|
let content_type = DOMString(DOMParserBinding::SupportedTypeValues::strings[ty as usize].to_owned());
|
||||||
let doc = self.window.Document();
|
let doc = self.window.Document();
|
||||||
let doc = doc.r();
|
let doc = doc.r();
|
||||||
let loader = DocumentLoader::new(&*doc.loader());
|
let loader = DocumentLoader::new(&*doc.loader());
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
||||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-item
|
// https://dom.spec.whatwg.org/#dom-domtokenlist-item
|
||||||
fn Item(&self, index: u32) -> Option<DOMString> {
|
fn Item(&self, index: u32) -> Option<DOMString> {
|
||||||
self.attribute().and_then(|attr| {
|
self.attribute().and_then(|attr| {
|
||||||
attr.value().as_tokens().get(index as usize).map(|token| (**token).to_owned())
|
attr.value().as_tokens().get(index as usize).map(|token| DOMString((**token).to_owned()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
||||||
// https://dom.spec.whatwg.org/#stringification-behavior
|
// https://dom.spec.whatwg.org/#stringification-behavior
|
||||||
fn Stringifier(&self) -> DOMString {
|
fn Stringifier(&self) -> DOMString {
|
||||||
let tokenlist = self.element.get_tokenlist_attribute(&self.local_name);
|
let tokenlist = self.element.get_tokenlist_attribute(&self.local_name);
|
||||||
str_join(&tokenlist, "\x20")
|
DOMString(str_join(&tokenlist, "\x20"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
|
|
|
@ -775,7 +775,7 @@ impl Element {
|
||||||
traversal_scope: traversal_scope,
|
traversal_scope: traversal_scope,
|
||||||
.. Default::default()
|
.. Default::default()
|
||||||
}) {
|
}) {
|
||||||
Ok(()) => Ok(String::from_utf8(writer).unwrap()),
|
Ok(()) => Ok(DOMString(String::from_utf8(writer).unwrap())),
|
||||||
Err(_) => panic!("Cannot serialize element"),
|
Err(_) => panic!("Cannot serialize element"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1030,10 +1030,10 @@ impl Element {
|
||||||
let base = doc.url();
|
let base = doc.url();
|
||||||
// https://html.spec.whatwg.org/multipage/#reflect
|
// https://html.spec.whatwg.org/multipage/#reflect
|
||||||
// XXXManishearth this doesn't handle `javascript:` urls properly
|
// XXXManishearth this doesn't handle `javascript:` urls properly
|
||||||
match UrlParser::new().base_url(&base).parse(&url) {
|
DOMString(match UrlParser::new().base_url(&base).parse(&url) {
|
||||||
Ok(parsed) => parsed.serialize(),
|
Ok(parsed) => parsed.serialize(),
|
||||||
Err(_) => "".to_owned()
|
Err(_) => "".to_owned()
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
pub fn set_url_attribute(&self, local_name: &Atom, value: DOMString) {
|
pub fn set_url_attribute(&self, local_name: &Atom, value: DOMString) {
|
||||||
self.set_string_attribute(local_name, value);
|
self.set_string_attribute(local_name, value);
|
||||||
|
@ -1087,7 +1087,7 @@ impl Element {
|
||||||
}
|
}
|
||||||
pub fn set_uint_attribute(&self, local_name: &Atom, value: u32) {
|
pub fn set_uint_attribute(&self, local_name: &Atom, value: u32) {
|
||||||
assert!(&**local_name == local_name.to_ascii_lowercase());
|
assert!(&**local_name == local_name.to_ascii_lowercase());
|
||||||
self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value));
|
self.set_attribute(local_name, AttrValue::UInt(DOMString(value.to_string()), value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1099,7 +1099,7 @@ impl ElementMethods for Element {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-element-localname
|
// https://dom.spec.whatwg.org/#dom-element-localname
|
||||||
fn LocalName(&self) -> DOMString {
|
fn LocalName(&self) -> DOMString {
|
||||||
(*self.local_name).to_owned()
|
DOMString((*self.local_name).to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-element-prefix
|
// https://dom.spec.whatwg.org/#dom-element-prefix
|
||||||
|
@ -1115,11 +1115,11 @@ impl ElementMethods for Element {
|
||||||
},
|
},
|
||||||
None => Cow::Borrowed(&*self.local_name)
|
None => Cow::Borrowed(&*self.local_name)
|
||||||
};
|
};
|
||||||
if self.html_element_in_html_document() {
|
DOMString(if self.html_element_in_html_document() {
|
||||||
qualified_name.to_ascii_uppercase()
|
qualified_name.to_ascii_uppercase()
|
||||||
} else {
|
} else {
|
||||||
qualified_name.into_owned()
|
qualified_name.into_owned()
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-element-id
|
// https://dom.spec.whatwg.org/#dom-element-id
|
||||||
|
|
|
@ -169,7 +169,7 @@ impl EventMethods for Event {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-event-type
|
// https://dom.spec.whatwg.org/#dom-event-type
|
||||||
fn Type(&self) -> DOMString {
|
fn Type(&self) -> DOMString {
|
||||||
(*self.type_()).to_owned()
|
DOMString((*self.type_()).to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-event-target
|
// https://dom.spec.whatwg.org/#dom-event-target
|
||||||
|
|
|
@ -228,7 +228,7 @@ impl FileReader {
|
||||||
let convert = blob_bytes;
|
let convert = blob_bytes;
|
||||||
// Step 7
|
// Step 7
|
||||||
let output = enc.decode(convert, DecoderTrap::Replace).unwrap();
|
let output = enc.decode(convert, DecoderTrap::Replace).unwrap();
|
||||||
output
|
DOMString(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
//https://w3c.github.io/FileAPI/#dfn-readAsDataURL
|
//https://w3c.github.io/FileAPI/#dfn-readAsDataURL
|
||||||
|
@ -248,7 +248,7 @@ impl FileReader {
|
||||||
format!("data:{};base64,{}", data.blobtype, base64)
|
format!("data:{};base64,{}", data.blobtype, base64)
|
||||||
};
|
};
|
||||||
|
|
||||||
output
|
DOMString(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,11 +319,11 @@ impl FileReaderMethods for FileReader {
|
||||||
|
|
||||||
|
|
||||||
impl FileReader {
|
impl FileReader {
|
||||||
fn dispatch_progress_event(&self, type_: DOMString, loaded: u64, total: Option<u64>) {
|
fn dispatch_progress_event(&self, type_: String, loaded: u64, total: Option<u64>) {
|
||||||
|
|
||||||
let global = self.global.root();
|
let global = self.global.root();
|
||||||
let progressevent = ProgressEvent::new(global.r(),
|
let progressevent = ProgressEvent::new(global.r(),
|
||||||
type_, EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
|
DOMString(type_), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
|
||||||
total.is_some(), loaded, total.unwrap_or(0));
|
total.is_some(), loaded, total.unwrap_or(0));
|
||||||
progressevent.upcast::<Event>().fire(self.upcast());
|
progressevent.upcast::<Event>().fire(self.upcast());
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl FormData {
|
||||||
fn get_file_from_blob(&self, value: &Blob, filename: Option<DOMString>) -> Root<File> {
|
fn get_file_from_blob(&self, value: &Blob, filename: Option<DOMString>) -> Root<File> {
|
||||||
let global = self.global.root();
|
let global = self.global.root();
|
||||||
let f = value.downcast::<File>();
|
let f = value.downcast::<File>();
|
||||||
let name = filename.unwrap_or(f.map(|inner| inner.name().clone()).unwrap_or("blob".to_owned()));
|
let name = filename.unwrap_or(f.map(|inner| inner.name().clone()).unwrap_or(DOMString("blob".to_owned())));
|
||||||
File::new(global.r(), value, name)
|
File::new(global.r(), value, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ impl Activatable for HTMLAnchorElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#following-hyperlinks-2
|
/// https://html.spec.whatwg.org/multipage/#following-hyperlinks-2
|
||||||
fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<DOMString>) {
|
fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<String>) {
|
||||||
// Step 1: replace.
|
// Step 1: replace.
|
||||||
// Step 2: source browsing context.
|
// Step 2: source browsing context.
|
||||||
// Step 3: target browsing context.
|
// Step 3: target browsing context.
|
||||||
|
@ -182,7 +182,7 @@ fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<DOMString>) {
|
||||||
// Step 6.
|
// Step 6.
|
||||||
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=28925
|
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=28925
|
||||||
if let Some(suffix) = hyperlink_suffix {
|
if let Some(suffix) = hyperlink_suffix {
|
||||||
href.push_str(&suffix);
|
href.0.push_str(&suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4-5.
|
// Step 4-5.
|
||||||
|
|
|
@ -181,7 +181,7 @@ impl VirtualMethods for HTMLBodyElement {
|
||||||
};
|
};
|
||||||
evtarget.set_event_handler_uncompiled(cx, url, reflector,
|
evtarget.set_event_handler_uncompiled(cx, url, reflector,
|
||||||
&name[2..],
|
&name[2..],
|
||||||
(**attr.value()).to_owned());
|
DOMString((**attr.value()).to_owned()));
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,7 @@ impl<'a> Activatable for &'a HTMLButtonElement {
|
||||||
if owner.is_none() || self.upcast::<Element>().click_in_progress() {
|
if owner.is_none() || self.upcast::<Element>().click_in_progress() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
node.query_selector_iter("button[type=submit]".to_owned()).unwrap()
|
node.query_selector_iter(DOMString("button[type=submit]".to_owned())).unwrap()
|
||||||
.filter_map(Root::downcast::<HTMLButtonElement>)
|
.filter_map(Root::downcast::<HTMLButtonElement>)
|
||||||
.find(|r| r.form_owner() == owner)
|
.find(|r| r.form_owner() == owner)
|
||||||
.map(|s| s.r().synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey));
|
.map(|s| s.r().synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey));
|
||||||
|
|
|
@ -264,7 +264,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
if self.Width() == 0 || self.Height() == 0 {
|
if self.Width() == 0 || self.Height() == 0 {
|
||||||
return Ok("data:,".to_owned());
|
return Ok(DOMString("data:,".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
|
@ -285,7 +285,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
let encoded = encoded.to_base64(STANDARD);
|
let encoded = encoded.to_base64(STANDARD);
|
||||||
Ok(format!("data:{};base64,{}", mime_type, encoded))
|
Ok(DOMString(format!("data:{};base64,{}", mime_type, encoded)))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::NotSupported)
|
Err(Error::NotSupported)
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,7 +274,7 @@ fn to_snake_case(name: DOMString) -> DOMString {
|
||||||
attr_name.push(ch);
|
attr_name.push(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attr_name
|
DOMString(attr_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -313,7 +313,7 @@ fn to_camel_case(name: &str) -> Option<DOMString> {
|
||||||
result.push(curr_char);
|
result.push(curr_char);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(result)
|
Some(DOMString(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLElement {
|
impl HTMLElement {
|
||||||
|
@ -329,7 +329,7 @@ impl HTMLElement {
|
||||||
pub fn get_custom_attr(&self, local_name: DOMString) -> Option<DOMString> {
|
pub fn get_custom_attr(&self, local_name: DOMString) -> Option<DOMString> {
|
||||||
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
||||||
self.upcast::<Element>().get_attribute(&ns!(""), &local_name).map(|attr| {
|
self.upcast::<Element>().get_attribute(&ns!(""), &local_name).map(|attr| {
|
||||||
(**attr.value()).to_owned()
|
DOMString((**attr.value()).to_owned())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +422,7 @@ impl VirtualMethods for HTMLElement {
|
||||||
let evtarget = self.upcast::<EventTarget>();
|
let evtarget = self.upcast::<EventTarget>();
|
||||||
evtarget.set_event_handler_uncompiled(cx, url, reflector,
|
evtarget.set_event_handler_uncompiled(cx, url, reflector,
|
||||||
&name[2..],
|
&name[2..],
|
||||||
(**attr.value()).to_owned());
|
DOMString((**attr.value()).to_owned()));
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ impl HTMLFormElement {
|
||||||
// TODO: Handle browsing contexts
|
// TODO: Handle browsing contexts
|
||||||
// TODO: Handle validation
|
// TODO: Handle validation
|
||||||
let event = Event::new(GlobalRef::Window(win.r()),
|
let event = Event::new(GlobalRef::Window(win.r()),
|
||||||
"submit".to_owned(),
|
DOMString("submit".to_owned()),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable);
|
EventCancelable::Cancelable);
|
||||||
event.fire(self.upcast());
|
event.fire(self.upcast());
|
||||||
|
@ -171,7 +171,7 @@ impl HTMLFormElement {
|
||||||
// Step 7-8
|
// Step 7-8
|
||||||
let mut action = submitter.action();
|
let mut action = submitter.action();
|
||||||
if action.is_empty() {
|
if action.is_empty() {
|
||||||
action = base.serialize();
|
action = DOMString(base.serialize());
|
||||||
}
|
}
|
||||||
// TODO: Resolve the url relative to the submitter element
|
// TODO: Resolve the url relative to the submitter element
|
||||||
// Step 10-15
|
// Step 10-15
|
||||||
|
@ -283,7 +283,7 @@ impl HTMLFormElement {
|
||||||
if prev == '\r' {
|
if prev == '\r' {
|
||||||
buf.push('\n');
|
buf.push('\n');
|
||||||
}
|
}
|
||||||
buf
|
DOMString(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ret = self.get_unclean_dataset(submitter);
|
let mut ret = self.get_unclean_dataset(submitter);
|
||||||
|
@ -311,7 +311,7 @@ impl HTMLFormElement {
|
||||||
|
|
||||||
let win = window_from_node(self);
|
let win = window_from_node(self);
|
||||||
let event = Event::new(GlobalRef::Window(win.r()),
|
let event = Event::new(GlobalRef::Window(win.r()),
|
||||||
"reset".to_owned(),
|
DOMString("reset".to_owned()),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable);
|
EventCancelable::Cancelable);
|
||||||
event.fire(self.upcast());
|
event.fire(self.upcast());
|
||||||
|
|
|
@ -144,7 +144,7 @@ impl HTMLIFrameElement {
|
||||||
let mut detail = RootedValue::new(cx, UndefinedValue());
|
let mut detail = RootedValue::new(cx, UndefinedValue());
|
||||||
event.detail().to_jsval(cx, detail.handle_mut());
|
event.detail().to_jsval(cx, detail.handle_mut());
|
||||||
let custom_event = CustomEvent::new(GlobalRef::Window(window.r()),
|
let custom_event = CustomEvent::new(GlobalRef::Window(window.r()),
|
||||||
event.name().to_owned(),
|
DOMString(event.name().to_owned()),
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
detail.handle());
|
detail.handle());
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl Runnable for ImageResponseHandlerRunnable {
|
||||||
// Fire image.onload
|
// Fire image.onload
|
||||||
let window = window_from_node(document.r());
|
let window = window_from_node(document.r());
|
||||||
let event = Event::new(GlobalRef::Window(window.r()),
|
let event = Event::new(GlobalRef::Window(window.r()),
|
||||||
"load".to_owned(),
|
DOMString("load".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
event.fire(element.upcast());
|
event.fire(element.upcast());
|
||||||
|
@ -146,7 +146,7 @@ impl HTMLImageElement {
|
||||||
width: Option<u32>,
|
width: Option<u32>,
|
||||||
height: Option<u32>) -> Fallible<Root<HTMLImageElement>> {
|
height: Option<u32>) -> Fallible<Root<HTMLImageElement>> {
|
||||||
let document = global.as_window().Document();
|
let document = global.as_window().Document();
|
||||||
let image = HTMLImageElement::new("img".to_owned(), None, document.r());
|
let image = HTMLImageElement::new(DOMString("img".to_owned()), None, document.r());
|
||||||
if let Some(w) = width {
|
if let Some(w) = width {
|
||||||
image.SetWidth(w);
|
image.SetWidth(w);
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,7 @@ impl VirtualMethods for HTMLImageElement {
|
||||||
match attr.local_name() {
|
match attr.local_name() {
|
||||||
&atom!(src) => {
|
&atom!(src) => {
|
||||||
self.update_image(mutation.new_value(attr).map(|value| {
|
self.update_image(mutation.new_value(attr).map(|value| {
|
||||||
((**value).to_owned(), window_from_node(self).get_url())
|
(DOMString((**value).to_owned()), window_from_node(self).get_url())
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl HTMLInputElement {
|
||||||
|
|
||||||
pub trait LayoutHTMLInputElementHelpers {
|
pub trait LayoutHTMLInputElementHelpers {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_value_for_layout(self) -> String;
|
unsafe fn get_value_for_layout(self) -> DOMString;
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_size_for_layout(self) -> u32;
|
unsafe fn get_size_for_layout(self) -> u32;
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
@ -143,35 +143,37 @@ pub trait LayoutHTMLInputElementHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_raw_textinput_value(input: LayoutJS<HTMLInputElement>) -> String {
|
unsafe fn get_raw_textinput_value(input: LayoutJS<HTMLInputElement>) -> DOMString {
|
||||||
let textinput = (*input.unsafe_get()).textinput.borrow_for_layout().get_content();
|
let textinput = (*input.unsafe_get()).textinput.borrow_for_layout().get_content();
|
||||||
if !textinput.is_empty() {
|
if !textinput.is_empty() {
|
||||||
textinput
|
textinput
|
||||||
} else {
|
} else {
|
||||||
(*input.unsafe_get()).placeholder.borrow_for_layout().to_owned()
|
(*input.unsafe_get()).placeholder.borrow_for_layout().clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
|
impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_value_for_layout(self) -> String {
|
unsafe fn get_value_for_layout(self) -> DOMString {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>) -> Option<String> {
|
unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>, default: &str) -> DOMString {
|
||||||
let elem = input.upcast::<Element>();
|
let elem = input.upcast::<Element>();
|
||||||
(*elem.unsafe_get()).get_attr_val_for_layout(&ns!(""), &atom!("value"))
|
let value = (*elem.unsafe_get())
|
||||||
.map(|s| s.to_owned())
|
.get_attr_val_for_layout(&ns!(""), &atom!("value"))
|
||||||
|
.unwrap_or(default);
|
||||||
|
DOMString(value.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
match (*self.unsafe_get()).input_type.get() {
|
match (*self.unsafe_get()).input_type.get() {
|
||||||
InputType::InputCheckbox | InputType::InputRadio => "".to_owned(),
|
InputType::InputCheckbox | InputType::InputRadio => DOMString::new(),
|
||||||
InputType::InputFile | InputType::InputImage => "".to_owned(),
|
InputType::InputFile | InputType::InputImage => DOMString::new(),
|
||||||
InputType::InputButton => get_raw_attr_value(self).unwrap_or_else(|| "".to_owned()),
|
InputType::InputButton => get_raw_attr_value(self, ""),
|
||||||
InputType::InputSubmit => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_SUBMIT_VALUE.to_owned()),
|
InputType::InputSubmit => get_raw_attr_value(self, DEFAULT_SUBMIT_VALUE),
|
||||||
InputType::InputReset => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_RESET_VALUE.to_owned()),
|
InputType::InputReset => get_raw_attr_value(self, DEFAULT_RESET_VALUE),
|
||||||
InputType::InputPassword => {
|
InputType::InputPassword => {
|
||||||
let raw = get_raw_textinput_value(self);
|
let raw = get_raw_textinput_value(self);
|
||||||
// The implementation of get_insertion_point_index_for_layout expects a 1:1 mapping of chars.
|
// The implementation of get_insertion_point_index_for_layout expects a 1:1 mapping of chars.
|
||||||
raw.chars().map(|_| '●').collect()
|
DOMString(raw.chars().map(|_| '●').collect())
|
||||||
}
|
}
|
||||||
_ => get_raw_textinput_value(self),
|
_ => get_raw_textinput_value(self),
|
||||||
}
|
}
|
||||||
|
@ -363,7 +365,7 @@ fn broadcast_radio_checked(broadcaster: &HTMLInputElement, group: Option<&Atom>)
|
||||||
// This function is a workaround for lifetime constraint difficulties.
|
// This function is a workaround for lifetime constraint difficulties.
|
||||||
fn do_broadcast(doc_node: &Node, broadcaster: &HTMLInputElement,
|
fn do_broadcast(doc_node: &Node, broadcaster: &HTMLInputElement,
|
||||||
owner: Option<&HTMLFormElement>, group: Option<&Atom>) {
|
owner: Option<&HTMLFormElement>, group: Option<&Atom>) {
|
||||||
let iter = doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap()
|
let iter = doc_node.query_selector_iter(DOMString("input[type=radio]".to_owned())).unwrap()
|
||||||
.filter_map(Root::downcast::<HTMLInputElement>)
|
.filter_map(Root::downcast::<HTMLInputElement>)
|
||||||
.filter(|r| in_same_group(r.r(), owner, group) && broadcaster != r.r());
|
.filter(|r| in_same_group(r.r(), owner, group) && broadcaster != r.r());
|
||||||
for ref r in iter {
|
for ref r in iter {
|
||||||
|
@ -426,9 +428,9 @@ impl HTMLInputElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut value = self.Value();
|
let mut value = self.Value();
|
||||||
if ty == "radio" || ty == "checkbox" {
|
if &*ty == "radio" || &*ty == "checkbox" {
|
||||||
if value.is_empty() {
|
if value.is_empty() {
|
||||||
value = "on".to_owned();
|
value = DOMString("on".to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(FormDatum {
|
Some(FormDatum {
|
||||||
|
@ -560,8 +562,8 @@ impl VirtualMethods for HTMLInputElement {
|
||||||
},
|
},
|
||||||
&atom!(value) if !self.value_changed.get() => {
|
&atom!(value) if !self.value_changed.get() => {
|
||||||
let value = mutation.new_value(attr).map(|value| (**value).to_owned());
|
let value = mutation.new_value(attr).map(|value| (**value).to_owned());
|
||||||
self.textinput.borrow_mut().set_content(
|
self.textinput.borrow_mut().set_content(DOMString(
|
||||||
value.unwrap_or_else(|| "".to_owned()));
|
value.unwrap_or_else(|| "".to_owned())));
|
||||||
},
|
},
|
||||||
&atom!(name) if self.input_type.get() == InputType::InputRadio => {
|
&atom!(name) if self.input_type.get() == InputType::InputRadio => {
|
||||||
self.radio_group_updated(
|
self.radio_group_updated(
|
||||||
|
@ -569,9 +571,9 @@ impl VirtualMethods for HTMLInputElement {
|
||||||
},
|
},
|
||||||
&atom!(placeholder) => {
|
&atom!(placeholder) => {
|
||||||
let mut placeholder = self.placeholder.borrow_mut();
|
let mut placeholder = self.placeholder.borrow_mut();
|
||||||
placeholder.clear();
|
placeholder.0.clear();
|
||||||
if let AttributeMutation::Set(_) = mutation {
|
if let AttributeMutation::Set(_) = mutation {
|
||||||
placeholder.extend(
|
placeholder.0.extend(
|
||||||
attr.value().chars().filter(|&c| c != '\n' && c != '\r'));
|
attr.value().chars().filter(|&c| c != '\n' && c != '\r'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -708,7 +710,8 @@ impl Activatable for HTMLInputElement {
|
||||||
let group = self.get_radio_group_name();;
|
let group = self.get_radio_group_name();;
|
||||||
|
|
||||||
// Safe since we only manipulate the DOM tree after finding an element
|
// Safe since we only manipulate the DOM tree after finding an element
|
||||||
let checked_member = doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap()
|
let checked_member = doc_node.query_selector_iter(DOMString("input[type=radio]".to_owned()))
|
||||||
|
.unwrap()
|
||||||
.filter_map(Root::downcast::<HTMLInputElement>)
|
.filter_map(Root::downcast::<HTMLInputElement>)
|
||||||
.find(|r| {
|
.find(|r| {
|
||||||
in_same_group(r.r(), owner.r(), group.as_ref()) &&
|
in_same_group(r.r(), owner.r(), group.as_ref()) &&
|
||||||
|
@ -809,13 +812,13 @@ impl Activatable for HTMLInputElement {
|
||||||
let target = self.upcast();
|
let target = self.upcast();
|
||||||
|
|
||||||
let event = Event::new(GlobalRef::Window(win.r()),
|
let event = Event::new(GlobalRef::Window(win.r()),
|
||||||
"input".to_owned(),
|
DOMString("input".to_owned()),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
|
|
||||||
let event = Event::new(GlobalRef::Window(win.r()),
|
let event = Event::new(GlobalRef::Window(win.r()),
|
||||||
"change".to_owned(),
|
DOMString("change".to_owned()),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
|
@ -840,7 +843,7 @@ impl Activatable for HTMLInputElement {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let submit_button;
|
let submit_button;
|
||||||
submit_button = node.query_selector_iter("input[type=submit]".to_owned()).unwrap()
|
submit_button = node.query_selector_iter(DOMString("input[type=submit]".to_owned())).unwrap()
|
||||||
.filter_map(Root::downcast::<HTMLInputElement>)
|
.filter_map(Root::downcast::<HTMLInputElement>)
|
||||||
.find(|r| r.form_owner() == owner);
|
.find(|r| r.form_owner() == owner);
|
||||||
match submit_button {
|
match submit_button {
|
||||||
|
@ -850,7 +853,7 @@ impl Activatable for HTMLInputElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let inputs = node.query_selector_iter("input".to_owned()).unwrap()
|
let inputs = node.query_selector_iter(DOMString("input".to_owned())).unwrap()
|
||||||
.filter_map(Root::downcast::<HTMLInputElement>)
|
.filter_map(Root::downcast::<HTMLInputElement>)
|
||||||
.filter(|input| {
|
.filter(|input| {
|
||||||
input.form_owner() == owner && match &*input.Type() {
|
input.form_owner() == owner && match &*input.Type() {
|
||||||
|
|
|
@ -261,7 +261,8 @@ impl StylesheetLoadResponder for StylesheetLoadDispatcher {
|
||||||
fn respond(self: Box<StylesheetLoadDispatcher>) {
|
fn respond(self: Box<StylesheetLoadDispatcher>) {
|
||||||
let elem = self.elem.root();
|
let elem = self.elem.root();
|
||||||
let window = window_from_node(elem.r());
|
let window = window_from_node(elem.r());
|
||||||
let event = Event::new(GlobalRef::Window(window.r()), "load".to_owned(),
|
let event = Event::new(GlobalRef::Window(window.r()),
|
||||||
|
DOMString("load".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
event.fire(elem.upcast::<EventTarget>());
|
event.fire(elem.upcast::<EventTarget>());
|
||||||
|
|
|
@ -80,7 +80,7 @@ fn collect_text(element: &Element, value: &mut DOMString) {
|
||||||
for child in element.upcast::<Node>().children() {
|
for child in element.upcast::<Node>().children() {
|
||||||
if child.is::<Text>() {
|
if child.is::<Text>() {
|
||||||
let characterdata = child.downcast::<CharacterData>().unwrap();
|
let characterdata = child.downcast::<CharacterData>().unwrap();
|
||||||
value.push_str(&characterdata.Data());
|
value.0.push_str(&characterdata.Data());
|
||||||
} else if let Some(element_child) = child.downcast() {
|
} else if let Some(element_child) = child.downcast() {
|
||||||
collect_text(element_child, value);
|
collect_text(element_child, value);
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
||||||
fn Text(&self) -> DOMString {
|
fn Text(&self) -> DOMString {
|
||||||
let mut content = DOMString::new();
|
let mut content = DOMString::new();
|
||||||
collect_text(self.upcast(), &mut content);
|
collect_text(self.upcast(), &mut content);
|
||||||
str_join(split_html_space_chars(&content), " ")
|
DOMString(str_join(split_html_space_chars(&content), " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-option-text
|
// https://html.spec.whatwg.org/multipage/#dom-option-text
|
||||||
|
|
|
@ -120,7 +120,7 @@ static SCRIPT_JS_MIMES: StaticStringVec = &[
|
||||||
|
|
||||||
#[derive(HeapSizeOf, JSTraceable)]
|
#[derive(HeapSizeOf, JSTraceable)]
|
||||||
pub enum ScriptOrigin {
|
pub enum ScriptOrigin {
|
||||||
Internal(String, Url),
|
Internal(DOMString, Url),
|
||||||
External(Result<(Metadata, Vec<u8>), String>),
|
External(Result<(Metadata, Vec<u8>), String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,7 +401,8 @@ impl HTMLScriptElement {
|
||||||
// TODO: Otherwise, decode the file to Unicode, using character
|
// TODO: Otherwise, decode the file to Unicode, using character
|
||||||
// encoding as the fallback encoding.
|
// encoding as the fallback encoding.
|
||||||
|
|
||||||
(UTF_8.decode(&*bytes, DecoderTrap::Replace).unwrap(), true,
|
(DOMString(UTF_8.decode(&*bytes, DecoderTrap::Replace).unwrap()),
|
||||||
|
true,
|
||||||
metadata.final_url)
|
metadata.final_url)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -542,13 +543,13 @@ impl HTMLScriptElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(&self,
|
fn dispatch_event(&self,
|
||||||
type_: DOMString,
|
type_: String,
|
||||||
bubbles: EventBubbles,
|
bubbles: EventBubbles,
|
||||||
cancelable: EventCancelable) -> bool {
|
cancelable: EventCancelable) -> bool {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let window = window.r();
|
let window = window.r();
|
||||||
let event = Event::new(GlobalRef::Window(window),
|
let event = Event::new(GlobalRef::Window(window),
|
||||||
type_,
|
DOMString(type_),
|
||||||
bubbles,
|
bubbles,
|
||||||
cancelable);
|
cancelable);
|
||||||
event.fire(self.upcast())
|
event.fire(self.upcast())
|
||||||
|
|
|
@ -153,11 +153,11 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-select-type
|
// https://html.spec.whatwg.org/multipage/#dom-select-type
|
||||||
fn Type(&self) -> DOMString {
|
fn Type(&self) -> DOMString {
|
||||||
if self.Multiple() {
|
DOMString(if self.Multiple() {
|
||||||
"select-multiple".to_owned()
|
"select-multiple"
|
||||||
} else {
|
} else {
|
||||||
"select-one".to_owned()
|
"select-one"
|
||||||
}
|
}.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-lfe-labels
|
// https://html.spec.whatwg.org/multipage/#dom-lfe-labels
|
||||||
|
|
|
@ -73,7 +73,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
|
||||||
let caption = match self.GetCaption() {
|
let caption = match self.GetCaption() {
|
||||||
Some(caption) => caption,
|
Some(caption) => caption,
|
||||||
None => {
|
None => {
|
||||||
let caption = HTMLTableCaptionElement::new("caption".to_owned(),
|
let caption = HTMLTableCaptionElement::new(DOMString("caption".to_owned()),
|
||||||
None,
|
None,
|
||||||
document_from_node(self).r());
|
document_from_node(self).r());
|
||||||
self.SetCaption(Some(caption.r()));
|
self.SetCaption(Some(caption.r()));
|
||||||
|
@ -92,7 +92,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-table-createtbody
|
// https://html.spec.whatwg.org/multipage/#dom-table-createtbody
|
||||||
fn CreateTBody(&self) -> Root<HTMLTableSectionElement> {
|
fn CreateTBody(&self) -> Root<HTMLTableSectionElement> {
|
||||||
let tbody = HTMLTableSectionElement::new("tbody".to_owned(),
|
let tbody = HTMLTableSectionElement::new(DOMString("tbody".to_owned()),
|
||||||
None,
|
None,
|
||||||
document_from_node(self).r());
|
document_from_node(self).r());
|
||||||
let node = self.upcast::<Node>();
|
let node = self.upcast::<Node>();
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
|
||||||
node.insert_cell_or_row(
|
node.insert_cell_or_row(
|
||||||
index,
|
index,
|
||||||
|| self.Cells(),
|
|| self.Cells(),
|
||||||
|| HTMLTableDataCellElement::new("td".to_owned(), None, node.owner_doc().r()))
|
|| HTMLTableDataCellElement::new(DOMString("td".to_owned()), None, node.owner_doc().r()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tr-deletecell
|
// https://html.spec.whatwg.org/multipage/#dom-tr-deletecell
|
||||||
|
|
|
@ -67,7 +67,7 @@ impl HTMLTableSectionElementMethods for HTMLTableSectionElement {
|
||||||
node.insert_cell_or_row(
|
node.insert_cell_or_row(
|
||||||
index,
|
index,
|
||||||
|| self.Rows(),
|
|| self.Rows(),
|
||||||
|| HTMLTableRowElement::new("tr".to_owned(), None, node.owner_doc().r()))
|
|| HTMLTableRowElement::new(DOMString("tr".to_owned()), None, node.owner_doc().r()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tbody-deleterow
|
// https://html.spec.whatwg.org/multipage/#dom-tbody-deleterow
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> {
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_value_for_layout(self) -> String {
|
unsafe fn get_value_for_layout(self) -> String {
|
||||||
(*self.unsafe_get()).textinput.borrow_for_layout().get_content()
|
(*self.unsafe_get()).textinput.borrow_for_layout().get_content().0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
|
@ -174,7 +174,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-textarea-type
|
// https://html.spec.whatwg.org/multipage/#dom-textarea-type
|
||||||
fn Type(&self) -> DOMString {
|
fn Type(&self) -> DOMString {
|
||||||
"textarea".to_owned()
|
DOMString("textarea".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-textarea-defaultvalue
|
// https://html.spec.whatwg.org/multipage/#dom-textarea-defaultvalue
|
||||||
|
@ -238,7 +238,7 @@ impl HTMLTextAreaElement {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let window = window.r();
|
let window = window.r();
|
||||||
let event = Event::new(GlobalRef::Window(window),
|
let event = Event::new(GlobalRef::Window(window),
|
||||||
"input".to_owned(),
|
DOMString("input".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl HTMLTitleElementMethods for HTMLTitleElement {
|
||||||
content.push_str(&text.upcast::<CharacterData>().data());
|
content.push_str(&text.upcast::<CharacterData>().data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
content
|
DOMString(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl LocationMethods for Location {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-location-href
|
// https://html.spec.whatwg.org/multipage/#dom-location-href
|
||||||
fn Stringifier(&self) -> DOMString {
|
fn Stringifier(&self) -> DOMString {
|
||||||
self.Href().0
|
DOMString(self.Href().0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-location-search
|
// https://html.spec.whatwg.org/multipage/#dom-location-search
|
||||||
|
|
|
@ -84,7 +84,7 @@ macro_rules! make_url_or_base_getter(
|
||||||
let url = element.get_url_attribute(&Atom::from_slice($htmlname));
|
let url = element.get_url_attribute(&Atom::from_slice($htmlname));
|
||||||
if url.is_empty() {
|
if url.is_empty() {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
window.get_url().serialize()
|
DOMString(window.get_url().serialize())
|
||||||
} else {
|
} else {
|
||||||
url
|
url
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ macro_rules! make_enumerated_getter(
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-fs-method
|
// https://html.spec.whatwg.org/multipage/#attr-fs-method
|
||||||
match &*val {
|
match &*val {
|
||||||
$($choices)|+ => val,
|
$($choices)|+ => val,
|
||||||
_ => $default.to_owned()
|
_ => DOMString($default.to_owned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl MessageEvent {
|
||||||
scope: GlobalRef,
|
scope: GlobalRef,
|
||||||
message: HandleValue) {
|
message: HandleValue) {
|
||||||
let messageevent = MessageEvent::new(
|
let messageevent = MessageEvent::new(
|
||||||
scope, "message".to_owned(), false, false, message,
|
scope, DOMString("message".to_owned()), false, false, message,
|
||||||
DOMString::new(), DOMString::new());
|
DOMString::new(), DOMString::new());
|
||||||
messageevent.upcast::<Event>().fire(target);
|
messageevent.upcast::<Event>().fire(target);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ impl NamedNodeMapMethods for NamedNodeMap {
|
||||||
// https://heycam.github.io/webidl/#dfn-supported-property-names
|
// https://heycam.github.io/webidl/#dfn-supported-property-names
|
||||||
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
|
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
|
||||||
self.owner.attrs().iter().map(|attr| {
|
self.owner.attrs().iter().map(|attr| {
|
||||||
(**attr.name()).to_owned()
|
DOMString((**attr.name()).to_owned())
|
||||||
}).collect()
|
}).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use util::opts;
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
|
||||||
pub fn Product() -> DOMString {
|
pub fn Product() -> DOMString {
|
||||||
"Gecko".to_owned()
|
DOMString("Gecko".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn TaintEnabled() -> bool {
|
pub fn TaintEnabled() -> bool {
|
||||||
|
@ -15,32 +15,32 @@ pub fn TaintEnabled() -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn AppName() -> DOMString {
|
pub fn AppName() -> DOMString {
|
||||||
"Netscape".to_owned() // Like Gecko/Webkit
|
DOMString("Netscape".to_owned()) // Like Gecko/Webkit
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn AppCodeName() -> DOMString {
|
pub fn AppCodeName() -> DOMString {
|
||||||
"Mozilla".to_owned()
|
DOMString("Mozilla".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub fn Platform() -> DOMString {
|
pub fn Platform() -> DOMString {
|
||||||
"Win32".to_owned()
|
DOMString("Win32".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||||
pub fn Platform() -> DOMString {
|
pub fn Platform() -> DOMString {
|
||||||
"Linux".to_owned()
|
DOMString("Linux".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub fn Platform() -> DOMString {
|
pub fn Platform() -> DOMString {
|
||||||
"Mac".to_owned()
|
DOMString("Mac".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn UserAgent() -> DOMString {
|
pub fn UserAgent() -> DOMString {
|
||||||
opts::get().user_agent.clone()
|
DOMString(opts::get().user_agent.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn AppVersion() -> DOMString {
|
pub fn AppVersion() -> DOMString {
|
||||||
"4.0".to_owned()
|
DOMString("4.0".to_owned())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1676,7 +1676,7 @@ impl Node {
|
||||||
copy
|
copy
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> String {
|
pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> DOMString {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
for node in iterator {
|
for node in iterator {
|
||||||
match node.downcast::<Text>() {
|
match node.downcast::<Text>() {
|
||||||
|
@ -1684,13 +1684,13 @@ impl Node {
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
content
|
DOMString(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn namespace_to_string(namespace: Namespace) -> Option<DOMString> {
|
pub fn namespace_to_string(namespace: Namespace) -> Option<DOMString> {
|
||||||
match namespace {
|
match namespace {
|
||||||
ns!("") => None,
|
ns!("") => None,
|
||||||
Namespace(ref ns) => Some((**ns).to_owned())
|
Namespace(ref ns) => Some(DOMString((**ns).to_owned()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1786,16 +1786,16 @@ impl NodeMethods for Node {
|
||||||
NodeTypeId::Element(..) => {
|
NodeTypeId::Element(..) => {
|
||||||
self.downcast::<Element>().unwrap().TagName()
|
self.downcast::<Element>().unwrap().TagName()
|
||||||
}
|
}
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => "#text".to_owned(),
|
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => DOMString("#text".to_owned()),
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
|
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
|
||||||
self.downcast::<ProcessingInstruction>().unwrap().Target()
|
self.downcast::<ProcessingInstruction>().unwrap().Target()
|
||||||
}
|
}
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => "#comment".to_owned(),
|
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => DOMString("#comment".to_owned()),
|
||||||
NodeTypeId::DocumentType => {
|
NodeTypeId::DocumentType => {
|
||||||
self.downcast::<DocumentType>().unwrap().name().clone()
|
self.downcast::<DocumentType>().unwrap().name().clone()
|
||||||
},
|
},
|
||||||
NodeTypeId::DocumentFragment => "#document-fragment".to_owned(),
|
NodeTypeId::DocumentFragment => DOMString("#document-fragment".to_owned()),
|
||||||
NodeTypeId::Document => "#document".to_owned()
|
NodeTypeId::Document => DOMString("#document".to_owned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ use script_task::{ScriptChan, ScriptTask};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use util::str::DOMString;
|
||||||
|
|
||||||
#[must_root]
|
#[must_root]
|
||||||
#[derive(JSTraceable, HeapSizeOf)]
|
#[derive(JSTraceable, HeapSizeOf)]
|
||||||
|
@ -47,7 +48,7 @@ impl Sink {
|
||||||
match child {
|
match child {
|
||||||
NodeOrText::AppendNode(n) => Root::from_ref(&*n),
|
NodeOrText::AppendNode(n) => Root::from_ref(&*n),
|
||||||
NodeOrText::AppendText(t) => {
|
NodeOrText::AppendText(t) => {
|
||||||
let text = Text::new(t.into(), &self.document);
|
let text = Text::new(DOMString(t.into()), &self.document);
|
||||||
Root::upcast(text)
|
Root::upcast(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,10 +186,10 @@ impl MainThreadRunnable for StorageEventRunnable {
|
||||||
|
|
||||||
let storage_event = StorageEvent::new(
|
let storage_event = StorageEvent::new(
|
||||||
global_ref,
|
global_ref,
|
||||||
"storage".to_owned(),
|
DOMString("storage".to_owned()),
|
||||||
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
|
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
|
||||||
this.key, this.old_value, this.new_value,
|
this.key, this.old_value, this.new_value,
|
||||||
ev_url.to_string(),
|
DOMString(ev_url.to_string()),
|
||||||
Some(storage)
|
Some(storage)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ impl TextMethods for Text {
|
||||||
let mut text = DOMString::new();
|
let mut text = DOMString::new();
|
||||||
for ref node in nodes {
|
for ref node in nodes {
|
||||||
let cdata = node.downcast::<CharacterData>().unwrap();
|
let cdata = node.downcast::<CharacterData>().unwrap();
|
||||||
text.push_str(&cdata.data());
|
text.0.push_str(&cdata.data());
|
||||||
}
|
}
|
||||||
text
|
text
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl TextDecoder {
|
||||||
impl TextDecoderMethods for TextDecoder {
|
impl TextDecoderMethods for TextDecoder {
|
||||||
// https://encoding.spec.whatwg.org/#dom-textdecoder-encoding
|
// https://encoding.spec.whatwg.org/#dom-textdecoder-encoding
|
||||||
fn Encoding(&self) -> DOMString {
|
fn Encoding(&self) -> DOMString {
|
||||||
self.encoding.whatwg_name().unwrap().to_owned()
|
DOMString(self.encoding.whatwg_name().unwrap().to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://encoding.spec.whatwg.org/#dom-textdecoder-fatal
|
// https://encoding.spec.whatwg.org/#dom-textdecoder-fatal
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl TextEncoder {
|
||||||
impl TextEncoderMethods for TextEncoder {
|
impl TextEncoderMethods for TextEncoder {
|
||||||
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
|
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
|
||||||
fn Encoding(&self) -> DOMString {
|
fn Encoding(&self) -> DOMString {
|
||||||
self.encoder.name().to_owned()
|
DOMString(self.encoder.name().to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
|
|
@ -188,7 +188,7 @@ impl URLMethods for URL {
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#dom-url-href
|
// https://url.spec.whatwg.org/#dom-url-href
|
||||||
fn Stringifier(&self) -> DOMString {
|
fn Stringifier(&self) -> DOMString {
|
||||||
self.Href().0
|
DOMString(self.Href().0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#dom-url-username
|
// https://url.spec.whatwg.org/#dom-url-username
|
||||||
|
|
|
@ -119,7 +119,7 @@ impl URLSearchParamsMethods for URLSearchParams {
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#stringification-behavior
|
// https://url.spec.whatwg.org/#stringification-behavior
|
||||||
fn Stringifier(&self) -> DOMString {
|
fn Stringifier(&self) -> DOMString {
|
||||||
self.serialize(None)
|
DOMString(self.serialize(None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ use std::fs::read_dir;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use util::opts;
|
use util::opts;
|
||||||
use util::resource_files::resources_dir_path;
|
use util::resource_files::resources_dir_path;
|
||||||
|
use util::str::DOMString;
|
||||||
|
|
||||||
|
|
||||||
pub fn load_script(head: &HTMLHeadElement) {
|
pub fn load_script(head: &HTMLHeadElement) {
|
||||||
|
@ -41,9 +42,9 @@ pub fn load_script(head: &HTMLHeadElement) {
|
||||||
Ok(ref s) if s.ends_with(".js") => "file://".to_owned() + &s[..],
|
Ok(ref s) if s.ends_with(".js") => "file://".to_owned() + &s[..],
|
||||||
_ => continue
|
_ => continue
|
||||||
};
|
};
|
||||||
let new_script = doc.CreateElement("script".to_owned()).unwrap();
|
let new_script = doc.CreateElement(DOMString("script".to_owned())).unwrap();
|
||||||
let new_script = new_script.r();
|
let new_script = new_script.r();
|
||||||
new_script.set_string_attribute(&atom!("src"), name);
|
new_script.set_string_attribute(&atom!("src"), DOMString(name));
|
||||||
node.InsertBefore(new_script.upcast(), first_child.r()).unwrap();
|
node.InsertBefore(new_script.upcast(), first_child.r()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@ pub struct WebGLActiveInfo {
|
||||||
size: i32,
|
size: i32,
|
||||||
// NOTE: `ty` stands for `type`, which is a reserved keyword
|
// NOTE: `ty` stands for `type`, which is a reserved keyword
|
||||||
ty: u32,
|
ty: u32,
|
||||||
name: String,
|
name: DOMString,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebGLActiveInfo {
|
impl WebGLActiveInfo {
|
||||||
fn new_inherited(size: i32, ty: u32, name: String) -> WebGLActiveInfo {
|
fn new_inherited(size: i32, ty: u32, name: DOMString) -> WebGLActiveInfo {
|
||||||
WebGLActiveInfo {
|
WebGLActiveInfo {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
size: size,
|
size: size,
|
||||||
|
@ -29,7 +29,7 @@ impl WebGLActiveInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(global: GlobalRef, size: i32, ty: u32, name: String) -> Root<WebGLActiveInfo> {
|
pub fn new(global: GlobalRef, size: i32, ty: u32, name: DOMString) -> Root<WebGLActiveInfo> {
|
||||||
reflect_dom_object(box WebGLActiveInfo::new_inherited(size, ty, name), global, WebGLActiveInfoBinding::Wrap)
|
reflect_dom_object(box WebGLActiveInfo::new_inherited(size, ty, name), global, WebGLActiveInfoBinding::Wrap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ use dom::webglrenderingcontext::MAX_UNIFORM_AND_ATTRIBUTE_LEN;
|
||||||
use dom::webglshader::WebGLShader;
|
use dom::webglshader::WebGLShader;
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
use util::str::DOMString;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct WebGLProgram {
|
pub struct WebGLProgram {
|
||||||
|
@ -94,7 +95,7 @@ impl WebGLProgram {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// glGetAttribLocation
|
/// glGetAttribLocation
|
||||||
pub fn get_attrib_location(&self, name: String) -> WebGLResult<Option<i32>> {
|
pub fn get_attrib_location(&self, name: DOMString) -> WebGLResult<Option<i32>> {
|
||||||
if name.len() > MAX_UNIFORM_AND_ATTRIBUTE_LEN {
|
if name.len() > MAX_UNIFORM_AND_ATTRIBUTE_LEN {
|
||||||
return Err(WebGLError::InvalidValue);
|
return Err(WebGLError::InvalidValue);
|
||||||
}
|
}
|
||||||
|
@ -105,12 +106,12 @@ impl WebGLProgram {
|
||||||
}
|
}
|
||||||
|
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::GetAttribLocation(self.id, name, sender))).unwrap();
|
self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::GetAttribLocation(self.id, name.0, sender))).unwrap();
|
||||||
Ok(receiver.recv().unwrap())
|
Ok(receiver.recv().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// glGetUniformLocation
|
/// glGetUniformLocation
|
||||||
pub fn get_uniform_location(&self, name: String) -> WebGLResult<Option<i32>> {
|
pub fn get_uniform_location(&self, name: DOMString) -> WebGLResult<Option<i32>> {
|
||||||
if name.len() > MAX_UNIFORM_AND_ATTRIBUTE_LEN {
|
if name.len() > MAX_UNIFORM_AND_ATTRIBUTE_LEN {
|
||||||
return Err(WebGLError::InvalidValue);
|
return Err(WebGLError::InvalidValue);
|
||||||
}
|
}
|
||||||
|
@ -121,7 +122,7 @@ impl WebGLProgram {
|
||||||
}
|
}
|
||||||
|
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::GetUniformLocation(self.id, name, sender))).unwrap();
|
self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::GetUniformLocation(self.id, name.0, sender))).unwrap();
|
||||||
Ok(receiver.recv().unwrap())
|
Ok(receiver.recv().unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,10 +118,11 @@ impl WebGLRenderingContext {
|
||||||
WebGLRenderingContextBinding::Wrap)),
|
WebGLRenderingContextBinding::Wrap)),
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
error!("Couldn't create WebGLRenderingContext: {}", msg);
|
error!("Couldn't create WebGLRenderingContext: {}", msg);
|
||||||
let event = WebGLContextEvent::new(global, "webglcontextcreationerror".to_owned(),
|
let event = WebGLContextEvent::new(global,
|
||||||
|
DOMString("webglcontextcreationerror".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::Cancelable,
|
EventCancelable::Cancelable,
|
||||||
msg);
|
DOMString(msg));
|
||||||
event.upcast::<Event>().fire(canvas.upcast());
|
event.upcast::<Event>().fire(canvas.upcast());
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -622,7 +623,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
|
||||||
fn GetShaderInfoLog(&self, shader: Option<&WebGLShader>) -> Option<DOMString> {
|
fn GetShaderInfoLog(&self, shader: Option<&WebGLShader>) -> Option<DOMString> {
|
||||||
if let Some(shader) = shader {
|
if let Some(shader) = shader {
|
||||||
shader.info_log()
|
shader.info_log().map(DOMString)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ use dom::webglobject::WebGLObject;
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::sync::{ONCE_INIT, Once};
|
use std::sync::{ONCE_INIT, Once};
|
||||||
|
use util::str::DOMString;
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Debug, JSTraceable, HeapSizeOf)]
|
#[derive(Clone, Copy, PartialEq, Debug, JSTraceable, HeapSizeOf)]
|
||||||
pub enum ShaderCompilationStatus {
|
pub enum ShaderCompilationStatus {
|
||||||
|
@ -28,7 +29,7 @@ pub struct WebGLShader {
|
||||||
webgl_object: WebGLObject,
|
webgl_object: WebGLObject,
|
||||||
id: u32,
|
id: u32,
|
||||||
gl_type: u32,
|
gl_type: u32,
|
||||||
source: DOMRefCell<Option<String>>,
|
source: DOMRefCell<Option<DOMString>>,
|
||||||
info_log: DOMRefCell<Option<String>>,
|
info_log: DOMRefCell<Option<String>>,
|
||||||
is_deleted: Cell<bool>,
|
is_deleted: Cell<bool>,
|
||||||
compilation_status: Cell<ShaderCompilationStatus>,
|
compilation_status: Cell<ShaderCompilationStatus>,
|
||||||
|
@ -144,12 +145,12 @@ impl WebGLShader {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the shader source
|
/// Get the shader source
|
||||||
pub fn source(&self) -> Option<String> {
|
pub fn source(&self) -> Option<DOMString> {
|
||||||
self.source.borrow().clone()
|
self.source.borrow().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// glShaderSource
|
/// glShaderSource
|
||||||
pub fn set_source(&self, source: String) {
|
pub fn set_source(&self, source: DOMString) {
|
||||||
*self.source.borrow_mut() = Some(source);
|
*self.source.borrow_mut() = Some(source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ pub struct WebSocket {
|
||||||
full: Cell<bool>, //Flag to tell if websocket queue is full
|
full: Cell<bool>, //Flag to tell if websocket queue is full
|
||||||
clean_close: Cell<bool>, //Flag to tell if the websocket closed cleanly (not due to full or fail)
|
clean_close: Cell<bool>, //Flag to tell if the websocket closed cleanly (not due to full or fail)
|
||||||
code: Cell<u16>, //Closing code
|
code: Cell<u16>, //Closing code
|
||||||
reason: DOMRefCell<DOMString>, //Closing reason
|
reason: DOMRefCell<String>, //Closing reason
|
||||||
binary_type: Cell<BinaryType>,
|
binary_type: Cell<BinaryType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ impl WebSocketMethods for WebSocket {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-websocket-url
|
// https://html.spec.whatwg.org/multipage/#dom-websocket-url
|
||||||
fn Url(&self) -> DOMString {
|
fn Url(&self) -> DOMString {
|
||||||
self.url.serialize()
|
DOMString(self.url.serialize())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-websocket-readystate
|
// https://html.spec.whatwg.org/multipage/#dom-websocket-readystate
|
||||||
|
@ -452,7 +452,7 @@ impl Runnable for ConnectionEstablishedTask {
|
||||||
|
|
||||||
// Step 6.
|
// Step 6.
|
||||||
let global = ws.global.root();
|
let global = ws.global.root();
|
||||||
let event = Event::new(global.r(), "open".to_owned(),
|
let event = Event::new(global.r(), DOMString("open".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
event.fire(ws.upcast());
|
event.fire(ws.upcast());
|
||||||
|
@ -494,23 +494,22 @@ impl Runnable for CloseTask {
|
||||||
//A Bad close
|
//A Bad close
|
||||||
ws.clean_close.set(false);
|
ws.clean_close.set(false);
|
||||||
let event = Event::new(global.r(),
|
let event = Event::new(global.r(),
|
||||||
"error".to_owned(),
|
DOMString("error".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::Cancelable);
|
EventCancelable::Cancelable);
|
||||||
event.fire(ws.upcast());
|
event.fire(ws.upcast());
|
||||||
}
|
}
|
||||||
let rsn = ws.reason.borrow();
|
let reason = ws.reason.borrow().clone();
|
||||||
let rsn_clone = rsn.clone();
|
|
||||||
/*In addition, we also have to fire a close even if error event fired
|
/*In addition, we also have to fire a close even if error event fired
|
||||||
https://html.spec.whatwg.org/multipage/#closeWebSocket
|
https://html.spec.whatwg.org/multipage/#closeWebSocket
|
||||||
*/
|
*/
|
||||||
let close_event = CloseEvent::new(global.r(),
|
let close_event = CloseEvent::new(global.r(),
|
||||||
"close".to_owned(),
|
DOMString("close".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable,
|
EventCancelable::NotCancelable,
|
||||||
ws.clean_close.get(),
|
ws.clean_close.get(),
|
||||||
ws.code.get(),
|
ws.code.get(),
|
||||||
rsn_clone);
|
DOMString(reason));
|
||||||
close_event.upcast::<Event>().fire(ws.upcast());
|
close_event.upcast::<Event>().fire(ws.upcast());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,7 @@ pub fn base64_btoa(input: DOMString) -> Fallible<DOMString> {
|
||||||
|
|
||||||
// "and then must apply the base64 algorithm to that sequence of
|
// "and then must apply the base64 algorithm to that sequence of
|
||||||
// octets, and return the result. [RFC4648]"
|
// octets, and return the result. [RFC4648]"
|
||||||
Ok(octets.to_base64(STANDARD))
|
Ok(DOMString(octets.to_base64(STANDARD)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ pub fn base64_atob(input: DOMString) -> Fallible<DOMString> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match input.from_base64() {
|
match input.from_base64() {
|
||||||
Ok(data) => Ok(data.iter().map(|&b| b as char).collect::<String>()),
|
Ok(data) => Ok(DOMString(data.iter().map(|&b| b as char).collect::<String>())),
|
||||||
Err(..) => Err(Error::InvalidCharacter)
|
Err(..) => Err(Error::InvalidCharacter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -986,12 +986,12 @@ impl Window {
|
||||||
pub fn resolved_style_query(&self,
|
pub fn resolved_style_query(&self,
|
||||||
element: TrustedNodeAddress,
|
element: TrustedNodeAddress,
|
||||||
pseudo: Option<PseudoElement>,
|
pseudo: Option<PseudoElement>,
|
||||||
property: &Atom) -> Option<String> {
|
property: &Atom) -> Option<DOMString> {
|
||||||
self.reflow(ReflowGoal::ForScriptQuery,
|
self.reflow(ReflowGoal::ForScriptQuery,
|
||||||
ReflowQueryType::ResolvedStyleQuery(element, pseudo, property.clone()),
|
ReflowQueryType::ResolvedStyleQuery(element, pseudo, property.clone()),
|
||||||
ReflowReason::Query);
|
ReflowReason::Query);
|
||||||
let ResolvedStyleResponse(resolved) = self.layout_rpc.resolved_style();
|
let ResolvedStyleResponse(resolved) = self.layout_rpc.resolved_style();
|
||||||
resolved
|
resolved.map(DOMString)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn offset_parent_query(&self, node: TrustedNodeAddress) -> (Option<Root<Element>>, Rect<Au>) {
|
pub fn offset_parent_query(&self, node: TrustedNodeAddress) -> (Option<Root<Element>>, Rect<Au>) {
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl Worker {
|
||||||
let pipeline_id = global.pipeline();
|
let pipeline_id = global.pipeline();
|
||||||
let title = format!("Worker for {}", worker_url);
|
let title = format!("Worker for {}", worker_url);
|
||||||
let page_info = DevtoolsPageInfo {
|
let page_info = DevtoolsPageInfo {
|
||||||
title: title,
|
title: DOMString(title),
|
||||||
url: worker_url.clone(),
|
url: worker_url.clone(),
|
||||||
};
|
};
|
||||||
chan.send(ScriptToDevtoolsControlMsg::NewGlobal((pipeline_id, Some(worker_id)),
|
chan.send(ScriptToDevtoolsControlMsg::NewGlobal((pipeline_id, Some(worker_id)),
|
||||||
|
@ -129,7 +129,7 @@ impl Worker {
|
||||||
let worker = address.root();
|
let worker = address.root();
|
||||||
let global = worker.r().global.root();
|
let global = worker.r().global.root();
|
||||||
let event = Event::new(global.r(),
|
let event = Event::new(global.r(),
|
||||||
"error".to_owned(),
|
DOMString("error".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
event.fire(worker.upcast());
|
event.fire(worker.upcast());
|
||||||
|
@ -140,7 +140,7 @@ impl Worker {
|
||||||
let worker = address.root();
|
let worker = address.root();
|
||||||
let global = worker.r().global.root();
|
let global = worker.r().global.root();
|
||||||
let error = RootedValue::new(global.r().get_cx(), UndefinedValue());
|
let error = RootedValue::new(global.r().get_cx(), UndefinedValue());
|
||||||
let errorevent = ErrorEvent::new(global.r(), "error".to_owned(),
|
let errorevent = ErrorEvent::new(global.r(), DOMString("error".to_owned()),
|
||||||
EventBubbles::Bubbles, EventCancelable::Cancelable,
|
EventBubbles::Bubbles, EventCancelable::Cancelable,
|
||||||
message, filename, lineno, colno, error.handle());
|
message, filename, lineno, colno, error.handle());
|
||||||
errorevent.upcast::<Event>().fire(worker.upcast());
|
errorevent.upcast::<Event>().fire(worker.upcast());
|
||||||
|
|
|
@ -289,7 +289,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
||||||
impl WorkerGlobalScope {
|
impl WorkerGlobalScope {
|
||||||
pub fn execute_script(&self, source: DOMString) {
|
pub fn execute_script(&self, source: DOMString) {
|
||||||
match self.runtime.evaluate_script(
|
match self.runtime.evaluate_script(
|
||||||
self.reflector().get_jsobject(), source, self.worker_url.serialize(), 1) {
|
self.reflector().get_jsobject(), source.0, self.worker_url.serialize(), 1) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// TODO: An error needs to be dispatched to the parent.
|
// TODO: An error needs to be dispatched to the parent.
|
||||||
|
|
|
@ -78,6 +78,6 @@ impl WorkerLocationMethods for WorkerLocation {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-workerlocation-href
|
// https://html.spec.whatwg.org/multipage/#dom-workerlocation-href
|
||||||
fn Stringifier(&self) -> DOMString {
|
fn Stringifier(&self) -> DOMString {
|
||||||
self.Href().0
|
DOMString(self.Href().0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -707,10 +707,10 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
||||||
fn GetResponseText(&self) -> Fallible<DOMString> {
|
fn GetResponseText(&self) -> Fallible<DOMString> {
|
||||||
match self.response_type.get() {
|
match self.response_type.get() {
|
||||||
_empty | Text => {
|
_empty | Text => {
|
||||||
match self.ready_state.get() {
|
Ok(DOMString(match self.ready_state.get() {
|
||||||
XMLHttpRequestState::Loading | XMLHttpRequestState::Done => Ok(self.text_response()),
|
XMLHttpRequestState::Loading | XMLHttpRequestState::Done => self.text_response(),
|
||||||
_ => Ok("".to_owned())
|
_ => "".to_owned()
|
||||||
}
|
}))
|
||||||
},
|
},
|
||||||
_ => Err(Error::InvalidState)
|
_ => Err(Error::InvalidState)
|
||||||
}
|
}
|
||||||
|
@ -731,7 +731,7 @@ impl XMLHttpRequest {
|
||||||
self.ready_state.set(rs);
|
self.ready_state.set(rs);
|
||||||
let global = self.global.root();
|
let global = self.global.root();
|
||||||
let event = Event::new(global.r(),
|
let event = Event::new(global.r(),
|
||||||
"readystatechange".to_owned(),
|
DOMString("readystatechange".to_owned()),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::Cancelable);
|
EventCancelable::Cancelable);
|
||||||
event.fire(self.upcast());
|
event.fire(self.upcast());
|
||||||
|
@ -910,10 +910,12 @@ impl XMLHttpRequest {
|
||||||
self.request_headers.borrow_mut().set_raw(name, vec![value.into_bytes()]);
|
self.request_headers.borrow_mut().set_raw(name, vec![value.into_bytes()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_progress_event(&self, upload: bool, type_: DOMString, loaded: u64, total: Option<u64>) {
|
fn dispatch_progress_event(&self, upload: bool, type_: String, loaded: u64, total: Option<u64>) {
|
||||||
let global = self.global.root();
|
let global = self.global.root();
|
||||||
let progressevent = ProgressEvent::new(global.r(),
|
let progressevent = ProgressEvent::new(global.r(),
|
||||||
type_, EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
|
DOMString(type_),
|
||||||
|
EventBubbles::DoesNotBubble,
|
||||||
|
EventCancelable::NotCancelable,
|
||||||
total.is_some(), loaded,
|
total.is_some(), loaded,
|
||||||
total.unwrap_or(0));
|
total.unwrap_or(0));
|
||||||
let target = if upload {
|
let target = if upload {
|
||||||
|
@ -924,14 +926,14 @@ impl XMLHttpRequest {
|
||||||
progressevent.upcast::<Event>().fire(target);
|
progressevent.upcast::<Event>().fire(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_upload_progress_event(&self, type_: DOMString, partial_load: Option<u64>) {
|
fn dispatch_upload_progress_event(&self, type_: String, partial_load: Option<u64>) {
|
||||||
// If partial_load is None, loading has completed and we can just use the value from the request body
|
// If partial_load is None, loading has completed and we can just use the value from the request body
|
||||||
|
|
||||||
let total = self.request_body_len.get() as u64;
|
let total = self.request_body_len.get() as u64;
|
||||||
self.dispatch_progress_event(true, type_, partial_load.unwrap_or(total), Some(total));
|
self.dispatch_progress_event(true, type_, partial_load.unwrap_or(total), Some(total));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_response_progress_event(&self, type_: DOMString) {
|
fn dispatch_response_progress_event(&self, type_: String) {
|
||||||
let len = self.response.borrow().len() as u64;
|
let len = self.response.borrow().len() as u64;
|
||||||
let total = self.response_headers.borrow().get::<ContentLength>().map(|x| { **x as u64 });
|
let total = self.response_headers.borrow().get::<ContentLength>().map(|x| { **x as u64 });
|
||||||
self.dispatch_progress_event(false, type_, len, total);
|
self.dispatch_progress_event(false, type_, len, total);
|
||||||
|
@ -985,7 +987,7 @@ impl XMLHttpRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text_response(&self) -> DOMString {
|
fn text_response(&self) -> String {
|
||||||
let mut encoding = UTF_8 as EncodingRef;
|
let mut encoding = UTF_8 as EncodingRef;
|
||||||
match self.response_headers.borrow().get() {
|
match self.response_headers.borrow().get() {
|
||||||
Some(&ContentType(mime::Mime(_, _, ref params))) => {
|
Some(&ContentType(mime::Mime(_, _, ref params))) => {
|
||||||
|
|
|
@ -71,14 +71,14 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
ElementCreator::ParserCreated);
|
ElementCreator::ParserCreated);
|
||||||
|
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
elem.set_attribute_from_parser(attr.name, attr.value.into(), None);
|
elem.set_attribute_from_parser(attr.name, DOMString(attr.value.into()), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::from_ref(elem.upcast())
|
JS::from_ref(elem.upcast())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_comment(&mut self, text: StrTendril) -> JS<Node> {
|
fn create_comment(&mut self, text: StrTendril) -> JS<Node> {
|
||||||
let comment = Comment::new(text.into(), &*self.document);
|
let comment = Comment::new(DOMString(text.into()), &*self.document);
|
||||||
JS::from_ref(comment.upcast())
|
JS::from_ref(comment.upcast())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,8 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
system_id: StrTendril) {
|
system_id: StrTendril) {
|
||||||
let doc = &*self.document;
|
let doc = &*self.document;
|
||||||
let doctype = DocumentType::new(
|
let doctype = DocumentType::new(
|
||||||
name.into(), Some(public_id.into()), Some(system_id.into()), doc);
|
DOMString(name.into()), Some(DOMString(public_id.into())),
|
||||||
|
Some(DOMString(system_id.into())), doc);
|
||||||
doc.upcast::<Node>().AppendChild(doctype.upcast()).expect("Appending failed");
|
doc.upcast::<Node>().AppendChild(doctype.upcast()).expect("Appending failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
let elem = target.downcast::<Element>()
|
let elem = target.downcast::<Element>()
|
||||||
.expect("tried to set attrs on non-Element in HTML parsing");
|
.expect("tried to set attrs on non-Element in HTML parsing");
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
elem.set_attribute_from_parser(attr.name, attr.value.into(), None);
|
elem.set_attribute_from_parser(attr.name, DOMString(attr.value.into()), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +238,7 @@ pub enum ParseContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_html(document: &Document,
|
pub fn parse_html(document: &Document,
|
||||||
input: String,
|
input: DOMString,
|
||||||
url: Url,
|
url: Url,
|
||||||
context: ParseContext) {
|
context: ParseContext) {
|
||||||
let parser = match context {
|
let parser = match context {
|
||||||
|
@ -246,7 +247,7 @@ pub fn parse_html(document: &Document,
|
||||||
ParseContext::Fragment(fc) =>
|
ParseContext::Fragment(fc) =>
|
||||||
ServoHTMLParser::new_for_fragment(Some(url), document, fc),
|
ServoHTMLParser::new_for_fragment(Some(url), document, fc),
|
||||||
};
|
};
|
||||||
parser.parse_chunk(input.into());
|
parser.parse_chunk(input.0.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#parsing-html-fragments
|
// https://html.spec.whatwg.org/multipage/#parsing-html-fragments
|
||||||
|
|
|
@ -1603,13 +1603,13 @@ impl ScriptTask {
|
||||||
incomplete.parent_info,
|
incomplete.parent_info,
|
||||||
incomplete.window_size);
|
incomplete.window_size);
|
||||||
|
|
||||||
let last_modified: Option<DOMString> = metadata.headers.as_ref().and_then(|headers| {
|
let last_modified = metadata.headers.as_ref().and_then(|headers| {
|
||||||
headers.get().map(|&LastModified(HttpDate(ref tm))| dom_last_modified(tm))
|
headers.get().map(|&LastModified(HttpDate(ref tm))| dom_last_modified(tm))
|
||||||
});
|
});
|
||||||
|
|
||||||
let content_type = match metadata.content_type {
|
let content_type = match metadata.content_type {
|
||||||
Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, _))) => {
|
Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, _))) => {
|
||||||
Some("text/plain".to_owned())
|
Some(DOMString("text/plain".to_owned()))
|
||||||
}
|
}
|
||||||
_ => None
|
_ => None
|
||||||
};
|
};
|
||||||
|
@ -1640,8 +1640,8 @@ impl ScriptTask {
|
||||||
let evalstr = incomplete.url.non_relative_scheme_data().unwrap();
|
let evalstr = incomplete.url.non_relative_scheme_data().unwrap();
|
||||||
let mut jsval = RootedValue::new(self.get_cx(), UndefinedValue());
|
let mut jsval = RootedValue::new(self.get_cx(), UndefinedValue());
|
||||||
window.evaluate_js_on_global_with_result(evalstr, jsval.handle_mut());
|
window.evaluate_js_on_global_with_result(evalstr, jsval.handle_mut());
|
||||||
let strval = FromJSValConvertible::from_jsval(self.get_cx(), jsval.handle(),
|
let strval = DOMString::from_jsval(self.get_cx(), jsval.handle(),
|
||||||
StringificationBehavior::Empty);
|
StringificationBehavior::Empty);
|
||||||
strval.unwrap_or(DOMString::new())
|
strval.unwrap_or(DOMString::new())
|
||||||
} else {
|
} else {
|
||||||
DOMString::new()
|
DOMString::new()
|
||||||
|
@ -1877,7 +1877,7 @@ impl ScriptTask {
|
||||||
// http://dev.w3.org/csswg/cssom-view/#resizing-viewports
|
// http://dev.w3.org/csswg/cssom-view/#resizing-viewports
|
||||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize
|
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize
|
||||||
let uievent = UIEvent::new(window.r(),
|
let uievent = UIEvent::new(window.r(),
|
||||||
"resize".to_owned(), EventBubbles::DoesNotBubble,
|
DOMString("resize".to_owned()), EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable, Some(window.r()),
|
EventCancelable::NotCancelable, Some(window.r()),
|
||||||
0i32);
|
0i32);
|
||||||
uievent.upcast::<Event>().fire(window.upcast());
|
uievent.upcast::<Event>().fire(window.upcast());
|
||||||
|
|
|
@ -137,7 +137,7 @@ impl<T: ClipboardProvider> TextInput<T> {
|
||||||
if self.selection_begin.is_none() {
|
if self.selection_begin.is_none() {
|
||||||
self.selection_begin = Some(self.edit_point);
|
self.selection_begin = Some(self.edit_point);
|
||||||
}
|
}
|
||||||
self.replace_selection(s.into());
|
self.replace_selection(DOMString(s.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_sorted_selection(&self) -> Option<(TextPoint, TextPoint)> {
|
pub fn get_sorted_selection(&self) -> Option<(TextPoint, TextPoint)> {
|
||||||
|
@ -170,7 +170,7 @@ impl<T: ClipboardProvider> TextInput<T> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replace_selection(&mut self, insert: String) {
|
pub fn replace_selection(&mut self, insert: DOMString) {
|
||||||
if let Some((begin, end)) = self.get_sorted_selection() {
|
if let Some((begin, end)) = self.get_sorted_selection() {
|
||||||
self.clear_selection();
|
self.clear_selection();
|
||||||
|
|
||||||
|
@ -181,20 +181,20 @@ impl<T: ClipboardProvider> TextInput<T> {
|
||||||
let lines_suffix = &self.lines[end.line + 1..];
|
let lines_suffix = &self.lines[end.line + 1..];
|
||||||
|
|
||||||
let mut insert_lines = if self.multiline {
|
let mut insert_lines = if self.multiline {
|
||||||
insert.split('\n').map(|s| s.to_owned()).collect()
|
insert.split('\n').map(|s| DOMString(s.to_owned())).collect()
|
||||||
} else {
|
} else {
|
||||||
vec!(insert)
|
vec!(insert)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut new_line = prefix.to_owned();
|
let mut new_line = prefix.to_owned();
|
||||||
new_line.push_str(&insert_lines[0]);
|
new_line.push_str(&insert_lines[0]);
|
||||||
insert_lines[0] = new_line;
|
insert_lines[0] = DOMString(new_line);
|
||||||
|
|
||||||
let last_insert_lines_index = insert_lines.len() - 1;
|
let last_insert_lines_index = insert_lines.len() - 1;
|
||||||
self.edit_point.index = insert_lines[last_insert_lines_index].len();
|
self.edit_point.index = insert_lines[last_insert_lines_index].len();
|
||||||
self.edit_point.line = begin.line + last_insert_lines_index;
|
self.edit_point.line = begin.line + last_insert_lines_index;
|
||||||
|
|
||||||
insert_lines[last_insert_lines_index].push_str(suffix);
|
insert_lines[last_insert_lines_index].0.push_str(suffix);
|
||||||
|
|
||||||
let mut new_lines = vec!();
|
let mut new_lines = vec!();
|
||||||
new_lines.push_all(lines_prefix);
|
new_lines.push_all(lines_prefix);
|
||||||
|
@ -441,14 +441,14 @@ impl<T: ClipboardProvider> TextInput<T> {
|
||||||
content.push('\n');
|
content.push('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
content
|
DOMString(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the current contents of the text input. If this is control supports multiple lines,
|
/// Set the current contents of the text input. If this is control supports multiple lines,
|
||||||
/// any \n encountered will be stripped and force a new logical line.
|
/// any \n encountered will be stripped and force a new logical line.
|
||||||
pub fn set_content(&mut self, content: DOMString) {
|
pub fn set_content(&mut self, content: DOMString) {
|
||||||
self.lines = if self.multiline {
|
self.lines = if self.multiline {
|
||||||
content.split('\n').map(|s| s.to_owned()).collect()
|
content.split('\n').map(|s| DOMString(s.to_owned())).collect()
|
||||||
} else {
|
} else {
|
||||||
vec!(content)
|
vec!(content)
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,6 +24,7 @@ use page::Page;
|
||||||
use script_task::get_page;
|
use script_task::get_page;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use util::str::DOMString;
|
||||||
|
|
||||||
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Option<Root<Node>> {
|
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Option<Root<Node>> {
|
||||||
let page = get_page(&*page, pipeline);
|
let page = get_page(&*page, pipeline);
|
||||||
|
@ -48,9 +49,8 @@ pub fn jsval_to_webdriver(cx: *mut JSContext, val: HandleValue) -> WebDriverJSRe
|
||||||
Ok(WebDriverJSValue::Number(FromJSValConvertible::from_jsval(cx, val, ()).unwrap()))
|
Ok(WebDriverJSValue::Number(FromJSValConvertible::from_jsval(cx, val, ()).unwrap()))
|
||||||
} else if val.get().is_string() {
|
} else if val.get().is_string() {
|
||||||
//FIXME: use jsstring_to_str when jsval grows to_jsstring
|
//FIXME: use jsstring_to_str when jsval grows to_jsstring
|
||||||
Ok(
|
let string: DOMString = FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap();
|
||||||
WebDriverJSValue::String(
|
Ok(WebDriverJSValue::String(string.0))
|
||||||
FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap()))
|
|
||||||
} else if val.get().is_null() {
|
} else if val.get().is_null() {
|
||||||
Ok(WebDriverJSValue::Null)
|
Ok(WebDriverJSValue::Null)
|
||||||
} else {
|
} else {
|
||||||
|
@ -115,7 +115,7 @@ pub fn handle_get_frame_id(page: &Rc<Page>,
|
||||||
|
|
||||||
pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector: String,
|
pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector: String,
|
||||||
reply: IpcSender<Result<Option<String>, ()>>) {
|
reply: IpcSender<Result<Option<String>, ()>>) {
|
||||||
reply.send(match page.document().QuerySelector(selector) {
|
reply.send(match page.document().QuerySelector(DOMString(selector)) {
|
||||||
Ok(node) => {
|
Ok(node) => {
|
||||||
Ok(node.map(|x| x.upcast::<Node>().get_unique_id()))
|
Ok(node.map(|x| x.upcast::<Node>().get_unique_id()))
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ pub fn handle_find_elements_css(page: &Rc<Page>,
|
||||||
_pipeline: PipelineId,
|
_pipeline: PipelineId,
|
||||||
selector: String,
|
selector: String,
|
||||||
reply: IpcSender<Result<Vec<String>, ()>>) {
|
reply: IpcSender<Result<Vec<String>, ()>>) {
|
||||||
reply.send(match page.document().QuerySelectorAll(selector) {
|
reply.send(match page.document().QuerySelectorAll(DOMString(selector)) {
|
||||||
Ok(ref nodes) => {
|
Ok(ref nodes) => {
|
||||||
let mut result = Vec::with_capacity(nodes.Length() as usize);
|
let mut result = Vec::with_capacity(nodes.Length() as usize);
|
||||||
for i in 0..nodes.Length() {
|
for i in 0..nodes.Length() {
|
||||||
|
@ -151,7 +151,7 @@ pub fn handle_get_active_element(page: &Rc<Page>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: IpcSender<String>) {
|
pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: IpcSender<String>) {
|
||||||
reply.send(page.document().Title()).unwrap();
|
reply.send(page.document().Title().0).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_get_text(page: &Rc<Page>,
|
pub fn handle_get_text(page: &Rc<Page>,
|
||||||
|
@ -160,7 +160,7 @@ pub fn handle_get_text(page: &Rc<Page>,
|
||||||
reply: IpcSender<Result<String, ()>>) {
|
reply: IpcSender<Result<String, ()>>) {
|
||||||
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
||||||
Some(ref node) => {
|
Some(ref node) => {
|
||||||
Ok(node.GetTextContent().unwrap_or("".to_owned()))
|
Ok(node.GetTextContent().map(|x| x.0).unwrap_or("".to_owned()))
|
||||||
},
|
},
|
||||||
None => Err(())
|
None => Err(())
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
@ -172,7 +172,7 @@ pub fn handle_get_name(page: &Rc<Page>,
|
||||||
reply: IpcSender<Result<String, ()>>) {
|
reply: IpcSender<Result<String, ()>>) {
|
||||||
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
||||||
Some(node) => {
|
Some(node) => {
|
||||||
Ok(node.downcast::<Element>().unwrap().TagName())
|
Ok(node.downcast::<Element>().unwrap().TagName().0)
|
||||||
},
|
},
|
||||||
None => Err(())
|
None => Err(())
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -1546,6 +1546,7 @@ version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
"script 0.0.1",
|
"script 0.0.1",
|
||||||
|
"util 0.0.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -35,7 +35,7 @@ use std::mem::{size_of, transmute};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::result::Result;
|
use std::result::Result;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use str::LengthOrPercentageOrAuto;
|
use str::{DOMString, LengthOrPercentageOrAuto};
|
||||||
use string_cache::atom::Atom;
|
use string_cache::atom::Atom;
|
||||||
use string_cache::namespace::Namespace;
|
use string_cache::namespace::Namespace;
|
||||||
use url;
|
use url;
|
||||||
|
@ -101,6 +101,12 @@ impl HeapSizeOf for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HeapSizeOf for DOMString {
|
||||||
|
fn heap_size_of_children(&self) -> usize {
|
||||||
|
self.0.heap_size_of_children()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: HeapSizeOf> HeapSizeOf for Option<T> {
|
impl<T: HeapSizeOf> HeapSizeOf for Option<T> {
|
||||||
fn heap_size_of_children(&self) -> usize {
|
fn heap_size_of_children(&self) -> usize {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
|
@ -8,12 +8,69 @@ use libc::c_char;
|
||||||
use num_lib::ToPrimitive;
|
use num_lib::ToPrimitive;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
use std::convert::AsRef;
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
|
use std::fmt;
|
||||||
use std::iter::{Filter, Peekable};
|
use std::iter::{Filter, Peekable};
|
||||||
use std::ops::Deref;
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::str::{CharIndices, FromStr, Split, from_utf8};
|
use std::str::{CharIndices, FromStr, Split, from_utf8};
|
||||||
|
|
||||||
pub type DOMString = String;
|
#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Deserialize, Serialize, Hash, Debug)]
|
||||||
|
pub struct DOMString(pub String);
|
||||||
|
|
||||||
|
impl DOMString {
|
||||||
|
pub fn new() -> DOMString {
|
||||||
|
DOMString(String::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for DOMString {
|
||||||
|
type Target = str;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn deref(&self) -> &str {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DerefMut for DOMString {
|
||||||
|
#[inline]
|
||||||
|
fn deref_mut(&mut self) -> &mut str {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<str> for DOMString {
|
||||||
|
fn as_ref(&self) -> &str {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for DOMString {
|
||||||
|
#[inline]
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::Display::fmt(&**self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq<str> for DOMString {
|
||||||
|
fn eq(&self, other: &str) -> bool {
|
||||||
|
&**self == other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> PartialEq<&'a str> for DOMString {
|
||||||
|
fn eq(&self, other: &&'a str) -> bool {
|
||||||
|
&**self == *other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<Vec<u8>> for DOMString {
|
||||||
|
fn into(self) -> Vec<u8> {
|
||||||
|
self.0.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type StaticCharVec = &'static [char];
|
pub type StaticCharVec = &'static [char];
|
||||||
pub type StaticStringVec = &'static [&'static str];
|
pub type StaticStringVec = &'static [&'static str];
|
||||||
|
|
||||||
|
|
|
@ -13,3 +13,6 @@ path = "../../../components/msg"
|
||||||
|
|
||||||
[dependencies.script]
|
[dependencies.script]
|
||||||
path = "../../../components/script"
|
path = "../../../components/script"
|
||||||
|
|
||||||
|
[dependencies.util]
|
||||||
|
path = "../../../components/util"
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
extern crate script;
|
extern crate script;
|
||||||
extern crate msg;
|
extern crate msg;
|
||||||
|
extern crate util;
|
||||||
|
|
||||||
#[cfg(all(test, target_pointer_width = "64"))] mod size_of;
|
#[cfg(all(test, target_pointer_width = "64"))] mod size_of;
|
||||||
#[cfg(test)] mod textinput;
|
#[cfg(test)] mod textinput;
|
||||||
|
|
|
@ -15,9 +15,10 @@ use msg::constellation_msg::{Key, KeyModifiers};
|
||||||
use script::clipboard_provider::DummyClipboardContext;
|
use script::clipboard_provider::DummyClipboardContext;
|
||||||
use script::textinput::{TextInput, Selection, Lines, Direction};
|
use script::textinput::{TextInput, Selection, Lines, Direction};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
use util::str::DOMString;
|
||||||
|
|
||||||
fn text_input(lines: Lines, s: &str) -> TextInput<DummyClipboardContext> {
|
fn text_input(lines: Lines, s: &str) -> TextInput<DummyClipboardContext> {
|
||||||
TextInput::new(lines, s.to_owned(), DummyClipboardContext::new(""))
|
TextInput::new(lines, DOMString(s.to_owned()), DummyClipboardContext::new(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -85,7 +86,7 @@ fn test_textinput_replace_selection() {
|
||||||
textinput.adjust_horizontal(2, Selection::NotSelected);
|
textinput.adjust_horizontal(2, Selection::NotSelected);
|
||||||
textinput.adjust_horizontal(2, Selection::Selected);
|
textinput.adjust_horizontal(2, Selection::Selected);
|
||||||
|
|
||||||
textinput.replace_selection("xyz".to_owned());
|
textinput.replace_selection(DOMString("xyz".to_owned()));
|
||||||
assert_eq!(textinput.get_content(), "abxyzefg");
|
assert_eq!(textinput.get_content(), "abxyzefg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +177,7 @@ fn test_textinput_set_content() {
|
||||||
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
||||||
assert_eq!(textinput.get_content(), "abc\nde\nf");
|
assert_eq!(textinput.get_content(), "abc\nde\nf");
|
||||||
|
|
||||||
textinput.set_content("abc\nf".to_owned());
|
textinput.set_content(DOMString("abc\nf".to_owned()));
|
||||||
assert_eq!(textinput.get_content(), "abc\nf");
|
assert_eq!(textinput.get_content(), "abc\nf");
|
||||||
|
|
||||||
assert_eq!(textinput.edit_point.line, 0);
|
assert_eq!(textinput.edit_point.line, 0);
|
||||||
|
@ -184,7 +185,7 @@ fn test_textinput_set_content() {
|
||||||
textinput.adjust_horizontal(3, Selection::Selected);
|
textinput.adjust_horizontal(3, Selection::Selected);
|
||||||
assert_eq!(textinput.edit_point.line, 0);
|
assert_eq!(textinput.edit_point.line, 0);
|
||||||
assert_eq!(textinput.edit_point.index, 3);
|
assert_eq!(textinput.edit_point.index, 3);
|
||||||
textinput.set_content("de".to_owned());
|
textinput.set_content(DOMString("de".to_owned()));
|
||||||
assert_eq!(textinput.get_content(), "de");
|
assert_eq!(textinput.get_content(), "de");
|
||||||
assert_eq!(textinput.edit_point.line, 0);
|
assert_eq!(textinput.edit_point.line, 0);
|
||||||
assert_eq!(textinput.edit_point.index, 2);
|
assert_eq!(textinput.edit_point.index, 2);
|
||||||
|
@ -197,7 +198,9 @@ fn test_clipboard_paste() {
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
const MODIFIERS: KeyModifiers = CONTROL;
|
const MODIFIERS: KeyModifiers = CONTROL;
|
||||||
|
|
||||||
let mut textinput = TextInput::new(Lines::Single, "defg".to_owned(), DummyClipboardContext::new("abc"));
|
let mut textinput = TextInput::new(Lines::Single,
|
||||||
|
DOMString("defg".to_owned()),
|
||||||
|
DummyClipboardContext::new("abc"));
|
||||||
assert_eq!(textinput.get_content(), "defg");
|
assert_eq!(textinput.get_content(), "defg");
|
||||||
assert_eq!(textinput.edit_point.index, 0);
|
assert_eq!(textinput.edit_point.index, 0);
|
||||||
textinput.handle_keydown_aux(Key::V, MODIFIERS);
|
textinput.handle_keydown_aux(Key::V, MODIFIERS);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue