Update to string-cache 0.3

This commit is contained in:
Simon Sapin 2016-10-30 19:27:43 +01:00
parent 9fcc9d9d3f
commit 53b638c0e2
170 changed files with 1309 additions and 1050 deletions

View file

@ -0,0 +1,16 @@
[package]
name = "servo_atoms"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
publish = false
build = "build.rs"
[lib]
path = "lib.rs"
[dependencies]
string_cache = {version = "0.3", features = ["heap_size"]}
[build-dependencies]
string_cache_codegen = "0.3"

19
components/atoms/build.rs Normal file
View file

@ -0,0 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
extern crate string_cache_codegen;
use std::env;
use std::fs::File;
use std::io::{BufReader, BufRead};
use std::path::Path;
fn main() {
let static_atoms = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("static_atoms.txt");
let static_atoms = BufReader::new(File::open(&static_atoms).unwrap());
string_cache_codegen::AtomType::new("Atom", "atom!")
.atoms(static_atoms.lines().map(Result::unwrap))
.write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join("atom.rs"))
.unwrap();
}

7
components/atoms/lib.rs Normal file
View file

@ -0,0 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
extern crate string_cache;
include!(concat!(env!("OUT_DIR"), "/atom.rs"));

View file

@ -0,0 +1,73 @@
serif
sans-serif
cursive
fantasy
monospace
left
center
right
hidden
submit
button
reset
radio
checkbox
file
image
password
text
search
url
tel
email
datetime
date
month
week
time
datetime-local
number
dir
bottom
top
left
right
width
height
margin-bottom
margin-top
margin-left
margin-right
padding-bottom
padding-top
padding-left
padding-right
DOMContentLoaded
select
input
load
loadstart
loadend
progress
transitionend
error
readystatechange
message
close
storage
activate
webglcontextcreationerror
mouseover
beforeunload
message
click
keydown
abort
beforescriptexecute
afterscriptexecute

View file

@ -32,9 +32,9 @@ plugins = {path = "../plugins"}
range = {path = "../range"}
rustc-serialize = "0.3"
serde = "0.8"
servo_atoms = {path = "../atoms"}
serde_derive = "0.8"
smallvec = "0.1"
string_cache = {version = "0.2.26", features = ["heap_size"]}
style = {path = "../style"}
style_traits = {path = "../style_traits"}
time = "0.1.12"

View file

@ -14,13 +14,13 @@ use platform::font_list::for_each_variation;
use platform::font_list::last_resort_font_families;
use platform::font_list::system_default_family;
use platform::font_template::FontTemplateData;
use servo_atoms::Atom;
use std::borrow::ToOwned;
use std::collections::HashMap;
use std::mem;
use std::ops::Deref;
use std::sync::{Arc, Mutex};
use std::u32;
use string_cache::Atom;
use style::font_face::{EffectiveSources, Source};
use style::properties::longhands::font_family::computed_value::FontFamily;
use url::Url;

View file

@ -6,11 +6,11 @@ use font::FontHandleMethods;
use platform::font::FontHandle;
use platform::font_context::FontContextHandle;
use platform::font_template::FontTemplateData;
use servo_atoms::Atom;
use std::fmt::{Debug, Error, Formatter};
use std::io::Error as IoError;
use std::sync::{Arc, Weak};
use std::u32;
use string_cache::Atom;
use style::computed_values::{font_stretch, font_weight};
/// Describes how to select a font from a given family. This is very basic at the moment and needs

View file

@ -71,9 +71,8 @@ extern crate serde_derive;
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
extern crate simd;
#[macro_use] extern crate servo_atoms;
extern crate smallvec;
#[macro_use]
extern crate string_cache;
extern crate style;
extern crate style_traits;
extern crate time;

View file

@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use servo_atoms::Atom;
use std::io::Error;
use string_cache::Atom;
use webrender_traits::NativeFontHandle;
#[derive(Deserialize, Serialize, Debug)]

View file

@ -2,9 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use servo_atoms::Atom;
use std::fs::File;
use std::io::{Read, Error};
use string_cache::Atom;
use webrender_traits::NativeFontHandle;
/// Platform specific font representation for Linux.

View file

@ -9,13 +9,13 @@ use core_text;
use core_text::font::CTFont;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::de::{Error, Visitor};
use servo_atoms::Atom;
use std::borrow::ToOwned;
use std::collections::HashMap;
use std::fs::File;
use std::io::{Read, Error as IoError};
use std::ops::Deref;
use std::sync::Mutex;
use string_cache::Atom;
use url::Url;
/// Platform specific font representation for mac.

View file

@ -3,11 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use gdi32;
use servo_atoms::Atom;
use std::ffi::OsString;
use std::io::Error;
use std::os::windows::ffi::OsStrExt;
use std::ptr;
use string_cache::Atom;
use webrender_traits::NativeFontHandle;
use winapi::{DWORD, LF_FACESIZE, LOGFONTW, OUT_TT_ONLY_PRECIS, WCHAR};

View file

@ -21,6 +21,7 @@ gfx = {path = "../gfx"}
gfx_traits = {path = "../gfx_traits"}
heapsize = "0.3.0"
heapsize_derive = "0.1"
html5ever-atoms = "0.1"
ipc-channel = "0.5"
libc = "0.2"
log = "0.3.5"
@ -36,8 +37,8 @@ script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
selectors = "0.14"
serde_derive = "0.8"
servo_atoms = {path = "../atoms"}
smallvec = "0.1"
string_cache = {version = "0.2.26", features = ["heap_size"]}
style = {path = "../style"}
style_traits = {path = "../style_traits"}
unicode-bidi = "0.2"

View file

@ -1660,7 +1660,10 @@ trait ObjectElement {
impl<N> ObjectElement for N where N: ThreadSafeLayoutNode {
fn has_object_data(&self) -> bool {
let elem = self.as_element().unwrap();
let type_and_data = (elem.get_attr(&ns!(), &atom!("type")), elem.get_attr(&ns!(), &atom!("data")));
let type_and_data = (
elem.get_attr(&ns!(), &local_name!("type")),
elem.get_attr(&ns!(), &local_name!("data")),
);
match type_and_data {
(None, Some(uri)) => is_image_data(uri),
_ => false
@ -1669,7 +1672,10 @@ impl<N> ObjectElement for N where N: ThreadSafeLayoutNode {
fn object_data(&self) -> Option<Url> {
let elem = self.as_element().unwrap();
let type_and_data = (elem.get_attr(&ns!(), &atom!("type")), elem.get_attr(&ns!(), &atom!("data")));
let type_and_data = (
elem.get_attr(&ns!(), &local_name!("type")),
elem.get_attr(&ns!(), &local_name!("data")),
);
match type_and_data {
(None, Some(uri)) if is_image_data(uri) => Url::parse(uri).ok(),
_ => None

View file

@ -886,7 +886,7 @@ impl TableColumnFragmentInfo {
/// Create the information specific to an table column fragment.
pub fn new<N: ThreadSafeLayoutNode>(node: &N) -> TableColumnFragmentInfo {
let element = node.as_element().unwrap();
let span = element.get_attr(&ns!(), &atom!("span"))
let span = element.get_attr(&ns!(), &local_name!("span"))
.and_then(|string| string.parse().ok())
.unwrap_or(0);
TableColumnFragmentInfo {

View file

@ -29,6 +29,7 @@ extern crate gfx;
extern crate gfx_traits;
extern crate heapsize;
#[macro_use] extern crate heapsize_derive;
#[macro_use] extern crate html5ever_atoms;
extern crate ipc_channel;
extern crate libc;
#[macro_use]
@ -47,8 +48,8 @@ extern crate range;
extern crate rustc_serialize;
extern crate script_layout_interface;
extern crate script_traits;
#[macro_use] extern crate servo_atoms;
extern crate smallvec;
#[macro_use(atom, ns)] extern crate string_cache;
extern crate style;
extern crate style_traits;
extern crate unicode_bidi;

View file

@ -23,10 +23,10 @@ use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutElemen
use script_traits::LayoutMsg as ConstellationMsg;
use script_traits::UntrustedNodeAddress;
use sequential;
use servo_atoms::Atom;
use std::cmp::{min, max};
use std::ops::Deref;
use std::sync::{Arc, Mutex};
use string_cache::Atom;
use style::computed_values;
use style::context::StyleContext;
use style::logical_geometry::{WritingMode, BlockFlowDirection, InlineBaseDirection};

View file

@ -36,7 +36,8 @@ fnv = "1.0"
gfx_traits = {path = "../gfx_traits"}
heapsize = "0.3.6"
heapsize_derive = "0.1"
html5ever = {version = "0.8.0", features = ["heap_size", "unstable"]}
html5ever = {version = "0.9.0", features = ["heap_size", "unstable"]}
html5ever-atoms = {version = "0.1", features = ["heap_size"]}
hyper = "0.9.9"
hyper_serde = "0.1.4"
image = "0.10"
@ -66,8 +67,8 @@ script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
selectors = "0.14"
serde = "0.8"
servo_atoms = {path = "../atoms"}
smallvec = "0.1"
string_cache = {version = "0.2.26", features = ["heap_size", "unstable"]}
style = {path = "../style"}
style_traits = {path = "../style_traits"}
time = "0.1.12"
@ -75,7 +76,7 @@ url = {version = "1.2", features = ["heap_size", "query_encoding"]}
util = {path = "../util"}
uuid = {version = "0.3.1", features = ["v4"]}
websocket = "0.17"
xml5ever = {version = "0.1.2", features = ["unstable"]}
xml5ever = {version = "0.2", features = ["unstable"]}
[dependencies.webrender_traits]
git = "https://github.com/servo/webrender"

View file

@ -13,10 +13,11 @@ use dom::bindings::str::DOMString;
use dom::element::{AttributeMutation, Element};
use dom::virtualmethods::vtable_for;
use dom::window::Window;
use html5ever_atoms::{Prefix, LocalName, Namespace};
use servo_atoms::Atom;
use std::borrow::ToOwned;
use std::cell::Ref;
use std::mem;
use string_cache::{Atom, Namespace};
use style::attr::{AttrIdentifier, AttrValue};
// https://dom.spec.whatwg.org/#interface-attr
@ -31,11 +32,11 @@ pub struct Attr {
}
impl Attr {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
value: AttrValue,
name: Atom,
name: LocalName,
namespace: Namespace,
prefix: Option<Atom>,
prefix: Option<Prefix>,
owner: Option<&Element>)
-> Attr {
Attr {
@ -52,11 +53,11 @@ impl Attr {
}
pub fn new(window: &Window,
local_name: Atom,
local_name: LocalName,
value: AttrValue,
name: Atom,
name: LocalName,
namespace: Namespace,
prefix: Option<Atom>,
prefix: Option<Prefix>,
owner: Option<&Element>)
-> Root<Attr> {
reflect_dom_object(box Attr::new_inherited(local_name,
@ -70,7 +71,7 @@ impl Attr {
}
#[inline]
pub fn name(&self) -> &Atom {
pub fn name(&self) -> &LocalName {
&self.identifier.name
}
@ -80,7 +81,7 @@ impl Attr {
}
#[inline]
pub fn prefix(&self) -> &Option<Atom> {
pub fn prefix(&self) -> &Option<Prefix> {
&self.identifier.prefix
}
}
@ -88,7 +89,7 @@ impl Attr {
impl AttrMethods for Attr {
// https://dom.spec.whatwg.org/#dom-attr-localname
fn LocalName(&self) -> DOMString {
// FIXME(ajeffrey): convert directly from Atom to DOMString
// FIXME(ajeffrey): convert directly from LocalName to DOMString
DOMString::from(&**self.local_name())
}
@ -132,7 +133,7 @@ impl AttrMethods for Attr {
// https://dom.spec.whatwg.org/#dom-attr-name
fn Name(&self) -> DOMString {
// FIXME(ajeffrey): convert directly from Atom to DOMString
// FIXME(ajeffrey): convert directly from LocalName to DOMString
DOMString::from(&*self.identifier.name)
}
@ -143,16 +144,15 @@ impl AttrMethods for Attr {
// https://dom.spec.whatwg.org/#dom-attr-namespaceuri
fn GetNamespaceURI(&self) -> Option<DOMString> {
let Namespace(ref atom) = self.identifier.namespace;
match &**atom {
"" => None,
url => Some(DOMString::from(url)),
match self.identifier.namespace {
ns!() => None,
ref url => Some(DOMString::from(&**url)),
}
}
// https://dom.spec.whatwg.org/#dom-attr-prefix
fn GetPrefix(&self) -> Option<DOMString> {
// FIXME(ajeffrey): convert directly from Atom to DOMString
// FIXME(ajeffrey): convert directly from LocalName to DOMString
self.prefix().as_ref().map(|p| DOMString::from(&**p))
}
@ -192,7 +192,7 @@ impl Attr {
self.value.borrow()
}
pub fn local_name(&self) -> &Atom {
pub fn local_name(&self) -> &LocalName {
&self.identifier.local_name
}
@ -216,9 +216,8 @@ impl Attr {
}
pub fn summarize(&self) -> AttrInfo {
let Namespace(ref ns) = self.identifier.namespace;
AttrInfo {
namespace: (**ns).to_owned(),
namespace: (*self.identifier.namespace).to_owned(),
name: String::from(self.Name()),
value: String::from(self.Value()),
}
@ -231,7 +230,7 @@ pub trait AttrHelpersForLayout {
unsafe fn value_ref_forever(&self) -> &'static str;
unsafe fn value_atom_forever(&self) -> Option<Atom>;
unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]>;
unsafe fn local_name_atom_forever(&self) -> Atom;
unsafe fn local_name_atom_forever(&self) -> LocalName;
unsafe fn value_for_layout(&self) -> &AttrValue;
}
@ -267,7 +266,7 @@ impl AttrHelpersForLayout for LayoutJS<Attr> {
}
#[inline]
unsafe fn local_name_atom_forever(&self) -> Atom {
unsafe fn local_name_atom_forever(&self) -> LocalName {
(*self.unsafe_get()).identifier.local_name.clone()
}

View file

@ -12,7 +12,7 @@ use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::globalscope::GlobalScope;
use string_cache::Atom;
use servo_atoms::Atom;
// https://html.spec.whatwg.org/multipage/#beforeunloadevent
#[dom_struct]

View file

@ -4,6 +4,8 @@
//! The `ByteString` struct.
use html5ever_atoms::{LocalName, Namespace};
use servo_atoms::Atom;
use std::ascii::AsciiExt;
use std::borrow::{Borrow, Cow, ToOwned};
use std::fmt;
@ -12,7 +14,6 @@ use std::ops;
use std::ops::{Deref, DerefMut};
use std::str;
use std::str::{Bytes, FromStr};
use string_cache::Atom;
/// Encapsulates the IDL `ByteString` type.
#[derive(JSTraceable, Clone, Eq, PartialEq, HeapSizeOf, Debug)]
@ -255,6 +256,18 @@ impl<'a> From<Cow<'a, str>> for DOMString {
}
}
impl From<DOMString> for LocalName {
fn from(contents: DOMString) -> LocalName {
LocalName::from(contents.0)
}
}
impl From<DOMString> for Namespace {
fn from(contents: DOMString) -> Namespace {
Namespace::from(contents.0)
}
}
impl From<DOMString> for Atom {
fn from(contents: DOMString) -> Atom {
Atom::from(contents.0)

View file

@ -47,6 +47,7 @@ use euclid::length::Length as EuclidLength;
use euclid::rect::Rect;
use euclid::size::Size2D;
use html5ever::tree_builder::QuirksMode;
use html5ever_atoms::{Prefix, LocalName, Namespace, QualName};
use hyper::header::Headers;
use hyper::method::Method;
use hyper::mime::Mime;
@ -76,6 +77,7 @@ use script_runtime::ScriptChan;
use script_traits::{TimerEventId, TimerSource, TouchpadPressurePhase};
use script_traits::{UntrustedNodeAddress, WindowSizeData, WindowSizeType};
use serde::{Deserialize, Serialize};
use servo_atoms::Atom;
use smallvec::SmallVec;
use std::boxed::FnBox;
use std::cell::{Cell, UnsafeCell};
@ -88,7 +90,6 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicBool, AtomicUsize};
use std::sync::mpsc::{Receiver, Sender};
use std::time::{SystemTime, Instant};
use string_cache::{Atom, Namespace, QualName};
use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
use style::element_state::*;
use style::media_queries::MediaQueryList;
@ -311,7 +312,7 @@ no_jsmanaged_fields!(Arc<T>);
no_jsmanaged_fields!(Image, ImageMetadata, ImageCacheChan, ImageCacheThread);
no_jsmanaged_fields!(Metadata);
no_jsmanaged_fields!(NetworkError);
no_jsmanaged_fields!(Atom, Namespace, QualName);
no_jsmanaged_fields!(Atom, Prefix, LocalName, Namespace, QualName);
no_jsmanaged_fields!(Trusted<T: Reflectable>);
no_jsmanaged_fields!(TrustedPromise);
no_jsmanaged_fields!(PropertyDeclarationBlock);

View file

@ -6,7 +6,7 @@
use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::str::DOMString;
use string_cache::{Atom, Namespace};
use html5ever_atoms::{Prefix, LocalName, Namespace};
/// Validate a qualified name. See https://dom.spec.whatwg.org/#validate for details.
pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult {
@ -27,7 +27,7 @@ pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult {
/// See https://dom.spec.whatwg.org/#validate-and-extract for details.
pub fn validate_and_extract(namespace: Option<DOMString>,
qualified_name: &str)
-> Fallible<(Namespace, Option<Atom>, Atom)> {
-> Fallible<(Namespace, Option<Prefix>, LocalName)> {
// Step 1.
let namespace = namespace_from_domstring(namespace);
@ -75,7 +75,7 @@ pub fn validate_and_extract(namespace: Option<DOMString>,
},
(ns, p) => {
// Step 10.
Ok((ns, p.map(Atom::from), Atom::from(local_name)))
Ok((ns, p.map(Prefix::from), LocalName::from(local_name)))
}
}
}
@ -174,6 +174,6 @@ pub fn xml_name_type(name: &str) -> XMLName {
pub fn namespace_from_domstring(url: Option<DOMString>) -> Namespace {
match url {
None => ns!(),
Some(s) => Namespace(Atom::from(s)),
Some(s) => Namespace::from(s),
}
}

View file

@ -12,7 +12,7 @@ use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::globalscope::GlobalScope;
use string_cache::Atom;
use servo_atoms::Atom;
#[dom_struct]
pub struct CloseEvent {

View file

@ -77,7 +77,7 @@ use dom::htmlulistelement::HTMLUListElement;
use dom::htmlunknownelement::HTMLUnknownElement;
use dom::htmlvideoelement::HTMLVideoElement;
use dom::svgsvgelement::SVGSVGElement;
use string_cache::{Atom, QualName};
use html5ever_atoms::{Prefix, QualName};
use util::prefs::PREFS;
fn create_svg_element(name: QualName,
@ -102,7 +102,7 @@ fn create_svg_element(name: QualName,
}
match name.local {
atom!("svg") => make!(SVGSVGElement),
local_name!("svg") => make!(SVGSVGElement),
_ => Element::new(name.local, name.ns, prefix, document),
}
}
@ -128,157 +128,157 @@ fn create_html_element(name: QualName,
// This is a big match, and the IDs for inline-interned atoms are not very structured.
// Perhaps we should build a perfect hash from those IDs instead.
match name.local {
atom!("a") => make!(HTMLAnchorElement),
atom!("abbr") => make!(HTMLElement),
atom!("acronym") => make!(HTMLElement),
atom!("address") => make!(HTMLElement),
atom!("applet") => make!(HTMLAppletElement),
atom!("area") => make!(HTMLAreaElement),
atom!("article") => make!(HTMLElement),
atom!("aside") => make!(HTMLElement),
atom!("audio") => make!(HTMLAudioElement),
atom!("b") => make!(HTMLElement),
atom!("base") => make!(HTMLBaseElement),
atom!("bdi") => make!(HTMLElement),
atom!("bdo") => make!(HTMLElement),
local_name!("a") => make!(HTMLAnchorElement),
local_name!("abbr") => make!(HTMLElement),
local_name!("acronym") => make!(HTMLElement),
local_name!("address") => make!(HTMLElement),
local_name!("applet") => make!(HTMLAppletElement),
local_name!("area") => make!(HTMLAreaElement),
local_name!("article") => make!(HTMLElement),
local_name!("aside") => make!(HTMLElement),
local_name!("audio") => make!(HTMLAudioElement),
local_name!("b") => make!(HTMLElement),
local_name!("base") => make!(HTMLBaseElement),
local_name!("bdi") => make!(HTMLElement),
local_name!("bdo") => make!(HTMLElement),
// https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:bgsound
atom!("bgsound") => make!(HTMLUnknownElement),
atom!("big") => make!(HTMLElement),
local_name!("bgsound") => make!(HTMLUnknownElement),
local_name!("big") => make!(HTMLElement),
// https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:blink
atom!("blink") => make!(HTMLUnknownElement),
local_name!("blink") => make!(HTMLUnknownElement),
// https://html.spec.whatwg.org/multipage/#the-blockquote-element
atom!("blockquote") => make!(HTMLQuoteElement),
atom!("body") => make!(HTMLBodyElement),
atom!("br") => make!(HTMLBRElement),
atom!("button") => make!(HTMLButtonElement),
atom!("canvas") => make!(HTMLCanvasElement),
atom!("caption") => make!(HTMLTableCaptionElement),
atom!("center") => make!(HTMLElement),
atom!("cite") => make!(HTMLElement),
atom!("code") => make!(HTMLElement),
atom!("col") => make!(HTMLTableColElement),
atom!("colgroup") => make!(HTMLTableColElement),
atom!("data") => make!(HTMLDataElement),
atom!("datalist") => make!(HTMLDataListElement),
atom!("dd") => make!(HTMLElement),
atom!("del") => make!(HTMLModElement),
atom!("details") => make!(HTMLDetailsElement),
atom!("dfn") => make!(HTMLElement),
atom!("dialog") => make!(HTMLDialogElement),
atom!("dir") => make!(HTMLDirectoryElement),
atom!("div") => make!(HTMLDivElement),
atom!("dl") => make!(HTMLDListElement),
atom!("dt") => make!(HTMLElement),
atom!("em") => make!(HTMLElement),
atom!("embed") => make!(HTMLEmbedElement),
atom!("fieldset") => make!(HTMLFieldSetElement),
atom!("figcaption") => make!(HTMLElement),
atom!("figure") => make!(HTMLElement),
atom!("font") => make!(HTMLFontElement),
atom!("footer") => make!(HTMLElement),
atom!("form") => make!(HTMLFormElement),
atom!("frame") => make!(HTMLFrameElement),
atom!("frameset") => make!(HTMLFrameSetElement),
atom!("h1") => make!(HTMLHeadingElement, HeadingLevel::Heading1),
atom!("h2") => make!(HTMLHeadingElement, HeadingLevel::Heading2),
atom!("h3") => make!(HTMLHeadingElement, HeadingLevel::Heading3),
atom!("h4") => make!(HTMLHeadingElement, HeadingLevel::Heading4),
atom!("h5") => make!(HTMLHeadingElement, HeadingLevel::Heading5),
atom!("h6") => make!(HTMLHeadingElement, HeadingLevel::Heading6),
atom!("head") => make!(HTMLHeadElement),
atom!("header") => make!(HTMLElement),
atom!("hgroup") => make!(HTMLElement),
atom!("hr") => make!(HTMLHRElement),
atom!("html") => make!(HTMLHtmlElement),
atom!("i") => make!(HTMLElement),
atom!("iframe") => make!(HTMLIFrameElement),
atom!("img") => make!(HTMLImageElement),
atom!("input") => make!(HTMLInputElement),
atom!("ins") => make!(HTMLModElement),
local_name!("blockquote") => make!(HTMLQuoteElement),
local_name!("body") => make!(HTMLBodyElement),
local_name!("br") => make!(HTMLBRElement),
local_name!("button") => make!(HTMLButtonElement),
local_name!("canvas") => make!(HTMLCanvasElement),
local_name!("caption") => make!(HTMLTableCaptionElement),
local_name!("center") => make!(HTMLElement),
local_name!("cite") => make!(HTMLElement),
local_name!("code") => make!(HTMLElement),
local_name!("col") => make!(HTMLTableColElement),
local_name!("colgroup") => make!(HTMLTableColElement),
local_name!("data") => make!(HTMLDataElement),
local_name!("datalist") => make!(HTMLDataListElement),
local_name!("dd") => make!(HTMLElement),
local_name!("del") => make!(HTMLModElement),
local_name!("details") => make!(HTMLDetailsElement),
local_name!("dfn") => make!(HTMLElement),
local_name!("dialog") => make!(HTMLDialogElement),
local_name!("dir") => make!(HTMLDirectoryElement),
local_name!("div") => make!(HTMLDivElement),
local_name!("dl") => make!(HTMLDListElement),
local_name!("dt") => make!(HTMLElement),
local_name!("em") => make!(HTMLElement),
local_name!("embed") => make!(HTMLEmbedElement),
local_name!("fieldset") => make!(HTMLFieldSetElement),
local_name!("figcaption") => make!(HTMLElement),
local_name!("figure") => make!(HTMLElement),
local_name!("font") => make!(HTMLFontElement),
local_name!("footer") => make!(HTMLElement),
local_name!("form") => make!(HTMLFormElement),
local_name!("frame") => make!(HTMLFrameElement),
local_name!("frameset") => make!(HTMLFrameSetElement),
local_name!("h1") => make!(HTMLHeadingElement, HeadingLevel::Heading1),
local_name!("h2") => make!(HTMLHeadingElement, HeadingLevel::Heading2),
local_name!("h3") => make!(HTMLHeadingElement, HeadingLevel::Heading3),
local_name!("h4") => make!(HTMLHeadingElement, HeadingLevel::Heading4),
local_name!("h5") => make!(HTMLHeadingElement, HeadingLevel::Heading5),
local_name!("h6") => make!(HTMLHeadingElement, HeadingLevel::Heading6),
local_name!("head") => make!(HTMLHeadElement),
local_name!("header") => make!(HTMLElement),
local_name!("hgroup") => make!(HTMLElement),
local_name!("hr") => make!(HTMLHRElement),
local_name!("html") => make!(HTMLHtmlElement),
local_name!("i") => make!(HTMLElement),
local_name!("iframe") => make!(HTMLIFrameElement),
local_name!("img") => make!(HTMLImageElement),
local_name!("input") => make!(HTMLInputElement),
local_name!("ins") => make!(HTMLModElement),
// https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:isindex-2
atom!("isindex") => make!(HTMLUnknownElement),
atom!("kbd") => make!(HTMLElement),
atom!("label") => make!(HTMLLabelElement),
atom!("legend") => make!(HTMLLegendElement),
atom!("li") => make!(HTMLLIElement),
atom!("link") => make!(HTMLLinkElement, creator),
local_name!("isindex") => make!(HTMLUnknownElement),
local_name!("kbd") => make!(HTMLElement),
local_name!("label") => make!(HTMLLabelElement),
local_name!("legend") => make!(HTMLLegendElement),
local_name!("li") => make!(HTMLLIElement),
local_name!("link") => make!(HTMLLinkElement, creator),
// https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:listing
atom!("listing") => make!(HTMLPreElement),
atom!("main") => make!(HTMLElement),
atom!("map") => make!(HTMLMapElement),
atom!("mark") => make!(HTMLElement),
atom!("marquee") => make!(HTMLElement),
atom!("meta") => make!(HTMLMetaElement),
atom!("meter") => make!(HTMLMeterElement),
local_name!("listing") => make!(HTMLPreElement),
local_name!("main") => make!(HTMLElement),
local_name!("map") => make!(HTMLMapElement),
local_name!("mark") => make!(HTMLElement),
local_name!("marquee") => make!(HTMLElement),
local_name!("meta") => make!(HTMLMetaElement),
local_name!("meter") => make!(HTMLMeterElement),
// https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:multicol
atom!("multicol") => make!(HTMLUnknownElement),
atom!("nav") => make!(HTMLElement),
local_name!("multicol") => make!(HTMLUnknownElement),
local_name!("nav") => make!(HTMLElement),
// https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:nextid
atom!("nextid") => make!(HTMLUnknownElement),
atom!("nobr") => make!(HTMLElement),
atom!("noframes") => make!(HTMLElement),
atom!("noscript") => make!(HTMLElement),
atom!("object") => make!(HTMLObjectElement),
atom!("ol") => make!(HTMLOListElement),
atom!("optgroup") => make!(HTMLOptGroupElement),
atom!("option") => make!(HTMLOptionElement),
atom!("output") => make!(HTMLOutputElement),
atom!("p") => make!(HTMLParagraphElement),
atom!("param") => make!(HTMLParamElement),
atom!("plaintext") => make!(HTMLPreElement),
atom!("pre") => make!(HTMLPreElement),
atom!("progress") => make!(HTMLProgressElement),
atom!("q") => make!(HTMLQuoteElement),
atom!("rp") => make!(HTMLElement),
atom!("rt") => make!(HTMLElement),
atom!("ruby") => make!(HTMLElement),
atom!("s") => make!(HTMLElement),
atom!("samp") => make!(HTMLElement),
atom!("script") => make!(HTMLScriptElement, creator),
atom!("section") => make!(HTMLElement),
atom!("select") => make!(HTMLSelectElement),
atom!("small") => make!(HTMLElement),
atom!("source") => make!(HTMLSourceElement),
local_name!("nextid") => make!(HTMLUnknownElement),
local_name!("nobr") => make!(HTMLElement),
local_name!("noframes") => make!(HTMLElement),
local_name!("noscript") => make!(HTMLElement),
local_name!("object") => make!(HTMLObjectElement),
local_name!("ol") => make!(HTMLOListElement),
local_name!("optgroup") => make!(HTMLOptGroupElement),
local_name!("option") => make!(HTMLOptionElement),
local_name!("output") => make!(HTMLOutputElement),
local_name!("p") => make!(HTMLParagraphElement),
local_name!("param") => make!(HTMLParamElement),
local_name!("plaintext") => make!(HTMLPreElement),
local_name!("pre") => make!(HTMLPreElement),
local_name!("progress") => make!(HTMLProgressElement),
local_name!("q") => make!(HTMLQuoteElement),
local_name!("rp") => make!(HTMLElement),
local_name!("rt") => make!(HTMLElement),
local_name!("ruby") => make!(HTMLElement),
local_name!("s") => make!(HTMLElement),
local_name!("samp") => make!(HTMLElement),
local_name!("script") => make!(HTMLScriptElement, creator),
local_name!("section") => make!(HTMLElement),
local_name!("select") => make!(HTMLSelectElement),
local_name!("small") => make!(HTMLElement),
local_name!("source") => make!(HTMLSourceElement),
// https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:spacer
atom!("spacer") => make!(HTMLUnknownElement),
atom!("span") => make!(HTMLSpanElement),
atom!("strike") => make!(HTMLElement),
atom!("strong") => make!(HTMLElement),
atom!("style") => make!(HTMLStyleElement),
atom!("sub") => make!(HTMLElement),
atom!("summary") => make!(HTMLElement),
atom!("sup") => make!(HTMLElement),
atom!("table") => make!(HTMLTableElement),
atom!("tbody") => make!(HTMLTableSectionElement),
atom!("td") => make!(HTMLTableDataCellElement),
atom!("template") => make!(HTMLTemplateElement),
atom!("textarea") => make!(HTMLTextAreaElement),
local_name!("spacer") => make!(HTMLUnknownElement),
local_name!("span") => make!(HTMLSpanElement),
local_name!("strike") => make!(HTMLElement),
local_name!("strong") => make!(HTMLElement),
local_name!("style") => make!(HTMLStyleElement),
local_name!("sub") => make!(HTMLElement),
local_name!("summary") => make!(HTMLElement),
local_name!("sup") => make!(HTMLElement),
local_name!("table") => make!(HTMLTableElement),
local_name!("tbody") => make!(HTMLTableSectionElement),
local_name!("td") => make!(HTMLTableDataCellElement),
local_name!("template") => make!(HTMLTemplateElement),
local_name!("textarea") => make!(HTMLTextAreaElement),
// https://html.spec.whatwg.org/multipage/#the-tfoot-element:concept-element-dom
atom!("tfoot") => make!(HTMLTableSectionElement),
atom!("th") => make!(HTMLTableHeaderCellElement),
local_name!("tfoot") => make!(HTMLTableSectionElement),
local_name!("th") => make!(HTMLTableHeaderCellElement),
// https://html.spec.whatwg.org/multipage/#the-thead-element:concept-element-dom
atom!("thead") => make!(HTMLTableSectionElement),
atom!("time") => make!(HTMLTimeElement),
atom!("title") => make!(HTMLTitleElement),
atom!("tr") => make!(HTMLTableRowElement),
atom!("tt") => make!(HTMLElement),
atom!("track") => make!(HTMLTrackElement),
atom!("u") => make!(HTMLElement),
atom!("ul") => make!(HTMLUListElement),
atom!("var") => make!(HTMLElement),
atom!("video") => make!(HTMLVideoElement),
atom!("wbr") => make!(HTMLElement),
atom!("xmp") => make!(HTMLPreElement),
local_name!("thead") => make!(HTMLTableSectionElement),
local_name!("time") => make!(HTMLTimeElement),
local_name!("title") => make!(HTMLTitleElement),
local_name!("tr") => make!(HTMLTableRowElement),
local_name!("tt") => make!(HTMLElement),
local_name!("track") => make!(HTMLTrackElement),
local_name!("u") => make!(HTMLElement),
local_name!("ul") => make!(HTMLUListElement),
local_name!("var") => make!(HTMLElement),
local_name!("video") => make!(HTMLVideoElement),
local_name!("wbr") => make!(HTMLElement),
local_name!("xmp") => make!(HTMLPreElement),
_ => make!(HTMLUnknownElement),
}
}
pub fn create_element(name: QualName,
prefix: Option<Atom>,
prefix: Option<Prefix>,
document: &Document,
creator: ElementCreator)
-> Root<Element> {
// FIXME(ajeffrey): Convert directly from Atom to DOMString.
// FIXME(ajeffrey): Convert directly from Prefix to DOMString.
let prefix = prefix.map(|p| DOMString::from(&*p));

View file

@ -13,9 +13,9 @@ use dom::element::Element;
use dom::node::{Node, NodeDamage, window_from_node};
use dom::window::Window;
use parking_lot::RwLock;
use servo_atoms::Atom;
use std::ascii::AsciiExt;
use std::sync::Arc;
use string_cache::Atom;
use style::parser::ParserContextExtraData;
use style::properties::{Shorthand, Importance, PropertyDeclarationBlock};
use style::properties::{is_supported_property, parse_one_declaration, parse_style_attribute};

View file

@ -14,7 +14,7 @@ use dom::event::Event;
use dom::globalscope::GlobalScope;
use js::jsapi::{HandleValue, JSContext};
use js::jsval::JSVal;
use string_cache::Atom;
use servo_atoms::Atom;
// https://dom.spec.whatwg.org/#interface-customevent
#[dom_struct]

View file

@ -91,6 +91,7 @@ use encoding::EncodingRef;
use encoding::all::UTF_8;
use euclid::point::Point2D;
use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks, QuirksMode};
use html5ever_atoms::{LocalName, QualName};
use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::{JSContext, JSObject, JSRuntime};
use js::jsapi::JS_GetRuntime;
@ -110,6 +111,7 @@ use script_traits::{AnimationState, CompositorEvent, MouseButton, MouseEventType
use script_traits::{ScriptMsg as ConstellationMsg, TouchpadPressurePhase};
use script_traits::{TouchEventType, TouchId};
use script_traits::UntrustedNodeAddress;
use servo_atoms::Atom;
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::boxed::FnBox;
@ -122,7 +124,6 @@ use std::mem;
use std::rc::Rc;
use std::sync::Arc;
use std::time::{Duration, Instant};
use string_cache::{Atom, QualName};
use style::attr::AttrValue;
use style::context::ReflowGoal;
use style::selector_impl::ElementSnapshot;
@ -175,7 +176,7 @@ pub struct Document {
quirks_mode: Cell<QuirksMode>,
/// Caches for the getElement methods
id_map: DOMRefCell<HashMap<Atom, Vec<JS<Element>>>>,
tag_map: DOMRefCell<HashMap<Atom, JS<HTMLCollection>>>,
tag_map: DOMRefCell<HashMap<LocalName, JS<HTMLCollection>>>,
tagns_map: DOMRefCell<HashMap<QualName, JS<HTMLCollection>>>,
classes_map: DOMRefCell<HashMap<Vec<Atom>, JS<HTMLCollection>>>,
images: MutNullableHeap<JS<HTMLCollection>>,
@ -288,7 +289,7 @@ struct LinksFilter;
impl CollectionFilter for LinksFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool {
(elem.is::<HTMLAnchorElement>() || elem.is::<HTMLAreaElement>()) &&
elem.has_attribute(&atom!("href"))
elem.has_attribute(&local_name!("href"))
}
}
@ -312,7 +313,7 @@ impl CollectionFilter for ScriptsFilter {
struct AnchorsFilter;
impl CollectionFilter for AnchorsFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool {
elem.is::<HTMLAnchorElement>() && elem.has_attribute(&atom!("href"))
elem.is::<HTMLAnchorElement>() && elem.has_attribute(&local_name!("href"))
}
}
@ -428,7 +429,7 @@ impl Document {
let base = self.upcast::<Node>()
.traverse_preorder()
.filter_map(Root::downcast::<HTMLBaseElement>)
.find(|element| element.upcast::<Element>().has_attribute(&atom!("href")));
.find(|element| element.upcast::<Element>().has_attribute(&local_name!("href")));
self.base_element.set(base.r());
}
@ -577,7 +578,7 @@ impl Document {
fn get_anchor_by_name(&self, name: &str) -> Option<Root<Element>> {
let check_anchor = |node: &HTMLAnchorElement| {
let elem = node.upcast::<Element>();
elem.get_attribute(&ns!(), &atom!("name"))
elem.get_attribute(&ns!(), &local_name!("name"))
.map_or(false, |attr| &**attr.value() == name)
};
let doc_node = self.upcast::<Node>();
@ -1322,7 +1323,7 @@ impl Document {
}
}
pub fn get_body_attribute(&self, local_name: &Atom) -> DOMString {
pub fn get_body_attribute(&self, local_name: &LocalName) -> DOMString {
match self.GetBody().and_then(Root::downcast::<HTMLBodyElement>) {
Some(ref body) => {
body.upcast::<Element>().get_string_attribute(local_name)
@ -1331,7 +1332,7 @@ impl Document {
}
}
pub fn set_body_attribute(&self, local_name: &Atom, value: DOMString) {
pub fn set_body_attribute(&self, local_name: &LocalName, value: DOMString) {
if let Some(ref body) = self.GetBody().and_then(Root::downcast::<HTMLBodyElement>) {
let body = body.upcast::<Element>();
let value = body.parse_attribute(&ns!(), &local_name, value);
@ -2175,13 +2176,13 @@ impl DocumentMethods for Document {
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagname
fn GetElementsByTagName(&self, tag_name: DOMString) -> Root<HTMLCollection> {
let tag_atom = Atom::from(&*tag_name);
let tag_atom = LocalName::from(&*tag_name);
match self.tag_map.borrow_mut().entry(tag_atom.clone()) {
Occupied(entry) => Root::from_ref(entry.get()),
Vacant(entry) => {
let mut tag_copy = tag_name;
tag_copy.make_ascii_lowercase();
let ascii_lower_tag = Atom::from(tag_copy);
let ascii_lower_tag = LocalName::from(tag_copy);
let result = HTMLCollection::by_atomic_tag_name(&self.window,
self.upcast(),
tag_atom,
@ -2198,7 +2199,7 @@ impl DocumentMethods for Document {
tag_name: DOMString)
-> Root<HTMLCollection> {
let ns = namespace_from_domstring(maybe_ns);
let local = Atom::from(tag_name);
let local = LocalName::from(tag_name);
let qname = QualName::new(ns, local);
match self.tagns_map.borrow_mut().entry(qname.clone()) {
Occupied(entry) => Root::from_ref(entry.get()),
@ -2241,7 +2242,7 @@ impl DocumentMethods for Document {
if self.is_html_document {
local_name.make_ascii_lowercase();
}
let name = QualName::new(ns!(html), Atom::from(local_name));
let name = QualName::new(ns!(html), LocalName::from(local_name));
Ok(Element::create(name, None, self, ElementCreator::ScriptCreated))
}
@ -2265,7 +2266,7 @@ impl DocumentMethods for Document {
if self.is_html_document {
local_name.make_ascii_lowercase();
}
let name = Atom::from(local_name);
let name = LocalName::from(local_name);
let value = AttrValue::String("".to_owned());
Ok(Attr::new(&self.window, name.clone(), value, name, ns!(), None, None))
@ -2279,7 +2280,7 @@ impl DocumentMethods for Document {
let (namespace, prefix, local_name) = try!(validate_and_extract(namespace,
&qualified_name));
let value = AttrValue::String("".to_owned());
let qualified_name = Atom::from(qualified_name);
let qualified_name = LocalName::from(qualified_name);
Ok(Attr::new(&self.window,
local_name,
value,
@ -2465,12 +2466,12 @@ impl DocumentMethods for Document {
// https://html.spec.whatwg.org/multipage/#document.title
fn Title(&self) -> DOMString {
let title = self.GetDocumentElement().and_then(|root| {
if root.namespace() == &ns!(svg) && root.local_name() == &atom!("svg") {
if root.namespace() == &ns!(svg) && root.local_name() == &local_name!("svg") {
// Step 1.
root.upcast::<Node>()
.child_elements()
.find(|node| {
node.namespace() == &ns!(svg) && node.local_name() == &atom!("title")
node.namespace() == &ns!(svg) && node.local_name() == &local_name!("title")
})
.map(Root::upcast::<Node>)
} else {
@ -2498,14 +2499,14 @@ impl DocumentMethods for Document {
None => return,
};
let elem = if root.namespace() == &ns!(svg) && root.local_name() == &atom!("svg") {
let elem = if root.namespace() == &ns!(svg) && root.local_name() == &local_name!("svg") {
let elem = root.upcast::<Node>().child_elements().find(|node| {
node.namespace() == &ns!(svg) && node.local_name() == &atom!("title")
node.namespace() == &ns!(svg) && node.local_name() == &local_name!("title")
});
match elem {
Some(elem) => Root::upcast::<Node>(elem),
None => {
let name = QualName::new(ns!(svg), atom!("title"));
let name = QualName::new(ns!(svg), local_name!("title"));
let elem = Element::create(name, None, self, ElementCreator::ScriptCreated);
let parent = root.upcast::<Node>();
let child = elem.upcast::<Node>();
@ -2522,7 +2523,7 @@ impl DocumentMethods for Document {
None => {
match self.GetHead() {
Some(head) => {
let name = QualName::new(ns!(html), atom!("title"));
let name = QualName::new(ns!(html), local_name!("title"));
let elem = Element::create(name,
None,
self,
@ -2617,7 +2618,7 @@ impl DocumentMethods for Document {
if element.namespace() != &ns!(html) {
return false;
}
element.get_attribute(&ns!(), &atom!("name"))
element.get_attribute(&ns!(), &local_name!("name"))
.map_or(false, |attr| &**attr.value() == &*name)
})
}
@ -2785,22 +2786,22 @@ impl DocumentMethods for Document {
// https://html.spec.whatwg.org/multipage/#dom-document-bgcolor
fn BgColor(&self) -> DOMString {
self.get_body_attribute(&atom!("bgcolor"))
self.get_body_attribute(&local_name!("bgcolor"))
}
// https://html.spec.whatwg.org/multipage/#dom-document-bgcolor
fn SetBgColor(&self, value: DOMString) {
self.set_body_attribute(&atom!("bgcolor"), value)
self.set_body_attribute(&local_name!("bgcolor"), value)
}
// https://html.spec.whatwg.org/multipage/#dom-document-fgcolor
fn FgColor(&self) -> DOMString {
self.get_body_attribute(&atom!("text"))
self.get_body_attribute(&local_name!("text"))
}
// https://html.spec.whatwg.org/multipage/#dom-document-fgcolor
fn SetFgColor(&self, value: DOMString) {
self.set_body_attribute(&atom!("text"), value)
self.set_body_attribute(&local_name!("text"), value)
}
#[allow(unsafe_code)]
@ -2827,10 +2828,10 @@ impl DocumentMethods for Document {
};
match html_elem_type {
HTMLElementTypeId::HTMLAppletElement => {
match elem.get_attribute(&ns!(), &atom!("name")) {
match elem.get_attribute(&ns!(), &local_name!("name")) {
Some(ref attr) if attr.value().as_atom() == name => true,
_ => {
match elem.get_attribute(&ns!(), &atom!("id")) {
match elem.get_attribute(&ns!(), &local_name!("id")) {
Some(ref attr) => attr.value().as_atom() == name,
None => false,
}
@ -2838,18 +2839,18 @@ impl DocumentMethods for Document {
}
},
HTMLElementTypeId::HTMLFormElement => {
match elem.get_attribute(&ns!(), &atom!("name")) {
match elem.get_attribute(&ns!(), &local_name!("name")) {
Some(ref attr) => attr.value().as_atom() == name,
None => false,
}
},
HTMLElementTypeId::HTMLImageElement => {
match elem.get_attribute(&ns!(), &atom!("name")) {
match elem.get_attribute(&ns!(), &local_name!("name")) {
Some(ref attr) => {
if attr.value().as_atom() == name {
true
} else {
match elem.get_attribute(&ns!(), &atom!("id")) {
match elem.get_attribute(&ns!(), &local_name!("id")) {
Some(ref attr) => attr.value().as_atom() == name,
None => false,
}

View file

@ -16,7 +16,7 @@ use dom::globalscope::GlobalScope;
use dom::htmlcollection::HTMLCollection;
use dom::node::{Node, window_from_node};
use dom::nodelist::NodeList;
use string_cache::Atom;
use servo_atoms::Atom;
// https://dom.spec.whatwg.org/#documentfragment
#[dom_struct]
@ -57,7 +57,7 @@ impl DocumentFragmentMethods for DocumentFragment {
let node = self.upcast::<Node>();
let id = Atom::from(id);
node.traverse_preorder().filter_map(Root::downcast::<Element>).find(|descendant| {
match descendant.get_attribute(&ns!(), &atom!("id")) {
match descendant.get_attribute(&ns!(), &local_name!("id")) {
None => false,
Some(attr) => *attr.value().as_atom() == id,
}

View file

@ -142,14 +142,14 @@ impl DOMImplementationMethods for DOMImplementation {
{
// Step 4.
let doc_node = doc.upcast::<Node>();
let doc_html = Root::upcast::<Node>(HTMLHtmlElement::new(atom!("html"),
let doc_html = Root::upcast::<Node>(HTMLHtmlElement::new(local_name!("html"),
None,
&doc));
doc_node.AppendChild(&doc_html).expect("Appending failed");
{
// Step 5.
let doc_head = Root::upcast::<Node>(HTMLHeadElement::new(atom!("head"),
let doc_head = Root::upcast::<Node>(HTMLHeadElement::new(local_name!("head"),
None,
&doc));
doc_html.AppendChild(&doc_head).unwrap();
@ -160,7 +160,7 @@ impl DOMImplementationMethods for DOMImplementation {
Some(title_str) => {
// Step 6.1.
let doc_title =
Root::upcast::<Node>(HTMLTitleElement::new(atom!("title"),
Root::upcast::<Node>(HTMLTitleElement::new(local_name!("title"),
None,
&doc));
doc_head.AppendChild(&doc_title).unwrap();
@ -173,7 +173,7 @@ impl DOMImplementationMethods for DOMImplementation {
}
// Step 7.
let doc_body = HTMLBodyElement::new(atom!("body"), None, &doc);
let doc_body = HTMLBodyElement::new(local_name!("body"), None, &doc);
doc_html.AppendChild(doc_body.upcast()).unwrap();
}

View file

@ -11,18 +11,19 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::str::DOMString;
use dom::element::Element;
use dom::node::window_from_node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use servo_atoms::Atom;
use style::str::HTML_SPACE_CHARACTERS;
#[dom_struct]
pub struct DOMTokenList {
reflector_: Reflector,
element: JS<Element>,
local_name: Atom,
local_name: LocalName,
}
impl DOMTokenList {
pub fn new_inherited(element: &Element, local_name: Atom) -> DOMTokenList {
pub fn new_inherited(element: &Element, local_name: LocalName) -> DOMTokenList {
DOMTokenList {
reflector_: Reflector::new(),
element: JS::from_ref(element),
@ -30,7 +31,7 @@ impl DOMTokenList {
}
}
pub fn new(element: &Element, local_name: &Atom) -> Root<DOMTokenList> {
pub fn new(element: &Element, local_name: &LocalName) -> Root<DOMTokenList> {
let window = window_from_node(element);
reflect_dom_object(box DOMTokenList::new_inherited(element, local_name.clone()),
&*window,

View file

@ -69,10 +69,12 @@ use html5ever::serialize::SerializeOpts;
use html5ever::serialize::TraversalScope;
use html5ever::serialize::TraversalScope::{ChildrenOnly, IncludeNode};
use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks};
use html5ever_atoms::{Prefix, LocalName, Namespace, QualName};
use parking_lot::RwLock;
use selectors::matching::{ElementFlags, MatchingReason, matches};
use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS};
use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str};
use servo_atoms::Atom;
use std::ascii::AsciiExt;
use std::borrow::Cow;
use std::cell::{Cell, Ref};
@ -81,7 +83,6 @@ use std::default::Default;
use std::fmt;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use string_cache::{Atom, Namespace, QualName};
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use style::element_state::*;
use style::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
@ -102,7 +103,7 @@ use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage};
#[dom_struct]
pub struct Element {
node: Node,
local_name: Atom,
local_name: LocalName,
tag_name: TagName,
namespace: Namespace,
prefix: Option<DOMString>,
@ -157,20 +158,20 @@ impl<'a> TryFrom<&'a str> for AdjacentPosition {
// Element methods
//
impl Element {
pub fn create(name: QualName, prefix: Option<Atom>,
pub fn create(name: QualName, prefix: Option<Prefix>,
document: &Document, creator: ElementCreator)
-> Root<Element> {
create_element(name, prefix, document, creator)
}
pub fn new_inherited(local_name: Atom,
pub fn new_inherited(local_name: LocalName,
namespace: Namespace, prefix: Option<DOMString>,
document: &Document) -> Element {
Element::new_inherited_with_state(ElementState::empty(), local_name,
namespace, prefix, document)
}
pub fn new_inherited_with_state(state: ElementState, local_name: Atom,
pub fn new_inherited_with_state(state: ElementState, local_name: LocalName,
namespace: Namespace, prefix: Option<DOMString>,
document: &Document)
-> Element {
@ -190,7 +191,7 @@ impl Element {
}
}
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
namespace: Namespace,
prefix: Option<DOMString>,
document: &Document) -> Root<Element> {
@ -232,16 +233,16 @@ impl Element {
#[allow(unsafe_code)]
pub trait RawLayoutElementHelpers {
unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &LocalName)
-> Option<&'a AttrValue>;
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &LocalName)
-> Option<&'a str>;
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &Atom) -> Vec<&'a str>;
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &LocalName) -> Vec<&'a str>;
}
#[inline]
#[allow(unsafe_code)]
pub unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, name: &Atom)
pub unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, name: &LocalName)
-> Option<LayoutJS<Attr>> {
// cast to point to T in RefCell<T> directly
let attrs = elem.attrs.borrow_for_layout();
@ -255,14 +256,14 @@ pub unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace,
#[allow(unsafe_code)]
impl RawLayoutElementHelpers for Element {
#[inline]
unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &LocalName)
-> Option<&'a AttrValue> {
get_attr_for_layout(self, namespace, name).map(|attr| {
attr.value_forever()
})
}
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &LocalName)
-> Option<&'a str> {
get_attr_for_layout(self, namespace, name).map(|attr| {
attr.value_ref_forever()
@ -270,7 +271,7 @@ impl RawLayoutElementHelpers for Element {
}
#[inline]
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &Atom) -> Vec<&'a str> {
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &LocalName) -> Vec<&'a str> {
let attrs = self.attrs.borrow_for_layout();
attrs.iter().filter_map(|attr| {
let attr = attr.to_layout();
@ -298,7 +299,7 @@ pub trait LayoutElementHelpers {
unsafe fn html_element_in_html_document_for_layout(&self) -> bool;
fn id_attribute(&self) -> *const Option<Atom>;
fn style_attribute(&self) -> *const Option<Arc<RwLock<PropertyDeclarationBlock>>>;
fn local_name(&self) -> &Atom;
fn local_name(&self) -> &LocalName;
fn namespace(&self) -> &Namespace;
fn get_checked_state_for_layout(&self) -> bool;
fn get_indeterminate_state_for_layout(&self) -> bool;
@ -310,7 +311,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
#[allow(unsafe_code)]
#[inline]
unsafe fn has_class_for_layout(&self, name: &Atom) -> bool {
get_attr_for_layout(&*self.unsafe_get(), &ns!(), &atom!("class")).map_or(false, |attr| {
get_attr_for_layout(&*self.unsafe_get(), &ns!(), &local_name!("class")).map_or(false, |attr| {
attr.value_tokens_forever().unwrap().iter().any(|atom| atom == name)
})
}
@ -318,7 +319,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
#[allow(unsafe_code)]
#[inline]
unsafe fn get_classes_for_layout(&self) -> Option<&'static [Atom]> {
get_attr_for_layout(&*self.unsafe_get(), &ns!(), &atom!("class"))
get_attr_for_layout(&*self.unsafe_get(), &ns!(), &local_name!("class"))
.map(|attr| attr.value_tokens_forever().unwrap())
}
@ -440,7 +441,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
let size = if let Some(this) = self.downcast::<HTMLInputElement>() {
// FIXME(pcwalton): More use of atoms, please!
match (*self.unsafe_get()).get_attr_val_for_layout(&ns!(), &atom!("type")) {
match (*self.unsafe_get()).get_attr_val_for_layout(&ns!(), &local_name!("type")) {
// Not text entry widget
Some("hidden") | Some("date") | Some("month") | Some("week") |
Some("time") | Some("datetime-local") | Some("number") | Some("range") |
@ -622,7 +623,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
}
#[allow(unsafe_code)]
fn local_name(&self) -> &Atom {
fn local_name(&self) -> &LocalName {
unsafe {
&(*self.unsafe_get()).local_name
}
@ -681,15 +682,15 @@ impl Element {
self.namespace == ns!(html) && self.upcast::<Node>().is_in_html_doc()
}
pub fn local_name(&self) -> &Atom {
pub fn local_name(&self) -> &LocalName {
&self.local_name
}
pub fn parsed_name(&self, mut name: DOMString) -> Atom {
pub fn parsed_name(&self, mut name: DOMString) -> LocalName {
if self.html_element_in_html_document() {
name.make_ascii_lowercase();
}
Atom::from(name)
LocalName::from(name)
}
pub fn namespace(&self) -> &Namespace {
@ -722,10 +723,14 @@ impl Element {
/* List of void elements from
https://html.spec.whatwg.org/multipage/#html-fragment-serialisation-algorithm */
atom!("area") | atom!("base") | atom!("basefont") | atom!("bgsound") | atom!("br") |
atom!("col") | atom!("embed") | atom!("frame") | atom!("hr") | atom!("img") |
atom!("input") | atom!("keygen") | atom!("link") | atom!("menuitem") | atom!("meta") |
atom!("param") | atom!("source") | atom!("track") | atom!("wbr") => true,
local_name!("area") | local_name!("base") | local_name!("basefont") |
local_name!("bgsound") | local_name!("br") |
local_name!("col") | local_name!("embed") | local_name!("frame") |
local_name!("hr") | local_name!("img") |
local_name!("input") | local_name!("keygen") | local_name!("link") |
local_name!("menuitem") | local_name!("meta") |
local_name!("param") | local_name!("source") | local_name!("track") |
local_name!("wbr") => true,
_ => false
}
}
@ -735,7 +740,7 @@ impl Element {
pub fn set_style_attr(&self, new_value: String) {
let mut new_style = AttrValue::String(new_value);
if let Some(style_attr) = self.attrs.borrow().iter().find(|a| a.name() == &atom!("style")) {
if let Some(style_attr) = self.attrs.borrow().iter().find(|a| a.name() == &local_name!("style")) {
style_attr.swap_value(&mut new_style);
return;
}
@ -744,11 +749,11 @@ impl Element {
// in order to avoid triggering mutation events
let window = window_from_node(self);
let attr = Attr::new(&window,
atom!("style"),
local_name!("style"),
new_style,
atom!("style"),
local_name!("style"),
ns!(),
Some(atom!("style")),
None,
Some(self));
assert!(attr.GetOwnerElement().r() == Some(self));
@ -798,8 +803,8 @@ impl Element {
// Step 2.
for attr in element.attrs.borrow().iter() {
if *attr.prefix() == Some(atom!("xmlns")) &&
**attr.value() == *namespace.0 {
if *attr.prefix() == Some(namespace_prefix!("xmlns")) &&
**attr.value() == *namespace {
return Some(attr.LocalName());
}
}
@ -856,11 +861,11 @@ impl Element {
impl Element {
pub fn push_new_attribute(&self,
local_name: Atom,
local_name: LocalName,
value: AttrValue,
name: Atom,
name: LocalName,
namespace: Namespace,
prefix: Option<Atom>) {
prefix: Option<Prefix>) {
let window = window_from_node(self);
let attr = Attr::new(&window,
local_name,
@ -881,7 +886,7 @@ impl Element {
}
}
pub fn get_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
pub fn get_attribute(&self, namespace: &Namespace, local_name: &LocalName) -> Option<Root<Attr>> {
self.attrs
.borrow()
.iter()
@ -898,7 +903,7 @@ impl Element {
pub fn set_attribute_from_parser(&self,
qname: QualName,
value: DOMString,
prefix: Option<Atom>) {
prefix: Option<Prefix>) {
// Don't set if the attribute already exists, so we can handle add_attrs_if_missing
if self.attrs
.borrow()
@ -911,14 +916,14 @@ impl Element {
None => qname.local.clone(),
Some(ref prefix) => {
let name = format!("{}:{}", &**prefix, &*qname.local);
Atom::from(name)
LocalName::from(name)
},
};
let value = self.parse_attribute(&qname.ns, &qname.local, value);
self.push_new_attribute(qname.local, value, name, qname.ns, prefix);
}
pub fn set_attribute(&self, name: &Atom, value: AttrValue) {
pub fn set_attribute(&self, name: &LocalName, value: AttrValue) {
assert!(name == &name.to_ascii_lowercase());
assert!(!name.contains(":"));
@ -938,7 +943,7 @@ impl Element {
}
// Steps 2-5.
let name = Atom::from(name);
let name = LocalName::from(name);
let value = self.parse_attribute(&ns!(), &name, value);
self.set_first_matching_attribute(name.clone(),
value,
@ -952,11 +957,11 @@ impl Element {
}
fn set_first_matching_attribute<F>(&self,
local_name: Atom,
local_name: LocalName,
value: AttrValue,
name: Atom,
name: LocalName,
namespace: Namespace,
prefix: Option<Atom>,
prefix: Option<Prefix>,
find: F)
where F: Fn(&Attr) -> bool
{
@ -974,7 +979,7 @@ impl Element {
pub fn parse_attribute(&self,
namespace: &Namespace,
local_name: &Atom,
local_name: &LocalName,
value: DOMString)
-> AttrValue {
if *namespace == ns!() {
@ -984,13 +989,13 @@ impl Element {
}
}
pub fn remove_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
pub fn remove_attribute(&self, namespace: &Namespace, local_name: &LocalName) -> Option<Root<Attr>> {
self.remove_first_matching_attribute(|attr| {
attr.namespace() == namespace && attr.local_name() == local_name
})
}
pub fn remove_attribute_by_name(&self, name: &Atom) -> Option<Root<Attr>> {
pub fn remove_attribute_by_name(&self, name: &LocalName) -> Option<Root<Attr>> {
self.remove_first_matching_attribute(|attr| attr.name() == name)
}
@ -1019,17 +1024,17 @@ impl Element {
Quirks => lhs.eq_ignore_ascii_case(&rhs),
}
};
self.get_attribute(&ns!(), &atom!("class"))
self.get_attribute(&ns!(), &local_name!("class"))
.map_or(false, |attr| attr.value().as_tokens().iter().any(|atom| is_equal(name, atom)))
}
pub fn set_atomic_attribute(&self, local_name: &Atom, value: DOMString) {
pub fn set_atomic_attribute(&self, local_name: &LocalName, value: DOMString) {
assert!(*local_name == local_name.to_ascii_lowercase());
let value = AttrValue::from_atomic(value.into());
self.set_attribute(local_name, value);
}
pub fn has_attribute(&self, local_name: &Atom) -> bool {
pub fn has_attribute(&self, local_name: &LocalName) -> bool {
assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b));
self.attrs
.borrow()
@ -1037,7 +1042,7 @@ impl Element {
.any(|attr| attr.local_name() == local_name && attr.namespace() == &ns!())
}
pub fn set_bool_attribute(&self, local_name: &Atom, value: bool) {
pub fn set_bool_attribute(&self, local_name: &LocalName, value: bool) {
if self.has_attribute(local_name) == value {
return;
}
@ -1048,7 +1053,7 @@ impl Element {
}
}
pub fn get_url_attribute(&self, local_name: &Atom) -> DOMString {
pub fn get_url_attribute(&self, local_name: &LocalName) -> DOMString {
assert!(*local_name == local_name.to_ascii_lowercase());
if !self.has_attribute(local_name) {
return DOMString::new();
@ -1063,22 +1068,22 @@ impl Element {
Err(_) => DOMString::from(""),
}
}
pub fn set_url_attribute(&self, local_name: &Atom, value: DOMString) {
pub fn set_url_attribute(&self, local_name: &LocalName, value: DOMString) {
self.set_string_attribute(local_name, value);
}
pub fn get_string_attribute(&self, local_name: &Atom) -> DOMString {
pub fn get_string_attribute(&self, local_name: &LocalName) -> DOMString {
match self.get_attribute(&ns!(), local_name) {
Some(x) => x.Value(),
None => DOMString::new(),
}
}
pub fn set_string_attribute(&self, local_name: &Atom, value: DOMString) {
pub fn set_string_attribute(&self, local_name: &LocalName, value: DOMString) {
assert!(*local_name == local_name.to_ascii_lowercase());
self.set_attribute(local_name, AttrValue::String(value.into()));
}
pub fn get_tokenlist_attribute(&self, local_name: &Atom) -> Vec<Atom> {
pub fn get_tokenlist_attribute(&self, local_name: &LocalName) -> Vec<Atom> {
self.get_attribute(&ns!(), local_name).map(|attr| {
attr.value()
.as_tokens()
@ -1086,18 +1091,18 @@ impl Element {
}).unwrap_or(vec!())
}
pub fn set_tokenlist_attribute(&self, local_name: &Atom, value: DOMString) {
pub fn set_tokenlist_attribute(&self, local_name: &LocalName, value: DOMString) {
assert!(*local_name == local_name.to_ascii_lowercase());
self.set_attribute(local_name,
AttrValue::from_serialized_tokenlist(value.into()));
}
pub fn set_atomic_tokenlist_attribute(&self, local_name: &Atom, tokens: Vec<Atom>) {
pub fn set_atomic_tokenlist_attribute(&self, local_name: &LocalName, tokens: Vec<Atom>) {
assert!(*local_name == local_name.to_ascii_lowercase());
self.set_attribute(local_name, AttrValue::from_atomic_tokens(tokens));
}
pub fn get_int_attribute(&self, local_name: &Atom, default: i32) -> i32 {
pub fn get_int_attribute(&self, local_name: &LocalName, default: i32) -> i32 {
// TODO: Is this assert necessary?
assert!(local_name.chars().all(|ch| {
!ch.is_ascii() || ch.to_ascii_lowercase() == ch
@ -1116,12 +1121,12 @@ impl Element {
}
}
pub fn set_int_attribute(&self, local_name: &Atom, value: i32) {
pub fn set_int_attribute(&self, local_name: &LocalName, value: i32) {
assert!(*local_name == local_name.to_ascii_lowercase());
self.set_attribute(local_name, AttrValue::Int(value.to_string(), value));
}
pub fn get_uint_attribute(&self, local_name: &Atom, default: u32) -> u32 {
pub fn get_uint_attribute(&self, local_name: &LocalName, default: u32) -> u32 {
assert!(local_name.chars().all(|ch| !ch.is_ascii() || ch.to_ascii_lowercase() == ch));
let attribute = self.get_attribute(&ns!(), local_name);
match attribute {
@ -1134,7 +1139,7 @@ impl Element {
None => default,
}
}
pub fn set_uint_attribute(&self, local_name: &Atom, value: u32) {
pub fn set_uint_attribute(&self, local_name: &LocalName, value: u32) {
assert!(*local_name == local_name.to_ascii_lowercase());
self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value));
}
@ -1226,7 +1231,7 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-localname
fn LocalName(&self) -> DOMString {
// FIXME(ajeffrey): Convert directly from Atom to DOMString
// FIXME(ajeffrey): Convert directly from LocalName to DOMString
DOMString::from(&*self.local_name)
}
@ -1245,9 +1250,9 @@ impl ElementMethods for Element {
None => Cow::Borrowed(&*self.local_name)
};
if self.html_element_in_html_document() {
Atom::from(qualified_name.to_ascii_uppercase())
LocalName::from(qualified_name.to_ascii_uppercase())
} else {
Atom::from(qualified_name)
LocalName::from(qualified_name)
}
});
DOMString::from(&*name)
@ -1255,27 +1260,27 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-id
fn Id(&self) -> DOMString {
self.get_string_attribute(&atom!("id"))
self.get_string_attribute(&local_name!("id"))
}
// https://dom.spec.whatwg.org/#dom-element-id
fn SetId(&self, id: DOMString) {
self.set_atomic_attribute(&atom!("id"), id);
self.set_atomic_attribute(&local_name!("id"), id);
}
// https://dom.spec.whatwg.org/#dom-element-classname
fn ClassName(&self) -> DOMString {
self.get_string_attribute(&atom!("class"))
self.get_string_attribute(&local_name!("class"))
}
// https://dom.spec.whatwg.org/#dom-element-classname
fn SetClassName(&self, class: DOMString) {
self.set_tokenlist_attribute(&atom!("class"), class);
self.set_tokenlist_attribute(&local_name!("class"), class);
}
// https://dom.spec.whatwg.org/#dom-element-classlist
fn ClassList(&self) -> Root<DOMTokenList> {
self.class_list.or_init(|| DOMTokenList::new(self, &atom!("class")))
self.class_list.or_init(|| DOMTokenList::new(self, &local_name!("class")))
}
// https://dom.spec.whatwg.org/#dom-element-attributes
@ -1319,7 +1324,7 @@ impl ElementMethods for Element {
local_name: DOMString)
-> Option<Root<Attr>> {
let namespace = &namespace_from_domstring(namespace);
self.get_attribute(namespace, &Atom::from(local_name))
self.get_attribute(namespace, &LocalName::from(local_name))
}
// https://dom.spec.whatwg.org/#dom-element-setattribute
@ -1347,7 +1352,7 @@ impl ElementMethods for Element {
value: DOMString) -> ErrorResult {
let (namespace, prefix, local_name) =
try!(validate_and_extract(namespace, &qualified_name));
let qualified_name = Atom::from(qualified_name);
let qualified_name = LocalName::from(qualified_name);
let value = self.parse_attribute(&namespace, &local_name, value);
self.set_first_matching_attribute(
local_name.clone(), value, qualified_name, namespace.clone(), prefix,
@ -1413,7 +1418,7 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-removeattributens
fn RemoveAttributeNS(&self, namespace: Option<DOMString>, local_name: DOMString) {
let namespace = namespace_from_domstring(namespace);
let local_name = Atom::from(local_name);
let local_name = LocalName::from(local_name);
self.remove_attribute(&namespace, &local_name);
}
@ -1781,7 +1786,7 @@ impl ElementMethods for Element {
// Step 4.
NodeTypeId::DocumentFragment => {
let body_elem = Element::create(QualName::new(ns!(html), atom!("body")),
let body_elem = Element::create(QualName::new(ns!(html), local_name!("body")),
None, &context_document,
ElementCreator::ScriptCreated);
Root::upcast(body_elem)
@ -1944,9 +1949,9 @@ impl ElementMethods for Element {
// Step 2.
let context = match context.downcast::<Element>() {
Some(elem) if elem.local_name() != &atom!("html") ||
Some(elem) if elem.local_name() != &local_name!("html") ||
!elem.html_element_in_html_document() => Root::from_ref(elem),
_ => Root::upcast(HTMLBodyElement::new(atom!("body"), None, &*context.owner_doc())),
_ => Root::upcast(HTMLBodyElement::new(local_name!("body"), None, &*context.owner_doc())),
};
// Step 3.
@ -1978,8 +1983,8 @@ impl ElementMethods for Element {
}
}
pub fn fragment_affecting_attributes() -> [Atom; 3] {
[atom!("width"), atom!("height"), atom!("src")]
pub fn fragment_affecting_attributes() -> [LocalName; 3] {
[local_name!("width"), local_name!("height"), local_name!("src")]
}
impl VirtualMethods for Element {
@ -1992,7 +1997,7 @@ impl VirtualMethods for Element {
let node = self.upcast::<Node>();
let doc = node.owner_doc();
match attr.local_name() {
&atom!("style") => {
&local_name!("style") => {
// Modifying the `style` attribute might change style.
*self.style_attribute.borrow_mut() =
mutation.new_value(attr).map(|value| {
@ -2007,7 +2012,7 @@ impl VirtualMethods for Element {
node.dirty(NodeDamage::NodeStyleDamaged);
}
},
&atom!("id") => {
&local_name!("id") => {
*self.id_attribute.borrow_mut() =
mutation.new_value(attr).and_then(|value| {
let value = value.as_atom();
@ -2039,7 +2044,7 @@ impl VirtualMethods for Element {
},
_ if attr.namespace() == &ns!() => {
if fragment_affecting_attributes().iter().any(|a| a == attr.local_name()) ||
common_style_affecting_attributes().iter().any(|a| &a.atom == attr.local_name()) ||
common_style_affecting_attributes().iter().any(|a| &a.attr_name == attr.local_name()) ||
rare_style_affecting_attributes().iter().any(|a| a == attr.local_name())
{
node.dirty(NodeDamage::OtherNodeDamage);
@ -2054,10 +2059,10 @@ impl VirtualMethods for Element {
node.rev_version();
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("id") => AttrValue::from_atomic(value.into()),
&atom!("class") => AttrValue::from_serialized_tokenlist(value.into()),
&local_name!("id") => AttrValue::from_atomic(value.into()),
&local_name!("class") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
@ -2191,7 +2196,7 @@ impl<'a> ::selectors::Element for Root<Element> {
})
}
fn get_local_name(&self) -> &Atom {
fn get_local_name(&self) -> &LocalName {
self.local_name()
}
@ -2246,7 +2251,7 @@ impl<'a> ::selectors::Element for Root<Element> {
fn each_class<F>(&self, mut callback: F)
where F: FnMut(&Atom)
{
if let Some(ref attr) = self.get_attribute(&ns!(), &atom!("class")) {
if let Some(ref attr) = self.get_attribute(&ns!(), &local_name!("class")) {
let tokens = attr.value();
let tokens = tokens.as_tokens();
for token in tokens {
@ -2357,7 +2362,7 @@ impl Element {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
self.has_attribute(&atom!("href"))
self.has_attribute(&local_name!("href"))
},
_ => false,
}
@ -2551,7 +2556,7 @@ impl Element {
}
pub fn check_disabled_attribute(&self) {
let has_disabled_attrib = self.has_attribute(&atom!("disabled"));
let has_disabled_attrib = self.has_attribute(&local_name!("disabled"));
self.set_disabled_state(has_disabled_attrib);
self.set_enabled_state(!has_disabled_attrib);
}
@ -2600,7 +2605,7 @@ impl AtomicElementFlags {
/// owner changes.
#[derive(JSTraceable, HeapSizeOf)]
struct TagName {
ptr: DOMRefCell<Option<Atom>>,
ptr: DOMRefCell<Option<LocalName>>,
}
impl TagName {
@ -2610,8 +2615,8 @@ impl TagName {
/// Retrieve a copy of the current inner value. If it is `None`, it is
/// initialized with the result of `cb` first.
fn or_init<F>(&self, cb: F) -> Atom
where F: FnOnce() -> Atom
fn or_init<F>(&self, cb: F) -> LocalName
where F: FnOnce() -> LocalName
{
match &mut *self.ptr.borrow_mut() {
&mut Some(ref name) => name.clone(),

View file

@ -15,8 +15,8 @@ use dom::event::{Event, EventBubbles, EventCancelable};
use dom::globalscope::GlobalScope;
use js::jsapi::{HandleValue, JSContext};
use js::jsval::JSVal;
use servo_atoms::Atom;
use std::cell::Cell;
use string_cache::Atom;
#[dom_struct]
pub struct ErrorEvent {

View file

@ -14,9 +14,9 @@ use dom::eventdispatcher::EventStatus;
use dom::eventtarget::EventTarget;
use dom::globalscope::GlobalScope;
use script_thread::Runnable;
use servo_atoms::Atom;
use std::cell::Cell;
use std::default::Default;
use string_cache::Atom;
use time;
#[derive(JSTraceable, Copy, Clone, Debug, PartialEq, Eq)]

View file

@ -32,6 +32,7 @@ use heapsize::HeapSizeOf;
use js::jsapi::{CompileFunction, JS_GetFunctionObject, JSAutoCompartment};
use js::rust::{AutoObjectVectorWrapper, CompileOptionsWrapper};
use libc::{c_char, size_t};
use servo_atoms::Atom;
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::default::Default;
@ -41,7 +42,6 @@ use std::mem;
use std::ops::{Deref, DerefMut};
use std::ptr;
use std::rc::Rc;
use string_cache::Atom;
use url::Url;
#[derive(PartialEq, Clone, JSTraceable)]

View file

@ -12,7 +12,7 @@ use dom::bindings::str::DOMString;
use dom::event::Event;
use dom::globalscope::GlobalScope;
use js::jsapi::{HandleValue, JSContext};
use string_cache::Atom;
use servo_atoms::Atom;
// https://w3c.github.io/ServiceWorker/#extendable-event
#[dom_struct]

View file

@ -15,8 +15,8 @@ use dom::extendableevent::ExtendableEvent;
use dom::globalscope::GlobalScope;
use js::jsapi::{HandleValue, Heap, JSContext};
use js::jsval::JSVal;
use servo_atoms::Atom;
use std::default::Default;
use string_cache::Atom;
#[dom_struct]
pub struct ExtendableMessageEvent {

View file

@ -30,10 +30,10 @@ use js::jsval::{self, JSVal};
use js::typedarray::Uint8Array;
use rustc_serialize::base64::{CharacterSet, Config, Newline, ToBase64};
use script_thread::RunnableWrapper;
use servo_atoms::Atom;
use std::cell::Cell;
use std::ptr;
use std::sync::Arc;
use string_cache::Atom;
use task_source::TaskSource;
use task_source::file_reading::{FileReadingTaskSource, FileReadingRunnable, FileReadingTask};
use util::thread::spawn_named;

View file

@ -15,24 +15,24 @@ use dom::blob::{Blob, BlobImpl};
use dom::file::File;
use dom::globalscope::GlobalScope;
use dom::htmlformelement::{HTMLFormElement, FormDatumValue, FormDatum};
use html5ever_atoms::LocalName;
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::iter;
use string_cache::Atom;
#[dom_struct]
pub struct FormData {
reflector_: Reflector,
data: DOMRefCell<HashMap<Atom, Vec<FormDatum>>>,
data: DOMRefCell<HashMap<LocalName, Vec<FormDatum>>>,
}
impl FormData {
fn new_inherited(opt_form: Option<&HTMLFormElement>) -> FormData {
let mut hashmap: HashMap<Atom, Vec<FormDatum>> = HashMap::new();
let mut hashmap: HashMap<LocalName, Vec<FormDatum>> = HashMap::new();
if let Some(form) = opt_form {
for datum in form.get_form_dataset(None) {
match hashmap.entry(Atom::from(datum.name.as_ref())) {
match hashmap.entry(LocalName::from(datum.name.as_ref())) {
Occupied(entry) => entry.into_mut().push(datum),
Vacant(entry) => { entry.insert(vec!(datum)); }
}
@ -66,7 +66,7 @@ impl FormDataMethods for FormData {
};
let mut data = self.data.borrow_mut();
match data.entry(Atom::from(name.0)) {
match data.entry(LocalName::from(name.0)) {
Occupied(entry) => entry.into_mut().push(datum),
Vacant(entry) => { entry.insert(vec!(datum)); }
}
@ -83,7 +83,7 @@ impl FormDataMethods for FormData {
let mut data = self.data.borrow_mut();
match data.entry(Atom::from(name.0)) {
match data.entry(LocalName::from(name.0)) {
Occupied(entry) => entry.into_mut().push(datum),
Vacant(entry) => { entry.insert(vec!(datum)); },
}
@ -91,13 +91,13 @@ impl FormDataMethods for FormData {
// https://xhr.spec.whatwg.org/#dom-formdata-delete
fn Delete(&self, name: USVString) {
self.data.borrow_mut().remove(&Atom::from(name.0));
self.data.borrow_mut().remove(&LocalName::from(name.0));
}
// https://xhr.spec.whatwg.org/#dom-formdata-get
fn Get(&self, name: USVString) -> Option<FileOrUSVString> {
self.data.borrow()
.get(&Atom::from(name.0))
.get(&LocalName::from(name.0))
.map(|entry| match entry[0].value {
FormDatumValue::String(ref s) => FileOrUSVString::USVString(USVString(s.to_string())),
FormDatumValue::File(ref b) => FileOrUSVString::File(Root::from_ref(&*b)),
@ -107,7 +107,7 @@ impl FormDataMethods for FormData {
// https://xhr.spec.whatwg.org/#dom-formdata-getall
fn GetAll(&self, name: USVString) -> Vec<FileOrUSVString> {
self.data.borrow()
.get(&Atom::from(name.0))
.get(&LocalName::from(name.0))
.map_or(vec![], |data|
data.iter().map(|item| match item.value {
FormDatumValue::String(ref s) => FileOrUSVString::USVString(USVString(s.to_string())),
@ -118,12 +118,12 @@ impl FormDataMethods for FormData {
// https://xhr.spec.whatwg.org/#dom-formdata-has
fn Has(&self, name: USVString) -> bool {
self.data.borrow().contains_key(&Atom::from(name.0))
self.data.borrow().contains_key(&LocalName::from(name.0))
}
// https://xhr.spec.whatwg.org/#dom-formdata-set
fn Set(&self, name: USVString, str_value: USVString) {
self.data.borrow_mut().insert(Atom::from(name.0.clone()), vec![FormDatum {
self.data.borrow_mut().insert(LocalName::from(name.0.clone()), vec![FormDatum {
ty: DOMString::from("string"),
name: DOMString::from(name.0),
value: FormDatumValue::String(DOMString::from(str_value.0)),
@ -133,7 +133,7 @@ impl FormDataMethods for FormData {
#[allow(unrooted_must_root)]
// https://xhr.spec.whatwg.org/#dom-formdata-set
fn Set_(&self, name: USVString, blob: &Blob, filename: Option<USVString>) {
self.data.borrow_mut().insert(Atom::from(name.0.clone()), vec![FormDatum {
self.data.borrow_mut().insert(LocalName::from(name.0.clone()), vec![FormDatum {
ty: DOMString::from("file"),
name: DOMString::from(name.0),
value: FormDatumValue::File(Root::from_ref(&*self.get_file(blob, filename))),

View file

@ -12,7 +12,7 @@ use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::{DOMString, USVString};
use dom::event::Event;
use dom::globalscope::GlobalScope;
use string_cache::Atom;
use servo_atoms::Atom;
// https://html.spec.whatwg.org/multipage/#hashchangeevent
#[dom_struct]

View file

@ -24,11 +24,11 @@ use dom::mouseevent::MouseEvent;
use dom::node::{Node, document_from_node, window_from_node};
use dom::urlhelper::UrlHelper;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use msg::constellation_msg::ReferrerPolicy;
use num_traits::ToPrimitive;
use script_traits::MozBrowserEvent;
use std::default::Default;
use string_cache::Atom;
use style::attr::AttrValue;
use url::Url;
use util::prefs::PREFS;
@ -41,7 +41,7 @@ pub struct HTMLAnchorElement {
}
impl HTMLAnchorElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLAnchorElement {
HTMLAnchorElement {
@ -53,7 +53,7 @@ impl HTMLAnchorElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLAnchorElement> {
Node::reflect_node(box HTMLAnchorElement::new_inherited(local_name, prefix, document),
@ -63,7 +63,7 @@ impl HTMLAnchorElement {
// https://html.spec.whatwg.org/multipage/#concept-hyperlink-url-set
fn set_url(&self) {
let attribute = self.upcast::<Element>().get_attribute(&ns!(), &atom!("href"));
let attribute = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href"));
*self.url.borrow_mut() = attribute.and_then(|attribute| {
let document = document_from_node(self);
document.base_url().join(&attribute.value()).ok()
@ -84,7 +84,7 @@ impl HTMLAnchorElement {
// https://html.spec.whatwg.org/multipage/#update-href
fn update_href(&self, url: DOMString) {
self.upcast::<Element>().set_string_attribute(&atom!("href"), url);
self.upcast::<Element>().set_string_attribute(&local_name!("href"), url);
}
}
@ -93,9 +93,9 @@ impl VirtualMethods for HTMLAnchorElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("rel") => AttrValue::from_serialized_tokenlist(value.into()),
&local_name!("rel") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
@ -115,7 +115,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
// https://html.spec.whatwg.org/multipage/#dom-a-rellist
fn RelList(&self) -> Root<DOMTokenList> {
self.rel_list.or_init(|| {
DOMTokenList::new(self.upcast(), &atom!("rel"))
DOMTokenList::new(self.upcast(), &local_name!("rel"))
})
}
@ -265,7 +265,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
USVString(match *self.url.borrow() {
None => {
match self.upcast::<Element>().get_attribute(&ns!(), &atom!("href")) {
match self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href")) {
// Step 3.
None => String::new(),
// Step 4.
@ -279,7 +279,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-href
fn SetHref(&self, value: USVString) {
self.upcast::<Element>().set_string_attribute(&atom!("href"),
self.upcast::<Element>().set_string_attribute(&local_name!("href"),
DOMString::from_string(value.0));
self.set_url();
}
@ -499,7 +499,7 @@ impl Activatable for HTMLAnchorElement {
// hyperlink"
// https://html.spec.whatwg.org/multipage/#the-a-element
// "The activation behaviour of a elements *that create hyperlinks*"
self.upcast::<Element>().has_attribute(&atom!("href"))
self.upcast::<Element>().has_attribute(&local_name!("href"))
}
@ -525,7 +525,7 @@ impl Activatable for HTMLAnchorElement {
let mouse_event = event.downcast::<MouseEvent>().unwrap();
let mut ismap_suffix = None;
if let Some(element) = target.downcast::<Element>() {
if target.is::<HTMLImageElement>() && element.has_attribute(&atom!("ismap")) {
if target.is::<HTMLImageElement>() && element.has_attribute(&local_name!("ismap")) {
let target_node = element.upcast::<Node>();
let rect = window_from_node(target_node).content_box_query(
target_node.to_trusted_node_address());
@ -563,10 +563,10 @@ fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<String>, referre
// Step 1: replace.
// Step 2: source browsing context.
// Step 3: target browsing context.
let target = subject.get_attribute(&ns!(), &atom!("target"));
let target = subject.get_attribute(&ns!(), &local_name!("target"));
// Step 4: disown target's opener if needed.
let attribute = subject.get_attribute(&ns!(), &atom!("href")).unwrap();
let attribute = subject.get_attribute(&ns!(), &local_name!("href")).unwrap();
let mut href = attribute.Value();
// Step 7: append a hyperlink suffix.

View file

@ -11,7 +11,7 @@ use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use style::attr::AttrValue;
#[dom_struct]
@ -20,7 +20,7 @@ pub struct HTMLAppletElement {
}
impl HTMLAppletElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLAppletElement {
HTMLAppletElement {
@ -30,7 +30,7 @@ impl HTMLAppletElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLAppletElement> {
Node::reflect_node(box HTMLAppletElement::new_inherited(local_name, prefix, document),
@ -52,9 +52,9 @@ impl VirtualMethods for HTMLAppletElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("name") => AttrValue::from_atomic(value.into()),
&local_name!("name") => AttrValue::from_atomic(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}

View file

@ -12,8 +12,8 @@ use dom::domtokenlist::DOMTokenList;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use std::default::Default;
use string_cache::Atom;
use style::attr::AttrValue;
#[dom_struct]
@ -23,7 +23,7 @@ pub struct HTMLAreaElement {
}
impl HTMLAreaElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLAreaElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLAreaElement {
HTMLAreaElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
rel_list: Default::default(),
@ -31,7 +31,7 @@ impl HTMLAreaElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLAreaElement> {
Node::reflect_node(box HTMLAreaElement::new_inherited(local_name, prefix, document),
@ -45,9 +45,9 @@ impl VirtualMethods for HTMLAreaElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("rel") => AttrValue::from_serialized_tokenlist(value.into()),
&local_name!("rel") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
@ -57,7 +57,7 @@ impl HTMLAreaElementMethods for HTMLAreaElement {
// https://html.spec.whatwg.org/multipage/#dom-area-rellist
fn RelList(&self) -> Root<DOMTokenList> {
self.rel_list.or_init(|| {
DOMTokenList::new(self.upcast(), &atom!("rel"))
DOMTokenList::new(self.upcast(), &local_name!("rel"))
})
}
}

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlmediaelement::HTMLMediaElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLAudioElement {
@ -16,7 +16,7 @@ pub struct HTMLAudioElement {
}
impl HTMLAudioElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLAudioElement {
HTMLAudioElement {
@ -26,7 +26,7 @@ impl HTMLAudioElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLAudioElement> {
Node::reflect_node(box HTMLAudioElement::new_inherited(local_name, prefix, document),

View file

@ -13,7 +13,7 @@ use dom::element::{AttributeMutation, Element};
use dom::htmlelement::HTMLElement;
use dom::node::{Node, UnbindContext, document_from_node};
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use style::attr::AttrValue;
use url::Url;
@ -23,14 +23,14 @@ pub struct HTMLBaseElement {
}
impl HTMLBaseElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLBaseElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLBaseElement {
HTMLBaseElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document)
}
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLBaseElement> {
Node::reflect_node(box HTMLBaseElement::new_inherited(local_name, prefix, document),
@ -40,7 +40,7 @@ impl HTMLBaseElement {
/// https://html.spec.whatwg.org/multipage/#frozen-base-url
pub fn frozen_base_url(&self) -> Url {
let href = self.upcast::<Element>().get_attribute(&ns!(), &atom!("href"))
let href = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href"))
.expect("The frozen base url is only defined for base elements \
that have a base url.");
let document = document_from_node(self);
@ -56,7 +56,7 @@ impl HTMLBaseElement {
return;
}
if self.upcast::<Element>().has_attribute(&atom!("href")) {
if self.upcast::<Element>().has_attribute(&local_name!("href")) {
let document = document_from_node(self);
document.refresh_base_element();
}
@ -69,7 +69,7 @@ impl HTMLBaseElementMethods for HTMLBaseElement {
let document = document_from_node(self);
// Step 1.
if !self.upcast::<Element>().has_attribute(&atom!("href")) {
if !self.upcast::<Element>().has_attribute(&local_name!("href")) {
return DOMString::from(document.base_url().as_str());
}
@ -77,7 +77,7 @@ impl HTMLBaseElementMethods for HTMLBaseElement {
let fallback_base_url = document.fallback_base_url();
// Step 3.
let url = self.upcast::<Element>().get_url_attribute(&atom!("href"));
let url = self.upcast::<Element>().get_url_attribute(&local_name!("href"));
// Step 4.
let url_record = fallback_base_url.join(&*url);
@ -97,7 +97,7 @@ impl VirtualMethods for HTMLBaseElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
if *attr.local_name() == atom!("href") {
if *attr.local_name() == local_name!("href") {
document_from_node(self).refresh_base_element();
}
}

View file

@ -17,8 +17,8 @@ use dom::globalscope::GlobalScope;
use dom::htmlelement::HTMLElement;
use dom::node::{Node, document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use script_traits::ScriptMsg as ConstellationMsg;
use string_cache::Atom;
use style::attr::AttrValue;
use time;
use url::Url;
@ -33,7 +33,7 @@ pub struct HTMLBodyElement {
}
impl HTMLBodyElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document)
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document)
-> HTMLBodyElement {
HTMLBodyElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
@ -41,7 +41,7 @@ impl HTMLBodyElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document)
pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document)
-> Root<HTMLBodyElement> {
Node::reflect_node(box HTMLBodyElement::new_inherited(local_name, prefix, document),
document,
@ -93,7 +93,7 @@ impl HTMLBodyElementLayoutHelpers for LayoutJS<HTMLBodyElement> {
fn get_background_color(&self) -> Option<RGBA> {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("bgcolor"))
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
.and_then(AttrValue::as_color)
.cloned()
}
@ -103,7 +103,7 @@ impl HTMLBodyElementLayoutHelpers for LayoutJS<HTMLBodyElement> {
fn get_color(&self) -> Option<RGBA> {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("text"))
.get_attr_for_layout(&ns!(), &local_name!("text"))
.and_then(AttrValue::as_color)
.cloned()
}
@ -113,7 +113,7 @@ impl HTMLBodyElementLayoutHelpers for LayoutJS<HTMLBodyElement> {
fn get_background(&self) -> Option<Url> {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("background"))
.get_attr_for_layout(&ns!(), &local_name!("background"))
.and_then(AttrValue::as_url)
.cloned()
}
@ -141,11 +141,11 @@ impl VirtualMethods for HTMLBodyElement {
window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap();
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match *name {
atom!("bgcolor") |
atom!("text") => AttrValue::from_legacy_color(value.into()),
atom!("background") => {
local_name!("bgcolor") |
local_name!("text") => AttrValue::from_legacy_color(value.into()),
local_name!("background") => {
AttrValue::from_url(document_from_node(self).url(), value.into())
},
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
@ -159,11 +159,14 @@ impl VirtualMethods for HTMLBodyElement {
// https://html.spec.whatwg.org/multipage/
// #event-handlers-on-elements,-document-objects,-and-window-objects:event-handlers-3
match name {
&atom!("onfocus") | &atom!("onload") | &atom!("onscroll") | &atom!("onafterprint") |
&atom!("onbeforeprint") | &atom!("onbeforeunload") | &atom!("onhashchange") |
&atom!("onlanguagechange") | &atom!("onmessage") | &atom!("onoffline") | &atom!("ononline") |
&atom!("onpagehide") | &atom!("onpageshow") | &atom!("onpopstate") | &atom!("onstorage") |
&atom!("onresize") | &atom!("onunload") | &atom!("onerror")
&local_name!("onfocus") | &local_name!("onload") | &local_name!("onscroll") |
&local_name!("onafterprint") | &local_name!("onbeforeprint") |
&local_name!("onbeforeunload") | &local_name!("onhashchange") |
&local_name!("onlanguagechange") | &local_name!("onmessage") |
&local_name!("onoffline") | &local_name!("ononline") |
&local_name!("onpagehide") | &local_name!("onpageshow") |
&local_name!("onpopstate") | &local_name!("onstorage") |
&local_name!("onresize") | &local_name!("onunload") | &local_name!("onerror")
=> {
let evtarget = window.upcast::<EventTarget>(); // forwarded event
let source_line = 1; //TODO(#9604) obtain current JS execution line

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLBRElement {
@ -16,14 +16,14 @@ pub struct HTMLBRElement {
}
impl HTMLBRElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLBRElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLBRElement {
HTMLBRElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document)
}
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLBRElement> {
Node::reflect_node(box HTMLBRElement::new_inherited(local_name, prefix, document),

View file

@ -23,8 +23,8 @@ use dom::nodelist::NodeList;
use dom::validation::Validatable;
use dom::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use std::cell::Cell;
use string_cache::Atom;
use style::element_state::*;
#[derive(JSTraceable, PartialEq, Copy, Clone)]
@ -43,7 +43,7 @@ pub struct HTMLButtonElement {
}
impl HTMLButtonElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLButtonElement {
HTMLButtonElement {
@ -55,7 +55,7 @@ impl HTMLButtonElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLButtonElement> {
Node::reflect_node(box HTMLButtonElement::new_inherited(local_name, prefix, document),
@ -180,7 +180,7 @@ impl VirtualMethods for HTMLButtonElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
&atom!("disabled") => {
&local_name!("disabled") => {
let el = self.upcast::<Element>();
match mutation {
AttributeMutation::Set(Some(_)) => {}
@ -195,7 +195,7 @@ impl VirtualMethods for HTMLButtonElement {
}
}
},
&atom!("type") => {
&local_name!("type") => {
match mutation {
AttributeMutation::Set(_) => {
let value = match &**attr.value() {

View file

@ -25,6 +25,7 @@ use dom::node::{Node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext};
use euclid::size::Size2D;
use html5ever_atoms::LocalName;
use image::ColorType;
use image::png::PNGEncoder;
use ipc_channel::ipc::{self, IpcSender};
@ -34,7 +35,6 @@ use offscreen_gl_context::GLContextAttributes;
use rustc_serialize::base64::{STANDARD, ToBase64};
use script_layout_interface::HTMLCanvasData;
use std::iter::repeat;
use string_cache::Atom;
use style::attr::AttrValue;
const DEFAULT_WIDTH: u32 = 300;
@ -56,7 +56,7 @@ pub struct HTMLCanvasElement {
}
impl HTMLCanvasElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLCanvasElement {
HTMLCanvasElement {
@ -66,7 +66,7 @@ impl HTMLCanvasElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLCanvasElement> {
Node::reflect_node(box HTMLCanvasElement::new_inherited(local_name, prefix, document),
@ -116,8 +116,8 @@ impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> {
}
});
let width_attr = canvas.upcast::<Element>().get_attr_for_layout(&ns!(), &atom!("width"));
let height_attr = canvas.upcast::<Element>().get_attr_for_layout(&ns!(), &atom!("height"));
let width_attr = canvas.upcast::<Element>().get_attr_for_layout(&ns!(), &local_name!("width"));
let height_attr = canvas.upcast::<Element>().get_attr_for_layout(&ns!(), &local_name!("height"));
HTMLCanvasData {
ipc_renderer: ipc_renderer,
width: width_attr.map_or(DEFAULT_WIDTH, |val| val.as_uint()),
@ -307,15 +307,15 @@ impl VirtualMethods for HTMLCanvasElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
&atom!("width") | &atom!("height") => self.recreate_contexts(),
&local_name!("width") | &local_name!("height") => self.recreate_contexts(),
_ => (),
};
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("width") => AttrValue::from_u32(value.into(), DEFAULT_WIDTH),
&atom!("height") => AttrValue::from_u32(value.into(), DEFAULT_HEIGHT),
&local_name!("width") => AttrValue::from_u32(value.into(), DEFAULT_WIDTH),
&local_name!("height") => AttrValue::from_u32(value.into(), DEFAULT_HEIGHT),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}

View file

@ -13,9 +13,10 @@ use dom::bindings::xmlname::namespace_from_domstring;
use dom::element::Element;
use dom::node::Node;
use dom::window::Window;
use html5ever_atoms::{LocalName, QualName};
use servo_atoms::Atom;
use std::ascii::AsciiExt;
use std::cell::Cell;
use string_cache::{Atom, Namespace, QualName};
use style::str::split_html_space_chars;
pub trait CollectionFilter : JSTraceable {
@ -115,22 +116,22 @@ impl HTMLCollection {
pub fn by_tag_name(window: &Window, root: &Node, mut tag: DOMString)
-> Root<HTMLCollection> {
let tag_atom = Atom::from(&*tag);
let tag_atom = LocalName::from(&*tag);
tag.make_ascii_lowercase();
let ascii_lower_tag = Atom::from(tag); // FIXME(ajeffrey): don't clone atom if it was already lowercased.
let ascii_lower_tag = LocalName::from(tag); // FIXME(ajeffrey): don't clone atom if it was already lowercased.
HTMLCollection::by_atomic_tag_name(window, root, tag_atom, ascii_lower_tag)
}
pub fn by_atomic_tag_name(window: &Window, root: &Node, tag_atom: Atom, ascii_lower_tag: Atom)
pub fn by_atomic_tag_name(window: &Window, root: &Node, tag_atom: LocalName, ascii_lower_tag: LocalName)
-> Root<HTMLCollection> {
#[derive(JSTraceable, HeapSizeOf)]
struct TagNameFilter {
tag: Atom,
ascii_lower_tag: Atom,
tag: LocalName,
ascii_lower_tag: LocalName,
}
impl CollectionFilter for TagNameFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool {
if self.tag == atom!("*") {
if self.tag == local_name!("*") {
true
} else if elem.html_element_in_html_document() {
*elem.local_name() == self.ascii_lower_tag
@ -148,7 +149,7 @@ impl HTMLCollection {
pub fn by_tag_name_ns(window: &Window, root: &Node, tag: DOMString,
maybe_ns: Option<DOMString>) -> Root<HTMLCollection> {
let local = Atom::from(tag);
let local = LocalName::from(tag);
let ns = namespace_from_domstring(maybe_ns);
let qname = QualName::new(ns, local);
HTMLCollection::by_qual_tag_name(window, root, qname)
@ -161,8 +162,8 @@ impl HTMLCollection {
}
impl CollectionFilter for TagNameNSFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool {
((self.qname.ns == Namespace(atom!("*"))) || (self.qname.ns == *elem.namespace())) &&
((self.qname.local == atom!("*")) || (self.qname.local == *elem.local_name()))
((self.qname.ns == namespace_url!("*")) || (self.qname.ns == *elem.namespace())) &&
((self.qname.local == local_name!("*")) || (self.qname.local == *elem.local_name()))
}
}
let filter = TagNameNSFilter {
@ -313,8 +314,8 @@ impl HTMLCollectionMethods for HTMLCollection {
// Step 2.
self.elements_iter().find(|elem| {
elem.get_string_attribute(&atom!("id")) == key ||
(elem.namespace() == &ns!(html) && elem.get_string_attribute(&atom!("name")) == key)
elem.get_string_attribute(&local_name!("id")) == key ||
(elem.namespace() == &ns!(html) && elem.get_string_attribute(&local_name!("name")) == key)
})
}
@ -336,12 +337,12 @@ impl HTMLCollectionMethods for HTMLCollection {
// Step 2
for elem in self.elements_iter() {
// Step 2.1
let id_attr = elem.get_string_attribute(&atom!("id"));
let id_attr = elem.get_string_attribute(&local_name!("id"));
if !id_attr.is_empty() && !result.contains(&id_attr) {
result.push(id_attr)
}
// Step 2.2
let name_attr = elem.get_string_attribute(&atom!("name"));
let name_attr = elem.get_string_attribute(&local_name!("name"));
if !name_attr.is_empty() && !result.contains(&name_attr) && *elem.namespace() == ns!(html) {
result.push(name_attr)
}

View file

@ -9,7 +9,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLDataElement {
@ -17,7 +17,7 @@ pub struct HTMLDataElement {
}
impl HTMLDataElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLDataElement {
HTMLDataElement {
@ -26,7 +26,7 @@ impl HTMLDataElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLDataElement> {
Node::reflect_node(box HTMLDataElement::new_inherited(local_name, prefix, document),

View file

@ -13,7 +13,7 @@ use dom::htmlcollection::{CollectionFilter, HTMLCollection};
use dom::htmlelement::HTMLElement;
use dom::htmloptionelement::HTMLOptionElement;
use dom::node::{Node, window_from_node};
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLDataListElement {
@ -21,7 +21,7 @@ pub struct HTMLDataListElement {
}
impl HTMLDataListElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLDataListElement {
HTMLDataListElement {
@ -31,7 +31,7 @@ impl HTMLDataListElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLDataListElement> {
Node::reflect_node(box HTMLDataListElement::new_inherited(local_name, prefix, document),

View file

@ -15,9 +15,9 @@ use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
use dom::node::{Node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use script_thread::Runnable;
use std::cell::Cell;
use string_cache::Atom;
use task_source::TaskSource;
#[dom_struct]
@ -27,7 +27,7 @@ pub struct HTMLDetailsElement {
}
impl HTMLDetailsElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLDetailsElement {
HTMLDetailsElement {
@ -38,7 +38,7 @@ impl HTMLDetailsElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLDetailsElement> {
Node::reflect_node(box HTMLDetailsElement::new_inherited(local_name, prefix, document),
@ -67,7 +67,7 @@ impl VirtualMethods for HTMLDetailsElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
if attr.local_name() == &atom!("open") {
if attr.local_name() == &local_name!("open") {
let counter = self.toggle_counter.get() + 1;
self.toggle_counter.set(counter);

View file

@ -13,7 +13,7 @@ use dom::element::Element;
use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
use dom::node::{Node, window_from_node};
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLDialogElement {
@ -22,7 +22,7 @@ pub struct HTMLDialogElement {
}
impl HTMLDialogElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLDialogElement {
HTMLDialogElement {
@ -33,7 +33,7 @@ impl HTMLDialogElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLDialogElement> {
Node::reflect_node(box HTMLDialogElement::new_inherited(local_name, prefix, document),
@ -67,7 +67,7 @@ impl HTMLDialogElementMethods for HTMLDialogElement {
let win = window_from_node(self);
// Step 1 & 2
if element.remove_attribute(&ns!(), &atom!("open")).is_none() {
if element.remove_attribute(&ns!(), &local_name!("open")).is_none() {
return;
}

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLDirectoryElement {
@ -16,7 +16,7 @@ pub struct HTMLDirectoryElement {
}
impl HTMLDirectoryElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLDirectoryElement {
HTMLDirectoryElement {
@ -26,7 +26,7 @@ impl HTMLDirectoryElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLDirectoryElement> {
Node::reflect_node(box HTMLDirectoryElement::new_inherited(local_name, prefix, document),

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLDivElement {
@ -16,7 +16,7 @@ pub struct HTMLDivElement {
}
impl HTMLDivElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLDivElement {
HTMLDivElement {
@ -25,7 +25,7 @@ impl HTMLDivElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLDivElement> {
Node::reflect_node(box HTMLDivElement::new_inherited(local_name, prefix, document),

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLDListElement {
@ -16,7 +16,7 @@ pub struct HTMLDListElement {
}
impl HTMLDListElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLDListElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLDListElement {
HTMLDListElement {
htmlelement:
HTMLElement::new_inherited(local_name, prefix, document)
@ -24,7 +24,7 @@ impl HTMLDListElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLDListElement> {
Node::reflect_node(box HTMLDListElement::new_inherited(local_name, prefix, document),

View file

@ -29,11 +29,11 @@ use dom::node::{Node, SEQUENTIALLY_FOCUSABLE};
use dom::node::{document_from_node, window_from_node};
use dom::nodelist::NodeList;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::default::Default;
use std::rc::Rc;
use string_cache::Atom;
use style::attr::AttrValue;
use style::element_state::*;
@ -45,12 +45,12 @@ pub struct HTMLElement {
}
impl HTMLElement {
pub fn new_inherited(tag_name: Atom, prefix: Option<DOMString>,
pub fn new_inherited(tag_name: LocalName, prefix: Option<DOMString>,
document: &Document) -> HTMLElement {
HTMLElement::new_inherited_with_state(ElementState::empty(), tag_name, prefix, document)
}
pub fn new_inherited_with_state(state: ElementState, tag_name: Atom,
pub fn new_inherited_with_state(state: ElementState, tag_name: LocalName,
prefix: Option<DOMString>, document: &Document)
-> HTMLElement {
HTMLElement {
@ -62,7 +62,7 @@ impl HTMLElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> Root<HTMLElement> {
pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> Root<HTMLElement> {
Node::reflect_node(box HTMLElement::new_inherited(local_name, prefix, document),
document,
HTMLElementBinding::Wrap)
@ -76,7 +76,7 @@ impl HTMLElement {
fn update_sequentially_focusable_status(&self) {
let element = self.upcast::<Element>();
let node = self.upcast::<Node>();
if element.has_attribute(&atom!("tabindex")) {
if element.has_attribute(&local_name!("tabindex")) {
node.set_flag(SEQUENTIALLY_FOCUSABLE, true);
} else {
match node.type_id() {
@ -87,12 +87,12 @@ impl HTMLElement {
=> node.set_flag(SEQUENTIALLY_FOCUSABLE, true),
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
if element.has_attribute(&atom!("href")) {
if element.has_attribute(&local_name!("href")) {
node.set_flag(SEQUENTIALLY_FOCUSABLE, true);
}
},
_ => {
if let Some(attr) = element.get_attribute(&ns!(), &atom!("draggable")) {
if let Some(attr) = element.get_attribute(&ns!(), &local_name!("draggable")) {
let value = attr.value();
let is_true = match *value {
AttrValue::String(ref string) => string == "true",
@ -393,16 +393,16 @@ impl HTMLElement {
}
pub fn get_custom_attr(&self, local_name: DOMString) -> Option<DOMString> {
// FIXME(ajeffrey): Convert directly from DOMString to Atom
let local_name = Atom::from(to_snake_case(local_name));
// FIXME(ajeffrey): Convert directly from DOMString to LocalName
let local_name = LocalName::from(to_snake_case(local_name));
self.upcast::<Element>().get_attribute(&ns!(), &local_name).map(|attr| {
DOMString::from(&**attr.value()) // FIXME(ajeffrey): Convert directly from AttrValue to DOMString
})
}
pub fn delete_custom_attr(&self, local_name: DOMString) {
// FIXME(ajeffrey): Convert directly from DOMString to Atom
let local_name = Atom::from(to_snake_case(local_name));
// FIXME(ajeffrey): Convert directly from DOMString to LocalName
let local_name = LocalName::from(to_snake_case(local_name));
self.upcast::<Element>().remove_attribute(&ns!(), &local_name);
}
@ -430,7 +430,7 @@ impl HTMLElement {
pub fn is_listed_element(&self) -> bool {
// Servo does not implement HTMLKeygenElement
// https://github.com/servo/servo/issues/2782
if self.upcast::<Element>().local_name() == &atom!("keygen") {
if self.upcast::<Element>().local_name() == &local_name!("keygen") {
return true;
}
@ -475,7 +475,7 @@ impl HTMLElement {
// will be a label for this HTMLElement
.take_while(|elem| !elem.is_labelable_element())
.filter_map(Root::downcast::<HTMLLabelElement>)
.filter(|elem| !elem.upcast::<Element>().has_attribute(&atom!("for")))
.filter(|elem| !elem.upcast::<Element>().has_attribute(&local_name!("for")))
.filter(|elem| elem.first_labelable_descendant().r() == Some(self))
.map(Root::upcast::<Node>);
@ -491,7 +491,7 @@ impl HTMLElement {
let children = root_node.traverse_preorder()
.filter_map(Root::downcast::<Element>)
.filter(|elem| elem.is::<HTMLLabelElement>())
.filter(|elem| elem.get_string_attribute(&atom!("for")) == id)
.filter(|elem| elem.get_string_attribute(&local_name!("for")) == id)
.map(Root::upcast::<Node>);
NodeList::new_simple_list(&window, children.chain(ancestors))

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLEmbedElement {
@ -16,14 +16,14 @@ pub struct HTMLEmbedElement {
}
impl HTMLEmbedElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLEmbedElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLEmbedElement {
HTMLEmbedElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document)
}
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLEmbedElement> {
Node::reflect_node(box HTMLEmbedElement::new_inherited(local_name, prefix, document),

View file

@ -17,7 +17,7 @@ use dom::htmllegendelement::HTMLLegendElement;
use dom::node::{Node, window_from_node};
use dom::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use style::element_state::*;
#[dom_struct]
@ -26,7 +26,7 @@ pub struct HTMLFieldSetElement {
}
impl HTMLFieldSetElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLFieldSetElement {
HTMLFieldSetElement {
@ -37,7 +37,7 @@ impl HTMLFieldSetElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLFieldSetElement> {
Node::reflect_node(box HTMLFieldSetElement::new_inherited(local_name, prefix, document),
@ -88,7 +88,7 @@ impl VirtualMethods for HTMLFieldSetElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
&atom!("disabled") => {
&local_name!("disabled") => {
let disabled_state = match mutation {
AttributeMutation::Set(None) => true,
AttributeMutation::Set(Some(_)) => {

View file

@ -13,7 +13,8 @@ use dom::element::{Element, RawLayoutElementHelpers};
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use servo_atoms::Atom;
use style::attr::AttrValue;
use style::str::{HTML_SPACE_CHARACTERS, read_numbers};
use style::values::specified;
@ -25,14 +26,14 @@ pub struct HTMLFontElement {
impl HTMLFontElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLFontElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLFontElement {
HTMLFontElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
}
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLFontElement> {
Node::reflect_node(box HTMLFontElement::new_inherited(local_name, prefix, document),
@ -61,7 +62,7 @@ impl HTMLFontElementMethods for HTMLFontElement {
fn SetSize(&self, value: DOMString) {
let element = self.upcast::<Element>();
let length = parse_length(&value);
element.set_attribute(&atom!("size"), AttrValue::Length(value.into(), length));
element.set_attribute(&local_name!("size"), AttrValue::Length(value.into(), length));
}
}
@ -70,11 +71,11 @@ impl VirtualMethods for HTMLFontElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("face") => AttrValue::from_atomic(value.into()),
&atom!("color") => AttrValue::from_legacy_color(value.into()),
&atom!("size") => {
&local_name!("face") => AttrValue::from_atomic(value.into()),
&local_name!("color") => AttrValue::from_legacy_color(value.into()),
&local_name!("size") => {
let length = parse_length(&value);
AttrValue::Length(value.into(), length)
},
@ -94,7 +95,7 @@ impl HTMLFontElementLayoutHelpers for LayoutJS<HTMLFontElement> {
fn get_color(&self) -> Option<RGBA> {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("color"))
.get_attr_for_layout(&ns!(), &local_name!("color"))
.and_then(AttrValue::as_color)
.cloned()
}
@ -104,7 +105,7 @@ impl HTMLFontElementLayoutHelpers for LayoutJS<HTMLFontElement> {
fn get_face(&self) -> Option<Atom> {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("face"))
.get_attr_for_layout(&ns!(), &local_name!("face"))
.map(AttrValue::as_atom)
.cloned()
}
@ -114,7 +115,7 @@ impl HTMLFontElementLayoutHelpers for LayoutJS<HTMLFontElement> {
fn get_size(&self) -> Option<specified::Length> {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("size"))
.get_attr_for_layout(&ns!(), &local_name!("size"))
.and_then(AttrValue::as_length)
.cloned()
}

View file

@ -50,8 +50,8 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection {
if name.is_empty() { return None; }
let mut filter_map = self.collection.elements_iter().filter_map(|elem| {
if elem.get_string_attribute(&atom!("name")) == name
|| elem.get_string_attribute(&atom!("id")) == name {
if elem.get_string_attribute(&local_name!("name")) == name
|| elem.get_string_attribute(&local_name!("id")) == name {
Some(elem)
} else { None }
});

View file

@ -40,6 +40,7 @@ use dom::virtualmethods::VirtualMethods;
use encoding::EncodingRef;
use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
use html5ever_atoms::LocalName;
use hyper::header::{Charset, ContentDisposition, ContentType, DispositionParam, DispositionType};
use hyper::method::Method;
use msg::constellation_msg::PipelineId;
@ -49,7 +50,6 @@ use script_traits::LoadData;
use std::borrow::ToOwned;
use std::cell::Cell;
use std::sync::mpsc::Sender;
use string_cache::Atom;
use style::attr::AttrValue;
use style::str::split_html_space_chars;
use task_source::TaskSource;
@ -66,7 +66,7 @@ pub struct HTMLFormElement {
}
impl HTMLFormElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLFormElement {
HTMLFormElement {
@ -78,7 +78,7 @@ impl HTMLFormElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLFormElement> {
Node::reflect_node(box HTMLFormElement::new_inherited(local_name, prefix, document),
@ -205,7 +205,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
}
_ => {
debug_assert!(!elem.downcast::<HTMLElement>().unwrap().is_listed_element() ||
elem.local_name() == &atom!("keygen"));
elem.local_name() == &local_name!("keygen"));
return false;
}
}
@ -255,9 +255,9 @@ impl HTMLFormElement {
// https://html.spec.whatwg.org/multipage/#picking-an-encoding-for-the-form
fn pick_encoding(&self) -> EncodingRef {
// Step 2
if self.upcast::<Element>().has_attribute(&atom!("accept-charset")) {
if self.upcast::<Element>().has_attribute(&local_name!("accept-charset")) {
// Substep 1
let input = self.upcast::<Element>().get_string_attribute(&atom!("accept-charset"));
let input = self.upcast::<Element>().get_string_attribute(&local_name!("accept-charset"));
// Substep 2, 3, 4
let mut candidate_encodings = split_html_space_chars(&*input).filter_map(encoding_from_whatwg_label);
@ -728,12 +728,12 @@ impl<'a> FormSubmitter<'a> {
match *self {
FormSubmitter::FormElement(form) => form.Action(),
FormSubmitter::InputElement(input_element) => {
input_element.get_form_attribute(&atom!("formaction"),
input_element.get_form_attribute(&local_name!("formaction"),
|i| i.FormAction(),
|f| f.Action())
},
FormSubmitter::ButtonElement(button_element) => {
button_element.get_form_attribute(&atom!("formaction"),
button_element.get_form_attribute(&local_name!("formaction"),
|i| i.FormAction(),
|f| f.Action())
}
@ -744,12 +744,12 @@ impl<'a> FormSubmitter<'a> {
let attr = match *self {
FormSubmitter::FormElement(form) => form.Enctype(),
FormSubmitter::InputElement(input_element) => {
input_element.get_form_attribute(&atom!("formenctype"),
input_element.get_form_attribute(&local_name!("formenctype"),
|i| i.FormEnctype(),
|f| f.Enctype())
},
FormSubmitter::ButtonElement(button_element) => {
button_element.get_form_attribute(&atom!("formenctype"),
button_element.get_form_attribute(&local_name!("formenctype"),
|i| i.FormEnctype(),
|f| f.Enctype())
}
@ -767,12 +767,12 @@ impl<'a> FormSubmitter<'a> {
let attr = match *self {
FormSubmitter::FormElement(form) => form.Method(),
FormSubmitter::InputElement(input_element) => {
input_element.get_form_attribute(&atom!("formmethod"),
input_element.get_form_attribute(&local_name!("formmethod"),
|i| i.FormMethod(),
|f| f.Method())
},
FormSubmitter::ButtonElement(button_element) => {
button_element.get_form_attribute(&atom!("formmethod"),
button_element.get_form_attribute(&local_name!("formmethod"),
|i| i.FormMethod(),
|f| f.Method())
}
@ -788,12 +788,12 @@ impl<'a> FormSubmitter<'a> {
match *self {
FormSubmitter::FormElement(form) => form.Target(),
FormSubmitter::InputElement(input_element) => {
input_element.get_form_attribute(&atom!("formtarget"),
input_element.get_form_attribute(&local_name!("formtarget"),
|i| i.FormTarget(),
|f| f.Target())
},
FormSubmitter::ButtonElement(button_element) => {
button_element.get_form_attribute(&atom!("formtarget"),
button_element.get_form_attribute(&local_name!("formtarget"),
|i| i.FormTarget(),
|f| f.Target())
}
@ -804,12 +804,12 @@ impl<'a> FormSubmitter<'a> {
match *self {
FormSubmitter::FormElement(form) => form.NoValidate(),
FormSubmitter::InputElement(input_element) => {
input_element.get_form_boolean_attribute(&atom!("formnovalidate"),
input_element.get_form_boolean_attribute(&local_name!("formnovalidate"),
|i| i.FormNoValidate(),
|f| f.NoValidate())
}
FormSubmitter::ButtonElement(button_element) => {
button_element.get_form_boolean_attribute(&atom!("formnovalidate"),
button_element.get_form_boolean_attribute(&local_name!("formnovalidate"),
|i| i.FormNoValidate(),
|f| f.NoValidate())
}
@ -823,7 +823,7 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable {
fn form_owner(&self) -> Option<Root<HTMLFormElement>> {
// https://html.spec.whatwg.org/multipage/#reset-the-form-owner
let elem = self.to_element();
let owner = elem.get_string_attribute(&atom!("form"));
let owner = elem.get_string_attribute(&local_name!("form"));
if !owner.is_empty() {
let doc = document_from_node(elem);
let owner = doc.GetElementById(owner);
@ -838,7 +838,7 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable {
}
fn get_form_attribute<InputFn, OwnerFn>(&self,
attr: &Atom,
attr: &LocalName,
input: InputFn,
owner: OwnerFn)
-> DOMString
@ -853,7 +853,7 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable {
}
fn get_form_boolean_attribute<InputFn, OwnerFn>(&self,
attr: &Atom,
attr: &LocalName,
input: InputFn,
owner: OwnerFn)
-> bool
@ -881,9 +881,9 @@ impl VirtualMethods for HTMLFormElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("name") => AttrValue::from_atomic(value.into()),
&local_name!("name") => AttrValue::from_atomic(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLFrameElement {
@ -16,14 +16,14 @@ pub struct HTMLFrameElement {
}
impl HTMLFrameElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLFrameElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLFrameElement {
HTMLFrameElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document)
}
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLFrameElement> {
Node::reflect_node(box HTMLFrameElement::new_inherited(local_name, prefix, document),

View file

@ -11,7 +11,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::{Node, window_from_node};
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLFrameSetElement {
@ -19,7 +19,7 @@ pub struct HTMLFrameSetElement {
}
impl HTMLFrameSetElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLFrameSetElement {
HTMLFrameSetElement {
@ -29,7 +29,7 @@ impl HTMLFrameSetElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLFrameSetElement> {
Node::reflect_node(box HTMLFrameSetElement::new_inherited(local_name, prefix, document),

View file

@ -14,7 +14,7 @@ use dom::htmlmetaelement::HTMLMetaElement;
use dom::node::{Node, document_from_node};
use dom::userscripts::load_script;
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLHeadElement {
@ -22,7 +22,7 @@ pub struct HTMLHeadElement {
}
impl HTMLHeadElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLHeadElement {
HTMLHeadElement {
@ -31,7 +31,7 @@ impl HTMLHeadElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLHeadElement> {
Node::reflect_node(box HTMLHeadElement::new_inherited(local_name, prefix, document),
@ -51,11 +51,11 @@ impl HTMLHeadElement {
let candidates = node.traverse_preorder()
.filter_map(Root::downcast::<Element>)
.filter(|elem| elem.is::<HTMLMetaElement>())
.filter(|elem| elem.get_string_attribute(&atom!("name")) == "referrer")
.filter(|elem| elem.get_attribute(&ns!(), &atom!("content")).is_some());
.filter(|elem| elem.get_string_attribute(&local_name!("name")) == "referrer")
.filter(|elem| elem.get_attribute(&ns!(), &local_name!("content")).is_some());
for meta in candidates {
if let Some(content) = meta.get_attribute(&ns!(), &atom!("content")).r() {
if let Some(content) = meta.get_attribute(&ns!(), &local_name!("content")).r() {
let content = content.value();
let content_val = content.trim();
if !content_val.is_empty() {

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[derive(JSTraceable, HeapSizeOf)]
pub enum HeadingLevel {
@ -27,7 +27,7 @@ pub struct HTMLHeadingElement {
}
impl HTMLHeadingElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document,
level: HeadingLevel) -> HTMLHeadingElement {
@ -39,7 +39,7 @@ impl HTMLHeadingElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document,
level: HeadingLevel) -> Root<HTMLHeadingElement> {

View file

@ -12,7 +12,7 @@ use dom::element::{Element, RawLayoutElementHelpers};
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
#[dom_struct]
@ -21,14 +21,14 @@ pub struct HTMLHRElement {
}
impl HTMLHRElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLHRElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLHRElement {
HTMLHRElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document)
}
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLHRElement> {
Node::reflect_node(box HTMLHRElement::new_inherited(local_name, prefix, document),
@ -67,7 +67,7 @@ impl HTMLHRLayoutHelpers for LayoutJS<HTMLHRElement> {
fn get_color(&self) -> Option<RGBA> {
unsafe {
(&*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("color"))
.get_attr_for_layout(&ns!(), &local_name!("color"))
.and_then(AttrValue::as_color)
.cloned()
}
@ -77,7 +77,7 @@ impl HTMLHRLayoutHelpers for LayoutJS<HTMLHRElement> {
fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe {
(&*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("width"))
.get_attr_for_layout(&ns!(), &local_name!("width"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
@ -91,11 +91,11 @@ impl VirtualMethods for HTMLHRElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("align") => AttrValue::from_dimension(value.into()),
&atom!("color") => AttrValue::from_legacy_color(value.into()),
&atom!("width") => AttrValue::from_dimension(value.into()),
&local_name!("align") => AttrValue::from_dimension(value.into()),
&local_name!("color") => AttrValue::from_legacy_color(value.into()),
&local_name!("width") => AttrValue::from_dimension(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLHtmlElement {
@ -16,14 +16,14 @@ pub struct HTMLHtmlElement {
}
impl HTMLHtmlElement {
fn new_inherited(localName: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLHtmlElement {
fn new_inherited(localName: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLHtmlElement {
HTMLHtmlElement {
htmlelement: HTMLElement::new_inherited(localName, prefix, document)
}
}
#[allow(unrooted_must_root)]
pub fn new(localName: Atom,
pub fn new(localName: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLHtmlElement> {
Node::reflect_node(box HTMLHtmlElement::new_inherited(localName, prefix, document),

View file

@ -35,6 +35,7 @@ use dom::node::{Node, NodeDamage, UnbindContext, document_from_node, window_from
use dom::urlhelper::UrlHelper;
use dom::virtualmethods::VirtualMethods;
use dom::window::{ReflowReason, Window};
use html5ever_atoms::LocalName;
use ipc_channel::ipc;
use js::jsapi::{JSAutoCompartment, JSContext, MutableHandleValue};
use js::jsval::{NullValue, UndefinedValue};
@ -43,8 +44,8 @@ use net_traits::response::HttpsState;
use script_layout_interface::message::ReflowQueryType;
use script_traits::{IFrameLoadInfo, LoadData, MozBrowserEvent, ScriptMsg as ConstellationMsg};
use script_traits::IFrameSandboxState::{IFrameSandboxed, IFrameUnsandboxed};
use servo_atoms::Atom;
use std::cell::Cell;
use string_cache::Atom;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use style::context::ReflowGoal;
use url::Url;
@ -84,7 +85,7 @@ impl HTMLIFrameElement {
/// step 1.
fn get_url(&self) -> Url {
let element = self.upcast::<Element>();
element.get_attribute(&ns!(), &atom!("src")).and_then(|src| {
element.get_attribute(&ns!(), &local_name!("src")).and_then(|src| {
let url = src.value();
if url.is_empty() {
None
@ -178,7 +179,7 @@ impl HTMLIFrameElement {
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
}
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLIFrameElement {
HTMLIFrameElement {
@ -193,7 +194,7 @@ impl HTMLIFrameElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLIFrameElement> {
Node::reflect_node(box HTMLIFrameElement::new_inherited(local_name, prefix, document),
@ -255,7 +256,7 @@ impl HTMLIFrameElement {
pub fn privatebrowsing(&self) -> bool {
if self.Mozbrowser() {
let element = self.upcast::<Element>();
element.has_attribute(&Atom::from("mozprivatebrowsing"))
element.has_attribute(&LocalName::from("mozprivatebrowsing"))
} else {
false
}
@ -290,7 +291,7 @@ impl HTMLIFrameElementLayoutMethods for LayoutJS<HTMLIFrameElement> {
fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("width"))
.get_attr_for_layout(&ns!(), &local_name!("width"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
@ -301,7 +302,7 @@ impl HTMLIFrameElementLayoutMethods for LayoutJS<HTMLIFrameElement> {
fn get_height(&self) -> LengthOrPercentageOrAuto {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("height"))
.get_attr_for_layout(&ns!(), &local_name!("height"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
@ -425,17 +426,17 @@ pub fn Navigate(iframe: &HTMLIFrameElement, direction: TraversalDirection) -> Er
impl HTMLIFrameElementMethods for HTMLIFrameElement {
// https://html.spec.whatwg.org/multipage/#dom-iframe-src
fn Src(&self) -> DOMString {
self.upcast::<Element>().get_string_attribute(&atom!("src"))
self.upcast::<Element>().get_string_attribute(&local_name!("src"))
}
// https://html.spec.whatwg.org/multipage/#dom-iframe-src
fn SetSrc(&self, src: DOMString) {
self.upcast::<Element>().set_url_attribute(&atom!("src"), src)
self.upcast::<Element>().set_url_attribute(&local_name!("src"), src)
}
// https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
fn Sandbox(&self) -> Root<DOMTokenList> {
self.sandbox.or_init(|| DOMTokenList::new(self.upcast::<Element>(), &atom!("sandbox")))
self.sandbox.or_init(|| DOMTokenList::new(self.upcast::<Element>(), &local_name!("sandbox")))
}
// https://html.spec.whatwg.org/multipage/#dom-iframe-contentwindow
@ -469,7 +470,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
fn Mozbrowser(&self) -> bool {
if window_from_node(self).is_mozbrowser() {
let element = self.upcast::<Element>();
element.has_attribute(&atom!("mozbrowser"))
element.has_attribute(&local_name!("mozbrowser"))
} else {
false
}
@ -478,7 +479,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
fn SetMozbrowser(&self, value: bool) {
let element = self.upcast::<Element>();
element.set_bool_attribute(&atom!("mozbrowser"), value);
element.set_bool_attribute(&local_name!("mozbrowser"), value);
}
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goBack
@ -552,13 +553,13 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
// check-tidy: no specs after this line
fn SetMozprivatebrowsing(&self, value: bool) {
let element = self.upcast::<Element>();
element.set_bool_attribute(&Atom::from("mozprivatebrowsing"), value);
element.set_bool_attribute(&LocalName::from("mozprivatebrowsing"), value);
}
fn Mozprivatebrowsing(&self) -> bool {
if window_from_node(self).is_mozbrowser() {
let element = self.upcast::<Element>();
element.has_attribute(&Atom::from("mozprivatebrowsing"))
element.has_attribute(&LocalName::from("mozprivatebrowsing"))
} else {
false
}
@ -573,7 +574,7 @@ impl VirtualMethods for HTMLIFrameElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
&atom!("sandbox") => {
&local_name!("sandbox") => {
self.sandbox_allowance.set(mutation.new_value(attr).map(|value| {
let mut modes = ALLOW_NOTHING;
for token in value.as_tokens() {
@ -590,7 +591,7 @@ impl VirtualMethods for HTMLIFrameElement {
modes
}));
},
&atom!("src") => {
&local_name!("src") => {
if let AttributeMutation::Set(_) = mutation {
if self.upcast::<Node>().is_in_doc() {
self.process_the_iframe_attributes();
@ -601,11 +602,11 @@ impl VirtualMethods for HTMLIFrameElement {
}
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("sandbox") => AttrValue::from_serialized_tokenlist(value.into()),
&atom!("width") => AttrValue::from_dimension(value.into()),
&atom!("height") => AttrValue::from_dimension(value.into()),
&local_name!("sandbox") => AttrValue::from_serialized_tokenlist(value.into()),
&local_name!("width") => AttrValue::from_dimension(value.into()),
&local_name!("height") => AttrValue::from_dimension(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}

View file

@ -21,6 +21,7 @@ use dom::htmlelement::HTMLElement;
use dom::node::{Node, NodeDamage, document_from_node, window_from_node};
use dom::values::UNSIGNED_LONG_MAX;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use net_traits::image::base::{Image, ImageMetadata};
@ -30,7 +31,6 @@ use script_runtime::ScriptThreadEventCategory::UpdateReplacedElement;
use script_thread::Runnable;
use std::i32;
use std::sync::Arc;
use string_cache::Atom;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use task_source::TaskSource;
use url::Url;
@ -195,7 +195,7 @@ impl HTMLImageElement {
}
}
}
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLImageElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLImageElement {
HTMLImageElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
current_request: DOMRefCell::new(ImageRequest {
@ -216,7 +216,7 @@ impl HTMLImageElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLImageElement> {
Node::reflect_node(box HTMLImageElement::new_inherited(local_name, prefix, document),
@ -228,7 +228,7 @@ impl HTMLImageElement {
width: Option<u32>,
height: Option<u32>) -> Fallible<Root<HTMLImageElement>> {
let document = global.as_window().Document();
let image = HTMLImageElement::new(atom!("img"), None, &document);
let image = HTMLImageElement::new(local_name!("img"), None, &document);
if let Some(w) = width {
image.SetWidth(w);
}
@ -266,7 +266,7 @@ impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> {
fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("width"))
.get_attr_for_layout(&ns!(), &local_name!("width"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
@ -277,7 +277,7 @@ impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> {
fn get_height(&self) -> LengthOrPercentageOrAuto {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("height"))
.get_attr_for_layout(&ns!(), &local_name!("height"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
@ -320,7 +320,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
// https://html.spec.whatwg.org/multipage/#dom-img-width
fn SetWidth(&self, value: u32) {
image_dimension_setter(self.upcast(), atom!("width"), value);
image_dimension_setter(self.upcast(), local_name!("width"), value);
}
// https://html.spec.whatwg.org/multipage/#dom-img-height
@ -332,7 +332,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
// https://html.spec.whatwg.org/multipage/#dom-img-height
fn SetHeight(&self, value: u32) {
image_dimension_setter(self.upcast(), atom!("height"), value);
image_dimension_setter(self.upcast(), local_name!("height"), value);
}
// https://html.spec.whatwg.org/multipage/#dom-img-naturalwidth
@ -415,7 +415,7 @@ impl VirtualMethods for HTMLImageElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
&atom!("src") => {
&local_name!("src") => {
self.update_image(mutation.new_value(attr).map(|value| {
// FIXME(ajeffrey): convert directly from AttrValue to DOMString
(DOMString::from(&**value), document_from_node(self).base_url())
@ -425,17 +425,17 @@ impl VirtualMethods for HTMLImageElement {
}
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("name") => AttrValue::from_atomic(value.into()),
&atom!("width") | &atom!("height") => AttrValue::from_dimension(value.into()),
&atom!("hspace") | &atom!("vspace") => AttrValue::from_u32(value.into(), 0),
&local_name!("name") => AttrValue::from_atomic(value.into()),
&local_name!("width") | &local_name!("height") => AttrValue::from_dimension(value.into()),
&local_name!("hspace") | &local_name!("vspace") => AttrValue::from_u32(value.into(), 0),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
}
fn image_dimension_setter(element: &Element, attr: Atom, value: u32) {
fn image_dimension_setter(element: &Element, attr: LocalName, value: u32) {
// This setter is a bit weird: the IDL type is unsigned long, but it's parsed as
// a dimension for rendering.
let value = if value > UNSIGNED_LONG_MAX {

View file

@ -32,6 +32,7 @@ use dom::node::{document_from_node, window_from_node};
use dom::nodelist::NodeList;
use dom::validation::Validatable;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use ipc_channel::ipc::{self, IpcSender};
use mime_guess;
use msg::constellation_msg::Key;
@ -39,10 +40,10 @@ use net_traits::{CoreResourceMsg, IpcSend};
use net_traits::blob_url_store::get_blob_origin;
use net_traits::filemanager_thread::{FileManagerThreadMsg, FilterPattern};
use script_traits::ScriptMsg as ConstellationMsg;
use servo_atoms::Atom;
use std::borrow::ToOwned;
use std::cell::Cell;
use std::ops::Range;
use string_cache::Atom;
use style::attr::AttrValue;
use style::element_state::*;
use style::str::split_commas;
@ -128,7 +129,7 @@ static DEFAULT_MAX_LENGTH: i32 = -1;
static DEFAULT_MIN_LENGTH: i32 = -1;
impl HTMLInputElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLInputElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLInputElement {
let chan = document.window().upcast::<GlobalScope>().constellation_chan().clone();
HTMLInputElement {
htmlelement:
@ -154,7 +155,7 @@ impl HTMLInputElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLInputElement> {
Node::reflect_node(box HTMLInputElement::new_inherited(local_name, prefix, document),
@ -164,7 +165,7 @@ impl HTMLInputElement {
pub fn type_(&self) -> Atom {
self.upcast::<Element>()
.get_attribute(&ns!(), &atom!("type"))
.get_attribute(&ns!(), &local_name!("type"))
.map_or_else(|| atom!(""), |a| a.value().as_atom().to_owned())
}
@ -209,7 +210,7 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>, default: &str) -> String {
let elem = input.upcast::<Element>();
let value = (*elem.unsafe_get())
.get_attr_val_for_layout(&ns!(), &atom!("value"))
.get_attr_val_for_layout(&ns!(), &local_name!("value"))
.unwrap_or(default);
String::from(value)
}
@ -371,13 +372,13 @@ impl HTMLInputElementMethods for HTMLInputElement {
ValueMode::Value => self.textinput.borrow().get_content(),
ValueMode::Default => {
self.upcast::<Element>()
.get_attribute(&ns!(), &atom!("value"))
.get_attribute(&ns!(), &local_name!("value"))
.map_or(DOMString::from(""),
|a| DOMString::from(a.summarize().value))
}
ValueMode::DefaultOn => {
self.upcast::<Element>()
.get_attribute(&ns!(), &atom!("value"))
.get_attribute(&ns!(), &local_name!("value"))
.map_or(DOMString::from("on"),
|a| DOMString::from(a.summarize().value))
}
@ -407,7 +408,7 @@ impl HTMLInputElementMethods for HTMLInputElement {
}
ValueMode::Default |
ValueMode::DefaultOn => {
self.upcast::<Element>().set_string_attribute(&atom!("value"), value);
self.upcast::<Element>().set_string_attribute(&local_name!("value"), value);
}
ValueMode::Filename => {
if value.is_empty() {
@ -734,7 +735,7 @@ impl HTMLInputElement {
fn radio_group_name(&self) -> Option<Atom> {
//TODO: determine form owner
self.upcast::<Element>()
.get_attribute(&ns!(), &atom!("name"))
.get_attribute(&ns!(), &local_name!("name"))
.map(|name| name.value().as_atom().clone())
}
@ -867,7 +868,7 @@ impl VirtualMethods for HTMLInputElement {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
&atom!("disabled") => {
&local_name!("disabled") => {
let disabled_state = match mutation {
AttributeMutation::Set(None) => true,
AttributeMutation::Set(Some(_)) => {
@ -886,7 +887,7 @@ impl VirtualMethods for HTMLInputElement {
el.set_read_write_state(read_write);
}
},
&atom!("checked") if !self.checked_changed.get() => {
&local_name!("checked") if !self.checked_changed.get() => {
let checked_state = match mutation {
AttributeMutation::Set(None) => true,
AttributeMutation::Set(Some(_)) => {
@ -897,13 +898,13 @@ impl VirtualMethods for HTMLInputElement {
};
self.update_checked_state(checked_state, false);
},
&atom!("size") => {
&local_name!("size") => {
let size = mutation.new_value(attr).map(|value| {
value.as_uint()
});
self.size.set(size.unwrap_or(DEFAULT_INPUT_SIZE));
}
&atom!("type") => {
&local_name!("type") => {
let el = self.upcast::<Element>();
match mutation {
AttributeMutation::Set(_) => {
@ -948,7 +949,7 @@ impl VirtualMethods for HTMLInputElement {
// Step 2
(_, _, ValueMode::Value) if old_value_mode != ValueMode::Value => {
self.SetValue(self.upcast::<Element>()
.get_attribute(&ns!(), &atom!("value"))
.get_attribute(&ns!(), &local_name!("value"))
.map_or(DOMString::from(""),
|a| DOMString::from(a.summarize().value)))
.expect("Failed to set input value on type change to ValueMode::Value.");
@ -987,17 +988,17 @@ impl VirtualMethods for HTMLInputElement {
self.update_placeholder_shown_state();
},
&atom!("value") if !self.value_changed.get() => {
&local_name!("value") if !self.value_changed.get() => {
let value = mutation.new_value(attr).map(|value| (**value).to_owned());
self.textinput.borrow_mut().set_content(
value.map_or(DOMString::new(), DOMString::from));
self.update_placeholder_shown_state();
},
&atom!("name") if self.input_type.get() == InputType::InputRadio => {
&local_name!("name") if self.input_type.get() == InputType::InputRadio => {
self.radio_group_updated(
mutation.new_value(attr).as_ref().map(|name| name.as_atom()));
},
&atom!("maxlength") => {
&local_name!("maxlength") => {
match *attr.value() {
AttrValue::Int(_, value) => {
if value < 0 {
@ -1009,7 +1010,7 @@ impl VirtualMethods for HTMLInputElement {
_ => panic!("Expected an AttrValue::Int"),
}
},
&atom!("minlength") => {
&local_name!("minlength") => {
match *attr.value() {
AttrValue::Int(_, value) => {
if value < 0 {
@ -1021,7 +1022,7 @@ impl VirtualMethods for HTMLInputElement {
_ => panic!("Expected an AttrValue::Int"),
}
},
&atom!("placeholder") => {
&local_name!("placeholder") => {
{
let mut placeholder = self.placeholder.borrow_mut();
placeholder.clear();
@ -1032,7 +1033,7 @@ impl VirtualMethods for HTMLInputElement {
}
self.update_placeholder_shown_state();
},
&atom!("readonly") if self.input_type.get() == InputType::InputText => {
&local_name!("readonly") if self.input_type.get() == InputType::InputText => {
let el = self.upcast::<Element>();
match mutation {
AttributeMutation::Set(_) => {
@ -1047,14 +1048,14 @@ impl VirtualMethods for HTMLInputElement {
}
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("accept") => AttrValue::from_comma_separated_tokenlist(value.into()),
&atom!("name") => AttrValue::from_atomic(value.into()),
&atom!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE),
&atom!("type") => AttrValue::from_atomic(value.into()),
&atom!("maxlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MAX_LENGTH),
&atom!("minlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MIN_LENGTH),
&local_name!("accept") => AttrValue::from_comma_separated_tokenlist(value.into()),
&local_name!("name") => AttrValue::from_atomic(value.into()),
&local_name!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE),
&local_name!("type") => AttrValue::from_atomic(value.into()),
&local_name!("maxlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MAX_LENGTH),
&local_name!("minlength") => AttrValue::from_limited_i32(value.into(), DEFAULT_MIN_LENGTH),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}

View file

@ -16,7 +16,7 @@ use dom::htmlelement::HTMLElement;
use dom::htmlformelement::{FormControl, HTMLFormElement};
use dom::node::{document_from_node, Node};
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use style::attr::AttrValue;
#[dom_struct]
@ -25,7 +25,7 @@ pub struct HTMLLabelElement {
}
impl HTMLLabelElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLLabelElement {
HTMLLabelElement {
@ -35,7 +35,7 @@ impl HTMLLabelElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLLabelElement> {
Node::reflect_node(box HTMLLabelElement::new_inherited(local_name, prefix, document),
@ -102,7 +102,7 @@ impl HTMLLabelElementMethods for HTMLLabelElement {
return None;
}
let for_attr = match self.upcast::<Element>().get_attribute(&ns!(), &atom!("for")) {
let for_attr = match self.upcast::<Element>().get_attribute(&ns!(), &local_name!("for")) {
Some(for_attr) => for_attr,
None => return self.first_labelable_descendant(),
};
@ -121,9 +121,9 @@ impl VirtualMethods for HTMLLabelElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("for") => AttrValue::from_atomic(value.into()),
&local_name!("for") => AttrValue::from_atomic(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}

View file

@ -15,7 +15,7 @@ use dom::htmlfieldsetelement::HTMLFieldSetElement;
use dom::htmlformelement::{HTMLFormElement, FormControl};
use dom::node::{Node, UnbindContext};
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLLegendElement {
@ -23,7 +23,7 @@ pub struct HTMLLegendElement {
}
impl HTMLLegendElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document)
-> HTMLLegendElement {
@ -31,7 +31,7 @@ impl HTMLLegendElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document)
-> Root<HTMLLegendElement> {

View file

@ -11,7 +11,7 @@ use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use style::attr::AttrValue;
#[dom_struct]
@ -20,14 +20,14 @@ pub struct HTMLLIElement {
}
impl HTMLLIElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLLIElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLLIElement {
HTMLLIElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document)
}
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLLIElement> {
Node::reflect_node(box HTMLLIElement::new_inherited(local_name, prefix, document),
@ -49,9 +49,9 @@ impl VirtualMethods for HTMLLIElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("value") => AttrValue::from_i32(value.into(), 0),
&local_name!("value") => AttrValue::from_i32(value.into(), 0),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}

View file

@ -24,6 +24,7 @@ use dom::node::{Node, document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use encoding::EncodingRef;
use encoding::all::UTF_8;
use html5ever_atoms::LocalName;
use hyper::header::ContentType;
use hyper::mime::{Mime, TopLevel, SubLevel};
use hyper_serde::Serde;
@ -41,7 +42,6 @@ use std::cell::Cell;
use std::default::Default;
use std::mem;
use std::sync::{Arc, Mutex};
use string_cache::Atom;
use style::attr::AttrValue;
use style::media_queries::{MediaQueryList, parse_media_query_list};
use style::parser::ParserContextExtraData;
@ -63,7 +63,7 @@ pub struct HTMLLinkElement {
}
impl HTMLLinkElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document,
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document,
creator: ElementCreator) -> HTMLLinkElement {
HTMLLinkElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
@ -74,7 +74,7 @@ impl HTMLLinkElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document,
creator: ElementCreator) -> Root<HTMLLinkElement> {
@ -88,7 +88,7 @@ impl HTMLLinkElement {
}
}
fn get_attr(element: &Element, local_name: &Atom) -> Option<String> {
fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> {
let elem = element.get_attribute(&ns!(), local_name);
elem.map(|e| {
let value = e.value();
@ -139,26 +139,26 @@ impl VirtualMethods for HTMLLinkElement {
return;
}
let rel = get_attr(self.upcast(), &atom!("rel"));
let rel = get_attr(self.upcast(), &local_name!("rel"));
match attr.local_name() {
&atom!("href") => {
&local_name!("href") => {
if string_is_stylesheet(&rel) {
self.handle_stylesheet_url(&attr.value());
} else if is_favicon(&rel) {
let sizes = get_attr(self.upcast(), &atom!("sizes"));
let sizes = get_attr(self.upcast(), &local_name!("sizes"));
self.handle_favicon_url(rel.as_ref().unwrap(), &attr.value(), &sizes);
}
},
&atom!("sizes") => {
&local_name!("sizes") => {
if is_favicon(&rel) {
if let Some(ref href) = get_attr(self.upcast(), &atom!("href")) {
if let Some(ref href) = get_attr(self.upcast(), &local_name!("href")) {
self.handle_favicon_url(rel.as_ref().unwrap(), href, &Some(attr.value().to_string()));
}
}
},
&atom!("media") => {
&local_name!("media") => {
if string_is_stylesheet(&rel) {
if let Some(href) = self.upcast::<Element>().get_attribute(&ns!(), &atom!("href")) {
if let Some(href) = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href")) {
self.handle_stylesheet_url(&href.value());
}
}
@ -167,9 +167,9 @@ impl VirtualMethods for HTMLLinkElement {
}
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("rel") => AttrValue::from_serialized_tokenlist(value.into()),
&local_name!("rel") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
@ -182,9 +182,9 @@ impl VirtualMethods for HTMLLinkElement {
if tree_in_doc {
let element = self.upcast();
let rel = get_attr(element, &atom!("rel"));
let href = get_attr(element, &atom!("href"));
let sizes = get_attr(self.upcast(), &atom!("sizes"));
let rel = get_attr(element, &local_name!("rel"));
let href = get_attr(element, &local_name!("href"));
let sizes = get_attr(self.upcast(), &local_name!("sizes"));
match href {
Some(ref href) if string_is_stylesheet(&rel) => {
@ -221,7 +221,7 @@ impl HTMLLinkElement {
let element = self.upcast::<Element>();
let mq_attribute = element.get_attribute(&ns!(), &atom!("media"));
let mq_attribute = element.get_attribute(&ns!(), &local_name!("media"));
let value = mq_attribute.r().map(|a| a.value());
let mq_str = match value {
Some(ref value) => &***value,
@ -398,7 +398,7 @@ impl HTMLLinkElementMethods for HTMLLinkElement {
// https://html.spec.whatwg.org/multipage/#dom-link-rel
fn SetRel(&self, rel: DOMString) {
self.upcast::<Element>().set_tokenlist_attribute(&atom!("rel"), rel);
self.upcast::<Element>().set_tokenlist_attribute(&local_name!("rel"), rel);
}
// https://html.spec.whatwg.org/multipage/#dom-link-media
@ -421,7 +421,7 @@ impl HTMLLinkElementMethods for HTMLLinkElement {
// https://html.spec.whatwg.org/multipage/#dom-link-rellist
fn RelList(&self) -> Root<DOMTokenList> {
self.rel_list.or_init(|| DOMTokenList::new(self.upcast(), &atom!("rel")))
self.rel_list.or_init(|| DOMTokenList::new(self.upcast(), &local_name!("rel")))
}
// https://html.spec.whatwg.org/multipage/#dom-link-charset

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLMapElement {
@ -16,7 +16,7 @@ pub struct HTMLMapElement {
}
impl HTMLMapElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLMapElement {
HTMLMapElement {
@ -25,7 +25,7 @@ impl HTMLMapElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLMapElement> {
Node::reflect_node(box HTMLMapElement::new_inherited(local_name, prefix, document),

View file

@ -27,15 +27,16 @@ use dom::htmlvideoelement::HTMLVideoElement;
use dom::mediaerror::MediaError;
use dom::node::{window_from_node, document_from_node, Node, UnbindContext};
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use net_traits::{FetchResponseListener, FetchMetadata, Metadata, NetworkError};
use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType};
use network_listener::{NetworkListener, PreInvoke};
use script_thread::{Runnable, ScriptThread};
use servo_atoms::Atom;
use std::cell::Cell;
use std::sync::{Arc, Mutex};
use string_cache::Atom;
use task_source::TaskSource;
use time::{self, Timespec, Duration};
use url::Url;
@ -224,7 +225,7 @@ pub struct HTMLMediaElement {
}
impl HTMLMediaElement {
pub fn new_inherited(tag_name: Atom,
pub fn new_inherited(tag_name: LocalName,
prefix: Option<DOMString>, document: &Document)
-> HTMLMediaElement {
HTMLMediaElement {
@ -443,7 +444,7 @@ impl HTMLMediaElement {
let mode = if false {
// TODO media provider object
ResourceSelectionMode::Object
} else if let Some(attr) = self.upcast::<Element>().get_attribute(&ns!(), &atom!("src")) {
} else if let Some(attr) = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("src")) {
ResourceSelectionMode::Attribute(attr.Value().to_string())
} else if false {
// TODO <source> child
@ -770,7 +771,7 @@ impl VirtualMethods for HTMLMediaElement {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
&atom!("src") => {
&local_name!("src") => {
if mutation.new_value(attr).is_some() {
self.media_element_load_algorithm();
}

View file

@ -16,10 +16,10 @@ use dom::htmlelement::HTMLElement;
use dom::htmlheadelement::HTMLHeadElement;
use dom::node::{Node, UnbindContext, document_from_node};
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use parking_lot::RwLock;
use std::ascii::AsciiExt;
use std::sync::Arc;
use string_cache::Atom;
use style::attr::AttrValue;
use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::{Stylesheet, CSSRule, Origin};
@ -33,7 +33,7 @@ pub struct HTMLMetaElement {
}
impl HTMLMetaElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLMetaElement {
HTMLMetaElement {
@ -43,7 +43,7 @@ impl HTMLMetaElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLMetaElement> {
Node::reflect_node(box HTMLMetaElement::new_inherited(local_name, prefix, document),
@ -57,7 +57,7 @@ impl HTMLMetaElement {
fn process_attributes(&self) {
let element = self.upcast::<Element>();
if let Some(name) = element.get_attribute(&ns!(), &atom!("name")).r() {
if let Some(name) = element.get_attribute(&ns!(), &local_name!("name")).r() {
let name = name.value().to_ascii_lowercase();
let name = name.trim_matches(HTML_SPACE_CHARACTERS);
@ -76,7 +76,7 @@ impl HTMLMetaElement {
return;
}
let element = self.upcast::<Element>();
if let Some(content) = element.get_attribute(&ns!(), &atom!("content")).r() {
if let Some(content) = element.get_attribute(&ns!(), &local_name!("content")).r() {
let content = content.value();
if !content.is_empty() {
if let Some(translated_rule) = ViewportRule::from_meta(&**content) {
@ -97,7 +97,7 @@ impl HTMLMetaElement {
fn process_referrer_attribute(&self) {
let element = self.upcast::<Element>();
if let Some(name) = element.get_attribute(&ns!(), &atom!("name")).r() {
if let Some(name) = element.get_attribute(&ns!(), &local_name!("name")).r() {
let name = name.value().to_ascii_lowercase();
let name = name.trim_matches(HTML_SPACE_CHARACTERS);
@ -146,9 +146,9 @@ impl VirtualMethods for HTMLMetaElement {
}
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&atom!("name") => AttrValue::from_atomic(value.into()),
&local_name!("name") => AttrValue::from_atomic(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}

View file

@ -10,7 +10,7 @@ use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom::nodelist::NodeList;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLMeterElement {
@ -18,7 +18,7 @@ pub struct HTMLMeterElement {
}
impl HTMLMeterElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLMeterElement {
HTMLMeterElement {
@ -27,7 +27,7 @@ impl HTMLMeterElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLMeterElement> {
Node::reflect_node(box HTMLMeterElement::new_inherited(local_name, prefix, document),

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLModElement {
@ -16,7 +16,7 @@ pub struct HTMLModElement {
}
impl HTMLModElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLModElement {
HTMLModElement {
@ -26,7 +26,7 @@ impl HTMLModElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLModElement> {
Node::reflect_node(box HTMLModElement::new_inherited(local_name, prefix, document),

View file

@ -17,9 +17,9 @@ use dom::node::{Node, window_from_node};
use dom::validation::Validatable;
use dom::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use net_traits::image::base::Image;
use std::sync::Arc;
use string_cache::Atom;
#[dom_struct]
pub struct HTMLObjectElement {
@ -29,7 +29,7 @@ pub struct HTMLObjectElement {
}
impl HTMLObjectElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLObjectElement {
HTMLObjectElement {
@ -40,7 +40,7 @@ impl HTMLObjectElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLObjectElement> {
Node::reflect_node(box HTMLObjectElement::new_inherited(local_name, prefix, document),
@ -60,8 +60,8 @@ impl<'a> ProcessDataURL for &'a HTMLObjectElement {
let elem = self.upcast::<Element>();
// TODO: support other values
match (elem.get_attribute(&ns!(), &atom!("type")),
elem.get_attribute(&ns!(), &atom!("data"))) {
match (elem.get_attribute(&ns!(), &local_name!("type")),
elem.get_attribute(&ns!(), &local_name!("data"))) {
(None, Some(_uri)) => {
// TODO(gw): Prefetch the image here.
}
@ -99,7 +99,7 @@ impl VirtualMethods for HTMLObjectElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
&atom!("data") => {
&local_name!("data") => {
if let AttributeMutation::Set(_) = mutation {
self.process_data_url();
}

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLOListElement {
@ -16,7 +16,7 @@ pub struct HTMLOListElement {
}
impl HTMLOListElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLOListElement {
HTMLOListElement {
@ -25,7 +25,7 @@ impl HTMLOListElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLOListElement> {
Node::reflect_node(box HTMLOListElement::new_inherited(local_name, prefix, document),

View file

@ -14,7 +14,7 @@ use dom::htmlelement::HTMLElement;
use dom::htmloptionelement::HTMLOptionElement;
use dom::node::Node;
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use style::element_state::*;
#[dom_struct]
@ -23,7 +23,7 @@ pub struct HTMLOptGroupElement {
}
impl HTMLOptGroupElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLOptGroupElement {
HTMLOptGroupElement {
@ -34,7 +34,7 @@ impl HTMLOptGroupElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLOptGroupElement> {
Node::reflect_node(box HTMLOptGroupElement::new_inherited(local_name, prefix, document),
@ -59,7 +59,7 @@ impl VirtualMethods for HTMLOptGroupElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
&atom!("disabled") => {
&local_name!("disabled") => {
let disabled_state = match mutation {
AttributeMutation::Set(None) => true,
AttributeMutation::Set(Some(_)) => {

View file

@ -22,8 +22,8 @@ use dom::htmlselectelement::HTMLSelectElement;
use dom::node::{Node, UnbindContext};
use dom::text::Text;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use std::cell::Cell;
use string_cache::Atom;
use style::element_state::*;
use style::str::{split_html_space_chars, str_join};
@ -39,7 +39,7 @@ pub struct HTMLOptionElement {
}
impl HTMLOptionElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLOptionElement {
HTMLOptionElement {
@ -52,7 +52,7 @@ impl HTMLOptionElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLOptionElement> {
Node::reflect_node(box HTMLOptionElement::new_inherited(local_name, prefix, document),
@ -82,7 +82,7 @@ impl HTMLOptionElement {
// FIXME(ajeffrey): Provide a way of buffering DOMStrings other than using Strings
fn collect_text(element: &Element, value: &mut String) {
let svg_script = *element.namespace() == ns!(svg) && element.local_name() == &atom!("script");
let svg_script = *element.namespace() == ns!(svg) && element.local_name() == &local_name!("script");
let html_script = element.is::<HTMLScriptElement>();
if svg_script || html_script {
return;
@ -133,7 +133,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
// https://html.spec.whatwg.org/multipage/#attr-option-value
fn Value(&self) -> DOMString {
let element = self.upcast::<Element>();
let attr = &atom!("value");
let attr = &local_name!("value");
if element.has_attribute(attr) {
element.get_string_attribute(attr)
} else {
@ -147,7 +147,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
// https://html.spec.whatwg.org/multipage/#attr-option-label
fn Label(&self) -> DOMString {
let element = self.upcast::<Element>();
let attr = &atom!("label");
let attr = &local_name!("label");
if element.has_attribute(attr) {
element.get_string_attribute(attr)
} else {
@ -185,7 +185,7 @@ impl VirtualMethods for HTMLOptionElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
&atom!("disabled") => {
&local_name!("disabled") => {
let el = self.upcast::<Element>();
match mutation {
AttributeMutation::Set(_) => {
@ -199,7 +199,7 @@ impl VirtualMethods for HTMLOptionElement {
}
}
},
&atom!("selected") => {
&local_name!("selected") => {
match mutation {
AttributeMutation::Set(_) => {
// https://html.spec.whatwg.org/multipage/#concept-option-selectedness

View file

@ -44,7 +44,7 @@ impl HTMLOptionsCollection {
let document = document_from_node(&*root);
for _ in 0..count {
let element = HTMLOptionElement::new(atom!("option"), None, &document);
let element = HTMLOptionElement::new(local_name!("option"), None, &document);
let node = element.upcast::<Node>();
try!(root.AppendChild(node));
};

View file

@ -13,7 +13,7 @@ use dom::htmlformelement::{FormControl, HTMLFormElement};
use dom::node::{Node, window_from_node};
use dom::nodelist::NodeList;
use dom::validitystate::ValidityState;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLOutputElement {
@ -21,7 +21,7 @@ pub struct HTMLOutputElement {
}
impl HTMLOutputElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLOutputElement {
HTMLOutputElement {
@ -31,7 +31,7 @@ impl HTMLOutputElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLOutputElement> {
Node::reflect_node(box HTMLOutputElement::new_inherited(local_name, prefix, document),

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLParagraphElement {
@ -16,7 +16,7 @@ pub struct HTMLParagraphElement {
}
impl HTMLParagraphElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLParagraphElement {
HTMLParagraphElement {
@ -26,7 +26,7 @@ impl HTMLParagraphElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLParagraphElement> {
Node::reflect_node(box HTMLParagraphElement::new_inherited(local_name, prefix, document),

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLParamElement {
@ -16,7 +16,7 @@ pub struct HTMLParamElement {
}
impl HTMLParamElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLParamElement {
HTMLParamElement {
@ -26,7 +26,7 @@ impl HTMLParamElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLParamElement> {
Node::reflect_node(box HTMLParamElement::new_inherited(local_name, prefix, document),

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLPreElement {
@ -16,7 +16,7 @@ pub struct HTMLPreElement {
}
impl HTMLPreElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLPreElement {
HTMLPreElement {
@ -26,7 +26,7 @@ impl HTMLPreElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLPreElement> {
Node::reflect_node(box HTMLPreElement::new_inherited(local_name, prefix, document),

View file

@ -10,7 +10,7 @@ use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom::nodelist::NodeList;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLProgressElement {
@ -18,7 +18,7 @@ pub struct HTMLProgressElement {
}
impl HTMLProgressElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLProgressElement {
HTMLProgressElement {
@ -28,7 +28,7 @@ impl HTMLProgressElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLProgressElement> {
Node::reflect_node(box HTMLProgressElement::new_inherited(local_name, prefix, document),

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLQuoteElement {
@ -16,7 +16,7 @@ pub struct HTMLQuoteElement {
}
impl HTMLQuoteElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLQuoteElement {
HTMLQuoteElement {
@ -26,7 +26,7 @@ impl HTMLQuoteElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLQuoteElement> {
Node::reflect_node(box HTMLQuoteElement::new_inherited(local_name, prefix, document),

View file

@ -28,16 +28,17 @@ use dom::virtualmethods::VirtualMethods;
use encoding::label::encoding_from_whatwg_label;
use encoding::types::{DecoderTrap, EncodingRef};
use html5ever::tree_builder::NextParserState;
use html5ever_atoms::LocalName;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use js::jsval::UndefinedValue;
use net_traits::{FetchMetadata, FetchResponseListener, Metadata, NetworkError};
use net_traits::request::{CORSSettings, CredentialsMode, Destination, RequestInit, RequestMode, Type as RequestType};
use network_listener::{NetworkListener, PreInvoke};
use servo_atoms::Atom;
use std::ascii::AsciiExt;
use std::cell::Cell;
use std::sync::{Arc, Mutex};
use string_cache::Atom;
use style::str::{HTML_SPACE_CHARACTERS, StaticStringVec};
use url::Url;
@ -67,7 +68,7 @@ pub struct HTMLScriptElement {
}
impl HTMLScriptElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document,
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document,
creator: ElementCreator) -> HTMLScriptElement {
HTMLScriptElement {
htmlelement:
@ -82,7 +83,7 @@ impl HTMLScriptElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom, prefix: Option<DOMString>, document: &Document,
pub fn new(local_name: LocalName, prefix: Option<DOMString>, document: &Document,
creator: ElementCreator) -> Root<HTMLScriptElement> {
Node::reflect_node(box HTMLScriptElement::new_inherited(local_name, prefix, document, creator),
document,
@ -286,7 +287,7 @@ impl HTMLScriptElement {
// Step 3.
let element = self.upcast::<Element>();
let async = element.has_attribute(&atom!("async"));
let async = element.has_attribute(&local_name!("async"));
// Note: confusingly, this is done if the element does *not* have an "async" attribute.
if was_parser_inserted && !async {
self.non_blocking.set(true);
@ -294,7 +295,7 @@ impl HTMLScriptElement {
// Step 4.
let text = self.Text();
if text.is_empty() && !element.has_attribute(&atom!("src")) {
if text.is_empty() && !element.has_attribute(&local_name!("src")) {
return NextParserState::Continue;
}
@ -331,8 +332,8 @@ impl HTMLScriptElement {
// TODO(#4577): Step 11: CSP.
// Step 12.
let for_attribute = element.get_attribute(&ns!(), &atom!("for"));
let event_attribute = element.get_attribute(&ns!(), &atom!("event"));
let for_attribute = element.get_attribute(&ns!(), &local_name!("for"));
let event_attribute = element.get_attribute(&ns!(), &local_name!("event"));
match (for_attribute.r(), event_attribute.r()) {
(Some(for_attribute), Some(event_attribute)) => {
let for_value = for_attribute.value().to_ascii_lowercase();
@ -351,7 +352,7 @@ impl HTMLScriptElement {
}
// Step 13.
let encoding = element.get_attribute(&ns!(), &atom!("charset"))
let encoding = element.get_attribute(&ns!(), &local_name!("charset"))
.and_then(|charset| encoding_from_whatwg_label(&charset.value()))
.unwrap_or_else(|| doc.encoding());
@ -370,7 +371,7 @@ impl HTMLScriptElement {
// TODO: Step 17: environment settings object.
let base_url = doc.base_url();
let is_external = match element.get_attribute(&ns!(), &atom!("src")) {
let is_external = match element.get_attribute(&ns!(), &local_name!("src")) {
// Step 18.
Some(ref src) => {
// Step 18.1.
@ -402,7 +403,7 @@ impl HTMLScriptElement {
};
// Step 20.
let deferred = element.has_attribute(&atom!("defer"));
let deferred = element.has_attribute(&local_name!("defer"));
// Step 20.a: classic, has src, has defer, was parser-inserted, is not async.
if is_external &&
deferred &&
@ -555,7 +556,7 @@ impl HTMLScriptElement {
pub fn is_javascript(&self) -> bool {
let element = self.upcast::<Element>();
let type_attr = element.get_attribute(&ns!(), &atom!("type"));
let type_attr = element.get_attribute(&ns!(), &local_name!("type"));
let is_js = match type_attr.as_ref().map(|s| s.value()) {
Some(ref s) if s.is_empty() => {
// type attr exists, but empty means js
@ -568,7 +569,7 @@ impl HTMLScriptElement {
},
None => {
debug!("no script type");
let language_attr = element.get_attribute(&ns!(), &atom!("language"));
let language_attr = element.get_attribute(&ns!(), &local_name!("language"));
let is_js = match language_attr.as_ref().map(|s| s.value()) {
Some(ref s) if s.is_empty() => {
debug!("script language empty, inferring js");
@ -615,7 +616,7 @@ impl VirtualMethods for HTMLScriptElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match *attr.local_name() {
atom!("src") => {
local_name!("src") => {
if let AttributeMutation::Set(_) = mutation {
if !self.parser_inserted.get() && self.upcast::<Node>().is_in_doc() {
self.prepare();
@ -692,7 +693,7 @@ impl HTMLScriptElementMethods for HTMLScriptElement {
// https://html.spec.whatwg.org/multipage/#dom-script-crossorigin
fn GetCrossOrigin(&self) -> Option<DOMString> {
let element = self.upcast::<Element>();
let attr = element.get_attribute(&ns!(), &atom!("crossorigin"));
let attr = element.get_attribute(&ns!(), &local_name!("crossorigin"));
if let Some(mut val) = attr.map(|v| v.Value()) {
val.make_ascii_lowercase();
@ -708,9 +709,9 @@ impl HTMLScriptElementMethods for HTMLScriptElement {
fn SetCrossOrigin(&self, value: Option<DOMString>) {
let element = self.upcast::<Element>();
match value {
Some(val) => element.set_string_attribute(&atom!("crossorigin"), val),
Some(val) => element.set_string_attribute(&local_name!("crossorigin"), val),
None => {
element.remove_attribute(&ns!(), &atom!("crossorigin"));
element.remove_attribute(&ns!(), &local_name!("crossorigin"));
}
}
}

View file

@ -30,7 +30,7 @@ use dom::nodelist::NodeList;
use dom::validation::Validatable;
use dom::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use style::attr::AttrValue;
use style::element_state::*;
@ -64,7 +64,7 @@ pub struct HTMLSelectElement {
static DEFAULT_SELECT_SIZE: u32 = 0;
impl HTMLSelectElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLSelectElement {
HTMLSelectElement {
@ -76,7 +76,7 @@ impl HTMLSelectElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLSelectElement> {
Node::reflect_node(box HTMLSelectElement::new_inherited(local_name, prefix, document),
@ -338,7 +338,7 @@ impl VirtualMethods for HTMLSelectElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
if attr.local_name() == &atom!("disabled") {
if attr.local_name() == &local_name!("disabled") {
let el = self.upcast::<Element>();
match mutation {
AttributeMutation::Set(_) => {
@ -374,9 +374,9 @@ impl VirtualMethods for HTMLSelectElement {
}
}
fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue {
match *local_name {
atom!("size") => AttrValue::from_u32(value.into(), DEFAULT_SELECT_SIZE),
local_name!("size") => AttrValue::from_u32(value.into(), DEFAULT_SELECT_SIZE),
_ => self.super_type().unwrap().parse_plain_attribute(local_name, value),
}
}

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLSourceElement {
@ -16,7 +16,7 @@ pub struct HTMLSourceElement {
}
impl HTMLSourceElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLSourceElement {
HTMLSourceElement {
@ -26,7 +26,7 @@ impl HTMLSourceElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLSourceElement> {
Node::reflect_node(box HTMLSourceElement::new_inherited(local_name, prefix, document),

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLSpanElement {
@ -16,14 +16,14 @@ pub struct HTMLSpanElement {
}
impl HTMLSpanElement {
fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLSpanElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLSpanElement {
HTMLSpanElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document)
}
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLSpanElement> {
Node::reflect_node(box HTMLSpanElement::new_inherited(local_name, prefix, document),

View file

@ -14,9 +14,9 @@ use dom::element::Element;
use dom::htmlelement::HTMLElement;
use dom::node::{ChildrenMutation, Node, document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use script_layout_interface::message::Msg;
use std::sync::Arc;
use string_cache::Atom;
use style::media_queries::parse_media_query_list;
use style::parser::ParserContextExtraData;
use style::stylesheets::{Stylesheet, Origin};
@ -29,7 +29,7 @@ pub struct HTMLStyleElement {
}
impl HTMLStyleElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLStyleElement {
HTMLStyleElement {
@ -39,7 +39,7 @@ impl HTMLStyleElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLStyleElement> {
Node::reflect_node(box HTMLStyleElement::new_inherited(local_name, prefix, document),
@ -55,7 +55,7 @@ impl HTMLStyleElement {
let win = window_from_node(node);
let url = win.get_url();
let mq_attribute = element.get_attribute(&ns!(), &atom!("media"));
let mq_attribute = element.get_attribute(&ns!(), &local_name!("media"));
let mq_str = match mq_attribute {
Some(a) => String::from(&**a.value()),
None => String::new(),

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLTableCaptionElement {
@ -16,7 +16,7 @@ pub struct HTMLTableCaptionElement {
}
impl HTMLTableCaptionElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLTableCaptionElement {
HTMLTableCaptionElement {
@ -26,7 +26,7 @@ impl HTMLTableCaptionElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLTableCaptionElement> {
Node::reflect_node(box HTMLTableCaptionElement::new_inherited(local_name, prefix, document),

View file

@ -14,7 +14,7 @@ use dom::htmlelement::HTMLElement;
use dom::htmltablerowelement::HTMLTableRowElement;
use dom::node::Node;
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use html5ever_atoms::LocalName;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
const DEFAULT_COLSPAN: u32 = 1;
@ -25,7 +25,7 @@ pub struct HTMLTableCellElement {
}
impl HTMLTableCellElement {
pub fn new_inherited(tag_name: Atom,
pub fn new_inherited(tag_name: LocalName,
prefix: Option<DOMString>,
document: &Document)
-> HTMLTableCellElement {
@ -88,7 +88,7 @@ impl HTMLTableCellElementLayoutHelpers for LayoutJS<HTMLTableCellElement> {
fn get_background_color(&self) -> Option<RGBA> {
unsafe {
(&*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("bgcolor"))
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
.and_then(AttrValue::as_color)
.cloned()
}
@ -97,7 +97,7 @@ impl HTMLTableCellElementLayoutHelpers for LayoutJS<HTMLTableCellElement> {
fn get_colspan(&self) -> Option<u32> {
unsafe {
(&*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("colspan"))
.get_attr_for_layout(&ns!(), &local_name!("colspan"))
.map(AttrValue::as_uint)
}
}
@ -105,7 +105,7 @@ impl HTMLTableCellElementLayoutHelpers for LayoutJS<HTMLTableCellElement> {
fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe {
(&*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(), &atom!("width"))
.get_attr_for_layout(&ns!(), &local_name!("width"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
@ -118,11 +118,11 @@ impl VirtualMethods for HTMLTableCellElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue {
fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue {
match *local_name {
atom!("colspan") => AttrValue::from_u32(value.into(), DEFAULT_COLSPAN),
atom!("bgcolor") => AttrValue::from_legacy_color(value.into()),
atom!("width") => AttrValue::from_nonzero_dimension(value.into()),
local_name!("colspan") => AttrValue::from_u32(value.into(), DEFAULT_COLSPAN),
local_name!("bgcolor") => AttrValue::from_legacy_color(value.into()),
local_name!("width") => AttrValue::from_nonzero_dimension(value.into()),
_ => self.super_type().unwrap().parse_plain_attribute(local_name, value),
}
}

View file

@ -8,7 +8,7 @@ use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use string_cache::Atom;
use html5ever_atoms::LocalName;
#[dom_struct]
pub struct HTMLTableColElement {
@ -16,7 +16,7 @@ pub struct HTMLTableColElement {
}
impl HTMLTableColElement {
fn new_inherited(local_name: Atom,
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> HTMLTableColElement {
HTMLTableColElement {
@ -26,7 +26,7 @@ impl HTMLTableColElement {
}
#[allow(unrooted_must_root)]
pub fn new(local_name: Atom,
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLTableColElement> {
Node::reflect_node(box HTMLTableColElement::new_inherited(local_name, prefix, document),

Some files were not shown because too many files have changed in this diff Show more