mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Create sugar for nsCSSShadowItem.
This commit is contained in:
parent
3e47e6eab2
commit
a87f63fa04
3 changed files with 49 additions and 70 deletions
|
@ -7,6 +7,7 @@
|
|||
mod ns_com_ptr;
|
||||
mod ns_compatibility;
|
||||
mod ns_css_shadow_array;
|
||||
mod ns_css_shadow_item;
|
||||
pub mod ns_css_value;
|
||||
mod ns_style_auto_array;
|
||||
pub mod ns_style_coord;
|
||||
|
|
43
components/style/gecko_bindings/sugar/ns_css_shadow_item.rs
Normal file
43
components/style/gecko_bindings/sugar/ns_css_shadow_item.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! 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;
|
||||
|
||||
impl nsCSSShadowItem {
|
||||
/// Set this item to the given shadow value.
|
||||
pub fn set_from_shadow(&mut self, other: Shadow) {
|
||||
self.mXOffset = other.offset_x.0;
|
||||
self.mYOffset = other.offset_y.0;
|
||||
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)
|
||||
},
|
||||
// TODO handle currentColor
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=760345
|
||||
Color::CurrentColor => 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate shadow value from this shadow item.
|
||||
pub fn to_shadow(&self) -> Shadow {
|
||||
Shadow {
|
||||
offset_x: Au(self.mXOffset),
|
||||
offset_y: Au(self.mYOffset),
|
||||
blur_radius: Au(self.mRadius),
|
||||
spread_radius: Au(self.mSpread),
|
||||
inset: self.mInset,
|
||||
color: Color::RGBA(convert_nscolor_to_rgba(self.mColor)),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3314,27 +3314,9 @@ fn static_assert() {
|
|||
I::IntoIter: ExactSizeIterator
|
||||
{
|
||||
let v = v.into_iter();
|
||||
|
||||
self.gecko.mBoxShadow.replace_with_new(v.len() as u32);
|
||||
|
||||
for (servo, gecko_shadow) in v.zip(self.gecko.mBoxShadow.iter_mut()) {
|
||||
|
||||
gecko_shadow.mXOffset = servo.offset_x.0;
|
||||
gecko_shadow.mYOffset = servo.offset_y.0;
|
||||
gecko_shadow.mRadius = servo.blur_radius.0;
|
||||
gecko_shadow.mSpread = servo.spread_radius.0;
|
||||
gecko_shadow.mSpread = servo.spread_radius.0;
|
||||
gecko_shadow.mInset = servo.inset;
|
||||
gecko_shadow.mColor = match servo.color {
|
||||
Color::RGBA(rgba) => {
|
||||
gecko_shadow.mHasColor = true;
|
||||
convert_rgba_to_nscolor(&rgba)
|
||||
},
|
||||
// TODO handle currentColor
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=760345
|
||||
Color::CurrentColor => 0,
|
||||
}
|
||||
|
||||
gecko_shadow.set_from_shadow(servo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3343,16 +3325,7 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn clone_box_shadow(&self) -> longhands::box_shadow::computed_value::T {
|
||||
let buf = self.gecko.mBoxShadow.iter().map(|shadow| {
|
||||
Shadow {
|
||||
offset_x: Au(shadow.mXOffset),
|
||||
offset_y: Au(shadow.mYOffset),
|
||||
blur_radius: Au(shadow.mRadius),
|
||||
spread_radius: Au(shadow.mSpread),
|
||||
inset: shadow.mInset,
|
||||
color: Color::RGBA(convert_nscolor_to_rgba(shadow.mColor)),
|
||||
}
|
||||
}).collect();
|
||||
let buf = self.gecko.mBoxShadow.iter().map(|v| v.to_shadow()).collect();
|
||||
longhands::box_shadow::computed_value::T(buf)
|
||||
}
|
||||
|
||||
|
@ -3524,21 +3497,7 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
let mut gecko_shadow = init_shadow(gecko_filter);
|
||||
gecko_shadow.mArray[0].mXOffset = shadow.offset_x.0;
|
||||
gecko_shadow.mArray[0].mYOffset = shadow.offset_y.0;
|
||||
gecko_shadow.mArray[0].mRadius = shadow.blur_radius.0;
|
||||
// mSpread is not supported in the spec, so we leave it as 0
|
||||
gecko_shadow.mArray[0].mInset = false; // Not supported in spec level 1
|
||||
|
||||
gecko_shadow.mArray[0].mColor = match shadow.color {
|
||||
Color::RGBA(rgba) => {
|
||||
gecko_shadow.mArray[0].mHasColor = true;
|
||||
convert_rgba_to_nscolor(&rgba)
|
||||
},
|
||||
// TODO handle currentColor
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=760345
|
||||
Color::CurrentColor => 0,
|
||||
};
|
||||
gecko_shadow.mArray[0].set_from_shadow(shadow);
|
||||
}
|
||||
Url(ref url) => {
|
||||
unsafe {
|
||||
|
@ -3622,24 +3581,9 @@ fn static_assert() {
|
|||
I::IntoIter: ExactSizeIterator
|
||||
{
|
||||
let v = v.into_iter();
|
||||
|
||||
self.gecko.mTextShadow.replace_with_new(v.len() as u32);
|
||||
|
||||
for (servo, gecko_shadow) in v.zip(self.gecko.mTextShadow.iter_mut()) {
|
||||
gecko_shadow.mXOffset = servo.offset_x.0;
|
||||
gecko_shadow.mYOffset = servo.offset_y.0;
|
||||
gecko_shadow.mRadius = servo.blur_radius.0;
|
||||
gecko_shadow.mHasColor = false;
|
||||
gecko_shadow.mColor = match servo.color {
|
||||
Color::RGBA(rgba) => {
|
||||
gecko_shadow.mHasColor = true;
|
||||
convert_rgba_to_nscolor(&rgba)
|
||||
},
|
||||
// TODO handle currentColor
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=760345
|
||||
Color::CurrentColor => 0,
|
||||
}
|
||||
|
||||
gecko_shadow.set_from_shadow(servo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3648,16 +3592,7 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn clone_text_shadow(&self) -> longhands::text_shadow::computed_value::T {
|
||||
let buf = self.gecko.mTextShadow.iter().map(|shadow| {
|
||||
Shadow {
|
||||
offset_x: Au(shadow.mXOffset),
|
||||
offset_y: Au(shadow.mYOffset),
|
||||
blur_radius: Au(shadow.mRadius),
|
||||
spread_radius: Au(0),
|
||||
color: Color::RGBA(convert_nscolor_to_rgba(shadow.mColor)),
|
||||
inset: false,
|
||||
}
|
||||
}).collect();
|
||||
let buf = self.gecko.mTextShadow.iter().map(|v| v.to_shadow()).collect();
|
||||
longhands::text_shadow::computed_value::T(buf)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue