Add glue for calc values

This commit is contained in:
Manish Goregaokar 2016-07-15 20:23:20 +05:30
parent b52b78c340
commit 67bcb96cea
No known key found for this signature in database
GPG key ID: 3BBF4D3E2EF79F98
4 changed files with 73 additions and 0 deletions

View file

@ -0,0 +1,36 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! This module contains conversion helpers between Servo and Gecko types
//! Ideally, it would be in geckolib itself, but coherence
//! forces us to keep the traits and implementations here
use app_units::Au;
use gecko_bindings::structs::nsStyleCoord_CalcValue;
use values::computed::CalcLengthOrPercentage;
impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
let has_percentage = other.percentage.is_some();
nsStyleCoord_CalcValue {
mLength: other.length.map(|l| l.0).unwrap_or(0),
mPercent: other.percentage.unwrap_or(0.0),
mHasPercent: has_percentage,
}
}
}
impl From<nsStyleCoord_CalcValue> for CalcLengthOrPercentage {
fn from(other: nsStyleCoord_CalcValue) -> CalcLengthOrPercentage {
let percentage = if other.mHasPercent {
Some(other.mPercent)
} else {
None
};
CalcLengthOrPercentage {
length: Some(Au(other.mLength)),
percentage: percentage,
}
}
}

View file

@ -80,6 +80,8 @@ pub mod data;
pub mod dom;
pub mod element_state;
pub mod error_reporting;
#[cfg(feature = "gecko")]
pub mod gecko_conversions;
pub mod font_face;
pub mod keyframes;
pub mod logical_geometry;