Skip to content

Commit

Permalink
Add insertRule/deleteRule support for stylo
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed Dec 1, 2016
1 parent 22c8df1 commit bddd467
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
3 changes: 2 additions & 1 deletion components/style/binding_tools/regen.py
Expand Up @@ -277,7 +277,6 @@
"StyleBasicShape",
"StyleBasicShapeType",
"StyleClipPath",
"nscoord",
"nsCSSKeyword",
"nsCSSShadowArray",
"nsCSSValue",
Expand Down Expand Up @@ -331,6 +330,8 @@
"nsStyleVariables",
"nsStyleVisibility",
"nsStyleXUL",
"nscoord",
"nsresult",
],
"array_types": {
"uintptr_t": "usize",
Expand Down
14 changes: 13 additions & 1 deletion components/style/gecko/conversions.rs
Expand Up @@ -14,11 +14,12 @@ use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue
use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, RawServoStyleRule};
use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules};
use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage};
use gecko_bindings::structs::nsresult;
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI};
use parking_lot::RwLock;
use properties::{ComputedValues, PropertyDeclarationBlock};
use stylesheets::{CssRules, Stylesheet, StyleRule};
use stylesheets::{CssRules, RulesMutateError, Stylesheet, StyleRule};
use values::computed::{CalcLengthOrPercentage, Gradient, Image, LengthOrPercentage, LengthOrPercentageOrAuto};

unsafe impl HasFFI for Stylesheet {
Expand Down Expand Up @@ -497,3 +498,14 @@ pub mod basic_shape {
}
}
}

impl From<RulesMutateError> for nsresult {
fn from(other: RulesMutateError) -> Self {
match other {
RulesMutateError::Syntax => nsresult::NS_ERROR_DOM_SYNTAX_ERR,
RulesMutateError::IndexSize => nsresult::NS_ERROR_DOM_INDEX_SIZE_ERR,
RulesMutateError::HierarchyRequest => nsresult::NS_ERROR_DOM_HIERARCHY_REQUEST_ERR,
RulesMutateError::InvalidState => nsresult::NS_ERROR_DOM_INVALID_STATE_ERR,
}
}
}
14 changes: 13 additions & 1 deletion components/style/gecko_bindings/bindings.rs
Expand Up @@ -71,7 +71,6 @@ use gecko_bindings::structs::SheetParsingMode;
use gecko_bindings::structs::StyleBasicShape;
use gecko_bindings::structs::StyleBasicShapeType;
use gecko_bindings::structs::StyleClipPath;
use gecko_bindings::structs::nscoord;
use gecko_bindings::structs::nsCSSKeyword;
use gecko_bindings::structs::nsCSSShadowArray;
use gecko_bindings::structs::nsCSSValue;
Expand Down Expand Up @@ -200,6 +199,8 @@ unsafe impl Sync for nsStyleVisibility {}
use gecko_bindings::structs::nsStyleXUL;
unsafe impl Send for nsStyleXUL {}
unsafe impl Sync for nsStyleXUL {}
use gecko_bindings::structs::nscoord;
use gecko_bindings::structs::nsresult;

#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -1025,6 +1026,17 @@ extern "C" {
index: u32)
-> RawServoStyleRuleStrong;
}
extern "C" {
pub fn Servo_CssRules_InsertRule(rules: ServoCssRulesBorrowed,
sheet: RawServoStyleSheetBorrowed,
rule: *const nsACString_internal,
index: u32, nested: bool,
rule_type: *mut u16) -> nsresult;
}
extern "C" {
pub fn Servo_CssRules_DeleteRule(rules: ServoCssRulesBorrowed, index: u32)
-> nsresult;
}
extern "C" {
pub fn Servo_StyleRule_Debug(rule: RawServoStyleRuleBorrowed,
result: *mut nsACString_internal);
Expand Down
26 changes: 26 additions & 0 deletions ports/geckolib/glue.rs
Expand Up @@ -43,6 +43,7 @@ use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t;
use style::gecko_bindings::structs;
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint};
use style::gecko_bindings::structs::nsresult;
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasBoxFFI};
use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong};
use style::gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
Expand Down Expand Up @@ -332,6 +333,31 @@ pub extern "C" fn Servo_CssRules_GetStyleRuleAt(rules: ServoCssRulesBorrowed, in
}
}

#[no_mangle]
pub extern "C" fn Servo_CssRules_InsertRule(rules: ServoCssRulesBorrowed, sheet: RawServoStyleSheetBorrowed,
rule: *const nsACString, index: u32, nested: bool,
rule_type: *mut u16) -> nsresult {
let rules = RwLock::<CssRules>::as_arc(&rules);
let sheet = Stylesheet::as_arc(&sheet);
let rule = unsafe { rule.as_ref().unwrap().as_str_unchecked() };
match rules.write().insert_rule(rule, sheet, index as usize, nested) {
Ok(new_rule) => {
*unsafe { rule_type.as_mut().unwrap() } = new_rule.rule_type() as u16;
nsresult::NS_OK
}
Err(err) => err.into()
}
}

#[no_mangle]
pub extern "C" fn Servo_CssRules_DeleteRule(rules: ServoCssRulesBorrowed, index: u32) -> nsresult {
let rules = RwLock::<CssRules>::as_arc(&rules);
match rules.write().remove_rule(index as usize) {
Ok(_) => nsresult::NS_OK,
Err(err) => err.into()
}
}

#[no_mangle]
pub extern "C" fn Servo_CssRules_AddRef(rules: ServoCssRulesBorrowed) -> () {
unsafe { RwLock::<CssRules>::addref(rules) };
Expand Down

0 comments on commit bddd467

Please sign in to comment.