Remove all color stuff from nsCSSValue.

This commit is contained in:
Xidorn Quan 2018-04-05 18:32:57 +10:00
parent 665ea9037a
commit 8932dc98be

View file

@ -7,7 +7,7 @@
use gecko_bindings::bindings; use gecko_bindings::bindings;
use gecko_bindings::structs; use gecko_bindings::structs;
use gecko_bindings::structs::{nsCSSValue, nsCSSUnit}; use gecko_bindings::structs::{nsCSSValue, nsCSSUnit};
use gecko_bindings::structs::{nsCSSValue_Array, nsCSSValueList, nscolor}; use gecko_bindings::structs::{nsCSSValue_Array, nsCSSValueList};
use gecko_string_cache::Atom; use gecko_string_cache::Atom;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem; use std::mem;
@ -33,33 +33,20 @@ impl nsCSSValue {
/// builds. /// builds.
pub fn integer_unchecked(&self) -> i32 { pub fn integer_unchecked(&self) -> i32 {
debug_assert!(self.mUnit == nsCSSUnit::eCSSUnit_Integer || debug_assert!(self.mUnit == nsCSSUnit::eCSSUnit_Integer ||
self.mUnit == nsCSSUnit::eCSSUnit_Enumerated || self.mUnit == nsCSSUnit::eCSSUnit_Enumerated);
self.mUnit == nsCSSUnit::eCSSUnit_EnumColor);
unsafe { *self.mValue.mInt.as_ref() } unsafe { *self.mValue.mInt.as_ref() }
} }
/// Checks if it is an integer and returns it if so /// Checks if it is an integer and returns it if so
pub fn integer(&self) -> Option<i32> { pub fn integer(&self) -> Option<i32> {
if self.mUnit == nsCSSUnit::eCSSUnit_Integer || if self.mUnit == nsCSSUnit::eCSSUnit_Integer ||
self.mUnit == nsCSSUnit::eCSSUnit_Enumerated || self.mUnit == nsCSSUnit::eCSSUnit_Enumerated {
self.mUnit == nsCSSUnit::eCSSUnit_EnumColor {
Some(unsafe { *self.mValue.mInt.as_ref() }) Some(unsafe { *self.mValue.mInt.as_ref() })
} else { } else {
None None
} }
} }
/// Checks if it is an RGBA color, returning it if so
/// Only use it with colors set by SetColorValue(),
/// which always sets RGBA colors
pub fn color_value(&self) -> Option<nscolor> {
if self.mUnit == nsCSSUnit::eCSSUnit_RGBAColor {
Some(unsafe { *self.mValue.mColor.as_ref() })
} else {
None
}
}
/// Returns this nsCSSValue value as a floating point value, unchecked in /// Returns this nsCSSValue value as a floating point value, unchecked in
/// release builds. /// release builds.
pub fn float_unchecked(&self) -> f32 { pub fn float_unchecked(&self) -> f32 {