mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Use enums for text-align / text-align-last.
This also fixes some backwards logic in nsBlockFrame::ReflowDirtyLines, and adds some static assertions to nsGenericHTMLElement that almost cause a very subtle bug. Depends on D63792 Differential Revision: https://phabricator.services.mozilla.com/D63793
This commit is contained in:
parent
37c382a74b
commit
7af9a087aa
8 changed files with 47 additions and 61 deletions
|
@ -10,10 +10,9 @@
|
||||||
|
|
||||||
#![allow(unsafe_code)]
|
#![allow(unsafe_code)]
|
||||||
|
|
||||||
use crate::gecko_bindings::structs::{self, Matrix4x4Components, nsresult};
|
use crate::gecko_bindings::structs::{Matrix4x4Components, nsresult};
|
||||||
use crate::stylesheets::RulesMutateError;
|
use crate::stylesheets::RulesMutateError;
|
||||||
use crate::values::computed::transform::Matrix3D;
|
use crate::values::computed::transform::Matrix3D;
|
||||||
use crate::values::computed::TextAlign;
|
|
||||||
|
|
||||||
impl From<RulesMutateError> for nsresult {
|
impl From<RulesMutateError> for nsresult {
|
||||||
fn from(other: RulesMutateError) -> Self {
|
fn from(other: RulesMutateError) -> Self {
|
||||||
|
@ -26,39 +25,6 @@ impl From<RulesMutateError> for nsresult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextAlign {
|
|
||||||
/// Obtain a specified value from a Gecko keyword value
|
|
||||||
///
|
|
||||||
/// Intended for use with presentation attributes, not style structs
|
|
||||||
pub fn from_gecko_keyword(kw: u32) -> Self {
|
|
||||||
match kw {
|
|
||||||
structs::NS_STYLE_TEXT_ALIGN_LEFT => TextAlign::Left,
|
|
||||||
structs::NS_STYLE_TEXT_ALIGN_RIGHT => TextAlign::Right,
|
|
||||||
structs::NS_STYLE_TEXT_ALIGN_CENTER => TextAlign::Center,
|
|
||||||
structs::NS_STYLE_TEXT_ALIGN_JUSTIFY => TextAlign::Justify,
|
|
||||||
structs::NS_STYLE_TEXT_ALIGN_MOZ_LEFT => TextAlign::MozLeft,
|
|
||||||
structs::NS_STYLE_TEXT_ALIGN_MOZ_RIGHT => TextAlign::MozRight,
|
|
||||||
structs::NS_STYLE_TEXT_ALIGN_MOZ_CENTER => TextAlign::MozCenter,
|
|
||||||
structs::NS_STYLE_TEXT_ALIGN_CHAR => TextAlign::Char,
|
|
||||||
structs::NS_STYLE_TEXT_ALIGN_END => TextAlign::End,
|
|
||||||
_ => panic!("Found unexpected value in style struct for text-align property"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert to String from given chars pointer.
|
|
||||||
pub unsafe fn string_from_chars_pointer(p: *const u16) -> String {
|
|
||||||
use std::slice;
|
|
||||||
let mut length = 0;
|
|
||||||
let mut iter = p;
|
|
||||||
while *iter != 0 {
|
|
||||||
length += 1;
|
|
||||||
iter = iter.offset(1);
|
|
||||||
}
|
|
||||||
let char_vec = slice::from_raw_parts(p, length as usize);
|
|
||||||
String::from_utf16_lossy(char_vec)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a Matrix4x4Components> for Matrix3D {
|
impl<'a> From<&'a Matrix4x4Components> for Matrix3D {
|
||||||
fn from(m: &'a Matrix4x4Components) -> Matrix3D {
|
fn from(m: &'a Matrix4x4Components) -> Matrix3D {
|
||||||
Matrix3D {
|
Matrix3D {
|
||||||
|
|
|
@ -382,6 +382,7 @@ class Longhand(object):
|
||||||
"ScrollSnapStrictness",
|
"ScrollSnapStrictness",
|
||||||
"ScrollSnapType",
|
"ScrollSnapType",
|
||||||
"TextAlign",
|
"TextAlign",
|
||||||
|
"TextAlignLast",
|
||||||
"TextDecorationLine",
|
"TextDecorationLine",
|
||||||
"TextEmphasisPosition",
|
"TextEmphasisPosition",
|
||||||
"TextTransform",
|
"TextTransform",
|
||||||
|
|
|
@ -2016,16 +2016,9 @@ fn static_assert() {
|
||||||
|
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="InheritedText"
|
<%self:impl_trait style_struct_name="InheritedText"
|
||||||
skip_longhands="text-align -webkit-text-stroke-width">
|
skip_longhands="-webkit-text-stroke-width">
|
||||||
|
|
||||||
<% text_align_keyword = Keyword("text-align",
|
|
||||||
"start end left right center justify -moz-center -moz-left -moz-right char",
|
|
||||||
gecko_strip_moz_prefix=False) %>
|
|
||||||
${impl_keyword('text_align', 'mTextAlign', text_align_keyword)}
|
|
||||||
|
|
||||||
${impl_non_negative_length('_webkit_text_stroke_width',
|
${impl_non_negative_length('_webkit_text_stroke_width',
|
||||||
'mWebkitTextStrokeWidth')}
|
'mWebkitTextStrokeWidth')}
|
||||||
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="Text" skip_longhands="initial-letter">
|
<%self:impl_trait style_struct_name="Text" skip_longhands="initial-letter">
|
||||||
|
|
|
@ -141,11 +141,12 @@ ${helpers.predefined_type(
|
||||||
% endif
|
% endif
|
||||||
</%helpers:single_keyword>
|
</%helpers:single_keyword>
|
||||||
|
|
||||||
${helpers.single_keyword(
|
${helpers.predefined_type(
|
||||||
"text-align-last",
|
"text-align-last",
|
||||||
"auto start end left right center justify",
|
"TextAlignLast",
|
||||||
|
"computed::text::TextAlignLast::Auto",
|
||||||
|
needs_context=False,
|
||||||
engines="gecko",
|
engines="gecko",
|
||||||
gecko_constant_prefix="NS_STYLE_TEXT_ALIGN",
|
|
||||||
animation_value_type="discrete",
|
animation_value_type="discrete",
|
||||||
spec="https://drafts.csswg.org/css-text/#propdef-text-align-last",
|
spec="https://drafts.csswg.org/css-text/#propdef-text-align-last",
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -78,7 +78,7 @@ pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||||
pub use self::text::TextUnderlinePosition;
|
pub use self::text::TextUnderlinePosition;
|
||||||
pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight};
|
pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight};
|
||||||
pub use self::text::{OverflowWrap, TextOverflow, WordBreak, WordSpacing};
|
pub use self::text::{OverflowWrap, TextOverflow, WordBreak, WordSpacing};
|
||||||
pub use self::text::{TextAlign, TextEmphasisPosition, TextEmphasisStyle};
|
pub use self::text::{TextAlign, TextAlignLast, TextEmphasisPosition, TextEmphasisStyle};
|
||||||
pub use self::text::{TextDecorationLength, TextDecorationSkipInk};
|
pub use self::text::{TextDecorationLength, TextDecorationSkipInk};
|
||||||
pub use self::time::Time;
|
pub use self::time::Time;
|
||||||
pub use self::transform::{Rotate, Scale, Transform, TransformOperation};
|
pub use self::transform::{Rotate, Scale, Transform, TransformOperation};
|
||||||
|
|
|
@ -18,8 +18,7 @@ use crate::Zero;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::{CssWriter, ToCss};
|
use style_traits::{CssWriter, ToCss};
|
||||||
|
|
||||||
pub use crate::values::specified::TextAlignKeyword as TextAlign;
|
pub use crate::values::specified::text::{TextAlignLast, TextUnderlinePosition};
|
||||||
pub use crate::values::specified::TextUnderlinePosition;
|
|
||||||
pub use crate::values::specified::{LineBreak, OverflowWrap, WordBreak};
|
pub use crate::values::specified::{LineBreak, OverflowWrap, WordBreak};
|
||||||
pub use crate::values::specified::{TextDecorationLine, TextEmphasisPosition};
|
pub use crate::values::specified::{TextDecorationLine, TextEmphasisPosition};
|
||||||
pub use crate::values::specified::{TextDecorationSkipInk, TextTransform};
|
pub use crate::values::specified::{TextDecorationSkipInk, TextTransform};
|
||||||
|
@ -30,6 +29,9 @@ pub type InitialLetter = GenericInitialLetter<CSSFloat, CSSInteger>;
|
||||||
/// Implements type for `text-decoration-thickness` property.
|
/// Implements type for `text-decoration-thickness` property.
|
||||||
pub type TextDecorationLength = GenericTextDecorationLength<LengthPercentage>;
|
pub type TextDecorationLength = GenericTextDecorationLength<LengthPercentage>;
|
||||||
|
|
||||||
|
/// The computed value of `text-align`.
|
||||||
|
pub type TextAlign = specified::TextAlignKeyword;
|
||||||
|
|
||||||
/// A computed value for the `letter-spacing` property.
|
/// A computed value for the `letter-spacing` property.
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|
|
@ -85,6 +85,7 @@ pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight, TextAl
|
||||||
pub use self::text::{OverflowWrap, TextEmphasisPosition, TextEmphasisStyle, WordBreak};
|
pub use self::text::{OverflowWrap, TextEmphasisPosition, TextEmphasisStyle, WordBreak};
|
||||||
pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
|
pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
|
||||||
pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextTransform};
|
pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextTransform};
|
||||||
|
pub use self::text::TextAlignLast;
|
||||||
pub use self::time::Time;
|
pub use self::time::Time;
|
||||||
pub use self::transform::{Rotate, Scale, Transform};
|
pub use self::transform::{Rotate, Scale, Transform};
|
||||||
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
||||||
|
|
|
@ -517,6 +517,35 @@ impl ToCss for TextTransformOther {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specified and computed value of text-align-last.
|
||||||
|
#[derive(
|
||||||
|
Clone,
|
||||||
|
Copy,
|
||||||
|
Debug,
|
||||||
|
Eq,
|
||||||
|
FromPrimitive,
|
||||||
|
Hash,
|
||||||
|
MallocSizeOf,
|
||||||
|
Parse,
|
||||||
|
PartialEq,
|
||||||
|
SpecifiedValueInfo,
|
||||||
|
ToComputedValue,
|
||||||
|
ToCss,
|
||||||
|
ToResolvedValue,
|
||||||
|
ToShmem,
|
||||||
|
)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum TextAlignLast {
|
||||||
|
Auto,
|
||||||
|
Start,
|
||||||
|
End,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Center,
|
||||||
|
Justify,
|
||||||
|
}
|
||||||
|
|
||||||
/// Specified value of text-align keyword value.
|
/// Specified value of text-align keyword value.
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -535,14 +564,18 @@ impl ToCss for TextTransformOther {
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
#[repr(u8)]
|
||||||
pub enum TextAlignKeyword {
|
pub enum TextAlignKeyword {
|
||||||
Start,
|
Start,
|
||||||
End,
|
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Right,
|
||||||
Center,
|
Center,
|
||||||
#[cfg(any(feature = "gecko", feature = "servo-layout-2013"))]
|
#[cfg(any(feature = "gecko", feature = "servo-layout-2013"))]
|
||||||
Justify,
|
Justify,
|
||||||
|
#[css(skip)]
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
Char,
|
||||||
|
End,
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
MozCenter,
|
MozCenter,
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
@ -555,9 +588,6 @@ pub enum TextAlignKeyword {
|
||||||
ServoLeft,
|
ServoLeft,
|
||||||
#[cfg(feature = "servo-layout-2013")]
|
#[cfg(feature = "servo-layout-2013")]
|
||||||
ServoRight,
|
ServoRight,
|
||||||
#[css(skip)]
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
Char,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Specified value of text-align property.
|
/// Specified value of text-align property.
|
||||||
|
@ -579,14 +609,6 @@ pub enum TextAlign {
|
||||||
MozCenterOrInherit,
|
MozCenterOrInherit,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextAlign {
|
|
||||||
/// Convert an enumerated value coming from Gecko to a `TextAlign`.
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
pub fn from_gecko_keyword(kw: u32) -> Self {
|
|
||||||
TextAlign::Keyword(TextAlignKeyword::from_gecko_keyword(kw))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToComputedValue for TextAlign {
|
impl ToComputedValue for TextAlign {
|
||||||
type ComputedValue = TextAlignKeyword;
|
type ComputedValue = TextAlignKeyword;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue