diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2017-08-30 00:31:39 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-08-30 23:01:12 +0200 |
commit | 542a9337a49989e90273e6fc320e86105abfbc9a (patch) | |
tree | 374838c4dfc9543fda36501d2b706bd90f74ff71 /components/style/gecko/conversions.rs | |
parent | 19cbea23a869cfb6d62d95f36c343e7c287129b9 (diff) | |
download | servo-542a9337a49989e90273e6fc320e86105abfbc9a.tar.gz servo-542a9337a49989e90273e6fc320e86105abfbc9a.zip |
Use generics for the vertical-align property
Diffstat (limited to 'components/style/gecko/conversions.rs')
-rw-r--r-- | components/style/gecko/conversions.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index f8455749ae3..ee13e6fffe7 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -12,13 +12,14 @@ use app_units::Au; use gecko::values::{convert_rgba_to_nscolor, GeckoStyleCoordConvertible}; use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetLayerImageImageValue}; use gecko_bindings::bindings::{Gecko_InitializeImageCropRect, Gecko_SetImageElement}; -use gecko_bindings::structs::{nsCSSUnit, nsStyleCoord_CalcValue, nsStyleImage}; -use gecko_bindings::structs::{nsresult, SheetType}; +use gecko_bindings::structs::{self, nsCSSUnit, nsStyleCoord_CalcValue}; +use gecko_bindings::structs::{nsStyleImage, nsresult, SheetType}; use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut}; use std::f32::consts::PI; use stylesheets::{Origin, RulesMutateError}; use values::computed::{Angle, CalcLengthOrPercentage, Gradient, Image}; use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, Percentage}; +use values::generics::box_::VerticalAlign; use values::generics::grid::TrackSize; use values::generics::image::{CompatMode, Image as GenericImage, GradientItem}; use values::generics::rect::Rect; @@ -920,6 +921,26 @@ impl<T> Rect<T> where T: GeckoStyleCoordConvertible { } } +impl<L> VerticalAlign<L> { + /// Converts an enumerated value coming from Gecko to a `VerticalAlign<L>`. + pub fn from_gecko_keyword(value: u32) -> Self { + match value { + structs::NS_STYLE_VERTICAL_ALIGN_BASELINE => VerticalAlign::Baseline, + structs::NS_STYLE_VERTICAL_ALIGN_SUB => VerticalAlign::Sub, + structs::NS_STYLE_VERTICAL_ALIGN_SUPER => VerticalAlign::Super, + structs::NS_STYLE_VERTICAL_ALIGN_TOP => VerticalAlign::Top, + structs::NS_STYLE_VERTICAL_ALIGN_TEXT_TOP => VerticalAlign::TextTop, + structs::NS_STYLE_VERTICAL_ALIGN_MIDDLE => VerticalAlign::Middle, + structs::NS_STYLE_VERTICAL_ALIGN_BOTTOM => VerticalAlign::Bottom, + structs::NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM => VerticalAlign::TextBottom, + structs::NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE => { + VerticalAlign::MozMiddleWithBaseline + }, + _ => panic!("unexpected enumerated value for vertical-align"), + } + } +} + /// Convert to String from given chars pointer. pub unsafe fn string_from_chars_pointer(p: *const u16) -> String { use std::slice; |