mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Auto merge of #12651 - heycam:background-position, r=Manishearth
Add support for background-position in geckolib. <!-- Please describe your changes on the following line: --> r? @Manishearth --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because this is a geckolib-only change <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12651) <!-- Reviewable:end -->
This commit is contained in:
commit
f16aac0e5d
2 changed files with 58 additions and 2 deletions
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use gecko_bindings::structs::nsStyleCoord_CalcValue;
|
use gecko_bindings::structs::nsStyleCoord_CalcValue;
|
||||||
use values::computed::CalcLengthOrPercentage;
|
use values::computed::{CalcLengthOrPercentage, LengthOrPercentage};
|
||||||
|
|
||||||
impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
|
impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
|
||||||
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
|
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
|
||||||
|
@ -34,3 +34,35 @@ impl From<nsStyleCoord_CalcValue> for CalcLengthOrPercentage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<LengthOrPercentage> for nsStyleCoord_CalcValue {
|
||||||
|
fn from(other: LengthOrPercentage) -> nsStyleCoord_CalcValue {
|
||||||
|
match other {
|
||||||
|
LengthOrPercentage::Length(au) => {
|
||||||
|
nsStyleCoord_CalcValue {
|
||||||
|
mLength: au.0,
|
||||||
|
mPercent: 0.0,
|
||||||
|
mHasPercent: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
LengthOrPercentage::Percentage(pc) => {
|
||||||
|
nsStyleCoord_CalcValue {
|
||||||
|
mLength: 0,
|
||||||
|
mPercent: pc,
|
||||||
|
mHasPercent: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
LengthOrPercentage::Calc(calc) => calc.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<nsStyleCoord_CalcValue> for LengthOrPercentage {
|
||||||
|
fn from(other: nsStyleCoord_CalcValue) -> LengthOrPercentage {
|
||||||
|
match (other.mHasPercent, other.mLength) {
|
||||||
|
(false, _) => LengthOrPercentage::Length(Au(other.mLength)),
|
||||||
|
(true, 0) => LengthOrPercentage::Percentage(other.mPercent),
|
||||||
|
_ => LengthOrPercentage::Calc(other.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -922,7 +922,8 @@ fn static_assert() {
|
||||||
// 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.
|
||||||
<% skip_background_longhands = """background-color background-repeat
|
<% skip_background_longhands = """background-color background-repeat
|
||||||
background-image background-clip
|
background-image background-clip
|
||||||
background-origin background-attachment""" %>
|
background-origin background-attachment
|
||||||
|
background-position""" %>
|
||||||
<%self:impl_trait style_struct_name="Background"
|
<%self:impl_trait style_struct_name="Background"
|
||||||
skip_longhands="${skip_background_longhands}"
|
skip_longhands="${skip_background_longhands}"
|
||||||
skip_additionals="*">
|
skip_additionals="*">
|
||||||
|
@ -1010,6 +1011,29 @@ fn static_assert() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn copy_background_position_from(&mut self, other: &Self) {
|
||||||
|
self.gecko.mImage.mPositionXCount = cmp::min(1, other.gecko.mImage.mPositionXCount);
|
||||||
|
self.gecko.mImage.mPositionYCount = cmp::min(1, other.gecko.mImage.mPositionYCount);
|
||||||
|
self.gecko.mImage.mLayers.mFirstElement.mPosition =
|
||||||
|
other.gecko.mImage.mLayers.mFirstElement.mPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clone_background_position(&self) -> longhands::background_position::computed_value::T {
|
||||||
|
let position = &self.gecko.mImage.mLayers.mFirstElement.mPosition;
|
||||||
|
longhands::background_position::computed_value::T {
|
||||||
|
horizontal: position.mXPosition.into(),
|
||||||
|
vertical: position.mYPosition.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_background_position(&mut self, v: longhands::background_position::computed_value::T) {
|
||||||
|
let position = &mut self.gecko.mImage.mLayers.mFirstElement.mPosition;
|
||||||
|
position.mXPosition = v.horizontal.into();
|
||||||
|
position.mYPosition = v.vertical.into();
|
||||||
|
self.gecko.mImage.mPositionXCount = 1;
|
||||||
|
self.gecko.mImage.mPositionYCount = 1;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn copy_background_image_from(&mut self, other: &Self) {
|
pub fn copy_background_image_from(&mut self, other: &Self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_CopyImageValueFrom(&mut self.gecko.mImage.mLayers.mFirstElement.mImage,
|
Gecko_CopyImageValueFrom(&mut self.gecko.mImage.mLayers.mFirstElement.mImage,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue