mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
Implement a MinLength type
Implement an ExtremumLength type which contains all the enumerated keyword values for min-width, min-height, max-width, and max-height. Then, implement a MinLength which can be used for min-width and min-height. So far this just maps to Gecko values. Refs #13821.
This commit is contained in:
parent
063aec5ade
commit
76de979231
9 changed files with 199 additions and 10 deletions
|
@ -11,9 +11,10 @@ use cssparser::RGBA;
|
|||
use gecko_bindings::structs::{nsStyleCoord, StyleGridTrackBreadth, StyleShapeRadius};
|
||||
use gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
||||
use std::cmp::max;
|
||||
use values::{Auto, Either, None_, Normal};
|
||||
use values::{Auto, Either, ExtremumLength, None_, Normal};
|
||||
use values::computed::{Angle, LengthOrPercentageOrNone, Number};
|
||||
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
use values::computed::MinLength;
|
||||
use values::computed::basic_shape::ShapeRadius;
|
||||
use values::specified::grid::{TrackBreadth, TrackKeyword};
|
||||
|
||||
|
@ -271,6 +272,55 @@ impl GeckoStyleCoordConvertible for Normal {
|
|||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for ExtremumLength {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
use gecko_bindings::structs::{NS_STYLE_WIDTH_AVAILABLE, NS_STYLE_WIDTH_FIT_CONTENT};
|
||||
use gecko_bindings::structs::{NS_STYLE_WIDTH_MAX_CONTENT, NS_STYLE_WIDTH_MIN_CONTENT};
|
||||
coord.set_value(CoordDataValue::Enumerated(
|
||||
match *self {
|
||||
ExtremumLength::MaxContent => NS_STYLE_WIDTH_MAX_CONTENT,
|
||||
ExtremumLength::MinContent => NS_STYLE_WIDTH_MIN_CONTENT,
|
||||
ExtremumLength::FitContent => NS_STYLE_WIDTH_FIT_CONTENT,
|
||||
ExtremumLength::FillAvailable => NS_STYLE_WIDTH_AVAILABLE,
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
use gecko_bindings::structs::{NS_STYLE_WIDTH_AVAILABLE, NS_STYLE_WIDTH_FIT_CONTENT};
|
||||
use gecko_bindings::structs::{NS_STYLE_WIDTH_MAX_CONTENT, NS_STYLE_WIDTH_MIN_CONTENT};
|
||||
match coord.as_value() {
|
||||
CoordDataValue::Enumerated(NS_STYLE_WIDTH_MAX_CONTENT) =>
|
||||
Some(ExtremumLength::MaxContent),
|
||||
CoordDataValue::Enumerated(NS_STYLE_WIDTH_MIN_CONTENT) =>
|
||||
Some(ExtremumLength::MinContent),
|
||||
CoordDataValue::Enumerated(NS_STYLE_WIDTH_FIT_CONTENT) =>
|
||||
Some(ExtremumLength::FitContent),
|
||||
CoordDataValue::Enumerated(NS_STYLE_WIDTH_AVAILABLE) => Some(ExtremumLength::FillAvailable),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for MinLength {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
MinLength::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord),
|
||||
MinLength::Auto => coord.set_value(CoordDataValue::Auto),
|
||||
MinLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
LengthOrPercentage::from_gecko_style_coord(coord).map(MinLength::LengthOrPercentage)
|
||||
.or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MinLength::ExtremumLength))
|
||||
.or_else(|| match coord.as_value() {
|
||||
CoordDataValue::Auto => Some(MinLength::Auto),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a given RGBA value to `nscolor`.
|
||||
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
|
||||
((rgba.alpha as u32) << 24) |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue