Skip to content

Commit

Permalink
Simplify caret-color conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed Jun 8, 2017
1 parent c629355 commit 5c643ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
33 changes: 20 additions & 13 deletions components/style/gecko_bindings/sugar/style_complex_color.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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)
}
}
}
22 changes: 2 additions & 20 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 5c643ad

Please sign in to comment.