1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:47:34 +00:00

Everywhere: Replace Vector<T*> with nonnull entries with Vector<T&>

This commit is contained in:
Ali Mohammad Pur 2021-06-08 19:36:27 +04:30 committed by Andreas Kling
parent 3d94b5051d
commit 7ac196974d
22 changed files with 92 additions and 94 deletions

View file

@ -21,16 +21,16 @@ String CookieJar::get_cookie(const URL& url, Web::Cookie::Source source)
if (!domain.has_value()) if (!domain.has_value())
return {}; return {};
Vector<Web::Cookie::Cookie*> cookie_list = get_matching_cookies(url, domain.value(), source); auto cookie_list = get_matching_cookies(url, domain.value(), source);
StringBuilder builder; StringBuilder builder;
for (const auto* cookie : cookie_list) { for (const auto& cookie : cookie_list) {
// If there is an unprocessed cookie in the cookie-list, output the characters %x3B and %x20 ("; ") // If there is an unprocessed cookie in the cookie-list, output the characters %x3B and %x20 ("; ")
if (!builder.is_empty()) if (!builder.is_empty())
builder.append("; "); builder.append("; ");
// Output the cookie's name, the %x3D ("=") character, and the cookie's value. // Output the cookie's name, the %x3D ("=") character, and the cookie's value.
builder.appendff("{}={}", cookie->name, cookie->value); builder.appendff("{}={}", cookie.name, cookie.value);
} }
return builder.build(); return builder.build();
@ -238,14 +238,14 @@ void CookieJar::store_cookie(const Web::Cookie::ParsedCookie& parsed_cookie, con
m_cookies.set(key, move(cookie)); m_cookies.set(key, move(cookie));
} }
Vector<Web::Cookie::Cookie*> CookieJar::get_matching_cookies(const URL& url, const String& canonicalized_domain, Web::Cookie::Source source) Vector<Web::Cookie::Cookie&> CookieJar::get_matching_cookies(const URL& url, const String& canonicalized_domain, Web::Cookie::Source source)
{ {
// https://tools.ietf.org/html/rfc6265#section-5.4 // https://tools.ietf.org/html/rfc6265#section-5.4
auto now = Core::DateTime::now(); auto now = Core::DateTime::now();
// 1. Let cookie-list be the set of cookies from the cookie store that meets all of the following requirements: // 1. Let cookie-list be the set of cookies from the cookie store that meets all of the following requirements:
Vector<Web::Cookie::Cookie*> cookie_list; Vector<Web::Cookie::Cookie&> cookie_list;
for (auto& cookie : m_cookies) { for (auto& cookie : m_cookies) {
// Either: The cookie's host-only-flag is true and the canonicalized request-host is identical to the cookie's domain. // Either: The cookie's host-only-flag is true and the canonicalized request-host is identical to the cookie's domain.
@ -270,11 +270,11 @@ Vector<Web::Cookie::Cookie*> CookieJar::get_matching_cookies(const URL& url, con
// 2. The user agent SHOULD sort the cookie-list in the following order: // 2. The user agent SHOULD sort the cookie-list in the following order:
// - Cookies with longer paths are listed before cookies with shorter paths. // - Cookies with longer paths are listed before cookies with shorter paths.
// - Among cookies that have equal-length path fields, cookies with earlier creation-times are listed before cookies with later creation-times. // - Among cookies that have equal-length path fields, cookies with earlier creation-times are listed before cookies with later creation-times.
cookie_list.insert_before_matching(&cookie.value, [&cookie](auto* entry) { cookie_list.insert_before_matching(cookie.value, [&cookie](auto& entry) {
if (cookie.value.path.length() > entry->path.length()) { if (cookie.value.path.length() > entry.path.length()) {
return true; return true;
} else if (cookie.value.path.length() == entry->path.length()) { } else if (cookie.value.path.length() == entry.path.length()) {
if (cookie.value.creation_time.timestamp() < entry->creation_time.timestamp()) if (cookie.value.creation_time.timestamp() < entry.creation_time.timestamp())
return true; return true;
} }
return false; return false;

View file

@ -37,7 +37,7 @@ private:
static String default_path(const URL& url); static String default_path(const URL& url);
void store_cookie(const Web::Cookie::ParsedCookie& parsed_cookie, const URL& url, String canonicalized_domain, Web::Cookie::Source source); void store_cookie(const Web::Cookie::ParsedCookie& parsed_cookie, const URL& url, String canonicalized_domain, Web::Cookie::Source source);
Vector<Web::Cookie::Cookie*> get_matching_cookies(const URL& url, const String& canonicalized_domain, Web::Cookie::Source source); Vector<Web::Cookie::Cookie&> get_matching_cookies(const URL& url, const String& canonicalized_domain, Web::Cookie::Source source);
void purge_expired_cookies(); void purge_expired_cookies();
HashMap<CookieStorageKey, Web::Cookie::Cookie> m_cookies; HashMap<CookieStorageKey, Web::Cookie::Cookie> m_cookies;

View file

@ -136,9 +136,9 @@ void KeyboardMapperWidget::load_from_file(String filename)
m_character_map = result.value(); m_character_map = result.value();
set_current_map("map"); set_current_map("map");
for (Widget* widget : m_map_group->child_widgets()) { for (auto& widget : m_map_group->child_widgets()) {
auto radio_button = (GUI::RadioButton*)widget; auto& radio_button = static_cast<GUI::RadioButton&>(widget);
radio_button->set_checked(radio_button->name() == "map"); radio_button.set_checked(radio_button.name() == "map");
} }
update_window_title(); update_window_title();
@ -153,9 +153,9 @@ void KeyboardMapperWidget::load_from_system()
m_character_map = result.value().character_map_data(); m_character_map = result.value().character_map_data();
set_current_map("map"); set_current_map("map");
for (Widget* widget : m_map_group->child_widgets()) { for (auto& widget : m_map_group->child_widgets()) {
auto radio_button = (GUI::RadioButton*)widget; auto& radio_button = static_cast<GUI::RadioButton&>(widget);
radio_button->set_checked(radio_button->name() == "map"); radio_button.set_checked(radio_button.name() == "map");
} }
update_window_title(); update_window_title();

View file

@ -112,14 +112,14 @@ void CellTypeDialog::setup_tabs(GUI::TabWidget& tabs, const Vector<Position>& po
for (auto& type_name : CellType::names()) for (auto& type_name : CellType::names())
g_types.append(type_name); g_types.append(type_name);
Vector<Cell*> cells; Vector<Cell&> cells;
for (auto& position : positions) { for (auto& position : positions) {
if (auto cell = sheet.at(position)) if (auto cell = sheet.at(position))
cells.append(cell); cells.append(*cell);
} }
if (cells.size() == 1) { if (cells.size() == 1) {
auto& cell = *cells.first(); auto& cell = cells.first();
m_format = cell.type_metadata().format; m_format = cell.type_metadata().format;
m_length = cell.type_metadata().length; m_length = cell.type_metadata().length;
m_type = &cell.type(); m_type = &cell.type();

View file

@ -115,18 +115,18 @@ void Sheet::update()
return; return;
} }
m_visited_cells_in_update.clear(); m_visited_cells_in_update.clear();
Vector<Cell*> cells_copy; Vector<Cell&> cells_copy;
// Grab a copy as updates might insert cells into the table. // Grab a copy as updates might insert cells into the table.
for (auto& it : m_cells) { for (auto& it : m_cells) {
if (it.value->dirty()) { if (it.value->dirty()) {
cells_copy.append(it.value); cells_copy.append(*it.value);
m_workbook.set_dirty(true); m_workbook.set_dirty(true);
} }
} }
for (auto& cell : cells_copy) for (auto& cell : cells_copy)
update(*cell); update(cell);
m_visited_cells_in_update.clear(); m_visited_cells_in_update.clear();
} }

View file

@ -171,11 +171,11 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
m_current_cell_label->set_enabled(true); m_current_cell_label->set_enabled(true);
m_current_cell_label->set_text(builder.string_view()); m_current_cell_label->set_text(builder.string_view());
Vector<Cell*> cells; Vector<Cell&> cells;
for (auto& position : selection) for (auto& position : selection)
cells.append(&sheet.ensure(position)); cells.append(sheet.ensure(position));
auto first_cell = cells.first(); auto& first_cell = cells.first();
m_cell_value_editor->on_change = nullptr; m_cell_value_editor->on_change = nullptr;
m_cell_value_editor->set_text(""); m_cell_value_editor->set_text("");
m_should_change_selected_cells = false; m_should_change_selected_cells = false;
@ -191,14 +191,14 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
// FIXME: Lines? // FIXME: Lines?
auto offset = m_cell_value_editor->cursor().column(); auto offset = m_cell_value_editor->cursor().column();
try_generate_tip_for_input_expression(text, offset); try_generate_tip_for_input_expression(text, offset);
for (auto* cell : cells) for (auto& cell : cells)
cell->set_data(text); cell.set_data(text);
sheet.update(); sheet.update();
update(); update();
} }
}; };
m_cell_value_editor->set_enabled(true); m_cell_value_editor->set_enabled(true);
static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(first_cell); static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(&first_cell);
}; };
m_selected_view->on_selection_dropped = [&]() { m_selected_view->on_selection_dropped = [&]() {
m_cell_value_editor->set_enabled(false); m_cell_value_editor->set_enabled(false);

View file

@ -663,7 +663,7 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab()
cpu_graph_group_box.set_layout<GUI::HorizontalBoxLayout>(); cpu_graph_group_box.set_layout<GUI::HorizontalBoxLayout>();
cpu_graph_group_box.layout()->set_margins({ 6, 16, 6, 6 }); cpu_graph_group_box.layout()->set_margins({ 6, 16, 6, 6 });
cpu_graph_group_box.set_fixed_height(120); cpu_graph_group_box.set_fixed_height(120);
Vector<GraphWidget*> cpu_graphs; Vector<GraphWidget&> cpu_graphs;
for (size_t i = 0; i < ProcessModel::the().cpus().size(); i++) { for (size_t i = 0; i < ProcessModel::the().cpus().size(); i++) {
auto& cpu_graph = cpu_graph_group_box.add<GraphWidget>(); auto& cpu_graph = cpu_graph_group_box.add<GraphWidget>();
cpu_graph.set_max(100); cpu_graph.set_max(100);
@ -679,12 +679,12 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab()
return String::formatted("Kernel: {}%", value); return String::formatted("Kernel: {}%", value);
}, },
}); });
cpu_graphs.append(&cpu_graph); cpu_graphs.append(cpu_graph);
} }
ProcessModel::the().on_cpu_info_change = [cpu_graphs](const NonnullOwnPtrVector<ProcessModel::CpuInfo>& cpus) { ProcessModel::the().on_cpu_info_change = [cpu_graphs](const NonnullOwnPtrVector<ProcessModel::CpuInfo>& cpus) {
float sum_cpu = 0; float sum_cpu = 0;
for (size_t i = 0; i < cpus.size(); ++i) { for (size_t i = 0; i < cpus.size(); ++i) {
cpu_graphs[i]->add_value({ (int)cpus[i].total_cpu_percent, (int)cpus[i].total_cpu_percent_kernel }); cpu_graphs[i].add_value({ (int)cpus[i].total_cpu_percent, (int)cpus[i].total_cpu_percent_kernel });
sum_cpu += cpus[i].total_cpu_percent; sum_cpu += cpus[i].total_cpu_percent;
} }
float cpu_usage = sum_cpu / (float)cpus.size(); float cpu_usage = sum_cpu / (float)cpus.size();

View file

@ -489,17 +489,17 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_next_editor_action
return GUI::Action::create("Switch to &Next Editor", { Mod_Ctrl, Key_E }, [this](auto&) { return GUI::Action::create("Switch to &Next Editor", { Mod_Ctrl, Key_E }, [this](auto&) {
if (m_all_editor_wrappers.size() <= 1) if (m_all_editor_wrappers.size() <= 1)
return; return;
Vector<EditorWrapper*> wrappers; Vector<EditorWrapper&> wrappers;
m_editors_splitter->for_each_child_of_type<EditorWrapper>([this, &wrappers](auto& child) { m_editors_splitter->for_each_child_of_type<EditorWrapper>([this, &wrappers](auto& child) {
wrappers.append(&child); wrappers.append(child);
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
for (size_t i = 0; i < wrappers.size(); ++i) { for (size_t i = 0; i < wrappers.size(); ++i) {
if (m_current_editor_wrapper.ptr() == wrappers[i]) { if (m_current_editor_wrapper.ptr() == &wrappers[i]) {
if (i == wrappers.size() - 1) if (i == wrappers.size() - 1)
wrappers[0]->editor().set_focus(true); wrappers[0].editor().set_focus(true);
else else
wrappers[i + 1]->editor().set_focus(true); wrappers[i + 1].editor().set_focus(true);
} }
} }
}); });
@ -510,17 +510,17 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_previous_editor_ac
return GUI::Action::create("Switch to &Previous Editor", { Mod_Ctrl | Mod_Shift, Key_E }, [this](auto&) { return GUI::Action::create("Switch to &Previous Editor", { Mod_Ctrl | Mod_Shift, Key_E }, [this](auto&) {
if (m_all_editor_wrappers.size() <= 1) if (m_all_editor_wrappers.size() <= 1)
return; return;
Vector<EditorWrapper*> wrappers; Vector<EditorWrapper&> wrappers;
m_editors_splitter->for_each_child_of_type<EditorWrapper>([this, &wrappers](auto& child) { m_editors_splitter->for_each_child_of_type<EditorWrapper>([this, &wrappers](auto& child) {
wrappers.append(&child); wrappers.append(child);
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
for (int i = wrappers.size() - 1; i >= 0; --i) { for (int i = wrappers.size() - 1; i >= 0; --i) {
if (m_current_editor_wrapper.ptr() == wrappers[i]) { if (m_current_editor_wrapper.ptr() == &wrappers[i]) {
if (i == 0) if (i == 0)
wrappers.last()->editor().set_focus(true); wrappers.last().editor().set_focus(true);
else else
wrappers[i - 1]->editor().set_focus(true); wrappers[i - 1].editor().set_focus(true);
} }
} }
}); });

View file

@ -58,7 +58,7 @@ struct EventLoop::Private {
}; };
static EventLoop* s_main_event_loop; static EventLoop* s_main_event_loop;
static Vector<EventLoop*>* s_event_loop_stack; static Vector<EventLoop&>* s_event_loop_stack;
static NeverDestroyed<IDAllocator> s_id_allocator; static NeverDestroyed<IDAllocator> s_id_allocator;
static HashMap<int, NonnullOwnPtr<EventLoopTimer>>* s_timers; static HashMap<int, NonnullOwnPtr<EventLoopTimer>>* s_timers;
static HashTable<Notifier*>* s_notifiers; static HashTable<Notifier*>* s_notifiers;
@ -257,7 +257,7 @@ EventLoop::EventLoop([[maybe_unused]] MakeInspectable make_inspectable)
: m_private(make<Private>()) : m_private(make<Private>())
{ {
if (!s_event_loop_stack) { if (!s_event_loop_stack) {
s_event_loop_stack = new Vector<EventLoop*>; s_event_loop_stack = new Vector<EventLoop&>;
s_timers = new HashMap<int, NonnullOwnPtr<EventLoopTimer>>; s_timers = new HashMap<int, NonnullOwnPtr<EventLoopTimer>>;
s_notifiers = new HashTable<Notifier*>; s_notifiers = new HashTable<Notifier*>;
} }
@ -274,7 +274,7 @@ EventLoop::EventLoop([[maybe_unused]] MakeInspectable make_inspectable)
#endif #endif
VERIFY(rc == 0); VERIFY(rc == 0);
s_event_loop_stack->append(this); s_event_loop_stack->append(*this);
#ifdef __serenity__ #ifdef __serenity__
if (getuid() != 0 if (getuid() != 0
@ -314,9 +314,7 @@ EventLoop& EventLoop::main()
EventLoop& EventLoop::current() EventLoop& EventLoop::current()
{ {
EventLoop* event_loop = s_event_loop_stack->last(); return s_event_loop_stack->last();
VERIFY(event_loop != nullptr);
return *event_loop;
} }
void EventLoop::quit(int code) void EventLoop::quit(int code)
@ -340,7 +338,7 @@ public:
{ {
if (&m_event_loop != s_main_event_loop) { if (&m_event_loop != s_main_event_loop) {
m_event_loop.take_pending_events_from(EventLoop::current()); m_event_loop.take_pending_events_from(EventLoop::current());
s_event_loop_stack->append(&event_loop); s_event_loop_stack->append(event_loop);
} }
} }
~EventLoopPusher() ~EventLoopPusher()

View file

@ -362,8 +362,8 @@ void ColorPicker::create_color_button(Widget& container, unsigned rgb)
auto& widget = container.add<ColorButton>(*this, color); auto& widget = container.add<ColorButton>(*this, color);
widget.on_click = [this](Color color) { widget.on_click = [this](Color color) {
for (auto& value : m_color_widgets) { for (auto& value : m_color_widgets) {
value->set_selected(false); value.set_selected(false);
value->update(); value.update();
} }
m_color = color; m_color = color;
@ -375,7 +375,7 @@ void ColorPicker::create_color_button(Widget& container, unsigned rgb)
widget.set_selected(true); widget.set_selected(true);
} }
m_color_widgets.append(&widget); m_color_widgets.append(widget);
} }
ColorButton::ColorButton(ColorPicker& picker, Color color) ColorButton::ColorButton(ColorPicker& picker, Color color)

View file

@ -37,7 +37,7 @@ private:
Color m_color; Color m_color;
bool m_color_has_alpha_channel { true }; bool m_color_has_alpha_channel { true };
Vector<ColorButton*> m_color_widgets; Vector<ColorButton&> m_color_widgets;
RefPtr<CustomColorWidget> m_custom_color; RefPtr<CustomColorWidget> m_custom_color;
RefPtr<ColorPreview> m_preview_widget; RefPtr<ColorPreview> m_preview_widget;
RefPtr<TextBox> m_html_text; RefPtr<TextBox> m_html_text;

View file

@ -155,7 +155,7 @@ void Splitter::recompute_grabbables()
m_hovered_index = {}; m_hovered_index = {};
auto child_widgets = this->child_widgets(); auto child_widgets = this->child_widgets();
child_widgets.remove_all_matching([&](auto& widget) { return !widget->is_visible(); }); child_widgets.remove_all_matching([&](auto& widget) { return !widget.is_visible(); });
if (child_widgets.size() < 2) if (child_widgets.size() < 2)
return; return;
@ -164,8 +164,8 @@ void Splitter::recompute_grabbables()
size_t end_index = 1; size_t end_index = 1;
while (end_index < child_widgets.size()) { while (end_index < child_widgets.size()) {
auto const& first_widget = *child_widgets[start_index]; auto const& first_widget = child_widgets[start_index];
auto const& second_widget = *child_widgets[end_index]; auto const& second_widget = child_widgets[end_index];
m_grabbables.append(Grabbable { m_grabbables.append(Grabbable {
.index = m_grabbables.size(), .index = m_grabbables.size(),
.grabbable_rect = rect_between_widgets(first_widget, second_widget, true), .grabbable_rect = rect_between_widgets(first_widget, second_widget, true),

View file

@ -851,14 +851,14 @@ void Widget::focus_previous_widget(FocusSource source, bool siblings_only)
{ {
auto focusable_widgets = window()->focusable_widgets(source); auto focusable_widgets = window()->focusable_widgets(source);
if (siblings_only) if (siblings_only)
focusable_widgets.remove_all_matching([this](auto& entry) { return entry->parent() != parent(); }); focusable_widgets.remove_all_matching([this](auto& entry) { return entry.parent() != parent(); });
for (int i = focusable_widgets.size() - 1; i >= 0; --i) { for (int i = focusable_widgets.size() - 1; i >= 0; --i) {
if (focusable_widgets[i] != this) if (&focusable_widgets[i] != this)
continue; continue;
if (i > 0) if (i > 0)
focusable_widgets[i - 1]->set_focus(true, source); focusable_widgets[i - 1].set_focus(true, source);
else else
focusable_widgets.last()->set_focus(true, source); focusable_widgets.last().set_focus(true, source);
} }
} }
@ -866,24 +866,24 @@ void Widget::focus_next_widget(FocusSource source, bool siblings_only)
{ {
auto focusable_widgets = window()->focusable_widgets(source); auto focusable_widgets = window()->focusable_widgets(source);
if (siblings_only) if (siblings_only)
focusable_widgets.remove_all_matching([this](auto& entry) { return entry->parent() != parent(); }); focusable_widgets.remove_all_matching([this](auto& entry) { return entry.parent() != parent(); });
for (size_t i = 0; i < focusable_widgets.size(); ++i) { for (size_t i = 0; i < focusable_widgets.size(); ++i) {
if (focusable_widgets[i] != this) if (&focusable_widgets[i] != this)
continue; continue;
if (i < focusable_widgets.size() - 1) if (i < focusable_widgets.size() - 1)
focusable_widgets[i + 1]->set_focus(true, source); focusable_widgets[i + 1].set_focus(true, source);
else else
focusable_widgets.first()->set_focus(true, source); focusable_widgets.first().set_focus(true, source);
} }
} }
Vector<Widget*> Widget::child_widgets() const Vector<Widget&> Widget::child_widgets() const
{ {
Vector<Widget*> widgets; Vector<Widget&> widgets;
widgets.ensure_capacity(children().size()); widgets.ensure_capacity(children().size());
for (auto& child : const_cast<Widget*>(this)->children()) { for (auto& child : const_cast<Widget*>(this)->children()) {
if (is<Widget>(child)) if (is<Widget>(child))
widgets.append(static_cast<Widget*>(&child)); widgets.append(static_cast<Widget&>(child));
} }
return widgets; return widgets;
} }

View file

@ -250,7 +250,7 @@ public:
}); });
} }
Vector<Widget*> child_widgets() const; Vector<Widget&> child_widgets() const;
void do_layout(); void do_layout();

View file

@ -843,13 +843,13 @@ void Window::start_interactive_resize()
WindowServerConnection::the().async_start_window_resize(m_window_id); WindowServerConnection::the().async_start_window_resize(m_window_id);
} }
Vector<Widget*> Window::focusable_widgets(FocusSource source) const Vector<Widget&> Window::focusable_widgets(FocusSource source) const
{ {
if (!m_main_widget) if (!m_main_widget)
return {}; return {};
HashTable<Widget*> seen_widgets; HashTable<Widget*> seen_widgets;
Vector<Widget*> collected_widgets; Vector<Widget&> collected_widgets;
Function<void(Widget&)> collect_focusable_widgets = [&](auto& widget) { Function<void(Widget&)> collect_focusable_widgets = [&](auto& widget) {
bool widget_accepts_focus = false; bool widget_accepts_focus = false;
@ -868,7 +868,7 @@ Vector<Widget*> Window::focusable_widgets(FocusSource source) const
if (widget_accepts_focus) { if (widget_accepts_focus) {
auto& effective_focus_widget = widget.focus_proxy() ? *widget.focus_proxy() : widget; auto& effective_focus_widget = widget.focus_proxy() ? *widget.focus_proxy() : widget;
if (seen_widgets.set(&effective_focus_widget) == AK::HashSetResult::InsertedNewEntry) if (seen_widgets.set(&effective_focus_widget) == AK::HashSetResult::InsertedNewEntry)
collected_widgets.append(&effective_focus_widget); collected_widgets.append(effective_focus_widget);
} }
widget.for_each_child_widget([&](auto& child) { widget.for_each_child_widget([&](auto& child) {
if (!child.is_visible()) if (!child.is_visible())
@ -1056,7 +1056,7 @@ void Window::focus_a_widget_if_possible(FocusSource source)
{ {
auto focusable_widgets = this->focusable_widgets(source); auto focusable_widgets = this->focusable_widgets(source);
if (!focusable_widgets.is_empty()) if (!focusable_widgets.is_empty())
set_focused_widget(focusable_widgets[0], source); set_focused_widget(&focusable_widgets[0], source);
} }
void Window::did_disable_focused_widget(Badge<Widget>) void Window::did_disable_focused_widget(Badge<Widget>)

View file

@ -172,7 +172,7 @@ public:
void apply_icon(); void apply_icon();
const Gfx::Bitmap* icon() const { return m_icon.ptr(); } const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
Vector<Widget*> focusable_widgets(FocusSource) const; Vector<Widget&> focusable_widgets(FocusSource) const;
void schedule_relayout(); void schedule_relayout();

View file

@ -228,7 +228,7 @@ ByteBuffer TLSv12::build_certificate()
{ {
PacketBuilder builder { MessageType::Handshake, m_context.options.version }; PacketBuilder builder { MessageType::Handshake, m_context.options.version };
Vector<const Certificate*> certificates; Vector<Certificate const&> certificates;
Vector<Certificate>* local_certificates = nullptr; Vector<Certificate>* local_certificates = nullptr;
if (m_context.is_server) { if (m_context.is_server) {
@ -250,7 +250,7 @@ ByteBuffer TLSv12::build_certificate()
// FIXME: Check for and respond with only the requested certificate types. // FIXME: Check for and respond with only the requested certificate types.
if (true) { if (true) {
certificates.append(&certificate); certificates.append(certificate);
} }
} }
} }
@ -266,9 +266,9 @@ ByteBuffer TLSv12::build_certificate()
builder.append_u24(total_certificate_size); builder.append_u24(total_certificate_size);
for (auto& certificate : certificates) { for (auto& certificate : certificates) {
if (!certificate->der.is_empty()) { if (!certificate.der.is_empty()) {
builder.append_u24(certificate->der.size()); builder.append_u24(certificate.der.size());
builder.append(certificate->der.bytes()); builder.append(certificate.der.bytes());
} }
} }
} }

View file

@ -227,34 +227,34 @@ void MenuManager::close_everyone()
void MenuManager::close_everyone_not_in_lineage(Menu& menu) void MenuManager::close_everyone_not_in_lineage(Menu& menu)
{ {
Vector<Menu*> menus_to_close; Vector<Menu&> menus_to_close;
for (auto& open_menu : m_open_menu_stack) { for (auto& open_menu : m_open_menu_stack) {
if (!open_menu) if (!open_menu)
continue; continue;
if (&menu == open_menu.ptr() || open_menu->is_menu_ancestor_of(menu)) if (&menu == open_menu.ptr() || open_menu->is_menu_ancestor_of(menu))
continue; continue;
menus_to_close.append(open_menu); menus_to_close.append(*open_menu);
} }
close_menus(menus_to_close); close_menus(menus_to_close);
} }
void MenuManager::close_menus(const Vector<Menu*>& menus) void MenuManager::close_menus(const Vector<Menu&>& menus)
{ {
for (auto& menu : menus) { for (auto& menu : menus) {
if (menu == m_current_menu) if (&menu == m_current_menu)
clear_current_menu(); clear_current_menu();
menu->set_visible(false); menu.set_visible(false);
menu->clear_hovered_item(); menu.clear_hovered_item();
m_open_menu_stack.remove_first_matching([&](auto& entry) { m_open_menu_stack.remove_first_matching([&](auto& entry) {
return entry == menu; return entry == &menu;
}); });
} }
refresh(); refresh();
} }
static void collect_menu_subtree(Menu& menu, Vector<Menu*>& menus) static void collect_menu_subtree(Menu& menu, Vector<Menu&>& menus)
{ {
menus.append(&menu); menus.append(menu);
for (size_t i = 0; i < menu.item_count(); ++i) { for (size_t i = 0; i < menu.item_count(); ++i) {
auto& item = menu.item(i); auto& item = menu.item(i);
if (!item.is_submenu()) if (!item.is_submenu())
@ -265,7 +265,7 @@ static void collect_menu_subtree(Menu& menu, Vector<Menu*>& menus)
void MenuManager::close_menu_and_descendants(Menu& menu) void MenuManager::close_menu_and_descendants(Menu& menu)
{ {
Vector<Menu*> menus_to_close; Vector<Menu&> menus_to_close;
collect_menu_subtree(menu, menus_to_close); collect_menu_subtree(menu, menus_to_close);
close_menus(menus_to_close); close_menus(menus_to_close);
} }

View file

@ -50,7 +50,7 @@ public:
Menu* hovered_menu() { return m_hovered_menu; } Menu* hovered_menu() { return m_hovered_menu; }
private: private:
void close_menus(const Vector<Menu*>&); void close_menus(const Vector<Menu&>&);
virtual void event(Core::Event&) override; virtual void event(Core::Event&) override;
void handle_mouse_event(MouseEvent&); void handle_mouse_event(MouseEvent&);

View file

@ -21,7 +21,7 @@ Menubar::~Menubar()
void Menubar::add_menu(Menu& menu) void Menubar::add_menu(Menu& menu)
{ {
m_menus.append(&menu); m_menus.append(menu);
} }
} }

View file

@ -29,7 +29,7 @@ public:
void for_each_menu(Callback callback) void for_each_menu(Callback callback)
{ {
for (auto& menu : m_menus) { for (auto& menu : m_menus) {
if (callback(*menu) == IterationDecision::Break) if (callback(menu) == IterationDecision::Break)
return; return;
} }
} }
@ -39,7 +39,7 @@ private:
ClientConnection& m_client; ClientConnection& m_client;
int m_menubar_id { 0 }; int m_menubar_id { 0 };
Vector<Menu*> m_menus; Vector<Menu&> m_menus;
}; };
} }

View file

@ -200,19 +200,19 @@ public:
{ {
auto* blocking_modal_window = window.blocking_modal_window(); auto* blocking_modal_window = window.blocking_modal_window();
if (blocking_modal_window || window.is_modal()) { if (blocking_modal_window || window.is_modal()) {
Vector<Window*> modal_stack; Vector<Window&> modal_stack;
auto* modal_stack_top = blocking_modal_window ? blocking_modal_window : &window; auto* modal_stack_top = blocking_modal_window ? blocking_modal_window : &window;
for (auto* parent = modal_stack_top->parent_window(); parent; parent = parent->parent_window()) { for (auto* parent = modal_stack_top->parent_window(); parent; parent = parent->parent_window()) {
auto* blocked_by = parent->blocking_modal_window(); auto* blocked_by = parent->blocking_modal_window();
if (!blocked_by || (blocked_by != modal_stack_top && !modal_stack_top->is_descendant_of(*blocked_by))) if (!blocked_by || (blocked_by != modal_stack_top && !modal_stack_top->is_descendant_of(*blocked_by)))
break; break;
modal_stack.append(parent); modal_stack.append(*parent);
if (!parent->is_modal()) if (!parent->is_modal())
break; break;
} }
if (!modal_stack.is_empty()) { if (!modal_stack.is_empty()) {
for (size_t i = modal_stack.size(); i > 0; i--) { for (size_t i = modal_stack.size(); i > 0; i--) {
IterationDecision decision = f(*modal_stack[i - 1], false); IterationDecision decision = f(modal_stack[i - 1], false);
if (decision != IterationDecision::Continue) if (decision != IterationDecision::Continue)
return decision; return decision;
} }