2020-04-01 13:53:28 -03:00
|
|
|
/*
|
2021-01-23 09:23:17 -03:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2021-09-08 08:22:28 -03:00
|
|
|
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
2020-04-01 13:53:28 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-01 13:53:28 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2020-11-21 15:32:39 -03:00
|
|
|
#include <AK/TypeCasts.h>
|
2020-06-20 12:45:27 -03:00
|
|
|
#include <AK/Weakable.h>
|
2020-04-01 13:53:28 -03:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
|
|
|
|
namespace Web {
|
|
|
|
|
namespace Bindings {
|
|
|
|
|
|
2020-06-20 12:45:27 -03:00
|
|
|
class WindowObject final
|
|
|
|
|
: public JS::GlobalObject
|
|
|
|
|
, public Weakable<WindowObject> {
|
2021-03-17 12:52:26 -03:00
|
|
|
JS_OBJECT(WindowObject, JS::GlobalObject);
|
|
|
|
|
|
2020-04-01 13:53:28 -03:00
|
|
|
public:
|
2020-07-26 14:37:56 -03:00
|
|
|
explicit WindowObject(DOM::Window&);
|
2021-03-17 12:52:26 -03:00
|
|
|
virtual void initialize_global_object() override;
|
2020-04-01 13:53:28 -03:00
|
|
|
virtual ~WindowObject() override;
|
|
|
|
|
|
2020-07-26 14:37:56 -03:00
|
|
|
DOM::Window& impl() { return *m_impl; }
|
|
|
|
|
const DOM::Window& impl() const { return *m_impl; }
|
2020-04-01 13:53:28 -03:00
|
|
|
|
2020-09-22 13:24:49 -03:00
|
|
|
Origin origin() const;
|
|
|
|
|
|
2021-09-12 10:59:49 -03:00
|
|
|
LocationObject* location_object() { return m_location_object; }
|
|
|
|
|
LocationObject const* location_object() const { return m_location_object; }
|
|
|
|
|
|
2021-01-18 05:50:00 -03:00
|
|
|
JS::Object* web_prototype(const String& class_name) { return m_prototypes.get(class_name).value_or(nullptr); }
|
|
|
|
|
JS::NativeFunction* web_constructor(const String& class_name) { return m_constructors.get(class_name).value_or(nullptr); }
|
2021-01-18 07:36:34 -03:00
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
JS::Object& ensure_web_prototype(const String& class_name)
|
|
|
|
|
{
|
|
|
|
|
auto it = m_prototypes.find(class_name);
|
|
|
|
|
if (it != m_prototypes.end())
|
|
|
|
|
return *it->value;
|
|
|
|
|
auto* prototype = heap().allocate<T>(*this, *this);
|
|
|
|
|
m_prototypes.set(class_name, prototype);
|
|
|
|
|
return *prototype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
JS::NativeFunction& ensure_web_constructor(const String& class_name)
|
|
|
|
|
{
|
|
|
|
|
auto it = m_constructors.find(class_name);
|
|
|
|
|
if (it != m_constructors.end())
|
|
|
|
|
return *it->value;
|
|
|
|
|
auto* constructor = heap().allocate<T>(*this, *this);
|
|
|
|
|
m_constructors.set(class_name, constructor);
|
2021-07-05 20:15:08 -03:00
|
|
|
define_direct_property(class_name, JS::Value(constructor), JS::Attribute::Writable | JS::Attribute::Configurable);
|
2021-01-18 07:36:34 -03:00
|
|
|
return *constructor;
|
|
|
|
|
}
|
2021-01-18 05:50:00 -03:00
|
|
|
|
2020-04-01 13:53:28 -03:00
|
|
|
private:
|
2020-11-28 10:33:36 -03:00
|
|
|
virtual void visit_edges(Visitor&) override;
|
2020-04-01 13:53:28 -03:00
|
|
|
|
2021-07-05 09:04:18 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(top_getter);
|
2021-04-07 06:19:51 -03:00
|
|
|
|
2021-07-05 09:04:18 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(document_getter);
|
2020-04-01 13:53:28 -03:00
|
|
|
|
2021-07-05 09:04:18 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(performance_getter);
|
2021-09-11 19:43:34 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(history_getter);
|
2021-07-05 09:04:18 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(screen_getter);
|
2020-09-29 13:19:18 -03:00
|
|
|
|
2021-07-05 09:04:18 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(event_getter);
|
2021-09-12 07:39:09 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(event_setter);
|
2020-11-21 15:32:39 -03:00
|
|
|
|
2021-07-05 09:04:18 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
|
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
|
2021-03-16 13:22:01 -03:00
|
|
|
|
2021-07-05 09:04:18 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(parent_getter);
|
2021-04-11 18:34:57 -03:00
|
|
|
|
2021-09-08 08:22:28 -03:00
|
|
|
JS_DECLARE_NATIVE_GETTER(scroll_x_getter);
|
|
|
|
|
JS_DECLARE_NATIVE_GETTER(scroll_y_getter);
|
2021-09-08 17:27:44 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(scroll);
|
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(scroll_by);
|
2021-09-08 08:22:28 -03:00
|
|
|
|
2020-06-20 08:55:34 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(alert);
|
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(confirm);
|
2021-02-20 08:05:18 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(prompt);
|
2020-06-20 08:55:34 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(set_interval);
|
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(set_timeout);
|
2020-06-27 13:30:29 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(clear_interval);
|
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(clear_timeout);
|
2020-06-20 08:55:34 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(request_animation_frame);
|
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(cancel_animation_frame);
|
2020-06-20 11:44:27 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(atob);
|
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(btoa);
|
2020-04-01 13:53:28 -03:00
|
|
|
|
2021-09-10 19:33:30 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(get_computed_style);
|
2021-09-12 13:10:27 -03:00
|
|
|
JS_DECLARE_NATIVE_FUNCTION(match_media);
|
2021-09-10 19:33:30 -03:00
|
|
|
|
2020-07-26 14:37:56 -03:00
|
|
|
NonnullRefPtr<DOM::Window> m_impl;
|
2020-04-08 16:11:51 -03:00
|
|
|
|
2021-09-12 11:23:30 -03:00
|
|
|
LocationObject* m_location_object { nullptr };
|
2021-09-12 10:59:49 -03:00
|
|
|
|
2021-01-18 05:50:00 -03:00
|
|
|
HashMap<String, JS::Object*> m_prototypes;
|
|
|
|
|
HashMap<String, JS::NativeFunction*> m_constructors;
|
2020-04-01 13:53:28 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|