diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2015-04-07 10:47:19 -0700 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2015-05-20 11:15:25 -0700 |
commit | 1a3395e0776d7a716dd97c0dd3e91e5e7d6025ac (patch) | |
tree | a046551cccd03dd35110e1e56959f42012a4d7c4 /components/script | |
parent | e52197d1261055527a838f74b353a1124d6b077a (diff) | |
download | servo-1a3395e0776d7a716dd97c0dd3e91e5e7d6025ac.tar.gz servo-1a3395e0776d7a716dd97c0dd3e91e5e7d6025ac.zip |
script: Implement the `width` and `height` attributes for iframes per
HTML5 § 4.8.6.
Improves Amazon and Ars Technica.
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/attr.rs | 6 | ||||
-rw-r--r-- | components/script/dom/element.rs | 39 | ||||
-rw-r--r-- | components/script/dom/htmliframeelement.rs | 47 | ||||
-rw-r--r-- | components/script/dom/webidls/HTMLIFrameElement.webidl | 4 |
4 files changed, 83 insertions, 13 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 8995f63ec2d..299d7408eaf 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -311,6 +311,7 @@ pub trait AttrHelpersForLayout { unsafe fn value_atom_forever(&self) -> Option<Atom>; unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]>; unsafe fn local_name_atom_forever(&self) -> Atom; + unsafe fn value(&self) -> &AttrValue; } #[allow(unsafe_code)] @@ -351,4 +352,9 @@ impl AttrHelpersForLayout for Attr { unsafe fn local_name_atom_forever(&self) -> Atom { self.local_name.clone() } + + #[inline] + unsafe fn value(&self) -> &AttrValue { + self.value.borrow_for_layout() + } } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index e8ae592e63c..a666a28e627 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -18,7 +18,7 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, EventTargetCast}; use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLFontElementDerived}; -use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast}; +use dom::bindings::codegen::InheritTypes::{HTMLIFrameElementDerived, HTMLInputElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLTableElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, HTMLTableCellElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementDerived, HTMLTextAreaElementDerived}; @@ -47,6 +47,7 @@ use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementHelpers}; use dom::htmlcollection::HTMLCollection; use dom::htmlelement::HTMLElementTypeId; use dom::htmlfontelement::{HTMLFontElement, HTMLFontElementHelpers}; +use dom::htmliframeelement::{HTMLIFrameElement, RawHTMLIFrameElementHelpers}; use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers, HTMLInputElementHelpers}; use dom::htmltableelement::{HTMLTableElement, HTMLTableElementHelpers}; use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementHelpers}; @@ -64,7 +65,7 @@ use style; use style::legacy::{UnsignedIntegerAttribute, from_declaration}; use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute}; use style::properties::DeclaredValue::SpecifiedValue; -use style::properties::longhands::{self, border_spacing}; +use style::properties::longhands::{self, border_spacing, height}; use style::values::CSSFloat; use style::values::specified::{self, CSSColor, CSSRGBA}; use util::geometry::Au; @@ -181,7 +182,8 @@ pub trait RawLayoutElementHelpers { #[inline] #[allow(unsafe_code)] -unsafe fn get_attr_for_layout(elem: &Element, namespace: &Namespace, name: &Atom) -> Option<LayoutJS<Attr>> { +pub unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, name: &Atom) + -> Option<LayoutJS<Attr>> { // cast to point to T in RefCell<T> directly let attrs = elem.attrs.borrow_for_layout(); attrs.iter().find(|attr: & &JS<Attr>| { @@ -331,7 +333,10 @@ impl RawLayoutElementHelpers for Element { } - let width = if self.is_htmltableelement() { + let width = if self.is_htmliframeelement() { + let this: &HTMLIFrameElement = mem::transmute(self); + this.get_width() + } else if self.is_htmltableelement() { let this: &HTMLTableElement = mem::transmute(self); this.get_width() } else if self.is_htmltabledatacellelement() { @@ -349,13 +354,37 @@ impl RawLayoutElementHelpers for Element { PropertyDeclaration::Width(SpecifiedValue(width_value)))); } LengthOrPercentageOrAuto::Length(length) => { - let width_value = specified::LengthOrPercentageOrAuto::Length(specified::Length::Absolute(length)); + let width_value = specified::LengthOrPercentageOrAuto::Length( + specified::Length::Absolute(length)); hints.push(from_declaration( PropertyDeclaration::Width(SpecifiedValue(width_value)))); } } + let height = if self.is_htmliframeelement() { + let this: &HTMLIFrameElement = mem::transmute(self); + this.get_height() + } else { + LengthOrPercentageOrAuto::Auto + }; + + match height { + LengthOrPercentageOrAuto::Auto => {} + LengthOrPercentageOrAuto::Percentage(percentage) => { + let width_value = specified::LengthOrPercentageOrAuto::Percentage(percentage); + hints.push(from_declaration(PropertyDeclaration::Height(SpecifiedValue( + height::SpecifiedValue(width_value))))); + } + LengthOrPercentageOrAuto::Length(length) => { + let width_value = specified::LengthOrPercentageOrAuto::Length( + specified::Length::Absolute(length)); + hints.push(from_declaration(PropertyDeclaration::Height(SpecifiedValue( + height::SpecifiedValue(width_value))))); + } + } + + let cols = if self.is_htmltextareaelement() { let this: &HTMLTextAreaElement = mem::transmute(self); match this.get_cols_for_layout() { diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 685f46db48e..fe09197e06b 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -2,9 +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; -use dom::attr::AttrValue; -use dom::attr::AttrHelpers; +use dom::attr::{Attr, AttrHelpers, AttrHelpersForLayout, AttrValue}; use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding; use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; @@ -17,8 +15,7 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JSRef, OptionalRootable, Rootable, Temporary}; use dom::customevent::CustomEvent; use dom::document::Document; -use dom::element::Element; -use dom::element::AttributeHandlers; +use dom::element::{self, AttributeHandlers, Element}; use dom::event::{Event, EventHelpers}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::element::ElementTypeId; @@ -40,6 +37,7 @@ use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; use url::{Url, UrlParser}; +use util::str::{self, LengthOrPercentageOrAuto}; enum SandboxAllowance { AllowNothing = 0x00, @@ -76,6 +74,11 @@ pub trait HTMLIFrameElementHelpers { fn update_subpage_id(self, new_subpage_id: SubpageId); } +pub trait RawHTMLIFrameElementHelpers { + fn get_width(&self) -> LengthOrPercentageOrAuto; + fn get_height(&self) -> LengthOrPercentageOrAuto; +} + impl<'a> HTMLIFrameElementHelpers for JSRef<'a, HTMLIFrameElement> { fn is_sandboxed(self) -> bool { self.sandbox.get().is_some() @@ -163,6 +166,30 @@ impl<'a> HTMLIFrameElementHelpers for JSRef<'a, HTMLIFrameElement> { } } +impl RawHTMLIFrameElementHelpers for HTMLIFrameElement { + #[allow(unsafe_code)] + fn get_width(&self) -> LengthOrPercentageOrAuto { + unsafe { + element::get_attr_for_layout(ElementCast::from_actual(&*self), + &ns!(""), + &atom!("width")).map(|attribute| { + str::parse_length(&**(*attribute.unsafe_get()).value()) + }).unwrap_or(LengthOrPercentageOrAuto::Auto) + } + } + + #[allow(unsafe_code)] + fn get_height(&self) -> LengthOrPercentageOrAuto { + unsafe { + element::get_attr_for_layout(ElementCast::from_actual(&*self), + &ns!(""), + &atom!("height")).map(|attribute| { + str::parse_length(&**(*attribute.unsafe_get()).value()) + }).unwrap_or(LengthOrPercentageOrAuto::Auto) + } + } +} + impl HTMLIFrameElement { fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLIFrameElement { HTMLIFrameElement { @@ -317,6 +344,14 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> { fn Stop(self) -> Fallible<()> { Err(NotSupported) } + + make_getter!(Width); + + make_setter!(SetWidth, "width"); + + make_getter!(Height); + + make_setter!(SetHeight, "height"); } impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> { @@ -347,7 +382,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> { } } self.sandbox.set(Some(modes)); - }, + } &atom!("src") => { let node: JSRef<Node> = NodeCast::from_ref(*self); if node.is_in_doc() { diff --git a/components/script/dom/webidls/HTMLIFrameElement.webidl b/components/script/dom/webidls/HTMLIFrameElement.webidl index 528ee2aa47b..e230cea4063 100644 --- a/components/script/dom/webidls/HTMLIFrameElement.webidl +++ b/components/script/dom/webidls/HTMLIFrameElement.webidl @@ -12,8 +12,8 @@ interface HTMLIFrameElement : HTMLElement { attribute DOMString sandbox; // attribute boolean seamless; // attribute boolean allowFullscreen; - // attribute DOMString width; - // attribute DOMString height; + attribute DOMString width; + attribute DOMString height; readonly attribute Document? contentDocument; //readonly attribute WindowProxy? contentWindow; readonly attribute Window? contentWindow; |