/* 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/. */
/// All [`@margin`][margin] rule names, with a preceding '@'. /// /// This array lets us have just one single memory region used for /// to_str, name, and the Debug implementation. const MARGIN_RULE_AT_NAMES:&[&'static str] = &[
$( concat!('@', $val), )+
];
impl MarginRuleType { /// Matches the rule type for this name. This does not expect a /// leading '@'. pubfn match_name(name: &str) -> Option<Self> {
Some(match_ignore_ascii_case! { name,
$( $val => MarginRuleType::$id, )+
_ => return None,
})
}
}
}
}
impl MarginRuleType { #[inline] fn to_str(&self) -> &'static str {
&MARGIN_RULE_AT_NAMES[*selfas usize]
} #[inline] fn name(&self) -> &'static str { // Use the at-name array, skipping the first character to get // the name without the @ sign.
&MARGIN_RULE_AT_NAMES[*selfas usize][1..]
}
}
// Implement Debug manually so that it will share the same string memory as // MarginRuleType::name and MarginRuleType::to_str. impl fmt::Debug for MarginRuleType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
f.write_str(self.name())
}
}
/// A [`@margin`][margin] rule. /// /// [margin]: https://drafts.csswg.org/css-page-3/#margin-at-rules #[derive(Clone, Debug, ToShmem)] pubstruct MarginRule { /// Type of this margin rule. pub rule_type: MarginRuleType, /// The declaration block this margin rule contains. pub block: Arc<Locked<PropertyDeclarationBlock>>, /// The source position this rule was found at. pub source_location: SourceLocation,
}
impl MarginRule { /// Measure heap usage. #[cfg(feature = "gecko")] pubfn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize { // Measurement of other fields may be added later. self.block.unconditional_shallow_size_of(ops) + self.block.read_with(guard).size_of(ops)
} /// Gets the name for this margin rule. #[inline] pubfn name(&self) -> &'static str { self.rule_type.name()
}
}
impl ToCssWithGuard for MarginRule { /// Serialization of a margin-rule is not specced, this is adapted from how /// page-rules and style-rules are serialized. fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result {
dest.write_str(self.rule_type.to_str())?;
dest.write_str(" { ")?; let declaration_block = self.block.read_with(guard);
declaration_block.to_css(dest)?; if !declaration_block.declarations().is_empty() {
dest.write_char(' ')?;
}
dest.write_char('}')
}
}
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.