mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Implement ChildNode.remove()
This commit is contained in:
parent
325a39b8ba
commit
6f310a5c20
8 changed files with 61 additions and 7 deletions
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
//! DOM bindings for `CharacterData`.
|
//! 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::js::JSRef;
|
||||||
use dom::bindings::error::{Fallible, ErrorResult, IndexSize};
|
use dom::bindings::error::{Fallible, ErrorResult, IndexSize};
|
||||||
use dom::bindings::utils::{Reflectable, Reflector};
|
use dom::bindings::utils::{Reflectable, Reflector};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
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;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
|
@ -48,6 +48,7 @@ pub trait CharacterDataMethods {
|
||||||
fn InsertData(&mut self, _offset: u32, _arg: DOMString) -> ErrorResult;
|
fn InsertData(&mut self, _offset: u32, _arg: DOMString) -> ErrorResult;
|
||||||
fn DeleteData(&mut self, _offset: u32, _count: u32) -> ErrorResult;
|
fn DeleteData(&mut self, _offset: u32, _count: u32) -> ErrorResult;
|
||||||
fn ReplaceData(&mut self, _offset: u32, _count: u32, _arg: DOMString) -> ErrorResult;
|
fn ReplaceData(&mut self, _offset: u32, _count: u32, _arg: DOMString) -> ErrorResult;
|
||||||
|
fn Remove(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
|
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
|
// FIXME: Once we have `Range`, we should implement step7 to step11
|
||||||
Ok(())
|
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 {
|
impl Reflectable for CharacterData {
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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::codegen::BindingDeclarations::DocumentTypeBinding;
|
||||||
use dom::bindings::js::{JSRef, Temporary};
|
use dom::bindings::js::{JSRef, Temporary};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||||
use dom::node::{Node, DoctypeNodeTypeId};
|
use dom::node::{Node, DoctypeNodeTypeId, NodeHelpers};
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
/// The `DOCTYPE` tag.
|
/// The `DOCTYPE` tag.
|
||||||
|
@ -59,6 +59,7 @@ pub trait DocumentTypeMethods {
|
||||||
fn Name(&self) -> DOMString;
|
fn Name(&self) -> DOMString;
|
||||||
fn PublicId(&self) -> DOMString;
|
fn PublicId(&self) -> DOMString;
|
||||||
fn SystemId(&self) -> DOMString;
|
fn SystemId(&self) -> DOMString;
|
||||||
|
fn Remove(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DocumentTypeMethods for JSRef<'a, DocumentType> {
|
impl<'a> DocumentTypeMethods for JSRef<'a, DocumentType> {
|
||||||
|
@ -73,4 +74,10 @@ impl<'a> DocumentTypeMethods for JSRef<'a, DocumentType> {
|
||||||
fn SystemId(&self) -> DOMString {
|
fn SystemId(&self) -> DOMString {
|
||||||
self.system_id.clone()
|
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 GetInnerHTML(&self) -> Fallible<DOMString>;
|
||||||
fn GetOuterHTML(&self) -> Fallible<DOMString>;
|
fn GetOuterHTML(&self) -> Fallible<DOMString>;
|
||||||
fn Children(&self) -> Temporary<HTMLCollection>;
|
fn Children(&self) -> Temporary<HTMLCollection>;
|
||||||
|
fn Remove(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ElementMethods for JSRef<'a, Element> {
|
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();
|
let window = window_from_node(self).root();
|
||||||
HTMLCollection::children(&*window, NodeCast::from_ref(self))
|
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) {
|
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_bounding_content_box(&self) -> Rect<Au>;
|
||||||
fn get_content_boxes(&self) -> Vec<Rect<Au>>;
|
fn get_content_boxes(&self) -> Vec<Rect<Au>>;
|
||||||
|
|
||||||
|
fn remove_self(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> NodeHelpers for JSRef<'a, Node> {
|
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();
|
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,
|
/// 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);
|
void replaceData(unsigned long offset, unsigned long count, DOMString data);
|
||||||
};
|
};
|
||||||
|
|
||||||
//CharacterData implements ChildNode;
|
CharacterData implements ChildNode;
|
||||||
|
|
25
src/components/script/dom/webidls/ChildNode.webidl
Normal file
25
src/components/script/dom/webidls/ChildNode.webidl
Normal file
|
@ -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;
|
readonly attribute DOMString systemId;
|
||||||
};
|
};
|
||||||
|
|
||||||
//DocumentType implements ChildNode;
|
DocumentType implements ChildNode;
|
||||||
|
|
|
@ -65,5 +65,5 @@ partial interface Element {
|
||||||
readonly attribute DOMString outerHTML;
|
readonly attribute DOMString outerHTML;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Element implements ChildNode;
|
Element implements ChildNode;
|
||||||
Element implements ParentNode;
|
Element implements ParentNode;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue