diff --git a/conversions.rs b/conversions.rs index d74ddd3..f27f6e1 100644 --- a/conversions.rs +++ b/conversions.rs @@ -38,6 +38,7 @@ pub trait AsLl { } impl ToLl for CssLanguageLevel { + #[inline] fn to_ll(&self) -> css_language_level { match *self { CssLevel1 => CSS_LEVEL_1, @@ -51,30 +52,35 @@ impl ToLl for CssLanguageLevel { } impl ToLl for CssError { + #[inline] fn to_ll(&self) -> css_error { *self as css_error } } impl ToLl for CssFontFamily { + #[inline] fn to_ll(&self) -> css_font_family_e { *self as css_font_family_e } } impl ToLl for CssColor { + #[inline] fn to_ll(&self) -> css_color { assert!(sys::size_of::() == sys::size_of::()); unsafe { transmute(*self) } } } +#[inline] pub fn ll_color_to_hl_color(color: css_color) -> CssColor { assert!(sys::size_of::() == sys::size_of::()); unsafe { transmute(color) } } impl ToLl<(css_unit, css_fixed)> for CssUnit { + #[inline] fn to_ll(&self) -> (css_unit, css_fixed) { use ll::types::*; use types::*; @@ -99,6 +105,7 @@ impl ToLl<(css_unit, css_fixed)> for CssUnit { } } +#[inline] pub fn ll_unit_to_hl_unit(unit: css_unit, value: css_fixed) -> CssUnit { use ll::types::*; use types::*; @@ -139,6 +146,7 @@ pub fn ll_unit_to_hl_unit(unit: css_unit, value: css_fixed) -> CssUnit { } } +#[inline] pub fn ll_qname_to_hl_qname(qname: *css_qname) -> CssQName { unsafe { CssQName { @@ -156,11 +164,13 @@ pub fn ll_qname_to_hl_qname(qname: *css_qname) -> CssQName { } impl ToLl for CssPseudoElement { + #[inline] fn to_ll(&self) -> css_pseudo_element { *self as css_pseudo_element } } +#[inline] pub fn c_enum_to_rust_enum(val: c_enum) -> T { // Sanity check that this is actually a 'c-like' (har) enum assert!(sys::size_of::() == sys::size_of::()); diff --git a/ll.rs b/ll.rs index fe0e04e..5a5cbc0 100644 --- a/ll.rs +++ b/ll.rs @@ -599,11 +599,288 @@ pub mod computed { use ll::hint::css_hint; use ll::types::css_color; use super::errors::css_error; + use super::properties::{CSS_BORDER_WIDTH_WIDTH, CSS_FONT_SIZE_DIMENSION, CSS_HEIGHT_SET}; + use super::properties::{CSS_MARGIN_SET, CSS_PADDING_SET, CSS_WIDTH_SET}; use super::stylesheet::css_fixed; use super::types::css_unit; use wapcaplet::ll::lwc_string; - pub type css_computed_style = c_void; + pub struct css_computed_style { + bits: [u8, ..34], + unused: [u8, ..2], + + background_color: css_color, + background_image: *lwc_string, + background_position: [css_fixed, ..2], + + border_color: [css_color, ..4], + border_width: [css_fixed, ..4], + + top: css_fixed, + right: css_fixed, + bottom: css_fixed, + left: css_fixed, + + color: css_color, + + font_size: css_fixed, + + height: css_fixed, + + line_height: css_fixed, + + list_style_image: *lwc_string, + + margin: [css_fixed, ..4], + + max_height: css_fixed, + max_width: css_fixed, + + min_height: css_fixed, + min_width: css_fixed, + + opacity: css_fixed, + + padding: [css_fixed, ..4], + + text_indent: css_fixed, + + vertical_align: css_fixed, + + width: css_fixed, + + // ... other stuff here ... + } + + static CSS_WIDTH_INDEX: uint = 18; + static CSS_WIDTH_SHIFT: u8 = 2; + static CSS_WIDTH_MASK: u8 = 0xfc; + #[inline(always)] + pub unsafe fn css_computed_width(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + let mut bits = (*style).bits[CSS_WIDTH_INDEX]; + bits &= CSS_WIDTH_MASK; + bits >>= CSS_WIDTH_SHIFT; + + if (bits & 0x3) == (CSS_WIDTH_SET as u8) { + *length = (*style).width; + *unit = (bits >> 2) as css_unit; + } + + bits & 0x3 + } + + static CSS_HEIGHT_INDEX: uint = 10; + static CSS_HEIGHT_SHIFT: u8 = 2; + static CSS_HEIGHT_MASK: u8 = 0xfc; + #[inline(always)] + pub unsafe fn css_computed_height(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + let mut bits = (*style).bits[CSS_HEIGHT_INDEX]; + bits &= CSS_HEIGHT_MASK; + bits >>= CSS_HEIGHT_SHIFT; + + if (bits & 0x3) == (CSS_HEIGHT_SET as u8) { + *length = (*style).height; + *unit = (bits >> 2) as css_unit; + } + + bits & 0x3 + } + + static CSS_CLEAR_INDEX: uint = 20; + static CSS_CLEAR_SHIFT: u8 = 0; + static CSS_CLEAR_MASK: u8 = 0x7; + #[inline(always)] + pub unsafe fn css_computed_clear(style: *css_computed_style) -> u8 { + let mut bits = (*style).bits[CSS_CLEAR_INDEX]; + bits &= CSS_CLEAR_MASK; + bits >>= CSS_CLEAR_SHIFT; + bits + } + + static CSS_FONT_SIZE_INDEX: uint = 1; + static CSS_FONT_SIZE_SHIFT: u8 = 0; + static CSS_FONT_SIZE_MASK: u8 = 0xff; + #[inline(always)] + pub unsafe fn css_computed_font_size(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + let mut bits = (*style).bits[CSS_FONT_SIZE_INDEX]; + bits &= CSS_FONT_SIZE_MASK; + bits >>= CSS_FONT_SIZE_SHIFT; + + if (bits & 0xf) == (CSS_FONT_SIZE_DIMENSION as u8) { + *length = (*style).font_size; + *unit = (bits >> 4) as css_unit; + } + + bits & 0xf + } + + #[inline(always)] + unsafe fn css_computed_margin(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit, + index: uint, + shift: u8, + mask: u8, + which: uint) + -> u8 { + let mut bits = (*style).bits[index]; + bits &= mask; + bits >>= shift; + + if (bits & 0x3) == (CSS_MARGIN_SET as u8) { + *length = (*style).margin[which]; + *unit = (bits >> 2) as css_unit; + } + + bits & 0x3 + } + + #[inline(always)] + pub unsafe fn css_computed_margin_top(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_margin(style, length, unit, 12, 2, 0xfc, 0) + } + + #[inline(always)] + pub unsafe fn css_computed_margin_right(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_margin(style, length, unit, 13, 2, 0xfc, 1) + } + + #[inline(always)] + pub unsafe fn css_computed_margin_bottom(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_margin(style, length, unit, 14, 2, 0xfc, 2) + } + + #[inline(always)] + pub unsafe fn css_computed_margin_left(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_margin(style, length, unit, 15, 2, 0xfc, 3) + } + + #[inline(always)] + unsafe fn css_computed_padding(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit, + index: uint, + shift: u8, + mask: u8, + which: uint) + -> u8 { + let mut bits = (*style).bits[index]; + bits &= mask; + bits >>= shift; + + if (bits & 0x3) == (CSS_PADDING_SET as u8) { + *length = (*style).padding[which]; + *unit = (bits >> 1) as css_unit; + } + + bits & 0x3 + } + + #[inline(always)] + pub unsafe fn css_computed_padding_top(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_padding(style, length, unit, 21, 3, 0xf8, 0) + } + + #[inline(always)] + pub unsafe fn css_computed_padding_right(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_padding(style, length, unit, 22, 3, 0xf8, 1) + } + + #[inline(always)] + pub unsafe fn css_computed_padding_bottom(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_padding(style, length, unit, 23, 3, 0xf8, 2) + } + + #[inline(always)] + pub unsafe fn css_computed_padding_left(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_padding(style, length, unit, 24, 3, 0xf8, 3) + } + + #[inline(always)] + unsafe fn css_computed_border_width(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit, + index: uint, + shift: u8, + mask: u8, + which: uint) + -> u8 { + let mut bits = (*style).bits[index]; + bits &= mask; + bits >>= shift; + + if (bits & 0x7) == (CSS_BORDER_WIDTH_WIDTH as u8) { + *length = (*style).border_width[which]; + *unit = (bits >> 3) as css_unit; + } + + bits & 0x7 + } + + #[inline(always)] + pub unsafe fn css_computed_border_top_width(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_border_width(style, length, unit, 2, 1, 0xfe, 0) + } + + #[inline(always)] + pub unsafe fn css_computed_border_right_width(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_border_width(style, length, unit, 3, 1, 0xfe, 1) + } + + #[inline(always)] + pub unsafe fn css_computed_border_bottom_width(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_border_width(style, length, unit, 4, 1, 0xfe, 2) + } + + #[inline(always)] + pub unsafe fn css_computed_border_left_width(style: *css_computed_style, + length: &mut css_fixed, + unit: &mut css_unit) + -> u8 { + css_computed_border_width(style, length, unit, 5, 1, 0xfe, 3) + } pub type compute_font_size_cb = extern "C" fn(pw: *c_void, parent: *css_hint, size: *mut css_hint) -> css_error; @@ -620,30 +897,14 @@ pub mod computed { pub fn css_computed_border_right_style(style: *css_computed_style) -> uint8_t; pub fn css_computed_border_bottom_style(style: *css_computed_style) -> uint8_t; pub fn css_computed_border_left_style(style: *css_computed_style) -> uint8_t; - pub fn css_computed_border_top_width(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_border_right_width(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_border_bottom_width(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_border_left_width(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; pub fn css_computed_border_top_color(style: *css_computed_style, color: *mut css_color) -> uint8_t; pub fn css_computed_border_right_color(style: *css_computed_style, color: *mut css_color) -> uint8_t; pub fn css_computed_border_bottom_color(style: *css_computed_style, color: *mut css_color) -> uint8_t; pub fn css_computed_border_left_color(style: *css_computed_style, color: *mut css_color) -> uint8_t; - pub fn css_computed_margin_top(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_margin_right(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_margin_bottom(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_margin_left(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_padding_top(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_padding_right(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_padding_bottom(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_padding_left(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; pub fn css_computed_display(style: *css_computed_style, root: bool) -> uint8_t; pub fn css_computed_float(style: *css_computed_style) -> uint8_t; - pub fn css_computed_clear(style: *css_computed_style) -> uint8_t; pub fn css_computed_position(style: *css_computed_style) -> uint8_t; - pub fn css_computed_width(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; - pub fn css_computed_height(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; pub fn css_computed_font_family(style: *css_computed_style, names: *mut **lwc_string) -> uint8_t; - pub fn css_computed_font_size(style: *css_computed_style, length: *mut css_fixed, unit: *mut css_unit) -> uint8_t; pub fn css_computed_font_style(style: *css_computed_style) -> uint8_t; pub fn css_computed_font_weight(style: *css_computed_style) -> uint8_t; pub fn css_computed_text_align(style: *css_computed_style) -> uint8_t; diff --git a/netsurfcss.rc b/netsurfcss.rc index 5b8508d..04195c2 100644 --- a/netsurfcss.rc +++ b/netsurfcss.rc @@ -234,7 +234,7 @@ pub mod stylesheet { impl Drop for CssStylesheet { #[fixed_stack_segment] - fn drop(&self) { + fn drop(&mut self) { assert!(self.sheet.is_not_null()); let code = unsafe { css_stylesheet_destroy(self.sheet) }; require_ok(code, "destroying stylesheet"); @@ -499,7 +499,7 @@ pub mod hint { } impl CssHint { - + #[inline] pub fn new(property: CssProperty, hint: *css_hint) -> CssHint { let status = get_css_hint_status(hint) as u32; match property { @@ -630,7 +630,7 @@ pub mod select { impl Drop for CssSelectCtx { #[fixed_stack_segment] - fn drop(&self) { + fn drop(&mut self) { assert!(self.select_ctx.is_not_null()); let code = unsafe { css_select_ctx_destroy(self.select_ctx) }; require_ok(code, "destroying select ctx"); @@ -1092,7 +1092,7 @@ pub mod select { impl Drop for CssSelectResults { #[fixed_stack_segment] - fn drop(&self) { + fn drop(&mut self) { assert!(self.results.is_not_null()); let code = unsafe { css_select_results_destroy(self.results) }; require_ok(code, "destroying select results"); @@ -1100,6 +1100,7 @@ pub mod select { } impl<'self> CssSelectResults { + #[inline] pub fn computed_style(&'self self, element: CssPseudoElement) -> CssComputedStyle<'self> { let element = element.to_ll(); let llstyle = unsafe { *self.results }.styles[element]; @@ -1108,7 +1109,7 @@ pub mod select { CssComputedStyle { result_backref: self, - computed_style: llstyle + computed_style: unsafe { transmute(llstyle) }, } } } @@ -1139,6 +1140,7 @@ pub mod computed { } impl<'self> CssComputedStyle<'self> { + #[inline] #[fixed_stack_segment] pub fn color(&self) -> CssColorValue { let mut color = 0; @@ -1148,6 +1150,7 @@ pub mod computed { CssColorValue::new(type_, color) } + #[inline] #[fixed_stack_segment] pub fn background_color(&self) -> CssColorValue { let mut color = 0; @@ -1157,6 +1160,7 @@ pub mod computed { CssColorValue::new(type_, color) } + #[inline] #[fixed_stack_segment] pub fn border_top_style(&self) -> CssBorderStyleValue { let type_ = unsafe { css_computed_border_top_style(self.computed_style) }; @@ -1165,6 +1169,7 @@ pub mod computed { CssBorderStyleValue::new(type_) } + #[inline] #[fixed_stack_segment] pub fn border_right_style(&self) -> CssBorderStyleValue { let type_ = unsafe { css_computed_border_right_style(self.computed_style) }; @@ -1173,14 +1178,16 @@ pub mod computed { CssBorderStyleValue::new(type_) } + #[inline] #[fixed_stack_segment] - pub fn border_bottom_style(&self) -> CssBorderStyleValue { + pub fn border_bottom_style(&self) -> CssBorderStyleValue { let type_ = unsafe { css_computed_border_bottom_style(self.computed_style) }; let type_ = type_ as css_border_style_e; CssBorderStyleValue::new(type_) } + #[inline] #[fixed_stack_segment] pub fn border_left_style(&self) -> CssBorderStyleValue { let type_ = unsafe { css_computed_border_left_style(self.computed_style) }; @@ -1189,54 +1196,59 @@ pub mod computed { CssBorderStyleValue::new(type_) } + #[inline] #[fixed_stack_segment] pub fn border_top_width(&self) -> CssBorderWidthValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_border_top_width(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_border_width_e; CssBorderWidthValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn border_right_width(&self) -> CssBorderWidthValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_border_right_width(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_border_width_e; CssBorderWidthValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn border_bottom_width(&self) -> CssBorderWidthValue { let mut length = 0; let mut unit = 0; let type_ = unsafe {css_computed_border_bottom_width(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_border_width_e; CssBorderWidthValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn border_left_width(&self) -> CssBorderWidthValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_border_left_width(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_border_width_e; CssBorderWidthValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn border_top_color(&self) -> CssColorValue { let mut color = 0; @@ -1246,6 +1258,7 @@ pub mod computed { CssColorValue::new(type_, color) } + #[inline] #[fixed_stack_segment] pub fn border_right_color(&self) -> CssColorValue { let mut color = 0; @@ -1255,6 +1268,7 @@ pub mod computed { CssColorValue::new(type_, color) } + #[inline] #[fixed_stack_segment] pub fn border_bottom_color(&self) -> CssColorValue { let mut color = 0; @@ -1264,6 +1278,7 @@ pub mod computed { CssColorValue::new(type_, color) } + #[inline] #[fixed_stack_segment] pub fn border_left_color(&self) -> CssColorValue { let mut color = 0; @@ -1273,102 +1288,111 @@ pub mod computed { CssColorValue::new(type_, color) } + #[inline] #[fixed_stack_segment] pub fn margin_top(&self) -> CssMarginValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_margin_top(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_margin_e; CssMarginValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn margin_right(&self) -> CssMarginValue { let mut length = 0; let mut unit = 0; let type_ = unsafe {css_computed_margin_right(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_margin_e; CssMarginValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn margin_bottom(&self) -> CssMarginValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_margin_bottom(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_margin_e; CssMarginValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn margin_left(&self) -> CssMarginValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_margin_left(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_margin_e; CssMarginValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn padding_top(&self) -> CssPaddingValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_padding_top(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_padding_e; CssPaddingValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn padding_right(&self) -> CssPaddingValue { let mut length = 0; let mut unit = 0; let type_ = unsafe {css_computed_padding_right(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_padding_e; CssPaddingValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn padding_bottom(&self) -> CssPaddingValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_padding_bottom(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_padding_e; CssPaddingValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn padding_left(&self) -> CssPaddingValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_padding_left(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_padding_e; CssPaddingValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn display(&self, root: bool) -> CssDisplayValue { let type_ = unsafe { css_computed_display(self.computed_style, root) }; @@ -1377,6 +1401,7 @@ pub mod computed { CssDisplayValue::new(type_) } + #[inline] #[fixed_stack_segment] pub fn position(&self) -> CssPositionValue { let type_ = unsafe { css_computed_position(self.computed_style) }; @@ -1385,30 +1410,33 @@ pub mod computed { CssPositionValue::new(type_) } + #[inline] #[fixed_stack_segment] pub fn width(&self) -> CssWidthValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_width(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_width_e; CssWidthValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn height(&self) -> CssHeightValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_height(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_height_e; CssHeightValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn float(&self) -> CssFloatValue { let type_ = unsafe { css_computed_float(self.computed_style) }; @@ -1417,6 +1445,7 @@ pub mod computed { CssFloatValue::new(type_) } + #[inline] #[fixed_stack_segment] pub fn clear(&self) -> CssClearValue { let type_ = unsafe { css_computed_clear(self.computed_style) }; @@ -1425,6 +1454,7 @@ pub mod computed { CssClearValue::new(type_) } + #[inline] #[fixed_stack_segment] pub fn font_family(&self) -> CssFontFamilyValue { let mut names: **lwc_string = null(); @@ -1435,18 +1465,20 @@ pub mod computed { CssFontFamilyValue::new(type_, names) } + #[inline] #[fixed_stack_segment] pub fn font_size(&self) -> CssFontSizeValue { let mut length = 0; let mut unit = 0; let type_ = unsafe { css_computed_font_size(self.computed_style, - to_mut_unsafe_ptr(&mut length), - to_mut_unsafe_ptr(&mut unit)) }; + &mut length, + &mut unit) }; let type_ = type_ as css_font_size_e; CssFontSizeValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn font_style(&self) -> CssFontStyleValue { let type_ = unsafe { css_computed_font_style(self.computed_style) }; @@ -1455,6 +1487,7 @@ pub mod computed { CssFontStyleValue::new(type_) } + #[inline] #[fixed_stack_segment] pub fn font_weight(&self) -> CssFontWeightValue { let type_ = unsafe { css_computed_font_weight(self.computed_style) }; @@ -1463,6 +1496,7 @@ pub mod computed { CssFontWeightValue::new(type_) } + #[inline] #[fixed_stack_segment] pub fn text_align(&self) -> CssTextAlignValue { let type_ = unsafe { css_computed_text_align(self.computed_style) }; @@ -1471,6 +1505,7 @@ pub mod computed { CssTextAlignValue::new(type_) } + #[inline] #[fixed_stack_segment] pub fn text_decoration(&self) -> CssTextDecorationValue { let type_ = unsafe { css_computed_text_decoration(self.computed_style) }; @@ -1480,7 +1515,7 @@ pub mod computed { CssTextDecorationValue::new(type_) } - + #[inline] #[fixed_stack_segment] pub fn line_height(&self) -> CssLineHeightValue { let mut length = 0; @@ -1493,6 +1528,7 @@ pub mod computed { CssLineHeightValue::new(type_, length, unit) } + #[inline] #[fixed_stack_segment] pub fn vertical_align(&self) -> CssVerticalAlignValue { let mut length = 0; @@ -1558,6 +1594,7 @@ mod values { } impl CssColorValue { + #[inline] pub fn new(type_: css_color_e, color: css_color) -> CssColorValue { if type_ == CSS_COLOR_INHERIT { CssColorInherit @@ -1576,6 +1613,7 @@ mod values { } impl CssMarginValue { + #[inline] pub fn new(type_: css_margin_e, length: css_fixed, unit: css_unit) -> CssMarginValue { if type_ == CSS_MARGIN_INHERIT { CssMarginInherit @@ -1596,6 +1634,7 @@ mod values { } impl CssPaddingValue { + #[inline] pub fn new(type_: css_padding_e, length: css_fixed, unit: css_unit) -> CssPaddingValue { if type_ == CSS_PADDING_INHERIT { CssPaddingInherit @@ -1622,6 +1661,7 @@ mod values { } impl CssBorderStyleValue { + #[inline] pub fn new(type_: css_border_style_e) -> CssBorderStyleValue { match type_ { CSS_BORDER_STYLE_INHERIT => CssBorderStyleInherit, @@ -1649,6 +1689,7 @@ mod values { } impl CssBorderWidthValue { + #[inline] pub fn new(type_: css_border_width_e, length: css_fixed, unit: css_unit) -> CssBorderWidthValue { if type_ == CSS_BORDER_WIDTH_INHERIT { CssBorderWidthInherit @@ -1687,6 +1728,7 @@ mod values { } impl CssDisplayValue { + #[inline] pub fn new(type_: css_display_e) -> CssDisplayValue { c_enum_to_rust_enum(type_) } @@ -1701,6 +1743,7 @@ mod values { } impl CssPositionValue { + #[inline] pub fn new(type_: css_position_e) -> CssPositionValue { c_enum_to_rust_enum(type_) } @@ -1713,6 +1756,7 @@ mod values { } impl CssWidthValue { + #[inline] pub fn new(type_: css_width_e, length: css_fixed, unit: css_unit) -> CssWidthValue { if type_ == CSS_WIDTH_INHERIT { CssWidthInherit @@ -1733,6 +1777,7 @@ mod values { } impl CssHeightValue { + #[inline] pub fn new(type_: css_height_e, length: css_fixed, unit: css_unit) -> CssHeightValue { if type_ == CSS_HEIGHT_INHERIT { CssHeightInherit @@ -1754,6 +1799,7 @@ mod values { } impl CssFloatValue { + #[inline] pub fn new(type_: css_float_e) -> CssFloatValue { c_enum_to_rust_enum(type_) } @@ -1768,6 +1814,7 @@ mod values { } impl CssClearValue { + #[inline] pub fn new(type_: css_clear_e) -> CssClearValue { c_enum_to_rust_enum(type_) } @@ -1784,6 +1831,7 @@ mod values { } impl CssFontFamilyValue { + #[inline] pub fn new(type_: css_font_family_e, names: **lwc_string) -> CssFontFamilyValue { if names.is_not_null() { CssFontFamilyValue(lwc_string_buf_to_hl_vec(names)) @@ -1820,6 +1868,7 @@ mod values { } impl CssFontSizeValue { + #[inline] pub fn new(type_: css_font_size_e, length: css_fixed, unit: css_unit) -> CssFontSizeValue { match type_ { x if x == CSS_FONT_SIZE_INHERIT => CssFontSizeInherit, @@ -1846,6 +1895,7 @@ mod values { } impl CssFontStyleValue { + #[inline] pub fn new(type_: css_font_style_e) -> CssFontStyleValue { c_enum_to_rust_enum(type_) } @@ -1869,6 +1919,7 @@ mod values { } impl CssFontWeightValue { + #[inline] pub fn new(type_: css_font_weight_e) -> CssFontWeightValue { c_enum_to_rust_enum(type_) } @@ -1888,6 +1939,7 @@ mod values { } impl CssTextAlignValue { + #[inline] pub fn new(type_: css_text_align_e) -> CssTextAlignValue { c_enum_to_rust_enum(type_) } @@ -1903,6 +1955,7 @@ mod values { } impl CssTextDecorationValue { + #[inline] pub fn new(type_: css_text_decoration_e) -> CssTextDecorationValue { c_enum_to_rust_enum(type_) } @@ -1916,6 +1969,7 @@ mod values { } impl CssLineHeightValue { + #[inline] pub fn new(type_: css_line_height_e, length: css_fixed, unit: css_unit) -> CssLineHeightValue { if type_ == CSS_LINE_HEIGHT_INHERIT { CssLineHeightInherit @@ -1945,6 +1999,7 @@ mod values { } impl CssVerticalAlignValue { + #[inline] pub fn new(type_: css_vertical_align_e, length: css_fixed, unit: css_unit) -> CssVerticalAlignValue { match type_ { CSS_VERTICAL_ALIGN_INHERIT => CssVerticalAlignInherit, diff --git a/util.rs b/util.rs index a0d965a..71d295a 100644 --- a/util.rs +++ b/util.rs @@ -12,11 +12,13 @@ use types::CssQName; use std::libc::c_void; use lwcstr_from_rust_str = wapcaplet::from_rust_string; +#[inline] pub fn css_fixed_to_float(f: css_fixed) -> float { static BEFORE: i32 = 10; f as float * 1.0f / ((1i32 << BEFORE) as float) } +#[inline] pub fn float_to_css_fixed(f: float) -> css_fixed { static BEFORE: i32 = 10; (f * ((1 << BEFORE) as float)) as css_fixed