diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-24 13:51:14 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-24 13:54:31 +0200 |
commit | 5e83a97fa235b152441c198e8d38c1260d97b16e (patch) | |
tree | f1fb7e1a07a91ba3171e7cc5fcfadd10cb8d2073 /Libraries/LibWeb/Layout | |
parent | 90edaabc4b303f444752eddabd632daaeea68af9 (diff) | |
download | serenity-5e83a97fa235b152441c198e8d38c1260d97b16e.zip |
LibWeb: Rename LayoutNode::style() => specified_style()
Let's make way for a slightly-more-cooked style() that will eventually
replace the raw specified_style() for layout and paint purposes.
Diffstat (limited to 'Libraries/LibWeb/Layout')
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutBlock.cpp | 20 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutBox.cpp | 16 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutImage.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutListItem.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutListItemMarker.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutNode.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutNode.h | 14 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutReplaced.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutText.cpp | 14 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutText.h | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LineBox.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LineBoxFragment.cpp | 2 |
13 files changed, 45 insertions, 45 deletions
diff --git a/Libraries/LibWeb/Layout/LayoutBlock.cpp b/Libraries/LibWeb/Layout/LayoutBlock.cpp index 45e870097c..bc85269c87 100644 --- a/Libraries/LibWeb/Layout/LayoutBlock.cpp +++ b/Libraries/LibWeb/Layout/LayoutBlock.cpp @@ -69,7 +69,7 @@ void LayoutBlock::layout_absolutely_positioned_descendant(LayoutBox& box) { box.layout(LayoutMode::Default); auto& box_model = box.box_model(); - auto& style = box.style(); + auto& style = box.specified_style(); auto zero_value = Length::make_px(0); auto specified_width = style.length_or_fallback(CSS::PropertyID::Width, Length::make_auto(), width()); @@ -164,7 +164,7 @@ void LayoutBlock::layout_contained_boxes(LayoutMode layout_mode) }); if (layout_mode != LayoutMode::Default) { - auto specified_width = style().length_or_fallback(CSS::PropertyID::Width, Length::make_auto(), containing_block()->width()); + auto specified_width = specified_style().length_or_fallback(CSS::PropertyID::Width, Length::make_auto(), containing_block()->width()); if (specified_width.is_auto()) set_width(content_width); } @@ -188,8 +188,8 @@ void LayoutBlock::layout_inline_children(LayoutMode layout_mode) } auto text_align = this->text_align(); - float min_line_height = style().line_height(*this); - float line_spacing = min_line_height - style().font().glyph_height(); + float min_line_height = specified_style().line_height(*this); + float line_spacing = min_line_height - specified_style().font().glyph_height(); float content_height = 0; float max_linebox_width = 0; @@ -277,7 +277,7 @@ void LayoutBlock::layout_inline_children(LayoutMode layout_mode) void LayoutBlock::compute_width_for_absolutely_positioned_block() { - auto& style = this->style(); + auto& style = this->specified_style(); auto& containing_block = *this->containing_block(); auto zero_value = Length::make_px(0); @@ -424,7 +424,7 @@ void LayoutBlock::compute_width() if (is_absolutely_positioned()) return compute_width_for_absolutely_positioned_block(); - auto& style = this->style(); + auto& style = this->specified_style(); auto auto_value = Length::make_auto(); auto zero_value = Length::make_px(0); @@ -561,7 +561,7 @@ void LayoutBlock::compute_width() void LayoutBlock::place_block_level_replaced_element_in_normal_flow(LayoutReplaced& box) { ASSERT(!is_absolutely_positioned()); - auto& style = box.style(); + auto& style = box.specified_style(); auto zero_value = Length::make_px(0); auto& containing_block = *this; auto& replaced_element_box_model = box.box_model(); @@ -616,7 +616,7 @@ LayoutBlock::ShrinkToFitResult LayoutBlock::calculate_shrink_to_fit_width() void LayoutBlock::place_block_level_non_replaced_element_in_normal_flow(LayoutBlock& block) { - auto& style = block.style(); + auto& style = block.specified_style(); auto zero_value = Length::make_px(0); auto& containing_block = *this; auto& box = block.box_model(); @@ -672,7 +672,7 @@ void LayoutBlock::place_block_level_non_replaced_element_in_normal_flow(LayoutBl void LayoutBlock::compute_height() { - auto& style = this->style(); + auto& style = this->specified_style(); auto specified_height = style.length_or_fallback(CSS::PropertyID::Height, Length::make_auto(), containing_block()->height()); auto specified_max_height = style.length_or_fallback(CSS::PropertyID::MaxHeight, Length::make_auto(), containing_block()->height()); @@ -740,7 +740,7 @@ NonnullRefPtr<StyleProperties> LayoutBlock::style_for_anonymous_block() const { auto new_style = StyleProperties::create(); - style().for_each_property([&](auto property_id, auto& value) { + specified_style().for_each_property([&](auto property_id, auto& value) { if (StyleResolver::is_inherited_property(property_id)) new_style->set_property(property_id, value); }); diff --git a/Libraries/LibWeb/Layout/LayoutBox.cpp b/Libraries/LibWeb/Layout/LayoutBox.cpp index af8bf6d687..9951221b0d 100644 --- a/Libraries/LibWeb/Layout/LayoutBox.cpp +++ b/Libraries/LibWeb/Layout/LayoutBox.cpp @@ -35,11 +35,11 @@ namespace Web { void LayoutBox::paint_border(PaintContext& context, Edge edge, const Gfx::FloatRect& rect, CSS::PropertyID style_property_id, CSS::PropertyID color_property_id, CSS::PropertyID width_property_id) { - auto border_width = style().property(width_property_id); + auto border_width = specified_style().property(width_property_id); if (!border_width.has_value()) return; - auto border_style = style().property(style_property_id); + auto border_style = specified_style().property(style_property_id); float width = border_width.value()->to_length().to_px(*this); if (width <= 0) return; @@ -47,13 +47,13 @@ void LayoutBox::paint_border(PaintContext& context, Edge edge, const Gfx::FloatR int int_width = max((int)width, 1); Color color; - auto border_color = style().property(color_property_id); + auto border_color = specified_style().property(color_property_id); if (border_color.has_value()) { color = border_color.value()->to_color(document()); } else { // FIXME: This is basically CSS "currentColor" which should be handled elsewhere // in a much more reusable way. - auto current_color = style().property(CSS::PropertyID::Color); + auto current_color = specified_style().property(CSS::PropertyID::Color); if (current_color.has_value()) color = current_color.value()->to_color(document()); else @@ -137,7 +137,7 @@ void LayoutBox::paint_border(PaintContext& context, Edge edge, const Gfx::FloatR }; auto width_for = [&](CSS::PropertyID property_id) -> float { - auto width = style().property(property_id); + auto width = specified_style().property(property_id); if (!width.has_value()) return 0; return width.value()->to_length().to_px(*this); @@ -203,12 +203,12 @@ void LayoutBox::paint(PaintContext& context, PaintPhase phase) if (phase == PaintPhase::Background && !is_body()) { // FIXME: We should paint the body here too, but that currently happens at the view layer. - auto bgcolor = style().property(CSS::PropertyID::BackgroundColor); + auto bgcolor = specified_style().property(CSS::PropertyID::BackgroundColor); if (bgcolor.has_value() && bgcolor.value()->is_color()) { context.painter().fill_rect(enclosing_int_rect(padded_rect), bgcolor.value()->to_color(document())); } - auto bgimage = style().property(CSS::PropertyID::BackgroundImage); + auto bgimage = specified_style().property(CSS::PropertyID::BackgroundImage); if (bgimage.has_value() && bgimage.value()->is_image()) { auto& image_value = static_cast<const ImageStyleValue&>(*bgimage.value()); if (image_value.bitmap()) { @@ -324,7 +324,7 @@ bool LayoutBox::establishes_stacking_context() const if (node() == document().root()) return true; auto position = this->position(); - auto z_index = style().z_index(); + auto z_index = specified_style().z_index(); if (position == CSS::Position::Absolute || position == CSS::Position::Relative) { if (z_index.has_value()) return true; diff --git a/Libraries/LibWeb/Layout/LayoutImage.cpp b/Libraries/LibWeb/Layout/LayoutImage.cpp index 17848fc900..b1f1882c27 100644 --- a/Libraries/LibWeb/Layout/LayoutImage.cpp +++ b/Libraries/LibWeb/Layout/LayoutImage.cpp @@ -94,7 +94,7 @@ void LayoutImage::paint(PaintContext& context, PaintPhase phase) auto alt = image_element.alt(); if (alt.is_empty()) alt = image_element.src(); - context.painter().draw_text(enclosing_int_rect(absolute_rect()), alt, Gfx::TextAlignment::Center, style().color_or_fallback(CSS::PropertyID::Color, document(), Color::Black), Gfx::TextElision::Right); + context.painter().draw_text(enclosing_int_rect(absolute_rect()), alt, Gfx::TextAlignment::Center, specified_style().color_or_fallback(CSS::PropertyID::Color, document(), Color::Black), Gfx::TextElision::Right); } else if (auto* bitmap = m_image_loader.bitmap()) { context.painter().draw_scaled_bitmap(enclosing_int_rect(absolute_rect()), *bitmap, bitmap->rect()); } diff --git a/Libraries/LibWeb/Layout/LayoutListItem.cpp b/Libraries/LibWeb/Layout/LayoutListItem.cpp index 877c095483..0c10aa29cd 100644 --- a/Libraries/LibWeb/Layout/LayoutListItem.cpp +++ b/Libraries/LibWeb/Layout/LayoutListItem.cpp @@ -47,7 +47,7 @@ void LayoutListItem::layout(LayoutMode layout_mode) LayoutBlock::layout(layout_mode); - if (style().string_or_fallback(CSS::PropertyID::ListStyleType, "disc") == "none") { + if (specified_style().string_or_fallback(CSS::PropertyID::ListStyleType, "disc") == "none") { return; } diff --git a/Libraries/LibWeb/Layout/LayoutListItemMarker.cpp b/Libraries/LibWeb/Layout/LayoutListItemMarker.cpp index 551f7e36ea..bee1d57258 100644 --- a/Libraries/LibWeb/Layout/LayoutListItemMarker.cpp +++ b/Libraries/LibWeb/Layout/LayoutListItemMarker.cpp @@ -45,7 +45,7 @@ void LayoutListItemMarker::paint(PaintContext& context, PaintPhase phase) Gfx::IntRect bullet_rect { 0, 0, 4, 4 }; bullet_rect.center_within(enclosing_int_rect(absolute_rect())); // FIXME: It would be nicer to not have to go via the parent here to get our inherited style. - auto color = parent()->style().color_or_fallback(CSS::PropertyID::Color, document(), context.palette().base_text()); + auto color = parent()->specified_style().color_or_fallback(CSS::PropertyID::Color, document(), context.palette().base_text()); context.painter().fill_rect(bullet_rect, color); } diff --git a/Libraries/LibWeb/Layout/LayoutNode.cpp b/Libraries/LibWeb/Layout/LayoutNode.cpp index 236bc0840d..e185991872 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.cpp +++ b/Libraries/LibWeb/Layout/LayoutNode.cpp @@ -173,7 +173,7 @@ void LayoutNode::set_needs_display() float LayoutNode::font_size() const { // FIXME: This doesn't work right for relative font-sizes - auto length = style().length_or_fallback(CSS::PropertyID::FontSize, Length(10, Length::Type::Px)); + auto length = specified_style().length_or_fallback(CSS::PropertyID::FontSize, Length(10, Length::Type::Px)); return length.raw_value(); } @@ -213,11 +213,11 @@ bool LayoutNode::is_fixed_position() const LayoutNodeWithStyle::LayoutNodeWithStyle(const Node* node, NonnullRefPtr<StyleProperties> style) : LayoutNode(node) - , m_style(move(style)) + , m_specified_style(move(style)) { m_has_style = true; - m_position = m_style->position(); - m_text_align = m_style->text_align(); + m_position = m_specified_style->position(); + m_text_align = m_specified_style->text_align(); } } diff --git a/Libraries/LibWeb/Layout/LayoutNode.h b/Libraries/LibWeb/Layout/LayoutNode.h index 2369ed7661..dc002f180c 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.h +++ b/Libraries/LibWeb/Layout/LayoutNode.h @@ -189,7 +189,7 @@ public: virtual LayoutNode& inline_wrapper() { return *this; } - const StyleProperties& style() const; + const StyleProperties& specified_style() const; CSS::Position position() const; CSS::TextAlign text_align() const; @@ -256,8 +256,8 @@ class LayoutNodeWithStyle : public LayoutNode { public: virtual ~LayoutNodeWithStyle() override { } - const StyleProperties& style() const { return m_style; } - void set_style(const StyleProperties& style) { m_style = style; } + const StyleProperties& specified_style() const { return m_specified_style; } + void set_specified_style(const StyleProperties& style) { m_specified_style = style; } CSS::Position position() const { return m_position; } CSS::TextAlign text_align() const { return m_text_align; } @@ -266,7 +266,7 @@ protected: explicit LayoutNodeWithStyle(const Node*, NonnullRefPtr<StyleProperties>); private: - NonnullRefPtr<StyleProperties> m_style; + NonnullRefPtr<StyleProperties> m_specified_style; CSS::Position m_position; CSS::TextAlign m_text_align; }; @@ -286,11 +286,11 @@ private: BoxModelMetrics m_box_model; }; -inline const StyleProperties& LayoutNode::style() const +inline const StyleProperties& LayoutNode::specified_style() const { if (m_has_style) - return static_cast<const LayoutNodeWithStyle*>(this)->style(); - return parent()->style(); + return static_cast<const LayoutNodeWithStyle*>(this)->specified_style(); + return parent()->specified_style(); } inline CSS::Position LayoutNode::position() const diff --git a/Libraries/LibWeb/Layout/LayoutReplaced.cpp b/Libraries/LibWeb/Layout/LayoutReplaced.cpp index d0dce29b2f..4751ffc53f 100644 --- a/Libraries/LibWeb/Layout/LayoutReplaced.cpp +++ b/Libraries/LibWeb/Layout/LayoutReplaced.cpp @@ -45,7 +45,7 @@ float LayoutReplaced::calculate_width() const { // 10.3.2 [Inline,] replaced elements - auto& style = this->style(); + auto& style = this->specified_style(); auto auto_value = Length::make_auto(); auto zero_value = Length::make_px(0); auto& containing_block = *this->containing_block(); @@ -98,7 +98,7 @@ float LayoutReplaced::calculate_height() const { // 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, // 'inline-block' replaced elements in normal flow and floating replaced elements - auto& style = this->style(); + auto& style = this->specified_style(); auto auto_value = Length::make_auto(); auto& containing_block = *this->containing_block(); diff --git a/Libraries/LibWeb/Layout/LayoutText.cpp b/Libraries/LibWeb/Layout/LayoutText.cpp index 119f8aee0c..7e9dc48c8a 100644 --- a/Libraries/LibWeb/Layout/LayoutText.cpp +++ b/Libraries/LibWeb/Layout/LayoutText.cpp @@ -68,14 +68,14 @@ const String& LayoutText::text_for_style(const StyleProperties& style) const void LayoutText::render_fragment(PaintContext& context, const LineBoxFragment& fragment) const { auto& painter = context.painter(); - painter.set_font(style().font()); + painter.set_font(specified_style().font()); - auto background_color = style().property(CSS::PropertyID::BackgroundColor); + auto background_color = specified_style().property(CSS::PropertyID::BackgroundColor); if (background_color.has_value() && background_color.value()->is_color()) painter.fill_rect(enclosing_int_rect(fragment.absolute_rect()), background_color.value()->to_color(document())); - auto color = style().color_or_fallback(CSS::PropertyID::Color, document(), context.palette().base_text()); - auto text_decoration = style().string_or_fallback(CSS::PropertyID::TextDecoration, "none"); + auto color = specified_style().color_or_fallback(CSS::PropertyID::Color, document(), context.palette().base_text()); + auto text_decoration = specified_style().string_or_fallback(CSS::PropertyID::TextDecoration, "none"); if (document().inspected_node() == &node()) context.painter().draw_rect(enclosing_int_rect(fragment.absolute_rect()), Color::Magenta); @@ -85,7 +85,7 @@ void LayoutText::render_fragment(PaintContext& context, const LineBoxFragment& f painter.draw_line(enclosing_int_rect(fragment.absolute_rect()).bottom_left().translated(0, 1), enclosing_int_rect(fragment.absolute_rect()).bottom_right().translated(0, 1), color); auto text = m_text_for_rendering; - auto text_transform = style().string_or_fallback(CSS::PropertyID::TextTransform, "none"); + auto text_transform = specified_style().string_or_fallback(CSS::PropertyID::TextTransform, "none"); if (text_transform == "uppercase") text = m_text_for_rendering.to_uppercase(); if (text_transform == "lowercase") @@ -149,7 +149,7 @@ void LayoutText::for_each_chunk(Callback callback, LayoutMode layout_mode, bool void LayoutText::split_into_lines_by_rules(LayoutBlock& container, LayoutMode layout_mode, bool do_collapse, bool do_wrap_lines, bool do_wrap_breaks) { - auto& font = style().font(); + auto& font = specified_style().font(); float space_width = font.glyph_width(' ') + font.glyph_spacing(); auto& line_boxes = container.line_boxes(); @@ -253,7 +253,7 @@ void LayoutText::split_into_lines(LayoutBlock& container, LayoutMode layout_mode bool do_collapse = true; bool do_wrap_lines = true; bool do_wrap_breaks = false; - auto white_space_prop = style().string_or_fallback(CSS::PropertyID::WhiteSpace, "normal"); + auto white_space_prop = specified_style().string_or_fallback(CSS::PropertyID::WhiteSpace, "normal"); if (white_space_prop == "nowrap") { do_collapse = true; diff --git a/Libraries/LibWeb/Layout/LayoutText.h b/Libraries/LibWeb/Layout/LayoutText.h index b5860dca02..62b12e863e 100644 --- a/Libraries/LibWeb/Layout/LayoutText.h +++ b/Libraries/LibWeb/Layout/LayoutText.h @@ -50,7 +50,7 @@ public: virtual void split_into_lines(LayoutBlock& container, LayoutMode) override; - const StyleProperties& style() const { return parent()->style(); } + const StyleProperties& specified_style() const { return parent()->specified_style(); } private: void split_into_lines_by_rules(LayoutBlock& container, LayoutMode, bool do_collapse, bool do_wrap_lines, bool do_wrap_breaks); diff --git a/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp b/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp index 1ed4397c2f..313d98e39b 100644 --- a/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp +++ b/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp @@ -51,7 +51,7 @@ static RefPtr<LayoutNode> create_layout_tree(Node& node, const StyleProperties* bool have_noninline_children = false; to<ParentNode>(node).for_each_child([&](Node& child) { - auto layout_child = create_layout_tree(child, &layout_node->style()); + auto layout_child = create_layout_tree(child, &layout_node->specified_style()); if (!layout_child) return; if (layout_child->is_inline()) diff --git a/Libraries/LibWeb/Layout/LineBox.cpp b/Libraries/LibWeb/Layout/LineBox.cpp index 667c696658..aac8862dd2 100644 --- a/Libraries/LibWeb/Layout/LineBox.cpp +++ b/Libraries/LibWeb/Layout/LineBox.cpp @@ -65,7 +65,7 @@ void LineBox::trim_trailing_whitespace() return; auto& last_fragment = m_fragments.last(); - int space_width = last_fragment.layout_node().style().font().glyph_width(' '); + int space_width = last_fragment.layout_node().specified_style().font().glyph_width(' '); while (last_fragment.length() && isspace(last_text[last_fragment.length() - 1])) { last_fragment.m_length -= 1; last_fragment.set_width(last_fragment.width() - space_width); diff --git a/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Libraries/LibWeb/Layout/LineBoxFragment.cpp index 55a9442e32..4d493359e1 100644 --- a/Libraries/LibWeb/Layout/LineBoxFragment.cpp +++ b/Libraries/LibWeb/Layout/LineBoxFragment.cpp @@ -79,7 +79,7 @@ int LineBoxFragment::text_index_at(float x) const if (!layout_node().is_text()) return 0; auto& layout_text = to<LayoutText>(layout_node()); - auto& font = layout_text.style().font(); + auto& font = layout_text.specified_style().font(); Utf8View view(text()); float relative_x = x - absolute_x(); |