Skip to content
Permalink
Browse files

Move unsafe layout calls onto LayoutJS.

  • Loading branch information
eefriedman committed Nov 9, 2015
1 parent ef52da7 commit 5293afc122626d997bab168554ac0a3cbb5ab03c
@@ -36,12 +36,12 @@ use dom::domrectlist::DOMRectList;
use dom::domtokenlist::DOMTokenList;
use dom::event::Event;
use dom::htmlanchorelement::HTMLAnchorElement;
use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementLayoutHelpers};
use dom::htmlcollection::HTMLCollection;
use dom::htmlfieldsetelement::HTMLFieldSetElement;
use dom::htmlfontelement::HTMLFontElement;
use dom::htmlfontelement::{HTMLFontElement, HTMLFontElementLayoutHelpers};
use dom::htmlhrelement::{HTMLHRElement, HTMLHRLayoutHelpers};
use dom::htmliframeelement::HTMLIFrameElement;
use dom::htmliframeelement::{HTMLIFrameElement, HTMLIFrameElementLayoutMethods};
use dom::htmlinputelement::{HTMLInputElement, LayoutHTMLInputElementHelpers};
use dom::htmllabelelement::HTMLLabelElement;
use dom::htmllegendelement::HTMLLegendElement;
@@ -274,7 +274,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
{
let bgcolor = if let Some(this) = self.downcast::<HTMLBodyElement>() {
(*this.unsafe_get()).get_background_color()
this.get_background_color()
} else if let Some(this) = self.downcast::<HTMLTableElement>() {
(*this.unsafe_get()).get_background_color()
} else if let Some(this) = self.downcast::<HTMLTableCellElement>() {
@@ -294,7 +294,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
}

let background = if let Some(this) = self.downcast::<HTMLBodyElement>() {
(*this.unsafe_get()).get_background()
this.get_background()
} else {
None
};
@@ -306,10 +306,10 @@ impl LayoutElementHelpers for LayoutJS<Element> {
}

let color = if let Some(this) = self.downcast::<HTMLFontElement>() {
(*this.unsafe_get()).get_color()
this.get_color()
} else if let Some(this) = self.downcast::<HTMLBodyElement>() {
// https://html.spec.whatwg.org/multipage/#the-page:the-body-element-20
(*this.unsafe_get()).get_color()
this.get_color()
} else if let Some(this) = self.downcast::<HTMLHRElement>() {
// https://html.spec.whatwg.org/multipage/#the-hr-element-2:presentational-hints-5
this.get_color()
@@ -326,7 +326,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
}

let font_family = if let Some(this) = self.downcast::<HTMLFontElement>() {
(*this.unsafe_get()).get_face()
this.get_face()
} else {
None
};
@@ -341,7 +341,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
}

let font_size = if let Some(this) = self.downcast::<HTMLFontElement>() {
(*this.unsafe_get()).get_size()
this.get_size()
} else {
None
};
@@ -398,7 +398,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {


let width = if let Some(this) = self.downcast::<HTMLIFrameElement>() {
(*this.unsafe_get()).get_width()
this.get_width()
} else if let Some(this) = self.downcast::<HTMLTableElement>() {
(*this.unsafe_get()).get_width()
} else if let Some(this) = self.downcast::<HTMLTableCellElement>() {
@@ -425,7 +425,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {


let height = if let Some(this) = self.downcast::<HTMLIFrameElement>() {
(*this.unsafe_get()).get_height()
this.get_height()
} else {
LengthOrPercentageOrAuto::Auto
};
@@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods};
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::js::{LayoutJS, Root};
use dom::bindings::reflector::Reflectable;
use dom::document::Document;
use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
@@ -87,32 +87,37 @@ impl HTMLBodyElementMethods for HTMLBodyElement {
}
}

pub trait HTMLBodyElementLayoutHelpers {
fn get_background_color(&self) -> Option<RGBA>;
fn get_color(&self) -> Option<RGBA>;
fn get_background(&self) -> Option<Url>;
}

impl HTMLBodyElement {
impl HTMLBodyElementLayoutHelpers for LayoutJS<HTMLBodyElement> {
#[allow(unsafe_code)]
pub fn get_background_color(&self) -> Option<RGBA> {
fn get_background_color(&self) -> Option<RGBA> {
unsafe {
self.upcast::<Element>()
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(""), &atom!("bgcolor"))
.and_then(AttrValue::as_color)
.cloned()
}
}

#[allow(unsafe_code)]
pub fn get_color(&self) -> Option<RGBA> {
fn get_color(&self) -> Option<RGBA> {
unsafe {
self.upcast::<Element>()
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(""), &atom!("text"))
.and_then(AttrValue::as_color)
.cloned()
}
}

#[allow(unsafe_code)]
pub fn get_background(&self) -> Option<Url> {
fn get_background(&self) -> Option<Url> {
unsafe {
self.background.borrow_for_layout().clone()
(*self.unsafe_get()).background.borrow_for_layout().clone()
}
}
}
@@ -7,7 +7,7 @@ use dom::attr::AttrValue;
use dom::bindings::codegen::Bindings::HTMLFontElementBinding;
use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::js::{LayoutJS, Root};
use dom::document::Document;
use dom::element::{Element, RawLayoutElementHelpers};
use dom::htmlelement::HTMLElement;
@@ -81,32 +81,37 @@ impl VirtualMethods for HTMLFontElement {
}
}

pub trait HTMLFontElementLayoutHelpers {
fn get_color(&self) -> Option<RGBA>;
fn get_face(&self) -> Option<Atom>;
fn get_size(&self) -> Option<specified::Length>;
}

impl HTMLFontElement {
impl HTMLFontElementLayoutHelpers for LayoutJS<HTMLFontElement> {
#[allow(unsafe_code)]
pub fn get_color(&self) -> Option<RGBA> {
fn get_color(&self) -> Option<RGBA> {
unsafe {
self.upcast::<Element>()
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(""), &atom!("color"))
.and_then(AttrValue::as_color)
.cloned()
}
}

#[allow(unsafe_code)]
pub fn get_face(&self) -> Option<Atom> {
fn get_face(&self) -> Option<Atom> {
unsafe {
self.upcast::<Element>()
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(""), &atom!("face"))
.map(AttrValue::as_atom)
.cloned()
}
}

#[allow(unsafe_code)]
pub fn get_size(&self) -> Option<specified::Length> {
fn get_size(&self) -> Option<specified::Length> {
unsafe {
self.upcast::<Element>()
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(""), &atom!("size"))
.and_then(AttrValue::as_length)
.cloned()
@@ -2,7 +2,7 @@
* 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::attr::{Attr, AttrHelpersForLayout, AttrValue};
use dom::attr::{Attr, AttrValue};
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding;
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
@@ -14,7 +14,7 @@ use dom::bindings::js::{Root, LayoutJS};
use dom::bindings::reflector::Reflectable;
use dom::customevent::CustomEvent;
use dom::document::Document;
use dom::element::{self, AttributeMutation, Element};
use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
use dom::event::Event;
use dom::htmlelement::HTMLElement;
use dom::node::{Node, window_from_node};
@@ -156,28 +156,6 @@ impl HTMLIFrameElement {
self.subpage_id.set(Some(new_subpage_id));
}

#[allow(unsafe_code)]
pub fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe {
element::get_attr_for_layout(self.upcast(),
&ns!(""),
&atom!("width")).map(|attribute| {
str::parse_length(&**attribute.value_for_layout())
}).unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}

#[allow(unsafe_code)]
pub fn get_height(&self) -> LengthOrPercentageOrAuto {
unsafe {
element::get_attr_for_layout(self.upcast(),
&ns!(""),
&atom!("height")).map(|attribute| {
str::parse_length(&**attribute.value_for_layout())
}).unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}

fn new_inherited(localName: DOMString,
prefix: Option<DOMString>,
document: &Document) -> HTMLIFrameElement {
@@ -211,6 +189,8 @@ impl HTMLIFrameElement {

pub trait HTMLIFrameElementLayoutMethods {
fn pipeline_id(self) -> Option<PipelineId>;
fn get_width(&self) -> LengthOrPercentageOrAuto;
fn get_height(&self) -> LengthOrPercentageOrAuto;
}

impl HTMLIFrameElementLayoutMethods for LayoutJS<HTMLIFrameElement> {
@@ -221,6 +201,26 @@ impl HTMLIFrameElementLayoutMethods for LayoutJS<HTMLIFrameElement> {
(*self.unsafe_get()).pipeline_id.get()
}
}

#[allow(unsafe_code)]
fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(""), &atom!("width"))
.map(|attribute| str::parse_length(&attribute))
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}

#[allow(unsafe_code)]
fn get_height(&self) -> LengthOrPercentageOrAuto {
unsafe {
(*self.upcast::<Element>().unsafe_get())
.get_attr_for_layout(&ns!(""), &atom!("height"))
.map(|attribute| str::parse_length(&attribute))
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}
}

pub fn Navigate(iframe: &HTMLIFrameElement, direction: NavigationDirection) -> Fallible<()> {

0 comments on commit 5293afc

Please sign in to comment.
You can’t perform that action at this time.