servo: Merge #2326 - Implement ChildNode.remove() (from jdm:remove); r=Ms2ger

Fixes #2191.

Source-Repo: https://github.com/servo/servo
Source-Revision: 2da560e9ee29160e49c2af922202a344d7ed355f
This commit is contained in:
Harry Maclean 2014-05-05 14:07:29 -04:00
Родитель 97440b2ff7
Коммит be6b296acf
8 изменённых файлов: 61 добавлений и 7 удалений

Просмотреть файл

@ -4,13 +4,13 @@
//! DOM bindings for `CharacterData`.
use dom::bindings::codegen::InheritTypes::CharacterDataDerived;
use dom::bindings::codegen::InheritTypes::{CharacterDataDerived, NodeCast};
use dom::bindings::js::JSRef;
use dom::bindings::error::{Fallible, ErrorResult, IndexSize};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::node::{CommentNodeTypeId, Node, NodeTypeId, TextNodeTypeId, ProcessingInstructionNodeTypeId};
use dom::node::{CommentNodeTypeId, Node, NodeTypeId, TextNodeTypeId, ProcessingInstructionNodeTypeId, NodeHelpers};
use servo_util::str::DOMString;
#[deriving(Encodable)]
@ -48,6 +48,7 @@ pub trait CharacterDataMethods {
fn InsertData(&mut self, _offset: u32, _arg: DOMString) -> ErrorResult;
fn DeleteData(&mut self, _offset: u32, _count: u32) -> ErrorResult;
fn ReplaceData(&mut self, _offset: u32, _count: u32, _arg: DOMString) -> ErrorResult;
fn Remove(&mut self);
}
impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
@ -98,6 +99,12 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
// FIXME: Once we have `Range`, we should implement step7 to step11
Ok(())
}
// http://dom.spec.whatwg.org/#dom-childnode-remove
fn Remove(&mut self) {
let node: &mut JSRef<Node> = NodeCast::from_mut_ref(self);
node.remove_self();
}
}
impl Reflectable for CharacterData {

Просмотреть файл

@ -2,12 +2,12 @@
* 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 dom::bindings::codegen::InheritTypes::DocumentTypeDerived;
use dom::bindings::codegen::InheritTypes::{DocumentTypeDerived, NodeCast};
use dom::bindings::codegen::BindingDeclarations::DocumentTypeBinding;
use dom::bindings::js::{JSRef, Temporary};
use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::node::{Node, DoctypeNodeTypeId};
use dom::node::{Node, DoctypeNodeTypeId, NodeHelpers};
use servo_util::str::DOMString;
/// The `DOCTYPE` tag.
@ -59,6 +59,7 @@ pub trait DocumentTypeMethods {
fn Name(&self) -> DOMString;
fn PublicId(&self) -> DOMString;
fn SystemId(&self) -> DOMString;
fn Remove(&mut self);
}
impl<'a> DocumentTypeMethods for JSRef<'a, DocumentType> {
@ -73,4 +74,10 @@ impl<'a> DocumentTypeMethods for JSRef<'a, DocumentType> {
fn SystemId(&self) -> DOMString {
self.system_id.clone()
}
// http://dom.spec.whatwg.org/#dom-childnode-remove
fn Remove(&mut self) {
let node: &mut JSRef<Node> = NodeCast::from_mut_ref(self);
node.remove_self();
}
}

Просмотреть файл

@ -406,6 +406,7 @@ pub trait ElementMethods {
fn GetInnerHTML(&self) -> Fallible<DOMString>;
fn GetOuterHTML(&self) -> Fallible<DOMString>;
fn Children(&self) -> Temporary<HTMLCollection>;
fn Remove(&mut self);
}
impl<'a> ElementMethods for JSRef<'a, Element> {
@ -678,6 +679,12 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
let window = window_from_node(self).root();
HTMLCollection::children(&*window, NodeCast::from_ref(self))
}
// http://dom.spec.whatwg.org/#dom-childnode-remove
fn Remove(&mut self) {
let node: &mut JSRef<Node> = NodeCast::from_mut_ref(self);
node.remove_self();
}
}
pub fn get_attribute_parts(name: DOMString) -> (Option<~str>, ~str) {

Просмотреть файл

@ -425,6 +425,8 @@ pub trait NodeHelpers {
fn get_bounding_content_box(&self) -> Rect<Au>;
fn get_content_boxes(&self) -> Vec<Rect<Au>>;
fn remove_self(&mut self);
}
impl<'a> NodeHelpers for JSRef<'a, Node> {
@ -630,6 +632,12 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
document.deref().wait_until_safe_to_modify_dom();
}
fn remove_self(&mut self) {
match self.parent_node().root() {
Some(ref mut parent) => parent.remove_child(self),
None => ()
}
}
}
/// If the given untrusted node address represents a valid DOM node in the given runtime,

Просмотреть файл

@ -25,4 +25,4 @@ interface CharacterData : Node {
void replaceData(unsigned long offset, unsigned long count, DOMString data);
};
//CharacterData implements ChildNode;
CharacterData implements ChildNode;

Просмотреть файл

@ -0,0 +1,25 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is:
* http://dom.spec.whatwg.org/#interface-childnode
*/
[NoInterfaceObject]
interface ChildNode {
// Not implemented yet:
// void before((Node or DOMString)... nodes);
// void after((Node or DOMString)... nodes);
// void replace((Node or DOMString)... nodes);
void remove();
};
// [NoInterfaceObject]
// interface NonDocumentTypeChildNode {
// [Pure]
// readonly attribute Element? previousElementSibling;
// [Pure]
// readonly attribute Element? nextElementSibling;
// };

Просмотреть файл

@ -16,4 +16,4 @@ interface DocumentType : Node {
readonly attribute DOMString systemId;
};
//DocumentType implements ChildNode;
DocumentType implements ChildNode;

Просмотреть файл

@ -65,5 +65,5 @@ partial interface Element {
readonly attribute DOMString outerHTML;
};
//Element implements ChildNode;
Element implements ChildNode;
Element implements ParentNode;