Skip to content

Commit

Permalink
layout: Remove support for disabling whitespace-collapsing
Browse files Browse the repository at this point in the history
This debug feature is no longer needed now that we wrap text.
  • Loading branch information
robinlinden committed Oct 25, 2023
1 parent 3527d09 commit af2d34f
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 59 deletions.
7 changes: 0 additions & 7 deletions browser/gui/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,6 @@ int App::run() {
switch_canvas();
break;
}
case sf::Keyboard::Key::F3: {
auto mode = engine_.whitespace_mode();
engine_.set_whitespace_mode(mode == layout::WhitespaceMode::Preserve
? layout::WhitespaceMode::Collapse
: layout::WhitespaceMode::Preserve);
break;
}
case sf::Keyboard::Key::F4: {
display_debug_gui_ = !display_debug_gui_;
break;
Expand Down
12 changes: 1 addition & 11 deletions engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ void Engine::set_layout_width(int width) {
on_layout_update_();
}

void Engine::set_whitespace_mode(layout::WhitespaceMode mode) {
whitespace_mode_ = mode;
if (!styled_) {
return;
}

layout_ = layout::create_layout(*styled_, layout_width_, mode);
on_layout_update_();
}

void Engine::on_navigation_success() {
dom_ = html::parse(response_.body);
stylesheet_ = css::default_style();
Expand Down Expand Up @@ -150,7 +140,7 @@ void Engine::on_navigation_success() {

spdlog::info("Styling dom w/ {} rules", stylesheet_.rules.size());
styled_ = style::style_tree(dom_.html_node, stylesheet_, {.window_width = layout_width_});
layout_ = layout::create_layout(*styled_, layout_width_, whitespace_mode_);
layout_ = layout::create_layout(*styled_, layout_width_);
on_page_loaded_();
}

Expand Down
3 changes: 0 additions & 3 deletions engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class Engine {
protocol::Error navigate(uri::Uri uri);

void set_layout_width(int width);
void set_whitespace_mode(layout::WhitespaceMode);
layout::WhitespaceMode whitespace_mode() const { return whitespace_mode_; }

void set_on_navigation_failure(auto cb) { on_navigation_failure_ = std::move(cb); }
void set_on_page_loaded(auto cb) { on_page_loaded_ = std::move(cb); }
Expand All @@ -51,7 +49,6 @@ class Engine {
}};

int layout_width_{};
layout::WhitespaceMode whitespace_mode_{layout::WhitespaceMode::Collapse};

std::unique_ptr<protocol::IProtocolHandler> protocol_handler_{};

Expand Down
26 changes: 0 additions & 26 deletions engine/engine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,31 +394,5 @@ int main() {
expect_eq(e.navigate(uri::Uri::parse("hax://example.com")), protocol::Error::InvalidResponse);
});

etest::test("whitespace mode", [] {
engine::Engine e{std::make_unique<FakeProtocolHandler>(std::map<std::string, Response>{
{"hax://example.com", Response{Error::Ok, {.status_code = 200}, {}, "<p> hello </p>"}},
})};

// Check that the engine is happy changing this even without a page loaded.
e.set_whitespace_mode(layout::WhitespaceMode::Preserve);
expect_eq(e.whitespace_mode(), layout::WhitespaceMode::Preserve);

e.navigate(uri::Uri::parse("hax://example.com"));

e.set_whitespace_mode(layout::WhitespaceMode::Collapse);
expect_eq(e.whitespace_mode(), layout::WhitespaceMode::Collapse);

auto const *p = dom::nodes_by_xpath(*e.layout(), "/html/body/p").at(0);
auto text = p->children.at(0).children.at(0).layout_text; // anon block -> text
expect_eq(std::get<std::string_view>(text), "hello"sv);

e.set_whitespace_mode(layout::WhitespaceMode::Preserve);
expect_eq(e.whitespace_mode(), layout::WhitespaceMode::Preserve);

p = dom::nodes_by_xpath(*e.layout(), "/html/body/p").at(0);
text = p->children.at(0).children.at(0).layout_text; // anon block -> text
expect_eq(std::get<std::string_view>(text), " hello "sv);
});

return etest::run_all_tests();
}
6 changes: 2 additions & 4 deletions layout/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,13 @@ void layout(LayoutBox &box, geom::Rect const &bounds, int const root_font_size)

} // namespace

std::optional<LayoutBox> create_layout(style::StyledNode const &node, int width, WhitespaceMode ws_mode) {
std::optional<LayoutBox> create_layout(style::StyledNode const &node, int width) {
auto tree = create_tree(node);
if (!tree) {
return {};
}

if (ws_mode == WhitespaceMode::Collapse) {
collapse_whitespace(*tree);
}
collapse_whitespace(*tree);

layout(*tree, {0, 0, width, 0}, node.get_property<css::PropertyId::FontSize>());
return *tree;
Expand Down
9 changes: 1 addition & 8 deletions layout/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@

namespace layout {

// Being able to toggle this is a debug feature that will go away once both it
// and text wrapping are more ready.
enum class WhitespaceMode {
Preserve,
Collapse,
};

std::optional<LayoutBox> create_layout(style::StyledNode const &, int width, WhitespaceMode = WhitespaceMode::Collapse);
std::optional<LayoutBox> create_layout(style::StyledNode const &, int width);

} // namespace layout

Expand Down

0 comments on commit af2d34f

Please sign in to comment.