mirror of
https://github.com/servo/servo.git
synced 2025-08-02 12:10:29 +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
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue