Skip to content

Commit

Permalink
stylo: Add necessary stubbed-out bindings for ServoSpecifiedValues
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Feb 19, 2017
1 parent 180f2af commit 31945c2
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 54 deletions.
1 change: 1 addition & 0 deletions components/style/build_gecko.rs
Expand Up @@ -584,6 +584,7 @@ mod bindings {
"nsStyleVisibility",
"nsStyleXUL",
"nsTimingFunction",
"nscolor",
"nscoord",
"nsresult",
"Loader",
Expand Down
66 changes: 62 additions & 4 deletions components/style/gecko_bindings/bindings.rs
Expand Up @@ -159,6 +159,7 @@ use gecko_bindings::structs::nsStyleXUL;
unsafe impl Send for nsStyleXUL {}
unsafe impl Sync for nsStyleXUL {}
use gecko_bindings::structs::nsTimingFunction;
use gecko_bindings::structs::nscolor;
use gecko_bindings::structs::nscoord;
use gecko_bindings::structs::nsresult;
use gecko_bindings::structs::Loader;
Expand Down Expand Up @@ -1440,11 +1441,68 @@ extern "C" {
nsCSSPropertyID);
}
extern "C" {
pub fn Servo_DeclarationBlock_AddPresValue(declarations:
pub fn Servo_DeclarationBlock_PropertyIsSet(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID)
-> bool;
}
extern "C" {
pub fn Servo_DeclarationBlock_SetIdentStringValue(declarations:
RawServoDeclarationBlockBorrowed,
property:
nsCSSPropertyID,
value:
*const nsAString_internal);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetKeywordValue(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID,
value: i32);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetIntValue(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID,
value: i32);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetPixelValue(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID,
value: f32);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetPercentValue(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID,
value: f32);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetAutoValue(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID,
css_value:
nsCSSValueBorrowedMut);
property: nsCSSPropertyID);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetCurrentColor(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetColorValue(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID,
value: nscolor);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetFontFamily(declarations:
RawServoDeclarationBlockBorrowed,
value:
*const nsAString_internal);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetTextDecorationColorOverride(declarations:
RawServoDeclarationBlockBorrowed);
}
extern "C" {
pub fn Servo_CSSSupports2(name: *const nsACString_internal,
Expand Down
145 changes: 95 additions & 50 deletions ports/geckolib/glue.rs
Expand Up @@ -36,7 +36,7 @@ use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSet
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong};
use style::gecko_bindings::bindings::{nsACString, nsCSSValueBorrowedMut, nsAString};
use style::gecko_bindings::bindings::{nsACString, nsAString};
use style::gecko_bindings::bindings::Gecko_AnimationAppendKeyframe;
use style::gecko_bindings::bindings::RawGeckoAnimationValueListBorrowedMut;
use style::gecko_bindings::bindings::RawGeckoElementBorrowed;
Expand Down Expand Up @@ -952,58 +952,103 @@ pub extern "C" fn Servo_DeclarationBlock_RemovePropertyById(declarations: RawSer
remove_property(declarations, get_property_id_from_nscsspropertyid!(property, ()))
}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_AddPresValue(declarations: RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID,
css_value: nsCSSValueBorrowedMut) {
use style::gecko::values::convert_nscolor_to_rgba;
use style::properties::{DeclaredValue, LonghandId, PropertyDeclaration, PropertyId, longhands};
use style::values::specified;
macro_rules! get_longhand_from_id {
($id:expr, $retval:expr) => {
match PropertyId::from_nscsspropertyid($id) {
Ok(PropertyId::Longhand(long)) => long,
_ => {
error!("stylo: unknown presentation property with id {:?}", $id);
return $retval
}
}
}
}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_PropertyIsSet(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID)
-> bool {
use style::properties::PropertyDeclarationId;
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
let prop = PropertyId::from_nscsspropertyid(property);
let long = get_longhand_from_id!(property, false);
declarations.read().get(PropertyDeclarationId::Longhand(long)).is_some()
}

let long = match prop {
Ok(PropertyId::Longhand(long)) => long,
_ => {
warn!("stylo: unknown presentation property with id {:?}", property);
return
}
};
let decl = match long {
LonghandId::FontSize => {
if let Some(int) = css_value.integer() {
PropertyDeclaration::FontSize(DeclaredValue::Value(
longhands::font_size::SpecifiedValue(
specified::LengthOrPercentage::Length(
specified::NoCalcLength::from_font_size_int(int as u8)
)
)
))
} else {
warn!("stylo: got unexpected non-integer value for font-size presentation attribute");
return
}
}
LonghandId::Color => {
if let Some(color) = css_value.color_value() {
PropertyDeclaration::Color(DeclaredValue::Value(
specified::CSSRGBA {
parsed: convert_nscolor_to_rgba(color),
authored: None
}
))
} else {
warn!("stylo: got unexpected non-integer value for color presentation attribute");
return
}
}
_ => {
warn!("stylo: cannot handle longhand {:?} from presentation attribute", long);
return
}
};
declarations.write().declarations.push((decl, Importance::Normal));
#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetIdentStringValue(_:
RawServoDeclarationBlockBorrowed,
_:
nsCSSPropertyID,
_:
*const nsAString) {
//
error!("stylo: Don't know how to handle ident presentation attributes (-x-lang)");
}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(_:
RawServoDeclarationBlockBorrowed,
_: nsCSSPropertyID,
_: i32) {

}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetIntValue(_: RawServoDeclarationBlockBorrowed,
_: nsCSSPropertyID,
_: i32) {
error!("stylo: Don't know how to handle integer presentation attributes (-x-span)");
}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(_:
RawServoDeclarationBlockBorrowed,
_: nsCSSPropertyID,
_: f32) {

}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(_:
RawServoDeclarationBlockBorrowed,
_: nsCSSPropertyID,
_: f32) {

}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(_:
RawServoDeclarationBlockBorrowed,
_: nsCSSPropertyID) {

}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetCurrentColor(_:
RawServoDeclarationBlockBorrowed,
_: nsCSSPropertyID) {

}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetColorValue(_:
RawServoDeclarationBlockBorrowed,
_: nsCSSPropertyID,
_: structs::nscolor) {

}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(_:
RawServoDeclarationBlockBorrowed,
_: *const nsAString) {

}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetTextDecorationColorOverride(_:
RawServoDeclarationBlockBorrowed) {

}

Expand Down

0 comments on commit 31945c2

Please sign in to comment.