diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index 439d1490e29..351337ff4a6 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -34,7 +34,7 @@ WebIDL::ExceptionOr> CSSStyleSheet::construct_im auto sheet = create(realm, CSSRuleList::create_empty(realm), CSS::MediaList::create(realm, {}), {}); // 2. Set sheet’s location to the base URL of the associated Document for the current global object. - auto associated_document = sheet->global_object().document(); + auto associated_document = verify_cast(HTML::current_global_object()).document(); sheet->set_location(MUST(associated_document->base_url().to_string())); // 3. Set sheet’s stylesheet base URL to the baseURL attribute value from options. diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 802c229484e..ec1620eb486 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -3406,8 +3406,6 @@ void Document::set_browsing_context(HTML::BrowsingContext* browsing_context) // https://html.spec.whatwg.org/multipage/document-lifecycle.html#unload-a-document void Document::unload(JS::GCPtr) { - auto& vm = this->vm(); - // FIXME: 1. Assert: this is running as part of a task queued on oldDocument's event loop. // FIXME: 2. Let unloadTimingInfo be a new document unload timing info. @@ -3421,7 +3419,7 @@ void Document::unload(JS::GCPtr) auto intend_to_store_in_bfcache = false; // 6. Let eventLoop be oldDocument's relevant agent's event loop. - auto& event_loop = *verify_cast(*vm.custom_data()).event_loop; + auto& event_loop = *verify_cast(*HTML::relevant_agent(*this).custom_data()).event_loop; // 7. Increase eventLoop's termination nesting level by 1. event_loop.increment_termination_nesting_level(); @@ -3455,7 +3453,7 @@ void Document::unload(JS::GCPtr) // FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event() // We should reorganize this so that the flag appears explicitly here instead. auto event = DOM::Event::create(realm(), HTML::EventNames::unload); - global_object().dispatch_event(event); + verify_cast(relevant_global_object(*this)).dispatch_event(event); } // FIXME: 13. If unloadTimingInfo is not null, then set unloadTimingInfo's unload event end time to the current high resolution time given newDocument's relevant global object, coarsened diff --git a/Userland/Libraries/LibWeb/Internals/Inspector.cpp b/Userland/Libraries/LibWeb/Internals/Inspector.cpp index a252d7391c0..fca0de7c954 100644 --- a/Userland/Libraries/LibWeb/Internals/Inspector.cpp +++ b/Userland/Libraries/LibWeb/Internals/Inspector.cpp @@ -5,13 +5,11 @@ */ #include -#include #include #include #include #include #include -#include #include #include #include @@ -35,7 +33,7 @@ void Inspector::initialize(JS::Realm& realm) PageClient& Inspector::inspector_page_client() const { - return global_object().browsing_context()->page().client(); + return verify_cast(HTML::relevant_global_object(*this)).page().client(); } void Inspector::inspector_loaded() @@ -45,8 +43,7 @@ void Inspector::inspector_loaded() void Inspector::inspect_dom_node(i32 node_id, Optional const& pseudo_element) { - auto& page = global_object().browsing_context()->page(); - page.client().inspector_did_select_dom_node(node_id, pseudo_element.map([](auto value) { + inspector_page_client().inspector_did_select_dom_node(node_id, pseudo_element.map([](auto value) { VERIFY(value < to_underlying(Web::CSS::Selector::PseudoElement::Type::KnownPseudoElementCount)); return static_cast(value); })); diff --git a/Userland/Libraries/LibWeb/Internals/InternalAnimationTimeline.cpp b/Userland/Libraries/LibWeb/Internals/InternalAnimationTimeline.cpp index 42b612f5cd5..a255e11fa69 100644 --- a/Userland/Libraries/LibWeb/Internals/InternalAnimationTimeline.cpp +++ b/Userland/Libraries/LibWeb/Internals/InternalAnimationTimeline.cpp @@ -30,7 +30,7 @@ InternalAnimationTimeline::InternalAnimationTimeline(JS::Realm& realm) { m_current_time = 0.0; - auto& document = static_cast(global_object()).associated_document(); + auto& document = verify_cast(HTML::relevant_global_object(*this)).associated_document(); document.associate_with_timeline(*this); } diff --git a/Userland/Libraries/LibWeb/Internals/Internals.cpp b/Userland/Libraries/LibWeb/Internals/Internals.cpp index 41584f3da2b..9e7cc2fb5f3 100644 --- a/Userland/Libraries/LibWeb/Internals/Internals.cpp +++ b/Userland/Libraries/LibWeb/Internals/Internals.cpp @@ -36,9 +36,19 @@ void Internals::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(Internals); } +HTML::Window& Internals::internals_window() const +{ + return verify_cast(HTML::relevant_global_object(*this)); +} + +Page& Internals::internals_page() const +{ + return internals_window().page(); +} + void Internals::signal_text_test_is_done() { - global_object().browsing_context()->page().client().page_did_finish_text_test(); + internals_page().client().page_did_finish_text_test(); } void Internals::gc() @@ -48,12 +58,12 @@ void Internals::gc() JS::Object* Internals::hit_test(double x, double y) { - auto* active_document = global_object().browsing_context()->top_level_browsing_context()->active_document(); + auto& active_document = internals_window().associated_document(); // NOTE: Force a layout update just before hit testing. This is because the current layout tree, which is required // for stacking context traversal, might not exist if this call occurs between the tear_down_layout_tree() // and update_layout() calls - active_document->update_layout(); - auto result = active_document->paintable_box()->hit_test({ x, y }, Painting::HitTestType::Exact); + active_document.update_layout(); + auto result = active_document.paintable_box()->hit_test({ x, y }, Painting::HitTestType::Exact); if (result.has_value()) { auto hit_tеsting_result = JS::Object::create(realm(), nullptr); hit_tеsting_result->define_direct_property("node", result->dom_node(), JS::default_attributes); @@ -65,7 +75,7 @@ JS::Object* Internals::hit_test(double x, double y) void Internals::send_text(HTML::HTMLElement& target, String const& text) { - auto& page = global_object().browsing_context()->page(); + auto& page = internals_page(); target.focus(); for (auto code_point : text.code_points()) @@ -77,12 +87,12 @@ void Internals::send_key(HTML::HTMLElement& target, String const& key_name) auto key_code = UIEvents::key_code_from_string(key_name); target.focus(); - global_object().browsing_context()->page().handle_keydown(key_code, 0, 0); + internals_page().handle_keydown(key_code, 0, 0); } void Internals::commit_text() { - global_object().browsing_context()->page().handle_keydown(UIEvents::Key_Return, 0, 0); + internals_page().handle_keydown(UIEvents::Key_Return, 0, 0); } void Internals::click(double x, double y) @@ -97,7 +107,7 @@ void Internals::middle_click(double x, double y) void Internals::click(double x, double y, UIEvents::MouseButton button) { - auto& page = global_object().browsing_context()->page(); + auto& page = internals_page(); auto position = page.css_to_device_point({ x, y }); page.handle_mousedown(position, position, button, 0, 0); @@ -106,7 +116,7 @@ void Internals::click(double x, double y, UIEvents::MouseButton button) void Internals::move_pointer_to(double x, double y) { - auto& page = global_object().browsing_context()->page(); + auto& page = internals_page(); auto position = page.css_to_device_point({ x, y }); page.handle_mousemove(position, position, 0, 0); @@ -114,7 +124,7 @@ void Internals::move_pointer_to(double x, double y) void Internals::wheel(double x, double y, double delta_x, double delta_y) { - auto& page = global_object().browsing_context()->page(); + auto& page = internals_page(); auto position = page.css_to_device_point({ x, y }); page.handle_mousewheel(position, position, 0, 0, 0, delta_x, delta_y); @@ -137,7 +147,7 @@ void Internals::simulate_drag_start(double x, double y, String const& name, Stri Vector files; files.empend(name.to_byte_string(), MUST(ByteBuffer::copy(contents.bytes()))); - auto& page = global_object().browsing_context()->page(); + auto& page = internals_page(); auto position = page.css_to_device_point({ x, y }); page.handle_drag_and_drop_event(DragEvent::Type::DragStart, position, position, UIEvents::MouseButton::Primary, 0, 0, move(files)); @@ -145,7 +155,7 @@ void Internals::simulate_drag_start(double x, double y, String const& name, Stri void Internals::simulate_drag_move(double x, double y) { - auto& page = global_object().browsing_context()->page(); + auto& page = internals_page(); auto position = page.css_to_device_point({ x, y }); page.handle_drag_and_drop_event(DragEvent::Type::DragMove, position, position, UIEvents::MouseButton::Primary, 0, 0, {}); @@ -153,7 +163,7 @@ void Internals::simulate_drag_move(double x, double y) void Internals::simulate_drop(double x, double y) { - auto& page = global_object().browsing_context()->page(); + auto& page = internals_page(); auto position = page.css_to_device_point({ x, y }); page.handle_drag_and_drop_event(DragEvent::Type::Drop, position, position, UIEvents::MouseButton::Primary, 0, 0, {}); diff --git a/Userland/Libraries/LibWeb/Internals/Internals.h b/Userland/Libraries/LibWeb/Internals/Internals.h index 58f76911526..03a338c4839 100644 --- a/Userland/Libraries/LibWeb/Internals/Internals.h +++ b/Userland/Libraries/LibWeb/Internals/Internals.h @@ -46,6 +46,9 @@ private: virtual void initialize(JS::Realm&) override; void click(double x, double y, UIEvents::MouseButton); + + HTML::Window& internals_window() const; + Page& internals_page() const; }; } diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp index d906f888f3d..50f20f197bd 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp @@ -175,7 +175,7 @@ Variant, JS::Handle> IntersectionObserve } // otherwise, it is the top-level browsing context’s document node, referred to as the implicit root. - return JS::make_handle(global_object().page().top_level_browsing_context().active_document()); + return JS::make_handle(verify_cast(HTML::relevant_global_object(*this)).page().top_level_browsing_context().active_document()); } // https://www.w3.org/TR/intersection-observer/#intersectionobserver-root-intersection-rectangle diff --git a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp index 540ae5af4bf..9c18b774416 100644 --- a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp +++ b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp @@ -39,7 +39,7 @@ double IdleDeadline::time_remaining() const { auto const& event_loop = HTML::main_thread_event_loop(); // 1. Let now be a DOMHighResTimeStamp representing current high resolution time in milliseconds. - auto now = HighResolutionTime::current_high_resolution_time(global_object()); + auto now = HighResolutionTime::current_high_resolution_time(HTML::relevant_global_object(*this)); // 2. Let deadline be the result of calling IdleDeadline's get deadline time algorithm. auto deadline = event_loop.compute_deadline(); // 3. Let timeRemaining be deadline - now. diff --git a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp index 50f5da4ab32..4d9bf5135d7 100644 --- a/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp +++ b/Userland/Libraries/LibWeb/Streams/ByteLengthQueuingStrategy.cpp @@ -34,7 +34,7 @@ ByteLengthQueuingStrategy::~ByteLengthQueuingStrategy() = default; JS::NonnullGCPtr ByteLengthQueuingStrategy::size() { // 1. Return this's relevant global object's byte length queuing strategy size function. - return global_object().byte_length_queuing_strategy_size_function(); + return verify_cast(HTML::relevant_global_object(*this)).byte_length_queuing_strategy_size_function(); } void ByteLengthQueuingStrategy::initialize(JS::Realm& realm) diff --git a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp index ada0e0bbeb2..e41550a799f 100644 --- a/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp +++ b/Userland/Libraries/LibWeb/Streams/CountQueuingStrategy.cpp @@ -34,7 +34,7 @@ CountQueuingStrategy::~CountQueuingStrategy() = default; JS::NonnullGCPtr CountQueuingStrategy::size() { // 1. Return this's relevant global object's count queuing strategy size function. - return global_object().count_queuing_strategy_size_function(); + return verify_cast(HTML::relevant_global_object(*this)).count_queuing_strategy_size_function(); } void CountQueuingStrategy::initialize(JS::Realm& realm)