aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXidorn Quan <me@upsuper.org>2016-11-29 23:02:05 +1100
committerXidorn Quan <me@upsuper.org>2016-12-01 16:20:02 +1100
commitbddd467c0e79257303e5a8785cd7059b4927ff40 (patch)
treea1136f713b3645431638030012b25b1f003556d5
parent22c8df150af341064abac25a26768c8c1517df1f (diff)
downloadservo-bddd467c0e79257303e5a8785cd7059b4927ff40.tar.gz
servo-bddd467c0e79257303e5a8785cd7059b4927ff40.zip
Add insertRule/deleteRule support for stylo
-rwxr-xr-xcomponents/style/binding_tools/regen.py3
-rw-r--r--components/style/gecko/conversions.rs14
-rw-r--r--components/style/gecko_bindings/bindings.rs14
-rw-r--r--ports/geckolib/glue.rs26
4 files changed, 54 insertions, 3 deletions
diff --git a/components/style/binding_tools/regen.py b/components/style/binding_tools/regen.py
index 1c7e193fa13..62f5a719daf 100755
--- a/components/style/binding_tools/regen.py
+++ b/components/style/binding_tools/regen.py
@@ -277,7 +277,6 @@ COMPILATION_TARGETS = {
"StyleBasicShape",
"StyleBasicShapeType",
"StyleClipPath",
- "nscoord",
"nsCSSKeyword",
"nsCSSShadowArray",
"nsCSSValue",
@@ -331,6 +330,8 @@ COMPILATION_TARGETS = {
"nsStyleVariables",
"nsStyleVisibility",
"nsStyleXUL",
+ "nscoord",
+ "nsresult",
],
"array_types": {
"uintptr_t": "usize",
diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs
index 89a53fdd697..e32168a436d 100644
--- a/components/style/gecko/conversions.rs
+++ b/components/style/gecko/conversions.rs
@@ -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 {
@@ -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,
+ }
+ }
+}
diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs
index de034c92460..fb290136855 100644
--- a/components/style/gecko_bindings/bindings.rs
+++ b/components/style/gecko_bindings/bindings.rs
@@ -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;
@@ -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)]
@@ -1026,6 +1027,17 @@ extern "C" {
-> 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);
}
diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs
index deed07b856d..3043f879e64 100644
--- a/ports/geckolib/glue.rs
+++ b/ports/geckolib/glue.rs
@@ -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};
@@ -333,6 +334,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) };
}