Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Implement basic column spans and the legacy `bgcolor` and `border` attributes. #4278

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

style: Parse the legacy `bgcolor` attribute per the HTML5 specification.

Additionally, this patch cleans up some miscellaneous formatting issues.
  • Loading branch information
pcwalton committed Dec 8, 2014
commit ae55357281fc52a3fce4af771760979c772f3f71
@@ -593,6 +593,12 @@ impl<'le> TElementAttributes for LayoutElement<'le> {
self.element.get_unsigned_integer_attribute_for_layout(attribute)
}
}

fn get_simple_color_attribute(self, attribute: SimpleColorAttribute) -> Option<SimpleColor> {
unsafe {
self.element.get_simple_color_attribute_for_layout(attribute)
}
}
}

fn get_content(content_list: &content::T) -> String {
@@ -48,7 +48,7 @@ use script_traits::UntrustedNodeAddress;
use servo_msg::compositor_msg::ScriptListener;
use servo_msg::constellation_msg::ConstellationChan;
use servo_util::smallvec::{SmallVec1, SmallVec};
use servo_util::str::LengthOrPercentageOrAuto;
use servo_util::str::{LengthOrPercentageOrAuto, SimpleColor};
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::comm::{Receiver, Sender};
@@ -214,6 +214,7 @@ no_jsmanaged_fields!(LayoutChan)
no_jsmanaged_fields!(WindowProxyHandler)
no_jsmanaged_fields!(UntrustedNodeAddress)
no_jsmanaged_fields!(LengthOrPercentageOrAuto)
no_jsmanaged_fields!(SimpleColor)

impl<'a> JSTraceable for &'a str {
#[inline]
@@ -30,6 +30,7 @@ use dom::document::{Document, DocumentHelpers, LayoutDocumentHelpers};
use dom::domtokenlist::DOMTokenList;
use dom::event::Event;
use dom::eventtarget::{EventTarget, NodeTargetTypeId, EventTargetHelpers};
use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementHelpers};
use dom::htmlcollection::HTMLCollection;
use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers};
use dom::htmlserializer::serialize;
@@ -46,7 +47,7 @@ use style::{SimpleColorAttribute, SizeIntegerAttribute, UnsignedIntegerAttribute
use style::{WidthLengthAttribute, matches, parse_selector_list_from_str};
use style;
use servo_util::namespace;
use servo_util::str::{DOMString, LengthOrPercentageOrAuto};
use servo_util::str::{DOMString, LengthOrPercentageOrAuto, SimpleColor};

use std::ascii::AsciiExt;
use std::cell::{Ref, RefMut};
@@ -205,6 +206,8 @@ pub trait RawLayoutElementHelpers {
-> Option<i32>;
unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute)
-> Option<u32>;
unsafe fn get_simple_color_attribute_for_layout(&self, attribute: SimpleColorAttribute)
-> Option<SimpleColor>;
fn local_name<'a>(&'a self) -> &'a Atom;
fn namespace<'a>(&'a self) -> &'a Namespace;
fn style_attribute<'a>(&'a self) -> &'a DOMRefCell<Option<style::PropertyDeclarationBlock>>;
@@ -352,6 +355,28 @@ impl RawLayoutElementHelpers for Element {
}
}

#[inline]
#[allow(unrooted_must_root)]
unsafe fn get_simple_color_attribute_for_layout(&self, attribute: SimpleColorAttribute)
-> Option<SimpleColor> {
match attribute {
BgColorSimpleColorAttribute => {
if self.is_htmlbodyelement() {
let this: &HTMLBodyElement = mem::transmute(self);
this.get_background_color()
} else if self.is_htmltableelement() {
let this: &HTMLTableElement = mem::transmute(self);
this.get_background_color()
} else if self.is_htmltablecellelement() {
let this: &HTMLTableCellElement = mem::transmute(self);
this.get_background_color()
} else {
panic!("I'm not a body, table, or table cell!")
}
}
}
}

// Getters used in components/layout/wrapper.rs

fn local_name<'a>(&'a self) -> &'a Atom {
@@ -2,11 +2,9 @@
* 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::AttrHelpers;
use dom::attr::{Attr, AttrHelpers};
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding;
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::HTMLBodyElementMethods;
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{mod, HTMLBodyElementMethods};
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::EventTargetCast;
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLElementCast};
@@ -19,11 +17,13 @@ use dom::htmlelement::HTMLElement;
use dom::node::{Node, ElementNodeTypeId, window_from_node};
use dom::virtualmethods::VirtualMethods;

use servo_util::str::DOMString;
use servo_util::str::{mod, DOMString, SimpleColor};
use std::cell::Cell;

#[dom_struct]
pub struct HTMLBodyElement {
htmlelement: HTMLElement
htmlelement: HTMLElement,
background_color: Cell<Option<SimpleColor>>,
}

impl HTMLBodyElementDerived for EventTarget {
@@ -33,14 +33,20 @@ impl HTMLBodyElementDerived for EventTarget {
}

impl HTMLBodyElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLBodyElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>)
-> HTMLBodyElement {
HTMLBodyElement {
htmlelement: HTMLElement::new_inherited(HTMLBodyElementTypeId, localName, prefix, document)
htmlelement: HTMLElement::new_inherited(HTMLBodyElementTypeId,
localName,
prefix,
document),
background_color: Cell::new(None),
}
}

#[allow(unrooted_must_root)]
pub fn new(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> Temporary<HTMLBodyElement> {
pub fn new(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>)
-> Temporary<HTMLBodyElement> {
let element = HTMLBodyElement::new_inherited(localName, prefix, document);
Node::reflect_node(box element, document, HTMLBodyElementBinding::Wrap)
}
@@ -58,6 +64,16 @@ impl<'a> HTMLBodyElementMethods for JSRef<'a, HTMLBodyElement> {
}
}

pub trait HTMLBodyElementHelpers {
fn get_background_color(&self) -> Option<SimpleColor>;
}

impl HTMLBodyElementHelpers for HTMLBodyElement {
fn get_background_color(&self) -> Option<SimpleColor> {
self.background_color.get()
}
}

impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> {
let element: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self);
@@ -91,6 +107,25 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
name.slice_from(2),
attr.value().as_slice().to_string());
}

match attr.local_name() {
&atom!("bgcolor") => {
self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok())
}
_ => {}
}
}

fn before_remove_attr(&self, attr: JSRef<Attr>) {
match self.super_type() {
Some(ref s) => s.before_remove_attr(attr),
_ => {}
}

match attr.local_name() {
&atom!("bgcolor") => self.background_color.set(None),
_ => {}
}
}
}

@@ -14,13 +14,13 @@ use dom::htmlelement::HTMLElement;
use dom::node::ElementNodeTypeId;
use dom::virtualmethods::VirtualMethods;

use servo_util::str::{AutoLpa, DOMString, LengthOrPercentageOrAuto};
use servo_util::str;
use servo_util::str::{mod, AutoLpa, DOMString, LengthOrPercentageOrAuto, SimpleColor};
use std::cell::Cell;

#[dom_struct]
pub struct HTMLTableCellElement {
htmlelement: HTMLElement,
background_color: Cell<Option<SimpleColor>>,
border: Cell<Option<u32>>,
width: Cell<LengthOrPercentageOrAuto>,
}
@@ -43,6 +43,7 @@ impl HTMLTableCellElement {
-> HTMLTableCellElement {
HTMLTableCellElement {
htmlelement: HTMLElement::new_inherited(type_id, tag_name, prefix, document),
background_color: Cell::new(None),
border: Cell::new(None),
width: Cell::new(AutoLpa),
}
@@ -55,11 +56,16 @@ impl HTMLTableCellElement {
}

pub trait HTMLTableCellElementHelpers {
fn get_background_color(&self) -> Option<SimpleColor>;
fn get_border(&self) -> Option<u32>;
fn get_width(&self) -> LengthOrPercentageOrAuto;
}

impl HTMLTableCellElementHelpers for HTMLTableCellElement {
fn get_background_color(&self) -> Option<SimpleColor> {
self.background_color.get()
}

fn get_border(&self) -> Option<u32> {
self.border.get()
}
@@ -82,6 +88,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableCellElement> {
}

match attr.local_name() {
&atom!("bgcolor") => {
self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok())
}
&atom!("border") => {
// According to HTML5 § 14.3.9, invalid values map to 1px.
self.border.set(Some(str::parse_unsigned_integer(attr.value()
@@ -100,6 +109,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableCellElement> {
}

match attr.local_name() {
&atom!("bgcolor") => self.background_color.set(None),
&atom!("border") => self.border.set(None),
&atom!("width") => self.width.set(AutoLpa),
_ => ()
@@ -24,6 +24,7 @@ use std::cell::Cell;
#[dom_struct]
pub struct HTMLTableElement {
htmlelement: HTMLElement,
background_color: Cell<Option<SimpleColor>>,
border: Cell<Option<u32>>,
}

@@ -41,6 +42,7 @@ impl HTMLTableElement {
localName,
prefix,
document),
background_color: Cell::new(None),
border: Cell::new(None),
}
}
@@ -91,10 +93,15 @@ impl<'a> HTMLTableElementMethods for JSRef<'a, HTMLTableElement> {
}

pub trait HTMLTableElementHelpers {
fn get_background_color(&self) -> Option<SimpleColor>;
fn get_border(&self) -> Option<u32>;
}

impl HTMLTableElementHelpers for HTMLTableElement {
fn get_background_color(&self) -> Option<SimpleColor> {
self.background_color.get()
}

fn get_border(&self) -> Option<u32> {
self.border.get()
}
@@ -113,6 +120,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableElement> {
}

match attr.local_name() {
&atom!("bgcolor") => {
self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok())
}
&atom!("border") => {
// According to HTML5 § 14.3.9, invalid values map to 1px.
self.border.set(Some(str::parse_unsigned_integer(attr.value()
@@ -130,6 +140,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableElement> {
}

match attr.local_name() {
&atom!("bgcolor") => self.background_color.set(None),
&atom!("border") => self.border.set(None),
_ => ()
}

Some generated files are not rendered by default. Learn more.

@@ -23,3 +23,9 @@ pub enum UnsignedIntegerAttribute {
BorderUnsignedIntegerAttribute,
}

/// Legacy presentational attributes that take a simple color as defined in HTML5 § 2.4.6.
pub enum SimpleColorAttribute {
/// `<body bgcolor>`
BgColorSimpleColorAttribute,
}

@@ -5,9 +5,9 @@
//! Traits that nodes must implement. Breaks the otherwise-cyclic dependency between layout and
//! style.

use legacy::{IntegerAttribute, LengthAttribute, UnsignedIntegerAttribute};
use legacy::{IntegerAttribute, LengthAttribute, SimpleColorAttribute, UnsignedIntegerAttribute};
use selectors::AttrSelector;
use servo_util::str::LengthOrPercentageOrAuto;
use servo_util::str::{LengthOrPercentageOrAuto, SimpleColor};
use string_cache::{Atom, Namespace};

pub trait TNode<'a, E: TElement<'a>> : Clone + Copy {
@@ -58,4 +58,5 @@ pub trait TElementAttributes : Copy {
fn get_length_attribute(self, attribute: LengthAttribute) -> LengthOrPercentageOrAuto;
fn get_integer_attribute(self, attribute: IntegerAttribute) -> Option<i32>;
fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32>;
fn get_simple_color_attribute(self, attribute: SimpleColorAttribute) -> Option<SimpleColor>;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.