Skip to content

Commit

Permalink
Remove ObjectElement
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Jan 14, 2019
1 parent 059c9f4 commit 887cc62
Showing 1 changed file with 19 additions and 40 deletions.
59 changes: 19 additions & 40 deletions components/layout/construct.rs
Expand Up @@ -419,8 +419,17 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
SpecificFragmentInfo::Media(Box::new(MediaFragmentInfo::new(data)))
},
Some(LayoutNodeType::Element(LayoutElementType::HTMLObjectElement)) => {
let elem = node.as_element().unwrap();
let type_and_data = (
elem.get_attr(&ns!(), &local_name!("type")),
elem.get_attr(&ns!(), &local_name!("data")),
);
let object_data = match type_and_data {
(None, Some(uri)) if is_image_data(uri) => ServoUrl::parse(uri).ok(),
_ => None,
};
let image_info = Box::new(ImageFragmentInfo::new(
node.object_data(),
object_data,
None,
node,
&self.layout_context,
Expand Down Expand Up @@ -1976,7 +1985,15 @@ where
Some(LayoutNodeType::Element(LayoutElementType::HTMLCanvasElement)) |
Some(LayoutNodeType::Element(LayoutElementType::SVGSVGElement)) => true,
Some(LayoutNodeType::Element(LayoutElementType::HTMLObjectElement)) => {
self.has_object_data()
let elem = self.as_element().unwrap();
let type_and_data = (
elem.get_attr(&ns!(), &local_name!("type")),
elem.get_attr(&ns!(), &local_name!("data")),
);
match type_and_data {
(None, Some(uri)) => is_image_data(uri),
_ => false,
}
},
Some(LayoutNodeType::Element(_)) => false,
None => self.get_pseudo_element_type().is_replaced_content(),
Expand Down Expand Up @@ -2007,44 +2024,6 @@ where
}
}

/// Methods for interacting with HTMLObjectElement nodes
trait ObjectElement {
/// Returns true if this node has object data that is correct uri.
fn has_object_data(&self) -> bool;

/// Returns the "data" attribute value parsed as a URL
fn object_data(&self) -> Option<ServoUrl>;
}

impl<N> ObjectElement for N
where
N: ThreadSafeLayoutNode,
{
fn has_object_data(&self) -> bool {
let elem = self.as_element().unwrap();
let type_and_data = (
elem.get_attr(&ns!(), &local_name!("type")),
elem.get_attr(&ns!(), &local_name!("data")),
);
match type_and_data {
(None, Some(uri)) => is_image_data(uri),
_ => false,
}
}

fn object_data(&self) -> Option<ServoUrl> {
let elem = self.as_element().unwrap();
let type_and_data = (
elem.get_attr(&ns!(), &local_name!("type")),
elem.get_attr(&ns!(), &local_name!("data")),
);
match type_and_data {
(None, Some(uri)) if is_image_data(uri) => ServoUrl::parse(uri).ok(),
_ => None,
}
}
}

impl FlowRef {
/// Adds a new flow as a child of this flow. Fails if this flow is marked as a leaf.
fn add_new_child(&mut self, mut new_child: FlowRef) {
Expand Down

0 comments on commit 887cc62

Please sign in to comment.