Skip to content

Add link href support. - #5

Open
neojski wants to merge 1 commit into
mbrubeck:masterfrom
neojski:implement-basic-style-link-support
Open

Add link href support.#5
neojski wants to merge 1 commit into
mbrubeck:masterfrom
neojski:implement-basic-style-link-support

Conversation

@neojski

@neojski neojski commented Nov 10, 2014

Copy link
Copy Markdown

So I've implemented basic link support. I'm pretty sure you don't want to merge it because you don't want this toy browser to grow uncontrollably. But I wanted to leave it here and discuss a little bit.

So the tricky thing here is that I implemented get_elements_by_tag_name on Node. But it is not a Node method but rather Element method. But Element itself in our case (ElementData) does not have children available.
I'm not really sure what to think about the relationship between Element and Node. It's like Element is a type of Node but with limited functionality. It's not inheritance either.

I checked and servo's Element simply has Node inside of it. And

    fn GetElementsByTagName(self, localname: DOMString) -> Temporary<HTMLCollection> {
        let window = window_from_node(self).root();
        HTMLCollection::by_tag_name(*window, NodeCast::from_ref(self), localname)
    }

is casting Element onto Node. Is this cast something more than just self.node?

@mbrubeck

Copy link
Copy Markdown
Owner

Thanks for sharing the code! I agree that it would be "better" here to have Element contain Node, so this method could be implemented on Element, but this would also add some extra boilerplate elsewhere.

Is this cast something more than just self.node?

In Servo, I believe NodeCast::from_ref actually calls std::mem::transmute under the hood, and relies on the fact that the node is the first field in the Element struct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants