mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
auto merge of #1075 : SimonSapin/servo/newnewcss, r=kmcallister
I believe this is all the preparatory work discussed in #1006 and #1057: The new 'style' crate implements the whole style system (including parsing, matching and cascading) and only depends on cssparser and util, so that gfx, script and main can all depend on it. Next: porting the layout code to this. (Really, this time! I think.)
This commit is contained in:
commit
6db57e6f72
38 changed files with 161 additions and 125 deletions
|
@ -24,7 +24,7 @@ use html::hubbub_html_parser::build_element_from_tag;
|
|||
use js::jsapi::{JSObject, JSContext, JSVal};
|
||||
use js::jsapi::{JSTRACE_OBJECT, JSTracer, JS_CallTracer};
|
||||
use js::glue::RUST_OBJECT_TO_JSVAL;
|
||||
use servo_util::tree::TreeNodeRef;
|
||||
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||
|
||||
use std::hashmap::HashMap;
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ use dom::node::{ElementNodeTypeId, Node, ScriptView, AbstractNode};
|
|||
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
|
||||
use layout_interface::{ContentBoxesResponse};
|
||||
use newcss::stylesheet::Stylesheet;
|
||||
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||
|
||||
use js::jsapi::{JSContext, JSObject};
|
||||
|
||||
|
@ -119,17 +120,12 @@ pub enum ElementTypeId {
|
|||
// Element methods
|
||||
//
|
||||
|
||||
impl<'self> Element {
|
||||
pub fn new(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> Element {
|
||||
Element {
|
||||
node: Node::new(ElementNodeTypeId(type_id), document),
|
||||
tag_name: tag_name,
|
||||
attrs: ~[],
|
||||
style_attribute: None,
|
||||
}
|
||||
impl ElementLike for Element {
|
||||
fn get_local_name<'a>(&'a self) -> &'a str {
|
||||
self.tag_name.as_slice()
|
||||
}
|
||||
|
||||
pub fn get_attr(&'self self, name: &str) -> Option<&'self str> {
|
||||
fn get_attr<'a>(&'a self, name: &str) -> Option<&'a str> {
|
||||
// FIXME: Need an each() that links lifetimes in Rust.
|
||||
for attr in self.attrs.iter() {
|
||||
// FIXME: only case-insensitive in the HTML namespace (as opposed to SVG, etc.)
|
||||
|
@ -140,6 +136,17 @@ impl<'self> Element {
|
|||
}
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'self> Element {
|
||||
pub fn new(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> Element {
|
||||
Element {
|
||||
node: Node::new(ElementNodeTypeId(type_id), document),
|
||||
tag_name: tag_name,
|
||||
attrs: ~[],
|
||||
style_attribute: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_attr(&mut self,
|
||||
abstract_self: AbstractNode<ScriptView>,
|
||||
|
|
|
@ -13,7 +13,7 @@ use dom::window::Window;
|
|||
|
||||
use js::jsapi::{JSObject, JSContext, JSTracer};
|
||||
|
||||
use servo_util::tree::TreeNodeRef;
|
||||
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||
|
||||
use std::libc;
|
||||
use std::ptr;
|
||||
|
|
|
@ -6,11 +6,12 @@ use dom::bindings::utils::{DOMString, ErrorResult, null_str_as_empty};
|
|||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{ScriptView, AbstractNode};
|
||||
use extra::url::Url;
|
||||
use gfx::geometry::to_px;
|
||||
use servo_util::geometry::to_px;
|
||||
use layout_interface::{ContentBoxQuery, ContentBoxResponse};
|
||||
use servo_net::image_cache_task;
|
||||
use servo_net::image_cache_task::ImageCacheTask;
|
||||
use servo_util::url::make_url;
|
||||
use servo_util::tree::ElementLike;
|
||||
|
||||
pub struct HTMLImageElement {
|
||||
htmlelement: HTMLElement,
|
||||
|
|
|
@ -25,7 +25,7 @@ use extra::arc::Arc;
|
|||
use js::jsapi::{JSObject, JSContext};
|
||||
use netsurfcss::util::VoidPtrLike;
|
||||
use newcss::complete::CompleteSelectResults;
|
||||
use servo_util::tree::{TreeNode, TreeNodeRef};
|
||||
use servo_util::tree::{TreeNode, TreeNodeRef, TreeNodeRefAsElement};
|
||||
use servo_util::range::Range;
|
||||
use gfx::display_list::DisplayList;
|
||||
|
||||
|
@ -154,8 +154,23 @@ impl<View> TreeNodeRef<Node<View>> for AbstractNode<View> {
|
|||
fn with_mut_base<R>(&self, callback: &fn(&mut Node<View>) -> R) -> R {
|
||||
self.transmute_mut(callback)
|
||||
}
|
||||
|
||||
fn is_element(&self) -> bool {
|
||||
match self.type_id() {
|
||||
ElementNodeTypeId(*) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<View> TreeNodeRefAsElement<Node<View>, Element> for AbstractNode<View> {
|
||||
#[inline]
|
||||
fn with_imm_element_like<R>(&self, f: &fn(&Element) -> R) -> R {
|
||||
self.with_imm_element(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<View> TreeNode<AbstractNode<View>> for Node<View> { }
|
||||
|
||||
impl<'self, View> AbstractNode<View> {
|
||||
|
@ -309,13 +324,6 @@ impl<'self, View> AbstractNode<View> {
|
|||
self.transmute_mut(f)
|
||||
}
|
||||
|
||||
pub fn is_element(self) -> bool {
|
||||
match self.type_id() {
|
||||
ElementNodeTypeId(*) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: This should be doing dynamic borrow checking for safety.
|
||||
pub fn with_imm_element<R>(self, f: &fn(&Element) -> R) -> R {
|
||||
if !self.is_element() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue