mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
script: Map HTMLCanvasElement width and height attributes.
This commit is contained in:
parent
df29d02026
commit
53cad6227e
4 changed files with 63 additions and 3 deletions
|
@ -36,7 +36,7 @@ use js::jsapi::{HandleValue, JSContext};
|
|||
use offscreen_gl_context::GLContextAttributes;
|
||||
use script_layout_interface::HTMLCanvasData;
|
||||
use std::iter::repeat;
|
||||
use style::attr::AttrValue;
|
||||
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
|
||||
|
||||
const DEFAULT_WIDTH: u32 = 300;
|
||||
const DEFAULT_HEIGHT: u32 = 150;
|
||||
|
@ -97,6 +97,8 @@ impl HTMLCanvasElement {
|
|||
|
||||
pub trait LayoutHTMLCanvasElementHelpers {
|
||||
fn data(&self) -> HTMLCanvasData;
|
||||
fn get_width(&self) -> LengthOrPercentageOrAuto;
|
||||
fn get_height(&self) -> LengthOrPercentageOrAuto;
|
||||
}
|
||||
|
||||
impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> {
|
||||
|
@ -124,6 +126,26 @@ impl LayoutHTMLCanvasElementHelpers for LayoutJS<HTMLCanvasElement> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_width(&self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
(&*self.upcast::<Element>().unsafe_get())
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_uint_px_dimension)
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_height(&self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
(&*self.upcast::<Element>().unsafe_get())
|
||||
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
||||
.map(AttrValue::as_uint_px_dimension)
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue