Skip to content

Commit

Permalink
layout: Update the width-property to use the new value abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
robinlinden committed Nov 13, 2023
1 parent f33c4b4 commit d02a6fa
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
4 changes: 2 additions & 2 deletions layout/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ void calculate_width_and_margin(

auto margin_left = box.get_property<css::PropertyId::MarginLeft>();
auto margin_right = box.get_property<css::PropertyId::MarginRight>();
if (auto width = box.get_property<css::PropertyId::Width>()) {
box.dimensions.content.width = *width;
if (auto width = box.get_property<css::PropertyId::Width>(); !width.is_auto()) {
box.dimensions.content.width = width.resolve(font_size, root_font_size);
calculate_left_and_right_margin(box, parent, margin_left, margin_right, font_size, root_font_size);
} else {
if (margin_left != "auto") {
Expand Down
11 changes: 0 additions & 11 deletions layout/layout_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ std::optional<int> LayoutBox::get_min_width_property() const {
return to_px(raw, font_size, root_font_size);
}

std::optional<int> LayoutBox::get_width_property() const {
auto raw = node->get_raw_property(css::PropertyId::Width);
if (raw == "auto") {
return std::nullopt;
}

int font_size = node->get_property<css::PropertyId::FontSize>();
int root_font_size = get_root_font_size(*node);
return to_px(raw, font_size, root_font_size);
}

std::optional<int> LayoutBox::get_max_width_property() const {
auto raw = node->get_raw_property(css::PropertyId::MaxWidth);
if (raw == "none") {
Expand Down
4 changes: 2 additions & 2 deletions layout/layout_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define LAYOUT_LAYOUT_BOX_H_

#include "layout/box_model.h"
#include "layout/unresolved_value.h"

#include "css/property_id.h"
#include "dom/dom.h"
Expand Down Expand Up @@ -50,7 +51,7 @@ struct LayoutBox {
} else if constexpr (T == css::PropertyId::MinWidth) {
return get_min_width_property();
} else if constexpr (T == css::PropertyId::Width) {
return get_width_property();
return UnresolvedValue{node->get_raw_property(T)};
} else if constexpr (T == css::PropertyId::MaxWidth) {
return get_max_width_property();
} else {
Expand All @@ -61,7 +62,6 @@ struct LayoutBox {
private:
std::pair<int, int> get_border_radius_property(css::PropertyId) const;
std::optional<int> get_min_width_property() const;
std::optional<int> get_width_property() const;
std::optional<int> get_max_width_property() const;
};

Expand Down
4 changes: 2 additions & 2 deletions layout/layout_property_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ int main() {
expect_property_eq<MinWidth>("13px", 13);
expect_property_eq<MinWidth>("auto", std::nullopt);

expect_property_eq<Width>("42px", 42);
expect_property_eq<Width>("auto", std::nullopt);
expect_property_eq<Width>("42px", layout::UnresolvedValue{"42px"});
expect_property_eq<Width>("auto", layout::UnresolvedValue{"auto"});

expect_property_eq<MaxWidth>("420px", 420);
expect_property_eq<MaxWidth>("none", std::nullopt);
Expand Down

0 comments on commit d02a6fa

Please sign in to comment.