mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 00:07:35 +00:00
LibWeb: Remove unecessary dependence on Window from WebGL and WebSocket
These classes only needed Window to get at its realm. Pass a realm directly to construct WebGL and WebSocket classes.
This commit is contained in:
parent
4bb6345b2f
commit
beb3519a49
9 changed files with 42 additions and 42 deletions
|
@ -4,26 +4,26 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/WebGL/WebGLContextEvent.h>
|
||||
|
||||
namespace Web::WebGL {
|
||||
|
||||
WebGLContextEvent* WebGLContextEvent::create(HTML::Window& window_object, FlyString const& event_name, WebGLContextEventInit const& event_init)
|
||||
WebGLContextEvent* WebGLContextEvent::create(JS::Realm& realm, FlyString const& event_name, WebGLContextEventInit const& event_init)
|
||||
{
|
||||
return window_object.heap().allocate<WebGLContextEvent>(window_object.realm(), window_object, event_name, event_init);
|
||||
return realm.heap().allocate<WebGLContextEvent>(realm, realm, event_name, event_init);
|
||||
}
|
||||
|
||||
WebGLContextEvent* WebGLContextEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, WebGLContextEventInit const& event_init)
|
||||
WebGLContextEvent* WebGLContextEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, WebGLContextEventInit const& event_init)
|
||||
{
|
||||
return create(window_object, event_name, event_init);
|
||||
return create(realm, event_name, event_init);
|
||||
}
|
||||
|
||||
WebGLContextEvent::WebGLContextEvent(HTML::Window& window_object, FlyString const& type, WebGLContextEventInit const& event_init)
|
||||
: DOM::Event(window_object, type, event_init)
|
||||
WebGLContextEvent::WebGLContextEvent(JS::Realm& realm, FlyString const& type, WebGLContextEventInit const& event_init)
|
||||
: DOM::Event(realm, type, event_init)
|
||||
, m_status_message(event_init.status_message)
|
||||
{
|
||||
set_prototype(&window_object.cached_web_prototype("WebGLContextEvent"));
|
||||
set_prototype(&Bindings::cached_web_prototype(realm, "WebGLContextEvent"));
|
||||
}
|
||||
|
||||
WebGLContextEvent::~WebGLContextEvent() = default;
|
||||
|
|
|
@ -19,16 +19,16 @@ class WebGLContextEvent final : public DOM::Event {
|
|||
WEB_PLATFORM_OBJECT(WebGLContextEvent, DOM::Event);
|
||||
|
||||
public:
|
||||
static WebGLContextEvent* create(HTML::Window&, FlyString const& type, WebGLContextEventInit const& event_init);
|
||||
static WebGLContextEvent* create_with_global_object(HTML::Window&, FlyString const& type, WebGLContextEventInit const& event_init);
|
||||
|
||||
WebGLContextEvent(HTML::Window&, FlyString const& type, WebGLContextEventInit const& event_init);
|
||||
static WebGLContextEvent* create(JS::Realm&, FlyString const& type, WebGLContextEventInit const& event_init);
|
||||
static WebGLContextEvent* construct_impl(JS::Realm&, FlyString const& type, WebGLContextEventInit const& event_init);
|
||||
|
||||
virtual ~WebGLContextEvent() override;
|
||||
|
||||
String const& status_message() const { return m_status_message; }
|
||||
|
||||
private:
|
||||
WebGLContextEvent(JS::Realm&, FlyString const& type, WebGLContextEventInit const& event_init);
|
||||
|
||||
String m_status_message { String::empty() };
|
||||
};
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/HTMLCanvasElement.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/WebGL/WebGLContextEvent.h>
|
||||
#include <LibWeb/WebGL/WebGLRenderingContext.h>
|
||||
|
||||
|
@ -17,7 +17,7 @@ static void fire_webgl_context_event(HTML::HTMLCanvasElement& canvas_element, Fl
|
|||
{
|
||||
// To fire a WebGL context event named e means that an event using the WebGLContextEvent interface, with its type attribute [DOM4] initialized to e, its cancelable attribute initialized to true, and its isTrusted attribute [DOM4] initialized to true, is to be dispatched at the given object.
|
||||
// FIXME: Consider setting a status message.
|
||||
auto event = WebGLContextEvent::create(canvas_element.document().window(), type, WebGLContextEventInit {});
|
||||
auto event = WebGLContextEvent::create(canvas_element.realm(), type, WebGLContextEventInit {});
|
||||
event->set_is_trusted(true);
|
||||
event->set_cancelable(true);
|
||||
canvas_element.dispatch_event(*event);
|
||||
|
@ -30,7 +30,7 @@ static void fire_webgl_context_creation_error(HTML::HTMLCanvasElement& canvas_el
|
|||
fire_webgl_context_event(canvas_element, "webglcontextcreationerror"sv);
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::GCPtr<WebGLRenderingContext>> WebGLRenderingContext::create(HTML::Window& window, HTML::HTMLCanvasElement& canvas_element, JS::Value options)
|
||||
JS::ThrowCompletionOr<JS::GCPtr<WebGLRenderingContext>> WebGLRenderingContext::create(JS::Realm& realm, HTML::HTMLCanvasElement& canvas_element, JS::Value options)
|
||||
{
|
||||
// We should be coming here from getContext being called on a wrapped <canvas> element.
|
||||
auto context_attributes = TRY(convert_value_to_context_attributes_dictionary(canvas_element.vm(), options));
|
||||
|
@ -46,13 +46,13 @@ JS::ThrowCompletionOr<JS::GCPtr<WebGLRenderingContext>> WebGLRenderingContext::c
|
|||
fire_webgl_context_creation_error(canvas_element);
|
||||
return JS::GCPtr<WebGLRenderingContext> { nullptr };
|
||||
}
|
||||
return window.heap().allocate<WebGLRenderingContext>(window.realm(), window, canvas_element, context_or_error.release_value(), context_attributes, context_attributes);
|
||||
return realm.heap().allocate<WebGLRenderingContext>(realm, realm, canvas_element, context_or_error.release_value(), context_attributes, context_attributes);
|
||||
}
|
||||
|
||||
WebGLRenderingContext::WebGLRenderingContext(HTML::Window& window, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
|
||||
: WebGLRenderingContextBase(window, canvas_element, move(context), move(context_creation_parameters), move(actual_context_parameters))
|
||||
WebGLRenderingContext::WebGLRenderingContext(JS::Realm& realm, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
|
||||
: WebGLRenderingContextBase(realm, canvas_element, move(context), move(context_creation_parameters), move(actual_context_parameters))
|
||||
{
|
||||
set_prototype(&window.cached_web_prototype("WebGLRenderingContext"));
|
||||
set_prototype(&Bindings::cached_web_prototype(realm, "WebGLRenderingContext"));
|
||||
}
|
||||
|
||||
WebGLRenderingContext::~WebGLRenderingContext() = default;
|
||||
|
|
|
@ -16,12 +16,12 @@ class WebGLRenderingContext final : public WebGLRenderingContextBase {
|
|||
WEB_PLATFORM_OBJECT(WebGLRenderingContext, WebGLRenderingContextBase);
|
||||
|
||||
public:
|
||||
static JS::ThrowCompletionOr<JS::GCPtr<WebGLRenderingContext>> create(HTML::Window&, HTML::HTMLCanvasElement& canvas_element, JS::Value options);
|
||||
static JS::ThrowCompletionOr<JS::GCPtr<WebGLRenderingContext>> create(JS::Realm&, HTML::HTMLCanvasElement& canvas_element, JS::Value options);
|
||||
|
||||
virtual ~WebGLRenderingContext() override;
|
||||
|
||||
private:
|
||||
WebGLRenderingContext(HTML::Window&, HTML::HTMLCanvasElement&, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters);
|
||||
WebGLRenderingContext(JS::Realm&, HTML::HTMLCanvasElement&, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -7,13 +7,12 @@
|
|||
#include <AK/Debug.h>
|
||||
#include <LibGL/GLContext.h>
|
||||
#include <LibWeb/HTML/HTMLCanvasElement.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/WebGL/WebGLRenderingContextBase.h>
|
||||
|
||||
namespace Web::WebGL {
|
||||
|
||||
WebGLRenderingContextBase::WebGLRenderingContextBase(HTML::Window& window, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
|
||||
: PlatformObject(window.realm())
|
||||
WebGLRenderingContextBase::WebGLRenderingContextBase(JS::Realm& realm, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
|
||||
: PlatformObject(realm)
|
||||
, m_canvas_element(canvas_element)
|
||||
, m_context(move(context))
|
||||
, m_context_creation_parameters(move(context_creation_parameters))
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
void viewport(GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
|
||||
protected:
|
||||
WebGLRenderingContextBase(HTML::Window&, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters);
|
||||
WebGLRenderingContextBase(JS::Realm&, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters);
|
||||
|
||||
private:
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue