Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement access to CSSStyleRule for stylo #14330

Merged
merged 5 commits into from Nov 24, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add stylo FFI for CSSStyleRule

  • Loading branch information
upsuper committed Nov 23, 2016
commit a9296bc89cdbdb634432d46dfa15791bfd22c614
@@ -335,7 +335,8 @@
"ServoComputedValues",
"ServoCssRules",
"RawServoStyleSheet",
"RawServoDeclarationBlock"
"RawServoDeclarationBlock",
"RawServoStyleRule",
],
"servo_owned_types": [
"RawServoStyleSet",
@@ -11,13 +11,14 @@
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, ServoCssRules};
use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, RawServoStyleRule};
use gecko_bindings::bindings::{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::{CssRule, Stylesheet};
use stylesheets::{CssRule, Stylesheet, StyleRule};
use values::computed::{CalcLengthOrPercentage, Gradient, Image, LengthOrPercentage, LengthOrPercentageOrAuto};

unsafe impl HasFFI for Stylesheet {
@@ -39,6 +40,11 @@ unsafe impl HasFFI for RwLock<Vec<CssRule>> {
}
unsafe impl HasArcFFI for RwLock<Vec<CssRule>> {}

unsafe impl HasFFI for RwLock<StyleRule> {
type FFIType = RawServoStyleRule;
}
unsafe impl HasArcFFI for RwLock<StyleRule> {}

impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
let has_percentage = other.percentage.is_some();
@@ -24,6 +24,11 @@ pub type RawServoDeclarationBlockBorrowedOrNull<'a> = Option<&'a RawServoDeclara
pub type RawServoDeclarationBlockBorrowed<'a> = &'a RawServoDeclarationBlock;
enum RawServoDeclarationBlockVoid{ }
pub struct RawServoDeclarationBlock(RawServoDeclarationBlockVoid);
pub type RawServoStyleRuleStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoStyleRule>;
pub type RawServoStyleRuleBorrowedOrNull<'a> = Option<&'a RawServoStyleRule>;
pub type RawServoStyleRuleBorrowed<'a> = &'a RawServoStyleRule;
enum RawServoStyleRuleVoid{ }
pub struct RawServoStyleRule(RawServoStyleRuleVoid);
pub type RawGeckoNodeBorrowed<'a> = &'a RawGeckoNode;
pub type RawGeckoNodeBorrowedOrNull<'a> = Option<&'a RawGeckoNode>;
pub type RawGeckoElementBorrowed<'a> = &'a RawGeckoElement;
@@ -220,6 +225,12 @@ extern "C" {
pub fn Servo_DeclarationBlock_Release(ptr:
RawServoDeclarationBlockBorrowed);
}
extern "C" {
pub fn Servo_StyleRule_AddRef(ptr: RawServoStyleRuleBorrowed);
}
extern "C" {
pub fn Servo_StyleRule_Release(ptr: RawServoStyleRuleBorrowed);
}
extern "C" {
pub fn Servo_StyleSet_Drop(ptr: RawServoStyleSetOwned);
}
@@ -994,6 +1005,11 @@ extern "C" {
pub fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed,
result: nsTArrayBorrowed_uintptr_t);
}
extern "C" {
pub fn Servo_CssRules_GetStyleRuleAt(rules: ServoCssRulesBorrowed,
index: u32)
-> RawServoStyleRuleStrong;
}
extern "C" {
pub fn Servo_ParseProperty(property: *const nsACString_internal,
value: *const nsACString_internal,
@@ -23,6 +23,7 @@ use style::gecko::wrapper::{GeckoElement, GeckoNode};
use style::gecko::wrapper::DUMMY_BASE_URL;
use style::gecko_bindings::bindings::{RawGeckoElementBorrowed, RawGeckoNodeBorrowed};
use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockStrong};
use style::gecko_bindings::bindings::{RawServoStyleRuleBorrowed, RawServoStyleRuleStrong};
use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
@@ -47,7 +48,7 @@ use style::properties::{apply_declarations, parse_one_declaration};
use style::selector_parser::PseudoElementCascadeType;
use style::sequential;
use style::string_cache::Atom;
use style::stylesheets::{CssRule, Origin, Stylesheet};
use style::stylesheets::{CssRule, Origin, Stylesheet, StyleRule};
use style::thread_state;
use style::timer::Timer;
use style_traits::ToCss;
@@ -290,6 +291,18 @@ pub extern "C" fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed,
result.iter_mut().zip(iter).fold((), |_, (r, v)| *r = v);
}

#[no_mangle]
pub extern "C" fn Servo_CssRules_GetStyleRuleAt(rules: ServoCssRulesBorrowed, index: u32)
-> RawServoStyleRuleStrong {
let rules = RwLock::<Vec<CssRule>>::as_arc(&rules).read();
match rules[index as usize] {
CssRule::Style(ref rule) => rule.clone().into_strong(),
_ => {
unreachable!("GetStyleRuleAt should only be called on a style rule");
}
}
}

#[no_mangle]
pub extern "C" fn Servo_CssRules_AddRef(rules: ServoCssRulesBorrowed) -> () {
unsafe { RwLock::<Vec<CssRule>>::addref(rules) };
@@ -300,6 +313,16 @@ pub extern "C" fn Servo_CssRules_Release(rules: ServoCssRulesBorrowed) -> () {
unsafe { RwLock::<Vec<CssRule>>::release(rules) };
}

#[no_mangle]
pub extern "C" fn Servo_StyleRule_AddRef(rule: RawServoStyleRuleBorrowed) -> () {
unsafe { RwLock::<StyleRule>::addref(rule) };
}

#[no_mangle]
pub extern "C" fn Servo_StyleRule_Release(rule: RawServoStyleRuleBorrowed) -> () {
unsafe { RwLock::<StyleRule>::release(rule) };
}

#[no_mangle]
pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)
-> ServoComputedValuesStrong {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.