mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
LibCore: Make Core::Object::add<ChildType> return a ChildType&
Since the returned object is now owned by the callee object, we can simply vend a ChildType&. This allows us to use "." instead of "->" at the call site, which is quite nice. :^)
This commit is contained in:
parent
fb09b6a8ce
commit
028c011760
46 changed files with 1035 additions and 1039 deletions
|
@ -80,8 +80,8 @@ int main(int argc, char** argv)
|
|||
widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
widget.layout()->set_spacing(0);
|
||||
|
||||
auto toolbar = widget.add<GUI::ToolBar>();
|
||||
auto html_widget = widget.add<HtmlView>();
|
||||
auto& toolbar = widget.add<GUI::ToolBar>();
|
||||
auto& html_widget = widget.add<HtmlView>();
|
||||
|
||||
History<URL> history;
|
||||
|
||||
|
@ -99,70 +99,70 @@ int main(int argc, char** argv)
|
|||
history.go_back();
|
||||
update_actions();
|
||||
TemporaryChange<bool> change(should_push_loads_to_history, false);
|
||||
html_widget->load(history.current());
|
||||
html_widget.load(history.current());
|
||||
});
|
||||
|
||||
go_forward_action = GUI::CommonActions::make_go_forward_action([&](auto&) {
|
||||
history.go_forward();
|
||||
update_actions();
|
||||
TemporaryChange<bool> change(should_push_loads_to_history, false);
|
||||
html_widget->load(history.current());
|
||||
html_widget.load(history.current());
|
||||
});
|
||||
|
||||
toolbar->add_action(*go_back_action);
|
||||
toolbar->add_action(*go_forward_action);
|
||||
toolbar.add_action(*go_back_action);
|
||||
toolbar.add_action(*go_forward_action);
|
||||
|
||||
toolbar->add_action(GUI::CommonActions::make_go_home_action([&](auto&) {
|
||||
html_widget->load(home_url);
|
||||
toolbar.add_action(GUI::CommonActions::make_go_home_action([&](auto&) {
|
||||
html_widget.load(home_url);
|
||||
}));
|
||||
|
||||
toolbar->add_action(GUI::CommonActions::make_reload_action([&](auto&) {
|
||||
toolbar.add_action(GUI::CommonActions::make_reload_action([&](auto&) {
|
||||
TemporaryChange<bool> change(should_push_loads_to_history, false);
|
||||
html_widget->reload();
|
||||
html_widget.reload();
|
||||
}));
|
||||
|
||||
auto location_box = toolbar->add<GUI::TextBox>();
|
||||
auto& location_box = toolbar.add<GUI::TextBox>();
|
||||
|
||||
location_box->on_return_pressed = [&] {
|
||||
html_widget->load(location_box->text());
|
||||
location_box.on_return_pressed = [&] {
|
||||
html_widget.load(location_box.text());
|
||||
};
|
||||
|
||||
html_widget->on_load_start = [&](auto& url) {
|
||||
location_box->set_text(url.to_string());
|
||||
html_widget.on_load_start = [&](auto& url) {
|
||||
location_box.set_text(url.to_string());
|
||||
if (should_push_loads_to_history)
|
||||
history.push(url);
|
||||
update_actions();
|
||||
};
|
||||
|
||||
html_widget->on_link_click = [&](auto& url) {
|
||||
html_widget.on_link_click = [&](auto& url) {
|
||||
if (url.starts_with("#")) {
|
||||
html_widget->scroll_to_anchor(url.substring_view(1, url.length() - 1));
|
||||
html_widget.scroll_to_anchor(url.substring_view(1, url.length() - 1));
|
||||
} else {
|
||||
html_widget->load(html_widget->document()->complete_url(url));
|
||||
html_widget.load(html_widget.document()->complete_url(url));
|
||||
}
|
||||
};
|
||||
|
||||
html_widget->on_title_change = [&](auto& title) {
|
||||
html_widget.on_title_change = [&](auto& title) {
|
||||
window->set_title(String::format("%s - Browser", title.characters()));
|
||||
};
|
||||
|
||||
auto focus_location_box_action = GUI::Action::create("Focus location box", { Mod_Ctrl, Key_L }, [&](auto&) {
|
||||
location_box->select_all();
|
||||
location_box->set_focus(true);
|
||||
location_box.select_all();
|
||||
location_box.set_focus(true);
|
||||
});
|
||||
|
||||
auto statusbar = widget.add<GUI::StatusBar>();
|
||||
auto& statusbar = widget.add<GUI::StatusBar>();
|
||||
|
||||
html_widget->on_link_hover = [&](auto& href) {
|
||||
statusbar->set_text(href);
|
||||
html_widget.on_link_hover = [&](auto& href) {
|
||||
statusbar.set_text(href);
|
||||
};
|
||||
|
||||
ResourceLoader::the().on_load_counter_change = [&] {
|
||||
if (ResourceLoader::the().pending_loads() == 0) {
|
||||
statusbar->set_text("");
|
||||
statusbar.set_text("");
|
||||
return;
|
||||
}
|
||||
statusbar->set_text(String::format("Loading (%d pending resources...)", ResourceLoader::the().pending_loads()));
|
||||
statusbar.set_text(String::format("Loading (%d pending resources...)", ResourceLoader::the().pending_loads()));
|
||||
};
|
||||
|
||||
auto menubar = make<GUI::MenuBar>();
|
||||
|
@ -179,13 +179,13 @@ int main(int argc, char** argv)
|
|||
inspect_menu->add_action(GUI::Action::create("View source", { Mod_Ctrl, Key_U }, [&](auto&) {
|
||||
String filename_to_open;
|
||||
char tmp_filename[] = "/tmp/view-source.XXXXXX";
|
||||
ASSERT(html_widget->document());
|
||||
if (html_widget->document()->url().protocol() == "file") {
|
||||
filename_to_open = html_widget->document()->url().path();
|
||||
ASSERT(html_widget.document());
|
||||
if (html_widget.document()->url().protocol() == "file") {
|
||||
filename_to_open = html_widget.document()->url().path();
|
||||
} else {
|
||||
int fd = mkstemp(tmp_filename);
|
||||
ASSERT(fd >= 0);
|
||||
auto source = html_widget->document()->source();
|
||||
auto source = html_widget.document()->source();
|
||||
write(fd, source.characters(), source.length());
|
||||
close(fd);
|
||||
filename_to_open = tmp_filename;
|
||||
|
@ -203,7 +203,7 @@ int main(int argc, char** argv)
|
|||
dom_inspector_window->set_main_widget<InspectorWidget>();
|
||||
}
|
||||
auto* inspector_widget = static_cast<InspectorWidget*>(dom_inspector_window->main_widget());
|
||||
inspector_widget->set_document(html_widget->document());
|
||||
inspector_widget->set_document(html_widget.document());
|
||||
dom_inspector_window->show();
|
||||
dom_inspector_window->move_to_front();
|
||||
}));
|
||||
|
@ -211,21 +211,21 @@ int main(int argc, char** argv)
|
|||
|
||||
auto debug_menu = GUI::Menu::construct("Debug");
|
||||
debug_menu->add_action(GUI::Action::create("Dump DOM tree", [&](auto&) {
|
||||
dump_tree(*html_widget->document());
|
||||
dump_tree(*html_widget.document());
|
||||
}));
|
||||
debug_menu->add_action(GUI::Action::create("Dump Layout tree", [&](auto&) {
|
||||
dump_tree(*html_widget->document()->layout_node());
|
||||
dump_tree(*html_widget.document()->layout_node());
|
||||
}));
|
||||
debug_menu->add_action(GUI::Action::create("Dump Style sheets", [&](auto&) {
|
||||
for (auto& sheet : html_widget->document()->stylesheets()) {
|
||||
for (auto& sheet : html_widget.document()->stylesheets()) {
|
||||
dump_sheet(sheet);
|
||||
}
|
||||
}));
|
||||
debug_menu->add_separator();
|
||||
auto line_box_borders_action = GUI::Action::create("Line box borders", [&](auto& action) {
|
||||
action.set_checked(!action.is_checked());
|
||||
html_widget->set_should_show_line_box_borders(action.is_checked());
|
||||
html_widget->update();
|
||||
html_widget.set_should_show_line_box_borders(action.is_checked());
|
||||
html_widget.update();
|
||||
});
|
||||
line_box_borders_action->set_checkable(true);
|
||||
line_box_borders_action->set_checked(false);
|
||||
|
@ -253,7 +253,7 @@ int main(int argc, char** argv)
|
|||
url_to_load.set_path(app.args()[0]);
|
||||
}
|
||||
|
||||
html_widget->load(url_to_load);
|
||||
html_widget.load(url_to_load);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue