mirror of
https://github.com/servo/servo.git
synced 2025-08-09 23:45:35 +01:00
script: Clamp table spans according to the HTML specification (#36703)
Previously, spans were partially clamped during layout, but this means that accessing and setting these properties via script wouldn't behave according to the HTML specification. In addition, the value wasn't floored in layout, so could lead to panics. This change improves clamping and moves it to script. Testing: This change includes a new WPT test. Fixes #36699. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
b10fc49e8a
commit
0d21992edd
9 changed files with 177 additions and 75 deletions
|
@ -20,8 +20,6 @@ use crate::dom::node::Node;
|
|||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
||||
const DEFAULT_SPAN: u32 = 1;
|
||||
|
||||
#[dom_struct]
|
||||
pub(crate) struct HTMLTableColElement {
|
||||
htmlelement: HTMLElement,
|
||||
|
@ -62,9 +60,11 @@ impl HTMLTableColElement {
|
|||
|
||||
impl HTMLTableColElementMethods<crate::DomTypeHolder> for HTMLTableColElement {
|
||||
// <https://html.spec.whatwg.org/multipage/#attr-col-span>
|
||||
make_uint_getter!(Span, "span", DEFAULT_SPAN);
|
||||
make_uint_getter!(Span, "span", 1);
|
||||
// <https://html.spec.whatwg.org/multipage/#attr-col-span>
|
||||
make_uint_setter!(SetSpan, "span", DEFAULT_SPAN);
|
||||
// > The span IDL attribute must reflect the content attribute of the same name. It is clamped
|
||||
// > to the range [1, 1000], and its default value is 1.
|
||||
make_clamped_uint_setter!(SetSpan, "span", 1, 1000, 1);
|
||||
}
|
||||
|
||||
pub(crate) trait HTMLTableColElementLayoutHelpers<'dom> {
|
||||
|
@ -96,11 +96,12 @@ impl VirtualMethods for HTMLTableColElement {
|
|||
fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue {
|
||||
match *local_name {
|
||||
local_name!("span") => {
|
||||
let mut attr = AttrValue::from_u32(value.into(), DEFAULT_SPAN);
|
||||
let mut attr = AttrValue::from_u32(value.into(), 1);
|
||||
if let AttrValue::UInt(_, ref mut val) = attr {
|
||||
if *val == 0 {
|
||||
*val = 1;
|
||||
}
|
||||
// From <https://html.spec.whatwg.org/multipage/#attr-col-span>:
|
||||
// > The span IDL attribute must reflect the content attribute of the same name.
|
||||
// > It is clamped to the range [1, 1000], and its default value is 1.
|
||||
*val = (*val).clamp(1, 1000);
|
||||
}
|
||||
attr
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue