mirror of
https://github.com/servo/servo.git
synced 2025-06-25 01:24:37 +01:00
Make most background- properties handle arrays
This commit is contained in:
parent
ce9640a48e
commit
65a8a8dccb
4 changed files with 72 additions and 67 deletions
|
@ -937,6 +937,32 @@ fn static_assert() {
|
||||||
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
|
<%def name="simple_background_array_property(name, field_name)">
|
||||||
|
pub fn copy_background_${name}_from(&mut self, other: &Self) {
|
||||||
|
unsafe {
|
||||||
|
Gecko_EnsureImageLayersLength(&mut self.gecko.mImage, other.gecko.mImage.mLayers.len());
|
||||||
|
}
|
||||||
|
for (layer, other) in self.gecko.mImage.mLayers.iter_mut()
|
||||||
|
.zip(other.gecko.mImage.mLayers.iter())
|
||||||
|
.take(other.gecko.mImage.${field_name}Count) {
|
||||||
|
layer.${field_name} = other.${field_name};
|
||||||
|
}
|
||||||
|
self.gecko.mImage.${field_name}Count = other.gecko.mImage.${field_name}Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_background_${name}(&mut self, v: longhands::background_${name}::computed_value::T) {
|
||||||
|
unsafe {
|
||||||
|
Gecko_EnsureImageLayersLength(&mut self.gecko.mImage, v.0.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
self.gecko.mImage.${field_name}Count = v.0.len() as u32;
|
||||||
|
for (servo, geckolayer) in v.0.into_iter().zip(self.gecko.mImage.mLayers.iter_mut()) {
|
||||||
|
geckolayer.${field_name} = {
|
||||||
|
${caller.body()}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</%def>
|
||||||
// TODO: Gecko accepts lists in most background-related properties. We just use
|
// TODO: Gecko accepts lists in most background-related properties. We just use
|
||||||
// the first element (which is the common case), but at some point we want to
|
// the first element (which is the common case), but at some point we want to
|
||||||
// add support for parsing these lists in servo and pushing to nsTArray's.
|
// add support for parsing these lists in servo and pushing to nsTArray's.
|
||||||
|
@ -950,86 +976,57 @@ fn static_assert() {
|
||||||
|
|
||||||
<% impl_color("background_color", "mBackgroundColor", need_clone=True) %>
|
<% impl_color("background_color", "mBackgroundColor", need_clone=True) %>
|
||||||
|
|
||||||
pub fn copy_background_repeat_from(&mut self, other: &Self) {
|
<%self:simple_background_array_property name="repeat" field_name="mRepeat">
|
||||||
self.gecko.mImage.mRepeatCount = cmp::min(1, other.gecko.mImage.mRepeatCount);
|
use properties::longhands::background_repeat::single_value::computed_value::T;
|
||||||
self.gecko.mImage.mLayers.mFirstElement.mRepeat =
|
|
||||||
other.gecko.mImage.mLayers.mFirstElement.mRepeat;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_background_repeat(&mut self, v: longhands::background_repeat::computed_value::T) {
|
|
||||||
use properties::longhands::background_repeat::computed_value::T;
|
|
||||||
use gecko_bindings::structs::{NS_STYLE_IMAGELAYER_REPEAT_REPEAT, NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT};
|
|
||||||
use gecko_bindings::structs::nsStyleImageLayers_Repeat;
|
use gecko_bindings::structs::nsStyleImageLayers_Repeat;
|
||||||
let (repeat_x, repeat_y) = match v {
|
use gecko_bindings::structs::NS_STYLE_IMAGELAYER_REPEAT_REPEAT;
|
||||||
T::repeat_x => (NS_STYLE_IMAGELAYER_REPEAT_REPEAT,
|
use gecko_bindings::structs::NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT;
|
||||||
NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT),
|
|
||||||
T::repeat_y => (NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT,
|
let (repeat_x, repeat_y) = match servo {
|
||||||
NS_STYLE_IMAGELAYER_REPEAT_REPEAT),
|
T::repeat_x => (NS_STYLE_IMAGELAYER_REPEAT_REPEAT,
|
||||||
T::repeat => (NS_STYLE_IMAGELAYER_REPEAT_REPEAT,
|
NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT),
|
||||||
|
T::repeat_y => (NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT,
|
||||||
NS_STYLE_IMAGELAYER_REPEAT_REPEAT),
|
NS_STYLE_IMAGELAYER_REPEAT_REPEAT),
|
||||||
T::no_repeat => (NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT,
|
T::repeat => (NS_STYLE_IMAGELAYER_REPEAT_REPEAT,
|
||||||
NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT),
|
NS_STYLE_IMAGELAYER_REPEAT_REPEAT),
|
||||||
|
T::no_repeat => (NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT,
|
||||||
|
NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT),
|
||||||
};
|
};
|
||||||
|
nsStyleImageLayers_Repeat {
|
||||||
|
mXRepeat: repeat_x as u8,
|
||||||
|
mYRepeat: repeat_y as u8,
|
||||||
|
}
|
||||||
|
</%self:simple_background_array_property>
|
||||||
|
|
||||||
self.gecko.mImage.mRepeatCount = 1;
|
<%self:simple_background_array_property name="clip" field_name="mClip">
|
||||||
self.gecko.mImage.mLayers.mFirstElement.mRepeat = nsStyleImageLayers_Repeat {
|
use properties::longhands::background_clip::single_value::computed_value::T;
|
||||||
mXRepeat: repeat_x as u8,
|
|
||||||
mYRepeat: repeat_y as u8,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn copy_background_clip_from(&mut self, other: &Self) {
|
match servo {
|
||||||
self.gecko.mImage.mClipCount = cmp::min(1, other.gecko.mImage.mClipCount);
|
|
||||||
self.gecko.mImage.mLayers.mFirstElement.mClip =
|
|
||||||
other.gecko.mImage.mLayers.mFirstElement.mClip;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_background_clip(&mut self, v: longhands::background_clip::computed_value::T) {
|
|
||||||
use properties::longhands::background_clip::computed_value::T;
|
|
||||||
self.gecko.mImage.mClipCount = 1;
|
|
||||||
|
|
||||||
// TODO: Gecko supports background-clip: text, but just on -webkit-
|
|
||||||
// prefixed properties.
|
|
||||||
self.gecko.mImage.mLayers.mFirstElement.mClip = match v {
|
|
||||||
T::border_box => structs::NS_STYLE_IMAGELAYER_CLIP_BORDER as u8,
|
T::border_box => structs::NS_STYLE_IMAGELAYER_CLIP_BORDER as u8,
|
||||||
T::padding_box => structs::NS_STYLE_IMAGELAYER_CLIP_PADDING as u8,
|
T::padding_box => structs::NS_STYLE_IMAGELAYER_CLIP_PADDING as u8,
|
||||||
T::content_box => structs::NS_STYLE_IMAGELAYER_CLIP_CONTENT as u8,
|
T::content_box => structs::NS_STYLE_IMAGELAYER_CLIP_CONTENT as u8,
|
||||||
};
|
}
|
||||||
}
|
</%self:simple_background_array_property>
|
||||||
|
|
||||||
pub fn copy_background_origin_from(&mut self, other: &Self) {
|
<%self:simple_background_array_property name="origin" field_name="mOrigin">
|
||||||
self.gecko.mImage.mOriginCount = cmp::min(1, other.gecko.mImage.mOriginCount);
|
use properties::longhands::background_origin::single_value::computed_value::T;
|
||||||
self.gecko.mImage.mLayers.mFirstElement.mOrigin =
|
|
||||||
other.gecko.mImage.mLayers.mFirstElement.mOrigin;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_background_origin(&mut self, v: longhands::background_origin::computed_value::T) {
|
match servo {
|
||||||
use properties::longhands::background_origin::computed_value::T;
|
|
||||||
|
|
||||||
self.gecko.mImage.mOriginCount = 1;
|
|
||||||
self.gecko.mImage.mLayers.mFirstElement.mOrigin = match v {
|
|
||||||
T::border_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_BORDER as u8,
|
T::border_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_BORDER as u8,
|
||||||
T::padding_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_PADDING as u8,
|
T::padding_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_PADDING as u8,
|
||||||
T::content_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_CONTENT as u8,
|
T::content_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_CONTENT as u8,
|
||||||
};
|
}
|
||||||
}
|
</%self:simple_background_array_property>
|
||||||
|
|
||||||
pub fn copy_background_attachment_from(&mut self, other: &Self) {
|
<%self:simple_background_array_property name="attachment" field_name="mAttachment">
|
||||||
self.gecko.mImage.mAttachmentCount = cmp::min(1, other.gecko.mImage.mAttachmentCount);
|
use properties::longhands::background_attachment::single_value::computed_value::T;
|
||||||
self.gecko.mImage.mLayers.mFirstElement.mAttachment =
|
|
||||||
other.gecko.mImage.mLayers.mFirstElement.mAttachment;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_background_attachment(&mut self, v: longhands::background_attachment::computed_value::T) {
|
match servo {
|
||||||
use properties::longhands::background_attachment::computed_value::T;
|
|
||||||
|
|
||||||
self.gecko.mImage.mAttachmentCount = 1;
|
|
||||||
self.gecko.mImage.mLayers.mFirstElement.mAttachment = match v {
|
|
||||||
T::scroll => structs::NS_STYLE_IMAGELAYER_ATTACHMENT_SCROLL as u8,
|
T::scroll => structs::NS_STYLE_IMAGELAYER_ATTACHMENT_SCROLL as u8,
|
||||||
T::fixed => structs::NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED as u8,
|
T::fixed => structs::NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED as u8,
|
||||||
T::local => structs::NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL as u8,
|
T::local => structs::NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL as u8,
|
||||||
};
|
}
|
||||||
}
|
</%self:simple_background_array_property>
|
||||||
|
|
||||||
pub fn copy_background_position_from(&mut self, other: &Self) {
|
pub fn copy_background_position_from(&mut self, other: &Self) {
|
||||||
self.gecko.mImage.mPositionXCount = cmp::min(1, other.gecko.mImage.mPositionXCount);
|
self.gecko.mImage.mPositionXCount = cmp::min(1, other.gecko.mImage.mPositionXCount);
|
||||||
|
|
|
@ -285,9 +285,6 @@
|
||||||
}
|
}
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="maybe_vector_longhand(name, maybe, **kwargs)">
|
|
||||||
|
|
||||||
</%def>
|
|
||||||
<%def name="single_keyword(name, values, vector=False, **kwargs)">
|
<%def name="single_keyword(name, values, vector=False, **kwargs)">
|
||||||
<%call expr="single_keyword_computed(name, values, vector, **kwargs)">
|
<%call expr="single_keyword_computed(name, values, vector, **kwargs)">
|
||||||
use values::computed::ComputedValueAsSpecified;
|
use values::computed::ComputedValueAsSpecified;
|
||||||
|
|
|
@ -107,18 +107,26 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
|
|
||||||
${helpers.single_keyword("background-repeat",
|
${helpers.single_keyword("background-repeat",
|
||||||
"repeat repeat-x repeat-y no-repeat",
|
"repeat repeat-x repeat-y no-repeat",
|
||||||
|
vector=True,
|
||||||
|
gecko_only=True,
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
${helpers.single_keyword("background-attachment",
|
${helpers.single_keyword("background-attachment",
|
||||||
"scroll fixed" + (" local" if product == "gecko" else ""),
|
"scroll fixed" + (" local" if product == "gecko" else ""),
|
||||||
|
vector=True,
|
||||||
|
gecko_only=True,
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
${helpers.single_keyword("background-clip",
|
${helpers.single_keyword("background-clip",
|
||||||
"border-box padding-box content-box",
|
"border-box padding-box content-box",
|
||||||
|
vector=True,
|
||||||
|
gecko_only=True,
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
${helpers.single_keyword("background-origin",
|
${helpers.single_keyword("background-origin",
|
||||||
"padding-box border-box content-box",
|
"padding-box border-box content-box",
|
||||||
|
vector=True,
|
||||||
|
gecko_only=True,
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
<%helpers:longhand name="background-size" animatable="True">
|
<%helpers:longhand name="background-size" animatable="True">
|
||||||
|
|
|
@ -3,13 +3,16 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use std::iter::{once, Chain, Once, IntoIterator};
|
use std::iter::{once, Chain, Once, IntoIterator};
|
||||||
use std::slice::IterMut;
|
use std::slice::{Iter, IterMut};
|
||||||
use structs::nsStyleAutoArray;
|
use structs::nsStyleAutoArray;
|
||||||
|
|
||||||
impl<T> nsStyleAutoArray<T> {
|
impl<T> nsStyleAutoArray<T> {
|
||||||
pub fn iter_mut(&mut self) -> Chain<Once<&mut T>, IterMut<T>> {
|
pub fn iter_mut(&mut self) -> Chain<Once<&mut T>, IterMut<T>> {
|
||||||
once(&mut self.mFirstElement).chain(self.mOtherElements.iter_mut())
|
once(&mut self.mFirstElement).chain(self.mOtherElements.iter_mut())
|
||||||
}
|
}
|
||||||
|
pub fn iter(&self) -> Chain<Once<&T>, Iter<T>> {
|
||||||
|
once(&self.mFirstElement).chain(self.mOtherElements.iter())
|
||||||
|
}
|
||||||
|
|
||||||
// Note that often structs containing autoarrays will have
|
// Note that often structs containing autoarrays will have
|
||||||
// additional member fields that contain the length, which must be kept
|
// additional member fields that contain the length, which must be kept
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue