Simplify caret-color conversion.

This commit is contained in:
Xidorn Quan 2017-06-08 10:42:32 +10:00
parent c62935577a
commit 5c643adb98
2 changed files with 22 additions and 33 deletions

View file

@ -6,7 +6,7 @@
use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
use gecko_bindings::structs::{nscolor, StyleComplexColor};
use values;
use values::{Auto, Either};
use values::computed::Color as ComputedColor;
impl From<nscolor> for StyleComplexColor {
@ -49,18 +49,6 @@ impl From<ComputedColor> for StyleComplexColor {
}
}
impl From<StyleComplexColor> for values::computed::ColorOrAuto {
fn from(color: StyleComplexColor) -> Self {
use values::{Auto, Either};
if color.mIsAuto {
return Either::Second(Auto);
}
Either::First(color.into())
}
}
impl From<StyleComplexColor> for ComputedColor {
fn from(other: StyleComplexColor) -> Self {
debug_assert!(!other.mIsAuto);
@ -70,3 +58,22 @@ impl From<StyleComplexColor> for ComputedColor {
}
}
}
impl From<Either<ComputedColor, Auto>> for StyleComplexColor {
fn from(other: Either<ComputedColor, Auto>) -> Self {
match other {
Either::First(color) => color.into(),
Either::Second(_auto) => StyleComplexColor::auto(),
}
}
}
impl From<StyleComplexColor> for Either<ComputedColor, Auto> {
fn from(other: StyleComplexColor) -> Self {
if !other.mIsAuto {
Either::First(other.into())
} else {
Either::Second(Auto)
}
}
}

View file

@ -42,7 +42,7 @@ use gecko_bindings::bindings::Gecko_SetNullImageValue;
use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
use gecko_bindings::bindings::RawGeckoPresContextBorrowed;
use gecko_bindings::structs::{self, StyleComplexColor};
use gecko_bindings::structs;
use gecko_bindings::structs::nsCSSPropertyID;
use gecko_bindings::structs::nsStyleVariables;
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
@ -4259,25 +4259,7 @@ clip-path
}
}
pub fn set_caret_color(&mut self, v: longhands::caret_color::computed_value::T){
use values::Either;
match v {
Either::First(color) => {
self.gecko.mCaretColor = StyleComplexColor::from(color);
}
Either::Second(_auto) => {
self.gecko.mCaretColor = StyleComplexColor::auto();
}
}
}
pub fn copy_caret_color_from(&mut self, other: &Self){
self.gecko.mCaretColor = other.gecko.mCaretColor;
}
<%call expr="impl_color_clone('caret_color', 'mCaretColor')"></%call>
<%call expr="impl_color('caret_color', 'mCaretColor', need_clone=True)"></%call>
</%self:impl_trait>
<%self:impl_trait style_struct_name="Column"