/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
impl AnchorFunction { /// Resolve the anchor function with the given resolver. Returns `Err()` if no anchor is found. #[cfg(feature = "gecko")] pubfn resolve(
anchor_name: &TreeScoped<DashedIdent>,
anchor_side: &AnchorSide,
prop_side: PhysicalSide,
params: &AnchorPosOffsetResolutionParams,
) -> Result<Length, ()> { usecrate::gecko_bindings::structs::Gecko_GetAnchorPosOffset;
let (keyword, percentage) = anchor_side.keyword_and_percentage(); letmut offset = Length::zero(); let valid = unsafe {
Gecko_GetAnchorPosOffset(
params,
anchor_name.value.0.as_ptr(),
&anchor_name.scope,
prop_side as u8,
keyword as u8,
percentage.0,
&mut offset,
)
};
if !valid { return Err(());
}
Ok(offset)
}
}
/// Perform the adjustment of a given value for a given try tactic, as per: /// https://drafts.csswg.org/css-anchor-position-1/#swap-due-to-a-try-tactic pub(crate) trait TryTacticAdjustment { /// Performs the adjustments necessary given an old side we're relative to, and a new side /// we're relative to. fn try_tactic_adjustment(&mutself, old_side: PhysicalSide, new_side: PhysicalSide);
}
/// A computed type for `inset` properties. pubtype Inset = GenericInset<Percentage, LengthPercentage>; impl TryTacticAdjustment for Inset { // https://drafts.csswg.org/css-anchor-position-1/#swap-due-to-a-try-tactic: // // For inset properties, change the specified side in anchor() functions to maintain the // same relative relationship to the new direction that they had to the old. // // If a <percentage> is used, and directions are opposing, change it to 100% minus the // original percentage. fn try_tactic_adjustment(&mutself, old_side: PhysicalSide, new_side: PhysicalSide) { matchself { Self::Auto => {}, Self::AnchorContainingCalcFunction(lp) | Self::LengthPercentage(lp) => {
lp.try_tactic_adjustment(old_side, new_side)
}, Self::AnchorFunction(anchor) => anchor.try_tactic_adjustment(old_side, new_side), Self::AnchorSizeFunction(anchor) => anchor.try_tactic_adjustment(old_side, new_side),
}
}
}
// This exists because the spec currently says that further simplifications // should be made to the computed value. That's confusing though, and probably // all these simplifications should be wrapped up into the simplifications that // we make to the specified value. I.e. all this should happen in // PositionArea::parse_internal(). // See also https://github.com/w3c/csswg-drafts/issues/12759 impl ToComputedValue for PositionArea { type ComputedValue = Self;
fn to_computed_value(&self, _context: &Context) -> Self { letmut computed = self.clone(); let pair_type = self.get_type(); if pair_type == PositionAreaType::Logical || pair_type == PositionAreaType::SelfLogical { if computed.second != PositionAreaKeyword::None {
computed.first = block_or_inline_to_inferred(computed.first);
computed.second = block_or_inline_to_inferred(computed.second);
}
} elseif pair_type == PositionAreaType::Inferred
|| pair_type == PositionAreaType::SelfInferred
{ if computed.second == PositionAreaKeyword::SpanAll { // We remove the superfluous span-all, converting the inferred // keyword to a logical keyword to avoid ambiguity, per spec.
computed.first = inferred_to_block(computed.first);
computed.second = PositionAreaKeyword::None;
} elseif computed.first == PositionAreaKeyword::SpanAll {
computed.first = computed.second;
computed.first = inferred_to_inline(computed.first);
computed.second = PositionAreaKeyword::None;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.