mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Move display outside of mako
This commit is contained in:
parent
be7d13e37f
commit
a764d9065e
5 changed files with 249 additions and 226 deletions
|
@ -9,8 +9,8 @@ use values::computed::length::LengthOrPercentage;
|
|||
use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
|
||||
use values::generics::box_::VerticalAlign as GenericVerticalAlign;
|
||||
|
||||
pub use values::specified::box_::{AnimationName, OverflowClipBox, OverscrollBehavior};
|
||||
pub use values::specified::box_::{ScrollSnapType, TouchAction, WillChange};
|
||||
pub use values::specified::box_::{AnimationName, Display, OverflowClipBox};
|
||||
pub use values::specified::box_::{OverscrollBehavior, ScrollSnapType, TouchAction, WillChange};
|
||||
|
||||
/// A computed value for the `vertical-align` property.
|
||||
pub type VerticalAlign = GenericVerticalAlign<LengthOrPercentage>;
|
||||
|
|
|
@ -40,7 +40,7 @@ pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVa
|
|||
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
|
||||
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
|
||||
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
|
||||
pub use self::box_::{AnimationIterationCount, AnimationName, OverscrollBehavior};
|
||||
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior};
|
||||
pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
|
||||
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
|
||||
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
||||
|
|
|
@ -7,15 +7,231 @@
|
|||
use Atom;
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
#[cfg(feature = "servo")]
|
||||
use properties::{longhands, PropertyDeclaration};
|
||||
use std::fmt;
|
||||
use style_traits::{ParseError, ToCss};
|
||||
use values::CustomIdent;
|
||||
use values::KeyframesName;
|
||||
#[cfg(feature = "servo")]
|
||||
use values::computed::Context;
|
||||
use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
|
||||
use values::generics::box_::VerticalAlign as GenericVerticalAlign;
|
||||
use values::specified::{AllowQuirks, Number};
|
||||
use values::specified::length::LengthOrPercentage;
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
/// Defines an element’s display type, which consists of
|
||||
/// the two basic qualities of how an element generates boxes
|
||||
/// <https://drafts.csswg.org/css-display/#propdef-display>
|
||||
pub enum Display {
|
||||
Inline, Block, InlineBlock,
|
||||
Table, InlineTable, TableRowGroup, TableHeaderGroup,
|
||||
TableFooterGroup, TableRow, TableColumnGroup,
|
||||
TableColumn, TableCell, TableCaption, ListItem, None,
|
||||
#[parse(aliases = "-webkit-flex")]
|
||||
Flex,
|
||||
#[parse(aliases = "-webkit-inline-flex")]
|
||||
InlineFlex,
|
||||
#[cfg(feature = "gecko")]
|
||||
Grid,
|
||||
#[cfg(feature = "gecko")]
|
||||
InlineGrid,
|
||||
#[cfg(feature = "gecko")]
|
||||
Ruby,
|
||||
#[cfg(feature = "gecko")]
|
||||
RubyBase,
|
||||
#[cfg(feature = "gecko")]
|
||||
RubyBaseContainer,
|
||||
#[cfg(feature = "gecko")]
|
||||
RubyText,
|
||||
#[cfg(feature = "gecko")]
|
||||
RubyTextContainer,
|
||||
#[cfg(feature = "gecko")]
|
||||
Contents,
|
||||
#[cfg(feature = "gecko")]
|
||||
FlowRoot,
|
||||
#[cfg(feature = "gecko")]
|
||||
WebkitBox,
|
||||
#[cfg(feature = "gecko")]
|
||||
WebkitInlineBox,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozBox,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozInlineBox,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozGrid,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozInlineGrid,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozGridGroup,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozGridLine,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozStack,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozInlineStack,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozDeck,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozPopup,
|
||||
#[cfg(feature = "gecko")]
|
||||
MozGroupbox,
|
||||
}
|
||||
|
||||
impl Display {
|
||||
/// The initial display value.
|
||||
#[inline]
|
||||
pub fn inline() -> Self {
|
||||
Display::Inline
|
||||
}
|
||||
|
||||
/// Returns whether this "display" value is the display of a flex or
|
||||
/// grid container.
|
||||
///
|
||||
/// This is used to implement various style fixups.
|
||||
pub fn is_item_container(&self) -> bool {
|
||||
match *self {
|
||||
Display::Flex | Display::InlineFlex => true,
|
||||
#[cfg(feature = "gecko")]
|
||||
Display::Grid | Display::InlineGrid => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns whether an element with this display type is a line
|
||||
/// participant, which means it may lay its children on the same
|
||||
/// line as itself.
|
||||
pub fn is_line_participant(&self) -> bool {
|
||||
match *self {
|
||||
Display::Inline => true,
|
||||
#[cfg(feature = "gecko")]
|
||||
Display::Contents |
|
||||
Display::Ruby |
|
||||
Display::RubyBaseContainer => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `new_display` should be ignored, given a previous
|
||||
/// `old_display` value.
|
||||
///
|
||||
/// This is used to ignore `display: -moz-box` declarations after an
|
||||
/// equivalent `display: -webkit-box` declaration, since the former
|
||||
/// has a vastly different meaning. See bug 1107378 and bug 1407701.
|
||||
///
|
||||
/// FIXME(emilio): This is a pretty decent hack, we should try to
|
||||
/// remove it.
|
||||
pub fn should_ignore_parsed_value(
|
||||
_old_display: Self,
|
||||
_new_display: Self,
|
||||
) -> bool {
|
||||
#[cfg(feature = "gecko")] {
|
||||
match (_old_display, _new_display) {
|
||||
(Display::WebkitBox, Display::MozBox) |
|
||||
(Display::WebkitInlineBox, Display::MozInlineBox) => {
|
||||
return true;
|
||||
}
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Returns whether this "display" value is one of the types for
|
||||
/// ruby.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn is_ruby_type(&self) -> bool {
|
||||
matches!(*self,
|
||||
Display::Ruby |
|
||||
Display::RubyBase |
|
||||
Display::RubyText |
|
||||
Display::RubyBaseContainer |
|
||||
Display::RubyTextContainer
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns whether this "display" value is a ruby level container.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn is_ruby_level_container(&self) -> bool {
|
||||
matches!(*self,
|
||||
Display::RubyBaseContainer |
|
||||
Display::RubyTextContainer
|
||||
)
|
||||
}
|
||||
|
||||
/// Convert this display into an equivalent block display.
|
||||
///
|
||||
/// Also used for style adjustments.
|
||||
pub fn equivalent_block_display(&self, _is_root_element: bool) -> Self {
|
||||
match *self {
|
||||
// Values that have a corresponding block-outside version.
|
||||
Display::InlineTable => Display::Table,
|
||||
Display::InlineFlex => Display::Flex,
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
Display::InlineGrid => Display::Grid,
|
||||
#[cfg(feature = "gecko")]
|
||||
Display::WebkitInlineBox => Display::WebkitBox,
|
||||
|
||||
// Special handling for contents and list-item on the root
|
||||
// element for Gecko.
|
||||
#[cfg(feature = "gecko")]
|
||||
Display::Contents | Display::ListItem if _is_root_element => Display::Block,
|
||||
|
||||
// These are not changed by blockification.
|
||||
Display::None |
|
||||
Display::Block |
|
||||
Display::Flex |
|
||||
Display::ListItem |
|
||||
Display::Table => *self,
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
Display::Contents |
|
||||
Display::FlowRoot |
|
||||
Display::Grid |
|
||||
Display::WebkitBox => *self,
|
||||
|
||||
// Everything else becomes block.
|
||||
_ => Display::Block,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Convert this display into an inline-outside display.
|
||||
///
|
||||
/// Ideally it should implement spec: https://drafts.csswg.org/css-display/#inlinify
|
||||
/// but the spec isn't stable enough, so we copy what Gecko does for now.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn inlinify(&self) -> Self {
|
||||
match *self {
|
||||
Display::Block |
|
||||
Display::FlowRoot => Display::InlineBlock,
|
||||
Display::Table => Display::InlineTable,
|
||||
Display::Flex => Display::InlineFlex,
|
||||
Display::Grid => Display::InlineGrid,
|
||||
Display::MozBox => Display::MozInlineBox,
|
||||
Display::MozStack => Display::MozInlineStack,
|
||||
Display::WebkitBox => Display::WebkitInlineBox,
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
#[inline]
|
||||
/// Custom cascade for the `display` property in servo
|
||||
pub fn cascade_property_custom(
|
||||
_declaration: &PropertyDeclaration,
|
||||
context: &mut Context
|
||||
) {
|
||||
longhands::_servo_display_for_hypothetical_box::derive_from_display(context);
|
||||
longhands::_servo_text_decorations_in_effect::derive_from_display(context);
|
||||
}
|
||||
}
|
||||
|
||||
/// A specified value for the `vertical-align` property.
|
||||
pub type VerticalAlign = GenericVerticalAlign<LengthOrPercentage>;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVa
|
|||
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
|
||||
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
|
||||
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
|
||||
pub use self::box_::{AnimationIterationCount, AnimationName, OverscrollBehavior};
|
||||
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior};
|
||||
pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
|
||||
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
|
||||
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue