mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Add separate computed Color value.
This commit is contained in:
parent
742c45f859
commit
c62935577a
20 changed files with 317 additions and 145 deletions
|
@ -5,10 +5,9 @@
|
|||
//! Rust helpers for Gecko's `nsCSSShadowItem`.
|
||||
|
||||
use app_units::Au;
|
||||
use cssparser::Color;
|
||||
use gecko::values::{convert_rgba_to_nscolor, convert_nscolor_to_rgba};
|
||||
use gecko_bindings::structs::nsCSSShadowItem;
|
||||
use values::computed::Shadow;
|
||||
use values::computed::{Color, Shadow};
|
||||
|
||||
impl nsCSSShadowItem {
|
||||
/// Set this item to the given shadow value.
|
||||
|
@ -18,14 +17,14 @@ impl nsCSSShadowItem {
|
|||
self.mRadius = other.blur_radius.0;
|
||||
self.mSpread = other.spread_radius.0;
|
||||
self.mInset = other.inset;
|
||||
self.mColor = match other.color {
|
||||
Color::RGBA(rgba) => {
|
||||
self.mHasColor = true;
|
||||
convert_rgba_to_nscolor(&rgba)
|
||||
},
|
||||
if other.color.is_currentcolor() {
|
||||
// TODO handle currentColor
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=760345
|
||||
Color::CurrentColor => 0,
|
||||
self.mHasColor = false;
|
||||
self.mColor = 0;
|
||||
} else {
|
||||
self.mHasColor = true;
|
||||
self.mColor = convert_rgba_to_nscolor(&other.color.color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +36,7 @@ impl nsCSSShadowItem {
|
|||
blur_radius: Au(self.mRadius),
|
||||
spread_radius: Au(self.mSpread),
|
||||
inset: self.mInset,
|
||||
color: Color::RGBA(convert_nscolor_to_rgba(self.mColor)),
|
||||
color: Color::rgba(convert_nscolor_to_rgba(self.mColor)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
//! Rust helpers to interact with Gecko's StyleComplexColor.
|
||||
|
||||
use cssparser;
|
||||
use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
|
||||
use gecko_bindings::structs::{nscolor, StyleComplexColor};
|
||||
use values;
|
||||
use values::computed::Color as ComputedColor;
|
||||
|
||||
impl From<nscolor> for StyleComplexColor {
|
||||
fn from(other: nscolor) -> Self {
|
||||
|
@ -39,13 +39,12 @@ impl StyleComplexColor {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<cssparser::Color> for StyleComplexColor {
|
||||
fn from(other: cssparser::Color) -> Self {
|
||||
use cssparser::Color;
|
||||
|
||||
match other {
|
||||
Color::RGBA(rgba) => convert_rgba_to_nscolor(&rgba).into(),
|
||||
Color::CurrentColor => StyleComplexColor::current_color(),
|
||||
impl From<ComputedColor> for StyleComplexColor {
|
||||
fn from(other: ComputedColor) -> Self {
|
||||
StyleComplexColor {
|
||||
mColor: convert_rgba_to_nscolor(&other.color).into(),
|
||||
mForegroundRatio: other.foreground_ratio,
|
||||
mIsAuto: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,17 +61,12 @@ impl From<StyleComplexColor> for values::computed::ColorOrAuto {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<StyleComplexColor> for cssparser::Color {
|
||||
impl From<StyleComplexColor> for ComputedColor {
|
||||
fn from(other: StyleComplexColor) -> Self {
|
||||
use cssparser::Color;
|
||||
|
||||
if other.mForegroundRatio == 0 {
|
||||
Color::RGBA(convert_nscolor_to_rgba(other.mColor))
|
||||
} else if other.mForegroundRatio == 255 {
|
||||
Color::CurrentColor
|
||||
} else {
|
||||
// FIXME #13546 handle interpolation values
|
||||
Color::CurrentColor
|
||||
debug_assert!(!other.mIsAuto);
|
||||
ComputedColor {
|
||||
color: convert_nscolor_to_rgba(other.mColor),
|
||||
foreground_ratio: other.mForegroundRatio,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue