diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp index 55249e4803..1cf8b287f4 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -362,8 +362,8 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::top_getter) if (!this_browsing_context) return JS::js_null(); - VERIFY(this_browsing_context->top_level_browsing_context().document()); - auto& top_window = this_browsing_context->top_level_browsing_context().document()->window(); + VERIFY(this_browsing_context->top_level_browsing_context().active_document()); + auto& top_window = this_browsing_context->top_level_browsing_context().active_document()->window(); return top_window.wrapper(); } @@ -379,8 +379,8 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::parent_getter) return JS::js_null(); if (this_browsing_context->parent()) { - VERIFY(this_browsing_context->parent()->document()); - auto& parent_window = this_browsing_context->parent()->document()->window(); + VERIFY(this_browsing_context->parent()->active_document()); + auto& parent_window = this_browsing_context->parent()->active_document()->window(); return parent_window.wrapper(); } VERIFY(this_browsing_context == &this_browsing_context->top_level_browsing_context()); diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp index c4e4d0afd1..ea276329c8 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContextContainer.cpp @@ -35,9 +35,9 @@ void BrowsingContextContainer::inserted() Origin BrowsingContextContainer::content_origin() const { - if (!m_nested_browsing_context || !m_nested_browsing_context->document()) + if (!m_nested_browsing_context || !m_nested_browsing_context->active_document()) return {}; - return m_nested_browsing_context->document()->origin(); + return m_nested_browsing_context->active_document()->origin(); } bool BrowsingContextContainer::may_access_from_origin(const Origin& origin) const @@ -47,7 +47,7 @@ bool BrowsingContextContainer::may_access_from_origin(const Origin& origin) cons const DOM::Document* BrowsingContextContainer::content_document() const { - return m_nested_browsing_context ? m_nested_browsing_context->document() : nullptr; + return m_nested_browsing_context ? m_nested_browsing_context->active_document() : nullptr; } void BrowsingContextContainer::nested_browsing_context_did_load(Badge) diff --git a/Userland/Libraries/LibWeb/InProcessWebView.cpp b/Userland/Libraries/LibWeb/InProcessWebView.cpp index 771b386145..f40e19a3e7 100644 --- a/Userland/Libraries/LibWeb/InProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/InProcessWebView.cpp @@ -278,9 +278,9 @@ void InProcessWebView::keydown_event(GUI::KeyEvent& event) URL InProcessWebView::url() const { - if (!page().top_level_browsing_context().document()) + if (!page().top_level_browsing_context().active_document()) return {}; - return page().top_level_browsing_context().document()->url(); + return page().top_level_browsing_context().active_document()->url(); } void InProcessWebView::reload() @@ -319,22 +319,22 @@ void InProcessWebView::page_did_request_scroll_into_view(const Gfx::IntRect& rec void InProcessWebView::load_empty_document() { - page().top_level_browsing_context().set_document(nullptr); + page().top_level_browsing_context().set_active_document(nullptr); } DOM::Document* InProcessWebView::document() { - return page().top_level_browsing_context().document(); + return page().top_level_browsing_context().active_document(); } const DOM::Document* InProcessWebView::document() const { - return page().top_level_browsing_context().document(); + return page().top_level_browsing_context().active_document(); } void InProcessWebView::set_document(DOM::Document* document) { - page().top_level_browsing_context().set_document(document); + page().top_level_browsing_context().set_active_document(document); } void InProcessWebView::did_scroll() diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index d19aa12da1..c4f47c723e 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -213,7 +213,7 @@ void FrameLoader::load_html(const StringView& html, const URL& url) auto document = DOM::Document::create(url); HTML::HTMLDocumentParser parser(document, html, "utf-8"); parser.run(url); - browsing_context().set_document(&parser.document()); + browsing_context().set_active_document(&parser.document()); } // FIXME: Use an actual templating engine (our own one when it's built, preferably @@ -233,7 +233,7 @@ void FrameLoader::load_error_page(const URL& failed_url, const String& error) generator.append(data); auto document = HTML::parse_html_document(generator.as_string_view(), failed_url, "utf-8"); VERIFY(document); - browsing_context().set_document(document); + browsing_context().set_active_document(document); }, [](auto& error, auto) { dbgln("Failed to load error page: {}", error); @@ -285,7 +285,7 @@ void FrameLoader::resource_did_load() document->set_encoding(resource()->encoding()); document->set_content_type(resource()->mime_type()); - browsing_context().set_document(document); + browsing_context().set_active_document(document); if (!parse_document(*document, resource()->encoded_data())) { load_error_page(url, "Failed to parse content."); diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp index 9fd86901ad..a46f13cc07 100644 --- a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp @@ -66,26 +66,26 @@ bool BrowsingContext::is_focused_context() const return m_page && &m_page->focused_context() == this; } -void BrowsingContext::set_document(DOM::Document* document) +void BrowsingContext::set_active_document(DOM::Document* document) { - if (m_document == document) + if (m_active_document == document) return; m_cursor_position = {}; - if (m_document) - m_document->detach_from_browsing_context({}, *this); + if (m_active_document) + m_active_document->detach_from_browsing_context({}, *this); - m_document = document; + m_active_document = document; - if (m_document) { - m_document->attach_to_browsing_context({}, *this); + if (m_active_document) { + m_active_document->attach_to_browsing_context({}, *this); if (m_page && is_top_level()) - m_page->client().page_did_change_title(m_document->title()); + m_page->client().page_did_change_title(m_active_document->title()); } if (m_page) - m_page->client().page_did_set_document_in_top_level_browsing_context(m_document); + m_page->client().page_did_set_document_in_top_level_browsing_context(m_active_document); } void BrowsingContext::set_viewport_rect(Gfx::IntRect const& rect) @@ -94,9 +94,9 @@ void BrowsingContext::set_viewport_rect(Gfx::IntRect const& rect) if (m_size != rect.size()) { m_size = rect.size(); - if (m_document) { - m_document->window().dispatch_event(DOM::Event::create(UIEvents::EventNames::resize)); - m_document->update_layout(); + if (active_document()) { + active_document()->window().dispatch_event(DOM::Event::create(UIEvents::EventNames::resize)); + active_document()->update_layout(); } did_change = true; } @@ -117,9 +117,9 @@ void BrowsingContext::set_size(Gfx::IntSize const& size) if (m_size == size) return; m_size = size; - if (m_document) { - m_document->window().dispatch_event(DOM::Event::create(UIEvents::EventNames::resize)); - m_document->update_layout(); + if (active_document()) { + active_document()->window().dispatch_event(DOM::Event::create(UIEvents::EventNames::resize)); + active_document()->update_layout(); } for (auto* client : m_viewport_clients) @@ -153,12 +153,12 @@ void BrowsingContext::set_needs_display(Gfx::IntRect const& rect) void BrowsingContext::scroll_to_anchor(String const& fragment) { - if (!document()) + if (!active_document()) return; - auto element = document()->get_element_by_id(fragment); + auto element = active_document()->get_element_by_id(fragment); if (!element) { - auto candidates = document()->get_elements_by_name(fragment); + auto candidates = active_document()->get_elements_by_name(fragment); for (auto& candidate : candidates->collect_matching_elements()) { if (is(*candidate)) { element = verify_cast(*candidate); @@ -168,7 +168,7 @@ void BrowsingContext::scroll_to_anchor(String const& fragment) } // FIXME: This is overly aggressive and should be something more like a "update_layout_if_needed()" - document()->force_layout(); + active_document()->force_layout(); if (!element || !element->layout_node()) return; @@ -227,9 +227,9 @@ void BrowsingContext::set_cursor_position(DOM::Position position) String BrowsingContext::selected_text() const { StringBuilder builder; - if (!m_document) + if (!active_document()) return {}; - auto* layout_root = m_document->layout_node(); + auto* layout_root = active_document()->layout_node(); if (!layout_root) return {}; if (!layout_root->selection().is_valid()) @@ -273,9 +273,9 @@ String BrowsingContext::selected_text() const void BrowsingContext::select_all() { - if (!m_document) + if (!active_document()) return; - auto* layout_root = m_document->layout_node(); + auto* layout_root = active_document()->layout_node(); if (!layout_root) return; diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.h b/Userland/Libraries/LibWeb/Page/BrowsingContext.h index 80acd890f8..507932634d 100644 --- a/Userland/Libraries/LibWeb/Page/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.h @@ -39,10 +39,10 @@ public: bool is_top_level() const { return this == &top_level_browsing_context(); } bool is_focused_context() const; - DOM::Document const* document() const { return m_document; } - DOM::Document* document() { return m_document; } + DOM::Document const* active_document() const { return m_active_document; } + DOM::Document* active_document() { return m_active_document; } - void set_document(DOM::Document*); + void set_active_document(DOM::Document*); Page* page() { return m_page; } Page const* page() const { return m_page; } @@ -111,7 +111,7 @@ private: EventHandler m_event_handler; WeakPtr m_container; - RefPtr m_document; + RefPtr m_active_document; Gfx::IntSize m_size; Gfx::IntPoint m_viewport_scroll_offset; diff --git a/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp b/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp index 60d421196c..f636f7cbf7 100644 --- a/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp @@ -92,7 +92,7 @@ void EditEventHandler::handle_delete(DOM::Range& range) // FIXME: When nodes are removed from the DOM, the associated layout nodes become stale and still // remain in the layout tree. This has to be fixed, this just causes everything to be recomputed // which really hurts performance. - m_frame.document()->force_layout(); + m_frame.active_document()->force_layout(); m_frame.did_edit({}); } @@ -114,7 +114,7 @@ void EditEventHandler::handle_insert(DOM::Position position, u32 code_point) // FIXME: When nodes are removed from the DOM, the associated layout nodes become stale and still // remain in the layout tree. This has to be fixed, this just causes everything to be recomputed // which really hurts performance. - m_frame.document()->force_layout(); + m_frame.active_document()->force_layout(); m_frame.did_edit({}); } diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 6b970b9ebb..a2da6c10b3 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -99,16 +99,16 @@ EventHandler::~EventHandler() const Layout::InitialContainingBlock* EventHandler::layout_root() const { - if (!m_frame.document()) + if (!m_frame.active_document()) return nullptr; - return m_frame.document()->layout_node(); + return m_frame.active_document()->layout_node(); } Layout::InitialContainingBlock* EventHandler::layout_root() { - if (!m_frame.document()) + if (!m_frame.active_document()) return nullptr; - return m_frame.document()->layout_node(); + return m_frame.active_document()->layout_node(); } bool EventHandler::handle_mousewheel(const Gfx::IntPoint& position, unsigned int buttons, unsigned int modifiers, int wheel_delta) @@ -182,7 +182,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt return true; } - NonnullRefPtr document = *m_frame.document(); + NonnullRefPtr document = *m_frame.active_document(); RefPtr node; { @@ -279,7 +279,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt return true; } - auto& document = *m_frame.document(); + auto& document = *m_frame.active_document(); bool hovered_node_changed = false; bool is_hovering_link = false; @@ -356,13 +356,13 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt bool EventHandler::focus_next_element() { - if (!m_frame.document()) + if (!m_frame.active_document()) return false; - auto* element = m_frame.document()->focused_element(); + auto* element = m_frame.active_document()->focused_element(); if (!element) { - element = m_frame.document()->first_child_of_type(); + element = m_frame.active_document()->first_child_of_type(); if (element && element->is_focusable()) { - m_frame.document()->set_focused_element(element); + m_frame.active_document()->set_focused_element(element); return true; } } @@ -370,7 +370,7 @@ bool EventHandler::focus_next_element() for (element = element->next_element_in_pre_order(); element && !element->is_focusable(); element = element->next_element_in_pre_order()) ; - m_frame.document()->set_focused_element(element); + m_frame.active_document()->set_focused_element(element); return element; } @@ -398,7 +398,7 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin if (layout_root()->selection().is_valid()) { auto range = layout_root()->selection().to_dom_range()->normalized(); if (range->start_container()->is_editable()) { - m_frame.document()->layout_node()->set_selection({}); + m_frame.active_document()->layout_node()->set_selection({}); // FIXME: This doesn't work for some reason? m_frame.set_cursor_position({ *range->start_container(), range->start_offset() }); diff --git a/Userland/Services/WebContent/ClientConnection.cpp b/Userland/Services/WebContent/ClientConnection.cpp index edc9c05fea..6c3b708d86 100644 --- a/Userland/Services/WebContent/ClientConnection.cpp +++ b/Userland/Services/WebContent/ClientConnection.cpp @@ -171,19 +171,19 @@ void ClientConnection::key_down(i32 key, unsigned int modifiers, u32 code_point) void ClientConnection::debug_request(const String& request, const String& argument) { if (request == "dump-dom-tree") { - if (auto* doc = page().top_level_browsing_context().document()) + if (auto* doc = page().top_level_browsing_context().active_document()) Web::dump_tree(*doc); } if (request == "dump-layout-tree") { - if (auto* doc = page().top_level_browsing_context().document()) { + if (auto* doc = page().top_level_browsing_context().active_document()) { if (auto* icb = doc->layout_node()) Web::dump_tree(*icb); } } if (request == "dump-style-sheets") { - if (auto* doc = page().top_level_browsing_context().document()) { + if (auto* doc = page().top_level_browsing_context().active_document()) { for (auto& sheet : doc->style_sheets().sheets()) { Web::dump_sheet(sheet); } @@ -211,21 +211,21 @@ void ClientConnection::debug_request(const String& request, const String& argume void ClientConnection::get_source() { - if (auto* doc = page().top_level_browsing_context().document()) { + if (auto* doc = page().top_level_browsing_context().active_document()) { async_did_get_source(doc->url(), doc->source()); } } void ClientConnection::inspect_dom_tree() { - if (auto* doc = page().top_level_browsing_context().document()) { + if (auto* doc = page().top_level_browsing_context().active_document()) { async_did_get_dom_tree(doc->dump_dom_tree_as_json()); } } Messages::WebContentServer::InspectDomNodeResponse ClientConnection::inspect_dom_node(i32 node_id) { - if (auto* doc = page().top_level_browsing_context().document()) { + if (auto* doc = page().top_level_browsing_context().active_document()) { Web::DOM::Node* node = Web::DOM::Node::from_id(node_id); if (!node || (&node->document() != doc)) { doc->set_inspected_node(nullptr); @@ -262,7 +262,7 @@ Messages::WebContentServer::InspectDomNodeResponse ClientConnection::inspect_dom Messages::WebContentServer::GetHoveredNodeIdResponse ClientConnection::get_hovered_node_id() { - if (auto* document = page().top_level_browsing_context().document()) { + if (auto* document = page().top_level_browsing_context().active_document()) { auto hovered_node = document->hovered_node(); if (hovered_node) return hovered_node->id(); @@ -272,7 +272,7 @@ Messages::WebContentServer::GetHoveredNodeIdResponse ClientConnection::get_hover void ClientConnection::initialize_js_console(Badge) { - auto* document = page().top_level_browsing_context().document(); + auto* document = page().top_level_browsing_context().active_document(); auto interpreter = document->interpreter().make_weak_ptr(); if (m_interpreter.ptr() == interpreter.ptr()) return; @@ -290,10 +290,10 @@ void ClientConnection::js_console_input(const String& js_source) void ClientConnection::run_javascript(String const& js_source) { - if (!page().top_level_browsing_context().document()) + if (!page().top_level_browsing_context().active_document()) return; - auto& interpreter = page().top_level_browsing_context().document()->interpreter(); + auto& interpreter = page().top_level_browsing_context().active_document()->interpreter(); auto parser = JS::Parser(JS::Lexer(js_source)); auto program = parser.parse_program(); @@ -323,7 +323,7 @@ void ClientConnection::select_all() Messages::WebContentServer::DumpLayoutTreeResponse ClientConnection::dump_layout_tree() { - auto* document = page().top_level_browsing_context().document(); + auto* document = page().top_level_browsing_context().active_document(); if (!document) return String { "(no DOM tree)" }; auto* layout_root = document->layout_node(); diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index 90ec128d77..ed24af5e82 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -48,7 +48,7 @@ void PageHost::set_palette_impl(const Gfx::PaletteImpl& impl) Web::Layout::InitialContainingBlock* PageHost::layout_root() { - auto* document = page().top_level_browsing_context().document(); + auto* document = page().top_level_browsing_context().active_document(); if (!document) return nullptr; return document->layout_node();