aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorXidorn Quan <me@upsuper.org>2016-11-23 10:30:48 +1100
committerXidorn Quan <me@upsuper.org>2016-11-24 10:28:38 +1100
commit9d4ab0d3e9545419fc9f6ab8cee406aed1e54757 (patch)
treeb059bc1b61742eee62c29556e63e3153f1f8a0f9 /components
parent210b1be1d093adf3a4fb4d4360c6e016676f34be (diff)
downloadservo-9d4ab0d3e9545419fc9f6ab8cee406aed1e54757.tar.gz
servo-9d4ab0d3e9545419fc9f6ab8cee406aed1e54757.zip
Add stylo FFI for CSSRuleList
Diffstat (limited to 'components')
-rwxr-xr-xcomponents/style/binding_tools/regen.py15
-rw-r--r--components/style/gecko/conversions.rs9
-rw-r--r--components/style/gecko_bindings/bindings.rs20
-rw-r--r--components/style/stylesheets.rs35
4 files changed, 76 insertions, 3 deletions
diff --git a/components/style/binding_tools/regen.py b/components/style/binding_tools/regen.py
index 4e0ef4b0e9b..1187e0d677e 100755
--- a/components/style/binding_tools/regen.py
+++ b/components/style/binding_tools/regen.py
@@ -328,8 +328,13 @@ COMPILATION_TARGETS = {
"nsStyleVisibility",
"nsStyleXUL",
],
+ "array_types": {
+ "uintptr_t": "usize",
+ },
"servo_nullable_arc_types": [
- "ServoComputedValues", "RawServoStyleSheet",
+ "ServoComputedValues",
+ "ServoCssRules",
+ "RawServoStyleSheet",
"RawServoDeclarationBlock"
],
"servo_owned_types": [
@@ -535,6 +540,14 @@ def build(objdir, target_name, debug, debugger, kind_name=None,
flags.append("--opaque-type")
flags.append(ty)
+ if "array_types" in current_target:
+ for cpp_type, rust_type in current_target["array_types"].items():
+ flags.append("--blacklist-type")
+ flags.append("nsTArrayBorrowed_{}".format(cpp_type))
+ flags.append("--raw-line")
+ flags.append("pub type nsTArrayBorrowed_{0}<'a> = &'a mut ::gecko_bindings::structs::nsTArray<{1}>;"
+ .format(cpp_type, rust_type))
+
if "blacklist_types" in current_target:
for ty in current_target["blacklist_types"]:
flags.append("--blacklist-type")
diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs
index 950003a2249..25daba40daf 100644
--- a/components/style/gecko/conversions.rs
+++ b/components/style/gecko/conversions.rs
@@ -11,13 +11,13 @@
use app_units::Au;
use gecko::values::{convert_rgba_to_nscolor, StyleCoordHelpers};
use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetUrlImageValue};
-use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, ServoComputedValues};
+use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, ServoComputedValues, ServoCssRules};
use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage};
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::Stylesheet;
+use stylesheets::{CssRule, Stylesheet};
use values::computed::{CalcLengthOrPercentage, Gradient, Image, LengthOrPercentage, LengthOrPercentageOrAuto};
unsafe impl HasFFI for Stylesheet {
@@ -34,6 +34,11 @@ unsafe impl HasFFI for RwLock<PropertyDeclarationBlock> {
}
unsafe impl HasArcFFI for RwLock<PropertyDeclarationBlock> {}
+unsafe impl HasFFI for RwLock<Vec<CssRule>> {
+ type FFIType = ServoCssRules;
+}
+unsafe impl HasArcFFI for RwLock<Vec<CssRule>> {}
+
impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
let has_percentage = other.percentage.is_some();
diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs
index dcd961263c6..32d68b78b58 100644
--- a/components/style/gecko_bindings/bindings.rs
+++ b/components/style/gecko_bindings/bindings.rs
@@ -3,11 +3,17 @@
pub use nsstring::{nsACString, nsAString};
type nsACString_internal = nsACString;
type nsAString_internal = nsAString;
+pub type nsTArrayBorrowed_uintptr_t<'a> = &'a mut ::gecko_bindings::structs::nsTArray<usize>;
pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>;
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
enum ServoComputedValuesVoid{ }
pub struct ServoComputedValues(ServoComputedValuesVoid);
+pub type ServoCssRulesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoCssRules>;
+pub type ServoCssRulesBorrowedOrNull<'a> = Option<&'a ServoCssRules>;
+pub type ServoCssRulesBorrowed<'a> = &'a ServoCssRules;
+enum ServoCssRulesVoid{ }
+pub struct ServoCssRules(ServoCssRulesVoid);
pub type RawServoStyleSheetStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoStyleSheet>;
pub type RawServoStyleSheetBorrowedOrNull<'a> = Option<&'a RawServoStyleSheet>;
pub type RawServoStyleSheetBorrowed<'a> = &'a RawServoStyleSheet;
@@ -189,6 +195,12 @@ pub type RawGeckoNode = nsINode;
pub type RawGeckoElement = Element;
pub type RawGeckoDocument = nsIDocument;
extern "C" {
+ pub fn Servo_CssRules_AddRef(ptr: ServoCssRulesBorrowed);
+}
+extern "C" {
+ pub fn Servo_CssRules_Release(ptr: ServoCssRulesBorrowed);
+}
+extern "C" {
pub fn Servo_StyleSheet_AddRef(ptr: RawServoStyleSheetBorrowed);
}
extern "C" {
@@ -951,6 +963,10 @@ extern "C" {
-> bool;
}
extern "C" {
+ pub fn Servo_StyleSheet_GetRules(sheet: RawServoStyleSheetBorrowed)
+ -> ServoCssRulesStrong;
+}
+extern "C" {
pub fn Servo_StyleSet_Init() -> RawServoStyleSetOwned;
}
extern "C" {
@@ -975,6 +991,10 @@ extern "C" {
RawServoStyleSheetBorrowed);
}
extern "C" {
+ pub fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed,
+ result: nsTArrayBorrowed_uintptr_t);
+}
+extern "C" {
pub fn Servo_ParseProperty(property: *const nsACString_internal,
value: *const nsACString_internal,
base_url: *const nsACString_internal,
diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs
index 6e057e26f37..12ca0423cfa 100644
--- a/components/style/stylesheets.rs
+++ b/components/style/stylesheets.rs
@@ -136,6 +136,30 @@ pub enum CssRule {
Keyframes(Arc<RwLock<KeyframesRule>>),
}
+pub enum CssRuleType {
+ // https://drafts.csswg.org/cssom/#the-cssrule-interface
+ Style = 1,
+ Charset = 2,
+ Import = 3,
+ Media = 4,
+ FontFace = 5,
+ Page = 6,
+ // https://drafts.csswg.org/css-animations-1/#interface-cssrule-idl
+ Keyframes = 7,
+ Keyframe = 8,
+ // https://drafts.csswg.org/cssom/#the-cssrule-interface
+ Margin = 9,
+ Namespace = 10,
+ // https://drafts.csswg.org/css-counter-styles-3/#extentions-to-cssrule-interface
+ CounterStyle = 11,
+ // https://drafts.csswg.org/css-conditional-3/#extentions-to-cssrule-interface
+ Supports = 12,
+ // https://drafts.csswg.org/css-fonts-3/#om-fontfeaturevalues
+ FontFeatureValues = 14,
+ // https://drafts.csswg.org/css-device-adapt/#css-rule-interface
+ Viewport = 15,
+}
+
/// Error reporter which silently forgets errors
pub struct MemoryHoleReporter;
@@ -157,6 +181,17 @@ pub enum SingleRuleParseError {
}
impl CssRule {
+ pub fn rule_type(&self) -> CssRuleType {
+ match *self {
+ CssRule::Style(_) => CssRuleType::Style,
+ CssRule::Media(_) => CssRuleType::Media,
+ CssRule::FontFace(_) => CssRuleType::FontFace,
+ CssRule::Keyframes(_) => CssRuleType::Keyframes,
+ CssRule::Namespace(_) => CssRuleType::Namespace,
+ CssRule::Viewport(_) => CssRuleType::Viewport,
+ }
+ }
+
/// Call `f` with the slice of rules directly contained inside this rule.
///
/// Note that only some types of rules can contain rules. An empty slice is used for others.