aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/comment.rs
blob: 3bc9344b4ebe13fd7943fc1657f415f7b54460c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* 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/. */

use dom::bindings::codegen::InheritTypes::CommentDerived;
use dom::bindings::codegen::Bindings::CommentBinding;
use dom::bindings::error::Fallible;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::characterdata::CharacterData;
use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::node::{CommentNodeTypeId, Node};
use dom::window::{Window, WindowMethods};
use servo_util::str::DOMString;

/// An HTML comment.
#[deriving(Encodable)]
pub struct Comment {
    pub characterdata: CharacterData,
}

impl CommentDerived for EventTarget {
    fn is_comment(&self) -> bool {
        self.type_id == NodeTargetTypeId(CommentNodeTypeId)
    }
}

impl Comment {
    pub fn new_inherited(text: DOMString, document: &JSRef<Document>) -> Comment {
        Comment {
            characterdata: CharacterData::new_inherited(CommentNodeTypeId, text, document)
        }
    }

    pub fn new(text: DOMString, document: &JSRef<Document>) -> Temporary<Comment> {
        let node = Comment::new_inherited(text, document);
        Node::reflect_node(box node, document, CommentBinding::Wrap)
    }

    pub fn Constructor(global: &JSRef<Window>, data: DOMString) -> Fallible<Temporary<Comment>> {
        let document = global.Document().root();
        Ok(Comment::new(data, &*document))
    }
}

pub trait CommentMethods {
}

impl Reflectable for Comment {
    fn reflector<'a>(&'a self) -> &'a Reflector {
        self.characterdata.reflector()
    }
}