1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:27:44 +00:00

LibWeb: Rename BrowsingContext::document() => active_document()

This better matches the spec nomenclature. Note that we don't yet
*retrieve* the active document according to spec.
This commit is contained in:
Andreas Kling 2021-09-09 13:14:32 +02:00
parent dd82f68326
commit 84fcf879f9
10 changed files with 69 additions and 69 deletions

View file

@ -362,8 +362,8 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::top_getter)
if (!this_browsing_context) if (!this_browsing_context)
return JS::js_null(); return JS::js_null();
VERIFY(this_browsing_context->top_level_browsing_context().document()); VERIFY(this_browsing_context->top_level_browsing_context().active_document());
auto& top_window = this_browsing_context->top_level_browsing_context().document()->window(); auto& top_window = this_browsing_context->top_level_browsing_context().active_document()->window();
return top_window.wrapper(); return top_window.wrapper();
} }
@ -379,8 +379,8 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::parent_getter)
return JS::js_null(); return JS::js_null();
if (this_browsing_context->parent()) { if (this_browsing_context->parent()) {
VERIFY(this_browsing_context->parent()->document()); VERIFY(this_browsing_context->parent()->active_document());
auto& parent_window = this_browsing_context->parent()->document()->window(); auto& parent_window = this_browsing_context->parent()->active_document()->window();
return parent_window.wrapper(); return parent_window.wrapper();
} }
VERIFY(this_browsing_context == &this_browsing_context->top_level_browsing_context()); VERIFY(this_browsing_context == &this_browsing_context->top_level_browsing_context());

View file

@ -35,9 +35,9 @@ void BrowsingContextContainer::inserted()
Origin BrowsingContextContainer::content_origin() const 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 {};
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 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 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<FrameLoader>) void BrowsingContextContainer::nested_browsing_context_did_load(Badge<FrameLoader>)

View file

@ -278,9 +278,9 @@ void InProcessWebView::keydown_event(GUI::KeyEvent& event)
URL InProcessWebView::url() const URL InProcessWebView::url() const
{ {
if (!page().top_level_browsing_context().document()) if (!page().top_level_browsing_context().active_document())
return {}; return {};
return page().top_level_browsing_context().document()->url(); return page().top_level_browsing_context().active_document()->url();
} }
void InProcessWebView::reload() void InProcessWebView::reload()
@ -319,22 +319,22 @@ void InProcessWebView::page_did_request_scroll_into_view(const Gfx::IntRect& rec
void InProcessWebView::load_empty_document() 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() 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 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) 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() void InProcessWebView::did_scroll()

View file

@ -213,7 +213,7 @@ void FrameLoader::load_html(const StringView& html, const URL& url)
auto document = DOM::Document::create(url); auto document = DOM::Document::create(url);
HTML::HTMLDocumentParser parser(document, html, "utf-8"); HTML::HTMLDocumentParser parser(document, html, "utf-8");
parser.run(url); 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 // 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); generator.append(data);
auto document = HTML::parse_html_document(generator.as_string_view(), failed_url, "utf-8"); auto document = HTML::parse_html_document(generator.as_string_view(), failed_url, "utf-8");
VERIFY(document); VERIFY(document);
browsing_context().set_document(document); browsing_context().set_active_document(document);
}, },
[](auto& error, auto) { [](auto& error, auto) {
dbgln("Failed to load error page: {}", error); dbgln("Failed to load error page: {}", error);
@ -285,7 +285,7 @@ void FrameLoader::resource_did_load()
document->set_encoding(resource()->encoding()); document->set_encoding(resource()->encoding());
document->set_content_type(resource()->mime_type()); 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())) { if (!parse_document(*document, resource()->encoded_data())) {
load_error_page(url, "Failed to parse content."); load_error_page(url, "Failed to parse content.");

View file

@ -66,26 +66,26 @@ bool BrowsingContext::is_focused_context() const
return m_page && &m_page->focused_context() == this; 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; return;
m_cursor_position = {}; m_cursor_position = {};
if (m_document) if (m_active_document)
m_document->detach_from_browsing_context({}, *this); m_active_document->detach_from_browsing_context({}, *this);
m_document = document; m_active_document = document;
if (m_document) { if (m_active_document) {
m_document->attach_to_browsing_context({}, *this); m_active_document->attach_to_browsing_context({}, *this);
if (m_page && is_top_level()) 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) 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) 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()) { if (m_size != rect.size()) {
m_size = rect.size(); m_size = rect.size();
if (m_document) { if (active_document()) {
m_document->window().dispatch_event(DOM::Event::create(UIEvents::EventNames::resize)); active_document()->window().dispatch_event(DOM::Event::create(UIEvents::EventNames::resize));
m_document->update_layout(); active_document()->update_layout();
} }
did_change = true; did_change = true;
} }
@ -117,9 +117,9 @@ void BrowsingContext::set_size(Gfx::IntSize const& size)
if (m_size == size) if (m_size == size)
return; return;
m_size = size; m_size = size;
if (m_document) { if (active_document()) {
m_document->window().dispatch_event(DOM::Event::create(UIEvents::EventNames::resize)); active_document()->window().dispatch_event(DOM::Event::create(UIEvents::EventNames::resize));
m_document->update_layout(); active_document()->update_layout();
} }
for (auto* client : m_viewport_clients) 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) void BrowsingContext::scroll_to_anchor(String const& fragment)
{ {
if (!document()) if (!active_document())
return; return;
auto element = document()->get_element_by_id(fragment); auto element = active_document()->get_element_by_id(fragment);
if (!element) { 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()) { for (auto& candidate : candidates->collect_matching_elements()) {
if (is<HTML::HTMLAnchorElement>(*candidate)) { if (is<HTML::HTMLAnchorElement>(*candidate)) {
element = verify_cast<HTML::HTMLAnchorElement>(*candidate); element = verify_cast<HTML::HTMLAnchorElement>(*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()" // 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()) if (!element || !element->layout_node())
return; return;
@ -227,9 +227,9 @@ void BrowsingContext::set_cursor_position(DOM::Position position)
String BrowsingContext::selected_text() const String BrowsingContext::selected_text() const
{ {
StringBuilder builder; StringBuilder builder;
if (!m_document) if (!active_document())
return {}; return {};
auto* layout_root = m_document->layout_node(); auto* layout_root = active_document()->layout_node();
if (!layout_root) if (!layout_root)
return {}; return {};
if (!layout_root->selection().is_valid()) if (!layout_root->selection().is_valid())
@ -273,9 +273,9 @@ String BrowsingContext::selected_text() const
void BrowsingContext::select_all() void BrowsingContext::select_all()
{ {
if (!m_document) if (!active_document())
return; return;
auto* layout_root = m_document->layout_node(); auto* layout_root = active_document()->layout_node();
if (!layout_root) if (!layout_root)
return; return;

View file

@ -39,10 +39,10 @@ public:
bool is_top_level() const { return this == &top_level_browsing_context(); } bool is_top_level() const { return this == &top_level_browsing_context(); }
bool is_focused_context() const; bool is_focused_context() const;
DOM::Document const* document() const { return m_document; } DOM::Document const* active_document() const { return m_active_document; }
DOM::Document* document() { return m_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* page() { return m_page; }
Page const* page() const { return m_page; } Page const* page() const { return m_page; }
@ -111,7 +111,7 @@ private:
EventHandler m_event_handler; EventHandler m_event_handler;
WeakPtr<HTML::BrowsingContextContainer> m_container; WeakPtr<HTML::BrowsingContextContainer> m_container;
RefPtr<DOM::Document> m_document; RefPtr<DOM::Document> m_active_document;
Gfx::IntSize m_size; Gfx::IntSize m_size;
Gfx::IntPoint m_viewport_scroll_offset; Gfx::IntPoint m_viewport_scroll_offset;

View file

@ -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 // 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 // remain in the layout tree. This has to be fixed, this just causes everything to be recomputed
// which really hurts performance. // which really hurts performance.
m_frame.document()->force_layout(); m_frame.active_document()->force_layout();
m_frame.did_edit({}); 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 // 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 // remain in the layout tree. This has to be fixed, this just causes everything to be recomputed
// which really hurts performance. // which really hurts performance.
m_frame.document()->force_layout(); m_frame.active_document()->force_layout();
m_frame.did_edit({}); m_frame.did_edit({});
} }

View file

@ -99,16 +99,16 @@ EventHandler::~EventHandler()
const Layout::InitialContainingBlock* EventHandler::layout_root() const const Layout::InitialContainingBlock* EventHandler::layout_root() const
{ {
if (!m_frame.document()) if (!m_frame.active_document())
return nullptr; return nullptr;
return m_frame.document()->layout_node(); return m_frame.active_document()->layout_node();
} }
Layout::InitialContainingBlock* EventHandler::layout_root() Layout::InitialContainingBlock* EventHandler::layout_root()
{ {
if (!m_frame.document()) if (!m_frame.active_document())
return nullptr; 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) 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; return true;
} }
NonnullRefPtr document = *m_frame.document(); NonnullRefPtr document = *m_frame.active_document();
RefPtr<DOM::Node> node; RefPtr<DOM::Node> node;
{ {
@ -279,7 +279,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
return true; return true;
} }
auto& document = *m_frame.document(); auto& document = *m_frame.active_document();
bool hovered_node_changed = false; bool hovered_node_changed = false;
bool is_hovering_link = 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() bool EventHandler::focus_next_element()
{ {
if (!m_frame.document()) if (!m_frame.active_document())
return false; return false;
auto* element = m_frame.document()->focused_element(); auto* element = m_frame.active_document()->focused_element();
if (!element) { if (!element) {
element = m_frame.document()->first_child_of_type<DOM::Element>(); element = m_frame.active_document()->first_child_of_type<DOM::Element>();
if (element && element->is_focusable()) { if (element && element->is_focusable()) {
m_frame.document()->set_focused_element(element); m_frame.active_document()->set_focused_element(element);
return true; 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()) 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; return element;
} }
@ -398,7 +398,7 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
if (layout_root()->selection().is_valid()) { if (layout_root()->selection().is_valid()) {
auto range = layout_root()->selection().to_dom_range()->normalized(); auto range = layout_root()->selection().to_dom_range()->normalized();
if (range->start_container()->is_editable()) { 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? // FIXME: This doesn't work for some reason?
m_frame.set_cursor_position({ *range->start_container(), range->start_offset() }); m_frame.set_cursor_position({ *range->start_container(), range->start_offset() });

View file

@ -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) void ClientConnection::debug_request(const String& request, const String& argument)
{ {
if (request == "dump-dom-tree") { 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); Web::dump_tree(*doc);
} }
if (request == "dump-layout-tree") { 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()) if (auto* icb = doc->layout_node())
Web::dump_tree(*icb); Web::dump_tree(*icb);
} }
} }
if (request == "dump-style-sheets") { 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()) { for (auto& sheet : doc->style_sheets().sheets()) {
Web::dump_sheet(sheet); Web::dump_sheet(sheet);
} }
@ -211,21 +211,21 @@ void ClientConnection::debug_request(const String& request, const String& argume
void ClientConnection::get_source() 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()); async_did_get_source(doc->url(), doc->source());
} }
} }
void ClientConnection::inspect_dom_tree() 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()); async_did_get_dom_tree(doc->dump_dom_tree_as_json());
} }
} }
Messages::WebContentServer::InspectDomNodeResponse ClientConnection::inspect_dom_node(i32 node_id) 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); Web::DOM::Node* node = Web::DOM::Node::from_id(node_id);
if (!node || (&node->document() != doc)) { if (!node || (&node->document() != doc)) {
doc->set_inspected_node(nullptr); doc->set_inspected_node(nullptr);
@ -262,7 +262,7 @@ Messages::WebContentServer::InspectDomNodeResponse ClientConnection::inspect_dom
Messages::WebContentServer::GetHoveredNodeIdResponse ClientConnection::get_hovered_node_id() 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(); auto hovered_node = document->hovered_node();
if (hovered_node) if (hovered_node)
return hovered_node->id(); return hovered_node->id();
@ -272,7 +272,7 @@ Messages::WebContentServer::GetHoveredNodeIdResponse ClientConnection::get_hover
void ClientConnection::initialize_js_console(Badge<PageHost>) void ClientConnection::initialize_js_console(Badge<PageHost>)
{ {
auto* document = page().top_level_browsing_context().document(); auto* document = page().top_level_browsing_context().active_document();
auto interpreter = document->interpreter().make_weak_ptr(); auto interpreter = document->interpreter().make_weak_ptr();
if (m_interpreter.ptr() == interpreter.ptr()) if (m_interpreter.ptr() == interpreter.ptr())
return; return;
@ -290,10 +290,10 @@ void ClientConnection::js_console_input(const String& js_source)
void ClientConnection::run_javascript(String const& 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; 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 parser = JS::Parser(JS::Lexer(js_source));
auto program = parser.parse_program(); auto program = parser.parse_program();
@ -323,7 +323,7 @@ void ClientConnection::select_all()
Messages::WebContentServer::DumpLayoutTreeResponse ClientConnection::dump_layout_tree() 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) if (!document)
return String { "(no DOM tree)" }; return String { "(no DOM tree)" };
auto* layout_root = document->layout_node(); auto* layout_root = document->layout_node();

View file

@ -48,7 +48,7 @@ void PageHost::set_palette_impl(const Gfx::PaletteImpl& impl)
Web::Layout::InitialContainingBlock* PageHost::layout_root() 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) if (!document)
return nullptr; return nullptr;
return document->layout_node(); return document->layout_node();