LibWeb: Implement BarProp properties for Window

This commit is contained in:
Totto16 2025-03-04 22:51:08 +01:00 committed by Tim Ledbetter
parent ad634897b8
commit b66e7ac1ba
Notes: github-actions[bot] 2025-03-29 02:36:35 +00:00
13 changed files with 201 additions and 0 deletions

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2025, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/BarPropPrototype.h>
#include <LibWeb/HTML/BarProp.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(BarProp);
GC::Ref<BarProp> BarProp::create(JS::Realm& realm)
{
return realm.create<BarProp>(realm);
}
BarProp::BarProp(JS::Realm& realm)
: Bindings::PlatformObject(realm)
{
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-barprop-visible
bool BarProp::visible() const
{
// 1. Let browsingContext be this's relevant global object's browsing context.
auto& global_object = HTML::relevant_global_object(*this);
auto* browsing_context = as<HTML::Window>(global_object).associated_document().browsing_context();
// 2. If browsingContext is null, then return true.
if (!browsing_context) {
return true;
}
// 3. Return the negation of browsingContext's top-level browsing context's is popup.
return browsing_context->top_level_browsing_context()->is_popup() != TokenizedFeature::Popup::Yes;
}
void BarProp::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(BarProp);
}
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2025, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGC/CellAllocator.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebIDL/Types.h>
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#barprop
class BarProp : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(BarProp, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(BarProp);
public:
BarProp(JS::Realm&);
static GC::Ref<BarProp> create(JS::Realm&);
[[nodiscard]] bool visible() const;
private:
virtual void initialize(JS::Realm&) override;
};
}

View file

@ -0,0 +1,6 @@
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#barprop
[Exposed=Window]
interface BarProp {
readonly attribute boolean visible;
};

View file

@ -77,6 +77,7 @@ public:
void set_opener_browsing_context(GC::Ptr<BrowsingContext> browsing_context) { m_opener_browsing_context = browsing_context; }
void set_is_popup(TokenizedFeature::Popup is_popup) { m_is_popup = is_popup; }
[[nodiscard]] TokenizedFeature::Popup is_popup() const { return m_is_popup; }
SandboxingFlagSet popup_sandboxing_flag_set() const { return m_popup_sandboxing_flag_set; }
void set_popup_sandboxing_flag_set(SandboxingFlagSet value) { m_popup_sandboxing_flag_set = value; }

View file

@ -128,6 +128,12 @@ void Window::visit_edges(JS::Cell::Visitor& visitor)
visitor.visit(m_pdf_viewer_plugin_objects);
visitor.visit(m_pdf_viewer_mime_type_objects);
visitor.visit(m_close_watcher_manager);
visitor.visit(m_locationbar);
visitor.visit(m_menubar);
visitor.visit(m_personalbar);
visitor.visit(m_scrollbars);
visitor.visit(m_statusbar);
visitor.visit(m_toolbar);
}
void Window::finalize()
@ -920,6 +926,60 @@ void Window::blur()
// The blur() method steps are to do nothing.
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-locationbar
GC::Ref<BarProp const> Window::locationbar()
{
if (!m_locationbar)
m_locationbar = BarProp::create(realm());
return *m_locationbar;
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-menubar
GC::Ref<BarProp const> Window::menubar()
{
if (!m_menubar)
m_menubar = BarProp::create(realm());
return *m_menubar;
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-personalbar
GC::Ref<BarProp const> Window::personalbar()
{
if (!m_personalbar)
m_personalbar = BarProp::create(realm());
return *m_personalbar;
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-scrollbars
GC::Ref<BarProp const> Window::scrollbars()
{
if (!m_scrollbars)
m_scrollbars = BarProp::create(realm());
return *m_scrollbars;
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-statusbar
GC::Ref<BarProp const> Window::statusbar()
{
if (!m_statusbar)
m_statusbar = BarProp::create(realm());
return *m_statusbar;
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-toolbar
GC::Ref<BarProp const> Window::toolbar()
{
if (!m_toolbar)
m_toolbar = BarProp::create(realm());
return *m_toolbar;
}
// https://html.spec.whatwg.org/multipage/window-object.html#dom-frames
GC::Ref<WindowProxy> Window::frames() const
{

View file

@ -16,6 +16,7 @@
#include <LibWeb/Bindings/WindowGlobalMixin.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/BarProp.h>
#include <LibWeb/HTML/CrossOrigin/CrossOriginPropertyDescriptorMap.h>
#include <LibWeb/HTML/GlobalEventHandlers.h>
#include <LibWeb/HTML/MimeType.h>
@ -173,6 +174,15 @@ public:
void focus();
void blur();
// For historical reasons, the Window interface had some properties that represented the visibility of certain web browser interface elements.
// For privacy and interoperability reasons, those properties now return values that represent whether the Window's browsing context's is popup property is true or false.
GC::Ref<BarProp const> locationbar();
GC::Ref<BarProp const> menubar();
GC::Ref<BarProp const> personalbar();
GC::Ref<BarProp const> scrollbars();
GC::Ref<BarProp const> statusbar();
GC::Ref<BarProp const> toolbar();
GC::Ref<WindowProxy> frames() const;
u32 length();
GC::Ptr<WindowProxy const> top() const;
@ -332,6 +342,13 @@ private:
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-status
// When the Window object is created, the attribute must be set to the empty string. It does not do anything else.
String m_status;
GC::Ptr<BarProp const> m_locationbar;
GC::Ptr<BarProp const> m_menubar;
GC::Ptr<BarProp const> m_personalbar;
GC::Ptr<BarProp const> m_scrollbars;
GC::Ptr<BarProp const> m_statusbar;
GC::Ptr<BarProp const> m_toolbar;
};
void run_animation_frame_callbacks(DOM::Document&, double now);

View file

@ -34,6 +34,13 @@ interface Window : EventTarget {
undefined focus();
undefined blur();
[Replaceable] readonly attribute BarProp locationbar;
[Replaceable] readonly attribute BarProp menubar;
[Replaceable] readonly attribute BarProp personalbar;
[Replaceable] readonly attribute BarProp scrollbars;
[Replaceable] readonly attribute BarProp statusbar;
[Replaceable] readonly attribute BarProp toolbar;
// other browsing contexts
[Replaceable] readonly attribute WindowProxy frames;
[Replaceable] readonly attribute unsigned long length;