mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Auto merge of #6019 - Ms2ger:preshint-border, r=pcwalton
<!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6019) <!-- Reviewable:end -->
This commit is contained in:
commit
398e7f07fe
5 changed files with 56 additions and 78 deletions
|
@ -40,6 +40,7 @@ use data::{LayoutDataAccess, LayoutDataFlags, LayoutDataWrapper, PrivateLayoutDa
|
|||
use opaque_node::OpaqueNodeMethods;
|
||||
|
||||
use gfx::display_list::OpaqueNode;
|
||||
use script::dom::attr::AttrValue;
|
||||
use script::dom::bindings::codegen::InheritTypes::{CharacterDataCast, ElementCast};
|
||||
use script::dom::bindings::codegen::InheritTypes::{HTMLIFrameElementCast, HTMLCanvasElementCast};
|
||||
use script::dom::bindings::codegen::InheritTypes::{HTMLImageElementCast, HTMLInputElementCast};
|
||||
|
@ -638,9 +639,8 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
|
|||
#[inline]
|
||||
fn has_nonzero_border(self) -> bool {
|
||||
unsafe {
|
||||
match self.element.get_unsigned_integer_attribute_for_layout(
|
||||
UnsignedIntegerAttribute::Border) {
|
||||
None | Some(0) => false,
|
||||
match self.element.get_attr_for_layout(&ns!(""), &atom!("border")) {
|
||||
None | Some(&AttrValue::UInt(_, 0)) => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -306,6 +306,7 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
pub trait AttrHelpersForLayout {
|
||||
unsafe fn value_forever(&self) -> &'static AttrValue;
|
||||
unsafe fn value_ref_forever(&self) -> &'static str;
|
||||
unsafe fn value_atom_forever(&self) -> Option<Atom>;
|
||||
unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]>;
|
||||
|
@ -314,6 +315,12 @@ pub trait AttrHelpersForLayout {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
impl AttrHelpersForLayout for Attr {
|
||||
#[inline]
|
||||
unsafe fn value_forever(&self) -> &'static AttrValue {
|
||||
// This transmute is used to cheat the lifetime restriction.
|
||||
mem::transmute::<&AttrValue, &AttrValue>(self.value.borrow_for_layout())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn value_ref_forever(&self) -> &'static str {
|
||||
// This transmute is used to cheat the lifetime restriction.
|
||||
|
|
|
@ -156,6 +156,8 @@ impl Element {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
pub trait RawLayoutElementHelpers {
|
||||
unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
||||
-> Option<&'a AttrValue>;
|
||||
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
||||
-> Option<&'a str>;
|
||||
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &Atom) -> Vec<&'a str>;
|
||||
|
@ -190,6 +192,13 @@ unsafe fn get_attr_for_layout(elem: &Element, namespace: &Namespace, name: &Atom
|
|||
#[allow(unsafe_code)]
|
||||
impl RawLayoutElementHelpers for Element {
|
||||
#[inline]
|
||||
unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
||||
-> Option<&'a AttrValue> {
|
||||
get_attr_for_layout(self, namespace, name).map(|attr| {
|
||||
(*attr.unsafe_get()).value_forever()
|
||||
})
|
||||
}
|
||||
|
||||
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
||||
-> Option<&'a str> {
|
||||
get_attr_for_layout(self, namespace, name).map(|attr| {
|
||||
|
@ -374,6 +383,30 @@ impl RawLayoutElementHelpers for Element {
|
|||
longhands::height::SpecifiedValue(
|
||||
specified::LengthOrPercentageOrAuto::Length(value))))));
|
||||
}
|
||||
|
||||
|
||||
let border = if self.is_htmltableelement() {
|
||||
let this: &HTMLTableElement = mem::transmute(self);
|
||||
this.get_border()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(border) = border {
|
||||
let width_value = specified::Length::Absolute(Au::from_px(border as i32));
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::BorderTopWidth(SpecifiedValue(
|
||||
longhands::border_top_width::SpecifiedValue(width_value)))));
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::BorderLeftWidth(SpecifiedValue(
|
||||
longhands::border_left_width::SpecifiedValue(width_value)))));
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::BorderBottomWidth(SpecifiedValue(
|
||||
longhands::border_bottom_width::SpecifiedValue(width_value)))));
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::BorderRightWidth(SpecifiedValue(
|
||||
longhands::border_right_width::SpecifiedValue(width_value)))));
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -403,16 +436,6 @@ impl RawLayoutElementHelpers for Element {
|
|||
attribute: UnsignedIntegerAttribute)
|
||||
-> Option<u32> {
|
||||
match attribute {
|
||||
UnsignedIntegerAttribute::Border => {
|
||||
if self.is_htmltableelement() {
|
||||
let this: &HTMLTableElement = mem::transmute(self);
|
||||
this.get_border()
|
||||
} else {
|
||||
// Don't panic since `:-servo-nonzero-border` can cause this to be called on
|
||||
// arbitrary elements.
|
||||
None
|
||||
}
|
||||
}
|
||||
UnsignedIntegerAttribute::ColSpan => {
|
||||
if self.is_htmltablecellelement() {
|
||||
let this: &HTMLTableCellElement = mem::transmute(self);
|
||||
|
|
|
@ -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, AttrHelpers};
|
||||
use dom::attr::{Attr, AttrHelpers, AttrValue};
|
||||
use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods;
|
||||
use dom::bindings::codegen::Bindings::HTMLTableElementBinding;
|
||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||
|
@ -17,8 +17,11 @@ use dom::htmltablecaptionelement::HTMLTableCaptionElement;
|
|||
use dom::node::{Node, NodeHelpers, NodeTypeId};
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
|
||||
use cssparser::RGBA;
|
||||
use util::str::{self, DOMString, LengthOrPercentageOrAuto};
|
||||
|
||||
use cssparser::RGBA;
|
||||
use string_cache::Atom;
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -158,5 +161,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableElement> {
|
|||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue {
|
||||
match local_name {
|
||||
&atom!("border") => AttrValue::from_u32(value, 1),
|
||||
_ => self.super_type().unwrap().parse_plain_attribute(local_name, value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,23 +7,17 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use selectors::tree::{TElement, TNode};
|
||||
use selectors::tree::TNode;
|
||||
use selectors::matching::DeclarationBlock;
|
||||
use node::TElementAttributes;
|
||||
use values::specified;
|
||||
use properties::DeclaredValue::SpecifiedValue;
|
||||
use properties::PropertyDeclaration;
|
||||
use properties::longhands;
|
||||
use selector_matching::Stylist;
|
||||
|
||||
use util::geometry::Au;
|
||||
use util::smallvec::VecLike;
|
||||
|
||||
/// Legacy presentational attributes that take a nonnegative integer as defined in HTML5 § 2.4.4.2.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub enum UnsignedIntegerAttribute {
|
||||
/// `<td border>`
|
||||
Border,
|
||||
/// `<td colspan>`
|
||||
ColSpan,
|
||||
}
|
||||
|
@ -46,16 +40,6 @@ pub trait PresentationalHintSynthesis {
|
|||
where N: TNode<'a>,
|
||||
N::Element: TElementAttributes<'a>,
|
||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||
/// Synthesizes rules for the legacy `border` attribute.
|
||||
fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>(
|
||||
&self,
|
||||
element: E,
|
||||
matching_rules_list: &mut V,
|
||||
shareable: &mut bool)
|
||||
where
|
||||
E: TElement<'a> +
|
||||
TElementAttributes<'a>,
|
||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||
}
|
||||
|
||||
impl PresentationalHintSynthesis for Stylist {
|
||||
|
@ -75,52 +59,6 @@ impl PresentationalHintSynthesis for Stylist {
|
|||
// Never share style for elements with preshints
|
||||
*shareable = false;
|
||||
}
|
||||
|
||||
match element.get_local_name() {
|
||||
name if *name == atom!("td") => {
|
||||
self.synthesize_presentational_hint_for_legacy_border_attribute(
|
||||
element,
|
||||
matching_rules_list,
|
||||
shareable);
|
||||
}
|
||||
name if *name == atom!("table") => {
|
||||
self.synthesize_presentational_hint_for_legacy_border_attribute(
|
||||
element,
|
||||
matching_rules_list,
|
||||
shareable);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>(
|
||||
&self,
|
||||
element: E,
|
||||
matching_rules_list: &mut V,
|
||||
shareable: &mut bool)
|
||||
where
|
||||
E: TElement<'a> +
|
||||
TElementAttributes<'a>,
|
||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
|
||||
match element.get_unsigned_integer_attribute(UnsignedIntegerAttribute::Border) {
|
||||
None => {}
|
||||
Some(length) => {
|
||||
let width_value = specified::Length::Absolute(Au::from_px(length as i32));
|
||||
matching_rules_list.push(from_declaration(
|
||||
PropertyDeclaration::BorderTopWidth(SpecifiedValue(
|
||||
longhands::border_top_width::SpecifiedValue(width_value)))));
|
||||
matching_rules_list.push(from_declaration(
|
||||
PropertyDeclaration::BorderLeftWidth(SpecifiedValue(
|
||||
longhands::border_left_width::SpecifiedValue(width_value)))));
|
||||
matching_rules_list.push(from_declaration(
|
||||
PropertyDeclaration::BorderBottomWidth(SpecifiedValue(
|
||||
longhands::border_bottom_width::SpecifiedValue(width_value)))));
|
||||
matching_rules_list.push(from_declaration(
|
||||
PropertyDeclaration::BorderRightWidth(SpecifiedValue(
|
||||
longhands::border_right_width::SpecifiedValue(width_value)))));
|
||||
*shareable = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue