Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Document.createElementNS() #1391

Closed
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b3aaa4b
Document.creatElementNS() and reftest
therealglazou Dec 12, 2013
6666929
merge upstream
therealglazou Feb 21, 2014
4f8acae
Merge remote-tracking branch 'upstream/master' into therealglazou/cre…
therealglazou Feb 21, 2014
28933b1
new version of Document.createElementNS
therealglazou Feb 21, 2014
9f0e696
De-@mut pipeline
larsbergstrom Feb 11, 2014
2ec9649
Shut down the profiler in headless compositing mode
pcwalton Feb 21, 2014
4fe305c
Prevent '&nbsp' from stripping as whitespace
june0cho Feb 21, 2014
26cd50d
Fix: whitespace is considered as spaces(U+0020), tabs(U+0009), and li…
june0cho Feb 21, 2014
735d826
De-@mut the FrameTree.
larsbergstrom Feb 14, 2014
d39f028
Update rust-layers submodule
larsbergstrom Feb 19, 2014
998a561
Remove commented-out parts of Document.webidl and HTMLDocument.webidl.
Ms2ger Feb 22, 2014
f345b69
Create a Line DisplayItem
ngsankha Feb 17, 2014
a8716ad
add Element::new
therealglazou Feb 24, 2014
b4d5184
trailing ws
therealglazou Feb 24, 2014
99f02d1
reuse get_attribute_parts
therealglazou Feb 24, 2014
d5a5fb6
no lowercasing for html element names
therealglazou Feb 24, 2014
0f764df
adding comment with spec URL
therealglazou Feb 24, 2014
77bd9b0
simplify match in CreateElementNS
therealglazou Feb 24, 2014
916c5d1
simplify match in CreateElementNS
therealglazou Feb 24, 2014
f1d60a7
simplify namespace error cases
therealglazou Feb 24, 2014
575c25e
simplify namespace error cases
therealglazou Feb 24, 2014
1308285
remove the ': Namesapce'
therealglazou Feb 24, 2014
3c28d06
better test
therealglazou Feb 24, 2014
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Document.creatElementNS() and reftest

  • Loading branch information
therealglazou committed Dec 12, 2013
commit b3aaa4b6dd03df0785e9ef748636e48e146ed28a
@@ -154,6 +154,7 @@ DOMInterfaces = {
'createComment',
'createDocumentFragment',
'createElement',
'createElementNS',
'createTextNode',
'title',
],
@@ -309,6 +310,7 @@ DOMInterfaces = {
'appendChild',
'nodeName',
'nodeValue',
'namespaceURI',
'removeChild',
'textContent',
'childNodes'
@@ -42,8 +42,8 @@ interface Document : Node {

[Creator, Throws]
Element createElement(DOMString localName);
// [Creator, Throws]
// Element createElementNS(DOMString? namespace, DOMString qualifiedName);
[Creator, Throws]
Element createElementNS(DOMString? namespace, DOMString qualifiedName);
[Creator]
DocumentFragment createDocumentFragment();
[Creator]
@@ -3,18 +3,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::comment::Comment;
use dom::bindings::codegen::ElementBinding;
use dom::bindings::codegen::DocumentBinding;
use dom::bindings::utils::{Reflectable, Reflector, Traceable, reflect_dom_object};
use dom::bindings::utils::{ErrorResult, Fallible, NotSupported, InvalidCharacter};
use dom::bindings::utils::{ErrorResult, Fallible, NotSupported, InvalidCharacter, NamespaceError};
use dom::bindings::utils::DOMString;
use dom::bindings::utils::{xml_name_type, InvalidXMLName};
use dom::bindings::utils::{xml_name_type, InvalidXMLName, Name, QName};
use dom::documentfragment::DocumentFragment;
use dom::element::{Element};
use dom::element::{HTMLHeadElementTypeId, HTMLTitleElementTypeId};
use dom::element::{HTMLHeadElementTypeId, HTMLTitleElementTypeId, nonHTMLTypeId};
use dom::event::{AbstractEvent, Event};
use dom::htmlcollection::HTMLCollection;
use dom::htmldocument::HTMLDocument;
use dom::mouseevent::MouseEvent;
use dom::namespace;
use dom::namespace::Namespace;
use dom::node::{AbstractNode, ScriptView, Node, ElementNodeTypeId, DocumentNodeTypeId};
use dom::text::Text;
use dom::uievent::UIEvent;
@@ -201,6 +204,56 @@ impl Document {
Ok(build_element_from_tag(local_name, abstract_self))
}

pub fn CreateElementNS(&self, abstract_self: AbstractDocument, namespace: Option<DOMString>, qualified_name: DOMString) -> Fallible<AbstractNode<ScriptView>> {
let ns: Namespace = Namespace::from_str(namespace);
let mut local_name;
match xml_name_type(qualified_name) {
InvalidXMLName => {
debug!("Not a valid element name");
return Err(InvalidCharacter);
},
Name => {
debug!("Not a valid qualified element name");
return Err(NamespaceError);
},
QName => {
let (prefix_from_qname, local_name_from_qname) = if qualified_name.contains(":") {
let parts: ~[&str] = qualified_name.splitn_iter(':', 1).collect();
(Some(parts[0].to_owned()), parts[1].to_owned())
} else {
(None, qualified_name.clone())
};
match (ns.clone(), prefix_from_qname, local_name_from_qname.clone()) {
(namespace::Null, None, _) => {},
(namespace::Null, _, _) => {
debug!("Namespace can't be null with a non-null prefix");
return Err(NamespaceError);
},
(namespace::XML, Some(~"xml"), _) => {},
(namespace::XML, _, _) => {
debug!("Namespace must be the xml namespace if the prefix is 'xml'");
return Err(NamespaceError);
},
(namespace::XMLNS, Some(~"xmlns"), _) | (namespace::XMLNS, _, ~"xmlns") => {},
(_, Some(~"xmlns"), _) | (_, _, ~"xmlns") => {
debug!("Namespace must be the xmlns namespace if the prefix or the qualified name is 'xmlns'");
return Err(NamespaceError);
},
_ => {}
}
local_name = local_name_from_qname;
}
}

if ns == namespace::HTML {
local_name = local_name.to_ascii_lower();
Ok(build_element_from_tag(local_name, abstract_self))
} else {
let element = Element::new(nonHTMLTypeId, local_name, ns, abstract_self);

This comment has been minimized.

Copy link
@Ms2ger

Ms2ger Dec 13, 2013

Contributor

This is not the new you're looking for. That's my fault; I should have renamed it to new_inherited long ago. However, now that I've fixed that, you'll need to write a new new, which calls new_inherited and reflects.

Ok(Node::reflect_node(@mut element, abstract_self, ElementBinding::Wrap))
}
}

pub fn CreateDocumentFragment(&self, abstract_self: AbstractDocument) -> AbstractNode<ScriptView> {
DocumentFragment::new(abstract_self)
}
@@ -117,6 +117,8 @@ pub enum ElementTypeId {
HTMLUListElementTypeId,
HTMLVideoElementTypeId,
HTMLUnknownElementTypeId,

nonHTMLTypeId,

This comment has been minimized.

Copy link
@Ms2ger

Ms2ger Dec 13, 2013

Contributor

I'd call it ElementTypeId, as Element is the most-derived class.

}

//
@@ -21,7 +21,7 @@ use dom::text::Text;

use js::jsapi::{JSObject, JSContext};
use servo_util::slot::{MutSlotRef, Slot, SlotRef};
use servo_util::tree::{TreeNode, TreeNodeRef, TreeNodeRefAsElement};
use servo_util::tree::{TreeNode, TreeNodeRef, TreeNodeRefAsElement, ElementLike};
use std::cast::transmute;
use std::cast;
use std::unstable::raw::Box;
@@ -1177,8 +1177,19 @@ impl Node<ScriptView> {
false
}

pub fn GetNamespaceURI(&self) -> Option<DOMString> {
None
pub fn GetNamespaceURI(&self, abstract_self: AbstractNode<ScriptView>) -> Option<DOMString> {

This comment has been minimized.

Copy link
@Ms2ger

Ms2ger Dec 12, 2013

Contributor

This should live on Element, not Node.

match self.type_id {
ElementNodeTypeId(*) => {
do abstract_self.with_imm_element_like |element| {
Some(element.get_namespace())
}
}
CommentNodeTypeId |
TextNodeTypeId |
DocumentFragmentNodeTypeId |
DoctypeNodeTypeId |
DocumentNodeTypeId(_) => None
}
}

pub fn GetPrefix(&self) -> Option<DOMString> {
@@ -13,3 +13,4 @@
== last_of_type_pseudo_a.html last_of_type_pseudo_b.html
== only_of_type_pseudo_a.html only_of_type_pseudo_b.html
== visibility_hidden.html visibility_hidden_ref.html
== dom_createelementns_a.html dom_createelementns_b.html
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<title>Document.createElementNS() test</title>
<script>
function test() {
var host = document.getElementById("body");
function appendElt(e, id) {
host.appendChild(e);
e.id = id;
e.setAttribute("ns", e.namespaceURI);
}

var img1 = document.createElement("address");
appendElt(img1, "img1");
var img2 = document.createElementNS("http://www.example.org/dummy", "p");
appendElt(img2, "img2");
var img3 = document.createElementNS("http://www.w3.org/1999/xhtml", "address");
appendElt(img3, "img3");

function appendSpan(id, ns) {
var e = document.createElement("span");
e.id = id;
e.setAttribute("ns", ns);
host.appendChild(e);
}
var ref = document.getElementById("ref");
appendSpan("s1", ref.firstChild.namespaceURI);
appendSpan("s2", ref.ownerDocument.namespaceURI);
appendSpan("s3", ref.lastChild.namespaceURI);
}
</script>
<style>
@namespace dummy url("http://www.example.org/dummy");
@namespace html url("http://www.w3.org/1999/xhtml");

* { margin: 0px; padding: 0px; }

address, dummy|p, p, html|span {
width: 40px;
height: 40px;
background: red;
margin-bottom: 10px;
display: block;
}

address[ns="http://www.w3.org/1999/xhtml"],
dummy|p[ns="http://www.example.org/dummy"],
span[ns="null"] {
background: green;
}
</style>
</head>
<body id="body">
<div id="ref"> <!--comment--></div>
<script>
test();
</script>
</body>
</html>
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>Document.createElementNS() test</title>
<style>
* { margin: 0px; padding: 0px; }

address, p, span {
width: 40px;
height: 40px;
background: green;
margin-bottom: 10px;
display: block;
}

</style>
</head>
<body id="body">
<div id="ref"> <!--comment--></div>
<address></address>
<p></p>
<address></address>
<span></span>
<span></span>
<span></span>
</body>
</html>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.