mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Auto merge of #16960 - servo:derive-all-the-things, r=emilio
Derive HasViewportPercentage 🍷 <!-- 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/16960) <!-- Reviewable:end -->
This commit is contained in:
commit
4f0b24ac0c
40 changed files with 258 additions and 574 deletions
|
@ -63,6 +63,8 @@ pub enum CSSPixel {}
|
|||
pub mod cursor;
|
||||
#[macro_use]
|
||||
pub mod values;
|
||||
#[macro_use]
|
||||
pub mod viewport;
|
||||
|
||||
pub use values::{ToCss, OneOrMoreCommaSeparated};
|
||||
pub use viewport::HasViewportPercentage;
|
||||
|
|
|
@ -20,6 +20,48 @@ define_css_keyword_enum!(Orientation:
|
|||
"portrait" => Portrait,
|
||||
"landscape" => Landscape);
|
||||
|
||||
/// A trait used to query whether this value has viewport units.
|
||||
pub trait HasViewportPercentage {
|
||||
/// Returns true if this value has viewport units.
|
||||
fn has_viewport_percentage(&self) -> bool;
|
||||
}
|
||||
|
||||
/// A macro used to implement HasViewportPercentage trait
|
||||
/// for a given type that may never contain viewport units.
|
||||
#[macro_export]
|
||||
macro_rules! no_viewport_percentage {
|
||||
($($name: ident),+) => {
|
||||
$(impl $crate::HasViewportPercentage for $name {
|
||||
#[inline]
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
false
|
||||
}
|
||||
})+
|
||||
};
|
||||
}
|
||||
|
||||
no_viewport_percentage!(bool, f32);
|
||||
|
||||
impl<T: HasViewportPercentage> HasViewportPercentage for Box<T> {
|
||||
#[inline]
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
(**self).has_viewport_percentage()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: HasViewportPercentage> HasViewportPercentage for Option<T> {
|
||||
#[inline]
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
self.as_ref().map_or(false, T::has_viewport_percentage)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: HasViewportPercentage> HasViewportPercentage for Vec<T> {
|
||||
#[inline]
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
self.iter().any(T::has_viewport_percentage)
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of viewport descriptors:
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue