LibWeb: Remove uses of obsolete PlatformObject::global_object()

This API is a relic from the time when it was important for objects to
have easy access to the Window, and to know it was the global object.

We now have more spec-related concepts like relevant_global_object and
current_global_object to pull the Window out of thin air.
This commit is contained in:
Andrew Kaster 2024-09-04 19:22:48 -06:00 committed by Andreas Kling
parent 4df280689b
commit 02a56f6480
Notes: github-actions[bot] 2024-09-07 09:40:02 +00:00
10 changed files with 36 additions and 28 deletions

View file

@ -34,7 +34,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSStyleSheet>> CSSStyleSheet::construct_im
auto sheet = create(realm, CSSRuleList::create_empty(realm), CSS::MediaList::create(realm, {}), {});
// 2. Set sheets 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::Window>(HTML::current_global_object()).document();
sheet->set_location(MUST(associated_document->base_url().to_string()));
// 3. Set sheets stylesheet base URL to the baseURL attribute value from options.

View file

@ -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<Document>)
{
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<Document>)
auto intend_to_store_in_bfcache = false;
// 6. Let eventLoop be oldDocument's relevant agent's event loop.
auto& event_loop = *verify_cast<Bindings::WebEngineCustomData>(*vm.custom_data()).event_loop;
auto& event_loop = *verify_cast<Bindings::WebEngineCustomData>(*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<Document>)
// 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<HTML::Window>(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

View file

@ -5,13 +5,11 @@
*/
#include <LibJS/Runtime/Realm.h>
#include <LibJS/Runtime/VM.h>
#include <LibWeb/Bindings/InspectorPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/CSS/StyleSheetIdentifier.h>
#include <LibWeb/DOM/NamedNodeMap.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Internals/Inspector.h>
#include <LibWeb/Page/Page.h>
@ -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::Window>(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<i32> 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<Web::CSS::Selector::PseudoElement::Type>(value);
}));

View file

@ -30,7 +30,7 @@ InternalAnimationTimeline::InternalAnimationTimeline(JS::Realm& realm)
{
m_current_time = 0.0;
auto& document = static_cast<HTML::Window&>(global_object()).associated_document();
auto& document = verify_cast<HTML::Window>(HTML::relevant_global_object(*this)).associated_document();
document.associate_with_timeline(*this);
}

View file

@ -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::Window>(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<HTML::SelectedFile> 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, {});

View file

@ -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;
};
}

View file

@ -175,7 +175,7 @@ Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>> IntersectionObserve
}
// otherwise, it is the top-level browsing contexts 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::Window>(HTML::relevant_global_object(*this)).page().top_level_browsing_context().active_document());
}
// https://www.w3.org/TR/intersection-observer/#intersectionobserver-root-intersection-rectangle

View file

@ -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.

View file

@ -34,7 +34,7 @@ ByteLengthQueuingStrategy::~ByteLengthQueuingStrategy() = default;
JS::NonnullGCPtr<WebIDL::CallbackType> 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::Window>(HTML::relevant_global_object(*this)).byte_length_queuing_strategy_size_function();
}
void ByteLengthQueuingStrategy::initialize(JS::Realm& realm)

View file

@ -34,7 +34,7 @@ CountQueuingStrategy::~CountQueuingStrategy() = default;
JS::NonnullGCPtr<WebIDL::CallbackType> 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::Window>(HTML::relevant_global_object(*this)).count_queuing_strategy_size_function();
}
void CountQueuingStrategy::initialize(JS::Realm& realm)