mirror of
https://github.com/servo/servo.git
synced 2025-08-08 23:15:33 +01:00
style: Prevent more missing docs in the values module.
This commit is contained in:
parent
a0d425e8ce
commit
f37aa12927
13 changed files with 281 additions and 37 deletions
|
@ -20,8 +20,13 @@ use values::specified::{LengthOrPercentage, Percentage};
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
/// A [position][pos].
|
||||
///
|
||||
/// [pos]: https://drafts.csswg.org/css-values/#position
|
||||
pub struct Position {
|
||||
/// The horizontal component.
|
||||
pub horizontal: HorizontalPosition,
|
||||
/// The vertical component.
|
||||
pub vertical: VerticalPosition,
|
||||
}
|
||||
|
||||
|
@ -59,9 +64,12 @@ impl HasViewportPercentage for Position {
|
|||
}
|
||||
|
||||
impl Position {
|
||||
pub fn new(mut first_position: Option<PositionComponent>, mut second_position: Option<PositionComponent>,
|
||||
first_keyword: Option<PositionComponent>, second_keyword: Option<PositionComponent>)
|
||||
-> Result<Position, ()> {
|
||||
/// Create a new position value.
|
||||
pub fn new(mut first_position: Option<PositionComponent>,
|
||||
mut second_position: Option<PositionComponent>,
|
||||
first_keyword: Option<PositionComponent>,
|
||||
second_keyword: Option<PositionComponent>)
|
||||
-> Result<Position, ()> {
|
||||
// Unwrap for checking if values are at right place.
|
||||
let first_key = first_keyword.unwrap_or(PositionComponent::Keyword(Keyword::Left));
|
||||
let second_key = second_keyword.unwrap_or(PositionComponent::Keyword(Keyword::Top));
|
||||
|
@ -150,6 +158,7 @@ impl Position {
|
|||
})
|
||||
}
|
||||
|
||||
/// Returns a "centered" position, as in "center center".
|
||||
pub fn center() -> Position {
|
||||
Position {
|
||||
horizontal: HorizontalPosition {
|
||||
|
@ -242,6 +251,7 @@ impl ToComputedValue for Position {
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub struct HorizontalPosition {
|
||||
pub keyword: Option<Keyword>,
|
||||
pub position: Option<LengthOrPercentage>,
|
||||
|
@ -249,11 +259,7 @@ pub struct HorizontalPosition {
|
|||
|
||||
impl HasViewportPercentage for HorizontalPosition {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
if let Some(pos) = self.position {
|
||||
pos.has_viewport_percentage()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
self.position.map_or(false, |pos| pos.has_viewport_percentage())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,6 +377,7 @@ impl ToComputedValue for HorizontalPosition {
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub struct VerticalPosition {
|
||||
pub keyword: Option<Keyword>,
|
||||
pub position: Option<LengthOrPercentage>,
|
||||
|
@ -378,11 +385,7 @@ pub struct VerticalPosition {
|
|||
|
||||
impl HasViewportPercentage for VerticalPosition {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
if let Some(pos) = self.position {
|
||||
pos.has_viewport_percentage()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
self.position.map_or(false, |pos| pos.has_viewport_percentage())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,6 +513,7 @@ define_css_keyword_enum!(Keyword:
|
|||
"y-end" => YEnd);
|
||||
|
||||
impl Keyword {
|
||||
/// Convert the given keyword to a length or a percentage.
|
||||
pub fn to_length_or_percentage(self) -> LengthOrPercentage {
|
||||
match self {
|
||||
Keyword::Center => LengthOrPercentage::Percentage(Percentage(0.5)),
|
||||
|
@ -532,10 +536,14 @@ enum PositionCategory {
|
|||
LengthOrPercentage,
|
||||
}
|
||||
|
||||
// http://dev.w3.org/csswg/css2/colors.html#propdef-background-position
|
||||
/// A position component.
|
||||
///
|
||||
/// http://dev.w3.org/csswg/css2/colors.html#propdef-background-position
|
||||
#[derive(Clone, PartialEq, Copy)]
|
||||
pub enum PositionComponent {
|
||||
/// A `<length>`
|
||||
Length(LengthOrPercentage),
|
||||
/// A position keyword.
|
||||
Keyword(Keyword),
|
||||
}
|
||||
|
||||
|
@ -568,6 +576,7 @@ impl HasViewportPercentage for PositionComponent {
|
|||
}
|
||||
|
||||
impl PositionComponent {
|
||||
/// Convert the given position component to a length or a percentage.
|
||||
#[inline]
|
||||
pub fn to_length_or_percentage(self) -> LengthOrPercentage {
|
||||
match self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue