use azul_css::{
css::CssPropertyValue,
dynamic_selector::{
CssPropertyWithConditions,
DynamicSelector, DynamicSelectorContext, OsCondition, ThemeCondition,
},
props::{
basic::{
font::StyleFontWeight, pixel::PixelValue, ColorU,
StyleFontSize,
},
layout::{
dimensions::{LayoutHeight, LayoutWidth},
display::LayoutDisplay,
fragmentation::{BreakInside, PageBreak},
spacing::{
LayoutMarginBottom, LayoutMarginLeft, LayoutMarginRight, LayoutMarginTop,
LayoutPaddingBottom, LayoutPaddingInlineEnd, LayoutPaddingInlineStart,
LayoutPaddingLeft, LayoutPaddingRight, LayoutPaddingTop,
},
},
property::{CssProperty, CssPropertyType},
style::{
border::{
BorderStyle,
LayoutBorderBottomWidth, LayoutBorderLeftWidth, LayoutBorderRightWidth, LayoutBorderTopWidth,
StyleBorderBottomColor, StyleBorderBottomStyle,
StyleBorderLeftColor, StyleBorderLeftStyle,
StyleBorderRightColor, StyleBorderRightStyle,
StyleBorderTopColor, StyleBorderTopStyle,
},
content::CounterReset,
effects::StyleCursor,
lists::StyleListStyleType,
scrollbar::{
LayoutScrollbarWidth, ScrollbarColorCustom, ScrollbarFadeDelay,
ScrollbarFadeDuration, ScrollbarVisibilityMode, StyleScrollbarColor,
},
text::StyleTextDecoration,
StyleTextAlign, StyleVerticalAlign,
},
},
};
use crate::dom::NodeType;
static WIDTH_100_PERCENT: CssProperty = CssProperty::Width(CssPropertyValue::Exact(
LayoutWidth::Px(PixelValue::const_percent(100)),
));
static HEIGHT_100_PERCENT: CssProperty = CssProperty::Height(CssPropertyValue::Exact(
LayoutHeight::Px(PixelValue::const_percent(100)),
));
static DISPLAY_BLOCK: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::Block));
static DISPLAY_INLINE: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::Inline));
static DISPLAY_INLINE_BLOCK: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::InlineBlock));
static DISPLAY_NONE: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::None));
static DISPLAY_TABLE: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::Table));
static DISPLAY_TABLE_ROW: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableRow));
static DISPLAY_TABLE_CELL: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableCell));
static DISPLAY_TABLE_HEADER_GROUP: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableHeaderGroup));
static DISPLAY_TABLE_ROW_GROUP: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableRowGroup));
static DISPLAY_TABLE_FOOTER_GROUP: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableFooterGroup));
static DISPLAY_TABLE_CAPTION: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableCaption));
static DISPLAY_TABLE_COLUMN_GROUP: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableColumnGroup));
static DISPLAY_TABLE_COLUMN: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableColumn));
static DISPLAY_LIST_ITEM: CssProperty =
CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::ListItem));
static CURSOR_POINTER: CssProperty =
CssProperty::Cursor(CssPropertyValue::Exact(StyleCursor::Pointer));
static CURSOR_TEXT: CssProperty =
CssProperty::Cursor(CssPropertyValue::Exact(StyleCursor::Text));
static MARGIN_TOP_ZERO: CssProperty =
CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
inner: PixelValue::const_px(0),
}));
static MARGIN_BOTTOM_ZERO: CssProperty =
CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
inner: PixelValue::const_px(0),
}));
static MARGIN_LEFT_ZERO: CssProperty =
CssProperty::MarginLeft(CssPropertyValue::Exact(LayoutMarginLeft {
inner: PixelValue::const_px(0),
}));
static MARGIN_RIGHT_ZERO: CssProperty =
CssProperty::MarginRight(CssPropertyValue::Exact(LayoutMarginRight {
inner: PixelValue::const_px(0),
}));
static MARGIN_TOP_8PX: CssProperty =
CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
inner: PixelValue::const_px(8),
}));
static MARGIN_BOTTOM_8PX: CssProperty =
CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
inner: PixelValue::const_px(8),
}));
static MARGIN_LEFT_8PX: CssProperty =
CssProperty::MarginLeft(CssPropertyValue::Exact(LayoutMarginLeft {
inner: PixelValue::const_px(8),
}));
static MARGIN_RIGHT_8PX: CssProperty =
CssProperty::MarginRight(CssPropertyValue::Exact(LayoutMarginRight {
inner: PixelValue::const_px(8),
}));
static FONT_SIZE_2EM: CssProperty = CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
inner: PixelValue::const_em(2),
}));
static FONT_SIZE_1_5EM: CssProperty =
CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
inner: PixelValue::const_em_fractional(1, 5),
}));
static FONT_SIZE_1_17EM: CssProperty =
CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
inner: PixelValue::const_em_fractional(1, 17),
}));
static FONT_SIZE_1EM: CssProperty = CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
inner: PixelValue::const_em(1),
}));
static FONT_SIZE_0_83EM: CssProperty =
CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
inner: PixelValue::const_em_fractional(0, 83),
}));
static FONT_SIZE_0_67EM: CssProperty =
CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
inner: PixelValue::const_em_fractional(0, 67),
}));
static MARGIN_TOP_1EM: CssProperty =
CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
inner: PixelValue::const_em(1),
}));
static MARGIN_BOTTOM_1EM: CssProperty =
CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
inner: PixelValue::const_em(1),
}));
static MARGIN_TOP_0_67EM: CssProperty =
CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
inner: PixelValue::const_em_fractional(0, 67),
}));
static MARGIN_BOTTOM_0_67EM: CssProperty =
CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
inner: PixelValue::const_em_fractional(0, 67),
}));
static MARGIN_TOP_0_83EM: CssProperty =
CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
inner: PixelValue::const_em_fractional(0, 83),
}));
static MARGIN_BOTTOM_0_83EM: CssProperty =
CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
inner: PixelValue::const_em_fractional(0, 83),
}));
static MARGIN_TOP_1_33EM: CssProperty =
CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
inner: PixelValue::const_em_fractional(1, 33),
}));
static MARGIN_BOTTOM_1_33EM: CssProperty =
CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
inner: PixelValue::const_em_fractional(1, 33),
}));
static MARGIN_TOP_1_67EM: CssProperty =
CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
inner: PixelValue::const_em_fractional(1, 67),
}));
static MARGIN_BOTTOM_1_67EM: CssProperty =
CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
inner: PixelValue::const_em_fractional(1, 67),
}));
static MARGIN_TOP_2_33EM: CssProperty =
CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
inner: PixelValue::const_em_fractional(2, 33),
}));
static MARGIN_BOTTOM_2_33EM: CssProperty =
CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
inner: PixelValue::const_em_fractional(2, 33),
}));
static FONT_WEIGHT_BOLD: CssProperty =
CssProperty::FontWeight(CssPropertyValue::Exact(StyleFontWeight::Bold));
static FONT_WEIGHT_BOLDER: CssProperty =
CssProperty::FontWeight(CssPropertyValue::Exact(StyleFontWeight::Bolder));
static PADDING_TOP_1PX: CssProperty =
CssProperty::PaddingTop(CssPropertyValue::Exact(LayoutPaddingTop {
inner: PixelValue::const_px(1),
}));
static PADDING_BOTTOM_1PX: CssProperty =
CssProperty::PaddingBottom(CssPropertyValue::Exact(LayoutPaddingBottom {
inner: PixelValue::const_px(1),
}));
static PADDING_LEFT_1PX: CssProperty =
CssProperty::PaddingLeft(CssPropertyValue::Exact(LayoutPaddingLeft {
inner: PixelValue::const_px(1),
}));
static PADDING_RIGHT_1PX: CssProperty =
CssProperty::PaddingRight(CssPropertyValue::Exact(LayoutPaddingRight {
inner: PixelValue::const_px(1),
}));
static TEXT_ALIGN_CENTER: CssProperty =
CssProperty::TextAlign(CssPropertyValue::Exact(StyleTextAlign::Center));
static VERTICAL_ALIGN_MIDDLE: CssProperty =
CssProperty::VerticalAlign(CssPropertyValue::Exact(StyleVerticalAlign::Middle));
static LIST_STYLE_TYPE_DISC: CssProperty =
CssProperty::ListStyleType(CssPropertyValue::Exact(StyleListStyleType::Disc));
static LIST_STYLE_TYPE_DECIMAL: CssProperty =
CssProperty::ListStyleType(CssPropertyValue::Exact(StyleListStyleType::Decimal));
static MARGIN_TOP_0_5EM: CssProperty =
CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
inner: PixelValue::const_em_fractional(0, 5),
}));
static MARGIN_BOTTOM_0_5EM: CssProperty =
CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
inner: PixelValue::const_em_fractional(0, 5),
}));
static BORDER_TOP_STYLE_INSET: CssProperty =
CssProperty::BorderTopStyle(CssPropertyValue::Exact(StyleBorderTopStyle {
inner: BorderStyle::Inset,
}));
static BORDER_TOP_WIDTH_1PX: CssProperty =
CssProperty::BorderTopWidth(CssPropertyValue::Exact(LayoutBorderTopWidth {
inner: PixelValue::const_px(1),
}));
static BORDER_TOP_COLOR_GRAY: CssProperty =
CssProperty::BorderTopColor(CssPropertyValue::Exact(StyleBorderTopColor {
inner: ColorU {
r: 128,
g: 128,
b: 128,
a: 255,
},
}));
static HEIGHT_ZERO: CssProperty = CssProperty::Height(CssPropertyValue::Exact(LayoutHeight::Px(
PixelValue::const_px(0),
)));
static COUNTER_RESET_LIST_ITEM: CssProperty =
CssProperty::CounterReset(CssPropertyValue::Exact(CounterReset::list_item()));
static BREAK_INSIDE_AVOID: CssProperty = CssProperty::break_inside(BreakInside::Avoid);
static BREAK_AFTER_AVOID: CssProperty = CssProperty::break_after(PageBreak::Avoid);
static PADDING_INLINE_START_40PX: CssProperty =
CssProperty::PaddingLeft(CssPropertyValue::Exact(LayoutPaddingLeft {
inner: PixelValue::const_px(40),
}));
static TEXT_DECORATION_UNDERLINE: CssProperty = CssProperty::TextDecoration(
CssPropertyValue::Exact(StyleTextDecoration::Underline),
);
static FONT_SIZE_13PX: CssProperty = CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
inner: PixelValue::const_px(13),
}));
static PADDING_TOP_5PX: CssProperty =
CssProperty::PaddingTop(CssPropertyValue::Exact(LayoutPaddingTop {
inner: PixelValue::const_px(5),
}));
static PADDING_BOTTOM_5PX: CssProperty =
CssProperty::PaddingBottom(CssPropertyValue::Exact(LayoutPaddingBottom {
inner: PixelValue::const_px(5),
}));
static PADDING_LEFT_10PX: CssProperty =
CssProperty::PaddingLeft(CssPropertyValue::Exact(LayoutPaddingLeft {
inner: PixelValue::const_px(10),
}));
static PADDING_RIGHT_10PX: CssProperty =
CssProperty::PaddingRight(CssPropertyValue::Exact(LayoutPaddingRight {
inner: PixelValue::const_px(10),
}));
static BUTTON_BORDER_COLOR: ColorU = ColorU { r: 200, g: 200, b: 200, a: 255 };
static BUTTON_BORDER_TOP_COLOR: CssProperty =
CssProperty::BorderTopColor(CssPropertyValue::Exact(StyleBorderTopColor {
inner: BUTTON_BORDER_COLOR,
}));
static BUTTON_BORDER_BOTTOM_COLOR: CssProperty =
CssProperty::BorderBottomColor(CssPropertyValue::Exact(StyleBorderBottomColor {
inner: BUTTON_BORDER_COLOR,
}));
static BUTTON_BORDER_LEFT_COLOR: CssProperty =
CssProperty::BorderLeftColor(CssPropertyValue::Exact(StyleBorderLeftColor {
inner: BUTTON_BORDER_COLOR,
}));
static BUTTON_BORDER_RIGHT_COLOR: CssProperty =
CssProperty::BorderRightColor(CssPropertyValue::Exact(StyleBorderRightColor {
inner: BUTTON_BORDER_COLOR,
}));
static BUTTON_BORDER_TOP_STYLE: CssProperty =
CssProperty::BorderTopStyle(CssPropertyValue::Exact(StyleBorderTopStyle {
inner: BorderStyle::Solid,
}));
static BUTTON_BORDER_BOTTOM_STYLE: CssProperty =
CssProperty::BorderBottomStyle(CssPropertyValue::Exact(StyleBorderBottomStyle {
inner: BorderStyle::Solid,
}));
static BUTTON_BORDER_LEFT_STYLE: CssProperty =
CssProperty::BorderLeftStyle(CssPropertyValue::Exact(StyleBorderLeftStyle {
inner: BorderStyle::Solid,
}));
static BUTTON_BORDER_RIGHT_STYLE: CssProperty =
CssProperty::BorderRightStyle(CssPropertyValue::Exact(StyleBorderRightStyle {
inner: BorderStyle::Solid,
}));
static BUTTON_BORDER_TOP_WIDTH: CssProperty =
CssProperty::BorderTopWidth(CssPropertyValue::Exact(LayoutBorderTopWidth {
inner: PixelValue::const_px(1),
}));
static BUTTON_BORDER_BOTTOM_WIDTH: CssProperty =
CssProperty::BorderBottomWidth(CssPropertyValue::Exact(LayoutBorderBottomWidth {
inner: PixelValue::const_px(1),
}));
static BUTTON_BORDER_LEFT_WIDTH: CssProperty =
CssProperty::BorderLeftWidth(CssPropertyValue::Exact(LayoutBorderLeftWidth {
inner: PixelValue::const_px(1),
}));
static BUTTON_BORDER_RIGHT_WIDTH: CssProperty =
CssProperty::BorderRightWidth(CssPropertyValue::Exact(LayoutBorderRightWidth {
inner: PixelValue::const_px(1),
}));
pub fn get_ua_property(
node_type: &NodeType,
property_type: CssPropertyType,
) -> Option<&'static CssProperty> {
use CssPropertyType as PT;
use NodeType as NT;
let result = match (node_type, property_type) {
(NT::Body, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Body, PT::MarginTop) => Some(&MARGIN_TOP_8PX),
(NT::Body, PT::MarginBottom) => Some(&MARGIN_BOTTOM_8PX),
(NT::Body, PT::MarginLeft) => Some(&MARGIN_LEFT_8PX),
(NT::Body, PT::MarginRight) => Some(&MARGIN_RIGHT_8PX),
(NT::Div, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::P, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::P, PT::MarginTop) => Some(&MARGIN_TOP_1EM),
(NT::P, PT::MarginBottom) => Some(&MARGIN_BOTTOM_1EM),
(NT::Main, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Header, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Footer, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Section, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Article, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Aside, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Nav, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::H1, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::H1, PT::FontSize) => Some(&FONT_SIZE_2EM),
(NT::H1, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
(NT::H1, PT::MarginTop) => Some(&MARGIN_TOP_0_67EM),
(NT::H1, PT::MarginBottom) => Some(&MARGIN_BOTTOM_0_67EM),
(NT::H1, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::H1, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
(NT::H2, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::H2, PT::FontSize) => Some(&FONT_SIZE_1_5EM),
(NT::H2, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
(NT::H2, PT::MarginTop) => Some(&MARGIN_TOP_0_83EM),
(NT::H2, PT::MarginBottom) => Some(&MARGIN_BOTTOM_0_83EM),
(NT::H2, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::H2, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
(NT::H3, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::H3, PT::FontSize) => Some(&FONT_SIZE_1_17EM),
(NT::H3, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
(NT::H3, PT::MarginTop) => Some(&MARGIN_TOP_1EM),
(NT::H3, PT::MarginBottom) => Some(&MARGIN_BOTTOM_1EM),
(NT::H3, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::H3, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
(NT::H4, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::H4, PT::FontSize) => Some(&FONT_SIZE_1EM),
(NT::H4, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
(NT::H4, PT::MarginTop) => Some(&MARGIN_TOP_1_33EM),
(NT::H4, PT::MarginBottom) => Some(&MARGIN_BOTTOM_1_33EM),
(NT::H4, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::H4, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
(NT::H5, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::H5, PT::FontSize) => Some(&FONT_SIZE_0_83EM),
(NT::H5, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
(NT::H5, PT::MarginTop) => Some(&MARGIN_TOP_1_67EM),
(NT::H5, PT::MarginBottom) => Some(&MARGIN_BOTTOM_1_67EM),
(NT::H5, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::H5, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
(NT::H6, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::H6, PT::FontSize) => Some(&FONT_SIZE_0_67EM),
(NT::H6, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
(NT::H6, PT::MarginTop) => Some(&MARGIN_TOP_2_33EM),
(NT::H6, PT::MarginBottom) => Some(&MARGIN_BOTTOM_2_33EM),
(NT::H6, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::H6, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
(NT::Ul, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Ul, PT::ListStyleType) => Some(&LIST_STYLE_TYPE_DISC),
(NT::Ul, PT::CounterReset) => Some(&COUNTER_RESET_LIST_ITEM),
(NT::Ul, PT::PaddingLeft) => Some(&PADDING_INLINE_START_40PX),
(NT::Ol, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Ol, PT::ListStyleType) => Some(&LIST_STYLE_TYPE_DECIMAL),
(NT::Ol, PT::CounterReset) => Some(&COUNTER_RESET_LIST_ITEM),
(NT::Ol, PT::PaddingLeft) => Some(&PADDING_INLINE_START_40PX),
(NT::Li, PT::Display) => Some(&DISPLAY_LIST_ITEM),
(NT::Dl, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Dt, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Dd, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Span, PT::Display) => Some(&DISPLAY_INLINE),
(NT::A, PT::Display) => Some(&DISPLAY_INLINE),
(NT::A, PT::TextDecoration) => Some(&TEXT_DECORATION_UNDERLINE),
(NT::Strong, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Strong, PT::FontWeight) => Some(&FONT_WEIGHT_BOLDER),
(NT::Em, PT::Display) => Some(&DISPLAY_INLINE),
(NT::B, PT::Display) => Some(&DISPLAY_INLINE),
(NT::B, PT::FontWeight) => Some(&FONT_WEIGHT_BOLDER),
(NT::I, PT::Display) => Some(&DISPLAY_INLINE),
(NT::U, PT::Display) => Some(&DISPLAY_INLINE),
(NT::U, PT::TextDecoration) => Some(&TEXT_DECORATION_UNDERLINE),
(NT::Small, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Code, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Kbd, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Samp, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Sub, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Sup, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Pre, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::BlockQuote, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Hr, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Hr, PT::Width) => Some(&WIDTH_100_PERCENT),
(NT::Hr, PT::Height) => Some(&HEIGHT_ZERO),
(NT::Hr, PT::MarginTop) => Some(&MARGIN_TOP_0_5EM),
(NT::Hr, PT::MarginBottom) => Some(&MARGIN_BOTTOM_0_5EM),
(NT::Hr, PT::BorderTopStyle) => Some(&BORDER_TOP_STYLE_INSET),
(NT::Hr, PT::BorderTopWidth) => Some(&BORDER_TOP_WIDTH_1PX),
(NT::Hr, PT::BorderTopColor) => Some(&BORDER_TOP_COLOR_GRAY),
(NT::Table, PT::Display) => Some(&DISPLAY_TABLE),
(NT::THead, PT::Display) => Some(&DISPLAY_TABLE_HEADER_GROUP),
(NT::THead, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
(NT::THead, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::TBody, PT::Display) => Some(&DISPLAY_TABLE_ROW_GROUP),
(NT::TBody, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
(NT::TFoot, PT::Display) => Some(&DISPLAY_TABLE_FOOTER_GROUP),
(NT::TFoot, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
(NT::TFoot, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::Tr, PT::Display) => Some(&DISPLAY_TABLE_ROW),
(NT::Tr, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
(NT::Tr, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::Th, PT::Display) => Some(&DISPLAY_TABLE_CELL),
(NT::Th, PT::TextAlign) => Some(&TEXT_ALIGN_CENTER),
(NT::Th, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
(NT::Th, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
(NT::Th, PT::PaddingTop) => Some(&PADDING_TOP_1PX),
(NT::Th, PT::PaddingBottom) => Some(&PADDING_BOTTOM_1PX),
(NT::Th, PT::PaddingLeft) => Some(&PADDING_LEFT_1PX),
(NT::Th, PT::PaddingRight) => Some(&PADDING_RIGHT_1PX),
(NT::Td, PT::Display) => Some(&DISPLAY_TABLE_CELL),
(NT::Td, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
(NT::Td, PT::PaddingTop) => Some(&PADDING_TOP_1PX),
(NT::Td, PT::PaddingBottom) => Some(&PADDING_BOTTOM_1PX),
(NT::Td, PT::PaddingLeft) => Some(&PADDING_LEFT_1PX),
(NT::Td, PT::PaddingRight) => Some(&PADDING_RIGHT_1PX),
(NT::Form, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Input, PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
(NT::Button, PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
(NT::Button, PT::Cursor) => Some(&CURSOR_POINTER),
(NT::Button, PT::FontSize) => Some(&FONT_SIZE_13PX),
(NT::Button, PT::PaddingTop) => Some(&PADDING_TOP_5PX),
(NT::Button, PT::PaddingBottom) => Some(&PADDING_BOTTOM_5PX),
(NT::Button, PT::PaddingLeft) => Some(&PADDING_LEFT_10PX),
(NT::Button, PT::PaddingRight) => Some(&PADDING_RIGHT_10PX),
(NT::Button, PT::BorderTopWidth) => Some(&BUTTON_BORDER_TOP_WIDTH),
(NT::Button, PT::BorderBottomWidth) => Some(&BUTTON_BORDER_BOTTOM_WIDTH),
(NT::Button, PT::BorderLeftWidth) => Some(&BUTTON_BORDER_LEFT_WIDTH),
(NT::Button, PT::BorderRightWidth) => Some(&BUTTON_BORDER_RIGHT_WIDTH),
(NT::Button, PT::BorderTopStyle) => Some(&BUTTON_BORDER_TOP_STYLE),
(NT::Button, PT::BorderBottomStyle) => Some(&BUTTON_BORDER_BOTTOM_STYLE),
(NT::Button, PT::BorderLeftStyle) => Some(&BUTTON_BORDER_LEFT_STYLE),
(NT::Button, PT::BorderRightStyle) => Some(&BUTTON_BORDER_RIGHT_STYLE),
(NT::Button, PT::BorderTopColor) => Some(&BUTTON_BORDER_TOP_COLOR),
(NT::Button, PT::BorderBottomColor) => Some(&BUTTON_BORDER_BOTTOM_COLOR),
(NT::Button, PT::BorderLeftColor) => Some(&BUTTON_BORDER_LEFT_COLOR),
(NT::Button, PT::BorderRightColor) => Some(&BUTTON_BORDER_RIGHT_COLOR),
(NT::Text(_), PT::Cursor) => Some(&CURSOR_TEXT),
(NT::Select, PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
(NT::TextArea, PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
(NT::TextArea, PT::Cursor) => Some(&CURSOR_TEXT),
(NT::Label, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Head, PT::Display) => Some(&DISPLAY_NONE),
(NT::Title, PT::Display) => Some(&DISPLAY_NONE),
(NT::Script, PT::Display) => Some(&DISPLAY_NONE),
(NT::Style, PT::Display) => Some(&DISPLAY_NONE),
(NT::Link, PT::Display) => Some(&DISPLAY_NONE),
(NT::Br, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Image(_), PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
(NT::Video, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Audio, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Canvas, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Svg, PT::Display) => Some(&DISPLAY_INLINE),
(NT::VirtualView, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Icon(_), PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
(NT::SelectOption, PT::Display) => Some(&DISPLAY_NONE),
(NT::OptGroup, PT::Display) => Some(&DISPLAY_NONE),
(NT::Abbr, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Cite, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Del, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Ins, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Mark, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Q, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Dfn, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Var, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Time, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Data, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Wbr, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Bdi, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Bdo, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Rp, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Rt, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Rtc, PT::Display) => Some(&DISPLAY_INLINE),
(NT::Ruby, PT::Display) => Some(&DISPLAY_INLINE),
(NT::FieldSet, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Figure, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Figure, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::FigCaption, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::FigCaption, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
(NT::Details, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Summary, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Dialog, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Caption, PT::Display) => Some(&DISPLAY_TABLE_CAPTION),
(NT::ColGroup, PT::Display) => Some(&DISPLAY_TABLE_COLUMN_GROUP),
(NT::Col, PT::Display) => Some(&DISPLAY_TABLE_COLUMN),
(NT::Menu, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Dir, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Html, PT::Display) => Some(&DISPLAY_BLOCK),
(NT::Html, PT::Height) => Some(&HEIGHT_100_PERCENT),
(_, PT::Display) => Some(&DISPLAY_INLINE),
_ => None,
};
result
}
const fn scrollbar_color(thumb: ColorU, track: ColorU) -> CssProperty {
CssProperty::ScrollbarColor(CssPropertyValue::Exact(
StyleScrollbarColor::Custom(ScrollbarColorCustom { thumb, track }),
))
}
const fn scrollbar_width(w: LayoutScrollbarWidth) -> CssProperty {
CssProperty::ScrollbarWidth(CssPropertyValue::Exact(w))
}
const fn scrollbar_visibility(v: ScrollbarVisibilityMode) -> CssProperty {
CssProperty::ScrollbarVisibility(CssPropertyValue::Exact(v))
}
const fn scrollbar_fade_delay(ms: u32) -> CssProperty {
CssProperty::ScrollbarFadeDelay(CssPropertyValue::Exact(ScrollbarFadeDelay::new(ms)))
}
const fn scrollbar_fade_duration(ms: u32) -> CssProperty {
CssProperty::ScrollbarFadeDuration(CssPropertyValue::Exact(ScrollbarFadeDuration::new(ms)))
}
pub(crate) static UA_SCROLLBAR_CSS: &[CssPropertyWithConditions] = &[
CssPropertyWithConditions::with_single_condition(
scrollbar_width(LayoutScrollbarWidth::Thin),
&[DynamicSelector::Os(OsCondition::MacOS)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_width(LayoutScrollbarWidth::Thin),
&[DynamicSelector::Os(OsCondition::IOS)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_width(LayoutScrollbarWidth::Thin),
&[DynamicSelector::Os(OsCondition::Android)],
),
CssPropertyWithConditions::simple(
scrollbar_width(LayoutScrollbarWidth::Auto),
),
CssPropertyWithConditions::with_single_condition(
scrollbar_visibility(ScrollbarVisibilityMode::WhenScrolling),
&[DynamicSelector::Os(OsCondition::MacOS)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_visibility(ScrollbarVisibilityMode::WhenScrolling),
&[DynamicSelector::Os(OsCondition::IOS)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_visibility(ScrollbarVisibilityMode::WhenScrolling),
&[DynamicSelector::Os(OsCondition::Android)],
),
CssPropertyWithConditions::simple(
scrollbar_visibility(ScrollbarVisibilityMode::Always),
),
CssPropertyWithConditions::with_single_condition(
scrollbar_fade_delay(500),
&[DynamicSelector::Os(OsCondition::MacOS)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_fade_delay(500),
&[DynamicSelector::Os(OsCondition::IOS)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_fade_delay(300),
&[DynamicSelector::Os(OsCondition::Android)],
),
CssPropertyWithConditions::simple(
scrollbar_fade_delay(0),
),
CssPropertyWithConditions::with_single_condition(
scrollbar_fade_duration(200),
&[DynamicSelector::Os(OsCondition::MacOS)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_fade_duration(200),
&[DynamicSelector::Os(OsCondition::IOS)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_fade_duration(150),
&[DynamicSelector::Os(OsCondition::Android)],
),
CssPropertyWithConditions::simple(
scrollbar_fade_duration(0),
),
CssPropertyWithConditions::with_single_condition(
scrollbar_color(
ColorU { r: 180, g: 180, b: 180, a: 200 },
ColorU { r: 40, g: 40, b: 40, a: 80 },
),
&[DynamicSelector::Os(OsCondition::MacOS), DynamicSelector::Theme(ThemeCondition::Dark)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_color(
ColorU { r: 80, g: 80, b: 80, a: 200 },
ColorU { r: 200, g: 200, b: 200, a: 80 },
),
&[DynamicSelector::Os(OsCondition::MacOS), DynamicSelector::Theme(ThemeCondition::Light)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_color(
ColorU { r: 110, g: 110, b: 110, a: 255 },
ColorU { r: 32, g: 32, b: 32, a: 255 },
),
&[DynamicSelector::Os(OsCondition::Windows), DynamicSelector::Theme(ThemeCondition::Dark)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_color(
ColorU { r: 130, g: 130, b: 130, a: 255 },
ColorU { r: 241, g: 241, b: 241, a: 255 },
),
&[DynamicSelector::Os(OsCondition::Windows), DynamicSelector::Theme(ThemeCondition::Light)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_color(
ColorU { r: 255, g: 255, b: 255, a: 100 },
ColorU::TRANSPARENT,
),
&[DynamicSelector::Os(OsCondition::IOS), DynamicSelector::Theme(ThemeCondition::Dark)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_color(
ColorU { r: 0, g: 0, b: 0, a: 100 },
ColorU::TRANSPARENT,
),
&[DynamicSelector::Os(OsCondition::IOS), DynamicSelector::Theme(ThemeCondition::Light)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_color(
ColorU { r: 255, g: 255, b: 255, a: 77 },
ColorU::TRANSPARENT,
),
&[DynamicSelector::Os(OsCondition::Android), DynamicSelector::Theme(ThemeCondition::Dark)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_color(
ColorU { r: 0, g: 0, b: 0, a: 77 },
ColorU::TRANSPARENT,
),
&[DynamicSelector::Os(OsCondition::Android), DynamicSelector::Theme(ThemeCondition::Light)],
),
CssPropertyWithConditions::with_single_condition(
scrollbar_color(
ColorU { r: 100, g: 100, b: 100, a: 255 },
ColorU { r: 45, g: 45, b: 45, a: 255 },
),
&[DynamicSelector::Theme(ThemeCondition::Dark)],
),
CssPropertyWithConditions::simple(
scrollbar_color(
ColorU { r: 193, g: 193, b: 193, a: 255 },
ColorU { r: 241, g: 241, b: 241, a: 255 },
),
),
];
pub struct ResolvedUaScrollbar {
pub color: StyleScrollbarColor,
pub width: LayoutScrollbarWidth,
pub visibility: ScrollbarVisibilityMode,
pub fade_delay: ScrollbarFadeDelay,
pub fade_duration: ScrollbarFadeDuration,
}
pub fn evaluate_ua_scrollbar_css(ctx: &DynamicSelectorContext) -> ResolvedUaScrollbar {
let mut color: Option<StyleScrollbarColor> = None;
let mut width: Option<LayoutScrollbarWidth> = None;
let mut visibility: Option<ScrollbarVisibilityMode> = None;
let mut fade_delay: Option<ScrollbarFadeDelay> = None;
let mut fade_duration: Option<ScrollbarFadeDuration> = None;
for prop in UA_SCROLLBAR_CSS {
if !prop.matches(ctx) {
continue;
}
match &prop.property {
CssProperty::ScrollbarColor(CssPropertyValue::Exact(c)) => {
if color.is_none() {
color = Some(*c);
}
}
CssProperty::ScrollbarWidth(CssPropertyValue::Exact(w)) => {
if width.is_none() {
width = Some(*w);
}
}
CssProperty::ScrollbarVisibility(CssPropertyValue::Exact(v)) => {
if visibility.is_none() {
visibility = Some(*v);
}
}
CssProperty::ScrollbarFadeDelay(CssPropertyValue::Exact(d)) => {
if fade_delay.is_none() {
fade_delay = Some(*d);
}
}
CssProperty::ScrollbarFadeDuration(CssPropertyValue::Exact(d)) => {
if fade_duration.is_none() {
fade_duration = Some(*d);
}
}
_ => {}
}
if color.is_some() && width.is_some() && visibility.is_some()
&& fade_delay.is_some() && fade_duration.is_some()
{
break;
}
}
ResolvedUaScrollbar {
color: color.unwrap_or(StyleScrollbarColor::Custom(ScrollbarColorCustom {
thumb: ColorU { r: 193, g: 193, b: 193, a: 255 },
track: ColorU { r: 241, g: 241, b: 241, a: 255 },
})),
width: width.unwrap_or(LayoutScrollbarWidth::Auto),
visibility: visibility.unwrap_or(ScrollbarVisibilityMode::Always),
fade_delay: fade_delay.unwrap_or(ScrollbarFadeDelay { ms: 0 }),
fade_duration: fade_duration.unwrap_or(ScrollbarFadeDuration { ms: 0 }),
}
}