mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Return word-spacing computed value as CSSPixels
This commit is contained in:
parent
099247d502
commit
831088939a
|
|
@ -890,20 +890,20 @@ WordBreak ComputedProperties::word_break() const
|
|||
return keyword_to_word_break(value.to_keyword()).release_value();
|
||||
}
|
||||
|
||||
Optional<LengthPercentage> ComputedProperties::word_spacing() const
|
||||
CSSPixels ComputedProperties::word_spacing() const
|
||||
{
|
||||
auto const& value = property(PropertyID::WordSpacing);
|
||||
if (value.is_keyword() && value.to_keyword() == Keyword::Normal)
|
||||
return LengthPercentage { Length::make_px(0) };
|
||||
return 0;
|
||||
|
||||
if (value.is_length())
|
||||
return LengthPercentage(value.as_length().length());
|
||||
return value.as_length().length().absolute_length_to_px();
|
||||
|
||||
if (value.is_percentage())
|
||||
return LengthPercentage(value.as_percentage().percentage());
|
||||
return font_size().scale_by(value.as_percentage().percentage().as_fraction());
|
||||
|
||||
if (value.is_calculated())
|
||||
return LengthPercentage { value.as_calculated() };
|
||||
return value.as_calculated().resolve_length({ .percentage_basis = Length::make_px(font_size()), .length_resolution_context = {} })->absolute_length_to_px();
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ public:
|
|||
WhiteSpaceCollapse white_space_collapse() const;
|
||||
WhiteSpaceTrimData white_space_trim() const;
|
||||
WordBreak word_break() const;
|
||||
Optional<LengthPercentage> word_spacing() const;
|
||||
CSSPixels word_spacing() const;
|
||||
CSSPixels letter_spacing() const;
|
||||
LineStyle line_style(PropertyID) const;
|
||||
OutlineStyle outline_style() const;
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ public:
|
|||
static CursorData cursor() { return { CSS::CursorPredefined::Auto }; }
|
||||
static CSS::WhiteSpaceCollapse white_space_collapse() { return CSS::WhiteSpaceCollapse::Collapse; }
|
||||
static CSS::WordBreak word_break() { return CSS::WordBreak::Normal; }
|
||||
static LengthPercentage word_spacing() { return CSS::Length::make_px(0); }
|
||||
static CSSPixels word_spacing() { return 0; }
|
||||
static CSSPixels letter_spacing() { return 0; }
|
||||
static Variant<LengthOrCalculated, NumberOrCalculated> tab_size() { return NumberOrCalculated(8.0f); }
|
||||
static CSS::TextAlign text_align() { return CSS::TextAlign::Start; }
|
||||
|
|
@ -491,7 +491,7 @@ public:
|
|||
CSS::Positioning position() const { return m_noninherited.position; }
|
||||
CSS::WhiteSpaceCollapse white_space_collapse() const { return m_inherited.white_space_collapse; }
|
||||
WhiteSpaceTrimData white_space_trim() const { return m_noninherited.white_space_trim; }
|
||||
LengthPercentage const& word_spacing() const { return m_inherited.word_spacing; }
|
||||
CSSPixels const& word_spacing() const { return m_inherited.word_spacing; }
|
||||
CSSPixels letter_spacing() const { return m_inherited.letter_spacing; }
|
||||
CSS::FlexDirection flex_direction() const { return m_noninherited.flex_direction; }
|
||||
CSS::FlexWrap flex_wrap() const { return m_noninherited.flex_wrap; }
|
||||
|
|
@ -700,7 +700,7 @@ protected:
|
|||
CSS::TextRendering text_rendering { InitialValues::text_rendering() };
|
||||
CSS::WhiteSpaceCollapse white_space_collapse { InitialValues::white_space_collapse() };
|
||||
CSS::WordBreak word_break { InitialValues::word_break() };
|
||||
LengthPercentage word_spacing { InitialValues::word_spacing() };
|
||||
CSSPixels word_spacing { InitialValues::word_spacing() };
|
||||
CSSPixels letter_spacing { InitialValues::letter_spacing() };
|
||||
CSS::ListStyleType list_style_type { InitialValues::list_style_type() };
|
||||
CSS::ListStylePosition list_style_position { InitialValues::list_style_position() };
|
||||
|
|
@ -919,7 +919,7 @@ public:
|
|||
void set_position(CSS::Positioning position) { m_noninherited.position = position; }
|
||||
void set_white_space_collapse(CSS::WhiteSpaceCollapse value) { m_inherited.white_space_collapse = value; }
|
||||
void set_white_space_trim(WhiteSpaceTrimData value) { m_noninherited.white_space_trim = value; }
|
||||
void set_word_spacing(CSS::LengthPercentage value) { m_inherited.word_spacing = move(value); }
|
||||
void set_word_spacing(CSSPixels value) { m_inherited.word_spacing = value; }
|
||||
void set_word_break(CSS::WordBreak value) { m_inherited.word_break = value; }
|
||||
void set_letter_spacing(CSSPixels value) { m_inherited.letter_spacing = value; }
|
||||
void set_width(CSS::Size const& width) { m_noninherited.width = width; }
|
||||
|
|
|
|||
|
|
@ -526,10 +526,9 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next_without_lookahead(
|
|||
};
|
||||
}
|
||||
|
||||
CSS::CalculationResolutionContext calculation_context { .length_resolution_context = CSS::Length::ResolutionContext::for_layout_node(text_node) };
|
||||
auto letter_spacing = text_node.computed_values().letter_spacing();
|
||||
// FIXME: We should apply word spacing to all word-separator characters not just breaking tabs
|
||||
auto word_spacing = text_node.computed_values().word_spacing().resolved(text_node, CSS::Length::make_px(chunk.font->glyph_width(' ')).to_px(text_node)).absolute_length_to_px();
|
||||
auto word_spacing = text_node.computed_values().word_spacing();
|
||||
|
||||
auto x = 0.0f;
|
||||
if (chunk.has_breaking_tab) {
|
||||
|
|
@ -542,6 +541,7 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next_without_lookahead(
|
|||
}
|
||||
|
||||
// https://drafts.csswg.org/css-text/#tab-size-property
|
||||
CSS::CalculationResolutionContext calculation_context { .length_resolution_context = CSS::Length::ResolutionContext::for_layout_node(text_node) };
|
||||
auto tab_size = text_node.computed_values().tab_size();
|
||||
CSSPixels tab_width;
|
||||
tab_width = tab_size.visit(
|
||||
|
|
|
|||
|
|
@ -617,9 +617,8 @@ void NodeWithStyle::apply_style(CSS::ComputedProperties const& computed_style)
|
|||
|
||||
computed_values.set_white_space_collapse(computed_style.white_space_collapse());
|
||||
computed_values.set_word_break(computed_style.word_break());
|
||||
if (auto word_spacing = computed_style.word_spacing(); word_spacing.has_value())
|
||||
computed_values.set_word_spacing(word_spacing.value());
|
||||
|
||||
computed_values.set_word_spacing(computed_style.word_spacing());
|
||||
computed_values.set_letter_spacing(computed_style.letter_spacing());
|
||||
|
||||
computed_values.set_float(computed_style.float_());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user