mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-19 15:32:31 +00:00
LibWeb: Implement BarProp properties for Window
This commit is contained in:
parent
ad634897b8
commit
b66e7ac1ba
Notes:
github-actions[bot]
2025-03-29 02:36:35 +00:00
Author: https://github.com/Totto16
Commit: b66e7ac1ba
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3810
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/tcl3 ✅
13 changed files with 201 additions and 0 deletions
|
@ -314,6 +314,7 @@ set(SOURCES
|
||||||
HTML/AudioTrack.cpp
|
HTML/AudioTrack.cpp
|
||||||
HTML/AudioTrackList.cpp
|
HTML/AudioTrackList.cpp
|
||||||
HTML/AutocompleteElement.cpp
|
HTML/AutocompleteElement.cpp
|
||||||
|
HTML/BarProp.cpp
|
||||||
HTML/BeforeUnloadEvent.cpp
|
HTML/BeforeUnloadEvent.cpp
|
||||||
HTML/BroadcastChannel.cpp
|
HTML/BroadcastChannel.cpp
|
||||||
HTML/BrowsingContext.cpp
|
HTML/BrowsingContext.cpp
|
||||||
|
|
|
@ -417,6 +417,7 @@ namespace Web::HTML {
|
||||||
class AnimationFrameCallbackDriver;
|
class AnimationFrameCallbackDriver;
|
||||||
class AudioTrack;
|
class AudioTrack;
|
||||||
class AudioTrackList;
|
class AudioTrackList;
|
||||||
|
class BarProp;
|
||||||
class BeforeUnloadEvent;
|
class BeforeUnloadEvent;
|
||||||
class BroadcastChannel;
|
class BroadcastChannel;
|
||||||
class BrowsingContext;
|
class BrowsingContext;
|
||||||
|
|
47
Libraries/LibWeb/HTML/BarProp.cpp
Normal file
47
Libraries/LibWeb/HTML/BarProp.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
30
Libraries/LibWeb/HTML/BarProp.h
Normal file
30
Libraries/LibWeb/HTML/BarProp.h
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
6
Libraries/LibWeb/HTML/BarProp.idl
Normal file
6
Libraries/LibWeb/HTML/BarProp.idl
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#barprop
|
||||||
|
[Exposed=Window]
|
||||||
|
interface BarProp {
|
||||||
|
readonly attribute boolean visible;
|
||||||
|
};
|
|
@ -77,6 +77,7 @@ public:
|
||||||
void set_opener_browsing_context(GC::Ptr<BrowsingContext> browsing_context) { m_opener_browsing_context = browsing_context; }
|
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; }
|
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; }
|
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; }
|
void set_popup_sandboxing_flag_set(SandboxingFlagSet value) { m_popup_sandboxing_flag_set = value; }
|
||||||
|
|
|
@ -128,6 +128,12 @@ void Window::visit_edges(JS::Cell::Visitor& visitor)
|
||||||
visitor.visit(m_pdf_viewer_plugin_objects);
|
visitor.visit(m_pdf_viewer_plugin_objects);
|
||||||
visitor.visit(m_pdf_viewer_mime_type_objects);
|
visitor.visit(m_pdf_viewer_mime_type_objects);
|
||||||
visitor.visit(m_close_watcher_manager);
|
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()
|
void Window::finalize()
|
||||||
|
@ -920,6 +926,60 @@ void Window::blur()
|
||||||
// The blur() method steps are to do nothing.
|
// 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
|
// https://html.spec.whatwg.org/multipage/window-object.html#dom-frames
|
||||||
GC::Ref<WindowProxy> Window::frames() const
|
GC::Ref<WindowProxy> Window::frames() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <LibWeb/Bindings/WindowGlobalMixin.h>
|
#include <LibWeb/Bindings/WindowGlobalMixin.h>
|
||||||
#include <LibWeb/DOM/EventTarget.h>
|
#include <LibWeb/DOM/EventTarget.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
#include <LibWeb/HTML/BarProp.h>
|
||||||
#include <LibWeb/HTML/CrossOrigin/CrossOriginPropertyDescriptorMap.h>
|
#include <LibWeb/HTML/CrossOrigin/CrossOriginPropertyDescriptorMap.h>
|
||||||
#include <LibWeb/HTML/GlobalEventHandlers.h>
|
#include <LibWeb/HTML/GlobalEventHandlers.h>
|
||||||
#include <LibWeb/HTML/MimeType.h>
|
#include <LibWeb/HTML/MimeType.h>
|
||||||
|
@ -173,6 +174,15 @@ public:
|
||||||
void focus();
|
void focus();
|
||||||
void blur();
|
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;
|
GC::Ref<WindowProxy> frames() const;
|
||||||
u32 length();
|
u32 length();
|
||||||
GC::Ptr<WindowProxy const> top() const;
|
GC::Ptr<WindowProxy const> top() const;
|
||||||
|
@ -332,6 +342,13 @@ private:
|
||||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-status
|
// 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.
|
// When the Window object is created, the attribute must be set to the empty string. It does not do anything else.
|
||||||
String m_status;
|
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);
|
void run_animation_frame_callbacks(DOM::Document&, double now);
|
||||||
|
|
|
@ -34,6 +34,13 @@ interface Window : EventTarget {
|
||||||
undefined focus();
|
undefined focus();
|
||||||
undefined blur();
|
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
|
// other browsing contexts
|
||||||
[Replaceable] readonly attribute WindowProxy frames;
|
[Replaceable] readonly attribute WindowProxy frames;
|
||||||
[Replaceable] readonly attribute unsigned long length;
|
[Replaceable] readonly attribute unsigned long length;
|
||||||
|
|
|
@ -110,6 +110,7 @@ libweb_js_bindings(Geometry/DOMRectList)
|
||||||
libweb_js_bindings(Geometry/DOMRectReadOnly)
|
libweb_js_bindings(Geometry/DOMRectReadOnly)
|
||||||
libweb_js_bindings(HTML/AudioTrack)
|
libweb_js_bindings(HTML/AudioTrack)
|
||||||
libweb_js_bindings(HTML/AudioTrackList)
|
libweb_js_bindings(HTML/AudioTrackList)
|
||||||
|
libweb_js_bindings(HTML/BarProp)
|
||||||
libweb_js_bindings(HTML/BeforeUnloadEvent)
|
libweb_js_bindings(HTML/BeforeUnloadEvent)
|
||||||
libweb_js_bindings(HTML/BroadcastChannel)
|
libweb_js_bindings(HTML/BroadcastChannel)
|
||||||
libweb_js_bindings(HTML/CanvasGradient)
|
libweb_js_bindings(HTML/CanvasGradient)
|
||||||
|
|
6
Tests/LibWeb/Text/expected/HTML/window-barprops.txt
Normal file
6
Tests/LibWeb/Text/expected/HTML/window-barprops.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
locationbar is BarProp: true visible: true
|
||||||
|
menubar is BarProp: true visible: true
|
||||||
|
personalbar is BarProp: true visible: true
|
||||||
|
scrollbars is BarProp: true visible: true
|
||||||
|
statusbar is BarProp: true visible: true
|
||||||
|
toolbar is BarProp: true visible: true
|
|
@ -23,6 +23,7 @@ AudioParam
|
||||||
AudioScheduledSourceNode
|
AudioScheduledSourceNode
|
||||||
AudioTrack
|
AudioTrack
|
||||||
AudioTrackList
|
AudioTrackList
|
||||||
|
BarProp
|
||||||
BaseAudioContext
|
BaseAudioContext
|
||||||
BeforeUnloadEvent
|
BeforeUnloadEvent
|
||||||
BigInt
|
BigInt
|
||||||
|
|
23
Tests/LibWeb/Text/input/HTML/window-barprops.html
Normal file
23
Tests/LibWeb/Text/input/HTML/window-barprops.html
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const availableProps = [
|
||||||
|
"locationbar",
|
||||||
|
"menubar",
|
||||||
|
"personalbar",
|
||||||
|
"scrollbars",
|
||||||
|
"statusbar",
|
||||||
|
"toolbar",
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const propName of availableProps) {
|
||||||
|
const windowProp = window[propName];
|
||||||
|
println(
|
||||||
|
`${propName} is BarProp: ${windowProp instanceof BarProp} visible: ${
|
||||||
|
windowProp.visible
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue